Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.FormatHolder;
import com.google.android.exoplayer2.Renderer;
import com.google.android.exoplayer2.decoder.CryptoInfo;
import com.google.android.exoplayer2.decoder.DecoderCounters;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
Expand Down Expand Up @@ -1144,6 +1145,19 @@ private boolean hasOutputBuffer() {
return outputIndex >= 0;
}

/**
* Check if the renderer has one or more output frames queued to render. For non-tunneled
* mode MediaCodecRenderer's this is true if the codec has returned a frame ready to render
* (that is {@see #hasOutputBuffer() is true}.
*
* This factors into the ready {@link Renderer#isReady()} decision
*
* @return
*/
protected boolean hasOutputReady() {
return hasOutputBuffer();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the crux of the fix, the comments should spell out the intentions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can review and debate a good name...

private void resetInputBuffer() {
inputIndex = C.INDEX_UNSET;
buffer.data = null;
Expand Down Expand Up @@ -1528,7 +1542,7 @@ public boolean isReady() {
return inputFormat != null
&& !waitingForKeys
&& (isSourceReady()
|| hasOutputBuffer()
|| hasOutputReady()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More descriptive of what the check really is.

|| (codecHotswapDeadlineMs != C.TIME_UNSET
&& SystemClock.elapsedRealtime() < codecHotswapDeadlineMs));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
/* package */ @Nullable OnFrameRenderedListenerV23 tunnelingOnFrameRenderedListener;
@Nullable private VideoFrameMetadataListener frameMetadataListener;

private long lastInputTimeUs;
private long lastOutputTimeUs;
/**
* @param context A context.
* @param mediaCodecSelector A decoder selector.
Expand Down Expand Up @@ -231,6 +233,8 @@ public MediaCodecVideoRenderer(
frameReleaseTimeHelper = new VideoFrameReleaseTimeHelper(this.context);
eventDispatcher = new EventDispatcher(eventHandler, eventListener);
deviceNeedsNoPostProcessWorkaround = deviceNeedsNoPostProcessWorkaround();
lastInputTimeUs = C.TIME_UNSET;
lastOutputTimeUs = C.TIME_UNSET;
joiningDeadlineMs = C.TIME_UNSET;
currentWidth = Format.NO_VALUE;
currentHeight = Format.NO_VALUE;
Expand Down Expand Up @@ -370,6 +374,8 @@ protected void onPositionReset(long positionUs, boolean joining) throws ExoPlayb
clearRenderedFirstFrame();
initialPositionUs = C.TIME_UNSET;
consecutiveDroppedFrameCount = 0;
lastInputTimeUs = C.TIME_UNSET;
lastOutputTimeUs = C.TIME_UNSET;
if (joining) {
setJoiningDeadlineMs();
} else {
Expand Down Expand Up @@ -400,6 +406,26 @@ public boolean isReady() {
}
}

/**
* Override, to handle tunneling. In the tunneled case we must assume there is
* output ready to render whenever we have queued any sample buffers to the codec that
* it has not reported as rendered.
*
* @return
*/
@Override
protected boolean hasOutputReady() {
boolean fifoReady = true;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are trying to use FIFO length as renderer readiness criteria. If the frame rate is low such as 1fps on music channels the length would still be satisfactory and player wouldn't go into buffering state as long as there is a frame queued in the FIFO. If network bandwidth is low the FIFO length will get close to zero before decoder starts stalling. It's important to note that Broadcom's decoder will stall before rendering last few frames so zero FIFO length cannot be used as a criteria. The 333ms value is somewhat experimental. It was chosen to accommodate at least 10 frames of 30fps stream.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrewlewis @ojw28 Where are you guys at with addressing this issue. I'm preparing to update our code base to what will likely by your 2.11.5 release. We would very much like to not keep merging conflicted changes to the MediaCodecVideoRenderer, for obvious reasons.

Pretty sure we can send you an STB (Broadcom based) that reproduces the issue #6366 I think I included the URL for a section of music choice content that reproduces the issue 100% of the time

We are also see this, as Dasha explained, in other streams where audio is buffered sufficiently ahead of video. As I'm sure you guys are aware, Broadcom codecs often require some special spoon feeding.

Thanks again for looking at this with us, please tell me what I need to do to help the process along.

if (lastOutputTimeUs != C.TIME_UNSET) {
long fifoLengthUs = lastInputTimeUs - lastOutputTimeUs;

// make sure there is at least 1/3s of video available in decoder FIFO,
// otherwise decoder may start stalling
fifoReady = fifoLengthUs > 333333;
}
return tunneling && fifoReady || super.hasOutputReady();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the comment says, in tunneling mode once we have queued buffers to the video codec to decode it will render it when the matching audio syncs up.

The bug occurs because the audio track is stopped before the audio matching the video PTS is queued thus stalling the video codec forever.

@Override
protected void onStarted() {
super.onStarted();
Expand Down Expand Up @@ -846,6 +872,7 @@ private void notifyFrameMetadataListener(

/** Called when a buffer was processed in tunneling mode. */
protected void onProcessedTunneledBuffer(long presentationTimeUs) {
lastOutputTimeUs = presentationTimeUs;
@Nullable Format format = updateOutputFormatForTime(presentationTimeUs);
if (format != null) {
processOutputFormat(getCodec(), format.width, format.height);
Expand Down