From fe7148dbd4769467b6e6289e2e23f5e43eb0cdcf Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 16 Jun 2017 19:39:15 -0700 Subject: [PATCH] Only throw decoder exceptions if we're still receiving them after 3 seconds --- .../video/MediaCodecDecoderRenderer.java | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) 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 fa17ad41..7c02bd07 100644 --- a/app/src/main/java/com/limelight/binding/video/MediaCodecDecoderRenderer.java +++ b/app/src/main/java/com/limelight/binding/video/MediaCodecDecoderRenderer.java @@ -51,6 +51,10 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer { private boolean needsBaselineSpsHack; private SeqParameterSet savedSps; + private RendererException initialException; + private long initialExceptionTimestamp; + private static final int EXCEPTION_REPORT_DELAY_MS = 3000; + private long lastTimestampUs; private long decoderTimeMs; private long totalTimeMs; @@ -296,11 +300,29 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer { // Only throw if we're not stopping if (!stopping) { - if (buf != null || codecFlags != 0) { - throw new RendererException(this, e, buf, codecFlags); + // + // There seems to be a race condition with decoder/surface teardown causing some + // decoders to to throw IllegalStateExceptions even before 'stopping' is set. + // To workaround this while allowing real exceptions to propagate, we will eat the + // first exception. If we are still receiving exceptions 3 seconds later, we will + // throw the original exception again. + // + if (initialException != null) { + // This isn't the first time we've had an exception processing video + if (System.currentTimeMillis() - initialExceptionTimestamp >= EXCEPTION_REPORT_DELAY_MS) { + // It's been over 3 seconds and we're still getting exceptions. Throw the original now. + throw initialException; + } } else { - throw new RendererException(this, e); + // This is the first exception we've hit + if (buf != null || codecFlags != 0) { + initialException = new RendererException(this, e, buf, codecFlags); + } + else { + initialException = new RendererException(this, e); + } + initialExceptionTimestamp = System.currentTimeMillis(); } } } @@ -901,6 +923,13 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer { str += "Is Exynos 4: "+renderer.isExynos4+"\n"; + str += "/proc/cpuinfo:\n"; + try { + str += MediaCodecHelper.readCpuinfo(); + } catch (Exception e) { + str += e.getMessage(); + } + str += "Full decoder dump:\n"; try { str += MediaCodecHelper.dumpDecoders();