use of androidx.media3.test.utils.FakeMediaChunk 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.test.utils.FakeMediaChunk 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);
}
use of androidx.media3.test.utils.FakeMediaChunk in project media by androidx.
the class AdaptiveTrackSelectionTest method evaluateQueueSizeDiscardChunksLessThanOrEqualToMaximumResolution.
@Test
public void evaluateQueueSizeDiscardChunksLessThanOrEqualToMaximumResolution() {
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(format2, /* startTimeUs= */
0, /* endTimeUs= */
10_000_000);
FakeMediaChunk chunk2 = new FakeMediaChunk(format2, /* startTimeUs= */
10_000_000, /* endTimeUs= */
20_000_000);
FakeMediaChunk chunk3 = new FakeMediaChunk(format2, /* startTimeUs= */
20_000_000, /* endTimeUs= */
30_000_000);
FakeMediaChunk chunk4 = new FakeMediaChunk(format2, /* startTimeUs= */
30_000_000, /* endTimeUs= */
40_000_000);
FakeMediaChunk chunk5 = new FakeMediaChunk(format1, /* startTimeUs= */
40_000_000, /* endTimeUs= */
50_000_000);
List<FakeMediaChunk> queue = ImmutableList.of(chunk1, chunk2, chunk3, chunk4, chunk5);
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(500L);
AdaptiveTrackSelection adaptiveTrackSelection = prepareAdaptiveTrackSelectionWithMaxResolutionToDiscard(trackGroup, /* maxWidthToDiscard= */
320, /* maxHeightToDiscard= */
240);
int initialQueueSize = adaptiveTrackSelection.evaluateQueueSize(/* playbackPositionUs= */
0, queue);
assertThat(initialQueueSize).isEqualTo(5);
fakeClock.advanceTime(2000);
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(2000L);
// When bandwidth estimation is updated and time has advanced enough, we can discard chunks at
// the end of the queue now.
// In this case, only chunks less than or equal to width = 320 and height = 240 are discarded.
int newSize = adaptiveTrackSelection.evaluateQueueSize(/* playbackPositionUs= */
0, queue);
assertThat(newSize).isEqualTo(4);
}
use of androidx.media3.test.utils.FakeMediaChunk in project media by androidx.
the class AdaptiveTrackSelectionTest method updateSelectedTrack_usesFormatOfLastChunkInTheQueueForSelection.
@Test
public void updateSelectedTrack_usesFormatOfLastChunkInTheQueueForSelection() {
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 = new AdaptiveTrackSelection.Factory(/* minDurationForQualityIncreaseMs= */
10_000, /* maxDurationForQualityDecreaseMs= */
10_000, /* minDurationToRetainAfterDiscardMs= */
25_000, /* bandwidthFraction= */
1f).createAdaptiveTrackSelection(trackGroup, /* tracks= */
new int[] { 0, 1 }, /* type= */
TrackSelection.TYPE_UNSET, mockBandwidthMeter, /* adaptationCheckpoints= */
ImmutableList.of());
// Make initial selection.
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(1000L);
prepareTrackSelection(adaptiveTrackSelection);
assertThat(adaptiveTrackSelection.getSelectedFormat()).isEqualTo(format2);
assertThat(adaptiveTrackSelection.getSelectionReason()).isEqualTo(C.SELECTION_REASON_INITIAL);
// Ensure that track selection wants to switch down due to low bandwidth.
FakeMediaChunk chunk1 = new FakeMediaChunk(format2, /* startTimeUs= */
0, /* endTimeUs= */
2_000_000, C.SELECTION_REASON_INITIAL);
FakeMediaChunk chunk2 = new FakeMediaChunk(format2, /* startTimeUs= */
2_000_000, /* endTimeUs= */
4_000_000, C.SELECTION_REASON_INITIAL);
List<FakeMediaChunk> queue = ImmutableList.of(chunk1, chunk2);
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(500L);
adaptiveTrackSelection.updateSelectedTrack(/* playbackPositionUs= */
0, /* bufferedDurationUs= */
4_000_000, /* availableDurationUs= */
C.TIME_UNSET, queue, createMediaChunkIterators(trackGroup, TEST_CHUNK_DURATION_US));
assertThat(adaptiveTrackSelection.getSelectedFormat()).isEqualTo(format1);
assertThat(adaptiveTrackSelection.getSelectionReason()).isEqualTo(C.SELECTION_REASON_ADAPTIVE);
// Assert that an improved bandwidth selects the last chunk's format and ignores the previous
// decision. Switching up from the previous decision wouldn't be possible yet because the
// buffered duration is less than minDurationForQualityIncreaseMs.
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(1000L);
adaptiveTrackSelection.updateSelectedTrack(/* playbackPositionUs= */
0, /* bufferedDurationUs= */
4_000_000, /* availableDurationUs= */
C.TIME_UNSET, queue, createMediaChunkIterators(trackGroup, TEST_CHUNK_DURATION_US));
assertThat(adaptiveTrackSelection.getSelectedFormat()).isEqualTo(format2);
assertThat(adaptiveTrackSelection.getSelectionReason()).isEqualTo(C.SELECTION_REASON_INITIAL);
}
use of androidx.media3.test.utils.FakeMediaChunk 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);
}
Aggregations