blob: 0a106f475c958642250664ac4a51946419ebcb12 [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
118 pjsua_config ua_cfg;
119 pjsua_logging_config log_cfg;
120 pjsua_media_config media_cfg;
121
122 // Initialize configs with default settings.
123 pjsua_config_default(&ua_cfg);
124 pjsua_logging_config_default(&log_cfg);
125 pjsua_media_config_default(&media_cfg);
126
127 // At the very least, application would want to override
128 // the call callbacks in pjsua_config:
129 ua_cfg.cb.on_incoming_call = ...
130 ua_cfg.cb.on_call_state = ..
131 ...
132
133 // Customize other settings (or initialize them from application specific
134 // configuration file):
135 ...
136
137 // Initialize pjsua
138 status = pjsua_init(&ua_cfg, &log_cfg, &media_cfg);
139 if (status != PJ_SUCCESS) {
140 pjsua_perror(THIS_FILE, "Error initializing pjsua", status);
141 return status;
142 }
143 ..
144
145 \endcode
146 *
147 * @subsection other_init_pjsua_lib Other Initialization
148 *
149 * After PJSUA is initialized with #pjsua_init(), application will normally
150 * need/want to perform the following tasks:
151 *
152 * - create SIP transport with #pjsua_transport_create(). Please see
153 * @ref PJSUA_LIB_TRANSPORT section for more info.
154 * - create one or more SIP accounts with #pjsua_acc_add() or
155 * #pjsua_acc_add_local(). Please see @ref PJSUA_LIB_ACC for more info.
156 * - add one or more buddies with #pjsua_buddy_add(). Please see
157 * @ref PJSUA_LIB_BUDDY section for more info.
158 * - optionally configure the sound device, codec settings, and other
159 * media settings. Please see @ref PJSUA_LIB_MEDIA for more info.
160 *
161 *
162 * @subsection starting_pjsua_lib Starting PJSUA
163 *
164 * After all initializations have been done, application must call
165 * #pjsua_start() to start PJSUA. This function will check that all settings
166 * are properly configured, and apply default settings when it's not, or
167 * report error status when it is unable to recover from missing setting.
168 *
169 * Most settings can be changed during run-time. For example, application
170 * may add, modify, or delete accounts, buddies, or change media settings
171 * during run-time.
Benny Prijonof04ffdd2006-02-21 00:11:18 +0000172 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000173
Benny Prijono312aff92006-06-17 04:08:30 +0000174/** Constant to identify invalid ID for all sorts of IDs. */
175#define PJSUA_INVALID_ID (-1)
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000176
177/** Call identification */
178typedef int pjsua_call_id;
179
Benny Prijono312aff92006-06-17 04:08:30 +0000180/** Account identification */
181typedef int pjsua_acc_id;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000182
183/** Buddy identification */
Benny Prijono8b1889b2006-06-06 18:40:40 +0000184typedef int pjsua_buddy_id;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000185
186/** File player identification */
Benny Prijono8b1889b2006-06-06 18:40:40 +0000187typedef int pjsua_player_id;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000188
189/** File recorder identification */
Benny Prijono8b1889b2006-06-06 18:40:40 +0000190typedef int pjsua_recorder_id;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000191
192/** Conference port identification */
Benny Prijono8b1889b2006-06-06 18:40:40 +0000193typedef int pjsua_conf_port_id;
194
195
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000196
Benny Prijonoa91a0032006-02-26 21:23:45 +0000197/**
Benny Prijono312aff92006-06-17 04:08:30 +0000198 * Maximum proxies in account.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000199 */
Benny Prijono312aff92006-06-17 04:08:30 +0000200#ifndef PJSUA_ACC_MAX_PROXIES
201# define PJSUA_ACC_MAX_PROXIES 8
202#endif
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000203
204
205
206/**
207 * Logging configuration.
208 */
209typedef struct pjsua_logging_config
210{
211 /**
212 * Log incoming and outgoing SIP message? Yes!
213 */
214 pj_bool_t msg_logging;
215
216 /**
217 * Input verbosity level. Value 5 is reasonable.
218 */
219 unsigned level;
220
221 /**
222 * Verbosity level for console. Value 4 is reasonable.
223 */
224 unsigned console_level;
225
226 /**
227 * Log decoration.
228 */
229 unsigned decor;
230
231 /**
232 * Optional log filename.
233 */
234 pj_str_t log_filename;
235
236 /**
237 * Optional callback function to be called to write log to
238 * application specific device. This function will be called for
239 * log messages on input verbosity level.
240 */
241 void (*cb)(int level, const char *data, pj_size_t len);
242
243
244} pjsua_logging_config;
245
246
247/**
248 * Use this function to initialize logging config.
249 *
250 * @param cfg The logging config to be initialized.
251 */
252PJ_INLINE(void) pjsua_logging_config_default(pjsua_logging_config *cfg)
253{
Benny Prijonoac623b32006-07-03 15:19:31 +0000254 pj_bzero(cfg, sizeof(*cfg));
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000255
256 cfg->msg_logging = PJ_TRUE;
257 cfg->level = 5;
258 cfg->console_level = 4;
259 cfg->decor = PJ_LOG_HAS_SENDER | PJ_LOG_HAS_TIME |
260 PJ_LOG_HAS_MICRO_SEC | PJ_LOG_HAS_NEWLINE;
261}
262
263/**
264 * Use this function to duplicate logging config.
265 *
266 * @param pool Pool to use.
267 * @param dst Destination config.
268 * @param src Source config.
269 */
270PJ_INLINE(void) pjsua_logging_config_dup(pj_pool_t *pool,
271 pjsua_logging_config *dst,
272 const pjsua_logging_config *src)
273{
274 pj_memcpy(dst, src, sizeof(*src));
275 pj_strdup_with_null(pool, &dst->log_filename, &src->log_filename);
276}
277
278
Benny Prijonodc39fe82006-05-26 12:17:46 +0000279
280/**
281 * Application callbacks.
282 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000283typedef struct pjsua_callback
Benny Prijonodc39fe82006-05-26 12:17:46 +0000284{
285 /**
Benny Prijono9fc735d2006-05-28 14:58:12 +0000286 * Notify application when invite state has changed.
287 * Application may then query the call info to get the
288 * detail call states.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000289 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000290 void (*on_call_state)(pjsua_call_id call_id, pjsip_event *e);
Benny Prijonodc39fe82006-05-26 12:17:46 +0000291
292 /**
Benny Prijono8b1889b2006-06-06 18:40:40 +0000293 * Notify application on incoming call.
294 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000295 void (*on_incoming_call)(pjsua_acc_id acc_id, pjsua_call_id call_id,
Benny Prijono8b1889b2006-06-06 18:40:40 +0000296 pjsip_rx_data *rdata);
297
298 /**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000299 * Notify application when media state in the call has changed.
300 * Normal application would need to implement this callback, e.g.
301 * to connect the call's media to sound device.
302 */
303 void (*on_call_media_state)(pjsua_call_id call_id);
304
305 /**
Benny Prijono9fc735d2006-05-28 14:58:12 +0000306 * Notify application on call being transfered.
307 * Application can decide to accept/reject transfer request
308 * by setting the code (default is 200). When this callback
309 * is not defined, the default behavior is to accept the
310 * transfer.
311 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000312 void (*on_call_transfered)(pjsua_call_id call_id,
Benny Prijono9fc735d2006-05-28 14:58:12 +0000313 const pj_str_t *dst,
314 pjsip_status_code *code);
315
316 /**
317 * Notify application when registration status has changed.
318 * Application may then query the account info to get the
319 * registration details.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000320 */
Benny Prijono8b1889b2006-06-06 18:40:40 +0000321 void (*on_reg_state)(pjsua_acc_id acc_id);
Benny Prijonodc39fe82006-05-26 12:17:46 +0000322
323 /**
Benny Prijono9fc735d2006-05-28 14:58:12 +0000324 * Notify application when the buddy state has changed.
325 * Application may then query the buddy into to get the details.
326 */
Benny Prijono8b1889b2006-06-06 18:40:40 +0000327 void (*on_buddy_state)(pjsua_buddy_id buddy_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +0000328
329 /**
330 * Notify application on incoming pager (i.e. MESSAGE request).
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000331 * Argument call_id will be -1 if MESSAGE request is not related to an
Benny Prijonodc39fe82006-05-26 12:17:46 +0000332 * existing call.
333 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000334 void (*on_pager)(pjsua_call_id call_id, const pj_str_t *from,
335 const pj_str_t *to, const pj_str_t *contact,
336 const pj_str_t *mime_type, const pj_str_t *body);
337
338 /**
339 * Notify application about the delivery status of outgoing pager
340 * request.
341 *
342 * @param call_id Containts the ID of the call where the IM was
343 * sent, or PJSUA_INVALID_ID if the IM was sent
344 * outside call context.
345 * @param to Destination URI.
346 * @param body Message body.
347 * @param user_data Arbitrary data that was specified when sending
348 * IM message.
349 * @param status Delivery status.
350 * @param reason Delivery status reason.
351 */
352 void (*on_pager_status)(pjsua_call_id call_id,
353 const pj_str_t *to,
354 const pj_str_t *body,
355 void *user_data,
356 pjsip_status_code status,
357 const pj_str_t *reason);
Benny Prijonodc39fe82006-05-26 12:17:46 +0000358
359 /**
Benny Prijono9fc735d2006-05-28 14:58:12 +0000360 * Notify application about typing indication.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000361 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000362 void (*on_typing)(pjsua_call_id call_id, const pj_str_t *from,
363 const pj_str_t *to, const pj_str_t *contact,
364 pj_bool_t is_typing);
Benny Prijonodc39fe82006-05-26 12:17:46 +0000365
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000366} pjsua_callback;
367
368
369
Benny Prijonodc39fe82006-05-26 12:17:46 +0000370
371/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000372 * PJSUA settings.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000373 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000374typedef struct pjsua_config
375{
376
377 /**
378 * Maximum calls to support (default: 4)
379 */
380 unsigned max_calls;
381
382 /**
383 * Number of worker threads. Normally application will want to have at
384 * least one worker thread, unless when it wants to poll the library
385 * periodically, which in this case the worker thread can be set to
386 * zero.
387 */
388 unsigned thread_cnt;
389
390 /**
391 * Number of outbound proxies in the array.
392 */
393 unsigned outbound_proxy_cnt;
394
395 /**
396 * Specify the URL of outbound proxies to visit for all outgoing requests.
397 * The outbound proxies will be used for all accounts, and it will
398 * be used to build the route set for outgoing requests. The final
399 * route set for outgoing requests will consists of the outbound proxies
400 * and the proxy configured in the account.
401 */
402 pj_str_t outbound_proxy[4];
403
404 /**
405 * Number of credentials in the credential array.
406 */
407 unsigned cred_count;
408
409 /**
410 * Array of credentials. These credentials will be used by all accounts,
411 * and can be used to authenticate against outbound proxies.
412 */
413 pjsip_cred_info cred_info[PJSUA_ACC_MAX_PROXIES];
414
415 /**
416 * Application callback.
417 */
418 pjsua_callback cb;
419
Benny Prijono56315612006-07-18 14:39:40 +0000420 /**
421 * User agent string (default empty)
422 */
423 pj_str_t user_agent;
424
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000425} pjsua_config;
426
427
428/**
429 * Use this function to initialize pjsua config.
430 *
431 * @param cfg pjsua config to be initialized.
432 */
433PJ_INLINE(void) pjsua_config_default(pjsua_config *cfg)
434{
Benny Prijonoac623b32006-07-03 15:19:31 +0000435 pj_bzero(cfg, sizeof(*cfg));
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000436
437 cfg->max_calls = 4;
438 cfg->thread_cnt = 1;
439}
440
441
442/**
443 * Duplicate credential.
444 */
445PJ_INLINE(void) pjsip_cred_dup( pj_pool_t *pool,
446 pjsip_cred_info *dst,
447 const pjsip_cred_info *src)
448{
449 pj_strdup_with_null(pool, &dst->realm, &src->realm);
450 pj_strdup_with_null(pool, &dst->scheme, &src->scheme);
451 pj_strdup_with_null(pool, &dst->username, &src->username);
452 pj_strdup_with_null(pool, &dst->data, &src->data);
453
454}
455
456
457/**
458 * Duplicate pjsua_config.
459 */
460PJ_INLINE(void) pjsua_config_dup(pj_pool_t *pool,
461 pjsua_config *dst,
462 const pjsua_config *src)
463{
464 unsigned i;
465
466 pj_memcpy(dst, src, sizeof(*src));
467
468 for (i=0; i<src->outbound_proxy_cnt; ++i) {
469 pj_strdup_with_null(pool, &dst->outbound_proxy[i],
470 &src->outbound_proxy[i]);
471 }
472
473 for (i=0; i<src->cred_count; ++i) {
474 pjsip_cred_dup(pool, &dst->cred_info[i], &src->cred_info[i]);
475 }
Benny Prijono56315612006-07-18 14:39:40 +0000476
477 pj_strdup_with_null(pool, &dst->user_agent, &src->user_agent);
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000478}
479
480
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000481
482/**
483 * This structure describes additional information to be sent with
484 * outgoing SIP message.
485 */
486typedef struct pjsua_msg_data
487{
488 /**
489 * Additional message headers as linked list.
490 */
491 pjsip_hdr hdr_list;
492
493 /**
494 * MIME type of optional message body.
495 */
496 pj_str_t content_type;
497
498 /**
499 * Optional message body.
500 */
501 pj_str_t msg_body;
502
503} pjsua_msg_data;
504
505
506/**
507 * Initialize message data.
508 *
509 * @param msg_data Message data to be initialized.
510 */
511PJ_INLINE(void) pjsua_msg_data_init(pjsua_msg_data *msg_data)
512{
Benny Prijonoac623b32006-07-03 15:19:31 +0000513 pj_bzero(msg_data, sizeof(*msg_data));
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000514 pj_list_init(&msg_data->hdr_list);
515}
Benny Prijono8b1889b2006-06-06 18:40:40 +0000516
Benny Prijono268ca612006-02-07 12:34:11 +0000517
Benny Prijono268ca612006-02-07 12:34:11 +0000518
519/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000520 * Instantiate pjsua application. Application must call this function before
521 * calling any other functions, to make sure that the underlying libraries
522 * are properly initialized. Once this function has returned success,
523 * application must call pjsua_destroy() before quitting.
524 *
525 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000526 */
527PJ_DECL(pj_status_t) pjsua_create(void);
528
529
530/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000531 * Initialize pjsua with the specified settings. All the settings are
532 * optional, and the default values will be used when the config is not
533 * specified.
Benny Prijonoccf95622006-02-07 18:48:01 +0000534 *
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000535 * @param ua_cfg User agent configuration.
536 * @param log_cfg Optional logging configuration.
537 * @param media_cfg Optional media configuration.
Benny Prijonoccf95622006-02-07 18:48:01 +0000538 *
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000539 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono268ca612006-02-07 12:34:11 +0000540 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000541PJ_DECL(pj_status_t) pjsua_init(const pjsua_config *ua_cfg,
542 const pjsua_logging_config *log_cfg,
543 const pjsua_media_config *media_cfg);
Benny Prijono268ca612006-02-07 12:34:11 +0000544
545
546/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000547 * Application is recommended to call this function after all initialization
548 * is done, so that the library can do additional checking set up
549 * additional
Benny Prijonoccf95622006-02-07 18:48:01 +0000550 *
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000551 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonoccf95622006-02-07 18:48:01 +0000552 */
Benny Prijonodc39fe82006-05-26 12:17:46 +0000553PJ_DECL(pj_status_t) pjsua_start(void);
Benny Prijonoccf95622006-02-07 18:48:01 +0000554
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000555
Benny Prijonoccf95622006-02-07 18:48:01 +0000556/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000557 * Destroy pjsua. This function must be called once PJSUA is created. To
558 * make it easier for application, application may call this function
559 * several times with no danger.
560 *
561 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono268ca612006-02-07 12:34:11 +0000562 */
Benny Prijonodc39fe82006-05-26 12:17:46 +0000563PJ_DECL(pj_status_t) pjsua_destroy(void);
Benny Prijonoa91a0032006-02-26 21:23:45 +0000564
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000565
Benny Prijono9fc735d2006-05-28 14:58:12 +0000566/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000567 * Poll pjsua for events, and if necessary block the caller thread for
568 * the specified maximum interval (in miliseconds).
569 *
570 * @param msec_timeout Maximum time to wait, in miliseconds.
571 *
572 * @return The number of events that have been handled during the
573 * poll. Negative value indicates error, and application
574 * can retrieve the error as (err = -return_value).
Benny Prijonob9b32ab2006-06-01 12:28:44 +0000575 */
576PJ_DECL(int) pjsua_handle_events(unsigned msec_timeout);
577
578
579/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000580 * Create memory pool.
581 *
582 * @param name Optional pool name.
Benny Prijono312aff92006-06-17 04:08:30 +0000583 * @param init_size Initial size of the pool.
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000584 * @param increment Increment size.
585 *
586 * @return The pool, or NULL when there's no memory.
587 */
588PJ_DECL(pj_pool_t*) pjsua_pool_create(const char *name, pj_size_t init_size,
589 pj_size_t increment);
590
591
592/**
593 * Application can call this function at any time (after pjsua_create(), of
594 * course) to change logging settings.
595 *
596 * @param c Logging configuration.
597 *
598 * @return PJ_SUCCESS on success, or the appropriate error code.
599 */
600PJ_DECL(pj_status_t) pjsua_reconfigure_logging(const pjsua_logging_config *c);
601
602
603/**
604 * Internal function to get SIP endpoint instance of pjsua, which is
605 * needed for example to register module, create transports, etc.
606 * Probably is only valid after #pjsua_init() is called.
607 *
608 * @return SIP endpoint instance.
Benny Prijono9fc735d2006-05-28 14:58:12 +0000609 */
610PJ_DECL(pjsip_endpoint*) pjsua_get_pjsip_endpt(void);
611
612/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000613 * Internal function to get media endpoint instance.
614 * Only valid after #pjsua_init() is called.
615 *
616 * @return Media endpoint instance.
Benny Prijono9fc735d2006-05-28 14:58:12 +0000617 */
618PJ_DECL(pjmedia_endpt*) pjsua_get_pjmedia_endpt(void);
619
Benny Prijono97b87172006-08-24 14:25:14 +0000620/**
621 * Internal function to get PJSUA pool factory.
622 * Only valid after #pjsua_init() is called.
623 *
624 * @return Pool factory currently used by PJSUA.
625 */
626PJ_DECL(pj_pool_factory*) pjsua_get_pool_factory(void);
627
628
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000629
630/*****************************************************************************
Benny Prijono312aff92006-06-17 04:08:30 +0000631 * Utilities.
632 *
Benny Prijono9fc735d2006-05-28 14:58:12 +0000633 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000634
635/**
Benny Prijono312aff92006-06-17 04:08:30 +0000636 * Verify that valid SIP url is given.
637 *
638 * @param c_url The URL, as NULL terminated string.
639 *
640 * @return PJ_SUCCESS on success, or the appropriate error code.
641 */
642PJ_DECL(pj_status_t) pjsua_verify_sip_url(const char *c_url);
643
644
645/**
646 * Display error message for the specified error code.
647 *
648 * @param sender The log sender field.
649 * @param title Message title for the error.
650 * @param status Status code.
651 */
652PJ_DECL(void) pjsua_perror(const char *sender, const char *title,
653 pj_status_t status);
654
655
656
657
658/**
659 * @}
660 */
661
662
663
664/*****************************************************************************
665 * TRANSPORT API
666 */
667
668/**
669 * @defgroup PJSUA_LIB_TRANSPORT Signaling Transport
670 * @ingroup PJSUA_LIB
671 * @brief API for managing SIP transports
672 * @{
673 * SIP transport must be created before adding an account. SIP transport is
674 * created by calling #pjsua_transport_create() function.
675 */
676
677
678/** SIP transport identification */
679typedef int pjsua_transport_id;
680
681
682/**
683 * STUN configuration.
684 */
685typedef struct pjsua_stun_config
686{
687 /**
688 * The first STUN server IP address or hostname.
689 */
690 pj_str_t stun_srv1;
691
692 /**
693 * Port number of the first STUN server.
694 * If zero, default STUN port will be used.
695 */
696 unsigned stun_port1;
697
698 /**
699 * Optional second STUN server IP address or hostname, for which the
700 * result of the mapping request will be compared to. If the value
701 * is empty, only one STUN server will be used.
702 */
703 pj_str_t stun_srv2;
704
705 /**
706 * Port number of the second STUN server.
707 * If zero, default STUN port will be used.
708 */
709 unsigned stun_port2;
710
711} pjsua_stun_config;
712
713
714
715/**
716 * Call this function to initialize STUN config with default values.
717 *
718 * @param cfg The STUN config to be initialized.
719 */
720PJ_INLINE(void) pjsua_stun_config_default(pjsua_stun_config *cfg)
721{
Benny Prijonoac623b32006-07-03 15:19:31 +0000722 pj_bzero(cfg, sizeof(*cfg));
Benny Prijono312aff92006-06-17 04:08:30 +0000723}
724
725
726/**
727 * Transport configuration for creating UDP transports for both SIP
728 * and media.
729 */
730typedef struct pjsua_transport_config
731{
732 /**
733 * UDP port number to bind locally. This setting MUST be specified
734 * even when default port is desired. If the value is zero, the
735 * transport will be bound to any available port, and application
736 * can query the port by querying the transport info.
737 */
738 unsigned port;
739
740 /**
741 * Optional address where the socket should be bound.
742 */
743 pj_in_addr ip_addr;
744
745 /**
746 * Flag to indicate whether STUN should be used.
747 */
748 pj_bool_t use_stun;
749
750 /**
751 * STUN configuration, must be specified when STUN is used.
752 */
753 pjsua_stun_config stun_config;
754
755} pjsua_transport_config;
756
757
758/**
759 * Call this function to initialize UDP config with default values.
760 *
761 * @param cfg The UDP config to be initialized.
762 */
763PJ_INLINE(void) pjsua_transport_config_default(pjsua_transport_config *cfg)
764{
Benny Prijonoac623b32006-07-03 15:19:31 +0000765 pj_bzero(cfg, sizeof(*cfg));
Benny Prijono312aff92006-06-17 04:08:30 +0000766}
767
768
769/**
770 * Normalize STUN config.
771 */
772PJ_INLINE(void) pjsua_normalize_stun_config( pjsua_stun_config *cfg )
773{
774 if (cfg->stun_srv1.slen) {
775
776 if (cfg->stun_port1 == 0)
777 cfg->stun_port1 = 3478;
778
779 if (cfg->stun_srv2.slen == 0) {
780 cfg->stun_srv2 = cfg->stun_srv1;
781 cfg->stun_port2 = cfg->stun_port1;
782 } else {
783 if (cfg->stun_port2 == 0)
784 cfg->stun_port2 = 3478;
785 }
786
787 } else {
788 cfg->stun_port1 = 0;
789 cfg->stun_srv2.slen = 0;
790 cfg->stun_port2 = 0;
791 }
792}
793
794
795/**
796 * Duplicate transport config.
797 */
798PJ_INLINE(void) pjsua_transport_config_dup(pj_pool_t *pool,
799 pjsua_transport_config *dst,
800 const pjsua_transport_config *src)
801{
802 pj_memcpy(dst, src, sizeof(*src));
803
804 if (src->stun_config.stun_srv1.slen) {
805 pj_strdup_with_null(pool, &dst->stun_config.stun_srv1,
806 &src->stun_config.stun_srv1);
807 }
808
809 if (src->stun_config.stun_srv2.slen) {
810 pj_strdup_with_null(pool, &dst->stun_config.stun_srv2,
811 &src->stun_config.stun_srv2);
812 }
813
814 pjsua_normalize_stun_config(&dst->stun_config);
815}
816
817
818
819/**
820 * Transport info.
821 */
822typedef struct pjsua_transport_info
823{
824 /**
825 * PJSUA transport identification.
826 */
827 pjsua_transport_id id;
828
829 /**
830 * Transport type.
831 */
832 pjsip_transport_type_e type;
833
834 /**
835 * Transport type name.
836 */
837 pj_str_t type_name;
838
839 /**
840 * Transport string info/description.
841 */
842 pj_str_t info;
843
844 /**
845 * Transport flag (see ##pjsip_transport_flags_e).
846 */
847 unsigned flag;
848
849 /**
850 * Local address length.
851 */
852 unsigned addr_len;
853
854 /**
855 * Local/bound address.
856 */
857 pj_sockaddr local_addr;
858
859 /**
860 * Published address (or transport address name).
861 */
862 pjsip_host_port local_name;
863
864 /**
865 * Current number of objects currently referencing this transport.
866 */
867 unsigned usage_count;
868
869
870} pjsua_transport_info;
871
872
873/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000874 * Create SIP transport.
875 *
876 * @param type Transport type.
877 * @param cfg Transport configuration.
878 * @param p_id Optional pointer to receive transport ID.
879 *
880 * @return PJ_SUCCESS on success, or the appropriate error code.
881 */
882PJ_DECL(pj_status_t) pjsua_transport_create(pjsip_transport_type_e type,
883 const pjsua_transport_config *cfg,
884 pjsua_transport_id *p_id);
885
886/**
887 * Register transport that has been created by application.
888 *
889 * @param tp Transport instance.
890 * @param p_id Optional pointer to receive transport ID.
891 *
892 * @return PJ_SUCCESS on success, or the appropriate error code.
893 */
894PJ_DECL(pj_status_t) pjsua_transport_register(pjsip_transport *tp,
895 pjsua_transport_id *p_id);
896
897
898/**
899 * Enumerate all transports currently created in the system.
900 *
901 * @param id Array to receive transport ids.
902 * @param count In input, specifies the maximum number of elements.
903 * On return, it contains the actual number of elements.
904 *
905 * @return PJ_SUCCESS on success, or the appropriate error code.
906 */
907PJ_DECL(pj_status_t) pjsua_enum_transports( pjsua_transport_id id[],
908 unsigned *count );
909
910
911/**
912 * Get information about transports.
913 *
914 * @param id Transport ID.
915 * @param info Pointer to receive transport info.
916 *
917 * @return PJ_SUCCESS on success, or the appropriate error code.
918 */
919PJ_DECL(pj_status_t) pjsua_transport_get_info(pjsua_transport_id id,
920 pjsua_transport_info *info);
921
922
923/**
924 * Disable a transport or re-enable it. By default transport is always
925 * enabled after it is created. Disabling a transport does not necessarily
926 * close the socket, it will only discard incoming messages and prevent
927 * the transport from being used to send outgoing messages.
928 *
929 * @param id Transport ID.
930 * @param enabled Non-zero to enable, zero to disable.
931 *
932 * @return PJ_SUCCESS on success, or the appropriate error code.
933 */
934PJ_DECL(pj_status_t) pjsua_transport_set_enable(pjsua_transport_id id,
935 pj_bool_t enabled);
936
937
938/**
939 * Close the transport. If transport is forcefully closed, it will be
940 * immediately closed, and any pending transactions that are using the
941 * transport may not terminate properly. Otherwise, the system will wait
942 * until all transactions are closed while preventing new users from
943 * using the transport, and will close the transport when it is safe to
944 * do so.
945 *
946 * @param id Transport ID.
947 * @param force Non-zero to immediately close the transport. This
948 * is not recommended!
949 *
950 * @return PJ_SUCCESS on success, or the appropriate error code.
951 */
952PJ_DECL(pj_status_t) pjsua_transport_close( pjsua_transport_id id,
953 pj_bool_t force );
Benny Prijono9fc735d2006-05-28 14:58:12 +0000954
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000955/**
Benny Prijono312aff92006-06-17 04:08:30 +0000956 * @}
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000957 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000958
959
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000960
961
962/*****************************************************************************
Benny Prijono312aff92006-06-17 04:08:30 +0000963 * ACCOUNT API
Benny Prijonoa91a0032006-02-26 21:23:45 +0000964 */
965
Benny Prijono312aff92006-06-17 04:08:30 +0000966
967/**
968 * @defgroup PJSUA_LIB_ACC Account Management
969 * @ingroup PJSUA_LIB
970 * @brief PJSUA supports multiple accounts..
971 * @{
972 * PJSUA accounts provide identity (or identities) of the user who is currently
973 * using the application. More than one account maybe created with PJSUA.
974 *
975 * Account may or may not have client registration associated with it.
976 * An account is also associated with <b>route set</b> and some <b>authentication
977 * credentials</b>, which are used when sending SIP request messages using the
978 * account. An account also has presence's <b>online status</b>, which
979 * will be reported to remote peer when the subscribe to the account's
980 * presence.
981 *
982 * At least one account MUST be created in the application. If no user
983 * association is required, application can create a userless account by
984 * calling #pjsua_acc_add_local(). A userless account identifies local endpoint
985 * instead of a particular user.
986 *
987 * Also one account must be set as the <b>default account</b>, which is used as
988 * the account to use when PJSUA fails to match a request with any other
989 * accounts.
990 *
991 * When sending outgoing SIP requests (such as making calls or sending
992 * instant messages), normally PJSUA requires the application to specify
993 * which account to use for the request. If no account is specified,
994 * PJSUA may be able to select the account by matching the destination
995 * domain name, and fall back to default account when no match is found.
996 */
997
998/**
999 * Maximum accounts.
1000 */
1001#ifndef PJSUA_MAX_ACC
1002# define PJSUA_MAX_ACC 8
1003#endif
1004
1005
1006/**
1007 * Default registration interval.
1008 */
1009#ifndef PJSUA_REG_INTERVAL
1010# define PJSUA_REG_INTERVAL 55
1011#endif
1012
1013
1014/**
Benny Prijono3a5e1ab2006-08-15 20:26:34 +00001015 * Default PUBLISH expiration
1016 */
1017#ifndef PJSUA_PUBLISH_EXPIRATION
1018# define PJSUA_PUBLISH_EXPIRATION 600
1019#endif
1020
1021
1022/**
Benny Prijono312aff92006-06-17 04:08:30 +00001023 * Account configuration.
1024 */
1025typedef struct pjsua_acc_config
1026{
1027 /**
1028 * The full SIP URL for the account. The value can take name address or
1029 * URL format, and will look something like "sip:account@serviceprovider".
1030 *
1031 * This field is mandatory.
1032 */
1033 pj_str_t id;
1034
1035 /**
1036 * This is the URL to be put in the request URI for the registration,
1037 * and will look something like "sip:serviceprovider".
1038 *
1039 * This field should be specified if registration is desired. If the
1040 * value is empty, no account registration will be performed.
1041 */
1042 pj_str_t reg_uri;
1043
Benny Prijono3a5e1ab2006-08-15 20:26:34 +00001044 /**
1045 * Publish presence?
1046 */
1047 pj_bool_t publish_enabled;
1048
Benny Prijono312aff92006-06-17 04:08:30 +00001049 /**
1050 * Optional URI to be put as Contact for this account. It is recommended
1051 * that this field is left empty, so that the value will be calculated
1052 * automatically based on the transport address.
1053 */
Benny Prijonob4a17c92006-07-10 14:40:21 +00001054 pj_str_t force_contact;
Benny Prijono312aff92006-06-17 04:08:30 +00001055
1056 /**
1057 * Number of proxies in the proxy array below.
1058 */
1059 unsigned proxy_cnt;
1060
1061 /**
1062 * Optional URI of the proxies to be visited for all outgoing requests
1063 * that are using this account (REGISTER, INVITE, etc). Application need
1064 * to specify these proxies if the service provider requires that requests
1065 * destined towards its network should go through certain proxies first
1066 * (for example, border controllers).
1067 *
1068 * These proxies will be put in the route set for this account, with
1069 * maintaining the orders (the first proxy in the array will be visited
1070 * first).
1071 */
1072 pj_str_t proxy[PJSUA_ACC_MAX_PROXIES];
1073
1074 /**
1075 * Optional interval for registration, in seconds. If the value is zero,
1076 * default interval will be used (PJSUA_REG_INTERVAL, 55 seconds).
1077 */
1078 unsigned reg_timeout;
1079
1080 /**
1081 * Number of credentials in the credential array.
1082 */
1083 unsigned cred_count;
1084
1085 /**
1086 * Array of credentials. If registration is desired, normally there should
1087 * be at least one credential specified, to successfully authenticate
1088 * against the service provider. More credentials can be specified, for
1089 * example when the requests are expected to be challenged by the
1090 * proxies in the route set.
1091 */
1092 pjsip_cred_info cred_info[PJSUA_ACC_MAX_PROXIES];
1093
1094} pjsua_acc_config;
1095
1096
1097/**
1098 * Call this function to initialize account config with default values.
1099 *
1100 * @param cfg The account config to be initialized.
1101 */
1102PJ_INLINE(void) pjsua_acc_config_default(pjsua_acc_config *cfg)
1103{
Benny Prijonoac623b32006-07-03 15:19:31 +00001104 pj_bzero(cfg, sizeof(*cfg));
Benny Prijono312aff92006-06-17 04:08:30 +00001105
1106 cfg->reg_timeout = PJSUA_REG_INTERVAL;
1107}
1108
1109
1110
1111/**
1112 * Account info. Application can query account info by calling
1113 * #pjsua_acc_get_info().
1114 */
1115typedef struct pjsua_acc_info
1116{
1117 /**
1118 * The account ID.
1119 */
1120 pjsua_acc_id id;
1121
1122 /**
1123 * Flag to indicate whether this is the default account.
1124 */
1125 pj_bool_t is_default;
1126
1127 /**
1128 * Account URI
1129 */
1130 pj_str_t acc_uri;
1131
1132 /**
1133 * Flag to tell whether this account has registration setting
1134 * (reg_uri is not empty).
1135 */
1136 pj_bool_t has_registration;
1137
1138 /**
1139 * An up to date expiration interval for account registration session.
1140 */
1141 int expires;
1142
1143 /**
1144 * Last registration status code. If status code is zero, the account
1145 * is currently not registered. Any other value indicates the SIP
1146 * status code of the registration.
1147 */
1148 pjsip_status_code status;
1149
1150 /**
1151 * String describing the registration status.
1152 */
1153 pj_str_t status_text;
1154
1155 /**
1156 * Presence online status for this account.
1157 */
1158 pj_bool_t online_status;
1159
1160 /**
1161 * Buffer that is used internally to store the status text.
1162 */
1163 char buf_[PJ_ERR_MSG_SIZE];
1164
1165} pjsua_acc_info;
1166
1167
1168
1169/**
1170 * Get number of current accounts.
1171 *
1172 * @return Current number of accounts.
1173 */
1174PJ_DECL(unsigned) pjsua_acc_get_count(void);
1175
1176
1177/**
1178 * Check if the specified account ID is valid.
1179 *
1180 * @param acc_id Account ID to check.
1181 *
1182 * @return Non-zero if account ID is valid.
1183 */
1184PJ_DECL(pj_bool_t) pjsua_acc_is_valid(pjsua_acc_id acc_id);
1185
1186
1187/**
Benny Prijono21b9ad92006-08-15 13:11:22 +00001188 * Set default account to be used when incoming and outgoing
1189 * requests doesn't match any accounts.
1190 *
1191 * @param acc_id The account ID to be used as default.
1192 *
1193 * @return PJ_SUCCESS on success.
1194 */
1195PJ_DECL(pj_status_t) pjsua_acc_set_default(pjsua_acc_id acc_id);
1196
1197
1198/**
1199 * Get default account.
1200 *
1201 * @return The default account ID, or PJSUA_INVALID_ID if no
1202 * default account is configured.
1203 */
1204PJ_DECL(pjsua_acc_id) pjsua_acc_get_default(void);
1205
1206
1207/**
Benny Prijono312aff92006-06-17 04:08:30 +00001208 * Add a new account to pjsua. PJSUA must have been initialized (with
1209 * #pjsua_init()) before calling this function.
1210 *
1211 * @param cfg Account configuration.
1212 * @param is_default If non-zero, this account will be set as the default
1213 * account. The default account will be used when sending
1214 * outgoing requests (e.g. making call) when no account is
1215 * specified, and when receiving incoming requests when the
1216 * request does not match any accounts. It is recommended
1217 * that default account is set to local/LAN account.
1218 * @param p_acc_id Pointer to receive account ID of the new account.
1219 *
1220 * @return PJ_SUCCESS on success, or the appropriate error code.
1221 */
1222PJ_DECL(pj_status_t) pjsua_acc_add(const pjsua_acc_config *cfg,
1223 pj_bool_t is_default,
1224 pjsua_acc_id *p_acc_id);
1225
1226
1227/**
1228 * Add a local account. A local account is used to identify local endpoint
1229 * instead of a specific user, and for this reason, a transport ID is needed
1230 * to obtain the local address information.
1231 *
1232 * @param tid Transport ID to generate account address.
1233 * @param is_default If non-zero, this account will be set as the default
1234 * account. The default account will be used when sending
1235 * outgoing requests (e.g. making call) when no account is
1236 * specified, and when receiving incoming requests when the
1237 * request does not match any accounts. It is recommended
1238 * that default account is set to local/LAN account.
1239 * @param p_acc_id Pointer to receive account ID of the new account.
1240 *
1241 * @return PJ_SUCCESS on success, or the appropriate error code.
1242 */
1243PJ_DECL(pj_status_t) pjsua_acc_add_local(pjsua_transport_id tid,
1244 pj_bool_t is_default,
1245 pjsua_acc_id *p_acc_id);
1246
1247/**
1248 * Delete account.
1249 *
1250 * @param acc_id Id of the account to be deleted.
1251 *
1252 * @return PJ_SUCCESS on success, or the appropriate error code.
1253 */
1254PJ_DECL(pj_status_t) pjsua_acc_del(pjsua_acc_id acc_id);
1255
1256
1257/**
1258 * Modify account information.
1259 *
1260 * @param acc_id Id of the account to be modified.
1261 * @param cfg New account configuration.
1262 *
1263 * @return PJ_SUCCESS on success, or the appropriate error code.
1264 */
1265PJ_DECL(pj_status_t) pjsua_acc_modify(pjsua_acc_id acc_id,
1266 const pjsua_acc_config *cfg);
1267
1268
1269/**
1270 * Modify account's presence status to be advertised to remote/presence
1271 * subscribers.
1272 *
1273 * @param acc_id The account ID.
1274 * @param is_online True of false.
1275 *
1276 * @return PJ_SUCCESS on success, or the appropriate error code.
1277 */
1278PJ_DECL(pj_status_t) pjsua_acc_set_online_status(pjsua_acc_id acc_id,
1279 pj_bool_t is_online);
1280
1281
1282/**
1283 * Update registration or perform unregistration.
1284 *
1285 * @param acc_id The account ID.
1286 * @param renew If renew argument is zero, this will start
1287 * unregistration process.
1288 *
1289 * @return PJ_SUCCESS on success, or the appropriate error code.
1290 */
1291PJ_DECL(pj_status_t) pjsua_acc_set_registration(pjsua_acc_id acc_id,
1292 pj_bool_t renew);
1293
1294
1295/**
1296 * Get account information.
1297 *
1298 * @param acc_id Account identification.
1299 * @param info Pointer to receive account information.
1300 *
1301 * @return PJ_SUCCESS on success, or the appropriate error code.
1302 */
1303PJ_DECL(pj_status_t) pjsua_acc_get_info(pjsua_acc_id acc_id,
1304 pjsua_acc_info *info);
1305
1306
1307/**
1308 * Enum accounts all account ids.
1309 *
1310 * @param ids Array of account IDs to be initialized.
1311 * @param count In input, specifies the maximum number of elements.
1312 * On return, it contains the actual number of elements.
1313 *
1314 * @return PJ_SUCCESS on success, or the appropriate error code.
1315 */
1316PJ_DECL(pj_status_t) pjsua_enum_accs(pjsua_acc_id ids[],
1317 unsigned *count );
1318
1319
1320/**
1321 * Enum accounts info.
1322 *
1323 * @param info Array of account infos to be initialized.
1324 * @param count In input, specifies the maximum number of elements.
1325 * On return, it contains the actual number of elements.
1326 *
1327 * @return PJ_SUCCESS on success, or the appropriate error code.
1328 */
1329PJ_DECL(pj_status_t) pjsua_acc_enum_info( pjsua_acc_info info[],
1330 unsigned *count );
1331
1332
1333/**
1334 * This is an internal function to find the most appropriate account to
1335 * used to reach to the specified URL.
1336 *
1337 * @param url The remote URL to reach.
1338 *
1339 * @return Account id.
1340 */
1341PJ_DECL(pjsua_acc_id) pjsua_acc_find_for_outgoing(const pj_str_t *url);
1342
1343
1344/**
1345 * This is an internal function to find the most appropriate account to be
1346 * used to handle incoming calls.
1347 *
1348 * @param rdata The incoming request message.
1349 *
1350 * @return Account id.
1351 */
1352PJ_DECL(pjsua_acc_id) pjsua_acc_find_for_incoming(pjsip_rx_data *rdata);
1353
1354
Benny Prijonoc570f2d2006-07-18 00:33:02 +00001355/**
1356 * Create a suitable URI to be put as Contact based on the specified
1357 * target URI for the specified account.
1358 *
1359 * @param pool Pool to allocate memory for the string.
1360 * @param contact The string where the Contact URI will be stored.
1361 * @param acc_id Account ID.
1362 * @param uri Destination URI of the request.
1363 *
1364 * @return PJ_SUCCESS on success, other on error.
1365 */
1366PJ_DECL(pj_status_t) pjsua_acc_create_uac_contact( pj_pool_t *pool,
1367 pj_str_t *contact,
1368 pjsua_acc_id acc_id,
1369 const pj_str_t *uri);
1370
1371
1372
1373/**
1374 * Create a suitable URI to be put as Contact based on the information
1375 * in the incoming request.
1376 *
1377 * @param pool Pool to allocate memory for the string.
1378 * @param contact The string where the Contact URI will be stored.
1379 * @param acc_id Account ID.
1380 * @param rdata Incoming request.
1381 *
1382 * @return PJ_SUCCESS on success, other on error.
1383 */
1384PJ_DECL(pj_status_t) pjsua_acc_create_uas_contact( pj_pool_t *pool,
1385 pj_str_t *contact,
1386 pjsua_acc_id acc_id,
1387 pjsip_rx_data *rdata );
1388
1389
Benny Prijono312aff92006-06-17 04:08:30 +00001390
1391/**
1392 * @}
1393 */
1394
1395
1396/*****************************************************************************
1397 * CALLS API
1398 */
1399
1400
1401/**
1402 * @defgroup PJSUA_LIB_CALL Calls
1403 * @ingroup PJSUA_LIB
1404 * @brief Call manipulation.
1405 * @{
1406 */
1407
1408/**
1409 * Max simultaneous calls.
1410 */
1411#ifndef PJSUA_MAX_CALLS
1412# define PJSUA_MAX_CALLS 32
1413#endif
1414
1415
1416
1417/**
1418 * Call media status.
1419 */
1420typedef enum pjsua_call_media_status
1421{
1422 PJSUA_CALL_MEDIA_NONE,
1423 PJSUA_CALL_MEDIA_ACTIVE,
1424 PJSUA_CALL_MEDIA_LOCAL_HOLD,
1425 PJSUA_CALL_MEDIA_REMOTE_HOLD,
1426} pjsua_call_media_status;
1427
1428
1429/**
1430 * Call info.
1431 */
1432typedef struct pjsua_call_info
1433{
1434 /** Call identification. */
1435 pjsua_call_id id;
1436
1437 /** Initial call role (UAC == caller) */
1438 pjsip_role_e role;
1439
Benny Prijono90315512006-09-14 16:05:16 +00001440 /** The account ID where this call belongs. */
1441 pjsua_acc_id acc_id;
1442
Benny Prijono312aff92006-06-17 04:08:30 +00001443 /** Local URI */
1444 pj_str_t local_info;
1445
1446 /** Local Contact */
1447 pj_str_t local_contact;
1448
1449 /** Remote URI */
1450 pj_str_t remote_info;
1451
1452 /** Remote contact */
1453 pj_str_t remote_contact;
1454
1455 /** Dialog Call-ID string. */
1456 pj_str_t call_id;
1457
1458 /** Call state */
1459 pjsip_inv_state state;
1460
1461 /** Text describing the state */
1462 pj_str_t state_text;
1463
1464 /** Last status code heard, which can be used as cause code */
1465 pjsip_status_code last_status;
1466
1467 /** The reason phrase describing the status. */
1468 pj_str_t last_status_text;
1469
1470 /** Call media status. */
1471 pjsua_call_media_status media_status;
1472
1473 /** Media direction */
1474 pjmedia_dir media_dir;
1475
1476 /** The conference port number for the call */
1477 pjsua_conf_port_id conf_slot;
1478
1479 /** Up-to-date call connected duration (zero when call is not
1480 * established)
1481 */
1482 pj_time_val connect_duration;
1483
1484 /** Total call duration, including set-up time */
1485 pj_time_val total_duration;
1486
1487 /** Internal */
1488 struct {
1489 char local_info[128];
1490 char local_contact[128];
1491 char remote_info[128];
1492 char remote_contact[128];
1493 char call_id[128];
1494 char last_status_text[128];
1495 } buf_;
1496
1497} pjsua_call_info;
1498
1499
1500
Benny Prijonoa91a0032006-02-26 21:23:45 +00001501/**
Benny Prijono9fc735d2006-05-28 14:58:12 +00001502 * Get maximum number of calls configured in pjsua.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001503 *
1504 * @return Maximum number of calls configured.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001505 */
Benny Prijono8b1889b2006-06-06 18:40:40 +00001506PJ_DECL(unsigned) pjsua_call_get_max_count(void);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001507
1508/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001509 * Get number of currently active calls.
1510 *
1511 * @return Number of currently active calls.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001512 */
Benny Prijono8b1889b2006-06-06 18:40:40 +00001513PJ_DECL(unsigned) pjsua_call_get_count(void);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001514
1515/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001516 * Enumerate all active calls.
1517 *
1518 * @param ids Array of account IDs to be initialized.
1519 * @param count In input, specifies the maximum number of elements.
1520 * On return, it contains the actual number of elements.
1521 *
1522 * @return PJ_SUCCESS on success, or the appropriate error code.
1523 */
1524PJ_DECL(pj_status_t) pjsua_enum_calls(pjsua_call_id ids[],
1525 unsigned *count);
1526
1527
1528/**
1529 * Make outgoing call to the specified URI using the specified account.
1530 *
1531 * @param acc_id The account to be used.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001532 * @param dst_uri URI to be put in the To header (normally is the same
1533 * as the target URI).
1534 * @param options Options (must be zero at the moment).
1535 * @param user_data Arbitrary user data to be attached to the call, and
1536 * can be retrieved later.
1537 * @param msg_data Optional headers etc to be added to outgoing INVITE
1538 * request, or NULL if no custom header is desired.
1539 * @param p_call_id Pointer to receive call identification.
1540 *
1541 * @return PJ_SUCCESS on success, or the appropriate error code.
1542 */
1543PJ_DECL(pj_status_t) pjsua_call_make_call(pjsua_acc_id acc_id,
1544 const pj_str_t *dst_uri,
1545 unsigned options,
1546 void *user_data,
1547 const pjsua_msg_data *msg_data,
1548 pjsua_call_id *p_call_id);
1549
1550
1551/**
Benny Prijono9fc735d2006-05-28 14:58:12 +00001552 * Check if the specified call has active INVITE session and the INVITE
1553 * session has not been disconnected.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001554 *
1555 * @param call_id Call identification.
1556 *
1557 * @return Non-zero if call is active.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001558 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001559PJ_DECL(pj_bool_t) pjsua_call_is_active(pjsua_call_id call_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001560
1561
1562/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001563 * Check if call has an active media session.
1564 *
1565 * @param call_id Call identification.
1566 *
1567 * @return Non-zero if yes.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001568 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001569PJ_DECL(pj_bool_t) pjsua_call_has_media(pjsua_call_id call_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001570
1571
1572/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001573 * Get the conference port identification associated with the call.
1574 *
1575 * @param call_id Call identification.
1576 *
1577 * @return Conference port ID, or PJSUA_INVALID_ID when the
1578 * media has not been established or is not active.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001579 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001580PJ_DECL(pjsua_conf_port_id) pjsua_call_get_conf_port(pjsua_call_id call_id);
1581
1582/**
1583 * Obtain detail information about the specified call.
1584 *
1585 * @param call_id Call identification.
1586 * @param info Call info to be initialized.
1587 *
1588 * @return PJ_SUCCESS on success, or the appropriate error code.
1589 */
1590PJ_DECL(pj_status_t) pjsua_call_get_info(pjsua_call_id call_id,
Benny Prijono9fc735d2006-05-28 14:58:12 +00001591 pjsua_call_info *info);
1592
1593
1594/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001595 * Attach application specific data to the call.
1596 *
1597 * @param call_id Call identification.
1598 * @param user_data Arbitrary data to be attached to the call.
1599 *
1600 * @return The user data.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001601 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001602PJ_DECL(pj_status_t) pjsua_call_set_user_data(pjsua_call_id call_id,
1603 void *user_data);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001604
1605
1606/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001607 * Get user data attached to the call.
1608 *
1609 * @param call_id Call identification.
1610 *
1611 * @return The user data.
Benny Prijono268ca612006-02-07 12:34:11 +00001612 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001613PJ_DECL(void*) pjsua_call_get_user_data(pjsua_call_id call_id);
Benny Prijono84126ab2006-02-09 09:30:09 +00001614
1615
1616/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001617 * Send response to incoming INVITE request.
1618 *
1619 * @param call_id Incoming call identification.
1620 * @param code Status code, (100-699).
1621 * @param reason Optional reason phrase. If NULL, default text
1622 * will be used.
1623 * @param msg_data Optional list of headers etc to be added to outgoing
1624 * response message.
1625 *
1626 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonoa91a0032006-02-26 21:23:45 +00001627 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001628PJ_DECL(pj_status_t) pjsua_call_answer(pjsua_call_id call_id,
1629 unsigned code,
1630 const pj_str_t *reason,
1631 const pjsua_msg_data *msg_data);
Benny Prijonoa91a0032006-02-26 21:23:45 +00001632
1633/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001634 * Hangup call by using method that is appropriate according to the
1635 * call state.
1636 *
1637 * @param call_id Call identification.
1638 * @param code Optional status code to be sent when we're rejecting
1639 * incoming call. If the value is zero, "603/Decline"
1640 * will be sent.
1641 * @param reason Optional reason phrase to be sent when we're rejecting
1642 * incoming call. If NULL, default text will be used.
1643 * @param msg_data Optional list of headers etc to be added to outgoing
1644 * request/response message.
1645 *
1646 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono26ff9062006-02-21 23:47:00 +00001647 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001648PJ_DECL(pj_status_t) pjsua_call_hangup(pjsua_call_id call_id,
1649 unsigned code,
1650 const pj_str_t *reason,
1651 const pjsua_msg_data *msg_data);
Benny Prijono26ff9062006-02-21 23:47:00 +00001652
1653
1654/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001655 * Put the specified call on hold.
1656 *
1657 * @param call_id Call identification.
1658 * @param msg_data Optional message components to be sent with
1659 * the request.
1660 *
1661 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono26ff9062006-02-21 23:47:00 +00001662 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001663PJ_DECL(pj_status_t) pjsua_call_set_hold(pjsua_call_id call_id,
1664 const pjsua_msg_data *msg_data);
Benny Prijono26ff9062006-02-21 23:47:00 +00001665
1666
1667/**
1668 * Send re-INVITE (to release hold).
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001669 *
1670 * @param call_id Call identification.
1671 * @param unhold If this argument is non-zero and the call is locally
1672 * held, this will release the local hold.
1673 * @param msg_data Optional message components to be sent with
1674 * the request.
1675 *
1676 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono26ff9062006-02-21 23:47:00 +00001677 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001678PJ_DECL(pj_status_t) pjsua_call_reinvite(pjsua_call_id call_id,
1679 pj_bool_t unhold,
1680 const pjsua_msg_data *msg_data);
Benny Prijono26ff9062006-02-21 23:47:00 +00001681
1682
1683/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001684 * Initiate call transfer to the specified address.
1685 *
1686 * @param call_id Call identification.
1687 * @param dest Address of new target to be contacted.
1688 * @param msg_data Optional message components to be sent with
1689 * the request.
1690 *
1691 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono26ff9062006-02-21 23:47:00 +00001692 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001693PJ_DECL(pj_status_t) pjsua_call_xfer(pjsua_call_id call_id,
1694 const pj_str_t *dest,
1695 const pjsua_msg_data *msg_data);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001696
1697/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001698 * Send DTMF digits to remote using RFC 2833 payload formats.
1699 *
1700 * @param call_id Call identification.
1701 * @param digits DTMF digits to be sent.
1702 *
1703 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001704 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001705PJ_DECL(pj_status_t) pjsua_call_dial_dtmf(pjsua_call_id call_id,
Benny Prijono9fc735d2006-05-28 14:58:12 +00001706 const pj_str_t *digits);
Benny Prijono26ff9062006-02-21 23:47:00 +00001707
Benny Prijono26ff9062006-02-21 23:47:00 +00001708/**
Benny Prijonob0808372006-03-02 21:18:58 +00001709 * Send instant messaging inside INVITE session.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001710 *
1711 * @param call_id Call identification.
1712 * @param mime_type Optional MIME type. If NULL, then "text/plain" is
1713 * assumed.
1714 * @param content The message content.
1715 * @param msg_data Optional list of headers etc to be included in outgoing
1716 * request. The body descriptor in the msg_data is
1717 * ignored.
1718 * @param user_data Optional user data, which will be given back when
1719 * the IM callback is called.
1720 *
1721 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonob0808372006-03-02 21:18:58 +00001722 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001723PJ_DECL(pj_status_t) pjsua_call_send_im( pjsua_call_id call_id,
1724 const pj_str_t *mime_type,
1725 const pj_str_t *content,
1726 const pjsua_msg_data *msg_data,
1727 void *user_data);
Benny Prijonob0808372006-03-02 21:18:58 +00001728
1729
1730/**
1731 * Send IM typing indication inside INVITE session.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001732 *
1733 * @param call_id Call identification.
1734 * @param is_typing Non-zero to indicate to remote that local person is
1735 * currently typing an IM.
1736 * @param msg_data Optional list of headers etc to be included in outgoing
1737 * request.
1738 *
1739 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonob0808372006-03-02 21:18:58 +00001740 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001741PJ_DECL(pj_status_t) pjsua_call_send_typing_ind(pjsua_call_id call_id,
1742 pj_bool_t is_typing,
1743 const pjsua_msg_data*msg_data);
Benny Prijonob0808372006-03-02 21:18:58 +00001744
1745/**
Benny Prijono834aee32006-02-19 01:38:06 +00001746 * Terminate all calls.
1747 */
Benny Prijonodc39fe82006-05-26 12:17:46 +00001748PJ_DECL(void) pjsua_call_hangup_all(void);
Benny Prijono834aee32006-02-19 01:38:06 +00001749
1750
Benny Prijonob9b32ab2006-06-01 12:28:44 +00001751/**
1752 * Dump call and media statistics to string.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001753 *
1754 * @param call_id Call identification.
1755 * @param with_media Non-zero to include media information too.
1756 * @param buffer Buffer where the statistics are to be written to.
1757 * @param maxlen Maximum length of buffer.
1758 * @param indent Spaces for left indentation.
1759 *
1760 * @return PJ_SUCCESS on success.
Benny Prijonob9b32ab2006-06-01 12:28:44 +00001761 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001762PJ_DECL(pj_status_t) pjsua_call_dump(pjsua_call_id call_id,
1763 pj_bool_t with_media,
1764 char *buffer,
1765 unsigned maxlen,
1766 const char *indent);
Benny Prijonob9b32ab2006-06-01 12:28:44 +00001767
Benny Prijono9fc735d2006-05-28 14:58:12 +00001768/**
Benny Prijono312aff92006-06-17 04:08:30 +00001769 * @}
Benny Prijono9fc735d2006-05-28 14:58:12 +00001770 */
Benny Prijono834aee32006-02-19 01:38:06 +00001771
1772
1773/*****************************************************************************
Benny Prijono312aff92006-06-17 04:08:30 +00001774 * BUDDY API
Benny Prijono834aee32006-02-19 01:38:06 +00001775 */
1776
Benny Prijono312aff92006-06-17 04:08:30 +00001777
1778/**
1779 * @defgroup PJSUA_LIB_BUDDY Buddy, Presence, and Instant Messaging
1780 * @ingroup PJSUA_LIB
1781 * @brief Buddy management, buddy's presence, and instant messaging.
1782 * @{
1783 */
1784
1785/**
1786 * Max buddies in buddy list.
1787 */
1788#ifndef PJSUA_MAX_BUDDIES
1789# define PJSUA_MAX_BUDDIES 256
1790#endif
1791
1792
1793/**
1794 * Buddy configuration.
1795 */
1796typedef struct pjsua_buddy_config
1797{
1798 /**
1799 * Buddy URL or name address.
1800 */
1801 pj_str_t uri;
1802
1803 /**
1804 * Specify whether presence subscription should start immediately.
1805 */
1806 pj_bool_t subscribe;
1807
1808} pjsua_buddy_config;
1809
1810
1811/**
1812 * Buddy's online status.
1813 */
1814typedef enum pjsua_buddy_status
1815{
1816 /**
1817 * Online status is unknown (possibly because no presence subscription
1818 * has been established).
1819 */
1820 PJSUA_BUDDY_STATUS_UNKNOWN,
1821
1822 /**
1823 * Buddy is known to be offline.
1824 */
1825 PJSUA_BUDDY_STATUS_ONLINE,
1826
1827 /**
1828 * Buddy is offline.
1829 */
1830 PJSUA_BUDDY_STATUS_OFFLINE,
1831
1832} pjsua_buddy_status;
1833
1834
1835
1836/**
1837 * Buddy info.
1838 */
1839typedef struct pjsua_buddy_info
1840{
1841 /**
1842 * The buddy ID.
1843 */
1844 pjsua_buddy_id id;
1845
1846 /**
1847 * The full URI of the buddy, as specified in the configuration.
1848 */
1849 pj_str_t uri;
1850
1851 /**
1852 * Buddy's Contact, only available when presence subscription has
1853 * been established to the buddy.
1854 */
1855 pj_str_t contact;
1856
1857 /**
1858 * Buddy's online status.
1859 */
1860 pjsua_buddy_status status;
1861
1862 /**
1863 * Text to describe buddy's online status.
1864 */
1865 pj_str_t status_text;
1866
1867 /**
1868 * Flag to indicate that we should monitor the presence information for
1869 * this buddy (normally yes, unless explicitly disabled).
1870 */
1871 pj_bool_t monitor_pres;
1872
1873 /**
1874 * Internal buffer.
1875 */
1876 char buf_[256];
1877
1878} pjsua_buddy_info;
1879
1880
Benny Prijono834aee32006-02-19 01:38:06 +00001881/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001882 * Get total number of buddies.
1883 *
1884 * @return Number of buddies.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001885 */
1886PJ_DECL(unsigned) pjsua_get_buddy_count(void);
1887
1888
1889/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001890 * Check if buddy ID is valid.
1891 *
1892 * @param buddy_id Buddy ID to check.
1893 *
1894 * @return Non-zero if buddy ID is valid.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001895 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001896PJ_DECL(pj_bool_t) pjsua_buddy_is_valid(pjsua_buddy_id buddy_id);
1897
1898
1899/**
1900 * Enum buddy IDs.
1901 *
1902 * @param ids Array of ids to be initialized.
1903 * @param count On input, specifies max elements in the array.
1904 * On return, it contains actual number of elements
1905 * that have been initialized.
1906 *
1907 * @return PJ_SUCCESS on success, or the appropriate error code.
1908 */
1909PJ_DECL(pj_status_t) pjsua_enum_buddies(pjsua_buddy_id ids[],
1910 unsigned *count);
1911
1912/**
1913 * Get detailed buddy info.
1914 *
1915 * @param buddy_id The buddy identification.
1916 * @param info Pointer to receive information about buddy.
1917 *
1918 * @return PJ_SUCCESS on success, or the appropriate error code.
1919 */
1920PJ_DECL(pj_status_t) pjsua_buddy_get_info(pjsua_buddy_id buddy_id,
Benny Prijono9fc735d2006-05-28 14:58:12 +00001921 pjsua_buddy_info *info);
1922
1923/**
1924 * Add new buddy.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001925 *
1926 * @param cfg Buddy configuration.
1927 * @param p_buddy_id Pointer to receive buddy ID.
1928 *
1929 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001930 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001931PJ_DECL(pj_status_t) pjsua_buddy_add(const pjsua_buddy_config *cfg,
1932 pjsua_buddy_id *p_buddy_id);
Benny Prijono8b1889b2006-06-06 18:40:40 +00001933
1934
1935/**
1936 * Delete buddy.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001937 *
1938 * @param buddy_id Buddy identification.
1939 *
1940 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono8b1889b2006-06-06 18:40:40 +00001941 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001942PJ_DECL(pj_status_t) pjsua_buddy_del(pjsua_buddy_id buddy_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001943
1944
1945/**
1946 * Enable/disable buddy's presence monitoring.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001947 *
1948 * @param buddy_id Buddy identification.
1949 * @param subscribe Specify non-zero to activate presence subscription to
1950 * the specified buddy.
1951 *
1952 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001953 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001954PJ_DECL(pj_status_t) pjsua_buddy_subscribe_pres(pjsua_buddy_id buddy_id,
1955 pj_bool_t subscribe);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001956
1957
1958/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001959 * Dump presence subscriptions to log file.
1960 *
1961 * @param verbose Yes or no.
Benny Prijono834aee32006-02-19 01:38:06 +00001962 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001963PJ_DECL(void) pjsua_pres_dump(pj_bool_t verbose);
Benny Prijono834aee32006-02-19 01:38:06 +00001964
1965
Benny Prijonob0808372006-03-02 21:18:58 +00001966/**
1967 * The MESSAGE method (defined in pjsua_im.c)
1968 */
1969extern const pjsip_method pjsip_message_method;
1970
1971
Benny Prijonob0808372006-03-02 21:18:58 +00001972
1973/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001974 * Send instant messaging outside dialog, using the specified account for
1975 * route set and authentication.
1976 *
1977 * @param acc_id Account ID to be used to send the request.
1978 * @param to Remote URI.
1979 * @param mime_type Optional MIME type. If NULL, then "text/plain" is
1980 * assumed.
1981 * @param content The message content.
1982 * @param msg_data Optional list of headers etc to be included in outgoing
1983 * request. The body descriptor in the msg_data is
1984 * ignored.
1985 * @param user_data Optional user data, which will be given back when
1986 * the IM callback is called.
1987 *
1988 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonob0808372006-03-02 21:18:58 +00001989 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001990PJ_DECL(pj_status_t) pjsua_im_send(pjsua_acc_id acc_id,
1991 const pj_str_t *to,
1992 const pj_str_t *mime_type,
1993 const pj_str_t *content,
1994 const pjsua_msg_data *msg_data,
1995 void *user_data);
Benny Prijonob0808372006-03-02 21:18:58 +00001996
1997
1998/**
1999 * Send typing indication outside dialog.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002000 *
2001 * @param acc_id Account ID to be used to send the request.
2002 * @param to Remote URI.
2003 * @param is_typing If non-zero, it tells remote person that local person
2004 * is currently composing an IM.
2005 * @param msg_data Optional list of headers etc to be added to outgoing
2006 * request.
2007 *
2008 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonob0808372006-03-02 21:18:58 +00002009 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002010PJ_DECL(pj_status_t) pjsua_im_typing(pjsua_acc_id acc_id,
2011 const pj_str_t *to,
2012 pj_bool_t is_typing,
2013 const pjsua_msg_data *msg_data);
Benny Prijonob0808372006-03-02 21:18:58 +00002014
2015
Benny Prijonof3195072006-02-14 21:15:30 +00002016
Benny Prijono312aff92006-06-17 04:08:30 +00002017/**
2018 * @}
Benny Prijono9fc735d2006-05-28 14:58:12 +00002019 */
2020
Benny Prijono312aff92006-06-17 04:08:30 +00002021
2022/*****************************************************************************
2023 * MEDIA API
2024 */
2025
2026
2027/**
2028 * @defgroup PJSUA_LIB_MEDIA Media
2029 * @ingroup PJSUA_LIB
2030 * @brief Media manipulation.
2031 * @{
2032 *
2033 * PJSUA has rather powerful media features, which are built around the
2034 * PJMEDIA conference bridge. Basically, all media termination (such as
2035 * calls, file players, file recorders, sound device, tone generators, etc)
2036 * are terminated in the conference bridge, and application can manipulate
2037 * the interconnection between these terminations freely. If more than
2038 * one media terminations are terminated in the same slot, the conference
2039 * bridge will mix the signal automatically.
2040 *
2041 * Application connects one media termination/slot to another by calling
2042 * #pjsua_conf_connect() function. This will establish <b>unidirectional</b>
2043 * media flow from the source termination to the sink termination. For
2044 * example, to stream a WAV file to remote call, application may use
2045 * the following steps:
2046 *
2047 \code
2048
2049 pj_status_t stream_to_call( pjsua_call_id call_id )
2050 {
2051 pjsua_player_id player_id;
2052
2053 status = pjsua_player_create("mysong.wav", 0, NULL, &player_id);
2054 if (status != PJ_SUCCESS)
2055 return status;
2056
2057 status = pjsua_conf_connect( pjsua_player_get_conf_port(),
2058 pjsua_call_get_conf_port() );
2059 }
2060 \endcode
2061 *
2062 *
2063 * Other features of PJSUA media:
2064 * - efficient N to M interconnections between media terminations.
2065 * - media termination can be connected to itself to create loopback
2066 * media.
2067 * - the media termination may have different clock rates, and resampling
2068 * will be done automatically by conference bridge.
2069 * - media terminations may also have different frame time; the
2070 * conference bridge will perform the necessary bufferring to adjust
2071 * the difference between terminations.
2072 * - interconnections are removed automatically when media termination
2073 * is removed from the bridge.
2074 * - sound device may be changed even when there are active media
2075 * interconnections.
2076 * - correctly report call's media quality (in #pjsua_call_dump()) from
2077 * RTCP packet exchange.
2078 */
2079
2080/**
2081 * Max ports in the conference bridge.
2082 */
2083#ifndef PJSUA_MAX_CONF_PORTS
2084# define PJSUA_MAX_CONF_PORTS 254
2085#endif
2086
Benny Prijono70972992006-08-05 11:13:58 +00002087#define PJSUA_DEFAULT_CLOCK_RATE 16000
2088#define PJSUA_DEFAULT_CODEC_QUALITY 5
2089#define PJSUA_DEFAULT_ILBC_MODE 20
2090#define PJSUA_DEFAULT_EC_TAIL_LEN 256
Benny Prijono312aff92006-06-17 04:08:30 +00002091
2092
2093/**
2094 * Media configuration.
2095 */
2096struct pjsua_media_config
2097{
2098 /**
2099 * Clock rate to be applied to the conference bridge.
2100 * If value is zero, default clock rate will be used (16KHz).
2101 */
2102 unsigned clock_rate;
2103
2104 /**
2105 * Specify maximum number of media ports to be created in the
2106 * conference bridge. Since all media terminate in the bridge
2107 * (calls, file player, file recorder, etc), the value must be
2108 * large enough to support all of them. However, the larger
2109 * the value, the more computations are performed.
2110 */
2111 unsigned max_media_ports;
2112
2113 /**
2114 * Specify whether the media manager should manage its own
2115 * ioqueue for the RTP/RTCP sockets. If yes, ioqueue will be created
2116 * and at least one worker thread will be created too. If no,
2117 * the RTP/RTCP sockets will share the same ioqueue as SIP sockets,
2118 * and no worker thread is needed.
2119 *
2120 * Normally application would say yes here, unless it wants to
2121 * run everything from a single thread.
2122 */
2123 pj_bool_t has_ioqueue;
2124
2125 /**
2126 * Specify the number of worker threads to handle incoming RTP
2127 * packets. A value of one is recommended for most applications.
2128 */
2129 unsigned thread_cnt;
2130
Benny Prijono0498d902006-06-19 14:49:14 +00002131 /**
2132 * Media quality, 0-10, according to this table:
Benny Prijono7ca96da2006-08-07 12:11:40 +00002133 * 5-10: resampling use large filter,
2134 * 3-4: resampling use small filter,
Benny Prijono0498d902006-06-19 14:49:14 +00002135 * 1-2: resampling use linear.
2136 * The media quality also sets speex codec quality/complexity to the
2137 * number.
2138 *
Benny Prijono70972992006-08-05 11:13:58 +00002139 * Default: 5 (PJSUA_DEFAULT_CODEC_QUALITY).
Benny Prijono0498d902006-06-19 14:49:14 +00002140 */
2141 unsigned quality;
Benny Prijono0a12f002006-07-26 17:05:39 +00002142
2143 /**
2144 * Specify default ptime.
2145 *
2146 * Default: 0 (codec specific)
2147 */
2148 unsigned ptime;
2149
2150 /**
2151 * Disable VAD?
2152 *
2153 * Default: 0 (no (meaning VAD is enabled))
2154 */
2155 pj_bool_t no_vad;
Benny Prijono00cae612006-07-31 15:19:36 +00002156
2157 /**
2158 * iLBC mode (20 or 30).
2159 *
Benny Prijono70972992006-08-05 11:13:58 +00002160 * Default: 20 (PJSUA_DEFAULT_ILBC_MODE)
Benny Prijono00cae612006-07-31 15:19:36 +00002161 */
2162 unsigned ilbc_mode;
2163
2164 /**
2165 * Percentage of RTP packet to drop in TX direction
2166 * (to simulate packet lost).
2167 *
2168 * Default: 0
2169 */
2170 unsigned tx_drop_pct;
2171
2172 /**
2173 * Percentage of RTP packet to drop in RX direction
2174 * (to simulate packet lost).
2175 *
2176 * Default: 0
2177 */
2178 unsigned rx_drop_pct;
2179
Benny Prijonoc8e24a12006-08-02 18:22:22 +00002180 /**
Benny Prijono5da50432006-08-07 10:24:52 +00002181 * Echo canceller options (see #pjmedia_echo_create())
2182 *
2183 * Default: 0.
2184 */
2185 unsigned ec_options;
2186
2187 /**
Benny Prijonoc8e24a12006-08-02 18:22:22 +00002188 * Echo canceller tail length, in miliseconds.
2189 *
Benny Prijono669643c2006-09-20 20:02:18 +00002190 * Default: PJSUA_DEFAULT_EC_TAIL_LEN
Benny Prijonoc8e24a12006-08-02 18:22:22 +00002191 */
2192 unsigned ec_tail_len;
Benny Prijono312aff92006-06-17 04:08:30 +00002193};
2194
2195
2196/**
2197 * Use this function to initialize media config.
2198 *
2199 * @param cfg The media config to be initialized.
2200 */
2201PJ_INLINE(void) pjsua_media_config_default(pjsua_media_config *cfg)
2202{
Benny Prijonoac623b32006-07-03 15:19:31 +00002203 pj_bzero(cfg, sizeof(*cfg));
Benny Prijono312aff92006-06-17 04:08:30 +00002204
Benny Prijono70972992006-08-05 11:13:58 +00002205 cfg->clock_rate = PJSUA_DEFAULT_CLOCK_RATE;
Benny Prijono312aff92006-06-17 04:08:30 +00002206 cfg->max_media_ports = 32;
2207 cfg->has_ioqueue = PJ_TRUE;
2208 cfg->thread_cnt = 1;
Benny Prijono70972992006-08-05 11:13:58 +00002209 cfg->quality = PJSUA_DEFAULT_CODEC_QUALITY;
2210 cfg->ilbc_mode = PJSUA_DEFAULT_ILBC_MODE;
2211 cfg->ec_tail_len = PJSUA_DEFAULT_EC_TAIL_LEN;
Benny Prijono312aff92006-06-17 04:08:30 +00002212}
2213
2214
2215
2216/**
2217 * Codec config.
2218 */
2219typedef struct pjsua_codec_info
2220{
2221 /**
2222 * Codec unique identification.
2223 */
2224 pj_str_t codec_id;
2225
2226 /**
2227 * Codec priority (integer 0-255).
2228 */
2229 pj_uint8_t priority;
2230
2231 /**
2232 * Internal buffer.
2233 */
2234 char buf_[32];
2235
2236} pjsua_codec_info;
2237
2238
2239/**
2240 * Conference port info.
2241 */
2242typedef struct pjsua_conf_port_info
2243{
2244 /** Conference port number. */
2245 pjsua_conf_port_id slot_id;
2246
2247 /** Port name. */
2248 pj_str_t name;
2249
2250 /** Clock rate. */
2251 unsigned clock_rate;
2252
2253 /** Number of channels. */
2254 unsigned channel_count;
2255
2256 /** Samples per frame */
2257 unsigned samples_per_frame;
2258
2259 /** Bits per sample */
2260 unsigned bits_per_sample;
2261
2262 /** Number of listeners in the array. */
2263 unsigned listener_cnt;
2264
2265 /** Array of listeners (in other words, ports where this port is
2266 * transmitting to.
2267 */
2268 pjsua_conf_port_id listeners[PJSUA_MAX_CONF_PORTS];
2269
2270} pjsua_conf_port_info;
2271
2272
2273/**
2274 * This structure holds information about custom media transport to
2275 * be registered to pjsua.
2276 */
2277typedef struct pjsua_media_transport
2278{
2279 /**
2280 * Media socket information containing the address information
2281 * of the RTP and RTCP socket.
2282 */
2283 pjmedia_sock_info skinfo;
2284
2285 /**
2286 * The media transport instance.
2287 */
2288 pjmedia_transport *transport;
2289
2290} pjsua_media_transport;
2291
2292
2293
2294
Benny Prijono9fc735d2006-05-28 14:58:12 +00002295/**
2296 * Get maxinum number of conference ports.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002297 *
2298 * @return Maximum number of ports in the conference bridge.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002299 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002300PJ_DECL(unsigned) pjsua_conf_get_max_ports(void);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002301
2302
2303/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002304 * Get current number of active ports in the bridge.
2305 *
2306 * @return The number.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002307 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002308PJ_DECL(unsigned) pjsua_conf_get_active_ports(void);
2309
2310
2311/**
2312 * Enumerate all conference ports.
2313 *
2314 * @param id Array of conference port ID to be initialized.
2315 * @param count On input, specifies max elements in the array.
2316 * On return, it contains actual number of elements
2317 * that have been initialized.
2318 *
2319 * @return PJ_SUCCESS on success, or the appropriate error code.
2320 */
2321PJ_DECL(pj_status_t) pjsua_enum_conf_ports(pjsua_conf_port_id id[],
2322 unsigned *count);
Benny Prijono8b1889b2006-06-06 18:40:40 +00002323
2324
2325/**
2326 * Get information about the specified conference port
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002327 *
2328 * @param id Port identification.
2329 * @param info Pointer to store the port info.
2330 *
2331 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono8b1889b2006-06-06 18:40:40 +00002332 */
2333PJ_DECL(pj_status_t) pjsua_conf_get_port_info( pjsua_conf_port_id id,
2334 pjsua_conf_port_info *info);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002335
2336
2337/**
Benny Prijonoe909eac2006-07-27 22:04:56 +00002338 * Add arbitrary media port to PJSUA's conference bridge. Application
2339 * can use this function to add the media port that it creates. For
2340 * media ports that are created by PJSUA-LIB (such as calls, file player,
2341 * or file recorder), PJSUA-LIB will automatically add the port to
2342 * the bridge.
2343 *
2344 * @param pool Pool to use.
2345 * @param port Media port to be added to the bridge.
2346 * @param p_id Optional pointer to receive the conference
2347 * slot id.
2348 *
2349 * @return PJ_SUCCESS on success, or the appropriate error code.
2350 */
2351PJ_DECL(pj_status_t) pjsua_conf_add_port(pj_pool_t *pool,
2352 pjmedia_port *port,
2353 pjsua_conf_port_id *p_id);
2354
2355
2356/**
2357 * Remove arbitrary slot from the conference bridge. Application should only
2358 * call this function if it registered the port manually.
2359 *
2360 * @param id The slot id of the port to be removed.
2361 *
2362 * @return PJ_SUCCESS on success, or the appropriate error code.
2363 */
2364PJ_DECL(pj_status_t) pjsua_conf_remove_port(pjsua_conf_port_id id);
2365
2366
2367/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002368 * Establish unidirectional media flow from souce to sink. One source
2369 * may transmit to multiple destinations/sink. And if multiple
2370 * sources are transmitting to the same sink, the media will be mixed
2371 * together. Source and sink may refer to the same ID, effectively
2372 * looping the media.
2373 *
2374 * If bidirectional media flow is desired, application needs to call
2375 * this function twice, with the second one having the arguments
2376 * reversed.
2377 *
2378 * @param source Port ID of the source media/transmitter.
2379 * @param sink Port ID of the destination media/received.
2380 *
2381 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002382 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002383PJ_DECL(pj_status_t) pjsua_conf_connect(pjsua_conf_port_id source,
2384 pjsua_conf_port_id sink);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002385
2386
2387/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002388 * Disconnect media flow from the source to destination port.
2389 *
2390 * @param source Port ID of the source media/transmitter.
2391 * @param sink Port ID of the destination media/received.
2392 *
2393 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002394 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002395PJ_DECL(pj_status_t) pjsua_conf_disconnect(pjsua_conf_port_id source,
2396 pjsua_conf_port_id sink);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002397
2398
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002399/*****************************************************************************
2400 * File player.
2401 */
2402
Benny Prijono9fc735d2006-05-28 14:58:12 +00002403/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002404 * Create a file player, and automatically connect this player to
2405 * the conference bridge.
2406 *
2407 * @param filename The filename to be played. Currently only
Benny Prijono312aff92006-06-17 04:08:30 +00002408 * WAV files are supported, and the WAV file MUST be
2409 * formatted as 16bit PCM mono/single channel (any
2410 * clock rate is supported).
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002411 * @param options Options (currently zero).
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002412 * @param p_id Pointer to receive player ID.
2413 *
2414 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002415 */
2416PJ_DECL(pj_status_t) pjsua_player_create(const pj_str_t *filename,
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002417 unsigned options,
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002418 pjsua_player_id *p_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002419
2420
2421/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002422 * Get conference port ID associated with player.
2423 *
2424 * @param id The file player ID.
2425 *
2426 * @return Conference port ID associated with this player.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002427 */
Benny Prijono8b1889b2006-06-06 18:40:40 +00002428PJ_DECL(pjsua_conf_port_id) pjsua_player_get_conf_port(pjsua_player_id id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002429
2430
2431/**
2432 * Set playback position.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002433 *
2434 * @param id The file player ID.
2435 * @param samples The playback position, in samples. Application can
2436 * specify zero to re-start the playback.
2437 *
2438 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002439 */
2440PJ_DECL(pj_status_t) pjsua_player_set_pos(pjsua_player_id id,
2441 pj_uint32_t samples);
2442
2443
2444/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002445 * Close the file, remove the player from the bridge, and free
2446 * resources associated with the file player.
2447 *
2448 * @param id The file player ID.
2449 *
2450 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002451 */
2452PJ_DECL(pj_status_t) pjsua_player_destroy(pjsua_player_id id);
2453
2454
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002455/*****************************************************************************
2456 * File recorder.
2457 */
Benny Prijono9fc735d2006-05-28 14:58:12 +00002458
2459/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002460 * Create a file recorder, and automatically connect this recorder to
2461 * the conference bridge.
2462 *
2463 * @param filename Output file name.
2464 * @param file_format Specify the file format (currently only WAV is
2465 * supported, so the value MUST be zero).
2466 * @param encoding Specify the encoding to be applied to the file.
2467 * Currently only 16bit raw PCM is supported, so
2468 * the value must be NULL.
2469 * @param max_size Maximum file size. Specify -1 to remove size
2470 * limitation.
2471 * @param options Optional options.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002472 * @param p_id Pointer to receive the recorder instance.
2473 *
2474 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002475 */
2476PJ_DECL(pj_status_t) pjsua_recorder_create(const pj_str_t *filename,
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002477 unsigned file_format,
2478 const pj_str_t *encoding,
2479 pj_ssize_t max_size,
2480 unsigned options,
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002481 pjsua_recorder_id *p_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002482
2483
2484/**
2485 * Get conference port associated with recorder.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002486 *
2487 * @param id The recorder ID.
2488 *
2489 * @return Conference port ID associated with this recorder.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002490 */
Benny Prijono8b1889b2006-06-06 18:40:40 +00002491PJ_DECL(pjsua_conf_port_id) pjsua_recorder_get_conf_port(pjsua_recorder_id id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002492
2493
2494/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002495 * Destroy recorder (this will complete recording).
2496 *
2497 * @param id The recorder ID.
2498 *
2499 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002500 */
2501PJ_DECL(pj_status_t) pjsua_recorder_destroy(pjsua_recorder_id id);
2502
2503
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002504/*****************************************************************************
2505 * Sound devices.
2506 */
2507
Benny Prijono9fc735d2006-05-28 14:58:12 +00002508/**
2509 * Enum sound devices.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002510 *
2511 * @param info Array of info to be initialized.
2512 * @param count On input, specifies max elements in the array.
2513 * On return, it contains actual number of elements
2514 * that have been initialized.
2515 *
2516 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002517 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002518PJ_DECL(pj_status_t) pjsua_enum_snd_devs(pjmedia_snd_dev_info info[],
2519 unsigned *count);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002520
2521
Benny Prijonoa3cbb1c2006-08-25 12:41:05 +00002522
2523/**
2524 * Get currently active sound devices. If sound devices has not been created
2525 * (for example when pjsua_start() is not called), it is possible that
2526 * the function returns PJ_SUCCESS with -1 as device IDs.
2527 *
2528 * @param capture_dev On return it will be filled with device ID of the
2529 * capture device.
2530 * @param playback_dev On return it will be filled with device ID of the
2531 * device ID of the playback device.
2532 *
2533 * @return PJ_SUCCESS on success, or the appropriate error code.
2534 */
2535PJ_DECL(pj_status_t) pjsua_get_snd_dev(int *capture_dev,
2536 int *playback_dev);
2537
2538
Benny Prijono9fc735d2006-05-28 14:58:12 +00002539/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002540 * Select or change sound device. Application may call this function at
2541 * any time to replace current sound device.
2542 *
2543 * @param capture_dev Device ID of the capture device.
2544 * @param playback_dev Device ID of the playback device.
2545 *
2546 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002547 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002548PJ_DECL(pj_status_t) pjsua_set_snd_dev(int capture_dev,
2549 int playback_dev);
2550
2551
2552/**
2553 * Set pjsua to use null sound device. The null sound device only provides
2554 * the timing needed by the conference bridge, and will not interract with
2555 * any hardware.
2556 *
2557 * @return PJ_SUCCESS on success, or the appropriate error code.
2558 */
2559PJ_DECL(pj_status_t) pjsua_set_null_snd_dev(void);
2560
2561
Benny Prijonoe909eac2006-07-27 22:04:56 +00002562/**
2563 * Disconnect the main conference bridge from any sound devices, and let
2564 * application connect the bridge to it's own sound device/master port.
2565 *
2566 * @return The port interface of the conference bridge,
2567 * so that application can connect this to it's own
2568 * sound device or master port.
2569 */
2570PJ_DECL(pjmedia_port*) pjsua_set_no_snd_dev(void);
2571
2572
Benny Prijonof20687a2006-08-04 18:27:19 +00002573/**
Benny Prijono22dfe592006-08-06 12:07:13 +00002574 * Configure the echo canceller tail length of the sound port.
Benny Prijonof20687a2006-08-04 18:27:19 +00002575 *
2576 * @param tail_ms The tail length, in miliseconds. Set to zero to
2577 * disable AEC.
Benny Prijono5da50432006-08-07 10:24:52 +00002578 * @param options Options to be passed to #pjmedia_echo_create().
2579 * Normally the value should be zero.
Benny Prijonof20687a2006-08-04 18:27:19 +00002580 *
2581 * @return PJ_SUCCESS on success.
2582 */
Benny Prijono5da50432006-08-07 10:24:52 +00002583PJ_DECL(pj_status_t) pjsua_set_ec(unsigned tail_ms, unsigned options);
Benny Prijonof20687a2006-08-04 18:27:19 +00002584
2585
2586/**
Benny Prijono22dfe592006-08-06 12:07:13 +00002587 * Get current echo canceller tail length.
Benny Prijonof20687a2006-08-04 18:27:19 +00002588 *
2589 * @param p_tail_ms Pointer to receive the tail length, in miliseconds.
2590 * If AEC is disabled, the value will be zero.
2591 *
2592 * @return PJ_SUCCESS on success.
2593 */
Benny Prijono22dfe592006-08-06 12:07:13 +00002594PJ_DECL(pj_status_t) pjsua_get_ec_tail(unsigned *p_tail_ms);
Benny Prijonof20687a2006-08-04 18:27:19 +00002595
2596
2597
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002598/*****************************************************************************
2599 * Codecs.
2600 */
2601
2602/**
2603 * Enum all supported codecs in the system.
2604 *
2605 * @param id Array of ID to be initialized.
2606 * @param count On input, specifies max elements in the array.
2607 * On return, it contains actual number of elements
2608 * that have been initialized.
2609 *
2610 * @return PJ_SUCCESS on success, or the appropriate error code.
2611 */
2612PJ_DECL(pj_status_t) pjsua_enum_codecs( pjsua_codec_info id[],
2613 unsigned *count );
2614
2615
2616/**
2617 * Change codec priority.
2618 *
2619 * @param id Codec ID.
2620 * @param priority Codec priority, 0-255, where zero means to disable
2621 * the codec.
2622 *
2623 * @return PJ_SUCCESS on success, or the appropriate error code.
2624 */
2625PJ_DECL(pj_status_t) pjsua_codec_set_priority( const pj_str_t *id,
2626 pj_uint8_t priority );
2627
2628
2629/**
2630 * Get codec parameters.
2631 *
2632 * @param id Codec ID.
2633 * @param param Structure to receive codec parameters.
2634 *
2635 * @return PJ_SUCCESS on success, or the appropriate error code.
2636 */
2637PJ_DECL(pj_status_t) pjsua_codec_get_param( const pj_str_t *id,
2638 pjmedia_codec_param *param );
2639
2640
2641/**
2642 * Set codec parameters.
2643 *
2644 * @param id Codec ID.
2645 * @param param Codec parameter to set.
2646 *
2647 * @return PJ_SUCCESS on success, or the appropriate error code.
2648 */
2649PJ_DECL(pj_status_t) pjsua_codec_set_param( const pj_str_t *id,
2650 const pjmedia_codec_param *param);
2651
2652
2653
Benny Prijono9fc735d2006-05-28 14:58:12 +00002654
Benny Prijono312aff92006-06-17 04:08:30 +00002655/**
2656 * Create UDP media transports for all the calls. This function creates
2657 * one UDP media transport for each call.
Benny Prijonof3195072006-02-14 21:15:30 +00002658 *
Benny Prijono312aff92006-06-17 04:08:30 +00002659 * @param cfg Media transport configuration. The "port" field in the
2660 * configuration is used as the start port to bind the
2661 * sockets.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002662 *
2663 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonof3195072006-02-14 21:15:30 +00002664 */
Benny Prijono312aff92006-06-17 04:08:30 +00002665PJ_DECL(pj_status_t)
2666pjsua_media_transports_create(const pjsua_transport_config *cfg);
Benny Prijonof3195072006-02-14 21:15:30 +00002667
Benny Prijonodc39fe82006-05-26 12:17:46 +00002668
2669/**
Benny Prijono312aff92006-06-17 04:08:30 +00002670 * Register custom media transports to be used by calls. There must
2671 * enough media transports for all calls.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002672 *
Benny Prijono312aff92006-06-17 04:08:30 +00002673 * @param tp The media transport array.
2674 * @param count Number of elements in the array. This number MUST
2675 * match the number of maximum calls configured when
2676 * pjsua is created.
2677 * @param auto_delete Flag to indicate whether the transports should be
2678 * destroyed when pjsua is shutdown.
2679 *
2680 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonodc39fe82006-05-26 12:17:46 +00002681 */
Benny Prijono312aff92006-06-17 04:08:30 +00002682PJ_DECL(pj_status_t)
2683pjsua_media_transports_attach( pjsua_media_transport tp[],
2684 unsigned count,
2685 pj_bool_t auto_delete);
Benny Prijonodc39fe82006-05-26 12:17:46 +00002686
2687
Benny Prijono312aff92006-06-17 04:08:30 +00002688/**
2689 * @}
2690 */
2691
Benny Prijonof3195072006-02-14 21:15:30 +00002692
Benny Prijono268ca612006-02-07 12:34:11 +00002693
Benny Prijono1a01ad32006-02-07 21:13:28 +00002694PJ_END_DECL
2695
Benny Prijonof3195072006-02-14 21:15:30 +00002696
Benny Prijono312aff92006-06-17 04:08:30 +00002697/**
2698 * @}
2699 */
2700
2701
Benny Prijono268ca612006-02-07 12:34:11 +00002702#endif /* __PJSUA_H__ */