Commit 5579cc89 by krocard Committed by Oliver Woodman

Propagate end of stream received from `OnFrameRenderedListener`

Previously the renderer EOS (aka last frame rendered), was reported as soon
as the last encoded frame was queued in the codec renderer.
This leaded to EOS reported too early.

PiperOrigin-RevId: 280456277
parent c8e7ecd3
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
### dev-v2 (not yet released) ### ### dev-v2 (not yet released) ###
* Video tunneling: Fix renderer end-of-stream with `OnFrameRenderedListener`
from API 23, tunneled renderer must send a special timestamp on EOS.
Previously the EOS was reported when the input stream reached EOS.
* Require an end time or duration for SubRip (SRT) and SubStation Alpha * Require an end time or duration for SubRip (SRT) and SubStation Alpha
(SSA/ASS) subtitles. This applies to both sidecar files & subtitles (SSA/ASS) subtitles. This applies to both sidecar files & subtitles
[embedded in Matroska streams](https://matroska.org/technical/specs/subtitles/index.html). [embedded in Matroska streams](https://matroska.org/technical/specs/subtitles/index.html).
......
...@@ -373,6 +373,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer { ...@@ -373,6 +373,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
private boolean waitingForFirstSyncSample; private boolean waitingForFirstSyncSample;
private boolean waitingForFirstSampleInFormat; private boolean waitingForFirstSampleInFormat;
private boolean skipMediaCodecStopOnRelease; private boolean skipMediaCodecStopOnRelease;
private boolean pendingOutputEndOfStream;
protected DecoderCounters decoderCounters; protected DecoderCounters decoderCounters;
...@@ -603,6 +604,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer { ...@@ -603,6 +604,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
protected void onPositionReset(long positionUs, boolean joining) throws ExoPlaybackException { protected void onPositionReset(long positionUs, boolean joining) throws ExoPlaybackException {
inputStreamEnded = false; inputStreamEnded = false;
outputStreamEnded = false; outputStreamEnded = false;
pendingOutputEndOfStream = false;
flushOrReinitializeCodec(); flushOrReinitializeCodec();
formatQueue.clear(); formatQueue.clear();
} }
...@@ -686,6 +688,10 @@ public abstract class MediaCodecRenderer extends BaseRenderer { ...@@ -686,6 +688,10 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
@Override @Override
public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException { public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
if (pendingOutputEndOfStream) {
pendingOutputEndOfStream = false;
processEndOfStream();
}
try { try {
if (outputStreamEnded) { if (outputStreamEnded) {
renderToEndOfStream(); renderToEndOfStream();
...@@ -1693,6 +1699,14 @@ public abstract class MediaCodecRenderer extends BaseRenderer { ...@@ -1693,6 +1699,14 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
} }
} }
/**
* Notifies the renderer that output end of stream is pending and should be handled on the next
* render.
*/
protected final void setPendingOutputEndOfStream() {
pendingOutputEndOfStream = true;
}
private void reinitializeCodec() throws ExoPlaybackException { private void reinitializeCodec() throws ExoPlaybackException {
releaseCodec(); releaseCodec();
maybeInitCodec(); maybeInitCodec();
......
...@@ -93,6 +93,9 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -93,6 +93,9 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
*/ */
private static final float INITIAL_FORMAT_MAX_INPUT_SIZE_SCALE_FACTOR = 1.5f; private static final float INITIAL_FORMAT_MAX_INPUT_SIZE_SCALE_FACTOR = 1.5f;
/** Magic frame render timestamp that indicates the EOS in tunneling mode. */
private static final long TUNNELING_EOS_PRESENTATION_TIME_US = Long.MAX_VALUE;
/** A {@link DecoderException} with additional surface information. */ /** A {@link DecoderException} with additional surface information. */
public static final class VideoDecoderException extends DecoderException { public static final class VideoDecoderException extends DecoderException {
...@@ -604,8 +607,8 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -604,8 +607,8 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
@Override @Override
protected boolean getCodecNeedsEosPropagation() { protected boolean getCodecNeedsEosPropagation() {
// In tunneling mode we can't dequeue an end-of-stream buffer, so propagate it in the renderer. // Since API 23, onFrameRenderedListener allows for detection of the renderer EOS.
return tunneling; return tunneling && Util.SDK_INT < 23;
} }
@Override @Override
...@@ -946,6 +949,11 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -946,6 +949,11 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
onProcessedOutputBuffer(presentationTimeUs); onProcessedOutputBuffer(presentationTimeUs);
} }
/** Called when a output EOS was received in tunneling mode. */
private void onProcessedTunneledEndOfStream() {
setPendingOutputEndOfStream();
}
/** /**
* Called when an output buffer is successfully processed. * Called when an output buffer is successfully processed.
* *
...@@ -1754,9 +1762,12 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -1754,9 +1762,12 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
// Stale event. // Stale event.
return; return;
} }
if (presentationTimeUs == TUNNELING_EOS_PRESENTATION_TIME_US) {
onProcessedTunneledEndOfStream();
} else {
onProcessedTunneledBuffer(presentationTimeUs); onProcessedTunneledBuffer(presentationTimeUs);
} }
} }
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment