use of androidx.media3.exoplayer.trackselection.AdaptiveTrackSelection in project media by androidx.
the class AdaptiveTrackSelectionTest method evaluateQueueSizeRetainMoreThanMinimumDurationAfterDiscard.
@Test
public void evaluateQueueSizeRetainMoreThanMinimumDurationAfterDiscard() {
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);
assertThat(initialQueueSize).isEqualTo(3);
fakeClock.advanceTime(2000);
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(1000L);
// When bandwidth estimation is updated and time has advanced enough, we can discard chunks at
// the end of the queue now.
// However, since duration to retain after discard = 15 000 ms, we need to retain at least the
// first 2 chunks
int newSize = adaptiveTrackSelection.evaluateQueueSize(0, queue);
assertThat(newSize).isEqualTo(2);
}
use of androidx.media3.exoplayer.trackselection.AdaptiveTrackSelection in project media by androidx.
the class AdaptiveTrackSelectionTest method initial_updateSelectedTrack_selectsHighestBitrateWithinBandwidthAndTimeToFirstByte.
@Test
public void initial_updateSelectedTrack_selectsHighestBitrateWithinBandwidthAndTimeToFirstByte() {
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);
when(mockBandwidthMeter.getTimeToFirstByteEstimateUs()).thenReturn(1_000_000L);
AdaptiveTrackSelection adaptiveTrackSelection = prepareAdaptiveTrackSelectionWithBandwidthFraction(trackGroup, /* bandwidthFraction= */
1f);
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 initial_updateSelectedTrack_selectsHighestBitrateWithinBandwidth.
@Test
public void initial_updateSelectedTrack_selectsHighestBitrateWithinBandwidth() {
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(1000L);
AdaptiveTrackSelection adaptiveTrackSelection = prepareAdaptiveTrackSelectionWithBandwidthFraction(trackGroup, /* bandwidthFraction= */
1f);
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 updateSelectedTrack_withQueueOfUnknownFormats_doesntThrow.
@Test
public void updateSelectedTrack_withQueueOfUnknownFormats_doesntThrow() {
Format format1 = videoFormat(/* bitrate= */
500, /* width= */
320, /* height= */
240);
Format format2 = videoFormat(/* bitrate= */
1000, /* width= */
640, /* height= */
480);
TrackGroup trackGroup = new TrackGroup(format1, format2);
AdaptiveTrackSelection adaptiveTrackSelection = prepareTrackSelection(prepareAdaptiveTrackSelection(trackGroup));
Format unknownFormat = videoFormat(/* bitrate= */
42, /* width= */
300, /* height= */
123);
FakeMediaChunk chunk = new FakeMediaChunk(unknownFormat, /* startTimeUs= */
0, /* endTimeUs= */
2_000_000);
List<FakeMediaChunk> queue = ImmutableList.of(chunk);
adaptiveTrackSelection.updateSelectedTrack(/* playbackPositionUs= */
0, /* bufferedDurationUs= */
2_000_000, /* availableDurationUs= */
C.TIME_UNSET, queue, createMediaChunkIterators(trackGroup, TEST_CHUNK_DURATION_US));
assertThat(adaptiveTrackSelection.getSelectedFormat()).isAnyOf(format1, format2);
}
use of androidx.media3.exoplayer.trackselection.AdaptiveTrackSelection in project media by androidx.
the class AdaptiveTrackSelectionTest method updateSelectedTrack_withAdaptationCheckpoints_usesOnlyAllocatedBandwidth.
@Test
public void updateSelectedTrack_withAdaptationCheckpoints_usesOnlyAllocatedBandwidth() {
Format format0 = videoFormat(/* bitrate= */
100, /* width= */
160, /* height= */
120);
Format format1 = videoFormat(/* bitrate= */
500, /* width= */
320, /* height= */
240);
Format format2 = videoFormat(/* bitrate= */
1000, /* width= */
640, /* height= */
480);
Format format3 = videoFormat(/* bitrate= */
1500, /* width= */
1024, /* height= */
768);
TrackGroup trackGroup = new TrackGroup(format0, format1, format2, format3);
// Choose checkpoints relative to formats so that one is in the first range, one somewhere in
// the middle, and one needs to extrapolate beyond the last checkpoint.
List<AdaptationCheckpoint> checkpoints = ImmutableList.of(new AdaptationCheckpoint(/* totalBandwidth= */
0, /* allocatedBandwidth= */
0), new AdaptationCheckpoint(/* totalBandwidth= */
1500, /* allocatedBandwidth= */
750), new AdaptationCheckpoint(/* totalBandwidth= */
3000, /* allocatedBandwidth= */
750), new AdaptationCheckpoint(/* totalBandwidth= */
4000, /* allocatedBandwidth= */
1250), new AdaptationCheckpoint(/* totalBandwidth= */
5000, /* allocatedBandwidth= */
1300));
AdaptiveTrackSelection adaptiveTrackSelection = prepareTrackSelection(prepareAdaptiveTrackSelectionWithAdaptationCheckpoints(trackGroup, checkpoints));
// Ensure format0 is selected initially so that we can assert the upswitches.
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(1L);
adaptiveTrackSelection.updateSelectedTrack(/* playbackPositionUs= */
0, /* bufferedDurationUs= */
999_999_999_999L, /* availableDurationUs= */
C.TIME_UNSET, /* queue= */
ImmutableList.of(), createMediaChunkIterators(trackGroup, TEST_CHUNK_DURATION_US));
assertThat(adaptiveTrackSelection.getSelectedFormat()).isEqualTo(format0);
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(999L);
adaptiveTrackSelection.updateSelectedTrack(/* playbackPositionUs= */
0, /* bufferedDurationUs= */
999_999_999_999L, /* availableDurationUs= */
C.TIME_UNSET, /* queue= */
ImmutableList.of(), createMediaChunkIterators(trackGroup, TEST_CHUNK_DURATION_US));
assertThat(adaptiveTrackSelection.getSelectedFormat()).isEqualTo(format0);
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(1000L);
adaptiveTrackSelection.updateSelectedTrack(/* playbackPositionUs= */
0, /* bufferedDurationUs= */
999_999_999_999L, /* availableDurationUs= */
C.TIME_UNSET, /* queue= */
ImmutableList.of(), createMediaChunkIterators(trackGroup, TEST_CHUNK_DURATION_US));
assertThat(adaptiveTrackSelection.getSelectedFormat()).isEqualTo(format1);
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(2499L);
adaptiveTrackSelection.updateSelectedTrack(/* playbackPositionUs= */
0, /* bufferedDurationUs= */
999_999_999_999L, /* availableDurationUs= */
C.TIME_UNSET, /* queue= */
ImmutableList.of(), createMediaChunkIterators(trackGroup, TEST_CHUNK_DURATION_US));
assertThat(adaptiveTrackSelection.getSelectedFormat()).isEqualTo(format1);
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(3500L);
adaptiveTrackSelection.updateSelectedTrack(/* playbackPositionUs= */
0, /* bufferedDurationUs= */
999_999_999_999L, /* availableDurationUs= */
C.TIME_UNSET, /* queue= */
ImmutableList.of(), createMediaChunkIterators(trackGroup, TEST_CHUNK_DURATION_US));
assertThat(adaptiveTrackSelection.getSelectedFormat()).isEqualTo(format2);
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(8999L);
adaptiveTrackSelection.updateSelectedTrack(/* playbackPositionUs= */
0, /* bufferedDurationUs= */
999_999_999_999L, /* availableDurationUs= */
C.TIME_UNSET, /* queue= */
ImmutableList.of(), createMediaChunkIterators(trackGroup, TEST_CHUNK_DURATION_US));
assertThat(adaptiveTrackSelection.getSelectedFormat()).isEqualTo(format2);
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(9000L);
adaptiveTrackSelection.updateSelectedTrack(/* playbackPositionUs= */
0, /* bufferedDurationUs= */
999_999_999_999L, /* availableDurationUs= */
C.TIME_UNSET, /* queue= */
ImmutableList.of(), createMediaChunkIterators(trackGroup, TEST_CHUNK_DURATION_US));
assertThat(adaptiveTrackSelection.getSelectedFormat()).isEqualTo(format3);
}
Aggregations