Skip to content

Commit e1b059a

Browse files
Merge pull request #1334 from smartdevicelink/bugfix/issue_1331
Update VideoStreamManager to use VideoStreamingState
2 parents 18b5f86 + 1e7384a commit e1b059a

2 files changed

Lines changed: 57 additions & 20 deletions

File tree

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/video/VideoStreamManagerTests.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.smartdevicelink.proxy.rpc.enums.HMILevel;
2828
import com.smartdevicelink.proxy.rpc.enums.SystemCapabilityType;
2929
import com.smartdevicelink.proxy.rpc.enums.TouchType;
30+
import com.smartdevicelink.proxy.rpc.enums.VideoStreamingState;
3031
import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener;
3132
import com.smartdevicelink.streaming.video.SdlRemoteDisplay;
3233
import com.smartdevicelink.streaming.video.VideoStreamingParameters;
@@ -531,4 +532,39 @@ private void assertMotionEventWithScale(int width, int height, float scale) {
531532
assertEquals(Math.round(e1x / scale), Math.round(motionEvent.getX(0)));
532533
assertEquals(Math.round(e1y / scale), Math.round(motionEvent.getY(0)));
533534
}
535+
536+
public void testIsHMIStateVideoStreamCapable() {
537+
VideoStreamManager videoStreamManager = new VideoStreamManager(mock(ISdl.class));
538+
539+
// Case 1 (VideoStreamingState = STREAMABLE)
540+
assertTrue(videoStreamManager.isHMIStateVideoStreamCapable(createOnHMIStatus(HMILevel.HMI_FULL, VideoStreamingState.STREAMABLE)));
541+
assertTrue(videoStreamManager.isHMIStateVideoStreamCapable(createOnHMIStatus(HMILevel.HMI_LIMITED, VideoStreamingState.STREAMABLE)));
542+
assertFalse(videoStreamManager.isHMIStateVideoStreamCapable(createOnHMIStatus(HMILevel.HMI_BACKGROUND, VideoStreamingState.STREAMABLE)));
543+
assertFalse(videoStreamManager.isHMIStateVideoStreamCapable(createOnHMIStatus(HMILevel.HMI_NONE, VideoStreamingState.STREAMABLE)));
544+
assertFalse(videoStreamManager.isHMIStateVideoStreamCapable(createOnHMIStatus(null, VideoStreamingState.STREAMABLE)));
545+
546+
// Case 2 (VideoStreamingState = NOT_STREAMABLE)
547+
assertFalse(videoStreamManager.isHMIStateVideoStreamCapable(createOnHMIStatus(HMILevel.HMI_FULL, VideoStreamingState.NOT_STREAMABLE)));
548+
assertFalse(videoStreamManager.isHMIStateVideoStreamCapable(createOnHMIStatus(HMILevel.HMI_LIMITED, VideoStreamingState.NOT_STREAMABLE)));
549+
assertFalse(videoStreamManager.isHMIStateVideoStreamCapable(createOnHMIStatus(HMILevel.HMI_BACKGROUND, VideoStreamingState.NOT_STREAMABLE)));
550+
assertFalse(videoStreamManager.isHMIStateVideoStreamCapable(createOnHMIStatus(HMILevel.HMI_NONE, VideoStreamingState.NOT_STREAMABLE)));
551+
assertFalse(videoStreamManager.isHMIStateVideoStreamCapable(createOnHMIStatus(null, VideoStreamingState.NOT_STREAMABLE)));
552+
553+
// Case 3 (VideoStreamingState = NULL)
554+
assertTrue(videoStreamManager.isHMIStateVideoStreamCapable(createOnHMIStatus(HMILevel.HMI_FULL, null)));
555+
assertTrue(videoStreamManager.isHMIStateVideoStreamCapable(createOnHMIStatus(HMILevel.HMI_LIMITED, null)));
556+
assertFalse(videoStreamManager.isHMIStateVideoStreamCapable(createOnHMIStatus(HMILevel.HMI_BACKGROUND, null)));
557+
assertFalse(videoStreamManager.isHMIStateVideoStreamCapable(createOnHMIStatus(HMILevel.HMI_NONE, null)));
558+
assertFalse(videoStreamManager.isHMIStateVideoStreamCapable(createOnHMIStatus(null, null)));
559+
560+
// Case 4 (onHMIStatus = NULL)
561+
assertFalse(videoStreamManager.isHMIStateVideoStreamCapable(null));
562+
}
563+
564+
private OnHMIStatus createOnHMIStatus(HMILevel hmiLevel, VideoStreamingState videoStreamingState) {
565+
OnHMIStatus onHMIStatus = new OnHMIStatus();
566+
onHMIStatus.setHmiLevel(hmiLevel);
567+
onHMIStatus.setVideoStreamingState(videoStreamingState);
568+
return onHMIStatus;
569+
}
534570
}

android/sdl_android/src/main/java/com/smartdevicelink/managers/video/VideoStreamManager.java

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import com.smartdevicelink.proxy.rpc.enums.PredefinedWindows;
6666
import com.smartdevicelink.proxy.rpc.enums.SystemCapabilityType;
6767
import com.smartdevicelink.proxy.rpc.enums.TouchType;
68+
import com.smartdevicelink.proxy.rpc.enums.VideoStreamingState;
6869
import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener;
6970
import com.smartdevicelink.streaming.video.SdlRemoteDisplay;
7071
import com.smartdevicelink.streaming.video.VideoStreamingParameters;
@@ -74,7 +75,6 @@
7475

7576
import java.lang.ref.WeakReference;
7677
import java.util.ArrayList;
77-
import java.util.Arrays;
7878
import java.util.List;
7979
import java.util.concurrent.CopyOnWriteArrayList;
8080
import java.util.concurrent.FutureTask;
@@ -90,13 +90,12 @@ public class VideoStreamManager extends BaseVideoStreamManager {
9090
private float[] touchScalar = {1.0f,1.0f}; //x, y
9191
private HapticInterfaceManager hapticManager;
9292
private SdlMotionEvent sdlMotionEvent = null;
93-
private HMILevel hmiLevel;
93+
private OnHMIStatus currentOnHMIStatus;
9494
private StreamingStateMachine stateMachine;
9595
private VideoStreamingParameters parameters;
9696
private IVideoStreamListener streamListener;
9797
private boolean isTransportAvailable = false;
9898
private boolean hasStarted;
99-
private List<HMILevel> streamableLevels = Arrays.asList(HMILevel.HMI_FULL, HMILevel.HMI_LIMITED);
10099
private String vehicleMake = null;
101100

102101
// INTERNAL INTERFACES
@@ -148,19 +147,17 @@ public void onServiceError(SdlSession session, SessionType type, String reason)
148147
@Override
149148
public void onNotified(RPCNotification notification) {
150149
if(notification != null){
151-
OnHMIStatus onHMIStatus = (OnHMIStatus)notification;
150+
OnHMIStatus onHMIStatus = (OnHMIStatus) notification;
152151
if (onHMIStatus.getWindowID() != null && onHMIStatus.getWindowID() != PredefinedWindows.DEFAULT_WINDOW.getValue()) {
153152
return;
154153
}
155-
HMILevel prevHMILevel = hmiLevel;
156-
hmiLevel = onHMIStatus.getHmiLevel();
157-
if (!HMILevel.HMI_NONE.equals(hmiLevel) && VideoStreamManager.this.parameters == null) {
154+
OnHMIStatus prevOnHMIStatus = currentOnHMIStatus;
155+
currentOnHMIStatus = onHMIStatus;
156+
if (!HMILevel.HMI_NONE.equals(currentOnHMIStatus.getHmiLevel()) && VideoStreamManager.this.parameters == null) {
158157
getVideoStreamingParams();
159158
}
160-
if (streamableLevels.contains(hmiLevel)) {
161-
checkState();
162-
}
163-
if (hasStarted && (streamableLevels.contains(prevHMILevel)) && (!streamableLevels.contains(hmiLevel))) {
159+
checkState();
160+
if (hasStarted && (isHMIStateVideoStreamCapable(prevOnHMIStatus)) && (!isHMIStateVideoStreamCapable(currentOnHMIStatus))) {
164161
internalInterface.stopVideoService();
165162
}
166163
}
@@ -185,11 +182,11 @@ public void onNotified(RPCNotification notification) {
185182
public VideoStreamManager(ISdl internalInterface){
186183
super(internalInterface);
187184

188-
if(internalInterface.getRegisterAppInterfaceResponse().getVehicleType() != null) {
185+
if(internalInterface != null && internalInterface.getRegisterAppInterfaceResponse() != null &&
186+
internalInterface.getRegisterAppInterfaceResponse().getVehicleType() != null) {
189187
vehicleMake = internalInterface.getRegisterAppInterfaceResponse().getVehicleType().getMake();
190188
}
191189
virtualDisplayEncoder = new VirtualDisplayEncoder();
192-
hmiLevel = HMILevel.HMI_NONE;
193190

194191
// Listen for video service events
195192
internalInterface.addServiceListener(SessionType.NAV, serviceListener);
@@ -211,14 +208,19 @@ public void start(CompletionListener listener) {
211208
private synchronized void checkState(){
212209
if(this.getState() == SETTING_UP
213210
&& isTransportAvailable
214-
&& hmiLevel != null
215-
&& streamableLevels.contains(hmiLevel)
211+
&& isHMIStateVideoStreamCapable(currentOnHMIStatus)
216212
&& parameters != null){
217213
stateMachine.transitionToState(StreamingStateMachine.READY);
218214
transitionToState(READY);
219215
}
220216
}
221217

218+
boolean isHMIStateVideoStreamCapable(OnHMIStatus onHMIStatus) {
219+
HMILevel hmiLevel = (onHMIStatus != null && onHMIStatus.getHmiLevel() != null) ? onHMIStatus.getHmiLevel() : HMILevel.HMI_NONE;
220+
VideoStreamingState videoStreamingState = (onHMIStatus != null && onHMIStatus.getVideoStreamingState() != null) ? onHMIStatus.getVideoStreamingState() : VideoStreamingState.STREAMABLE;
221+
return (hmiLevel.equals(HMILevel.HMI_FULL) || hmiLevel.equals(HMILevel.HMI_LIMITED)) && videoStreamingState.equals(VideoStreamingState.STREAMABLE);
222+
}
223+
222224
private void getVideoStreamingParams(){
223225
if(internalInterface.getProtocolVersion().getMajor() >= 5) {
224226
internalInterface.getCapability(SystemCapabilityType.VIDEO_STREAMING, new OnSystemCapabilityListener() {
@@ -310,13 +312,12 @@ public void onError(String info) {
310312
*/
311313
protected void startStreaming(VideoStreamingParameters parameters, boolean encrypted){
312314
this.parameters = parameters;
313-
if (!streamableLevels.contains(hmiLevel)) {
314-
Log.e(TAG, "Cannot start video service if HMILevel is not FULL or LIMITED.");
315+
if (!isHMIStateVideoStreamCapable(currentOnHMIStatus)) {
316+
Log.e(TAG, "Cannot start video service in the current HMI status");
315317
return;
316318
}
317319
//Start the video service
318320
this.internalInterface.startVideoService(parameters, encrypted);
319-
320321
}
321322

322323
/**
@@ -406,15 +407,15 @@ public boolean isServiceActive(){
406407
* @return boolean (true = yes, false = no)
407408
*/
408409
public boolean isStreaming(){
409-
return (stateMachine.getState() == StreamingStateMachine.STARTED) && (streamableLevels.contains(hmiLevel));
410+
return (stateMachine.getState() == StreamingStateMachine.STARTED) && (isHMIStateVideoStreamCapable(currentOnHMIStatus));
410411
}
411412

412413
/**
413414
* Check if video streaming has been paused due to app moving to background or manually stopped
414415
* @return boolean (true = not paused, false = paused)
415416
*/
416417
public boolean isPaused(){
417-
return (hasStarted && stateMachine.getState() == StreamingStateMachine.STOPPED) || (!streamableLevels.contains(hmiLevel));
418+
return (hasStarted && stateMachine.getState() == StreamingStateMachine.STOPPED) || (!isHMIStateVideoStreamCapable(currentOnHMIStatus));
418419
}
419420

420421
/**

0 commit comments

Comments
 (0)