From 8750ed8de6469dc818007f2eb254df9ddbd52cc5 Mon Sep 17 00:00:00 2001 From: tonihei Date: Tue, 31 Oct 2023 12:24:24 +0000 Subject: [PATCH] Format with google-java-format Also amended Javadoc and added assertion to grow method --- .../decoder/SimpleDecoderOutputBuffer.java | 10 +++++--- .../decoder/ffmpeg/FfmpegAudioDecoder.java | 25 +++++++++++++------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/libraries/decoder/src/main/java/androidx/media3/decoder/SimpleDecoderOutputBuffer.java b/libraries/decoder/src/main/java/androidx/media3/decoder/SimpleDecoderOutputBuffer.java index eb01d97c499..b3b1a1562f2 100644 --- a/libraries/decoder/src/main/java/androidx/media3/decoder/SimpleDecoderOutputBuffer.java +++ b/libraries/decoder/src/main/java/androidx/media3/decoder/SimpleDecoderOutputBuffer.java @@ -51,14 +51,16 @@ public ByteBuffer init(long timeUs, int size) { } /** - * Reallocates the buffer with new size - * Existing data between beginning of the buffer and {@link ByteBuffer#limit} is copied to the new buffer, - * and {@link ByteBuffer#position} is preserved. {@link ByteBuffer#limit} is set to the new size. - * @param newSize New size of buffer. + * Grows the buffer with to a new size. + * + *

Existing data is copied to the new buffer, and {@link ByteBuffer#position} is preserved. + * + * @param newSize New size of the buffer. * @return The {@link #data} buffer, for convenience. */ public ByteBuffer grow(int newSize) { Assertions.checkNotNull(data); + Assertions.checkArgument(newSize >= data.limit()); final ByteBuffer newData = ByteBuffer.allocateDirect(newSize).order(ByteOrder.nativeOrder()); final int restorePosition = data.position(); data.position(0); diff --git a/libraries/decoder_ffmpeg/src/main/java/androidx/media3/decoder/ffmpeg/FfmpegAudioDecoder.java b/libraries/decoder_ffmpeg/src/main/java/androidx/media3/decoder/ffmpeg/FfmpegAudioDecoder.java index 37a2c6b4486..42e54b5a7fc 100644 --- a/libraries/decoder_ffmpeg/src/main/java/androidx/media3/decoder/ffmpeg/FfmpegAudioDecoder.java +++ b/libraries/decoder_ffmpeg/src/main/java/androidx/media3/decoder/ffmpeg/FfmpegAudioDecoder.java @@ -63,7 +63,8 @@ public FfmpegAudioDecoder( codecName = Assertions.checkNotNull(FfmpegLibrary.getCodecName(format.sampleMimeType)); extraData = getExtraData(format.sampleMimeType, format.initializationData); encoding = outputFloat ? C.ENCODING_PCM_FLOAT : C.ENCODING_PCM_16BIT; - outputBufferSize = outputFloat ? INITIAL_OUTPUT_BUFFER_SIZE_32BIT : INITIAL_OUTPUT_BUFFER_SIZE_16BIT; + outputBufferSize = + outputFloat ? INITIAL_OUTPUT_BUFFER_SIZE_32BIT : INITIAL_OUTPUT_BUFFER_SIZE_16BIT; nativeContext = ffmpegInitialize(codecName, extraData, outputFloat, format.sampleRate, format.channelCount); if (nativeContext == 0) { @@ -106,9 +107,10 @@ protected FfmpegDecoderException decode( } ByteBuffer inputData = Util.castNonNull(inputBuffer.data); int inputSize = inputData.limit(); - outputBuffer.init(inputBuffer.timeUs, outputBufferSize); - - int result = ffmpegDecode(nativeContext, inputData, inputSize, outputBuffer, outputBuffer.data, outputBufferSize); + ByteBuffer outputData = outputBuffer.init(inputBuffer.timeUs, outputBufferSize); + int result = + ffmpegDecode( + nativeContext, inputData, inputSize, outputBuffer, outputData, outputBufferSize); if (result == AUDIO_DECODER_ERROR_OTHER) { return new FfmpegDecoderException("Error decoding (see logcat)."); } else if (result == AUDIO_DECODER_ERROR_INVALID_DATA) { @@ -135,13 +137,15 @@ protected FfmpegDecoderException decode( } hasOutputFormat = true; } - outputBuffer.data.position(0); - outputBuffer.data.limit(result); + outputData.position(0); + outputData.limit(result); return null; } // Called from native code - /** @noinspection unused*/ + /** + * @noinspection unused + */ private ByteBuffer growOutputBuffer(SimpleDecoderOutputBuffer outputBuffer, int requiredSize) { // Use it for new buffer so that hopefully we won't need to reallocate again outputBufferSize = requiredSize; @@ -229,7 +233,12 @@ private native long ffmpegInitialize( int rawChannelCount); private native int ffmpegDecode( - long context, ByteBuffer inputData, int inputSize, SimpleDecoderOutputBuffer decoderOutputBuffer, ByteBuffer outputData, int outputSize); + long context, + ByteBuffer inputData, + int inputSize, + SimpleDecoderOutputBuffer decoderOutputBuffer, + ByteBuffer outputData, + int outputSize); private native int ffmpegGetChannelCount(long context);