1 /* $Id$ */
2 /*
3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5 *
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
28 PJ_BEGIN_DECL
29
30 /** Forward decl of pjsua call */
31 typedef struct pjsua_call pjsua_call;
32
33 /** Forward decl of pjsua call media */
34 typedef struct pjsua_call_media pjsua_call_media;
35
36
37 /**
38 * Call's media stream.
39 */
40 struct pjsua_call_media
41 {
42 pjsua_call *call; /**< Parent call. */
43 pjmedia_type type; /**< Media type. */
44 unsigned idx; /**< This media index in parent call. */
45 pj_str_t rem_mid; /**< Remote SDP "a=mid" attribute. */
46 pjsua_call_media_status state; /**< Media state. */
47 pjsua_call_media_status prev_state;/**< Previous media state. */
48 pjmedia_dir dir; /**< Media direction. */
49
50 /** The stream */
51 struct {
52 /** Audio stream */
53 struct {
54 pjmedia_stream *stream; /**< The audio stream. */
55 pjmedia_port *media_port;/**< The media port. */
56 pj_bool_t destroy_port;/**< Destroy the media port? */
57 int conf_slot; /**< Slot # in conference bridge. */
58 } a;
59
60 /** Video stream */
61 struct {
62 pjmedia_vid_stream *stream; /**< The video stream. */
63 pjsua_conf_port_id strm_enc_slot; /**< Stream encode slot */
64 pjsua_conf_port_id strm_dec_slot; /**< Stream decode slot */
65 pjsua_vid_win_id cap_win_id;/**< The video capture window */
66 pjsua_vid_win_id rdr_win_id;/**< The video render window */
67 pjmedia_vid_dev_index cap_dev; /**< The video capture device */
68 pjmedia_vid_dev_index rdr_dev; /**< The video-in render device */
69 } v;
70
71 } strm;
72
73 pj_uint32_t ssrc; /**< RTP SSRC */
74 pj_uint32_t rtp_tx_ts; /**< Initial RTP timestamp for sender. */
75 pj_uint16_t rtp_tx_seq;/**< Initial RTP sequence for sender. */
76 pj_uint8_t rtp_tx_seq_ts_set;
77 /**< Bitmask flags if initial RTP sequence
78 and/or timestamp for sender are set.
79 bit 0/LSB : sequence flag
80 bit 1 : timestamp flag */
81
82 pjmedia_transport *tp; /**< Current media transport (can be 0) */
83 pj_status_t tp_ready; /**< Media transport status. */
84 pj_status_t tp_result; /**< Media transport creation result. */
85 pjmedia_transport *tp_orig; /**< Original media transport */
86 pj_bool_t tp_auto_del; /**< May delete media transport */
87 pjsua_med_tp_st tp_st; /**< Media transport state */
88 pj_bool_t use_custom_med_tp;/**< Use custom media transport? */
89 pj_bool_t enable_rtcp_mux;/**< Enable RTP& RTCP multiplexing?*/
90 pj_sockaddr rtp_addr; /**< Current RTP source address
91 (used to update ICE default
92 address) */
93 pjmedia_srtp_use rem_srtp_use; /**< Remote's SRTP usage policy. */
94 pj_timestamp last_req_keyframe;/**< Last TX keyframe request. */
95
96 pjsua_med_tp_state_cb med_init_cb;/**< Media transport
97 initialization callback. */
98
99 /** Media transport creation callback. */
100 pj_status_t (*med_create_cb)(pjsua_call_media *call_med,
101 pj_status_t status, int security_level,
102 int *sip_err_code);
103 };
104
105 /**
106 * Maximum number of SDP "m=" lines to be supported.
107 */
108 #define PJSUA_MAX_CALL_MEDIA PJMEDIA_MAX_SDP_MEDIA
109
110 /* Call answer's list. */
111 typedef struct call_answer
112 {
113 PJ_DECL_LIST_MEMBER(struct call_answer);
114 pjsua_msg_data *msg_data; /**< Answer's headers list. */
115 pj_str_t *reason; /**< Answer's reason phrase. */
116 unsigned code; /**< Answer's status code. */
117 pjsua_call_setting *opt; /**< Answer's call setting. */
118 } call_answer;
119
120
121 /* Generic states */
122 typedef enum pjsua_op_state {
123 PJSUA_OP_STATE_NULL,
124 PJSUA_OP_STATE_READY,
125 PJSUA_OP_STATE_RUNNING,
126 PJSUA_OP_STATE_DONE,
127 } pjsua_op_state;
128
129 /**
130 * Structure to be attached to invite dialog.
131 * Given a dialog "dlg", application can retrieve this structure
132 * by accessing dlg->mod_data[pjsua.mod.id].
133 */
134 struct pjsua_call
135 {
136 unsigned index; /**< Index in pjsua array. */
137 pjsua_call_setting opt; /**< Call setting. */
138 pj_bool_t opt_inited;/**< Initial call setting has been set,
139 to avoid different opt in answer. */
140 pjsip_inv_session *inv; /**< The invite session. */
141 void *user_data; /**< User/application data. */
142 pjsip_status_code last_code; /**< Last status code seen. */
143 pj_str_t last_text; /**< Last status text seen. */
144 pj_time_val start_time;/**< First INVITE sent/received. */
145 pj_time_val res_time; /**< First response sent/received. */
146 pj_time_val conn_time; /**< Connected/confirmed time. */
147 pj_time_val dis_time; /**< Disconnect time. */
148 pjsua_acc_id acc_id; /**< Account index being used. */
149 int secure_level;/**< Signaling security level. */
150 pjsua_call_hold_type call_hold_type; /**< How to do call hold. */
151 pj_bool_t local_hold;/**< Flag for call-hold by local. */
152 void *hold_msg; /**< Outgoing hold tx_data. */
153 pj_str_t cname; /**< RTCP CNAME. */
154 char cname_buf[16];/**< cname buffer. */
155
156 unsigned med_cnt; /**< Number of media in SDP. */
157 pjsua_call_media media[PJSUA_MAX_CALL_MEDIA]; /**< Array of media */
158 unsigned med_prov_cnt;/**< Number of provisional media. */
159 pjsua_call_media media_prov[PJSUA_MAX_CALL_MEDIA];
160 /**< Array of provisional media. */
161 pj_bool_t med_update_success;
162 /**< Is media update successful? */
163 pj_bool_t hanging_up;/**< Is call in the process of hangup? */
164
165 int audio_idx; /**< First active audio media. */
166 pj_mutex_t *med_ch_mutex;/**< Media channel callback's mutex. */
167 pjsua_med_tp_state_cb med_ch_cb;/**< Media channel callback. */
168 pjsua_med_tp_state_info med_ch_info;/**< Media channel info. */
169
170 pjsip_evsub *xfer_sub; /**< Xfer server subscription, if this
171 call was triggered by xfer. */
172 pj_stun_nat_type rem_nat_type; /**< NAT type of remote endpoint. */
173
174 char last_text_buf_[128]; /**< Buffer for last_text. */
175
176 struct {
177 int retry_cnt; /**< Retry count. */
178 } lock_codec; /**< Data for codec locking when answer
179 contains multiple codecs. */
180
181 struct {
182 pjsip_dialog *dlg; /**< Call dialog. */
183 pjmedia_sdp_session *rem_sdp;/**< Remote SDP. */
184 pj_pool_t *pool_prov;/**< Provisional pool. */
185 pj_bool_t med_ch_deinit;/**< Media channel de-init-ed? */
186 union {
187 struct {
188 pjsua_msg_data *msg_data;/**< Headers for outgoing INVITE. */
189 pj_bool_t hangup; /**< Call is hangup? */
190 } out_call;
191 struct {
192 call_answer answers;/**< A list of call answers. */
193 pj_bool_t hangup;/**< Call is hangup? */
194 pjsip_dialog *replaced_dlg; /**< Replaced dialog. */
195 } inc_call;
196 } call_var;
197 } async_call; /**< Temporary storage for async
198 outgoing/incoming call. */
199
200 pj_bool_t rem_offerer; /**< Was remote SDP offerer? */
201 unsigned rem_aud_cnt; /**< No of active audio in last remote
202 offer. */
203 unsigned rem_vid_cnt; /**< No of active video in last remote
204 offer. */
205
206 pj_bool_t rx_reinv_async;/**< on_call_rx_reinvite() async. */
207 pj_timer_entry reinv_timer; /**< Reinvite retry timer. */
208 pj_bool_t reinv_pending;/**< Pending until CONFIRMED state. */
209 pj_bool_t reinv_ice_sent;/**< Has reinvite for ICE upd sent? */
210 pjsip_rx_data *incoming_data;/**< Cloned incoming call rdata.
211 On pjsua2, when handling incoming
212 call, onCreateMediaTransport() will
213 not be called since the call isn't
214 created yet. This temporary
215 variable is used to handle such
216 case, see ticket #1916. */
217
218 struct {
219 pj_bool_t enabled;
220 pj_bool_t remote_sup;
221 pj_bool_t remote_dlg_est;
222 pjsua_op_state trickling;
223 int retrans18x_count;
224 pj_bool_t pending_info;
225 pj_timer_entry timer;
226 } trickle_ice;
227
228 pj_timer_entry hangup_timer; /**< Hangup retry timer. */
229 unsigned hangup_retry; /**< Number of hangup retries. */
230 unsigned hangup_code; /**< Hangup code. */
231 pj_str_t hangup_reason; /**< Hangup reason. */
232 pjsua_msg_data *hangup_msg_data;/**< Hangup message data. */
233 };
234
235
236 /**
237 * Server presence subscription list head.
238 */
239 struct pjsua_srv_pres
240 {
241 PJ_DECL_LIST_MEMBER(struct pjsua_srv_pres);
242 pjsip_evsub *sub; /**< The evsub. */
243 char *remote; /**< Remote URI. */
244 int acc_id; /**< Account ID. */
245 pjsip_dialog *dlg; /**< Dialog. */
246 unsigned expires; /**< "expires" value in the request,
247 PJSIP_EXPIRES_NOT_SPECIFIED
248 if not present. */
249 };
250
251 /**
252 * Account
253 */
254 typedef struct pjsua_acc
255 {
256 pj_pool_t *pool; /**< Pool for this account. */
257 pjsua_acc_config cfg; /**< Account configuration. */
258 pj_bool_t valid; /**< Is this account valid? */
259
260 int index; /**< Index in accounts array. */
261 pj_str_t display; /**< Display name, if any. */
262 pj_str_t user_part; /**< User part of local URI. */
263 pj_bool_t is_sips; /**< Local URI uses "sips"? */
264 pj_str_t contact; /**< Our Contact header. */
265 pj_str_t reg_contact; /**< Contact header for REGISTER.
266 It may be different than acc
267 contact if outbound is used */
268 pj_bool_t contact_rewritten;
269 /**< Contact rewrite has been done? */
270 pjsip_host_port via_addr; /**< Address for Via header */
271 pjsip_transport *via_tp; /**< Transport associated with
272 the Via address */
273
274 pj_str_t srv_domain; /**< Host part of reg server. */
275 int srv_port; /**< Port number of reg server. */
276
277 pjsip_regc *regc; /**< Client registration session. */
278 pj_status_t reg_last_err; /**< Last registration error. */
279 int reg_last_code; /**< Last status last register. */
280
281 pj_str_t reg_mapped_addr;/**< Our addr as seen by reg srv.
282 Only if allow_sdp_nat_rewrite
283 is set */
284
285 struct {
286 pj_bool_t active; /**< Flag of reregister status. */
287 pj_timer_entry timer; /**< Timer for reregistration. */
288 void *reg_tp; /**< Transport for registration. */
289 unsigned attempt_cnt; /**< Attempt counter. */
290 } auto_rereg; /**< Reregister/reconnect data. */
291
292 pj_timer_entry ka_timer; /**< Keep-alive timer for UDP. */
293 pjsip_transport *ka_transport; /**< Transport for keep-alive. */
294 pj_sockaddr ka_target; /**< Destination address for K-A */
295 unsigned ka_target_len; /**< Length of ka_target. */
296
297 pjsip_route_hdr route_set; /**< Complete route set inc. outbnd.*/
298 pj_uint32_t global_route_crc; /** CRC of global route setting. */
299 pj_uint32_t local_route_crc; /** CRC of account route setting.*/
300
301 unsigned rfc5626_status;/**< SIP outbound status:
302 0: not used
303 1: requested
304 2: acknowledged by servers */
305 pj_str_t rfc5626_instprm;/**< SIP outbound instance param. */
306 pj_str_t rfc5626_regprm;/**< SIP outbound reg param. */
307
308 unsigned cred_cnt; /**< Number of credentials. */
309 pjsip_cred_info cred[PJSUA_ACC_MAX_PROXIES]; /**< Complete creds. */
310
311 pj_bool_t online_status; /**< Our online status. */
312 pjrpid_element rpid; /**< RPID element information. */
313 pjsua_srv_pres pres_srv_list; /**< Server subscription list. */
314 pjsip_publishc *publish_sess; /**< Client publication session. */
315 pj_bool_t publish_state; /**< Last published online status */
316
317 pjsip_evsub *mwi_sub; /**< MWI client subscription */
318 pjsip_dialog *mwi_dlg; /**< Dialog for MWI sub. */
319
320 pj_uint16_t next_rtp_port; /**< Next RTP port to be used. */
321 pjsip_transport_type_e tp_type; /**< Transport type (for local acc or
322 transport binding) */
323 pjsua_ip_change_op ip_change_op;/**< IP change process progress. */
324 } pjsua_acc;
325
326
327 /**
328 *Transport.
329 */
330 typedef struct pjsua_transport_data
331 {
332 int index;
333 pjsip_transport_type_e type;
334 pjsip_host_port local_name;
335
336 union {
337 pjsip_transport *tp;
338 pjsip_tpfactory *factory;
339 void *ptr;
340 } data;
341
342 pj_bool_t is_restarting;
343 pj_status_t restart_status;
344 pj_bool_t has_bound_addr;
345 } pjsua_transport_data;
346
347
348 /** Maximum length of subscription termination reason. */
349 #define PJSUA_BUDDY_SUB_TERM_REASON_LEN 32
350
351 /**
352 * Buddy data.
353 */
354 typedef struct pjsua_buddy
355 {
356 pj_pool_t *pool; /**< Pool for this buddy. */
357 unsigned index; /**< Buddy index. */
358 void *user_data; /**< Application data. */
359 pj_str_t uri; /**< Buddy URI. */
360 pj_str_t contact; /**< Contact learned from subscrp. */
361 pj_str_t name; /**< Buddy name. */
362 pj_str_t display; /**< Buddy display name. */
363 pj_str_t host; /**< Buddy host. */
364 unsigned port; /**< Buddy port. */
365 pj_bool_t monitor; /**< Should we monitor? */
366 pjsip_dialog *dlg; /**< The underlying dialog. */
367 pjsip_evsub *sub; /**< Buddy presence subscription */
368 unsigned term_code; /**< Subscription termination code */
369 pj_str_t term_reason;/**< Subscription termination reason */
370 pjsip_pres_status status; /**< Buddy presence status. */
371 pj_timer_entry timer; /**< Resubscription timer */
372 } pjsua_buddy;
373
374
375 /**
376 * File player/recorder data.
377 */
378 typedef struct pjsua_file_data
379 {
380 pj_bool_t type; /* 0=player, 1=playlist */
381 pjmedia_port *port;
382 pj_pool_t *pool;
383 unsigned slot;
384 } pjsua_file_data;
385
386
387 /**
388 * Additional parameters for conference bridge.
389 */
390 typedef struct pjsua_conf_setting
391 {
392 unsigned channel_count;
393 unsigned samples_per_frame;
394 unsigned bits_per_sample;
395 } pjsua_conf_setting;
396
397 typedef struct pjsua_stun_resolve
398 {
399 PJ_DECL_LIST_MEMBER(struct pjsua_stun_resolve);
400
401 pj_pool_t *pool; /**< Pool */
402 int ref_cnt; /**< Reference count */
403 pj_bool_t destroy_flag; /**< To be destroyed */
404 pj_bool_t has_result;
405 unsigned count; /**< # of entries */
406 pj_str_t *srv; /**< Array of entries */
407 unsigned idx; /**< Current index */
408 void *token; /**< App token */
409 pj_stun_resolve_cb cb; /**< App callback */
410 pj_bool_t blocking; /**< Blocking? */
411 pj_thread_t *waiter; /**< Waiting thread */
412 pj_timer_entry timer; /**< Destroy timer */
413 pj_status_t status; /**< Session status */
414 pj_sockaddr addr; /**< Result */
415 pj_stun_sock *stun_sock; /**< Testing STUN sock */
416 int af; /**< Address family */
417 pj_bool_t async_wait;/**< Async resolution
418 of STUN entry */
419 } pjsua_stun_resolve;
420
421 /* See also pjsua_vid_win_type_name() */
422 typedef enum pjsua_vid_win_type
423 {
424 PJSUA_WND_TYPE_NONE,
425 PJSUA_WND_TYPE_PREVIEW,
426 PJSUA_WND_TYPE_STREAM
427 } pjsua_vid_win_type;
428
429 typedef struct pjsua_vid_win
430 {
431 pjsua_vid_win_type type; /**< Type. */
432 pj_pool_t *pool; /**< Own pool. */
433 unsigned ref_cnt; /**< Reference counter. */
434 pjmedia_vid_port *vp_cap; /**< Capture vidport. */
435 pjmedia_vid_port *vp_rend; /**< Renderer vidport */
436 pjsua_conf_port_id cap_slot; /**< Capturer conf slot */
437 pjsua_conf_port_id rend_slot; /**< Renderer conf slot */
438 pjmedia_vid_dev_index preview_cap_id;/**< Capture dev id */
439 pj_bool_t preview_running;/**< Preview is started*/
440 pj_bool_t is_native; /**< Preview is by dev */
441 } pjsua_vid_win;
442
443
444 typedef struct pjsua_timer_list
445 {
446 PJ_DECL_LIST_MEMBER(struct pjsua_timer_list);
447 pj_timer_entry entry;
448 void (*cb)(void *user_data);
449 void *user_data;
450 } pjsua_timer_list;
451
452
453 typedef struct pjsua_event_list
454 {
455 PJ_DECL_LIST_MEMBER(struct pjsua_event_list);
456 pjmedia_event event;
457 pjsua_call_id call_id;
458 unsigned med_idx;
459 } pjsua_event_list;
460
461
462 /**
463 * Global pjsua application data.
464 */
465 struct pjsua_data
466 {
467
468 /* Control: */
469 pj_caching_pool cp; /**< Global pool factory. */
470 pj_pool_t *pool; /**< pjsua's private pool. */
471 pj_pool_t *timer_pool;/**< pjsua's timer pool. */
472 pj_mutex_t *mutex; /**< Mutex protection for this data */
473 unsigned mutex_nesting_level; /**< Mutex nesting level. */
474 pj_thread_t *mutex_owner; /**< Mutex owner. */
475 pjsua_state state; /**< Library state. */
476
477 /* Logging: */
478 pjsua_logging_config log_cfg; /**< Current logging config. */
479 pj_oshandle_t log_file; /**<Output log file handle */
480
481 /* SIP: */
482 pjsip_endpoint *endpt; /**< Global endpoint. */
483 pjsip_module mod; /**< pjsua's PJSIP module. */
484 pjsua_transport_data tpdata[8]; /**< Array of transports. */
485 pjsip_tp_state_callback old_tp_cb; /**< Old transport callback. */
486
487 /* Threading: */
488 pj_bool_t thread_quit_flag; /**< Thread quit flag. */
489 pj_thread_t *thread[4]; /**< Array of threads. */
490
491 /* STUN and resolver */
492 pj_stun_config stun_cfg; /**< Global STUN settings. */
493 pj_sockaddr stun_srv; /**< Resolved STUN server address */
494 pj_status_t stun_status; /**< STUN server status. */
495 pjsua_stun_resolve stun_res; /**< List of pending STUN resolution*/
496 unsigned stun_srv_idx; /**< Resolved STUN server index */
497 unsigned stun_opt; /**< STUN resolution option. */
498 pj_dns_resolver *resolver; /**< DNS resolver. */
499
500 /* Detected NAT type */
501 pj_stun_nat_type nat_type; /**< NAT type. */
502 pj_status_t nat_status; /**< Detection status. */
503 pj_bool_t nat_in_progress; /**< Detection in progress */
504
505 /* List of outbound proxies: */
506 pjsip_route_hdr outbound_proxy;
507
508 /* Account: */
509 unsigned acc_cnt; /**< Number of accounts. */
510 pjsua_acc_id default_acc; /**< Default account ID */
511 pjsua_acc acc[PJSUA_MAX_ACC]; /**< Account array. */
512 pjsua_acc_id acc_ids[PJSUA_MAX_ACC]; /**< Acc sorted by prio*/
513
514 /* Calls: */
515 pjsua_config ua_cfg; /**< UA config. */
516 unsigned call_cnt; /**< Call counter. */
517 pjsua_call calls[PJSUA_MAX_CALLS];/**< Calls array. */
518 pjsua_call_id next_call_id; /**< Next call id to use*/
519
520 /* Buddy; */
521 unsigned buddy_cnt; /**< Buddy count. */
522 pjsua_buddy buddy[PJSUA_MAX_BUDDIES]; /**< Buddy array. */
523
524 /* Presence: */
525 pj_timer_entry pres_timer;/**< Presence refresh timer. */
526
527 /* Media: */
528 pjsua_media_config media_cfg; /**< Media config. */
529 pjmedia_endpt *med_endpt; /**< Media endpoint. */
530 pjsua_conf_setting mconf_cfg; /**< Additionan conf. bridge. param */
531 pjmedia_conf *mconf; /**< Conference bridge. */
532 pj_bool_t is_mswitch;/**< Are we using audio switchboard
533 (a.k.a APS-Direct) */
534
535 /* Sound device */
536 pjmedia_aud_dev_index cap_dev; /**< Capture device ID. */
537 pjmedia_aud_dev_index play_dev; /**< Playback device ID. */
538 pj_uint32_t aud_svmask;/**< Which settings to save */
539 pjmedia_aud_param aud_param; /**< User settings to sound dev */
540 pj_bool_t aud_open_cnt;/**< How many # device is opened */
541 pj_bool_t no_snd; /**< No sound (app will manage it) */
542 pj_pool_t *snd_pool; /**< Sound's private pool. */
543 pjmedia_snd_port *snd_port; /**< Sound port. */
544 pj_timer_entry snd_idle_timer;/**< Sound device idle timer. */
545 pjmedia_master_port *null_snd; /**< Master port for null sound. */
546 pjmedia_port *null_port; /**< Null port. */
547 pj_bool_t snd_is_on; /**< Media flow is currently active */
548 unsigned snd_mode; /**< Sound device mode. */
549
550 /* Video device */
551 pjmedia_vid_dev_index vcap_dev; /**< Capture device ID. */
552 pjmedia_vid_dev_index vrdr_dev; /**< Playback device ID. */
553
554 /* For keeping video device settings */
555 #if PJSUA_HAS_VIDEO
556 pjmedia_vid_conf *vid_conf;
557 pj_uint32_t vid_caps[PJMEDIA_VID_DEV_MAX_DEVS];
558 pjmedia_vid_dev_param vid_param[PJMEDIA_VID_DEV_MAX_DEVS];
559 #endif
560
561 /* File players: */
562 unsigned player_cnt;/**< Number of file players. */
563 pjsua_file_data player[PJSUA_MAX_PLAYERS];/**< Array of players.*/
564
565 /* File recorders: */
566 unsigned rec_cnt; /**< Number of file recorders. */
567 pjsua_file_data recorder[PJSUA_MAX_RECORDERS];/**< Array of recs.*/
568
569 /* Video windows */
570 #if PJSUA_HAS_VIDEO
571 pjsua_vid_win win[PJSUA_MAX_VID_WINS]; /**< Array of windows */
572 #endif
573
574 /* Timer entry and event list */
575 pjsua_timer_list active_timer_list;
576 pjsua_timer_list timer_list;
577 pjsua_event_list event_list;
578 pj_mutex_t *timer_mutex;
579 };
580
581
582 extern struct pjsua_data pjsua_var;
583
584 /**
585 * Get the instance of pjsua
586 */
587 PJ_DECL(struct pjsua_data*) pjsua_get_var(void);
588
589
590
591 /**
592 * IM callback data.
593 */
594 typedef struct pjsua_im_data
595 {
596 pjsua_acc_id acc_id;
597 pjsua_call_id call_id;
598 pj_str_t to;
599 pj_str_t body;
600 void *user_data;
601 } pjsua_im_data;
602
603 pj_status_t pjsua_media_apply_xml_control(pjsua_call_id call_id,
604 const pj_str_t *xml_st);
605
606
607 /**
608 * Duplicate IM data.
609 */
pjsua_im_data_dup(pj_pool_t * pool,const pjsua_im_data * src)610 PJ_INLINE(pjsua_im_data*) pjsua_im_data_dup(pj_pool_t *pool,
611 const pjsua_im_data *src)
612 {
613 pjsua_im_data *dst;
614
615 dst = (pjsua_im_data*) pj_pool_alloc(pool, sizeof(*dst));
616 dst->acc_id = src->acc_id;
617 dst->call_id = src->call_id;
618 pj_strdup_with_null(pool, &dst->to, &src->to);
619 dst->user_data = src->user_data;
620 pj_strdup_with_null(pool, &dst->body, &src->body);
621
622 return dst;
623 }
624
625
626 #if 1
627
PJSUA_LOCK()628 PJ_INLINE(void) PJSUA_LOCK()
629 {
630 pj_mutex_lock(pjsua_var.mutex);
631 pjsua_var.mutex_owner = pj_thread_this();
632 ++pjsua_var.mutex_nesting_level;
633 }
634
PJSUA_UNLOCK()635 PJ_INLINE(void) PJSUA_UNLOCK()
636 {
637 if (--pjsua_var.mutex_nesting_level == 0)
638 pjsua_var.mutex_owner = NULL;
639 pj_mutex_unlock(pjsua_var.mutex);
640 }
641
PJSUA_TRY_LOCK()642 PJ_INLINE(pj_status_t) PJSUA_TRY_LOCK()
643 {
644 pj_status_t status;
645 status = pj_mutex_trylock(pjsua_var.mutex);
646 if (status == PJ_SUCCESS) {
647 pjsua_var.mutex_owner = pj_thread_this();
648 ++pjsua_var.mutex_nesting_level;
649 }
650 return status;
651 }
652
PJSUA_LOCK_IS_LOCKED()653 PJ_INLINE(pj_bool_t) PJSUA_LOCK_IS_LOCKED()
654 {
655 return pjsua_var.mutex_owner == pj_thread_this();
656 }
657
658 #else
659 #define PJSUA_LOCK()
660 #define PJSUA_TRY_LOCK() PJ_SUCCESS
661 #define PJSUA_UNLOCK()
662 #define PJSUA_LOCK_IS_LOCKED() PJ_TRUE
663 #endif
664
665 /* Core */
666 void pjsua_set_state(pjsua_state new_state);
667
668 /******
669 * STUN resolution
670 */
671 /* Resolve the STUN server */
672 pj_status_t resolve_stun_server(pj_bool_t wait, pj_bool_t retry_if_cur_error,
673 unsigned options);
674
675 /**
676 * Normalize route URI (check for ";lr" and append one if it doesn't
677 * exist and pjsua_config.force_lr is set.
678 */
679 pj_status_t normalize_route_uri(pj_pool_t *pool, pj_str_t *uri);
680
681 /* acc use stun? */
682 pj_bool_t pjsua_sip_acc_is_using_stun(pjsua_acc_id acc_id);
683 pj_bool_t pjsua_media_acc_is_using_stun(pjsua_acc_id acc_id);
684
685 /* acc use IPv6? */
686 pj_bool_t pjsua_sip_acc_is_using_ipv6(pjsua_acc_id acc_id);
687
688 /* Get local transport address suitable to be used for Via or Contact address
689 * to send request to the specified destination URI.
690 */
691 pj_status_t pjsua_acc_get_uac_addr(pjsua_acc_id acc_id,
692 pj_pool_t *pool,
693 const pj_str_t *dst_uri,
694 pjsip_host_port *addr,
695 pjsip_transport_type_e *p_tp_type,
696 int *p_secure,
697 const void **p_tp);
698
699 /**
700 * Handle incoming invite request.
701 */
702 pj_bool_t pjsua_call_on_incoming(pjsip_rx_data *rdata);
703
704 /*
705 * Media channel.
706 */
707 pj_status_t pjsua_media_channel_init(pjsua_call_id call_id,
708 pjsip_role_e role,
709 int security_level,
710 pj_pool_t *tmp_pool,
711 const pjmedia_sdp_session *rem_sdp,
712 int *sip_err_code,
713 pj_bool_t async,
714 pjsua_med_tp_state_cb cb);
715 pj_status_t pjsua_media_channel_create_sdp(pjsua_call_id call_id,
716 pj_pool_t *pool,
717 const pjmedia_sdp_session *rem_sdp,
718 pjmedia_sdp_session **p_sdp,
719 int *sip_err_code);
720 pj_status_t pjsua_media_channel_update(pjsua_call_id call_id,
721 const pjmedia_sdp_session *local_sdp,
722 const pjmedia_sdp_session *remote_sdp);
723 pj_status_t pjsua_media_channel_deinit(pjsua_call_id call_id);
724
725 void pjsua_ice_check_start_trickling(pjsua_call *call,
726 pj_bool_t forceful,
727 pjsip_event *e);
728
729 /*
730 * Error message when media operation is requested while another is in progress
731 */
732 #define ERR_MEDIA_CHANGING " because another media operation is in progress"
733
734 pj_bool_t pjsua_call_media_is_changing(pjsua_call *call);
735 pj_status_t pjsua_call_media_init(pjsua_call_media *call_med,
736 pjmedia_type type,
737 const pjsua_transport_config *tcfg,
738 int security_level,
739 int *sip_err_code,
740 pj_bool_t async,
741 pjsua_med_tp_state_cb cb);
742 void pjsua_call_cleanup_flag(pjsua_call_setting *opt);
743 void pjsua_set_media_tp_state(pjsua_call_media *call_med, pjsua_med_tp_st tp_st);
744
745 void pjsua_media_prov_clean_up(pjsua_call_id call_id);
746 void pjsua_media_prov_revert(pjsua_call_id call_id);
747
748 /* Callback to receive media events */
749 pj_status_t on_media_event(pjmedia_event *event, void *user_data);
750 void call_med_event_cb(void *user_data);
751 pj_status_t call_media_on_event(pjmedia_event *event,
752 void *user_data);
753
754 /**
755 * Init presence.
756 */
757 pj_status_t pjsua_pres_init();
758
759 /*
760 * Start presence subsystem.
761 */
762 pj_status_t pjsua_pres_start(void);
763
764 /**
765 * Refresh presence subscriptions
766 */
767 void pjsua_pres_refresh(void);
768
769 /*
770 * Update server subscription (e.g. when our online status has changed)
771 */
772 void pjsua_pres_update_acc(int acc_id, pj_bool_t force);
773
774 /*
775 * Shutdown presence.
776 */
777 void pjsua_pres_shutdown(unsigned flags);
778
779 /**
780 * Init presence for aoocunt.
781 */
782 pj_status_t pjsua_pres_init_acc(int acc_id);
783
784 /**
785 * Send PUBLISH
786 */
787 pj_status_t pjsua_pres_init_publish_acc(int acc_id);
788
789 /**
790 * Send un-PUBLISH
791 */
792 void pjsua_pres_unpublish(pjsua_acc *acc, unsigned flags);
793
794 /**
795 * Terminate server subscription for the account
796 */
797 void pjsua_pres_delete_acc(int acc_id, unsigned flags);
798
799 /**
800 * Init IM module handler to handle incoming MESSAGE outside dialog.
801 */
802 pj_status_t pjsua_im_init(void);
803
804 /**
805 * Start MWI subscription
806 */
807 pj_status_t pjsua_start_mwi(pjsua_acc_id acc_id, pj_bool_t force_renew);
808
809 /**
810 * Init call subsystem.
811 */
812 pj_status_t pjsua_call_subsys_init(const pjsua_config *cfg);
813
814 /**
815 * Start call subsystem.
816 */
817 pj_status_t pjsua_call_subsys_start(void);
818
819 /**
820 * Init media subsystems.
821 */
822 pj_status_t pjsua_media_subsys_init(const pjsua_media_config *cfg);
823
824 /**
825 * Start pjsua media subsystem.
826 */
827 pj_status_t pjsua_media_subsys_start(void);
828
829 /**
830 * Destroy pjsua media subsystem.
831 */
832 pj_status_t pjsua_media_subsys_destroy(unsigned flags);
833
834 /**
835 * Private: check if we can accept the message.
836 * If not, then p_accept header will be filled with a valid
837 * Accept header.
838 */
839 pj_bool_t pjsua_im_accept_pager(pjsip_rx_data *rdata,
840 pjsip_accept_hdr **p_accept_hdr);
841
842 /**
843 * Private: process pager message.
844 * This may trigger pjsua_ui_on_pager() or pjsua_ui_on_typing().
845 */
846 void pjsua_im_process_pager(int call_id, const pj_str_t *from,
847 const pj_str_t *to, pjsip_rx_data *rdata);
848
849
850 /**
851 * Create Accept header for MESSAGE.
852 */
853 pjsip_accept_hdr* pjsua_im_create_accept(pj_pool_t *pool);
854
855 /*
856 * Add additional headers etc in msg_data specified by application
857 * when sending requests.
858 */
859 void pjsua_process_msg_data(pjsip_tx_data *tdata,
860 const pjsua_msg_data *msg_data);
861
862
863 /*
864 * Add route_set to outgoing requests
865 */
866 void pjsua_set_msg_route_set( pjsip_tx_data *tdata,
867 const pjsip_route_hdr *route_set );
868
869
870 /*
871 * Simple version of MIME type parsing (it doesn't support parameters)
872 */
873 void pjsua_parse_media_type( pj_pool_t *pool,
874 const pj_str_t *mime,
875 pjsip_media_type *media_type);
876
877
878 /*
879 * Internal function to init transport selector from transport id.
880 */
881 void pjsua_init_tpselector(pjsua_transport_id tp_id,
882 pjsip_tpselector *sel);
883
884 pjsip_dialog* on_dlg_forked(pjsip_dialog *first_set, pjsip_rx_data *res);
885 pj_status_t acquire_call(const char *title,
886 pjsua_call_id call_id,
887 pjsua_call **p_call,
888 pjsip_dialog **p_dlg);
889 const char *good_number(char *buf, pj_int32_t val);
890 void print_call(const char *title,
891 int call_id,
892 char *buf, pj_size_t size);
893
894 /*
895 * Audio
896 */
897 pj_status_t pjsua_aud_subsys_init(void);
898 pj_status_t pjsua_aud_subsys_start(void);
899 pj_status_t pjsua_aud_subsys_destroy(void);
900 void pjsua_aud_stop_stream(pjsua_call_media *call_med);
901 pj_status_t pjsua_aud_channel_update(pjsua_call_media *call_med,
902 pj_pool_t *tmp_pool,
903 pjmedia_stream_info *si,
904 const pjmedia_sdp_session *local_sdp,
905 const pjmedia_sdp_session *remote_sdp);
906 void pjsua_check_snd_dev_idle();
907
908 /*
909 * Video
910 */
911 pj_status_t pjsua_vid_subsys_init(void);
912 pj_status_t pjsua_vid_subsys_start(void);
913 pj_status_t pjsua_vid_subsys_destroy(void);
914 void pjsua_vid_stop_stream(pjsua_call_media *call_med);
915 pj_status_t pjsua_vid_channel_init(pjsua_call_media *call_med);
916 pj_status_t pjsua_vid_channel_update(pjsua_call_media *call_med,
917 pj_pool_t *tmp_pool,
918 pjmedia_vid_stream_info *si,
919 const pjmedia_sdp_session *local_sdp,
920 const pjmedia_sdp_session *remote_sdp);
921
922 #if PJSUA_HAS_VIDEO
923 void pjsua_vid_win_reset(pjsua_vid_win_id wid);
924 #else
925 # define pjsua_vid_win_reset(wid)
926 #endif
927
928 /*
929 * Schedule check for the need of re-INVITE/UPDATE after media update
930 */
931 void pjsua_call_schedule_reinvite_check(pjsua_call *call, unsigned delay_ms);
932
933 /*
934 * Update contact per account on IP change process.
935 */
936 pj_status_t pjsua_acc_update_contact_on_ip_change(pjsua_acc *acc);
937
938 /*
939 * Call handling per account on IP change process.
940 */
941 pj_status_t pjsua_acc_handle_call_on_ip_change(pjsua_acc *acc);
942
943 /*
944 * End IP change process per account.
945 */
946 void pjsua_acc_end_ip_change(pjsua_acc *acc);
947
948 PJ_END_DECL
949
950 #endif /* __PJSUA_INTERNAL_H__ */
951
952