Search in sources :

Example 1 with DEFAULT_LOCATION_EXCLUSION_MS

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

the class DefaultLoadErrorHandlingPolicyTest method getFallbackSelectionFor_responseCode500.

@Test
public void getFallbackSelectionFor_responseCode500() {
    InvalidResponseCodeException exception = buildInvalidResponseCodeException(500, "Internal server error");
    @Nullable LoadErrorHandlingPolicy.FallbackSelection defaultPolicyFallbackSelection = getDefaultPolicyFallbackSelection(exception, /* numberOfLocations= */
    1, /* numberOfExcludedLocations= */
    0, /* numberOfTracks= */
    10, /* numberOfExcludedTracks= */
    0);
    assertThat(defaultPolicyFallbackSelection.type).isEqualTo(FALLBACK_TYPE_TRACK);
    assertThat(defaultPolicyFallbackSelection.exclusionDurationMs).isEqualTo(DEFAULT_TRACK_EXCLUSION_MS);
    defaultPolicyFallbackSelection = getDefaultPolicyFallbackSelection(exception, /* numberOfLocations= */
    2, /* numberOfExcludedLocations= */
    0, /* numberOfTracks= */
    4, /* numberOfExcludedTracks= */
    1);
    assertThat(defaultPolicyFallbackSelection.type).isEqualTo(FALLBACK_TYPE_LOCATION);
    assertThat(defaultPolicyFallbackSelection.exclusionDurationMs).isEqualTo(DEFAULT_LOCATION_EXCLUSION_MS);
}
Also used : InvalidResponseCodeException(com.google.android.exoplayer2.upstream.HttpDataSource.InvalidResponseCodeException) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Example 2 with DEFAULT_LOCATION_EXCLUSION_MS

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

the class DefaultLoadErrorHandlingPolicyTest method getFallbackSelectionFor_responseCode403.

@Test
public void getFallbackSelectionFor_responseCode403() {
    InvalidResponseCodeException exception = buildInvalidResponseCodeException(403, "Forbidden");
    @Nullable LoadErrorHandlingPolicy.FallbackSelection defaultPolicyFallbackSelection = getDefaultPolicyFallbackSelection(exception, /* numberOfLocations= */
    1, /* numberOfExcludedLocations= */
    0, /* numberOfTracks= */
    10, /* numberOfExcludedTracks= */
    0);
    assertThat(defaultPolicyFallbackSelection.type).isEqualTo(FALLBACK_TYPE_TRACK);
    assertThat(defaultPolicyFallbackSelection.exclusionDurationMs).isEqualTo(DEFAULT_TRACK_EXCLUSION_MS);
    defaultPolicyFallbackSelection = getDefaultPolicyFallbackSelection(exception, /* numberOfLocations= */
    2, /* numberOfExcludedLocations= */
    0, /* numberOfTracks= */
    4, /* numberOfExcludedTracks= */
    1);
    assertThat(defaultPolicyFallbackSelection.type).isEqualTo(FALLBACK_TYPE_LOCATION);
    assertThat(defaultPolicyFallbackSelection.exclusionDurationMs).isEqualTo(DEFAULT_LOCATION_EXCLUSION_MS);
}
Also used : InvalidResponseCodeException(com.google.android.exoplayer2.upstream.HttpDataSource.InvalidResponseCodeException) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Example 3 with DEFAULT_LOCATION_EXCLUSION_MS

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

the class BaseUrlExclusionListTest method getPriorityCountAfterExclusion_correctPriorityCount.

@Test
public void getPriorityCountAfterExclusion_correctPriorityCount() {
    List<BaseUrl> baseUrls = ImmutableList.of(new BaseUrl(/* url= */
    "a", /* serviceLocation= */
    "a", /* priority= */
    1, /* weight= */
    1), new BaseUrl(/* url= */
    "b", /* serviceLocation= */
    "b", /* priority= */
    2, /* weight= */
    1), new BaseUrl(/* url= */
    "c", /* serviceLocation= */
    "c", /* priority= */
    2, /* weight= */
    1), new BaseUrl(/* url= */
    "d", /* serviceLocation= */
    "d", /* priority= */
    3, /* weight= */
    1), new BaseUrl(/* url= */
    "e", /* serviceLocation= */
    "e", /* priority= */
    3, /* weight= */
    1));
    BaseUrlExclusionList baseUrlExclusionList = new BaseUrlExclusionList();
    // Empty base URL list.
    assertThat(baseUrlExclusionList.getPriorityCountAfterExclusion(ImmutableList.of())).isEqualTo(0);
    assertThat(baseUrlExclusionList.getPriorityCountAfterExclusion(baseUrls)).isEqualTo(3);
    // Exclude base urls.
    baseUrlExclusionList.exclude(baseUrls.get(0), DEFAULT_LOCATION_EXCLUSION_MS);
    assertThat(baseUrlExclusionList.getPriorityCountAfterExclusion(baseUrls)).isEqualTo(2);
    baseUrlExclusionList.exclude(baseUrls.get(1), 2 * DEFAULT_LOCATION_EXCLUSION_MS);
    assertThat(baseUrlExclusionList.getPriorityCountAfterExclusion(baseUrls)).isEqualTo(1);
    baseUrlExclusionList.exclude(baseUrls.get(3), 3 * DEFAULT_LOCATION_EXCLUSION_MS);
    assertThat(baseUrlExclusionList.getPriorityCountAfterExclusion(baseUrls)).isEqualTo(0);
    // Time passes.
    ShadowSystemClock.advanceBy(Duration.ofMillis(DEFAULT_LOCATION_EXCLUSION_MS));
    assertThat(baseUrlExclusionList.getPriorityCountAfterExclusion(baseUrls)).isEqualTo(1);
    ShadowSystemClock.advanceBy(Duration.ofMillis(DEFAULT_LOCATION_EXCLUSION_MS));
    assertThat(baseUrlExclusionList.getPriorityCountAfterExclusion(baseUrls)).isEqualTo(2);
    ShadowSystemClock.advanceBy(Duration.ofMillis(DEFAULT_LOCATION_EXCLUSION_MS));
    assertThat(baseUrlExclusionList.getPriorityCountAfterExclusion(baseUrls)).isEqualTo(3);
}
Also used : BaseUrl(com.google.android.exoplayer2.source.dash.manifest.BaseUrl) Test(org.junit.Test)

Example 4 with DEFAULT_LOCATION_EXCLUSION_MS

use of com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy.DEFAULT_LOCATION_EXCLUSION_MS 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 DEFAULT_LOCATION_EXCLUSION_MS

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

the class DefaultLoadErrorHandlingPolicyTest method getFallbackSelectionFor_responseCode410.

@Test
public void getFallbackSelectionFor_responseCode410() {
    InvalidResponseCodeException exception = buildInvalidResponseCodeException(410, "Gone");
    @Nullable LoadErrorHandlingPolicy.FallbackSelection defaultPolicyFallbackSelection = getDefaultPolicyFallbackSelection(exception, /* numberOfLocations= */
    1, /* numberOfExcludedLocations= */
    0, /* numberOfTracks= */
    10, /* numberOfExcludedTracks= */
    0);
    assertThat(defaultPolicyFallbackSelection.type).isEqualTo(FALLBACK_TYPE_TRACK);
    assertThat(defaultPolicyFallbackSelection.exclusionDurationMs).isEqualTo(DEFAULT_TRACK_EXCLUSION_MS);
    defaultPolicyFallbackSelection = getDefaultPolicyFallbackSelection(exception, /* numberOfLocations= */
    2, /* numberOfExcludedLocations= */
    0, /* numberOfTracks= */
    4, /* numberOfExcludedTracks= */
    1);
    assertThat(defaultPolicyFallbackSelection.type).isEqualTo(FALLBACK_TYPE_LOCATION);
    assertThat(defaultPolicyFallbackSelection.exclusionDurationMs).isEqualTo(DEFAULT_LOCATION_EXCLUSION_MS);
}
Also used : InvalidResponseCodeException(com.google.android.exoplayer2.upstream.HttpDataSource.InvalidResponseCodeException) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 Nullable (androidx.annotation.Nullable)6 InvalidResponseCodeException (com.google.android.exoplayer2.upstream.HttpDataSource.InvalidResponseCodeException)5 Uri (android.net.Uri)1 SystemClock (android.os.SystemClock)1 ApplicationProvider (androidx.test.core.app.ApplicationProvider)1 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)1 C (com.google.android.exoplayer2.C)1 Format (com.google.android.exoplayer2.Format)1 PlayerId (com.google.android.exoplayer2.analytics.PlayerId)1 LoadEventInfo (com.google.android.exoplayer2.source.LoadEventInfo)1 MediaLoadData (com.google.android.exoplayer2.source.MediaLoadData)1 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)1 BundledChunkExtractor (com.google.android.exoplayer2.source.chunk.BundledChunkExtractor)1 Chunk (com.google.android.exoplayer2.source.chunk.Chunk)1 ChunkHolder (com.google.android.exoplayer2.source.chunk.ChunkHolder)1 BaseUrl (com.google.android.exoplayer2.source.dash.manifest.BaseUrl)1 DashManifest (com.google.android.exoplayer2.source.dash.manifest.DashManifest)1 DashManifestParser (com.google.android.exoplayer2.source.dash.manifest.DashManifestParser)1 FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)1