Search in sources :

Example 6 with BaseUrl

use of com.google.android.exoplayer2.source.dash.manifest.BaseUrl in project ExoPlayer by google.

the class DashUtilTest method resolveCacheKey_representationCacheKeyDefined_usesRepresentationCacheKey.

@Test
public void resolveCacheKey_representationCacheKeyDefined_usesRepresentationCacheKey() {
    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", /* contentLength= */
    1);
    RangedUri rangedUri = new RangedUri("path/to/resource", /* start= */
    0, /* length= */
    1);
    String cacheKey = DashUtil.resolveCacheKey(representation, rangedUri);
    assertThat(cacheKey).isEqualTo("cacheKey");
}
Also used : SingleSegmentBase(com.google.android.exoplayer2.source.dash.manifest.SegmentBase.SingleSegmentBase) RangedUri(com.google.android.exoplayer2.source.dash.manifest.RangedUri) Representation(com.google.android.exoplayer2.source.dash.manifest.Representation) BaseUrl(com.google.android.exoplayer2.source.dash.manifest.BaseUrl) Test(org.junit.Test)

Example 7 with BaseUrl

use of com.google.android.exoplayer2.source.dash.manifest.BaseUrl 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 8 with BaseUrl

use of com.google.android.exoplayer2.source.dash.manifest.BaseUrl in project ExoPlayer by google.

the class BaseUrlExclusionListTest method selectBaseUrl_samePriority_choiceIsRandom.

@Test
public void selectBaseUrl_samePriority_choiceIsRandom() {
    List<BaseUrl> baseUrls = ImmutableList.of(new BaseUrl(/* url= */
    "a", /* serviceLocation= */
    "a", /* priority= */
    1, /* weight= */
    99), new BaseUrl(/* url= */
    "b", /* serviceLocation= */
    "b", /* priority= */
    1, /* weight= */
    1));
    Random mockRandom = mock(Random.class);
    when(mockRandom.nextInt(anyInt())).thenReturn(99);
    assertThat(new BaseUrlExclusionList(mockRandom).selectBaseUrl(baseUrls)).isEqualTo(baseUrls.get(1));
    // Random is used for random choice.
    verify(mockRandom).nextInt(/* bound= */
    100);
    verifyNoMoreInteractions(mockRandom);
}
Also used : Random(java.util.Random) BaseUrl(com.google.android.exoplayer2.source.dash.manifest.BaseUrl) Test(org.junit.Test)

Example 9 with BaseUrl

use of com.google.android.exoplayer2.source.dash.manifest.BaseUrl in project ExoPlayer by google.

the class BaseUrlExclusionListTest method selectBaseUrl_excludeByServiceLocation_excludesAllBaseUrlOfSameServiceLocation.

@Test
public void selectBaseUrl_excludeByServiceLocation_excludesAllBaseUrlOfSameServiceLocation() {
    BaseUrlExclusionList baseUrlExclusionList = new BaseUrlExclusionList();
    List<BaseUrl> baseUrls = ImmutableList.of(new BaseUrl(/* url= */
    "a", /* serviceLocation= */
    "a", /* priority= */
    1, /* weight= */
    1), new BaseUrl(/* url= */
    "b", /* serviceLocation= */
    "a", /* priority= */
    2, /* weight= */
    1), new BaseUrl(/* url= */
    "c", /* serviceLocation= */
    "c", /* priority= */
    3, /* weight= */
    1));
    baseUrlExclusionList.exclude(baseUrls.get(0), 5000);
    ShadowSystemClock.advanceBy(Duration.ofMillis(4999));
    assertThat(baseUrlExclusionList.selectBaseUrl(baseUrls).url).isEqualTo("c");
    ShadowSystemClock.advanceBy(Duration.ofMillis(1));
    assertThat(baseUrlExclusionList.selectBaseUrl(baseUrls).url).isEqualTo("a");
}
Also used : BaseUrl(com.google.android.exoplayer2.source.dash.manifest.BaseUrl) Test(org.junit.Test)

Example 10 with BaseUrl

use of com.google.android.exoplayer2.source.dash.manifest.BaseUrl in project ExoPlayer by google.

the class BaseUrlExclusionListTest method selectBaseUrl_samePriority_choiceFromSameElementsRandomOnlyOnceSameAfterwards.

@Test
public void selectBaseUrl_samePriority_choiceFromSameElementsRandomOnlyOnceSameAfterwards() {
    List<BaseUrl> baseUrlsVideo = ImmutableList.of(new BaseUrl(/* url= */
    "a/v", /* serviceLocation= */
    "a", /* priority= */
    1, /* weight= */
    99), new BaseUrl(/* url= */
    "b/v", /* serviceLocation= */
    "b", /* priority= */
    1, /* weight= */
    1));
    List<BaseUrl> baseUrlsAudio = ImmutableList.of(new BaseUrl(/* url= */
    "a/a", /* serviceLocation= */
    "a", /* priority= */
    1, /* weight= */
    99), new BaseUrl(/* url= */
    "b/a", /* serviceLocation= */
    "b", /* priority= */
    1, /* weight= */
    1));
    Random mockRandom = mock(Random.class);
    BaseUrlExclusionList baseUrlExclusionList = new BaseUrlExclusionList(mockRandom);
    when(mockRandom.nextInt(anyInt())).thenReturn(99);
    for (int i = 0; i < 5; i++) {
        assertThat(baseUrlExclusionList.selectBaseUrl(baseUrlsVideo).serviceLocation).isEqualTo("b");
        assertThat(baseUrlExclusionList.selectBaseUrl(baseUrlsAudio).serviceLocation).isEqualTo("b");
    }
    // Random is used only once.
    verify(mockRandom).nextInt(/* bound= */
    100);
    verifyNoMoreInteractions(mockRandom);
}
Also used : Random(java.util.Random) BaseUrl(com.google.android.exoplayer2.source.dash.manifest.BaseUrl) Test(org.junit.Test)

Aggregations

BaseUrl (com.google.android.exoplayer2.source.dash.manifest.BaseUrl)17 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)9 Nullable (androidx.annotation.Nullable)7 SingleSegmentBase (com.google.android.exoplayer2.source.dash.manifest.SegmentBase.SingleSegmentBase)6 Random (java.util.Random)5 Format (com.google.android.exoplayer2.Format)4 RangedUri (com.google.android.exoplayer2.source.dash.manifest.RangedUri)4 Representation (com.google.android.exoplayer2.source.dash.manifest.Representation)4 Uri (android.net.Uri)3 Pair (android.util.Pair)3 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)3 LoadErrorHandlingPolicy (com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy)3 SystemClock (android.os.SystemClock)2 ApplicationProvider (androidx.test.core.app.ApplicationProvider)2 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)2 C (com.google.android.exoplayer2.C)2 PlayerId (com.google.android.exoplayer2.analytics.PlayerId)2 SchemeData (com.google.android.exoplayer2.drm.DrmInitData.SchemeData)2 LoadEventInfo (com.google.android.exoplayer2.source.LoadEventInfo)2