mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2026-06-16 13:51:51 +00:00
Lower the buffer size of the Opus decoder based on the data we're actual receiving. Handle invocations of the decoder with null data for packet loss indication.
This commit is contained in:
+2
-2
@@ -30,7 +30,7 @@ int nv_opus_get_channel_count(void) {
|
||||
|
||||
// This number assumes 2 channels at 48 KHz
|
||||
int nv_opus_get_max_out_shorts(void) {
|
||||
return 5760*2;
|
||||
return 512*nv_opus_get_channel_count();
|
||||
}
|
||||
|
||||
// The Opus stream is 48 KHz
|
||||
@@ -48,7 +48,7 @@ int nv_opus_decode(unsigned char* indata, int inlen, short* outpcmdata) {
|
||||
// Decoding to 16-bit PCM with FEC off
|
||||
// Maximum length assuming 48KHz sample rate
|
||||
err = opus_decode(decoder, indata, inlen,
|
||||
outpcmdata, 5760, 0);
|
||||
outpcmdata, 512, 0);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
+12
-5
@@ -1,5 +1,6 @@
|
||||
#include "nv_opus_dec.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <jni.h>
|
||||
|
||||
// This function must be called before
|
||||
@@ -48,13 +49,19 @@ Java_com_limelight_nvstream_av_audio_OpusDecoder_decode(
|
||||
jbyte* jni_input_data;
|
||||
jshort* jni_pcm_data;
|
||||
|
||||
jni_input_data = (*env)->GetByteArrayElements(env, indata, 0);
|
||||
jni_pcm_data = (*env)->GetShortArrayElements(env, outpcmdata, 0);
|
||||
jni_pcm_data = (*env)->GetShortArrayElements(env, outpcmdata, 0);
|
||||
if (indata != NULL) {
|
||||
jni_input_data = (*env)->GetByteArrayElements(env, indata, 0);
|
||||
|
||||
ret = nv_opus_decode(&jni_input_data[inoff], inlen, jni_pcm_data);
|
||||
ret = nv_opus_decode(&jni_input_data[inoff], inlen, jni_pcm_data);
|
||||
|
||||
// The input data isn't changed so it can be safely aborted
|
||||
(*env)->ReleaseByteArrayElements(env, indata, jni_input_data, JNI_ABORT);
|
||||
}
|
||||
else {
|
||||
ret = nv_opus_decode(NULL, 0, jni_pcm_data);
|
||||
}
|
||||
|
||||
// The input data isn't changed so it can be safely aborted
|
||||
(*env)->ReleaseByteArrayElements(env, indata, jni_input_data, JNI_ABORT);
|
||||
(*env)->ReleaseShortArrayElements(env, outpcmdata, jni_pcm_data, 0);
|
||||
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user