1 /* $Id$ */
2 /*
3  * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (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 #ifndef __PJSUA_APP_COMMON_H__
20 #define __PJSUA_APP_COMMON_H__
21 
22 #include <pjsua-lib/pjsua.h>
23 
24 PJ_BEGIN_DECL
25 
26 #define current_acc	pjsua_acc_get_default()
27 
28 #define PJSUA_APP_NO_LIMIT_DURATION	(int)0x7FFFFFFF
29 #define PJSUA_APP_MAX_AVI		4
30 #define PJSUA_APP_NO_NB			-2
31 
32 typedef struct input_result
33 {
34     int	  nb_result;
35     char *uri_result;
36 } input_result;
37 
38 /* Call specific data */
39 typedef struct app_call_data
40 {
41     pj_timer_entry	    timer;
42     pj_bool_t		    ringback_on;
43     pj_bool_t		    ring_on;
44 } app_call_data;
45 
46 /* Video settings */
47 typedef struct app_vid
48 {
49     unsigned		    vid_cnt;
50     int			    vcapture_dev;
51     int			    vrender_dev;
52     pj_bool_t		    in_auto_show;
53     pj_bool_t		    out_auto_transmit;
54 } app_vid;
55 
56 /* Enumeration of CLI frontends */
57 typedef enum {
58     CLI_FE_CONSOLE	    = 1,
59     CLI_FE_TELNET	    = 2
60 } CLI_FE;
61 
62 /** CLI config **/
63 typedef struct cli_cfg_t
64 {
65     /** Bitmask of CLI_FE **/
66     int			    cli_fe;
67     pj_cli_cfg		    cfg;
68     pj_cli_telnet_cfg	    telnet_cfg;
69     pj_cli_console_cfg	    console_cfg;
70 } cli_cfg_t;
71 
72 /* Pjsua application data */
73 typedef struct pjsua_app_config
74 {
75     pjsua_config	    cfg;
76     pjsua_logging_config    log_cfg;
77     pjsua_media_config	    media_cfg;
78     pj_bool_t		    no_refersub;
79     pj_bool_t		    ipv6;
80     pj_bool_t		    enable_qos;
81     pj_bool_t		    no_tcp;
82     pj_bool_t		    no_udp;
83     pj_bool_t		    use_tls;
84     pjsua_transport_config  udp_cfg;
85     pjsua_transport_config  rtp_cfg;
86     pjsip_redirect_op	    redir_op;
87     int			    srtp_keying;
88 
89     unsigned		    acc_cnt;
90     pjsua_acc_config	    acc_cfg[PJSUA_MAX_ACC];
91 
92     unsigned		    buddy_cnt;
93     pjsua_buddy_config	    buddy_cfg[PJSUA_MAX_BUDDIES];
94 
95     app_call_data	    call_data[PJSUA_MAX_CALLS];
96 
97     pj_pool_t		   *pool;
98     /* Compatibility with older pjsua */
99 
100     unsigned		    codec_cnt;
101     pj_str_t		    codec_arg[32];
102     unsigned		    codec_dis_cnt;
103     pj_str_t                codec_dis[32];
104     pj_bool_t		    null_audio;
105     unsigned		    wav_count;
106     pj_str_t		    wav_files[32];
107     unsigned		    tone_count;
108     pjmedia_tone_desc	    tones[32];
109     pjsua_conf_port_id	    tone_slots[32];
110     pjsua_player_id	    wav_id;
111     pjsua_conf_port_id	    wav_port;
112     pj_bool_t		    auto_play;
113     pj_bool_t		    auto_play_hangup;
114     pj_timer_entry	    auto_hangup_timer;
115     pj_bool_t		    auto_loop;
116     pj_bool_t		    auto_conf;
117     pj_str_t		    rec_file;
118     pj_bool_t		    auto_rec;
119     pjsua_recorder_id	    rec_id;
120     pjsua_conf_port_id	    rec_port;
121     unsigned		    auto_answer;
122     unsigned		    duration;
123 
124 #ifdef STEREO_DEMO
125     pjmedia_snd_port	   *snd;
126     pjmedia_port	   *sc, *sc_ch1;
127     pjsua_conf_port_id	    sc_ch1_slot;
128 #endif
129 
130     float		    mic_level,
131 			    speaker_level;
132 
133     int			    capture_dev, playback_dev;
134     unsigned		    capture_lat, playback_lat;
135 
136     pj_bool_t		    no_tones;
137     int			    ringback_slot;
138     int			    ringback_cnt;
139     pjmedia_port	   *ringback_port;
140     int			    ring_slot;
141     int			    ring_cnt;
142     pjmedia_port	   *ring_port;
143 
144     app_vid		    vid;
145     unsigned		    aud_cnt;
146 
147     /* AVI to play */
148     unsigned                avi_cnt;
149     struct {
150 	pj_str_t		path;
151 	pjmedia_vid_dev_index	dev_id;
152 	pjsua_conf_port_id	slot;
153     } avi[PJSUA_APP_MAX_AVI];
154     pj_bool_t               avi_auto_play;
155     int			    avi_def_idx;
156 
157     /* CLI setting */
158     pj_bool_t		    use_cli;
159     cli_cfg_t		    cli_cfg;
160 } pjsua_app_config;
161 
162 /** Extern variable declaration **/
163 extern pjsua_call_id	    current_call;
164 extern pjsua_app_config	    app_config;
165 extern int		    stdout_refresh;
166 extern pj_bool_t	    stdout_refresh_quit;
167 extern pjsua_call_setting   call_opt;
168 extern pjsua_msg_data	    msg_data;
169 extern pj_bool_t	    app_running;
170 
171 int my_atoi(const char *cs);
172 int my_atoi2(const pj_str_t *s);
173 pj_bool_t find_next_call(void);
174 pj_bool_t find_prev_call(void);
175 void send_request(char *cstr_method, const pj_str_t *dst_uri);
176 void log_call_dump(int call_id);
177 int write_settings(pjsua_app_config *cfg, char *buf, pj_size_t max);
178 void app_config_init_video(pjsua_acc_config *acc_cfg);
179 void arrange_window(pjsua_vid_win_id wid);
180 
181 /** Defined in pjsua_app_config.c **/
182 /** This is to load the configuration **/
183 pj_status_t load_config(int argc, char **argv, pj_str_t *uri_arg);
184 
185 /** Pjsua app callback **/
186 /** This callback is called when CLI is started. **/
187 void cli_on_started(pj_status_t status);
188 
189 /** This callback is called when "shutdown"/"restart" command is invoked **/
190 void cli_on_stopped(pj_bool_t restart, int argc, char **argv);
191 
192 /** This callback is called when "quit"/"restart" command is invoked **/
193 void legacy_on_stopped(pj_bool_t restart);
194 
195 /** Pjsua cli method **/
196 pj_status_t cli_init(void);
197 pj_status_t cli_main(pj_bool_t wait_telnet_cli);
198 void cli_destroy(void);
199 void cli_get_info(char *info, pj_size_t size);
200 
201 /** Legacy method **/
202 void legacy_main(void);
203 
204 #if PJSUA_HAS_VIDEO
205 void vid_print_dev(int id, const pjmedia_vid_dev_info *vdi, const char *title);
206 void vid_list_devs(void);
207 void app_config_show_video(int acc_id, const pjsua_acc_config *acc_cfg);
208 #endif
209 
210 #ifdef HAVE_MULTIPART_TEST
211     /*
212     * Enable multipart in msg_data and add a dummy body into the
213     * multipart bodies.
214     */
215     void add_multipart(pjsua_msg_data *msg_data);
216 #  define TEST_MULTIPART(msg_data)	add_multipart(msg_data)
217 #else
218 #  define TEST_MULTIPART(msg_data)
219 #endif
220 
221 
222 PJ_END_DECL
223 
224 #endif	/* __PJSUA_APP_COMMON_H__ */
225 
226