diff options
| author | Roberto Perez <robertoalexis@google.com> | 2020-06-23 14:47:28 -0700 |
|---|---|---|
| committer | Roberto Perez <robertoalexis@google.com> | 2020-06-24 23:05:17 +0000 |
| commit | 91e0357069492ef1942de42b315d23ddb5e83a50 (patch) | |
| tree | 05af85421528837d50f47be00a4101d543ad3cfe | |
| parent | 71830ca5bdf01aad461c9778f3c80bf9e1c1a5d1 (diff) | |
| download | platform_packages_apps_Car_Cluster-91e0357069492ef1942de42b315d23ddb5e83a50.tar.gz platform_packages_apps_Car_Cluster-91e0357069492ef1942de42b315d23ddb5e83a50.tar.bz2 platform_packages_apps_Car_Cluster-91e0357069492ef1942de42b315d23ddb5e83a50.zip | |
DO NOT MERGE: Prevent cluster service crash if video codec initialization fails
Bug: 158657049
Test: lunch gcar_hl_emu_x86 && make && emulator
Change-Id: I711491ed80df4b6045a13fac037157ee538f2479
| -rw-r--r-- | src/android/car/cluster/NetworkedVirtualDisplay.java | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/android/car/cluster/NetworkedVirtualDisplay.java b/src/android/car/cluster/NetworkedVirtualDisplay.java index 56121d0..8f7c65e 100644 --- a/src/android/car/cluster/NetworkedVirtualDisplay.java +++ b/src/android/car/cluster/NetworkedVirtualDisplay.java @@ -164,19 +164,27 @@ public class NetworkedVirtualDisplay { Log.i(TAG, "onVirtualDisplayReady, display: " + display); } - private void startCasting(Handler handler) { + private boolean setupCasting(Handler handler) { Log.i(TAG, "Start casting..."); if (mVideoEncoder != null) { Log.i(TAG, "Already started casting"); - return; + return true; } mVideoEncoder = createVideoStream(handler); + if (mVideoEncoder == null) { + return false; + } + if (mVirtualDisplay == null) { mVirtualDisplay = createVirtualDisplay(); } mVirtualDisplay.setSurface(mVideoEncoder.createInputSurface()); + return true; + } + + private void startCasting() { mVideoEncoder.start(); Log.i(TAG, "Video encoder started"); } @@ -207,8 +215,8 @@ public class NetworkedVirtualDisplay { public void onError(@NonNull MediaCodec codec, @NonNull CodecException e) { Log.e(TAG, "onError, codec: " + codec, e); mCounter.bufferErrors++; - stopCasting(); - startCasting(handler); + mHandler.sendMessage(Message.obtain(mHandler, MSG_STOP)); + mHandler.sendMessage(Message.obtain(mHandler, MSG_START)); } @Override @@ -286,6 +294,7 @@ public class NetworkedVirtualDisplay { private class BroadcastThreadHandler extends Handler { private static final int MAX_FAIL_COUNT = 10; + private static final int RETRY_DELAY = 500; private int mFailConnectCounter; BroadcastThreadHandler(Looper looper) { @@ -311,7 +320,7 @@ public class NetworkedVirtualDisplay { if (mActiveThread == null) { mActiveThread = tryNetworkConnect(); } - if (mActiveThread == null) { + if (mActiveThread == null || !setupCasting(this)) { // When failed attempt limit is reached, clean up and quit this thread. mFailConnectCounter++; if (mFailConnectCounter >= MAX_FAIL_COUNT) { @@ -319,7 +328,8 @@ public class NetworkedVirtualDisplay { release(); throw new RuntimeException("Abort after failed connection attempts"); } - mHandler.sendMessage(Message.obtain(mHandler, MSG_START)); + mHandler.sendMessageDelayed(Message.obtain(mHandler, MSG_START), + RETRY_DELAY); break; } @@ -327,10 +337,9 @@ public class NetworkedVirtualDisplay { mFailConnectCounter = 0; mCounter.clientsConnected++; mActiveThread.start(); - startCasting(this); + startCasting(); } catch (Exception e) { - Log.e(TAG, "Failed to start thread", e); - Log.e(TAG, "DebugCounter: " + mCounter); + Log.e(TAG, "Failed to start thread (counter: " + mCounter + ")", e); } break; |
