Benny Prijono | 268ca61 | 2006-02-07 12:34:11 +0000 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | /* |
| 3 | * Copyright (C) 2003-2006 Benny Prijono <benny@prijono.org> |
| 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_H__ |
| 20 | #define __PJSUA_H__ |
| 21 | |
| 22 | /* Include all PJSIP core headers. */ |
| 23 | #include <pjsip.h> |
| 24 | |
| 25 | /* Include all PJMEDIA headers. */ |
| 26 | #include <pjmedia.h> |
| 27 | |
| 28 | /* Include all PJSIP-UA headers */ |
| 29 | #include <pjsip_ua.h> |
| 30 | |
| 31 | /* Include all PJLIB-UTIL headers. */ |
| 32 | #include <pjlib-util.h> |
| 33 | |
| 34 | /* Include all PJLIB headers. */ |
| 35 | #include <pjlib.h> |
| 36 | |
| 37 | |
Benny Prijono | 1a01ad3 | 2006-02-07 21:13:28 +0000 | [diff] [blame] | 38 | PJ_BEGIN_DECL |
| 39 | |
Benny Prijono | 268ca61 | 2006-02-07 12:34:11 +0000 | [diff] [blame] | 40 | /* PJSUA application variables. */ |
Benny Prijono | 9519658 | 2006-02-09 00:13:40 +0000 | [diff] [blame] | 41 | struct pjsua |
Benny Prijono | 268ca61 | 2006-02-07 12:34:11 +0000 | [diff] [blame] | 42 | { |
| 43 | /* Control: */ |
| 44 | |
Benny Prijono | 9519658 | 2006-02-09 00:13:40 +0000 | [diff] [blame] | 45 | pj_caching_pool cp; /**< Global pool factory. */ |
| 46 | pjsip_endpoint *endpt; /**< Global endpoint. */ |
| 47 | pj_pool_t *pool; /**< pjsua's private pool. */ |
| 48 | pjsip_module mod; /**< pjsua's PJSIP module. */ |
Benny Prijono | 268ca61 | 2006-02-07 12:34:11 +0000 | [diff] [blame] | 49 | |
| 50 | |
Benny Prijono | 9519658 | 2006-02-09 00:13:40 +0000 | [diff] [blame] | 51 | /* Media: */ |
| 52 | |
| 53 | pjmedia_endpt *med_endpt; /**< Media endpoint. */ |
| 54 | pj_bool_t null_audio; |
| 55 | pjmedia_sock_info med_skinfo; |
| 56 | |
Benny Prijono | 268ca61 | 2006-02-07 12:34:11 +0000 | [diff] [blame] | 57 | /* User info: */ |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame] | 58 | |
Benny Prijono | 268ca61 | 2006-02-07 12:34:11 +0000 | [diff] [blame] | 59 | pj_str_t local_uri; /**< Uri in From: header. */ |
| 60 | pj_str_t contact_uri; /**< Uri in Contact: header. */ |
| 61 | |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame] | 62 | /* Proxy URLs: */ |
| 63 | |
| 64 | pj_str_t proxy; |
| 65 | pj_str_t outbound_proxy; |
Benny Prijono | 9519658 | 2006-02-09 00:13:40 +0000 | [diff] [blame] | 66 | pjsip_route_hdr route_set; |
| 67 | |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame] | 68 | |
| 69 | /* Registration: */ |
| 70 | |
| 71 | pj_str_t registrar_uri; |
| 72 | pjsip_regc *regc; |
| 73 | pj_int32_t reg_timeout; |
| 74 | pj_timer_entry regc_timer; |
| 75 | |
| 76 | |
| 77 | /* Authentication credentials: */ |
| 78 | |
| 79 | int cred_count; |
| 80 | pjsip_cred_info cred_info[4]; |
| 81 | |
| 82 | |
Benny Prijono | 268ca61 | 2006-02-07 12:34:11 +0000 | [diff] [blame] | 83 | /* Threading: */ |
| 84 | |
| 85 | int thread_cnt; /**< Thread count. */ |
| 86 | pj_thread_t *threads[8]; /**< Thread instances. */ |
| 87 | pj_bool_t quit_flag; /**< To signal thread to quit. */ |
| 88 | |
| 89 | /* Transport (UDP): */ |
| 90 | |
| 91 | pj_uint16_t sip_port; /**< SIP signaling port. */ |
| 92 | pj_sock_t sip_sock; /**< SIP UDP socket. */ |
| 93 | pj_sockaddr_in sip_sock_name; /**< Public/STUN UDP socket addr. */ |
Benny Prijono | 268ca61 | 2006-02-07 12:34:11 +0000 | [diff] [blame] | 94 | |
| 95 | |
| 96 | |
| 97 | /* STUN: */ |
| 98 | |
| 99 | pj_str_t stun_srv1; |
| 100 | int stun_port1; |
| 101 | pj_str_t stun_srv2; |
| 102 | int stun_port2; |
| 103 | |
| 104 | |
| 105 | /* Misc: */ |
| 106 | |
| 107 | int log_level; /**< Logging verbosity. */ |
| 108 | int app_log_level; /**< stdout log verbosity. */ |
| 109 | unsigned log_decor; /**< Log decoration. */ |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame] | 110 | char *log_filename; /**< Log filename. */ |
Benny Prijono | 268ca61 | 2006-02-07 12:34:11 +0000 | [diff] [blame] | 111 | |
Benny Prijono | 1a01ad3 | 2006-02-07 21:13:28 +0000 | [diff] [blame] | 112 | }; |
Benny Prijono | 268ca61 | 2006-02-07 12:34:11 +0000 | [diff] [blame] | 113 | |
Benny Prijono | 9519658 | 2006-02-09 00:13:40 +0000 | [diff] [blame] | 114 | |
| 115 | /** PJSUA instance. */ |
| 116 | extern struct pjsua pjsua; |
| 117 | |
| 118 | |
| 119 | /** |
| 120 | * Structure to be attached to all dialog. |
| 121 | * Given a dialog "dlg", application can retrieve this structure |
| 122 | * by accessing dlg->mod_data[pjsua.mod.id]. |
| 123 | */ |
| 124 | struct pjsua_inv_data |
| 125 | { |
| 126 | pjmedia_session *session; |
| 127 | }; |
| 128 | |
Benny Prijono | 268ca61 | 2006-02-07 12:34:11 +0000 | [diff] [blame] | 129 | |
| 130 | /***************************************************************************** |
Benny Prijono | 84126ab | 2006-02-09 09:30:09 +0000 | [diff] [blame^] | 131 | * PJSUA API (defined in pjsua_core.c). |
Benny Prijono | 268ca61 | 2006-02-07 12:34:11 +0000 | [diff] [blame] | 132 | */ |
| 133 | |
| 134 | /** |
| 135 | * Initialize pjsua settings with default parameters. |
| 136 | */ |
| 137 | void pjsua_default(void); |
| 138 | |
| 139 | |
| 140 | /** |
| 141 | * Display error message for the specified error code. |
| 142 | */ |
| 143 | void pjsua_perror(const char *title, pj_status_t status); |
| 144 | |
| 145 | |
| 146 | /** |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame] | 147 | * Initialize pjsua application. Application can call this before parsing |
| 148 | * application settings. |
| 149 | * |
| 150 | * This will initialize all libraries, create endpoint instance, and register |
| 151 | * pjsip modules. Transport will NOT be created however. |
| 152 | * |
| 153 | * Application may register module after calling this function. |
Benny Prijono | 268ca61 | 2006-02-07 12:34:11 +0000 | [diff] [blame] | 154 | */ |
| 155 | pj_status_t pjsua_init(void); |
| 156 | |
| 157 | |
| 158 | /** |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame] | 159 | * Start pjsua stack. Application calls this after pjsua settings has been |
| 160 | * configured. |
| 161 | * |
| 162 | * This will start the transport, worker threads (if any), and registration |
| 163 | * process, if registration is configured. |
| 164 | */ |
| 165 | pj_status_t pjsua_start(void); |
| 166 | |
| 167 | |
| 168 | /** |
Benny Prijono | 268ca61 | 2006-02-07 12:34:11 +0000 | [diff] [blame] | 169 | * Destroy pjsua. |
| 170 | */ |
| 171 | pj_status_t pjsua_destroy(void); |
| 172 | |
| 173 | |
Benny Prijono | 84126ab | 2006-02-09 09:30:09 +0000 | [diff] [blame^] | 174 | /***************************************************************************** |
| 175 | * PJSUA Invite session API (defined in pjsua_inv.c). |
| 176 | */ |
| 177 | |
Benny Prijono | 268ca61 | 2006-02-07 12:34:11 +0000 | [diff] [blame] | 178 | /** |
| 179 | * Make outgoing call. |
| 180 | */ |
| 181 | pj_status_t pjsua_invite(const char *cstr_dest_uri, |
| 182 | pjsip_inv_session **p_inv); |
| 183 | |
| 184 | |
Benny Prijono | 84126ab | 2006-02-09 09:30:09 +0000 | [diff] [blame^] | 185 | /** |
| 186 | * Handle incoming invite request. |
| 187 | */ |
| 188 | pj_bool_t pjsua_inv_on_incoming(pjsip_rx_data *rdata); |
| 189 | |
| 190 | |
| 191 | /** |
| 192 | * Callback to be called by session when invite session's state has changed. |
| 193 | */ |
| 194 | void pjsua_inv_on_state_changed(pjsip_inv_session *inv, pjsip_event *e); |
| 195 | |
| 196 | |
| 197 | /** |
| 198 | * Callback to be called by session when outgoing dialog has forked. |
| 199 | * This function will create a forked dialog. |
| 200 | */ |
| 201 | void pjsua_inv_on_new_session(pjsip_inv_session *inv, pjsip_event *e); |
| 202 | |
| 203 | |
| 204 | /** |
| 205 | * Callback to be called when SDP offer/answer negotiation has just completed |
| 206 | * in the session. This function will start/update media if negotiation |
| 207 | * has succeeded. |
| 208 | */ |
| 209 | void pjsua_inv_on_media_update(pjsip_inv_session *inv, pj_status_t status); |
| 210 | |
| 211 | |
Benny Prijono | 268ca61 | 2006-02-07 12:34:11 +0000 | [diff] [blame] | 212 | /***************************************************************************** |
Benny Prijono | 84126ab | 2006-02-09 09:30:09 +0000 | [diff] [blame^] | 213 | * PJSUA Client Registration API (defined in pjsua_reg.c). |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame] | 214 | */ |
| 215 | |
| 216 | /** |
| 217 | * Initialize client registration session. |
| 218 | * |
| 219 | * @param app_callback Optional callback |
| 220 | */ |
| 221 | pj_status_t pjsua_regc_init(void); |
| 222 | |
| 223 | /** |
| 224 | * Update registration or perform unregistration. If renew argument is zero, |
| 225 | * this will start unregistration process. |
| 226 | */ |
| 227 | void pjsua_regc_update(pj_bool_t renew); |
| 228 | |
| 229 | |
| 230 | /***************************************************************************** |
Benny Prijono | 268ca61 | 2006-02-07 12:34:11 +0000 | [diff] [blame] | 231 | * User Interface API. |
Benny Prijono | 84126ab | 2006-02-09 09:30:09 +0000 | [diff] [blame^] | 232 | * |
Benny Prijono | 268ca61 | 2006-02-07 12:34:11 +0000 | [diff] [blame] | 233 | * The UI API specifies functions that will be called by pjsua upon |
| 234 | * occurence of various events. |
| 235 | */ |
| 236 | |
| 237 | /** |
| 238 | * Notify UI when invite state has changed. |
| 239 | */ |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame] | 240 | void pjsua_ui_inv_on_state_changed(pjsip_inv_session *inv, pjsip_event *e); |
Benny Prijono | 268ca61 | 2006-02-07 12:34:11 +0000 | [diff] [blame] | 241 | |
| 242 | |
Benny Prijono | 1a01ad3 | 2006-02-07 21:13:28 +0000 | [diff] [blame] | 243 | PJ_END_DECL |
| 244 | |
Benny Prijono | 268ca61 | 2006-02-07 12:34:11 +0000 | [diff] [blame] | 245 | #endif /* __PJSUA_H__ */ |