Search in sources :

Example 1 with DefaultLoadErrorHandlingPolicy

use of com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy in project ExoPlayer by google.

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 : RobolectricUtil.runMainLooperUntil(com.google.android.exoplayer2.robolectric.RobolectricUtil.runMainLooperUntil) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) AssetDataSource(com.google.android.exoplayer2.upstream.AssetDataSource) DefaultLoadErrorHandlingPolicy(com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy) 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) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) ApplicationProvider(androidx.test.core.app.ApplicationProvider) Mp4Extractor(com.google.android.exoplayer2.extractor.mp4.Mp4Extractor) PlayerId(com.google.android.exoplayer2.analytics.PlayerId) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) DefaultAllocator(com.google.android.exoplayer2.upstream.DefaultAllocator) C(com.google.android.exoplayer2.C) AssetDataSource(com.google.android.exoplayer2.upstream.AssetDataSource) DefaultLoadErrorHandlingPolicy(com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) DefaultAllocator(com.google.android.exoplayer2.upstream.DefaultAllocator)

Example 2 with DefaultLoadErrorHandlingPolicy

use of com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy in project ExoPlayer by google.

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(com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy.LoadErrorInfo) Nullable(androidx.annotation.Nullable)

Example 3 with DefaultLoadErrorHandlingPolicy

use of com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy in project ExoPlayer by google.

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(com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy) ChunkHolder(com.google.android.exoplayer2.source.chunk.ChunkHolder) Test(org.junit.Test)

Example 4 with DefaultLoadErrorHandlingPolicy

use of com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy in project ExoPlayer by google.

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 : Util(com.google.android.exoplayer2.util.Util) LoadEventInfo(com.google.android.exoplayer2.source.LoadEventInfo) Uri(android.net.Uri) RunWith(org.junit.runner.RunWith) SystemClock(android.os.SystemClock) Random(java.util.Random) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) TestUtil(com.google.android.exoplayer2.testutil.TestUtil) ApplicationProvider(androidx.test.core.app.ApplicationProvider) ArrayList(java.util.ArrayList) Format(com.google.android.exoplayer2.Format) FixedTrackSelection(com.google.android.exoplayer2.trackselection.FixedTrackSelection) PlayerId(com.google.android.exoplayer2.analytics.PlayerId) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) DashManifestParser(com.google.android.exoplayer2.source.dash.manifest.DashManifestParser) Duration(java.time.Duration) AdaptiveTrackSelection(com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection) C(com.google.android.exoplayer2.C) BundledChunkExtractor(com.google.android.exoplayer2.source.chunk.BundledChunkExtractor) DefaultLoadErrorHandlingPolicy(com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy) DEFAULT_LOCATION_EXCLUSION_MS(com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy.DEFAULT_LOCATION_EXCLUSION_MS) ImmutableMap(com.google.common.collect.ImmutableMap) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) DataSpec(com.google.android.exoplayer2.upstream.DataSpec) IOException(java.io.IOException) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) HttpDataSource(com.google.android.exoplayer2.upstream.HttpDataSource) ChunkHolder(com.google.android.exoplayer2.source.chunk.ChunkHolder) FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) DefaultBandwidthMeter(com.google.android.exoplayer2.upstream.DefaultBandwidthMeter) List(java.util.List) Nullable(androidx.annotation.Nullable) Chunk(com.google.android.exoplayer2.source.chunk.Chunk) DashManifest(com.google.android.exoplayer2.source.dash.manifest.DashManifest) LoadErrorHandlingPolicy(com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy) ShadowSystemClock(org.robolectric.shadows.ShadowSystemClock) MediaLoadData(com.google.android.exoplayer2.source.MediaLoadData) Assertions.checkNotNull(com.google.android.exoplayer2.util.Assertions.checkNotNull) Assertions(com.google.android.exoplayer2.util.Assertions) LoaderErrorThrower(com.google.android.exoplayer2.upstream.LoaderErrorThrower) DefaultLoadErrorHandlingPolicy(com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy) ChunkHolder(com.google.android.exoplayer2.source.chunk.ChunkHolder) ArrayList(java.util.ArrayList) Chunk(com.google.android.exoplayer2.source.chunk.Chunk) Test(org.junit.Test)

Example 5 with DefaultLoadErrorHandlingPolicy

use of com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy in project ExoPlayer by google.

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(com.google.android.exoplayer2.source.chunk.ChunkSampleStream) ExoTrackSelection(com.google.android.exoplayer2.trackselection.ExoTrackSelection) DefaultLoadErrorHandlingPolicy(com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) CompositeSequenceableLoader(com.google.android.exoplayer2.source.CompositeSequenceableLoader)

Aggregations

DefaultLoadErrorHandlingPolicy (com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy)6 Uri (android.net.Uri)3 Nullable (androidx.annotation.Nullable)3 ApplicationProvider (androidx.test.core.app.ApplicationProvider)3 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)3 C (com.google.android.exoplayer2.C)3 PlayerId (com.google.android.exoplayer2.analytics.PlayerId)3 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)3 ChunkHolder (com.google.android.exoplayer2.source.chunk.ChunkHolder)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 Test (org.junit.Test)3 SystemClock (android.os.SystemClock)2 Format (com.google.android.exoplayer2.Format)2 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)2 LoadEventInfo (com.google.android.exoplayer2.source.LoadEventInfo)2 MediaLoadData (com.google.android.exoplayer2.source.MediaLoadData)2 BundledChunkExtractor (com.google.android.exoplayer2.source.chunk.BundledChunkExtractor)2 Chunk (com.google.android.exoplayer2.source.chunk.Chunk)2 DashManifest (com.google.android.exoplayer2.source.dash.manifest.DashManifest)2 DashManifestParser (com.google.android.exoplayer2.source.dash.manifest.DashManifestParser)2