Search in sources :

Example 26 with RendererCapabilities

use of androidx.media3.exoplayer.RendererCapabilities in project media by androidx.

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(androidx.media3.exoplayer.trackselection.DefaultTrackSelector.ParametersBuilder) Format(androidx.media3.common.Format) TrackGroupArray(androidx.media3.common.TrackGroupArray) RendererCapabilities(androidx.media3.exoplayer.RendererCapabilities) Test(org.junit.Test)

Example 27 with RendererCapabilities

use of androidx.media3.exoplayer.RendererCapabilities in project media by androidx.

the class DefaultTrackSelectorTest method selectAudioTracks_withinCapabilities_andSameLanguage_selectsHigherBitrate.

/**
 * Tests that track selector will select audio tracks with higher bit rate when other factors are
 * the same, and tracks are within renderer's capabilities, and have the same language.
 */
@Test
public void selectAudioTracks_withinCapabilities_andSameLanguage_selectsHigherBitrate() throws Exception {
    Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon().setLanguage("en");
    Format lowerBitrateFormat = formatBuilder.setAverageBitrate(15000).build();
    Format higherBitrateFormat = formatBuilder.setAverageBitrate(30000).build();
    TrackGroupArray trackGroups = wrapFormats(lowerBitrateFormat, higherBitrateFormat);
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, higherBitrateFormat);
}
Also used : Format(androidx.media3.common.Format) TrackGroupArray(androidx.media3.common.TrackGroupArray) Test(org.junit.Test)

Example 28 with RendererCapabilities

use of androidx.media3.exoplayer.RendererCapabilities in project media by androidx.

the class DefaultTrackSelectorTest method selectTracksWithNoTrackWithinCapabilitiesAndSetByParamsReturnNoSelection.

/**
 * Tests that track selector will return a null track selection for a renderer when all tracks
 * exceed that renderer's capabilities when {@link Parameters} does not allow
 * exceeding-capabilities tracks.
 */
@Test
public void selectTracksWithNoTrackWithinCapabilitiesAndSetByParamsReturnNoSelection() throws Exception {
    TrackGroupArray trackGroups = singleTrackGroup(AUDIO_FORMAT);
    trackSelector.setParameters(defaultParameters.buildUpon().setExceedRendererCapabilitiesIfNecessary(false));
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertNoSelection(result.selections[0]);
}
Also used : TrackGroupArray(androidx.media3.common.TrackGroupArray) Test(org.junit.Test)

Example 29 with RendererCapabilities

use of androidx.media3.exoplayer.RendererCapabilities in project media by androidx.

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(androidx.media3.common.Format) TrackGroupArray(androidx.media3.common.TrackGroupArray) RendererCapabilities(androidx.media3.exoplayer.RendererCapabilities) Test(org.junit.Test)

Example 30 with RendererCapabilities

use of androidx.media3.exoplayer.RendererCapabilities in project media by androidx.

the class DefaultTrackSelectorTest method selectPreferredAudioTrackMultipleRenderers.

/**
 * Tests audio track selection when there are multiple audio renderers.
 */
@Test
public void selectPreferredAudioTrackMultipleRenderers() throws Exception {
    Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
    Format english = formatBuilder.setId("en").setLanguage("en").build();
    Format german = formatBuilder.setId("de").setLanguage("de").build();
    // First renderer handles english.
    Map<String, Integer> firstRendererMappedCapabilities = new HashMap<>();
    firstRendererMappedCapabilities.put(english.id, FORMAT_HANDLED);
    firstRendererMappedCapabilities.put(german.id, FORMAT_UNSUPPORTED_SUBTYPE);
    RendererCapabilities firstRendererCapabilities = new FakeMappedRendererCapabilities(C.TRACK_TYPE_AUDIO, firstRendererMappedCapabilities);
    // Second renderer handles german.
    Map<String, Integer> secondRendererMappedCapabilities = new HashMap<>();
    secondRendererMappedCapabilities.put(english.id, FORMAT_UNSUPPORTED_SUBTYPE);
    secondRendererMappedCapabilities.put(german.id, FORMAT_HANDLED);
    RendererCapabilities secondRendererCapabilities = new FakeMappedRendererCapabilities(C.TRACK_TYPE_AUDIO, secondRendererMappedCapabilities);
    RendererCapabilities[] rendererCapabilities = new RendererCapabilities[] { firstRendererCapabilities, secondRendererCapabilities };
    // Without an explicit language preference, prefer the first renderer.
    TrackGroupArray trackGroups = wrapFormats(english, german);
    TrackSelectorResult result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, english);
    assertNoSelection(result.selections[1]);
    // Explicit language preference for english. First renderer should be used.
    trackSelector.setParameters(defaultParameters.buildUpon().setPreferredAudioLanguage("en"));
    result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, english);
    assertNoSelection(result.selections[1]);
    // Explicit language preference for German. Second renderer should be used.
    trackSelector.setParameters(defaultParameters.buildUpon().setPreferredAudioLanguage("de"));
    result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
    assertNoSelection(result.selections[0]);
    assertFixedSelection(result.selections[1], trackGroups, german);
}
Also used : Format(androidx.media3.common.Format) HashMap(java.util.HashMap) TrackGroupArray(androidx.media3.common.TrackGroupArray) RendererCapabilities(androidx.media3.exoplayer.RendererCapabilities) Test(org.junit.Test)

Aggregations

TrackGroupArray (androidx.media3.common.TrackGroupArray)58 Test (org.junit.Test)57 Format (androidx.media3.common.Format)47 RendererCapabilities (androidx.media3.exoplayer.RendererCapabilities)35 TrackGroup (androidx.media3.common.TrackGroup)9 HashMap (java.util.HashMap)8 ParametersBuilder (androidx.media3.exoplayer.trackselection.DefaultTrackSelector.ParametersBuilder)5 TrackSelectionOverride (androidx.media3.common.TrackSelectionOverrides.TrackSelectionOverride)4 Capabilities (androidx.media3.exoplayer.RendererCapabilities.Capabilities)3 Nullable (androidx.annotation.Nullable)2 SelectionOverride (androidx.media3.exoplayer.trackselection.DefaultTrackSelector.SelectionOverride)2 TrackSelectorResult (androidx.media3.exoplayer.trackselection.TrackSelectorResult)2 Handler (android.os.Handler)1 FormatSupport (androidx.media3.common.C.FormatSupport)1 TracksInfo (androidx.media3.common.TracksInfo)1 ExoPlaybackException (androidx.media3.exoplayer.ExoPlaybackException)1 Renderer (androidx.media3.exoplayer.Renderer)1 AdaptiveSupport (androidx.media3.exoplayer.RendererCapabilities.AdaptiveSupport)1 AnalyticsCollector (androidx.media3.exoplayer.analytics.AnalyticsCollector)1 DefaultAnalyticsCollector (androidx.media3.exoplayer.analytics.DefaultAnalyticsCollector)1