Commit 95f41134 by andrewlewis Committed by Oliver Woodman

Fix seeking into a different period that has been prepared.

When seekToPeriodPosition found that the seek destination period was already
prepared, it would not disable/re-enable renderers. This was fine if the
playing period wasn't changing, but in other cases the renderers would be left
reading the incorrect streams (and the underlying periods may have been
released).

Also, transition to the buffering state before re-enabling renderers, so that
the renderers are not started until leaving the buffering state.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=129625632
parent 57832724
...@@ -533,6 +533,23 @@ import java.util.ArrayList; ...@@ -533,6 +533,23 @@ import java.util.ArrayList;
} }
private void seekToPeriodPosition(int periodIndex, long positionUs) throws ExoPlaybackException { private void seekToPeriodPosition(int periodIndex, long positionUs) throws ExoPlaybackException {
if (periodIndex != playbackInfo.periodIndex) {
playbackInfo = new PlaybackInfo(periodIndex);
playbackInfo.startPositionUs = positionUs;
playbackInfo.positionUs = positionUs;
eventHandler.obtainMessage(MSG_POSITION_DISCONTINUITY, playbackInfo).sendToTarget();
} else {
playbackInfo.startPositionUs = positionUs;
playbackInfo.positionUs = positionUs;
}
if (mediaSource == null) {
if (positionUs != C.UNSET_TIME_US) {
resetInternalPosition(positionUs);
}
return;
}
stopRenderers(); stopRenderers();
rebuffering = false; rebuffering = false;
...@@ -553,6 +570,16 @@ import java.util.ArrayList; ...@@ -553,6 +570,16 @@ import java.util.ArrayList;
period = period.nextPeriod; period = period.nextPeriod;
} }
// Disable all the renderers if the period is changing.
if (newPlayingPeriod != playingPeriod) {
for (Renderer renderer : enabledRenderers) {
renderer.disable();
}
enabledRenderers = new Renderer[0];
rendererMediaClock = null;
rendererMediaClockSource = null;
}
// Update loaded periods. // Update loaded periods.
bufferAheadPeriodCount = 0; bufferAheadPeriodCount = 0;
if (newPlayingPeriod != null) { if (newPlayingPeriod != null) {
...@@ -563,16 +590,12 @@ import java.util.ArrayList; ...@@ -563,16 +590,12 @@ import java.util.ArrayList;
loadingPeriod = playingPeriod; loadingPeriod = playingPeriod;
if (playingPeriod.hasEnabledTracks) { if (playingPeriod.hasEnabledTracks) {
positionUs = playingPeriod.mediaPeriod.seekToUs(positionUs); positionUs = playingPeriod.mediaPeriod.seekToUs(positionUs);
playbackInfo.startPositionUs = positionUs;
playbackInfo.positionUs = positionUs;
} }
resetInternalPosition(positionUs); resetInternalPosition(positionUs);
maybeContinueLoading(); maybeContinueLoading();
} else { } else {
for (Renderer renderer : enabledRenderers) {
renderer.disable();
}
enabledRenderers = new Renderer[0];
rendererMediaClock = null;
rendererMediaClockSource = null;
playingPeriod = null; playingPeriod = null;
readingPeriod = null; readingPeriod = null;
loadingPeriod = null; loadingPeriod = null;
...@@ -580,24 +603,10 @@ import java.util.ArrayList; ...@@ -580,24 +603,10 @@ import java.util.ArrayList;
resetInternalPosition(positionUs); resetInternalPosition(positionUs);
} }
} }
// Update the expose playback information.
if (periodIndex != playbackInfo.periodIndex) {
playbackInfo = new PlaybackInfo(periodIndex);
playbackInfo.startPositionUs = positionUs;
playbackInfo.positionUs = positionUs;
eventHandler.obtainMessage(MSG_POSITION_DISCONTINUITY, playbackInfo).sendToTarget();
} else {
playbackInfo.startPositionUs = positionUs;
playbackInfo.positionUs = positionUs;
}
updatePlaybackPositions(); updatePlaybackPositions();
if (mediaSource != null) {
setState(ExoPlayer.STATE_BUFFERING); setState(ExoPlayer.STATE_BUFFERING);
handler.sendEmptyMessage(MSG_DO_SOME_WORK); handler.sendEmptyMessage(MSG_DO_SOME_WORK);
} }
}
private void resetInternalPosition(long periodPositionUs) throws ExoPlaybackException { private void resetInternalPosition(long periodPositionUs) throws ExoPlaybackException {
long periodOffsetUs = playingPeriod == null ? 0 : playingPeriod.offsetUs; long periodOffsetUs = playingPeriod == null ? 0 : playingPeriod.offsetUs;
......
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