Search in sources :

Example 66 with TrackSelectorResult

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

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

Example 67 with TrackSelectorResult

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

the class DefaultTrackSelectorTest method selectTracksWithClearedNullOverride.

/**
 * Tests that a null override can be cleared.
 */
@Test
public void selectTracksWithClearedNullOverride() throws ExoPlaybackException {
    trackSelector.setParameters(trackSelector.buildUponParameters().setSelectionOverride(0, new TrackGroupArray(VIDEO_TRACK_GROUP), null).clearSelectionOverride(0, new TrackGroupArray(VIDEO_TRACK_GROUP)));
    TrackSelectorResult result = trackSelector.selectTracks(RENDERER_CAPABILITIES, TRACK_GROUPS, periodId, TIMELINE);
    assertSelections(result, TRACK_SELECTIONS);
    assertThat(result.rendererConfigurations).isEqualTo(new RendererConfiguration[] { DEFAULT, DEFAULT });
}
Also used : TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) Test(org.junit.Test)

Example 68 with TrackSelectorResult

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

the class DefaultTrackSelectorTest method selectTracksPreferHigherNumChannelBeforeSampleRate.

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

Example 69 with TrackSelectorResult

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

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

Example 70 with TrackSelectorResult

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

the class DefaultTrackSelectorTest method selectTracks_withoutPreferredAudioRoleFlags_selectsDefaultTrack.

/**
 * Tests that track selector with select default audio track if no role flag preference is
 * specified by {@link Parameters}.
 */
@Test
public void selectTracks_withoutPreferredAudioRoleFlags_selectsDefaultTrack() throws Exception {
    Format firstFormat = AUDIO_FORMAT;
    Format defaultFormat = AUDIO_FORMAT.buildUpon().setSelectionFlags(C.SELECTION_FLAG_DEFAULT).build();
    Format roleFlagFormat = AUDIO_FORMAT.buildUpon().setRoleFlags(C.ROLE_FLAG_CAPTION).build();
    TrackGroupArray trackGroups = wrapFormats(firstFormat, defaultFormat, roleFlagFormat);
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, defaultFormat);
}
Also used : Format(com.google.android.exoplayer2.Format) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) 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