DefaultTrackSelector extends MappingTrackSelector { @Override protected final Pair<@NullableType RendererConfiguration[], @NullableType TrackSelection[]> selectTracks( MappedTrackInfo mappedTrackInfo, @Capabilities int[][][] rendererFormatSupports, @AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupports) throws ExoPlaybackException { Parameters params = parametersReference.get(); int rendererCount = mappedTrackInfo.getRendererCount(); TrackSelection.@NullableType Definition[] definitions = selectAllTracks( mappedTrackInfo, rendererFormatSupports, rendererMixedMimeTypeAdaptationSupports, params); for (int i = 0; i < rendererCount; i++) { if (params.getRendererDisabled(i)) { definitions[i] = null; continue; } TrackGroupArray rendererTrackGroups = mappedTrackInfo.getTrackGroups(i); if (params.hasSelectionOverride(i, rendererTrackGroups)) { SelectionOverride override = params.getSelectionOverride(i, rendererTrackGroups); definitions[i] = override == null ? null : new TrackSelection.Definition( rendererTrackGroups.get(override.groupIndex), override.tracks, override.reason, override.data); } } @NullableType TrackSelection[] rendererTrackSelections = trackSelectionFactory.createTrackSelections(definitions, getBandwidthMeter()); @NullableType RendererConfiguration[] rendererConfigurations = new RendererConfiguration[rendererCount]; for (int i = 0; i < rendererCount; i++) { boolean forceRendererDisabled = params.getRendererDisabled(i); boolean rendererEnabled = !forceRendererDisabled && (mappedTrackInfo.getRendererType(i) == C.TRACK_TYPE_NONE || rendererTrackSelections[i] != null); rendererConfigurations[i] = rendererEnabled ? RendererConfiguration.DEFAULT : null; } maybeConfigureRenderersForTunneling( mappedTrackInfo, rendererFormatSupports, rendererConfigurations, rendererTrackSelections, params.tunnelingAudioSessionId); return Pair.create(rendererConfigurations, rendererTrackSelections); } @Deprecated @SuppressWarnings("deprecation")  DefaultTrackSelector(); @Deprecated @SuppressWarnings("deprecation")  DefaultTrackSelector(BandwidthMeter bandwidthMeter); @Deprecated  DefaultTrackSelector(TrackSelection.Factory trackSelectionFactory);  DefaultTrackSelector(Context context);  DefaultTrackSelector(Context context, TrackSelection.Factory trackSelectionFactory);  DefaultTrackSelector(Parameters parameters, TrackSelection.Factory trackSelectionFactory); void setParameters(Parameters parameters); void setParameters(ParametersBuilder parametersBuilder); Parameters getParameters(); ParametersBuilder buildUponParameters(); @Deprecated final void setRendererDisabled(int rendererIndex, boolean disabled); @Deprecated final boolean getRendererDisabled(int rendererIndex); @Deprecated final void setSelectionOverride(
      int rendererIndex, TrackGroupArray groups, @Nullable SelectionOverride override); @Deprecated final boolean hasSelectionOverride(int rendererIndex, TrackGroupArray groups); @Deprecated @Nullable final SelectionOverride getSelectionOverride(int rendererIndex, TrackGroupArray groups); @Deprecated final void clearSelectionOverride(int rendererIndex, TrackGroupArray groups); @Deprecated final void clearSelectionOverrides(int rendererIndex); @Deprecated final void clearSelectionOverrides(); @Deprecated void setTunnelingAudioSessionId(int tunnelingAudioSessionId); void experimental_allowMultipleAdaptiveSelections();  }
@Test public void testSelectTracksWithNoSampleRenderer() throws ExoPlaybackException { TrackSelectorResult result = trackSelector.selectTracks( RENDERER_CAPABILITIES_WITH_NO_SAMPLE_RENDERER, TRACK_GROUPS, periodId, TIMELINE); assertSelections(result, TRACK_SELECTIONS_WITH_NO_SAMPLE_RENDERER); assertThat(new RendererConfiguration[] {DEFAULT, DEFAULT}) .isEqualTo(result.rendererConfigurations); }
@Test public void testSelectTracksSelectTrackWithSelectionFlag() throws Exception { Format audioFormat = buildAudioFormatWithLanguageAndFlags( "audio", null, 0); Format formatWithSelectionFlag = buildAudioFormatWithLanguageAndFlags( "audio", null, C.SELECTION_FLAG_DEFAULT); TrackGroupArray trackGroups = wrapFormats(audioFormat, formatWithSelectionFlag); TrackSelectorResult result = trackSelector.selectTracks( new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES}, trackGroups, periodId, TIMELINE); assertFixedSelection(result.selections.get(0), trackGroups, formatWithSelectionFlag); }
@Test public void testSelectTracksPreferTrackWithinCapabilities() throws Exception { Format supportedFormat = buildAudioFormat("supportedFormat"); Format exceededFormat = buildAudioFormat("exceededFormat"); 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.get(0), trackGroups, supportedFormat); }
@Test public void testSelectTracksWithNoTrackWithinCapabilitiesSelectExceededCapabilityTrack() throws Exception { Format audioFormat = Format.createAudioSampleFormat("audio", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.NO_VALUE, 2, 44100, null, null, 0, null); TrackGroupArray trackGroups = singleTrackGroup(audioFormat); TrackSelectorResult result = trackSelector.selectTracks( new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES}, trackGroups, periodId, TIMELINE); assertFixedSelection(result.selections.get(0), trackGroups, audioFormat); }
@Test public void testSelectTracksPreferTrackWithinCapabilitiesOverSelectionFlag() throws Exception { Format exceededWithSelectionFlagFormat = Format.createAudioSampleFormat( "exceededFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.NO_VALUE, 2, 44100, null, null, C.SELECTION_FLAG_DEFAULT, null); Format supportedFormat = Format.createAudioSampleFormat("supportedFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.NO_VALUE, 2, 44100, null, null, 0, null); TrackGroupArray trackGroups = wrapFormats(exceededWithSelectionFlagFormat, supportedFormat); Map<String, Integer> mappedCapabilities = new HashMap<>(); mappedCapabilities.put(supportedFormat.id, FORMAT_HANDLED); mappedCapabilities.put(exceededWithSelectionFlagFormat.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.get(0), trackGroups, supportedFormat); }
@Test public void testSelectTracksWithinCapabilitiesSelectHigherNumChannel() throws Exception { Format higherChannelFormat = Format.createAudioSampleFormat( "audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.NO_VALUE, 6, 44100, null, null, 0, null); Format lowerChannelFormat = Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.NO_VALUE, 2, 44100, null, null, 0, null); TrackGroupArray trackGroups = wrapFormats(higherChannelFormat, lowerChannelFormat); TrackSelectorResult result = trackSelector.selectTracks( new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES}, trackGroups, periodId, TIMELINE); assertFixedSelection(result.selections.get(0), trackGroups, higherChannelFormat); }
@Test public void testSelectTracksWithinCapabilitiesSelectHigherSampleRate() throws Exception { Format higherSampleRateFormat = Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.NO_VALUE, 2, 44100, null, null, 0, null); Format lowerSampleRateFormat = Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.NO_VALUE, 2, 22050, null, null, 0, null); TrackGroupArray trackGroups = wrapFormats(higherSampleRateFormat, lowerSampleRateFormat); TrackSelectorResult result = trackSelector.selectTracks( new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES}, trackGroups, periodId, TIMELINE); assertFixedSelection(result.selections.get(0), trackGroups, higherSampleRateFormat); }
@Test public void selectAudioTracks_withinCapabilities_andSameLanguage_selectsHigherBitrate() throws Exception { Format lowerBitrateFormat = Format.createAudioSampleFormat( "audioFormat", MimeTypes.AUDIO_AAC, null, 15000, Format.NO_VALUE, 2, 44100, null, null, 0, "hi"); Format higherBitrateFormat = Format.createAudioSampleFormat( "audioFormat", MimeTypes.AUDIO_AAC, null, 30000, Format.NO_VALUE, 2, 44100, null, null, 0, "hi"); TrackGroupArray trackGroups = wrapFormats(lowerBitrateFormat, higherBitrateFormat); TrackSelectorResult result = trackSelector.selectTracks( new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES}, trackGroups, periodId, TIMELINE); assertFixedSelection(result.selections.get(0), trackGroups, higherBitrateFormat); }
@Test public void selectAudioTracks_withinCapabilities_andDifferentLanguage_selectsFirstTrack() throws Exception { Format firstLanguageFormat = Format.createAudioSampleFormat( "audioFormat", MimeTypes.AUDIO_AAC, null, 15000, Format.NO_VALUE, 2, 44100, null, null, 0, "hi"); Format higherBitrateFormat = Format.createAudioSampleFormat( "audioFormat", MimeTypes.AUDIO_AAC, null, 30000, Format.NO_VALUE, 2, 44100, null, null, 0, "te"); TrackGroupArray trackGroups = wrapFormats(firstLanguageFormat, higherBitrateFormat); TrackSelectorResult result = trackSelector.selectTracks( new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES}, trackGroups, periodId, TIMELINE); assertFixedSelection(result.selections.get(0), trackGroups, firstLanguageFormat); }
@Test public void testSelectTracksPreferHigherNumChannelBeforeSampleRate() throws Exception { Format higherChannelLowerSampleRateFormat = Format.createAudioSampleFormat( "audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.NO_VALUE, 6, 22050, null, null, 0, null); Format lowerChannelHigherSampleRateFormat = Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.NO_VALUE, 2, 44100, null, null, 0, null); TrackGroupArray trackGroups = wrapFormats(higherChannelLowerSampleRateFormat, lowerChannelHigherSampleRateFormat); TrackSelectorResult result = trackSelector.selectTracks( new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES}, trackGroups, periodId, TIMELINE); assertFixedSelection(result.selections.get(0), trackGroups, higherChannelLowerSampleRateFormat); }
@Test public void testSelectTracksPreferHigherSampleRateBeforeBitrate() throws Exception { Format higherSampleRateLowerBitrateFormat = Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 15000, Format.NO_VALUE, 2, 44100, null, null, 0, null); Format lowerSampleRateHigherBitrateFormat = Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 30000, Format.NO_VALUE, 2, 22050, null, null, 0, null); TrackGroupArray trackGroups = wrapFormats(higherSampleRateLowerBitrateFormat, lowerSampleRateHigherBitrateFormat); TrackSelectorResult result = trackSelector.selectTracks( new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES}, trackGroups, periodId, TIMELINE); assertFixedSelection(result.selections.get(0), trackGroups, higherSampleRateLowerBitrateFormat); }
@Test public void testSelectTracksExceedingCapabilitiesSelectLowerNumChannel() throws Exception { Format higherChannelFormat = Format.createAudioSampleFormat( "audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.NO_VALUE, 6, 44100, null, null, 0, null); Format lowerChannelFormat = Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.NO_VALUE, 2, 44100, null, null, 0, null); TrackGroupArray trackGroups = wrapFormats(higherChannelFormat, lowerChannelFormat); TrackSelectorResult result = trackSelector.selectTracks( new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES}, trackGroups, periodId, TIMELINE); assertFixedSelection(result.selections.get(0), trackGroups, lowerChannelFormat); }
@Test public void testSelectTracksExceedingCapabilitiesSelectLowerSampleRate() throws Exception { Format lowerSampleRateFormat = Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.NO_VALUE, 2, 22050, null, null, 0, null); Format higherSampleRateFormat = Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.NO_VALUE, 2, 44100, null, null, 0, null); TrackGroupArray trackGroups = wrapFormats(higherSampleRateFormat, lowerSampleRateFormat); TrackSelectorResult result = trackSelector.selectTracks( new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES}, trackGroups, periodId, TIMELINE); assertFixedSelection(result.selections.get(0), trackGroups, lowerSampleRateFormat); }
@Test public void testSelectTracksExceedingCapabilitiesSelectLowerBitrate() throws Exception { Format lowerBitrateFormat = Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 15000, Format.NO_VALUE, 2, 44100, null, null, 0, null); Format higherBitrateFormat = Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 30000, Format.NO_VALUE, 2, 44100, null, null, 0, null); TrackGroupArray trackGroups = wrapFormats(lowerBitrateFormat, higherBitrateFormat); TrackSelectorResult result = trackSelector.selectTracks( new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES}, trackGroups, periodId, TIMELINE); assertFixedSelection(result.selections.get(0), trackGroups, lowerBitrateFormat); }
@Test public void testSelectTracksExceedingCapabilitiesPreferLowerNumChannelBeforeSampleRate() throws Exception { Format lowerChannelHigherSampleRateFormat = Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.NO_VALUE, 2, 44100, null, null, 0, null); Format higherChannelLowerSampleRateFormat = Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.NO_VALUE, 6, 22050, null, null, 0, null); TrackGroupArray trackGroups = wrapFormats(higherChannelLowerSampleRateFormat, lowerChannelHigherSampleRateFormat); TrackSelectorResult result = trackSelector.selectTracks( new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES}, trackGroups, periodId, TIMELINE); assertFixedSelection(result.selections.get(0), trackGroups, lowerChannelHigherSampleRateFormat); }
@Test public void testSelectTracksExceedingCapabilitiesPreferLowerSampleRateBeforeBitrate() throws Exception { Format higherSampleRateLowerBitrateFormat = Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 15000, Format.NO_VALUE, 2, 44100, null, null, 0, null); Format lowerSampleRateHigherBitrateFormat = Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 30000, Format.NO_VALUE, 2, 22050, null, null, 0, null); TrackGroupArray trackGroups = wrapFormats(higherSampleRateLowerBitrateFormat, lowerSampleRateHigherBitrateFormat); TrackSelectorResult result = trackSelector.selectTracks( new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES}, trackGroups, periodId, TIMELINE); assertFixedSelection(result.selections.get(0), trackGroups, lowerSampleRateHigherBitrateFormat); }
@Test public void testSelectingForcedTextTrackMatchesAudioLanguage() throws ExoPlaybackException { Format forcedEnglish = buildTextFormat( "forcedEnglish", "eng", C.SELECTION_FLAG_FORCED); Format forcedGerman = buildTextFormat( "forcedGerman", "deu", C.SELECTION_FLAG_FORCED); Format forcedNoLanguage = buildTextFormat( "forcedNoLanguage", C.LANGUAGE_UNDETERMINED, C.SELECTION_FLAG_FORCED); Format audio = buildAudioFormat( "audio"); Format germanAudio = buildAudioFormat( "germanAudio", MimeTypes.AUDIO_AAC, Format.NO_VALUE, "deu", 0, Format.NO_VALUE, Format.NO_VALUE); RendererCapabilities[] rendererCapabilities = new RendererCapabilities[] { ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES, ALL_TEXT_FORMAT_SUPPORTED_RENDERER_CAPABILITIES }; TrackGroupArray trackGroups = wrapFormats(audio, forcedNoLanguage); TrackSelectorResult result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE); assertFixedSelection(result.selections.get(1), trackGroups, forcedNoLanguage); trackGroups = wrapFormats(audio, forcedEnglish, forcedGerman); result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE); assertNoSelection(result.selections.get(1)); trackGroups = wrapFormats(germanAudio, forcedGerman, forcedEnglish); result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE); assertFixedSelection(result.selections.get(1), trackGroups, forcedGerman); trackGroups = wrapFormats(germanAudio, forcedEnglish, forcedGerman); result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE); assertFixedSelection(result.selections.get(1), trackGroups, forcedGerman); }
@Test public void testSelectTracksWithMultipleAudioTracks() throws Exception { TrackGroupArray trackGroups = singleTrackGroup(buildAudioFormat("0"), buildAudioFormat("1")); TrackSelectorResult result = trackSelector.selectTracks( new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE); assertThat(result.length).isEqualTo(1); assertAdaptiveSelection(result.selections.get(0), trackGroups.get(0), 0, 1); }
@Test public void testSelectTracksWithMultipleVideoTracks() throws Exception { TrackGroupArray trackGroups = singleTrackGroup(buildVideoFormat("0"), buildVideoFormat("1")); TrackSelectorResult result = trackSelector.selectTracks( new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE); assertThat(result.length).isEqualTo(1); assertAdaptiveSelection(result.selections.get(0), trackGroups.get(0), 0, 1); }