Skip to content

Commit

Permalink
Format with google-java-format
Browse files Browse the repository at this point in the history
Also amended Javadoc and added assertion to grow method
  • Loading branch information
tonihei committed Oct 31, 2023
1 parent adee462 commit 8750ed8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 8750ed8

Please sign in to comment.