Search in sources :

Example 16 with BaseUrl

use of androidx.media3.exoplayer.dash.manifest.BaseUrl in project media by androidx.

the class DashUtilTest method resolveCacheKey_representationCacheKeyIsNull_resolvesRangedUriWithFirstBaseUrl.

@Test
public void resolveCacheKey_representationCacheKeyIsNull_resolvesRangedUriWithFirstBaseUrl() {
    ImmutableList<BaseUrl> baseUrls = ImmutableList.of(new BaseUrl("http://www.google.com"), new BaseUrl("http://www.foo.com"));
    Representation.SingleSegmentRepresentation representation = new Representation.SingleSegmentRepresentation(/* revisionId= */
    1L, new Format.Builder().build(), baseUrls, new SingleSegmentBase(), /* inbandEventStreams= */
    null, /* essentialProperties= */
    ImmutableList.of(), /* supplementalProperties= */
    ImmutableList.of(), /* cacheKey= */
    null, /* contentLength= */
    1);
    RangedUri rangedUri = new RangedUri("path/to/resource", /* start= */
    0, /* length= */
    1);
    String cacheKey = DashUtil.resolveCacheKey(representation, rangedUri);
    assertThat(cacheKey).isEqualTo("http://www.google.com/path/to/resource");
}
Also used : SingleSegmentBase(androidx.media3.exoplayer.dash.manifest.SegmentBase.SingleSegmentBase) RangedUri(androidx.media3.exoplayer.dash.manifest.RangedUri) Representation(androidx.media3.exoplayer.dash.manifest.Representation) BaseUrl(androidx.media3.exoplayer.dash.manifest.BaseUrl) Test(org.junit.Test)

Example 17 with BaseUrl

use of androidx.media3.exoplayer.dash.manifest.BaseUrl 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 18 with BaseUrl

use of androidx.media3.exoplayer.dash.manifest.BaseUrl 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)

Example 19 with BaseUrl

use of androidx.media3.exoplayer.dash.manifest.BaseUrl in project media by androidx.

the class DefaultDashChunkSource method updateSelectedBaseUrl.

private RepresentationHolder updateSelectedBaseUrl(int trackIndex) {
    RepresentationHolder representationHolder = representationHolders[trackIndex];
    @Nullable BaseUrl selectedBaseUrl = baseUrlExclusionList.selectBaseUrl(representationHolder.representation.baseUrls);
    if (selectedBaseUrl != null && !selectedBaseUrl.equals(representationHolder.selectedBaseUrl)) {
        representationHolder = representationHolder.copyWithNewSelectedBaseUrl(selectedBaseUrl);
        representationHolders[trackIndex] = representationHolder;
    }
    return representationHolder;
}
Also used : BaseUrl(androidx.media3.exoplayer.dash.manifest.BaseUrl) Nullable(androidx.annotation.Nullable)

Example 20 with BaseUrl

use of androidx.media3.exoplayer.dash.manifest.BaseUrl in project media by androidx.

the class BaseUrlExclusionListTest method selectBaseUrl_twiceTheSameLocationExcluded_correctExpirationDuration.

@Test
public void selectBaseUrl_twiceTheSameLocationExcluded_correctExpirationDuration() {
    List<BaseUrl> baseUrls = ImmutableList.of(new BaseUrl(/* url= */
    "a", /* serviceLocation= */
    "a", /* priority= */
    1, /* weight= */
    1), new BaseUrl(/* url= */
    "c", /* serviceLocation= */
    "a", /* priority= */
    2, /* weight= */
    1), new BaseUrl(/* url= */
    "d", /* serviceLocation= */
    "d", /* priority= */
    2, /* weight= */
    1));
    BaseUrlExclusionList baseUrlExclusionList = new BaseUrlExclusionList();
    // Exclude location 'a'.
    baseUrlExclusionList.exclude(baseUrls.get(0), 5000);
    // Exclude location 'a' which increases exclusion duration of 'a'.
    baseUrlExclusionList.exclude(baseUrls.get(1), 10000);
    assertThat(baseUrlExclusionList.selectBaseUrl(baseUrls)).isNull();
    ShadowSystemClock.advanceBy(Duration.ofMillis(9999));
    // Location 'a' still excluded.
    assertThat(baseUrlExclusionList.selectBaseUrl(baseUrls)).isNull();
    ShadowSystemClock.advanceBy(Duration.ofMillis(1));
    assertThat(baseUrlExclusionList.getPriorityCountAfterExclusion(baseUrls)).isEqualTo(2);
    assertThat(baseUrlExclusionList.selectBaseUrl(baseUrls).url).isEqualTo("a");
}
Also used : BaseUrl(androidx.media3.exoplayer.dash.manifest.BaseUrl) Test(org.junit.Test)

Aggregations

BaseUrl (androidx.media3.exoplayer.dash.manifest.BaseUrl)17 Test (org.junit.Test)14 Nullable (androidx.annotation.Nullable)7 ArrayList (java.util.ArrayList)6 Random (java.util.Random)5 Format (androidx.media3.common.Format)3 SingleSegmentBase (androidx.media3.exoplayer.dash.manifest.SegmentBase.SingleSegmentBase)3 LoadErrorHandlingPolicy (androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy)3 IOException (java.io.IOException)3 Uri (android.net.Uri)2 SystemClock (android.os.SystemClock)2 Pair (android.util.Pair)2 C (androidx.media3.common.C)2 TrackGroup (androidx.media3.common.TrackGroup)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 PlayerId (androidx.media3.exoplayer.analytics.PlayerId)2