From fb011e66a6ff164c76dc8f17b4df152a1848835b Mon Sep 17 00:00:00 2001 From: olly Date: Tue, 2 Jun 2020 22:48:15 +0100 Subject: [PATCH] AudioTrackPositionTracker: Prevent negative timestamps Issue: #7456 PiperOrigin-RevId: 314408767 --- RELEASENOTES.md | 6 ++++-- .../android/exoplayer2/audio/AudioTrackPositionTracker.java | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index e953578ee2..5c37ac1245 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -11,8 +11,9 @@ * Fix "Not allowed to start service" `IllegalStateException` in `DownloadService` ([#7306](https://github.com/google/ExoPlayer/issues/7306)). -* Ads: - * Fix `AdsMediaSource` child `MediaSource`s not being released. +* Fix issue in `AudioTrackPositionTracker` that could cause negative positions + to be reported at the start of playback and immediately after seeking + ([#7456](https://github.com/google/ExoPlayer/issues/7456). * DASH: * Merge trick play adaptation sets (i.e., adaptation sets marked with `http://dashif.org/guidelines/trickmode`) into the same `TrackGroup` as @@ -58,6 +59,7 @@ ([#5444](https://github.com/google/ExoPlayer/issues/5444), [#5966](https://github.com/google/ExoPlayer/issues/5966), [#7002](https://github.com/google/ExoPlayer/issues/7002)). + * Fix `AdsMediaSource` child `MediaSource`s not being released. * Cronet extension: Default to using the Cronet implementation in Google Play Services rather than Cronet Embedded. This allows Cronet to be used with a negligible increase in application size, compared to approximately 8MB when diff --git a/library/core/src/main/java/com/google/android/exoplayer2/audio/AudioTrackPositionTracker.java b/library/core/src/main/java/com/google/android/exoplayer2/audio/AudioTrackPositionTracker.java index 4ee70bd813..f227a6f3d8 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/audio/AudioTrackPositionTracker.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/audio/AudioTrackPositionTracker.java @@ -206,6 +206,7 @@ import java.lang.reflect.Method; hasData = false; stopTimestampUs = C.TIME_UNSET; forceResetWorkaroundTimeMs = C.TIME_UNSET; + lastLatencySampleTimeUs = 0; latencyUs = 0; } @@ -239,7 +240,7 @@ import java.lang.reflect.Method; positionUs = systemTimeUs + smoothedPlayheadOffsetUs; } if (!sourceEnded) { - positionUs -= latencyUs; + positionUs = Math.max(0, positionUs - latencyUs); } return positionUs; } @@ -353,7 +354,7 @@ import java.lang.reflect.Method; } /** - * Resets the position tracker. Should be called when the audio track previous passed to {@link + * Resets the position tracker. Should be called when the audio track previously passed to {@link * #setAudioTrack(AudioTrack, int, int, int)} is no longer in use. */ public void reset() {