From b5e41a903dd3f1d1ef83a69efce48fb3f8378746 Mon Sep 17 00:00:00 2001 From: olly Date: Mon, 15 Aug 2016 03:18:59 -0700 Subject: [PATCH] Remove buffered position edge case. It's no longer safe to convert END_OF_SOURCE -> duration on the main therad, since the Timeline from which the duration is obtained is posted to the main thread, where-as the buffered position is passed by updating a volatile. Hence an update to the latter might become visible to the main thread before the corresponding Timeline. This change moves the conversion to the playback thread. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=130265893 --- .../com/google/android/exoplayer2/ExoPlayerImpl.java | 8 ++++---- .../android/exoplayer2/ExoPlayerImplInternal.java | 11 ++++------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java b/library/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java index b167597e16..e28ef71a3f 100644 --- a/library/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java +++ b/library/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java @@ -141,7 +141,7 @@ import java.util.concurrent.CopyOnWriteArraySet; @Override public void seekTo(int periodIndex, long positionMs) { - boolean seekToDefaultPosition = positionMs == ExoPlayer.UNKNOWN_TIME; + boolean seekToDefaultPosition = positionMs == UNKNOWN_TIME; maskingPeriodIndex = periodIndex; maskingPositionMs = seekToDefaultPosition ? 0 : positionMs; pendingSeekAcks++; @@ -155,7 +155,7 @@ import java.util.concurrent.CopyOnWriteArraySet; @Override public void seekToDefaultPosition(int periodIndex) { - seekTo(periodIndex, ExoPlayer.UNKNOWN_TIME); + seekTo(periodIndex, UNKNOWN_TIME); } @Override @@ -212,7 +212,7 @@ import java.util.concurrent.CopyOnWriteArraySet; public long getBufferedPosition() { if (pendingSeekAcks == 0) { long bufferedPositionUs = playbackInfo.bufferedPositionUs; - return bufferedPositionUs == C.END_OF_SOURCE_US ? getDuration() : bufferedPositionUs / 1000; + return bufferedPositionUs == C.UNSET_TIME_US ? UNKNOWN_TIME : (bufferedPositionUs / 1000); } else { return maskingPositionMs; } @@ -222,7 +222,7 @@ import java.util.concurrent.CopyOnWriteArraySet; public int getBufferedPercentage() { long bufferedPosition = getBufferedPosition(); long duration = getDuration(); - return bufferedPosition == ExoPlayer.UNKNOWN_TIME || duration == ExoPlayer.UNKNOWN_TIME ? 0 + return bufferedPosition == UNKNOWN_TIME || duration == UNKNOWN_TIME ? 0 : (int) (duration == 0 ? 100 : (bufferedPosition * 100) / duration); } diff --git a/library/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java b/library/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java index 5a9bf0cc11..ffad64152e 100644 --- a/library/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java +++ b/library/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java @@ -409,13 +409,10 @@ import java.io.IOException; elapsedRealtimeUs = SystemClock.elapsedRealtime() * 1000; // Update the buffered position. - long bufferedPositionUs; - if (enabledRenderers.length == 0) { - bufferedPositionUs = C.END_OF_SOURCE_US; - } else { - bufferedPositionUs = mediaPeriod.getBufferedPositionUs(); - } - playbackInfo.bufferedPositionUs = bufferedPositionUs; + long bufferedPositionUs = enabledRenderers.length == 0 ? C.END_OF_SOURCE_US + : mediaPeriod.getBufferedPositionUs(); + playbackInfo.bufferedPositionUs = bufferedPositionUs == C.END_OF_SOURCE_US + ? timeline.getPeriodDurationUs(playingPeriod.index) : bufferedPositionUs; } private void doSomeWork() throws ExoPlaybackException, IOException {