mirror of
https://github.com/androidx/media.git
synced 2025-05-16 20:19:57 +08:00
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.
This commit is contained in:
parent
5a16aee2c9
commit
2cf8553049
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user