diff options
author | Brett <3911458+BrettyWhite@users.noreply.github.com> | 2019-10-21 12:00:39 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-21 12:00:39 -0400 |
commit | 71475782ba1f7e235991e4ab598dd751fc9a4f93 (patch) | |
tree | b1e475739931eff9bef82effcd2ffd3c48754576 | |
parent | 7c189e82a632766cb3a286ec5ce01330243b9f2b (diff) | |
parent | f0d8be6568b26896d32aa00168cb19bb38ace774 (diff) | |
download | sdl_android-71475782ba1f7e235991e4ab598dd751fc9a4f93.tar.gz |
Merge pull request #1206 from smartdevicelink/bugfix/video_streaming_param_issue
Fix issue where video formats aren’t supported
4 files changed, 145 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..0fc981672 100644 --- a/base/src/main/java/com/smartdevicelink/proxy/rpc/VideoStreamingFormat.java +++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/VideoStreamingFormat.java @@ -78,6 +78,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..ded3a9cd9 100644 --- a/base/src/main/java/com/smartdevicelink/streaming/video/VideoStreamingParameters.java +++ b/base/src/main/java/com/smartdevicelink/streaming/video/VideoStreamingParameters.java @@ -37,6 +37,7 @@ 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.util.DebugTool; import java.util.List; @@ -44,6 +45,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 +144,22 @@ 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; + } + } + } + DebugTool.logWarning("The VideoStreamingFormat has not been updated because none of the provided formats are supported."); + + //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 } } |