Debian Codegraph @

Xpjproject/pjsip/include/pjsua-lib/pjsua_internal.h

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