Commit d487b599 by cblay Committed by Oliver Woodman

Also plumb new Timeline through to TrackSelector.selectTracks() so periodId is useful

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=214650418
parent 3073d38a
......@@ -51,7 +51,8 @@ import java.util.concurrent.CopyOnWriteArraySet;
* This empty track selector result can only be used for {@link PlaybackInfo#trackSelectorResult}
* when the player does not have any track selection made (such as when player is reset, or when
* player seeks to an unprepared period). It will not be used as result of any {@link
* TrackSelector#selectTracks(RendererCapabilities[], TrackGroupArray, MediaPeriodId)} operation.
* TrackSelector#selectTracks(RendererCapabilities[], TrackGroupArray, MediaPeriodId, Timeline)}
* operation.
*/
/* package */ final TrackSelectorResult emptyTrackSelectorResult;
......
......@@ -998,7 +998,7 @@ import java.util.Collections;
// The reselection did not change any prepared periods.
return;
}
if (periodHolder.selectTracks(playbackSpeed)) {
if (periodHolder.selectTracks(playbackSpeed, playbackInfo.timeline)) {
// Selected tracks have changed for this period.
break;
}
......@@ -1531,7 +1531,8 @@ import java.util.Collections;
return;
}
MediaPeriodHolder loadingPeriodHolder = queue.getLoadingPeriod();
loadingPeriodHolder.handlePrepared(mediaClock.getPlaybackParameters().speed);
loadingPeriodHolder.handlePrepared(
mediaClock.getPlaybackParameters().speed, playbackInfo.timeline);
updateLoadControlTrackSelection(
loadingPeriodHolder.trackGroups, loadingPeriodHolder.trackSelectorResult);
if (!queue.hasPlayingPeriod()) {
......
......@@ -140,10 +140,10 @@ import com.google.android.exoplayer2.util.Log;
return !prepared ? 0 : mediaPeriod.getNextLoadPositionUs();
}
public void handlePrepared(float playbackSpeed) throws ExoPlaybackException {
public void handlePrepared(float playbackSpeed, Timeline timeline) throws ExoPlaybackException {
prepared = true;
trackGroups = mediaPeriod.getTrackGroups();
selectTracks(playbackSpeed);
selectTracks(playbackSpeed, timeline);
long newStartPositionUs = applyTrackSelection(info.startPositionUs, false);
rendererPositionOffsetUs += info.startPositionUs - newStartPositionUs;
info = info.copyWithStartPositionUs(newStartPositionUs);
......@@ -160,9 +160,9 @@ import com.google.android.exoplayer2.util.Log;
mediaPeriod.continueLoading(loadingPeriodPositionUs);
}
public boolean selectTracks(float playbackSpeed) throws ExoPlaybackException {
public boolean selectTracks(float playbackSpeed, Timeline timeline) throws ExoPlaybackException {
TrackSelectorResult selectorResult =
trackSelector.selectTracks(rendererCapabilities, trackGroups, info.id);
trackSelector.selectTracks(rendererCapabilities, trackGroups, info.id, timeline);
if (selectorResult.isEquivalent(periodTrackSelectorResult)) {
return false;
}
......
......@@ -23,6 +23,7 @@ import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.Renderer;
import com.google.android.exoplayer2.RendererCapabilities;
import com.google.android.exoplayer2.RendererConfiguration;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray;
......@@ -330,7 +331,8 @@ public abstract class MappingTrackSelector extends TrackSelector {
public final TrackSelectorResult selectTracks(
RendererCapabilities[] rendererCapabilities,
TrackGroupArray trackGroups,
MediaPeriodId periodId)
MediaPeriodId periodId,
Timeline timeline)
throws ExoPlaybackException {
// Structures into which data will be written during the selection. The extra item at the end
// of each array is to store data associated with track groups that cannot be associated with
......
......@@ -21,6 +21,7 @@ import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.Renderer;
import com.google.android.exoplayer2.RendererCapabilities;
import com.google.android.exoplayer2.RendererConfiguration;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.upstream.BandwidthMeter;
......@@ -41,9 +42,9 @@ import com.google.android.exoplayer2.util.Assertions;
* <li>When the player is created it will initialize the track selector by calling {@link
* #init(InvalidationListener, BandwidthMeter)}.
* <li>When the player needs to make a track selection it will call {@link
* #selectTracks(RendererCapabilities[], TrackGroupArray, MediaPeriodId)}. This typically
* occurs at the start of playback, when the player starts to buffer a new period of the media
* being played, and when the track selector invalidates its previous selections.
* #selectTracks(RendererCapabilities[], TrackGroupArray, MediaPeriodId, Timeline)}. This
* typically occurs at the start of playback, when the player starts to buffer a new period of
* the media being played, and when the track selector invalidates its previous selections.
* <li>The player may perform a track selection well in advance of the selected tracks becoming
* active, where active is defined to mean that the renderers are actually consuming media
* corresponding to the selection that was made. For example when playing media containing
......@@ -67,14 +68,14 @@ import com.google.android.exoplayer2.util.Assertions;
* <h3>Renderer configuration</h3>
*
* The {@link TrackSelectorResult} returned by {@link #selectTracks(RendererCapabilities[],
* TrackGroupArray, MediaPeriodId)} contains not only {@link TrackSelection}s for each renderer, but
* also {@link RendererConfiguration}s defining configuration parameters that the renderers should
* apply when consuming the corresponding media. Whilst it may seem counter-intuitive for a track
* selector to also specify renderer configuration information, in practice the two are tightly
* bound together. It may only be possible to play a certain combination tracks if the renderers are
* configured in a particular way. Equally, it may only be possible to configure renderers in a
* particular way if certain tracks are selected. Hence it makes sense to determined the track
* selection and corresponding renderer configurations in a single step.
* TrackGroupArray, MediaPeriodId, Timeline)} contains not only {@link TrackSelection}s for each
* renderer, but also {@link RendererConfiguration}s defining configuration parameters that the
* renderers should apply when consuming the corresponding media. Whilst it may seem counter-
* intuitive for a track selector to also specify renderer configuration information, in practice
* the two are tightly bound together. It may only be possible to play a certain combination tracks
* if the renderers are configured in a particular way. Equally, it may only be possible to
* configure renderers in a particular way if certain tracks are selected. Hence it makes sense to
* determined the track selection and corresponding renderer configurations in a single step.
*
* <h3>Threading model</h3>
*
......@@ -119,18 +120,20 @@ public abstract class TrackSelector {
* are to be selected.
* @param trackGroups The available track groups.
* @param periodId The {@link MediaPeriodId} of the period for which tracks are to be selected.
* @param timeline The {@link Timeline} holding the period for which tracks are to be selected.
* @return A {@link TrackSelectorResult} describing the track selections.
* @throws ExoPlaybackException If an error occurs selecting tracks.
*/
public abstract TrackSelectorResult selectTracks(
RendererCapabilities[] rendererCapabilities,
TrackGroupArray trackGroups,
MediaPeriodId periodId)
MediaPeriodId periodId,
Timeline timeline)
throws ExoPlaybackException;
/**
* Called by the player when a {@link TrackSelectorResult} previously generated by {@link
* #selectTracks(RendererCapabilities[], TrackGroupArray, MediaPeriodId)} is activated.
* #selectTracks(RendererCapabilities[], TrackGroupArray, MediaPeriodId, Timeline)} is activated.
*
* @param info The value of {@link TrackSelectorResult#info} in the activated selection.
*/
......
......@@ -23,10 +23,13 @@ import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.RendererCapabilities;
import com.google.android.exoplayer2.RendererConfiguration;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.testutil.FakeTimeline;
import com.google.android.exoplayer2.util.MimeTypes;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
......@@ -52,7 +55,14 @@ public final class MappingTrackSelectorTest {
Format.NO_VALUE, 2, 44100, null, null, 0, null));
private static final TrackGroupArray TRACK_GROUPS = new TrackGroupArray(
VIDEO_TRACK_GROUP, AUDIO_TRACK_GROUP);
private static final MediaPeriodId PERIOD_ID = new MediaPeriodId(/* periodUid= */ new Object());
private static final Timeline TIMELINE = new FakeTimeline(/* windowCount= */ 1);
private static MediaPeriodId periodId;
@BeforeClass
public static void setUpBeforeClass() {
periodId = new MediaPeriodId(TIMELINE.getUidOfPeriod(/* periodIndex= */ 0));
}
/**
* Tests that the video and audio track groups are mapped onto the correct renderers.
......@@ -60,7 +70,7 @@ public final class MappingTrackSelectorTest {
@Test
public void testMapping() throws ExoPlaybackException {
FakeMappingTrackSelector trackSelector = new FakeMappingTrackSelector();
trackSelector.selectTracks(RENDERER_CAPABILITIES, TRACK_GROUPS, PERIOD_ID);
trackSelector.selectTracks(RENDERER_CAPABILITIES, TRACK_GROUPS, periodId, TIMELINE);
trackSelector.assertMappedTrackGroups(0, VIDEO_TRACK_GROUP);
trackSelector.assertMappedTrackGroups(1, AUDIO_TRACK_GROUP);
}
......@@ -74,7 +84,7 @@ public final class MappingTrackSelectorTest {
FakeMappingTrackSelector trackSelector = new FakeMappingTrackSelector();
RendererCapabilities[] reverseOrderRendererCapabilities = new RendererCapabilities[] {
AUDIO_CAPABILITIES, VIDEO_CAPABILITIES};
trackSelector.selectTracks(reverseOrderRendererCapabilities, TRACK_GROUPS, PERIOD_ID);
trackSelector.selectTracks(reverseOrderRendererCapabilities, TRACK_GROUPS, periodId, TIMELINE);
trackSelector.assertMappedTrackGroups(0, AUDIO_TRACK_GROUP);
trackSelector.assertMappedTrackGroups(1, VIDEO_TRACK_GROUP);
}
......@@ -88,7 +98,7 @@ public final class MappingTrackSelectorTest {
FakeMappingTrackSelector trackSelector = new FakeMappingTrackSelector();
TrackGroupArray multiTrackGroups = new TrackGroupArray(VIDEO_TRACK_GROUP, AUDIO_TRACK_GROUP,
VIDEO_TRACK_GROUP);
trackSelector.selectTracks(RENDERER_CAPABILITIES, multiTrackGroups, PERIOD_ID);
trackSelector.selectTracks(RENDERER_CAPABILITIES, multiTrackGroups, periodId, TIMELINE);
trackSelector.assertMappedTrackGroups(0, VIDEO_TRACK_GROUP, VIDEO_TRACK_GROUP);
trackSelector.assertMappedTrackGroups(1, AUDIO_TRACK_GROUP);
}
......
......@@ -20,6 +20,7 @@ import static org.junit.Assert.fail;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.RendererCapabilities;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.trackselection.TrackSelector.InvalidationListener;
......@@ -44,7 +45,8 @@ public class TrackSelectorTest {
public TrackSelectorResult selectTracks(
RendererCapabilities[] rendererCapabilities,
TrackGroupArray trackGroups,
MediaPeriodId periodId)
MediaPeriodId periodId,
Timeline timeline)
throws ExoPlaybackException {
throw new UnsupportedOperationException();
}
......
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