Search in sources :

Example 26 with TrackGroupArray

use of com.google.android.exoplayer2.source.TrackGroupArray 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 27 with TrackGroupArray

use of com.google.android.exoplayer2.source.TrackGroupArray in project ExoPlayer by google.

the class DefaultTrackSelectorTest method selectTracksPreferTrackWithinCapabilities.

/**
 * Tests that track selector will prefer tracks that are within renderer's capabilities over track
 * that exceed renderer's capabilities.
 */
@Test
public void selectTracksPreferTrackWithinCapabilities() throws Exception {
    Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
    Format supportedFormat = formatBuilder.setId("supportedFormat").build();
    Format exceededFormat = formatBuilder.setId("exceededFormat").build();
    TrackGroupArray trackGroups = wrapFormats(exceededFormat, supportedFormat);
    Map<String, Integer> mappedCapabilities = new HashMap<>();
    mappedCapabilities.put(supportedFormat.id, FORMAT_HANDLED);
    mappedCapabilities.put(exceededFormat.id, FORMAT_EXCEEDS_CAPABILITIES);
    RendererCapabilities mappedAudioRendererCapabilities = new FakeMappedRendererCapabilities(C.TRACK_TYPE_AUDIO, mappedCapabilities);
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { mappedAudioRendererCapabilities }, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, supportedFormat);
}
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 28 with TrackGroupArray

use of com.google.android.exoplayer2.source.TrackGroupArray in project ExoPlayer by google.

the class DefaultTrackSelectorTest method textTrackSelectionFlags.

/**
 * Tests text track selection flags.
 */
@Test
public void textTrackSelectionFlags() throws ExoPlaybackException {
    Format.Builder formatBuilder = TEXT_FORMAT.buildUpon().setLanguage("eng");
    Format forcedOnly = formatBuilder.setSelectionFlags(C.SELECTION_FLAG_FORCED).build();
    Format forcedDefault = formatBuilder.setSelectionFlags(C.SELECTION_FLAG_FORCED | C.SELECTION_FLAG_DEFAULT).build();
    Format defaultOnly = formatBuilder.setSelectionFlags(C.SELECTION_FLAG_DEFAULT).build();
    Format noFlag = formatBuilder.setSelectionFlags(0).build();
    RendererCapabilities[] textRendererCapabilities = new RendererCapabilities[] { ALL_TEXT_FORMAT_SUPPORTED_RENDERER_CAPABILITIES };
    // There is no text language preference, the first track flagged as default should be selected.
    TrackGroupArray trackGroups = wrapFormats(forcedOnly, forcedDefault, defaultOnly, noFlag);
    TrackSelectorResult result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, forcedDefault);
    // Ditto.
    trackGroups = wrapFormats(forcedOnly, noFlag, defaultOnly);
    result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, defaultOnly);
    // Default flags are disabled and no language preference is provided, so no text track is
    // selected.
    trackGroups = wrapFormats(defaultOnly, noFlag, forcedOnly, forcedDefault);
    trackSelector.setParameters(defaultParameters.buildUpon().setDisabledTextTrackSelectionFlags(C.SELECTION_FLAG_DEFAULT));
    result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
    assertNoSelection(result.selections[0]);
    // All selection flags are disabled and there is no language preference, so nothing should be
    // selected.
    trackGroups = wrapFormats(forcedOnly, forcedDefault, defaultOnly, noFlag);
    trackSelector.setParameters(trackSelector.getParameters().buildUpon().setDisabledTextTrackSelectionFlags(C.SELECTION_FLAG_DEFAULT | C.SELECTION_FLAG_FORCED));
    result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
    assertNoSelection(result.selections[0]);
    // There is a preferred language, so a language-matching track flagged as default should
    // be selected, and the one without forced flag should be preferred.
    trackSelector.setParameters(defaultParameters.buildUpon().setPreferredTextLanguage("eng"));
    result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, defaultOnly);
    // Same as above, but the default flag is disabled. If multiple tracks match the preferred
    // language, those not flagged as forced are preferred, as they likely include the contents of
    // forced subtitles.
    trackGroups = wrapFormats(noFlag, forcedOnly, forcedDefault, defaultOnly);
    trackSelector.setParameters(trackSelector.getParameters().buildUpon().setDisabledTextTrackSelectionFlags(C.SELECTION_FLAG_DEFAULT));
    result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, noFlag);
}
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 29 with TrackGroupArray

use of com.google.android.exoplayer2.source.TrackGroupArray in project ExoPlayer by google.

the class DefaultTrackSelectorTest method selectTracksWithMultipleVideoTracksWithMixedDecoderSupportLevels.

@Test
public void selectTracksWithMultipleVideoTracksWithMixedDecoderSupportLevels() throws Exception {
    Format.Builder formatBuilder = VIDEO_FORMAT.buildUpon();
    Format format0 = formatBuilder.setId("0").setAverageBitrate(200).build();
    Format format1 = formatBuilder.setId("1").setAverageBitrate(400).build();
    Format format2 = formatBuilder.setId("2").setAverageBitrate(600).build();
    Format format3 = formatBuilder.setId("3").setAverageBitrate(800).build();
    TrackGroupArray trackGroups = singleTrackGroup(format0, format1, format2, format3);
    @Capabilities int unsupported = RendererCapabilities.create(FORMAT_UNSUPPORTED_TYPE);
    @Capabilities int primaryHardware = RendererCapabilities.create(FORMAT_HANDLED, ADAPTIVE_NOT_SEAMLESS, TUNNELING_NOT_SUPPORTED, HARDWARE_ACCELERATION_SUPPORTED, DECODER_SUPPORT_PRIMARY);
    @Capabilities int primarySoftware = RendererCapabilities.create(FORMAT_HANDLED, ADAPTIVE_NOT_SEAMLESS, TUNNELING_NOT_SUPPORTED, HARDWARE_ACCELERATION_NOT_SUPPORTED, DECODER_SUPPORT_PRIMARY);
    @Capabilities int fallbackHardware = RendererCapabilities.create(FORMAT_HANDLED, ADAPTIVE_NOT_SEAMLESS, TUNNELING_NOT_SUPPORTED, HARDWARE_ACCELERATION_SUPPORTED, DECODER_SUPPORT_FALLBACK);
    @Capabilities int fallbackSoftware = RendererCapabilities.create(FORMAT_HANDLED, ADAPTIVE_NOT_SEAMLESS, TUNNELING_NOT_SUPPORTED, HARDWARE_ACCELERATION_NOT_SUPPORTED, DECODER_SUPPORT_FALLBACK);
    // Select all tracks supported by primary, hardware decoder by default.
    ImmutableMap<String, Integer> rendererCapabilitiesMap = ImmutableMap.of("0", primaryHardware, "1", primaryHardware, "2", primarySoftware, "3", fallbackHardware);
    RendererCapabilities rendererCapabilities = new FakeMappedRendererCapabilities(C.TRACK_TYPE_VIDEO, rendererCapabilitiesMap);
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { rendererCapabilities }, trackGroups, periodId, TIMELINE);
    assertAdaptiveSelection(result.selections[0], trackGroups.get(0), 1, 0);
    // Select all tracks supported by primary, software decoder by default if no primary, hardware
    // decoder is available.
    rendererCapabilitiesMap = ImmutableMap.of("0", fallbackHardware, "1", fallbackHardware, "2", primarySoftware, "3", fallbackSoftware);
    rendererCapabilities = new FakeMappedRendererCapabilities(C.TRACK_TYPE_VIDEO, rendererCapabilitiesMap);
    result = trackSelector.selectTracks(new RendererCapabilities[] { rendererCapabilities }, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups.get(0), 2);
    // Select all tracks supported by fallback, hardware decoder if no primary decoder is
    // available.
    rendererCapabilitiesMap = ImmutableMap.of("0", fallbackHardware, "1", unsupported, "2", fallbackSoftware, "3", fallbackHardware);
    rendererCapabilities = new FakeMappedRendererCapabilities(C.TRACK_TYPE_VIDEO, rendererCapabilitiesMap);
    result = trackSelector.selectTracks(new RendererCapabilities[] { rendererCapabilities }, trackGroups, periodId, TIMELINE);
    assertAdaptiveSelection(result.selections[0], trackGroups.get(0), 3, 0);
    // Select all tracks supported by fallback, software decoder if no other decoder is available.
    rendererCapabilitiesMap = ImmutableMap.of("0", fallbackSoftware, "1", fallbackSoftware, "2", unsupported, "3", fallbackSoftware);
    rendererCapabilities = new FakeMappedRendererCapabilities(C.TRACK_TYPE_VIDEO, rendererCapabilitiesMap);
    result = trackSelector.selectTracks(new RendererCapabilities[] { rendererCapabilities }, trackGroups, periodId, TIMELINE);
    assertAdaptiveSelection(result.selections[0], trackGroups.get(0), 3, 1, 0);
    // Select all tracks if mixed decoder support is allowed.
    rendererCapabilitiesMap = ImmutableMap.of("0", primaryHardware, "1", unsupported, "2", primarySoftware, "3", fallbackHardware);
    rendererCapabilities = new FakeMappedRendererCapabilities(C.TRACK_TYPE_VIDEO, rendererCapabilitiesMap);
    trackSelector.setParameters(defaultParameters.buildUpon().setAllowVideoMixedDecoderSupportAdaptiveness(true));
    result = trackSelector.selectTracks(new RendererCapabilities[] { rendererCapabilities }, trackGroups, periodId, TIMELINE);
    assertAdaptiveSelection(result.selections[0], trackGroups.get(0), 3, 2, 0);
}
Also used : Format(com.google.android.exoplayer2.Format) Capabilities(com.google.android.exoplayer2.RendererCapabilities.Capabilities) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) Test(org.junit.Test)

Example 30 with TrackGroupArray

use of com.google.android.exoplayer2.source.TrackGroupArray 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

TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)126 Test (org.junit.Test)92 Format (com.google.android.exoplayer2.Format)67 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)50 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)36 Nullable (androidx.annotation.Nullable)18 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)17 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)17 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)14 DrmSessionManager (com.google.android.exoplayer2.drm.DrmSessionManager)13 MediaSource (com.google.android.exoplayer2.source.MediaSource)13 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)13 FakeMediaPeriod (com.google.android.exoplayer2.testutil.FakeMediaPeriod)13 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)13 Allocator (com.google.android.exoplayer2.upstream.Allocator)12 ArrayList (java.util.ArrayList)11 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)9 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)9 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)9 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)9