diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index acac5a780..1ffaba727 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -7759,19 +7759,45 @@ static void _next_video_frame_decoded_callback(LinphoneCall *call, void *user_da return; } - jobject listener = (jobject) user_data; + jobject listener = (jobject) env->NewLocalRef((jobject)user_data); + if (listener == NULL){ + ms_error("_next_video_frame_decoded_callback: listener has gone."); + return; + } jclass clazz = (jclass) env->GetObjectClass(listener); jmethodID method = env->GetMethodID(clazz, "onNextVideoFrameDecoded","(Lorg/linphone/core/LinphoneCall;)V"); env->DeleteLocalRef(clazz); jobject jcall = getCall(env, call); env->CallVoidMethod(listener, method, jcall); + env->DeleteLocalRef(listener); +} + +static void _on_tmmbr_received(LinphoneCall *call, int index, int bitrate){ + LinphoneCallCbs *cbs = linphone_call_get_current_callbacks(call); + JNIEnv *env = ms_get_jni_env(); + jobject listener = (jobject) env->NewLocalRef((jobject)linphone_call_cbs_get_user_data(cbs)); + if (listener == NULL){ + ms_error("_on_tmmbr_received: listener has gone."); + return; + } + jclass clazz = (jclass) env->GetObjectClass(listener); + jmethodID method = env->GetMethodID(clazz, "tmmbrReceived","(Lorg/linphone/core/LinphoneCall;II)V"); + env->DeleteLocalRef(clazz); + + jobject jcall = getCall(env, call); + env->CallVoidMethod(listener, method, jcall,(jint)index, (jint)bitrate); + env->DeleteLocalRef(listener); } JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneCallImpl_setListener(JNIEnv* env, jobject thiz, jlong ptr, jobject jlistener) { - jobject listener = env->NewGlobalRef(jlistener); LinphoneCall *call = (LinphoneCall *)ptr; - linphone_call_set_next_video_frame_decoded_callback(call, _next_video_frame_decoded_callback, listener); + LinphoneCallCbs *cbs = linphone_factory_create_call_cbs(linphone_factory_get()); + linphone_call_cbs_set_user_data(cbs, env->NewWeakGlobalRef(jlistener)); + linphone_call_cbs_set_tmmbr_received(cbs, _on_tmmbr_received); + linphone_call_add_callbacks(call, cbs); + + linphone_call_set_next_video_frame_decoded_callback(call, _next_video_frame_decoded_callback, env->NewWeakGlobalRef(jlistener)); } extern "C" void Java_org_linphone_core_LinphoneCallImpl_setVideoWindowId(JNIEnv* env diff --git a/java/common/org/linphone/core/LinphoneCall.java b/java/common/org/linphone/core/LinphoneCall.java index 332a76b57..ead69a5f0 100644 --- a/java/common/org/linphone/core/LinphoneCall.java +++ b/java/common/org/linphone/core/LinphoneCall.java @@ -31,8 +31,12 @@ public interface LinphoneCall { /** * LinphoneCall listener */ - interface LinphoneCallListener { + public interface LinphoneCallListener { void onNextVideoFrameDecoded(LinphoneCall call); + /** + * Invoked when a TMMBR RTCP packet is received. + */ + void tmmbrReceived(LinphoneCall call, int streamIndex, int bitrate); } /**