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");
}
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);
}
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);
}
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");
}
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);
}
Aggregations