Commit 835b6382 by tonihei Committed by Oliver Woodman

Move external timeline and start position overwrites to ExoPlayerImpl.

Makes it less error-prone to accidentatly forget to set the right overwrites.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177282089
parent 9e8f50a9
...@@ -502,10 +502,19 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -502,10 +502,19 @@ import java.util.concurrent.CopyOnWriteArraySet;
private void handlePlaybackInfo(PlaybackInfo playbackInfo, int prepareOrStopAcks, int seekAcks, private void handlePlaybackInfo(PlaybackInfo playbackInfo, int prepareOrStopAcks, int seekAcks,
boolean positionDiscontinuity, @DiscontinuityReason int positionDiscontinuityReason) { boolean positionDiscontinuity, @DiscontinuityReason int positionDiscontinuityReason) {
Assertions.checkNotNull(playbackInfo.timeline);
pendingPrepareOrStopAcks -= prepareOrStopAcks; pendingPrepareOrStopAcks -= prepareOrStopAcks;
pendingSeekAcks -= seekAcks; pendingSeekAcks -= seekAcks;
if (pendingPrepareOrStopAcks == 0 && pendingSeekAcks == 0) { if (pendingPrepareOrStopAcks == 0 && pendingSeekAcks == 0) {
if (playbackInfo.timeline == null) {
// Replace internal null timeline with externally visible empty timeline.
playbackInfo = playbackInfo.copyWithTimeline(Timeline.EMPTY, playbackInfo.manifest);
}
if (playbackInfo.startPositionUs == C.TIME_UNSET) {
// Replace internal unset start position with externally visible start position of zero.
playbackInfo =
playbackInfo.fromNewPosition(
playbackInfo.periodId, /* startPositionUs= */ 0, playbackInfo.contentPositionUs);
}
boolean timelineOrManifestChanged = this.playbackInfo.timeline != playbackInfo.timeline boolean timelineOrManifestChanged = this.playbackInfo.timeline != playbackInfo.timeline
|| this.playbackInfo.manifest != playbackInfo.manifest; || this.playbackInfo.manifest != playbackInfo.manifest;
this.playbackInfo = playbackInfo; this.playbackInfo = playbackInfo;
......
...@@ -632,11 +632,7 @@ import java.io.IOException; ...@@ -632,11 +632,7 @@ import java.io.IOException;
if (mediaSource == null || timeline == null) { if (mediaSource == null || timeline == null) {
pendingInitialSeekPosition = seekPosition; pendingInitialSeekPosition = seekPosition;
eventHandler eventHandler
.obtainMessage( .obtainMessage(MSG_SEEK_ACK, /* seekAdjusted */ 0, 0, playbackInfo)
MSG_SEEK_ACK,
/* seekAdjusted */ 0,
0,
timeline == null ? playbackInfo.copyWithTimeline(Timeline.EMPTY, null) : playbackInfo)
.sendToTarget(); .sendToTarget();
return; return;
} }
...@@ -649,10 +645,8 @@ import java.io.IOException; ...@@ -649,10 +645,8 @@ import java.io.IOException;
// Reset, but retain the source so that it can still be used should a seek occur. // Reset, but retain the source so that it can still be used should a seek occur.
resetInternal( resetInternal(
/* releaseMediaSource= */ false, /* resetPosition= */ true, /* resetState= */ false); /* releaseMediaSource= */ false, /* resetPosition= */ true, /* resetState= */ false);
// Set the playback position to 0 for notifying the eventHandler (instead of C.TIME_UNSET). eventHandler
eventHandler.obtainMessage(MSG_SEEK_ACK, /* seekAdjusted */ 1, 0, .obtainMessage(MSG_SEEK_ACK, /* seekAdjusted */ 1, 0, playbackInfo)
playbackInfo.fromNewPosition(playbackInfo.periodId.periodIndex, /* startPositionUs= */ 0,
/* contentPositionUs= */ C.TIME_UNSET))
.sendToTarget(); .sendToTarget();
return; return;
} }
...@@ -774,21 +768,9 @@ import java.io.IOException; ...@@ -774,21 +768,9 @@ import java.io.IOException;
private void stopInternal(boolean reset) { private void stopInternal(boolean reset) {
resetInternal( resetInternal(
/* releaseMediaSource= */ true, /* resetPosition= */ reset, /* resetState= */ reset); /* releaseMediaSource= */ true, /* resetPosition= */ reset, /* resetState= */ reset);
PlaybackInfo publicPlaybackInfo = playbackInfo;
if (playbackInfo.timeline == null) {
// Resetting the state sets the timeline to null. Use Timeline.EMPTY for notifying the
// eventHandler.
publicPlaybackInfo = publicPlaybackInfo.copyWithTimeline(Timeline.EMPTY, null);
}
if (playbackInfo.startPositionUs == C.TIME_UNSET) {
// When resetting the state, set the playback position to 0 (instead of C.TIME_UNSET) for
// notifying the eventHandler.
publicPlaybackInfo =
publicPlaybackInfo.fromNewPosition(playbackInfo.periodId.periodIndex, 0, C.TIME_UNSET);
}
int prepareOrStopAcks = pendingPrepareCount + 1; int prepareOrStopAcks = pendingPrepareCount + 1;
pendingPrepareCount = 0; pendingPrepareCount = 0;
notifySourceInfoRefresh(prepareOrStopAcks, publicPlaybackInfo); notifySourceInfoRefresh(prepareOrStopAcks, playbackInfo);
loadControl.onStopped(); loadControl.onStopped();
setState(Player.STATE_IDLE); setState(Player.STATE_IDLE);
} }
...@@ -1187,9 +1169,7 @@ import java.io.IOException; ...@@ -1187,9 +1169,7 @@ import java.io.IOException;
// Reset, but retain the source so that it can still be used should a seek occur. // Reset, but retain the source so that it can still be used should a seek occur.
resetInternal( resetInternal(
/* releaseMediaSource= */ false, /* resetPosition= */ true, /* resetState= */ false); /* releaseMediaSource= */ false, /* resetPosition= */ true, /* resetState= */ false);
// Set the playback position to 0 for notifying the eventHandler (instead of C.TIME_UNSET). notifySourceInfoRefresh(prepareAcks, playbackInfo);
notifySourceInfoRefresh(prepareAcks,
playbackInfo.fromNewPosition(playbackInfo.periodId.periodIndex, 0, C.TIME_UNSET));
} }
private void notifySourceInfoRefresh() { private void notifySourceInfoRefresh() {
......
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