use of androidx.media3.exoplayer.trackselection.AdaptiveTrackSelection in project media by androidx.
the class DefaultDashChunkSourceTest method createDashChunkSource.
private DashChunkSource createDashChunkSource(int numberOfTracks) throws IOException {
Assertions.checkArgument(numberOfTracks < 6);
DashManifest manifest = new DashManifestParser().parse(Uri.parse("https://example.com/test.mpd"), TestUtil.getInputStream(ApplicationProvider.getApplicationContext(), SAMPLE_MPD_VOD_LOCATION_FALLBACK));
int[] adaptationSetIndices = new int[] { 0 };
int[] selectedTracks = new int[numberOfTracks];
Format[] formats = new Format[numberOfTracks];
for (int i = 0; i < numberOfTracks; i++) {
selectedTracks[i] = i;
formats[i] = manifest.getPeriod(0).adaptationSets.get(adaptationSetIndices[0]).representations.get(i).format;
}
AdaptiveTrackSelection adaptiveTrackSelection = new AdaptiveTrackSelection(new TrackGroup(formats), selectedTracks, new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build());
return new DefaultDashChunkSource(BundledChunkExtractor.FACTORY, new LoaderErrorThrower.Dummy(), manifest, new BaseUrlExclusionList(new Random(/* seed= */
1234)), /* periodIndex= */
0, /* adaptationSetIndices= */
adaptationSetIndices, adaptiveTrackSelection, C.TRACK_TYPE_VIDEO, new FakeDataSource(), /* elapsedRealtimeOffsetMs= */
0, /* maxSegmentsPerLoad= */
1, /* enableEventMessageTrack= */
false, /* closedCaptionFormats */
ImmutableList.of(), /* playerTrackEmsgHandler= */
null, PlayerId.UNSET);
}
use of androidx.media3.exoplayer.trackselection.AdaptiveTrackSelection in project media by androidx.
the class AdaptiveTrackSelectionTest method initial_updateSelectedTrack_selectsHighestBitrateWithinBandwidthFraction.
@Test
public void initial_updateSelectedTrack_selectsHighestBitrateWithinBandwidthFraction() {
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);
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(2000L);
AdaptiveTrackSelection adaptiveTrackSelection = prepareAdaptiveTrackSelectionWithBandwidthFraction(trackGroup, /* bandwidthFraction= */
0.5f);
assertThat(adaptiveTrackSelection.getSelectedFormat()).isEqualTo(format2);
assertThat(adaptiveTrackSelection.getSelectionReason()).isEqualTo(C.SELECTION_REASON_INITIAL);
}
use of androidx.media3.exoplayer.trackselection.AdaptiveTrackSelection in project media by androidx.
the class AdaptiveTrackSelectionTest method evaluateQueueSizeReturnQueueSizeIfBandwidthIsNotImproved.
@Test
public void evaluateQueueSizeReturnQueueSizeIfBandwidthIsNotImproved() {
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);
FakeMediaChunk chunk1 = new FakeMediaChunk(format1, /* startTimeUs= */
0, /* endTimeUs= */
10_000_000);
FakeMediaChunk chunk2 = new FakeMediaChunk(format1, /* startTimeUs= */
10_000_000, /* endTimeUs= */
20_000_000);
FakeMediaChunk chunk3 = new FakeMediaChunk(format1, /* startTimeUs= */
20_000_000, /* endTimeUs= */
30_000_000);
List<FakeMediaChunk> queue = ImmutableList.of(chunk1, chunk2, chunk3);
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(500L);
AdaptiveTrackSelection adaptiveTrackSelection = prepareAdaptiveTrackSelection(trackGroup);
int size = adaptiveTrackSelection.evaluateQueueSize(0, queue);
assertThat(size).isEqualTo(3);
}
use of androidx.media3.exoplayer.trackselection.AdaptiveTrackSelection in project media by androidx.
the class AdaptiveTrackSelectionTest method updateSelectedTrackSwitchDownIfNotBufferedEnough.
@Test
public void updateSelectedTrackSwitchDownIfNotBufferedEnough() {
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 500L, which prompts the track selection to switch down
// if necessary.
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(1000L, 500L);
AdaptiveTrackSelection adaptiveTrackSelection = prepareAdaptiveTrackSelectionWithMaxDurationForQualityDecreaseMs(trackGroup, /* maxDurationForQualityDecreaseMs= */
25_000);
adaptiveTrackSelection.updateSelectedTrack(/* playbackPositionUs= */
0, /* bufferedDurationUs= */
24_999_000, /* availableDurationUs= */
C.TIME_UNSET, /* queue= */
Collections.emptyList(), createMediaChunkIterators(trackGroup, TEST_CHUNK_DURATION_US));
// When bandwidth estimation is updated to 500L, we should switch down to use a lower bitrate
// format. When we don't have enough buffer at higher quality (24_999_000 us is smaller than
// maxDurationForQualityDecreaseMs), we should switch down now.
assertThat(adaptiveTrackSelection.getSelectedFormat()).isEqualTo(format1);
assertThat(adaptiveTrackSelection.getSelectionReason()).isEqualTo(C.SELECTION_REASON_ADAPTIVE);
}
use of androidx.media3.exoplayer.trackselection.AdaptiveTrackSelection in project media by androidx.
the class AdaptiveTrackSelectionTest method evaluateQueueSizeDoNotReevaluateUntilAfterMinTimeBetweenBufferReevaluation.
@Test
public void evaluateQueueSizeDoNotReevaluateUntilAfterMinTimeBetweenBufferReevaluation() {
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);
FakeMediaChunk chunk1 = new FakeMediaChunk(format1, /* startTimeUs= */
0, /* endTimeUs= */
10_000_000);
FakeMediaChunk chunk2 = new FakeMediaChunk(format1, /* startTimeUs= */
10_000_000, /* endTimeUs= */
20_000_000);
FakeMediaChunk chunk3 = new FakeMediaChunk(format1, /* startTimeUs= */
20_000_000, /* endTimeUs= */
30_000_000);
List<FakeMediaChunk> queue = ImmutableList.of(chunk1, chunk2, chunk3);
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(500L);
AdaptiveTrackSelection adaptiveTrackSelection = prepareAdaptiveTrackSelectionWithMinTimeBetweenBufferReevaluationMs(trackGroup, /* durationToRetainAfterDiscardMs= */
15_000);
int initialQueueSize = adaptiveTrackSelection.evaluateQueueSize(0, queue);
fakeClock.advanceTime(999);
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(1000L);
// When the bandwidth estimation is updated, we should be able to discard chunks from the end of
// the queue. However, since the duration since the last evaluation (999ms) is less than 1000ms,
// we will not reevaluate the queue size and should not discard chunks.
int newSize = adaptiveTrackSelection.evaluateQueueSize(/* playbackPositionUs= */
0, queue);
assertThat(newSize).isEqualTo(initialQueueSize);
// Verify that the comment above is correct.
fakeClock.advanceTime(1);
newSize = adaptiveTrackSelection.evaluateQueueSize(/* playbackPositionUs= */
0, queue);
assertThat(newSize).isLessThan(initialQueueSize);
}
Aggregations