use of com.google.android.exoplayer2.trackselection.ExoTrackSelection.Definition in project ExoPlayer by google.
the class DefaultTrackSelector method getLegacyRendererOverride.
// Calling deprecated getSelectionOverride.
@SuppressWarnings("deprecation")
private ExoTrackSelection.@NullableType Definition getLegacyRendererOverride(MappedTrackInfo mappedTrackInfo, Parameters params, int rendererIndex) {
TrackGroupArray rendererTrackGroups = mappedTrackInfo.getTrackGroups(rendererIndex);
@Nullable SelectionOverride override = params.getSelectionOverride(rendererIndex, rendererTrackGroups);
if (override == null) {
return null;
}
return new ExoTrackSelection.Definition(rendererTrackGroups.get(override.groupIndex), override.tracks, override.type);
}
use of com.google.android.exoplayer2.trackselection.ExoTrackSelection.Definition in project ExoPlayer by google.
the class TrackSelectionUtil method createTrackSelectionsForDefinitions.
/**
* Creates track selections for an array of track selection definitions, with at most one
* multi-track adaptive selection.
*
* @param definitions The list of track selection {@link Definition definitions}. May include null
* values.
* @param adaptiveTrackSelectionFactory A factory for the multi-track adaptive track selection.
* @return The array of created track selection. For null entries in {@code definitions} returns
* null values.
*/
@NullableType
public static ExoTrackSelection[] createTrackSelectionsForDefinitions(@NullableType Definition[] definitions, AdaptiveTrackSelectionFactory adaptiveTrackSelectionFactory) {
ExoTrackSelection[] selections = new ExoTrackSelection[definitions.length];
boolean createdAdaptiveTrackSelection = false;
for (int i = 0; i < definitions.length; i++) {
Definition definition = definitions[i];
if (definition == null) {
continue;
}
if (definition.tracks.length > 1 && !createdAdaptiveTrackSelection) {
createdAdaptiveTrackSelection = true;
selections[i] = adaptiveTrackSelectionFactory.createAdaptiveTrackSelection(definition);
} else {
selections[i] = new FixedTrackSelection(definition.group, definition.tracks[0], /* type= */
definition.type);
}
}
return selections;
}
use of com.google.android.exoplayer2.trackselection.ExoTrackSelection.Definition in project ExoPlayer by google.
the class MergingMediaPeriodTest method prepareMergingPeriod.
private MergingMediaPeriod prepareMergingPeriod(MergingPeriodDefinition... definitions) throws Exception {
MediaPeriod[] mediaPeriods = new MediaPeriod[definitions.length];
long[] timeOffsetsUs = new long[definitions.length];
for (int i = 0; i < definitions.length; i++) {
MergingPeriodDefinition definition = definitions[i];
timeOffsetsUs[i] = definition.timeOffsetUs;
TrackGroup[] trackGroups = new TrackGroup[definition.formats.length];
for (int j = 0; j < definition.formats.length; j++) {
trackGroups[j] = new TrackGroup(definition.formats[j]);
}
mediaPeriods[i] = new FakeMediaPeriodWithSelectTracksPosition(new TrackGroupArray(trackGroups), new EventDispatcher().withParameters(/* windowIndex= */
i, new MediaPeriodId(/* periodUid= */
i), /* mediaTimeOffsetMs= */
0), /* trackDataFactory= */
(unusedFormat, unusedMediaPeriodId) -> ImmutableList.of(oneByteSample(definition.singleSampleTimeUs, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM));
}
MergingMediaPeriod mergingMediaPeriod = new MergingMediaPeriod(new DefaultCompositeSequenceableLoaderFactory(), timeOffsetsUs, mediaPeriods);
CountDownLatch prepareCountDown = new CountDownLatch(1);
mergingMediaPeriod.prepare(new MediaPeriod.Callback() {
@Override
public void onPrepared(MediaPeriod mediaPeriod) {
prepareCountDown.countDown();
}
@Override
public void onContinueLoadingRequested(MediaPeriod source) {
mergingMediaPeriod.continueLoading(/* positionUs= */
0);
}
}, /* positionUs= */
0);
prepareCountDown.await();
return mergingMediaPeriod;
}
use of com.google.android.exoplayer2.trackselection.ExoTrackSelection.Definition in project ExoPlayer by google.
the class AdaptiveTrackSelectionTest method builderCreateTrackSelections_withMultipleAdaptiveGroups_usesCorrectAdaptationCheckpoints.
@Test
public void builderCreateTrackSelections_withMultipleAdaptiveGroups_usesCorrectAdaptationCheckpoints() {
Format group1Format1 = new Format.Builder().setAverageBitrate(500).build();
Format group1Format2 = new Format.Builder().setAverageBitrate(1000).build();
Format group2Format1 = new Format.Builder().setAverageBitrate(250).build();
Format group2Format2 = new Format.Builder().setAverageBitrate(500).build();
Format group2Format3 = new Format.Builder().setAverageBitrate(1250).build();
Format group2UnusedFormat = new Format.Builder().setAverageBitrate(2000).build();
Format fixedFormat = new Format.Builder().setAverageBitrate(5000).build();
TrackGroup trackGroup1 = new TrackGroup(group1Format1, group1Format2);
TrackGroup trackGroup2 = new TrackGroup(group2Format1, group2Format2, group2Format3, group2UnusedFormat);
TrackGroup fixedGroup = new TrackGroup(fixedFormat);
Definition definition1 = new Definition(trackGroup1, /* tracks...= */
0, 1);
Definition definition2 = new Definition(trackGroup2, /* tracks...= */
0, 1, 2);
Definition fixedDefinition = new Definition(fixedGroup, /* tracks...= */
0);
List<List<AdaptationCheckpoint>> checkPoints = new ArrayList<>();
AdaptiveTrackSelection.Factory factory = new AdaptiveTrackSelection.Factory() {
@Override
protected AdaptiveTrackSelection createAdaptiveTrackSelection(TrackGroup group, int[] tracks, int type, BandwidthMeter bandwidthMeter, ImmutableList<AdaptationCheckpoint> adaptationCheckpoints) {
checkPoints.add(adaptationCheckpoints);
return super.createAdaptiveTrackSelection(group, tracks, TrackSelection.TYPE_UNSET, bandwidthMeter, adaptationCheckpoints);
}
};
Timeline timeline = new FakeTimeline();
factory.createTrackSelections(new Definition[] { null, definition1, fixedDefinition, definition2, null }, mockBandwidthMeter, new MediaSource.MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
0)), timeline);
assertThat(checkPoints).hasSize(2);
assertThat(checkPoints.get(0)).containsExactly(new AdaptationCheckpoint(/* totalBandwidth= */
0, /* allocatedBandwidth= */
0), new AdaptationCheckpoint(/* totalBandwidth= */
5750, /* allocatedBandwidth= */
500), new AdaptationCheckpoint(/* totalBandwidth= */
6000, /* allocatedBandwidth= */
500), new AdaptationCheckpoint(/* totalBandwidth= */
6500, /* allocatedBandwidth= */
1000), new AdaptationCheckpoint(/* totalBandwidth= */
7250, /* allocatedBandwidth= */
1000), new AdaptationCheckpoint(/* totalBandwidth= */
9500, /* allocatedBandwidth= */
2000)).inOrder();
assertThat(checkPoints.get(1)).containsExactly(new AdaptationCheckpoint(/* totalBandwidth= */
0, /* allocatedBandwidth= */
0), new AdaptationCheckpoint(/* totalBandwidth= */
5750, /* allocatedBandwidth= */
250), new AdaptationCheckpoint(/* totalBandwidth= */
6000, /* allocatedBandwidth= */
500), new AdaptationCheckpoint(/* totalBandwidth= */
6500, /* allocatedBandwidth= */
500), new AdaptationCheckpoint(/* totalBandwidth= */
7250, /* allocatedBandwidth= */
1250), new AdaptationCheckpoint(/* totalBandwidth= */
9500, /* allocatedBandwidth= */
2500)).inOrder();
}
use of com.google.android.exoplayer2.trackselection.ExoTrackSelection.Definition in project ExoPlayer by google.
the class AdaptiveTrackSelectionTest method builderCreateTrackSelections_withSingleAdaptiveGroup_usesCorrectAdaptationCheckpoints.
@Test
public void builderCreateTrackSelections_withSingleAdaptiveGroup_usesCorrectAdaptationCheckpoints() {
Format formatFixed1 = new Format.Builder().setAverageBitrate(500).build();
Format formatFixed2 = new Format.Builder().setAverageBitrate(1000).build();
Format formatAdaptive1 = new Format.Builder().setAverageBitrate(2000).build();
Format formatAdaptive2 = new Format.Builder().setAverageBitrate(3000).build();
Format formatAdaptive3 = new Format.Builder().setAverageBitrate(4000).build();
Format formatAdaptive4 = new Format.Builder().setAverageBitrate(5000).build();
TrackGroup trackGroupMultipleFixed = new TrackGroup(formatFixed1, formatFixed2);
TrackGroup trackGroupAdaptive = new TrackGroup(formatAdaptive1, formatAdaptive2, formatAdaptive3, formatAdaptive4);
Definition definitionFixed1 = new Definition(trackGroupMultipleFixed, /* tracks...= */
0);
Definition definitionFixed2 = new Definition(trackGroupMultipleFixed, /* tracks...= */
1);
Definition definitionAdaptive = new Definition(trackGroupAdaptive, /* tracks...= */
1, 2, 3);
List<List<AdaptationCheckpoint>> checkPoints = new ArrayList<>();
AdaptiveTrackSelection.Factory factory = new AdaptiveTrackSelection.Factory() {
@Override
protected AdaptiveTrackSelection createAdaptiveTrackSelection(TrackGroup group, int[] tracks, int type, BandwidthMeter bandwidthMeter, ImmutableList<AdaptationCheckpoint> adaptationCheckpoints) {
checkPoints.add(adaptationCheckpoints);
return super.createAdaptiveTrackSelection(group, tracks, TrackSelection.TYPE_UNSET, bandwidthMeter, adaptationCheckpoints);
}
};
Timeline timeline = new FakeTimeline();
factory.createTrackSelections(new Definition[] { null, definitionFixed1, null, definitionFixed2, definitionAdaptive }, mockBandwidthMeter, new MediaSource.MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
0)), timeline);
assertThat(checkPoints).hasSize(1);
assertThat(checkPoints.get(0)).containsExactly(new AdaptationCheckpoint(/* totalBandwidth= */
0, /* allocatedBandwidth= */
0), new AdaptationCheckpoint(/* totalBandwidth= */
4500, /* allocatedBandwidth= */
3000), new AdaptationCheckpoint(/* totalBandwidth= */
5500, /* allocatedBandwidth= */
4000), new AdaptationCheckpoint(/* totalBandwidth= */
6500, /* allocatedBandwidth= */
5000), new AdaptationCheckpoint(/* totalBandwidth= */
11500, /* allocatedBandwidth= */
10000)).inOrder();
}
Aggregations