diff options
author | Joey Grover <joeygrover@gmail.com> | 2017-10-11 13:43:32 -0400 |
---|---|---|
committer | Joey Grover <joeygrover@gmail.com> | 2017-10-11 13:43:32 -0400 |
commit | b572ec80361f24f0c0683ed21e94afc6f177ab15 (patch) | |
tree | 0fd7f6d6a191966c31931031c6bf93dafc9c22c9 | |
parent | cb361499473c21b9d6dee9cfe14ffb6287e422f7 (diff) | |
download | sdl_android-b572ec80361f24f0c0683ed21e94afc6f177ab15.tar.gz |
Code cleanup
4 files changed, 247 insertions, 179 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 58dba5e00..22c515957 100644 --- a/sdl_android/src/main/java/com/smartdevicelink/encoder/VirtualDisplayEncoder.java +++ b/sdl_android/src/main/java/com/smartdevicelink/encoder/VirtualDisplayEncoder.java @@ -1,3 +1,35 @@ +/* + * Copyright (c) 2017 Livio, 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 Livio 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.encoder; import android.annotation.TargetApi; @@ -20,9 +52,8 @@ import com.smartdevicelink.streaming.video.VideoStreamingParameters; import java.nio.ByteBuffer; -import static com.smartdevicelink.proxy.constants.Names.screenParams; - @TargetApi(21) +@SuppressWarnings("NullableProblems") public class VirtualDisplayEncoder { private static final String TAG = "VirtualDisplayEncoder"; private VideoStreamingParameters streamingParams = new VideoStreamingParameters(); @@ -166,7 +197,6 @@ public class VirtualDisplayEncoder { mVideoEncoder = MediaCodec.createEncoderByType(videoMimeType); mVideoEncoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE); Surface surface = mVideoEncoder.createInputSurface(); - mVideoEncoder.setCallback(new MediaCodec.Callback() { @Override public void onInputBufferAvailable(MediaCodec codec, int index) { 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 21f8ce37a..d924f88cd 100644 --- a/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java +++ b/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java @@ -12,7 +12,6 @@ import java.net.HttpURLConnection; import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
-import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Vector;
@@ -35,6 +34,7 @@ import android.os.Handler; import android.os.Looper;
import android.os.SystemClock;
import android.telephony.TelephonyManager;
+import android.util.DisplayMetrics;
import android.util.Log;
import android.util.SparseArray;
import android.view.Display;
@@ -51,7 +51,6 @@ import com.smartdevicelink.exception.SdlException; import com.smartdevicelink.exception.SdlExceptionCause;
import com.smartdevicelink.marshal.JsonRPCMarshaller;
import com.smartdevicelink.protocol.ProtocolMessage;
-import com.smartdevicelink.protocol.enums.ControlFrameTags;
import com.smartdevicelink.protocol.enums.FunctionID;
import com.smartdevicelink.protocol.enums.MessageType;
import com.smartdevicelink.protocol.enums.SessionType;
@@ -93,8 +92,6 @@ import com.smartdevicelink.proxy.rpc.enums.SystemCapabilityType; import com.smartdevicelink.proxy.rpc.enums.TextAlignment;
import com.smartdevicelink.proxy.rpc.enums.TouchType;
import com.smartdevicelink.proxy.rpc.enums.UpdateMode;
-import com.smartdevicelink.proxy.rpc.enums.VideoStreamingCodec;
-import com.smartdevicelink.proxy.rpc.enums.VideoStreamingProtocol;
import com.smartdevicelink.proxy.rpc.listeners.OnPutFileUpdateListener;
import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener;
import com.smartdevicelink.proxy.rpc.listeners.OnRPCResponseListener;
@@ -120,9 +117,6 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> private static final String SDL_LIB_TRACE_KEY = "42baba60-eb57-11df-98cf-0800200c9a66";
private static final int PROX_PROT_VER_ONE = 1;
private static final int RESPONSE_WAIT_TIME = 2000;
-
- private static final VideoStreamingFormat VIDEO_STREAMING_FORMAT_H264_RAW = new VideoStreamingFormat(VideoStreamingCodec.H264,VideoStreamingProtocol.RAW);
- private static final VideoStreamingFormat VIDEO_STREAMING_FORMAT_H264_RTP = new VideoStreamingFormat(VideoStreamingCodec.H264,VideoStreamingProtocol.RTP);
private SdlSession sdlSession = null;
private proxyListenerType _proxyListener = null;
@@ -237,6 +231,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> protected SparseArray<OnRPCResponseListener> rpcResponseListeners = null;
protected SparseArray<CopyOnWriteArrayList<OnRPCNotificationListener>> rpcNotificationListeners = null;
+ protected VideoStreamingManager manager; //Will move to SdlSession once the class becomes public
// Interface broker
private SdlInterfaceBroker _interfaceBroker = null;
@@ -267,21 +262,18 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> @Override
public void addServiceListener(SessionType serviceType, ISdlServiceListener sdlServiceListener) {
- if(sdlSession!=null){
- sdlSession.addServiceListener(serviceType,sdlServiceListener);
- }
+ SdlProxyBase.this.addServiceListener(serviceType,sdlServiceListener);
}
@Override
public void removeServiceListener(SessionType serviceType, ISdlServiceListener sdlServiceListener) {
- if(sdlSession!=null){
- sdlSession.removeServiceListener(serviceType,sdlServiceListener);
- }
+ SdlProxyBase.this.removeServiceListener(serviceType,sdlServiceListener);
}
@Override
public void startVideoService(VideoStreamingParameters parameters, boolean encrypted) {
if(isConnected()){
+ sdlSession.setDesiredVideoParams(parameters);
sdlSession.startService(SessionType.NAV,sdlSession.getSessionId(),encrypted);
}
}
@@ -3687,22 +3679,25 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> return Executors.newSingleThreadScheduledExecutor();
}
+ @SuppressWarnings("unused")
public void startService(SessionType serviceType, boolean isEncrypted){
sdlSession.startService(serviceType, sdlSession.getSessionId(), isEncrypted);
}
+ @SuppressWarnings("unused")
public void endService(SessionType serviceType){
sdlSession.endService(serviceType, sdlSession.getSessionId());
}
- public void setDesiredVideoParams(VideoStreamingParameters params){
- sdlSession.setDesiredVideoParams(params);
- }
/**
+ * @deprecated
*Opens the video service (serviceType 11) and subsequently streams raw H264 video from an InputStream provided by the app
*@return true if service is opened successfully and stream is started, return false otherwise
+ * @see #startRemoteDisplayStream(Context, Class, VideoStreamingParameters, boolean) startRemoteDisplayStream
+ * @see #startVideoStream(boolean, VideoStreamingParameters) startVideoStream
+ * @see #createOpenGLInputSurface(int, int, int, int, int, boolean) createOpenGLInputSurface
*/
@SuppressWarnings("unused")
@Deprecated
@@ -3745,8 +3740,12 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> }
/**
+ * @deprecated
*Opens the video service (serviceType 11) and subsequently provides an OutputStream to the app to use for a raw H264 video stream
- *@return OutputStream if service is opened successfully and stream is started, return null otherwise
+ *@return OutputStream if service is opened successfully and stream is started, return null otherwise
+ * @see #startRemoteDisplayStream(Context, Class, VideoStreamingParameters, boolean) startRemoteDisplayStream
+ * @see #startVideoStream(boolean, VideoStreamingParameters) startVideoStream
+ * @see #createOpenGLInputSurface(int, int, int, int, int, boolean) createOpenGLInputSurface
*/
@SuppressWarnings("unused")
@Deprecated
@@ -3950,7 +3949,6 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> sdlSession.setDesiredVideoParams(parameters);
- //VideoStreamingCodec[] codecs = {parameters.getFormat().getCodec()};
VideoStreamingParameters acceptedParams = tryStartVideoStream(isEncrypted, parameters);
if (acceptedParams != null) {
return sdlSession.startVideoStream();
@@ -3968,7 +3966,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> */
@SuppressWarnings("unused")
public boolean endVideoStream() {
- if (sdlSession == null) return false;
+ if (sdlSession == null){ return false; }
navServiceEndResponseReceived = false;
navServiceEndResponse = false;
@@ -4016,9 +4014,9 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> public Surface createOpenGLInputSurface(int frameRate, int iFrameInterval, int width,
int height, int bitrate, boolean isEncrypted) {
- if (sdlSession == null) return null;
- SdlConnection sdlConn = sdlSession.getSdlConnection();
- if (sdlConn == null) return null;
+ if (sdlSession == null || sdlSession.getSdlConnection() == null){
+ return null;
+ }
VideoStreamingParameters desired = new VideoStreamingParameters();
desired.setFrameRate(frameRate);
@@ -4038,8 +4036,72 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> }
}
+ /**
+ * Starts streaming a remote display to the module if there is a connected session. This method of streaming requires the device to be on API level 21 or higher
+ * @param context a context that can be used to create the remote display
+ * @param remoteDisplay class object of the remote display. This class will be used to create an instance of the remote display and will be projected to the module
+ * @param parameters streaming parameters to be used when streaming. If null is sent in, the default/optimized options will be used.
+ * If you are unsure about what parameters to be used it is best to just send null and let the system determine what
+ * works best for the currently connected module.
+ *
+ * @param encrypted a flag of if the stream should be encrypted. Only set if you have a supplied encryption library that the module can understand.
+ */
+ @TargetApi(21)
+ public void startRemoteDisplayStream(Context context, final Class<? extends SdlRemoteDisplay> remoteDisplay, final VideoStreamingParameters parameters, final boolean encrypted){
+ if(getWiProVersion() >= 5 && !_systemCapabilityManager.isCapabilitySupported(SystemCapabilityType.VIDEO_STREAMING)){
+ Log.e(TAG, "Video streaming not supported on this module");
+ return;
+ }
+ //Create streaming manager
+ if(manager == null){
+ manager = new VideoStreamingManager(context,this._internalInterface);
+ }
+
+ if(parameters == null){
+ if(getWiProVersion() >= 5) {
+ _systemCapabilityManager.getCapability(SystemCapabilityType.VIDEO_STREAMING, new OnSystemCapabilityListener() {
+ @Override
+ public void onCapabilityRetrieved(Object capability) {
+ VideoStreamingParameters params = new VideoStreamingParameters();
+ params.update((VideoStreamingCapability)capability); //Streaming parameters are ready time to stream
+ sdlSession.setDesiredVideoParams(params);
+ manager.startVideoStreaming(remoteDisplay, params, encrypted);
+ }
+
+ @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();
+ DisplayCapabilities dispCap = (DisplayCapabilities)_systemCapabilityManager.getCapability(SystemCapabilityType.DISPLAY);
+ if(dispCap !=null){
+ params.setResolution(dispCap.getScreenParams().getImageResolution());
+ }
+ sdlSession.setDesiredVideoParams(params);
+ manager.startVideoStreaming(remoteDisplay,params, encrypted);
+ }
+ }else{
+ sdlSession.setDesiredVideoParams(parameters);
+ manager.startVideoStreaming(remoteDisplay,parameters, encrypted);
+ }
+ }
+
+ /**
+ * Stops the remote display stream if one has been started
+ */
+ public void stopRemoteDisplayStream(){
+ if(manager!=null){
+ manager.dispose();
+ }
+ manager = null;
+ }
+
/**
- * Try to open a video service by trying all available codec/protocols one by one.
+ * Try to open a video service by using the video streaming parameters supplied.
*
* Only information from codecs, width and height are used during video format negotiation.
*
@@ -4049,8 +4111,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> * @return If the service is opened successfully, an instance of VideoStreamingParams is
* returned which contains accepted video format. If the service is opened with legacy
* mode (i.e. without any negotiation) then an instance of VideoStreamingParams is
- * returned, but its video format and resolution are null.
- * If the service was not opened then null is returned.
+ * returned. If the service was not opened then null is returned.
*/
@SuppressWarnings("unused")
private VideoStreamingParameters tryStartVideoStream(boolean isEncrypted, VideoStreamingParameters parameters) {
@@ -4079,91 +4140,30 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> ScheduledExecutorService scheduler = createScheduler();
scheduler.execute(fTask);
- //noinspection StatementWithEmptyBody
- while (!navServiceStartResponseReceived && !fTask.isDone());
- scheduler.shutdown();
-
- if (navServiceStartResponse) {
- return sdlSession.getAcceptedVideoParams();
- }
-
- if (navServiceStartRejectedParams != null) {
- StringBuilder builder = new StringBuilder();
- for (String paramName : navServiceStartRejectedParams) {
- if (builder.length() > 0) {
- builder.append(", ");
- }
- builder.append(paramName);
- }
- DebugTool.logWarning("StartService for nav failed. Rejected params: " + builder.toString());
+ //noinspection StatementWithEmptyBody
+ while (!navServiceStartResponseReceived && !fTask.isDone());
+ scheduler.shutdown();
- if (!navServiceStartRejectedParams.contains(ControlFrameTags.Video.StartService.VIDEO_PROTOCOL)
- && !navServiceStartRejectedParams.contains(ControlFrameTags.Video.StartService.VIDEO_CODEC)) {
- // The reason of NACK is not protocol nor codec. There is no point retrying with
- // another video format, so we simply fail here.
- }
- } else {
- DebugTool.logWarning("StartService for nav failed (rejected params not supplied)");
- }
+ if (navServiceStartResponse) {
+ return sdlSession.getAcceptedVideoParams();
+ }
- return null;
- }
+ if (navServiceStartRejectedParams != null) {
+ StringBuilder builder = new StringBuilder();
+ for (String paramName : navServiceStartRejectedParams) {
+ if (builder.length() > 0) {
+ builder.append(", ");
+ }
+ builder.append(paramName);
+ }
- /**
- * Creates a list of VideoStreamingParams with video formats that are supported by both HMI and proxy
- *
- * Note: this method does not take care of matching video resolution. App should look into
- * HMI capability's preferredResolution and adjust width and height accordingly.
- *
- * @param hmiCapability HMI's capability information
- * @param frameRate specified rate of frames
- * @param frameInterval specified interval
- * @param width specified width of the video
- * @param height specified height of the video
- * @param bitrate specified bitrate of the video
- * @param availableFormats list of video formats supported by proxy
- * @return list of VideoStreamingParams instance. This list can be empty.
- */
- private static List<VideoStreamingParameters> createDesiredVideoParams(
- VideoStreamingCapability hmiCapability,
- int frameRate, int frameInterval, int width, int height, int bitrate,
- VideoStreamingFormat[] availableFormats) {
- ArrayList<VideoStreamingFormat> formats = new ArrayList<>();
- if (hmiCapability != null && hmiCapability.getSupportedFormats() != null
- && availableFormats != null) {
- // supportedFormat is listed in HMI's preferred order
- for (VideoStreamingFormat supportedFormat : hmiCapability.getSupportedFormats()) {
- for (VideoStreamingFormat availableFormat : availableFormats) {
- if (supportedFormat.getProtocol() == availableFormat.getProtocol()
- && supportedFormat.getCodec() == availableFormat.getCodec()) {
- formats.add(supportedFormat);
- break;
- }
- }
- }
- }
+ DebugTool.logWarning("StartService for nav failed. Rejected params: " + builder.toString());
- ArrayList<VideoStreamingParameters> list = new ArrayList<>();
- for (VideoStreamingFormat format : formats) {
- VideoStreamingParameters params = new VideoStreamingParameters();
- ImageResolution resolution = new ImageResolution();
- resolution.setResolutionWidth(width);
- resolution.setResolutionHeight(height);
- params.setResolution(resolution);
- if (frameRate >= 0) {
- params.setFrameRate(frameRate);
- }
- if (bitrate >= 0) {
- params.setBitrate(bitrate);
- }
- if (frameInterval >= 0) {
- params.setInterval(frameInterval);
- }
- params.setFormat(format);
- list.add(params);
- }
+ } else {
+ DebugTool.logWarning("StartService for nav failed (rejected params not supplied)");
+ }
- return list;
+ return null;
}
/**
@@ -6166,6 +6166,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> }
}
+ @SuppressWarnings("unused")
public VideoStreamingParameters getAcceptedVideoParams(){
return sdlSession.getAcceptedVideoParams();
}
@@ -6224,59 +6225,14 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> return sPoliciesURL;
}
- VideoStreamingManager manager;
-
- public void startRemoteDisplayStream(Context context, final Class<? extends SdlRemoteDisplay> remoteDisplay, final VideoStreamingParameters parameters, final boolean encrypted){
- if(getWiProVersion() >= 5 && !_systemCapabilityManager.isCapabilitySupported(SystemCapabilityType.VIDEO_STREAMING)){
- Log.e(TAG, "Video streaming not supported on this module");
- return;
- }
- //Create streaming manager
- if(manager == null){
- manager = new VideoStreamingManager(context,this._internalInterface);
- }
-
- if(parameters == null){
- if(getWiProVersion() >= 5) {
- _systemCapabilityManager.getCapability(SystemCapabilityType.VIDEO_STREAMING, new OnSystemCapabilityListener() {
- @Override
- public void onCapabilityRetrieved(Object capability) {
- VideoStreamingParameters params = new VideoStreamingParameters();
- params.update((VideoStreamingCapability)capability); //Streaming parameters are ready time to stream
- sdlSession.setDesiredVideoParams(params);
- manager.startVideoStreaming(remoteDisplay, params, encrypted);
- }
-
- @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();
- DisplayCapabilities dispCap = (DisplayCapabilities)_systemCapabilityManager.getCapability(SystemCapabilityType.DISPLAY);
- if(dispCap !=null){
- params.setResolution(dispCap.getScreenParams().getImageResolution());
- }
- sdlSession.setDesiredVideoParams(params);
- manager.startVideoStreaming(remoteDisplay,params, encrypted);
- }
- }else{
- sdlSession.setDesiredVideoParams(parameters);
- manager.startVideoStreaming(remoteDisplay,parameters, encrypted);
- }
- }
-
- public void stopRemoteDisplayStream(){
- if(manager!=null){
- manager.stopStreaming();
- }
- }
+ /**
+ * VideoStreamingManager houses all the elements needed to create a scoped, streaming manager for video projection. It is only a private, instance
+ * dependant class at the moment until it can become public. Once the class is public and API defined, it will be moved into the SdlSession class
+ */
@TargetApi(21)
- private class VideoStreamingManager implements ISdlServiceListener{ //THis should move out of the SdlProxyBase and into the SdlSession once we are able to make it public
+ private class VideoStreamingManager implements ISdlServiceListener{
Context context;
ISdl internalInterface;
volatile VirtualDisplayEncoder encoder;
@@ -6284,8 +6240,6 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> SdlRemoteDisplay remoteDisplay;
IVideoStreamListener streamListener;
float[] touchScalar = {1.0f,1.0f}; //x, y
- //Touch manager
- //Haptic manager
public VideoStreamingManager(Context context,ISdl iSdl){
this.context = context;
@@ -6318,7 +6272,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> //We are all set so we can start streaming at at this point
encoder.start();
//Encoder should be up and running
- createDisplay(encoder.getVirtualDisplay());
+ createRemoteDisplay(encoder.getVirtualDisplay());
} catch (Exception e) {
e.printStackTrace();
}
@@ -6338,7 +6292,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> internalInterface.removeServiceListener(SessionType.NAV,this);
}
- private void createDisplay(final Display disp){
+ private void createRemoteDisplay(final Display disp){
try{
if (disp == null){
return;
@@ -6398,6 +6352,9 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> @Override
public void onServiceEnded(SdlSession session, SessionType type) {
+ if(SessionType.NAV.equals(type)){
+ dispose();
+ }
}
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 d354f461f..8af6b1c59 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 @@ -1,3 +1,35 @@ +/* + * Copyright (c) 2017 Livio, 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 Livio 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 android.annotation.TargetApi; @@ -17,10 +49,14 @@ import java.lang.reflect.Constructor; import java.util.concurrent.Callable; /** - * Created by Joey Grover on 10/4/17. + * SdlRemoteDisplay is an abstract class that should be extended by developers to creat their remote displays. + * All logic for UI events can be stored in their extension. + * + * <br><br> <b>NOTE:</b> When the UI changes (buttons appear, layouts change, etc) the developer should call {@link #invalidate()} to alert any + * other interfaces that are listening for those types of events. */ -@TargetApi(21) -public class SdlRemoteDisplay extends Presentation { +@TargetApi(17) +public abstract class SdlRemoteDisplay extends Presentation { private static final String TAG = "SdlRemoteDisplay"; private static final int REFRESH_RATE_MS = 50; @@ -38,7 +74,7 @@ public class SdlRemoteDisplay extends Presentation { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setTitle("Presentation"); + setTitle(TAG); w = getWindow(); @@ -57,7 +93,9 @@ public class SdlRemoteDisplay extends Presentation { protected Runnable mStartRefreshTaskCallback = new Runnable() { public void run() { - mainView = w.getDecorView().findViewById(android.R.id.content); + if(mainView == null){ + mainView = w.getDecorView().findViewById(android.R.id.content); + } if (mainView != null) { mainView.invalidate(); } @@ -66,12 +104,23 @@ public class SdlRemoteDisplay extends Presentation { } }; + @SuppressWarnings("unused") public View getMainView(){ + if(mainView == null){ + mainView = w.getDecorView().findViewById(android.R.id.content); + } return this.mainView; } + @SuppressWarnings("unused") + public void invalidate(){ + // let listeners know the view has been invalidated + if(callback != null){ + callback.onInvalidated(this); + } + } + public void handleMotionEvent(final MotionEvent motionEvent){ - Log.d(TAG, "Received motion event to process"); uiHandler.post(new Runnable() { @Override public void run() { @@ -93,6 +142,10 @@ public class SdlRemoteDisplay extends Presentation { } }); } + public interface Callback{ + void onCreated(SdlRemoteDisplay remoteDisplay); + void onInvalidated(SdlRemoteDisplay remoteDisplay); + } public static class Creator implements Callable<Boolean> { private Context context; @@ -100,7 +153,7 @@ public class SdlRemoteDisplay extends Presentation { boolean presentationShowError = false; SdlRemoteDisplay remoteDisplay; Class<? extends SdlRemoteDisplay> remoteDisplayClass; - protected Handler uiHandler = new Handler(Looper.getMainLooper()); //FIXME + private Handler uiHandler = new Handler(Looper.getMainLooper()); private Callback callback; @@ -111,9 +164,7 @@ public class SdlRemoteDisplay extends Presentation { this.remoteDisplayClass = remoteDisplayClass; this.callback = callback; } - public SdlRemoteDisplay getRemoteDisplay(){ - return remoteDisplay; - } + @Override public Boolean call() { @@ -124,9 +175,8 @@ public class SdlRemoteDisplay extends Presentation { // when setting up the Dialog. if ((remoteDisplay == null) && (mDisplay != null)) { - Constructor constructor = null; try { - constructor = remoteDisplayClass.getConstructor(Context.class, Display.class); + Constructor constructor = remoteDisplayClass.getConstructor(Context.class, Display.class); remoteDisplay = (SdlRemoteDisplay) constructor.newInstance(context, mDisplay); } catch (Exception e) { e.printStackTrace(); @@ -137,6 +187,7 @@ public class SdlRemoteDisplay extends Presentation { try { remoteDisplay.show(); + remoteDisplay.callback = callback; if(callback!=null){ callback.onCreated(remoteDisplay); } @@ -145,7 +196,6 @@ public class SdlRemoteDisplay extends Presentation { Log.e(TAG, "Couldn't show presentation! Display was removed in the meantime.", ex); remoteDisplay = null; presentationShowError = true; - return; } } } @@ -154,8 +204,5 @@ public class SdlRemoteDisplay extends Presentation { return presentationShowError; } - public interface Callback{ - void onCreated(SdlRemoteDisplay remoteDisplay); - } } } diff --git a/sdl_android/src/main/java/com/smartdevicelink/streaming/video/VideoStreamingParameters.java b/sdl_android/src/main/java/com/smartdevicelink/streaming/video/VideoStreamingParameters.java index a370421d0..b7e2b5566 100644 --- a/sdl_android/src/main/java/com/smartdevicelink/streaming/video/VideoStreamingParameters.java +++ b/sdl_android/src/main/java/com/smartdevicelink/streaming/video/VideoStreamingParameters.java @@ -1,6 +1,37 @@ +/* + * Copyright (c) 2017 Livio, 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 Livio 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 android.content.Intent; import android.util.DisplayMetrics; import com.smartdevicelink.proxy.rpc.ImageResolution; @@ -11,6 +42,7 @@ import com.smartdevicelink.proxy.rpc.enums.VideoStreamingProtocol; import java.util.List; +@SuppressWarnings("FieldCanBeLocal") public class VideoStreamingParameters { private final VideoStreamingProtocol DEFAULT_PROTOCOL = VideoStreamingProtocol.RAW; private final VideoStreamingCodec DEFAULT_CODEC = VideoStreamingCodec.H264; @@ -56,6 +88,7 @@ public class VideoStreamingParameters { * Will only copy values that are not null or are greater than 0 * @param params VideoStreamingParameters that should be copied into this new instants */ + @SuppressWarnings("unused") public VideoStreamingParameters(VideoStreamingParameters params){ update(params); } @@ -97,6 +130,7 @@ public class VideoStreamingParameters { } + @SuppressWarnings("unused") public void setDisplayDensity(int displayDensity) { this.displayDensity = displayDensity; } |