mirror of
https://github.com/samsonjs/media.git
synced 2026-04-01 10:35:48 +00:00
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
This commit is contained in:
parent
6e24372414
commit
b5e41a903d
2 changed files with 8 additions and 11 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue