Search in sources :

Example 1 with AdaptiveTrackSelection

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);
}
Also used : DashManifest(androidx.media3.exoplayer.dash.manifest.DashManifest) DashManifestParser(androidx.media3.exoplayer.dash.manifest.DashManifestParser) Format(androidx.media3.common.Format) Random(java.util.Random) FakeDataSource(androidx.media3.test.utils.FakeDataSource) AdaptiveTrackSelection(androidx.media3.exoplayer.trackselection.AdaptiveTrackSelection) TrackGroup(androidx.media3.common.TrackGroup) LoaderErrorThrower(androidx.media3.exoplayer.upstream.LoaderErrorThrower)

Example 2 with AdaptiveTrackSelection

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);
}
Also used : Format(androidx.media3.common.Format) TrackGroup(androidx.media3.common.TrackGroup) Test(org.junit.Test)

Example 3 with AdaptiveTrackSelection

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);
}
Also used : Format(androidx.media3.common.Format) TrackGroup(androidx.media3.common.TrackGroup) FakeMediaChunk(androidx.media3.test.utils.FakeMediaChunk) AdaptationCheckpoint(androidx.media3.exoplayer.trackselection.AdaptiveTrackSelection.AdaptationCheckpoint) Test(org.junit.Test)

Example 4 with AdaptiveTrackSelection

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);
}
Also used : Format(androidx.media3.common.Format) TrackGroup(androidx.media3.common.TrackGroup) Test(org.junit.Test)

Example 5 with AdaptiveTrackSelection

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);
}
Also used : Format(androidx.media3.common.Format) TrackGroup(androidx.media3.common.TrackGroup) FakeMediaChunk(androidx.media3.test.utils.FakeMediaChunk) AdaptationCheckpoint(androidx.media3.exoplayer.trackselection.AdaptiveTrackSelection.AdaptationCheckpoint) Test(org.junit.Test)

Aggregations

Format (androidx.media3.common.Format)18 TrackGroup (androidx.media3.common.TrackGroup)18 Test (org.junit.Test)17 AdaptationCheckpoint (androidx.media3.exoplayer.trackselection.AdaptiveTrackSelection.AdaptationCheckpoint)7 FakeMediaChunk (androidx.media3.test.utils.FakeMediaChunk)6 Timeline (androidx.media3.common.Timeline)2 MediaSource (androidx.media3.exoplayer.source.MediaSource)2 Definition (androidx.media3.exoplayer.trackselection.ExoTrackSelection.Definition)2 BandwidthMeter (androidx.media3.exoplayer.upstream.BandwidthMeter)2 FakeTimeline (androidx.media3.test.utils.FakeTimeline)2 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 DashManifest (androidx.media3.exoplayer.dash.manifest.DashManifest)1 DashManifestParser (androidx.media3.exoplayer.dash.manifest.DashManifestParser)1 AdaptiveTrackSelection (androidx.media3.exoplayer.trackselection.AdaptiveTrackSelection)1 LoaderErrorThrower (androidx.media3.exoplayer.upstream.LoaderErrorThrower)1 FakeDataSource (androidx.media3.test.utils.FakeDataSource)1 Random (java.util.Random)1