6565import com .smartdevicelink .proxy .rpc .enums .PredefinedWindows ;
6666import com .smartdevicelink .proxy .rpc .enums .SystemCapabilityType ;
6767import com .smartdevicelink .proxy .rpc .enums .TouchType ;
68+ import com .smartdevicelink .proxy .rpc .enums .VideoStreamingState ;
6869import com .smartdevicelink .proxy .rpc .listeners .OnRPCNotificationListener ;
6970import com .smartdevicelink .streaming .video .SdlRemoteDisplay ;
7071import com .smartdevicelink .streaming .video .VideoStreamingParameters ;
7475
7576import java .lang .ref .WeakReference ;
7677import java .util .ArrayList ;
77- import java .util .Arrays ;
7878import java .util .List ;
7979import java .util .concurrent .CopyOnWriteArrayList ;
8080import 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