mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-02-16 18:41:00 +00:00
Fix for missing changes in Opus JNI code
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
#include <opus.h>
|
||||
#include "nv_opus_dec.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
OpusDecoder* decoder;
|
||||
|
||||
#ifdef _WIN32
|
||||
@@ -37,8 +39,8 @@ int nv_opus_get_channel_count(void) {
|
||||
}
|
||||
|
||||
// This number assumes 2 channels at 48 KHz
|
||||
int nv_opus_get_max_out_bytes(void) {
|
||||
return 1024*nv_opus_get_channel_count();
|
||||
int nv_opus_get_max_out_shorts(void) {
|
||||
return 512*nv_opus_get_channel_count();
|
||||
}
|
||||
|
||||
// The Opus stream is 48 KHz
|
||||
@@ -46,20 +48,17 @@ int nv_opus_get_sample_rate(void) {
|
||||
return 48000;
|
||||
}
|
||||
|
||||
// outpcmdata must be 11520*2 bytes in length
|
||||
// outpcmdata must be 5760*2 shorts in length
|
||||
// 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
|
||||
int nv_opus_decode(unsigned char* indata, int inlen, unsigned char* outpcmdata) {
|
||||
int nv_opus_decode(unsigned char* indata, int inlen, short* outpcmdata) {
|
||||
int err;
|
||||
|
||||
// Decoding to 16-bit PCM with FEC off
|
||||
// Maximum length assuming 48KHz sample rate
|
||||
err = opus_decode(decoder, indata, inlen,
|
||||
(opus_int16*) outpcmdata, 512, 0);
|
||||
outpcmdata, 512, 0);
|
||||
|
||||
if (err>0)
|
||||
err = err * 2;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
int nv_opus_init(void);
|
||||
void nv_opus_destroy(void);
|
||||
int nv_opus_get_channel_count(void);
|
||||
int nv_opus_get_max_out_bytes(void);
|
||||
int nv_opus_get_max_out_shorts(void);
|
||||
int nv_opus_get_sample_rate(void);
|
||||
int nv_opus_decode(unsigned char* indata, int inlen, unsigned char* outpcmdata);
|
||||
int nv_opus_decode(unsigned char* indata, int inlen, short* outpcmdata);
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <jni.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
// This function must be called before
|
||||
// any other decoding functions
|
||||
JNIEXPORT jint JNICALL
|
||||
@@ -25,8 +27,8 @@ Java_com_limelight_nvstream_av_audio_OpusDecoder_getChannelCount(JNIEnv *env, jo
|
||||
|
||||
// This number assumes 2 channels at 48 KHz
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_limelight_nvstream_av_audio_OpusDecoder_getMaxOutputBytes(JNIEnv *env, jobject this) {
|
||||
return nv_opus_get_max_out_bytes();
|
||||
Java_com_limelight_nvstream_av_audio_OpusDecoder_getMaxOutputShorts(JNIEnv *env, jobject this) {
|
||||
return nv_opus_get_max_out_shorts();
|
||||
}
|
||||
|
||||
// The Opus stream is 48 KHz
|
||||
@@ -52,14 +54,14 @@ Java_com_limelight_nvstream_av_audio_OpusDecoder_decode(
|
||||
jni_pcm_data = (*env)->GetByteArrayElements(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, (jshort*) 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);
|
||||
ret = nv_opus_decode(NULL, 0, (jshort*) jni_pcm_data);
|
||||
}
|
||||
|
||||
(*env)->ReleaseByteArrayElements(env, outpcmdata, jni_pcm_data, 0);
|
||||
|
||||
Reference in New Issue
Block a user