use of com.google.android.exoplayer2.Format in project ExoPlayer by google.
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 com.google.android.exoplayer2.Format 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.Format in project ExoPlayer by google.
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 com.google.android.exoplayer2.Format in project ExoPlayer by google.
the class AdaptiveTrackSelectionTest method updateSelectedTrackDoNotSwitchUpIfNotBufferedEnough.
@Test
public void updateSelectedTrackDoNotSwitchUpIfNotBufferedEnough() {
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= */
9_999_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. However, since we only buffered 9_999_000 us, which is smaller than
// minDurationForQualityIncreaseMs, we should defer switch up.
assertThat(adaptiveTrackSelection.getSelectedFormat()).isEqualTo(format2);
assertThat(adaptiveTrackSelection.getSelectionReason()).isEqualTo(C.SELECTION_REASON_INITIAL);
}
use of com.google.android.exoplayer2.Format in project ExoPlayer by google.
the class AdaptiveTrackSelectionTest method updateSelectedTrackDoNotSwitchDownIfBufferedEnough.
@Test
public void updateSelectedTrackDoNotSwitchDownIfBufferedEnough() {
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= */
25_000_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. However, since we have enough buffer at higher quality (25_000_000 us, which is equal
// to maxDurationForQualityDecreaseMs), we should defer switch down.
assertThat(adaptiveTrackSelection.getSelectedFormat()).isEqualTo(format2);
assertThat(adaptiveTrackSelection.getSelectionReason()).isEqualTo(C.SELECTION_REASON_INITIAL);
}
Aggregations