blob: 5c3dd34daf8da7d729cbae50a8faa57a811b8013 [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
Benny Prijono0bc99a92011-03-17 04:34:43 +000030/** Forward decl of pjsua call */
31typedef struct pjsua_call pjsua_call;
32
Sauw Ming73ecfe82011-09-21 10:20:01 +000033/** Forward decl of pjsua call media */
34typedef struct pjsua_call_media pjsua_call_media;
35
Nanang Izzuddin62053a62011-07-12 11:08:32 +000036
Benny Prijono0bc99a92011-03-17 04:34:43 +000037/**
38 * Call's media stream.
39 */
Sauw Ming96cabac2011-09-21 11:21:33 +000040struct pjsua_call_media
Benny Prijono0bc99a92011-03-17 04:34:43 +000041{
42 pjsua_call *call; /**< Parent call. */
43 pjmedia_type type; /**< Media type. */
44 unsigned idx; /**< This media index in parent call. */
45 pjsua_call_media_status state; /**< Media state. */
46 pjmedia_dir dir; /**< Media direction. */
47
48 /** The stream */
Benny Prijono9b61ff52011-03-18 09:55:48 +000049 struct {
Benny Prijono0bc99a92011-03-17 04:34:43 +000050 /** Audio stream */
51 struct {
Nanang Izzuddinbf26db12011-03-18 07:54:50 +000052 pjmedia_stream *stream; /**< The audio stream. */
Benny Prijono0bc99a92011-03-17 04:34:43 +000053 int conf_slot; /**< Slot # in conference bridge. */
54 } a;
55
56 /** Video stream */
57 struct {
Nanang Izzuddinbf26db12011-03-18 07:54:50 +000058 pjmedia_vid_stream *stream; /**< The video stream. */
Nanang Izzuddin62053a62011-07-12 11:08:32 +000059 pjsua_vid_win_id cap_win_id;/**< The video capture window */
60 pjsua_vid_win_id rdr_win_id;/**< The video render window */
Nanang Izzuddinb4d4dad2011-07-13 08:51:10 +000061 pjmedia_vid_dev_index cap_dev; /**< The video capture device */
62 pjmedia_vid_dev_index rdr_dev; /**< The video-in render device */
Benny Prijono0bc99a92011-03-17 04:34:43 +000063 } v;
64
65 } strm;
66
67 pj_uint32_t ssrc; /**< RTP SSRC */
68 pj_uint32_t rtp_tx_ts; /**< Initial RTP timestamp for sender. */
69 pj_uint16_t rtp_tx_seq;/**< Initial RTP sequence for sender. */
70 pj_uint8_t rtp_tx_seq_ts_set;
71 /**< Bitmask flags if initial RTP sequence
72 and/or timestamp for sender are set.
73 bit 0/LSB : sequence flag
74 bit 1 : timestamp flag */
75
76 pjmedia_transport *tp; /**< Current media transport (can be 0) */
77 pj_status_t tp_ready; /**< Media transport status. */
78 pjmedia_transport *tp_orig; /**< Original media transport */
Sauw Ming73ecfe82011-09-21 10:20:01 +000079 pj_bool_t tp_auto_del; /**< May delete media transport */
Benny Prijono0bc99a92011-03-17 04:34:43 +000080 pjsua_med_tp_st tp_st; /**< Media transport state */
81 pj_sockaddr rtp_addr; /**< Current RTP source address
82 (used to update ICE default
83 address) */
84 pjmedia_srtp_use rem_srtp_use; /**< Remote's SRTP usage policy. */
Benny Prijonoee0ba182011-07-15 06:18:29 +000085
Sauw Ming73ecfe82011-09-21 10:20:01 +000086 pjmedia_event_subscription esub_rend;/**< Subscribe renderer events. */
Benny Prijono1fe04ee2011-07-15 07:27:05 +000087 pjmedia_event_subscription esub_cap;/**< Subscribe capture events. */
Sauw Ming73ecfe82011-09-21 10:20:01 +000088
89 pjsua_med_tp_state_cb med_init_cb;/**< Media transport
90 initialization callback. */
91
92 /** Media transport creation callback. */
93 pj_status_t (*med_create_cb)(pjsua_call_media *call_med,
94 pj_status_t status, int security_level,
95 int *sip_err_code);
Sauw Ming96cabac2011-09-21 11:21:33 +000096};
Benny Prijono0bc99a92011-03-17 04:34:43 +000097
98/**
99 * Maximum number of SDP "m=" lines to be supported.
100 */
101#define PJSUA_MAX_CALL_MEDIA PJMEDIA_MAX_SDP_MEDIA
102
Benny Prijono224b4e22008-06-19 14:10:28 +0000103/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000104 * Structure to be attached to invite dialog.
105 * Given a dialog "dlg", application can retrieve this structure
106 * by accessing dlg->mod_data[pjsua.mod.id].
107 */
Benny Prijono0bc99a92011-03-17 04:34:43 +0000108struct pjsua_call
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000109{
110 unsigned index; /**< Index in pjsua array. */
111 pjsip_inv_session *inv; /**< The invite session. */
112 void *user_data; /**< User/application data. */
113 pjsip_status_code last_code; /**< Last status code seen. */
114 pj_str_t last_text; /**< Last status text seen. */
115 pj_time_val start_time;/**< First INVITE sent/received. */
116 pj_time_val res_time; /**< First response sent/received. */
117 pj_time_val conn_time; /**< Connected/confirmed time. */
118 pj_time_val dis_time; /**< Disconnect time. */
119 pjsua_acc_id acc_id; /**< Account index being used. */
Benny Prijonodb844a42008-02-02 17:07:18 +0000120 int secure_level;/**< Signaling security level. */
Benny Prijonodd63b992010-10-01 02:03:42 +0000121 pjsua_call_hold_type call_hold_type; /**< How to do call hold. */
Nanang Izzuddin99d69522008-08-04 15:01:38 +0000122 pj_bool_t local_hold;/**< Flag for call-hold by local. */
Benny Prijono0bc99a92011-03-17 04:34:43 +0000123
124 unsigned med_cnt; /**< Number of media in SDP. */
125 pjsua_call_media media[PJSUA_MAX_CALL_MEDIA]; /**< Array of media */
Nanang Izzuddinbf26db12011-03-18 07:54:50 +0000126 int audio_idx; /**< First active audio media. */
Sauw Ming73ecfe82011-09-21 10:20:01 +0000127 pj_mutex_t *med_ch_mutex;/**< Media channel callback's mutex. */
128 pjsua_med_tp_state_cb med_ch_cb;/**< Media channel callback. */
129 pjsua_med_tp_state_info med_ch_info;/**< Media channel info. */
Benny Prijono0bc99a92011-03-17 04:34:43 +0000130
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000131 pjsip_evsub *xfer_sub; /**< Xfer server subscription, if this
132 call was triggered by xfer. */
Benny Prijono91a6a172007-10-31 08:59:29 +0000133 pj_stun_nat_type rem_nat_type; /**< NAT type of remote endpoint. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000134
135 char last_text_buf_[128]; /**< Buffer for last_text. */
136
Nanang Izzuddin93bacd02010-06-15 09:56:39 +0000137 struct {
138 pj_timer_entry reinv_timer;/**< Reinvite retry timer. */
Benny Prijono1e601552010-10-20 05:31:08 +0000139 pj_uint32_t sdp_ver; /**< SDP version of the bad answer */
140 int retry_cnt; /**< Retry count. */
Nanang Izzuddinec919002010-11-25 09:27:06 +0000141 pj_bool_t pending; /**< Pending until CONFIRMED state */
Nanang Izzuddin93bacd02010-06-15 09:56:39 +0000142 } lock_codec; /**< Data for codec locking when answer
143 contains multiple codecs. */
144
Sauw Ming73ecfe82011-09-21 10:20:01 +0000145 struct {
146 pjsip_dialog *dlg; /**< Call dialog. */
147 pjmedia_sdp_session *rem_sdp;/**< Remote SDP. */
148 union {
149 struct {
150 unsigned options; /**< Outgoing call options. */
151 pjsua_msg_data *msg_data;/**< Headers for outgoing INVITE. */
152 } out_call;
153 } call_var;
154 } async_call; /**< Temporary storage for async
155 outgoing/incoming call. */
Benny Prijono0bc99a92011-03-17 04:34:43 +0000156};
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000157
158
159/**
160 * Server presence subscription list head.
161 */
Benny Prijono63fba012008-07-17 14:19:10 +0000162struct pjsua_srv_pres
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000163{
164 PJ_DECL_LIST_MEMBER(struct pjsua_srv_pres);
Benny Prijono63fba012008-07-17 14:19:10 +0000165 pjsip_evsub *sub; /**< The evsub. */
166 char *remote; /**< Remote URI. */
167 int acc_id; /**< Account ID. */
168 pjsip_dialog *dlg; /**< Dialog. */
169 int expires; /**< "expires" value in the request. */
170};
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000171
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000172/**
173 * Account
174 */
175typedef struct pjsua_acc
176{
Benny Prijonoc91ed8d2008-07-13 12:24:55 +0000177 pj_pool_t *pool; /**< Pool for this account. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000178 pjsua_acc_config cfg; /**< Account configuration. */
179 pj_bool_t valid; /**< Is this account valid? */
180
181 int index; /**< Index in accounts array. */
Benny Prijonoc570f2d2006-07-18 00:33:02 +0000182 pj_str_t display; /**< Display name, if any. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000183 pj_str_t user_part; /**< User part of local URI. */
Nanang Izzuddin5af37ff2009-08-05 18:41:23 +0000184 pj_str_t contact; /**< Our Contact header. */
Benny Prijonob54719f2010-11-16 03:07:46 +0000185 pj_str_t reg_contact; /**< Contact header for REGISTER.
186 It may be different than acc
187 contact if outbound is used */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000188
Benny Prijonob4a17c92006-07-10 14:40:21 +0000189 pj_str_t srv_domain; /**< Host part of reg server. */
190 int srv_port; /**< Port number of reg server. */
191
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000192 pjsip_regc *regc; /**< Client registration session. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000193 pj_status_t reg_last_err; /**< Last registration error. */
194 int reg_last_code; /**< Last status last register. */
195
Nanang Izzuddin36dd5b62010-03-30 11:13:59 +0000196 struct {
197 pj_bool_t active; /**< Flag of reregister status. */
198 pj_timer_entry timer; /**< Timer for reregistration. */
199 void *reg_tp; /**< Transport for registration. */
200 unsigned attempt_cnt; /**< Attempt counter. */
201 } auto_rereg; /**< Reregister/reconnect data. */
202
Benny Prijonobddef2c2007-10-31 13:28:08 +0000203 pj_timer_entry ka_timer; /**< Keep-alive timer for UDP. */
204 pjsip_transport *ka_transport; /**< Transport for keep-alive. */
205 pj_sockaddr ka_target; /**< Destination address for K-A */
206 unsigned ka_target_len; /**< Length of ka_target. */
207
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000208 pjsip_route_hdr route_set; /**< Complete route set inc. outbnd.*/
Nanang Izzuddinc3ea16a2010-04-20 14:36:38 +0000209 pj_uint32_t global_route_crc; /** CRC of global route setting. */
210 pj_uint32_t local_route_crc; /** CRC of account route setting.*/
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000211
Benny Prijonob54719f2010-11-16 03:07:46 +0000212 unsigned rfc5626_status;/**< SIP outbound status:
213 0: not used
214 1: requested
215 2: acknowledged by servers */
216 pj_str_t rfc5626_instprm;/**< SIP outbound instance param. */
217 pj_str_t rfc5626_regprm;/**< SIP outbound reg param. */
218
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000219 unsigned cred_cnt; /**< Number of credentials. */
220 pjsip_cred_info cred[PJSUA_ACC_MAX_PROXIES]; /**< Complete creds. */
221
222 pj_bool_t online_status; /**< Our online status. */
Benny Prijono4461c7d2007-08-25 13:36:15 +0000223 pjrpid_element rpid; /**< RPID element information. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000224 pjsua_srv_pres pres_srv_list; /**< Server subscription list. */
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000225 pjsip_publishc *publish_sess; /**< Client publication session. */
226 pj_bool_t publish_state; /**< Last published online status */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000227
Benny Prijono4dd961b2009-10-26 11:21:37 +0000228 pjsip_evsub *mwi_sub; /**< MWI client subscription */
229 pjsip_dialog *mwi_dlg; /**< Dialog for MWI sub. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000230} pjsua_acc;
231
232
233/**
234 *Transport.
235 */
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000236typedef struct pjsua_transport_data
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000237{
Benny Prijonoe93e2872006-06-28 16:46:49 +0000238 int index;
239 pjsip_transport_type_e type;
240 pjsip_host_port local_name;
241
242 union {
243 pjsip_transport *tp;
244 pjsip_tpfactory *factory;
245 void *ptr;
246 } data;
247
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000248} pjsua_transport_data;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000249
250
Benny Prijono63fba012008-07-17 14:19:10 +0000251/** Maximum length of subscription termination reason. */
252#define PJSUA_BUDDY_SUB_TERM_REASON_LEN 32
253
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000254/**
255 * Buddy data.
256 */
257typedef struct pjsua_buddy
258{
Benny Prijonoc91ed8d2008-07-13 12:24:55 +0000259 pj_pool_t *pool; /**< Pool for this buddy. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000260 unsigned index; /**< Buddy index. */
Benny Prijono705e7842008-07-21 18:12:51 +0000261 void *user_data; /**< Application data. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000262 pj_str_t uri; /**< Buddy URI. */
263 pj_str_t contact; /**< Contact learned from subscrp. */
264 pj_str_t name; /**< Buddy name. */
265 pj_str_t display; /**< Buddy display name. */
266 pj_str_t host; /**< Buddy host. */
267 unsigned port; /**< Buddy port. */
268 pj_bool_t monitor; /**< Should we monitor? */
Benny Prijonof9c40c32007-06-28 07:20:26 +0000269 pjsip_dialog *dlg; /**< The underlying dialog. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000270 pjsip_evsub *sub; /**< Buddy presence subscription */
Benny Prijono73bb7232009-10-20 13:56:26 +0000271 unsigned term_code; /**< Subscription termination code */
Benny Prijono63fba012008-07-17 14:19:10 +0000272 pj_str_t term_reason;/**< Subscription termination reason */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000273 pjsip_pres_status status; /**< Buddy presence status. */
Benny Prijono73bb7232009-10-20 13:56:26 +0000274 pj_timer_entry timer; /**< Resubscription timer */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000275} pjsua_buddy;
276
277
278/**
279 * File player/recorder data.
280 */
281typedef struct pjsua_file_data
282{
Benny Prijonoa66c3312007-01-21 23:12:40 +0000283 pj_bool_t type; /* 0=player, 1=playlist */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000284 pjmedia_port *port;
Benny Prijonod5696da2007-07-17 16:25:45 +0000285 pj_pool_t *pool;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000286 unsigned slot;
287} pjsua_file_data;
288
289
290/**
291 * Additional parameters for conference bridge.
292 */
293typedef struct pjsua_conf_setting
294{
295 unsigned channel_count;
296 unsigned samples_per_frame;
297 unsigned bits_per_sample;
298} pjsua_conf_setting;
299
Benny Prijonobb995fd2009-08-12 11:03:23 +0000300typedef struct pjsua_stun_resolve
301{
302 PJ_DECL_LIST_MEMBER(struct pjsua_stun_resolve);
303
304 pj_pool_t *pool; /**< Pool */
305 unsigned count; /**< # of entries */
306 pj_str_t *srv; /**< Array of entries */
307 unsigned idx; /**< Current index */
308 void *token; /**< App token */
309 pj_stun_resolve_cb cb; /**< App callback */
310 pj_bool_t blocking; /**< Blocking? */
311 pj_status_t status; /**< Session status */
312 pj_sockaddr addr; /**< Result */
313 pj_stun_sock *stun_sock; /**< Testing STUN sock */
314} pjsua_stun_resolve;
315
Benny Prijonoaa15fbb2011-09-19 08:26:35 +0000316/* See also pjsua_vid_win_type_name() */
Benny Prijono9f468d12011-07-07 07:46:33 +0000317typedef enum pjsua_vid_win_type
318{
319 PJSUA_WND_TYPE_NONE,
320 PJSUA_WND_TYPE_PREVIEW,
321 PJSUA_WND_TYPE_STREAM
322} pjsua_vid_win_type;
323
324typedef struct pjsua_vid_win
325{
326 pjsua_vid_win_type type; /**< Type. */
327 pj_pool_t *pool; /**< Own pool. */
Nanang Izzuddin62053a62011-07-12 11:08:32 +0000328 unsigned ref_cnt; /**< Reference counter. */
Benny Prijono9f468d12011-07-07 07:46:33 +0000329 pjmedia_vid_port *vp_cap; /**< Capture vidport. */
330 pjmedia_vid_port *vp_rend; /**< Renderer vidport */
Nanang Izzuddin62053a62011-07-12 11:08:32 +0000331 pjmedia_port *tee; /**< Video tee */
Benny Prijonoaa15fbb2011-09-19 08:26:35 +0000332 pjmedia_vid_dev_index preview_cap_id;/**< Capture dev id */
Benny Prijono39203b82011-09-20 10:07:55 +0000333 pj_bool_t preview_running;/**< Preview is started*/
Benny Prijonoaa15fbb2011-09-19 08:26:35 +0000334 pj_bool_t is_native; /**< Preview is by dev */
Benny Prijono9f468d12011-07-07 07:46:33 +0000335} pjsua_vid_win;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000336
337/**
338 * Global pjsua application data.
339 */
340struct pjsua_data
341{
342
343 /* Control: */
344 pj_caching_pool cp; /**< Global pool factory. */
345 pj_pool_t *pool; /**< pjsua's private pool. */
346 pj_mutex_t *mutex; /**< Mutex protection for this data */
Benny Prijono0bc99a92011-03-17 04:34:43 +0000347 pjsua_state state; /**< Library state. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000348
349 /* Logging: */
350 pjsua_logging_config log_cfg; /**< Current logging config. */
351 pj_oshandle_t log_file; /**<Output log file handle */
352
353 /* SIP: */
354 pjsip_endpoint *endpt; /**< Global endpoint. */
355 pjsip_module mod; /**< pjsua's PJSIP module. */
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000356 pjsua_transport_data tpdata[8]; /**< Array of transports. */
Benny Prijono21407322010-03-10 13:33:25 +0000357 pjsip_tp_state_callback old_tp_cb; /**< Old transport callback. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000358
359 /* Threading: */
360 pj_bool_t thread_quit_flag; /**< Thread quit flag. */
361 pj_thread_t *thread[4]; /**< Array of threads. */
362
Benny Prijonoc97608e2007-03-23 16:34:20 +0000363 /* STUN and resolver */
364 pj_stun_config stun_cfg; /**< Global STUN settings. */
365 pj_sockaddr stun_srv; /**< Resolved STUN server address */
366 pj_status_t stun_status; /**< STUN server status. */
Benny Prijonobb995fd2009-08-12 11:03:23 +0000367 pjsua_stun_resolve stun_res; /**< List of pending STUN resolution*/
Benny Prijonoc97608e2007-03-23 16:34:20 +0000368 pj_dns_resolver *resolver; /**< DNS resolver. */
369
Benny Prijono6ba8c542007-10-16 01:34:14 +0000370 /* Detected NAT type */
371 pj_stun_nat_type nat_type; /**< NAT type. */
372 pj_status_t nat_status; /**< Detection status. */
373 pj_bool_t nat_in_progress; /**< Detection in progress */
374
Benny Prijono29c8ca32010-06-22 06:02:13 +0000375 /* List of outbound proxies: */
376 pjsip_route_hdr outbound_proxy;
377
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000378 /* Account: */
379 unsigned acc_cnt; /**< Number of accounts. */
380 pjsua_acc_id default_acc; /**< Default account ID */
381 pjsua_acc acc[PJSUA_MAX_ACC]; /**< Account array. */
Benny Prijono093d3022006-09-24 00:07:11 +0000382 pjsua_acc_id acc_ids[PJSUA_MAX_ACC]; /**< Acc sorted by prio*/
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000383
384 /* Calls: */
385 pjsua_config ua_cfg; /**< UA config. */
386 unsigned call_cnt; /**< Call counter. */
387 pjsua_call calls[PJSUA_MAX_CALLS];/**< Calls array. */
Benny Prijono5773cd62008-01-19 13:01:42 +0000388 pjsua_call_id next_call_id; /**< Next call id to use*/
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000389
390 /* Buddy; */
391 unsigned buddy_cnt; /**< Buddy count. */
392 pjsua_buddy buddy[PJSUA_MAX_BUDDIES]; /**< Buddy array. */
393
Benny Prijono7a5f5102007-05-29 00:33:09 +0000394 /* Presence: */
395 pj_timer_entry pres_timer;/**< Presence refresh timer. */
396
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000397 /* Media: */
398 pjsua_media_config media_cfg; /**< Media config. */
399 pjmedia_endpt *med_endpt; /**< Media endpoint. */
400 pjsua_conf_setting mconf_cfg; /**< Additionan conf. bridge. param */
401 pjmedia_conf *mconf; /**< Conference bridge. */
Benny Prijonof798e502009-03-09 13:08:16 +0000402 pj_bool_t is_mswitch;/**< Are we using audio switchboard
403 (a.k.a APS-Direct) */
404
405 /* Sound device */
406 pjmedia_aud_dev_index cap_dev; /**< Capture device ID. */
407 pjmedia_aud_dev_index play_dev; /**< Playback device ID. */
408 pj_uint32_t aud_svmask;/**< Which settings to save */
409 pjmedia_aud_param aud_param; /**< User settings to sound dev */
410 pj_bool_t aud_open_cnt;/**< How many # device is opened */
Benny Prijonoe909eac2006-07-27 22:04:56 +0000411 pj_bool_t no_snd; /**< No sound (app will manage it) */
Nanang Izzuddin68559c32008-06-13 17:01:46 +0000412 pj_pool_t *snd_pool; /**< Sound's private pool. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000413 pjmedia_snd_port *snd_port; /**< Sound port. */
Nanang Izzuddin68559c32008-06-13 17:01:46 +0000414 pj_timer_entry snd_idle_timer;/**< Sound device idle timer. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000415 pjmedia_master_port *null_snd; /**< Master port for null sound. */
416 pjmedia_port *null_port; /**< Null port. */
Benny Prijono2d647722011-07-13 03:05:22 +0000417 pj_bool_t snd_is_on; /**< Media flow is currently active */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000418
Nanang Izzuddin50fae732011-03-22 09:49:23 +0000419 /* Video device */
420 pjmedia_vid_dev_index vcap_dev; /**< Capture device ID. */
421 pjmedia_vid_dev_index vrdr_dev; /**< Playback device ID. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000422
423 /* File players: */
424 unsigned player_cnt;/**< Number of file players. */
Benny Prijonocba59d92007-02-16 09:22:56 +0000425 pjsua_file_data player[PJSUA_MAX_PLAYERS];/**< Array of players.*/
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000426
427 /* File recorders: */
428 unsigned rec_cnt; /**< Number of file recorders. */
Benny Prijonocba59d92007-02-16 09:22:56 +0000429 pjsua_file_data recorder[PJSUA_MAX_RECORDERS];/**< Array of recs.*/
Benny Prijono9f468d12011-07-07 07:46:33 +0000430
431 /* Video windows */
432#if PJSUA_HAS_VIDEO
433 pjsua_vid_win win[PJSUA_MAX_VID_WINS]; /**< Array of windows */
434#endif
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000435};
436
437
438extern struct pjsua_data pjsua_var;
439
Benny Prijono44e88ea2007-10-30 15:42:35 +0000440/**
441 * Get the instance of pjsua
442 */
443PJ_DECL(struct pjsua_data*) pjsua_get_var(void);
444
445
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000446
447/**
448 * IM callback data.
449 */
450typedef struct pjsua_im_data
451{
452 pjsua_acc_id acc_id;
453 pjsua_call_id call_id;
454 pj_str_t to;
455 pj_str_t body;
456 void *user_data;
457} pjsua_im_data;
458
459
460/**
461 * Duplicate IM data.
462 */
463PJ_INLINE(pjsua_im_data*) pjsua_im_data_dup(pj_pool_t *pool,
464 const pjsua_im_data *src)
465{
466 pjsua_im_data *dst;
467
Benny Prijono07113c92006-11-21 08:38:00 +0000468 dst = (pjsua_im_data*) pj_pool_alloc(pool, sizeof(*dst));
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000469 dst->acc_id = src->acc_id;
470 dst->call_id = src->call_id;
471 pj_strdup_with_null(pool, &dst->to, &src->to);
472 dst->user_data = src->user_data;
473 pj_strdup_with_null(pool, &dst->body, &src->body);
474
475 return dst;
476}
477
478
Benny Prijono148c9dd2006-09-19 13:37:53 +0000479#if 1
480#define PJSUA_LOCK() pj_mutex_lock(pjsua_var.mutex)
481#define PJSUA_TRY_LOCK() pj_mutex_trylock(pjsua_var.mutex)
482#define PJSUA_UNLOCK() pj_mutex_unlock(pjsua_var.mutex)
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000483#else
484#define PJSUA_LOCK()
Benny Prijono148c9dd2006-09-19 13:37:53 +0000485#define PJSUA_TRY_LOCK() PJ_SUCCESS
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000486#define PJSUA_UNLOCK()
487#endif
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000488
Benny Prijono0bc99a92011-03-17 04:34:43 +0000489/* Core */
490void pjsua_set_state(pjsua_state new_state);
491
Benny Prijonobb995fd2009-08-12 11:03:23 +0000492/******
493 * STUN resolution
494 */
495/* Resolve the STUN server */
496pj_status_t resolve_stun_server(pj_bool_t wait);
497
Benny Prijono91d06b62008-09-20 12:16:56 +0000498/**
499 * Normalize route URI (check for ";lr" and append one if it doesn't
500 * exist and pjsua_config.force_lr is set.
501 */
502pj_status_t normalize_route_uri(pj_pool_t *pool, pj_str_t *uri);
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000503
Benny Prijonoc97608e2007-03-23 16:34:20 +0000504/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000505 * Handle incoming invite request.
506 */
507pj_bool_t pjsua_call_on_incoming(pjsip_rx_data *rdata);
508
Benny Prijonoc97608e2007-03-23 16:34:20 +0000509/*
510 * Media channel.
511 */
512pj_status_t pjsua_media_channel_init(pjsua_call_id call_id,
Benny Prijonod8179652008-01-23 20:39:07 +0000513 pjsip_role_e role,
Benny Prijono25b2ea12008-01-24 19:20:54 +0000514 int security_level,
Benny Prijono224b4e22008-06-19 14:10:28 +0000515 pj_pool_t *tmp_pool,
516 const pjmedia_sdp_session *rem_sdp,
Sauw Ming73ecfe82011-09-21 10:20:01 +0000517 int *sip_err_code,
518 pj_bool_t async,
519 pjsua_med_tp_state_cb cb);
Benny Prijonoc97608e2007-03-23 16:34:20 +0000520pj_status_t pjsua_media_channel_create_sdp(pjsua_call_id call_id,
521 pj_pool_t *pool,
Benny Prijonod8179652008-01-23 20:39:07 +0000522 const pjmedia_sdp_session *rem_sdp,
Benny Prijono25b2ea12008-01-24 19:20:54 +0000523 pjmedia_sdp_session **p_sdp,
524 int *sip_err_code);
Benny Prijonoc97608e2007-03-23 16:34:20 +0000525pj_status_t pjsua_media_channel_update(pjsua_call_id call_id,
Benny Prijono224b4e22008-06-19 14:10:28 +0000526 const pjmedia_sdp_session *local_sdp,
Benny Prijonodbce2cf2007-03-28 16:24:00 +0000527 const pjmedia_sdp_session *remote_sdp);
Benny Prijonoc97608e2007-03-23 16:34:20 +0000528pj_status_t pjsua_media_channel_deinit(pjsua_call_id call_id);
529
Benny Prijonoee0ba182011-07-15 06:18:29 +0000530pj_status_t pjsua_call_media_init(pjsua_call_media *call_med,
531 pjmedia_type type,
532 const pjsua_transport_config *tcfg,
533 int security_level,
Sauw Ming73ecfe82011-09-21 10:20:01 +0000534 int *sip_err_code,
535 pj_bool_t async,
536 pjsua_med_tp_state_cb cb);
Benny Prijonoee0ba182011-07-15 06:18:29 +0000537pj_status_t video_channel_update(pjsua_call_media *call_med,
538 pj_pool_t *tmp_pool,
539 const pjmedia_sdp_session *local_sdp,
540 const pjmedia_sdp_session *remote_sdp);
Nanang Izzuddin250ffa12011-07-15 08:13:11 +0000541void stop_video_stream(pjsua_call_media *call_med);
Sauw Ming73ecfe82011-09-21 10:20:01 +0000542void set_media_tp_state(pjsua_call_media *call_med, pjsua_med_tp_st tp_st);
Benny Prijonoee0ba182011-07-15 06:18:29 +0000543
Benny Prijonoc97608e2007-03-23 16:34:20 +0000544
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000545/**
546 * Init presence.
547 */
548pj_status_t pjsua_pres_init();
549
550/*
551 * Start presence subsystem.
552 */
553pj_status_t pjsua_pres_start(void);
554
555/**
556 * Refresh presence subscriptions
557 */
558void pjsua_pres_refresh(void);
559
560/*
Benny Prijono4461c7d2007-08-25 13:36:15 +0000561 * Update server subscription (e.g. when our online status has changed)
562 */
563void pjsua_pres_update_acc(int acc_id, pj_bool_t force);
564
565/*
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000566 * Shutdown presence.
567 */
568void pjsua_pres_shutdown(void);
569
570/**
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000571 * Init presence for aoocunt.
572 */
573pj_status_t pjsua_pres_init_acc(int acc_id);
574
575/**
Benny Prijono8b6834f2007-02-24 13:29:22 +0000576 * Send PUBLISH
577 */
578pj_status_t pjsua_pres_init_publish_acc(int acc_id);
579
580/**
Benny Prijono166d5022010-02-10 14:24:48 +0000581 * Send un-PUBLISH
582 */
583void pjsua_pres_unpublish(pjsua_acc *acc);
584
585/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000586 * Terminate server subscription for the account
587 */
588void pjsua_pres_delete_acc(int acc_id);
589
590/**
591 * Init IM module handler to handle incoming MESSAGE outside dialog.
592 */
593pj_status_t pjsua_im_init(void);
594
595/**
Benny Prijono4dd961b2009-10-26 11:21:37 +0000596 * Start MWI subscription
597 */
598void pjsua_start_mwi(pjsua_acc *acc);
599
600/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000601 * Init call subsystem.
602 */
603pj_status_t pjsua_call_subsys_init(const pjsua_config *cfg);
604
605/**
606 * Start call subsystem.
607 */
608pj_status_t pjsua_call_subsys_start(void);
609
610/**
611 * Init media subsystems.
612 */
613pj_status_t pjsua_media_subsys_init(const pjsua_media_config *cfg);
614
615/**
616 * Start pjsua media subsystem.
617 */
618pj_status_t pjsua_media_subsys_start(void);
619
620/**
621 * Destroy pjsua media subsystem.
622 */
623pj_status_t pjsua_media_subsys_destroy(void);
624
625/**
626 * Private: check if we can accept the message.
627 * If not, then p_accept header will be filled with a valid
628 * Accept header.
629 */
630pj_bool_t pjsua_im_accept_pager(pjsip_rx_data *rdata,
631 pjsip_accept_hdr **p_accept_hdr);
632
633/**
634 * Private: process pager message.
635 * This may trigger pjsua_ui_on_pager() or pjsua_ui_on_typing().
636 */
637void pjsua_im_process_pager(int call_id, const pj_str_t *from,
638 const pj_str_t *to, pjsip_rx_data *rdata);
639
640
641/**
642 * Create Accept header for MESSAGE.
643 */
644pjsip_accept_hdr* pjsua_im_create_accept(pj_pool_t *pool);
645
646/*
647 * Add additional headers etc in msg_data specified by application
648 * when sending requests.
649 */
650void pjsua_process_msg_data(pjsip_tx_data *tdata,
651 const pjsua_msg_data *msg_data);
652
653
654/*
655 * Add route_set to outgoing requests
656 */
657void pjsua_set_msg_route_set( pjsip_tx_data *tdata,
658 const pjsip_route_hdr *route_set );
659
660
661/*
662 * Simple version of MIME type parsing (it doesn't support parameters)
663 */
664void pjsua_parse_media_type( pj_pool_t *pool,
665 const pj_str_t *mime,
666 pjsip_media_type *media_type);
667
668
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000669/*
670 * Internal function to init transport selector from transport id.
671 */
672void pjsua_init_tpselector(pjsua_transport_id tp_id,
673 pjsip_tpselector *sel);
674
Benny Prijono3c5e28b2008-09-24 10:10:15 +0000675pjsip_dialog* on_dlg_forked(pjsip_dialog *first_set, pjsip_rx_data *res);
Benny Prijono627cbb42007-09-25 20:48:49 +0000676pj_status_t acquire_call(const char *title,
677 pjsua_call_id call_id,
678 pjsua_call **p_call,
679 pjsip_dialog **p_dlg);
680const char *good_number(char *buf, pj_int32_t val);
681void print_call(const char *title,
682 int call_id,
683 char *buf, pj_size_t size);
684
Benny Prijono9f468d12011-07-07 07:46:33 +0000685/*
686 * Video
687 */
688pj_status_t pjsua_vid_subsys_init(void);
689pj_status_t pjsua_vid_subsys_start(void);
690pj_status_t pjsua_vid_subsys_destroy(void);
691
Benny Prijono9f468d12011-07-07 07:46:33 +0000692#if PJSUA_HAS_VIDEO
Benny Prijonoaa15fbb2011-09-19 08:26:35 +0000693PJ_DECL(void) pjsua_vid_win_reset(pjsua_vid_win_id wid);
Nanang Izzuddind93c68a2011-07-19 08:40:20 +0000694#else
Benny Prijonoaa15fbb2011-09-19 08:26:35 +0000695# define pjsua_vid_win_reset(wid)
Benny Prijono9f468d12011-07-07 07:46:33 +0000696#endif
Benny Prijono9f468d12011-07-07 07:46:33 +0000697
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000698
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000699PJ_END_DECL
700
701#endif /* __PJSUA_INTERNAL_H__ */
702