From 0c9100d573138cdc4e28fe7302d38d989828e00d Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 16 Oct 2017 14:08:38 +0200 Subject: [PATCH] Reworking of the EC calibrator API in order to be automatically wrapped --- coreapi/ec-calibrator.c | 33 ++++++++++++++++++++++++++++++++- coreapi/linphonecore.c | 15 +++++++++++++-- coreapi/private.h | 4 ++++ coreapi/vtables.c | 15 +++++++++++++++ include/linphone/callbacks.h | 20 ++++++++++++++++++++ include/linphone/core.h | 18 ++++++++++++++++++ include/linphone/core_utils.h | 23 ++++++++++++++++++----- 7 files changed, 120 insertions(+), 8 deletions(-) diff --git a/coreapi/ec-calibrator.c b/coreapi/ec-calibrator.c index 0c1ce7212..f82e597c1 100644 --- a/coreapi/ec-calibrator.c +++ b/coreapi/ec-calibrator.c @@ -24,7 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "mediastreamer2/dtmfgen.h" #include "linphone/lpconfig.h" - +#include "c-wrapper/c-wrapper.h" static void ecc_init_filters(EcCalibrator *ecc){ @@ -325,6 +325,37 @@ int linphone_core_start_echo_calibration(LinphoneCore *lc, LinphoneEcCalibration return 0; } +static void _ec_calibration_result_cb(LinphoneCore *lc, LinphoneEcCalibratorStatus status, int delay_ms, void *user_data) { + linphone_core_notify_ec_calibration_result(lc, status, delay_ms); +} + +static void _ec_calibration_audio_init_cb(void *user_data) { + LinphoneCore *lc = (LinphoneCore *)user_data; + linphone_core_notify_ec_calibration_audio_init(lc); +} + +static void _ec_calibration_audio_uninit_cb(void *user_data) { + LinphoneCore *lc = (LinphoneCore *)user_data; + linphone_core_notify_ec_calibration_audio_uninit(lc); +} + +LinphoneStatus linphone_core_start_echo_canceller_calibration(LinphoneCore *lc) { + unsigned int rate; + + if (lc->ecc!=NULL){ + ms_error("Echo calibration is still on going !"); + return -1; + } + rate = (unsigned int)lp_config_get_int(lc->config,"sound","echo_cancellation_rate",8000); + lc->ecc=ec_calibrator_new(lc->factory, lc->sound_conf.play_sndcard, lc->sound_conf.capt_sndcard, rate, + _ec_calibration_result_cb, + _ec_calibration_audio_init_cb, + _ec_calibration_audio_uninit_cb, lc); + lc->ecc->play_cool_tones = !!lp_config_get_int(lc->config, "sound", "ec_calibrator_cool_tones", 0); + ec_calibrator_start(lc->ecc); + return 0; +} + bool_t linphone_core_has_builtin_echo_canceller(LinphoneCore *lc) { MSFactory * factory = linphone_core_get_ms_factory(lc); MSDevicesInfo *devices = ms_factory_get_devices_info(factory); diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index ea0417a84..96bb06105 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -436,6 +436,18 @@ void linphone_core_cbs_set_chat_room_instantiated (LinphoneCoreCbs *cbs, Linphon cbs->vtable->chat_room_instantiated = cb; } +void linphone_core_cbs_set_ec_calibration_result(LinphoneCoreCbs *cbs, LinphoneCoreCbsEcCalibrationResultCb cb) { + cbs->vtable->ec_calibration_result = cb; +} + +void linphone_core_cbs_set_ec_calibration_audio_init(LinphoneCoreCbs *cbs, LinphoneCoreCbsEcCalibrationAudioInitCb cb) { + cbs->vtable->ec_calibration_audio_init = cb; +} + +void linphone_core_cbs_set_ec_calibration_audio_uninit(LinphoneCoreCbs *cbs, LinphoneCoreCbsEcCalibrationAudioUninitCb cb) { + cbs->vtable->ec_calibration_audio_uninit = cb; +} + typedef belle_sip_object_t_vptr_t LinphoneCore_vptr_t; BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneCore); @@ -2190,7 +2202,6 @@ static void linphone_core_init(LinphoneCore * lc, LinphoneCoreCbs *cbs, LpConfig _linphone_core_add_callbacks(lc, internal_cbs, TRUE); belle_sip_object_unref(internal_cbs); - if (cbs != NULL) { _linphone_core_add_callbacks(lc, cbs, FALSE); } else { @@ -7379,4 +7390,4 @@ bool_t linphone_core_has_crappy_opengl(LinphoneCore *lc) { if (sound_description == NULL) return FALSE; if (sound_description->flags & DEVICE_HAS_CRAPPY_OPENGL) return TRUE; return FALSE; -} \ No newline at end of file +} diff --git a/coreapi/private.h b/coreapi/private.h index cd82d149a..be9d0150c 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -1475,6 +1475,10 @@ void linphone_core_notify_call_created(LinphoneCore *lc, LinphoneCall *call); void linphone_core_notify_version_update_check_result_received(LinphoneCore *lc, LinphoneVersionUpdateCheckResult result, const char *version, const char *url); void linphone_core_notify_chat_room_instantiated (LinphoneCore *lc, LinphoneChatRoom *cr); +void linphone_core_notify_ec_calibration_result(LinphoneCore *lc, LinphoneEcCalibratorStatus status, int delay_ms); +void linphone_core_notify_ec_calibration_audio_init(LinphoneCore *lc); +void linphone_core_notify_ec_calibration_audio_uninit(LinphoneCore *lc); + void set_playback_gain_db(AudioStream *st, float gain); LinphoneMediaDirection media_direction_from_sal_stream_dir(SalStreamDir dir); diff --git a/coreapi/vtables.c b/coreapi/vtables.c index b14221950..280283771 100644 --- a/coreapi/vtables.c +++ b/coreapi/vtables.c @@ -292,6 +292,21 @@ void linphone_core_notify_chat_room_instantiated (LinphoneCore *lc, LinphoneChat cleanup_dead_vtable_refs(lc); } +void linphone_core_notify_ec_calibration_result(LinphoneCore *lc, LinphoneEcCalibratorStatus status, int delay_ms) { + NOTIFY_IF_EXIST(ec_calibration_result, lc, status, delay_ms); + cleanup_dead_vtable_refs(lc); +} + +void linphone_core_notify_ec_calibration_audio_init(LinphoneCore *lc) { + NOTIFY_IF_EXIST(ec_calibration_audio_init, lc); + cleanup_dead_vtable_refs(lc); +} + +void linphone_core_notify_ec_calibration_audio_uninit(LinphoneCore *lc) { + NOTIFY_IF_EXIST(ec_calibration_audio_uninit, lc); + cleanup_dead_vtable_refs(lc); +} + static VTableReference * v_table_reference_new(LinphoneCoreCbs *cbs, bool_t internal){ VTableReference *ref=ms_new0(VTableReference,1); ref->valid=TRUE; diff --git a/include/linphone/callbacks.h b/include/linphone/callbacks.h index 1c9b8b9ba..b70febf8b 100644 --- a/include/linphone/callbacks.h +++ b/include/linphone/callbacks.h @@ -492,6 +492,26 @@ typedef void (*LinphoneFriendListCbsSyncStateChangedCb)(LinphoneFriendList *list * @{ */ +/** + * @brief Function prototype used by #linphone_core_cbs_set_ec_calibrator_result(). + * @param lc The core. + * @param status The state of the calibrator. + * @param delay_ms The measured delay if available. + */ +typedef void (*LinphoneCoreCbsEcCalibrationResultCb)(LinphoneCore *lc, LinphoneEcCalibratorStatus status, int delay_ms); + +/** + * @brief Function prototype used by #linphone_core_cbs_set_ec_calibrator_audio_init(). + * @param lc The core. + */ +typedef void (*LinphoneCoreCbsEcCalibrationAudioInitCb)(LinphoneCore *lc); + +/** + * @biref Function prototype used by #linphone_core_cbs_set_ec_calibrator_audio_uninit(). + * @param lc The core. + */ +typedef void (*LinphoneCoreCbsEcCalibrationAudioUninitCb)(LinphoneCore *lc); + /** * Callback to decrypt incoming LinphoneChatMessage * @param engine ImEncryptionEngine object diff --git a/include/linphone/core.h b/include/linphone/core.h index 9add3df87..3e06c01a0 100644 --- a/include/linphone/core.h +++ b/include/linphone/core.h @@ -186,6 +186,9 @@ typedef struct _LinphoneCoreVTable{ LinphoneCoreCbsCallCreatedCb call_created; LinphoneCoreCbsVersionUpdateCheckResultReceivedCb version_update_check_result_received; LinphoneCoreCbsChatRoomInstantiatedCb chat_room_instantiated; + LinphoneCoreCbsEcCalibrationResultCb ec_calibration_result; + LinphoneCoreCbsEcCalibrationAudioInitCb ec_calibration_audio_init; + LinphoneCoreCbsEcCalibrationAudioUninitCb ec_calibration_audio_uninit; void *user_data; /**