Search in sources :

Example 1 with DefaultLoadErrorHandlingPolicy

use of androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy in project media by androidx.

the class DefaultLoadErrorHandlingPolicyTest method getDefaultPolicyFallbackSelection.

@Nullable
private static LoadErrorHandlingPolicy.FallbackSelection getDefaultPolicyFallbackSelection(IOException exception, int numberOfLocations, int numberOfExcludedLocations, int numberOfTracks, int numberOfExcludedTracks) {
    LoadErrorInfo loadErrorInfo = new LoadErrorInfo(PLACEHOLDER_LOAD_EVENT_INFO, PLACEHOLDER_MEDIA_LOAD_DATA, exception, /* errorCount= */
    1);
    LoadErrorHandlingPolicy.FallbackOptions fallbackOptions = new LoadErrorHandlingPolicy.FallbackOptions(numberOfLocations, numberOfExcludedLocations, numberOfTracks, numberOfExcludedTracks);
    return new DefaultLoadErrorHandlingPolicy().getFallbackSelectionFor(fallbackOptions, loadErrorInfo);
}
Also used : LoadErrorInfo(androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy.LoadErrorInfo) Nullable(androidx.annotation.Nullable)

Example 2 with DefaultLoadErrorHandlingPolicy

use of androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy in project media by androidx.

the class FakeAdaptiveMediaPeriod method selectTracks.

// Casting sample streams created by this class.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public long selectTracks(@NullableType ExoTrackSelection[] selections, boolean[] mayRetainStreamFlags, @NullableType SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
    assertThat(prepared).isTrue();
    int rendererCount = selections.length;
    for (int i = 0; i < rendererCount; i++) {
        if (streams[i] != null && (selections[i] == null || !mayRetainStreamFlags[i])) {
            ((ChunkSampleStream<FakeChunkSource>) streams[i]).release();
            sampleStreams.remove(streams[i]);
            streams[i] = null;
        }
        if (streams[i] == null && selections[i] != null) {
            ExoTrackSelection selection = selections[i];
            assertThat(selection.length()).isAtLeast(1);
            TrackGroup trackGroup = selection.getTrackGroup();
            assertThat(trackGroupArray.indexOf(trackGroup)).isNotEqualTo(C.INDEX_UNSET);
            int indexInTrackGroup = selection.getIndexInTrackGroup(selection.getSelectedIndex());
            assertThat(indexInTrackGroup).isAtLeast(0);
            assertThat(indexInTrackGroup).isLessThan(trackGroup.length);
            FakeChunkSource chunkSource = chunkSourceFactory.createChunkSource(selection, durationUs, transferListener);
            ChunkSampleStream<FakeChunkSource> sampleStream = new ChunkSampleStream<>(MimeTypes.getTrackType(selection.getSelectedFormat().sampleMimeType), /* embeddedTrackTypes= */
            null, /* embeddedTrackFormats= */
            null, chunkSource, /* callback= */
            this, allocator, positionUs, DrmSessionManager.DRM_UNSUPPORTED, new DrmSessionEventListener.EventDispatcher(), new DefaultLoadErrorHandlingPolicy(/* minimumLoadableRetryCount= */
            3), mediaSourceEventDispatcher);
            streams[i] = sampleStream;
            sampleStreams.add(sampleStream);
            streamResetFlags[i] = true;
        }
    }
    sequenceableLoader = new CompositeSequenceableLoader(sampleStreams.toArray(new ChunkSampleStream[0]));
    return seekToUs(positionUs);
}
Also used : ChunkSampleStream(androidx.media3.exoplayer.source.chunk.ChunkSampleStream) ExoTrackSelection(androidx.media3.exoplayer.trackselection.ExoTrackSelection) DefaultLoadErrorHandlingPolicy(androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy) TrackGroup(androidx.media3.common.TrackGroup) DrmSessionEventListener(androidx.media3.exoplayer.drm.DrmSessionEventListener) CompositeSequenceableLoader(androidx.media3.exoplayer.source.CompositeSequenceableLoader)

Example 3 with DefaultLoadErrorHandlingPolicy

use of androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy in project media by androidx.

the class ProgressiveMediaPeriodTest method testExtractorsUpdatesSourceInfoBeforeOnPreparedCallback.

private static void testExtractorsUpdatesSourceInfoBeforeOnPreparedCallback(ProgressiveMediaExtractor extractor) throws TimeoutException {
    AtomicBoolean sourceInfoRefreshCalled = new AtomicBoolean(false);
    ProgressiveMediaPeriod.Listener sourceInfoRefreshListener = (durationUs, isSeekable, isLive) -> sourceInfoRefreshCalled.set(true);
    MediaPeriodId mediaPeriodId = new MediaPeriodId(/* periodUid= */
    new Object());
    ProgressiveMediaPeriod mediaPeriod = new ProgressiveMediaPeriod(Uri.parse("asset://android_asset/media/mp4/sample.mp4"), new AssetDataSource(ApplicationProvider.getApplicationContext()), extractor, DrmSessionManager.DRM_UNSUPPORTED, new DrmSessionEventListener.EventDispatcher().withParameters(/* windowIndex= */
    0, mediaPeriodId), new DefaultLoadErrorHandlingPolicy(), new MediaSourceEventListener.EventDispatcher().withParameters(/* windowIndex= */
    0, mediaPeriodId, /* mediaTimeOffsetMs= */
    0), sourceInfoRefreshListener, new DefaultAllocator(/* trimOnReset= */
    true, C.DEFAULT_BUFFER_SEGMENT_SIZE), /* customCacheKey= */
    null, ProgressiveMediaSource.DEFAULT_LOADING_CHECK_INTERVAL_BYTES);
    AtomicBoolean prepareCallbackCalled = new AtomicBoolean(false);
    AtomicBoolean sourceInfoRefreshCalledBeforeOnPrepared = new AtomicBoolean(false);
    mediaPeriod.prepare(new MediaPeriod.Callback() {

        @Override
        public void onPrepared(MediaPeriod mediaPeriod) {
            sourceInfoRefreshCalledBeforeOnPrepared.set(sourceInfoRefreshCalled.get());
            prepareCallbackCalled.set(true);
        }

        @Override
        public void onContinueLoadingRequested(MediaPeriod source) {
            source.continueLoading(/* positionUs= */
            0);
        }
    }, /* positionUs= */
    0);
    runMainLooperUntil(prepareCallbackCalled::get);
    mediaPeriod.release();
    assertThat(sourceInfoRefreshCalledBeforeOnPrepared.get()).isTrue();
}
Also used : Uri(android.net.Uri) RunWith(org.junit.runner.RunWith) TimeoutException(java.util.concurrent.TimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) DefaultLoadErrorHandlingPolicy(androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) DefaultAllocator(androidx.media3.exoplayer.upstream.DefaultAllocator) ApplicationProvider(androidx.test.core.app.ApplicationProvider) DrmSessionManager(androidx.media3.exoplayer.drm.DrmSessionManager) C(androidx.media3.common.C) Mp4Extractor(androidx.media3.extractor.mp4.Mp4Extractor) DrmSessionEventListener(androidx.media3.exoplayer.drm.DrmSessionEventListener) PlayerId(androidx.media3.exoplayer.analytics.PlayerId) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) AssetDataSource(androidx.media3.datasource.AssetDataSource) RobolectricUtil.runMainLooperUntil(androidx.media3.test.utils.robolectric.RobolectricUtil.runMainLooperUntil) AssetDataSource(androidx.media3.datasource.AssetDataSource) DefaultLoadErrorHandlingPolicy(androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) DefaultAllocator(androidx.media3.exoplayer.upstream.DefaultAllocator)

Example 4 with DefaultLoadErrorHandlingPolicy

use of androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy in project media by androidx.

the class DefaultDashChunkSourceTest method getNextChunk_onChunkLoadErrorTrackExclusionEnabled_correctFallbackBehavior.

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

        @Override
        public FallbackSelection getFallbackSelectionFor(FallbackOptions fallbackOptions, LoadErrorInfo loadErrorInfo) {
            // Exclude tracks only.
            return new FallbackSelection(FALLBACK_TYPE_TRACK, DefaultLoadErrorHandlingPolicy.DEFAULT_TRACK_EXCLUSION_MS);
        }
    };
    DashChunkSource chunkSource = createDashChunkSource(/* numberOfTracks= */
    4);
    ChunkHolder output = new ChunkHolder();
    List<Chunk> chunks = new ArrayList<>();
    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_700000.m4s", "http://video.com/baseUrl/a/video/video_0_452000.m4s", "http://video.com/baseUrl/a/video/video_0_250000.m4s", "http://video.com/baseUrl/a/video/video_0_1300000.m4s").inOrder();
}
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)

Example 5 with DefaultLoadErrorHandlingPolicy

use of androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy 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)

Aggregations

DefaultLoadErrorHandlingPolicy (androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy)6 Test (org.junit.Test)4 Uri (android.net.Uri)3 Nullable (androidx.annotation.Nullable)3 C (androidx.media3.common.C)3 TrackGroup (androidx.media3.common.TrackGroup)3 PlayerId (androidx.media3.exoplayer.analytics.PlayerId)3 ChunkHolder (androidx.media3.exoplayer.source.chunk.ChunkHolder)3 ApplicationProvider (androidx.test.core.app.ApplicationProvider)3 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 ArrayList (java.util.ArrayList)3 RunWith (org.junit.runner.RunWith)3 SystemClock (android.os.SystemClock)2 Format (androidx.media3.common.Format)2 Assertions (androidx.media3.common.util.Assertions)2 Assertions.checkNotNull (androidx.media3.common.util.Assertions.checkNotNull)2 Util (androidx.media3.common.util.Util)2 DataSpec (androidx.media3.datasource.DataSpec)2 HttpDataSource (androidx.media3.datasource.HttpDataSource)2