Search in sources :

Example 16 with SampleQueue

use of com.google.android.exoplayer2.source.SampleQueue in project ExoPlayer by google.

the class HlsSampleStreamWrapper method maybeFinishPrepare.

private void maybeFinishPrepare() {
    if (released || trackGroupToSampleQueueIndex != null || !sampleQueuesBuilt) {
        return;
    }
    for (SampleQueue sampleQueue : sampleQueues) {
        if (sampleQueue.getUpstreamFormat() == null) {
            return;
        }
    }
    if (trackGroups != null) {
        // The track groups were created with multivariant playlist information. They only need to be
        // mapped to a sample queue.
        mapSampleQueuesToMatchTrackGroups();
    } else {
        // Tracks are created using media segment information.
        buildTracksFromSampleStreams();
        setIsPrepared();
        callback.onPrepared();
    }
}
Also used : SampleQueue(com.google.android.exoplayer2.source.SampleQueue)

Example 17 with SampleQueue

use of com.google.android.exoplayer2.source.SampleQueue in project ExoPlayer by google.

the class SampleQueueTest method setUp.

@Before
public void setUp() {
    allocator = new DefaultAllocator(false, ALLOCATION_SIZE);
    mockDrmSession = Mockito.mock(DrmSession.class);
    mockDrmSessionManager = new MockDrmSessionManager(mockDrmSession);
    eventDispatcher = new DrmSessionEventListener.EventDispatcher();
    sampleQueue = new SampleQueue(allocator, mockDrmSessionManager, eventDispatcher);
    formatHolder = new FormatHolder();
    inputBuffer = new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_NORMAL);
}
Also used : DrmSession(com.google.android.exoplayer2.drm.DrmSession) DecoderInputBuffer(com.google.android.exoplayer2.decoder.DecoderInputBuffer) FormatHolder(com.google.android.exoplayer2.FormatHolder) DefaultAllocator(com.google.android.exoplayer2.upstream.DefaultAllocator) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) Before(org.junit.Before)

Example 18 with SampleQueue

use of com.google.android.exoplayer2.source.SampleQueue in project ExoPlayer by google.

the class SampleQueueTest method assertReadSample.

/**
 * Asserts {@link SampleQueue#read} returns {@link C#RESULT_BUFFER_READ} and that the buffer is
 * filled with the specified sample data.
 *
 * @param timeUs The expected buffer timestamp.
 * @param isKeyFrame The expected keyframe flag.
 * @param isDecodeOnly The expected decodeOnly flag.
 * @param isEncrypted The expected encrypted flag.
 * @param sampleData An array containing the expected sample data.
 * @param offset The offset in {@code sampleData} of the expected sample data.
 * @param length The length of the expected sample data.
 */
private void assertReadSample(long timeUs, boolean isKeyFrame, boolean isDecodeOnly, boolean isEncrypted, byte[] sampleData, int offset, int length) {
    // Check that peek whilst omitting data yields the expected values.
    formatHolder.format = null;
    DecoderInputBuffer flagsOnlyBuffer = DecoderInputBuffer.newNoDataInstance();
    int result = sampleQueue.read(formatHolder, flagsOnlyBuffer, FLAG_OMIT_SAMPLE_DATA | FLAG_PEEK, /* loadingFinished= */
    false);
    assertSampleBufferReadResult(flagsOnlyBuffer, result, timeUs, isKeyFrame, isDecodeOnly, isEncrypted);
    // Check that peek yields the expected values.
    clearFormatHolderAndInputBuffer();
    result = sampleQueue.read(formatHolder, inputBuffer, FLAG_PEEK, /* loadingFinished= */
    false);
    assertSampleBufferReadResult(result, timeUs, isKeyFrame, isDecodeOnly, isEncrypted, sampleData, offset, length);
    // Check that read yields the expected values.
    clearFormatHolderAndInputBuffer();
    result = sampleQueue.read(formatHolder, inputBuffer, /* readFlags= */
    0, /* loadingFinished= */
    false);
    assertSampleBufferReadResult(result, timeUs, isKeyFrame, isDecodeOnly, isEncrypted, sampleData, offset, length);
}
Also used : DecoderInputBuffer(com.google.android.exoplayer2.decoder.DecoderInputBuffer)

Example 19 with SampleQueue

use of com.google.android.exoplayer2.source.SampleQueue in project ExoPlayer by google.

the class SampleQueueTest method assertReadTestData.

/**
 * Asserts correct reading of standard test data from {@code sampleQueue}.
 *
 * @param startFormat The format of the last sample previously read from {@code sampleQueue}.
 * @param firstSampleIndex The index of the first sample that's expected to be read.
 * @param sampleCount The number of samples to read.
 * @param sampleOffsetUs The expected sample offset.
 */
private void assertReadTestData(Format startFormat, int firstSampleIndex, int sampleCount, long sampleOffsetUs, long decodeOnlyUntilUs) {
    Format format = adjustFormat(startFormat, sampleOffsetUs);
    for (int i = firstSampleIndex; i < firstSampleIndex + sampleCount; i++) {
        // Use equals() on the read side despite using referential equality on the write side, since
        // sampleQueue de-duplicates written formats using equals().
        Format testSampleFormat = adjustFormat(SAMPLE_FORMATS[i], sampleOffsetUs);
        if (!testSampleFormat.equals(format)) {
            // If the format has changed, we should read it.
            assertReadFormat(false, testSampleFormat);
            format = testSampleFormat;
        }
        // If we require the format, we should always read it.
        assertReadFormat(true, testSampleFormat);
        // Assert the sample is as expected.
        long expectedTimeUs = SAMPLE_TIMESTAMPS[i] + sampleOffsetUs;
        assertReadSample(expectedTimeUs, (SAMPLE_FLAGS[i] & C.BUFFER_FLAG_KEY_FRAME) != 0, /* isDecodeOnly= */
        expectedTimeUs < decodeOnlyUntilUs, /* isEncrypted= */
        false, DATA, DATA.length - SAMPLE_OFFSETS[i] - SAMPLE_SIZES[i], SAMPLE_SIZES[i]);
    }
}
Also used : Format(com.google.android.exoplayer2.Format)

Example 20 with SampleQueue

use of com.google.android.exoplayer2.source.SampleQueue in project ExoPlayer by google.

the class SampleQueueTest method writeSample.

/**
 * Writes a single sample to {@code sampleQueue}.
 */
private void writeSample(byte[] data, long timestampUs, int sampleFlags) {
    sampleQueue.sampleData(new ParsableByteArray(data), data.length);
    sampleQueue.sampleMetadata(timestampUs, sampleFlags, data.length, /* offset= */
    0, (sampleFlags & C.BUFFER_FLAG_ENCRYPTED) != 0 ? CRYPTO_DATA : null);
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray)

Aggregations

SampleQueue (com.google.android.exoplayer2.source.SampleQueue)14 Nullable (androidx.annotation.Nullable)5 Format (com.google.android.exoplayer2.Format)4 DecoderInputBuffer (com.google.android.exoplayer2.decoder.DecoderInputBuffer)2 LoadEventInfo (com.google.android.exoplayer2.source.LoadEventInfo)2 ExoTrackSelection (com.google.android.exoplayer2.trackselection.ExoTrackSelection)2 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)2 ImmutableList (com.google.common.collect.ImmutableList)2 Uri (android.net.Uri)1 FormatHolder (com.google.android.exoplayer2.FormatHolder)1 DrmSession (com.google.android.exoplayer2.drm.DrmSession)1 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)1 Metadata (com.google.android.exoplayer2.metadata.Metadata)1 IcyHeaders (com.google.android.exoplayer2.metadata.icy.IcyHeaders)1 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)1 Chunk (com.google.android.exoplayer2.source.chunk.Chunk)1 MediaChunkIterator (com.google.android.exoplayer2.source.chunk.MediaChunkIterator)1 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)1 DefaultAllocator (com.google.android.exoplayer2.upstream.DefaultAllocator)1 StatsDataSource (com.google.android.exoplayer2.upstream.StatsDataSource)1