Commit fe1e4fa1 by aquilescanta Committed by Oliver Woodman

Fix preparation of media sources with empty timeline

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=182533415
parent cf27bc84
...@@ -1399,7 +1399,7 @@ public final class ExoPlayerTest extends TestCase { ...@@ -1399,7 +1399,7 @@ public final class ExoPlayerTest extends TestCase {
assertEquals(2, target3.windowIndex); assertEquals(2, target3.windowIndex);
} }
public void testSetAndSwitchSurfaceTest() throws Exception { public void testSetAndSwitchSurface() throws Exception {
final List<Integer> rendererMessages = new ArrayList<>(); final List<Integer> rendererMessages = new ArrayList<>();
Renderer videoRenderer = Renderer videoRenderer =
new FakeRenderer(Builder.VIDEO_FORMAT) { new FakeRenderer(Builder.VIDEO_FORMAT) {
...@@ -1409,10 +1409,38 @@ public final class ExoPlayerTest extends TestCase { ...@@ -1409,10 +1409,38 @@ public final class ExoPlayerTest extends TestCase {
rendererMessages.add(what); rendererMessages.add(what);
} }
}; };
ActionSchedule actionSchedule =
addSurfaceSwitch(new ActionSchedule.Builder("testSetAndSwitchSurface")).build();
new ExoPlayerTestRunner.Builder()
.setRenderers(videoRenderer)
.setActionSchedule(actionSchedule)
.build()
.start()
.blockUntilActionScheduleFinished(TIMEOUT_MS)
.blockUntilEnded(TIMEOUT_MS);
assertEquals(2, Collections.frequency(rendererMessages, C.MSG_SET_SURFACE));
}
public void testSwitchSurfaceOnEndedState() throws Exception {
ActionSchedule.Builder scheduleBuilder =
new ActionSchedule.Builder("testSwitchSurfaceOnEndedState")
.waitForPlaybackState(Player.STATE_ENDED);
ActionSchedule waitForEndedAndSwitchSchedule = addSurfaceSwitch(scheduleBuilder).build();
new ExoPlayerTestRunner.Builder()
.setTimeline(Timeline.EMPTY)
.setActionSchedule(waitForEndedAndSwitchSchedule)
.build()
.start()
.blockUntilActionScheduleFinished(TIMEOUT_MS)
.blockUntilEnded(TIMEOUT_MS);
}
// Internal methods.
private static ActionSchedule.Builder addSurfaceSwitch(ActionSchedule.Builder builder) {
final Surface surface1 = DummySurface.newInstanceV17(/* context= */ null, /* secure= */ false); final Surface surface1 = DummySurface.newInstanceV17(/* context= */ null, /* secure= */ false);
final Surface surface2 = DummySurface.newInstanceV17(/* context= */ null, /* secure= */ false); final Surface surface2 = DummySurface.newInstanceV17(/* context= */ null, /* secure= */ false);
ActionSchedule actionSchedule = return builder
new ActionSchedule.Builder("setAndSwitchSurfaceTest")
.executeRunnable( .executeRunnable(
new PlayerRunnable() { new PlayerRunnable() {
@Override @Override
...@@ -1426,18 +1454,11 @@ public final class ExoPlayerTest extends TestCase { ...@@ -1426,18 +1454,11 @@ public final class ExoPlayerTest extends TestCase {
public void run(SimpleExoPlayer player) { public void run(SimpleExoPlayer player) {
player.setVideoSurface(surface2); player.setVideoSurface(surface2);
} }
}) });
.build();
new ExoPlayerTestRunner.Builder()
.setRenderers(videoRenderer)
.setActionSchedule(actionSchedule)
.build()
.start()
.blockUntilActionScheduleFinished(TIMEOUT_MS)
.blockUntilEnded(TIMEOUT_MS);
assertEquals(2, Collections.frequency(rendererMessages, C.MSG_SET_SURFACE));
} }
// Internal classes.
private static final class PositionGrabbingMessageTarget extends PlayerTarget { private static final class PositionGrabbingMessageTarget extends PlayerTarget {
public int windowIndex; public int windowIndex;
......
...@@ -881,8 +881,11 @@ import java.util.Collections; ...@@ -881,8 +881,11 @@ import java.util.Collections;
private void sendCustomMessageToTarget(PlayerMessage message) { private void sendCustomMessageToTarget(PlayerMessage message) {
if (message.getHandler().getLooper() == handler.getLooper()) { if (message.getHandler().getLooper() == handler.getLooper()) {
deliverCustomMessage(message); deliverCustomMessage(message);
if (playbackInfo.playbackState == Player.STATE_READY
|| 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, message).sendToTarget();
} }
...@@ -1413,7 +1416,7 @@ import java.util.Collections; ...@@ -1413,7 +1416,7 @@ import java.util.Collections;
MediaPeriodHolder loadingPeriodHolder = queue.getLoadingPeriod(); MediaPeriodHolder loadingPeriodHolder = queue.getLoadingPeriod();
if (loadingPeriodHolder == null || loadingPeriodHolder.isFullyBuffered()) { if (loadingPeriodHolder == null || loadingPeriodHolder.isFullyBuffered()) {
setIsLoading(false); setIsLoading(false);
} else if (loadingPeriodHolder != null && !playbackInfo.isLoading) { } else if (!playbackInfo.isLoading) {
maybeContinueLoading(); maybeContinueLoading();
} }
......
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