From 4b9c6b149afd55ee20d61300aaaa9131f05d9e05 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 6 Jun 2017 22:48:28 -0700 Subject: [PATCH] Remove the decoder stop hack and try to workaround the issue differently --- app/src/main/java/com/limelight/Game.java | 8 -------- .../binding/video/MediaCodecDecoderRenderer.java | 8 ++++++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/limelight/Game.java b/app/src/main/java/com/limelight/Game.java index 89e0a712..67a4717e 100644 --- a/app/src/main/java/com/limelight/Game.java +++ b/app/src/main/java/com/limelight/Game.java @@ -993,14 +993,6 @@ public class Game extends Activity implements SurfaceHolder.Callback, @Override public void surfaceDestroyed(SurfaceHolder holder) { if (connected) { - // HACK: Android is supposed to let you return from this function - // before throwing a fit if you access the surface again. Unfortunately, - // MediaCodec often tries to access the destroyed surface and triggers - // an IllegalStateException. To workaround this, we will invoke - // the DecoderRenderer's stop function ourselves, so it will hopefully - // happen early enough to not trigger the bug - decoderRenderer.stop(); - stopConnection(); } } diff --git a/app/src/main/java/com/limelight/binding/video/MediaCodecDecoderRenderer.java b/app/src/main/java/com/limelight/binding/video/MediaCodecDecoderRenderer.java index f5a79f03..2f100190 100644 --- a/app/src/main/java/com/limelight/binding/video/MediaCodecDecoderRenderer.java +++ b/app/src/main/java/com/limelight/binding/video/MediaCodecDecoderRenderer.java @@ -416,10 +416,18 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer { // Halt the rendering thread rendererThread.interrupt(); + + // Invalidate pending decode buffers + videoDecoder.flush(); + + // Wait for the renderer thread to shut down try { rendererThread.join(); } catch (InterruptedException ignored) { } + // Stop the video decoder + videoDecoder.stop(); + // Halt the spinner threads for (Thread t : spinnerThreads) { t.interrupt();