Search in sources :

Example 6 with C

use of com.google.android.exoplayer2.C in project ExoPlayer by google.

the class DefaultTrackSelectorTest method selectTracksPreferTrackWithinCapabilitiesOverSelectionFlag.

/**
 * Tests that track selector will prefer tracks that are within renderer's capabilities over
 * tracks that have {@link C#SELECTION_FLAG_DEFAULT} but exceed renderer's capabilities.
 */
@Test
public void selectTracksPreferTrackWithinCapabilitiesOverSelectionFlag() throws Exception {
    Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
    Format exceededWithSelectionFlagFormat = formatBuilder.setId("exceededFormat").setSelectionFlags(C.SELECTION_FLAG_DEFAULT).build();
    Format supportedFormat = formatBuilder.setId("supportedFormat").setSelectionFlags(0).build();
    TrackGroupArray trackGroups = wrapFormats(exceededWithSelectionFlagFormat, supportedFormat);
    Map<String, Integer> mappedCapabilities = new HashMap<>();
    mappedCapabilities.put(supportedFormat.id, FORMAT_HANDLED);
    mappedCapabilities.put(exceededWithSelectionFlagFormat.id, FORMAT_EXCEEDS_CAPABILITIES);
    RendererCapabilities mappedAudioRendererCapabilities = new FakeMappedRendererCapabilities(C.TRACK_TYPE_AUDIO, mappedCapabilities);
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { mappedAudioRendererCapabilities }, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, supportedFormat);
}
Also used : Format(com.google.android.exoplayer2.Format) HashMap(java.util.HashMap) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) Test(org.junit.Test)

Example 7 with C

use of com.google.android.exoplayer2.C in project ExoPlayer by google.

the class DefaultTrackSelectorTest method selectTracksPreferTrackWithinCapabilitiesOverSelectionFlagAndPreferredLanguage.

/**
 * Tests that track selector will prefer tracks that are within renderer's capabilities over track
 * that have both language matching preferred audio given by {@link Parameters} and {@link
 * C#SELECTION_FLAG_DEFAULT}, but exceed renderer's capabilities.
 */
@Test
public void selectTracksPreferTrackWithinCapabilitiesOverSelectionFlagAndPreferredLanguage() throws Exception {
    Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
    Format exceededDefaultSelectionEnFormat = formatBuilder.setId("exceededFormat").setSelectionFlags(C.SELECTION_FLAG_DEFAULT).setLanguage("eng").build();
    Format supportedFrFormat = formatBuilder.setId("supportedFormat").setSelectionFlags(0).setLanguage("fra").build();
    TrackGroupArray trackGroups = wrapFormats(exceededDefaultSelectionEnFormat, supportedFrFormat);
    Map<String, Integer> mappedCapabilities = new HashMap<>();
    mappedCapabilities.put(exceededDefaultSelectionEnFormat.id, FORMAT_EXCEEDS_CAPABILITIES);
    mappedCapabilities.put(supportedFrFormat.id, FORMAT_HANDLED);
    RendererCapabilities mappedAudioRendererCapabilities = new FakeMappedRendererCapabilities(C.TRACK_TYPE_AUDIO, mappedCapabilities);
    trackSelector.setParameters(defaultParameters.buildUpon().setPreferredAudioLanguage("eng"));
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { mappedAudioRendererCapabilities }, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, supportedFrFormat);
}
Also used : Format(com.google.android.exoplayer2.Format) HashMap(java.util.HashMap) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) Test(org.junit.Test)

Example 8 with C

use of com.google.android.exoplayer2.C in project ExoPlayer by google.

the class Id3PeekerTest method peekId3Data_returnId3TagAccordingToGivenPredicate_ifId3TagPresent.

@Test
public void peekId3Data_returnId3TagAccordingToGivenPredicate_ifId3TagPresent() throws IOException {
    Id3Peeker id3Peeker = new Id3Peeker();
    FakeExtractorInput input = new FakeExtractorInput.Builder().setData(getByteArray(ApplicationProvider.getApplicationContext(), "media/id3/comm_apic.id3")).build();
    @Nullable Metadata metadata = id3Peeker.peekId3Data(input, (majorVersion, id0, id1, id2, id3) -> id0 == 'C' && id1 == 'O' && id2 == 'M' && id3 == 'M');
    assertThat(metadata).isNotNull();
    assertThat(metadata.length()).isEqualTo(1);
    CommentFrame commentFrame = (CommentFrame) metadata.get(0);
    assertThat(commentFrame.language).isEqualTo("eng");
    assertThat(commentFrame.description).isEqualTo("description");
    assertThat(commentFrame.text).isEqualTo("text");
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) Metadata(com.google.android.exoplayer2.metadata.Metadata) CommentFrame(com.google.android.exoplayer2.metadata.id3.CommentFrame) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Example 9 with C

use of com.google.android.exoplayer2.C 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 10 with C

use of com.google.android.exoplayer2.C 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)

Aggregations

Test (org.junit.Test)14 BaseUrl (com.google.android.exoplayer2.source.dash.manifest.BaseUrl)6 Format (com.google.android.exoplayer2.Format)5 SeekPoint (com.google.android.exoplayer2.extractor.SeekPoint)5 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)4 IOException (java.io.IOException)4 Nullable (androidx.annotation.Nullable)3 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)3 HashMap (java.util.HashMap)3 Metadata (com.google.android.exoplayer2.metadata.Metadata)2 EventStream (com.google.android.exoplayer2.source.dash.manifest.EventStream)2 InterruptedIOException (java.io.InterruptedIOException)2 TargetApi (android.annotation.TargetApi)1 Activity (android.app.Activity)1 ActivityManager (android.app.ActivityManager)1 Application (android.app.Application)1 UiModeManager (android.app.UiModeManager)1 Context (android.content.Context)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1