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;
* 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)} operation.
* TrackSelector#selectTracks(RendererCapabilities[], TrackGroupArray, MediaPeriodId)} operation.
*/
/* package */ final TrackSelectorResult emptyTrackSelectorResult;
......
......@@ -162,7 +162,7 @@ import com.google.android.exoplayer2.util.Log;
public boolean selectTracks(float playbackSpeed) throws ExoPlaybackException {
TrackSelectorResult selectorResult =
trackSelector.selectTracks(rendererCapabilities, trackGroups);
trackSelector.selectTracks(rendererCapabilities, trackGroups, info.id);
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.source.MediaSource.MediaPeriodId;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.util.Util;
......@@ -326,8 +327,11 @@ public abstract class MappingTrackSelector extends TrackSelector {
}
@Override
public final TrackSelectorResult selectTracks(RendererCapabilities[] rendererCapabilities,
TrackGroupArray trackGroups) throws ExoPlaybackException {
public final TrackSelectorResult selectTracks(
RendererCapabilities[] rendererCapabilities,
TrackGroupArray trackGroups,
MediaPeriodId periodId)
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
// any renderer.
......
......@@ -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.source.MediaSource.MediaPeriodId;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.upstream.BandwidthMeter;
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
* #init(InvalidationListener, BandwidthMeter)}.
* <li>When the player needs to make a track selection it will call {@link
* #selectTracks(RendererCapabilities[], TrackGroupArray)}. 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)}. 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
......@@ -66,14 +67,14 @@ import com.google.android.exoplayer2.util.Assertions;
* <h3>Renderer configuration</h3>
*
* The {@link TrackSelectorResult} returned by {@link #selectTracks(RendererCapabilities[],
* TrackGroupArray)} 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)} 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>
*
......@@ -117,15 +118,19 @@ public abstract class TrackSelector {
* @param rendererCapabilities The {@link RendererCapabilities} of the renderers for which tracks
* 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.
* @return A {@link TrackSelectorResult} describing the track selections.
* @throws ExoPlaybackException If an error occurs selecting tracks.
*/
public abstract TrackSelectorResult selectTracks(RendererCapabilities[] rendererCapabilities,
TrackGroupArray trackGroups) throws ExoPlaybackException;
public abstract TrackSelectorResult selectTracks(
RendererCapabilities[] rendererCapabilities,
TrackGroupArray trackGroups,
MediaPeriodId periodId)
throws ExoPlaybackException;
/**
* Called by the player when a {@link TrackSelectorResult} previously generated by
* {@link #selectTracks(RendererCapabilities[], TrackGroupArray)} is activated.
* Called by the player when a {@link TrackSelectorResult} previously generated by {@link
* #selectTracks(RendererCapabilities[], TrackGroupArray, MediaPeriodId)} is activated.
*
* @param info The value of {@link TrackSelectorResult#info} in the activated selection.
*/
......
......@@ -23,6 +23,7 @@ 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.source.MediaSource.MediaPeriodId;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.util.MimeTypes;
......@@ -51,6 +52,7 @@ 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());
/**
* Tests that the video and audio track groups are mapped onto the correct renderers.
......@@ -58,7 +60,7 @@ public final class MappingTrackSelectorTest {
@Test
public void testMapping() throws ExoPlaybackException {
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(1, AUDIO_TRACK_GROUP);
}
......@@ -72,7 +74,7 @@ public final class MappingTrackSelectorTest {
FakeMappingTrackSelector trackSelector = new FakeMappingTrackSelector();
RendererCapabilities[] reverseOrderRendererCapabilities = new RendererCapabilities[] {
AUDIO_CAPABILITIES, VIDEO_CAPABILITIES};
trackSelector.selectTracks(reverseOrderRendererCapabilities, TRACK_GROUPS);
trackSelector.selectTracks(reverseOrderRendererCapabilities, TRACK_GROUPS, PERIOD_ID);
trackSelector.assertMappedTrackGroups(0, AUDIO_TRACK_GROUP);
trackSelector.assertMappedTrackGroups(1, VIDEO_TRACK_GROUP);
}
......@@ -86,7 +88,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);
trackSelector.selectTracks(RENDERER_CAPABILITIES, multiTrackGroups, PERIOD_ID);
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.source.MediaSource.MediaPeriodId;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.trackselection.TrackSelector.InvalidationListener;
import com.google.android.exoplayer2.upstream.BandwidthMeter;
......@@ -37,16 +38,20 @@ public class TrackSelectorTest {
@Before
public void setUp() {
trackSelector = new TrackSelector() {
@Override
public TrackSelectorResult selectTracks(RendererCapabilities[] rendererCapabilities,
TrackGroupArray trackGroups) throws ExoPlaybackException {
throw new UnsupportedOperationException();
}
trackSelector =
new TrackSelector() {
@Override
public TrackSelectorResult selectTracks(
RendererCapabilities[] rendererCapabilities,
TrackGroupArray trackGroups,
MediaPeriodId periodId)
throws ExoPlaybackException {
throw new UnsupportedOperationException();
}
@Override
public void onSelectionActivated(Object info) {}
};
@Override
public void onSelectionActivated(Object info) {}
};
}
@Test
......
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