From a7aab35b4ff560c454b5bf50761e98955301ca1d Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Tue, 18 Mar 2014 17:12:40 +0100 Subject: [PATCH] add function to override common telephony tones by wav files --- coreapi/linphonecall.c | 2 +- coreapi/linphonecore.c | 75 ++++++++++++++++++++++-------------------- coreapi/linphonecore.h | 20 +++++++++++ coreapi/misc.c | 27 +++++++++++++-- coreapi/private.h | 10 ++---- 5 files changed, 87 insertions(+), 47 deletions(-) diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index b9681978d..eee0e6305 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -2525,7 +2525,7 @@ static void linphone_core_disconnected(LinphoneCore *lc, LinphoneCall *call){ if (lc->vtable.display_warning!=NULL) lc->vtable.display_warning(lc,temp); linphone_core_terminate_call(lc,call); - linphone_core_play_named_tone(lc,LinphoneToneCallFailed); + linphone_core_play_named_tone(lc,LinphoneToneCallLost); } static void handle_ice_events(LinphoneCall *call, OrtpEvent *ev){ diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index d56c41709..396f20e51 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -610,7 +610,7 @@ static void sound_config_read(LinphoneCore *lc) /*just parse requested stream feature once at start to print out eventual errors*/ linphone_core_get_audio_features(lc); - _linphone_core_set_call_error_tone(lc,LinphoneReasonBusy,LinphoneToneBusy,NULL); + _linphone_core_set_tone(lc,LinphoneReasonBusy,LinphoneToneBusy,NULL); } static void certificates_config_read(LinphoneCore *lc) @@ -5441,41 +5441,46 @@ int linphone_core_play_local(LinphoneCore *lc, const char *audiofile){ void linphone_core_play_named_tone(LinphoneCore *lc, LinphoneToneID toneid){ if (linphone_core_tone_indications_enabled(lc)){ - MSFilter *f=get_dtmf_gen(lc); - MSDtmfGenCustomTone def; - if (f==NULL){ - ms_error("No dtmf generator at this time !"); - return; + const char *audiofile=linphone_core_get_tone_file(lc,toneid); + if (!audiofile){ + MSFilter *f=get_dtmf_gen(lc); + MSDtmfGenCustomTone def; + if (f==NULL){ + ms_error("No dtmf generator at this time !"); + return; + } + memset(&def,0,sizeof(def)); + def.amplitude=1; + /*these are french tones, excepted the failed one, which is USA congestion tone (does not exist in France)*/ + switch(toneid){ + case LinphoneToneCallOnHold: + case LinphoneToneCallWaiting: + def.duration=300; + def.frequencies[0]=440; + def.interval=2000; + break; + case LinphoneToneBusy: + def.duration=500; + def.frequencies[0]=440; + def.interval=500; + def.repeat_count=3; + break; + case LinphoneToneCallLost: + def.duration=250; + def.frequencies[0]=480; + def.frequencies[0]=620; + def.interval=250; + def.repeat_count=3; + + break; + default: + ms_warning("Unhandled tone id."); + } + if (def.duration>0) + ms_filter_call_method(f, MS_DTMF_GEN_PLAY_CUSTOM,&def); + }else{ + linphone_core_play_local(lc,audiofile); } - memset(&def,0,sizeof(def)); - def.amplitude=1; - /*these are french tones, excepted the failed one, which is USA congestion tone (does not exist in France)*/ - switch(toneid){ - case LinphoneToneCallOnHold: - case LinphoneToneCallWaiting: - def.duration=300; - def.frequencies[0]=440; - def.interval=2000; - break; - case LinphoneToneBusy: - def.duration=500; - def.frequencies[0]=440; - def.interval=500; - def.repeat_count=3; - break; - case LinphoneToneCallFailed: - def.duration=250; - def.frequencies[0]=480; - def.frequencies[0]=620; - def.interval=250; - def.repeat_count=3; - - break; - default: - ms_warning("Unhandled tone id."); - } - if (def.duration>0) - ms_filter_call_method(f, MS_DTMF_GEN_PLAY_CUSTOM,&def); } } diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 32a092176..76e036dd2 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -2328,7 +2328,27 @@ LINPHONE_PUBLIC bool_t linphone_core_is_provisioning_transient(LinphoneCore *lc) LINPHONE_PUBLIC int linphone_core_migrate_to_multi_transport(LinphoneCore *lc); + +/** + * Enum listing frequent telephony tones. +**/ +enum _LinphoneToneID{ + LinphoneToneUndefined, /**tones;elem!=NULL;elem=elem->next){ + LinphoneToneDescription *tone=(LinphoneToneDescription*)elem->data; + if (tone->toneid==id && tone->reason==LinphoneReasonNone && tone->audiofile!=NULL) return tone->audiofile; + } + return NULL; +} + +void _linphone_core_set_tone(LinphoneCore *lc, LinphoneReason reason, LinphoneToneID id, const char *audiofile){ LinphoneToneDescription *tone=linphone_core_get_call_error_tone(lc,reason); if (tone){ lc->tones=ms_list_remove(lc->tones,tone); @@ -1350,12 +1359,24 @@ void _linphone_core_set_call_error_tone(LinphoneCore *lc, LinphoneReason reason, } /** - * Assign an audio file to played locally upon call failure, for a given reason. + * Assign an audio file to be played locally upon call failure, for a given reason. * @param lc the core * @param reason the #LinphoneReason representing the failure error code. * @param audiofile a wav file to be played when such call failure happens. * @ingroup misc **/ void linphone_core_set_call_error_tone(LinphoneCore *lc, LinphoneReason reason, const char *audiofile){ - _linphone_core_set_call_error_tone(lc,reason,LinphoneToneUndefined, audiofile); + _linphone_core_set_tone(lc,reason,LinphoneToneUndefined, audiofile); } + +/** + * Assign an audio file to be played as a specific tone id. + * This function typically allows to customize telephony tones per country. + * @param lc the core + * @param id the tone id + * @param audiofile a wav file to be played. +**/ +void linphone_core_set_tone(LinphoneCore *lc, LinphoneToneID id, const char *audiofile){ + _linphone_core_set_tone(lc, LinphoneReasonNone, id, audiofile); +} + diff --git a/coreapi/private.h b/coreapi/private.h index f0ddaaeaa..5e297658b 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -586,13 +586,6 @@ struct _LinphoneConference{ bool_t local_muted; }; -typedef enum _LinphoneToneID{ - LinphoneToneUndefined, - LinphoneToneBusy, - LinphoneToneCallWaiting, - LinphoneToneCallOnHold, - LinphoneToneCallFailed -}LinphoneToneID; typedef struct _LinphoneToneDescription{ LinphoneReason reason; @@ -604,7 +597,8 @@ LinphoneToneDescription * linphone_tone_description_new(LinphoneReason reason, L void linphone_tone_description_destroy(LinphoneToneDescription *obj); LinphoneToneDescription *linphone_core_get_call_error_tone(const LinphoneCore *lc, LinphoneReason reason); void linphone_core_play_call_error_tone(LinphoneCore *lc, LinphoneReason reason); -void _linphone_core_set_call_error_tone(LinphoneCore *lc, LinphoneReason reason, LinphoneToneID id, const char *audiofile); +void _linphone_core_set_tone(LinphoneCore *lc, LinphoneReason reason, LinphoneToneID id, const char *audiofile); +const char *linphone_core_get_tone_file(const LinphoneCore *lc, LinphoneToneID id); typedef struct _LinphoneConference LinphoneConference;