blob: 4dd9e9dcab14d1080b830216cae564c9951ed81d [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
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. */
101} pjsua_call_media;
102
103/**
104 * Maximum number of SDP "m=" lines to be supported.
105 */
106#define PJSUA_MAX_CALL_MEDIA PJMEDIA_MAX_SDP_MEDIA
107
Benny Prijono224b4e22008-06-19 14:10:28 +0000108/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000109 * Structure to be attached to invite dialog.
110 * Given a dialog "dlg", application can retrieve this structure
111 * by accessing dlg->mod_data[pjsua.mod.id].
112 */
Benny Prijono0bc99a92011-03-17 04:34:43 +0000113struct pjsua_call
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000114{
115 unsigned index; /**< Index in pjsua array. */
116 pjsip_inv_session *inv; /**< The invite session. */
117 void *user_data; /**< User/application data. */
118 pjsip_status_code last_code; /**< Last status code seen. */
119 pj_str_t last_text; /**< Last status text seen. */
120 pj_time_val start_time;/**< First INVITE sent/received. */
121 pj_time_val res_time; /**< First response sent/received. */
122 pj_time_val conn_time; /**< Connected/confirmed time. */
123 pj_time_val dis_time; /**< Disconnect time. */
124 pjsua_acc_id acc_id; /**< Account index being used. */
Benny Prijonodb844a42008-02-02 17:07:18 +0000125 int secure_level;/**< Signaling security level. */
Benny Prijonodd63b992010-10-01 02:03:42 +0000126 pjsua_call_hold_type call_hold_type; /**< How to do call hold. */
Nanang Izzuddin99d69522008-08-04 15:01:38 +0000127 pj_bool_t local_hold;/**< Flag for call-hold by local. */
Benny Prijono0bc99a92011-03-17 04:34:43 +0000128
129 unsigned med_cnt; /**< Number of media in SDP. */
130 pjsua_call_media media[PJSUA_MAX_CALL_MEDIA]; /**< Array of media */
Nanang Izzuddinbf26db12011-03-18 07:54:50 +0000131 int audio_idx; /**< First active audio media. */
Benny Prijono0bc99a92011-03-17 04:34:43 +0000132
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000133 pjsip_evsub *xfer_sub; /**< Xfer server subscription, if this
134 call was triggered by xfer. */
Benny Prijono91a6a172007-10-31 08:59:29 +0000135 pj_stun_nat_type rem_nat_type; /**< NAT type of remote endpoint. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000136
137 char last_text_buf_[128]; /**< Buffer for last_text. */
138
Nanang Izzuddin93bacd02010-06-15 09:56:39 +0000139 struct {
140 pj_timer_entry reinv_timer;/**< Reinvite retry timer. */
Benny Prijono1e601552010-10-20 05:31:08 +0000141 pj_uint32_t sdp_ver; /**< SDP version of the bad answer */
142 int retry_cnt; /**< Retry count. */
Nanang Izzuddinec919002010-11-25 09:27:06 +0000143 pj_bool_t pending; /**< Pending until CONFIRMED state */
Nanang Izzuddin93bacd02010-06-15 09:56:39 +0000144 } lock_codec; /**< Data for codec locking when answer
145 contains multiple codecs. */
146
Benny Prijono0bc99a92011-03-17 04:34:43 +0000147};
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000148
149
150/**
151 * Server presence subscription list head.
152 */
Benny Prijono63fba012008-07-17 14:19:10 +0000153struct pjsua_srv_pres
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000154{
155 PJ_DECL_LIST_MEMBER(struct pjsua_srv_pres);
Benny Prijono63fba012008-07-17 14:19:10 +0000156 pjsip_evsub *sub; /**< The evsub. */
157 char *remote; /**< Remote URI. */
158 int acc_id; /**< Account ID. */
159 pjsip_dialog *dlg; /**< Dialog. */
160 int expires; /**< "expires" value in the request. */
161};
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000162
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000163/**
164 * Account
165 */
166typedef struct pjsua_acc
167{
Benny Prijonoc91ed8d2008-07-13 12:24:55 +0000168 pj_pool_t *pool; /**< Pool for this account. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000169 pjsua_acc_config cfg; /**< Account configuration. */
170 pj_bool_t valid; /**< Is this account valid? */
171
172 int index; /**< Index in accounts array. */
Benny Prijonoc570f2d2006-07-18 00:33:02 +0000173 pj_str_t display; /**< Display name, if any. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000174 pj_str_t user_part; /**< User part of local URI. */
Nanang Izzuddin5af37ff2009-08-05 18:41:23 +0000175 pj_str_t contact; /**< Our Contact header. */
Benny Prijonob54719f2010-11-16 03:07:46 +0000176 pj_str_t reg_contact; /**< Contact header for REGISTER.
177 It may be different than acc
178 contact if outbound is used */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000179
Benny Prijonob4a17c92006-07-10 14:40:21 +0000180 pj_str_t srv_domain; /**< Host part of reg server. */
181 int srv_port; /**< Port number of reg server. */
182
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000183 pjsip_regc *regc; /**< Client registration session. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000184 pj_status_t reg_last_err; /**< Last registration error. */
185 int reg_last_code; /**< Last status last register. */
186
Nanang Izzuddin36dd5b62010-03-30 11:13:59 +0000187 struct {
188 pj_bool_t active; /**< Flag of reregister status. */
189 pj_timer_entry timer; /**< Timer for reregistration. */
190 void *reg_tp; /**< Transport for registration. */
191 unsigned attempt_cnt; /**< Attempt counter. */
192 } auto_rereg; /**< Reregister/reconnect data. */
193
Benny Prijonobddef2c2007-10-31 13:28:08 +0000194 pj_timer_entry ka_timer; /**< Keep-alive timer for UDP. */
195 pjsip_transport *ka_transport; /**< Transport for keep-alive. */
196 pj_sockaddr ka_target; /**< Destination address for K-A */
197 unsigned ka_target_len; /**< Length of ka_target. */
198
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000199 pjsip_route_hdr route_set; /**< Complete route set inc. outbnd.*/
Nanang Izzuddinc3ea16a2010-04-20 14:36:38 +0000200 pj_uint32_t global_route_crc; /** CRC of global route setting. */
201 pj_uint32_t local_route_crc; /** CRC of account route setting.*/
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000202
Benny Prijonob54719f2010-11-16 03:07:46 +0000203 unsigned rfc5626_status;/**< SIP outbound status:
204 0: not used
205 1: requested
206 2: acknowledged by servers */
207 pj_str_t rfc5626_instprm;/**< SIP outbound instance param. */
208 pj_str_t rfc5626_regprm;/**< SIP outbound reg param. */
209
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000210 unsigned cred_cnt; /**< Number of credentials. */
211 pjsip_cred_info cred[PJSUA_ACC_MAX_PROXIES]; /**< Complete creds. */
212
213 pj_bool_t online_status; /**< Our online status. */
Benny Prijono4461c7d2007-08-25 13:36:15 +0000214 pjrpid_element rpid; /**< RPID element information. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000215 pjsua_srv_pres pres_srv_list; /**< Server subscription list. */
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000216 pjsip_publishc *publish_sess; /**< Client publication session. */
217 pj_bool_t publish_state; /**< Last published online status */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000218
Benny Prijono4dd961b2009-10-26 11:21:37 +0000219 pjsip_evsub *mwi_sub; /**< MWI client subscription */
220 pjsip_dialog *mwi_dlg; /**< Dialog for MWI sub. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000221} pjsua_acc;
222
223
224/**
225 *Transport.
226 */
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000227typedef struct pjsua_transport_data
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000228{
Benny Prijonoe93e2872006-06-28 16:46:49 +0000229 int index;
230 pjsip_transport_type_e type;
231 pjsip_host_port local_name;
232
233 union {
234 pjsip_transport *tp;
235 pjsip_tpfactory *factory;
236 void *ptr;
237 } data;
238
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000239} pjsua_transport_data;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000240
241
Benny Prijono63fba012008-07-17 14:19:10 +0000242/** Maximum length of subscription termination reason. */
243#define PJSUA_BUDDY_SUB_TERM_REASON_LEN 32
244
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000245/**
246 * Buddy data.
247 */
248typedef struct pjsua_buddy
249{
Benny Prijonoc91ed8d2008-07-13 12:24:55 +0000250 pj_pool_t *pool; /**< Pool for this buddy. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000251 unsigned index; /**< Buddy index. */
Benny Prijono705e7842008-07-21 18:12:51 +0000252 void *user_data; /**< Application data. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000253 pj_str_t uri; /**< Buddy URI. */
254 pj_str_t contact; /**< Contact learned from subscrp. */
255 pj_str_t name; /**< Buddy name. */
256 pj_str_t display; /**< Buddy display name. */
257 pj_str_t host; /**< Buddy host. */
258 unsigned port; /**< Buddy port. */
259 pj_bool_t monitor; /**< Should we monitor? */
Benny Prijonof9c40c32007-06-28 07:20:26 +0000260 pjsip_dialog *dlg; /**< The underlying dialog. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000261 pjsip_evsub *sub; /**< Buddy presence subscription */
Benny Prijono73bb7232009-10-20 13:56:26 +0000262 unsigned term_code; /**< Subscription termination code */
Benny Prijono63fba012008-07-17 14:19:10 +0000263 pj_str_t term_reason;/**< Subscription termination reason */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000264 pjsip_pres_status status; /**< Buddy presence status. */
Benny Prijono73bb7232009-10-20 13:56:26 +0000265 pj_timer_entry timer; /**< Resubscription timer */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000266} pjsua_buddy;
267
268
269/**
270 * File player/recorder data.
271 */
272typedef struct pjsua_file_data
273{
Benny Prijonoa66c3312007-01-21 23:12:40 +0000274 pj_bool_t type; /* 0=player, 1=playlist */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000275 pjmedia_port *port;
Benny Prijonod5696da2007-07-17 16:25:45 +0000276 pj_pool_t *pool;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000277 unsigned slot;
278} pjsua_file_data;
279
280
281/**
282 * Additional parameters for conference bridge.
283 */
284typedef struct pjsua_conf_setting
285{
286 unsigned channel_count;
287 unsigned samples_per_frame;
288 unsigned bits_per_sample;
289} pjsua_conf_setting;
290
Benny Prijonobb995fd2009-08-12 11:03:23 +0000291typedef struct pjsua_stun_resolve
292{
293 PJ_DECL_LIST_MEMBER(struct pjsua_stun_resolve);
294
295 pj_pool_t *pool; /**< Pool */
296 unsigned count; /**< # of entries */
297 pj_str_t *srv; /**< Array of entries */
298 unsigned idx; /**< Current index */
299 void *token; /**< App token */
300 pj_stun_resolve_cb cb; /**< App callback */
301 pj_bool_t blocking; /**< Blocking? */
302 pj_status_t status; /**< Session status */
303 pj_sockaddr addr; /**< Result */
304 pj_stun_sock *stun_sock; /**< Testing STUN sock */
305} pjsua_stun_resolve;
306
Benny Prijono9f468d12011-07-07 07:46:33 +0000307typedef enum pjsua_vid_win_type
308{
309 PJSUA_WND_TYPE_NONE,
310 PJSUA_WND_TYPE_PREVIEW,
311 PJSUA_WND_TYPE_STREAM
312} pjsua_vid_win_type;
313
314typedef struct pjsua_vid_win
315{
316 pjsua_vid_win_type type; /**< Type. */
317 pj_pool_t *pool; /**< Own pool. */
Nanang Izzuddin62053a62011-07-12 11:08:32 +0000318 unsigned ref_cnt; /**< Reference counter. */
Benny Prijono9f468d12011-07-07 07:46:33 +0000319 pjmedia_vid_port *vp_cap; /**< Capture vidport. */
320 pjmedia_vid_port *vp_rend; /**< Renderer vidport */
Nanang Izzuddin62053a62011-07-12 11:08:32 +0000321 pjmedia_port *tee; /**< Video tee */
Benny Prijono9f468d12011-07-07 07:46:33 +0000322 pjmedia_vid_dev_index preview_cap_id;/* Capture dev id */
323} pjsua_vid_win;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000324
325/**
326 * Global pjsua application data.
327 */
328struct pjsua_data
329{
330
331 /* Control: */
332 pj_caching_pool cp; /**< Global pool factory. */
333 pj_pool_t *pool; /**< pjsua's private pool. */
334 pj_mutex_t *mutex; /**< Mutex protection for this data */
Benny Prijono0bc99a92011-03-17 04:34:43 +0000335 pjsua_state state; /**< Library state. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000336
337 /* Logging: */
338 pjsua_logging_config log_cfg; /**< Current logging config. */
339 pj_oshandle_t log_file; /**<Output log file handle */
340
341 /* SIP: */
342 pjsip_endpoint *endpt; /**< Global endpoint. */
343 pjsip_module mod; /**< pjsua's PJSIP module. */
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000344 pjsua_transport_data tpdata[8]; /**< Array of transports. */
Benny Prijono21407322010-03-10 13:33:25 +0000345 pjsip_tp_state_callback old_tp_cb; /**< Old transport callback. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000346
347 /* Threading: */
348 pj_bool_t thread_quit_flag; /**< Thread quit flag. */
349 pj_thread_t *thread[4]; /**< Array of threads. */
350
Benny Prijonoc97608e2007-03-23 16:34:20 +0000351 /* STUN and resolver */
352 pj_stun_config stun_cfg; /**< Global STUN settings. */
353 pj_sockaddr stun_srv; /**< Resolved STUN server address */
354 pj_status_t stun_status; /**< STUN server status. */
Benny Prijonobb995fd2009-08-12 11:03:23 +0000355 pjsua_stun_resolve stun_res; /**< List of pending STUN resolution*/
Benny Prijonoc97608e2007-03-23 16:34:20 +0000356 pj_dns_resolver *resolver; /**< DNS resolver. */
357
Benny Prijono6ba8c542007-10-16 01:34:14 +0000358 /* Detected NAT type */
359 pj_stun_nat_type nat_type; /**< NAT type. */
360 pj_status_t nat_status; /**< Detection status. */
361 pj_bool_t nat_in_progress; /**< Detection in progress */
362
Benny Prijono29c8ca32010-06-22 06:02:13 +0000363 /* List of outbound proxies: */
364 pjsip_route_hdr outbound_proxy;
365
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000366 /* Account: */
367 unsigned acc_cnt; /**< Number of accounts. */
368 pjsua_acc_id default_acc; /**< Default account ID */
369 pjsua_acc acc[PJSUA_MAX_ACC]; /**< Account array. */
Benny Prijono093d3022006-09-24 00:07:11 +0000370 pjsua_acc_id acc_ids[PJSUA_MAX_ACC]; /**< Acc sorted by prio*/
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000371
372 /* Calls: */
373 pjsua_config ua_cfg; /**< UA config. */
374 unsigned call_cnt; /**< Call counter. */
375 pjsua_call calls[PJSUA_MAX_CALLS];/**< Calls array. */
Benny Prijono5773cd62008-01-19 13:01:42 +0000376 pjsua_call_id next_call_id; /**< Next call id to use*/
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000377
378 /* Buddy; */
379 unsigned buddy_cnt; /**< Buddy count. */
380 pjsua_buddy buddy[PJSUA_MAX_BUDDIES]; /**< Buddy array. */
381
Benny Prijono7a5f5102007-05-29 00:33:09 +0000382 /* Presence: */
383 pj_timer_entry pres_timer;/**< Presence refresh timer. */
384
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000385 /* Media: */
386 pjsua_media_config media_cfg; /**< Media config. */
387 pjmedia_endpt *med_endpt; /**< Media endpoint. */
388 pjsua_conf_setting mconf_cfg; /**< Additionan conf. bridge. param */
389 pjmedia_conf *mconf; /**< Conference bridge. */
Benny Prijonof798e502009-03-09 13:08:16 +0000390 pj_bool_t is_mswitch;/**< Are we using audio switchboard
391 (a.k.a APS-Direct) */
392
393 /* Sound device */
394 pjmedia_aud_dev_index cap_dev; /**< Capture device ID. */
395 pjmedia_aud_dev_index play_dev; /**< Playback device ID. */
396 pj_uint32_t aud_svmask;/**< Which settings to save */
397 pjmedia_aud_param aud_param; /**< User settings to sound dev */
398 pj_bool_t aud_open_cnt;/**< How many # device is opened */
Benny Prijonoe909eac2006-07-27 22:04:56 +0000399 pj_bool_t no_snd; /**< No sound (app will manage it) */
Nanang Izzuddin68559c32008-06-13 17:01:46 +0000400 pj_pool_t *snd_pool; /**< Sound's private pool. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000401 pjmedia_snd_port *snd_port; /**< Sound port. */
Nanang Izzuddin68559c32008-06-13 17:01:46 +0000402 pj_timer_entry snd_idle_timer;/**< Sound device idle timer. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000403 pjmedia_master_port *null_snd; /**< Master port for null sound. */
404 pjmedia_port *null_port; /**< Null port. */
Benny Prijono2d647722011-07-13 03:05:22 +0000405 pj_bool_t snd_is_on; /**< Media flow is currently active */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000406
Nanang Izzuddin50fae732011-03-22 09:49:23 +0000407 /* Video device */
408 pjmedia_vid_dev_index vcap_dev; /**< Capture device ID. */
409 pjmedia_vid_dev_index vrdr_dev; /**< Playback device ID. */
410
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000411 /* File players: */
412 unsigned player_cnt;/**< Number of file players. */
Benny Prijonocba59d92007-02-16 09:22:56 +0000413 pjsua_file_data player[PJSUA_MAX_PLAYERS];/**< Array of players.*/
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000414
415 /* File recorders: */
416 unsigned rec_cnt; /**< Number of file recorders. */
Benny Prijonocba59d92007-02-16 09:22:56 +0000417 pjsua_file_data recorder[PJSUA_MAX_RECORDERS];/**< Array of recs.*/
Benny Prijono9f468d12011-07-07 07:46:33 +0000418
419 /* Video windows */
420#if PJSUA_HAS_VIDEO
421 pjsua_vid_win win[PJSUA_MAX_VID_WINS]; /**< Array of windows */
422#endif
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000423};
424
425
426extern struct pjsua_data pjsua_var;
427
Benny Prijono44e88ea2007-10-30 15:42:35 +0000428/**
429 * Get the instance of pjsua
430 */
431PJ_DECL(struct pjsua_data*) pjsua_get_var(void);
432
433
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000434
435/**
436 * IM callback data.
437 */
438typedef struct pjsua_im_data
439{
440 pjsua_acc_id acc_id;
441 pjsua_call_id call_id;
442 pj_str_t to;
443 pj_str_t body;
444 void *user_data;
445} pjsua_im_data;
446
447
448/**
449 * Duplicate IM data.
450 */
451PJ_INLINE(pjsua_im_data*) pjsua_im_data_dup(pj_pool_t *pool,
452 const pjsua_im_data *src)
453{
454 pjsua_im_data *dst;
455
Benny Prijono07113c92006-11-21 08:38:00 +0000456 dst = (pjsua_im_data*) pj_pool_alloc(pool, sizeof(*dst));
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000457 dst->acc_id = src->acc_id;
458 dst->call_id = src->call_id;
459 pj_strdup_with_null(pool, &dst->to, &src->to);
460 dst->user_data = src->user_data;
461 pj_strdup_with_null(pool, &dst->body, &src->body);
462
463 return dst;
464}
465
466
Benny Prijono148c9dd2006-09-19 13:37:53 +0000467#if 1
468#define PJSUA_LOCK() pj_mutex_lock(pjsua_var.mutex)
469#define PJSUA_TRY_LOCK() pj_mutex_trylock(pjsua_var.mutex)
470#define PJSUA_UNLOCK() pj_mutex_unlock(pjsua_var.mutex)
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000471#else
472#define PJSUA_LOCK()
Benny Prijono148c9dd2006-09-19 13:37:53 +0000473#define PJSUA_TRY_LOCK() PJ_SUCCESS
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000474#define PJSUA_UNLOCK()
475#endif
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000476
Benny Prijono0bc99a92011-03-17 04:34:43 +0000477/* Core */
478void pjsua_set_state(pjsua_state new_state);
479
Benny Prijonobb995fd2009-08-12 11:03:23 +0000480/******
481 * STUN resolution
482 */
483/* Resolve the STUN server */
484pj_status_t resolve_stun_server(pj_bool_t wait);
485
Benny Prijono91d06b62008-09-20 12:16:56 +0000486/**
487 * Normalize route URI (check for ";lr" and append one if it doesn't
488 * exist and pjsua_config.force_lr is set.
489 */
490pj_status_t normalize_route_uri(pj_pool_t *pool, pj_str_t *uri);
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000491
Benny Prijonoc97608e2007-03-23 16:34:20 +0000492/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000493 * Handle incoming invite request.
494 */
495pj_bool_t pjsua_call_on_incoming(pjsip_rx_data *rdata);
496
Benny Prijonoc97608e2007-03-23 16:34:20 +0000497/*
498 * Media channel.
499 */
500pj_status_t pjsua_media_channel_init(pjsua_call_id call_id,
Benny Prijonod8179652008-01-23 20:39:07 +0000501 pjsip_role_e role,
Benny Prijono25b2ea12008-01-24 19:20:54 +0000502 int security_level,
Benny Prijono224b4e22008-06-19 14:10:28 +0000503 pj_pool_t *tmp_pool,
504 const pjmedia_sdp_session *rem_sdp,
Benny Prijono25b2ea12008-01-24 19:20:54 +0000505 int *sip_err_code);
Benny Prijonoc97608e2007-03-23 16:34:20 +0000506pj_status_t pjsua_media_channel_create_sdp(pjsua_call_id call_id,
507 pj_pool_t *pool,
Benny Prijonod8179652008-01-23 20:39:07 +0000508 const pjmedia_sdp_session *rem_sdp,
Benny Prijono25b2ea12008-01-24 19:20:54 +0000509 pjmedia_sdp_session **p_sdp,
510 int *sip_err_code);
Benny Prijonoc97608e2007-03-23 16:34:20 +0000511pj_status_t pjsua_media_channel_update(pjsua_call_id call_id,
Benny Prijono224b4e22008-06-19 14:10:28 +0000512 const pjmedia_sdp_session *local_sdp,
Benny Prijonodbce2cf2007-03-28 16:24:00 +0000513 const pjmedia_sdp_session *remote_sdp);
Benny Prijonoc97608e2007-03-23 16:34:20 +0000514pj_status_t pjsua_media_channel_deinit(pjsua_call_id call_id);
515
516
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000517/**
518 * Init presence.
519 */
520pj_status_t pjsua_pres_init();
521
522/*
523 * Start presence subsystem.
524 */
525pj_status_t pjsua_pres_start(void);
526
527/**
528 * Refresh presence subscriptions
529 */
530void pjsua_pres_refresh(void);
531
532/*
Benny Prijono4461c7d2007-08-25 13:36:15 +0000533 * Update server subscription (e.g. when our online status has changed)
534 */
535void pjsua_pres_update_acc(int acc_id, pj_bool_t force);
536
537/*
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000538 * Shutdown presence.
539 */
540void pjsua_pres_shutdown(void);
541
542/**
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000543 * Init presence for aoocunt.
544 */
545pj_status_t pjsua_pres_init_acc(int acc_id);
546
547/**
Benny Prijono8b6834f2007-02-24 13:29:22 +0000548 * Send PUBLISH
549 */
550pj_status_t pjsua_pres_init_publish_acc(int acc_id);
551
552/**
Benny Prijono166d5022010-02-10 14:24:48 +0000553 * Send un-PUBLISH
554 */
555void pjsua_pres_unpublish(pjsua_acc *acc);
556
557/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000558 * Terminate server subscription for the account
559 */
560void pjsua_pres_delete_acc(int acc_id);
561
562/**
563 * Init IM module handler to handle incoming MESSAGE outside dialog.
564 */
565pj_status_t pjsua_im_init(void);
566
567/**
Benny Prijono4dd961b2009-10-26 11:21:37 +0000568 * Start MWI subscription
569 */
570void pjsua_start_mwi(pjsua_acc *acc);
571
572/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000573 * Init call subsystem.
574 */
575pj_status_t pjsua_call_subsys_init(const pjsua_config *cfg);
576
577/**
578 * Start call subsystem.
579 */
580pj_status_t pjsua_call_subsys_start(void);
581
582/**
583 * Init media subsystems.
584 */
585pj_status_t pjsua_media_subsys_init(const pjsua_media_config *cfg);
586
587/**
588 * Start pjsua media subsystem.
589 */
590pj_status_t pjsua_media_subsys_start(void);
591
592/**
593 * Destroy pjsua media subsystem.
594 */
595pj_status_t pjsua_media_subsys_destroy(void);
596
597/**
598 * Private: check if we can accept the message.
599 * If not, then p_accept header will be filled with a valid
600 * Accept header.
601 */
602pj_bool_t pjsua_im_accept_pager(pjsip_rx_data *rdata,
603 pjsip_accept_hdr **p_accept_hdr);
604
605/**
606 * Private: process pager message.
607 * This may trigger pjsua_ui_on_pager() or pjsua_ui_on_typing().
608 */
609void pjsua_im_process_pager(int call_id, const pj_str_t *from,
610 const pj_str_t *to, pjsip_rx_data *rdata);
611
612
613/**
614 * Create Accept header for MESSAGE.
615 */
616pjsip_accept_hdr* pjsua_im_create_accept(pj_pool_t *pool);
617
618/*
619 * Add additional headers etc in msg_data specified by application
620 * when sending requests.
621 */
622void pjsua_process_msg_data(pjsip_tx_data *tdata,
623 const pjsua_msg_data *msg_data);
624
625
626/*
627 * Add route_set to outgoing requests
628 */
629void pjsua_set_msg_route_set( pjsip_tx_data *tdata,
630 const pjsip_route_hdr *route_set );
631
632
633/*
634 * Simple version of MIME type parsing (it doesn't support parameters)
635 */
636void pjsua_parse_media_type( pj_pool_t *pool,
637 const pj_str_t *mime,
638 pjsip_media_type *media_type);
639
640
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000641/*
642 * Internal function to init transport selector from transport id.
643 */
644void pjsua_init_tpselector(pjsua_transport_id tp_id,
645 pjsip_tpselector *sel);
646
Benny Prijono3c5e28b2008-09-24 10:10:15 +0000647pjsip_dialog* on_dlg_forked(pjsip_dialog *first_set, pjsip_rx_data *res);
Benny Prijono627cbb42007-09-25 20:48:49 +0000648pj_status_t acquire_call(const char *title,
649 pjsua_call_id call_id,
650 pjsua_call **p_call,
651 pjsip_dialog **p_dlg);
652const char *good_number(char *buf, pj_int32_t val);
653void print_call(const char *title,
654 int call_id,
655 char *buf, pj_size_t size);
656
Benny Prijono9f468d12011-07-07 07:46:33 +0000657/*
658 * Video
659 */
660pj_status_t pjsua_vid_subsys_init(void);
661pj_status_t pjsua_vid_subsys_start(void);
662pj_status_t pjsua_vid_subsys_destroy(void);
663
664PJ_INLINE(void) pjsua_vid_win_reset(pjsua_vid_win_id wid)
665{
666#if PJSUA_HAS_VIDEO
667 pjsua_vid_win *w = &pjsua_var.win[wid];
668 pj_pool_t *pool = w->pool;
669
670 pj_bzero(w, sizeof(*w));
671 if (pool) pj_pool_reset(pool);
Nanang Izzuddin62053a62011-07-12 11:08:32 +0000672 w->ref_cnt = 0;
Benny Prijono9f468d12011-07-07 07:46:33 +0000673 w->pool = pool;
674 w->preview_cap_id = PJMEDIA_VID_INVALID_DEV;
675#endif
676}
677
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000678
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000679PJ_END_DECL
680
681#endif /* __PJSUA_INTERNAL_H__ */
682