Search in sources :

Example 16 with RendererCapabilities

use of com.google.android.exoplayer2.RendererCapabilities in project ExoPlayer by google.

the class DefaultTrackSelectorTest method selectTracks_multipleVideoTracksWithoutBitrate_onlySelectsSingleTrack.

@Test
public void selectTracks_multipleVideoTracksWithoutBitrate_onlySelectsSingleTrack() throws Exception {
    TrackGroupArray trackGroups = singleTrackGroup(VIDEO_FORMAT.buildUpon().setId("0").setAverageBitrate(Format.NO_VALUE).build(), VIDEO_FORMAT.buildUpon().setId("1").setAverageBitrate(Format.NO_VALUE).build());
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { VIDEO_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 17 with RendererCapabilities

use of com.google.android.exoplayer2.RendererCapabilities 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 18 with RendererCapabilities

use of com.google.android.exoplayer2.RendererCapabilities in project ExoPlayer by google.

the class DefaultTrackSelectorTest method selectTracksWithMultipleAudioTracksWithMixedChannelCounts.

@Test
public void selectTracksWithMultipleAudioTracksWithMixedChannelCounts() throws Exception {
    Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
    Format stereoAudioFormat = formatBuilder.setChannelCount(2).build();
    Format surroundAudioFormat = formatBuilder.setChannelCount(5).build();
    // Should not adapt between different channel counts, so we expect a fixed selection containing
    // the track with more channels.
    TrackGroupArray trackGroups = singleTrackGroup(stereoAudioFormat, surroundAudioFormat);
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { AUDIO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertThat(result.length).isEqualTo(1);
    assertFixedSelection(result.selections[0], trackGroups, surroundAudioFormat);
    // The same applies if the tracks are provided in the opposite order.
    trackGroups = singleTrackGroup(surroundAudioFormat, stereoAudioFormat);
    result = trackSelector.selectTracks(new RendererCapabilities[] { AUDIO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertThat(result.length).isEqualTo(1);
    assertFixedSelection(result.selections[0], trackGroups, surroundAudioFormat);
    // If we constrain the channel count to 4 we expect a fixed selection containing the track with
    // fewer channels.
    trackSelector.setParameters(defaultParameters.buildUpon().setMaxAudioChannelCount(4));
    result = trackSelector.selectTracks(new RendererCapabilities[] { AUDIO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertThat(result.length).isEqualTo(1);
    assertFixedSelection(result.selections[0], trackGroups, stereoAudioFormat);
    // If we constrain the channel count to 2 we expect a fixed selection containing the track with
    // fewer channels.
    trackSelector.setParameters(defaultParameters.buildUpon().setMaxAudioChannelCount(2));
    result = trackSelector.selectTracks(new RendererCapabilities[] { AUDIO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertThat(result.length).isEqualTo(1);
    assertFixedSelection(result.selections[0], trackGroups, stereoAudioFormat);
    // If we constrain the channel count to 1 we expect a fixed selection containing the track with
    // fewer channels.
    trackSelector.setParameters(defaultParameters.buildUpon().setMaxAudioChannelCount(1));
    result = trackSelector.selectTracks(new RendererCapabilities[] { AUDIO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertThat(result.length).isEqualTo(1);
    assertFixedSelection(result.selections[0], trackGroups, stereoAudioFormat);
    // If we disable exceeding of constraints we expect no selection.
    trackSelector.setParameters(defaultParameters.buildUpon().setMaxAudioChannelCount(1).setExceedAudioConstraintsIfNecessary(false));
    result = trackSelector.selectTracks(new RendererCapabilities[] { AUDIO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertThat(result.length).isEqualTo(1);
    assertNoSelection(result.selections[0]);
}
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 19 with RendererCapabilities

use of com.google.android.exoplayer2.RendererCapabilities 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)

Example 20 with RendererCapabilities

use of com.google.android.exoplayer2.RendererCapabilities in project ExoPlayer by google.

the class DefaultTrackSelectorTest method selectTracksWithinCapabilitiesAndForceHighestBitrateSelectHigherBitrate.

/**
 * Tests that track selector will select the highest bitrate supported audio track when {@link
 * Parameters#forceHighestSupportedBitrate} is set.
 */
@Test
public void selectTracksWithinCapabilitiesAndForceHighestBitrateSelectHigherBitrate() throws Exception {
    Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
    Format lowerBitrateFormat = formatBuilder.setId("5000").setAverageBitrate(5000).build();
    Format higherBitrateFormat = formatBuilder.setId("15000").setAverageBitrate(15000).build();
    Format exceedsBitrateFormat = formatBuilder.setId("30000").setAverageBitrate(30000).build();
    TrackGroupArray trackGroups = wrapFormats(lowerBitrateFormat, higherBitrateFormat, exceedsBitrateFormat);
    Map<String, Integer> mappedCapabilities = new HashMap<>();
    mappedCapabilities.put(lowerBitrateFormat.id, FORMAT_HANDLED);
    mappedCapabilities.put(higherBitrateFormat.id, FORMAT_HANDLED);
    mappedCapabilities.put(exceedsBitrateFormat.id, FORMAT_EXCEEDS_CAPABILITIES);
    RendererCapabilities mappedAudioRendererCapabilities = new FakeMappedRendererCapabilities(C.TRACK_TYPE_AUDIO, mappedCapabilities);
    trackSelector.setParameters(defaultParameters.buildUpon().setForceHighestSupportedBitrate(true));
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { mappedAudioRendererCapabilities }, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, higherBitrateFormat);
}
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)

Aggregations

TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)59 Test (org.junit.Test)57 Format (com.google.android.exoplayer2.Format)47 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)36 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)11 HashMap (java.util.HashMap)8 ParametersBuilder (com.google.android.exoplayer2.trackselection.DefaultTrackSelector.ParametersBuilder)5 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)4 Capabilities (com.google.android.exoplayer2.RendererCapabilities.Capabilities)3 Nullable (androidx.annotation.Nullable)2 RendererConfiguration (com.google.android.exoplayer2.RendererConfiguration)2 SelectionOverride (com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride)2 TrackSelectorResult (com.google.android.exoplayer2.trackselection.TrackSelectorResult)2 Point (android.graphics.Point)1 Handler (android.os.Handler)1 FormatSupport (com.google.android.exoplayer2.C.FormatSupport)1 ExoPlaybackException (com.google.android.exoplayer2.ExoPlaybackException)1 Renderer (com.google.android.exoplayer2.Renderer)1 AdaptiveSupport (com.google.android.exoplayer2.RendererCapabilities.AdaptiveSupport)1 TracksInfo (com.google.android.exoplayer2.TracksInfo)1