From 27e11f1f1a767ebdca75ea54158713a03d465af7 Mon Sep 17 00:00:00 2001 From: olly Date: Wed, 6 Jan 2016 09:01:51 -0800 Subject: [PATCH] Workaround flushing issues on S-3 JB MR2. Targeting to all API level 19 devices using the OMX.SEC.avc.dec decoder is probably the right thing to do. It shouldn't have negative implications if we apply the workaround on devices that don't really need it, except to slow down seeking slightly due to decoder re-allocation. Given we're talking about JB, I think the priority should be to "make sure it works". Issue: #951 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=111514406 --- .../exoplayer/MediaCodecTrackRenderer.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/com/google/android/exoplayer/MediaCodecTrackRenderer.java b/library/src/main/java/com/google/android/exoplayer/MediaCodecTrackRenderer.java index e6c565cb3a..26d4cc11e0 100644 --- a/library/src/main/java/com/google/android/exoplayer/MediaCodecTrackRenderer.java +++ b/library/src/main/java/com/google/android/exoplayer/MediaCodecTrackRenderer.java @@ -208,6 +208,7 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer private DrmInitData drmInitData; private MediaCodec codec; private boolean codecIsAdaptive; + private boolean codecNeedsFlushWorkaround; private boolean codecNeedsEosPropagationWorkaround; private boolean codecNeedsEosFlushWorkaround; private boolean codecReceivedEos; @@ -358,6 +359,7 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer String codecName = decoderInfo.name; codecIsAdaptive = decoderInfo.adaptive; + codecNeedsFlushWorkaround = codecNeedsFlushWorkaround(codecName); codecNeedsEosPropagationWorkaround = codecNeedsEosPropagationWorkaround(codecName); codecNeedsEosFlushWorkaround = codecNeedsEosFlushWorkaround(codecName); try { @@ -436,6 +438,7 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer codecReconfigured = false; codecHasQueuedBuffers = false; codecIsAdaptive = false; + codecNeedsFlushWorkaround = false; codecNeedsEosPropagationWorkaround = false; codecNeedsEosFlushWorkaround = false; codecReceivedEos = false; @@ -521,7 +524,7 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer waitingForFirstSyncFrame = true; waitingForKeys = false; decodeOnlyPresentationTimestamps.clear(); - if (Util.SDK_INT < 18 || (codecNeedsEosFlushWorkaround && codecReceivedEos)) { + if (codecNeedsFlushWorkaround || (codecNeedsEosFlushWorkaround && codecReceivedEos)) { // Workaround framework bugs. See [Internal: b/8347958, b/8578467, b/8543366, b/23361053]. releaseCodec(); maybeInitCodec(); @@ -944,6 +947,20 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer return -1; } + /** + * Returns whether the decoder is known to fail when flushed. + *

+ * If true is returned, the renderer will work around the issue by releasing the decoder and + * instantiating a new one rather than flushing the current instance. + * + * @param name The name of the decoder. + * @return True if the decoder is known to fail when flushed. + */ + private static boolean codecNeedsFlushWorkaround(String name) { + return Util.SDK_INT < 18 + || (Util.SDK_INT == 18 && "OMX.SEC.avc.dec".equals(name)); + } + /** * Returns whether the decoder is known to handle the propagation of the * {@link MediaCodec#BUFFER_FLAG_END_OF_STREAM} flag incorrectly on the host device.