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