Commit 3073d38a by cblay Committed by Oliver Woodman

Pass MediaPeriodId to TrackSelector.selectTracks()

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=214638939
parent 776ad20a
...@@ -51,7 +51,7 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -51,7 +51,7 @@ 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)} operation. * TrackSelector#selectTracks(RendererCapabilities[], TrackGroupArray, MediaPeriodId)} operation.
*/ */
/* package */ final TrackSelectorResult emptyTrackSelectorResult; /* package */ final TrackSelectorResult emptyTrackSelectorResult;
......
...@@ -162,7 +162,7 @@ import com.google.android.exoplayer2.util.Log; ...@@ -162,7 +162,7 @@ import com.google.android.exoplayer2.util.Log;
public boolean selectTracks(float playbackSpeed) throws ExoPlaybackException { public boolean selectTracks(float playbackSpeed) throws ExoPlaybackException {
TrackSelectorResult selectorResult = TrackSelectorResult selectorResult =
trackSelector.selectTracks(rendererCapabilities, trackGroups); trackSelector.selectTracks(rendererCapabilities, trackGroups, info.id);
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.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.util.Util; import com.google.android.exoplayer2.util.Util;
...@@ -326,8 +327,11 @@ public abstract class MappingTrackSelector extends TrackSelector { ...@@ -326,8 +327,11 @@ public abstract class MappingTrackSelector extends TrackSelector {
} }
@Override @Override
public final TrackSelectorResult selectTracks(RendererCapabilities[] rendererCapabilities, public final TrackSelectorResult selectTracks(
TrackGroupArray trackGroups) throws ExoPlaybackException { RendererCapabilities[] rendererCapabilities,
TrackGroupArray trackGroups,
MediaPeriodId periodId)
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
// any renderer. // any renderer.
......
...@@ -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.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;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
...@@ -40,9 +41,9 @@ import com.google.android.exoplayer2.util.Assertions; ...@@ -40,9 +41,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)}. This typically occurs at the start * #selectTracks(RendererCapabilities[], TrackGroupArray, MediaPeriodId)}. This typically
* of playback, when the player starts to buffer a new period of the media being played, and * occurs at the start of playback, when the player starts to buffer a new period of the media
* when the track selector invalidates its previous selections. * 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
...@@ -66,14 +67,14 @@ import com.google.android.exoplayer2.util.Assertions; ...@@ -66,14 +67,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)} contains not only {@link TrackSelection}s for each renderer, but also {@link * TrackGroupArray, MediaPeriodId)} contains not only {@link TrackSelection}s for each renderer, but
* RendererConfiguration}s defining configuration parameters that the renderers should apply when * also {@link RendererConfiguration}s defining configuration parameters that the renderers should
* consuming the corresponding media. Whilst it may seem counter-intuitive for a track selector to * apply when consuming the corresponding media. Whilst it may seem counter-intuitive for a track
* also specify renderer configuration information, in practice the two are tightly bound together. * selector to also specify renderer configuration information, in practice the two are tightly
* It may only be possible to play a certain combination tracks if the renderers are configured in a * bound together. It may only be possible to play a certain combination tracks if the renderers are
* particular way. Equally, it may only be possible to configure renderers in a particular way if * configured in a particular way. Equally, it may only be possible to configure renderers in a
* certain tracks are selected. Hence it makes sense to determined the track selection and * particular way if certain tracks are selected. Hence it makes sense to determined the track
* corresponding renderer configurations in a single step. * selection and corresponding renderer configurations in a single step.
* *
* <h3>Threading model</h3> * <h3>Threading model</h3>
* *
...@@ -117,15 +118,19 @@ public abstract class TrackSelector { ...@@ -117,15 +118,19 @@ public abstract class TrackSelector {
* @param rendererCapabilities The {@link RendererCapabilities} of the renderers for which tracks * @param rendererCapabilities The {@link RendererCapabilities} of the renderers for which tracks
* 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.
* @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(RendererCapabilities[] rendererCapabilities, public abstract TrackSelectorResult selectTracks(
TrackGroupArray trackGroups) throws ExoPlaybackException; RendererCapabilities[] rendererCapabilities,
TrackGroupArray trackGroups,
MediaPeriodId periodId)
throws ExoPlaybackException;
/** /**
* Called by the player when a {@link TrackSelectorResult} previously generated by * Called by the player when a {@link TrackSelectorResult} previously generated by {@link
* {@link #selectTracks(RendererCapabilities[], TrackGroupArray)} is activated. * #selectTracks(RendererCapabilities[], TrackGroupArray, MediaPeriodId)} 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,6 +23,7 @@ import com.google.android.exoplayer2.ExoPlaybackException; ...@@ -23,6 +23,7 @@ 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.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.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
...@@ -51,6 +52,7 @@ public final class MappingTrackSelectorTest { ...@@ -51,6 +52,7 @@ 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());
/** /**
* 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.
...@@ -58,7 +60,7 @@ public final class MappingTrackSelectorTest { ...@@ -58,7 +60,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); trackSelector.selectTracks(RENDERER_CAPABILITIES, TRACK_GROUPS, PERIOD_ID);
trackSelector.assertMappedTrackGroups(0, VIDEO_TRACK_GROUP); trackSelector.assertMappedTrackGroups(0, VIDEO_TRACK_GROUP);
trackSelector.assertMappedTrackGroups(1, AUDIO_TRACK_GROUP); trackSelector.assertMappedTrackGroups(1, AUDIO_TRACK_GROUP);
} }
...@@ -72,7 +74,7 @@ public final class MappingTrackSelectorTest { ...@@ -72,7 +74,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); trackSelector.selectTracks(reverseOrderRendererCapabilities, TRACK_GROUPS, PERIOD_ID);
trackSelector.assertMappedTrackGroups(0, AUDIO_TRACK_GROUP); trackSelector.assertMappedTrackGroups(0, AUDIO_TRACK_GROUP);
trackSelector.assertMappedTrackGroups(1, VIDEO_TRACK_GROUP); trackSelector.assertMappedTrackGroups(1, VIDEO_TRACK_GROUP);
} }
...@@ -86,7 +88,7 @@ public final class MappingTrackSelectorTest { ...@@ -86,7 +88,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); trackSelector.selectTracks(RENDERER_CAPABILITIES, multiTrackGroups, PERIOD_ID);
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.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;
import com.google.android.exoplayer2.upstream.BandwidthMeter; import com.google.android.exoplayer2.upstream.BandwidthMeter;
...@@ -37,10 +38,14 @@ public class TrackSelectorTest { ...@@ -37,10 +38,14 @@ public class TrackSelectorTest {
@Before @Before
public void setUp() { public void setUp() {
trackSelector = new TrackSelector() { trackSelector =
new TrackSelector() {
@Override @Override
public TrackSelectorResult selectTracks(RendererCapabilities[] rendererCapabilities, public TrackSelectorResult selectTracks(
TrackGroupArray trackGroups) throws ExoPlaybackException { RendererCapabilities[] rendererCapabilities,
TrackGroupArray trackGroups,
MediaPeriodId periodId)
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