]> sjero.net Git - linphone/commitdiff
improved test with new event queue
authorSimon Morlat <simon.morlat@linphone.org>
Sun, 30 May 2010 20:40:19 +0000 (22:40 +0200)
committerSimon Morlat <simon.morlat@linphone.org>
Sun, 30 May 2010 20:40:19 +0000 (22:40 +0200)
coreapi/Makefile.am
coreapi/linphonecore.c
coreapi/linphonecore_utils.h
coreapi/lsd.c
coreapi/private.h
coreapi/test_lsd.c [new file with mode: 0644]

index 66a2bf5f6a9a6b2365d64730859d110e6656e13a..44f7532a85af7047df108bd7d83915f946c19038 100644 (file)
@@ -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) \
index d6df2f81a1e275134351bc9977dd50d7305bdc83..822dc169a6a33c8a43a415129778c6c1b772b20d 100644 (file)
@@ -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 <ortp/telephonyevents.h>
 
@@ -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);
index 0df37b800642ebe0f55e3dabea6ef90e41f39a40..43d6559bd650fddcd5b42c45f9b4f1e387c6c93e 100644 (file)
@@ -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);
index 0ed782fe27feed7d05c91282d03d1c8e107ba751..2dd9898a5d6d1fe13de2791fbd5c3df5dc95912b 100644 (file)
@@ -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;i<MAX_BRANCHES;++i){
                mp.pin=i;
                lsd_player_init(&lsd->branches[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);
index 22286987ecbfbf5cb67b891936af8968eff4e498..7a4c420520e0fa7491bac485bdf55d6bdbd3fb37 100644 (file)
@@ -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 (file)
index 0000000..64b5d8a
--- /dev/null
@@ -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)-orig<seconds){
+               /* we need to call iterate to receive notifications */
+               linphone_core_iterate(lc);
+               ms_usleep (50000);
+       }
+}
+
+int main(int argc, char *argv[]){
+       LinphoneCore *lc;
+       LinphoneCoreVTable vtable={0};
+       LinphoneSoundDaemon *lsd;
+       LsdPlayer *p;
+
+       linphone_core_enable_logs(stdout);
+       lc=linphone_core_new(&vtable,NULL,NULL,NULL);
+       lsd=linphone_sound_daemon_new (NULL);
+
+       linphone_core_use_sound_daemon(lc,lsd);
+
+       /* start a play */
+       p=linphone_sound_daemon_get_player(lsd);
+       lsd_player_set_callback (p,play_finished);
+       lsd_player_set_user_pointer (p,"share/hello8000.wav");
+       lsd_player_play (p,"share/hello8000.wav");
+       wait_a_bit (lc,2);
+
+       /*start another one */
+       p=linphone_sound_daemon_get_player(lsd);
+       lsd_player_set_callback (p,play_finished);
+       lsd_player_set_user_pointer (p,"share/hello16000.wav");
+       lsd_player_enable_loop (p,TRUE);
+       lsd_player_play (p,"share/hello16000.wav");
+
+       /* after a few seconds decrease the volume */
+       wait_a_bit (lc,3);
+       lsd_player_set_gain (p,0.3);
+       wait_a_bit(lc,5);
+
+       /*now play some stereo music*/
+       p=linphone_sound_daemon_get_player(lsd);
+       lsd_player_set_callback (p,play_finished);
+       lsd_player_set_user_pointer (p,"share/rings/rock.wav");
+       lsd_player_play(p,"share/rings/rock.wav");
+       wait_a_bit(lc,2);
+
+       /*now play some stereo music at 22khz in order to test
+        stereo resampling */
+       p=linphone_sound_daemon_get_player(lsd);
+       lsd_player_set_callback (p,play_finished);
+       lsd_player_set_user_pointer (p,"share/rings/bigben.wav");
+       lsd_player_play(p,"share/rings/bigben.wav");
+       wait_a_bit(lc,6);
+
+       /* now place an outgoing call if sip address argument is given */
+       if (argc>1){
+               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;
+}