Commit 51e4f7b2 by andrewlewis Committed by Oliver Woodman

Fix supplemental data handling with dropped frames

PiperOrigin-RevId: 276024935
parent 3e6fe458
...@@ -101,10 +101,7 @@ import java.nio.ByteBuffer; ...@@ -101,10 +101,7 @@ import java.nio.ByteBuffer;
boolean decodeOnly = inputBuffer.isDecodeOnly(); boolean decodeOnly = inputBuffer.isDecodeOnly();
if (!decodeOnly) { if (!decodeOnly) {
@Nullable outputBuffer.init(inputBuffer.timeUs, outputMode, /* supplementalData= */ null);
ByteBuffer supplementalData =
inputBuffer.hasSupplementalData() ? inputBuffer.supplementalData : null;
outputBuffer.init(inputBuffer.timeUs, outputMode, supplementalData);
} }
// We need to dequeue the decoded frame from the decoder even when the input data is // We need to dequeue the decoded frame from the decoder even when the input data is
// decode-only. // decode-only.
......
...@@ -22,6 +22,7 @@ import com.google.android.exoplayer2.decoder.CryptoInfo; ...@@ -22,6 +22,7 @@ import com.google.android.exoplayer2.decoder.CryptoInfo;
import com.google.android.exoplayer2.decoder.SimpleDecoder; import com.google.android.exoplayer2.decoder.SimpleDecoder;
import com.google.android.exoplayer2.drm.DecryptionException; import com.google.android.exoplayer2.drm.DecryptionException;
import com.google.android.exoplayer2.drm.ExoMediaCrypto; import com.google.android.exoplayer2.drm.ExoMediaCrypto;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoDecoderInputBuffer; import com.google.android.exoplayer2.video.VideoDecoderInputBuffer;
import com.google.android.exoplayer2.video.VideoDecoderOutputBuffer; import com.google.android.exoplayer2.video.VideoDecoderOutputBuffer;
...@@ -40,6 +41,8 @@ import java.nio.ByteBuffer; ...@@ -40,6 +41,8 @@ import java.nio.ByteBuffer;
@Nullable private final ExoMediaCrypto exoMediaCrypto; @Nullable private final ExoMediaCrypto exoMediaCrypto;
private final long vpxDecContext; private final long vpxDecContext;
@Nullable private ByteBuffer lastSupplementalData;
@C.VideoOutputMode private volatile int outputMode; @C.VideoOutputMode private volatile int outputMode;
/** /**
...@@ -124,6 +127,11 @@ import java.nio.ByteBuffer; ...@@ -124,6 +127,11 @@ import java.nio.ByteBuffer;
@Nullable @Nullable
protected VpxDecoderException decode( protected VpxDecoderException decode(
VideoDecoderInputBuffer inputBuffer, VideoDecoderOutputBuffer outputBuffer, boolean reset) { VideoDecoderInputBuffer inputBuffer, VideoDecoderOutputBuffer outputBuffer, boolean reset) {
if (reset && lastSupplementalData != null) {
// Don't propagate supplemental data across calls to flush the decoder.
lastSupplementalData.clear();
}
ByteBuffer inputData = Util.castNonNull(inputBuffer.data); ByteBuffer inputData = Util.castNonNull(inputBuffer.data);
int inputSize = inputData.limit(); int inputSize = inputData.limit();
CryptoInfo cryptoInfo = inputBuffer.cryptoInfo; CryptoInfo cryptoInfo = inputBuffer.cryptoInfo;
...@@ -143,11 +151,22 @@ import java.nio.ByteBuffer; ...@@ -143,11 +151,22 @@ import java.nio.ByteBuffer;
} }
} }
if (inputBuffer.hasSupplementalData()) {
ByteBuffer supplementalData = Assertions.checkNotNull(inputBuffer.supplementalData);
int size = supplementalData.remaining();
if (size > 0) {
if (lastSupplementalData == null || lastSupplementalData.capacity() < size) {
lastSupplementalData = ByteBuffer.allocate(size);
} else {
lastSupplementalData.clear();
}
lastSupplementalData.put(supplementalData);
lastSupplementalData.flip();
}
}
if (!inputBuffer.isDecodeOnly()) { if (!inputBuffer.isDecodeOnly()) {
@Nullable outputBuffer.init(inputBuffer.timeUs, outputMode, lastSupplementalData);
ByteBuffer supplementalData =
inputBuffer.hasSupplementalData() ? inputBuffer.supplementalData : null;
outputBuffer.init(inputBuffer.timeUs, outputMode, supplementalData);
int getFrameResult = vpxGetFrame(vpxDecContext, outputBuffer); int getFrameResult = vpxGetFrame(vpxDecContext, outputBuffer);
if (getFrameResult == 1) { if (getFrameResult == 1) {
outputBuffer.addFlag(C.BUFFER_FLAG_DECODE_ONLY); outputBuffer.addFlag(C.BUFFER_FLAG_DECODE_ONLY);
...@@ -162,6 +181,7 @@ import java.nio.ByteBuffer; ...@@ -162,6 +181,7 @@ import java.nio.ByteBuffer;
@Override @Override
public void release() { public void release() {
super.release(); super.release();
lastSupplementalData = null;
vpxClose(vpxDecContext); vpxClose(vpxDecContext);
} }
......
...@@ -108,6 +108,8 @@ public class VideoDecoderOutputBuffer extends OutputBuffer { ...@@ -108,6 +108,8 @@ public class VideoDecoderOutputBuffer extends OutputBuffer {
this.supplementalData.put(supplementalData); this.supplementalData.put(supplementalData);
this.supplementalData.flip(); this.supplementalData.flip();
supplementalData.position(0); supplementalData.position(0);
} else {
this.supplementalData = null;
} }
} }
......
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