use of com.google.android.exoplayer2.decoder.DecoderInputBuffer in project ExoPlayer by google.
the class DecoderVideoRendererTest method setUp.
@Before
public void setUp() {
surface = new Surface(new SurfaceTexture(/* texName= */
0));
renderer = new DecoderVideoRenderer(/* allowedJoiningTimeMs= */
0, new Handler(), eventListener, /* maxDroppedFramesToNotify= */
-1) {
private final Phaser inputBuffersInCodecPhaser = new Phaser();
@C.VideoOutputMode
private int outputMode;
@Override
public String getName() {
return "TestVideoRenderer";
}
@Override
@Capabilities
public int supportsFormat(Format format) {
return RendererCapabilities.create(C.FORMAT_HANDLED);
}
@Override
protected void setDecoderOutputMode(@C.VideoOutputMode int outputMode) {
this.outputMode = outputMode;
}
@Override
protected void renderOutputBufferToSurface(VideoDecoderOutputBuffer outputBuffer, Surface surface) {
// Do nothing.
}
@Override
protected void onQueueInputBuffer(DecoderInputBuffer buffer) {
// Decoding is done on a background thread we have no control about from the test.
// Ensure the background calls are predictably serialized by waiting for them to finish:
// 1. Register queued input buffers here.
// 2. Deregister the input buffer when it's cleared. If an input buffer is cleared it
// will have been fully handled by the decoder.
// 3. Send a message on the test thread to wait for all currently pending input buffers
// to be cleared.
// 4. The tests need to call ShadowLooper.idleMainThread() to execute the wait message
// sent in step (3).
int currentPhase = inputBuffersInCodecPhaser.register();
new Handler().post(() -> inputBuffersInCodecPhaser.awaitAdvance(currentPhase));
super.onQueueInputBuffer(buffer);
}
@Override
protected SimpleDecoder<DecoderInputBuffer, ? extends VideoDecoderOutputBuffer, ? extends DecoderException> createDecoder(Format format, @Nullable CryptoConfig cryptoConfig) {
return new SimpleDecoder<DecoderInputBuffer, VideoDecoderOutputBuffer, DecoderException>(new DecoderInputBuffer[10], new VideoDecoderOutputBuffer[10]) {
@Override
protected DecoderInputBuffer createInputBuffer() {
return new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DIRECT) {
@Override
public void clear() {
super.clear();
inputBuffersInCodecPhaser.arriveAndDeregister();
}
};
}
@Override
protected VideoDecoderOutputBuffer createOutputBuffer() {
return new VideoDecoderOutputBuffer(this::releaseOutputBuffer);
}
@Override
protected DecoderException createUnexpectedDecodeException(Throwable error) {
return new DecoderException("error", error);
}
@Nullable
@Override
protected DecoderException decode(DecoderInputBuffer inputBuffer, VideoDecoderOutputBuffer outputBuffer, boolean reset) {
outputBuffer.init(inputBuffer.timeUs, outputMode, /* supplementalData= */
null);
return null;
}
@Override
public String getName() {
return "TestDecoder";
}
};
}
};
renderer.setOutput(surface);
}
use of com.google.android.exoplayer2.decoder.DecoderInputBuffer 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.decoder.DecoderInputBuffer in project ExoPlayer by google.
the class TransformerBaseRenderer method feedMuxerFromPipeline.
/**
* Attempts to write sample pipeline output data to the muxer.
*
* @return Whether it may be possible to write more data immediately by calling this method again.
* @throws Muxer.MuxerException If a muxing problem occurs.
* @throws TransformationException If a {@link SamplePipeline} problem occurs.
*/
@RequiresNonNull("samplePipeline")
private boolean feedMuxerFromPipeline() throws Muxer.MuxerException, TransformationException {
if (!muxerWrapperTrackAdded) {
@Nullable Format samplePipelineOutputFormat = samplePipeline.getOutputFormat();
if (samplePipelineOutputFormat == null) {
return false;
}
muxerWrapperTrackAdded = true;
muxerWrapper.addTrackFormat(samplePipelineOutputFormat);
}
if (samplePipeline.isEnded()) {
muxerWrapper.endTrack(getTrackType());
muxerWrapperTrackEnded = true;
return false;
}
@Nullable DecoderInputBuffer samplePipelineOutputBuffer = samplePipeline.getOutputBuffer();
if (samplePipelineOutputBuffer == null) {
return false;
}
if (!muxerWrapper.writeSample(getTrackType(), checkStateNotNull(samplePipelineOutputBuffer.data), samplePipelineOutputBuffer.isKeyFrame(), samplePipelineOutputBuffer.timeUs)) {
return false;
}
samplePipeline.releaseOutputBuffer();
return true;
}
use of com.google.android.exoplayer2.decoder.DecoderInputBuffer 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.decoder.DecoderInputBuffer 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));
}
Aggregations