haiyangwu / mediasoup-client-android

mediasoup android client side library https://mediasoup.org
MIT License
178 stars 107 forks source link

JNI crashes on WebRtcAudioRecord.nativeDataIsRecorded and WebRtcAudioTrack.nativeGetPlayoutData #54

Open grebulon opened 2 years ago

grebulon commented 2 years ago

I'm using this library successfully, but sometimes get these two crashes indicating that there are missing native JNI functions:

First: org.webrtc.voiceengine.WebRtcAudioRecord.nativeDataIsRecorded

----- Unhandled Exception: No implementation found for void org.webrtc.voiceengine.WebRtcAudioRecord.nativeDataIsRecorded(int, long) (tried Java_org_webrtc_voiceengine_WebRtcAudioRecord_nativeDataIsRecorded and Java_org_webrtc_voiceengine_WebRtcAudioRecord_nativeDataIsRecorded__IJ) -----
java.lang.UnsatisfiedLinkError: No implementation found for void org.webrtc.voiceengine.WebRtcAudioRecord.nativeDataIsRecorded(int, long) (tried Java_org_webrtc_voiceengine_WebRtcAudioRecord_nativeDataIsRecorded and Java_org_webrtc_voiceengine_WebRtcAudioRecord_nativeDataIsRecorded__IJ)
--------- Stack trace ---------
org.webrtc.voiceengine.WebRtcAudioRecord.nativeDataIsRecorded(Native Method)
org.webrtc.voiceengine.WebRtcAudioRecord.access$600(WebRtcAudioRecord.java:26)
org.webrtc.voiceengine.WebRtcAudioRecord$AudioRecordThread.run(WebRtcAudioRecord.java:166)

Second: org.webrtc.voiceengine.WebRtcAudioTrack.nativeGetPlayoutData (already reported)

----- Unhandled Exception: No implementation found for void org.webrtc.voiceengine.WebRtcAudioTrack.nativeGetPlayoutData(int, long) (tried Java_org_webrtc_voiceengine_WebRtcAudioTrack_nativeGetPlayoutData and Java_org_webrtc_voiceengine_WebRtcAudioTrack_nativeGetPlayoutData__IJ) -----
java.lang.UnsatisfiedLinkError: No implementation found for void org.webrtc.voiceengine.WebRtcAudioTrack.nativeGetPlayoutData(int, long) (tried Java_org_webrtc_voiceengine_WebRtcAudioTrack_nativeGetPlayoutData and Java_org_webrtc_voiceengine_WebRtcAudioTrack_nativeGetPlayoutData__IJ)
--------- Stack trace ---------
org.webrtc.voiceengine.WebRtcAudioTrack.nativeGetPlayoutData(Native Method)
org.webrtc.voiceengine.WebRtcAudioTrack.access$400(WebRtcAudioTrack.java:28)
org.webrtc.voiceengine.WebRtcAudioTrack$AudioTrackThread.run(WebRtcAudioTrack.java:147)
grebulon commented 2 years ago

The native cc code for DataIsRecorded is defined as:

{"nativeDataIsRecorded", "(IJ)V", reinterpret_cast<void*>(&webrtc::AudioRecordJni::DataIsRecorded)}};

JNI_FUNCTION_ALIGN void JNICALL AudioRecordJni::DataIsRecorded(JNIEnv* env, jobject obj, jint length, jlong nativeAudioRecord)

The arguments are: jint length, jlong nativeAudioRecord

It is called twice:

From: ./mediasoup-client/deps/webrtc/src/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java - as:

private native void nativeDataIsRecorded(int bytes, long nativeAudioRecord);

From: ./mediasoup-client/deps/webrtc/src/sdk/android/src/java/org/webrtc/audio/WebRtcAudioRecord.java - as:

private native void nativeDataIsRecorded(long nativeAudioRecordJni, int bytes);

In the second case, the arguments are reversed: long nativeAudioRecordJni, int bytes.

Same goes for GetPlayoutData:

{"nativeGetPlayoutData", "(IJ)V", reinterpret_cast<void*>(&webrtc::AudioTrackJni::GetPlayoutData)}};

JNI_FUNCTION_ALIGN void JNICALL AudioTrackJni::GetPlayoutData(JNIEnv* env, jobject obj, jint length, jlong nativeAudioTrack)

Called properly from: ./mediasoup-client/deps/webrtc/src/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java - as:

private native void nativeGetPlayoutData(int bytes, long nativeAudioRecord);

From: ./mediasoup-client/deps/webrtc/src/sdk/android/src/java/org/webrtc/audio/WebRtcAudioTrack.java - as (wrong order):

private static native void nativeGetPlayoutData(long nativeAudioTrackJni, int bytes);