Commit 51963dea by olly Committed by Oliver Woodman

Clean up message naming in EPII

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=184122057
parent 19501523
...@@ -72,10 +72,10 @@ import java.util.Collections; ...@@ -72,10 +72,10 @@ import java.util.Collections;
private static final int MSG_PERIOD_PREPARED = 9; private static final int MSG_PERIOD_PREPARED = 9;
private static final int MSG_SOURCE_CONTINUE_LOADING_REQUESTED = 10; private static final int MSG_SOURCE_CONTINUE_LOADING_REQUESTED = 10;
private static final int MSG_TRACK_SELECTION_INVALIDATED = 11; private static final int MSG_TRACK_SELECTION_INVALIDATED = 11;
private static final int MSG_CUSTOM = 12; private static final int MSG_SET_REPEAT_MODE = 12;
private static final int MSG_SET_REPEAT_MODE = 13; private static final int MSG_SET_SHUFFLE_ENABLED = 13;
private static final int MSG_SET_SHUFFLE_ENABLED = 14; private static final int MSG_SEND_MESSAGE = 14;
private static final int MSG_SEND_MESSAGE_TO_TARGET = 15; private static final int MSG_SEND_MESSAGE_TO_TARGET_THREAD = 15;
private static final int PREPARING_SOURCE_INTERVAL_MS = 10; private static final int PREPARING_SOURCE_INTERVAL_MS = 10;
private static final int RENDERING_INTERVAL_MS = 10; private static final int RENDERING_INTERVAL_MS = 10;
...@@ -104,7 +104,7 @@ import java.util.Collections; ...@@ -104,7 +104,7 @@ import java.util.Collections;
private final boolean retainBackBufferFromKeyframe; private final boolean retainBackBufferFromKeyframe;
private final DefaultMediaClock mediaClock; private final DefaultMediaClock mediaClock;
private final PlaybackInfoUpdate playbackInfoUpdate; private final PlaybackInfoUpdate playbackInfoUpdate;
private final ArrayList<CustomMessageInfo> customMessageInfos; private final ArrayList<PendingMessageInfo> pendingMessages;
private final Clock clock; private final Clock clock;
private final MediaPeriodQueue queue; private final MediaPeriodQueue queue;
...@@ -123,7 +123,7 @@ import java.util.Collections; ...@@ -123,7 +123,7 @@ import java.util.Collections;
private int pendingPrepareCount; private int pendingPrepareCount;
private SeekPosition pendingInitialSeekPosition; private SeekPosition pendingInitialSeekPosition;
private long rendererPositionUs; private long rendererPositionUs;
private int nextCustomMessageInfoIndex; private int nextPendingMessageIndex;
public ExoPlayerImplInternal( public ExoPlayerImplInternal(
Renderer[] renderers, Renderer[] renderers,
...@@ -162,7 +162,7 @@ import java.util.Collections; ...@@ -162,7 +162,7 @@ import java.util.Collections;
rendererCapabilities[i] = renderers[i].getCapabilities(); rendererCapabilities[i] = renderers[i].getCapabilities();
} }
mediaClock = new DefaultMediaClock(this, clock); mediaClock = new DefaultMediaClock(this, clock);
customMessageInfos = new ArrayList<>(); pendingMessages = new ArrayList<>();
enabledRenderers = new Renderer[0]; enabledRenderers = new Renderer[0];
window = new Timeline.Window(); window = new Timeline.Window();
period = new Timeline.Period(); period = new Timeline.Period();
...@@ -217,7 +217,7 @@ import java.util.Collections; ...@@ -217,7 +217,7 @@ import java.util.Collections;
message.markAsProcessed(/* isDelivered= */ false); message.markAsProcessed(/* isDelivered= */ false);
return; return;
} }
handler.obtainMessage(MSG_CUSTOM, message).sendToTarget(); handler.obtainMessage(MSG_SEND_MESSAGE, message).sendToTarget();
} }
public synchronized void release() { public synchronized void release() {
...@@ -324,11 +324,11 @@ import java.util.Collections; ...@@ -324,11 +324,11 @@ import java.util.Collections;
case MSG_TRACK_SELECTION_INVALIDATED: case MSG_TRACK_SELECTION_INVALIDATED:
reselectTracksInternal(); reselectTracksInternal();
break; break;
case MSG_CUSTOM: case MSG_SEND_MESSAGE:
sendMessageInternal((PlayerMessage) msg.obj); sendMessageInternal((PlayerMessage) msg.obj);
break; break;
case MSG_SEND_MESSAGE_TO_TARGET: case MSG_SEND_MESSAGE_TO_TARGET_THREAD:
sendCustomMessageToTargetThread((PlayerMessage) msg.obj); sendMessageToTargetThread((PlayerMessage) msg.obj);
break; break;
case MSG_RELEASE: case MSG_RELEASE:
releaseInternal(); releaseInternal();
...@@ -504,7 +504,7 @@ import java.util.Collections; ...@@ -504,7 +504,7 @@ import java.util.Collections;
} else { } else {
rendererPositionUs = mediaClock.syncAndGetPositionUs(); rendererPositionUs = mediaClock.syncAndGetPositionUs();
periodPositionUs = playingPeriodHolder.toPeriodTime(rendererPositionUs); periodPositionUs = playingPeriodHolder.toPeriodTime(rendererPositionUs);
maybeTriggerCustomMessages(playbackInfo.positionUs, periodPositionUs); maybeTriggerPendingMessages(playbackInfo.positionUs, periodPositionUs);
playbackInfo.positionUs = periodPositionUs; playbackInfo.positionUs = periodPositionUs;
} }
...@@ -805,11 +805,11 @@ import java.util.Collections; ...@@ -805,11 +805,11 @@ import java.util.Collections;
} }
if (resetState) { if (resetState) {
queue.setTimeline(null); queue.setTimeline(null);
for (CustomMessageInfo customMessageInfo : customMessageInfos) { for (PendingMessageInfo pendingMessageInfo : pendingMessages) {
customMessageInfo.message.markAsProcessed(/* isDelivered= */ false); pendingMessageInfo.message.markAsProcessed(/* isDelivered= */ false);
} }
customMessageInfos.clear(); pendingMessages.clear();
nextCustomMessageInfoIndex = 0; nextPendingMessageIndex = 0;
} }
playbackInfo = playbackInfo =
new PlaybackInfo( new PlaybackInfo(
...@@ -833,48 +833,48 @@ import java.util.Collections; ...@@ -833,48 +833,48 @@ import java.util.Collections;
private void sendMessageInternal(PlayerMessage message) { private void sendMessageInternal(PlayerMessage message) {
if (message.getPositionMs() == C.TIME_UNSET) { if (message.getPositionMs() == C.TIME_UNSET) {
// If no delivery time is specified, trigger immediate message delivery. // If no delivery time is specified, trigger immediate message delivery.
sendCustomMessageToTarget(message); sendMessageToTarget(message);
} else if (playbackInfo.timeline == null) { } else if (playbackInfo.timeline == null) {
// Still waiting for initial timeline to resolve position. // Still waiting for initial timeline to resolve position.
customMessageInfos.add(new CustomMessageInfo(message)); pendingMessages.add(new PendingMessageInfo(message));
} else { } else {
CustomMessageInfo customMessageInfo = new CustomMessageInfo(message); PendingMessageInfo pendingMessageInfo = new PendingMessageInfo(message);
if (resolveCustomMessagePosition(customMessageInfo)) { if (resolvePendingMessagePosition(pendingMessageInfo)) {
customMessageInfos.add(customMessageInfo); pendingMessages.add(pendingMessageInfo);
// Ensure new message is inserted according to playback order. // Ensure new message is inserted according to playback order.
Collections.sort(customMessageInfos); Collections.sort(pendingMessages);
} else { } else {
message.markAsProcessed(/* isDelivered= */ false); message.markAsProcessed(/* isDelivered= */ false);
} }
} }
} }
private void sendCustomMessageToTarget(PlayerMessage message) { private void sendMessageToTarget(PlayerMessage message) {
if (message.getHandler().getLooper() == handler.getLooper()) { if (message.getHandler().getLooper() == handler.getLooper()) {
deliverCustomMessage(message); deliverMessage(message);
if (playbackInfo.playbackState == Player.STATE_READY if (playbackInfo.playbackState == Player.STATE_READY
|| playbackInfo.playbackState == Player.STATE_BUFFERING) { || playbackInfo.playbackState == Player.STATE_BUFFERING) {
// The message may have caused something to change that now requires us to do work. // The message may have caused something to change that now requires us to do work.
handler.sendEmptyMessage(MSG_DO_SOME_WORK); handler.sendEmptyMessage(MSG_DO_SOME_WORK);
} }
} else { } else {
handler.obtainMessage(MSG_SEND_MESSAGE_TO_TARGET, message).sendToTarget(); handler.obtainMessage(MSG_SEND_MESSAGE_TO_TARGET_THREAD, message).sendToTarget();
} }
} }
private void sendCustomMessageToTargetThread(final PlayerMessage message) { private void sendMessageToTargetThread(final PlayerMessage message) {
message message
.getHandler() .getHandler()
.post( .post(
new Runnable() { new Runnable() {
@Override @Override
public void run() { public void run() {
deliverCustomMessage(message); deliverMessage(message);
} }
}); });
} }
private void deliverCustomMessage(PlayerMessage message) { private void deliverMessage(PlayerMessage message) {
try { try {
message.getTarget().handleMessage(message.getType(), message.getPayload()); message.getTarget().handleMessage(message.getType(), message.getPayload());
} catch (ExoPlaybackException e) { } catch (ExoPlaybackException e) {
...@@ -884,48 +884,48 @@ import java.util.Collections; ...@@ -884,48 +884,48 @@ import java.util.Collections;
} }
} }
private void resolveCustomMessagePositions() { private void resolvePendingMessagePositions() {
for (int i = customMessageInfos.size() - 1; i >= 0; i--) { for (int i = pendingMessages.size() - 1; i >= 0; i--) {
if (!resolveCustomMessagePosition(customMessageInfos.get(i))) { if (!resolvePendingMessagePosition(pendingMessages.get(i))) {
// Remove messages if new position can't be resolved. // Unable to resolve a new position for the message. Remove it.
customMessageInfos.get(i).message.markAsProcessed(/* isDelivered= */ false); pendingMessages.get(i).message.markAsProcessed(/* isDelivered= */ false);
customMessageInfos.remove(i); pendingMessages.remove(i);
} }
} }
// Re-sort messages by playback order. // Re-sort messages by playback order.
Collections.sort(customMessageInfos); Collections.sort(pendingMessages);
} }
private boolean resolveCustomMessagePosition(CustomMessageInfo customMessageInfo) { private boolean resolvePendingMessagePosition(PendingMessageInfo pendingMessageInfo) {
if (customMessageInfo.resolvedPeriodUid == null) { if (pendingMessageInfo.resolvedPeriodUid == null) {
// Position is still unresolved. Try to find window in current timeline. // Position is still unresolved. Try to find window in current timeline.
Pair<Integer, Long> periodPosition = Pair<Integer, Long> periodPosition =
resolveSeekPosition( resolveSeekPosition(
new SeekPosition( new SeekPosition(
customMessageInfo.message.getTimeline(), pendingMessageInfo.message.getTimeline(),
customMessageInfo.message.getWindowIndex(), pendingMessageInfo.message.getWindowIndex(),
C.msToUs(customMessageInfo.message.getPositionMs())), C.msToUs(pendingMessageInfo.message.getPositionMs())),
/* trySubsequentPeriods= */ false); /* trySubsequentPeriods= */ false);
if (periodPosition == null) { if (periodPosition == null) {
return false; return false;
} }
customMessageInfo.setResolvedPosition( pendingMessageInfo.setResolvedPosition(
periodPosition.first, periodPosition.first,
periodPosition.second, periodPosition.second,
playbackInfo.timeline.getPeriod(periodPosition.first, period, true).uid); playbackInfo.timeline.getPeriod(periodPosition.first, period, true).uid);
} else { } else {
// Position has been resolved for a previous timeline. Try to find the updated period index. // Position has been resolved for a previous timeline. Try to find the updated period index.
int index = playbackInfo.timeline.getIndexOfPeriod(customMessageInfo.resolvedPeriodUid); int index = playbackInfo.timeline.getIndexOfPeriod(pendingMessageInfo.resolvedPeriodUid);
if (index == C.INDEX_UNSET) { if (index == C.INDEX_UNSET) {
return false; return false;
} }
customMessageInfo.resolvedPeriodIndex = index; pendingMessageInfo.resolvedPeriodIndex = index;
} }
return true; return true;
} }
private void maybeTriggerCustomMessages(long oldPeriodPositionUs, long newPeriodPositionUs) { private void maybeTriggerPendingMessages(long oldPeriodPositionUs, long newPeriodPositionUs) {
if (customMessageInfos.isEmpty() || playbackInfo.periodId.isAd()) { if (pendingMessages.isEmpty() || playbackInfo.periodId.isAd()) {
return; return;
} }
// If this is the first call from the start position, include oldPeriodPositionUs in potential // If this is the first call from the start position, include oldPeriodPositionUs in potential
...@@ -935,33 +935,29 @@ import java.util.Collections; ...@@ -935,33 +935,29 @@ import java.util.Collections;
} }
// Correct next index if necessary (e.g. after seeking, timeline changes, or new messages) // Correct next index if necessary (e.g. after seeking, timeline changes, or new messages)
int currentPeriodIndex = playbackInfo.periodId.periodIndex; int currentPeriodIndex = playbackInfo.periodId.periodIndex;
CustomMessageInfo prevInfo = PendingMessageInfo previousInfo =
nextCustomMessageInfoIndex > 0 nextPendingMessageIndex > 0 ? pendingMessages.get(nextPendingMessageIndex - 1) : null;
? customMessageInfos.get(nextCustomMessageInfoIndex - 1) while (previousInfo != null
: null; && (previousInfo.resolvedPeriodIndex > currentPeriodIndex
while (prevInfo != null || (previousInfo.resolvedPeriodIndex == currentPeriodIndex
&& (prevInfo.resolvedPeriodIndex > currentPeriodIndex && previousInfo.resolvedPeriodTimeUs > oldPeriodPositionUs))) {
|| (prevInfo.resolvedPeriodIndex == currentPeriodIndex nextPendingMessageIndex--;
&& prevInfo.resolvedPeriodTimeUs > oldPeriodPositionUs))) { previousInfo =
nextCustomMessageInfoIndex--; nextPendingMessageIndex > 0 ? pendingMessages.get(nextPendingMessageIndex - 1) : null;
prevInfo = }
nextCustomMessageInfoIndex > 0 PendingMessageInfo nextInfo =
? customMessageInfos.get(nextCustomMessageInfoIndex - 1) nextPendingMessageIndex < pendingMessages.size()
: null; ? pendingMessages.get(nextPendingMessageIndex)
}
CustomMessageInfo nextInfo =
nextCustomMessageInfoIndex < customMessageInfos.size()
? customMessageInfos.get(nextCustomMessageInfoIndex)
: null; : null;
while (nextInfo != null while (nextInfo != null
&& nextInfo.resolvedPeriodUid != null && nextInfo.resolvedPeriodUid != null
&& (nextInfo.resolvedPeriodIndex < currentPeriodIndex && (nextInfo.resolvedPeriodIndex < currentPeriodIndex
|| (nextInfo.resolvedPeriodIndex == currentPeriodIndex || (nextInfo.resolvedPeriodIndex == currentPeriodIndex
&& nextInfo.resolvedPeriodTimeUs <= oldPeriodPositionUs))) { && nextInfo.resolvedPeriodTimeUs <= oldPeriodPositionUs))) {
nextCustomMessageInfoIndex++; nextPendingMessageIndex++;
nextInfo = nextInfo =
nextCustomMessageInfoIndex < customMessageInfos.size() nextPendingMessageIndex < pendingMessages.size()
? customMessageInfos.get(nextCustomMessageInfoIndex) ? pendingMessages.get(nextPendingMessageIndex)
: null; : null;
} }
// Check if any message falls within the covered time span. // Check if any message falls within the covered time span.
...@@ -970,15 +966,15 @@ import java.util.Collections; ...@@ -970,15 +966,15 @@ import java.util.Collections;
&& nextInfo.resolvedPeriodIndex == currentPeriodIndex && nextInfo.resolvedPeriodIndex == currentPeriodIndex
&& nextInfo.resolvedPeriodTimeUs > oldPeriodPositionUs && nextInfo.resolvedPeriodTimeUs > oldPeriodPositionUs
&& nextInfo.resolvedPeriodTimeUs <= newPeriodPositionUs) { && nextInfo.resolvedPeriodTimeUs <= newPeriodPositionUs) {
sendCustomMessageToTarget(nextInfo.message); sendMessageToTarget(nextInfo.message);
if (nextInfo.message.getDeleteAfterDelivery()) { if (nextInfo.message.getDeleteAfterDelivery()) {
customMessageInfos.remove(nextCustomMessageInfoIndex); pendingMessages.remove(nextPendingMessageIndex);
} else { } else {
nextCustomMessageInfoIndex++; nextPendingMessageIndex++;
} }
nextInfo = nextInfo =
nextCustomMessageInfoIndex < customMessageInfos.size() nextPendingMessageIndex < pendingMessages.size()
? customMessageInfos.get(nextCustomMessageInfoIndex) ? pendingMessages.get(nextPendingMessageIndex)
: null; : null;
} }
} }
...@@ -1157,7 +1153,7 @@ import java.util.Collections; ...@@ -1157,7 +1153,7 @@ import java.util.Collections;
Object manifest = sourceRefreshInfo.manifest; Object manifest = sourceRefreshInfo.manifest;
queue.setTimeline(timeline); queue.setTimeline(timeline);
playbackInfo = playbackInfo.copyWithTimeline(timeline, manifest); playbackInfo = playbackInfo.copyWithTimeline(timeline, manifest);
resolveCustomMessagePositions(); resolvePendingMessagePositions();
if (oldTimeline == null) { if (oldTimeline == null) {
playbackInfoUpdate.incrementPendingOperationAcks(pendingPrepareCount); playbackInfoUpdate.incrementPendingOperationAcks(pendingPrepareCount);
...@@ -1689,7 +1685,7 @@ import java.util.Collections; ...@@ -1689,7 +1685,7 @@ import java.util.Collections;
} }
} }
private static final class CustomMessageInfo implements Comparable<CustomMessageInfo> { private static final class PendingMessageInfo implements Comparable<PendingMessageInfo> {
public final PlayerMessage message; public final PlayerMessage message;
...@@ -1697,7 +1693,7 @@ import java.util.Collections; ...@@ -1697,7 +1693,7 @@ import java.util.Collections;
public long resolvedPeriodTimeUs; public long resolvedPeriodTimeUs;
public @Nullable Object resolvedPeriodUid; public @Nullable Object resolvedPeriodUid;
public CustomMessageInfo(PlayerMessage message) { public PendingMessageInfo(PlayerMessage message) {
this.message = message; this.message = message;
} }
...@@ -1708,9 +1704,9 @@ import java.util.Collections; ...@@ -1708,9 +1704,9 @@ import java.util.Collections;
} }
@Override @Override
public int compareTo(@NonNull CustomMessageInfo other) { public int compareTo(@NonNull PendingMessageInfo other) {
if ((resolvedPeriodUid == null) != (other.resolvedPeriodUid == null)) { if ((resolvedPeriodUid == null) != (other.resolvedPeriodUid == null)) {
// CustomMessageInfos with a resolved period position are always smaller. // PendingMessageInfos with a resolved period position are always smaller.
return resolvedPeriodUid != null ? -1 : 1; return resolvedPeriodUid != null ? -1 : 1;
} }
if (resolvedPeriodUid == null) { if (resolvedPeriodUid == null) {
......
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