blob: 5f920432880d0b1616d1232a21077fda28f42d8e [file] [log] [blame]
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001/* $Id$ */
2/*
Benny Prijono844653c2008-12-23 17:27:53 +00003 * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
Benny Prijono32177c02008-06-20 22:44:47 +00004 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
Benny Prijonoeebe9af2006-06-13 22:57:13 +00005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20#ifndef __PJSUA_INTERNAL_H__
21#define __PJSUA_INTERNAL_H__
22
23/**
24 * This is the private header used by pjsua library implementation.
25 * Applications should not include this file.
26 */
27
28PJ_BEGIN_DECL
29
30/**
Benny Prijono224b4e22008-06-19 14:10:28 +000031 * Media transport state.
32 */
33typedef enum pjsua_med_tp_st
34{
35 /** Not initialized */
36 PJSUA_MED_TP_IDLE,
37
38 /** Initialized (media_create() has been called) */
39 PJSUA_MED_TP_INIT,
40
41 /** Running (media_start() has been called) */
Nanang Izzuddinb6c239c2011-05-10 05:42:28 +000042 PJSUA_MED_TP_RUNNING,
43
44 /** Disabled (transport is initialized, but media is being disabled) */
45 PJSUA_MED_TP_DISABLED
Benny Prijono224b4e22008-06-19 14:10:28 +000046
47} pjsua_med_tp_st;
48
Benny Prijono0bc99a92011-03-17 04:34:43 +000049/** Forward decl of pjsua call */
50typedef struct pjsua_call pjsua_call;
51
52/**
53 * Call's media stream.
54 */
55typedef struct pjsua_call_media
56{
57 pjsua_call *call; /**< Parent call. */
58 pjmedia_type type; /**< Media type. */
59 unsigned idx; /**< This media index in parent call. */
60 pjsua_call_media_status state; /**< Media state. */
61 pjmedia_dir dir; /**< Media direction. */
62
63 /** The stream */
Benny Prijono9b61ff52011-03-18 09:55:48 +000064 struct {
Benny Prijono0bc99a92011-03-17 04:34:43 +000065 /** Audio stream */
66 struct {
Nanang Izzuddinbf26db12011-03-18 07:54:50 +000067 pjmedia_stream *stream; /**< The audio stream. */
Benny Prijono0bc99a92011-03-17 04:34:43 +000068 int conf_slot; /**< Slot # in conference bridge. */
69 } a;
70
71 /** Video stream */
72 struct {
Nanang Izzuddinbf26db12011-03-18 07:54:50 +000073 pjmedia_vid_stream *stream; /**< The video stream. */
74 pjmedia_vid_port *capturer; /**< Video capturer. */
75 pjmedia_vid_port *renderer; /**< Video renderer. */
76 pjmedia_converter *conv_enc; /**< Converter for encoding dir.*/
77 pjmedia_converter *conv_dec; /**< Converter for decoding dir.*/
Benny Prijono0bc99a92011-03-17 04:34:43 +000078 } v;
79
80 } strm;
81
82 pj_uint32_t ssrc; /**< RTP SSRC */
83 pj_uint32_t rtp_tx_ts; /**< Initial RTP timestamp for sender. */
84 pj_uint16_t rtp_tx_seq;/**< Initial RTP sequence for sender. */
85 pj_uint8_t rtp_tx_seq_ts_set;
86 /**< Bitmask flags if initial RTP sequence
87 and/or timestamp for sender are set.
88 bit 0/LSB : sequence flag
89 bit 1 : timestamp flag */
90
91 pjmedia_transport *tp; /**< Current media transport (can be 0) */
92 pj_status_t tp_ready; /**< Media transport status. */
93 pjmedia_transport *tp_orig; /**< Original media transport */
94 pj_bool_t tp_auto_del; /**< May delete media transport */
95 pjsua_med_tp_st tp_st; /**< Media transport state */
96 pj_sockaddr rtp_addr; /**< Current RTP source address
97 (used to update ICE default
98 address) */
99 pjmedia_srtp_use rem_srtp_use; /**< Remote's SRTP usage policy. */
100} pjsua_call_media;
101
102/**
103 * Maximum number of SDP "m=" lines to be supported.
104 */
105#define PJSUA_MAX_CALL_MEDIA PJMEDIA_MAX_SDP_MEDIA
106
Benny Prijono224b4e22008-06-19 14:10:28 +0000107/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000108 * Structure to be attached to invite dialog.
109 * Given a dialog "dlg", application can retrieve this structure
110 * by accessing dlg->mod_data[pjsua.mod.id].
111 */
Benny Prijono0bc99a92011-03-17 04:34:43 +0000112struct pjsua_call
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000113{
114 unsigned index; /**< Index in pjsua array. */
115 pjsip_inv_session *inv; /**< The invite session. */
116 void *user_data; /**< User/application data. */
117 pjsip_status_code last_code; /**< Last status code seen. */
118 pj_str_t last_text; /**< Last status text seen. */
119 pj_time_val start_time;/**< First INVITE sent/received. */
120 pj_time_val res_time; /**< First response sent/received. */
121 pj_time_val conn_time; /**< Connected/confirmed time. */
122 pj_time_val dis_time; /**< Disconnect time. */
123 pjsua_acc_id acc_id; /**< Account index being used. */
Benny Prijonodb844a42008-02-02 17:07:18 +0000124 int secure_level;/**< Signaling security level. */
Benny Prijonodd63b992010-10-01 02:03:42 +0000125 pjsua_call_hold_type call_hold_type; /**< How to do call hold. */
Nanang Izzuddin99d69522008-08-04 15:01:38 +0000126 pj_bool_t local_hold;/**< Flag for call-hold by local. */
Benny Prijono0bc99a92011-03-17 04:34:43 +0000127
128 unsigned med_cnt; /**< Number of media in SDP. */
129 pjsua_call_media media[PJSUA_MAX_CALL_MEDIA]; /**< Array of media */
Nanang Izzuddinbf26db12011-03-18 07:54:50 +0000130 int audio_idx; /**< First active audio media. */
Benny Prijono0bc99a92011-03-17 04:34:43 +0000131
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000132 pjsip_evsub *xfer_sub; /**< Xfer server subscription, if this
133 call was triggered by xfer. */
Benny Prijono91a6a172007-10-31 08:59:29 +0000134 pj_stun_nat_type rem_nat_type; /**< NAT type of remote endpoint. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000135
136 char last_text_buf_[128]; /**< Buffer for last_text. */
137
Nanang Izzuddin93bacd02010-06-15 09:56:39 +0000138 struct {
139 pj_timer_entry reinv_timer;/**< Reinvite retry timer. */
Benny Prijono1e601552010-10-20 05:31:08 +0000140 pj_uint32_t sdp_ver; /**< SDP version of the bad answer */
141 int retry_cnt; /**< Retry count. */
Nanang Izzuddinec919002010-11-25 09:27:06 +0000142 pj_bool_t pending; /**< Pending until CONFIRMED state */
Nanang Izzuddin93bacd02010-06-15 09:56:39 +0000143 } lock_codec; /**< Data for codec locking when answer
144 contains multiple codecs. */
145
Benny Prijono0bc99a92011-03-17 04:34:43 +0000146};
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000147
148
149/**
150 * Server presence subscription list head.
151 */
Benny Prijono63fba012008-07-17 14:19:10 +0000152struct pjsua_srv_pres
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000153{
154 PJ_DECL_LIST_MEMBER(struct pjsua_srv_pres);
Benny Prijono63fba012008-07-17 14:19:10 +0000155 pjsip_evsub *sub; /**< The evsub. */
156 char *remote; /**< Remote URI. */
157 int acc_id; /**< Account ID. */
158 pjsip_dialog *dlg; /**< Dialog. */
159 int expires; /**< "expires" value in the request. */
160};
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000161
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000162/**
163 * Account
164 */
165typedef struct pjsua_acc
166{
Benny Prijonoc91ed8d2008-07-13 12:24:55 +0000167 pj_pool_t *pool; /**< Pool for this account. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000168 pjsua_acc_config cfg; /**< Account configuration. */
169 pj_bool_t valid; /**< Is this account valid? */
170
171 int index; /**< Index in accounts array. */
Benny Prijonoc570f2d2006-07-18 00:33:02 +0000172 pj_str_t display; /**< Display name, if any. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000173 pj_str_t user_part; /**< User part of local URI. */
Nanang Izzuddin5af37ff2009-08-05 18:41:23 +0000174 pj_str_t contact; /**< Our Contact header. */
Benny Prijonob54719f2010-11-16 03:07:46 +0000175 pj_str_t reg_contact; /**< Contact header for REGISTER.
176 It may be different than acc
177 contact if outbound is used */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000178
Benny Prijonob4a17c92006-07-10 14:40:21 +0000179 pj_str_t srv_domain; /**< Host part of reg server. */
180 int srv_port; /**< Port number of reg server. */
181
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000182 pjsip_regc *regc; /**< Client registration session. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000183 pj_status_t reg_last_err; /**< Last registration error. */
184 int reg_last_code; /**< Last status last register. */
185
Nanang Izzuddin36dd5b62010-03-30 11:13:59 +0000186 struct {
187 pj_bool_t active; /**< Flag of reregister status. */
188 pj_timer_entry timer; /**< Timer for reregistration. */
189 void *reg_tp; /**< Transport for registration. */
190 unsigned attempt_cnt; /**< Attempt counter. */
191 } auto_rereg; /**< Reregister/reconnect data. */
192
Benny Prijonobddef2c2007-10-31 13:28:08 +0000193 pj_timer_entry ka_timer; /**< Keep-alive timer for UDP. */
194 pjsip_transport *ka_transport; /**< Transport for keep-alive. */
195 pj_sockaddr ka_target; /**< Destination address for K-A */
196 unsigned ka_target_len; /**< Length of ka_target. */
197
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000198 pjsip_route_hdr route_set; /**< Complete route set inc. outbnd.*/
Nanang Izzuddinc3ea16a2010-04-20 14:36:38 +0000199 pj_uint32_t global_route_crc; /** CRC of global route setting. */
200 pj_uint32_t local_route_crc; /** CRC of account route setting.*/
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000201
Benny Prijonob54719f2010-11-16 03:07:46 +0000202 unsigned rfc5626_status;/**< SIP outbound status:
203 0: not used
204 1: requested
205 2: acknowledged by servers */
206 pj_str_t rfc5626_instprm;/**< SIP outbound instance param. */
207 pj_str_t rfc5626_regprm;/**< SIP outbound reg param. */
208
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000209 unsigned cred_cnt; /**< Number of credentials. */
210 pjsip_cred_info cred[PJSUA_ACC_MAX_PROXIES]; /**< Complete creds. */
211
212 pj_bool_t online_status; /**< Our online status. */
Benny Prijono4461c7d2007-08-25 13:36:15 +0000213 pjrpid_element rpid; /**< RPID element information. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000214 pjsua_srv_pres pres_srv_list; /**< Server subscription list. */
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000215 pjsip_publishc *publish_sess; /**< Client publication session. */
216 pj_bool_t publish_state; /**< Last published online status */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000217
Benny Prijono4dd961b2009-10-26 11:21:37 +0000218 pjsip_evsub *mwi_sub; /**< MWI client subscription */
219 pjsip_dialog *mwi_dlg; /**< Dialog for MWI sub. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000220} pjsua_acc;
221
222
223/**
224 *Transport.
225 */
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000226typedef struct pjsua_transport_data
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000227{
Benny Prijonoe93e2872006-06-28 16:46:49 +0000228 int index;
229 pjsip_transport_type_e type;
230 pjsip_host_port local_name;
231
232 union {
233 pjsip_transport *tp;
234 pjsip_tpfactory *factory;
235 void *ptr;
236 } data;
237
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000238} pjsua_transport_data;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000239
240
Benny Prijono63fba012008-07-17 14:19:10 +0000241/** Maximum length of subscription termination reason. */
242#define PJSUA_BUDDY_SUB_TERM_REASON_LEN 32
243
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000244/**
245 * Buddy data.
246 */
247typedef struct pjsua_buddy
248{
Benny Prijonoc91ed8d2008-07-13 12:24:55 +0000249 pj_pool_t *pool; /**< Pool for this buddy. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000250 unsigned index; /**< Buddy index. */
Benny Prijono705e7842008-07-21 18:12:51 +0000251 void *user_data; /**< Application data. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000252 pj_str_t uri; /**< Buddy URI. */
253 pj_str_t contact; /**< Contact learned from subscrp. */
254 pj_str_t name; /**< Buddy name. */
255 pj_str_t display; /**< Buddy display name. */
256 pj_str_t host; /**< Buddy host. */
257 unsigned port; /**< Buddy port. */
258 pj_bool_t monitor; /**< Should we monitor? */
Benny Prijonof9c40c32007-06-28 07:20:26 +0000259 pjsip_dialog *dlg; /**< The underlying dialog. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000260 pjsip_evsub *sub; /**< Buddy presence subscription */
Benny Prijono73bb7232009-10-20 13:56:26 +0000261 unsigned term_code; /**< Subscription termination code */
Benny Prijono63fba012008-07-17 14:19:10 +0000262 pj_str_t term_reason;/**< Subscription termination reason */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000263 pjsip_pres_status status; /**< Buddy presence status. */
Benny Prijono73bb7232009-10-20 13:56:26 +0000264 pj_timer_entry timer; /**< Resubscription timer */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000265} pjsua_buddy;
266
267
268/**
269 * File player/recorder data.
270 */
271typedef struct pjsua_file_data
272{
Benny Prijonoa66c3312007-01-21 23:12:40 +0000273 pj_bool_t type; /* 0=player, 1=playlist */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000274 pjmedia_port *port;
Benny Prijonod5696da2007-07-17 16:25:45 +0000275 pj_pool_t *pool;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000276 unsigned slot;
277} pjsua_file_data;
278
279
280/**
281 * Additional parameters for conference bridge.
282 */
283typedef struct pjsua_conf_setting
284{
285 unsigned channel_count;
286 unsigned samples_per_frame;
287 unsigned bits_per_sample;
288} pjsua_conf_setting;
289
Benny Prijonobb995fd2009-08-12 11:03:23 +0000290typedef struct pjsua_stun_resolve
291{
292 PJ_DECL_LIST_MEMBER(struct pjsua_stun_resolve);
293
294 pj_pool_t *pool; /**< Pool */
295 unsigned count; /**< # of entries */
296 pj_str_t *srv; /**< Array of entries */
297 unsigned idx; /**< Current index */
298 void *token; /**< App token */
299 pj_stun_resolve_cb cb; /**< App callback */
300 pj_bool_t blocking; /**< Blocking? */
301 pj_status_t status; /**< Session status */
302 pj_sockaddr addr; /**< Result */
303 pj_stun_sock *stun_sock; /**< Testing STUN sock */
304} pjsua_stun_resolve;
305
Benny Prijono9f468d12011-07-07 07:46:33 +0000306typedef enum pjsua_vid_win_type
307{
308 PJSUA_WND_TYPE_NONE,
309 PJSUA_WND_TYPE_PREVIEW,
310 PJSUA_WND_TYPE_STREAM
311} pjsua_vid_win_type;
312
313typedef struct pjsua_vid_win
314{
315 pjsua_vid_win_type type; /**< Type. */
316 pj_pool_t *pool; /**< Own pool. */
317 pjsua_call_id call_id; /**< Owner call or -1 */
318 pjmedia_vid_port *vp_cap; /**< Capture vidport. */
319 pjmedia_vid_port *vp_rend; /**< Renderer vidport */
320 pjmedia_vid_dev_index preview_cap_id;/* Capture dev id */
321} pjsua_vid_win;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000322
323/**
324 * Global pjsua application data.
325 */
326struct pjsua_data
327{
328
329 /* Control: */
330 pj_caching_pool cp; /**< Global pool factory. */
331 pj_pool_t *pool; /**< pjsua's private pool. */
332 pj_mutex_t *mutex; /**< Mutex protection for this data */
Benny Prijono0bc99a92011-03-17 04:34:43 +0000333 pjsua_state state; /**< Library state. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000334
335 /* Logging: */
336 pjsua_logging_config log_cfg; /**< Current logging config. */
337 pj_oshandle_t log_file; /**<Output log file handle */
338
339 /* SIP: */
340 pjsip_endpoint *endpt; /**< Global endpoint. */
341 pjsip_module mod; /**< pjsua's PJSIP module. */
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000342 pjsua_transport_data tpdata[8]; /**< Array of transports. */
Benny Prijono21407322010-03-10 13:33:25 +0000343 pjsip_tp_state_callback old_tp_cb; /**< Old transport callback. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000344
345 /* Threading: */
346 pj_bool_t thread_quit_flag; /**< Thread quit flag. */
347 pj_thread_t *thread[4]; /**< Array of threads. */
348
Benny Prijonoc97608e2007-03-23 16:34:20 +0000349 /* STUN and resolver */
350 pj_stun_config stun_cfg; /**< Global STUN settings. */
351 pj_sockaddr stun_srv; /**< Resolved STUN server address */
352 pj_status_t stun_status; /**< STUN server status. */
Benny Prijonobb995fd2009-08-12 11:03:23 +0000353 pjsua_stun_resolve stun_res; /**< List of pending STUN resolution*/
Benny Prijonoc97608e2007-03-23 16:34:20 +0000354 pj_dns_resolver *resolver; /**< DNS resolver. */
355
Benny Prijono6ba8c542007-10-16 01:34:14 +0000356 /* Detected NAT type */
357 pj_stun_nat_type nat_type; /**< NAT type. */
358 pj_status_t nat_status; /**< Detection status. */
359 pj_bool_t nat_in_progress; /**< Detection in progress */
360
Benny Prijono29c8ca32010-06-22 06:02:13 +0000361 /* List of outbound proxies: */
362 pjsip_route_hdr outbound_proxy;
363
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000364 /* Account: */
365 unsigned acc_cnt; /**< Number of accounts. */
366 pjsua_acc_id default_acc; /**< Default account ID */
367 pjsua_acc acc[PJSUA_MAX_ACC]; /**< Account array. */
Benny Prijono093d3022006-09-24 00:07:11 +0000368 pjsua_acc_id acc_ids[PJSUA_MAX_ACC]; /**< Acc sorted by prio*/
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000369
370 /* Calls: */
371 pjsua_config ua_cfg; /**< UA config. */
372 unsigned call_cnt; /**< Call counter. */
373 pjsua_call calls[PJSUA_MAX_CALLS];/**< Calls array. */
Benny Prijono5773cd62008-01-19 13:01:42 +0000374 pjsua_call_id next_call_id; /**< Next call id to use*/
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000375
376 /* Buddy; */
377 unsigned buddy_cnt; /**< Buddy count. */
378 pjsua_buddy buddy[PJSUA_MAX_BUDDIES]; /**< Buddy array. */
379
Benny Prijono7a5f5102007-05-29 00:33:09 +0000380 /* Presence: */
381 pj_timer_entry pres_timer;/**< Presence refresh timer. */
382
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000383 /* Media: */
384 pjsua_media_config media_cfg; /**< Media config. */
385 pjmedia_endpt *med_endpt; /**< Media endpoint. */
386 pjsua_conf_setting mconf_cfg; /**< Additionan conf. bridge. param */
387 pjmedia_conf *mconf; /**< Conference bridge. */
Benny Prijonof798e502009-03-09 13:08:16 +0000388 pj_bool_t is_mswitch;/**< Are we using audio switchboard
389 (a.k.a APS-Direct) */
390
391 /* Sound device */
392 pjmedia_aud_dev_index cap_dev; /**< Capture device ID. */
393 pjmedia_aud_dev_index play_dev; /**< Playback device ID. */
394 pj_uint32_t aud_svmask;/**< Which settings to save */
395 pjmedia_aud_param aud_param; /**< User settings to sound dev */
396 pj_bool_t aud_open_cnt;/**< How many # device is opened */
Benny Prijonoe909eac2006-07-27 22:04:56 +0000397 pj_bool_t no_snd; /**< No sound (app will manage it) */
Nanang Izzuddin68559c32008-06-13 17:01:46 +0000398 pj_pool_t *snd_pool; /**< Sound's private pool. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000399 pjmedia_snd_port *snd_port; /**< Sound port. */
Nanang Izzuddin68559c32008-06-13 17:01:46 +0000400 pj_timer_entry snd_idle_timer;/**< Sound device idle timer. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000401 pjmedia_master_port *null_snd; /**< Master port for null sound. */
402 pjmedia_port *null_port; /**< Null port. */
403
404
Nanang Izzuddin50fae732011-03-22 09:49:23 +0000405 /* Video device */
406 pjmedia_vid_dev_index vcap_dev; /**< Capture device ID. */
407 pjmedia_vid_dev_index vrdr_dev; /**< Playback device ID. */
408
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000409 /* File players: */
410 unsigned player_cnt;/**< Number of file players. */
Benny Prijonocba59d92007-02-16 09:22:56 +0000411 pjsua_file_data player[PJSUA_MAX_PLAYERS];/**< Array of players.*/
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000412
413 /* File recorders: */
414 unsigned rec_cnt; /**< Number of file recorders. */
Benny Prijonocba59d92007-02-16 09:22:56 +0000415 pjsua_file_data recorder[PJSUA_MAX_RECORDERS];/**< Array of recs.*/
Benny Prijono9f468d12011-07-07 07:46:33 +0000416
417 /* Video windows */
418#if PJSUA_HAS_VIDEO
419 pjsua_vid_win win[PJSUA_MAX_VID_WINS]; /**< Array of windows */
420#endif
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000421};
422
423
424extern struct pjsua_data pjsua_var;
425
Benny Prijono44e88ea2007-10-30 15:42:35 +0000426/**
427 * Get the instance of pjsua
428 */
429PJ_DECL(struct pjsua_data*) pjsua_get_var(void);
430
431
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000432
433/**
434 * IM callback data.
435 */
436typedef struct pjsua_im_data
437{
438 pjsua_acc_id acc_id;
439 pjsua_call_id call_id;
440 pj_str_t to;
441 pj_str_t body;
442 void *user_data;
443} pjsua_im_data;
444
445
446/**
447 * Duplicate IM data.
448 */
449PJ_INLINE(pjsua_im_data*) pjsua_im_data_dup(pj_pool_t *pool,
450 const pjsua_im_data *src)
451{
452 pjsua_im_data *dst;
453
Benny Prijono07113c92006-11-21 08:38:00 +0000454 dst = (pjsua_im_data*) pj_pool_alloc(pool, sizeof(*dst));
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000455 dst->acc_id = src->acc_id;
456 dst->call_id = src->call_id;
457 pj_strdup_with_null(pool, &dst->to, &src->to);
458 dst->user_data = src->user_data;
459 pj_strdup_with_null(pool, &dst->body, &src->body);
460
461 return dst;
462}
463
464
Benny Prijono148c9dd2006-09-19 13:37:53 +0000465#if 1
466#define PJSUA_LOCK() pj_mutex_lock(pjsua_var.mutex)
467#define PJSUA_TRY_LOCK() pj_mutex_trylock(pjsua_var.mutex)
468#define PJSUA_UNLOCK() pj_mutex_unlock(pjsua_var.mutex)
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000469#else
470#define PJSUA_LOCK()
Benny Prijono148c9dd2006-09-19 13:37:53 +0000471#define PJSUA_TRY_LOCK() PJ_SUCCESS
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000472#define PJSUA_UNLOCK()
473#endif
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000474
Benny Prijono0bc99a92011-03-17 04:34:43 +0000475/* Core */
476void pjsua_set_state(pjsua_state new_state);
477
Benny Prijonobb995fd2009-08-12 11:03:23 +0000478/******
479 * STUN resolution
480 */
481/* Resolve the STUN server */
482pj_status_t resolve_stun_server(pj_bool_t wait);
483
Benny Prijono91d06b62008-09-20 12:16:56 +0000484/**
485 * Normalize route URI (check for ";lr" and append one if it doesn't
486 * exist and pjsua_config.force_lr is set.
487 */
488pj_status_t normalize_route_uri(pj_pool_t *pool, pj_str_t *uri);
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000489
Benny Prijonoc97608e2007-03-23 16:34:20 +0000490/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000491 * Handle incoming invite request.
492 */
493pj_bool_t pjsua_call_on_incoming(pjsip_rx_data *rdata);
494
Benny Prijonoc97608e2007-03-23 16:34:20 +0000495/*
496 * Media channel.
497 */
498pj_status_t pjsua_media_channel_init(pjsua_call_id call_id,
Benny Prijonod8179652008-01-23 20:39:07 +0000499 pjsip_role_e role,
Benny Prijono25b2ea12008-01-24 19:20:54 +0000500 int security_level,
Benny Prijono224b4e22008-06-19 14:10:28 +0000501 pj_pool_t *tmp_pool,
502 const pjmedia_sdp_session *rem_sdp,
Benny Prijono25b2ea12008-01-24 19:20:54 +0000503 int *sip_err_code);
Benny Prijonoc97608e2007-03-23 16:34:20 +0000504pj_status_t pjsua_media_channel_create_sdp(pjsua_call_id call_id,
505 pj_pool_t *pool,
Benny Prijonod8179652008-01-23 20:39:07 +0000506 const pjmedia_sdp_session *rem_sdp,
Benny Prijono25b2ea12008-01-24 19:20:54 +0000507 pjmedia_sdp_session **p_sdp,
508 int *sip_err_code);
Benny Prijonoc97608e2007-03-23 16:34:20 +0000509pj_status_t pjsua_media_channel_update(pjsua_call_id call_id,
Benny Prijono224b4e22008-06-19 14:10:28 +0000510 const pjmedia_sdp_session *local_sdp,
Benny Prijonodbce2cf2007-03-28 16:24:00 +0000511 const pjmedia_sdp_session *remote_sdp);
Benny Prijonoc97608e2007-03-23 16:34:20 +0000512pj_status_t pjsua_media_channel_deinit(pjsua_call_id call_id);
513
514
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000515/**
516 * Init presence.
517 */
518pj_status_t pjsua_pres_init();
519
520/*
521 * Start presence subsystem.
522 */
523pj_status_t pjsua_pres_start(void);
524
525/**
526 * Refresh presence subscriptions
527 */
528void pjsua_pres_refresh(void);
529
530/*
Benny Prijono4461c7d2007-08-25 13:36:15 +0000531 * Update server subscription (e.g. when our online status has changed)
532 */
533void pjsua_pres_update_acc(int acc_id, pj_bool_t force);
534
535/*
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000536 * Shutdown presence.
537 */
538void pjsua_pres_shutdown(void);
539
540/**
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000541 * Init presence for aoocunt.
542 */
543pj_status_t pjsua_pres_init_acc(int acc_id);
544
545/**
Benny Prijono8b6834f2007-02-24 13:29:22 +0000546 * Send PUBLISH
547 */
548pj_status_t pjsua_pres_init_publish_acc(int acc_id);
549
550/**
Benny Prijono166d5022010-02-10 14:24:48 +0000551 * Send un-PUBLISH
552 */
553void pjsua_pres_unpublish(pjsua_acc *acc);
554
555/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000556 * Terminate server subscription for the account
557 */
558void pjsua_pres_delete_acc(int acc_id);
559
560/**
561 * Init IM module handler to handle incoming MESSAGE outside dialog.
562 */
563pj_status_t pjsua_im_init(void);
564
565/**
Benny Prijono4dd961b2009-10-26 11:21:37 +0000566 * Start MWI subscription
567 */
568void pjsua_start_mwi(pjsua_acc *acc);
569
570/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000571 * Init call subsystem.
572 */
573pj_status_t pjsua_call_subsys_init(const pjsua_config *cfg);
574
575/**
576 * Start call subsystem.
577 */
578pj_status_t pjsua_call_subsys_start(void);
579
580/**
581 * Init media subsystems.
582 */
583pj_status_t pjsua_media_subsys_init(const pjsua_media_config *cfg);
584
585/**
586 * Start pjsua media subsystem.
587 */
588pj_status_t pjsua_media_subsys_start(void);
589
590/**
591 * Destroy pjsua media subsystem.
592 */
593pj_status_t pjsua_media_subsys_destroy(void);
594
595/**
596 * Private: check if we can accept the message.
597 * If not, then p_accept header will be filled with a valid
598 * Accept header.
599 */
600pj_bool_t pjsua_im_accept_pager(pjsip_rx_data *rdata,
601 pjsip_accept_hdr **p_accept_hdr);
602
603/**
604 * Private: process pager message.
605 * This may trigger pjsua_ui_on_pager() or pjsua_ui_on_typing().
606 */
607void pjsua_im_process_pager(int call_id, const pj_str_t *from,
608 const pj_str_t *to, pjsip_rx_data *rdata);
609
610
611/**
612 * Create Accept header for MESSAGE.
613 */
614pjsip_accept_hdr* pjsua_im_create_accept(pj_pool_t *pool);
615
616/*
617 * Add additional headers etc in msg_data specified by application
618 * when sending requests.
619 */
620void pjsua_process_msg_data(pjsip_tx_data *tdata,
621 const pjsua_msg_data *msg_data);
622
623
624/*
625 * Add route_set to outgoing requests
626 */
627void pjsua_set_msg_route_set( pjsip_tx_data *tdata,
628 const pjsip_route_hdr *route_set );
629
630
631/*
632 * Simple version of MIME type parsing (it doesn't support parameters)
633 */
634void pjsua_parse_media_type( pj_pool_t *pool,
635 const pj_str_t *mime,
636 pjsip_media_type *media_type);
637
638
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000639/*
640 * Internal function to init transport selector from transport id.
641 */
642void pjsua_init_tpselector(pjsua_transport_id tp_id,
643 pjsip_tpselector *sel);
644
Benny Prijono3c5e28b2008-09-24 10:10:15 +0000645pjsip_dialog* on_dlg_forked(pjsip_dialog *first_set, pjsip_rx_data *res);
Benny Prijono627cbb42007-09-25 20:48:49 +0000646pj_status_t acquire_call(const char *title,
647 pjsua_call_id call_id,
648 pjsua_call **p_call,
649 pjsip_dialog **p_dlg);
650const char *good_number(char *buf, pj_int32_t val);
651void print_call(const char *title,
652 int call_id,
653 char *buf, pj_size_t size);
654
Benny Prijono9f468d12011-07-07 07:46:33 +0000655/*
656 * Video
657 */
658pj_status_t pjsua_vid_subsys_init(void);
659pj_status_t pjsua_vid_subsys_start(void);
660pj_status_t pjsua_vid_subsys_destroy(void);
661
662PJ_INLINE(void) pjsua_vid_win_reset(pjsua_vid_win_id wid)
663{
664#if PJSUA_HAS_VIDEO
665 pjsua_vid_win *w = &pjsua_var.win[wid];
666 pj_pool_t *pool = w->pool;
667
668 pj_bzero(w, sizeof(*w));
669 if (pool) pj_pool_reset(pool);
670 w->call_id = PJSUA_INVALID_ID;
671 w->pool = pool;
672 w->preview_cap_id = PJMEDIA_VID_INVALID_DEV;
673#endif
674}
675
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000676
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000677PJ_END_DECL
678
679#endif /* __PJSUA_INTERNAL_H__ */
680