From 73220be19b95a27f16096b3e907aec86be758038 Mon Sep 17 00:00:00 2001 From: olly Date: Mon, 28 Nov 2016 03:15:20 -0800 Subject: [PATCH] drainOutputBuffer return false on EOS I can't see how this would ever make a difference, but there's no point in returning true. Either we've really reached EOS (in which case outputStreamEnded will be true and the next drainOutputBuffer will be turned into a no-op) or we've re-initialized the codec (in which case there wont be anything to drain since we wont have fed anything to the codec yet). This change should also prevent the hypothetical NPE described in issue #2096, although we're unsure how that NPE would occur unless MediaCodecRenderer has been extended in an unusual way. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=140338581 --- .../android/exoplayer2/mediacodec/MediaCodecRenderer.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java b/library/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java index ca06a006190..440451c1831 100644 --- a/library/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java +++ b/library/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java @@ -479,7 +479,9 @@ public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackEx if (codec != null) { TraceUtil.beginSection("drainAndFeed"); while (drainOutputBuffer(positionUs, elapsedRealtimeUs)) {} - while (feedInputBuffer()) {} + if (codec != null) { + while (feedInputBuffer()) {} + } TraceUtil.endSection(); } else if (format != null) { skipToKeyframeBefore(positionUs); @@ -864,7 +866,7 @@ private boolean drainOutputBuffer(long positionUs, long elapsedRealtimeUs) // The dequeued buffer indicates the end of the stream. Process it immediately. processEndOfStream(); outputIndex = C.INDEX_UNSET; - return true; + return false; } else { // The dequeued buffer is a media buffer. Do some initial setup. The buffer will be // processed by calling processOutputBuffer (possibly multiple times) below. @@ -885,7 +887,6 @@ private boolean drainOutputBuffer(long positionUs, long elapsedRealtimeUs) if (codecNeedsEosPropagationWorkaround && (inputStreamEnded || codecReinitializationState == REINITIALIZATION_STATE_WAIT_END_OF_STREAM)) { processEndOfStream(); - return true; } return false; }