Search in sources :

Example 61 with TrackSelectorResult

use of com.google.android.exoplayer2.trackselection.TrackSelectorResult in project ExoPlayer by google.

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(com.google.android.exoplayer2.source.TrackGroupArray) Test(org.junit.Test)

Example 62 with TrackSelectorResult

use of com.google.android.exoplayer2.trackselection.TrackSelectorResult in project ExoPlayer by google.

the class DefaultTrackSelectorTest method selectTracksWithinCapabilitiesSelectHigherSampleRate.

/**
 * Tests that track selector will select audio tracks with higher sample rate when other factors
 * are the same, and tracks are within renderer's capabilities.
 */
@Test
public void selectTracksWithinCapabilitiesSelectHigherSampleRate() throws Exception {
    Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
    Format higherSampleRateFormat = formatBuilder.setSampleRate(44100).build();
    Format lowerSampleRateFormat = formatBuilder.setSampleRate(22050).build();
    TrackGroupArray trackGroups = wrapFormats(higherSampleRateFormat, lowerSampleRateFormat);
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, higherSampleRateFormat);
}
Also used : Format(com.google.android.exoplayer2.Format) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) Test(org.junit.Test)

Example 63 with TrackSelectorResult

use of com.google.android.exoplayer2.trackselection.TrackSelectorResult in project ExoPlayer by google.

the class DefaultTrackSelectorTest method selectUndeterminedTextLanguageAsFallback.

/**
 * Tests that the default track selector will select a text track with undetermined language if no
 * text track with the preferred language is available but {@link
 * Parameters#selectUndeterminedTextLanguage} is true.
 */
@Test
public void selectUndeterminedTextLanguageAsFallback() throws ExoPlaybackException {
    Format.Builder formatBuilder = TEXT_FORMAT.buildUpon();
    Format spanish = formatBuilder.setLanguage("spa").build();
    Format german = formatBuilder.setLanguage("de").build();
    Format undeterminedUnd = formatBuilder.setLanguage(C.LANGUAGE_UNDETERMINED).build();
    Format undeterminedNull = formatBuilder.setLanguage(null).build();
    RendererCapabilities[] textRendererCapabilites = new RendererCapabilities[] { ALL_TEXT_FORMAT_SUPPORTED_RENDERER_CAPABILITIES };
    TrackGroupArray trackGroups = wrapFormats(spanish, german, undeterminedUnd, undeterminedNull);
    TrackSelectorResult result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
    assertNoSelection(result.selections[0]);
    trackSelector.setParameters(defaultParameters.buildUpon().setSelectUndeterminedTextLanguage(true));
    result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, undeterminedUnd);
    ParametersBuilder builder = defaultParameters.buildUpon().setPreferredTextLanguage("spa");
    trackSelector.setParameters(builder);
    result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, spanish);
    trackGroups = wrapFormats(german, undeterminedUnd, undeterminedNull);
    result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
    assertNoSelection(result.selections[0]);
    trackSelector.setParameters(builder.setSelectUndeterminedTextLanguage(true));
    result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, undeterminedUnd);
    trackGroups = wrapFormats(german, undeterminedNull);
    result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, undeterminedNull);
    trackGroups = wrapFormats(german);
    result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
    assertNoSelection(result.selections[0]);
}
Also used : ParametersBuilder(com.google.android.exoplayer2.trackselection.DefaultTrackSelector.ParametersBuilder) Format(com.google.android.exoplayer2.Format) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) Test(org.junit.Test)

Example 64 with TrackSelectorResult

use of com.google.android.exoplayer2.trackselection.TrackSelectorResult in project ExoPlayer by google.

the class DefaultTrackSelectorTest method selectTracksWithNullOverrideForDifferentTracks.

/**
 * Tests that an override is not applied for a different set of available track groups.
 */
@Test
public void selectTracksWithNullOverrideForDifferentTracks() throws ExoPlaybackException {
    TrackGroup videoGroup0 = VIDEO_TRACK_GROUP.copyWithId("0");
    TrackGroup videoGroup1 = VIDEO_TRACK_GROUP.copyWithId("1");
    trackSelector.setParameters(trackSelector.buildUponParameters().setSelectionOverride(0, new TrackGroupArray(VIDEO_TRACK_GROUP.copyWithId("2")), null));
    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(com.google.android.exoplayer2.source.TrackGroup) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) Test(org.junit.Test)

Example 65 with TrackSelectorResult

use of com.google.android.exoplayer2.trackselection.TrackSelectorResult in project ExoPlayer by google.

the class DefaultTrackSelectorTest method selectTracks_withPreferredVideoMimeTypes_selectsTrackWithPreferredMimeType.

@Test
public void selectTracks_withPreferredVideoMimeTypes_selectsTrackWithPreferredMimeType() throws Exception {
    Format formatAv1 = new Format.Builder().setSampleMimeType(MimeTypes.VIDEO_AV1).build();
    Format formatVp9 = new Format.Builder().setSampleMimeType(MimeTypes.VIDEO_VP9).build();
    Format formatH264Low = new Format.Builder().setSampleMimeType(MimeTypes.VIDEO_H264).setAverageBitrate(400).build();
    Format formatH264High = new Format.Builder().setSampleMimeType(MimeTypes.VIDEO_H264).setAverageBitrate(800).build();
    // Use an adaptive group to check that MIME type has a higher priority than number of tracks.
    TrackGroup adaptiveGroup = new TrackGroup(formatH264Low, formatH264High);
    TrackGroupArray trackGroups = new TrackGroupArray(new TrackGroup(formatAv1), new TrackGroup(formatVp9), adaptiveGroup);
    trackSelector.setParameters(defaultParameters.buildUpon().setPreferredVideoMimeType(MimeTypes.VIDEO_VP9));
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { VIDEO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertThat(result.length).isEqualTo(1);
    assertFixedSelection(result.selections[0], trackGroups, formatVp9);
    trackSelector.setParameters(defaultParameters.buildUpon().setPreferredVideoMimeTypes(MimeTypes.VIDEO_VP9, MimeTypes.VIDEO_AV1));
    result = trackSelector.selectTracks(new RendererCapabilities[] { VIDEO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertThat(result.length).isEqualTo(1);
    assertFixedSelection(result.selections[0], trackGroups, formatVp9);
    trackSelector.setParameters(defaultParameters.buildUpon().setPreferredVideoMimeTypes(MimeTypes.VIDEO_DIVX, MimeTypes.VIDEO_H264));
    result = trackSelector.selectTracks(new RendererCapabilities[] { VIDEO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertThat(result.length).isEqualTo(1);
    assertAdaptiveSelection(result.selections[0], adaptiveGroup, /* expectedTracks...= */
    1, 0);
    // Select default (=most tracks) if no preference is specified.
    trackSelector.setParameters(defaultParameters.buildUpon().setPreferredVideoMimeType(null));
    result = trackSelector.selectTracks(new RendererCapabilities[] { VIDEO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertThat(result.length).isEqualTo(1);
    assertAdaptiveSelection(result.selections[0], adaptiveGroup, /* expectedTracks...= */
    1, 0);
}
Also used : Format(com.google.android.exoplayer2.Format) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) ParametersBuilder(com.google.android.exoplayer2.trackselection.DefaultTrackSelector.ParametersBuilder) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) Test(org.junit.Test)

Aggregations

TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)62 Test (org.junit.Test)58 Format (com.google.android.exoplayer2.Format)47 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)30 TrackSelectorResult (com.google.android.exoplayer2.trackselection.TrackSelectorResult)17 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)12 HashMap (java.util.HashMap)8 ParametersBuilder (com.google.android.exoplayer2.trackselection.DefaultTrackSelector.ParametersBuilder)7 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)6 SampleStream (com.google.android.exoplayer2.source.SampleStream)5 TrackSelection (com.google.android.exoplayer2.trackselection.TrackSelection)5 Nullable (androidx.annotation.Nullable)4 Capabilities (com.google.android.exoplayer2.RendererCapabilities.Capabilities)4 TextRenderer (com.google.android.exoplayer2.text.TextRenderer)4 ExoTrackSelection (com.google.android.exoplayer2.trackselection.ExoTrackSelection)3 ExoPlaybackException (com.google.android.exoplayer2.ExoPlaybackException)2 AdaptiveSupport (com.google.android.exoplayer2.RendererCapabilities.AdaptiveSupport)2 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)2 BaseTrackSelection (com.google.android.exoplayer2.trackselection.BaseTrackSelection)2 SelectionOverride (com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride)2