Search in sources :

Example 16 with Parameters

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

Example 17 with Parameters

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

the class DefaultTrackSelectorTest method selectTracksPreferTrackWithinCapabilitiesOverPreferredLanguage.

/**
 * Tests that track selector will prefer tracks that are within renderer's capabilities over track
 * that have language matching preferred audio given by {@link Parameters} but exceed renderer's
 * capabilities.
 */
@Test
public void selectTracksPreferTrackWithinCapabilitiesOverPreferredLanguage() throws Exception {
    Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
    Format exceededEnFormat = formatBuilder.setId("exceededFormat").setLanguage("eng").build();
    Format supportedFrFormat = formatBuilder.setId("supportedFormat").setLanguage("fra").build();
    TrackGroupArray trackGroups = wrapFormats(exceededEnFormat, supportedFrFormat);
    Map<String, Integer> mappedCapabilities = new HashMap<>();
    mappedCapabilities.put(exceededEnFormat.id, FORMAT_EXCEEDS_CAPABILITIES);
    mappedCapabilities.put(supportedFrFormat.id, FORMAT_HANDLED);
    RendererCapabilities mappedAudioRendererCapabilities = new FakeMappedRendererCapabilities(C.TRACK_TYPE_AUDIO, mappedCapabilities);
    trackSelector.setParameters(defaultParameters.buildUpon().setPreferredAudioLanguage("eng"));
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { mappedAudioRendererCapabilities }, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, supportedFrFormat);
}
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 18 with Parameters

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

the class DefaultTrackSelectorTest method parameters_buildUponThenBuild_isEqual.

@Test
public void parameters_buildUponThenBuild_isEqual() {
    Parameters parameters = buildParametersForEqualsTest();
    assertThat(parameters.buildUpon().build()).isEqualTo(parameters);
}
Also used : Parameters(com.google.android.exoplayer2.trackselection.DefaultTrackSelector.Parameters) Test(org.junit.Test)

Example 19 with Parameters

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

the class DefaultTrackSelectorTest method roundTripViaBundle_ofParameters_yieldsEqualInstance.

/**
 * Tests {@link Parameters} {@link Bundleable} implementation.
 */
@Test
public void roundTripViaBundle_ofParameters_yieldsEqualInstance() {
    Parameters parametersToBundle = buildParametersForEqualsTest();
    Parameters parametersFromBundle = Parameters.CREATOR.fromBundle(parametersToBundle.toBundle());
    assertThat(parametersFromBundle).isEqualTo(parametersToBundle);
}
Also used : Parameters(com.google.android.exoplayer2.trackselection.DefaultTrackSelector.Parameters) Test(org.junit.Test)

Example 20 with Parameters

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

the class ExtractorAsserts method assertAllBehaviors.

/**
 * Asserts that an extractor behaves correctly given valid input data:
 *
 * <ul>
 *   <li>Calls {@link Extractor#seek(long, long)} and {@link Extractor#release()} without calling
 *       {@link Extractor#init(ExtractorOutput)} to check these calls do not fail.
 *   <li>Calls {@link #assertOutput(Extractor, String, byte[], Context, boolean, boolean, boolean,
 *       boolean, boolean)} with all possible combinations of "simulate" parameters.
 * </ul>
 *
 * @param factory An {@link ExtractorFactory} which creates instances of the {@link Extractor}
 *     class which is to be tested.
 * @param file The path to the input sample.
 * @param dumpFilesPrefix The dump files prefix appended to the dump files path.
 * @throws IOException If reading from the input fails.
 */
public static void assertAllBehaviors(ExtractorFactory factory, String file, String dumpFilesPrefix) throws IOException {
    // Check behavior prior to initialization.
    Extractor extractor = factory.create();
    extractor.seek(0, 0);
    extractor.release();
    // Assert output.
    Context context = ApplicationProvider.getApplicationContext();
    byte[] fileData = TestUtil.getByteArray(context, file);
    assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, true, false, false, false);
    assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, true, false, false, true);
    assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, true, false, true, false);
    assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, true, false, true, true);
    assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, true, true, false, false);
    assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, true, true, false, true);
    assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, true, true, true, false);
    assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, true, true, true, true);
    assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, false, false, false, false);
}
Also used : Context(android.content.Context) Extractor(com.google.android.exoplayer2.extractor.Extractor)

Aggregations

Test (org.junit.Test)23 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)19 Format (com.google.android.exoplayer2.Format)15 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)9 Nullable (androidx.annotation.Nullable)5 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)4 HashMap (java.util.HashMap)4 SuppressLint (android.annotation.SuppressLint)3 Point (android.graphics.Point)3 ParametersBuilder (com.google.android.exoplayer2.trackselection.DefaultTrackSelector.ParametersBuilder)3 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)3 Pair (android.util.Pair)2 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)2 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)2 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)2 Parameters (com.google.android.exoplayer2.trackselection.DefaultTrackSelector.Parameters)2 TargetApi (android.annotation.TargetApi)1 Context (android.content.Context)1 SparseArray (android.util.SparseArray)1 ExoPlaybackException (com.google.android.exoplayer2.ExoPlaybackException)1