Commit 60681b97 by kimvde Committed by bachinger

Add onReset implementation to TransformerTranscodingVideoRenderer

PiperOrigin-RevId: 392468554
parent 2f09ecef
...@@ -37,7 +37,7 @@ import java.nio.ByteBuffer; ...@@ -37,7 +37,7 @@ import java.nio.ByteBuffer;
private static final String TAG = "TransformerTranscodingVideoRenderer"; private static final String TAG = "TransformerTranscodingVideoRenderer";
private final DecoderInputBuffer buffer; private final DecoderInputBuffer decoderInputBuffer;
/** The format the encoder is configured to output, may differ from the actual output format. */ /** The format the encoder is configured to output, may differ from the actual output format. */
private final Format encoderConfigurationOutputFormat; private final Format encoderConfigurationOutputFormat;
...@@ -57,7 +57,7 @@ import java.nio.ByteBuffer; ...@@ -57,7 +57,7 @@ import java.nio.ByteBuffer;
Format encoderConfigurationOutputFormat) { Format encoderConfigurationOutputFormat) {
super(C.TRACK_TYPE_VIDEO, muxerWrapper, mediaClock, transformation); super(C.TRACK_TYPE_VIDEO, muxerWrapper, mediaClock, transformation);
buffer = new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DIRECT); decoderInputBuffer = new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DIRECT);
surface = MediaCodec.createPersistentInputSurface(); surface = MediaCodec.createPersistentInputSurface();
this.encoderConfigurationOutputFormat = encoderConfigurationOutputFormat; this.encoderConfigurationOutputFormat = encoderConfigurationOutputFormat;
} }
...@@ -89,6 +89,23 @@ import java.nio.ByteBuffer; ...@@ -89,6 +89,23 @@ import java.nio.ByteBuffer;
return muxerWrapperTrackEnded; return muxerWrapperTrackEnded;
} }
@Override
protected void onReset() {
decoderInputBuffer.clear();
decoderInputBuffer.data = null;
surface.release();
if (decoder != null) {
decoder.release();
decoder = null;
}
if (encoder != null) {
encoder.release();
encoder = null;
}
hasEncoderActualOutputFormat = false;
muxerWrapperTrackEnded = false;
}
private boolean ensureDecoderConfigured() throws ExoPlaybackException { private boolean ensureDecoderConfigured() throws ExoPlaybackException {
if (decoder != null) { if (decoder != null) {
return true; return true;
...@@ -97,7 +114,8 @@ import java.nio.ByteBuffer; ...@@ -97,7 +114,8 @@ import java.nio.ByteBuffer;
FormatHolder formatHolder = getFormatHolder(); FormatHolder formatHolder = getFormatHolder();
@SampleStream.ReadDataResult @SampleStream.ReadDataResult
int result = int result =
readSource(formatHolder, buffer, /* readFlags= */ SampleStream.FLAG_REQUIRE_FORMAT); readSource(
formatHolder, decoderInputBuffer, /* readFlags= */ SampleStream.FLAG_REQUIRE_FORMAT);
if (result != C.RESULT_FORMAT_READ) { if (result != C.RESULT_FORMAT_READ) {
return false; return false;
} }
...@@ -133,23 +151,23 @@ import java.nio.ByteBuffer; ...@@ -133,23 +151,23 @@ import java.nio.ByteBuffer;
private boolean feedDecoderFromInput() { private boolean feedDecoderFromInput() {
MediaCodecAdapterWrapper decoder = checkNotNull(this.decoder); MediaCodecAdapterWrapper decoder = checkNotNull(this.decoder);
if (!decoder.maybeDequeueInputBuffer(buffer)) { if (!decoder.maybeDequeueInputBuffer(decoderInputBuffer)) {
return false; return false;
} }
buffer.clear(); decoderInputBuffer.clear();
@SampleStream.ReadDataResult @SampleStream.ReadDataResult
int result = readSource(getFormatHolder(), buffer, /* readFlags= */ 0); int result = readSource(getFormatHolder(), decoderInputBuffer, /* readFlags= */ 0);
switch (result) { switch (result) {
case C.RESULT_FORMAT_READ: case C.RESULT_FORMAT_READ:
throw new IllegalStateException("Format changes are not supported."); throw new IllegalStateException("Format changes are not supported.");
case C.RESULT_BUFFER_READ: case C.RESULT_BUFFER_READ:
mediaClock.updateTimeForTrackType(getTrackType(), buffer.timeUs); mediaClock.updateTimeForTrackType(getTrackType(), decoderInputBuffer.timeUs);
ByteBuffer data = checkNotNull(buffer.data); ByteBuffer data = checkNotNull(decoderInputBuffer.data);
data.flip(); data.flip();
decoder.queueInputBuffer(buffer); decoder.queueInputBuffer(decoderInputBuffer);
return !buffer.isEndOfStream(); return !decoderInputBuffer.isEndOfStream();
case C.RESULT_NOTHING_READ: case C.RESULT_NOTHING_READ:
default: default:
return false; return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment