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 { 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; private static final int NUM_BUFFERS = 16;
/** /** The default input buffer size. */
* The initial input buffer size. Input buffers are reallocated dynamically if this value is private static final int DEFAULT_INPUT_BUFFER_SIZE = 960 * 6;
* insufficient.
*/
private static final int INITIAL_INPUT_BUFFER_SIZE = 960 * 6;
private final boolean enableFloatOutput; private final boolean enableFloatOutput;
@ -120,13 +115,11 @@ public final class FfmpegAudioRenderer extends SimpleDecoderAudioRenderer {
@Override @Override
protected FfmpegDecoder createDecoder(Format format, ExoMediaCrypto mediaCrypto) protected FfmpegDecoder createDecoder(Format format, ExoMediaCrypto mediaCrypto)
throws FfmpegDecoderException { throws FfmpegDecoderException {
int initialInputBufferSize =
format.maxInputSize != Format.NO_VALUE ? format.maxInputSize : DEFAULT_INPUT_BUFFER_SIZE;
decoder = decoder =
new FfmpegDecoder( new FfmpegDecoder(
NUM_BUFFERS, NUM_BUFFERS, NUM_BUFFERS, initialInputBufferSize, format, shouldUseFloatOutput(format));
NUM_BUFFERS,
INITIAL_INPUT_BUFFER_SIZE,
format,
shouldUseFloatOutput(format));
return decoder; return decoder;
} }

View File

@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer2.ext.flac; 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.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.SimpleOutputBuffer;
@ -37,11 +38,17 @@ import java.util.List;
* *
* @param numInputBuffers The number of input buffers. * @param numInputBuffers The number of input buffers.
* @param numOutputBuffers The number of output 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 * @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. * @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 { throws FlacDecoderException {
super(new DecoderInputBuffer[numInputBuffers], new SimpleOutputBuffer[numOutputBuffers]); super(new DecoderInputBuffer[numInputBuffers], new SimpleOutputBuffer[numOutputBuffers]);
if (initializationData.size() != 1) { if (initializationData.size() != 1) {
@ -60,7 +67,9 @@ import java.util.List;
throw new FlacDecoderException("Metadata decoding failed"); throw new FlacDecoderException("Metadata decoding failed");
} }
setInitialInputBufferSize(streamInfo.maxFrameSize); int initialInputBufferSize =
maxInputBufferSize != Format.NO_VALUE ? maxInputBufferSize : streamInfo.maxFrameSize;
setInitialInputBufferSize(initialInputBufferSize);
maxOutputBufferSize = streamInfo.maxDecodedFrameSize(); maxOutputBufferSize = streamInfo.maxDecodedFrameSize();
} }

View File

@ -65,7 +65,8 @@ public class LibflacAudioRenderer extends SimpleDecoderAudioRenderer {
@Override @Override
protected FlacDecoder createDecoder(Format format, ExoMediaCrypto mediaCrypto) protected FlacDecoder createDecoder(Format format, ExoMediaCrypto mediaCrypto)
throws FlacDecoderException { 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 { public final class LibopusAudioRenderer extends SimpleDecoderAudioRenderer {
/** The number of input and output buffers. */
private static final int NUM_BUFFERS = 16; 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; private OpusDecoder decoder;
@ -88,8 +90,15 @@ public final class LibopusAudioRenderer extends SimpleDecoderAudioRenderer {
@Override @Override
protected OpusDecoder createDecoder(Format format, ExoMediaCrypto mediaCrypto) protected OpusDecoder createDecoder(Format format, ExoMediaCrypto mediaCrypto)
throws OpusDecoderException { throws OpusDecoderException {
decoder = new OpusDecoder(NUM_BUFFERS, NUM_BUFFERS, INITIAL_INPUT_BUFFER_SIZE, int initialInputBufferSize =
format.initializationData, mediaCrypto); format.maxInputSize != Format.NO_VALUE ? format.maxInputSize : DEFAULT_INPUT_BUFFER_SIZE;
decoder =
new OpusDecoder(
NUM_BUFFERS,
NUM_BUFFERS,
initialInputBufferSize,
format.initializationData,
mediaCrypto);
return decoder; 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. * requiring multiple output buffers to be dequeued at a time for it to make progress.
*/ */
private static final int NUM_OUTPUT_BUFFERS = 8; private static final int NUM_OUTPUT_BUFFERS = 8;
/** /** The default input buffer size. */
* The initial input buffer size. Input buffers are reallocated dynamically if this value is private static final int DEFAULT_INPUT_BUFFER_SIZE = 768 * 1024; // Value based on cs/SoftVpx.cpp.
* insufficient.
*/
private static final int INITIAL_INPUT_BUFFER_SIZE = 768 * 1024; // Value based on cs/SoftVpx.cpp.
private final boolean scaleToFit; private final boolean scaleToFit;
private final boolean disableLoopFilter; private final boolean disableLoopFilter;
@ -703,11 +700,13 @@ public class LibvpxVideoRenderer extends BaseRenderer {
try { try {
long decoderInitializingTimestamp = SystemClock.elapsedRealtime(); long decoderInitializingTimestamp = SystemClock.elapsedRealtime();
TraceUtil.beginSection("createVpxDecoder"); TraceUtil.beginSection("createVpxDecoder");
int initialInputBufferSize =
format.maxInputSize != Format.NO_VALUE ? format.maxInputSize : DEFAULT_INPUT_BUFFER_SIZE;
decoder = decoder =
new VpxDecoder( new VpxDecoder(
NUM_INPUT_BUFFERS, NUM_INPUT_BUFFERS,
NUM_OUTPUT_BUFFERS, NUM_OUTPUT_BUFFERS,
INITIAL_INPUT_BUFFER_SIZE, initialInputBufferSize,
mediaCrypto, mediaCrypto,
disableLoopFilter, disableLoopFilter,
useSurfaceYuvOutput); useSurfaceYuvOutput);