diff --git a/linphone/coreapi/linphonecore.c b/linphone/coreapi/linphonecore.c index 4adf160dc..655cb7fb0 100644 --- a/linphone/coreapi/linphonecore.c +++ b/linphone/coreapi/linphonecore.c @@ -1417,11 +1417,16 @@ int linphone_core_change_qos(LinphoneCore *lc, int answer) void linphone_core_init_media_streams(LinphoneCore *lc){ lc->audiostream=audio_stream_new(linphone_core_get_audio_port(lc),linphone_core_ipv6_enabled(lc)); if (linphone_core_echo_limiter_enabled(lc)){ - const char * type=lp_config_get_string(lc->config,"sound","el_type","mic"); + const char *type=lp_config_get_string(lc->config,"sound","el_type","mic"); + float gain=lp_config_get_float(lc->config,"sound","mic_gain",-1); if (strcasecmp(type,"mic")==0) audio_stream_enable_echo_limiter(lc->audiostream,ELControlMic); else if (strcasecmp(type,"speaker")==0) audio_stream_enable_echo_limiter(lc->audiostream,ELControlSpeaker); + if (gain>0){ + audio_stream_enable_gain_control(lc->audiostream,TRUE); + } + } #ifdef VIDEO_ENABLED if (lc->video_conf.display || lc->video_conf.capture) @@ -1443,6 +1448,7 @@ static void post_configure_audio_streams(LinphoneCore *lc){ float speed=lp_config_get_float(lc->config,"sound","el_speed",-1); float thres=lp_config_get_float(lc->config,"sound","el_thres",-1); float force=lp_config_get_float(lc->config,"sound","el_force",-1); + float gain=lp_config_get_float(lc->config,"sound","mic_gain",-1); MSFilter *f=NULL; if (st->el_type==ELControlMic){ f=st->volsend; @@ -1463,6 +1469,8 @@ static void post_configure_audio_streams(LinphoneCore *lc){ ms_filter_call_method(f,MS_VOLUME_SET_EA_THRESHOLD,&thres); if (force!=-1) ms_filter_call_method(f,MS_VOLUME_SET_EA_FORCE,&force); + if (gain!=-1) + ms_filter_call_method(st->volsend,MS_VOLUME_SET_GAIN,&gain); } if (lc->vtable.dtmf_received!=NULL){ /* replace by our default action*/ diff --git a/linphone/mediastreamer2/include/mediastreamer2/mediastream.h b/linphone/mediastreamer2/include/mediastreamer2/mediastream.h index 63e7fb838..e41f939da 100644 --- a/linphone/mediastreamer2/include/mediastreamer2/mediastream.h +++ b/linphone/mediastreamer2/include/mediastreamer2/mediastream.h @@ -52,6 +52,7 @@ struct _AudioStream time_t last_packet_time; EchoLimiterType el_type; /*use echo limiter: two MSVolume, measured input level controlling local output level*/ bool_t play_dtmfs; + bool_t use_gc; }; #ifdef __cplusplus @@ -101,7 +102,12 @@ bool_t audio_stream_alive(AudioStream * stream, int timeout); /*enable echo-limiter dispositve: one MSVolume in input branch controls a MSVolume in the output branch*/ void audio_stream_enable_echo_limiter(AudioStream *stream, EchoLimiterType type); -/* stop the above process*/ +/*enable gain control, to be done before start() */ +void audio_stream_enable_gain_control(AudioStream *stream, bool_t val); + +void audio_stream_set_mic_gain(AudioStream *stream, float gain); + +/* stop the audio streaming thread and free everything*/ void audio_stream_stop (AudioStream * stream); RingStream *ring_start (const char * file, int interval, MSSndCard *sndcard); diff --git a/linphone/mediastreamer2/src/audiostream.c b/linphone/mediastreamer2/src/audiostream.c index 4cc28d544..bb0edda7c 100644 --- a/linphone/mediastreamer2/src/audiostream.c +++ b/linphone/mediastreamer2/src/audiostream.c @@ -247,12 +247,14 @@ int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char ms_filter_call_method(stream->ec,MS_FILTER_SET_SAMPLE_RATE,&pt->clock_rate); } - if (stream->el_type!=ELInactive){ + if (stream->el_type!=ELInactive || stream->use_gc){ stream->volsend=ms_filter_new(MS_VOLUME_ID); stream->volrecv=ms_filter_new(MS_VOLUME_ID); - if (stream->el_type==ELControlSpeaker) - ms_filter_call_method(stream->volrecv,MS_VOLUME_SET_PEER,stream->volsend); - else ms_filter_call_method(stream->volsend,MS_VOLUME_SET_PEER,stream->volrecv); + if (stream->el_type!=ELInactive){ + if (stream->el_type==ELControlSpeaker) + ms_filter_call_method(stream->volrecv,MS_VOLUME_SET_PEER,stream->volsend); + else ms_filter_call_method(stream->volsend,MS_VOLUME_SET_PEER,stream->volrecv); + } } /* give the sound filters some properties */ @@ -379,6 +381,7 @@ AudioStream *audio_stream_new(int locport, bool_t ipv6){ stream->session=create_duplex_rtpsession(locport,ipv6); stream->rtpsend=ms_filter_new(MS_RTP_SEND_ID); stream->play_dtmfs=TRUE; + stream->use_gc=FALSE; return stream; } @@ -399,6 +402,17 @@ void audio_stream_enable_echo_limiter(AudioStream *stream, EchoLimiterType type) stream->el_type=type; } +void audio_stream_enable_gain_control(AudioStream *stream, bool_t val){ + stream->use_gc=val; +} + +void audio_stream_set_mic_gain(AudioStream *stream, float gain){ + if (stream->volsend){ + ms_filter_call_method(stream->volsend,MS_VOLUME_SET_GAIN,&gain); + }else ms_warning("Could not apply gain: gain control wasn't activated. " + "Use audio_stream_enable_gain_control() before starting the stream."); +} + void audio_stream_stop(AudioStream * stream) { if (stream->ticker){