diff options
author | Joey Grover <joeygrover@gmail.com> | 2017-10-09 13:30:12 -0400 |
---|---|---|
committer | Joey Grover <joeygrover@gmail.com> | 2017-10-09 13:30:12 -0400 |
commit | c314d5723b41ca87caebb569757163e51b115e00 (patch) | |
tree | e59dca39318ee610f99d49965be26ad251370f77 | |
parent | de67f861e36718e617aa919e24ff183e9d05ff9d (diff) | |
download | sdl_android-c314d5723b41ca87caebb569757163e51b115e00.tar.gz |
Move the remote display creation into manager
Touch is currently broken with this commit
-rw-r--r-- | sdl_android/src/main/java/com/smartdevicelink/encoder/VirtualDisplayEncoder.java | 41 | ||||
-rw-r--r-- | sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java | 33 |
2 files changed, 38 insertions, 36 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 b1fac6b91..68cd06035 100644 --- a/sdl_android/src/main/java/com/smartdevicelink/encoder/VirtualDisplayEncoder.java +++ b/sdl_android/src/main/java/com/smartdevicelink/encoder/VirtualDisplayEncoder.java @@ -52,8 +52,6 @@ public class VirtualDisplayEncoder { private volatile MediaCodec.BufferInfo mVideoBufferInfo = null; private volatile Surface inputSurface = null; private volatile VirtualDisplay virtualDisplay = null; - private volatile SdlRemoteDisplay presentation = null; - private Class<? extends SdlRemoteDisplay> presentationClass = null; private VideoStreamWriterThread streamWriterThread = null; private Context mContext; private IVideoStreamListener mOutputListener; @@ -73,13 +71,13 @@ public class VirtualDisplayEncoder { * @param streamingParams * @throws Exception */ - public void init(Context context, IVideoStreamListener outputListener, Class<? extends SdlRemoteDisplay> presentationClass, VideoStreamingParameters streamingParams) throws Exception { + public void init(Context context, IVideoStreamListener outputListener, 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 || outputListener == null || presentationClass == null || screenParams == null || streamingParams.getResolution() == null || streamingParams.getFormat() == null) { + if (context == null || outputListener == 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"); } @@ -92,8 +90,6 @@ public class VirtualDisplayEncoder { mOutputListener = outputListener; - this.presentationClass = presentationClass; - setupVideoStreamWriter(); initPassed = true; @@ -136,7 +132,7 @@ public class VirtualDisplayEncoder { startEncoder(); - displayPresentation(); + //displayPresentation(); } catch (Exception ex) { Log.e(TAG, "Unable to create Virtual Display."); throw new RuntimeException(ex); @@ -279,9 +275,9 @@ public class VirtualDisplayEncoder { public void handleTouchEvent(OnTouchEvent touchEvent) { final MotionEvent motionEvent = convertTouchEvent(touchEvent); - if (motionEvent != null && presentation != null) { - presentation.handleMotionEvent(motionEvent); - } + //if (motionEvent != null && presentation != null) { + // presentation.handleMotionEvent(motionEvent); + //} } private MotionEvent convertTouchEvent(OnTouchEvent touchEvent){ @@ -336,34 +332,13 @@ public class VirtualDisplayEncoder { } - - private void displayPresentation() { - + public Display getVirtualDisplay(){ synchronized (START_DISP_LOCK) { - try { - final Display disp = virtualDisplay.getDisplay(); - - if (disp == null){ - return; - } - - // Dismiss the current presentation if the display has changed. - if (presentation != null && presentation.getDisplay() != disp) { - presentation.dismissPresentation(); - } - - FutureTask<Boolean> fTask = new FutureTask<Boolean>( new SdlRemoteDisplay.ShowPresentationCallableMethod(mContext,disp,presentation,presentationClass)); - Thread showPresentation = new Thread(fTask); - - showPresentation.start(); - } catch (Exception ex) { - Log.e(TAG, "Unable to create Virtual Display."); - } + return virtualDisplay.getDisplay(); } } - private void setupVideoStreamWriter() { if (streamWriterThread == null) { // Setup VideoStreamWriterThread thread 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 351c6202e..e363aabd4 100644 --- a/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java +++ b/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java @@ -26,6 +26,7 @@ import org.json.JSONArray; import org.json.JSONException;
import org.json.JSONObject;
+import android.annotation.TargetApi;
import android.app.Service;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
@@ -36,6 +37,7 @@ import android.os.Looper; import android.telephony.TelephonyManager;
import android.util.Log;
import android.util.SparseArray;
+import android.view.Display;
import android.view.Surface;
import com.smartdevicelink.Dispatcher.IDispatchingStrategy;
@@ -6269,10 +6271,12 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> }
}
+ @TargetApi(21)
private class VideoStreamingManager implements ISdlServiceListener{
Context context;
ISdl internalInterface;
volatile VirtualDisplayEncoder encoder;
+ private Class<? extends SdlRemoteDisplay> remoteDisplayClass = null;
SdlRemoteDisplay remoteDisplay;
IVideoStreamListener streamListener;
//Touch manager
@@ -6285,12 +6289,15 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> internalInterface.addServiceListener(SessionType.NAV,this);
}
- public void startVideoStreaming(Class<? extends SdlRemoteDisplay> remoteDisplay, VideoStreamingParameters parameters, boolean encrypted){
+ public void startVideoStreaming(Class<? extends SdlRemoteDisplay> remoteDisplayClass, VideoStreamingParameters parameters, boolean encrypted){
streamListener = startVideoStream(encrypted,parameters);
+ this.remoteDisplayClass = remoteDisplayClass;
try {
- encoder.init(context,streamListener,remoteDisplay,parameters);
- //We are all set so we can start streaming at athis point
+ encoder.init(context,streamListener,remoteDisplayClass,parameters);
+ //We are all set so we can start streaming at at this point
encoder.start();
+ //Encoder should be up and running
+ createDisplay(encoder.getVirtualDisplay());
} catch (Exception e) {
e.printStackTrace();
}
@@ -6307,6 +6314,26 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> internalInterface.removeServiceListener(SessionType.NAV,this);
}
+ private void createDisplay(Display disp){
+ try{
+ if (disp == null){
+ return;
+ }
+
+ // Dismiss the current presentation if the display has changed.
+ if (remoteDisplay != null && remoteDisplay.getDisplay() != disp) {
+ remoteDisplay.dismissPresentation();
+ }
+
+ FutureTask<Boolean> fTask = new FutureTask<Boolean>( new SdlRemoteDisplay.ShowPresentationCallableMethod(context, disp, remoteDisplay, remoteDisplayClass));
+ Thread showPresentation = new Thread(fTask);
+
+ showPresentation.start();
+ } catch (Exception ex) {
+ Log.e(TAG, "Unable to create Virtual Display.");
+ }
+ }
+
@Override
public void onServiceStarted(SdlSession session, SessionType type, boolean isEncrypted) {
|