Search in sources :

Example 6 with Parameters

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

the class TrackSelectionParametersTest method parametersSet_fromDefault_isAsExpected.

@Test
public void parametersSet_fromDefault_isAsExpected() {
    TrackSelectionOverrides trackSelectionOverrides = new TrackSelectionOverrides.Builder().addOverride(new TrackSelectionOverride(new TrackGroup(new Format.Builder().build()))).addOverride(new TrackSelectionOverride(new TrackGroup(new Format.Builder().setId(4).build(), new Format.Builder().setId(5).build()), /* trackIndices= */
    ImmutableList.of(1))).build();
    TrackSelectionParameters parameters = TrackSelectionParameters.DEFAULT_WITHOUT_CONTEXT.buildUpon().setMaxVideoSize(/* maxVideoWidth= */
    0, /* maxVideoHeight= */
    1).setMaxVideoFrameRate(2).setMaxVideoBitrate(3).setMinVideoSize(/* minVideoWidth= */
    4, /* minVideoHeight= */
    5).setMinVideoFrameRate(6).setMinVideoBitrate(7).setViewportSize(/* viewportWidth= */
    8, /* viewportHeight= */
    9, /* viewportOrientationMayChange= */
    true).setPreferredVideoMimeTypes(MimeTypes.VIDEO_AV1, MimeTypes.VIDEO_H264).setPreferredAudioLanguages("zh", "jp").setPreferredAudioRoleFlags(C.ROLE_FLAG_COMMENTARY).setMaxAudioChannelCount(10).setMaxAudioBitrate(11).setPreferredAudioMimeTypes(MimeTypes.AUDIO_AC3, MimeTypes.AUDIO_E_AC3).setPreferredTextLanguages("de", "en").setPreferredTextRoleFlags(C.ROLE_FLAG_CAPTION).setSelectUndeterminedTextLanguage(true).setForceLowestBitrate(false).setForceHighestSupportedBitrate(true).setTrackSelectionOverrides(trackSelectionOverrides).setDisabledTrackTypes(ImmutableSet.of(C.TRACK_TYPE_AUDIO, C.TRACK_TYPE_TEXT)).build();
    // Video
    assertThat(parameters.maxVideoWidth).isEqualTo(0);
    assertThat(parameters.maxVideoHeight).isEqualTo(1);
    assertThat(parameters.maxVideoFrameRate).isEqualTo(2);
    assertThat(parameters.maxVideoBitrate).isEqualTo(3);
    assertThat(parameters.minVideoWidth).isEqualTo(4);
    assertThat(parameters.minVideoHeight).isEqualTo(5);
    assertThat(parameters.minVideoFrameRate).isEqualTo(6);
    assertThat(parameters.minVideoBitrate).isEqualTo(7);
    assertThat(parameters.viewportWidth).isEqualTo(8);
    assertThat(parameters.viewportHeight).isEqualTo(9);
    assertThat(parameters.viewportOrientationMayChange).isTrue();
    assertThat(parameters.preferredVideoMimeTypes).containsExactly(MimeTypes.VIDEO_AV1, MimeTypes.VIDEO_H264).inOrder();
    // Audio
    assertThat(parameters.preferredAudioLanguages).containsExactly("zh", "jp").inOrder();
    assertThat(parameters.preferredAudioRoleFlags).isEqualTo(C.ROLE_FLAG_COMMENTARY);
    assertThat(parameters.maxAudioChannelCount).isEqualTo(10);
    assertThat(parameters.maxAudioBitrate).isEqualTo(11);
    assertThat(parameters.preferredAudioMimeTypes).containsExactly(MimeTypes.AUDIO_AC3, MimeTypes.AUDIO_E_AC3).inOrder();
    // Text
    assertThat(parameters.preferredTextLanguages).containsExactly("de", "en").inOrder();
    assertThat(parameters.preferredTextRoleFlags).isEqualTo(C.ROLE_FLAG_CAPTION);
    assertThat(parameters.selectUndeterminedTextLanguage).isTrue();
    // General
    assertThat(parameters.forceLowestBitrate).isFalse();
    assertThat(parameters.forceHighestSupportedBitrate).isTrue();
    assertThat(parameters.trackSelectionOverrides).isEqualTo(trackSelectionOverrides);
    assertThat(parameters.disabledTrackTypes).containsExactly(C.TRACK_TYPE_AUDIO, C.TRACK_TYPE_TEXT);
}
Also used : TrackGroup(com.google.android.exoplayer2.source.TrackGroup) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) Test(org.junit.Test)

Example 7 with Parameters

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

the class DefaultTrackSelector method getLegacyRendererOverride.

// Calling deprecated getSelectionOverride.
@SuppressWarnings("deprecation")
private ExoTrackSelection.@NullableType Definition getLegacyRendererOverride(MappedTrackInfo mappedTrackInfo, Parameters params, int rendererIndex) {
    TrackGroupArray rendererTrackGroups = mappedTrackInfo.getTrackGroups(rendererIndex);
    @Nullable SelectionOverride override = params.getSelectionOverride(rendererIndex, rendererTrackGroups);
    if (override == null) {
        return null;
    }
    return new ExoTrackSelection.Definition(rendererTrackGroups.get(override.groupIndex), override.tracks, override.type);
}
Also used : TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) Nullable(androidx.annotation.Nullable)

Example 8 with Parameters

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

the class DefaultTrackSelectorTest method selectTracksSelectTrackWithSelectionFlag.

/**
 * Tests that track selector will select audio track with {@link C#SELECTION_FLAG_DEFAULT} given
 * default values of {@link Parameters}.
 */
@Test
public void selectTracksSelectTrackWithSelectionFlag() throws Exception {
    Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
    Format audioFormat = formatBuilder.setSelectionFlags(0).build();
    Format formatWithSelectionFlag = formatBuilder.setSelectionFlags(C.SELECTION_FLAG_DEFAULT).build();
    TrackGroupArray trackGroups = wrapFormats(audioFormat, formatWithSelectionFlag);
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, formatWithSelectionFlag);
}
Also used : Format(com.google.android.exoplayer2.Format) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) Test(org.junit.Test)

Example 9 with Parameters

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

the class DefaultTrackSelectorTest method setParameterWithSameParametersDoesNotNotifyInvalidationListenerAgain.

/**
 * Tests that track selector will not call {@link
 * InvalidationListener#onTrackSelectionsInvalidated()} again when it's set with the same values
 * of {@link Parameters}.
 */
@Test
public void setParameterWithSameParametersDoesNotNotifyInvalidationListenerAgain() {
    ParametersBuilder builder = defaultParameters.buildUpon().setPreferredAudioLanguage("eng");
    trackSelector.setParameters(builder);
    trackSelector.setParameters(builder);
    verify(invalidationListener, times(1)).onTrackSelectionsInvalidated();
}
Also used : ParametersBuilder(com.google.android.exoplayer2.trackselection.DefaultTrackSelector.ParametersBuilder) Test(org.junit.Test)

Example 10 with Parameters

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

the class DefaultTrackSelectorTest method selectTracks_withoutPreferredAudioRoleFlagsOrDefaultTrack_selectsFirstTrack.

/**
 * Tests that track selector with select the first audio track if no role flag preference is
 * specified by {@link Parameters} and no default track exists.
 */
@Test
public void selectTracks_withoutPreferredAudioRoleFlagsOrDefaultTrack_selectsFirstTrack() throws Exception {
    Format firstFormat = AUDIO_FORMAT;
    Format roleFlagFormat = AUDIO_FORMAT.buildUpon().setRoleFlags(C.ROLE_FLAG_CAPTION).build();
    TrackGroupArray trackGroups = wrapFormats(firstFormat, roleFlagFormat);
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, firstFormat);
}
Also used : Format(com.google.android.exoplayer2.Format) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)23 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)19 Format (com.google.android.exoplayer2.Format)15 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)9 Nullable (androidx.annotation.Nullable)5 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)4 HashMap (java.util.HashMap)4 SuppressLint (android.annotation.SuppressLint)3 Point (android.graphics.Point)3 ParametersBuilder (com.google.android.exoplayer2.trackselection.DefaultTrackSelector.ParametersBuilder)3 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)3 Pair (android.util.Pair)2 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)2 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)2 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)2 Parameters (com.google.android.exoplayer2.trackselection.DefaultTrackSelector.Parameters)2 TargetApi (android.annotation.TargetApi)1 Context (android.content.Context)1 SparseArray (android.util.SparseArray)1 ExoPlaybackException (com.google.android.exoplayer2.ExoPlaybackException)1