Search in sources :

Example 11 with Parameters

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

the class DefaultTrackSelectorTest method setParameterWithNonDefaultParameterNotifyInvalidationListener.

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

Example 12 with Parameters

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

the class DefaultTrackSelectorTest method selectTracks_withPreferredTextRoleFlags_selectPreferredTrack.

/**
 * Tests that track selector will select the text track with the highest number of matching role
 * flags given by {@link Parameters}.
 */
@Test
public void selectTracks_withPreferredTextRoleFlags_selectPreferredTrack() throws Exception {
    Format.Builder formatBuilder = TEXT_FORMAT.buildUpon();
    Format noRoleFlags = formatBuilder.build();
    Format lessRoleFlags = formatBuilder.setRoleFlags(C.ROLE_FLAG_CAPTION).build();
    Format moreRoleFlags = formatBuilder.setRoleFlags(C.ROLE_FLAG_CAPTION | C.ROLE_FLAG_COMMENTARY | C.ROLE_FLAG_DUB).build();
    TrackGroupArray trackGroups = wrapFormats(noRoleFlags, moreRoleFlags, lessRoleFlags);
    trackSelector.setParameters(defaultParameters.buildUpon().setPreferredTextRoleFlags(C.ROLE_FLAG_CAPTION | C.ROLE_FLAG_COMMENTARY));
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { ALL_TEXT_FORMAT_SUPPORTED_RENDERER_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, moreRoleFlags);
    // Also verify that exact match between parameters and tracks is preferred.
    trackSelector.setParameters(defaultParameters.buildUpon().setPreferredTextRoleFlags(C.ROLE_FLAG_CAPTION));
    result = trackSelector.selectTracks(new RendererCapabilities[] { ALL_TEXT_FORMAT_SUPPORTED_RENDERER_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, lessRoleFlags);
}
Also used : Format(com.google.android.exoplayer2.Format) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) Test(org.junit.Test)

Example 13 with Parameters

use of com.google.android.exoplayer2.trackselection.DefaultTrackSelector.Parameters 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 14 with Parameters

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

the class DefaultTrackSelectorTest method selectTracks_withPreferredAudioRoleFlags_selectPreferredTrack.

/**
 * Tests that track selector will select the audio track with the highest number of matching role
 * flags given by {@link Parameters}.
 */
@Test
public void selectTracks_withPreferredAudioRoleFlags_selectPreferredTrack() throws Exception {
    Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
    Format noRoleFlags = formatBuilder.build();
    Format lessRoleFlags = formatBuilder.setRoleFlags(C.ROLE_FLAG_CAPTION).build();
    Format moreRoleFlags = formatBuilder.setRoleFlags(C.ROLE_FLAG_CAPTION | C.ROLE_FLAG_COMMENTARY | C.ROLE_FLAG_DUB).build();
    TrackGroupArray trackGroups = wrapFormats(noRoleFlags, moreRoleFlags, lessRoleFlags);
    trackSelector.setParameters(defaultParameters.buildUpon().setPreferredAudioRoleFlags(C.ROLE_FLAG_CAPTION | C.ROLE_FLAG_COMMENTARY));
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, moreRoleFlags);
    // Also verify that exact match between parameters and tracks is preferred.
    trackSelector.setParameters(defaultParameters.buildUpon().setPreferredAudioRoleFlags(C.ROLE_FLAG_CAPTION));
    result = trackSelector.selectTracks(new RendererCapabilities[] { ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, lessRoleFlags);
}
Also used : Format(com.google.android.exoplayer2.Format) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) Test(org.junit.Test)

Example 15 with Parameters

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

the class DefaultTrackSelectorTest method selectTracksWithNoTrackWithinCapabilitiesSelectExceededCapabilityTrack.

/**
 * Tests that track selector will select a track that exceeds the renderer's capabilities when
 * there are no other choice, given the default {@link Parameters}.
 */
@Test
public void selectTracksWithNoTrackWithinCapabilitiesSelectExceededCapabilityTrack() throws Exception {
    TrackGroupArray trackGroups = singleTrackGroup(AUDIO_FORMAT);
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, AUDIO_FORMAT);
}
Also used : 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