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();
}
}
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);
}
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);
}
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]);
}
}
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);
}
Aggregations