Search in sources :

Example 21 with BaseUrl

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

the class BaseUrlExclusionListTest method selectBaseUrl_excludeByPriority_excludesAllBaseUrlsOfSamePriority.

@Test
public void selectBaseUrl_excludeByPriority_excludesAllBaseUrlsOfSamePriority() {
    Random mockRandom = mock(Random.class);
    when(mockRandom.nextInt(anyInt())).thenReturn(0);
    BaseUrlExclusionList baseUrlExclusionList = new BaseUrlExclusionList(mockRandom);
    List<BaseUrl> baseUrls = ImmutableList.of(new BaseUrl(/* url= */
    "a", /* serviceLocation= */
    "a", /* priority= */
    1, /* weight= */
    1), new BaseUrl(/* url= */
    "b", /* serviceLocation= */
    "b", /* priority= */
    1, /* weight= */
    99), new BaseUrl(/* url= */
    "c", /* serviceLocation= */
    "c", /* priority= */
    2, /* 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 : Random(java.util.Random) BaseUrl(androidx.media3.exoplayer.dash.manifest.BaseUrl) Test(org.junit.Test)

Example 22 with BaseUrl

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

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(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