]> sjero.net Git - linphone/blob - coreapi/test_lsd.c
Merge branch 'dev_multicall'
[linphone] / coreapi / test_lsd.c
1 /*
2 linphone
3 Copyright (C) 2010 Simon MORLAT (simon.morlat@linphone.org)
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 */
19
20 /* Linphone Sound Daemon: is a lightweight utility to play sounds to speaker during a conversation.
21  This is useful for embedded platforms, where sound apis are not performant enough to allow
22  simultaneous sound access.
23
24  This file is a test program that plays several sound files and places a call simultatenously.
25 */
26
27 #include "linphonecore_utils.h"
28
29 static void play_finished(LsdPlayer *p){
30         const char *filename=(const char *)lsd_player_get_user_pointer (p);
31         ms_message("Playing of %s is finished.",filename);
32         if (!lsd_player_loop_enabled (p)){
33                 linphone_sound_daemon_release_player (lsd_player_get_daemon(p),p);
34         }
35 }
36
37 static void wait_a_bit(LinphoneCore *lc, int seconds){
38         time_t orig=time(NULL);
39         while(time(NULL)-orig<seconds){
40                 /* we need to call iterate to receive notifications */
41                 linphone_core_iterate(lc);
42                 ms_usleep (50000);
43         }
44 }
45
46 int main(int argc, char *argv[]){
47         LinphoneCore *lc;
48         LinphoneCoreVTable vtable={0};
49         LinphoneSoundDaemon *lsd;
50         LsdPlayer *p;
51
52         linphone_core_enable_logs(stdout);
53         lc=linphone_core_new(&vtable,NULL,NULL,NULL);
54         lsd=linphone_sound_daemon_new (NULL,44100,1);
55
56         linphone_core_use_sound_daemon(lc,lsd);
57
58         /* start a play */
59         p=linphone_sound_daemon_get_player(lsd);
60         lsd_player_set_callback (p,play_finished);
61         lsd_player_set_user_pointer (p,"share/hello8000.wav");
62         lsd_player_play (p,"share/hello8000.wav");
63         wait_a_bit (lc,2);
64
65         /*start another one */
66         p=linphone_sound_daemon_get_player(lsd);
67         lsd_player_set_callback (p,play_finished);
68         lsd_player_set_user_pointer (p,"share/hello16000.wav");
69         lsd_player_enable_loop (p,TRUE);
70         lsd_player_play (p,"share/hello16000.wav");
71
72         /* after a few seconds decrease the volume */
73         wait_a_bit (lc,3);
74         lsd_player_set_gain (p,0.3);
75         wait_a_bit(lc,5);
76
77         /*now play some stereo music*/
78         p=linphone_sound_daemon_get_player(lsd);
79         lsd_player_set_callback (p,play_finished);
80         lsd_player_set_user_pointer (p,"share/rings/rock.wav");
81         lsd_player_play(p,"share/rings/rock.wav");
82         wait_a_bit(lc,2);
83
84         /*now play some stereo music at 22khz in order to test
85          stereo resampling */
86         p=linphone_sound_daemon_get_player(lsd);
87         lsd_player_set_callback (p,play_finished);
88         lsd_player_set_user_pointer (p,"share/rings/bigben.wav");
89         lsd_player_play(p,"share/rings/bigben.wav");
90         wait_a_bit(lc,6);
91
92         /* now place an outgoing call if sip address argument is given */
93         if (argc>1){
94                 linphone_core_invite(lc,argv[1]);
95                 wait_a_bit(lc,10);
96                 linphone_core_terminate_call(lc,NULL);
97         }
98         linphone_core_use_sound_daemon(lc,NULL);
99         linphone_sound_daemon_destroy(lsd);
100         linphone_core_destroy(lc);
101         
102         return 0;
103 }