mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Fix supplemental data handling with dropped frames
PiperOrigin-RevId: 276024935
This commit is contained in:
parent
3e6fe45885
commit
51e4f7b260
3 changed files with 27 additions and 8 deletions
|
|
@ -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;
|
||||||
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;
|
||||||
@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;
|
||||||
@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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
@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 {
|
||||||
this.supplementalData.put(supplementalData);
|
this.supplementalData.put(supplementalData);
|
||||||
this.supplementalData.flip();
|
this.supplementalData.flip();
|
||||||
supplementalData.position(0);
|
supplementalData.position(0);
|
||||||
|
} else {
|
||||||
|
this.supplementalData = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue