Commit fdb53ac8 by tonihei Committed by Oliver Woodman

Correct period index counting in ExoPlayerTestRunner.

The initial period index was counted in onPlayerStateChanged. However, we
actually want to save the period index in the newly introduced onPositionDiscontinuity
after preparation.

While being here, also updated deprecated LinkedList to ArrayList.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=176479509
parent aac53cac
...@@ -40,7 +40,6 @@ import com.google.android.exoplayer2.trackselection.TrackSelectionArray; ...@@ -40,7 +40,6 @@ import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.video.VideoRendererEventListener; import com.google.android.exoplayer2.video.VideoRendererEventListener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
...@@ -316,10 +315,10 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener { ...@@ -316,10 +315,10 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener {
private final HandlerThread playerThread; private final HandlerThread playerThread;
private final Handler handler; private final Handler handler;
private final CountDownLatch endedCountDownLatch; private final CountDownLatch endedCountDownLatch;
private final LinkedList<Timeline> timelines; private final ArrayList<Timeline> timelines;
private final LinkedList<Object> manifests; private final ArrayList<Object> manifests;
private final ArrayList<Integer> timelineChangeReasons; private final ArrayList<Integer> timelineChangeReasons;
private final LinkedList<Integer> periodIndices; private final ArrayList<Integer> periodIndices;
private final ArrayList<Integer> discontinuityReasons; private final ArrayList<Integer> discontinuityReasons;
private SimpleExoPlayer player; private SimpleExoPlayer player;
...@@ -337,10 +336,10 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener { ...@@ -337,10 +336,10 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener {
this.loadControl = loadControl; this.loadControl = loadControl;
this.actionSchedule = actionSchedule; this.actionSchedule = actionSchedule;
this.eventListener = eventListener; this.eventListener = eventListener;
this.timelines = new LinkedList<>(); this.timelines = new ArrayList<>();
this.manifests = new LinkedList<>(); this.manifests = new ArrayList<>();
this.timelineChangeReasons = new ArrayList<>(); this.timelineChangeReasons = new ArrayList<>();
this.periodIndices = new LinkedList<>(); this.periodIndices = new ArrayList<>();
this.discontinuityReasons = new ArrayList<>(); this.discontinuityReasons = new ArrayList<>();
this.endedCountDownLatch = new CountDownLatch(1); this.endedCountDownLatch = new CountDownLatch(1);
this.playerThread = new HandlerThread("ExoPlayerTest thread"); this.playerThread = new HandlerThread("ExoPlayerTest thread");
...@@ -413,8 +412,8 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener { ...@@ -413,8 +412,8 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener {
*/ */
public void assertTimelinesEqual(Timeline... timelines) { public void assertTimelinesEqual(Timeline... timelines) {
Assert.assertEquals(timelines.length, this.timelines.size()); Assert.assertEquals(timelines.length, this.timelines.size());
for (Timeline timeline : timelines) { for (int i = 0; i < timelines.length; i++) {
Assert.assertEquals(timeline, this.timelines.remove()); Assert.assertEquals(timelines[i], this.timelines.get(i));
} }
} }
...@@ -427,8 +426,8 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener { ...@@ -427,8 +426,8 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener {
*/ */
public void assertManifestsEqual(Object... manifests) { public void assertManifestsEqual(Object... manifests) {
Assert.assertEquals(manifests.length, this.manifests.size()); Assert.assertEquals(manifests.length, this.manifests.size());
for (Object manifest : manifests) { for (int i = 0; i < manifests.length; i++) {
Assert.assertEquals(manifest, this.manifests.remove()); Assert.assertEquals(manifests[i], this.manifests.get(i));
} }
} }
...@@ -486,8 +485,8 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener { ...@@ -486,8 +485,8 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener {
*/ */
public void assertPlayedPeriodIndices(int... periodIndices) { public void assertPlayedPeriodIndices(int... periodIndices) {
Assert.assertEquals(periodIndices.length, this.periodIndices.size()); Assert.assertEquals(periodIndices.length, this.periodIndices.size());
for (int periodIndex : periodIndices) { for (int i = 0; i < periodIndices.length; i++) {
Assert.assertEquals(periodIndex, (int) this.periodIndices.remove()); Assert.assertEquals(periodIndices[i], (int) this.periodIndices.get(i));
} }
} }
...@@ -526,6 +525,9 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener { ...@@ -526,6 +525,9 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener {
timelines.add(timeline); timelines.add(timeline);
manifests.add(manifest); manifests.add(manifest);
timelineChangeReasons.add(reason); timelineChangeReasons.add(reason);
if (reason == Player.TIMELINE_CHANGE_REASON_PREPARED) {
periodIndices.add(player.getCurrentPeriodIndex());
}
} }
@Override @Override
...@@ -535,9 +537,6 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener { ...@@ -535,9 +537,6 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener {
@Override @Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
if (periodIndices.isEmpty() && playbackState == Player.STATE_READY) {
periodIndices.add(player.getCurrentPeriodIndex());
}
playerWasPrepared |= playbackState != Player.STATE_IDLE; playerWasPrepared |= playbackState != Player.STATE_IDLE;
if (playbackState == Player.STATE_ENDED if (playbackState == Player.STATE_ENDED
|| (playbackState == Player.STATE_IDLE && playerWasPrepared)) { || (playbackState == Player.STATE_IDLE && playerWasPrepared)) {
...@@ -553,7 +552,13 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener { ...@@ -553,7 +552,13 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener {
@Override @Override
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) { public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
discontinuityReasons.add(reason); discontinuityReasons.add(reason);
periodIndices.add(player.getCurrentPeriodIndex()); int currentIndex = player.getCurrentPeriodIndex();
if (reason == Player.DISCONTINUITY_REASON_PERIOD_TRANSITION
|| periodIndices.isEmpty()
|| periodIndices.get(periodIndices.size() - 1) != currentIndex) {
// Ignore seek or internal discontinuities within a period.
periodIndices.add(currentIndex);
}
} }
} }
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