Skip to content

Commit

Permalink
Prevent frozen frames when the decoder is always late.
Browse files Browse the repository at this point in the history
Create a MediaCodecVideoTrackRenderer.shouldDropFrame function that can be overriden by a child class. The YouTube override prevents a frame drop if we haven't rendered anything in the last 35 ms.

The YouTube override is off at the moment, I plan to use a server side flag to do a slow and controlled experiment.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=142190774
  • Loading branch information
anjalibh authored and ojw28 committed Dec 16, 2016
1 parent 65490f5 commit 6c4795b
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ protected boolean processOutputBuffer(long positionUs, long elapsedRealtimeUs, M
bufferPresentationTimeUs, unadjustedFrameReleaseTimeNs);
earlyUs = (adjustedReleaseTimeNs - systemTimeNs) / 1000;

if (earlyUs < -30000) {
if (shouldDropOutputBuffer(earlyUs, elapsedRealtimeUs)) {
// We're more than 30ms late rendering the frame.
dropOutputBuffer(codec, bufferIndex);
return true;
Expand Down Expand Up @@ -437,6 +437,17 @@ protected boolean processOutputBuffer(long positionUs, long elapsedRealtimeUs, M
return false;
}

/**
* Returns true if the current frame should be dropped.
*
* @param earlyUs Time indicating how early the frame is. Negative values indicate late frame.
* @param elapsedRealtimeUs Wall clock time.
*/
protected boolean shouldDropOutputBuffer(long earlyUs, long elapsedRealtimeUs) {
// Drop the frame if we're more than 30ms late rendering the frame.
return earlyUs < -30000;
}

private void skipOutputBuffer(MediaCodec codec, int bufferIndex) {
TraceUtil.beginSection("skipVideoBuffer");
codec.releaseOutputBuffer(bufferIndex, false);
Expand Down

0 comments on commit 6c4795b

Please sign in to comment.