Commit b5e41a90 by olly Committed by Oliver Woodman

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
parent 6e243724
...@@ -141,7 +141,7 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -141,7 +141,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
@Override @Override
public void seekTo(int periodIndex, long positionMs) { public void seekTo(int periodIndex, long positionMs) {
boolean seekToDefaultPosition = positionMs == ExoPlayer.UNKNOWN_TIME; boolean seekToDefaultPosition = positionMs == UNKNOWN_TIME;
maskingPeriodIndex = periodIndex; maskingPeriodIndex = periodIndex;
maskingPositionMs = seekToDefaultPosition ? 0 : positionMs; maskingPositionMs = seekToDefaultPosition ? 0 : positionMs;
pendingSeekAcks++; pendingSeekAcks++;
...@@ -155,7 +155,7 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -155,7 +155,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
@Override @Override
public void seekToDefaultPosition(int periodIndex) { public void seekToDefaultPosition(int periodIndex) {
seekTo(periodIndex, ExoPlayer.UNKNOWN_TIME); seekTo(periodIndex, UNKNOWN_TIME);
} }
@Override @Override
...@@ -212,7 +212,7 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -212,7 +212,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
public long getBufferedPosition() { public long getBufferedPosition() {
if (pendingSeekAcks == 0) { if (pendingSeekAcks == 0) {
long bufferedPositionUs = playbackInfo.bufferedPositionUs; 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 { } else {
return maskingPositionMs; return maskingPositionMs;
} }
...@@ -222,7 +222,7 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -222,7 +222,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
public int getBufferedPercentage() { public int getBufferedPercentage() {
long bufferedPosition = getBufferedPosition(); long bufferedPosition = getBufferedPosition();
long duration = getDuration(); 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); : (int) (duration == 0 ? 100 : (bufferedPosition * 100) / duration);
} }
......
...@@ -409,13 +409,10 @@ import java.io.IOException; ...@@ -409,13 +409,10 @@ import java.io.IOException;
elapsedRealtimeUs = SystemClock.elapsedRealtime() * 1000; elapsedRealtimeUs = SystemClock.elapsedRealtime() * 1000;
// Update the buffered position. // Update the buffered position.
long bufferedPositionUs; long bufferedPositionUs = enabledRenderers.length == 0 ? C.END_OF_SOURCE_US
if (enabledRenderers.length == 0) { : mediaPeriod.getBufferedPositionUs();
bufferedPositionUs = C.END_OF_SOURCE_US; playbackInfo.bufferedPositionUs = bufferedPositionUs == C.END_OF_SOURCE_US
} else { ? timeline.getPeriodDurationUs(playingPeriod.index) : bufferedPositionUs;
bufferedPositionUs = mediaPeriod.getBufferedPositionUs();
}
playbackInfo.bufferedPositionUs = bufferedPositionUs;
} }
private void doSomeWork() throws ExoPlaybackException, IOException { private void doSomeWork() throws ExoPlaybackException, IOException {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment