Search in sources :

Example 1 with BaseUrl

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

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(androidx.media3.exoplayer.dash.manifest.BaseUrl) Test(org.junit.Test)

Example 2 with BaseUrl

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

the class BaseUrlExclusionListTest method reset_dropsAllExclusions.

@Test
public void reset_dropsAllExclusions() {
    BaseUrlExclusionList baseUrlExclusionList = new BaseUrlExclusionList();
    ImmutableList<BaseUrl> baseUrls = ImmutableList.of(new BaseUrl("a", "a", DEFAULT_DVB_PRIORITY, DEFAULT_WEIGHT));
    baseUrlExclusionList.exclude(baseUrls.get(0), 5000);
    baseUrlExclusionList.reset();
    assertThat(baseUrlExclusionList.selectBaseUrl(baseUrls).url).isEqualTo("a");
}
Also used : BaseUrl(androidx.media3.exoplayer.dash.manifest.BaseUrl) Test(org.junit.Test)

Example 3 with BaseUrl

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

the class BaseUrlExclusionListTest method getPriorityCount_correctPriorityCount.

@Test
public void getPriorityCount_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));
    assertThat(BaseUrlExclusionList.getPriorityCount(baseUrls)).isEqualTo(3);
    assertThat(BaseUrlExclusionList.getPriorityCount(ImmutableList.of())).isEqualTo(0);
}
Also used : BaseUrl(androidx.media3.exoplayer.dash.manifest.BaseUrl) Test(org.junit.Test)

Example 4 with BaseUrl

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

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(androidx.media3.exoplayer.dash.manifest.BaseUrl) Test(org.junit.Test)

Example 5 with BaseUrl

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

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