Commit 2cf85530 by Romain Caire

opus: use fixed max size in Opus decoding as per documentation: If this is less…

opus: use fixed max size in Opus decoding as per documentation: If this is less than the maximum packet duration (120 ms; 5760 for 48kHz), this function will not be capable of decoding some packets.
parent 5a16aee2
Showing with 3 additions and 2 deletions
......@@ -59,6 +59,7 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) {
}
static const int kBytesPerSample = 2; // opus fixed point uses 16 bit samples.
static const int kMaxOpusOutputPacketSizeSamples = 960 * 6;// Maximum packet size used in Xiph's opusdec.
static int channelCount;
static int errorCode;
......@@ -101,7 +102,7 @@ DECODER_FUNC(jint, opusDecode, jlong jDecoder, jlong jTimeUs,
const int32_t inputSampleCount =
opus_packet_get_nb_samples(inputBuffer, inputSize, sampleRate);
const jint outputSize = inputSampleCount * kBytesPerSample * channelCount;
const jint outputSize = kMaxOpusOutputPacketSizeSamples * kBytesPerSample * channelCount;
env->CallObjectMethod(jOutputBuffer, outputBufferInit, jTimeUs, outputSize);
const jobject jOutputBufferData = env->CallObjectMethod(jOutputBuffer,
......@@ -110,7 +111,7 @@ DECODER_FUNC(jint, opusDecode, jlong jDecoder, jlong jTimeUs,
int16_t* outputBufferData = reinterpret_cast<int16_t*>(
env->GetDirectBufferAddress(jOutputBufferData));
int sampleCount = opus_multistream_decode(decoder, inputBuffer, inputSize,
outputBufferData, outputSize, 0);
outputBufferData, kMaxOpusOutputPacketSizeSamples, 0);
// record error code
errorCode = (sampleCount < 0) ? sampleCount : 0;
return (sampleCount < 0) ? sampleCount
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment