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