blob: 8f9b31c0a9959d8bf7184f77062e642f710cc4e3 [file] [log] [blame]
Benny Prijono268ca612006-02-07 12:34:11 +00001/* $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
Benny Prijono1f9afba2006-02-10 15:57:32 +000028/* Include all PJMEDIA-CODEC headers. */
29#include <pjmedia-codec.h>
30
Benny Prijono268ca612006-02-07 12:34:11 +000031/* Include all PJSIP-UA headers */
32#include <pjsip_ua.h>
33
34/* Include all PJLIB-UTIL headers. */
35#include <pjlib-util.h>
36
37/* Include all PJLIB headers. */
38#include <pjlib.h>
39
40
Benny Prijono1a01ad32006-02-07 21:13:28 +000041PJ_BEGIN_DECL
42
Benny Prijono632ce712006-02-09 14:01:40 +000043
44/**
45 * Structure to be attached to all dialog.
46 * Given a dialog "dlg", application can retrieve this structure
47 * by accessing dlg->mod_data[pjsua.mod.id].
48 */
49struct pjsua_inv_data
50{
51 PJ_DECL_LIST_MEMBER(struct pjsua_inv_data);
52
53 pjsip_inv_session *inv;
54 pjmedia_session *session;
55};
56
57
58
Benny Prijono268ca612006-02-07 12:34:11 +000059/* PJSUA application variables. */
Benny Prijono95196582006-02-09 00:13:40 +000060struct pjsua
Benny Prijono268ca612006-02-07 12:34:11 +000061{
62 /* Control: */
63
Benny Prijono95196582006-02-09 00:13:40 +000064 pj_caching_pool cp; /**< Global pool factory. */
65 pjsip_endpoint *endpt; /**< Global endpoint. */
66 pj_pool_t *pool; /**< pjsua's private pool. */
67 pjsip_module mod; /**< pjsua's PJSIP module. */
Benny Prijono268ca612006-02-07 12:34:11 +000068
69
Benny Prijono95196582006-02-09 00:13:40 +000070 /* Media: */
71
72 pjmedia_endpt *med_endpt; /**< Media endpoint. */
73 pj_bool_t null_audio;
74 pjmedia_sock_info med_skinfo;
75
Benny Prijono268ca612006-02-07 12:34:11 +000076 /* User info: */
Benny Prijonoccf95622006-02-07 18:48:01 +000077
Benny Prijono268ca612006-02-07 12:34:11 +000078 pj_str_t local_uri; /**< Uri in From: header. */
79 pj_str_t contact_uri; /**< Uri in Contact: header. */
80
Benny Prijonoccf95622006-02-07 18:48:01 +000081 /* Proxy URLs: */
82
83 pj_str_t proxy;
84 pj_str_t outbound_proxy;
Benny Prijono95196582006-02-09 00:13:40 +000085 pjsip_route_hdr route_set;
86
Benny Prijonoccf95622006-02-07 18:48:01 +000087
88 /* Registration: */
89
90 pj_str_t registrar_uri;
91 pjsip_regc *regc;
92 pj_int32_t reg_timeout;
93 pj_timer_entry regc_timer;
94
95
96 /* Authentication credentials: */
97
98 int cred_count;
99 pjsip_cred_info cred_info[4];
100
101
Benny Prijono268ca612006-02-07 12:34:11 +0000102 /* Threading: */
103
104 int thread_cnt; /**< Thread count. */
105 pj_thread_t *threads[8]; /**< Thread instances. */
106 pj_bool_t quit_flag; /**< To signal thread to quit. */
107
108 /* Transport (UDP): */
109
110 pj_uint16_t sip_port; /**< SIP signaling port. */
111 pj_sock_t sip_sock; /**< SIP UDP socket. */
112 pj_sockaddr_in sip_sock_name; /**< Public/STUN UDP socket addr. */
Benny Prijono268ca612006-02-07 12:34:11 +0000113
114
115
116 /* STUN: */
117
118 pj_str_t stun_srv1;
119 int stun_port1;
120 pj_str_t stun_srv2;
121 int stun_port2;
122
123
124 /* Misc: */
125
126 int log_level; /**< Logging verbosity. */
127 int app_log_level; /**< stdout log verbosity. */
128 unsigned log_decor; /**< Log decoration. */
Benny Prijonoccf95622006-02-07 18:48:01 +0000129 char *log_filename; /**< Log filename. */
Benny Prijono268ca612006-02-07 12:34:11 +0000130
Benny Prijono632ce712006-02-09 14:01:40 +0000131 /* List of invite sessions: */
132
133 struct pjsua_inv_data inv_list;
Benny Prijono1a01ad32006-02-07 21:13:28 +0000134};
Benny Prijono268ca612006-02-07 12:34:11 +0000135
Benny Prijono95196582006-02-09 00:13:40 +0000136
137/** PJSUA instance. */
138extern struct pjsua pjsua;
139
140
Benny Prijono268ca612006-02-07 12:34:11 +0000141
142/*****************************************************************************
Benny Prijono84126ab2006-02-09 09:30:09 +0000143 * PJSUA API (defined in pjsua_core.c).
Benny Prijono268ca612006-02-07 12:34:11 +0000144 */
145
146/**
147 * Initialize pjsua settings with default parameters.
148 */
149void pjsua_default(void);
150
151
152/**
153 * Display error message for the specified error code.
154 */
155void pjsua_perror(const char *title, pj_status_t status);
156
157
158/**
Benny Prijonoccf95622006-02-07 18:48:01 +0000159 * Initialize pjsua application. Application can call this before parsing
160 * application settings.
161 *
162 * This will initialize all libraries, create endpoint instance, and register
163 * pjsip modules. Transport will NOT be created however.
164 *
165 * Application may register module after calling this function.
Benny Prijono268ca612006-02-07 12:34:11 +0000166 */
167pj_status_t pjsua_init(void);
168
169
170/**
Benny Prijonoccf95622006-02-07 18:48:01 +0000171 * Start pjsua stack. Application calls this after pjsua settings has been
172 * configured.
173 *
174 * This will start the transport, worker threads (if any), and registration
175 * process, if registration is configured.
176 */
177pj_status_t pjsua_start(void);
178
179
180/**
Benny Prijono268ca612006-02-07 12:34:11 +0000181 * Destroy pjsua.
182 */
183pj_status_t pjsua_destroy(void);
184
185
Benny Prijono84126ab2006-02-09 09:30:09 +0000186/*****************************************************************************
187 * PJSUA Invite session API (defined in pjsua_inv.c).
188 */
189
Benny Prijono268ca612006-02-07 12:34:11 +0000190/**
191 * Make outgoing call.
192 */
193pj_status_t pjsua_invite(const char *cstr_dest_uri,
194 pjsip_inv_session **p_inv);
195
196
Benny Prijono84126ab2006-02-09 09:30:09 +0000197/**
198 * Handle incoming invite request.
199 */
200pj_bool_t pjsua_inv_on_incoming(pjsip_rx_data *rdata);
201
202
203/**
204 * Callback to be called by session when invite session's state has changed.
205 */
206void pjsua_inv_on_state_changed(pjsip_inv_session *inv, pjsip_event *e);
207
208
209/**
210 * Callback to be called by session when outgoing dialog has forked.
211 * This function will create a forked dialog.
212 */
213void pjsua_inv_on_new_session(pjsip_inv_session *inv, pjsip_event *e);
214
215
216/**
217 * Callback to be called when SDP offer/answer negotiation has just completed
218 * in the session. This function will start/update media if negotiation
219 * has succeeded.
220 */
221void pjsua_inv_on_media_update(pjsip_inv_session *inv, pj_status_t status);
222
223
Benny Prijono268ca612006-02-07 12:34:11 +0000224/*****************************************************************************
Benny Prijono84126ab2006-02-09 09:30:09 +0000225 * PJSUA Client Registration API (defined in pjsua_reg.c).
Benny Prijonoccf95622006-02-07 18:48:01 +0000226 */
227
228/**
229 * Initialize client registration session.
230 *
231 * @param app_callback Optional callback
232 */
233pj_status_t pjsua_regc_init(void);
234
235/**
236 * Update registration or perform unregistration. If renew argument is zero,
237 * this will start unregistration process.
238 */
239void pjsua_regc_update(pj_bool_t renew);
240
241
242/*****************************************************************************
Benny Prijono268ca612006-02-07 12:34:11 +0000243 * User Interface API.
Benny Prijono84126ab2006-02-09 09:30:09 +0000244 *
Benny Prijono268ca612006-02-07 12:34:11 +0000245 * The UI API specifies functions that will be called by pjsua upon
246 * occurence of various events.
247 */
248
249/**
250 * Notify UI when invite state has changed.
251 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000252void pjsua_ui_inv_on_state_changed(pjsip_inv_session *inv, pjsip_event *e);
Benny Prijono268ca612006-02-07 12:34:11 +0000253
254
Benny Prijono1a01ad32006-02-07 21:13:28 +0000255PJ_END_DECL
256
Benny Prijono268ca612006-02-07 12:34:11 +0000257#endif /* __PJSUA_H__ */