Search in sources :

Example 6 with ChunkHolder

use of androidx.media3.exoplayer.source.chunk.ChunkHolder in project media by androidx.

the class DefaultDashChunkSourceTest method getNextChunk_onChunkLoadErrorExclusionDisabled_neverRequestReplacementChunk.

@Test
public void getNextChunk_onChunkLoadErrorExclusionDisabled_neverRequestReplacementChunk() throws Exception {
    DefaultLoadErrorHandlingPolicy loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy() {

        @Override
        @Nullable
        public FallbackSelection getFallbackSelectionFor(FallbackOptions fallbackOptions, LoadErrorInfo loadErrorInfo) {
            // Never exclude, neither tracks nor locations.
            return null;
        }
    };
    DashChunkSource chunkSource = createDashChunkSource(/* numberOfTracks= */
    2);
    ChunkHolder output = new ChunkHolder();
    chunkSource.getNextChunk(/* playbackPositionUs= */
    0, /* loadPositionUs= */
    0, /* queue= */
    ImmutableList.of(), output);
    boolean requestReplacementChunk = chunkSource.onChunkLoadError(checkNotNull(output.chunk), /* cancelable= */
    true, createFakeLoadErrorInfo(output.chunk.dataSpec, /* httpResponseCode= */
    404, /* errorCount= */
    1), loadErrorHandlingPolicy);
    assertThat(requestReplacementChunk).isFalse();
}
Also used : DefaultLoadErrorHandlingPolicy(androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy) ChunkHolder(androidx.media3.exoplayer.source.chunk.ChunkHolder) Test(org.junit.Test)

Example 7 with ChunkHolder

use of androidx.media3.exoplayer.source.chunk.ChunkHolder in project media by androidx.

the class DefaultDashChunkSourceTest method getNextChunk_forLowLatencyManifest_setsCorrectMayNotLoadAtFullNetworkSpeedFlag.

@Test
public void getNextChunk_forLowLatencyManifest_setsCorrectMayNotLoadAtFullNetworkSpeedFlag() throws Exception {
    long nowMs = 2_000_000_000_000L;
    SystemClock.setCurrentTimeMillis(nowMs);
    DashManifest manifest = new DashManifestParser().parse(Uri.parse("https://example.com/test.mpd"), TestUtil.getInputStream(ApplicationProvider.getApplicationContext(), SAMPLE_MPD_LIVE_WITH_OFFSET_INSIDE_WINDOW));
    DefaultDashChunkSource chunkSource = new DefaultDashChunkSource(BundledChunkExtractor.FACTORY, new LoaderErrorThrower.Dummy(), manifest, new BaseUrlExclusionList(), /* periodIndex= */
    0, /* adaptationSetIndices= */
    new int[] { 0 }, new FixedTrackSelection(new TrackGroup(new Format.Builder().build()), /* track= */
    0), C.TRACK_TYPE_VIDEO, new FakeDataSource(), /* elapsedRealtimeOffsetMs= */
    0, /* maxSegmentsPerLoad= */
    1, /* enableEventMessageTrack= */
    false, /* closedCaptionFormats */
    ImmutableList.of(), /* playerTrackEmsgHandler= */
    null, PlayerId.UNSET);
    long nowInPeriodUs = Util.msToUs(nowMs - manifest.availabilityStartTimeMs);
    ChunkHolder output = new ChunkHolder();
    chunkSource.getNextChunk(/* playbackPositionUs= */
    nowInPeriodUs - 5 * C.MICROS_PER_SECOND, /* loadPositionUs= */
    nowInPeriodUs - 5 * C.MICROS_PER_SECOND, /* queue= */
    ImmutableList.of(), output);
    assertThat(output.chunk.dataSpec.flags & DataSpec.FLAG_MIGHT_NOT_USE_FULL_NETWORK_SPEED).isEqualTo(0);
    chunkSource.getNextChunk(/* playbackPositionUs= */
    nowInPeriodUs, /* loadPositionUs= */
    nowInPeriodUs, /* queue= */
    ImmutableList.of(), output);
    assertThat(output.chunk.dataSpec.flags & DataSpec.FLAG_MIGHT_NOT_USE_FULL_NETWORK_SPEED).isNotEqualTo(0);
}
Also used : DashManifestParser(androidx.media3.exoplayer.dash.manifest.DashManifestParser) FakeDataSource(androidx.media3.test.utils.FakeDataSource) LoaderErrorThrower(androidx.media3.exoplayer.upstream.LoaderErrorThrower) TrackGroup(androidx.media3.common.TrackGroup) ChunkHolder(androidx.media3.exoplayer.source.chunk.ChunkHolder) DashManifest(androidx.media3.exoplayer.dash.manifest.DashManifest) FixedTrackSelection(androidx.media3.exoplayer.trackselection.FixedTrackSelection) Test(org.junit.Test)

Example 8 with ChunkHolder

use of androidx.media3.exoplayer.source.chunk.ChunkHolder in project media by androidx.

the class DefaultDashChunkSourceTest method getNextChunk_onChunkLoadErrorLocationExclusionEnabled_correctFallbackBehavior.

@Test
public void getNextChunk_onChunkLoadErrorLocationExclusionEnabled_correctFallbackBehavior() throws Exception {
    DefaultLoadErrorHandlingPolicy loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy() {

        @Override
        public FallbackSelection getFallbackSelectionFor(FallbackOptions fallbackOptions, LoadErrorInfo loadErrorInfo) {
            return new FallbackSelection(FALLBACK_TYPE_LOCATION, DEFAULT_LOCATION_EXCLUSION_MS);
        }
    };
    List<Chunk> chunks = new ArrayList<>();
    DashChunkSource chunkSource = createDashChunkSource(/* numberOfTracks= */
    1);
    ChunkHolder output = new ChunkHolder();
    boolean requestReplacementChunk = true;
    while (requestReplacementChunk) {
        chunkSource.getNextChunk(/* playbackPositionUs= */
        0, /* loadPositionUs= */
        0, /* queue= */
        ImmutableList.of(), output);
        chunks.add(output.chunk);
        requestReplacementChunk = chunkSource.onChunkLoadError(checkNotNull(output.chunk), /* cancelable= */
        true, createFakeLoadErrorInfo(output.chunk.dataSpec, /* httpResponseCode= */
        404, /* errorCount= */
        1), loadErrorHandlingPolicy);
    }
    assertThat(Lists.transform(chunks, (chunk) -> chunk.dataSpec.uri.toString())).containsExactly("http://video.com/baseUrl/a/video/video_0_1300000.m4s", "http://video.com/baseUrl/b/video/video_0_1300000.m4s", "http://video.com/baseUrl/d/video/video_0_1300000.m4s").inOrder();
    // Assert expiration of exclusions.
    ShadowSystemClock.advanceBy(Duration.ofMillis(DEFAULT_LOCATION_EXCLUSION_MS));
    chunkSource.onChunkLoadError(checkNotNull(output.chunk), /* cancelable= */
    true, createFakeLoadErrorInfo(output.chunk.dataSpec, /* httpResponseCode= */
    404, /* errorCount= */
    1), loadErrorHandlingPolicy);
    chunkSource.getNextChunk(/* playbackPositionUs= */
    0, /* loadPositionUs= */
    0, /* queue= */
    ImmutableList.of(), output);
    assertThat(output.chunk.dataSpec.uri.toString()).isEqualTo("http://video.com/baseUrl/a/video/video_0_1300000.m4s");
}
Also used : TrackGroup(androidx.media3.common.TrackGroup) LoaderErrorThrower(androidx.media3.exoplayer.upstream.LoaderErrorThrower) Assertions.checkNotNull(androidx.media3.common.util.Assertions.checkNotNull) LoadEventInfo(androidx.media3.exoplayer.source.LoadEventInfo) Uri(android.net.Uri) LoadErrorHandlingPolicy(androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy) RunWith(org.junit.runner.RunWith) DEFAULT_LOCATION_EXCLUSION_MS(androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy.DEFAULT_LOCATION_EXCLUSION_MS) SystemClock(android.os.SystemClock) FixedTrackSelection(androidx.media3.exoplayer.trackselection.FixedTrackSelection) Random(java.util.Random) DefaultLoadErrorHandlingPolicy(androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) HttpDataSource(androidx.media3.datasource.HttpDataSource) ApplicationProvider(androidx.test.core.app.ApplicationProvider) ArrayList(java.util.ArrayList) DashManifestParser(androidx.media3.exoplayer.dash.manifest.DashManifestParser) FakeDataSource(androidx.media3.test.utils.FakeDataSource) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) BundledChunkExtractor(androidx.media3.exoplayer.source.chunk.BundledChunkExtractor) TestUtil(androidx.media3.test.utils.TestUtil) Duration(java.time.Duration) AdaptiveTrackSelection(androidx.media3.exoplayer.trackselection.AdaptiveTrackSelection) Assertions(androidx.media3.common.util.Assertions) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultBandwidthMeter(androidx.media3.exoplayer.upstream.DefaultBandwidthMeter) MediaLoadData(androidx.media3.exoplayer.source.MediaLoadData) IOException(java.io.IOException) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) Util(androidx.media3.common.util.Util) Format(androidx.media3.common.Format) C(androidx.media3.common.C) List(java.util.List) Nullable(androidx.annotation.Nullable) PlayerId(androidx.media3.exoplayer.analytics.PlayerId) DashManifest(androidx.media3.exoplayer.dash.manifest.DashManifest) Chunk(androidx.media3.exoplayer.source.chunk.Chunk) ShadowSystemClock(org.robolectric.shadows.ShadowSystemClock) ChunkHolder(androidx.media3.exoplayer.source.chunk.ChunkHolder) DataSpec(androidx.media3.datasource.DataSpec) DefaultLoadErrorHandlingPolicy(androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy) ChunkHolder(androidx.media3.exoplayer.source.chunk.ChunkHolder) ArrayList(java.util.ArrayList) Chunk(androidx.media3.exoplayer.source.chunk.Chunk) Test(org.junit.Test)

Aggregations

ChunkHolder (androidx.media3.exoplayer.source.chunk.ChunkHolder)5 Test (org.junit.Test)5 TrackGroup (androidx.media3.common.TrackGroup)4 DashManifest (androidx.media3.exoplayer.dash.manifest.DashManifest)4 DashManifestParser (androidx.media3.exoplayer.dash.manifest.DashManifestParser)4 FixedTrackSelection (androidx.media3.exoplayer.trackselection.FixedTrackSelection)4 LoaderErrorThrower (androidx.media3.exoplayer.upstream.LoaderErrorThrower)4 FakeDataSource (androidx.media3.test.utils.FakeDataSource)4 Uri (android.net.Uri)3 Nullable (androidx.annotation.Nullable)3 Format (androidx.media3.common.Format)3 DataSpec (androidx.media3.datasource.DataSpec)3 BundledChunkExtractor (androidx.media3.exoplayer.source.chunk.BundledChunkExtractor)3 MediaChunkIterator (androidx.media3.exoplayer.source.chunk.MediaChunkIterator)3 DefaultLoadErrorHandlingPolicy (androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy)3 SystemClock (android.os.SystemClock)2 C (androidx.media3.common.C)2 Assertions (androidx.media3.common.util.Assertions)2 Assertions.checkNotNull (androidx.media3.common.util.Assertions.checkNotNull)2 Util (androidx.media3.common.util.Util)2