diff options
author | Joey Grover <joeygrover@gmail.com> | 2017-10-06 17:13:52 -0400 |
---|---|---|
committer | Joey Grover <joeygrover@gmail.com> | 2017-10-06 17:13:52 -0400 |
commit | de67f861e36718e617aa919e24ff183e9d05ff9d (patch) | |
tree | 027b598bbf79f3eee5bafb027b3e3c8e294fc30e /sdl_android/src | |
parent | 0714975c0ae5152914ef431e99d7fc1b136892b9 (diff) | |
download | sdl_android-de67f861e36718e617aa919e24ff183e9d05ff9d.tar.gz |
Integrating streaming listener over outputstream. Fix a few compare issues for backwards compat.
Works at this point. Still needs clean up.
Diffstat (limited to 'sdl_android/src')
3 files changed, 60 insertions, 55 deletions
diff --git a/sdl_android/src/main/java/com/smartdevicelink/encoder/VirtualDisplayEncoder.java b/sdl_android/src/main/java/com/smartdevicelink/encoder/VirtualDisplayEncoder.java index d8489ea44..b1fac6b91 100644 --- a/sdl_android/src/main/java/com/smartdevicelink/encoder/VirtualDisplayEncoder.java +++ b/sdl_android/src/main/java/com/smartdevicelink/encoder/VirtualDisplayEncoder.java @@ -21,6 +21,7 @@ import android.view.View; import android.view.Window; import android.view.WindowManager; +import com.smartdevicelink.proxy.interfaces.IVideoStreamListener; import com.smartdevicelink.proxy.rpc.ImageResolution; import com.smartdevicelink.proxy.rpc.OnTouchEvent; import com.smartdevicelink.proxy.rpc.ScreenParams; @@ -55,7 +56,7 @@ public class VirtualDisplayEncoder { private Class<? extends SdlRemoteDisplay> presentationClass = null; private VideoStreamWriterThread streamWriterThread = null; private Context mContext; - private OutputStream sdlOutStream = null; + private IVideoStreamListener mOutputListener; private Boolean initPassed = false; private final Object CLOSE_VID_SESSION_LOCK = new Object(); private final Object START_DISP_LOCK = new Object(); @@ -67,18 +68,18 @@ public class VirtualDisplayEncoder { * Initialization method for VirtualDisplayEncoder object. MUST be called before start() or shutdown() * Will overwrite previously set videoWeight and videoHeight * @param context - * @param videoStream + * @param outputListener * @param presentationClass * @param streamingParams * @throws Exception */ - public void init(Context context, OutputStream videoStream, Class<? extends SdlRemoteDisplay> presentationClass, VideoStreamingParameters streamingParams) throws Exception { + public void init(Context context, IVideoStreamListener outputListener, Class<? extends SdlRemoteDisplay> presentationClass, VideoStreamingParameters streamingParams) throws Exception { if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Log.e(TAG, "API level of 21 required for VirtualDisplayEncoder"); throw new Exception("API level of 21 required"); } - if (context == null || videoStream == null || presentationClass == null || screenParams == null || streamingParams.getResolution() == null || streamingParams.getFormat() == null) { + if (context == null || outputListener == null || presentationClass == null || screenParams == null || streamingParams.getResolution() == null || streamingParams.getFormat() == null) { Log.e(TAG, "init parameters cannot be null for VirtualDisplayEncoder"); throw new Exception("init parameters cannot be null"); } @@ -89,7 +90,7 @@ public class VirtualDisplayEncoder { this.streamingParams.update(streamingParams); - sdlOutStream = videoStream; + mOutputListener = outputListener; this.presentationClass = presentationClass; @@ -178,7 +179,7 @@ public class VirtualDisplayEncoder { private void closeVideoSession() { synchronized (CLOSE_VID_SESSION_LOCK) { - if (sdlOutStream != null) { + /*if (sdlOutStream != null) { try { sdlOutStream.close(); @@ -192,7 +193,7 @@ public class VirtualDisplayEncoder { streamWriterThread.clearOutputStream(); streamWriterThread.clearByteBuffer(); } - } + }*/ } } @@ -239,8 +240,9 @@ public class VirtualDisplayEncoder { byte[] dataToWrite = new byte[info.size]; encodedData.get(dataToWrite, info.offset, info.size); - - onStreamDataAvailable(dataToWrite, info.size); + if(mOutputListener!=null){ + mOutputListener.sendFrame(dataToWrite,0,dataToWrite.length, info.presentationTimeUs); + } } codec.releaseOutputBuffer(index, false); @@ -326,28 +328,6 @@ public class VirtualDisplayEncoder { return MotionEvent.obtain(downTime, eventTime, eventAction, x, y, 0); } - private void onStreamDataAvailable(byte[] data, int size) { - if (sdlOutStream != null) { - try { - synchronized (streamWriterThread.BUFFER_LOCK) { - streamWriterThread.isWaiting = true; - streamWriterThread.BUFFER_LOCK.wait(); - streamWriterThread.isWaiting = false; - - if (streamWriterThread.getOutputStream() == null) { - streamWriterThread.setOutputStream(sdlOutStream); - } - - streamWriterThread.setByteBuffer(data, size); - } - } catch (Exception e) { - e.printStackTrace(); - } - } else { - Log.e(TAG, "sdlOutStream is null"); - } - } - private void startEncoder() { if (mVideoEncoder != null) { @@ -372,7 +352,7 @@ public class VirtualDisplayEncoder { presentation.dismissPresentation(); } - FutureTask<Boolean> fTask = new FutureTask<Boolean>( presentation.new ShowPresentationCallableMethod(mContext,disp,presentation,presentationClass)); + FutureTask<Boolean> fTask = new FutureTask<Boolean>( new SdlRemoteDisplay.ShowPresentationCallableMethod(mContext,disp,presentation,presentationClass)); Thread showPresentation = new Thread(fTask); showPresentation.start(); diff --git a/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java b/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java index 3d7202e7f..351c6202e 100644 --- a/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java +++ b/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java @@ -3950,6 +3950,9 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> VideoStreamingParameters acceptedParams = tryStartVideoStream(isEncrypted, parameters);
if (acceptedParams != null) {
return sdlSession.startVideoStream();
+ } else if(getWiProVersion() < 5){
+ sdlSession.setAcceptedVideoParams(new VideoStreamingParameters());
+ return sdlSession.startVideoStream();
} else {
return null;
}
@@ -4051,7 +4054,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> DebugTool.logWarning("SdlSession is not created yet.");
return null;
}
- if(!_systemCapabilityManager.isCapabilitySupported(SystemCapabilityType.VIDEO_STREAMING)){
+ if(getWiProVersion() >= 5 && !_systemCapabilityManager.isCapabilitySupported(SystemCapabilityType.VIDEO_STREAMING)){
DebugTool.logWarning("Module doesn't support video streaming.");
return null;
}
@@ -6218,33 +6221,41 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> }
VideoStreamingManager manager;
+
public void startRemoteDisplayStream(Context context, final Class<? extends SdlRemoteDisplay> remoteDisplay, final VideoStreamingParameters parameters, final boolean encrypted){
- if(!_systemCapabilityManager.isCapabilitySupported(SystemCapabilityType.VIDEO_STREAMING)){
+ if(getWiProVersion() > 4 && !_systemCapabilityManager.isCapabilitySupported(SystemCapabilityType.VIDEO_STREAMING)){
Log.e(TAG, "Video streaming not supported on this module");
}
//Create streaming manager
manager = new VideoStreamingManager(context,this._internalInterface);
if(parameters == null){
- _systemCapabilityManager.getCapability(SystemCapabilityType.VIDEO_STREAMING, new OnSystemCapabilityListener() {
- @Override
- public void onCapabilityRetrieved(Object capability) {
- VideoStreamingParameters params = new VideoStreamingParameters();
- List<VideoStreamingCapability> caps = SystemCapabilityManager.convertToList(capability,VideoStreamingCapability.class);
- if(caps!=null && caps.size() > 0){
- params.update(caps.get(0)); //Update our streaming parameters with the capabilities we retrieved
+ if(getWiProVersion() >= 5) {
+ _systemCapabilityManager.getCapability(SystemCapabilityType.VIDEO_STREAMING, new OnSystemCapabilityListener() {
+ @Override
+ public void onCapabilityRetrieved(Object capability) {
+ VideoStreamingParameters params = new VideoStreamingParameters();
+ List<VideoStreamingCapability> caps = SystemCapabilityManager.convertToList(capability, VideoStreamingCapability.class);
+ if (caps != null && caps.size() > 0) {
+ params.update(caps.get(0)); //Update our streaming parameters with the capabilities we retrieved
+ }
+ //Streaming parameters are ready time to stream
+ sdlSession.setDesiredVideoParams(params);
+ manager.startVideoStreaming(remoteDisplay, parameters, encrypted);
}
- //Streaming parameters are ready time to stream
- sdlSession.setDesiredVideoParams(params);
- manager.startVideoStreaming(remoteDisplay,parameters, encrypted);
- }
- @Override
- public void onError(String info) {
- Log.e(TAG, "Error retrieving video streaming capability: " + info);
+ @Override
+ public void onError(String info) {
+ Log.e(TAG, "Error retrieving video streaming capability: " + info);
- }
- });
+ }
+ });
+ }else{
+ //We just use default video streaming params
+ VideoStreamingParameters params = new VideoStreamingParameters();
+ sdlSession.setDesiredVideoParams(params);
+ manager.startVideoStreaming(remoteDisplay,params, encrypted);
+ }
}else{
sdlSession.setDesiredVideoParams(parameters);
manager.startVideoStreaming(remoteDisplay,parameters, encrypted);
@@ -6252,10 +6263,16 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> //Start service w/params
}
+ public void stopRemoteDisplayStream(){
+ if(manager!=null){
+ manager.stopStreaming();
+ }
+ }
+
private class VideoStreamingManager implements ISdlServiceListener{
Context context;
ISdl internalInterface;
- VirtualDisplayEncoder encoder;
+ volatile VirtualDisplayEncoder encoder;
SdlRemoteDisplay remoteDisplay;
IVideoStreamListener streamListener;
//Touch manager
@@ -6271,15 +6288,22 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> public void startVideoStreaming(Class<? extends SdlRemoteDisplay> remoteDisplay, VideoStreamingParameters parameters, boolean encrypted){
streamListener = startVideoStream(encrypted,parameters);
try {
- encoder.init(context,null,remoteDisplay,parameters);
+ encoder.init(context,streamListener,remoteDisplay,parameters);
+ //We are all set so we can start streaming at athis point
+ encoder.start();
} catch (Exception e) {
e.printStackTrace();
}
- //Start streaming
+ }
+ public void stopStreaming(){
+ if(encoder!=null){
+ encoder.shutDown();
+ }
}
public void dispose(){
+ stopStreaming();
internalInterface.removeServiceListener(SessionType.NAV,this);
}
diff --git a/sdl_android/src/main/java/com/smartdevicelink/streaming/video/SdlRemoteDisplay.java b/sdl_android/src/main/java/com/smartdevicelink/streaming/video/SdlRemoteDisplay.java index 8004e8605..7e6ac8188 100644 --- a/sdl_android/src/main/java/com/smartdevicelink/streaming/video/SdlRemoteDisplay.java +++ b/sdl_android/src/main/java/com/smartdevicelink/streaming/video/SdlRemoteDisplay.java @@ -27,7 +27,7 @@ public class SdlRemoteDisplay extends Presentation { protected Window w; protected View mainView; protected Handler handler = new Handler(); - private Handler uiHandler = new Handler(Looper.getMainLooper()); + protected Handler uiHandler = new Handler(Looper.getMainLooper()); public SdlRemoteDisplay(Context context, Display display) { @@ -88,12 +88,13 @@ public class SdlRemoteDisplay extends Presentation { }); } - public class ShowPresentationCallableMethod implements Callable<Boolean> { + public static class ShowPresentationCallableMethod implements Callable<Boolean> { private Context context; private Display mDisplay; boolean presentationShowError = false; SdlRemoteDisplay remoteDisplay; Class<? extends SdlRemoteDisplay> remoteDisplayClass; + protected Handler uiHandler = new Handler(Looper.getMainLooper()); //FIXME public ShowPresentationCallableMethod(Context context, Display display, SdlRemoteDisplay remoteDisplay, Class<? extends SdlRemoteDisplay> remoteDisplayClass){ |