Skip to content

Commit

Permalink
Remove old workaround for timestamp jumps
Browse files Browse the repository at this point in the history
This workaround was added for TS streams that do not adjust their
timestamps to start from zero. Over time, the default audio sink
logic has become more robust towards unexpected timestamps and
we no longer need this workaround to jump forward in time.

The workaround also actively caused issues by adjusting the audio
timestamps backwards if the stream starts with large negative
values. See Issue: androidx/media#291. This caused playback to get stuck due
to another bug in the first-frame rendering logic in the video
renderer that is now fixed.

PiperOrigin-RevId: 553493618
  • Loading branch information
tonihei authored and tianyif committed Aug 7, 2023
1 parent 6f24573 commit 2f5ded8
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ public abstract class DecoderAudioRenderer<
private boolean audioTrackNeedsConfigure;

private long currentPositionUs;
private boolean allowFirstBufferPositionDiscontinuity;
private boolean allowPositionDiscontinuity;
private boolean inputStreamEnded;
private boolean outputStreamEnded;
Expand Down Expand Up @@ -529,7 +528,6 @@ private boolean feedInputBuffer() throws DecoderException, ExoPlaybackException
}
inputBuffer.flip();
inputBuffer.format = inputFormat;
onQueueInputBuffer(inputBuffer);
decoder.queueInputBuffer(inputBuffer);
decoderReceivedBuffers = true;
decoderCounters.queuedInputBufferCount++;
Expand Down Expand Up @@ -612,7 +610,6 @@ protected void onPositionReset(long positionUs, boolean joining) throws ExoPlayb
}

currentPositionUs = positionUs;
allowFirstBufferPositionDiscontinuity = true;
allowPositionDiscontinuity = true;
inputStreamEnded = false;
outputStreamEnded = false;
Expand Down Expand Up @@ -813,18 +810,6 @@ private void onInputFormatChanged(FormatHolder formatHolder) throws ExoPlaybackE
eventDispatcher.inputFormatChanged(inputFormat, evaluation);
}

protected void onQueueInputBuffer(DecoderInputBuffer buffer) {
if (allowFirstBufferPositionDiscontinuity && !buffer.isDecodeOnly()) {
// TODO: Remove this hack once we have a proper fix for [Internal: b/71876314].
// Allow the position to jump if the first presentable input buffer has a timestamp that
// differs significantly from what was expected.
if (Math.abs(buffer.timeUs - currentPositionUs) > 500000) {
currentPositionUs = buffer.timeUs;
}
allowFirstBufferPositionDiscontinuity = false;
}
}

private void updateCurrentPosition() {
long newCurrentPositionUs = audioSink.getCurrentPositionUs(isEnded());
if (newCurrentPositionUs != AudioSink.CURRENT_POSITION_NOT_SET) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import com.google.android.exoplayer2.audio.AudioRendererEventListener.EventDispatcher;
import com.google.android.exoplayer2.audio.AudioSink.InitializationException;
import com.google.android.exoplayer2.audio.AudioSink.WriteException;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.decoder.DecoderReuseEvaluation;
import com.google.android.exoplayer2.decoder.DecoderReuseEvaluation.DecoderDiscardReasons;
import com.google.android.exoplayer2.mediacodec.MediaCodecAdapter;
Expand Down Expand Up @@ -113,7 +112,6 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
@Nullable private Format decryptOnlyCodecFormat;

private long currentPositionUs;
private boolean allowFirstBufferPositionDiscontinuity;
private boolean allowPositionDiscontinuity;
private boolean audioSinkNeedsReset;

Expand Down Expand Up @@ -625,7 +623,6 @@ protected void onPositionReset(long positionUs, boolean joining) throws ExoPlayb
}

currentPositionUs = positionUs;
allowFirstBufferPositionDiscontinuity = true;
allowPositionDiscontinuity = true;
}

Expand Down Expand Up @@ -702,28 +699,6 @@ public PlaybackParameters getPlaybackParameters() {
return audioSink.getPlaybackParameters();
}

@Override
protected void onQueueInputBuffer(DecoderInputBuffer buffer) {
if (allowFirstBufferPositionDiscontinuity && !buffer.isDecodeOnly()) {
// TODO: Remove this hack once we have a proper fix for [Internal: b/71876314].
// Allow the position to jump if the first presentable input buffer has a timestamp that
// differs significantly from what was expected.
if (Math.abs(buffer.timeUs - currentPositionUs) > 500000) {
currentPositionUs = buffer.timeUs;
}
allowFirstBufferPositionDiscontinuity = false;
}
}

@CallSuper
@Override
protected void onProcessedOutputBuffer(long presentationTimeUs) {
super.onProcessedOutputBuffer(presentationTimeUs);
// An output buffer has been successfully processed. If this value is not set to false then
// onQueueInputBuffer on transition from offload to codec-based playback may occur early.
allowFirstBufferPositionDiscontinuity = false;
}

@Override
protected void onProcessedStreamChange() {
super.onProcessedStreamChange();
Expand Down

0 comments on commit 2f5ded8

Please sign in to comment.