blob: 0d7a645428a5e28eac8f720d695e59c9a88acac1 [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
Benny Prijono312aff92006-06-17 04:08:30 +000022/**
23 * @file pjsua.h
24 * @brief PJSUA API.
25 */
26
27
Benny Prijono268ca612006-02-07 12:34:11 +000028/* Include all PJSIP core headers. */
29#include <pjsip.h>
30
31/* Include all PJMEDIA headers. */
32#include <pjmedia.h>
33
Benny Prijono1f9afba2006-02-10 15:57:32 +000034/* Include all PJMEDIA-CODEC headers. */
35#include <pjmedia-codec.h>
36
Benny Prijono268ca612006-02-07 12:34:11 +000037/* Include all PJSIP-UA headers */
38#include <pjsip_ua.h>
39
Benny Prijono834aee32006-02-19 01:38:06 +000040/* Include all PJSIP-SIMPLE headers */
41#include <pjsip_simple.h>
42
Benny Prijono268ca612006-02-07 12:34:11 +000043/* Include all PJLIB-UTIL headers. */
44#include <pjlib-util.h>
45
46/* Include all PJLIB headers. */
47#include <pjlib.h>
48
49
Benny Prijono312aff92006-06-17 04:08:30 +000050/**
51 * @defgroup PJSUA_LIB PJSUA API
52 * @ingroup PJSIP
53 * @brief Very high level API for constructing SIP UA applications.
54 * @{
55 *
56 * PJSUA API is very high level API for constructing SIP user agent
57 * applications. It wraps together the signaling and media functionalities
58 * into an easy to use call API, provides account management, buddy
59 * management, presence, instant messaging, along with multimedia
60 * features such as conferencing, file streaming, local playback,
61 * voice recording, and so on.
62 *
63 * Application must link with <b>pjsua-lib</b> to use this API. In addition,
64 * this library depends on the following libraries:
65 * - <b>pjsip-ua</b>,
66 * - <b>pjsip-simple</b>,
67 * - <b>pjsip-core</b>,
68 * - <b>pjmedia</b>,
69 * - <b>pjmedia-codec</b>,
70 * - <b>pjlib-util</b>, and
71 * - <b>pjlib</b>,
72 *
73 * so application must also link with these libraries as well.
74 *
75 * @section root_using_pjsua_lib Using PJSUA API
76 *
77 * Please refer to @ref using_pjsua_lib on how to use PJSUA API.
78 */
79
Benny Prijono1a01ad32006-02-07 21:13:28 +000080PJ_BEGIN_DECL
81
Benny Prijono632ce712006-02-09 14:01:40 +000082
Benny Prijono312aff92006-06-17 04:08:30 +000083/** Forward declaration */
84typedef struct pjsua_media_config pjsua_media_config;
Benny Prijonoa91a0032006-02-26 21:23:45 +000085
Benny Prijonof3195072006-02-14 21:15:30 +000086
Benny Prijono312aff92006-06-17 04:08:30 +000087/*****************************************************************************
88 * BASE API
89 */
90
Benny Prijonof04ffdd2006-02-21 00:11:18 +000091/**
Benny Prijono312aff92006-06-17 04:08:30 +000092 * @defgroup PJSUA_LIB_BASE Base API
93 * @ingroup PJSUA_LIB
94 * @brief Basic application creation/initialization, logging configuration, etc.
95 * @{
96 *
97 * The base PJSUA API controls PJSUA creation, initialization, and startup, and
98 * also provides various auxiliary functions.
99 *
100 * @section using_pjsua_lib Using PJSUA Library
101 *
102 * @subsection creating_pjsua_lib Creating PJSUA
103 *
104 * Before anything else, application must create PJSUA by calling #pjsua_create().
105 * This, among other things, will initialize PJLIB, which is crucial before
106 * any PJLIB functions can be called.
107 *
108 * @subsection init_pjsua_lib Initializing PJSUA
109 *
110 * After PJSUA is created, application can initialize PJSUA by calling
111 * #pjsua_init(). This function takes several configuration settings in the
112 * argument, so application normally would want to set these configuration
113 * before passing them to #pjsua_init().
114 *
115 * Sample code to initialize PJSUA:
116 \code
117
Benny Prijonob5388cf2007-01-04 22:45:08 +0000118 #include <pjsua-lib/pjsua.h>
119
120 #define THIS_FILE __FILE__
121
122 static pj_status_t app_init(void)
123 {
Benny Prijono312aff92006-06-17 04:08:30 +0000124 pjsua_config ua_cfg;
125 pjsua_logging_config log_cfg;
126 pjsua_media_config media_cfg;
Benny Prijonob5388cf2007-01-04 22:45:08 +0000127 pj_status_t status;
128
129 // Must create pjsua before anything else!
130 status = pjsua_create();
131 if (status != PJ_SUCCESS) {
132 pjsua_perror(THIS_FILE, "Error initializing pjsua", status);
133 return status;
134 }
Benny Prijono312aff92006-06-17 04:08:30 +0000135
136 // Initialize configs with default settings.
137 pjsua_config_default(&ua_cfg);
138 pjsua_logging_config_default(&log_cfg);
139 pjsua_media_config_default(&media_cfg);
140
141 // At the very least, application would want to override
142 // the call callbacks in pjsua_config:
143 ua_cfg.cb.on_incoming_call = ...
144 ua_cfg.cb.on_call_state = ..
145 ...
146
147 // Customize other settings (or initialize them from application specific
148 // configuration file):
149 ...
150
151 // Initialize pjsua
152 status = pjsua_init(&ua_cfg, &log_cfg, &media_cfg);
153 if (status != PJ_SUCCESS) {
154 pjsua_perror(THIS_FILE, "Error initializing pjsua", status);
155 return status;
156 }
Benny Prijonob5388cf2007-01-04 22:45:08 +0000157 .
158 ...
159 }
Benny Prijono312aff92006-06-17 04:08:30 +0000160 \endcode
161 *
162 * @subsection other_init_pjsua_lib Other Initialization
163 *
164 * After PJSUA is initialized with #pjsua_init(), application will normally
165 * need/want to perform the following tasks:
166 *
167 * - create SIP transport with #pjsua_transport_create(). Please see
168 * @ref PJSUA_LIB_TRANSPORT section for more info.
169 * - create one or more SIP accounts with #pjsua_acc_add() or
170 * #pjsua_acc_add_local(). Please see @ref PJSUA_LIB_ACC for more info.
171 * - add one or more buddies with #pjsua_buddy_add(). Please see
172 * @ref PJSUA_LIB_BUDDY section for more info.
173 * - optionally configure the sound device, codec settings, and other
174 * media settings. Please see @ref PJSUA_LIB_MEDIA for more info.
175 *
176 *
177 * @subsection starting_pjsua_lib Starting PJSUA
178 *
179 * After all initializations have been done, application must call
180 * #pjsua_start() to start PJSUA. This function will check that all settings
181 * are properly configured, and apply default settings when it's not, or
182 * report error status when it is unable to recover from missing setting.
183 *
184 * Most settings can be changed during run-time. For example, application
185 * may add, modify, or delete accounts, buddies, or change media settings
186 * during run-time.
Benny Prijonob5388cf2007-01-04 22:45:08 +0000187 *
188 * Sample code:
189 \code
190 static pj_status_t app_run(void)
191 {
192 pj_status_t status;
193
194 // Start pjsua
195 status = pjsua_start();
196 if (status != PJ_SUCCESS) {
197 pjsua_destroy();
198 pjsua_perror(THIS_FILE, "Error starting pjsua", status);
199 return status;
200 }
201
202 // Run application loop
203 while (1) {
204 char choice[10];
205
206 printf("Select menu: ");
207 fgets(choice, sizeof(choice), stdin);
208 ...
209 }
210 }
211 \endcode
Benny Prijonof04ffdd2006-02-21 00:11:18 +0000212 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000213
Benny Prijono312aff92006-06-17 04:08:30 +0000214/** Constant to identify invalid ID for all sorts of IDs. */
215#define PJSUA_INVALID_ID (-1)
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000216
217/** Call identification */
218typedef int pjsua_call_id;
219
Benny Prijono312aff92006-06-17 04:08:30 +0000220/** Account identification */
221typedef int pjsua_acc_id;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000222
223/** Buddy identification */
Benny Prijono8b1889b2006-06-06 18:40:40 +0000224typedef int pjsua_buddy_id;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000225
226/** File player identification */
Benny Prijono8b1889b2006-06-06 18:40:40 +0000227typedef int pjsua_player_id;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000228
229/** File recorder identification */
Benny Prijono8b1889b2006-06-06 18:40:40 +0000230typedef int pjsua_recorder_id;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000231
232/** Conference port identification */
Benny Prijono8b1889b2006-06-06 18:40:40 +0000233typedef int pjsua_conf_port_id;
234
235
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000236
Benny Prijonoa91a0032006-02-26 21:23:45 +0000237/**
Benny Prijono312aff92006-06-17 04:08:30 +0000238 * Maximum proxies in account.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000239 */
Benny Prijono312aff92006-06-17 04:08:30 +0000240#ifndef PJSUA_ACC_MAX_PROXIES
241# define PJSUA_ACC_MAX_PROXIES 8
242#endif
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000243
244
245
246/**
Benny Prijonob5388cf2007-01-04 22:45:08 +0000247 * Logging configuration, which can be (optionally) specified when calling
248 * #pjsua_init(). Application must call #pjsua_logging_config_default() to
249 * initialize this structure with the default values.
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000250 */
251typedef struct pjsua_logging_config
252{
253 /**
254 * Log incoming and outgoing SIP message? Yes!
255 */
256 pj_bool_t msg_logging;
257
258 /**
259 * Input verbosity level. Value 5 is reasonable.
260 */
261 unsigned level;
262
263 /**
264 * Verbosity level for console. Value 4 is reasonable.
265 */
266 unsigned console_level;
267
268 /**
269 * Log decoration.
270 */
271 unsigned decor;
272
273 /**
274 * Optional log filename.
275 */
276 pj_str_t log_filename;
277
278 /**
279 * Optional callback function to be called to write log to
280 * application specific device. This function will be called for
281 * log messages on input verbosity level.
282 */
283 void (*cb)(int level, const char *data, pj_size_t len);
284
285
286} pjsua_logging_config;
287
288
289/**
290 * Use this function to initialize logging config.
291 *
292 * @param cfg The logging config to be initialized.
293 */
294PJ_INLINE(void) pjsua_logging_config_default(pjsua_logging_config *cfg)
295{
Benny Prijonoac623b32006-07-03 15:19:31 +0000296 pj_bzero(cfg, sizeof(*cfg));
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000297
298 cfg->msg_logging = PJ_TRUE;
299 cfg->level = 5;
300 cfg->console_level = 4;
301 cfg->decor = PJ_LOG_HAS_SENDER | PJ_LOG_HAS_TIME |
302 PJ_LOG_HAS_MICRO_SEC | PJ_LOG_HAS_NEWLINE;
303}
304
305/**
306 * Use this function to duplicate logging config.
307 *
308 * @param pool Pool to use.
309 * @param dst Destination config.
310 * @param src Source config.
311 */
312PJ_INLINE(void) pjsua_logging_config_dup(pj_pool_t *pool,
313 pjsua_logging_config *dst,
314 const pjsua_logging_config *src)
315{
316 pj_memcpy(dst, src, sizeof(*src));
317 pj_strdup_with_null(pool, &dst->log_filename, &src->log_filename);
318}
319
320
Benny Prijonodc39fe82006-05-26 12:17:46 +0000321
322/**
Benny Prijonob5388cf2007-01-04 22:45:08 +0000323 * This structure describes application callback to receive various event
324 * notification from PJSUA-API. All of these callbacks are OPTIONAL,
325 * although definitely application would want to implement some of
326 * the important callbacks (such as \a on_incoming_call).
Benny Prijonodc39fe82006-05-26 12:17:46 +0000327 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000328typedef struct pjsua_callback
Benny Prijonodc39fe82006-05-26 12:17:46 +0000329{
330 /**
Benny Prijono9fc735d2006-05-28 14:58:12 +0000331 * Notify application when invite state has changed.
332 * Application may then query the call info to get the
333 * detail call states.
Benny Prijono0875ae82006-12-26 00:11:48 +0000334 *
335 * @param call_id The call index.
336 * @param e Event which causes the call state to change.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000337 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000338 void (*on_call_state)(pjsua_call_id call_id, pjsip_event *e);
Benny Prijonodc39fe82006-05-26 12:17:46 +0000339
340 /**
Benny Prijono8b1889b2006-06-06 18:40:40 +0000341 * Notify application on incoming call.
Benny Prijono0875ae82006-12-26 00:11:48 +0000342 *
343 * @param acc_id The account which match the incoming call.
344 * @param call_id The call id that has just been created for
345 * the call.
346 * @param rdata The incoming INVITE request.
Benny Prijono8b1889b2006-06-06 18:40:40 +0000347 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000348 void (*on_incoming_call)(pjsua_acc_id acc_id, pjsua_call_id call_id,
Benny Prijono8b1889b2006-06-06 18:40:40 +0000349 pjsip_rx_data *rdata);
350
351 /**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000352 * Notify application when media state in the call has changed.
353 * Normal application would need to implement this callback, e.g.
354 * to connect the call's media to sound device.
Benny Prijono0875ae82006-12-26 00:11:48 +0000355 *
356 * @param call_id The call index.
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000357 */
358 void (*on_call_media_state)(pjsua_call_id call_id);
359
360 /**
Benny Prijono0875ae82006-12-26 00:11:48 +0000361 * Notify application upon incoming DTMF digits.
362 *
363 * @param call_id The call index.
364 * @param digit DTMF ASCII digit.
365 */
366 void (*on_dtmf_digit)(pjsua_call_id call_id, int digit);
367
368 /**
Benny Prijonob5388cf2007-01-04 22:45:08 +0000369 * Notify application on call being transfered (i.e. REFER is received).
Benny Prijono9fc735d2006-05-28 14:58:12 +0000370 * Application can decide to accept/reject transfer request
371 * by setting the code (default is 200). When this callback
372 * is not defined, the default behavior is to accept the
373 * transfer.
Benny Prijono0875ae82006-12-26 00:11:48 +0000374 *
375 * @param call_id The call index.
376 * @param dst The destination where the call will be
377 * transfered to.
378 * @param code Status code to be returned for the call transfer
379 * request. On input, it contains status code 200.
Benny Prijono9fc735d2006-05-28 14:58:12 +0000380 */
Benny Prijono4ddad2c2006-10-18 17:16:34 +0000381 void (*on_call_transfer_request)(pjsua_call_id call_id,
382 const pj_str_t *dst,
383 pjsip_status_code *code);
384
385 /**
386 * Notify application of the status of previously sent call
387 * transfer request. Application can monitor the status of the
388 * call transfer request, for example to decide whether to
389 * terminate existing call.
390 *
391 * @param call_id Call ID.
392 * @param status_code Status progress of the transfer request.
393 * @param status_text Status progress text.
394 * @param final If non-zero, no further notification will
395 * be reported. The status_code specified in
396 * this callback is the final status.
397 * @param p_cont Initially will be set to non-zero, application
398 * can set this to FALSE if it no longer wants
399 * to receie further notification (for example,
400 * after it hangs up the call).
401 */
402 void (*on_call_transfer_status)(pjsua_call_id call_id,
403 int status_code,
404 const pj_str_t *status_text,
405 pj_bool_t final,
406 pj_bool_t *p_cont);
Benny Prijono9fc735d2006-05-28 14:58:12 +0000407
408 /**
Benny Prijono053f5222006-11-11 16:16:04 +0000409 * Notify application about incoming INVITE with Replaces header.
410 * Application may reject the request by setting non-2xx code.
411 *
412 * @param call_id The call ID to be replaced.
413 * @param rdata The incoming INVITE request to replace the call.
414 * @param st_code Status code to be set by application. Application
415 * should only return a final status (200-699).
416 * @param st_text Optional status text to be set by application.
417 */
418 void (*on_call_replace_request)(pjsua_call_id call_id,
419 pjsip_rx_data *rdata,
420 int *st_code,
421 pj_str_t *st_text);
422
423 /**
424 * Notify application that an existing call has been replaced with
425 * a new call. This happens when PJSUA-API receives incoming INVITE
426 * request with Replaces header.
427 *
428 * After this callback is called, normally PJSUA-API will disconnect
429 * \a old_call_id and establish \a new_call_id.
430 *
431 * @param old_call_id Existing call which to be replaced with the
432 * new call.
433 * @param new_call_id The new call.
434 * @param rdata The incoming INVITE with Replaces request.
435 */
436 void (*on_call_replaced)(pjsua_call_id old_call_id,
437 pjsua_call_id new_call_id);
438
439
440 /**
Benny Prijono9fc735d2006-05-28 14:58:12 +0000441 * Notify application when registration status has changed.
442 * Application may then query the account info to get the
443 * registration details.
Benny Prijono0875ae82006-12-26 00:11:48 +0000444 *
445 * @param acc_id Account ID.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000446 */
Benny Prijono8b1889b2006-06-06 18:40:40 +0000447 void (*on_reg_state)(pjsua_acc_id acc_id);
Benny Prijonodc39fe82006-05-26 12:17:46 +0000448
449 /**
Benny Prijono9fc735d2006-05-28 14:58:12 +0000450 * Notify application when the buddy state has changed.
451 * Application may then query the buddy into to get the details.
Benny Prijono0875ae82006-12-26 00:11:48 +0000452 *
453 * @param buddy_id The buddy id.
Benny Prijono9fc735d2006-05-28 14:58:12 +0000454 */
Benny Prijono8b1889b2006-06-06 18:40:40 +0000455 void (*on_buddy_state)(pjsua_buddy_id buddy_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +0000456
457 /**
458 * Notify application on incoming pager (i.e. MESSAGE request).
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000459 * Argument call_id will be -1 if MESSAGE request is not related to an
Benny Prijonodc39fe82006-05-26 12:17:46 +0000460 * existing call.
Benny Prijono0875ae82006-12-26 00:11:48 +0000461 *
462 * @param call_id Containts the ID of the call where the IM was
463 * sent, or PJSUA_INVALID_ID if the IM was sent
464 * outside call context.
465 * @param from URI of the sender.
466 * @param to URI of the destination message.
467 * @param contact The Contact URI of the sender, if present.
468 * @param mime_type MIME type of the message.
469 * @param body The message content.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000470 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000471 void (*on_pager)(pjsua_call_id call_id, const pj_str_t *from,
472 const pj_str_t *to, const pj_str_t *contact,
473 const pj_str_t *mime_type, const pj_str_t *body);
474
475 /**
476 * Notify application about the delivery status of outgoing pager
477 * request.
478 *
479 * @param call_id Containts the ID of the call where the IM was
480 * sent, or PJSUA_INVALID_ID if the IM was sent
481 * outside call context.
482 * @param to Destination URI.
483 * @param body Message body.
484 * @param user_data Arbitrary data that was specified when sending
485 * IM message.
486 * @param status Delivery status.
487 * @param reason Delivery status reason.
488 */
489 void (*on_pager_status)(pjsua_call_id call_id,
490 const pj_str_t *to,
491 const pj_str_t *body,
492 void *user_data,
493 pjsip_status_code status,
494 const pj_str_t *reason);
Benny Prijonodc39fe82006-05-26 12:17:46 +0000495
496 /**
Benny Prijono9fc735d2006-05-28 14:58:12 +0000497 * Notify application about typing indication.
Benny Prijono0875ae82006-12-26 00:11:48 +0000498 *
499 * @param call_id Containts the ID of the call where the IM was
500 * sent, or PJSUA_INVALID_ID if the IM was sent
501 * outside call context.
502 * @param from URI of the sender.
503 * @param to URI of the destination message.
504 * @param contact The Contact URI of the sender, if present.
505 * @param is_typing Non-zero if peer is typing, or zero if peer
506 * has stopped typing a message.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000507 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000508 void (*on_typing)(pjsua_call_id call_id, const pj_str_t *from,
509 const pj_str_t *to, const pj_str_t *contact,
510 pj_bool_t is_typing);
Benny Prijonodc39fe82006-05-26 12:17:46 +0000511
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000512} pjsua_callback;
513
514
515
Benny Prijonodc39fe82006-05-26 12:17:46 +0000516
517/**
Benny Prijonob5388cf2007-01-04 22:45:08 +0000518 * This structure describes the settings to control the API and
519 * user agent behavior, and can be specified when calling #pjsua_init().
520 * Before setting the values, application must call #pjsua_config_default()
521 * to initialize this structure with the default values.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000522 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000523typedef struct pjsua_config
524{
525
526 /**
Benny Prijonob5388cf2007-01-04 22:45:08 +0000527 * Maximum calls to support (default: 4). The value specified here
528 * must be smaller than the compile time maximum settings
529 * PJSUA_MAX_CALLS, which by default is 32. To increase this
530 * limit, the library must be recompiled with new PJSUA_MAX_CALLS
531 * value.
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000532 */
533 unsigned max_calls;
534
535 /**
536 * Number of worker threads. Normally application will want to have at
537 * least one worker thread, unless when it wants to poll the library
538 * periodically, which in this case the worker thread can be set to
539 * zero.
540 */
541 unsigned thread_cnt;
542
543 /**
Benny Prijonofa9e5b12006-10-08 12:39:34 +0000544 * Number of nameservers. If no name server is configured, the SIP SRV
545 * resolution would be disabled, and domain will be resolved with
546 * standard pj_gethostbyname() function.
547 */
548 unsigned nameserver_count;
549
550 /**
551 * Array of nameservers to be used by the SIP resolver subsystem.
552 * The order of the name server specifies the priority (first name
553 * server will be used first, unless it is not reachable).
554 */
555 pj_str_t nameserver[4];
556
557 /**
Benny Prijonob5388cf2007-01-04 22:45:08 +0000558 * Number of outbound proxies in the \a outbound_proxy array.
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000559 */
560 unsigned outbound_proxy_cnt;
561
562 /**
563 * Specify the URL of outbound proxies to visit for all outgoing requests.
564 * The outbound proxies will be used for all accounts, and it will
565 * be used to build the route set for outgoing requests. The final
566 * route set for outgoing requests will consists of the outbound proxies
567 * and the proxy configured in the account.
568 */
569 pj_str_t outbound_proxy[4];
570
571 /**
572 * Number of credentials in the credential array.
573 */
574 unsigned cred_count;
575
576 /**
577 * Array of credentials. These credentials will be used by all accounts,
Benny Prijonob5388cf2007-01-04 22:45:08 +0000578 * and can be used to authenticate against outbound proxies. If the
579 * credential is specific to the account, then application should set
580 * the credential in the pjsua_acc_config rather than the credential
581 * here.
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000582 */
583 pjsip_cred_info cred_info[PJSUA_ACC_MAX_PROXIES];
584
585 /**
Benny Prijonob5388cf2007-01-04 22:45:08 +0000586 * Application callback to receive various event notifications from
587 * the library.
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000588 */
589 pjsua_callback cb;
590
Benny Prijono56315612006-07-18 14:39:40 +0000591 /**
Benny Prijonob5388cf2007-01-04 22:45:08 +0000592 * Optional user agent string (default empty). If it's empty, no
593 * User-Agent header will be sent with outgoing requests.
Benny Prijono56315612006-07-18 14:39:40 +0000594 */
595 pj_str_t user_agent;
596
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000597} pjsua_config;
598
599
600/**
601 * Use this function to initialize pjsua config.
602 *
603 * @param cfg pjsua config to be initialized.
604 */
605PJ_INLINE(void) pjsua_config_default(pjsua_config *cfg)
606{
Benny Prijonoac623b32006-07-03 15:19:31 +0000607 pj_bzero(cfg, sizeof(*cfg));
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000608
609 cfg->max_calls = 4;
610 cfg->thread_cnt = 1;
611}
612
613
614/**
615 * Duplicate credential.
616 */
617PJ_INLINE(void) pjsip_cred_dup( pj_pool_t *pool,
618 pjsip_cred_info *dst,
619 const pjsip_cred_info *src)
620{
621 pj_strdup_with_null(pool, &dst->realm, &src->realm);
622 pj_strdup_with_null(pool, &dst->scheme, &src->scheme);
623 pj_strdup_with_null(pool, &dst->username, &src->username);
624 pj_strdup_with_null(pool, &dst->data, &src->data);
625
626}
627
628
629/**
630 * Duplicate pjsua_config.
631 */
632PJ_INLINE(void) pjsua_config_dup(pj_pool_t *pool,
633 pjsua_config *dst,
634 const pjsua_config *src)
635{
636 unsigned i;
637
638 pj_memcpy(dst, src, sizeof(*src));
639
640 for (i=0; i<src->outbound_proxy_cnt; ++i) {
641 pj_strdup_with_null(pool, &dst->outbound_proxy[i],
642 &src->outbound_proxy[i]);
643 }
644
645 for (i=0; i<src->cred_count; ++i) {
646 pjsip_cred_dup(pool, &dst->cred_info[i], &src->cred_info[i]);
647 }
Benny Prijono56315612006-07-18 14:39:40 +0000648
649 pj_strdup_with_null(pool, &dst->user_agent, &src->user_agent);
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000650}
651
652
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000653
654/**
655 * This structure describes additional information to be sent with
Benny Prijonob5388cf2007-01-04 22:45:08 +0000656 * outgoing SIP message. It can (optionally) be specified for example
657 * with #pjsua_call_make_call(), #pjsua_call_answer(), #pjsua_call_hangup(),
658 * #pjsua_call_set_hold(), #pjsua_call_send_im(), and many more.
659 *
660 * Application MUST call #pjsua_msg_data_init() to initialize this
661 * structure before setting its values.
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000662 */
663typedef struct pjsua_msg_data
664{
665 /**
666 * Additional message headers as linked list.
667 */
668 pjsip_hdr hdr_list;
669
670 /**
671 * MIME type of optional message body.
672 */
673 pj_str_t content_type;
674
675 /**
676 * Optional message body.
677 */
678 pj_str_t msg_body;
679
680} pjsua_msg_data;
681
682
683/**
684 * Initialize message data.
685 *
686 * @param msg_data Message data to be initialized.
687 */
688PJ_INLINE(void) pjsua_msg_data_init(pjsua_msg_data *msg_data)
689{
Benny Prijonoac623b32006-07-03 15:19:31 +0000690 pj_bzero(msg_data, sizeof(*msg_data));
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000691 pj_list_init(&msg_data->hdr_list);
692}
Benny Prijono8b1889b2006-06-06 18:40:40 +0000693
Benny Prijono268ca612006-02-07 12:34:11 +0000694
Benny Prijono268ca612006-02-07 12:34:11 +0000695
696/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000697 * Instantiate pjsua application. Application must call this function before
698 * calling any other functions, to make sure that the underlying libraries
699 * are properly initialized. Once this function has returned success,
700 * application must call pjsua_destroy() before quitting.
701 *
702 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000703 */
704PJ_DECL(pj_status_t) pjsua_create(void);
705
706
707/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000708 * Initialize pjsua with the specified settings. All the settings are
709 * optional, and the default values will be used when the config is not
710 * specified.
Benny Prijonoccf95622006-02-07 18:48:01 +0000711 *
Benny Prijonob5388cf2007-01-04 22:45:08 +0000712 * Note that #pjsua_create() MUST be called before calling this function.
713 *
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000714 * @param ua_cfg User agent configuration.
715 * @param log_cfg Optional logging configuration.
716 * @param media_cfg Optional media configuration.
Benny Prijonoccf95622006-02-07 18:48:01 +0000717 *
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000718 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono268ca612006-02-07 12:34:11 +0000719 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000720PJ_DECL(pj_status_t) pjsua_init(const pjsua_config *ua_cfg,
721 const pjsua_logging_config *log_cfg,
722 const pjsua_media_config *media_cfg);
Benny Prijono268ca612006-02-07 12:34:11 +0000723
724
725/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000726 * Application is recommended to call this function after all initialization
727 * is done, so that the library can do additional checking set up
728 * additional
Benny Prijonoccf95622006-02-07 18:48:01 +0000729 *
Benny Prijonob5388cf2007-01-04 22:45:08 +0000730 * Application may call this function anytime after #pjsua_init().
731 *
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000732 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonoccf95622006-02-07 18:48:01 +0000733 */
Benny Prijonodc39fe82006-05-26 12:17:46 +0000734PJ_DECL(pj_status_t) pjsua_start(void);
Benny Prijonoccf95622006-02-07 18:48:01 +0000735
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000736
Benny Prijonoccf95622006-02-07 18:48:01 +0000737/**
Benny Prijonob5388cf2007-01-04 22:45:08 +0000738 * Destroy pjsua. Application is recommended to perform graceful shutdown
739 * before calling this function (such as unregister the account from the SIP
740 * server, terminate presense subscription, and hangup active calls), however,
741 * this function will do all of these if it finds there are active sessions
742 * that need to be terminated. This function will approximately block for
743 * one second to wait for replies from remote.
744 *
745 * Application.may safely call this function more than once if it doesn't
746 * keep track of it's state.
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000747 *
748 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono268ca612006-02-07 12:34:11 +0000749 */
Benny Prijonodc39fe82006-05-26 12:17:46 +0000750PJ_DECL(pj_status_t) pjsua_destroy(void);
Benny Prijonoa91a0032006-02-26 21:23:45 +0000751
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000752
Benny Prijono9fc735d2006-05-28 14:58:12 +0000753/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000754 * Poll pjsua for events, and if necessary block the caller thread for
755 * the specified maximum interval (in miliseconds).
756 *
Benny Prijonob5388cf2007-01-04 22:45:08 +0000757 * Application doesn't normally need to call this function if it has
758 * configured worker thread (\a thread_cnt field) in pjsua_config structure,
759 * because polling then will be done by these worker threads instead.
760 *
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000761 * @param msec_timeout Maximum time to wait, in miliseconds.
762 *
763 * @return The number of events that have been handled during the
764 * poll. Negative value indicates error, and application
765 * can retrieve the error as (err = -return_value).
Benny Prijonob9b32ab2006-06-01 12:28:44 +0000766 */
767PJ_DECL(int) pjsua_handle_events(unsigned msec_timeout);
768
769
770/**
Benny Prijonob5388cf2007-01-04 22:45:08 +0000771 * Create memory pool to be used by the application. Once application
772 * finished using the pool, it must be released with pj_pool_release().
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000773 *
774 * @param name Optional pool name.
Benny Prijono312aff92006-06-17 04:08:30 +0000775 * @param init_size Initial size of the pool.
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000776 * @param increment Increment size.
777 *
778 * @return The pool, or NULL when there's no memory.
779 */
780PJ_DECL(pj_pool_t*) pjsua_pool_create(const char *name, pj_size_t init_size,
781 pj_size_t increment);
782
783
784/**
785 * Application can call this function at any time (after pjsua_create(), of
786 * course) to change logging settings.
787 *
788 * @param c Logging configuration.
789 *
790 * @return PJ_SUCCESS on success, or the appropriate error code.
791 */
792PJ_DECL(pj_status_t) pjsua_reconfigure_logging(const pjsua_logging_config *c);
793
794
795/**
796 * Internal function to get SIP endpoint instance of pjsua, which is
797 * needed for example to register module, create transports, etc.
Benny Prijonob5388cf2007-01-04 22:45:08 +0000798 * Only valid after #pjsua_init() is called.
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000799 *
800 * @return SIP endpoint instance.
Benny Prijono9fc735d2006-05-28 14:58:12 +0000801 */
802PJ_DECL(pjsip_endpoint*) pjsua_get_pjsip_endpt(void);
803
804/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000805 * Internal function to get media endpoint instance.
806 * Only valid after #pjsua_init() is called.
807 *
808 * @return Media endpoint instance.
Benny Prijono9fc735d2006-05-28 14:58:12 +0000809 */
810PJ_DECL(pjmedia_endpt*) pjsua_get_pjmedia_endpt(void);
811
Benny Prijono97b87172006-08-24 14:25:14 +0000812/**
813 * Internal function to get PJSUA pool factory.
Benny Prijonob5388cf2007-01-04 22:45:08 +0000814 * Only valid after #pjsua_create() is called.
Benny Prijono97b87172006-08-24 14:25:14 +0000815 *
816 * @return Pool factory currently used by PJSUA.
817 */
818PJ_DECL(pj_pool_factory*) pjsua_get_pool_factory(void);
819
820
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000821
822/*****************************************************************************
Benny Prijono312aff92006-06-17 04:08:30 +0000823 * Utilities.
824 *
Benny Prijono9fc735d2006-05-28 14:58:12 +0000825 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000826
827/**
Benny Prijonob5388cf2007-01-04 22:45:08 +0000828 * This is a utility function to verify that valid SIP url is given. If the
829 * URL is valid, PJ_SUCCESS will be returned.
Benny Prijono312aff92006-06-17 04:08:30 +0000830 *
831 * @param c_url The URL, as NULL terminated string.
832 *
833 * @return PJ_SUCCESS on success, or the appropriate error code.
834 */
835PJ_DECL(pj_status_t) pjsua_verify_sip_url(const char *c_url);
836
837
838/**
Benny Prijonob5388cf2007-01-04 22:45:08 +0000839 * This is a utility function to display error message for the specified
840 * error code. The error message will be sent to the log.
Benny Prijono312aff92006-06-17 04:08:30 +0000841 *
842 * @param sender The log sender field.
843 * @param title Message title for the error.
844 * @param status Status code.
845 */
846PJ_DECL(void) pjsua_perror(const char *sender, const char *title,
847 pj_status_t status);
848
849
850
851
852/**
853 * @}
854 */
855
856
857
858/*****************************************************************************
859 * TRANSPORT API
860 */
861
862/**
863 * @defgroup PJSUA_LIB_TRANSPORT Signaling Transport
864 * @ingroup PJSUA_LIB
865 * @brief API for managing SIP transports
866 * @{
867 * SIP transport must be created before adding an account. SIP transport is
868 * created by calling #pjsua_transport_create() function.
869 */
870
871
872/** SIP transport identification */
873typedef int pjsua_transport_id;
874
875
876/**
Benny Prijonob5388cf2007-01-04 22:45:08 +0000877 * This structure describes STUN configuration for SIP and media transport,
878 * and is embedded inside pjsua_transport_config structure.
Benny Prijono312aff92006-06-17 04:08:30 +0000879 */
880typedef struct pjsua_stun_config
881{
882 /**
883 * The first STUN server IP address or hostname.
884 */
885 pj_str_t stun_srv1;
886
887 /**
888 * Port number of the first STUN server.
889 * If zero, default STUN port will be used.
890 */
891 unsigned stun_port1;
892
893 /**
894 * Optional second STUN server IP address or hostname, for which the
895 * result of the mapping request will be compared to. If the value
896 * is empty, only one STUN server will be used.
897 */
898 pj_str_t stun_srv2;
899
900 /**
901 * Port number of the second STUN server.
902 * If zero, default STUN port will be used.
903 */
904 unsigned stun_port2;
905
906} pjsua_stun_config;
907
908
909
910/**
911 * Call this function to initialize STUN config with default values.
912 *
913 * @param cfg The STUN config to be initialized.
914 */
915PJ_INLINE(void) pjsua_stun_config_default(pjsua_stun_config *cfg)
916{
Benny Prijonoac623b32006-07-03 15:19:31 +0000917 pj_bzero(cfg, sizeof(*cfg));
Benny Prijono312aff92006-06-17 04:08:30 +0000918}
919
920
921/**
Benny Prijono0a5cad82006-09-26 13:21:02 +0000922 * Transport configuration for creating transports for both SIP
Benny Prijonob5388cf2007-01-04 22:45:08 +0000923 * and media. Before setting some values to this structure, application
924 * MUST call #pjsua_transport_config_default() to initialize its
925 * values with default settings.
Benny Prijono312aff92006-06-17 04:08:30 +0000926 */
927typedef struct pjsua_transport_config
928{
929 /**
930 * UDP port number to bind locally. This setting MUST be specified
931 * even when default port is desired. If the value is zero, the
932 * transport will be bound to any available port, and application
933 * can query the port by querying the transport info.
934 */
935 unsigned port;
936
937 /**
Benny Prijono0a5cad82006-09-26 13:21:02 +0000938 * Optional address to advertise as the address of this transport.
939 * Application can specify any address or hostname for this field,
940 * for example it can point to one of the interface address in the
941 * system, or it can point to the public address of a NAT router
942 * where port mappings have been configured for the application.
943 *
944 * Note: this option can be used for both UDP and TCP as well!
Benny Prijono312aff92006-06-17 04:08:30 +0000945 */
Benny Prijono0a5cad82006-09-26 13:21:02 +0000946 pj_str_t public_addr;
947
948 /**
949 * Optional address where the socket should be bound to. This option
950 * SHOULD only be used to selectively bind the socket to particular
951 * interface (instead of 0.0.0.0), and SHOULD NOT be used to set the
952 * published address of a transport (the public_addr field should be
953 * used for that purpose).
954 *
955 * Note that unlike public_addr field, the address (or hostname) here
956 * MUST correspond to the actual interface address in the host, since
957 * this address will be specified as bind() argument.
958 */
959 pj_str_t bound_addr;
Benny Prijono312aff92006-06-17 04:08:30 +0000960
961 /**
962 * Flag to indicate whether STUN should be used.
963 */
964 pj_bool_t use_stun;
965
966 /**
967 * STUN configuration, must be specified when STUN is used.
968 */
969 pjsua_stun_config stun_config;
970
Benny Prijono6e0e54b2006-12-08 21:58:31 +0000971 /**
Benny Prijonob5388cf2007-01-04 22:45:08 +0000972 * This specifies TLS settings for TLS transport. It is only be used
973 * when this transport config is being used to create a SIP TLS
974 * transport.
Benny Prijono6e0e54b2006-12-08 21:58:31 +0000975 */
Benny Prijonof3bbc132006-12-25 06:43:59 +0000976 pjsip_tls_setting tls_setting;
Benny Prijono6e0e54b2006-12-08 21:58:31 +0000977
Benny Prijono312aff92006-06-17 04:08:30 +0000978} pjsua_transport_config;
979
980
981/**
982 * Call this function to initialize UDP config with default values.
983 *
984 * @param cfg The UDP config to be initialized.
985 */
986PJ_INLINE(void) pjsua_transport_config_default(pjsua_transport_config *cfg)
987{
Benny Prijonoac623b32006-07-03 15:19:31 +0000988 pj_bzero(cfg, sizeof(*cfg));
Benny Prijonob5388cf2007-01-04 22:45:08 +0000989 pjsua_stun_config_default(&cfg->stun_config);
Benny Prijonof3bbc132006-12-25 06:43:59 +0000990 pjsip_tls_setting_default(&cfg->tls_setting);
Benny Prijono312aff92006-06-17 04:08:30 +0000991}
992
993
994/**
Benny Prijonob5388cf2007-01-04 22:45:08 +0000995 * This is a utility function to normalize STUN config. It's only
996 * used internally by the library.
997 *
998 * @param cfg The STUN config to be initialized.
Benny Prijono312aff92006-06-17 04:08:30 +0000999 */
1000PJ_INLINE(void) pjsua_normalize_stun_config( pjsua_stun_config *cfg )
1001{
1002 if (cfg->stun_srv1.slen) {
1003
1004 if (cfg->stun_port1 == 0)
1005 cfg->stun_port1 = 3478;
1006
1007 if (cfg->stun_srv2.slen == 0) {
1008 cfg->stun_srv2 = cfg->stun_srv1;
1009 cfg->stun_port2 = cfg->stun_port1;
1010 } else {
1011 if (cfg->stun_port2 == 0)
1012 cfg->stun_port2 = 3478;
1013 }
1014
1015 } else {
1016 cfg->stun_port1 = 0;
1017 cfg->stun_srv2.slen = 0;
1018 cfg->stun_port2 = 0;
1019 }
1020}
1021
1022
1023/**
1024 * Duplicate transport config.
1025 */
1026PJ_INLINE(void) pjsua_transport_config_dup(pj_pool_t *pool,
1027 pjsua_transport_config *dst,
1028 const pjsua_transport_config *src)
1029{
1030 pj_memcpy(dst, src, sizeof(*src));
1031
1032 if (src->stun_config.stun_srv1.slen) {
1033 pj_strdup_with_null(pool, &dst->stun_config.stun_srv1,
1034 &src->stun_config.stun_srv1);
1035 }
1036
1037 if (src->stun_config.stun_srv2.slen) {
1038 pj_strdup_with_null(pool, &dst->stun_config.stun_srv2,
1039 &src->stun_config.stun_srv2);
1040 }
1041
1042 pjsua_normalize_stun_config(&dst->stun_config);
1043}
1044
1045
1046
1047/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00001048 * This structure describes transport information returned by
1049 * #pjsua_transport_get_info() function.
Benny Prijono312aff92006-06-17 04:08:30 +00001050 */
1051typedef struct pjsua_transport_info
1052{
1053 /**
1054 * PJSUA transport identification.
1055 */
1056 pjsua_transport_id id;
1057
1058 /**
1059 * Transport type.
1060 */
1061 pjsip_transport_type_e type;
1062
1063 /**
1064 * Transport type name.
1065 */
1066 pj_str_t type_name;
1067
1068 /**
1069 * Transport string info/description.
1070 */
1071 pj_str_t info;
1072
1073 /**
1074 * Transport flag (see ##pjsip_transport_flags_e).
1075 */
1076 unsigned flag;
1077
1078 /**
1079 * Local address length.
1080 */
1081 unsigned addr_len;
1082
1083 /**
1084 * Local/bound address.
1085 */
1086 pj_sockaddr local_addr;
1087
1088 /**
1089 * Published address (or transport address name).
1090 */
1091 pjsip_host_port local_name;
1092
1093 /**
1094 * Current number of objects currently referencing this transport.
1095 */
1096 unsigned usage_count;
1097
1098
1099} pjsua_transport_info;
1100
1101
1102/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00001103 * Create and start a new SIP transport according to the specified
1104 * settings.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001105 *
1106 * @param type Transport type.
1107 * @param cfg Transport configuration.
1108 * @param p_id Optional pointer to receive transport ID.
1109 *
1110 * @return PJ_SUCCESS on success, or the appropriate error code.
1111 */
1112PJ_DECL(pj_status_t) pjsua_transport_create(pjsip_transport_type_e type,
1113 const pjsua_transport_config *cfg,
1114 pjsua_transport_id *p_id);
1115
1116/**
1117 * Register transport that has been created by application.
1118 *
1119 * @param tp Transport instance.
1120 * @param p_id Optional pointer to receive transport ID.
1121 *
1122 * @return PJ_SUCCESS on success, or the appropriate error code.
1123 */
1124PJ_DECL(pj_status_t) pjsua_transport_register(pjsip_transport *tp,
1125 pjsua_transport_id *p_id);
1126
1127
1128/**
1129 * Enumerate all transports currently created in the system.
1130 *
1131 * @param id Array to receive transport ids.
1132 * @param count In input, specifies the maximum number of elements.
1133 * On return, it contains the actual number of elements.
1134 *
1135 * @return PJ_SUCCESS on success, or the appropriate error code.
1136 */
1137PJ_DECL(pj_status_t) pjsua_enum_transports( pjsua_transport_id id[],
1138 unsigned *count );
1139
1140
1141/**
1142 * Get information about transports.
1143 *
1144 * @param id Transport ID.
1145 * @param info Pointer to receive transport info.
1146 *
1147 * @return PJ_SUCCESS on success, or the appropriate error code.
1148 */
1149PJ_DECL(pj_status_t) pjsua_transport_get_info(pjsua_transport_id id,
1150 pjsua_transport_info *info);
1151
1152
1153/**
1154 * Disable a transport or re-enable it. By default transport is always
1155 * enabled after it is created. Disabling a transport does not necessarily
1156 * close the socket, it will only discard incoming messages and prevent
1157 * the transport from being used to send outgoing messages.
1158 *
1159 * @param id Transport ID.
1160 * @param enabled Non-zero to enable, zero to disable.
1161 *
1162 * @return PJ_SUCCESS on success, or the appropriate error code.
1163 */
1164PJ_DECL(pj_status_t) pjsua_transport_set_enable(pjsua_transport_id id,
1165 pj_bool_t enabled);
1166
1167
1168/**
1169 * Close the transport. If transport is forcefully closed, it will be
1170 * immediately closed, and any pending transactions that are using the
Benny Prijonob5388cf2007-01-04 22:45:08 +00001171 * transport may not terminate properly (it may even crash). Otherwise,
1172 * the system will wait until all transactions are closed while preventing
1173 * new users from using the transport, and will close the transport when
1174 * it is safe to do so.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001175 *
1176 * @param id Transport ID.
1177 * @param force Non-zero to immediately close the transport. This
1178 * is not recommended!
1179 *
1180 * @return PJ_SUCCESS on success, or the appropriate error code.
1181 */
1182PJ_DECL(pj_status_t) pjsua_transport_close( pjsua_transport_id id,
1183 pj_bool_t force );
Benny Prijono9fc735d2006-05-28 14:58:12 +00001184
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001185/**
Benny Prijono312aff92006-06-17 04:08:30 +00001186 * @}
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001187 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001188
1189
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001190
1191
1192/*****************************************************************************
Benny Prijono312aff92006-06-17 04:08:30 +00001193 * ACCOUNT API
Benny Prijonoa91a0032006-02-26 21:23:45 +00001194 */
1195
Benny Prijono312aff92006-06-17 04:08:30 +00001196
1197/**
1198 * @defgroup PJSUA_LIB_ACC Account Management
1199 * @ingroup PJSUA_LIB
1200 * @brief PJSUA supports multiple accounts..
1201 * @{
1202 * PJSUA accounts provide identity (or identities) of the user who is currently
1203 * using the application. More than one account maybe created with PJSUA.
1204 *
1205 * Account may or may not have client registration associated with it.
1206 * An account is also associated with <b>route set</b> and some <b>authentication
1207 * credentials</b>, which are used when sending SIP request messages using the
1208 * account. An account also has presence's <b>online status</b>, which
1209 * will be reported to remote peer when the subscribe to the account's
1210 * presence.
1211 *
1212 * At least one account MUST be created in the application. If no user
1213 * association is required, application can create a userless account by
1214 * calling #pjsua_acc_add_local(). A userless account identifies local endpoint
1215 * instead of a particular user.
1216 *
1217 * Also one account must be set as the <b>default account</b>, which is used as
1218 * the account to use when PJSUA fails to match a request with any other
1219 * accounts.
1220 *
1221 * When sending outgoing SIP requests (such as making calls or sending
1222 * instant messages), normally PJSUA requires the application to specify
1223 * which account to use for the request. If no account is specified,
1224 * PJSUA may be able to select the account by matching the destination
1225 * domain name, and fall back to default account when no match is found.
1226 */
1227
1228/**
1229 * Maximum accounts.
1230 */
1231#ifndef PJSUA_MAX_ACC
1232# define PJSUA_MAX_ACC 8
1233#endif
1234
1235
1236/**
1237 * Default registration interval.
1238 */
1239#ifndef PJSUA_REG_INTERVAL
1240# define PJSUA_REG_INTERVAL 55
1241#endif
1242
1243
1244/**
Benny Prijono3a5e1ab2006-08-15 20:26:34 +00001245 * Default PUBLISH expiration
1246 */
1247#ifndef PJSUA_PUBLISH_EXPIRATION
1248# define PJSUA_PUBLISH_EXPIRATION 600
1249#endif
1250
1251
1252/**
Benny Prijono093d3022006-09-24 00:07:11 +00001253 * Default account priority.
1254 */
1255#ifndef PJSUA_DEFAULT_ACC_PRIORITY
1256# define PJSUA_DEFAULT_ACC_PRIORITY 0
1257#endif
1258
1259
1260/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00001261 * This structure describes account configuration to be specified when
1262 * adding a new account with #pjsua_acc_add(). Application MUST initialize
1263 * this structure first by calling #pjsua_acc_config_default().
Benny Prijono312aff92006-06-17 04:08:30 +00001264 */
1265typedef struct pjsua_acc_config
1266{
Benny Prijono093d3022006-09-24 00:07:11 +00001267 /**
1268 * Account priority, which is used to control the order of matching
1269 * incoming/outgoing requests. The higher the number means the higher
1270 * the priority is, and the account will be matched first.
1271 */
1272 int priority;
1273
Benny Prijono312aff92006-06-17 04:08:30 +00001274 /**
1275 * The full SIP URL for the account. The value can take name address or
1276 * URL format, and will look something like "sip:account@serviceprovider".
1277 *
1278 * This field is mandatory.
1279 */
1280 pj_str_t id;
1281
1282 /**
1283 * This is the URL to be put in the request URI for the registration,
1284 * and will look something like "sip:serviceprovider".
1285 *
1286 * This field should be specified if registration is desired. If the
1287 * value is empty, no account registration will be performed.
1288 */
1289 pj_str_t reg_uri;
1290
Benny Prijono3a5e1ab2006-08-15 20:26:34 +00001291 /**
Benny Prijonob5388cf2007-01-04 22:45:08 +00001292 * If this flag is set, the presence information of this account will
1293 * be PUBLISH-ed to the server where the account belongs.
Benny Prijono3a5e1ab2006-08-15 20:26:34 +00001294 */
1295 pj_bool_t publish_enabled;
1296
Benny Prijono312aff92006-06-17 04:08:30 +00001297 /**
1298 * Optional URI to be put as Contact for this account. It is recommended
1299 * that this field is left empty, so that the value will be calculated
1300 * automatically based on the transport address.
1301 */
Benny Prijonob4a17c92006-07-10 14:40:21 +00001302 pj_str_t force_contact;
Benny Prijono312aff92006-06-17 04:08:30 +00001303
1304 /**
1305 * Number of proxies in the proxy array below.
1306 */
1307 unsigned proxy_cnt;
1308
1309 /**
1310 * Optional URI of the proxies to be visited for all outgoing requests
1311 * that are using this account (REGISTER, INVITE, etc). Application need
1312 * to specify these proxies if the service provider requires that requests
1313 * destined towards its network should go through certain proxies first
1314 * (for example, border controllers).
1315 *
1316 * These proxies will be put in the route set for this account, with
1317 * maintaining the orders (the first proxy in the array will be visited
Benny Prijonob5388cf2007-01-04 22:45:08 +00001318 * first). If global outbound proxies are configured in pjsua_config,
1319 * then these account proxies will be placed after the global outbound
1320 * proxies in the routeset.
Benny Prijono312aff92006-06-17 04:08:30 +00001321 */
1322 pj_str_t proxy[PJSUA_ACC_MAX_PROXIES];
1323
1324 /**
1325 * Optional interval for registration, in seconds. If the value is zero,
1326 * default interval will be used (PJSUA_REG_INTERVAL, 55 seconds).
1327 */
1328 unsigned reg_timeout;
1329
1330 /**
1331 * Number of credentials in the credential array.
1332 */
1333 unsigned cred_count;
1334
1335 /**
1336 * Array of credentials. If registration is desired, normally there should
1337 * be at least one credential specified, to successfully authenticate
1338 * against the service provider. More credentials can be specified, for
1339 * example when the requests are expected to be challenged by the
1340 * proxies in the route set.
1341 */
1342 pjsip_cred_info cred_info[PJSUA_ACC_MAX_PROXIES];
1343
Benny Prijono62c5c5b2007-01-13 23:22:40 +00001344 /**
1345 * Optionally bind this account to specific transport. This normally is
1346 * not a good idea, as account should be able to send requests using
1347 * any available transports according to the destination. But some
1348 * application may want to have explicit control over the transport to
1349 * use, so in that case it can set this field.
1350 *
1351 * Default: -1 (PJSUA_INVALID_ID)
1352 *
1353 * @see pjsua_acc_set_transport()
1354 */
1355 pjsua_transport_id transport_id;
1356
Benny Prijono312aff92006-06-17 04:08:30 +00001357} pjsua_acc_config;
1358
1359
1360/**
1361 * Call this function to initialize account config with default values.
1362 *
1363 * @param cfg The account config to be initialized.
1364 */
1365PJ_INLINE(void) pjsua_acc_config_default(pjsua_acc_config *cfg)
1366{
Benny Prijonoac623b32006-07-03 15:19:31 +00001367 pj_bzero(cfg, sizeof(*cfg));
Benny Prijono312aff92006-06-17 04:08:30 +00001368
1369 cfg->reg_timeout = PJSUA_REG_INTERVAL;
Benny Prijono62c5c5b2007-01-13 23:22:40 +00001370 cfg->transport_id = PJSUA_INVALID_ID;
Benny Prijono312aff92006-06-17 04:08:30 +00001371}
1372
1373
1374
1375/**
1376 * Account info. Application can query account info by calling
1377 * #pjsua_acc_get_info().
1378 */
1379typedef struct pjsua_acc_info
1380{
1381 /**
1382 * The account ID.
1383 */
1384 pjsua_acc_id id;
1385
1386 /**
1387 * Flag to indicate whether this is the default account.
1388 */
1389 pj_bool_t is_default;
1390
1391 /**
1392 * Account URI
1393 */
1394 pj_str_t acc_uri;
1395
1396 /**
1397 * Flag to tell whether this account has registration setting
1398 * (reg_uri is not empty).
1399 */
1400 pj_bool_t has_registration;
1401
1402 /**
1403 * An up to date expiration interval for account registration session.
1404 */
1405 int expires;
1406
1407 /**
1408 * Last registration status code. If status code is zero, the account
1409 * is currently not registered. Any other value indicates the SIP
1410 * status code of the registration.
1411 */
1412 pjsip_status_code status;
1413
1414 /**
1415 * String describing the registration status.
1416 */
1417 pj_str_t status_text;
1418
1419 /**
1420 * Presence online status for this account.
1421 */
1422 pj_bool_t online_status;
1423
1424 /**
1425 * Buffer that is used internally to store the status text.
1426 */
1427 char buf_[PJ_ERR_MSG_SIZE];
1428
1429} pjsua_acc_info;
1430
1431
1432
1433/**
1434 * Get number of current accounts.
1435 *
1436 * @return Current number of accounts.
1437 */
1438PJ_DECL(unsigned) pjsua_acc_get_count(void);
1439
1440
1441/**
1442 * Check if the specified account ID is valid.
1443 *
1444 * @param acc_id Account ID to check.
1445 *
1446 * @return Non-zero if account ID is valid.
1447 */
1448PJ_DECL(pj_bool_t) pjsua_acc_is_valid(pjsua_acc_id acc_id);
1449
1450
1451/**
Benny Prijono21b9ad92006-08-15 13:11:22 +00001452 * Set default account to be used when incoming and outgoing
1453 * requests doesn't match any accounts.
1454 *
1455 * @param acc_id The account ID to be used as default.
1456 *
1457 * @return PJ_SUCCESS on success.
1458 */
1459PJ_DECL(pj_status_t) pjsua_acc_set_default(pjsua_acc_id acc_id);
1460
1461
1462/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00001463 * Get default account to be used when receiving incoming requests (calls),
1464 * when the destination of the incoming call doesn't match any other
1465 * accounts.
Benny Prijono21b9ad92006-08-15 13:11:22 +00001466 *
1467 * @return The default account ID, or PJSUA_INVALID_ID if no
1468 * default account is configured.
1469 */
1470PJ_DECL(pjsua_acc_id) pjsua_acc_get_default(void);
1471
1472
1473/**
Benny Prijono312aff92006-06-17 04:08:30 +00001474 * Add a new account to pjsua. PJSUA must have been initialized (with
Benny Prijonob5388cf2007-01-04 22:45:08 +00001475 * #pjsua_init()) before calling this function. If registration is configured
1476 * for this account, this function would also start the SIP registration
1477 * session with the SIP registrar server. This SIP registration session
1478 * will be maintained internally by the library, and application doesn't
1479 * need to do anything to maintain the registration session.
1480 *
Benny Prijono312aff92006-06-17 04:08:30 +00001481 *
1482 * @param cfg Account configuration.
1483 * @param is_default If non-zero, this account will be set as the default
1484 * account. The default account will be used when sending
1485 * outgoing requests (e.g. making call) when no account is
1486 * specified, and when receiving incoming requests when the
1487 * request does not match any accounts. It is recommended
1488 * that default account is set to local/LAN account.
1489 * @param p_acc_id Pointer to receive account ID of the new account.
1490 *
1491 * @return PJ_SUCCESS on success, or the appropriate error code.
1492 */
1493PJ_DECL(pj_status_t) pjsua_acc_add(const pjsua_acc_config *cfg,
1494 pj_bool_t is_default,
1495 pjsua_acc_id *p_acc_id);
1496
1497
1498/**
1499 * Add a local account. A local account is used to identify local endpoint
1500 * instead of a specific user, and for this reason, a transport ID is needed
1501 * to obtain the local address information.
1502 *
1503 * @param tid Transport ID to generate account address.
1504 * @param is_default If non-zero, this account will be set as the default
1505 * account. The default account will be used when sending
1506 * outgoing requests (e.g. making call) when no account is
1507 * specified, and when receiving incoming requests when the
1508 * request does not match any accounts. It is recommended
1509 * that default account is set to local/LAN account.
1510 * @param p_acc_id Pointer to receive account ID of the new account.
1511 *
1512 * @return PJ_SUCCESS on success, or the appropriate error code.
1513 */
1514PJ_DECL(pj_status_t) pjsua_acc_add_local(pjsua_transport_id tid,
1515 pj_bool_t is_default,
1516 pjsua_acc_id *p_acc_id);
1517
1518/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00001519 * Delete an account. This will unregister the account from the SIP server,
1520 * if necessary, and terminate server side presence subscriptions associated
1521 * with this account.
Benny Prijono312aff92006-06-17 04:08:30 +00001522 *
1523 * @param acc_id Id of the account to be deleted.
1524 *
1525 * @return PJ_SUCCESS on success, or the appropriate error code.
1526 */
1527PJ_DECL(pj_status_t) pjsua_acc_del(pjsua_acc_id acc_id);
1528
1529
1530/**
1531 * Modify account information.
1532 *
1533 * @param acc_id Id of the account to be modified.
1534 * @param cfg New account configuration.
1535 *
1536 * @return PJ_SUCCESS on success, or the appropriate error code.
1537 */
1538PJ_DECL(pj_status_t) pjsua_acc_modify(pjsua_acc_id acc_id,
1539 const pjsua_acc_config *cfg);
1540
1541
1542/**
1543 * Modify account's presence status to be advertised to remote/presence
Benny Prijonob5388cf2007-01-04 22:45:08 +00001544 * subscribers. This would trigger the sending of outgoing NOTIFY request
1545 * if there are server side presence subscription for this account.
Benny Prijono312aff92006-06-17 04:08:30 +00001546 *
1547 * @param acc_id The account ID.
1548 * @param is_online True of false.
1549 *
1550 * @return PJ_SUCCESS on success, or the appropriate error code.
1551 */
1552PJ_DECL(pj_status_t) pjsua_acc_set_online_status(pjsua_acc_id acc_id,
1553 pj_bool_t is_online);
1554
1555
1556/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00001557 * Update registration or perform unregistration. If registration is
1558 * configured for this account, then initial SIP REGISTER will be sent
1559 * when the account is added with #pjsua_acc_add(). Application normally
1560 * only need to call this function if it wants to manually update the
1561 * registration or to unregister from the server.
Benny Prijono312aff92006-06-17 04:08:30 +00001562 *
1563 * @param acc_id The account ID.
1564 * @param renew If renew argument is zero, this will start
1565 * unregistration process.
1566 *
1567 * @return PJ_SUCCESS on success, or the appropriate error code.
1568 */
1569PJ_DECL(pj_status_t) pjsua_acc_set_registration(pjsua_acc_id acc_id,
1570 pj_bool_t renew);
1571
1572
1573/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00001574 * Get information about the specified account.
Benny Prijono312aff92006-06-17 04:08:30 +00001575 *
1576 * @param acc_id Account identification.
1577 * @param info Pointer to receive account information.
1578 *
1579 * @return PJ_SUCCESS on success, or the appropriate error code.
1580 */
1581PJ_DECL(pj_status_t) pjsua_acc_get_info(pjsua_acc_id acc_id,
1582 pjsua_acc_info *info);
1583
1584
1585/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00001586 * Enumerate all account currently active in the library. This will fill
1587 * the array with the account Ids, and application can then query the
1588 * account information for each id with #pjsua_acc_get_info().
1589 *
1590 * @see pjsua_acc_enum_info().
Benny Prijono312aff92006-06-17 04:08:30 +00001591 *
1592 * @param ids Array of account IDs to be initialized.
1593 * @param count In input, specifies the maximum number of elements.
1594 * On return, it contains the actual number of elements.
1595 *
1596 * @return PJ_SUCCESS on success, or the appropriate error code.
1597 */
1598PJ_DECL(pj_status_t) pjsua_enum_accs(pjsua_acc_id ids[],
1599 unsigned *count );
1600
1601
1602/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00001603 * Enumerate account informations.
Benny Prijono312aff92006-06-17 04:08:30 +00001604 *
1605 * @param info Array of account infos to be initialized.
1606 * @param count In input, specifies the maximum number of elements.
1607 * On return, it contains the actual number of elements.
1608 *
1609 * @return PJ_SUCCESS on success, or the appropriate error code.
1610 */
1611PJ_DECL(pj_status_t) pjsua_acc_enum_info( pjsua_acc_info info[],
1612 unsigned *count );
1613
1614
1615/**
1616 * This is an internal function to find the most appropriate account to
1617 * used to reach to the specified URL.
1618 *
1619 * @param url The remote URL to reach.
1620 *
1621 * @return Account id.
1622 */
1623PJ_DECL(pjsua_acc_id) pjsua_acc_find_for_outgoing(const pj_str_t *url);
1624
1625
1626/**
1627 * This is an internal function to find the most appropriate account to be
1628 * used to handle incoming calls.
1629 *
1630 * @param rdata The incoming request message.
1631 *
1632 * @return Account id.
1633 */
1634PJ_DECL(pjsua_acc_id) pjsua_acc_find_for_incoming(pjsip_rx_data *rdata);
1635
1636
Benny Prijonoc570f2d2006-07-18 00:33:02 +00001637/**
1638 * Create a suitable URI to be put as Contact based on the specified
1639 * target URI for the specified account.
1640 *
1641 * @param pool Pool to allocate memory for the string.
1642 * @param contact The string where the Contact URI will be stored.
1643 * @param acc_id Account ID.
1644 * @param uri Destination URI of the request.
1645 *
1646 * @return PJ_SUCCESS on success, other on error.
1647 */
1648PJ_DECL(pj_status_t) pjsua_acc_create_uac_contact( pj_pool_t *pool,
1649 pj_str_t *contact,
1650 pjsua_acc_id acc_id,
1651 const pj_str_t *uri);
1652
1653
1654
1655/**
1656 * Create a suitable URI to be put as Contact based on the information
1657 * in the incoming request.
1658 *
1659 * @param pool Pool to allocate memory for the string.
1660 * @param contact The string where the Contact URI will be stored.
1661 * @param acc_id Account ID.
1662 * @param rdata Incoming request.
1663 *
1664 * @return PJ_SUCCESS on success, other on error.
1665 */
1666PJ_DECL(pj_status_t) pjsua_acc_create_uas_contact( pj_pool_t *pool,
1667 pj_str_t *contact,
1668 pjsua_acc_id acc_id,
1669 pjsip_rx_data *rdata );
1670
1671
Benny Prijono62c5c5b2007-01-13 23:22:40 +00001672/**
1673 * Lock/bind this account to a specific transport/listener. Normally
1674 * application shouldn't need to do this, as transports will be selected
1675 * automatically by the stack according to the destination.
1676 *
1677 * When account is locked/bound to a specific transport, all outgoing
1678 * requests from this account will use the specified transport (this
1679 * includes SIP registration, dialog (call and event subscription), and
1680 * out-of-dialog requests such as MESSAGE).
1681 *
1682 * Note that transport_id may be specified in pjsua_acc_config too.
1683 *
1684 * @param acc_id The account ID.
1685 * @param tp_id The transport ID.
1686 *
1687 * @return PJ_SUCCESS on success.
1688 */
1689PJ_DECL(pj_status_t) pjsua_acc_set_transport(pjsua_acc_id acc_id,
1690 pjsua_transport_id tp_id);
1691
Benny Prijono312aff92006-06-17 04:08:30 +00001692
1693/**
1694 * @}
1695 */
1696
1697
1698/*****************************************************************************
1699 * CALLS API
1700 */
1701
1702
1703/**
1704 * @defgroup PJSUA_LIB_CALL Calls
1705 * @ingroup PJSUA_LIB
1706 * @brief Call manipulation.
1707 * @{
1708 */
1709
1710/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00001711 * Maximum simultaneous calls.
Benny Prijono312aff92006-06-17 04:08:30 +00001712 */
1713#ifndef PJSUA_MAX_CALLS
1714# define PJSUA_MAX_CALLS 32
1715#endif
1716
1717
1718
1719/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00001720 * This enumeration specifies the media status of a call, and it's part
1721 * of pjsua_call_info structure.
Benny Prijono312aff92006-06-17 04:08:30 +00001722 */
1723typedef enum pjsua_call_media_status
1724{
Benny Prijonob5388cf2007-01-04 22:45:08 +00001725 /** Call currently has no media */
Benny Prijono312aff92006-06-17 04:08:30 +00001726 PJSUA_CALL_MEDIA_NONE,
Benny Prijonob5388cf2007-01-04 22:45:08 +00001727
1728 /** The media is active */
Benny Prijono312aff92006-06-17 04:08:30 +00001729 PJSUA_CALL_MEDIA_ACTIVE,
Benny Prijonob5388cf2007-01-04 22:45:08 +00001730
1731 /** The media is currently put on hold by local endpoint */
Benny Prijono312aff92006-06-17 04:08:30 +00001732 PJSUA_CALL_MEDIA_LOCAL_HOLD,
Benny Prijonob5388cf2007-01-04 22:45:08 +00001733
1734 /** The media is currently put on hold by remote endpoint */
Benny Prijono312aff92006-06-17 04:08:30 +00001735 PJSUA_CALL_MEDIA_REMOTE_HOLD,
Benny Prijonob5388cf2007-01-04 22:45:08 +00001736
Benny Prijono312aff92006-06-17 04:08:30 +00001737} pjsua_call_media_status;
1738
1739
1740/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00001741 * This structure describes the information and current status of a call.
Benny Prijono312aff92006-06-17 04:08:30 +00001742 */
1743typedef struct pjsua_call_info
1744{
1745 /** Call identification. */
1746 pjsua_call_id id;
1747
1748 /** Initial call role (UAC == caller) */
1749 pjsip_role_e role;
1750
Benny Prijono90315512006-09-14 16:05:16 +00001751 /** The account ID where this call belongs. */
1752 pjsua_acc_id acc_id;
1753
Benny Prijono312aff92006-06-17 04:08:30 +00001754 /** Local URI */
1755 pj_str_t local_info;
1756
1757 /** Local Contact */
1758 pj_str_t local_contact;
1759
1760 /** Remote URI */
1761 pj_str_t remote_info;
1762
1763 /** Remote contact */
1764 pj_str_t remote_contact;
1765
1766 /** Dialog Call-ID string. */
1767 pj_str_t call_id;
1768
1769 /** Call state */
1770 pjsip_inv_state state;
1771
1772 /** Text describing the state */
1773 pj_str_t state_text;
1774
1775 /** Last status code heard, which can be used as cause code */
1776 pjsip_status_code last_status;
1777
1778 /** The reason phrase describing the status. */
1779 pj_str_t last_status_text;
1780
1781 /** Call media status. */
1782 pjsua_call_media_status media_status;
1783
1784 /** Media direction */
1785 pjmedia_dir media_dir;
1786
1787 /** The conference port number for the call */
1788 pjsua_conf_port_id conf_slot;
1789
1790 /** Up-to-date call connected duration (zero when call is not
1791 * established)
1792 */
1793 pj_time_val connect_duration;
1794
1795 /** Total call duration, including set-up time */
1796 pj_time_val total_duration;
1797
1798 /** Internal */
1799 struct {
1800 char local_info[128];
1801 char local_contact[128];
1802 char remote_info[128];
1803 char remote_contact[128];
1804 char call_id[128];
1805 char last_status_text[128];
1806 } buf_;
1807
1808} pjsua_call_info;
1809
1810
1811
Benny Prijonoa91a0032006-02-26 21:23:45 +00001812/**
Benny Prijono9fc735d2006-05-28 14:58:12 +00001813 * Get maximum number of calls configured in pjsua.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001814 *
1815 * @return Maximum number of calls configured.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001816 */
Benny Prijono8b1889b2006-06-06 18:40:40 +00001817PJ_DECL(unsigned) pjsua_call_get_max_count(void);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001818
1819/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001820 * Get number of currently active calls.
1821 *
1822 * @return Number of currently active calls.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001823 */
Benny Prijono8b1889b2006-06-06 18:40:40 +00001824PJ_DECL(unsigned) pjsua_call_get_count(void);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001825
1826/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00001827 * Enumerate all active calls. Application may then query the information and
1828 * state of each call by calling #pjsua_call_get_info().
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001829 *
1830 * @param ids Array of account IDs to be initialized.
1831 * @param count In input, specifies the maximum number of elements.
1832 * On return, it contains the actual number of elements.
1833 *
1834 * @return PJ_SUCCESS on success, or the appropriate error code.
1835 */
1836PJ_DECL(pj_status_t) pjsua_enum_calls(pjsua_call_id ids[],
1837 unsigned *count);
1838
1839
1840/**
1841 * Make outgoing call to the specified URI using the specified account.
1842 *
1843 * @param acc_id The account to be used.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001844 * @param dst_uri URI to be put in the To header (normally is the same
1845 * as the target URI).
1846 * @param options Options (must be zero at the moment).
1847 * @param user_data Arbitrary user data to be attached to the call, and
1848 * can be retrieved later.
1849 * @param msg_data Optional headers etc to be added to outgoing INVITE
1850 * request, or NULL if no custom header is desired.
1851 * @param p_call_id Pointer to receive call identification.
1852 *
1853 * @return PJ_SUCCESS on success, or the appropriate error code.
1854 */
1855PJ_DECL(pj_status_t) pjsua_call_make_call(pjsua_acc_id acc_id,
1856 const pj_str_t *dst_uri,
1857 unsigned options,
1858 void *user_data,
1859 const pjsua_msg_data *msg_data,
1860 pjsua_call_id *p_call_id);
1861
1862
1863/**
Benny Prijono9fc735d2006-05-28 14:58:12 +00001864 * Check if the specified call has active INVITE session and the INVITE
1865 * session has not been disconnected.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001866 *
1867 * @param call_id Call identification.
1868 *
1869 * @return Non-zero if call is active.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001870 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001871PJ_DECL(pj_bool_t) pjsua_call_is_active(pjsua_call_id call_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001872
1873
1874/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001875 * Check if call has an active media session.
1876 *
1877 * @param call_id Call identification.
1878 *
1879 * @return Non-zero if yes.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001880 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001881PJ_DECL(pj_bool_t) pjsua_call_has_media(pjsua_call_id call_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001882
1883
1884/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001885 * Get the conference port identification associated with the call.
1886 *
1887 * @param call_id Call identification.
1888 *
1889 * @return Conference port ID, or PJSUA_INVALID_ID when the
1890 * media has not been established or is not active.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001891 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001892PJ_DECL(pjsua_conf_port_id) pjsua_call_get_conf_port(pjsua_call_id call_id);
1893
1894/**
1895 * Obtain detail information about the specified call.
1896 *
1897 * @param call_id Call identification.
1898 * @param info Call info to be initialized.
1899 *
1900 * @return PJ_SUCCESS on success, or the appropriate error code.
1901 */
1902PJ_DECL(pj_status_t) pjsua_call_get_info(pjsua_call_id call_id,
Benny Prijono9fc735d2006-05-28 14:58:12 +00001903 pjsua_call_info *info);
1904
1905
1906/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00001907 * Attach application specific data to the call. Application can then
1908 * inspect this data by calling #pjsua_call_get_user_data().
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001909 *
1910 * @param call_id Call identification.
1911 * @param user_data Arbitrary data to be attached to the call.
1912 *
1913 * @return The user data.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001914 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001915PJ_DECL(pj_status_t) pjsua_call_set_user_data(pjsua_call_id call_id,
1916 void *user_data);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001917
1918
1919/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00001920 * Get user data attached to the call, which has been previously set with
1921 * #pjsua_call_set_user_data().
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001922 *
1923 * @param call_id Call identification.
1924 *
1925 * @return The user data.
Benny Prijono268ca612006-02-07 12:34:11 +00001926 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001927PJ_DECL(void*) pjsua_call_get_user_data(pjsua_call_id call_id);
Benny Prijono84126ab2006-02-09 09:30:09 +00001928
1929
1930/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00001931 * Send response to incoming INVITE request. Depending on the status
1932 * code specified as parameter, this function may send provisional
1933 * response, establish the call, or terminate the call.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001934 *
1935 * @param call_id Incoming call identification.
1936 * @param code Status code, (100-699).
1937 * @param reason Optional reason phrase. If NULL, default text
1938 * will be used.
1939 * @param msg_data Optional list of headers etc to be added to outgoing
1940 * response message.
1941 *
1942 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonoa91a0032006-02-26 21:23:45 +00001943 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001944PJ_DECL(pj_status_t) pjsua_call_answer(pjsua_call_id call_id,
1945 unsigned code,
1946 const pj_str_t *reason,
1947 const pjsua_msg_data *msg_data);
Benny Prijonoa91a0032006-02-26 21:23:45 +00001948
1949/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001950 * Hangup call by using method that is appropriate according to the
Benny Prijonob5388cf2007-01-04 22:45:08 +00001951 * call state. This function is different than answering the call with
1952 * 3xx-6xx response (with #pjsua_call_answer()), in that this function
1953 * will hangup the call regardless of the state and role of the call,
1954 * while #pjsua_call_answer() only works with incoming calls on EARLY
1955 * state.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001956 *
1957 * @param call_id Call identification.
1958 * @param code Optional status code to be sent when we're rejecting
1959 * incoming call. If the value is zero, "603/Decline"
1960 * will be sent.
1961 * @param reason Optional reason phrase to be sent when we're rejecting
1962 * incoming call. If NULL, default text will be used.
1963 * @param msg_data Optional list of headers etc to be added to outgoing
1964 * request/response message.
1965 *
1966 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono26ff9062006-02-21 23:47:00 +00001967 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001968PJ_DECL(pj_status_t) pjsua_call_hangup(pjsua_call_id call_id,
1969 unsigned code,
1970 const pj_str_t *reason,
1971 const pjsua_msg_data *msg_data);
Benny Prijono26ff9062006-02-21 23:47:00 +00001972
1973
1974/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00001975 * Put the specified call on hold. This will send re-INVITE with the
1976 * appropriate SDP to inform remote that the call is being put on hold.
1977 * The final status of the request itself will be reported on the
1978 * \a on_call_media_state() callback, which inform the application that
1979 * the media state of the call has changed.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001980 *
1981 * @param call_id Call identification.
1982 * @param msg_data Optional message components to be sent with
1983 * the request.
1984 *
1985 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono26ff9062006-02-21 23:47:00 +00001986 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001987PJ_DECL(pj_status_t) pjsua_call_set_hold(pjsua_call_id call_id,
1988 const pjsua_msg_data *msg_data);
Benny Prijono26ff9062006-02-21 23:47:00 +00001989
1990
1991/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00001992 * Send re-INVITE to release hold.
1993 * The final status of the request itself will be reported on the
1994 * \a on_call_media_state() callback, which inform the application that
1995 * the media state of the call has changed.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001996 *
1997 * @param call_id Call identification.
1998 * @param unhold If this argument is non-zero and the call is locally
1999 * held, this will release the local hold.
2000 * @param msg_data Optional message components to be sent with
2001 * the request.
2002 *
2003 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono26ff9062006-02-21 23:47:00 +00002004 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002005PJ_DECL(pj_status_t) pjsua_call_reinvite(pjsua_call_id call_id,
2006 pj_bool_t unhold,
2007 const pjsua_msg_data *msg_data);
Benny Prijono26ff9062006-02-21 23:47:00 +00002008
2009
2010/**
Benny Prijono053f5222006-11-11 16:16:04 +00002011 * Initiate call transfer to the specified address. This function will send
2012 * REFER request to instruct remote call party to initiate a new INVITE
2013 * session to the specified destination/target.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002014 *
Benny Prijonob5388cf2007-01-04 22:45:08 +00002015 * If application is interested to monitor the successfulness and
2016 * the progress of the transfer request, it can implement
2017 * \a on_call_transfer_status() callback which will report the progress
2018 * of the call transfer request.
2019 *
Benny Prijono053f5222006-11-11 16:16:04 +00002020 * @param call_id The call id to be transfered.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002021 * @param dest Address of new target to be contacted.
2022 * @param msg_data Optional message components to be sent with
2023 * the request.
2024 *
2025 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono26ff9062006-02-21 23:47:00 +00002026 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002027PJ_DECL(pj_status_t) pjsua_call_xfer(pjsua_call_id call_id,
2028 const pj_str_t *dest,
2029 const pjsua_msg_data *msg_data);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002030
2031/**
Benny Prijono053f5222006-11-11 16:16:04 +00002032 * Flag to indicate that "Require: replaces" should not be put in the
2033 * outgoing INVITE request caused by REFER request created by
2034 * #pjsua_call_xfer_replaces().
2035 */
2036#define PJSUA_XFER_NO_REQUIRE_REPLACES 1
2037
2038/**
2039 * Initiate attended call transfer. This function will send REFER request
2040 * to instruct remote call party to initiate new INVITE session to the URL
2041 * of \a dest_call_id. The party at \a dest_call_id then should "replace"
2042 * the call with us with the new call from the REFER recipient.
2043 *
2044 * @param call_id The call id to be transfered.
2045 * @param dest_call_id The call id to be replaced.
2046 * @param options Application may specify PJSUA_XFER_NO_REQUIRE_REPLACES
2047 * to suppress the inclusion of "Require: replaces" in
2048 * the outgoing INVITE request created by the REFER
2049 * request.
2050 * @param msg_data Optional message components to be sent with
2051 * the request.
2052 *
2053 * @return PJ_SUCCESS on success, or the appropriate error code.
2054 */
2055PJ_DECL(pj_status_t) pjsua_call_xfer_replaces(pjsua_call_id call_id,
2056 pjsua_call_id dest_call_id,
2057 unsigned options,
2058 const pjsua_msg_data *msg_data);
2059
2060/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002061 * Send DTMF digits to remote using RFC 2833 payload formats.
2062 *
2063 * @param call_id Call identification.
2064 * @param digits DTMF digits to be sent.
2065 *
2066 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002067 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002068PJ_DECL(pj_status_t) pjsua_call_dial_dtmf(pjsua_call_id call_id,
Benny Prijono9fc735d2006-05-28 14:58:12 +00002069 const pj_str_t *digits);
Benny Prijono26ff9062006-02-21 23:47:00 +00002070
Benny Prijono26ff9062006-02-21 23:47:00 +00002071/**
Benny Prijonob0808372006-03-02 21:18:58 +00002072 * Send instant messaging inside INVITE session.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002073 *
2074 * @param call_id Call identification.
2075 * @param mime_type Optional MIME type. If NULL, then "text/plain" is
2076 * assumed.
2077 * @param content The message content.
2078 * @param msg_data Optional list of headers etc to be included in outgoing
2079 * request. The body descriptor in the msg_data is
2080 * ignored.
2081 * @param user_data Optional user data, which will be given back when
2082 * the IM callback is called.
2083 *
2084 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonob0808372006-03-02 21:18:58 +00002085 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002086PJ_DECL(pj_status_t) pjsua_call_send_im( pjsua_call_id call_id,
2087 const pj_str_t *mime_type,
2088 const pj_str_t *content,
2089 const pjsua_msg_data *msg_data,
2090 void *user_data);
Benny Prijonob0808372006-03-02 21:18:58 +00002091
2092
2093/**
2094 * Send IM typing indication inside INVITE session.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002095 *
2096 * @param call_id Call identification.
2097 * @param is_typing Non-zero to indicate to remote that local person is
2098 * currently typing an IM.
2099 * @param msg_data Optional list of headers etc to be included in outgoing
2100 * request.
2101 *
2102 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonob0808372006-03-02 21:18:58 +00002103 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002104PJ_DECL(pj_status_t) pjsua_call_send_typing_ind(pjsua_call_id call_id,
2105 pj_bool_t is_typing,
2106 const pjsua_msg_data*msg_data);
Benny Prijonob0808372006-03-02 21:18:58 +00002107
2108/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00002109 * Terminate all calls. This will initiate #pjsua_call_hangup() for all
2110 * currently active calls.
Benny Prijono834aee32006-02-19 01:38:06 +00002111 */
Benny Prijonodc39fe82006-05-26 12:17:46 +00002112PJ_DECL(void) pjsua_call_hangup_all(void);
Benny Prijono834aee32006-02-19 01:38:06 +00002113
2114
Benny Prijonob9b32ab2006-06-01 12:28:44 +00002115/**
2116 * Dump call and media statistics to string.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002117 *
2118 * @param call_id Call identification.
2119 * @param with_media Non-zero to include media information too.
2120 * @param buffer Buffer where the statistics are to be written to.
2121 * @param maxlen Maximum length of buffer.
2122 * @param indent Spaces for left indentation.
2123 *
2124 * @return PJ_SUCCESS on success.
Benny Prijonob9b32ab2006-06-01 12:28:44 +00002125 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002126PJ_DECL(pj_status_t) pjsua_call_dump(pjsua_call_id call_id,
2127 pj_bool_t with_media,
2128 char *buffer,
2129 unsigned maxlen,
2130 const char *indent);
Benny Prijonob9b32ab2006-06-01 12:28:44 +00002131
Benny Prijono9fc735d2006-05-28 14:58:12 +00002132/**
Benny Prijono312aff92006-06-17 04:08:30 +00002133 * @}
Benny Prijono9fc735d2006-05-28 14:58:12 +00002134 */
Benny Prijono834aee32006-02-19 01:38:06 +00002135
2136
2137/*****************************************************************************
Benny Prijono312aff92006-06-17 04:08:30 +00002138 * BUDDY API
Benny Prijono834aee32006-02-19 01:38:06 +00002139 */
2140
Benny Prijono312aff92006-06-17 04:08:30 +00002141
2142/**
2143 * @defgroup PJSUA_LIB_BUDDY Buddy, Presence, and Instant Messaging
2144 * @ingroup PJSUA_LIB
2145 * @brief Buddy management, buddy's presence, and instant messaging.
2146 * @{
2147 */
2148
2149/**
2150 * Max buddies in buddy list.
2151 */
2152#ifndef PJSUA_MAX_BUDDIES
2153# define PJSUA_MAX_BUDDIES 256
2154#endif
2155
2156
2157/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00002158 * This structure describes buddy configuration when adding a buddy to
2159 * the buddy list with #pjsua_buddy_add(). Application MUST initialize
2160 * the structure with #pjsua_buddy_config_default() to initialize this
2161 * structure with default configuration.
Benny Prijono312aff92006-06-17 04:08:30 +00002162 */
2163typedef struct pjsua_buddy_config
2164{
2165 /**
2166 * Buddy URL or name address.
2167 */
2168 pj_str_t uri;
2169
2170 /**
2171 * Specify whether presence subscription should start immediately.
2172 */
2173 pj_bool_t subscribe;
2174
2175} pjsua_buddy_config;
2176
2177
2178/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00002179 * This enumeration describes basic buddy's online status.
Benny Prijono312aff92006-06-17 04:08:30 +00002180 */
2181typedef enum pjsua_buddy_status
2182{
2183 /**
2184 * Online status is unknown (possibly because no presence subscription
2185 * has been established).
2186 */
2187 PJSUA_BUDDY_STATUS_UNKNOWN,
2188
2189 /**
2190 * Buddy is known to be offline.
2191 */
2192 PJSUA_BUDDY_STATUS_ONLINE,
2193
2194 /**
2195 * Buddy is offline.
2196 */
2197 PJSUA_BUDDY_STATUS_OFFLINE,
2198
2199} pjsua_buddy_status;
2200
2201
2202
2203/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00002204 * This structure describes buddy info, which can be retrieved by calling
2205 * #pjsua_buddy_get_info().
Benny Prijono312aff92006-06-17 04:08:30 +00002206 */
2207typedef struct pjsua_buddy_info
2208{
2209 /**
2210 * The buddy ID.
2211 */
2212 pjsua_buddy_id id;
2213
2214 /**
2215 * The full URI of the buddy, as specified in the configuration.
2216 */
2217 pj_str_t uri;
2218
2219 /**
2220 * Buddy's Contact, only available when presence subscription has
2221 * been established to the buddy.
2222 */
2223 pj_str_t contact;
2224
2225 /**
2226 * Buddy's online status.
2227 */
2228 pjsua_buddy_status status;
2229
2230 /**
2231 * Text to describe buddy's online status.
2232 */
2233 pj_str_t status_text;
2234
2235 /**
2236 * Flag to indicate that we should monitor the presence information for
2237 * this buddy (normally yes, unless explicitly disabled).
2238 */
2239 pj_bool_t monitor_pres;
2240
2241 /**
2242 * Internal buffer.
2243 */
2244 char buf_[256];
2245
2246} pjsua_buddy_info;
2247
2248
Benny Prijono834aee32006-02-19 01:38:06 +00002249/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00002250 * Set default values to the buddy config.
2251 */
2252PJ_INLINE(void) pjsua_buddy_config_default(pjsua_buddy_config *cfg)
2253{
2254 pj_bzero(cfg, sizeof(*cfg));
2255}
2256
2257
2258/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002259 * Get total number of buddies.
2260 *
2261 * @return Number of buddies.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002262 */
2263PJ_DECL(unsigned) pjsua_get_buddy_count(void);
2264
2265
2266/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002267 * Check if buddy ID is valid.
2268 *
2269 * @param buddy_id Buddy ID to check.
2270 *
2271 * @return Non-zero if buddy ID is valid.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002272 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002273PJ_DECL(pj_bool_t) pjsua_buddy_is_valid(pjsua_buddy_id buddy_id);
2274
2275
2276/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00002277 * Enumerate all buddy IDs in the buddy list. Application then can use
2278 * #pjsua_buddy_get_info() to get the detail information for each buddy
2279 * id.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002280 *
2281 * @param ids Array of ids to be initialized.
2282 * @param count On input, specifies max elements in the array.
2283 * On return, it contains actual number of elements
2284 * that have been initialized.
2285 *
2286 * @return PJ_SUCCESS on success, or the appropriate error code.
2287 */
2288PJ_DECL(pj_status_t) pjsua_enum_buddies(pjsua_buddy_id ids[],
2289 unsigned *count);
2290
2291/**
2292 * Get detailed buddy info.
2293 *
2294 * @param buddy_id The buddy identification.
2295 * @param info Pointer to receive information about buddy.
2296 *
2297 * @return PJ_SUCCESS on success, or the appropriate error code.
2298 */
2299PJ_DECL(pj_status_t) pjsua_buddy_get_info(pjsua_buddy_id buddy_id,
Benny Prijono9fc735d2006-05-28 14:58:12 +00002300 pjsua_buddy_info *info);
2301
2302/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00002303 * Add new buddy to the buddy list. If presence subscription is enabled
2304 * for this buddy, this function will also start the presence subscription
2305 * session immediately.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002306 *
2307 * @param cfg Buddy configuration.
2308 * @param p_buddy_id Pointer to receive buddy ID.
2309 *
2310 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002311 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002312PJ_DECL(pj_status_t) pjsua_buddy_add(const pjsua_buddy_config *cfg,
2313 pjsua_buddy_id *p_buddy_id);
Benny Prijono8b1889b2006-06-06 18:40:40 +00002314
2315
2316/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00002317 * Delete the specified buddy from the buddy list. Any presence subscription
2318 * to this buddy will be terminated.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002319 *
2320 * @param buddy_id Buddy identification.
2321 *
2322 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono8b1889b2006-06-06 18:40:40 +00002323 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002324PJ_DECL(pj_status_t) pjsua_buddy_del(pjsua_buddy_id buddy_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002325
2326
2327/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00002328 * Enable/disable buddy's presence monitoring. Once buddy's presence is
2329 * subscribed, application will be informed about buddy's presence status
2330 * changed via \a on_buddy_state() callback.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002331 *
2332 * @param buddy_id Buddy identification.
2333 * @param subscribe Specify non-zero to activate presence subscription to
2334 * the specified buddy.
2335 *
2336 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002337 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002338PJ_DECL(pj_status_t) pjsua_buddy_subscribe_pres(pjsua_buddy_id buddy_id,
2339 pj_bool_t subscribe);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002340
2341
2342/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00002343 * Dump presence subscriptions to log.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002344 *
2345 * @param verbose Yes or no.
Benny Prijono834aee32006-02-19 01:38:06 +00002346 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002347PJ_DECL(void) pjsua_pres_dump(pj_bool_t verbose);
Benny Prijono834aee32006-02-19 01:38:06 +00002348
2349
Benny Prijonob0808372006-03-02 21:18:58 +00002350/**
2351 * The MESSAGE method (defined in pjsua_im.c)
2352 */
2353extern const pjsip_method pjsip_message_method;
2354
2355
Benny Prijonob0808372006-03-02 21:18:58 +00002356
2357/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002358 * Send instant messaging outside dialog, using the specified account for
2359 * route set and authentication.
2360 *
2361 * @param acc_id Account ID to be used to send the request.
2362 * @param to Remote URI.
2363 * @param mime_type Optional MIME type. If NULL, then "text/plain" is
2364 * assumed.
2365 * @param content The message content.
2366 * @param msg_data Optional list of headers etc to be included in outgoing
2367 * request. The body descriptor in the msg_data is
2368 * ignored.
2369 * @param user_data Optional user data, which will be given back when
2370 * the IM callback is called.
2371 *
2372 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonob0808372006-03-02 21:18:58 +00002373 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002374PJ_DECL(pj_status_t) pjsua_im_send(pjsua_acc_id acc_id,
2375 const pj_str_t *to,
2376 const pj_str_t *mime_type,
2377 const pj_str_t *content,
2378 const pjsua_msg_data *msg_data,
2379 void *user_data);
Benny Prijonob0808372006-03-02 21:18:58 +00002380
2381
2382/**
2383 * Send typing indication outside dialog.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002384 *
2385 * @param acc_id Account ID to be used to send the request.
2386 * @param to Remote URI.
2387 * @param is_typing If non-zero, it tells remote person that local person
2388 * is currently composing an IM.
2389 * @param msg_data Optional list of headers etc to be added to outgoing
2390 * request.
2391 *
2392 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonob0808372006-03-02 21:18:58 +00002393 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002394PJ_DECL(pj_status_t) pjsua_im_typing(pjsua_acc_id acc_id,
2395 const pj_str_t *to,
2396 pj_bool_t is_typing,
2397 const pjsua_msg_data *msg_data);
Benny Prijonob0808372006-03-02 21:18:58 +00002398
2399
Benny Prijonof3195072006-02-14 21:15:30 +00002400
Benny Prijono312aff92006-06-17 04:08:30 +00002401/**
2402 * @}
Benny Prijono9fc735d2006-05-28 14:58:12 +00002403 */
2404
Benny Prijono312aff92006-06-17 04:08:30 +00002405
2406/*****************************************************************************
2407 * MEDIA API
2408 */
2409
2410
2411/**
2412 * @defgroup PJSUA_LIB_MEDIA Media
2413 * @ingroup PJSUA_LIB
2414 * @brief Media manipulation.
2415 * @{
2416 *
2417 * PJSUA has rather powerful media features, which are built around the
2418 * PJMEDIA conference bridge. Basically, all media termination (such as
2419 * calls, file players, file recorders, sound device, tone generators, etc)
2420 * are terminated in the conference bridge, and application can manipulate
2421 * the interconnection between these terminations freely. If more than
2422 * one media terminations are terminated in the same slot, the conference
2423 * bridge will mix the signal automatically.
2424 *
2425 * Application connects one media termination/slot to another by calling
2426 * #pjsua_conf_connect() function. This will establish <b>unidirectional</b>
2427 * media flow from the source termination to the sink termination. For
2428 * example, to stream a WAV file to remote call, application may use
2429 * the following steps:
2430 *
2431 \code
2432
2433 pj_status_t stream_to_call( pjsua_call_id call_id )
2434 {
2435 pjsua_player_id player_id;
2436
2437 status = pjsua_player_create("mysong.wav", 0, NULL, &player_id);
2438 if (status != PJ_SUCCESS)
2439 return status;
2440
2441 status = pjsua_conf_connect( pjsua_player_get_conf_port(),
2442 pjsua_call_get_conf_port() );
2443 }
2444 \endcode
2445 *
2446 *
2447 * Other features of PJSUA media:
2448 * - efficient N to M interconnections between media terminations.
2449 * - media termination can be connected to itself to create loopback
2450 * media.
2451 * - the media termination may have different clock rates, and resampling
2452 * will be done automatically by conference bridge.
2453 * - media terminations may also have different frame time; the
2454 * conference bridge will perform the necessary bufferring to adjust
2455 * the difference between terminations.
2456 * - interconnections are removed automatically when media termination
2457 * is removed from the bridge.
2458 * - sound device may be changed even when there are active media
2459 * interconnections.
2460 * - correctly report call's media quality (in #pjsua_call_dump()) from
2461 * RTCP packet exchange.
2462 */
2463
2464/**
2465 * Max ports in the conference bridge.
2466 */
2467#ifndef PJSUA_MAX_CONF_PORTS
Benny Prijono12a669c2006-11-23 07:32:13 +00002468# define PJSUA_MAX_CONF_PORTS 254
Benny Prijono312aff92006-06-17 04:08:30 +00002469#endif
2470
Benny Prijonob5388cf2007-01-04 22:45:08 +00002471/**
2472 * The default clock rate to be used by the conference bridge.
2473 */
Benny Prijono12a669c2006-11-23 07:32:13 +00002474#ifndef PJSUA_DEFAULT_CLOCK_RATE
2475# define PJSUA_DEFAULT_CLOCK_RATE 16000
2476#endif
2477
Benny Prijonob5388cf2007-01-04 22:45:08 +00002478/**
2479 * Default codec quality settings.
2480 */
Benny Prijono12a669c2006-11-23 07:32:13 +00002481#ifndef PJSUA_DEFAULT_CODEC_QUALITY
2482# define PJSUA_DEFAULT_CODEC_QUALITY 5
2483#endif
2484
Benny Prijonob5388cf2007-01-04 22:45:08 +00002485/**
2486 * Default iLBC mode.
2487 */
Benny Prijono12a669c2006-11-23 07:32:13 +00002488#ifndef PJSUA_DEFAULT_ILBC_MODE
2489# define PJSUA_DEFAULT_ILBC_MODE 20
2490#endif
2491
Benny Prijonob5388cf2007-01-04 22:45:08 +00002492/**
2493 * The default echo canceller tail length.
2494 */
Benny Prijono12a669c2006-11-23 07:32:13 +00002495#ifndef PJSUA_DEFAULT_EC_TAIL_LEN
Benny Prijonod2990b92006-11-23 10:19:46 +00002496# define PJSUA_DEFAULT_EC_TAIL_LEN 800
Benny Prijono12a669c2006-11-23 07:32:13 +00002497#endif
Benny Prijono312aff92006-06-17 04:08:30 +00002498
2499
2500/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00002501 * This structure describes media configuration, which will be specified
2502 * when calling #pjsua_init(). Application MUST initialize this structure
2503 * by calling #pjsua_media_config_default().
Benny Prijono312aff92006-06-17 04:08:30 +00002504 */
2505struct pjsua_media_config
2506{
2507 /**
2508 * Clock rate to be applied to the conference bridge.
Benny Prijonob5388cf2007-01-04 22:45:08 +00002509 * If value is zero, default clock rate will be used
2510 * (PJSUA_DEFAULT_CLOCK_RATE, which by default is 16KHz).
Benny Prijono312aff92006-06-17 04:08:30 +00002511 */
2512 unsigned clock_rate;
2513
2514 /**
2515 * Specify maximum number of media ports to be created in the
2516 * conference bridge. Since all media terminate in the bridge
2517 * (calls, file player, file recorder, etc), the value must be
2518 * large enough to support all of them. However, the larger
2519 * the value, the more computations are performed.
2520 */
2521 unsigned max_media_ports;
2522
2523 /**
2524 * Specify whether the media manager should manage its own
2525 * ioqueue for the RTP/RTCP sockets. If yes, ioqueue will be created
2526 * and at least one worker thread will be created too. If no,
2527 * the RTP/RTCP sockets will share the same ioqueue as SIP sockets,
2528 * and no worker thread is needed.
2529 *
2530 * Normally application would say yes here, unless it wants to
2531 * run everything from a single thread.
2532 */
2533 pj_bool_t has_ioqueue;
2534
2535 /**
2536 * Specify the number of worker threads to handle incoming RTP
2537 * packets. A value of one is recommended for most applications.
2538 */
2539 unsigned thread_cnt;
2540
Benny Prijono0498d902006-06-19 14:49:14 +00002541 /**
2542 * Media quality, 0-10, according to this table:
Benny Prijono7ca96da2006-08-07 12:11:40 +00002543 * 5-10: resampling use large filter,
2544 * 3-4: resampling use small filter,
Benny Prijono0498d902006-06-19 14:49:14 +00002545 * 1-2: resampling use linear.
2546 * The media quality also sets speex codec quality/complexity to the
2547 * number.
2548 *
Benny Prijono70972992006-08-05 11:13:58 +00002549 * Default: 5 (PJSUA_DEFAULT_CODEC_QUALITY).
Benny Prijono0498d902006-06-19 14:49:14 +00002550 */
2551 unsigned quality;
Benny Prijono0a12f002006-07-26 17:05:39 +00002552
2553 /**
2554 * Specify default ptime.
2555 *
2556 * Default: 0 (codec specific)
2557 */
2558 unsigned ptime;
2559
2560 /**
2561 * Disable VAD?
2562 *
2563 * Default: 0 (no (meaning VAD is enabled))
2564 */
2565 pj_bool_t no_vad;
Benny Prijono00cae612006-07-31 15:19:36 +00002566
2567 /**
2568 * iLBC mode (20 or 30).
2569 *
Benny Prijono70972992006-08-05 11:13:58 +00002570 * Default: 20 (PJSUA_DEFAULT_ILBC_MODE)
Benny Prijono00cae612006-07-31 15:19:36 +00002571 */
2572 unsigned ilbc_mode;
2573
2574 /**
2575 * Percentage of RTP packet to drop in TX direction
2576 * (to simulate packet lost).
2577 *
2578 * Default: 0
2579 */
2580 unsigned tx_drop_pct;
2581
2582 /**
2583 * Percentage of RTP packet to drop in RX direction
2584 * (to simulate packet lost).
2585 *
2586 * Default: 0
2587 */
2588 unsigned rx_drop_pct;
2589
Benny Prijonoc8e24a12006-08-02 18:22:22 +00002590 /**
Benny Prijono5da50432006-08-07 10:24:52 +00002591 * Echo canceller options (see #pjmedia_echo_create())
2592 *
2593 * Default: 0.
2594 */
2595 unsigned ec_options;
2596
2597 /**
Benny Prijonoc8e24a12006-08-02 18:22:22 +00002598 * Echo canceller tail length, in miliseconds.
2599 *
Benny Prijono669643c2006-09-20 20:02:18 +00002600 * Default: PJSUA_DEFAULT_EC_TAIL_LEN
Benny Prijonoc8e24a12006-08-02 18:22:22 +00002601 */
2602 unsigned ec_tail_len;
Benny Prijono1d0ca0c2006-11-21 09:06:47 +00002603
2604 /**
2605 * Jitter buffer initial prefetch delay in msec. The value must be
2606 * between jb_min_pre and jb_max_pre below.
2607 *
2608 * Default: -1 (to use default stream settings, currently 150 msec)
2609 */
2610 int jb_init;
2611
2612 /**
2613 * Jitter buffer minimum prefetch delay in msec.
2614 *
2615 * Default: -1 (to use default stream settings, currently 60 msec)
2616 */
2617 int jb_min_pre;
2618
2619 /**
2620 * Jitter buffer maximum prefetch delay in msec.
2621 *
2622 * Default: -1 (to use default stream settings, currently 240 msec)
2623 */
2624 int jb_max_pre;
2625
2626 /**
2627 * Set maximum delay that can be accomodated by the jitter buffer msec.
2628 *
2629 * Default: -1 (to use default stream settings, currently 360 msec)
2630 */
2631 int jb_max;
2632
Benny Prijono312aff92006-06-17 04:08:30 +00002633};
2634
2635
2636/**
2637 * Use this function to initialize media config.
2638 *
2639 * @param cfg The media config to be initialized.
2640 */
2641PJ_INLINE(void) pjsua_media_config_default(pjsua_media_config *cfg)
2642{
Benny Prijonoac623b32006-07-03 15:19:31 +00002643 pj_bzero(cfg, sizeof(*cfg));
Benny Prijono312aff92006-06-17 04:08:30 +00002644
Benny Prijono70972992006-08-05 11:13:58 +00002645 cfg->clock_rate = PJSUA_DEFAULT_CLOCK_RATE;
Benny Prijono312aff92006-06-17 04:08:30 +00002646 cfg->max_media_ports = 32;
2647 cfg->has_ioqueue = PJ_TRUE;
2648 cfg->thread_cnt = 1;
Benny Prijono70972992006-08-05 11:13:58 +00002649 cfg->quality = PJSUA_DEFAULT_CODEC_QUALITY;
2650 cfg->ilbc_mode = PJSUA_DEFAULT_ILBC_MODE;
2651 cfg->ec_tail_len = PJSUA_DEFAULT_EC_TAIL_LEN;
Benny Prijono1d0ca0c2006-11-21 09:06:47 +00002652 cfg->jb_init = cfg->jb_min_pre = cfg->jb_max_pre = cfg->jb_max = -1;
Benny Prijono312aff92006-06-17 04:08:30 +00002653}
2654
2655
2656
2657/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00002658 * This structure describes codec information, which can be retrieved by
2659 * calling #pjsua_enum_codecs().
Benny Prijono312aff92006-06-17 04:08:30 +00002660 */
2661typedef struct pjsua_codec_info
2662{
2663 /**
2664 * Codec unique identification.
2665 */
2666 pj_str_t codec_id;
2667
2668 /**
2669 * Codec priority (integer 0-255).
2670 */
2671 pj_uint8_t priority;
2672
2673 /**
2674 * Internal buffer.
2675 */
2676 char buf_[32];
2677
2678} pjsua_codec_info;
2679
2680
2681/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00002682 * This structure descibes information about a particular media port that
2683 * has been registered into the conference bridge. Application can query
2684 * this info by calling #pjsua_conf_get_port_info().
Benny Prijono312aff92006-06-17 04:08:30 +00002685 */
2686typedef struct pjsua_conf_port_info
2687{
2688 /** Conference port number. */
2689 pjsua_conf_port_id slot_id;
2690
2691 /** Port name. */
2692 pj_str_t name;
2693
2694 /** Clock rate. */
2695 unsigned clock_rate;
2696
2697 /** Number of channels. */
2698 unsigned channel_count;
2699
2700 /** Samples per frame */
2701 unsigned samples_per_frame;
2702
2703 /** Bits per sample */
2704 unsigned bits_per_sample;
2705
2706 /** Number of listeners in the array. */
2707 unsigned listener_cnt;
2708
2709 /** Array of listeners (in other words, ports where this port is
2710 * transmitting to.
2711 */
2712 pjsua_conf_port_id listeners[PJSUA_MAX_CONF_PORTS];
2713
2714} pjsua_conf_port_info;
2715
2716
2717/**
2718 * This structure holds information about custom media transport to
2719 * be registered to pjsua.
2720 */
2721typedef struct pjsua_media_transport
2722{
2723 /**
2724 * Media socket information containing the address information
2725 * of the RTP and RTCP socket.
2726 */
2727 pjmedia_sock_info skinfo;
2728
2729 /**
2730 * The media transport instance.
2731 */
2732 pjmedia_transport *transport;
2733
2734} pjsua_media_transport;
2735
2736
2737
2738
Benny Prijono9fc735d2006-05-28 14:58:12 +00002739/**
2740 * Get maxinum number of conference ports.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002741 *
2742 * @return Maximum number of ports in the conference bridge.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002743 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002744PJ_DECL(unsigned) pjsua_conf_get_max_ports(void);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002745
2746
2747/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002748 * Get current number of active ports in the bridge.
2749 *
2750 * @return The number.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002751 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002752PJ_DECL(unsigned) pjsua_conf_get_active_ports(void);
2753
2754
2755/**
2756 * Enumerate all conference ports.
2757 *
2758 * @param id Array of conference port ID to be initialized.
2759 * @param count On input, specifies max elements in the array.
2760 * On return, it contains actual number of elements
2761 * that have been initialized.
2762 *
2763 * @return PJ_SUCCESS on success, or the appropriate error code.
2764 */
2765PJ_DECL(pj_status_t) pjsua_enum_conf_ports(pjsua_conf_port_id id[],
2766 unsigned *count);
Benny Prijono8b1889b2006-06-06 18:40:40 +00002767
2768
2769/**
2770 * Get information about the specified conference port
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002771 *
2772 * @param id Port identification.
2773 * @param info Pointer to store the port info.
2774 *
2775 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono8b1889b2006-06-06 18:40:40 +00002776 */
2777PJ_DECL(pj_status_t) pjsua_conf_get_port_info( pjsua_conf_port_id id,
2778 pjsua_conf_port_info *info);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002779
2780
2781/**
Benny Prijonoe909eac2006-07-27 22:04:56 +00002782 * Add arbitrary media port to PJSUA's conference bridge. Application
2783 * can use this function to add the media port that it creates. For
2784 * media ports that are created by PJSUA-LIB (such as calls, file player,
2785 * or file recorder), PJSUA-LIB will automatically add the port to
2786 * the bridge.
2787 *
2788 * @param pool Pool to use.
2789 * @param port Media port to be added to the bridge.
2790 * @param p_id Optional pointer to receive the conference
2791 * slot id.
2792 *
2793 * @return PJ_SUCCESS on success, or the appropriate error code.
2794 */
2795PJ_DECL(pj_status_t) pjsua_conf_add_port(pj_pool_t *pool,
2796 pjmedia_port *port,
2797 pjsua_conf_port_id *p_id);
2798
2799
2800/**
2801 * Remove arbitrary slot from the conference bridge. Application should only
Benny Prijonob5388cf2007-01-04 22:45:08 +00002802 * call this function if it registered the port manually with previous call
2803 * to #pjsua_conf_add_port().
Benny Prijonoe909eac2006-07-27 22:04:56 +00002804 *
2805 * @param id The slot id of the port to be removed.
2806 *
2807 * @return PJ_SUCCESS on success, or the appropriate error code.
2808 */
2809PJ_DECL(pj_status_t) pjsua_conf_remove_port(pjsua_conf_port_id id);
2810
2811
2812/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002813 * Establish unidirectional media flow from souce to sink. One source
2814 * may transmit to multiple destinations/sink. And if multiple
2815 * sources are transmitting to the same sink, the media will be mixed
2816 * together. Source and sink may refer to the same ID, effectively
2817 * looping the media.
2818 *
2819 * If bidirectional media flow is desired, application needs to call
2820 * this function twice, with the second one having the arguments
2821 * reversed.
2822 *
2823 * @param source Port ID of the source media/transmitter.
2824 * @param sink Port ID of the destination media/received.
2825 *
2826 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002827 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002828PJ_DECL(pj_status_t) pjsua_conf_connect(pjsua_conf_port_id source,
2829 pjsua_conf_port_id sink);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002830
2831
2832/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002833 * Disconnect media flow from the source to destination port.
2834 *
2835 * @param source Port ID of the source media/transmitter.
2836 * @param sink Port ID of the destination media/received.
2837 *
2838 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002839 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002840PJ_DECL(pj_status_t) pjsua_conf_disconnect(pjsua_conf_port_id source,
2841 pjsua_conf_port_id sink);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002842
2843
Benny Prijono6dd967c2006-12-26 02:27:14 +00002844/**
2845 * Adjust the signal level to be transmitted from the bridge to the
2846 * specified port by making it louder or quieter.
2847 *
2848 * @param slot The conference bridge slot number.
2849 * @param level Signal level adjustment. Value 1.0 means no level
2850 * adjustment, while value 0 means to mute the port.
2851 *
2852 * @return PJ_SUCCESS on success, or the appropriate error code.
2853 */
2854PJ_DECL(pj_status_t) pjsua_conf_adjust_tx_level(pjsua_conf_port_id slot,
2855 float level);
2856
2857/**
2858 * Adjust the signal level to be received from the specified port (to
2859 * the bridge) by making it louder or quieter.
2860 *
2861 * @param slot The conference bridge slot number.
2862 * @param level Signal level adjustment. Value 1.0 means no level
2863 * adjustment, while value 0 means to mute the port.
2864 *
2865 * @return PJ_SUCCESS on success, or the appropriate error code.
2866 */
2867PJ_DECL(pj_status_t) pjsua_conf_adjust_rx_level(pjsua_conf_port_id slot,
2868 float level);
2869
2870/**
2871 * Get last signal level transmitted to or received from the specified port.
2872 * The signal level is an integer value in zero to 255, with zero indicates
2873 * no signal, and 255 indicates the loudest signal level.
2874 *
2875 * @param slot The conference bridge slot number.
2876 * @param tx_level Optional argument to receive the level of signal
2877 * transmitted to the specified port (i.e. the direction
2878 * is from the bridge to the port).
2879 * @param rx_level Optional argument to receive the level of signal
2880 * received from the port (i.e. the direction is from the
2881 * port to the bridge).
2882 *
2883 * @return PJ_SUCCESS on success.
2884 */
2885PJ_DECL(pj_status_t) pjsua_conf_get_signal_level(pjsua_conf_port_id slot,
2886 unsigned *tx_level,
2887 unsigned *rx_level);
2888
2889/**
2890 *
2891 */
2892
2893
2894
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002895/*****************************************************************************
Benny Prijonoa66c3312007-01-21 23:12:40 +00002896 * File player and playlist.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002897 */
2898
Benny Prijono9fc735d2006-05-28 14:58:12 +00002899/**
Benny Prijonoa66c3312007-01-21 23:12:40 +00002900 * Create a file player, and automatically add this player to
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002901 * the conference bridge.
2902 *
2903 * @param filename The filename to be played. Currently only
Benny Prijono312aff92006-06-17 04:08:30 +00002904 * WAV files are supported, and the WAV file MUST be
2905 * formatted as 16bit PCM mono/single channel (any
2906 * clock rate is supported).
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002907 * @param options Options (currently zero).
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002908 * @param p_id Pointer to receive player ID.
2909 *
2910 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002911 */
2912PJ_DECL(pj_status_t) pjsua_player_create(const pj_str_t *filename,
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002913 unsigned options,
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002914 pjsua_player_id *p_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002915
2916
2917/**
Benny Prijonoa66c3312007-01-21 23:12:40 +00002918 * Create a file playlist media port, and automatically add the port
2919 * to the conference bridge.
2920 *
2921 * @param file_names Array of file names to be added to the play list.
2922 * Note that the files must have the same clock rate,
2923 * number of channels, and number of bits per sample.
2924 * @param file_count Number of files in the array.
2925 * @param label Optional label to be set for the media port.
2926 * @param options Optional option flag. Application may specify
2927 * PJMEDIA_FILE_NO_LOOP to prevent looping.
2928 * @param p_id Optional pointer to receive player ID.
2929 *
2930 * @return PJ_SUCCESS on success, or the appropriate error code.
2931 */
2932PJ_DECL(pj_status_t) pjsua_playlist_create(const pj_str_t file_names[],
2933 unsigned file_count,
2934 const pj_str_t *label,
2935 unsigned options,
2936 pjsua_player_id *p_id);
2937
2938/**
2939 * Get conference port ID associated with player or playlist.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002940 *
2941 * @param id The file player ID.
2942 *
2943 * @return Conference port ID associated with this player.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002944 */
Benny Prijono8b1889b2006-06-06 18:40:40 +00002945PJ_DECL(pjsua_conf_port_id) pjsua_player_get_conf_port(pjsua_player_id id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002946
2947
2948/**
Benny Prijonoa66c3312007-01-21 23:12:40 +00002949 * Get the media port for the player or playlist.
Benny Prijono469b1522006-12-26 03:05:17 +00002950 *
2951 * @param id The player ID.
2952 * @param p_port The media port associated with the player.
2953 *
2954 * @return PJ_SUCCESS on success.
2955 */
2956PJ_DECL(pj_status_t) pjsua_player_get_port(pjsua_recorder_id id,
2957 pjmedia_port **p_port);
2958
2959/**
Benny Prijonoa66c3312007-01-21 23:12:40 +00002960 * Set playback position. This operation is not valid for playlist.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002961 *
2962 * @param id The file player ID.
2963 * @param samples The playback position, in samples. Application can
2964 * specify zero to re-start the playback.
2965 *
2966 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002967 */
2968PJ_DECL(pj_status_t) pjsua_player_set_pos(pjsua_player_id id,
2969 pj_uint32_t samples);
2970
2971
2972/**
Benny Prijonoa66c3312007-01-21 23:12:40 +00002973 * Close the file of playlist, remove the player from the bridge, and free
2974 * resources associated with the file player or playlist.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002975 *
2976 * @param id The file player ID.
2977 *
2978 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002979 */
2980PJ_DECL(pj_status_t) pjsua_player_destroy(pjsua_player_id id);
2981
2982
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002983/*****************************************************************************
2984 * File recorder.
2985 */
Benny Prijono9fc735d2006-05-28 14:58:12 +00002986
2987/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002988 * Create a file recorder, and automatically connect this recorder to
Benny Prijono8f310522006-10-20 11:08:49 +00002989 * the conference bridge. The recorder currently supports recording WAV file,
2990 * and on Windows, MP3 file. The type of the recorder to use is determined
2991 * by the extension of the file (e.g. ".wav" or ".mp3").
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002992 *
Benny Prijonob3cdb2b2006-10-19 15:49:47 +00002993 * @param filename Output file name. The function will determine the
2994 * default format to be used based on the file extension.
2995 * Currently ".wav" is supported on all platforms, and
2996 * also ".mp3" is support on Windows.
Benny Prijono8f310522006-10-20 11:08:49 +00002997 * @param enc_type Optionally specify the type of encoder to be used to
2998 * compress the media, if the file can support different
2999 * encodings. This value must be zero for now.
3000 * @param enc_param Optionally specify codec specific parameter to be
3001 * passed to the file writer. For .MP3 recorder, this
3002 * can point to pjmedia_mp3_encoder_option structure to
3003 * specify additional settings for the .mp3 recorder.
3004 * For .WAV recorder, this value must be NULL.
3005 * @param max_size Maximum file size. Specify zero or -1 to remove size
3006 * limitation. This value must be zero or -1 for now.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00003007 * @param options Optional options.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00003008 * @param p_id Pointer to receive the recorder instance.
3009 *
3010 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00003011 */
3012PJ_DECL(pj_status_t) pjsua_recorder_create(const pj_str_t *filename,
Benny Prijono8f310522006-10-20 11:08:49 +00003013 unsigned enc_type,
3014 void *enc_param,
Benny Prijonoeebe9af2006-06-13 22:57:13 +00003015 pj_ssize_t max_size,
3016 unsigned options,
Benny Prijonoeebe9af2006-06-13 22:57:13 +00003017 pjsua_recorder_id *p_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00003018
3019
3020/**
3021 * Get conference port associated with recorder.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00003022 *
3023 * @param id The recorder ID.
3024 *
3025 * @return Conference port ID associated with this recorder.
Benny Prijono9fc735d2006-05-28 14:58:12 +00003026 */
Benny Prijono8b1889b2006-06-06 18:40:40 +00003027PJ_DECL(pjsua_conf_port_id) pjsua_recorder_get_conf_port(pjsua_recorder_id id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00003028
3029
3030/**
Benny Prijono469b1522006-12-26 03:05:17 +00003031 * Get the media port for the recorder.
3032 *
3033 * @param id The recorder ID.
3034 * @param p_port The media port associated with the recorder.
3035 *
3036 * @return PJ_SUCCESS on success.
3037 */
3038PJ_DECL(pj_status_t) pjsua_recorder_get_port(pjsua_recorder_id id,
3039 pjmedia_port **p_port);
3040
3041
3042/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00003043 * Destroy recorder (this will complete recording).
3044 *
3045 * @param id The recorder ID.
3046 *
3047 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00003048 */
3049PJ_DECL(pj_status_t) pjsua_recorder_destroy(pjsua_recorder_id id);
3050
3051
Benny Prijonoeebe9af2006-06-13 22:57:13 +00003052/*****************************************************************************
3053 * Sound devices.
3054 */
3055
Benny Prijono9fc735d2006-05-28 14:58:12 +00003056/**
Benny Prijonob5388cf2007-01-04 22:45:08 +00003057 * Enum all sound devices installed in the system.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00003058 *
3059 * @param info Array of info to be initialized.
3060 * @param count On input, specifies max elements in the array.
3061 * On return, it contains actual number of elements
3062 * that have been initialized.
3063 *
3064 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00003065 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00003066PJ_DECL(pj_status_t) pjsua_enum_snd_devs(pjmedia_snd_dev_info info[],
3067 unsigned *count);
Benny Prijono9fc735d2006-05-28 14:58:12 +00003068
3069
Benny Prijonoa3cbb1c2006-08-25 12:41:05 +00003070
3071/**
3072 * Get currently active sound devices. If sound devices has not been created
3073 * (for example when pjsua_start() is not called), it is possible that
3074 * the function returns PJ_SUCCESS with -1 as device IDs.
3075 *
3076 * @param capture_dev On return it will be filled with device ID of the
3077 * capture device.
3078 * @param playback_dev On return it will be filled with device ID of the
3079 * device ID of the playback device.
3080 *
3081 * @return PJ_SUCCESS on success, or the appropriate error code.
3082 */
3083PJ_DECL(pj_status_t) pjsua_get_snd_dev(int *capture_dev,
3084 int *playback_dev);
3085
3086
Benny Prijono9fc735d2006-05-28 14:58:12 +00003087/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00003088 * Select or change sound device. Application may call this function at
3089 * any time to replace current sound device.
3090 *
3091 * @param capture_dev Device ID of the capture device.
3092 * @param playback_dev Device ID of the playback device.
3093 *
3094 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00003095 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00003096PJ_DECL(pj_status_t) pjsua_set_snd_dev(int capture_dev,
3097 int playback_dev);
3098
3099
3100/**
3101 * Set pjsua to use null sound device. The null sound device only provides
3102 * the timing needed by the conference bridge, and will not interract with
3103 * any hardware.
3104 *
3105 * @return PJ_SUCCESS on success, or the appropriate error code.
3106 */
3107PJ_DECL(pj_status_t) pjsua_set_null_snd_dev(void);
3108
3109
Benny Prijonoe909eac2006-07-27 22:04:56 +00003110/**
3111 * Disconnect the main conference bridge from any sound devices, and let
3112 * application connect the bridge to it's own sound device/master port.
3113 *
3114 * @return The port interface of the conference bridge,
3115 * so that application can connect this to it's own
3116 * sound device or master port.
3117 */
3118PJ_DECL(pjmedia_port*) pjsua_set_no_snd_dev(void);
3119
3120
Benny Prijonof20687a2006-08-04 18:27:19 +00003121/**
Benny Prijono22dfe592006-08-06 12:07:13 +00003122 * Configure the echo canceller tail length of the sound port.
Benny Prijonof20687a2006-08-04 18:27:19 +00003123 *
3124 * @param tail_ms The tail length, in miliseconds. Set to zero to
3125 * disable AEC.
Benny Prijono5da50432006-08-07 10:24:52 +00003126 * @param options Options to be passed to #pjmedia_echo_create().
3127 * Normally the value should be zero.
Benny Prijonof20687a2006-08-04 18:27:19 +00003128 *
3129 * @return PJ_SUCCESS on success.
3130 */
Benny Prijono5da50432006-08-07 10:24:52 +00003131PJ_DECL(pj_status_t) pjsua_set_ec(unsigned tail_ms, unsigned options);
Benny Prijonof20687a2006-08-04 18:27:19 +00003132
3133
3134/**
Benny Prijono22dfe592006-08-06 12:07:13 +00003135 * Get current echo canceller tail length.
Benny Prijonof20687a2006-08-04 18:27:19 +00003136 *
3137 * @param p_tail_ms Pointer to receive the tail length, in miliseconds.
3138 * If AEC is disabled, the value will be zero.
3139 *
3140 * @return PJ_SUCCESS on success.
3141 */
Benny Prijono22dfe592006-08-06 12:07:13 +00003142PJ_DECL(pj_status_t) pjsua_get_ec_tail(unsigned *p_tail_ms);
Benny Prijonof20687a2006-08-04 18:27:19 +00003143
3144
3145
Benny Prijonoeebe9af2006-06-13 22:57:13 +00003146/*****************************************************************************
3147 * Codecs.
3148 */
3149
3150/**
3151 * Enum all supported codecs in the system.
3152 *
3153 * @param id Array of ID to be initialized.
3154 * @param count On input, specifies max elements in the array.
3155 * On return, it contains actual number of elements
3156 * that have been initialized.
3157 *
3158 * @return PJ_SUCCESS on success, or the appropriate error code.
3159 */
3160PJ_DECL(pj_status_t) pjsua_enum_codecs( pjsua_codec_info id[],
3161 unsigned *count );
3162
3163
3164/**
3165 * Change codec priority.
3166 *
3167 * @param id Codec ID.
3168 * @param priority Codec priority, 0-255, where zero means to disable
3169 * the codec.
3170 *
3171 * @return PJ_SUCCESS on success, or the appropriate error code.
3172 */
3173PJ_DECL(pj_status_t) pjsua_codec_set_priority( const pj_str_t *id,
3174 pj_uint8_t priority );
3175
3176
3177/**
3178 * Get codec parameters.
3179 *
3180 * @param id Codec ID.
3181 * @param param Structure to receive codec parameters.
3182 *
3183 * @return PJ_SUCCESS on success, or the appropriate error code.
3184 */
3185PJ_DECL(pj_status_t) pjsua_codec_get_param( const pj_str_t *id,
3186 pjmedia_codec_param *param );
3187
3188
3189/**
3190 * Set codec parameters.
3191 *
3192 * @param id Codec ID.
3193 * @param param Codec parameter to set.
3194 *
3195 * @return PJ_SUCCESS on success, or the appropriate error code.
3196 */
3197PJ_DECL(pj_status_t) pjsua_codec_set_param( const pj_str_t *id,
3198 const pjmedia_codec_param *param);
3199
3200
3201
Benny Prijono9fc735d2006-05-28 14:58:12 +00003202
Benny Prijono312aff92006-06-17 04:08:30 +00003203/**
3204 * Create UDP media transports for all the calls. This function creates
3205 * one UDP media transport for each call.
Benny Prijonof3195072006-02-14 21:15:30 +00003206 *
Benny Prijono312aff92006-06-17 04:08:30 +00003207 * @param cfg Media transport configuration. The "port" field in the
3208 * configuration is used as the start port to bind the
3209 * sockets.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00003210 *
3211 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonof3195072006-02-14 21:15:30 +00003212 */
Benny Prijono312aff92006-06-17 04:08:30 +00003213PJ_DECL(pj_status_t)
3214pjsua_media_transports_create(const pjsua_transport_config *cfg);
Benny Prijonof3195072006-02-14 21:15:30 +00003215
Benny Prijonodc39fe82006-05-26 12:17:46 +00003216
3217/**
Benny Prijono312aff92006-06-17 04:08:30 +00003218 * Register custom media transports to be used by calls. There must
3219 * enough media transports for all calls.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00003220 *
Benny Prijono312aff92006-06-17 04:08:30 +00003221 * @param tp The media transport array.
3222 * @param count Number of elements in the array. This number MUST
3223 * match the number of maximum calls configured when
3224 * pjsua is created.
3225 * @param auto_delete Flag to indicate whether the transports should be
3226 * destroyed when pjsua is shutdown.
3227 *
3228 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonodc39fe82006-05-26 12:17:46 +00003229 */
Benny Prijono312aff92006-06-17 04:08:30 +00003230PJ_DECL(pj_status_t)
3231pjsua_media_transports_attach( pjsua_media_transport tp[],
3232 unsigned count,
3233 pj_bool_t auto_delete);
Benny Prijonodc39fe82006-05-26 12:17:46 +00003234
3235
Benny Prijono312aff92006-06-17 04:08:30 +00003236/**
3237 * @}
3238 */
3239
Benny Prijonof3195072006-02-14 21:15:30 +00003240
Benny Prijono268ca612006-02-07 12:34:11 +00003241
Benny Prijono1a01ad32006-02-07 21:13:28 +00003242PJ_END_DECL
3243
Benny Prijonof3195072006-02-14 21:15:30 +00003244
Benny Prijono312aff92006-06-17 04:08:30 +00003245/**
3246 * @}
3247 */
3248
3249
Benny Prijono268ca612006-02-07 12:34:11 +00003250#endif /* __PJSUA_H__ */