Use maxInputSize for extension decoders where possible

Issue: #3120

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=204898773
This commit is contained in:
olly 2018-07-17 05:55:52 -07:00 committed by Oliver Woodman
parent 73af056da3
commit 972fd0ced8
5 changed files with 37 additions and 26 deletions

View File

@ -37,15 +37,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
*/
public final class FfmpegAudioRenderer extends SimpleDecoderAudioRenderer {
/**
* The number of input and output buffers.
*/
/** The number of input and output buffers. */
private static final int NUM_BUFFERS = 16;
/**
* The initial input buffer size. Input buffers are reallocated dynamically if this value is
* insufficient.
*/
private static final int INITIAL_INPUT_BUFFER_SIZE = 960 * 6;
/** The default input buffer size. */
private static final int DEFAULT_INPUT_BUFFER_SIZE = 960 * 6;
private final boolean enableFloatOutput;
@ -120,13 +115,11 @@ public final class FfmpegAudioRenderer extends SimpleDecoderAudioRenderer {
@Override
protected FfmpegDecoder createDecoder(Format format, ExoMediaCrypto mediaCrypto)
throws FfmpegDecoderException {
int initialInputBufferSize =
format.maxInputSize != Format.NO_VALUE ? format.maxInputSize : DEFAULT_INPUT_BUFFER_SIZE;
decoder =
new FfmpegDecoder(
NUM_BUFFERS,
NUM_BUFFERS,
INITIAL_INPUT_BUFFER_SIZE,
format,
shouldUseFloatOutput(format));
NUM_BUFFERS, NUM_BUFFERS, initialInputBufferSize, format, shouldUseFloatOutput(format));
return decoder;
}

View File

@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer2.ext.flac;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.decoder.SimpleDecoder;
import com.google.android.exoplayer2.decoder.SimpleOutputBuffer;
@ -37,11 +38,17 @@ import java.util.List;
*
* @param numInputBuffers The number of input buffers.
* @param numOutputBuffers The number of output buffers.
* @param maxInputBufferSize The maximum required input buffer size if known, or {@link
* Format#NO_VALUE} otherwise.
* @param initializationData Codec-specific initialization data. It should contain only one entry
* which is the flac file header.
* which is the flac file header.
* @throws FlacDecoderException Thrown if an exception occurs when initializing the decoder.
*/
public FlacDecoder(int numInputBuffers, int numOutputBuffers, List<byte[]> initializationData)
public FlacDecoder(
int numInputBuffers,
int numOutputBuffers,
int maxInputBufferSize,
List<byte[]> initializationData)
throws FlacDecoderException {
super(new DecoderInputBuffer[numInputBuffers], new SimpleOutputBuffer[numOutputBuffers]);
if (initializationData.size() != 1) {
@ -60,7 +67,9 @@ import java.util.List;
throw new FlacDecoderException("Metadata decoding failed");
}
setInitialInputBufferSize(streamInfo.maxFrameSize);
int initialInputBufferSize =
maxInputBufferSize != Format.NO_VALUE ? maxInputBufferSize : streamInfo.maxFrameSize;
setInitialInputBufferSize(initialInputBufferSize);
maxOutputBufferSize = streamInfo.maxDecodedFrameSize();
}

View File

@ -65,7 +65,8 @@ public class LibflacAudioRenderer extends SimpleDecoderAudioRenderer {
@Override
protected FlacDecoder createDecoder(Format format, ExoMediaCrypto mediaCrypto)
throws FlacDecoderException {
return new FlacDecoder(NUM_BUFFERS, NUM_BUFFERS, format.initializationData);
return new FlacDecoder(
NUM_BUFFERS, NUM_BUFFERS, format.maxInputSize, format.initializationData);
}
}

View File

@ -30,8 +30,10 @@ import com.google.android.exoplayer2.util.MimeTypes;
*/
public final class LibopusAudioRenderer extends SimpleDecoderAudioRenderer {
/** The number of input and output buffers. */
private static final int NUM_BUFFERS = 16;
private static final int INITIAL_INPUT_BUFFER_SIZE = 960 * 6;
/** The default input buffer size. */
private static final int DEFAULT_INPUT_BUFFER_SIZE = 960 * 6;
private OpusDecoder decoder;
@ -88,8 +90,15 @@ public final class LibopusAudioRenderer extends SimpleDecoderAudioRenderer {
@Override
protected OpusDecoder createDecoder(Format format, ExoMediaCrypto mediaCrypto)
throws OpusDecoderException {
decoder = new OpusDecoder(NUM_BUFFERS, NUM_BUFFERS, INITIAL_INPUT_BUFFER_SIZE,
format.initializationData, mediaCrypto);
int initialInputBufferSize =
format.maxInputSize != Format.NO_VALUE ? format.maxInputSize : DEFAULT_INPUT_BUFFER_SIZE;
decoder =
new OpusDecoder(
NUM_BUFFERS,
NUM_BUFFERS,
initialInputBufferSize,
format.initializationData,
mediaCrypto);
return decoder;
}

View File

@ -99,11 +99,8 @@ public class LibvpxVideoRenderer extends BaseRenderer {
* requiring multiple output buffers to be dequeued at a time for it to make progress.
*/
private static final int NUM_OUTPUT_BUFFERS = 8;
/**
* The initial input buffer size. Input buffers are reallocated dynamically if this value is
* insufficient.
*/
private static final int INITIAL_INPUT_BUFFER_SIZE = 768 * 1024; // Value based on cs/SoftVpx.cpp.
/** The default input buffer size. */
private static final int DEFAULT_INPUT_BUFFER_SIZE = 768 * 1024; // Value based on cs/SoftVpx.cpp.
private final boolean scaleToFit;
private final boolean disableLoopFilter;
@ -703,11 +700,13 @@ public class LibvpxVideoRenderer extends BaseRenderer {
try {
long decoderInitializingTimestamp = SystemClock.elapsedRealtime();
TraceUtil.beginSection("createVpxDecoder");
int initialInputBufferSize =
format.maxInputSize != Format.NO_VALUE ? format.maxInputSize : DEFAULT_INPUT_BUFFER_SIZE;
decoder =
new VpxDecoder(
NUM_INPUT_BUFFERS,
NUM_OUTPUT_BUFFERS,
INITIAL_INPUT_BUFFER_SIZE,
initialInputBufferSize,
mediaCrypto,
disableLoopFilter,
useSurfaceYuvOutput);