Search in sources :

Example 81 with Format

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

the class DefaultTrackSelectorTest method selectTracksPreferTrackWithinCapabilitiesOverSelectionFlagAndPreferredLanguage.

/**
 * Tests that track selector will prefer tracks that are within renderer's capabilities over track
 * that have both language matching preferred audio given by {@link Parameters} and {@link
 * C#SELECTION_FLAG_DEFAULT}, but exceed renderer's capabilities.
 */
@Test
public void selectTracksPreferTrackWithinCapabilitiesOverSelectionFlagAndPreferredLanguage() throws Exception {
    Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
    Format exceededDefaultSelectionEnFormat = formatBuilder.setId("exceededFormat").setSelectionFlags(C.SELECTION_FLAG_DEFAULT).setLanguage("eng").build();
    Format supportedFrFormat = formatBuilder.setId("supportedFormat").setSelectionFlags(0).setLanguage("fra").build();
    TrackGroupArray trackGroups = wrapFormats(exceededDefaultSelectionEnFormat, supportedFrFormat);
    Map<String, Integer> mappedCapabilities = new HashMap<>();
    mappedCapabilities.put(exceededDefaultSelectionEnFormat.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 82 with Format

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

the class SampleQueueTest method writeTestData.

/**
 * Writes the specified test data to {@code sampleQueue}.
 */
@SuppressWarnings("ReferenceEquality")
private void writeTestData(byte[] data, int[] sampleSizes, int[] sampleOffsets, long[] sampleTimestamps, Format[] sampleFormats, int[] sampleFlags) {
    sampleQueue.sampleData(new ParsableByteArray(data), data.length);
    Format format = null;
    for (int i = 0; i < sampleTimestamps.length; i++) {
        if (sampleFormats[i] != format) {
            sampleQueue.format(sampleFormats[i]);
            format = sampleFormats[i];
        }
        sampleQueue.sampleMetadata(sampleTimestamps[i], sampleFlags[i], sampleSizes[i], sampleOffsets[i], (sampleFlags[i] & C.BUFFER_FLAG_ENCRYPTED) != 0 ? CRYPTO_DATA : null);
    }
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray) Format(com.google.android.exoplayer2.Format)

Example 83 with Format

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

the class SampleQueueTest method multipleFormatsDeduplicated.

@Test
public void multipleFormatsDeduplicated() {
    sampleQueue.format(FORMAT_1);
    sampleQueue.sampleData(new ParsableByteArray(DATA), ALLOCATION_SIZE);
    sampleQueue.sampleMetadata(0, C.BUFFER_FLAG_KEY_FRAME, ALLOCATION_SIZE, 0, null);
    // Writing multiple formats should not cause a format change on the read side, provided the last
    // format to be written is equal to the format of the previous sample.
    sampleQueue.format(FORMAT_2);
    sampleQueue.format(FORMAT_1_COPY);
    sampleQueue.sampleData(new ParsableByteArray(DATA), ALLOCATION_SIZE);
    sampleQueue.sampleMetadata(1000, C.BUFFER_FLAG_KEY_FRAME, ALLOCATION_SIZE, 0, null);
    assertReadFormat(false, FORMAT_1);
    assertReadSample(0, /* isKeyFrame= */
    true, /* isDecodeOnly= */
    false, /* isEncrypted= */
    false, DATA, /* offset= */
    0, ALLOCATION_SIZE);
    // Assert the second sample is read without a format change.
    assertReadSample(1000, /* isKeyFrame= */
    true, /* isDecodeOnly= */
    false, /* isEncrypted= */
    false, DATA, /* offset= */
    0, ALLOCATION_SIZE);
    // The same applies if the queue is empty when the formats are written.
    sampleQueue.format(FORMAT_2);
    sampleQueue.format(FORMAT_1);
    sampleQueue.sampleData(new ParsableByteArray(DATA), ALLOCATION_SIZE);
    sampleQueue.sampleMetadata(2000, C.BUFFER_FLAG_KEY_FRAME, ALLOCATION_SIZE, 0, null);
    // Assert the third sample is read without a format change.
    assertReadSample(2000, /* isKeyFrame= */
    true, /* isDecodeOnly= */
    false, /* isEncrypted= */
    false, DATA, /* offset= */
    0, ALLOCATION_SIZE);
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray) Test(org.junit.Test)

Example 84 with Format

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

the class SampleQueueTest method readSingleSamples.

@Test
public void readSingleSamples() {
    sampleQueue.sampleData(new ParsableByteArray(DATA), ALLOCATION_SIZE);
    assertAllocationCount(1);
    // Nothing to read.
    assertNoSamplesToRead(null);
    sampleQueue.format(FORMAT_1);
    // Read the format.
    assertReadFormat(false, FORMAT_1);
    // Nothing to read.
    assertNoSamplesToRead(FORMAT_1);
    sampleQueue.sampleMetadata(1000, C.BUFFER_FLAG_KEY_FRAME, ALLOCATION_SIZE, 0, null);
    // If formatRequired, should read the format rather than the sample.
    assertReadFormat(true, FORMAT_1);
    // Otherwise should read the sample.
    assertReadSample(1000, /* isKeyFrame= */
    true, /* isDecodeOnly= */
    false, /* isEncrypted= */
    false, DATA, /* offset= */
    0, ALLOCATION_SIZE);
    // Allocation should still be held.
    assertAllocationCount(1);
    sampleQueue.discardToRead();
    // The allocation should have been released.
    assertAllocationCount(0);
    // Nothing to read.
    assertNoSamplesToRead(FORMAT_1);
    // Write a second sample followed by one byte that does not belong to it.
    sampleQueue.sampleData(new ParsableByteArray(DATA), ALLOCATION_SIZE);
    sampleQueue.sampleMetadata(2000, 0, ALLOCATION_SIZE - 1, 1, null);
    // If formatRequired, should read the format rather than the sample.
    assertReadFormat(true, FORMAT_1);
    // Read the sample.
    assertReadSample(2000, /* isKeyFrame= */
    false, /* isDecodeOnly= */
    false, /* isEncrypted= */
    false, DATA, /* offset= */
    0, ALLOCATION_SIZE - 1);
    // Allocation should still be held.
    assertAllocationCount(1);
    sampleQueue.discardToRead();
    // The last byte written to the sample queue may belong to a sample whose metadata has yet to be
    // written, so an allocation should still be held.
    assertAllocationCount(1);
    // Write metadata for a third sample containing the remaining byte.
    sampleQueue.sampleMetadata(3000, 0, 1, 0, null);
    // If formatRequired, should read the format rather than the sample.
    assertReadFormat(true, FORMAT_1);
    // Read the sample.
    assertReadSample(3000, /* isKeyFrame= */
    false, /* isDecodeOnly= */
    false, /* isEncrypted= */
    false, DATA, ALLOCATION_SIZE - 1, 1);
    // Allocation should still be held.
    assertAllocationCount(1);
    sampleQueue.discardToRead();
    // The allocation should have been released.
    assertAllocationCount(0);
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray) Test(org.junit.Test)

Example 85 with Format

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

the class SampleQueueTest method setStartTimeUs_notAllSamplesAreSyncSamples_discardsOnReadSide.

@Test
public void setStartTimeUs_notAllSamplesAreSyncSamples_discardsOnReadSide() {
    // The format uses a MIME type for which MimeTypes.allSamplesAreSyncSamples() is false.
    Format format = new Format.Builder().setSampleMimeType(MimeTypes.VIDEO_H264).build();
    Format[] sampleFormats = new Format[SAMPLE_SIZES.length];
    Arrays.fill(sampleFormats, format);
    sampleQueue.setStartTimeUs(LAST_SAMPLE_TIMESTAMP);
    writeTestData();
    assertThat(sampleQueue.getReadIndex()).isEqualTo(0);
    assertReadTestData(/* startFormat= */
    null, /* firstSampleIndex= */
    0, /* sampleCount= */
    SAMPLE_TIMESTAMPS.length, /* sampleOffsetUs= */
    0, /* decodeOnlyUntilUs= */
    LAST_SAMPLE_TIMESTAMP);
}
Also used : Format(com.google.android.exoplayer2.Format) Test(org.junit.Test)

Aggregations

Format (com.google.android.exoplayer2.Format)245 Test (org.junit.Test)178 Nullable (androidx.annotation.Nullable)65 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)62 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)55 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)35 ArrayList (java.util.ArrayList)32 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)26 FakeSampleStream (com.google.android.exoplayer2.testutil.FakeSampleStream)26 MediaFormat (android.media.MediaFormat)22 DefaultAllocator (com.google.android.exoplayer2.upstream.DefaultAllocator)22 SuppressLint (android.annotation.SuppressLint)18 Metadata (com.google.android.exoplayer2.metadata.Metadata)18 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)18 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)16 ImmutableList (com.google.common.collect.ImmutableList)16 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)15 EventStream (com.google.android.exoplayer2.source.dash.manifest.EventStream)15 SurfaceTexture (android.graphics.SurfaceTexture)14 Surface (android.view.Surface)14