]> sjero.net Git - linphone/blob - coreapi/test_lsd.c
Aac-eld add missing header according to RFC3640 3.3.6
[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
30 static void play_finished(LsdPlayer *p){
31         const char *filename=(const char *)lsd_player_get_user_pointer (p);
32         ms_message("Playing of %s is finished.",filename);
33         if (!lsd_player_loop_enabled (p)){
34                 linphone_sound_daemon_release_player (lsd_player_get_daemon(p),p);
35         }
36 }
37
38 static void wait_a_bit(LinphoneCore *lc, int seconds){
39         time_t orig=ms_time(NULL);
40         while(ms_time(NULL)-orig<seconds){
41                 /* we need to call iterate to receive notifications */
42                 linphone_core_iterate(lc);
43                 ms_usleep (50000);
44         }
45 }
46
47 int main(int argc, char *argv[]){
48         LinphoneCore *lc;
49         LinphoneCoreVTable vtable={0};
50         LinphoneSoundDaemon *lsd;
51         LsdPlayer *p;
52
53         linphone_core_enable_logs(stdout);
54         lc=linphone_core_new(&vtable,NULL,NULL,NULL);
55         lsd=linphone_sound_daemon_new (NULL,44100,1);
56
57         linphone_core_use_sound_daemon(lc,lsd);
58
59         /* start a play */
60         p=linphone_sound_daemon_get_player(lsd);
61         lsd_player_set_callback (p,play_finished);
62         lsd_player_set_user_pointer (p,"share/hello8000.wav");
63         lsd_player_play (p,"share/hello8000.wav");
64         wait_a_bit (lc,2);
65
66         /*start another one */
67         p=linphone_sound_daemon_get_player(lsd);
68         lsd_player_set_callback (p,play_finished);
69         lsd_player_set_user_pointer (p,"share/hello16000.wav");
70         lsd_player_enable_loop (p,TRUE);
71         lsd_player_play (p,"share/hello16000.wav");
72
73         /* after a few seconds decrease the volume */
74         wait_a_bit (lc,3);
75         lsd_player_set_gain (p,0.3);
76         wait_a_bit(lc,5);
77
78         /*now play some stereo music*/
79         p=linphone_sound_daemon_get_player(lsd);
80         lsd_player_set_callback (p,play_finished);
81         lsd_player_set_user_pointer (p,"share/rings/rock.wav");
82         lsd_player_play(p,"share/rings/rock.wav");
83         wait_a_bit(lc,2);
84
85         /*now play some stereo music at 22khz in order to test
86          stereo resampling */
87         p=linphone_sound_daemon_get_player(lsd);
88         lsd_player_set_callback (p,play_finished);
89         lsd_player_set_user_pointer (p,"share/rings/bigben.wav");
90         lsd_player_play(p,"share/rings/bigben.wav");
91         wait_a_bit(lc,6);
92
93         /* now place an outgoing call if sip address argument is given */
94         if (argc>1){
95                 linphone_core_invite(lc,argv[1]);
96                 wait_a_bit(lc,10);
97                 linphone_core_terminate_call(lc,NULL);
98         }
99         linphone_core_use_sound_daemon(lc,NULL);
100         linphone_sound_daemon_destroy(lsd);
101         linphone_core_destroy(lc);
102         
103         return 0;
104 }