Get decoder buffers into the right place

PiperOrigin-RevId: 404876228
This commit is contained in:
olly 2021-10-21 22:08:25 +01:00 committed by Oliver Woodman
parent 5e26ba8238
commit 37b5847681
27 changed files with 86 additions and 135 deletions

View File

@ -6,6 +6,6 @@
} }
# Some members of this class are being accessed from native methods. Keep them unobfuscated. # Some members of this class are being accessed from native methods. Keep them unobfuscated.
-keep class com.google.android.exoplayer2.video.VideoDecoderOutputBuffer { -keep class com.google.android.exoplayer2.decoder.VideoDecoderOutputBuffer {
*; *;
} }

View File

@ -24,15 +24,14 @@ import androidx.annotation.VisibleForTesting;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.decoder.SimpleDecoder; import com.google.android.exoplayer2.decoder.SimpleDecoder;
import com.google.android.exoplayer2.decoder.VideoDecoderOutputBuffer;
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.VideoDecoderOutputBuffer;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
/** Gav1 decoder. */ /** Gav1 decoder. */
@VisibleForTesting(otherwise = PACKAGE_PRIVATE) @VisibleForTesting(otherwise = PACKAGE_PRIVATE)
public final class Gav1Decoder public final class Gav1Decoder
extends SimpleDecoder<VideoDecoderInputBuffer, VideoDecoderOutputBuffer, Gav1DecoderException> { extends SimpleDecoder<DecoderInputBuffer, VideoDecoderOutputBuffer, Gav1DecoderException> {
private static final int GAV1_ERROR = 0; private static final int GAV1_ERROR = 0;
private static final int GAV1_OK = 1; private static final int GAV1_OK = 1;
@ -56,9 +55,7 @@ public final class Gav1Decoder
public Gav1Decoder( public Gav1Decoder(
int numInputBuffers, int numOutputBuffers, int initialInputBufferSize, int threads) int numInputBuffers, int numOutputBuffers, int initialInputBufferSize, int threads)
throws Gav1DecoderException { throws Gav1DecoderException {
super( super(new DecoderInputBuffer[numInputBuffers], new VideoDecoderOutputBuffer[numOutputBuffers]);
new VideoDecoderInputBuffer[numInputBuffers],
new VideoDecoderOutputBuffer[numOutputBuffers]);
if (!Gav1Library.isAvailable()) { if (!Gav1Library.isAvailable()) {
throw new Gav1DecoderException("Failed to load decoder native library."); throw new Gav1DecoderException("Failed to load decoder native library.");
} }
@ -86,8 +83,8 @@ public final class Gav1Decoder
} }
@Override @Override
protected VideoDecoderInputBuffer createInputBuffer() { protected DecoderInputBuffer createInputBuffer() {
return new VideoDecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DIRECT); return new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DIRECT);
} }
@Override @Override
@ -98,7 +95,7 @@ public final class Gav1Decoder
@Override @Override
@Nullable @Nullable
protected Gav1DecoderException decode( protected Gav1DecoderException decode(
VideoDecoderInputBuffer inputBuffer, VideoDecoderOutputBuffer outputBuffer, boolean reset) { DecoderInputBuffer inputBuffer, VideoDecoderOutputBuffer outputBuffer, boolean reset) {
ByteBuffer inputData = Util.castNonNull(inputBuffer.data); ByteBuffer inputData = Util.castNonNull(inputBuffer.data);
int inputSize = inputData.limit(); int inputSize = inputData.limit();
if (gav1Decode(gav1DecoderContext, inputData, inputSize) == GAV1_ERROR) { if (gav1Decode(gav1DecoderContext, inputData, inputSize) == GAV1_ERROR) {

View File

@ -25,11 +25,11 @@ import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.RendererCapabilities; import com.google.android.exoplayer2.RendererCapabilities;
import com.google.android.exoplayer2.decoder.CryptoConfig; import com.google.android.exoplayer2.decoder.CryptoConfig;
import com.google.android.exoplayer2.decoder.DecoderReuseEvaluation; import com.google.android.exoplayer2.decoder.DecoderReuseEvaluation;
import com.google.android.exoplayer2.decoder.VideoDecoderOutputBuffer;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.TraceUtil; import com.google.android.exoplayer2.util.TraceUtil;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.DecoderVideoRenderer; import com.google.android.exoplayer2.video.DecoderVideoRenderer;
import com.google.android.exoplayer2.video.VideoDecoderOutputBuffer;
import com.google.android.exoplayer2.video.VideoRendererEventListener; import com.google.android.exoplayer2.video.VideoRendererEventListener;
/** Decodes and renders video using libgav1 decoder. */ /** Decodes and renders video using libgav1 decoder. */

View File

@ -537,7 +537,7 @@ DECODER_FUNC(jlong, gav1Init, jint threads) {
// Populate JNI References. // Populate JNI References.
const jclass outputBufferClass = env->FindClass( const jclass outputBufferClass = env->FindClass(
"com/google/android/exoplayer2/video/VideoDecoderOutputBuffer"); "com/google/android/exoplayer2/decoder/VideoDecoderOutputBuffer");
context->decoder_private_field = context->decoder_private_field =
env->GetFieldID(outputBufferClass, "decoderPrivate", "I"); env->GetFieldID(outputBufferClass, "decoderPrivate", "I");
context->output_mode_field = env->GetFieldID(outputBufferClass, "mode", "I"); context->output_mode_field = env->GetFieldID(outputBufferClass, "mode", "I");

View File

@ -20,7 +20,7 @@ import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.decoder.SimpleDecoder; import com.google.android.exoplayer2.decoder.SimpleDecoder;
import com.google.android.exoplayer2.decoder.SimpleOutputBuffer; import com.google.android.exoplayer2.decoder.SimpleDecoderOutputBuffer;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.ParsableByteArray; import com.google.android.exoplayer2.util.ParsableByteArray;
@ -30,7 +30,7 @@ import java.util.List;
/** FFmpeg audio decoder. */ /** FFmpeg audio decoder. */
/* package */ final class FfmpegAudioDecoder /* package */ final class FfmpegAudioDecoder
extends SimpleDecoder<DecoderInputBuffer, SimpleOutputBuffer, FfmpegDecoderException> { extends SimpleDecoder<DecoderInputBuffer, SimpleDecoderOutputBuffer, FfmpegDecoderException> {
// Output buffer sizes when decoding PCM mu-law streams, which is the maximum FFmpeg outputs. // Output buffer sizes when decoding PCM mu-law streams, which is the maximum FFmpeg outputs.
private static final int OUTPUT_BUFFER_SIZE_16BIT = 65536; private static final int OUTPUT_BUFFER_SIZE_16BIT = 65536;
@ -56,7 +56,7 @@ import java.util.List;
int initialInputBufferSize, int initialInputBufferSize,
boolean outputFloat) boolean outputFloat)
throws FfmpegDecoderException { throws FfmpegDecoderException {
super(new DecoderInputBuffer[numInputBuffers], new SimpleOutputBuffer[numOutputBuffers]); super(new DecoderInputBuffer[numInputBuffers], new SimpleDecoderOutputBuffer[numOutputBuffers]);
if (!FfmpegLibrary.isAvailable()) { if (!FfmpegLibrary.isAvailable()) {
throw new FfmpegDecoderException("Failed to load decoder native libraries."); throw new FfmpegDecoderException("Failed to load decoder native libraries.");
} }
@ -86,8 +86,8 @@ import java.util.List;
} }
@Override @Override
protected SimpleOutputBuffer createOutputBuffer() { protected SimpleDecoderOutputBuffer createOutputBuffer() {
return new SimpleOutputBuffer(this::releaseOutputBuffer); return new SimpleDecoderOutputBuffer(this::releaseOutputBuffer);
} }
@Override @Override
@ -98,7 +98,7 @@ import java.util.List;
@Override @Override
@Nullable @Nullable
protected FfmpegDecoderException decode( protected FfmpegDecoderException decode(
DecoderInputBuffer inputBuffer, SimpleOutputBuffer outputBuffer, boolean reset) { DecoderInputBuffer inputBuffer, SimpleDecoderOutputBuffer outputBuffer, boolean reset) {
if (reset) { if (reset) {
nativeContext = ffmpegReset(nativeContext, extraData); nativeContext = ffmpegReset(nativeContext, extraData);
if (nativeContext == 0) { if (nativeContext == 0) {

View File

@ -27,12 +27,12 @@ import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.RendererCapabilities; import com.google.android.exoplayer2.RendererCapabilities;
import com.google.android.exoplayer2.decoder.CryptoConfig; import com.google.android.exoplayer2.decoder.CryptoConfig;
import com.google.android.exoplayer2.decoder.Decoder; import com.google.android.exoplayer2.decoder.Decoder;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.decoder.DecoderReuseEvaluation; import com.google.android.exoplayer2.decoder.DecoderReuseEvaluation;
import com.google.android.exoplayer2.decoder.VideoDecoderOutputBuffer;
import com.google.android.exoplayer2.util.TraceUtil; import com.google.android.exoplayer2.util.TraceUtil;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.DecoderVideoRenderer; import com.google.android.exoplayer2.video.DecoderVideoRenderer;
import com.google.android.exoplayer2.video.VideoDecoderInputBuffer;
import com.google.android.exoplayer2.video.VideoDecoderOutputBuffer;
import com.google.android.exoplayer2.video.VideoRendererEventListener; import com.google.android.exoplayer2.video.VideoRendererEventListener;
// TODO: Remove the NOTE below. // TODO: Remove the NOTE below.
@ -94,7 +94,7 @@ public final class FfmpegVideoRenderer extends DecoderVideoRenderer {
@SuppressWarnings("nullness:return") @SuppressWarnings("nullness:return")
@Override @Override
protected Decoder<VideoDecoderInputBuffer, VideoDecoderOutputBuffer, FfmpegDecoderException> protected Decoder<DecoderInputBuffer, VideoDecoderOutputBuffer, FfmpegDecoderException>
createDecoder(Format format, @Nullable CryptoConfig cryptoConfig) createDecoder(Format format, @Nullable CryptoConfig cryptoConfig)
throws FfmpegDecoderException { throws FfmpegDecoderException {
TraceUtil.beginSection("createFfmpegVideoDecoder"); TraceUtil.beginSection("createFfmpegVideoDecoder");

View File

@ -23,7 +23,7 @@ import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.ParserException; import com.google.android.exoplayer2.ParserException;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.decoder.SimpleDecoder; import com.google.android.exoplayer2.decoder.SimpleDecoder;
import com.google.android.exoplayer2.decoder.SimpleOutputBuffer; import com.google.android.exoplayer2.decoder.SimpleDecoderOutputBuffer;
import com.google.android.exoplayer2.extractor.FlacStreamMetadata; import com.google.android.exoplayer2.extractor.FlacStreamMetadata;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.io.IOException; import java.io.IOException;
@ -33,7 +33,7 @@ import java.util.List;
/** Flac decoder. */ /** Flac decoder. */
@VisibleForTesting(otherwise = PACKAGE_PRIVATE) @VisibleForTesting(otherwise = PACKAGE_PRIVATE)
public final class FlacDecoder public final class FlacDecoder
extends SimpleDecoder<DecoderInputBuffer, SimpleOutputBuffer, FlacDecoderException> { extends SimpleDecoder<DecoderInputBuffer, SimpleDecoderOutputBuffer, FlacDecoderException> {
private final FlacStreamMetadata streamMetadata; private final FlacStreamMetadata streamMetadata;
private final FlacDecoderJni decoderJni; private final FlacDecoderJni decoderJni;
@ -55,7 +55,7 @@ public final class FlacDecoder
int maxInputBufferSize, int maxInputBufferSize,
List<byte[]> initializationData) List<byte[]> initializationData)
throws FlacDecoderException { throws FlacDecoderException {
super(new DecoderInputBuffer[numInputBuffers], new SimpleOutputBuffer[numOutputBuffers]); super(new DecoderInputBuffer[numInputBuffers], new SimpleDecoderOutputBuffer[numOutputBuffers]);
if (initializationData.size() != 1) { if (initializationData.size() != 1) {
throw new FlacDecoderException("Initialization data must be of length 1"); throw new FlacDecoderException("Initialization data must be of length 1");
} }
@ -86,8 +86,8 @@ public final class FlacDecoder
} }
@Override @Override
protected SimpleOutputBuffer createOutputBuffer() { protected SimpleDecoderOutputBuffer createOutputBuffer() {
return new SimpleOutputBuffer(this::releaseOutputBuffer); return new SimpleDecoderOutputBuffer(this::releaseOutputBuffer);
} }
@Override @Override
@ -98,7 +98,7 @@ public final class FlacDecoder
@Override @Override
@Nullable @Nullable
protected FlacDecoderException decode( protected FlacDecoderException decode(
DecoderInputBuffer inputBuffer, SimpleOutputBuffer outputBuffer, boolean reset) { DecoderInputBuffer inputBuffer, SimpleDecoderOutputBuffer outputBuffer, boolean reset) {
if (reset) { if (reset) {
decoderJni.flush(); decoderJni.flush();
} }

View File

@ -6,6 +6,6 @@
} }
# Some members of this class are being accessed from native methods. Keep them unobfuscated. # Some members of this class are being accessed from native methods. Keep them unobfuscated.
-keep class com.google.android.exoplayer2.decoder.SimpleOutputBuffer { -keep class com.google.android.exoplayer2.decoder.SimpleDecoderOutputBuffer {
*; *;
} }

View File

@ -26,7 +26,7 @@ import com.google.android.exoplayer2.decoder.CryptoException;
import com.google.android.exoplayer2.decoder.CryptoInfo; import com.google.android.exoplayer2.decoder.CryptoInfo;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.decoder.SimpleDecoder; import com.google.android.exoplayer2.decoder.SimpleDecoder;
import com.google.android.exoplayer2.decoder.SimpleOutputBuffer; import com.google.android.exoplayer2.decoder.SimpleDecoderOutputBuffer;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -35,7 +35,7 @@ import java.util.List;
/** Opus decoder. */ /** Opus decoder. */
@VisibleForTesting(otherwise = PACKAGE_PRIVATE) @VisibleForTesting(otherwise = PACKAGE_PRIVATE)
public final class OpusDecoder public final class OpusDecoder
extends SimpleDecoder<DecoderInputBuffer, SimpleOutputBuffer, OpusDecoderException> { extends SimpleDecoder<DecoderInputBuffer, SimpleDecoderOutputBuffer, OpusDecoderException> {
private static final int NO_ERROR = 0; private static final int NO_ERROR = 0;
private static final int DECODE_ERROR = -1; private static final int DECODE_ERROR = -1;
@ -73,7 +73,7 @@ public final class OpusDecoder
@Nullable CryptoConfig cryptoConfig, @Nullable CryptoConfig cryptoConfig,
boolean outputFloat) boolean outputFloat)
throws OpusDecoderException { throws OpusDecoderException {
super(new DecoderInputBuffer[numInputBuffers], new SimpleOutputBuffer[numOutputBuffers]); super(new DecoderInputBuffer[numInputBuffers], new SimpleDecoderOutputBuffer[numOutputBuffers]);
if (!OpusLibrary.isAvailable()) { if (!OpusLibrary.isAvailable()) {
throw new OpusDecoderException("Failed to load decoder native libraries"); throw new OpusDecoderException("Failed to load decoder native libraries");
} }
@ -147,8 +147,8 @@ public final class OpusDecoder
} }
@Override @Override
protected SimpleOutputBuffer createOutputBuffer() { protected SimpleDecoderOutputBuffer createOutputBuffer() {
return new SimpleOutputBuffer(this::releaseOutputBuffer); return new SimpleDecoderOutputBuffer(this::releaseOutputBuffer);
} }
@Override @Override
@ -159,7 +159,7 @@ public final class OpusDecoder
@Override @Override
@Nullable @Nullable
protected OpusDecoderException decode( protected OpusDecoderException decode(
DecoderInputBuffer inputBuffer, SimpleOutputBuffer outputBuffer, boolean reset) { DecoderInputBuffer inputBuffer, SimpleDecoderOutputBuffer outputBuffer, boolean reset) {
if (reset) { if (reset) {
opusReset(nativeDecoderContext); opusReset(nativeDecoderContext);
// When seeking to 0, skip number of samples as specified in opus header. When seeking to // When seeking to 0, skip number of samples as specified in opus header. When seeking to
@ -239,14 +239,14 @@ public final class OpusDecoder
long timeUs, long timeUs,
ByteBuffer inputBuffer, ByteBuffer inputBuffer,
int inputSize, int inputSize,
SimpleOutputBuffer outputBuffer); SimpleDecoderOutputBuffer outputBuffer);
private native int opusSecureDecode( private native int opusSecureDecode(
long decoder, long decoder,
long timeUs, long timeUs,
ByteBuffer inputBuffer, ByteBuffer inputBuffer,
int inputSize, int inputSize,
SimpleOutputBuffer outputBuffer, SimpleDecoderOutputBuffer outputBuffer,
int sampleRate, int sampleRate,
@Nullable CryptoConfig mediaCrypto, @Nullable CryptoConfig mediaCrypto,
int inputMode, int inputMode,

View File

@ -87,7 +87,7 @@ DECODER_FUNC(jlong, opusInit, jint sampleRate, jint channelCount,
// Populate JNI References. // Populate JNI References.
const jclass outputBufferClass = env->FindClass( const jclass outputBufferClass = env->FindClass(
"com/google/android/exoplayer2/decoder/SimpleOutputBuffer"); "com/google/android/exoplayer2/decoder/SimpleDecoderOutputBuffer");
outputBufferInit = outputBufferInit =
env->GetMethodID(outputBufferClass, "init", "(JI)Ljava/nio/ByteBuffer;"); env->GetMethodID(outputBufferClass, "init", "(JI)Ljava/nio/ByteBuffer;");

View File

@ -6,7 +6,7 @@
} }
# Some members of this class are being accessed from native methods. Keep them unobfuscated. # Some members of this class are being accessed from native methods. Keep them unobfuscated.
-keep class com.google.android.exoplayer2.video.VideoDecoderOutputBuffer { -keep class com.google.android.exoplayer2.decoder.VideoDecoderOutputBuffer {
*; *;
} }

View File

@ -26,10 +26,10 @@ import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.RendererCapabilities; import com.google.android.exoplayer2.RendererCapabilities;
import com.google.android.exoplayer2.decoder.CryptoConfig; import com.google.android.exoplayer2.decoder.CryptoConfig;
import com.google.android.exoplayer2.decoder.DecoderReuseEvaluation; import com.google.android.exoplayer2.decoder.DecoderReuseEvaluation;
import com.google.android.exoplayer2.decoder.VideoDecoderOutputBuffer;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.TraceUtil; import com.google.android.exoplayer2.util.TraceUtil;
import com.google.android.exoplayer2.video.DecoderVideoRenderer; import com.google.android.exoplayer2.video.DecoderVideoRenderer;
import com.google.android.exoplayer2.video.VideoDecoderOutputBuffer;
import com.google.android.exoplayer2.video.VideoRendererEventListener; import com.google.android.exoplayer2.video.VideoRendererEventListener;
/** Decodes and renders video using the native VP9 decoder. */ /** Decodes and renders video using the native VP9 decoder. */

View File

@ -26,16 +26,15 @@ import com.google.android.exoplayer2.decoder.CryptoException;
import com.google.android.exoplayer2.decoder.CryptoInfo; import com.google.android.exoplayer2.decoder.CryptoInfo;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.decoder.SimpleDecoder; import com.google.android.exoplayer2.decoder.SimpleDecoder;
import com.google.android.exoplayer2.decoder.VideoDecoderOutputBuffer;
import com.google.android.exoplayer2.util.Assertions; 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.VideoDecoderOutputBuffer;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
/** Vpx decoder. */ /** Vpx decoder. */
@VisibleForTesting(otherwise = PACKAGE_PRIVATE) @VisibleForTesting(otherwise = PACKAGE_PRIVATE)
public final class VpxDecoder public final class VpxDecoder
extends SimpleDecoder<VideoDecoderInputBuffer, VideoDecoderOutputBuffer, VpxDecoderException> { extends SimpleDecoder<DecoderInputBuffer, VideoDecoderOutputBuffer, VpxDecoderException> {
// These constants should match the codes returned from vpxDecode and vpxSecureDecode functions in // These constants should match the codes returned from vpxDecode and vpxSecureDecode functions in
// https://github.com/google/ExoPlayer/blob/release-v2/extensions/vp9/src/main/jni/vpx_jni.cc. // https://github.com/google/ExoPlayer/blob/release-v2/extensions/vp9/src/main/jni/vpx_jni.cc.
@ -68,9 +67,7 @@ public final class VpxDecoder
@Nullable CryptoConfig cryptoConfig, @Nullable CryptoConfig cryptoConfig,
int threads) int threads)
throws VpxDecoderException { throws VpxDecoderException {
super( super(new DecoderInputBuffer[numInputBuffers], new VideoDecoderOutputBuffer[numOutputBuffers]);
new VideoDecoderInputBuffer[numInputBuffers],
new VideoDecoderOutputBuffer[numOutputBuffers]);
if (!VpxLibrary.isAvailable()) { if (!VpxLibrary.isAvailable()) {
throw new VpxDecoderException("Failed to load decoder native libraries."); throw new VpxDecoderException("Failed to load decoder native libraries.");
} }
@ -92,8 +89,8 @@ public final class VpxDecoder
} }
@Override @Override
protected VideoDecoderInputBuffer createInputBuffer() { protected DecoderInputBuffer createInputBuffer() {
return new VideoDecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DIRECT); return new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DIRECT);
} }
@Override @Override
@ -119,7 +116,7 @@ public final class VpxDecoder
@Override @Override
@Nullable @Nullable
protected VpxDecoderException decode( protected VpxDecoderException decode(
VideoDecoderInputBuffer inputBuffer, VideoDecoderOutputBuffer outputBuffer, boolean reset) { DecoderInputBuffer inputBuffer, VideoDecoderOutputBuffer outputBuffer, boolean reset) {
if (reset && lastSupplementalData != null) { if (reset && lastSupplementalData != null) {
// Don't propagate supplemental data across calls to flush the decoder. // Don't propagate supplemental data across calls to flush the decoder.
lastSupplementalData.clear(); lastSupplementalData.clear();

View File

@ -479,7 +479,7 @@ DECODER_FUNC(jlong, vpxInit, jboolean disableLoopFilter,
// Populate JNI References. // Populate JNI References.
const jclass outputBufferClass = env->FindClass( const jclass outputBufferClass = env->FindClass(
"com/google/android/exoplayer2/video/VideoDecoderOutputBuffer"); "com/google/android/exoplayer2/decoder/VideoDecoderOutputBuffer");
initForYuvFrame = initForYuvFrame =
env->GetMethodID(outputBufferClass, "initForYuvFrame", "(IIIII)Z"); env->GetMethodID(outputBufferClass, "initForYuvFrame", "(IIIII)Z");
initForPrivateFrame = initForPrivateFrame =

View File

@ -44,7 +44,7 @@ import com.google.android.exoplayer2.decoder.DecoderCounters;
import com.google.android.exoplayer2.decoder.DecoderException; import com.google.android.exoplayer2.decoder.DecoderException;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.decoder.DecoderReuseEvaluation; import com.google.android.exoplayer2.decoder.DecoderReuseEvaluation;
import com.google.android.exoplayer2.decoder.SimpleOutputBuffer; import com.google.android.exoplayer2.decoder.SimpleDecoderOutputBuffer;
import com.google.android.exoplayer2.drm.DrmSession; import com.google.android.exoplayer2.drm.DrmSession;
import com.google.android.exoplayer2.drm.DrmSession.DrmSessionException; import com.google.android.exoplayer2.drm.DrmSession.DrmSessionException;
import com.google.android.exoplayer2.source.SampleStream.ReadDataResult; import com.google.android.exoplayer2.source.SampleStream.ReadDataResult;
@ -82,7 +82,10 @@ import java.lang.annotation.RetentionPolicy;
*/ */
public abstract class DecoderAudioRenderer< public abstract class DecoderAudioRenderer<
T extends T extends
Decoder<DecoderInputBuffer, ? extends SimpleOutputBuffer, ? extends DecoderException>> Decoder<
DecoderInputBuffer,
? extends SimpleDecoderOutputBuffer,
? extends DecoderException>>
extends BaseRenderer implements MediaClock { extends BaseRenderer implements MediaClock {
private static final String TAG = "DecoderAudioRenderer"; private static final String TAG = "DecoderAudioRenderer";
@ -124,7 +127,7 @@ public abstract class DecoderAudioRenderer<
@Nullable private T decoder; @Nullable private T decoder;
@Nullable private DecoderInputBuffer inputBuffer; @Nullable private DecoderInputBuffer inputBuffer;
@Nullable private SimpleOutputBuffer outputBuffer; @Nullable private SimpleDecoderOutputBuffer outputBuffer;
@Nullable private DrmSession decoderDrmSession; @Nullable private DrmSession decoderDrmSession;
@Nullable private DrmSession sourceDrmSession; @Nullable private DrmSession sourceDrmSession;
@ -456,6 +459,7 @@ public abstract class DecoderAudioRenderer<
return false; return false;
} }
inputBuffer.flip(); inputBuffer.flip();
inputBuffer.format = inputFormat;
onQueueInputBuffer(inputBuffer); onQueueInputBuffer(inputBuffer);
decoder.queueInputBuffer(inputBuffer); decoder.queueInputBuffer(inputBuffer);
decoderReceivedBuffers = true; decoderReceivedBuffers = true;

View File

@ -42,6 +42,7 @@ import com.google.android.exoplayer2.decoder.DecoderCounters;
import com.google.android.exoplayer2.decoder.DecoderException; import com.google.android.exoplayer2.decoder.DecoderException;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.decoder.DecoderReuseEvaluation; import com.google.android.exoplayer2.decoder.DecoderReuseEvaluation;
import com.google.android.exoplayer2.decoder.VideoDecoderOutputBuffer;
import com.google.android.exoplayer2.drm.DrmSession; import com.google.android.exoplayer2.drm.DrmSession;
import com.google.android.exoplayer2.drm.DrmSession.DrmSessionException; import com.google.android.exoplayer2.drm.DrmSession.DrmSessionException;
import com.google.android.exoplayer2.source.SampleStream.ReadDataResult; import com.google.android.exoplayer2.source.SampleStream.ReadDataResult;
@ -108,10 +109,10 @@ public abstract class DecoderVideoRenderer extends BaseRenderer {
@Nullable @Nullable
private Decoder< private Decoder<
VideoDecoderInputBuffer, ? extends VideoDecoderOutputBuffer, ? extends DecoderException> DecoderInputBuffer, ? extends VideoDecoderOutputBuffer, ? extends DecoderException>
decoder; decoder;
private VideoDecoderInputBuffer inputBuffer; private DecoderInputBuffer inputBuffer;
private VideoDecoderOutputBuffer outputBuffer; private VideoDecoderOutputBuffer outputBuffer;
@VideoOutputMode private int outputMode; @VideoOutputMode private int outputMode;
@Nullable private Object output; @Nullable private Object output;
@ -415,7 +416,7 @@ public abstract class DecoderVideoRenderer extends BaseRenderer {
* *
* @param buffer The buffer that will be queued. * @param buffer The buffer that will be queued.
*/ */
protected void onQueueInputBuffer(VideoDecoderInputBuffer buffer) { protected void onQueueInputBuffer(DecoderInputBuffer buffer) {
// Do nothing. // Do nothing.
} }
@ -536,7 +537,7 @@ public abstract class DecoderVideoRenderer extends BaseRenderer {
* @throws DecoderException If an error occurred creating a suitable decoder. * @throws DecoderException If an error occurred creating a suitable decoder.
*/ */
protected abstract Decoder< protected abstract Decoder<
VideoDecoderInputBuffer, ? extends VideoDecoderOutputBuffer, ? extends DecoderException> DecoderInputBuffer, ? extends VideoDecoderOutputBuffer, ? extends DecoderException>
createDecoder(Format format, @Nullable CryptoConfig cryptoConfig) throws DecoderException; createDecoder(Format format, @Nullable CryptoConfig cryptoConfig) throws DecoderException;
/** /**

View File

@ -20,6 +20,7 @@ import android.opengl.GLES20;
import android.opengl.GLSurfaceView; import android.opengl.GLSurfaceView;
import android.util.AttributeSet; import android.util.AttributeSet;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.decoder.VideoDecoderOutputBuffer;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;

View File

@ -1,54 +0,0 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.video;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
/** Input buffer to a video decoder. */
public class VideoDecoderInputBuffer extends DecoderInputBuffer {
@Nullable public Format format;
/**
* Creates a new instance.
*
* @param bufferReplacementMode Determines the behavior of {@link #ensureSpaceForWrite(int)}. One
* of {@link #BUFFER_REPLACEMENT_MODE_DISABLED}, {@link #BUFFER_REPLACEMENT_MODE_NORMAL} and
* {@link #BUFFER_REPLACEMENT_MODE_DIRECT}.
*/
public VideoDecoderInputBuffer(@BufferReplacementMode int bufferReplacementMode) {
super(bufferReplacementMode);
}
/**
* Creates a new instance.
*
* @param bufferReplacementMode Determines the behavior of {@link #ensureSpaceForWrite(int)}. One
* of {@link #BUFFER_REPLACEMENT_MODE_DISABLED}, {@link #BUFFER_REPLACEMENT_MODE_NORMAL} and
* {@link #BUFFER_REPLACEMENT_MODE_DIRECT}.
* @param paddingSize If non-zero, {@link #ensureSpaceForWrite(int)} will ensure that the buffer
* is this number of bytes larger than the requested length. This can be useful for decoders
* that consume data in fixed size blocks, for efficiency. Setting the padding size to the
* decoder's fixed read size is necessary to prevent such a decoder from trying to read beyond
* the end of the buffer.
*/
public VideoDecoderInputBuffer(
@BufferReplacementMode int bufferReplacementMode, int paddingSize) {
super(bufferReplacementMode, paddingSize);
}
}

View File

@ -15,6 +15,8 @@
*/ */
package com.google.android.exoplayer2.video; package com.google.android.exoplayer2.video;
import com.google.android.exoplayer2.decoder.VideoDecoderOutputBuffer;
/** Renders the {@link VideoDecoderOutputBuffer}. */ /** Renders the {@link VideoDecoderOutputBuffer}. */
public interface VideoDecoderOutputBufferRenderer { public interface VideoDecoderOutputBufferRenderer {

View File

@ -34,7 +34,7 @@ import com.google.android.exoplayer2.decoder.CryptoConfig;
import com.google.android.exoplayer2.decoder.DecoderException; import com.google.android.exoplayer2.decoder.DecoderException;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.decoder.SimpleDecoder; import com.google.android.exoplayer2.decoder.SimpleDecoder;
import com.google.android.exoplayer2.decoder.SimpleOutputBuffer; import com.google.android.exoplayer2.decoder.SimpleDecoderOutputBuffer;
import com.google.android.exoplayer2.drm.DrmSessionEventListener; import com.google.android.exoplayer2.drm.DrmSessionEventListener;
import com.google.android.exoplayer2.drm.DrmSessionManager; import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.testutil.FakeSampleStream; import com.google.android.exoplayer2.testutil.FakeSampleStream;
@ -133,10 +133,10 @@ public class DecoderAudioRendererTest {
} }
private static final class FakeDecoder private static final class FakeDecoder
extends SimpleDecoder<DecoderInputBuffer, SimpleOutputBuffer, DecoderException> { extends SimpleDecoder<DecoderInputBuffer, SimpleDecoderOutputBuffer, DecoderException> {
public FakeDecoder() { public FakeDecoder() {
super(new DecoderInputBuffer[1], new SimpleOutputBuffer[1]); super(new DecoderInputBuffer[1], new SimpleDecoderOutputBuffer[1]);
} }
@Override @Override
@ -150,8 +150,8 @@ public class DecoderAudioRendererTest {
} }
@Override @Override
protected SimpleOutputBuffer createOutputBuffer() { protected SimpleDecoderOutputBuffer createOutputBuffer() {
return new SimpleOutputBuffer(this::releaseOutputBuffer); return new SimpleDecoderOutputBuffer(this::releaseOutputBuffer);
} }
@Override @Override
@ -161,7 +161,7 @@ public class DecoderAudioRendererTest {
@Override @Override
protected DecoderException decode( protected DecoderException decode(
DecoderInputBuffer inputBuffer, SimpleOutputBuffer outputBuffer, boolean reset) { DecoderInputBuffer inputBuffer, SimpleDecoderOutputBuffer outputBuffer, boolean reset) {
if (inputBuffer.isEndOfStream()) { if (inputBuffer.isEndOfStream()) {
outputBuffer.setFlags(C.BUFFER_FLAG_END_OF_STREAM); outputBuffer.setFlags(C.BUFFER_FLAG_END_OF_STREAM);
} }

View File

@ -38,6 +38,7 @@ import com.google.android.exoplayer2.decoder.CryptoConfig;
import com.google.android.exoplayer2.decoder.DecoderException; import com.google.android.exoplayer2.decoder.DecoderException;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.decoder.SimpleDecoder; import com.google.android.exoplayer2.decoder.SimpleDecoder;
import com.google.android.exoplayer2.decoder.VideoDecoderOutputBuffer;
import com.google.android.exoplayer2.drm.DrmSessionEventListener; import com.google.android.exoplayer2.drm.DrmSessionEventListener;
import com.google.android.exoplayer2.drm.DrmSessionManager; import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.testutil.FakeSampleStream; import com.google.android.exoplayer2.testutil.FakeSampleStream;
@ -108,7 +109,7 @@ public final class DecoderVideoRendererTest {
} }
@Override @Override
protected void onQueueInputBuffer(VideoDecoderInputBuffer buffer) { protected void onQueueInputBuffer(DecoderInputBuffer buffer) {
// Decoding is done on a background thread we have no control about from the test. // 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: // Ensure the background calls are predictably serialized by waiting for them to finish:
// 1. Register queued input buffers here. // 1. Register queued input buffers here.
@ -125,17 +126,16 @@ public final class DecoderVideoRendererTest {
@Override @Override
protected SimpleDecoder< protected SimpleDecoder<
VideoDecoderInputBuffer, DecoderInputBuffer,
? extends VideoDecoderOutputBuffer, ? extends VideoDecoderOutputBuffer,
? extends DecoderException> ? extends DecoderException>
createDecoder(Format format, @Nullable CryptoConfig cryptoConfig) { createDecoder(Format format, @Nullable CryptoConfig cryptoConfig) {
return new SimpleDecoder< return new SimpleDecoder<
VideoDecoderInputBuffer, VideoDecoderOutputBuffer, DecoderException>( DecoderInputBuffer, VideoDecoderOutputBuffer, DecoderException>(
new VideoDecoderInputBuffer[10], new VideoDecoderOutputBuffer[10]) { new DecoderInputBuffer[10], new VideoDecoderOutputBuffer[10]) {
@Override @Override
protected VideoDecoderInputBuffer createInputBuffer() { protected DecoderInputBuffer createInputBuffer() {
return new VideoDecoderInputBuffer( return new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DIRECT) {
DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DIRECT) {
@Override @Override
public void clear() { public void clear() {
super.clear(); super.clear();
@ -157,7 +157,7 @@ public final class DecoderVideoRendererTest {
@Nullable @Nullable
@Override @Override
protected DecoderException decode( protected DecoderException decode(
VideoDecoderInputBuffer inputBuffer, DecoderInputBuffer inputBuffer,
VideoDecoderOutputBuffer outputBuffer, VideoDecoderOutputBuffer outputBuffer,
boolean reset) { boolean reset) {
outputBuffer.init(inputBuffer.timeUs, outputMode, /* supplementalData= */ null); outputBuffer.init(inputBuffer.timeUs, outputMode, /* supplementalData= */ null);

View File

@ -18,6 +18,7 @@ package com.google.android.exoplayer2.decoder;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
@ -73,6 +74,9 @@ public class DecoderInputBuffer extends Buffer {
/** Allows buffer replacement using {@link ByteBuffer#allocateDirect(int)}. */ /** Allows buffer replacement using {@link ByteBuffer#allocateDirect(int)}. */
public static final int BUFFER_REPLACEMENT_MODE_DIRECT = 2; public static final int BUFFER_REPLACEMENT_MODE_DIRECT = 2;
/** The {@link Format}. */
@Nullable public Format format;
/** {@link CryptoInfo} for encrypted data. */ /** {@link CryptoInfo} for encrypted data. */
public final CryptoInfo cryptoInfo; public final CryptoInfo cryptoInfo;

View File

@ -16,10 +16,10 @@
package com.google.android.exoplayer2.decoder; package com.google.android.exoplayer2.decoder;
/** Output buffer decoded by a {@link Decoder}. */ /** Output buffer decoded by a {@link Decoder}. */
public abstract class OutputBuffer extends Buffer { public abstract class DecoderOutputBuffer extends Buffer {
/** Buffer owner. */ /** Buffer owner. */
public interface Owner<S extends OutputBuffer> { public interface Owner<S extends DecoderOutputBuffer> {
/** /**
* Releases the buffer. * Releases the buffer.

View File

@ -27,7 +27,7 @@ import java.util.ArrayDeque;
*/ */
@SuppressWarnings("UngroupedOverloads") @SuppressWarnings("UngroupedOverloads")
public abstract class SimpleDecoder< public abstract class SimpleDecoder<
I extends DecoderInputBuffer, O extends OutputBuffer, E extends DecoderException> I extends DecoderInputBuffer, O extends DecoderOutputBuffer, E extends DecoderException>
implements Decoder<I, O, E> { implements Decoder<I, O, E> {
private final Thread decodeThread; private final Thread decodeThread;

View File

@ -20,13 +20,13 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
/** Buffer for {@link SimpleDecoder} output. */ /** Buffer for {@link SimpleDecoder} output. */
public class SimpleOutputBuffer extends OutputBuffer { public class SimpleDecoderOutputBuffer extends DecoderOutputBuffer {
private final Owner<SimpleOutputBuffer> owner; private final Owner<SimpleDecoderOutputBuffer> owner;
@Nullable public ByteBuffer data; @Nullable public ByteBuffer data;
public SimpleOutputBuffer(Owner<SimpleOutputBuffer> owner) { public SimpleDecoderOutputBuffer(Owner<SimpleDecoderOutputBuffer> owner) {
this.owner = owner; this.owner = owner;
} }

View File

@ -13,16 +13,15 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.google.android.exoplayer2.video; package com.google.android.exoplayer2.decoder;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.decoder.OutputBuffer;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
/** Video decoder output buffer containing video frame data. */ /** Video decoder output buffer containing video frame data. */
public class VideoDecoderOutputBuffer extends OutputBuffer { public class VideoDecoderOutputBuffer extends DecoderOutputBuffer {
public static final int COLORSPACE_UNKNOWN = 0; public static final int COLORSPACE_UNKNOWN = 0;
public static final int COLORSPACE_BT601 = 1; public static final int COLORSPACE_BT601 = 1;

View File

@ -17,12 +17,12 @@ package com.google.android.exoplayer2.text;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.decoder.OutputBuffer; import com.google.android.exoplayer2.decoder.DecoderOutputBuffer;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import java.util.List; import java.util.List;
/** Base class for {@link SubtitleDecoder} output buffers. */ /** Base class for {@link SubtitleDecoder} output buffers. */
public abstract class SubtitleOutputBuffer extends OutputBuffer implements Subtitle { public abstract class SubtitleOutputBuffer extends DecoderOutputBuffer implements Subtitle {
@Nullable private Subtitle subtitle; @Nullable private Subtitle subtitle;
private long subsampleOffsetUs; private long subsampleOffsetUs;