Skip to content

Commit 8750ed8

Browse files
committed
Format with google-java-format
Also amended Javadoc and added assertion to grow method
1 parent adee462 commit 8750ed8

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

libraries/decoder/src/main/java/androidx/media3/decoder/SimpleDecoderOutputBuffer.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@ public ByteBuffer init(long timeUs, int size) {
5151
}
5252

5353
/**
54-
* Reallocates the buffer with new size
55-
* Existing data between beginning of the buffer and {@link ByteBuffer#limit} is copied to the new buffer,
56-
* and {@link ByteBuffer#position} is preserved. {@link ByteBuffer#limit} is set to the new size.
57-
* @param newSize New size of buffer.
54+
* Grows the buffer with to a new size.
55+
*
56+
* <p>Existing data is copied to the new buffer, and {@link ByteBuffer#position} is preserved.
57+
*
58+
* @param newSize New size of the buffer.
5859
* @return The {@link #data} buffer, for convenience.
5960
*/
6061
public ByteBuffer grow(int newSize) {
6162
Assertions.checkNotNull(data);
63+
Assertions.checkArgument(newSize >= data.limit());
6264
final ByteBuffer newData = ByteBuffer.allocateDirect(newSize).order(ByteOrder.nativeOrder());
6365
final int restorePosition = data.position();
6466
data.position(0);

libraries/decoder_ffmpeg/src/main/java/androidx/media3/decoder/ffmpeg/FfmpegAudioDecoder.java

+17-8
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public FfmpegAudioDecoder(
6363
codecName = Assertions.checkNotNull(FfmpegLibrary.getCodecName(format.sampleMimeType));
6464
extraData = getExtraData(format.sampleMimeType, format.initializationData);
6565
encoding = outputFloat ? C.ENCODING_PCM_FLOAT : C.ENCODING_PCM_16BIT;
66-
outputBufferSize = outputFloat ? INITIAL_OUTPUT_BUFFER_SIZE_32BIT : INITIAL_OUTPUT_BUFFER_SIZE_16BIT;
66+
outputBufferSize =
67+
outputFloat ? INITIAL_OUTPUT_BUFFER_SIZE_32BIT : INITIAL_OUTPUT_BUFFER_SIZE_16BIT;
6768
nativeContext =
6869
ffmpegInitialize(codecName, extraData, outputFloat, format.sampleRate, format.channelCount);
6970
if (nativeContext == 0) {
@@ -106,9 +107,10 @@ protected FfmpegDecoderException decode(
106107
}
107108
ByteBuffer inputData = Util.castNonNull(inputBuffer.data);
108109
int inputSize = inputData.limit();
109-
outputBuffer.init(inputBuffer.timeUs, outputBufferSize);
110-
111-
int result = ffmpegDecode(nativeContext, inputData, inputSize, outputBuffer, outputBuffer.data, outputBufferSize);
110+
ByteBuffer outputData = outputBuffer.init(inputBuffer.timeUs, outputBufferSize);
111+
int result =
112+
ffmpegDecode(
113+
nativeContext, inputData, inputSize, outputBuffer, outputData, outputBufferSize);
112114
if (result == AUDIO_DECODER_ERROR_OTHER) {
113115
return new FfmpegDecoderException("Error decoding (see logcat).");
114116
} else if (result == AUDIO_DECODER_ERROR_INVALID_DATA) {
@@ -135,13 +137,15 @@ protected FfmpegDecoderException decode(
135137
}
136138
hasOutputFormat = true;
137139
}
138-
outputBuffer.data.position(0);
139-
outputBuffer.data.limit(result);
140+
outputData.position(0);
141+
outputData.limit(result);
140142
return null;
141143
}
142144

143145
// Called from native code
144-
/** @noinspection unused*/
146+
/**
147+
* @noinspection unused
148+
*/
145149
private ByteBuffer growOutputBuffer(SimpleDecoderOutputBuffer outputBuffer, int requiredSize) {
146150
// Use it for new buffer so that hopefully we won't need to reallocate again
147151
outputBufferSize = requiredSize;
@@ -229,7 +233,12 @@ private native long ffmpegInitialize(
229233
int rawChannelCount);
230234

231235
private native int ffmpegDecode(
232-
long context, ByteBuffer inputData, int inputSize, SimpleDecoderOutputBuffer decoderOutputBuffer, ByteBuffer outputData, int outputSize);
236+
long context,
237+
ByteBuffer inputData,
238+
int inputSize,
239+
SimpleDecoderOutputBuffer decoderOutputBuffer,
240+
ByteBuffer outputData,
241+
int outputSize);
233242

234243
private native int ffmpegGetChannelCount(long context);
235244

0 commit comments

Comments
 (0)