blob: 46547eec2964f04cce8f6a60ec7b2c8fe1cffa60 [file] [log] [blame]
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001/* $Id$ */
2/*
Nanang Izzuddina62ffc92011-05-05 06:14:19 +00003 * Copyright (C) 2008-2011 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
Nanang Izzuddin62053a62011-07-12 11:08:32 +000052
Benny Prijono0bc99a92011-03-17 04:34:43 +000053/**
54 * Call's media stream.
55 */
56typedef struct pjsua_call_media
57{
58 pjsua_call *call; /**< Parent call. */
59 pjmedia_type type; /**< Media type. */
60 unsigned idx; /**< This media index in parent call. */
61 pjsua_call_media_status state; /**< Media state. */
62 pjmedia_dir dir; /**< Media direction. */
63
64 /** The stream */
Benny Prijono9b61ff52011-03-18 09:55:48 +000065 struct {
Benny Prijono0bc99a92011-03-17 04:34:43 +000066 /** Audio stream */
67 struct {
Nanang Izzuddinbf26db12011-03-18 07:54:50 +000068 pjmedia_stream *stream; /**< The audio stream. */
Benny Prijono0bc99a92011-03-17 04:34:43 +000069 int conf_slot; /**< Slot # in conference bridge. */
70 } a;
71
72 /** Video stream */
73 struct {
Nanang Izzuddinbf26db12011-03-18 07:54:50 +000074 pjmedia_vid_stream *stream; /**< The video stream. */
Nanang Izzuddin62053a62011-07-12 11:08:32 +000075 pjsua_vid_win_id cap_win_id;/**< The video capture window */
76 pjsua_vid_win_id rdr_win_id;/**< The video render window */
Nanang Izzuddinb4d4dad2011-07-13 08:51:10 +000077 pjmedia_vid_dev_index cap_dev; /**< The video capture device */
78 pjmedia_vid_dev_index rdr_dev; /**< The video-in render device */
Benny Prijono0bc99a92011-03-17 04:34:43 +000079 } v;
80
81 } strm;
82
83 pj_uint32_t ssrc; /**< RTP SSRC */
84 pj_uint32_t rtp_tx_ts; /**< Initial RTP timestamp for sender. */
85 pj_uint16_t rtp_tx_seq;/**< Initial RTP sequence for sender. */
86 pj_uint8_t rtp_tx_seq_ts_set;
87 /**< Bitmask flags if initial RTP sequence
88 and/or timestamp for sender are set.
89 bit 0/LSB : sequence flag
90 bit 1 : timestamp flag */
91
92 pjmedia_transport *tp; /**< Current media transport (can be 0) */
93 pj_status_t tp_ready; /**< Media transport status. */
94 pjmedia_transport *tp_orig; /**< Original media transport */
95 pj_bool_t tp_auto_del; /**< May delete media transport */
96 pjsua_med_tp_st tp_st; /**< Media transport state */
97 pj_sockaddr rtp_addr; /**< Current RTP source address
98 (used to update ICE default
99 address) */
100 pjmedia_srtp_use rem_srtp_use; /**< Remote's SRTP usage policy. */
Benny Prijonoee0ba182011-07-15 06:18:29 +0000101
Benny Prijono1fe04ee2011-07-15 07:27:05 +0000102 pjmedia_event_subscription esub_rend;/**< Subscribe renderer events. */
103 pjmedia_event_subscription esub_cap;/**< Subscribe capture events. */
Benny Prijono0bc99a92011-03-17 04:34:43 +0000104} pjsua_call_media;
105
106/**
107 * Maximum number of SDP "m=" lines to be supported.
108 */
109#define PJSUA_MAX_CALL_MEDIA PJMEDIA_MAX_SDP_MEDIA
110
Benny Prijono224b4e22008-06-19 14:10:28 +0000111/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000112 * Structure to be attached to invite dialog.
113 * Given a dialog "dlg", application can retrieve this structure
114 * by accessing dlg->mod_data[pjsua.mod.id].
115 */
Benny Prijono0bc99a92011-03-17 04:34:43 +0000116struct pjsua_call
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000117{
118 unsigned index; /**< Index in pjsua array. */
119 pjsip_inv_session *inv; /**< The invite session. */
120 void *user_data; /**< User/application data. */
121 pjsip_status_code last_code; /**< Last status code seen. */
122 pj_str_t last_text; /**< Last status text seen. */
123 pj_time_val start_time;/**< First INVITE sent/received. */
124 pj_time_val res_time; /**< First response sent/received. */
125 pj_time_val conn_time; /**< Connected/confirmed time. */
126 pj_time_val dis_time; /**< Disconnect time. */
127 pjsua_acc_id acc_id; /**< Account index being used. */
Benny Prijonodb844a42008-02-02 17:07:18 +0000128 int secure_level;/**< Signaling security level. */
Benny Prijonodd63b992010-10-01 02:03:42 +0000129 pjsua_call_hold_type call_hold_type; /**< How to do call hold. */
Nanang Izzuddin99d69522008-08-04 15:01:38 +0000130 pj_bool_t local_hold;/**< Flag for call-hold by local. */
Benny Prijono0bc99a92011-03-17 04:34:43 +0000131
132 unsigned med_cnt; /**< Number of media in SDP. */
133 pjsua_call_media media[PJSUA_MAX_CALL_MEDIA]; /**< Array of media */
Nanang Izzuddinbf26db12011-03-18 07:54:50 +0000134 int audio_idx; /**< First active audio media. */
Benny Prijono0bc99a92011-03-17 04:34:43 +0000135
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000136 pjsip_evsub *xfer_sub; /**< Xfer server subscription, if this
137 call was triggered by xfer. */
Benny Prijono91a6a172007-10-31 08:59:29 +0000138 pj_stun_nat_type rem_nat_type; /**< NAT type of remote endpoint. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000139
140 char last_text_buf_[128]; /**< Buffer for last_text. */
141
Nanang Izzuddin93bacd02010-06-15 09:56:39 +0000142 struct {
143 pj_timer_entry reinv_timer;/**< Reinvite retry timer. */
Benny Prijono1e601552010-10-20 05:31:08 +0000144 pj_uint32_t sdp_ver; /**< SDP version of the bad answer */
145 int retry_cnt; /**< Retry count. */
Nanang Izzuddinec919002010-11-25 09:27:06 +0000146 pj_bool_t pending; /**< Pending until CONFIRMED state */
Nanang Izzuddin93bacd02010-06-15 09:56:39 +0000147 } lock_codec; /**< Data for codec locking when answer
148 contains multiple codecs. */
149
Benny Prijono0bc99a92011-03-17 04:34:43 +0000150};
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000151
152
153/**
154 * Server presence subscription list head.
155 */
Benny Prijono63fba012008-07-17 14:19:10 +0000156struct pjsua_srv_pres
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000157{
158 PJ_DECL_LIST_MEMBER(struct pjsua_srv_pres);
Benny Prijono63fba012008-07-17 14:19:10 +0000159 pjsip_evsub *sub; /**< The evsub. */
160 char *remote; /**< Remote URI. */
161 int acc_id; /**< Account ID. */
162 pjsip_dialog *dlg; /**< Dialog. */
163 int expires; /**< "expires" value in the request. */
164};
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000165
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000166/**
167 * Account
168 */
169typedef struct pjsua_acc
170{
Benny Prijonoc91ed8d2008-07-13 12:24:55 +0000171 pj_pool_t *pool; /**< Pool for this account. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000172 pjsua_acc_config cfg; /**< Account configuration. */
173 pj_bool_t valid; /**< Is this account valid? */
174
175 int index; /**< Index in accounts array. */
Benny Prijonoc570f2d2006-07-18 00:33:02 +0000176 pj_str_t display; /**< Display name, if any. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000177 pj_str_t user_part; /**< User part of local URI. */
Nanang Izzuddin5af37ff2009-08-05 18:41:23 +0000178 pj_str_t contact; /**< Our Contact header. */
Benny Prijonob54719f2010-11-16 03:07:46 +0000179 pj_str_t reg_contact; /**< Contact header for REGISTER.
180 It may be different than acc
181 contact if outbound is used */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000182
Benny Prijonob4a17c92006-07-10 14:40:21 +0000183 pj_str_t srv_domain; /**< Host part of reg server. */
184 int srv_port; /**< Port number of reg server. */
185
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000186 pjsip_regc *regc; /**< Client registration session. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000187 pj_status_t reg_last_err; /**< Last registration error. */
188 int reg_last_code; /**< Last status last register. */
189
Nanang Izzuddin36dd5b62010-03-30 11:13:59 +0000190 struct {
191 pj_bool_t active; /**< Flag of reregister status. */
192 pj_timer_entry timer; /**< Timer for reregistration. */
193 void *reg_tp; /**< Transport for registration. */
194 unsigned attempt_cnt; /**< Attempt counter. */
195 } auto_rereg; /**< Reregister/reconnect data. */
196
Benny Prijonobddef2c2007-10-31 13:28:08 +0000197 pj_timer_entry ka_timer; /**< Keep-alive timer for UDP. */
198 pjsip_transport *ka_transport; /**< Transport for keep-alive. */
199 pj_sockaddr ka_target; /**< Destination address for K-A */
200 unsigned ka_target_len; /**< Length of ka_target. */
201
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000202 pjsip_route_hdr route_set; /**< Complete route set inc. outbnd.*/
Nanang Izzuddinc3ea16a2010-04-20 14:36:38 +0000203 pj_uint32_t global_route_crc; /** CRC of global route setting. */
204 pj_uint32_t local_route_crc; /** CRC of account route setting.*/
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000205
Benny Prijonob54719f2010-11-16 03:07:46 +0000206 unsigned rfc5626_status;/**< SIP outbound status:
207 0: not used
208 1: requested
209 2: acknowledged by servers */
210 pj_str_t rfc5626_instprm;/**< SIP outbound instance param. */
211 pj_str_t rfc5626_regprm;/**< SIP outbound reg param. */
212
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000213 unsigned cred_cnt; /**< Number of credentials. */
214 pjsip_cred_info cred[PJSUA_ACC_MAX_PROXIES]; /**< Complete creds. */
215
216 pj_bool_t online_status; /**< Our online status. */
Benny Prijono4461c7d2007-08-25 13:36:15 +0000217 pjrpid_element rpid; /**< RPID element information. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000218 pjsua_srv_pres pres_srv_list; /**< Server subscription list. */
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000219 pjsip_publishc *publish_sess; /**< Client publication session. */
220 pj_bool_t publish_state; /**< Last published online status */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000221
Benny Prijono4dd961b2009-10-26 11:21:37 +0000222 pjsip_evsub *mwi_sub; /**< MWI client subscription */
223 pjsip_dialog *mwi_dlg; /**< Dialog for MWI sub. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000224} pjsua_acc;
225
226
227/**
228 *Transport.
229 */
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000230typedef struct pjsua_transport_data
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000231{
Benny Prijonoe93e2872006-06-28 16:46:49 +0000232 int index;
233 pjsip_transport_type_e type;
234 pjsip_host_port local_name;
235
236 union {
237 pjsip_transport *tp;
238 pjsip_tpfactory *factory;
239 void *ptr;
240 } data;
241
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000242} pjsua_transport_data;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000243
244
Benny Prijono63fba012008-07-17 14:19:10 +0000245/** Maximum length of subscription termination reason. */
246#define PJSUA_BUDDY_SUB_TERM_REASON_LEN 32
247
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000248/**
249 * Buddy data.
250 */
251typedef struct pjsua_buddy
252{
Benny Prijonoc91ed8d2008-07-13 12:24:55 +0000253 pj_pool_t *pool; /**< Pool for this buddy. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000254 unsigned index; /**< Buddy index. */
Benny Prijono705e7842008-07-21 18:12:51 +0000255 void *user_data; /**< Application data. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000256 pj_str_t uri; /**< Buddy URI. */
257 pj_str_t contact; /**< Contact learned from subscrp. */
258 pj_str_t name; /**< Buddy name. */
259 pj_str_t display; /**< Buddy display name. */
260 pj_str_t host; /**< Buddy host. */
261 unsigned port; /**< Buddy port. */
262 pj_bool_t monitor; /**< Should we monitor? */
Benny Prijonof9c40c32007-06-28 07:20:26 +0000263 pjsip_dialog *dlg; /**< The underlying dialog. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000264 pjsip_evsub *sub; /**< Buddy presence subscription */
Benny Prijono73bb7232009-10-20 13:56:26 +0000265 unsigned term_code; /**< Subscription termination code */
Benny Prijono63fba012008-07-17 14:19:10 +0000266 pj_str_t term_reason;/**< Subscription termination reason */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000267 pjsip_pres_status status; /**< Buddy presence status. */
Benny Prijono73bb7232009-10-20 13:56:26 +0000268 pj_timer_entry timer; /**< Resubscription timer */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000269} pjsua_buddy;
270
271
272/**
273 * File player/recorder data.
274 */
275typedef struct pjsua_file_data
276{
Benny Prijonoa66c3312007-01-21 23:12:40 +0000277 pj_bool_t type; /* 0=player, 1=playlist */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000278 pjmedia_port *port;
Benny Prijonod5696da2007-07-17 16:25:45 +0000279 pj_pool_t *pool;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000280 unsigned slot;
281} pjsua_file_data;
282
283
284/**
285 * Additional parameters for conference bridge.
286 */
287typedef struct pjsua_conf_setting
288{
289 unsigned channel_count;
290 unsigned samples_per_frame;
291 unsigned bits_per_sample;
292} pjsua_conf_setting;
293
Benny Prijonobb995fd2009-08-12 11:03:23 +0000294typedef struct pjsua_stun_resolve
295{
296 PJ_DECL_LIST_MEMBER(struct pjsua_stun_resolve);
297
298 pj_pool_t *pool; /**< Pool */
299 unsigned count; /**< # of entries */
300 pj_str_t *srv; /**< Array of entries */
301 unsigned idx; /**< Current index */
302 void *token; /**< App token */
303 pj_stun_resolve_cb cb; /**< App callback */
304 pj_bool_t blocking; /**< Blocking? */
305 pj_status_t status; /**< Session status */
306 pj_sockaddr addr; /**< Result */
307 pj_stun_sock *stun_sock; /**< Testing STUN sock */
308} pjsua_stun_resolve;
309
Benny Prijonoaa15fbb2011-09-19 08:26:35 +0000310/* See also pjsua_vid_win_type_name() */
Benny Prijono9f468d12011-07-07 07:46:33 +0000311typedef enum pjsua_vid_win_type
312{
313 PJSUA_WND_TYPE_NONE,
314 PJSUA_WND_TYPE_PREVIEW,
315 PJSUA_WND_TYPE_STREAM
316} pjsua_vid_win_type;
317
318typedef struct pjsua_vid_win
319{
320 pjsua_vid_win_type type; /**< Type. */
321 pj_pool_t *pool; /**< Own pool. */
Nanang Izzuddin62053a62011-07-12 11:08:32 +0000322 unsigned ref_cnt; /**< Reference counter. */
Benny Prijono9f468d12011-07-07 07:46:33 +0000323 pjmedia_vid_port *vp_cap; /**< Capture vidport. */
324 pjmedia_vid_port *vp_rend; /**< Renderer vidport */
Nanang Izzuddin62053a62011-07-12 11:08:32 +0000325 pjmedia_port *tee; /**< Video tee */
Benny Prijonoaa15fbb2011-09-19 08:26:35 +0000326 pjmedia_vid_dev_index preview_cap_id;/**< Capture dev id */
327 pj_bool_t is_native; /**< Preview is by dev */
Benny Prijono9f468d12011-07-07 07:46:33 +0000328} pjsua_vid_win;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000329
330/**
331 * Global pjsua application data.
332 */
333struct pjsua_data
334{
335
336 /* Control: */
337 pj_caching_pool cp; /**< Global pool factory. */
338 pj_pool_t *pool; /**< pjsua's private pool. */
339 pj_mutex_t *mutex; /**< Mutex protection for this data */
Benny Prijono0bc99a92011-03-17 04:34:43 +0000340 pjsua_state state; /**< Library state. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000341
342 /* Logging: */
343 pjsua_logging_config log_cfg; /**< Current logging config. */
344 pj_oshandle_t log_file; /**<Output log file handle */
345
346 /* SIP: */
347 pjsip_endpoint *endpt; /**< Global endpoint. */
348 pjsip_module mod; /**< pjsua's PJSIP module. */
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000349 pjsua_transport_data tpdata[8]; /**< Array of transports. */
Benny Prijono21407322010-03-10 13:33:25 +0000350 pjsip_tp_state_callback old_tp_cb; /**< Old transport callback. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000351
352 /* Threading: */
353 pj_bool_t thread_quit_flag; /**< Thread quit flag. */
354 pj_thread_t *thread[4]; /**< Array of threads. */
355
Benny Prijonoc97608e2007-03-23 16:34:20 +0000356 /* STUN and resolver */
357 pj_stun_config stun_cfg; /**< Global STUN settings. */
358 pj_sockaddr stun_srv; /**< Resolved STUN server address */
359 pj_status_t stun_status; /**< STUN server status. */
Benny Prijonobb995fd2009-08-12 11:03:23 +0000360 pjsua_stun_resolve stun_res; /**< List of pending STUN resolution*/
Benny Prijonoc97608e2007-03-23 16:34:20 +0000361 pj_dns_resolver *resolver; /**< DNS resolver. */
362
Benny Prijono6ba8c542007-10-16 01:34:14 +0000363 /* Detected NAT type */
364 pj_stun_nat_type nat_type; /**< NAT type. */
365 pj_status_t nat_status; /**< Detection status. */
366 pj_bool_t nat_in_progress; /**< Detection in progress */
367
Benny Prijono29c8ca32010-06-22 06:02:13 +0000368 /* List of outbound proxies: */
369 pjsip_route_hdr outbound_proxy;
370
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000371 /* Account: */
372 unsigned acc_cnt; /**< Number of accounts. */
373 pjsua_acc_id default_acc; /**< Default account ID */
374 pjsua_acc acc[PJSUA_MAX_ACC]; /**< Account array. */
Benny Prijono093d3022006-09-24 00:07:11 +0000375 pjsua_acc_id acc_ids[PJSUA_MAX_ACC]; /**< Acc sorted by prio*/
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000376
377 /* Calls: */
378 pjsua_config ua_cfg; /**< UA config. */
379 unsigned call_cnt; /**< Call counter. */
380 pjsua_call calls[PJSUA_MAX_CALLS];/**< Calls array. */
Benny Prijono5773cd62008-01-19 13:01:42 +0000381 pjsua_call_id next_call_id; /**< Next call id to use*/
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000382
383 /* Buddy; */
384 unsigned buddy_cnt; /**< Buddy count. */
385 pjsua_buddy buddy[PJSUA_MAX_BUDDIES]; /**< Buddy array. */
386
Benny Prijono7a5f5102007-05-29 00:33:09 +0000387 /* Presence: */
388 pj_timer_entry pres_timer;/**< Presence refresh timer. */
389
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000390 /* Media: */
391 pjsua_media_config media_cfg; /**< Media config. */
392 pjmedia_endpt *med_endpt; /**< Media endpoint. */
393 pjsua_conf_setting mconf_cfg; /**< Additionan conf. bridge. param */
394 pjmedia_conf *mconf; /**< Conference bridge. */
Benny Prijonof798e502009-03-09 13:08:16 +0000395 pj_bool_t is_mswitch;/**< Are we using audio switchboard
396 (a.k.a APS-Direct) */
397
398 /* Sound device */
399 pjmedia_aud_dev_index cap_dev; /**< Capture device ID. */
400 pjmedia_aud_dev_index play_dev; /**< Playback device ID. */
401 pj_uint32_t aud_svmask;/**< Which settings to save */
402 pjmedia_aud_param aud_param; /**< User settings to sound dev */
403 pj_bool_t aud_open_cnt;/**< How many # device is opened */
Benny Prijonoe909eac2006-07-27 22:04:56 +0000404 pj_bool_t no_snd; /**< No sound (app will manage it) */
Nanang Izzuddin68559c32008-06-13 17:01:46 +0000405 pj_pool_t *snd_pool; /**< Sound's private pool. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000406 pjmedia_snd_port *snd_port; /**< Sound port. */
Nanang Izzuddin68559c32008-06-13 17:01:46 +0000407 pj_timer_entry snd_idle_timer;/**< Sound device idle timer. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000408 pjmedia_master_port *null_snd; /**< Master port for null sound. */
409 pjmedia_port *null_port; /**< Null port. */
Benny Prijono2d647722011-07-13 03:05:22 +0000410 pj_bool_t snd_is_on; /**< Media flow is currently active */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000411
Nanang Izzuddin50fae732011-03-22 09:49:23 +0000412 /* Video device */
413 pjmedia_vid_dev_index vcap_dev; /**< Capture device ID. */
414 pjmedia_vid_dev_index vrdr_dev; /**< Playback device ID. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000415
416 /* File players: */
417 unsigned player_cnt;/**< Number of file players. */
Benny Prijonocba59d92007-02-16 09:22:56 +0000418 pjsua_file_data player[PJSUA_MAX_PLAYERS];/**< Array of players.*/
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000419
420 /* File recorders: */
421 unsigned rec_cnt; /**< Number of file recorders. */
Benny Prijonocba59d92007-02-16 09:22:56 +0000422 pjsua_file_data recorder[PJSUA_MAX_RECORDERS];/**< Array of recs.*/
Benny Prijono9f468d12011-07-07 07:46:33 +0000423
424 /* Video windows */
425#if PJSUA_HAS_VIDEO
426 pjsua_vid_win win[PJSUA_MAX_VID_WINS]; /**< Array of windows */
427#endif
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000428};
429
430
431extern struct pjsua_data pjsua_var;
432
Benny Prijono44e88ea2007-10-30 15:42:35 +0000433/**
434 * Get the instance of pjsua
435 */
436PJ_DECL(struct pjsua_data*) pjsua_get_var(void);
437
438
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000439
440/**
441 * IM callback data.
442 */
443typedef struct pjsua_im_data
444{
445 pjsua_acc_id acc_id;
446 pjsua_call_id call_id;
447 pj_str_t to;
448 pj_str_t body;
449 void *user_data;
450} pjsua_im_data;
451
452
453/**
454 * Duplicate IM data.
455 */
456PJ_INLINE(pjsua_im_data*) pjsua_im_data_dup(pj_pool_t *pool,
457 const pjsua_im_data *src)
458{
459 pjsua_im_data *dst;
460
Benny Prijono07113c92006-11-21 08:38:00 +0000461 dst = (pjsua_im_data*) pj_pool_alloc(pool, sizeof(*dst));
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000462 dst->acc_id = src->acc_id;
463 dst->call_id = src->call_id;
464 pj_strdup_with_null(pool, &dst->to, &src->to);
465 dst->user_data = src->user_data;
466 pj_strdup_with_null(pool, &dst->body, &src->body);
467
468 return dst;
469}
470
471
Benny Prijono148c9dd2006-09-19 13:37:53 +0000472#if 1
473#define PJSUA_LOCK() pj_mutex_lock(pjsua_var.mutex)
474#define PJSUA_TRY_LOCK() pj_mutex_trylock(pjsua_var.mutex)
475#define PJSUA_UNLOCK() pj_mutex_unlock(pjsua_var.mutex)
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000476#else
477#define PJSUA_LOCK()
Benny Prijono148c9dd2006-09-19 13:37:53 +0000478#define PJSUA_TRY_LOCK() PJ_SUCCESS
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000479#define PJSUA_UNLOCK()
480#endif
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000481
Benny Prijono0bc99a92011-03-17 04:34:43 +0000482/* Core */
483void pjsua_set_state(pjsua_state new_state);
484
Benny Prijonobb995fd2009-08-12 11:03:23 +0000485/******
486 * STUN resolution
487 */
488/* Resolve the STUN server */
489pj_status_t resolve_stun_server(pj_bool_t wait);
490
Benny Prijono91d06b62008-09-20 12:16:56 +0000491/**
492 * Normalize route URI (check for ";lr" and append one if it doesn't
493 * exist and pjsua_config.force_lr is set.
494 */
495pj_status_t normalize_route_uri(pj_pool_t *pool, pj_str_t *uri);
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000496
Benny Prijonoc97608e2007-03-23 16:34:20 +0000497/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000498 * Handle incoming invite request.
499 */
500pj_bool_t pjsua_call_on_incoming(pjsip_rx_data *rdata);
501
Benny Prijonoc97608e2007-03-23 16:34:20 +0000502/*
503 * Media channel.
504 */
505pj_status_t pjsua_media_channel_init(pjsua_call_id call_id,
Benny Prijonod8179652008-01-23 20:39:07 +0000506 pjsip_role_e role,
Benny Prijono25b2ea12008-01-24 19:20:54 +0000507 int security_level,
Benny Prijono224b4e22008-06-19 14:10:28 +0000508 pj_pool_t *tmp_pool,
509 const pjmedia_sdp_session *rem_sdp,
Benny Prijono25b2ea12008-01-24 19:20:54 +0000510 int *sip_err_code);
Benny Prijonoc97608e2007-03-23 16:34:20 +0000511pj_status_t pjsua_media_channel_create_sdp(pjsua_call_id call_id,
512 pj_pool_t *pool,
Benny Prijonod8179652008-01-23 20:39:07 +0000513 const pjmedia_sdp_session *rem_sdp,
Benny Prijono25b2ea12008-01-24 19:20:54 +0000514 pjmedia_sdp_session **p_sdp,
515 int *sip_err_code);
Benny Prijonoc97608e2007-03-23 16:34:20 +0000516pj_status_t pjsua_media_channel_update(pjsua_call_id call_id,
Benny Prijono224b4e22008-06-19 14:10:28 +0000517 const pjmedia_sdp_session *local_sdp,
Benny Prijonodbce2cf2007-03-28 16:24:00 +0000518 const pjmedia_sdp_session *remote_sdp);
Benny Prijonoc97608e2007-03-23 16:34:20 +0000519pj_status_t pjsua_media_channel_deinit(pjsua_call_id call_id);
520
Benny Prijonoee0ba182011-07-15 06:18:29 +0000521pj_status_t pjsua_call_media_init(pjsua_call_media *call_med,
522 pjmedia_type type,
523 const pjsua_transport_config *tcfg,
524 int security_level,
525 int *sip_err_code);
526pj_status_t video_channel_update(pjsua_call_media *call_med,
527 pj_pool_t *tmp_pool,
528 const pjmedia_sdp_session *local_sdp,
529 const pjmedia_sdp_session *remote_sdp);
Nanang Izzuddin250ffa12011-07-15 08:13:11 +0000530void stop_video_stream(pjsua_call_media *call_med);
Benny Prijonoee0ba182011-07-15 06:18:29 +0000531
Benny Prijonoc97608e2007-03-23 16:34:20 +0000532
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000533/**
534 * Init presence.
535 */
536pj_status_t pjsua_pres_init();
537
538/*
539 * Start presence subsystem.
540 */
541pj_status_t pjsua_pres_start(void);
542
543/**
544 * Refresh presence subscriptions
545 */
546void pjsua_pres_refresh(void);
547
548/*
Benny Prijono4461c7d2007-08-25 13:36:15 +0000549 * Update server subscription (e.g. when our online status has changed)
550 */
551void pjsua_pres_update_acc(int acc_id, pj_bool_t force);
552
553/*
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000554 * Shutdown presence.
555 */
556void pjsua_pres_shutdown(void);
557
558/**
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000559 * Init presence for aoocunt.
560 */
561pj_status_t pjsua_pres_init_acc(int acc_id);
562
563/**
Benny Prijono8b6834f2007-02-24 13:29:22 +0000564 * Send PUBLISH
565 */
566pj_status_t pjsua_pres_init_publish_acc(int acc_id);
567
568/**
Benny Prijono166d5022010-02-10 14:24:48 +0000569 * Send un-PUBLISH
570 */
571void pjsua_pres_unpublish(pjsua_acc *acc);
572
573/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000574 * Terminate server subscription for the account
575 */
576void pjsua_pres_delete_acc(int acc_id);
577
578/**
579 * Init IM module handler to handle incoming MESSAGE outside dialog.
580 */
581pj_status_t pjsua_im_init(void);
582
583/**
Benny Prijono4dd961b2009-10-26 11:21:37 +0000584 * Start MWI subscription
585 */
586void pjsua_start_mwi(pjsua_acc *acc);
587
588/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000589 * Init call subsystem.
590 */
591pj_status_t pjsua_call_subsys_init(const pjsua_config *cfg);
592
593/**
594 * Start call subsystem.
595 */
596pj_status_t pjsua_call_subsys_start(void);
597
598/**
599 * Init media subsystems.
600 */
601pj_status_t pjsua_media_subsys_init(const pjsua_media_config *cfg);
602
603/**
604 * Start pjsua media subsystem.
605 */
606pj_status_t pjsua_media_subsys_start(void);
607
608/**
609 * Destroy pjsua media subsystem.
610 */
611pj_status_t pjsua_media_subsys_destroy(void);
612
613/**
614 * Private: check if we can accept the message.
615 * If not, then p_accept header will be filled with a valid
616 * Accept header.
617 */
618pj_bool_t pjsua_im_accept_pager(pjsip_rx_data *rdata,
619 pjsip_accept_hdr **p_accept_hdr);
620
621/**
622 * Private: process pager message.
623 * This may trigger pjsua_ui_on_pager() or pjsua_ui_on_typing().
624 */
625void pjsua_im_process_pager(int call_id, const pj_str_t *from,
626 const pj_str_t *to, pjsip_rx_data *rdata);
627
628
629/**
630 * Create Accept header for MESSAGE.
631 */
632pjsip_accept_hdr* pjsua_im_create_accept(pj_pool_t *pool);
633
634/*
635 * Add additional headers etc in msg_data specified by application
636 * when sending requests.
637 */
638void pjsua_process_msg_data(pjsip_tx_data *tdata,
639 const pjsua_msg_data *msg_data);
640
641
642/*
643 * Add route_set to outgoing requests
644 */
645void pjsua_set_msg_route_set( pjsip_tx_data *tdata,
646 const pjsip_route_hdr *route_set );
647
648
649/*
650 * Simple version of MIME type parsing (it doesn't support parameters)
651 */
652void pjsua_parse_media_type( pj_pool_t *pool,
653 const pj_str_t *mime,
654 pjsip_media_type *media_type);
655
656
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000657/*
658 * Internal function to init transport selector from transport id.
659 */
660void pjsua_init_tpselector(pjsua_transport_id tp_id,
661 pjsip_tpselector *sel);
662
Benny Prijono3c5e28b2008-09-24 10:10:15 +0000663pjsip_dialog* on_dlg_forked(pjsip_dialog *first_set, pjsip_rx_data *res);
Benny Prijono627cbb42007-09-25 20:48:49 +0000664pj_status_t acquire_call(const char *title,
665 pjsua_call_id call_id,
666 pjsua_call **p_call,
667 pjsip_dialog **p_dlg);
668const char *good_number(char *buf, pj_int32_t val);
669void print_call(const char *title,
670 int call_id,
671 char *buf, pj_size_t size);
672
Benny Prijono9f468d12011-07-07 07:46:33 +0000673/*
674 * Video
675 */
676pj_status_t pjsua_vid_subsys_init(void);
677pj_status_t pjsua_vid_subsys_start(void);
678pj_status_t pjsua_vid_subsys_destroy(void);
679
Benny Prijono9f468d12011-07-07 07:46:33 +0000680#if PJSUA_HAS_VIDEO
Benny Prijonoaa15fbb2011-09-19 08:26:35 +0000681PJ_DECL(void) pjsua_vid_win_reset(pjsua_vid_win_id wid);
Nanang Izzuddind93c68a2011-07-19 08:40:20 +0000682#else
Benny Prijonoaa15fbb2011-09-19 08:26:35 +0000683# define pjsua_vid_win_reset(wid)
Benny Prijono9f468d12011-07-07 07:46:33 +0000684#endif
Benny Prijono9f468d12011-07-07 07:46:33 +0000685
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000686
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000687PJ_END_DECL
688
689#endif /* __PJSUA_INTERNAL_H__ */
690