Commit 32858511 by olly Committed by Oliver Woodman

Pass prepareAcks in SourceInfo

This makes it a bit more obvious what's going on during
preparation. In particular, it makes it clear that
MSG_SOURCE_INFO_REFRESHED arrives before MSG_TRACKS_CHANGED.

Issue: #3362

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=173392080
parent 8b3ec480
...@@ -454,10 +454,6 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -454,10 +454,6 @@ import java.util.concurrent.CopyOnWriteArraySet;
// Not private so it can be called from an inner class without going through a thunk method. // Not private so it can be called from an inner class without going through a thunk method.
/* package */ void handleEvent(Message msg) { /* package */ void handleEvent(Message msg) {
switch (msg.what) { switch (msg.what) {
case ExoPlayerImplInternal.MSG_PREPARE_ACK: {
pendingPrepareAcks--;
break;
}
case ExoPlayerImplInternal.MSG_STATE_CHANGED: { case ExoPlayerImplInternal.MSG_STATE_CHANGED: {
playbackState = msg.arg1; playbackState = msg.arg1;
for (Player.EventListener listener : listeners) { for (Player.EventListener listener : listeners) {
...@@ -474,6 +470,7 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -474,6 +470,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
} }
case ExoPlayerImplInternal.MSG_SOURCE_INFO_REFRESHED: { case ExoPlayerImplInternal.MSG_SOURCE_INFO_REFRESHED: {
SourceInfo sourceInfo = (SourceInfo) msg.obj; SourceInfo sourceInfo = (SourceInfo) msg.obj;
pendingPrepareAcks -= sourceInfo.prepareAcks;
pendingSeekAcks -= sourceInfo.seekAcks; pendingSeekAcks -= sourceInfo.seekAcks;
if (pendingPrepareAcks == 0) { if (pendingPrepareAcks == 0) {
timeline = sourceInfo.timeline; timeline = sourceInfo.timeline;
......
...@@ -92,12 +92,15 @@ import java.io.IOException; ...@@ -92,12 +92,15 @@ import java.io.IOException;
public final Timeline timeline; public final Timeline timeline;
public final Object manifest; public final Object manifest;
public final PlaybackInfo playbackInfo; public final PlaybackInfo playbackInfo;
public final int prepareAcks;
public final int seekAcks; public final int seekAcks;
public SourceInfo(Timeline timeline, Object manifest, PlaybackInfo playbackInfo, int seekAcks) { public SourceInfo(Timeline timeline, Object manifest, PlaybackInfo playbackInfo,
int prepareAcks, int seekAcks) {
this.timeline = timeline; this.timeline = timeline;
this.manifest = manifest; this.manifest = manifest;
this.playbackInfo = playbackInfo; this.playbackInfo = playbackInfo;
this.prepareAcks = prepareAcks;
this.seekAcks = seekAcks; this.seekAcks = seekAcks;
} }
...@@ -106,15 +109,14 @@ import java.io.IOException; ...@@ -106,15 +109,14 @@ import java.io.IOException;
private static final String TAG = "ExoPlayerImplInternal"; private static final String TAG = "ExoPlayerImplInternal";
// External messages // External messages
public static final int MSG_PREPARE_ACK = 0; public static final int MSG_STATE_CHANGED = 0;
public static final int MSG_STATE_CHANGED = 1; public static final int MSG_LOADING_CHANGED = 1;
public static final int MSG_LOADING_CHANGED = 2; public static final int MSG_TRACKS_CHANGED = 2;
public static final int MSG_TRACKS_CHANGED = 3; public static final int MSG_SEEK_ACK = 3;
public static final int MSG_SEEK_ACK = 4; public static final int MSG_POSITION_DISCONTINUITY = 4;
public static final int MSG_POSITION_DISCONTINUITY = 5; public static final int MSG_SOURCE_INFO_REFRESHED = 5;
public static final int MSG_SOURCE_INFO_REFRESHED = 6; public static final int MSG_PLAYBACK_PARAMETERS_CHANGED = 6;
public static final int MSG_PLAYBACK_PARAMETERS_CHANGED = 7; public static final int MSG_ERROR = 7;
public static final int MSG_ERROR = 8;
// Internal messages // Internal messages
private static final int MSG_PREPARE = 0; private static final int MSG_PREPARE = 0;
...@@ -181,6 +183,7 @@ import java.io.IOException; ...@@ -181,6 +183,7 @@ import java.io.IOException;
private int customMessagesProcessed; private int customMessagesProcessed;
private long elapsedRealtimeUs; private long elapsedRealtimeUs;
private int pendingPrepareCount;
private int pendingInitialSeekCount; private int pendingInitialSeekCount;
private SeekPosition pendingSeekPosition; private SeekPosition pendingSeekPosition;
private long rendererPositionUs; private long rendererPositionUs;
...@@ -439,7 +442,7 @@ import java.io.IOException; ...@@ -439,7 +442,7 @@ import java.io.IOException;
} }
private void prepareInternal(MediaSource mediaSource, boolean resetPosition) { private void prepareInternal(MediaSource mediaSource, boolean resetPosition) {
eventHandler.sendEmptyMessage(MSG_PREPARE_ACK); pendingPrepareCount++;
resetInternal(true); resetInternal(true);
loadControl.onPrepared(); loadControl.onPrepared();
if (resetPosition) { if (resetPosition) {
...@@ -1027,6 +1030,8 @@ import java.io.IOException; ...@@ -1027,6 +1030,8 @@ import java.io.IOException;
Object manifest = sourceRefreshInfo.manifest; Object manifest = sourceRefreshInfo.manifest;
if (oldTimeline == null) { if (oldTimeline == null) {
int processedPrepareAcks = pendingPrepareCount;
pendingPrepareCount = 0;
if (pendingInitialSeekCount > 0) { if (pendingInitialSeekCount > 0) {
Pair<Integer, Long> periodPosition = resolveSeekPosition(pendingSeekPosition); Pair<Integer, Long> periodPosition = resolveSeekPosition(pendingSeekPosition);
int processedInitialSeekCount = pendingInitialSeekCount; int processedInitialSeekCount = pendingInitialSeekCount;
...@@ -1035,18 +1040,19 @@ import java.io.IOException; ...@@ -1035,18 +1040,19 @@ import java.io.IOException;
if (periodPosition == null) { if (periodPosition == null) {
// The seek position was valid for the timeline that it was performed into, but the // The seek position was valid for the timeline that it was performed into, but the
// timeline has changed and a suitable seek position could not be resolved in the new one. // timeline has changed and a suitable seek position could not be resolved in the new one.
handleSourceInfoRefreshEndedPlayback(manifest, processedInitialSeekCount); handleSourceInfoRefreshEndedPlayback(manifest, processedPrepareAcks,
processedInitialSeekCount);
} else { } else {
int periodIndex = periodPosition.first; int periodIndex = periodPosition.first;
long positionUs = periodPosition.second; long positionUs = periodPosition.second;
MediaPeriodId periodId = MediaPeriodId periodId =
mediaPeriodInfoSequence.resolvePeriodPositionForAds(periodIndex, positionUs); mediaPeriodInfoSequence.resolvePeriodPositionForAds(periodIndex, positionUs);
playbackInfo = new PlaybackInfo(periodId, periodId.isAd() ? 0 : positionUs, positionUs); playbackInfo = new PlaybackInfo(periodId, periodId.isAd() ? 0 : positionUs, positionUs);
notifySourceInfoRefresh(manifest, playbackInfo, processedInitialSeekCount); notifySourceInfoRefresh(manifest, processedPrepareAcks, processedInitialSeekCount);
} }
} else if (playbackInfo.startPositionUs == C.TIME_UNSET) { } else if (playbackInfo.startPositionUs == C.TIME_UNSET) {
if (timeline.isEmpty()) { if (timeline.isEmpty()) {
handleSourceInfoRefreshEndedPlayback(manifest); handleSourceInfoRefreshEndedPlayback(manifest, processedPrepareAcks, 0);
} else { } else {
Pair<Integer, Long> defaultPosition = getPeriodPosition( Pair<Integer, Long> defaultPosition = getPeriodPosition(
timeline.getFirstWindowIndex(shuffleModeEnabled), C.TIME_UNSET); timeline.getFirstWindowIndex(shuffleModeEnabled), C.TIME_UNSET);
...@@ -1056,10 +1062,10 @@ import java.io.IOException; ...@@ -1056,10 +1062,10 @@ import java.io.IOException;
startPositionUs); startPositionUs);
playbackInfo = new PlaybackInfo(periodId, periodId.isAd() ? 0 : startPositionUs, playbackInfo = new PlaybackInfo(periodId, periodId.isAd() ? 0 : startPositionUs,
startPositionUs); startPositionUs);
notifySourceInfoRefresh(manifest); notifySourceInfoRefresh(manifest, processedPrepareAcks, 0);
} }
} else { } else {
notifySourceInfoRefresh(manifest); notifySourceInfoRefresh(manifest, processedPrepareAcks, 0);
} }
return; return;
} }
...@@ -1186,11 +1192,11 @@ import java.io.IOException; ...@@ -1186,11 +1192,11 @@ import java.io.IOException;
} }
private void handleSourceInfoRefreshEndedPlayback(Object manifest) { private void handleSourceInfoRefreshEndedPlayback(Object manifest) {
handleSourceInfoRefreshEndedPlayback(manifest, 0); handleSourceInfoRefreshEndedPlayback(manifest, 0, 0);
} }
private void handleSourceInfoRefreshEndedPlayback(Object manifest, private void handleSourceInfoRefreshEndedPlayback(Object manifest, int prepareAcks,
int processedInitialSeekCount) { int seekAcks) {
int firstPeriodIndex = timeline.isEmpty() ? 0 : timeline.getWindow( int firstPeriodIndex = timeline.isEmpty() ? 0 : timeline.getWindow(
timeline.getFirstWindowIndex(shuffleModeEnabled), window).firstPeriodIndex; timeline.getFirstWindowIndex(shuffleModeEnabled), window).firstPeriodIndex;
// Set the internal position to (firstPeriodIndex,TIME_UNSET) so that a subsequent seek to // Set the internal position to (firstPeriodIndex,TIME_UNSET) so that a subsequent seek to
...@@ -1198,20 +1204,23 @@ import java.io.IOException; ...@@ -1198,20 +1204,23 @@ import java.io.IOException;
playbackInfo = new PlaybackInfo(firstPeriodIndex, C.TIME_UNSET); playbackInfo = new PlaybackInfo(firstPeriodIndex, C.TIME_UNSET);
setState(Player.STATE_ENDED); setState(Player.STATE_ENDED);
// Set the playback position to (firstPeriodIndex,0) for notifying the eventHandler. // Set the playback position to (firstPeriodIndex,0) for notifying the eventHandler.
notifySourceInfoRefresh(manifest, new PlaybackInfo(firstPeriodIndex, 0), notifySourceInfoRefresh(manifest, prepareAcks, seekAcks, new PlaybackInfo(firstPeriodIndex, 0));
processedInitialSeekCount);
// 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(false); resetInternal(false);
} }
private void notifySourceInfoRefresh(Object manifest) { private void notifySourceInfoRefresh(Object manifest) {
notifySourceInfoRefresh(manifest, playbackInfo, 0); notifySourceInfoRefresh(manifest, 0, 0);
}
private void notifySourceInfoRefresh(Object manifest, int prepareAcks, int seekAcks) {
notifySourceInfoRefresh(manifest, prepareAcks, seekAcks, playbackInfo);
} }
private void notifySourceInfoRefresh(Object manifest, PlaybackInfo playbackInfo, private void notifySourceInfoRefresh(Object manifest, int prepareAcks, int seekAcks,
int processedInitialSeekCount) { PlaybackInfo playbackInfo) {
eventHandler.obtainMessage(MSG_SOURCE_INFO_REFRESHED, eventHandler.obtainMessage(MSG_SOURCE_INFO_REFRESHED,
new SourceInfo(timeline, manifest, playbackInfo, processedInitialSeekCount)).sendToTarget(); new SourceInfo(timeline, manifest, playbackInfo, prepareAcks, seekAcks)).sendToTarget();
} }
/** /**
......
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