Skip to content

Commit 7147578

Browse files
authored
Merge pull request #1206 from smartdevicelink/bugfix/video_streaming_param_issue
Fix issue where video formats aren’t supported
2 parents 7c189e8 + f0d8be6 commit 7147578

4 files changed

Lines changed: 145 additions & 118 deletions

File tree

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package com.smartdevicelink.test.streaming.video;
2+
3+
import com.smartdevicelink.AndroidTestCase2;
4+
import com.smartdevicelink.proxy.rpc.ImageResolution;
5+
import com.smartdevicelink.proxy.rpc.VideoStreamingCapability;
6+
import com.smartdevicelink.proxy.rpc.VideoStreamingFormat;
7+
import com.smartdevicelink.proxy.rpc.enums.VideoStreamingCodec;
8+
import com.smartdevicelink.proxy.rpc.enums.VideoStreamingProtocol;
9+
import com.smartdevicelink.streaming.video.VideoStreamingParameters;
10+
import java.util.Collections;
11+
12+
13+
public class VideoStreamingParametersTest extends AndroidTestCase2 {
14+
15+
private VideoStreamingParameters params;
16+
private VideoStreamingCapability capability;
17+
private ImageResolution preferredResolution;
18+
19+
public void setUp() {
20+
params = new VideoStreamingParameters();
21+
capability = new VideoStreamingCapability();
22+
}
23+
24+
public void testUpdateNullScale() {
25+
preferredResolution = new ImageResolution(800, 354);
26+
27+
capability.setScale(null);
28+
capability.setPreferredResolution(preferredResolution);
29+
30+
params.update(capability);
31+
32+
int width = params.getResolution().getResolutionWidth();
33+
int height = params.getResolution().getResolutionHeight();
34+
35+
assertEquals(800, width);
36+
assertEquals(354, height);
37+
}
38+
39+
public void testUpdateScale_1_Resolution_800_354() {
40+
preferredResolution = new ImageResolution(800, 354);
41+
42+
capability.setScale(1.0);
43+
capability.setPreferredResolution(preferredResolution);
44+
45+
params.update(capability);
46+
47+
int width = params.getResolution().getResolutionWidth();
48+
int height = params.getResolution().getResolutionHeight();
49+
50+
assertEquals(800, width);
51+
assertEquals(354, height);
52+
}
53+
54+
public void testUpdateScale_1_25_Resolution_1280_569() {
55+
preferredResolution = new ImageResolution(1280, 569);
56+
57+
capability.setScale(1.25);
58+
capability.setPreferredResolution(preferredResolution);
59+
60+
params.update(capability);
61+
62+
int width = params.getResolution().getResolutionWidth();
63+
int height = params.getResolution().getResolutionHeight();
64+
65+
assertEquals(1024, width);
66+
assertEquals(456, height);
67+
}
68+
69+
public void testUpdateScale_1_5_Resolution_1280_569() {
70+
preferredResolution = new ImageResolution(1280, 569);
71+
72+
capability.setScale(1.5);
73+
capability.setPreferredResolution(preferredResolution);
74+
75+
params.update(capability);
76+
77+
int width = params.getResolution().getResolutionWidth();
78+
int height = params.getResolution().getResolutionHeight();
79+
80+
assertEquals(854, width);
81+
assertEquals(380, height);
82+
}
83+
84+
public void testUpdateCapabilityFormat(){
85+
VideoStreamingCapability capability = new VideoStreamingCapability();
86+
capability.setMaxBitrate(10000);
87+
capability.setPreferredResolution( new ImageResolution(800,600));
88+
capability.setIsHapticSpatialDataSupported(false);
89+
90+
VideoStreamingFormat format = new VideoStreamingFormat(VideoStreamingProtocol.RAW, VideoStreamingCodec.H264);
91+
capability.setSupportedFormats(Collections.singletonList(format));
92+
93+
VideoStreamingParameters params = new VideoStreamingParameters();
94+
params.setFormat(null);
95+
96+
assertNull(params.getFormat());
97+
98+
params.update(capability);
99+
100+
assertEquals(params.getFormat(), format);
101+
102+
format = new VideoStreamingFormat(VideoStreamingProtocol.RTP, VideoStreamingCodec.H264);
103+
capability.setSupportedFormats(Collections.singletonList(format));
104+
params.update(capability);
105+
assertEquals(params.getFormat(), format);
106+
107+
format = new VideoStreamingFormat(VideoStreamingProtocol.RTP, VideoStreamingCodec.H265);
108+
capability.setSupportedFormats(Collections.singletonList(format));
109+
params.update(capability);
110+
assertFalse(params.getFormat().equals(format));
111+
112+
format = new VideoStreamingFormat(VideoStreamingProtocol.RAW, VideoStreamingCodec.VP8);
113+
capability.setSupportedFormats(Collections.singletonList(format));
114+
params.update(capability);
115+
assertFalse(params.getFormat().equals(format));
116+
117+
}
118+
}

android/sdl_android/src/test/java/com/smartdevicelink/streaming/video/VideoStreamingParametersTest.java

Lines changed: 0 additions & 116 deletions
This file was deleted.

base/src/main/java/com/smartdevicelink/proxy/rpc/VideoStreamingFormat.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ public VideoStreamingCodec getCodec(){
7777
return (VideoStreamingCodec) getObject(VideoStreamingCodec.class, KEY_CODEC);
7878
}
7979

80+
@Override
81+
public boolean equals(Object obj) {
82+
if(obj != null && obj instanceof VideoStreamingFormat){
83+
VideoStreamingFormat compareTo = (VideoStreamingFormat) obj;
84+
return getCodec() == compareTo.getCodec() && getProtocol() == compareTo.getProtocol();
85+
}
86+
return false;
87+
}
88+
8089
@Override
8190
public String toString() {
8291
return "codec=" + String.valueOf(getCodec()) +

base/src/main/java/com/smartdevicelink/streaming/video/VideoStreamingParameters.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,16 @@
3737
import com.smartdevicelink.proxy.rpc.VideoStreamingFormat;
3838
import com.smartdevicelink.proxy.rpc.enums.VideoStreamingCodec;
3939
import com.smartdevicelink.proxy.rpc.enums.VideoStreamingProtocol;
40+
import com.smartdevicelink.util.DebugTool;
4041

4142
import java.util.List;
4243

4344
@SuppressWarnings("FieldCanBeLocal")
4445
public class VideoStreamingParameters {
4546
private final VideoStreamingProtocol DEFAULT_PROTOCOL = VideoStreamingProtocol.RAW;
4647
private final VideoStreamingCodec DEFAULT_CODEC = VideoStreamingCodec.H264;
48+
private final VideoStreamingFormat[] CURRENTLY_SUPPORTED_FORMATS = { new VideoStreamingFormat(VideoStreamingProtocol.RTP, VideoStreamingCodec.H264),
49+
new VideoStreamingFormat(VideoStreamingProtocol.RAW, VideoStreamingCodec.H264) };
4750
private final int DEFAULT_WIDTH = 1024;
4851
private final int DEFAULT_HEIGHT = 576;
4952
private final int DEFAULT_DENSITY = 240;
@@ -141,9 +144,22 @@ public void update(VideoStreamingCapability capability){
141144
if(resolution.getResolutionHeight()!=null && resolution.getResolutionHeight() > 0){ this.resolution.setResolutionHeight((int)(resolution.getResolutionHeight() / scale)); }
142145
if(resolution.getResolutionWidth()!=null && resolution.getResolutionWidth() > 0){ this.resolution.setResolutionWidth((int)(resolution.getResolutionWidth() / scale)); }
143146
}
144-
List<VideoStreamingFormat> formats = capability.getSupportedFormats();
147+
148+
// This should be the last call as it will return out once a suitable format is found
149+
final List<VideoStreamingFormat> formats = capability.getSupportedFormats();
145150
if(formats != null && formats.size()>0){
146-
this.format = formats.get(0);
151+
for(VideoStreamingFormat format : formats){
152+
for(int i = 0; i < CURRENTLY_SUPPORTED_FORMATS.length; i ++){
153+
if(CURRENTLY_SUPPORTED_FORMATS[i].equals(format) ){
154+
this.format = format;
155+
return;
156+
}
157+
}
158+
}
159+
DebugTool.logWarning("The VideoStreamingFormat has not been updated because none of the provided formats are supported.");
160+
161+
//TODO In the future we should set format to null, but might be a breaking change
162+
// For now, format will remain whatever was set prior to this update
147163
}
148164

149165
}

0 commit comments

Comments
 (0)