use of com.google.android.exoplayer2.Format in project ExoPlayer by google.
the class AdaptiveTrackSelectionTest method updateSelectedTrackSwitchUpIfBufferedEnough.
@Test
public void updateSelectedTrackSwitchUpIfBufferedEnough() {
Format format1 = videoFormat(/* bitrate= */
500, /* width= */
320, /* height= */
240);
Format format2 = videoFormat(/* bitrate= */
1000, /* width= */
640, /* height= */
480);
Format format3 = videoFormat(/* bitrate= */
2000, /* width= */
960, /* height= */
720);
TrackGroup trackGroup = new TrackGroup(format1, format2, format3);
// The second measurement onward returns 2000L, which prompts the track selection to switch up
// if possible.
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(1000L, 2000L);
AdaptiveTrackSelection adaptiveTrackSelection = prepareAdaptiveTrackSelectionWithMinDurationForQualityIncreaseMs(trackGroup, /* minDurationForQualityIncreaseMs= */
10_000);
adaptiveTrackSelection.updateSelectedTrack(/* playbackPositionUs= */
0, /* bufferedDurationUs= */
10_000_000, /* availableDurationUs= */
C.TIME_UNSET, /* queue= */
Collections.emptyList(), createMediaChunkIterators(trackGroup, TEST_CHUNK_DURATION_US));
// When bandwidth estimation is updated to 2000L, we can switch up to use a higher bitrate
// format. When we have buffered enough (10_000_000 us, which is equal to
// minDurationForQualityIncreaseMs), we should switch up now.
assertThat(adaptiveTrackSelection.getSelectedFormat()).isEqualTo(format3);
assertThat(adaptiveTrackSelection.getSelectionReason()).isEqualTo(C.SELECTION_REASON_ADAPTIVE);
}
use of com.google.android.exoplayer2.Format 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();
}
use of com.google.android.exoplayer2.Format in project ExoPlayer by google.
the class DefaultTrackSelectorTest method selectTracksSelectTrackWithSelectionFlag.
/**
* Tests that track selector will select audio track with {@link C#SELECTION_FLAG_DEFAULT} given
* default values of {@link Parameters}.
*/
@Test
public void selectTracksSelectTrackWithSelectionFlag() throws Exception {
Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
Format audioFormat = formatBuilder.setSelectionFlags(0).build();
Format formatWithSelectionFlag = formatBuilder.setSelectionFlags(C.SELECTION_FLAG_DEFAULT).build();
TrackGroupArray trackGroups = wrapFormats(audioFormat, formatWithSelectionFlag);
TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES }, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections[0], trackGroups, formatWithSelectionFlag);
}
use of com.google.android.exoplayer2.Format in project ExoPlayer by google.
the class DefaultTrackSelectorTest method selectTracksPreferTrackWithinCapabilities.
/**
* Tests that track selector will prefer tracks that are within renderer's capabilities over track
* that exceed renderer's capabilities.
*/
@Test
public void selectTracksPreferTrackWithinCapabilities() throws Exception {
Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
Format supportedFormat = formatBuilder.setId("supportedFormat").build();
Format exceededFormat = formatBuilder.setId("exceededFormat").build();
TrackGroupArray trackGroups = wrapFormats(exceededFormat, supportedFormat);
Map<String, Integer> mappedCapabilities = new HashMap<>();
mappedCapabilities.put(supportedFormat.id, FORMAT_HANDLED);
mappedCapabilities.put(exceededFormat.id, FORMAT_EXCEEDS_CAPABILITIES);
RendererCapabilities mappedAudioRendererCapabilities = new FakeMappedRendererCapabilities(C.TRACK_TYPE_AUDIO, mappedCapabilities);
TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { mappedAudioRendererCapabilities }, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections[0], trackGroups, supportedFormat);
}
use of com.google.android.exoplayer2.Format in project ExoPlayer by google.
the class DefaultTrackSelectorTest method textTrackSelectionFlags.
/**
* Tests text track selection flags.
*/
@Test
public void textTrackSelectionFlags() throws ExoPlaybackException {
Format.Builder formatBuilder = TEXT_FORMAT.buildUpon().setLanguage("eng");
Format forcedOnly = formatBuilder.setSelectionFlags(C.SELECTION_FLAG_FORCED).build();
Format forcedDefault = formatBuilder.setSelectionFlags(C.SELECTION_FLAG_FORCED | C.SELECTION_FLAG_DEFAULT).build();
Format defaultOnly = formatBuilder.setSelectionFlags(C.SELECTION_FLAG_DEFAULT).build();
Format noFlag = formatBuilder.setSelectionFlags(0).build();
RendererCapabilities[] textRendererCapabilities = new RendererCapabilities[] { ALL_TEXT_FORMAT_SUPPORTED_RENDERER_CAPABILITIES };
// There is no text language preference, the first track flagged as default should be selected.
TrackGroupArray trackGroups = wrapFormats(forcedOnly, forcedDefault, defaultOnly, noFlag);
TrackSelectorResult result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections[0], trackGroups, forcedDefault);
// Ditto.
trackGroups = wrapFormats(forcedOnly, noFlag, defaultOnly);
result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections[0], trackGroups, defaultOnly);
// Default flags are disabled and no language preference is provided, so no text track is
// selected.
trackGroups = wrapFormats(defaultOnly, noFlag, forcedOnly, forcedDefault);
trackSelector.setParameters(defaultParameters.buildUpon().setDisabledTextTrackSelectionFlags(C.SELECTION_FLAG_DEFAULT));
result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
assertNoSelection(result.selections[0]);
// All selection flags are disabled and there is no language preference, so nothing should be
// selected.
trackGroups = wrapFormats(forcedOnly, forcedDefault, defaultOnly, noFlag);
trackSelector.setParameters(trackSelector.getParameters().buildUpon().setDisabledTextTrackSelectionFlags(C.SELECTION_FLAG_DEFAULT | C.SELECTION_FLAG_FORCED));
result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
assertNoSelection(result.selections[0]);
// There is a preferred language, so a language-matching track flagged as default should
// be selected, and the one without forced flag should be preferred.
trackSelector.setParameters(defaultParameters.buildUpon().setPreferredTextLanguage("eng"));
result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections[0], trackGroups, defaultOnly);
// Same as above, but the default flag is disabled. If multiple tracks match the preferred
// language, those not flagged as forced are preferred, as they likely include the contents of
// forced subtitles.
trackGroups = wrapFormats(noFlag, forcedOnly, forcedDefault, defaultOnly);
trackSelector.setParameters(trackSelector.getParameters().buildUpon().setDisabledTextTrackSelectionFlags(C.SELECTION_FLAG_DEFAULT));
result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections[0], trackGroups, noFlag);
}
Aggregations