From b1de997388a064d20200806523614f690dfe00b2 Mon Sep 17 00:00:00 2001 From: olly Date: Thu, 21 Apr 2016 08:50:24 -0700 Subject: [PATCH] Remove incorrect AudioTrack timestamp adjustment. This is just wrong. I think there used to be an off-by-one timestamp error in YouTube's fmp4 streams, and this code was initially designed exclusively to play such streams. I don't see this issue any more though, if it was ever there! ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=120447694 --- .../android/exoplayer/audio/AudioTrack.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer/audio/AudioTrack.java b/library/src/main/java/com/google/android/exoplayer/audio/AudioTrack.java index 357d2e4db5..6dd5893d82 100644 --- a/library/src/main/java/com/google/android/exoplayer/audio/AudioTrack.java +++ b/library/src/main/java/com/google/android/exoplayer/audio/AudioTrack.java @@ -579,26 +579,23 @@ public final class AudioTrack { // If this is the first encoded sample, calculate the sample size in frames. framesPerEncodedSample = getFramesPerEncodedSample(encoding, buffer); } - long frames = passthrough ? framesPerEncodedSample : pcmBytesToFrames(size); - long bufferDurationUs = framesToDurationUs(frames); - // Note: presentationTimeUs corresponds to the end of the sample, not the start. - long bufferStartTime = presentationTimeUs - bufferDurationUs; if (startMediaTimeState == START_NOT_SET) { - startMediaTimeUs = Math.max(0, bufferStartTime); + startMediaTimeUs = Math.max(0, presentationTimeUs); startMediaTimeState = START_IN_SYNC; } else { - // Sanity check that bufferStartTime is consistent with the expected value. - long expectedBufferStartTime = startMediaTimeUs + framesToDurationUs(getSubmittedFrames()); + // Sanity check that presentationTimeUs is consistent with the expected value. + long expectedPresentationTimeUs = startMediaTimeUs + + framesToDurationUs(getSubmittedFrames()); if (startMediaTimeState == START_IN_SYNC - && Math.abs(expectedBufferStartTime - bufferStartTime) > 200000) { - Log.e(TAG, "Discontinuity detected [expected " + expectedBufferStartTime + ", got " - + bufferStartTime + "]"); + && Math.abs(expectedPresentationTimeUs - presentationTimeUs) > 200000) { + Log.e(TAG, "Discontinuity detected [expected " + expectedPresentationTimeUs + ", got " + + presentationTimeUs + "]"); startMediaTimeState = START_NEED_SYNC; } if (startMediaTimeState == START_NEED_SYNC) { // Adjust startMediaTimeUs to be consistent with the current buffer's start time and the // number of bytes submitted. - startMediaTimeUs += (bufferStartTime - expectedBufferStartTime); + startMediaTimeUs += (presentationTimeUs - expectedPresentationTimeUs); startMediaTimeState = START_IN_SYNC; result |= RESULT_POSITION_DISCONTINUITY; }