mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-19 19:13:03 +00:00
Update decoder code
This commit is contained in:
parent
c9014da186
commit
ad10413714
@ -3,19 +3,23 @@
|
||||
#include <stdlib.h>
|
||||
#include <jni.h>
|
||||
|
||||
static int SamplesPerChannel;
|
||||
static int ChannelCount;
|
||||
|
||||
// This function must be called before
|
||||
// any other decoding functions
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_limelight_nvstream_av_audio_OpusDecoder_init(JNIEnv *env, jobject this,
|
||||
int sampleRate, int channelCount, int streams,
|
||||
Java_com_limelight_nvstream_av_audio_OpusDecoder_init(JNIEnv *env, jobject this, int sampleRate,
|
||||
int samplesPerChannel, int channelCount, int streams,
|
||||
int coupledStreams, jbyteArray mapping) {
|
||||
jbyte* jni_mapping_data;
|
||||
jint ret;
|
||||
|
||||
SamplesPerChannel = samplesPerChannel;
|
||||
ChannelCount = channelCount;
|
||||
|
||||
jni_mapping_data = (*env)->GetByteArrayElements(env, mapping, 0);
|
||||
|
||||
ret = nv_opus_init(sampleRate, channelCount, streams, coupledStreams, jni_mapping_data);
|
||||
|
||||
(*env)->ReleaseByteArrayElements(env, mapping, jni_mapping_data, JNI_ABORT);
|
||||
|
||||
return ret;
|
||||
@ -30,7 +34,7 @@ Java_com_limelight_nvstream_av_audio_OpusDecoder_destroy(JNIEnv *env, jobject th
|
||||
|
||||
// packets must be decoded in order
|
||||
// a packet loss must call this function with NULL indata and 0 inlen
|
||||
// returns the number of decoded samples
|
||||
// returns the number of decoded bytes
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_limelight_nvstream_av_audio_OpusDecoder_decode(
|
||||
JNIEnv *env, jobject this, // JNI parameters
|
||||
@ -45,14 +49,18 @@ Java_com_limelight_nvstream_av_audio_OpusDecoder_decode(
|
||||
if (indata != NULL) {
|
||||
jni_input_data = (*env)->GetByteArrayElements(env, indata, 0);
|
||||
|
||||
ret = nv_opus_decode(&jni_input_data[inoff], inlen, (jshort*)jni_pcm_data,
|
||||
(*env)->GetArrayLength(env, outpcmdata)/2);
|
||||
ret = nv_opus_decode(&jni_input_data[inoff], inlen, (jshort*)jni_pcm_data, SamplesPerChannel);
|
||||
|
||||
// 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, (jshort*)jni_pcm_data, (*env)->GetArrayLength(env, outpcmdata)/2);
|
||||
ret = nv_opus_decode(NULL, 0, (jshort*)jni_pcm_data, SamplesPerChannel);
|
||||
}
|
||||
|
||||
// Convert samples (2 bytes) per channel to total bytes returned
|
||||
if (ret > 0) {
|
||||
ret *= ChannelCount * 2;
|
||||
}
|
||||
|
||||
(*env)->ReleaseByteArrayElements(env, outpcmdata, jni_pcm_data, 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user