Search in sources :

Example 96 with TrackGroupArray

use of androidx.media3.common.TrackGroupArray in project media by androidx.

the class DefaultTrackSelectorTest method selectTracks_withEmptyTrackOverrideForDifferentTracks_hasNoEffect.

/**
 * Tests that an empty override is not applied for a different set of available track groups.
 */
@Test
public void selectTracks_withEmptyTrackOverrideForDifferentTracks_hasNoEffect() throws ExoPlaybackException {
    TrackGroup videoGroup0 = VIDEO_TRACK_GROUP.copyWithId("0");
    TrackGroup videoGroup1 = VIDEO_TRACK_GROUP.copyWithId("1");
    trackSelector.setParameters(trackSelector.buildUponParameters().setTrackSelectionOverrides(new TrackSelectionOverrides.Builder().setOverrideForType(new TrackSelectionOverride(new TrackGroup(VIDEO_FORMAT, VIDEO_FORMAT), ImmutableList.of())).build()));
    TrackSelectorResult result = trackSelector.selectTracks(RENDERER_CAPABILITIES, new TrackGroupArray(videoGroup0, AUDIO_TRACK_GROUP, videoGroup1), periodId, TIMELINE);
    assertThat(result.selections).asList().containsExactly(new FixedTrackSelection(videoGroup0, /* track= */
    0), new FixedTrackSelection(AUDIO_TRACK_GROUP, /* track= */
    0)).inOrder();
    assertThat(result.rendererConfigurations).isEqualTo(new RendererConfiguration[] { DEFAULT, DEFAULT });
}
Also used : TrackGroup(androidx.media3.common.TrackGroup) ParametersBuilder(androidx.media3.exoplayer.trackselection.DefaultTrackSelector.ParametersBuilder) TrackGroupArray(androidx.media3.common.TrackGroupArray) TrackSelectionOverride(androidx.media3.common.TrackSelectionOverrides.TrackSelectionOverride) Test(org.junit.Test)

Example 97 with TrackGroupArray

use of androidx.media3.common.TrackGroupArray in project media by androidx.

the class DefaultTrackSelectorTest method selectTracksWithMultipleAudioTracksWithMixedSampleRates.

@Test
public void selectTracksWithMultipleAudioTracksWithMixedSampleRates() throws Exception {
    Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
    Format highSampleRateAudioFormat = formatBuilder.setSampleRate(44100).build();
    Format lowSampleRateAudioFormat = formatBuilder.setSampleRate(22050).build();
    // Should not adapt between mixed sample rates by default, so we expect a fixed selection
    // containing the higher sample rate stream.
    TrackGroupArray trackGroups = singleTrackGroup(highSampleRateAudioFormat, lowSampleRateAudioFormat);
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { AUDIO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertThat(result.length).isEqualTo(1);
    assertFixedSelection(result.selections[0], trackGroups, highSampleRateAudioFormat);
    // The same applies if the tracks are provided in the opposite order.
    trackGroups = singleTrackGroup(lowSampleRateAudioFormat, highSampleRateAudioFormat);
    result = trackSelector.selectTracks(new RendererCapabilities[] { AUDIO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertThat(result.length).isEqualTo(1);
    assertFixedSelection(result.selections[0], trackGroups, highSampleRateAudioFormat);
    // If we explicitly enable mixed sample rate adaptiveness, expect an adaptive selection.
    trackSelector.setParameters(defaultParameters.buildUpon().setAllowAudioMixedSampleRateAdaptiveness(true));
    result = trackSelector.selectTracks(new RendererCapabilities[] { AUDIO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertThat(result.length).isEqualTo(1);
    assertAdaptiveSelection(result.selections[0], trackGroups.get(0), 0, 1);
}
Also used : Format(androidx.media3.common.Format) TrackGroupArray(androidx.media3.common.TrackGroupArray) RendererCapabilities(androidx.media3.exoplayer.RendererCapabilities) Test(org.junit.Test)

Example 98 with TrackGroupArray

use of androidx.media3.common.TrackGroupArray in project media by androidx.

the class DefaultTrackSelectorTest method selectTracks_multipleAudioTracksWithoutBitrate_onlySelectsSingleTrack.

@Test
public void selectTracks_multipleAudioTracksWithoutBitrate_onlySelectsSingleTrack() throws Exception {
    TrackGroupArray trackGroups = singleTrackGroup(AUDIO_FORMAT.buildUpon().setId("0").setAverageBitrate(Format.NO_VALUE).build(), AUDIO_FORMAT.buildUpon().setId("1").setAverageBitrate(Format.NO_VALUE).build());
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { AUDIO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertThat(result.length).isEqualTo(1);
    assertFixedSelection(result.selections[0], trackGroups.get(0), /* expectedTrack= */
    0);
}
Also used : TrackGroupArray(androidx.media3.common.TrackGroupArray) Test(org.junit.Test)

Example 99 with TrackGroupArray

use of androidx.media3.common.TrackGroupArray in project media by androidx.

the class DefaultTrackSelectorTest method selectTracks_multipleAudioTracks_selectsAllTracksInBestConfigurationOnly.

@Test
public void selectTracks_multipleAudioTracks_selectsAllTracksInBestConfigurationOnly() throws Exception {
    TrackGroupArray trackGroups = singleTrackGroup(buildAudioFormatWithConfiguration(/* id= */
    "0", /* channelCount= */
    6, MimeTypes.AUDIO_AAC, /* sampleRate= */
    44100), buildAudioFormatWithConfiguration(/* id= */
    "1", /* channelCount= */
    2, MimeTypes.AUDIO_AAC, /* sampleRate= */
    44100), buildAudioFormatWithConfiguration(/* id= */
    "2", /* channelCount= */
    6, MimeTypes.AUDIO_AC3, /* sampleRate= */
    44100), buildAudioFormatWithConfiguration(/* id= */
    "3", /* channelCount= */
    6, MimeTypes.AUDIO_AAC, /* sampleRate= */
    22050), buildAudioFormatWithConfiguration(/* id= */
    "4", /* channelCount= */
    6, MimeTypes.AUDIO_AAC, /* sampleRate= */
    22050), buildAudioFormatWithConfiguration(/* id= */
    "5", /* channelCount= */
    6, MimeTypes.AUDIO_AAC, /* sampleRate= */
    22050), buildAudioFormatWithConfiguration(/* id= */
    "6", /* channelCount= */
    6, MimeTypes.AUDIO_AAC, /* sampleRate= */
    44100));
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { AUDIO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertThat(result.length).isEqualTo(1);
    assertAdaptiveSelection(result.selections[0], trackGroups.get(0), 0, 6);
}
Also used : TrackGroupArray(androidx.media3.common.TrackGroupArray) Test(org.junit.Test)

Example 100 with TrackGroupArray

use of androidx.media3.common.TrackGroupArray in project media by androidx.

the class DefaultTrackSelectorTest method forcedAndDefaultTextTracksInteractWithSelectedAudioLanguageAsExpected.

/**
 * Tests that the default track selector will select:
 *
 * <ul>
 *   <li>A forced text track with unknown language if the selected audio language is also unknown.
 *   <li>A forced text track matching the selected audio language.
 *   <li>A default text track matching the selected audio language when a default text track in
 *       another language is present.
 *   <li>A default text track that doesn't match the selected audio language when a default text
 *       track in the selected audio language is not present (but other text tracks in this
 *       language are present).
 * </ul>
 */
@Test
public void forcedAndDefaultTextTracksInteractWithSelectedAudioLanguageAsExpected() throws ExoPlaybackException {
    Format.Builder forcedTextBuilder = TEXT_FORMAT.buildUpon().setSelectionFlags(C.SELECTION_FLAG_FORCED);
    Format.Builder defaultTextBuilder = TEXT_FORMAT.buildUpon().setSelectionFlags(C.SELECTION_FLAG_DEFAULT);
    Format forcedEnglish = forcedTextBuilder.setLanguage("eng").build();
    Format defaultEnglish = defaultTextBuilder.setLanguage("eng").build();
    Format forcedGerman = forcedTextBuilder.setLanguage("deu").build();
    Format defaultGerman = defaultTextBuilder.setLanguage("deu").build();
    Format forcedNoLanguage = forcedTextBuilder.setLanguage(C.LANGUAGE_UNDETERMINED).build();
    Format noLanguageAudio = AUDIO_FORMAT.buildUpon().setLanguage(null).build();
    Format germanAudio = AUDIO_FORMAT.buildUpon().setLanguage("deu").build();
    RendererCapabilities[] rendererCapabilities = new RendererCapabilities[] { ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES, ALL_TEXT_FORMAT_SUPPORTED_RENDERER_CAPABILITIES };
    // Neither the audio nor the forced text track define a language. We select them both under the
    // assumption that they have matching language.
    TrackGroupArray trackGroups = wrapFormats(noLanguageAudio, forcedNoLanguage);
    TrackSelectorResult result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[1], trackGroups, forcedNoLanguage);
    // No forced text track should be selected because none of the forced text tracks' languages
    // matches the selected audio language.
    trackGroups = wrapFormats(noLanguageAudio, forcedEnglish, forcedGerman);
    result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
    assertNoSelection(result.selections[1]);
    // The audio declares german. The german forced track should be selected.
    trackGroups = wrapFormats(germanAudio, forcedGerman, forcedEnglish);
    result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[1], trackGroups, forcedGerman);
    // Ditto
    trackGroups = wrapFormats(germanAudio, forcedEnglish, forcedGerman);
    result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[1], trackGroups, forcedGerman);
    // The audio declares german. The default german track should be selected (in favour of the
    // default english track and forced german track).
    trackGroups = wrapFormats(germanAudio, forcedGerman, defaultGerman, forcedEnglish, defaultEnglish);
    result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[1], trackGroups, defaultGerman);
    // The audio declares german. The default english track should be selected because there's no
    // default german track.
    trackGroups = wrapFormats(germanAudio, forcedGerman, forcedEnglish, defaultEnglish);
    result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[1], trackGroups, defaultEnglish);
}
Also used : Format(androidx.media3.common.Format) TrackGroupArray(androidx.media3.common.TrackGroupArray) RendererCapabilities(androidx.media3.exoplayer.RendererCapabilities) Test(org.junit.Test)

Aggregations

TrackGroupArray (androidx.media3.common.TrackGroupArray)117 Test (org.junit.Test)92 Format (androidx.media3.common.Format)60 TrackGroup (androidx.media3.common.TrackGroup)40 RendererCapabilities (androidx.media3.exoplayer.RendererCapabilities)36 Nullable (androidx.annotation.Nullable)18 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)17 FakeTimeline (androidx.media3.test.utils.FakeTimeline)17 TransferListener (androidx.media3.datasource.TransferListener)14 DrmSessionManager (androidx.media3.exoplayer.drm.DrmSessionManager)13 MediaPeriodId (androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)13 FakeMediaPeriod (androidx.media3.test.utils.FakeMediaPeriod)13 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)13 Allocator (androidx.media3.exoplayer.upstream.Allocator)12 MediaSource (androidx.media3.exoplayer.source.MediaSource)10 MediaItem (androidx.media3.common.MediaItem)9 ClippingMediaSource (androidx.media3.exoplayer.source.ClippingMediaSource)9 CompositeMediaSource (androidx.media3.exoplayer.source.CompositeMediaSource)9 ConcatenatingMediaSource (androidx.media3.exoplayer.source.ConcatenatingMediaSource)9 MaskingMediaSource (androidx.media3.exoplayer.source.MaskingMediaSource)9