Commit 7fa19445 authored by Simon Morlat's avatar Simon Morlat
Browse files

improved test with new event queue

parent 359bb6e0
...@@ -49,6 +49,11 @@ if BUILD_WIN32 ...@@ -49,6 +49,11 @@ if BUILD_WIN32
liblinphone_la_LIBADD+=$(top_builddir)/oRTP/src/libortp.la liblinphone_la_LIBADD+=$(top_builddir)/oRTP/src/libortp.la
endif endif
noinst_PROGRAMS=test_lsd
test_lsd_SOURCES=test_lsd.c
test_lsd_LDADD=liblinphone.la
AM_CFLAGS=$(STRICT_OPTIONS) -DIN_LINPHONE \ AM_CFLAGS=$(STRICT_OPTIONS) -DIN_LINPHONE \
$(ORTP_CFLAGS) \ $(ORTP_CFLAGS) \
......
...@@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ...@@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "mediastreamer2/mediastream.h" #include "mediastreamer2/mediastream.h"
#include "mediastreamer2/msvolume.h" #include "mediastreamer2/msvolume.h"
#include "mediastreamer2/msequalizer.h" #include "mediastreamer2/msequalizer.h"
#include "mediastreamer2/mseventqueue.h"
#include <ortp/telephonyevents.h> #include <ortp/telephonyevents.h>
...@@ -631,6 +632,11 @@ static void sip_config_read(LinphoneCore *lc) ...@@ -631,6 +632,11 @@ static void sip_config_read(LinphoneCore *lc)
int port; int port;
int i,tmp; int i,tmp;
int ipv6; 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); port=lp_config_get_int(lc->config,"sip","use_info",0);
linphone_core_set_use_info_for_dtmf(lc,port); linphone_core_set_use_info_for_dtmf(lc,port);
...@@ -641,6 +647,7 @@ static void sip_config_read(LinphoneCore *lc) ...@@ -641,6 +647,7 @@ static void sip_config_read(LinphoneCore *lc)
if (ipv6==-1){ if (ipv6==-1){
ipv6=0; ipv6=0;
if (host_has_ipv6_network()){ if (host_has_ipv6_network()){
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")); 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"));
} }
} }
...@@ -1078,6 +1085,10 @@ static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vta ...@@ -1078,6 +1085,10 @@ static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vta
#endif #endif
ms_init(); 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); lc->config=lp_config_new(config_path);
if (factory_config_path) if (factory_config_path)
...@@ -1086,9 +1097,7 @@ static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vta ...@@ -1086,9 +1097,7 @@ static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vta
lc->sal=sal_init(); lc->sal=sal_init();
sal_set_user_pointer(lc->sal,lc); sal_set_user_pointer(lc->sal,lc);
sal_set_callbacks(lc->sal,&linphone_sal_callbacks); 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(); sip_setup_register_all();
sound_config_read(lc); sound_config_read(lc);
net_config_read(lc); net_config_read(lc);
...@@ -1101,6 +1110,7 @@ static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vta ...@@ -1101,6 +1110,7 @@ static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vta
lc->presence_mode=LINPHONE_STATUS_ONLINE; lc->presence_mode=LINPHONE_STATUS_ONLINE;
lc->max_call_logs=15; lc->max_call_logs=15;
ui_config_read(lc); ui_config_read(lc);
if (lc->vtable.display_status)
lc->vtable.display_status(lc,_("Ready")); lc->vtable.display_status(lc,_("Ready"));
gstate_new_state(lc, GSTATE_POWER_ON, NULL); gstate_new_state(lc, GSTATE_POWER_ON, NULL);
lc->auto_net_state_mon=lc->sip_conf.auto_net_state_mon; lc->auto_net_state_mon=lc->sip_conf.auto_net_state_mon;
...@@ -1667,6 +1677,7 @@ void linphone_core_iterate(LinphoneCore *lc){ ...@@ -1667,6 +1677,7 @@ void linphone_core_iterate(LinphoneCore *lc){
} }
sal_iterate(lc->sal); sal_iterate(lc->sal);
ms_event_queue_pump(lc->msevq);
if (lc->auto_net_state_mon) monitor_network_state(lc,curtime); if (lc->auto_net_state_mon) monitor_network_state(lc,curtime);
proxy_update(lc); proxy_update(lc);
...@@ -3593,6 +3604,7 @@ static void linphone_core_uninit(LinphoneCore *lc) ...@@ -3593,6 +3604,7 @@ static void linphone_core_uninit(LinphoneCore *lc)
lc->previewstream=NULL; lc->previewstream=NULL;
} }
#endif #endif
ms_event_queue_destroy(lc->msevq);
/* save all config */ /* save all config */
net_config_uninit(lc); net_config_uninit(lc);
sip_config_uninit(lc); sip_config_uninit(lc);
......
...@@ -33,11 +33,13 @@ typedef void (*LsdEndOfPlayCallback)(LsdPlayer *p); ...@@ -33,11 +33,13 @@ typedef void (*LsdEndOfPlayCallback)(LsdPlayer *p);
void lsd_player_set_callback(LsdPlayer *p, LsdEndOfPlayCallback cb); void lsd_player_set_callback(LsdPlayer *p, LsdEndOfPlayCallback cb);
void lsd_player_set_user_pointer(LsdPlayer *p, void *up); 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_play(LsdPlayer *p, const char *filename);
int lsd_player_stop(LsdPlayer *p); int lsd_player_stop(LsdPlayer *p);
void lsd_player_enable_loop(LsdPlayer *p, bool_t loopmode); 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); 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); LinphoneSoundDaemon * linphone_sound_daemon_new(const char *cardname);
LsdPlayer * linphone_sound_daemon_get_player(LinphoneSoundDaemon *lsd); LsdPlayer * linphone_sound_daemon_get_player(LinphoneSoundDaemon *lsd);
......
...@@ -45,6 +45,8 @@ struct _LsdPlayer{ ...@@ -45,6 +45,8 @@ struct _LsdPlayer{
LsdEndOfPlayCallback eop_cb; LsdEndOfPlayCallback eop_cb;
int mixer_pin; int mixer_pin;
void *user_data; void *user_data;
bool_t loop;
bool_t pad[3];
}; };
struct _LinphoneSoundDaemon { struct _LinphoneSoundDaemon {
...@@ -86,6 +88,7 @@ LsdPlayer *linphone_sound_daemon_get_player(LinphoneSoundDaemon *obj){ ...@@ -86,6 +88,7 @@ LsdPlayer *linphone_sound_daemon_get_player(LinphoneSoundDaemon *obj){
ms_filter_call_method(p,MS_PLAYER_GET_STATE,&state); ms_filter_call_method(p,MS_PLAYER_GET_STATE,&state);
if (state==MSPlayerClosed){ if (state==MSPlayerClosed){
lsd_player_set_gain(b,1); lsd_player_set_gain(b,1);
lsd_player_enable_loop (b,FALSE);
return b; return b;
} }
} }
...@@ -118,6 +121,7 @@ static void lsd_player_init(LsdPlayer *p, MSConnectionPoint mixer, MSFilterId pl ...@@ -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,p->chanadapter,0,0);
ms_connection_helper_link(&h,mixer.filter,mixer.pin,-1); ms_connection_helper_link(&h,mixer.filter,mixer.pin,-1);
p->mixer_pin=mixer.pin; p->mixer_pin=mixer.pin;
p->loop=FALSE;
p->lsd=lsd; p->lsd=lsd;
} }
...@@ -143,11 +147,14 @@ void lsd_player_set_user_pointer(LsdPlayer *p, void *up){ ...@@ -143,11 +147,14 @@ void lsd_player_set_user_pointer(LsdPlayer *p, void *up){
p->user_data=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; return p->user_data;
} }
static void lsd_player_on_eop(void * userdata, unsigned int id, void *arg){ 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 ){ int lsd_player_play(LsdPlayer *b, const char *filename ){
...@@ -161,6 +168,7 @@ 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){ if (ms_filter_call_method(b->player,MS_PLAYER_OPEN,(void*)filename)!=0){
ms_warning("Could not play %s",filename);
return -1; return -1;
} }
ms_filter_call_method(b->player,MS_FILTER_GET_SAMPLE_RATE,&rate); 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 ){ ...@@ -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_FILTER_SET_NCHANNELS,&chans);
ms_filter_call_method(b->chanadapter,MS_CHANNEL_ADAPTER_SET_OUTPUT_NCHANNELS,&lsd->out_nchans); 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; return 0;
} }
...@@ -180,9 +189,14 @@ void lsd_player_enable_loop(LsdPlayer *p, bool_t loopmode){ ...@@ -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){ if (ms_filter_get_id(p->player)==MS_FILE_PLAYER_ID){
int arg=loopmode ? 0 : -1; int arg=loopmode ? 0 : -1;
ms_filter_call_method(p->player,MS_FILE_PLAYER_LOOP,&arg); 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){ void lsd_player_set_gain(LsdPlayer *p, float gain){
MSAudioMixerCtl gainctl; MSAudioMixerCtl gainctl;
gainctl.pin=p->mixer_pin; gainctl.pin=p->mixer_pin;
...@@ -220,7 +234,7 @@ LinphoneSoundDaemon * linphone_sound_daemon_new(const char *cardname){ ...@@ -220,7 +234,7 @@ LinphoneSoundDaemon * linphone_sound_daemon_new(const char *cardname){
mp.filter=lsd->mixer; mp.filter=lsd->mixer;
mp.pin=0; 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){ for(i=1;i<MAX_BRANCHES;++i){
mp.pin=i; mp.pin=i;
lsd_player_init(&lsd->branches[i],mp,MS_FILE_PLAYER_ID,lsd); lsd_player_init(&lsd->branches[i],mp,MS_FILE_PLAYER_ID,lsd);
...@@ -246,6 +260,7 @@ void linphone_sound_daemon_destroy(LinphoneSoundDaemon *obj){ ...@@ -246,6 +260,7 @@ void linphone_sound_daemon_destroy(LinphoneSoundDaemon *obj){
mp.pin=i; mp.pin=i;
lsd_player_uninit (&obj->branches[i],mp); lsd_player_uninit (&obj->branches[i],mp);
} }
ms_filter_unlink(obj->mixer,0,obj->soundout,0);
ms_ticker_destroy(obj->ticker); ms_ticker_destroy(obj->ticker);
ms_filter_destroy(obj->soundout); ms_filter_destroy(obj->soundout);
ms_filter_destroy(obj->mixer); ms_filter_destroy(obj->mixer);
......
...@@ -371,6 +371,7 @@ struct _LinphoneCore ...@@ -371,6 +371,7 @@ struct _LinphoneCore
struct _AudioStream *audiostream; /**/ struct _AudioStream *audiostream; /**/
struct _VideoStream *videostream; struct _VideoStream *videostream;
struct _VideoStream *previewstream; struct _VideoStream *previewstream;
struct _MSEventQueue *msevq;
RtpTransport *a_rtp,*a_rtcp; RtpTransport *a_rtp,*a_rtcp;
MSList *bl_reqs; MSList *bl_reqs;
MSList *subscribers; /* unknown subscribers */ MSList *subscribers; /* unknown subscribers */
......
/*
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;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment