From 95de57a6c6752fcd436799d9a59ea98a2a5b4cf2 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 11 Dec 2014 11:16:15 +0100 Subject: [PATCH] Fix ec calibration crash in Android --- coreapi/linphonecore_jni.cc | 39 +++++++++++-------- .../org/linphone/core/LinphoneCore.java | 5 ++- .../linphone/core/LinphoneCoreListener.java | 20 +++++----- .../org/linphone/core/LinphoneCoreImpl.java | 5 ++- 4 files changed, 40 insertions(+), 29 deletions(-) diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 00e2c3692..98f14bff9 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -763,17 +763,24 @@ public: ms_error("cannot attach VM"); return; } - LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); - LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); - env->CallVoidMethod(lcData->listener - ,lcData->ecCalibrationStatusId - ,lcData->core - ,env->CallStaticObjectMethod(lcData->ecCalibratorStatusClass,lcData->ecCalibratorStatusFromIntId,(jint)status) - ,delay_ms - ,data ? data : NULL); - if (data != NULL &&status !=LinphoneEcCalibratorInProgress ) { - //final state, releasing global ref - env->DeleteGlobalRef((jobject)data); + + LinphoneCoreVTable *table = (LinphoneCoreVTable*) data; + if (table) { + LinphoneCoreData* lcData = (LinphoneCoreData*) linphone_core_v_table_get_user_data(table); + if (lcData->ecCalibrationStatusId) { + jobject ecData = env->NewGlobalRef((jobject) data); + jobject state = env->CallStaticObjectMethod(lcData->ecCalibratorStatusClass, lcData->ecCalibratorStatusFromIntId, (jint)status); + env->CallVoidMethod(lcData->listener + ,lcData->ecCalibrationStatusId + ,lcData->core + ,state + ,delay_ms + ,ecData); + env->DeleteGlobalRef(ecData); + } + if (status != LinphoneEcCalibratorInProgress) { + linphone_core_v_table_destroy(table); + } } } @@ -1727,11 +1734,11 @@ extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_startEchoCalibration(JNI ,jobject thiz ,jlong lc ,jobject data) { - return (jint)linphone_core_start_echo_calibration((LinphoneCore*)lc - , LinphoneCoreData::ecCalibrationStatus - , NULL - , NULL - , data?env->NewGlobalRef(data):NULL); + LinphoneCoreVTable *vTable = linphone_core_v_table_new(); + LinphoneCoreData* ldata = new LinphoneCoreData(env, thiz, vTable, data); + linphone_core_v_table_set_user_data(vTable, ldata); + + return (jint)linphone_core_start_echo_calibration((LinphoneCore*)lc, ldata->ecCalibrationStatus, NULL, NULL, vTable); } diff --git a/java/common/org/linphone/core/LinphoneCore.java b/java/common/org/linphone/core/LinphoneCore.java index 93c5fe1cf..4b8f42a1b 100644 --- a/java/common/org/linphone/core/LinphoneCore.java +++ b/java/common/org/linphone/core/LinphoneCore.java @@ -20,6 +20,7 @@ package org.linphone.core; import java.util.Vector; +import org.linphone.core.LinphoneCoreListener.LinphoneEchoCalibrationListener; import org.linphone.mediastream.video.AndroidVideoWindowImpl; import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration; @@ -1057,10 +1058,10 @@ public interface LinphoneCore { /** * Start an echo calibration of the sound devices, in order to find adequate settings for the echo canceler automatically. * status is notified to {@link LinphoneCoreListener#ecCalibrationStatus(EcCalibratorStatus, int, Object)} - * @param User object + * @param listener the LinphoneEchoCalibrationListener to call when the calibration is done * @throws LinphoneCoreException if operation is still in progress; **/ - void startEchoCalibration(Object data) throws LinphoneCoreException; + void startEchoCalibration(LinphoneEchoCalibrationListener listener) throws LinphoneCoreException; /** * Returns true if echo calibration is recommended. diff --git a/java/common/org/linphone/core/LinphoneCoreListener.java b/java/common/org/linphone/core/LinphoneCoreListener.java index d92743ce1..4be9ff799 100644 --- a/java/common/org/linphone/core/LinphoneCoreListener.java +++ b/java/common/org/linphone/core/LinphoneCoreListener.java @@ -75,15 +75,6 @@ public interface LinphoneCoreListener { */ void dtmfReceived(LinphoneCore lc, LinphoneCall call, int dtmf); - /** - * Invoked when echo cancalation calibration is completed - * @param lc LinphoneCore - * @param status - * @param delay_ms echo delay - * @param data - */ - void ecCalibrationStatus(LinphoneCore lc,LinphoneCore.EcCalibratorStatus status, int delay_ms, Object data); - /** * Report Notified message received for this identity. * @param lc LinphoneCore @@ -243,5 +234,16 @@ public interface LinphoneCoreListener { */ void isComposingReceived(LinphoneCore lc, LinphoneChatRoom cr); } + + public interface LinphoneEchoCalibrationListener extends LinphoneCoreListener { + /** + * Invoked when echo cancalation calibration is completed + * @param lc LinphoneCore + * @param status + * @param delay_ms echo delay + * @param data + */ + void ecCalibrationStatus(LinphoneCore lc,LinphoneCore.EcCalibratorStatus status, int delay_ms, Object data); + } } diff --git a/java/impl/org/linphone/core/LinphoneCoreImpl.java b/java/impl/org/linphone/core/LinphoneCoreImpl.java index ea8899883..21a356490 100644 --- a/java/impl/org/linphone/core/LinphoneCoreImpl.java +++ b/java/impl/org/linphone/core/LinphoneCoreImpl.java @@ -24,6 +24,7 @@ import java.io.File; import java.io.IOException; import org.linphone.core.LinphoneCall.State; +import org.linphone.core.LinphoneCoreListener.LinphoneEchoCalibrationListener; import org.linphone.mediastream.Log; import org.linphone.mediastream.video.AndroidVideoWindowImpl; import org.linphone.mediastream.video.capture.hwconf.Hacks; @@ -558,8 +559,8 @@ class LinphoneCoreImpl implements LinphoneCore { public synchronized boolean isKeepAliveEnabled() { return isKeepAliveEnabled(nativePtr); } - public synchronized void startEchoCalibration(Object data) throws LinphoneCoreException { - startEchoCalibration(nativePtr, data); + public synchronized void startEchoCalibration(LinphoneEchoCalibrationListener listener) throws LinphoneCoreException { + startEchoCalibration(nativePtr, listener); } public synchronized Transports getSignalingTransportPorts() {