summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Grover <joeygrover@gmail.com>2019-10-17 16:06:53 -0400
committerJoey Grover <joeygrover@gmail.com>2019-10-17 16:06:53 -0400
commit3202e0f3913b502554ea89b46c8eafaf77b06c16 (patch)
tree10269e772866db36cd886bec7504a2af9be17152
parent7c189e82a632766cb3a286ec5ce01330243b9f2b (diff)
downloadsdl_android-3202e0f3913b502554ea89b46c8eafaf77b06c16.tar.gz
Fix issue where video formats aren’t supported
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/video/VideoStreamingParametersTest.java118
-rw-r--r--android/sdl_android/src/test/java/com/smartdevicelink/streaming/video/VideoStreamingParametersTest.java116
-rw-r--r--base/src/main/java/com/smartdevicelink/proxy/rpc/VideoStreamingFormat.java11
-rw-r--r--base/src/main/java/com/smartdevicelink/streaming/video/VideoStreamingParameters.java17
4 files changed, 144 insertions, 118 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/video/VideoStreamingParametersTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/video/VideoStreamingParametersTest.java
new file mode 100644
index 000000000..a81f69eb3
--- /dev/null
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/streaming/video/VideoStreamingParametersTest.java
@@ -0,0 +1,118 @@
+package com.smartdevicelink.test.streaming.video;
+
+import com.smartdevicelink.AndroidTestCase2;
+import com.smartdevicelink.proxy.rpc.ImageResolution;
+import com.smartdevicelink.proxy.rpc.VideoStreamingCapability;
+import com.smartdevicelink.proxy.rpc.VideoStreamingFormat;
+import com.smartdevicelink.proxy.rpc.enums.VideoStreamingCodec;
+import com.smartdevicelink.proxy.rpc.enums.VideoStreamingProtocol;
+import com.smartdevicelink.streaming.video.VideoStreamingParameters;
+import java.util.Collections;
+
+
+public class VideoStreamingParametersTest extends AndroidTestCase2 {
+
+ private VideoStreamingParameters params;
+ private VideoStreamingCapability capability;
+ private ImageResolution preferredResolution;
+
+ public void setUp() {
+ params = new VideoStreamingParameters();
+ capability = new VideoStreamingCapability();
+ }
+
+ public void testUpdateNullScale() {
+ preferredResolution = new ImageResolution(800, 354);
+
+ capability.setScale(null);
+ capability.setPreferredResolution(preferredResolution);
+
+ params.update(capability);
+
+ int width = params.getResolution().getResolutionWidth();
+ int height = params.getResolution().getResolutionHeight();
+
+ assertEquals(800, width);
+ assertEquals(354, height);
+ }
+
+ public void testUpdateScale_1_Resolution_800_354() {
+ preferredResolution = new ImageResolution(800, 354);
+
+ capability.setScale(1.0);
+ capability.setPreferredResolution(preferredResolution);
+
+ params.update(capability);
+
+ int width = params.getResolution().getResolutionWidth();
+ int height = params.getResolution().getResolutionHeight();
+
+ assertEquals(800, width);
+ assertEquals(354, height);
+ }
+
+ public void testUpdateScale_1_25_Resolution_1280_569() {
+ preferredResolution = new ImageResolution(1280, 569);
+
+ capability.setScale(1.25);
+ capability.setPreferredResolution(preferredResolution);
+
+ params.update(capability);
+
+ int width = params.getResolution().getResolutionWidth();
+ int height = params.getResolution().getResolutionHeight();
+
+ assertEquals(1024, width);
+ assertEquals(456, height);
+ }
+
+ public void testUpdateScale_1_5_Resolution_1280_569() {
+ preferredResolution = new ImageResolution(1280, 569);
+
+ capability.setScale(1.5);
+ capability.setPreferredResolution(preferredResolution);
+
+ params.update(capability);
+
+ int width = params.getResolution().getResolutionWidth();
+ int height = params.getResolution().getResolutionHeight();
+
+ assertEquals(854, width);
+ assertEquals(380, height);
+ }
+
+ public void testUpdateCapabilityFormat(){
+ VideoStreamingCapability capability = new VideoStreamingCapability();
+ capability.setMaxBitrate(10000);
+ capability.setPreferredResolution( new ImageResolution(800,600));
+ capability.setIsHapticSpatialDataSupported(false);
+
+ VideoStreamingFormat format = new VideoStreamingFormat(VideoStreamingProtocol.RAW, VideoStreamingCodec.H264);
+ capability.setSupportedFormats(Collections.singletonList(format));
+
+ VideoStreamingParameters params = new VideoStreamingParameters();
+ params.setFormat(null);
+
+ assertNull(params.getFormat());
+
+ params.update(capability);
+
+ assertEquals(params.getFormat(), format);
+
+ format = new VideoStreamingFormat(VideoStreamingProtocol.RTP, VideoStreamingCodec.H264);
+ capability.setSupportedFormats(Collections.singletonList(format));
+ params.update(capability);
+ assertEquals(params.getFormat(), format);
+
+ format = new VideoStreamingFormat(VideoStreamingProtocol.RTP, VideoStreamingCodec.H265);
+ capability.setSupportedFormats(Collections.singletonList(format));
+ params.update(capability);
+ assertFalse(params.getFormat().equals(format));
+
+ format = new VideoStreamingFormat(VideoStreamingProtocol.RAW, VideoStreamingCodec.VP8);
+ capability.setSupportedFormats(Collections.singletonList(format));
+ params.update(capability);
+ assertFalse(params.getFormat().equals(format));
+
+ }
+}
diff --git a/android/sdl_android/src/test/java/com/smartdevicelink/streaming/video/VideoStreamingParametersTest.java b/android/sdl_android/src/test/java/com/smartdevicelink/streaming/video/VideoStreamingParametersTest.java
deleted file mode 100644
index f08bada0f..000000000
--- a/android/sdl_android/src/test/java/com/smartdevicelink/streaming/video/VideoStreamingParametersTest.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package com.smartdevicelink.streaming.video;
-
-import com.smartdevicelink.proxy.rpc.ImageResolution;
-import com.smartdevicelink.proxy.rpc.VideoStreamingCapability;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-public class VideoStreamingParametersTest {
- private VideoStreamingParameters params;
- private VideoStreamingCapability capability;
- private ImageResolution preferredResolution;
-
- @Before
- public void setUp() {
- params = new VideoStreamingParameters();
- capability = new VideoStreamingCapability();
- }
-
- @Test
- public void update_NullScale() {
- preferredResolution = new ImageResolution(800, 354);
-
- capability.setScale(null);
- capability.setPreferredResolution(preferredResolution);
-
- params.update(capability);
-
- int width = params.getResolution().getResolutionWidth();
- int height = params.getResolution().getResolutionHeight();
-
- assertEquals(800, width);
- assertEquals(354, height);
- }
-
- @Test
- public void update_Scale_1_Resolution_800_354() {
- preferredResolution = new ImageResolution(800, 354);
-
- capability.setScale(1.0);
- capability.setPreferredResolution(preferredResolution);
-
- params.update(capability);
-
- int width = params.getResolution().getResolutionWidth();
- int height = params.getResolution().getResolutionHeight();
-
- assertEquals(800, width);
- assertEquals(354, height);
- }
-
- @Test
- public void update_Scale_1_25_Resolution_1280_569() {
- preferredResolution = new ImageResolution(1280, 569);
-
- capability.setScale(1.25);
- capability.setPreferredResolution(preferredResolution);
-
- params.update(capability);
-
- int width = params.getResolution().getResolutionWidth();
- int height = params.getResolution().getResolutionHeight();
-
- assertEquals(1024, width);
- assertEquals(456, height);
- }
-
- @Test
- public void update_Scale_1_5_Resolution_1280_569() {
- preferredResolution = new ImageResolution(1280, 569);
-
- capability.setScale(1.5);
- capability.setPreferredResolution(preferredResolution);
-
- params.update(capability);
-
- int width = params.getResolution().getResolutionWidth();
- int height = params.getResolution().getResolutionHeight();
-
- assertEquals(854, width);
- assertEquals(380, height);
- }
-} \ No newline at end of file
diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/VideoStreamingFormat.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/VideoStreamingFormat.java
index afad87256..4328b5a1a 100644
--- a/base/src/main/java/com/smartdevicelink/proxy/rpc/VideoStreamingFormat.java
+++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/VideoStreamingFormat.java
@@ -31,7 +31,9 @@
*/
package com.smartdevicelink.proxy.rpc;
+import android.provider.MediaStore;
import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
import com.smartdevicelink.proxy.RPCStruct;
import com.smartdevicelink.proxy.rpc.enums.VideoStreamingCodec;
@@ -78,6 +80,15 @@ public class VideoStreamingFormat extends RPCStruct {
}
@Override
+ public boolean equals(Object obj) {
+ if(obj != null && obj instanceof VideoStreamingFormat){
+ VideoStreamingFormat compareTo = (VideoStreamingFormat) obj;
+ return getCodec() == compareTo.getCodec() && getProtocol() == compareTo.getProtocol();
+ }
+ return false;
+ }
+
+ @Override
public String toString() {
return "codec=" + String.valueOf(getCodec()) +
", protocol=" + String.valueOf(getProtocol());
diff --git a/base/src/main/java/com/smartdevicelink/streaming/video/VideoStreamingParameters.java b/base/src/main/java/com/smartdevicelink/streaming/video/VideoStreamingParameters.java
index f79596738..4c051d0b3 100644
--- a/base/src/main/java/com/smartdevicelink/streaming/video/VideoStreamingParameters.java
+++ b/base/src/main/java/com/smartdevicelink/streaming/video/VideoStreamingParameters.java
@@ -44,6 +44,8 @@ import java.util.List;
public class VideoStreamingParameters {
private final VideoStreamingProtocol DEFAULT_PROTOCOL = VideoStreamingProtocol.RAW;
private final VideoStreamingCodec DEFAULT_CODEC = VideoStreamingCodec.H264;
+ private final VideoStreamingFormat[] CURRENTLY_SUPPORTED_FORMATS = { new VideoStreamingFormat(VideoStreamingProtocol.RTP, VideoStreamingCodec.H264),
+ new VideoStreamingFormat(VideoStreamingProtocol.RAW, VideoStreamingCodec.H264) };
private final int DEFAULT_WIDTH = 1024;
private final int DEFAULT_HEIGHT = 576;
private final int DEFAULT_DENSITY = 240;
@@ -141,9 +143,20 @@ public class VideoStreamingParameters {
if(resolution.getResolutionHeight()!=null && resolution.getResolutionHeight() > 0){ this.resolution.setResolutionHeight((int)(resolution.getResolutionHeight() / scale)); }
if(resolution.getResolutionWidth()!=null && resolution.getResolutionWidth() > 0){ this.resolution.setResolutionWidth((int)(resolution.getResolutionWidth() / scale)); }
}
- List<VideoStreamingFormat> formats = capability.getSupportedFormats();
+
+ // This should be the last call as it will return out once a suitable format is found
+ final List<VideoStreamingFormat> formats = capability.getSupportedFormats();
if(formats != null && formats.size()>0){
- this.format = formats.get(0);
+ for(VideoStreamingFormat format : formats){
+ for(int i = 0; i < CURRENTLY_SUPPORTED_FORMATS.length; i ++){
+ if(CURRENTLY_SUPPORTED_FORMATS[i].equals(format) ){
+ this.format = format;
+ return;
+ }
+ }
+ }
+ //TODO In the future we should set format to null, but might be a breaking change
+ // For now format, will remain whatever was set prior to this update
}
}