use of com.google.android.exoplayer2.FormatHolder in project ExoPlayer by google.
the class SampleQueueTest method allowPlaceholderSessionPopulatesDrmSession.
@Test
public void allowPlaceholderSessionPopulatesDrmSession() {
when(mockDrmSession.getState()).thenReturn(DrmSession.STATE_OPENED_WITH_KEYS);
DrmSession mockPlaceholderDrmSession = Mockito.mock(DrmSession.class);
when(mockPlaceholderDrmSession.getState()).thenReturn(DrmSession.STATE_OPENED_WITH_KEYS);
mockDrmSessionManager.mockPlaceholderDrmSession = mockPlaceholderDrmSession;
writeTestDataWithEncryptedSections();
int result = sampleQueue.read(formatHolder, inputBuffer, /* readFlags= */
0, /* loadingFinished= */
false);
assertThat(result).isEqualTo(RESULT_FORMAT_READ);
assertThat(formatHolder.drmSession).isSameInstanceAs(mockDrmSession);
assertReadEncryptedSample(/* sampleIndex= */
0);
assertReadEncryptedSample(/* sampleIndex= */
1);
formatHolder.clear();
assertThat(formatHolder.drmSession).isNull();
result = sampleQueue.read(formatHolder, inputBuffer, /* readFlags= */
0, /* loadingFinished= */
false);
assertThat(result).isEqualTo(RESULT_FORMAT_READ);
assertThat(formatHolder.drmSession).isSameInstanceAs(mockPlaceholderDrmSession);
assertReadEncryptedSample(/* sampleIndex= */
2);
result = sampleQueue.read(formatHolder, inputBuffer, /* readFlags= */
0, /* loadingFinished= */
false);
assertThat(result).isEqualTo(RESULT_FORMAT_READ);
assertThat(formatHolder.drmSession).isSameInstanceAs(mockDrmSession);
assertReadEncryptedSample(/* sampleIndex= */
3);
}
use of com.google.android.exoplayer2.FormatHolder in project ExoPlayer by google.
the class TransformerAudioRenderer method ensureConfigured.
/**
* Attempts to read the input format and to initialize the {@link SamplePipeline}.
*/
@Override
protected boolean ensureConfigured() throws TransformationException {
if (samplePipeline != null) {
return true;
}
FormatHolder formatHolder = getFormatHolder();
@ReadDataResult int result = readSource(formatHolder, decoderInputBuffer, /* readFlags= */
FLAG_REQUIRE_FORMAT);
if (result != C.RESULT_FORMAT_READ) {
return false;
}
Format inputFormat = checkNotNull(formatHolder.format);
if (shouldPassthrough(inputFormat)) {
samplePipeline = new PassthroughSamplePipeline(inputFormat, transformationRequest, fallbackListener);
} else {
samplePipeline = new AudioTranscodingSamplePipeline(inputFormat, transformationRequest, decoderFactory, encoderFactory, muxerWrapper.getSupportedSampleMimeTypes(getTrackType()), fallbackListener);
}
return true;
}
use of com.google.android.exoplayer2.FormatHolder in project ExoPlayer by google.
the class TransformerVideoRenderer method ensureConfigured.
/**
* Attempts to read the input format and to initialize the {@link SamplePipeline}.
*/
@Override
protected boolean ensureConfigured() throws TransformationException {
if (samplePipeline != null) {
return true;
}
FormatHolder formatHolder = getFormatHolder();
@ReadDataResult int result = readSource(formatHolder, decoderInputBuffer, /* readFlags= */
FLAG_REQUIRE_FORMAT);
if (result != C.RESULT_FORMAT_READ) {
return false;
}
Format inputFormat = checkNotNull(formatHolder.format);
if (shouldPassthrough(inputFormat)) {
samplePipeline = new PassthroughSamplePipeline(inputFormat, transformationRequest, fallbackListener);
} else {
samplePipeline = new VideoTranscodingSamplePipeline(context, inputFormat, transformationRequest, decoderFactory, encoderFactory, muxerWrapper.getSupportedSampleMimeTypes(getTrackType()), fallbackListener, debugViewProvider);
}
if (transformationRequest.flattenForSlowMotion) {
sefSlowMotionFlattener = new SefSlowMotionFlattener(inputFormat);
}
return true;
}
use of com.google.android.exoplayer2.FormatHolder in project ExoPlayer by google.
the class EventSampleStreamTest method seekToUsThenReadDataReturnDataFromSeekPosition.
/**
* Tests that {@link EventSampleStream#seekToUs(long)} (long)} will seek to the given position,
* and the next {@link EventSampleStream#readData(FormatHolder, DecoderInputBuffer, int)} call
* will return sample data from that position.
*/
@Test
public void seekToUsThenReadDataReturnDataFromSeekPosition() {
long presentationTimeUs1 = 1000000;
long presentationTimeUs2 = 2000000;
EventMessage eventMessage1 = newEventMessageWithId(1);
EventMessage eventMessage2 = newEventMessageWithId(2);
EventStream eventStream = new EventStream(SCHEME_ID, VALUE, TIME_SCALE, new long[] { presentationTimeUs1, presentationTimeUs2 }, new EventMessage[] { eventMessage1, eventMessage2 });
EventSampleStream sampleStream = new EventSampleStream(eventStream, FORMAT, false);
// first read - read format
readData(sampleStream);
sampleStream.seekToUs(presentationTimeUs2);
int result = readData(sampleStream);
assertThat(result).isEqualTo(C.RESULT_BUFFER_READ);
assertThat(inputBuffer.data.array()).isEqualTo(getEncodedMessage(eventMessage2));
}
use of com.google.android.exoplayer2.FormatHolder in project ExoPlayer by google.
the class EventSampleStreamTest method updateEventStreamContinueToReadAfterLastReadSamplePresentationTime.
/**
* Tests that {@link EventSampleStream#updateEventStream(EventStream, boolean)} will update the
* underlying event stream, but keep the read timestamp, so the next {@link
* EventSampleStream#readData(FormatHolder, DecoderInputBuffer, int)} call will return sample data
* from after the last read sample timestamp.
*/
@Test
public void updateEventStreamContinueToReadAfterLastReadSamplePresentationTime() {
long presentationTimeUs1 = 1000000;
long presentationTimeUs2 = 2000000;
long presentationTimeUs3 = 3000000;
EventMessage eventMessage1 = newEventMessageWithId(1);
EventMessage eventMessage2 = newEventMessageWithId(2);
EventMessage eventMessage3 = newEventMessageWithId(3);
EventStream eventStream1 = new EventStream(SCHEME_ID, VALUE, TIME_SCALE, new long[] { presentationTimeUs1, presentationTimeUs2 }, new EventMessage[] { eventMessage1, eventMessage2 });
EventStream eventStream2 = new EventStream(SCHEME_ID, VALUE, TIME_SCALE, new long[] { presentationTimeUs1, presentationTimeUs2, presentationTimeUs3 }, new EventMessage[] { eventMessage1, eventMessage2, eventMessage3 });
EventSampleStream sampleStream = new EventSampleStream(eventStream1, FORMAT, true);
// first read - read format
readData(sampleStream);
// read first and second sample.
readData(sampleStream);
readData(sampleStream);
sampleStream.updateEventStream(eventStream2, true);
int result = readData(sampleStream);
assertThat(result).isEqualTo(C.RESULT_BUFFER_READ);
assertThat(inputBuffer.data.array()).isEqualTo(getEncodedMessage(eventMessage3));
}
Aggregations