Commit 9fd19d0e by tonihei Committed by Oliver Woodman

Add shuffle logic to concatenated timelines.

The implementation in the abstract base class takes care to forward the queries
to the correct methods given the shuffle mode and a given shuffle order.

All concatenated timeline implementations use an unshuffled order so far. The
handling of the shuffle orders will follow in other changes.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=166191165
parent 4883a9ba
...@@ -26,9 +26,17 @@ import com.google.android.exoplayer2.Timeline; ...@@ -26,9 +26,17 @@ import com.google.android.exoplayer2.Timeline;
/* package */ abstract class AbstractConcatenatedTimeline extends Timeline { /* package */ abstract class AbstractConcatenatedTimeline extends Timeline {
private final int childCount; private final int childCount;
private final ShuffleOrder shuffleOrder;
public AbstractConcatenatedTimeline(int childCount) { /**
this.childCount = childCount; * Sets up a concatenated timeline with a shuffle order of child timelines.
*
* @param shuffleOrder A shuffle order of child timelines. The number of child timelines must
* match the number of elements in the shuffle order.
*/
public AbstractConcatenatedTimeline(ShuffleOrder shuffleOrder) {
this.shuffleOrder = shuffleOrder;
this.childCount = shuffleOrder.getLength();
} }
@Override @Override
...@@ -42,16 +50,17 @@ import com.google.android.exoplayer2.Timeline; ...@@ -42,16 +50,17 @@ import com.google.android.exoplayer2.Timeline;
shuffleModeEnabled); shuffleModeEnabled);
if (nextWindowIndexInChild != C.INDEX_UNSET) { if (nextWindowIndexInChild != C.INDEX_UNSET) {
return firstWindowIndexInChild + nextWindowIndexInChild; return firstWindowIndexInChild + nextWindowIndexInChild;
} else {
int nextChildIndex = childIndex + 1;
if (nextChildIndex < childCount) {
return getFirstWindowIndexByChildIndex(nextChildIndex);
} else if (repeatMode == Player.REPEAT_MODE_ALL) {
return 0;
} else {
return C.INDEX_UNSET;
} }
int nextChildIndex = shuffleModeEnabled ? shuffleOrder.getNextIndex(childIndex)
: childIndex + 1;
if (nextChildIndex != C.INDEX_UNSET && nextChildIndex < childCount) {
return getFirstWindowIndexByChildIndex(nextChildIndex)
+ getTimelineByChildIndex(nextChildIndex).getFirstWindowIndex(shuffleModeEnabled);
} }
if (repeatMode == Player.REPEAT_MODE_ALL) {
return getFirstWindowIndex(shuffleModeEnabled);
}
return C.INDEX_UNSET;
} }
@Override @Override
...@@ -65,15 +74,31 @@ import com.google.android.exoplayer2.Timeline; ...@@ -65,15 +74,31 @@ import com.google.android.exoplayer2.Timeline;
shuffleModeEnabled); shuffleModeEnabled);
if (previousWindowIndexInChild != C.INDEX_UNSET) { if (previousWindowIndexInChild != C.INDEX_UNSET) {
return firstWindowIndexInChild + previousWindowIndexInChild; return firstWindowIndexInChild + previousWindowIndexInChild;
} else { }
if (firstWindowIndexInChild > 0) { int previousChildIndex = shuffleModeEnabled ? shuffleOrder.getPreviousIndex(childIndex)
return firstWindowIndexInChild - 1; : childIndex - 1;
} else if (repeatMode == Player.REPEAT_MODE_ALL) { if (previousChildIndex != C.INDEX_UNSET && previousChildIndex >= 0) {
return getWindowCount() - 1; return getFirstWindowIndexByChildIndex(previousChildIndex)
} else { + getTimelineByChildIndex(previousChildIndex).getLastWindowIndex(shuffleModeEnabled);
}
if (repeatMode == Player.REPEAT_MODE_ALL) {
return getLastWindowIndex(shuffleModeEnabled);
}
return C.INDEX_UNSET; return C.INDEX_UNSET;
} }
@Override
public int getLastWindowIndex(boolean shuffleModeEnabled) {
int lastChildIndex = shuffleModeEnabled ? shuffleOrder.getLastIndex() : childCount - 1;
return getFirstWindowIndexByChildIndex(lastChildIndex)
+ getTimelineByChildIndex(lastChildIndex).getLastWindowIndex(shuffleModeEnabled);
} }
@Override
public int getFirstWindowIndex(boolean shuffleModeEnabled) {
int firstChildIndex = shuffleModeEnabled ? shuffleOrder.getFirstIndex() : 0;
return getFirstWindowIndexByChildIndex(firstChildIndex)
+ getTimelineByChildIndex(firstChildIndex).getFirstWindowIndex(shuffleModeEnabled);
} }
@Override @Override
......
...@@ -19,6 +19,7 @@ import com.google.android.exoplayer2.C; ...@@ -19,6 +19,7 @@ import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.ShuffleOrder.UnshuffledShuffleOrder;
import com.google.android.exoplayer2.upstream.Allocator; import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
...@@ -167,7 +168,7 @@ public final class ConcatenatingMediaSource implements MediaSource { ...@@ -167,7 +168,7 @@ public final class ConcatenatingMediaSource implements MediaSource {
private final boolean isRepeatOneAtomic; private final boolean isRepeatOneAtomic;
public ConcatenatedTimeline(Timeline[] timelines, boolean isRepeatOneAtomic) { public ConcatenatedTimeline(Timeline[] timelines, boolean isRepeatOneAtomic) {
super(timelines.length); super(new UnshuffledShuffleOrder(timelines.length));
int[] sourcePeriodOffsets = new int[timelines.length]; int[] sourcePeriodOffsets = new int[timelines.length];
int[] sourceWindowOffsets = new int[timelines.length]; int[] sourceWindowOffsets = new int[timelines.length];
long periodCount = 0; long periodCount = 0;
......
...@@ -23,6 +23,7 @@ import com.google.android.exoplayer2.ExoPlayer; ...@@ -23,6 +23,7 @@ import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.ExoPlayer.ExoPlayerComponent; import com.google.android.exoplayer2.ExoPlayer.ExoPlayerComponent;
import com.google.android.exoplayer2.ExoPlayer.ExoPlayerMessage; import com.google.android.exoplayer2.ExoPlayer.ExoPlayerMessage;
import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.ShuffleOrder.UnshuffledShuffleOrder;
import com.google.android.exoplayer2.trackselection.TrackSelection; import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.upstream.Allocator; import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
...@@ -397,7 +398,7 @@ public final class DynamicConcatenatingMediaSource implements MediaSource, ExoPl ...@@ -397,7 +398,7 @@ public final class DynamicConcatenatingMediaSource implements MediaSource, ExoPl
public ConcatenatedTimeline(Collection<MediaSourceHolder> mediaSourceHolders, int windowCount, public ConcatenatedTimeline(Collection<MediaSourceHolder> mediaSourceHolders, int windowCount,
int periodCount) { int periodCount) {
super(mediaSourceHolders.size()); super(new UnshuffledShuffleOrder(mediaSourceHolders.size()));
this.windowCount = windowCount; this.windowCount = windowCount;
this.periodCount = periodCount; this.periodCount = periodCount;
int childCount = mediaSourceHolders.size(); int childCount = mediaSourceHolders.size();
......
...@@ -19,6 +19,7 @@ import com.google.android.exoplayer2.C; ...@@ -19,6 +19,7 @@ import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.ShuffleOrder.UnshuffledShuffleOrder;
import com.google.android.exoplayer2.upstream.Allocator; import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import java.io.IOException; import java.io.IOException;
...@@ -101,7 +102,7 @@ public final class LoopingMediaSource implements MediaSource { ...@@ -101,7 +102,7 @@ public final class LoopingMediaSource implements MediaSource {
private final int loopCount; private final int loopCount;
public LoopingTimeline(Timeline childTimeline, int loopCount) { public LoopingTimeline(Timeline childTimeline, int loopCount) {
super(loopCount); super(new UnshuffledShuffleOrder(loopCount));
this.childTimeline = childTimeline; this.childTimeline = childTimeline;
childPeriodCount = childTimeline.getPeriodCount(); childPeriodCount = childTimeline.getPeriodCount();
childWindowCount = childTimeline.getWindowCount(); childWindowCount = childTimeline.getWindowCount();
......
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