Format with google-java-format

Also amended Javadoc and added assertion to grow method
This commit is contained in:
tonihei 2023-10-31 12:24:24 +00:00
parent adee4626d3
commit 8750ed8de6
2 changed files with 23 additions and 12 deletions

View File

@ -51,14 +51,16 @@ public class SimpleDecoderOutputBuffer extends DecoderOutputBuffer {
} }
/** /**
* Reallocates the buffer with new size * Grows the buffer with to a 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. * <p>Existing data is copied to the new buffer, and {@link ByteBuffer#position} is preserved.
* @param newSize New size of buffer. *
* @param newSize New size of the buffer.
* @return The {@link #data} buffer, for convenience. * @return The {@link #data} buffer, for convenience.
*/ */
public ByteBuffer grow(int newSize) { public ByteBuffer grow(int newSize) {
Assertions.checkNotNull(data); Assertions.checkNotNull(data);
Assertions.checkArgument(newSize >= data.limit());
final ByteBuffer newData = ByteBuffer.allocateDirect(newSize).order(ByteOrder.nativeOrder()); final ByteBuffer newData = ByteBuffer.allocateDirect(newSize).order(ByteOrder.nativeOrder());
final int restorePosition = data.position(); final int restorePosition = data.position();
data.position(0); data.position(0);

View File

@ -63,7 +63,8 @@ import java.util.List;
codecName = Assertions.checkNotNull(FfmpegLibrary.getCodecName(format.sampleMimeType)); codecName = Assertions.checkNotNull(FfmpegLibrary.getCodecName(format.sampleMimeType));
extraData = getExtraData(format.sampleMimeType, format.initializationData); extraData = getExtraData(format.sampleMimeType, format.initializationData);
encoding = outputFloat ? C.ENCODING_PCM_FLOAT : C.ENCODING_PCM_16BIT; 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 = nativeContext =
ffmpegInitialize(codecName, extraData, outputFloat, format.sampleRate, format.channelCount); ffmpegInitialize(codecName, extraData, outputFloat, format.sampleRate, format.channelCount);
if (nativeContext == 0) { if (nativeContext == 0) {
@ -106,9 +107,10 @@ import java.util.List;
} }
ByteBuffer inputData = Util.castNonNull(inputBuffer.data); ByteBuffer inputData = Util.castNonNull(inputBuffer.data);
int inputSize = inputData.limit(); int inputSize = inputData.limit();
outputBuffer.init(inputBuffer.timeUs, outputBufferSize); ByteBuffer outputData = outputBuffer.init(inputBuffer.timeUs, outputBufferSize);
int result =
int result = ffmpegDecode(nativeContext, inputData, inputSize, outputBuffer, outputBuffer.data, outputBufferSize); ffmpegDecode(
nativeContext, inputData, inputSize, outputBuffer, outputData, outputBufferSize);
if (result == AUDIO_DECODER_ERROR_OTHER) { if (result == AUDIO_DECODER_ERROR_OTHER) {
return new FfmpegDecoderException("Error decoding (see logcat)."); return new FfmpegDecoderException("Error decoding (see logcat).");
} else if (result == AUDIO_DECODER_ERROR_INVALID_DATA) { } else if (result == AUDIO_DECODER_ERROR_INVALID_DATA) {
@ -135,13 +137,15 @@ import java.util.List;
} }
hasOutputFormat = true; hasOutputFormat = true;
} }
outputBuffer.data.position(0); outputData.position(0);
outputBuffer.data.limit(result); outputData.limit(result);
return null; return null;
} }
// Called from native code // Called from native code
/** @noinspection unused*/ /**
* @noinspection unused
*/
private ByteBuffer growOutputBuffer(SimpleDecoderOutputBuffer outputBuffer, int requiredSize) { private ByteBuffer growOutputBuffer(SimpleDecoderOutputBuffer outputBuffer, int requiredSize) {
// Use it for new buffer so that hopefully we won't need to reallocate again // Use it for new buffer so that hopefully we won't need to reallocate again
outputBufferSize = requiredSize; outputBufferSize = requiredSize;
@ -229,7 +233,12 @@ import java.util.List;
int rawChannelCount); int rawChannelCount);
private native int ffmpegDecode( 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); private native int ffmpegGetChannelCount(long context);