From 7fa19445c215e1146078e5dba8bc49bc942e35e9 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Sun, 30 May 2010 22:40:19 +0200 Subject: [PATCH] improved test with new event queue --- coreapi/Makefile.am | 5 ++ coreapi/linphonecore.c | 24 ++++++--- coreapi/linphonecore_utils.h | 4 +- coreapi/lsd.c | 19 ++++++- coreapi/private.h | 1 + coreapi/test_lsd.c | 102 +++++++++++++++++++++++++++++++++++ 6 files changed, 146 insertions(+), 9 deletions(-) create mode 100644 coreapi/test_lsd.c diff --git a/coreapi/Makefile.am b/coreapi/Makefile.am index 66a2bf5f..44f7532a 100644 --- a/coreapi/Makefile.am +++ b/coreapi/Makefile.am @@ -49,6 +49,11 @@ if BUILD_WIN32 liblinphone_la_LIBADD+=$(top_builddir)/oRTP/src/libortp.la endif +noinst_PROGRAMS=test_lsd + +test_lsd_SOURCES=test_lsd.c + +test_lsd_LDADD=liblinphone.la AM_CFLAGS=$(STRICT_OPTIONS) -DIN_LINPHONE \ $(ORTP_CFLAGS) \ diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index d6df2f81..822dc169 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "mediastreamer2/mediastream.h" #include "mediastreamer2/msvolume.h" #include "mediastreamer2/msequalizer.h" +#include "mediastreamer2/mseventqueue.h" #include @@ -631,6 +632,11 @@ static void sip_config_read(LinphoneCore *lc) int port; int i,tmp; int ipv6; + + if (lp_config_get_int(lc->config,"sip","use_session_timers",0)==1){ + sal_use_session_timers(lc->sal,200); + } + port=lp_config_get_int(lc->config,"sip","use_info",0); linphone_core_set_use_info_for_dtmf(lc,port); @@ -641,7 +647,8 @@ static void sip_config_read(LinphoneCore *lc) if (ipv6==-1){ ipv6=0; if (host_has_ipv6_network()){ - lc->vtable.display_message(lc,_("Your machine appears to be connected to an IPv6 network. By default linphone always uses IPv4. Please update your configuration if you want to use IPv6")); + if (lc->vtable.display_message) + lc->vtable.display_message(lc,_("Your machine appears to be connected to an IPv6 network. By default linphone always uses IPv4. Please update your configuration if you want to use IPv6")); } } linphone_core_enable_ipv6(lc,ipv6); @@ -1078,6 +1085,10 @@ static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vta #endif ms_init(); + /* create a mediastreamer2 event queue and set it as global */ + /* This allows to run event's callback in linphone_core_iterate() */ + lc->msevq=ms_event_queue_new(); + ms_set_global_event_queue(lc->msevq); lc->config=lp_config_new(config_path); if (factory_config_path) @@ -1086,9 +1097,7 @@ static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vta lc->sal=sal_init(); sal_set_user_pointer(lc->sal,lc); sal_set_callbacks(lc->sal,&linphone_sal_callbacks); - if (lp_config_get_int(lc->config,"sip","use_session_timers",0)==1){ - sal_use_session_timers(lc->sal,200); - } + sip_setup_register_all(); sound_config_read(lc); net_config_read(lc); @@ -1101,8 +1110,9 @@ static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vta lc->presence_mode=LINPHONE_STATUS_ONLINE; lc->max_call_logs=15; ui_config_read(lc); - lc->vtable.display_status(lc,_("Ready")); - gstate_new_state(lc, GSTATE_POWER_ON, NULL); + if (lc->vtable.display_status) + lc->vtable.display_status(lc,_("Ready")); + gstate_new_state(lc, GSTATE_POWER_ON, NULL); lc->auto_net_state_mon=lc->sip_conf.auto_net_state_mon; lc->ready=TRUE; @@ -1667,6 +1677,7 @@ void linphone_core_iterate(LinphoneCore *lc){ } sal_iterate(lc->sal); + ms_event_queue_pump(lc->msevq); if (lc->auto_net_state_mon) monitor_network_state(lc,curtime); proxy_update(lc); @@ -3593,6 +3604,7 @@ static void linphone_core_uninit(LinphoneCore *lc) lc->previewstream=NULL; } #endif + ms_event_queue_destroy(lc->msevq); /* save all config */ net_config_uninit(lc); sip_config_uninit(lc); diff --git a/coreapi/linphonecore_utils.h b/coreapi/linphonecore_utils.h index 0df37b80..43d6559b 100644 --- a/coreapi/linphonecore_utils.h +++ b/coreapi/linphonecore_utils.h @@ -33,11 +33,13 @@ typedef void (*LsdEndOfPlayCallback)(LsdPlayer *p); void lsd_player_set_callback(LsdPlayer *p, LsdEndOfPlayCallback cb); void lsd_player_set_user_pointer(LsdPlayer *p, void *up); -void *lsd_player_get_user_pointer(LsdPlayer *p); +void *lsd_player_get_user_pointer(const LsdPlayer *p); int lsd_player_play(LsdPlayer *p, const char *filename); int lsd_player_stop(LsdPlayer *p); void lsd_player_enable_loop(LsdPlayer *p, bool_t loopmode); +bool_t lsd_player_loop_enabled(const LsdPlayer *p); void lsd_player_set_gain(LsdPlayer *p, float gain); +LinphoneSoundDaemon lsd_player_get_daemon(const LsdPlayer *p); LinphoneSoundDaemon * linphone_sound_daemon_new(const char *cardname); LsdPlayer * linphone_sound_daemon_get_player(LinphoneSoundDaemon *lsd); diff --git a/coreapi/lsd.c b/coreapi/lsd.c index 0ed782fe..2dd9898a 100644 --- a/coreapi/lsd.c +++ b/coreapi/lsd.c @@ -45,6 +45,8 @@ struct _LsdPlayer{ LsdEndOfPlayCallback eop_cb; int mixer_pin; void *user_data; + bool_t loop; + bool_t pad[3]; }; struct _LinphoneSoundDaemon { @@ -86,6 +88,7 @@ LsdPlayer *linphone_sound_daemon_get_player(LinphoneSoundDaemon *obj){ ms_filter_call_method(p,MS_PLAYER_GET_STATE,&state); if (state==MSPlayerClosed){ lsd_player_set_gain(b,1); + lsd_player_enable_loop (b,FALSE); return b; } } @@ -118,6 +121,7 @@ static void lsd_player_init(LsdPlayer *p, MSConnectionPoint mixer, MSFilterId pl ms_connection_helper_link(&h,p->chanadapter,0,0); ms_connection_helper_link(&h,mixer.filter,mixer.pin,-1); p->mixer_pin=mixer.pin; + p->loop=FALSE; p->lsd=lsd; } @@ -143,11 +147,14 @@ void lsd_player_set_user_pointer(LsdPlayer *p, void *up){ p->user_data=up; } -void *lsd_player_get_user_pointer(LsdPlayer *p){ +void *lsd_player_get_user_pointer(const LsdPlayer *p){ return p->user_data; } static void lsd_player_on_eop(void * userdata, unsigned int id, void *arg){ + LsdPlayer *p=(LsdPlayer *)userdata; + if (p->eop_cb!=NULL) + p->eop_cb(p); } int lsd_player_play(LsdPlayer *b, const char *filename ){ @@ -161,6 +168,7 @@ int lsd_player_play(LsdPlayer *b, const char *filename ){ } if (ms_filter_call_method(b->player,MS_PLAYER_OPEN,(void*)filename)!=0){ + ms_warning("Could not play %s",filename); return -1; } ms_filter_call_method(b->player,MS_FILTER_GET_SAMPLE_RATE,&rate); @@ -173,6 +181,7 @@ int lsd_player_play(LsdPlayer *b, const char *filename ){ ms_filter_call_method(b->chanadapter,MS_FILTER_SET_NCHANNELS,&chans); ms_filter_call_method(b->chanadapter,MS_CHANNEL_ADAPTER_SET_OUTPUT_NCHANNELS,&lsd->out_nchans); + ms_filter_call_method_noarg (b->player,MS_PLAYER_START); return 0; } @@ -180,9 +189,14 @@ void lsd_player_enable_loop(LsdPlayer *p, bool_t loopmode){ if (ms_filter_get_id(p->player)==MS_FILE_PLAYER_ID){ int arg=loopmode ? 0 : -1; ms_filter_call_method(p->player,MS_FILE_PLAYER_LOOP,&arg); + p->loop=loopmode; } } +bool_t lsd_player_loop_enabled(const LsdPlayer *p){ + return p->loop; +} + void lsd_player_set_gain(LsdPlayer *p, float gain){ MSAudioMixerCtl gainctl; gainctl.pin=p->mixer_pin; @@ -220,7 +234,7 @@ LinphoneSoundDaemon * linphone_sound_daemon_new(const char *cardname){ mp.filter=lsd->mixer; mp.pin=0; - lsd_player_init(&lsd->branches[0],mp,MS_ITC_SINK_ID,lsd); + lsd_player_init(&lsd->branches[0],mp,MS_ITC_SOURCE_ID,lsd); for(i=1;ibranches[i],mp,MS_FILE_PLAYER_ID,lsd); @@ -246,6 +260,7 @@ void linphone_sound_daemon_destroy(LinphoneSoundDaemon *obj){ mp.pin=i; lsd_player_uninit (&obj->branches[i],mp); } + ms_filter_unlink(obj->mixer,0,obj->soundout,0); ms_ticker_destroy(obj->ticker); ms_filter_destroy(obj->soundout); ms_filter_destroy(obj->mixer); diff --git a/coreapi/private.h b/coreapi/private.h index 22286987..7a4c4205 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -371,6 +371,7 @@ struct _LinphoneCore struct _AudioStream *audiostream; /**/ struct _VideoStream *videostream; struct _VideoStream *previewstream; + struct _MSEventQueue *msevq; RtpTransport *a_rtp,*a_rtcp; MSList *bl_reqs; MSList *subscribers; /* unknown subscribers */ diff --git a/coreapi/test_lsd.c b/coreapi/test_lsd.c new file mode 100644 index 00000000..64b5d8a7 --- /dev/null +++ b/coreapi/test_lsd.c @@ -0,0 +1,102 @@ +/* +linphone +Copyright (C) 2010 Simon MORLAT (simon.morlat@linphone.org) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +/* Linphone Sound Daemon: is a lightweight utility to play sounds to speaker during a conversation. + This is useful for embedded platforms, where sound apis are not performant enough to allow + simultaneous sound access. + + This file is a test program that plays several sound files and places a call simultatenously. +*/ + +#include "linphonecore_utils.h" + +static void play_finished(LsdPlayer *p){ + const char *filename=(const char *)lsd_player_get_user_pointer (p); + ms_message("Playing of %s is finished.",filename); + if (!lsd_player_loop_enabled (p)){ + linphone_sound_daemon_release_player (lsd_player_get_daemon(p)); + } +} + +static void wait_a_bit(LinphoneCore *lc, int seconds){ + time_t orig=time(NULL); + while(time(NULL)-orig1){ + linphone_core_invite(lc,argv[1]); + wait_a_bit(lc,10); + linphone_core_terminate_call(lc,NULL); + } + + linphone_core_destroy(lc); + linphone_sound_daemon_destroy(lsd); + return 0; +} -- 2.39.2