summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAustin Kirk <askirk@umich.edu>2017-05-02 15:33:13 -0400
committerAustin Kirk <askirk@umich.edu>2017-05-02 15:33:13 -0400
commit7f204e85663430bfeab1076c74dbfdd817636c22 (patch)
treedb04e61733ecc1639c09718c3a376311dcf52c16
parentef7929077cab597b7158c43a3d53bf127f963eb1 (diff)
downloadsdl_android-7f204e85663430bfeab1076c74dbfdd817636c22.tar.gz
Updated to Address Buffer Concern, Null Checksfeature/issue_469
- Made unneccesaryily static Objects nonstatic - Check for null params in init() - Added BUFFER_LOCK, wait() for buffer to be written, then notify() before setting a new buffer - Remove unnecessary logging - Added isWaiting member in VideoStreamWriterThread to check if we’re waiting to clear the buffer
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/encoder/VirtualDisplayEncoder.java38
1 files changed, 26 insertions, 12 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 f77f16aa9..4b013699f 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/encoder/VirtualDisplayEncoder.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/encoder/VirtualDisplayEncoder.java
@@ -54,9 +54,9 @@ public class VirtualDisplayEncoder {
private Boolean initPassed = false;
private Handler uiHandler = new Handler(Looper.getMainLooper());
private final static int REFRESH_RATE_MS = 100;
- private final static Object CLOSE_VID_SESSION_LOCK = new Object();
- private final static Object START_DISP_LOCK = new Object();
- private final static Object STREAMING_LOCK = new Object();
+ private final Object CLOSE_VID_SESSION_LOCK = new Object();
+ private final Object START_DISP_LOCK = new Object();
+ private final Object STREAMING_LOCK = new Object();
public class StreamingParameters {
protected int displayDensity = DisplayMetrics.DENSITY_HIGH;
@@ -147,6 +147,11 @@ public class VirtualDisplayEncoder {
throw new Exception("API level of 21 required");
}
+ if (context == null || videoStream == null || presentationClass == null || screenParams == null) {
+ Log.e(TAG, "init parameters cannot be null for VirtualDisplayEncoder");
+ throw new Exception("init parameters cannot be null");
+ }
+
mDisplayManager = (DisplayManager)context.getSystemService(Context.DISPLAY_SERVICE);
mContext = context;
@@ -392,11 +397,17 @@ public class VirtualDisplayEncoder {
private void onStreamDataAvailable(byte[] data, int size) {
if (sdlOutStream != null) {
try {
- if (streamWriterThread.getOutputStream() == null) {
- streamWriterThread.setOutputStream(sdlOutStream);
- }
+ 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);
+ streamWriterThread.setByteBuffer(data, size);
+ }
} catch (Exception e) {
e.printStackTrace();
}
@@ -505,13 +516,11 @@ public class VirtualDisplayEncoder {
final Display disp = virtualDisplay.getDisplay();
if (disp == null){
- Log.i(TAG, "Display is null");
return;
}
// Dismiss the current presentation if the display has changed.
if (presentation != null && presentation.getDisplay() != disp) {
- Log.i(TAG, "Dismissing current presentation display.");
dismissPresentation();
}
@@ -519,9 +528,8 @@ public class VirtualDisplayEncoder {
Thread showPresentation = new Thread(fTask);
showPresentation.start();
- Log.i(TAG, "displayPresentation");
} catch (Exception ex) {
- Log.w(TAG, "Unable to create Virtual Display.");
+ Log.e(TAG, "Unable to create Virtual Display.");
}
}
}
@@ -532,7 +540,6 @@ public class VirtualDisplayEncoder {
public void run() {
if (presentation != null) {
presentation.dismiss();
- Log.i(TAG, "Dismiss Presentation.");
presentation = null;
}
}
@@ -569,9 +576,11 @@ public class VirtualDisplayEncoder {
private class VideoStreamWriterThread extends Thread {
private Boolean isHalted = false;
+ private Boolean isWaiting = false;
private byte[] buf = null;
private Integer size = 0;
private OutputStream os = null;
+ protected final Object BUFFER_LOCK = new Object();
public OutputStream getOutputStream() {
return os;
@@ -638,6 +647,11 @@ public class VirtualDisplayEncoder {
public void run() {
while (!isHalted) {
writeToStream();
+ if(isWaiting){
+ synchronized(BUFFER_LOCK){
+ BUFFER_LOCK.notify();
+ }
+ }
}
}