diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index 3ab82d28a..2b3db0775 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -1662,6 +1662,19 @@ static void parametrize_equalizer(LinphoneCore *lc, AudioStream *st){ } } +void set_mic_gain_db(AudioStream *st, float gain){ + if (st->volsend){ + ms_filter_call_method(st->volsend,MS_VOLUME_SET_DB_GAIN,&gain); + }else ms_warning("Could not apply mic gain: gain control wasn't activated."); +} + +void set_playback_gain_db(AudioStream *st, float gain){ + if (st->volrecv){ + ms_filter_call_method(st->volrecv,MS_VOLUME_SET_DB_GAIN,&gain); + }else ms_warning("Could not apply playback gain: gain control wasn't activated."); +} + +/*This function is not static because used internally in linphone-daemon project*/ void _post_configure_audio_stream(AudioStream *st, LinphoneCore *lc, bool_t muted){ float mic_gain=lc->sound_conf.soft_mic_lev; float thres = 0; @@ -1678,13 +1691,13 @@ void _post_configure_audio_stream(AudioStream *st, LinphoneCore *lc, bool_t mute int spk_agc; if (!muted) - linphone_core_set_mic_gain_db (lc, mic_gain); + set_mic_gain_db(st,mic_gain); else audio_stream_set_mic_gain(st,0); recv_gain = lc->sound_conf.soft_play_lev; if (recv_gain != 0) { - linphone_core_set_playback_gain_db (lc,recv_gain); + set_playback_gain_db(st,recv_gain); } if (st->volsend){ @@ -1720,10 +1733,10 @@ void _post_configure_audio_stream(AudioStream *st, LinphoneCore *lc, bool_t mute parametrize_equalizer(lc,st); } -static void post_configure_audio_streams(LinphoneCall*call){ +static void post_configure_audio_streams(LinphoneCall *call, bool_t muted){ AudioStream *st=call->audiostream; LinphoneCore *lc=call->core; - _post_configure_audio_stream(st,lc,call->audio_muted); + _post_configure_audio_stream(st,lc,muted); if (linphone_core_dtmf_received_has_listener(lc)){ audio_stream_play_received_dtmfs(call->audiostream,FALSE); } @@ -1996,10 +2009,7 @@ static void linphone_call_start_audio_stream(LinphoneCall *call, const char *cna captcard, use_ec ); - post_configure_audio_streams(call); - if (muted && !send_ringbacktone){ - audio_stream_set_mic_gain(call->audiostream,0); - } + post_configure_audio_streams(call, muted && !send_ringbacktone); if (stream->dir==SalStreamSendOnly && playfile!=NULL){ int pause_time=500; ms_filter_call_method(call->audiostream->soundread,MS_FILE_PLAYER_LOOP,&pause_time); diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index e1b289275..503ab479b 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -3778,9 +3778,7 @@ void linphone_core_set_mic_gain_db (LinphoneCore *lc, float gaindb){ ms_message("linphone_core_set_mic_gain_db(): no active call."); return; } - if (st->volsend){ - ms_filter_call_method(st->volsend,MS_VOLUME_SET_DB_GAIN,&gain); - }else ms_warning("Could not apply gain: gain control wasn't activated."); + set_mic_gain_db(st,gain); } /** @@ -3811,9 +3809,7 @@ void linphone_core_set_playback_gain_db (LinphoneCore *lc, float gaindb){ ms_message("linphone_core_set_playback_gain_db(): no active call."); return; } - if (st->volrecv){ - ms_filter_call_method(st->volrecv,MS_VOLUME_SET_DB_GAIN,&gain); - }else ms_warning("Could not apply gain: gain control wasn't activated."); + set_playback_gain_db(st,gain); } /** diff --git a/coreapi/player.c b/coreapi/player.c index df1641886..709cd25bd 100644 --- a/coreapi/player.c +++ b/coreapi/player.c @@ -31,7 +31,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. int linphone_player_open(LinphonePlayer *obj, const char *filename, LinphonePlayerEofCallback cb, void *user_data){ obj->user_data=user_data; obj->cb=cb; - return obj->open(obj->impl,filename); + return obj->open(obj,filename); } /** @@ -40,7 +40,7 @@ int linphone_player_open(LinphonePlayer *obj, const char *filename, LinphonePlay * @return 0 if successful, -1 otherwise **/ int linphone_player_start(LinphonePlayer *obj){ - return obj->start(obj->impl); + return obj->start(obj); } /** @@ -49,7 +49,7 @@ int linphone_player_start(LinphonePlayer *obj){ * @return 0 if successful, -1 otherwise **/ int linphone_player_pause(LinphonePlayer *obj){ - return obj->pause(obj->impl); + return obj->pause(obj); } /** @@ -59,7 +59,7 @@ int linphone_player_pause(LinphonePlayer *obj){ * @return 0 if successful, -1 otherwise **/ int linphone_player_seek(LinphonePlayer *obj, int time_ms){ - return obj->seek(obj->impl,time_ms); + return obj->seek(obj,time_ms); } /** @@ -68,7 +68,7 @@ int linphone_player_seek(LinphonePlayer *obj, int time_ms){ * @return the state of the player within MSPlayerClosed, MSPlayerStarted, MSPlayerPaused. **/ MSPlayerState linphone_player_get_state(LinphonePlayer *obj){ - return obj->get_state(obj->impl); + return obj->get_state(obj); } /** @@ -76,7 +76,7 @@ MSPlayerState linphone_player_get_state(LinphonePlayer *obj){ * @param obj the player. **/ void linphone_player_close(LinphonePlayer *obj){ - return obj->close(obj->impl); + return obj->close(obj); } @@ -104,7 +104,7 @@ static bool_t call_player_check_state(LinphonePlayer *player, bool_t check_playe static void on_eof(void *user_data, MSFilter *f, unsigned int event_id, void *arg){ LinphonePlayer *player=(LinphonePlayer *)user_data; - if (player->cb) player->cb(player,user_data); + if (player->cb) player->cb(player,player->user_data); } static int call_player_open(LinphonePlayer* player, const char *filename){ diff --git a/coreapi/private.h b/coreapi/private.h index c1c5a31ad..795dfb60f 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -1020,7 +1020,8 @@ void linphone_core_notify_notify_received(LinphoneCore *lc, LinphoneEvent *lev, void linphone_core_notify_subscription_state_changed(LinphoneCore *lc, LinphoneEvent *lev, LinphoneSubscriptionState state); void linphone_core_notify_publish_state_changed(LinphoneCore *lc, LinphoneEvent *lev, LinphonePublishState state); - +void set_mic_gain_db(AudioStream *st, float gain); +void set_playback_gain_db(AudioStream *st, float gain); #ifdef __cplusplus } diff --git a/mediastreamer2 b/mediastreamer2 index 21e35e89f..baf0fb51d 160000 --- a/mediastreamer2 +++ b/mediastreamer2 @@ -1 +1 @@ -Subproject commit 21e35e89ffa8920bb0b5865d365b84471ecfa321 +Subproject commit baf0fb51df2149f4672c09a504d95b994f06c153 diff --git a/tester/call_tester.c b/tester/call_tester.c index 35b4c2bdd..680144803 100644 --- a/tester/call_tester.c +++ b/tester/call_tester.c @@ -25,10 +25,16 @@ #include "lpconfig.h" #include "private.h" #include "liblinphone_tester.h" +#include "mediastreamer2/dsptools.h" + +#ifdef WIN32 +#define unlink _unlink +#endif static void srtp_call(void); static void call_base(LinphoneMediaEncryption mode, bool_t enable_video,bool_t enable_relay,LinphoneFirewallPolicy policy); static void disable_all_audio_codecs_except_one(LinphoneCore *lc, const char *mime, int rate); +static char *create_filepath(const char *dir, const char *filename, const char *ext); // prototype definition for call_recording() #ifdef ANDROID @@ -1878,6 +1884,53 @@ static void call_with_declined_srtp(void) { linphone_core_manager_destroy(pauline); } +static void on_eof(LinphonePlayer *player, void *user_data){ + LinphoneCoreManager *marie=(LinphoneCoreManager*)user_data; + marie->stat.number_of_player_eof++; +} + +static void call_with_file_player(void) { + LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); + LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc"); + LinphonePlayer *player; + char hellopath[256]; + char *recordpath = create_filepath(liblinphone_tester_writable_dir_prefix, "record", "wav"); + float similar; + + /*make sure the record file doesn't already exists, otherwise this test will append new samples to it*/ + unlink(recordpath); + + snprintf(hellopath,sizeof(hellopath), "%s/sounds/hello8000.wav", liblinphone_tester_file_prefix); + + /*caller uses soundcard*/ + + /*callee is recording and plays file*/ + linphone_core_use_files(pauline->lc,TRUE); + linphone_core_set_play_file(pauline->lc,hellopath); + linphone_core_set_record_file(pauline->lc,recordpath); + + CU_ASSERT_TRUE(call(marie,pauline)); + + player=linphone_call_get_player(linphone_core_get_current_call(marie->lc)); + CU_ASSERT_PTR_NOT_NULL(player); + if (player){ + CU_ASSERT_TRUE(linphone_player_open(player,hellopath,on_eof,marie)==0); + CU_ASSERT_TRUE(linphone_player_start(player)==0); + } + CU_ASSERT_TRUE(wait_for_until(pauline->lc,marie->lc,&marie->stat.number_of_player_eof,1,12000)); + + /*just to sleep*/ + linphone_core_terminate_all_calls(marie->lc); + CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallEnd,1)); + CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1)); + CU_ASSERT_TRUE(ms_audio_diff(hellopath,recordpath,&similar,NULL,NULL)==0); + CU_ASSERT_TRUE(similar>0.9); + CU_ASSERT_TRUE(similar<=1.0); + linphone_core_manager_destroy(marie); + linphone_core_manager_destroy(pauline); + ms_free(recordpath); +} + static void call_base(LinphoneMediaEncryption mode, bool_t enable_video,bool_t enable_relay,LinphoneFirewallPolicy policy) { LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc"); @@ -2808,13 +2861,7 @@ static void savpf_to_savpf_call(void) { } static char *create_filepath(const char *dir, const char *filename, const char *ext) { - char *filepath = ms_new0(char, strlen(dir) + strlen(filename) + strlen(ext) + 3); - strcpy(filepath, dir); - strcat(filepath, "/"); - strcat(filepath, filename); - strcat(filepath, "."); - strcat(filepath, ext); - return filepath; + return ms_strdup_printf("%s/%s.%s",dir,filename,ext); } static void record_call(const char *filename, bool_t enableVideo) { @@ -3015,6 +3062,7 @@ test_t call_tests[] = { { "ZRTP call",zrtp_call}, { "ZRTP video call",zrtp_video_call}, { "SRTP call with declined srtp", call_with_declined_srtp }, + { "Call with file player", call_with_file_player}, #ifdef VIDEO_ENABLED { "Simple video call",video_call}, { "Simple video call using policy",video_call_using_policy}, diff --git a/tester/liblinphone_tester.h b/tester/liblinphone_tester.h index 67b68f87c..ef736a31f 100644 --- a/tester/liblinphone_tester.h +++ b/tester/liblinphone_tester.h @@ -195,6 +195,7 @@ typedef struct _stats { int number_of_LinphoneCallEncryptedOff; int number_of_NetworkReachableTrue; int number_of_NetworkReachableFalse; + int number_of_player_eof; LinphoneChatMessage* last_received_chat_message; }stats;