Skip to content

Commit 60794d8

Browse files
committed
Fix so video renderer correctly reports ready in tunneling mode.
In tunneled playback mode the video renderer is potentially 'ready' with output at anytime there are buffers queued to the codec. This fix add the more specific boolean `hasOuputReady()` and uses this in the `isReady()` check. This changes fixes issue #6366 The call to dequeueOutputBuffer() simply returns TRY_AGAIN always in tunneled mode (this comment is correct: #1688 (comment) so the super.hasOutputReady() is always false in tunneling mode, even though the codec may have output ready.
1 parent 151b75d commit 60794d8

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.google.android.exoplayer2.ExoPlaybackException;
3535
import com.google.android.exoplayer2.Format;
3636
import com.google.android.exoplayer2.FormatHolder;
37+
import com.google.android.exoplayer2.Renderer;
3738
import com.google.android.exoplayer2.decoder.CryptoInfo;
3839
import com.google.android.exoplayer2.decoder.DecoderCounters;
3940
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
@@ -1144,6 +1145,19 @@ private boolean hasOutputBuffer() {
11441145
return outputIndex >= 0;
11451146
}
11461147

1148+
/**
1149+
* Check if the renderer has one or more output frames queued to render. For non-tunneled
1150+
* mode MediaCodecRenderer's this is true if the codec has returned a frame ready to render
1151+
* (that is {@see #hasOutputBuffer() is true}.
1152+
*
1153+
* This factors into the ready {@link Renderer#isReady()} decision
1154+
*
1155+
* @return
1156+
*/
1157+
protected boolean hasOutputReady() {
1158+
return hasOutputBuffer();
1159+
}
1160+
11471161
private void resetInputBuffer() {
11481162
inputIndex = C.INDEX_UNSET;
11491163
buffer.data = null;
@@ -1528,7 +1542,7 @@ public boolean isReady() {
15281542
return inputFormat != null
15291543
&& !waitingForKeys
15301544
&& (isSourceReady()
1531-
|| hasOutputBuffer()
1545+
|| hasOutputReady()
15321546
|| (codecHotswapDeadlineMs != C.TIME_UNSET
15331547
&& SystemClock.elapsedRealtime() < codecHotswapDeadlineMs));
15341548
}

library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,18 @@ public boolean isReady() {
400400
}
401401
}
402402

403+
/**
404+
* Override, to handle tunneling. In the tunneled case we must assume there is
405+
* output ready to render whenever we have queued any sample buffers to the codec that
406+
* it has not reported as rendered.
407+
*
408+
* @return
409+
*/
410+
@Override
411+
protected boolean hasOutputReady() {
412+
return tunneling && buffersInCodecCount > 0 || super.hasOutputReady();
413+
}
414+
403415
@Override
404416
protected void onStarted() {
405417
super.onStarted();

0 commit comments

Comments
 (0)