blob: ec040fb96bf97c934fba378e16c054ca231c0f89 [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 Prijono4ddad2c2006-10-18 17:16:34 +0000312 void (*on_call_transfer_request)(pjsua_call_id call_id,
313 const pj_str_t *dst,
314 pjsip_status_code *code);
315
316 /**
317 * Notify application of the status of previously sent call
318 * transfer request. Application can monitor the status of the
319 * call transfer request, for example to decide whether to
320 * terminate existing call.
321 *
322 * @param call_id Call ID.
323 * @param status_code Status progress of the transfer request.
324 * @param status_text Status progress text.
325 * @param final If non-zero, no further notification will
326 * be reported. The status_code specified in
327 * this callback is the final status.
328 * @param p_cont Initially will be set to non-zero, application
329 * can set this to FALSE if it no longer wants
330 * to receie further notification (for example,
331 * after it hangs up the call).
332 */
333 void (*on_call_transfer_status)(pjsua_call_id call_id,
334 int status_code,
335 const pj_str_t *status_text,
336 pj_bool_t final,
337 pj_bool_t *p_cont);
Benny Prijono9fc735d2006-05-28 14:58:12 +0000338
339 /**
Benny Prijono053f5222006-11-11 16:16:04 +0000340 * Notify application about incoming INVITE with Replaces header.
341 * Application may reject the request by setting non-2xx code.
342 *
343 * @param call_id The call ID to be replaced.
344 * @param rdata The incoming INVITE request to replace the call.
345 * @param st_code Status code to be set by application. Application
346 * should only return a final status (200-699).
347 * @param st_text Optional status text to be set by application.
348 */
349 void (*on_call_replace_request)(pjsua_call_id call_id,
350 pjsip_rx_data *rdata,
351 int *st_code,
352 pj_str_t *st_text);
353
354 /**
355 * Notify application that an existing call has been replaced with
356 * a new call. This happens when PJSUA-API receives incoming INVITE
357 * request with Replaces header.
358 *
359 * After this callback is called, normally PJSUA-API will disconnect
360 * \a old_call_id and establish \a new_call_id.
361 *
362 * @param old_call_id Existing call which to be replaced with the
363 * new call.
364 * @param new_call_id The new call.
365 * @param rdata The incoming INVITE with Replaces request.
366 */
367 void (*on_call_replaced)(pjsua_call_id old_call_id,
368 pjsua_call_id new_call_id);
369
370
371 /**
Benny Prijono9fc735d2006-05-28 14:58:12 +0000372 * Notify application when registration status has changed.
373 * Application may then query the account info to get the
374 * registration details.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000375 */
Benny Prijono8b1889b2006-06-06 18:40:40 +0000376 void (*on_reg_state)(pjsua_acc_id acc_id);
Benny Prijonodc39fe82006-05-26 12:17:46 +0000377
378 /**
Benny Prijono9fc735d2006-05-28 14:58:12 +0000379 * Notify application when the buddy state has changed.
380 * Application may then query the buddy into to get the details.
381 */
Benny Prijono8b1889b2006-06-06 18:40:40 +0000382 void (*on_buddy_state)(pjsua_buddy_id buddy_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +0000383
384 /**
385 * Notify application on incoming pager (i.e. MESSAGE request).
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000386 * Argument call_id will be -1 if MESSAGE request is not related to an
Benny Prijonodc39fe82006-05-26 12:17:46 +0000387 * existing call.
388 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000389 void (*on_pager)(pjsua_call_id call_id, const pj_str_t *from,
390 const pj_str_t *to, const pj_str_t *contact,
391 const pj_str_t *mime_type, const pj_str_t *body);
392
393 /**
394 * Notify application about the delivery status of outgoing pager
395 * request.
396 *
397 * @param call_id Containts the ID of the call where the IM was
398 * sent, or PJSUA_INVALID_ID if the IM was sent
399 * outside call context.
400 * @param to Destination URI.
401 * @param body Message body.
402 * @param user_data Arbitrary data that was specified when sending
403 * IM message.
404 * @param status Delivery status.
405 * @param reason Delivery status reason.
406 */
407 void (*on_pager_status)(pjsua_call_id call_id,
408 const pj_str_t *to,
409 const pj_str_t *body,
410 void *user_data,
411 pjsip_status_code status,
412 const pj_str_t *reason);
Benny Prijonodc39fe82006-05-26 12:17:46 +0000413
414 /**
Benny Prijono9fc735d2006-05-28 14:58:12 +0000415 * Notify application about typing indication.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000416 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000417 void (*on_typing)(pjsua_call_id call_id, const pj_str_t *from,
418 const pj_str_t *to, const pj_str_t *contact,
419 pj_bool_t is_typing);
Benny Prijonodc39fe82006-05-26 12:17:46 +0000420
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000421} pjsua_callback;
422
423
424
Benny Prijonodc39fe82006-05-26 12:17:46 +0000425
426/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000427 * PJSUA settings.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000428 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000429typedef struct pjsua_config
430{
431
432 /**
433 * Maximum calls to support (default: 4)
434 */
435 unsigned max_calls;
436
437 /**
438 * Number of worker threads. Normally application will want to have at
439 * least one worker thread, unless when it wants to poll the library
440 * periodically, which in this case the worker thread can be set to
441 * zero.
442 */
443 unsigned thread_cnt;
444
445 /**
Benny Prijonofa9e5b12006-10-08 12:39:34 +0000446 * Number of nameservers. If no name server is configured, the SIP SRV
447 * resolution would be disabled, and domain will be resolved with
448 * standard pj_gethostbyname() function.
449 */
450 unsigned nameserver_count;
451
452 /**
453 * Array of nameservers to be used by the SIP resolver subsystem.
454 * The order of the name server specifies the priority (first name
455 * server will be used first, unless it is not reachable).
456 */
457 pj_str_t nameserver[4];
458
459 /**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000460 * Number of outbound proxies in the array.
461 */
462 unsigned outbound_proxy_cnt;
463
464 /**
465 * Specify the URL of outbound proxies to visit for all outgoing requests.
466 * The outbound proxies will be used for all accounts, and it will
467 * be used to build the route set for outgoing requests. The final
468 * route set for outgoing requests will consists of the outbound proxies
469 * and the proxy configured in the account.
470 */
471 pj_str_t outbound_proxy[4];
472
473 /**
474 * Number of credentials in the credential array.
475 */
476 unsigned cred_count;
477
478 /**
479 * Array of credentials. These credentials will be used by all accounts,
480 * and can be used to authenticate against outbound proxies.
481 */
482 pjsip_cred_info cred_info[PJSUA_ACC_MAX_PROXIES];
483
484 /**
485 * Application callback.
486 */
487 pjsua_callback cb;
488
Benny Prijono56315612006-07-18 14:39:40 +0000489 /**
490 * User agent string (default empty)
491 */
492 pj_str_t user_agent;
493
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000494} pjsua_config;
495
496
497/**
498 * Use this function to initialize pjsua config.
499 *
500 * @param cfg pjsua config to be initialized.
501 */
502PJ_INLINE(void) pjsua_config_default(pjsua_config *cfg)
503{
Benny Prijonoac623b32006-07-03 15:19:31 +0000504 pj_bzero(cfg, sizeof(*cfg));
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000505
506 cfg->max_calls = 4;
507 cfg->thread_cnt = 1;
508}
509
510
511/**
512 * Duplicate credential.
513 */
514PJ_INLINE(void) pjsip_cred_dup( pj_pool_t *pool,
515 pjsip_cred_info *dst,
516 const pjsip_cred_info *src)
517{
518 pj_strdup_with_null(pool, &dst->realm, &src->realm);
519 pj_strdup_with_null(pool, &dst->scheme, &src->scheme);
520 pj_strdup_with_null(pool, &dst->username, &src->username);
521 pj_strdup_with_null(pool, &dst->data, &src->data);
522
523}
524
525
526/**
527 * Duplicate pjsua_config.
528 */
529PJ_INLINE(void) pjsua_config_dup(pj_pool_t *pool,
530 pjsua_config *dst,
531 const pjsua_config *src)
532{
533 unsigned i;
534
535 pj_memcpy(dst, src, sizeof(*src));
536
537 for (i=0; i<src->outbound_proxy_cnt; ++i) {
538 pj_strdup_with_null(pool, &dst->outbound_proxy[i],
539 &src->outbound_proxy[i]);
540 }
541
542 for (i=0; i<src->cred_count; ++i) {
543 pjsip_cred_dup(pool, &dst->cred_info[i], &src->cred_info[i]);
544 }
Benny Prijono56315612006-07-18 14:39:40 +0000545
546 pj_strdup_with_null(pool, &dst->user_agent, &src->user_agent);
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000547}
548
549
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000550
551/**
552 * This structure describes additional information to be sent with
553 * outgoing SIP message.
554 */
555typedef struct pjsua_msg_data
556{
557 /**
558 * Additional message headers as linked list.
559 */
560 pjsip_hdr hdr_list;
561
562 /**
563 * MIME type of optional message body.
564 */
565 pj_str_t content_type;
566
567 /**
568 * Optional message body.
569 */
570 pj_str_t msg_body;
571
572} pjsua_msg_data;
573
574
575/**
576 * Initialize message data.
577 *
578 * @param msg_data Message data to be initialized.
579 */
580PJ_INLINE(void) pjsua_msg_data_init(pjsua_msg_data *msg_data)
581{
Benny Prijonoac623b32006-07-03 15:19:31 +0000582 pj_bzero(msg_data, sizeof(*msg_data));
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000583 pj_list_init(&msg_data->hdr_list);
584}
Benny Prijono8b1889b2006-06-06 18:40:40 +0000585
Benny Prijono268ca612006-02-07 12:34:11 +0000586
Benny Prijono268ca612006-02-07 12:34:11 +0000587
588/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000589 * Instantiate pjsua application. Application must call this function before
590 * calling any other functions, to make sure that the underlying libraries
591 * are properly initialized. Once this function has returned success,
592 * application must call pjsua_destroy() before quitting.
593 *
594 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000595 */
596PJ_DECL(pj_status_t) pjsua_create(void);
597
598
599/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000600 * Initialize pjsua with the specified settings. All the settings are
601 * optional, and the default values will be used when the config is not
602 * specified.
Benny Prijonoccf95622006-02-07 18:48:01 +0000603 *
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000604 * @param ua_cfg User agent configuration.
605 * @param log_cfg Optional logging configuration.
606 * @param media_cfg Optional media configuration.
Benny Prijonoccf95622006-02-07 18:48:01 +0000607 *
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000608 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono268ca612006-02-07 12:34:11 +0000609 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000610PJ_DECL(pj_status_t) pjsua_init(const pjsua_config *ua_cfg,
611 const pjsua_logging_config *log_cfg,
612 const pjsua_media_config *media_cfg);
Benny Prijono268ca612006-02-07 12:34:11 +0000613
614
615/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000616 * Application is recommended to call this function after all initialization
617 * is done, so that the library can do additional checking set up
618 * additional
Benny Prijonoccf95622006-02-07 18:48:01 +0000619 *
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000620 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonoccf95622006-02-07 18:48:01 +0000621 */
Benny Prijonodc39fe82006-05-26 12:17:46 +0000622PJ_DECL(pj_status_t) pjsua_start(void);
Benny Prijonoccf95622006-02-07 18:48:01 +0000623
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000624
Benny Prijonoccf95622006-02-07 18:48:01 +0000625/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000626 * Destroy pjsua. This function must be called once PJSUA is created. To
627 * make it easier for application, application may call this function
628 * several times with no danger.
629 *
630 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono268ca612006-02-07 12:34:11 +0000631 */
Benny Prijonodc39fe82006-05-26 12:17:46 +0000632PJ_DECL(pj_status_t) pjsua_destroy(void);
Benny Prijonoa91a0032006-02-26 21:23:45 +0000633
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000634
Benny Prijono9fc735d2006-05-28 14:58:12 +0000635/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000636 * Poll pjsua for events, and if necessary block the caller thread for
637 * the specified maximum interval (in miliseconds).
638 *
639 * @param msec_timeout Maximum time to wait, in miliseconds.
640 *
641 * @return The number of events that have been handled during the
642 * poll. Negative value indicates error, and application
643 * can retrieve the error as (err = -return_value).
Benny Prijonob9b32ab2006-06-01 12:28:44 +0000644 */
645PJ_DECL(int) pjsua_handle_events(unsigned msec_timeout);
646
647
648/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000649 * Create memory pool.
650 *
651 * @param name Optional pool name.
Benny Prijono312aff92006-06-17 04:08:30 +0000652 * @param init_size Initial size of the pool.
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000653 * @param increment Increment size.
654 *
655 * @return The pool, or NULL when there's no memory.
656 */
657PJ_DECL(pj_pool_t*) pjsua_pool_create(const char *name, pj_size_t init_size,
658 pj_size_t increment);
659
660
661/**
662 * Application can call this function at any time (after pjsua_create(), of
663 * course) to change logging settings.
664 *
665 * @param c Logging configuration.
666 *
667 * @return PJ_SUCCESS on success, or the appropriate error code.
668 */
669PJ_DECL(pj_status_t) pjsua_reconfigure_logging(const pjsua_logging_config *c);
670
671
672/**
673 * Internal function to get SIP endpoint instance of pjsua, which is
674 * needed for example to register module, create transports, etc.
675 * Probably is only valid after #pjsua_init() is called.
676 *
677 * @return SIP endpoint instance.
Benny Prijono9fc735d2006-05-28 14:58:12 +0000678 */
679PJ_DECL(pjsip_endpoint*) pjsua_get_pjsip_endpt(void);
680
681/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000682 * Internal function to get media endpoint instance.
683 * Only valid after #pjsua_init() is called.
684 *
685 * @return Media endpoint instance.
Benny Prijono9fc735d2006-05-28 14:58:12 +0000686 */
687PJ_DECL(pjmedia_endpt*) pjsua_get_pjmedia_endpt(void);
688
Benny Prijono97b87172006-08-24 14:25:14 +0000689/**
690 * Internal function to get PJSUA pool factory.
691 * Only valid after #pjsua_init() is called.
692 *
693 * @return Pool factory currently used by PJSUA.
694 */
695PJ_DECL(pj_pool_factory*) pjsua_get_pool_factory(void);
696
697
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000698
699/*****************************************************************************
Benny Prijono312aff92006-06-17 04:08:30 +0000700 * Utilities.
701 *
Benny Prijono9fc735d2006-05-28 14:58:12 +0000702 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000703
704/**
Benny Prijono312aff92006-06-17 04:08:30 +0000705 * Verify that valid SIP url is given.
706 *
707 * @param c_url The URL, as NULL terminated string.
708 *
709 * @return PJ_SUCCESS on success, or the appropriate error code.
710 */
711PJ_DECL(pj_status_t) pjsua_verify_sip_url(const char *c_url);
712
713
714/**
715 * Display error message for the specified error code.
716 *
717 * @param sender The log sender field.
718 * @param title Message title for the error.
719 * @param status Status code.
720 */
721PJ_DECL(void) pjsua_perror(const char *sender, const char *title,
722 pj_status_t status);
723
724
725
726
727/**
728 * @}
729 */
730
731
732
733/*****************************************************************************
734 * TRANSPORT API
735 */
736
737/**
738 * @defgroup PJSUA_LIB_TRANSPORT Signaling Transport
739 * @ingroup PJSUA_LIB
740 * @brief API for managing SIP transports
741 * @{
742 * SIP transport must be created before adding an account. SIP transport is
743 * created by calling #pjsua_transport_create() function.
744 */
745
746
747/** SIP transport identification */
748typedef int pjsua_transport_id;
749
750
751/**
752 * STUN configuration.
753 */
754typedef struct pjsua_stun_config
755{
756 /**
757 * The first STUN server IP address or hostname.
758 */
759 pj_str_t stun_srv1;
760
761 /**
762 * Port number of the first STUN server.
763 * If zero, default STUN port will be used.
764 */
765 unsigned stun_port1;
766
767 /**
768 * Optional second STUN server IP address or hostname, for which the
769 * result of the mapping request will be compared to. If the value
770 * is empty, only one STUN server will be used.
771 */
772 pj_str_t stun_srv2;
773
774 /**
775 * Port number of the second STUN server.
776 * If zero, default STUN port will be used.
777 */
778 unsigned stun_port2;
779
780} pjsua_stun_config;
781
782
783
784/**
785 * Call this function to initialize STUN config with default values.
786 *
787 * @param cfg The STUN config to be initialized.
788 */
789PJ_INLINE(void) pjsua_stun_config_default(pjsua_stun_config *cfg)
790{
Benny Prijonoac623b32006-07-03 15:19:31 +0000791 pj_bzero(cfg, sizeof(*cfg));
Benny Prijono312aff92006-06-17 04:08:30 +0000792}
793
794
795/**
Benny Prijono0a5cad82006-09-26 13:21:02 +0000796 * Transport configuration for creating transports for both SIP
Benny Prijono312aff92006-06-17 04:08:30 +0000797 * and media.
798 */
799typedef struct pjsua_transport_config
800{
801 /**
802 * UDP port number to bind locally. This setting MUST be specified
803 * even when default port is desired. If the value is zero, the
804 * transport will be bound to any available port, and application
805 * can query the port by querying the transport info.
806 */
807 unsigned port;
808
809 /**
Benny Prijono0a5cad82006-09-26 13:21:02 +0000810 * Optional address to advertise as the address of this transport.
811 * Application can specify any address or hostname for this field,
812 * for example it can point to one of the interface address in the
813 * system, or it can point to the public address of a NAT router
814 * where port mappings have been configured for the application.
815 *
816 * Note: this option can be used for both UDP and TCP as well!
Benny Prijono312aff92006-06-17 04:08:30 +0000817 */
Benny Prijono0a5cad82006-09-26 13:21:02 +0000818 pj_str_t public_addr;
819
820 /**
821 * Optional address where the socket should be bound to. This option
822 * SHOULD only be used to selectively bind the socket to particular
823 * interface (instead of 0.0.0.0), and SHOULD NOT be used to set the
824 * published address of a transport (the public_addr field should be
825 * used for that purpose).
826 *
827 * Note that unlike public_addr field, the address (or hostname) here
828 * MUST correspond to the actual interface address in the host, since
829 * this address will be specified as bind() argument.
830 */
831 pj_str_t bound_addr;
Benny Prijono312aff92006-06-17 04:08:30 +0000832
833 /**
834 * Flag to indicate whether STUN should be used.
835 */
836 pj_bool_t use_stun;
837
838 /**
839 * STUN configuration, must be specified when STUN is used.
840 */
841 pjsua_stun_config stun_config;
842
843} pjsua_transport_config;
844
845
846/**
847 * Call this function to initialize UDP config with default values.
848 *
849 * @param cfg The UDP config to be initialized.
850 */
851PJ_INLINE(void) pjsua_transport_config_default(pjsua_transport_config *cfg)
852{
Benny Prijonoac623b32006-07-03 15:19:31 +0000853 pj_bzero(cfg, sizeof(*cfg));
Benny Prijono312aff92006-06-17 04:08:30 +0000854}
855
856
857/**
858 * Normalize STUN config.
859 */
860PJ_INLINE(void) pjsua_normalize_stun_config( pjsua_stun_config *cfg )
861{
862 if (cfg->stun_srv1.slen) {
863
864 if (cfg->stun_port1 == 0)
865 cfg->stun_port1 = 3478;
866
867 if (cfg->stun_srv2.slen == 0) {
868 cfg->stun_srv2 = cfg->stun_srv1;
869 cfg->stun_port2 = cfg->stun_port1;
870 } else {
871 if (cfg->stun_port2 == 0)
872 cfg->stun_port2 = 3478;
873 }
874
875 } else {
876 cfg->stun_port1 = 0;
877 cfg->stun_srv2.slen = 0;
878 cfg->stun_port2 = 0;
879 }
880}
881
882
883/**
884 * Duplicate transport config.
885 */
886PJ_INLINE(void) pjsua_transport_config_dup(pj_pool_t *pool,
887 pjsua_transport_config *dst,
888 const pjsua_transport_config *src)
889{
890 pj_memcpy(dst, src, sizeof(*src));
891
892 if (src->stun_config.stun_srv1.slen) {
893 pj_strdup_with_null(pool, &dst->stun_config.stun_srv1,
894 &src->stun_config.stun_srv1);
895 }
896
897 if (src->stun_config.stun_srv2.slen) {
898 pj_strdup_with_null(pool, &dst->stun_config.stun_srv2,
899 &src->stun_config.stun_srv2);
900 }
901
902 pjsua_normalize_stun_config(&dst->stun_config);
903}
904
905
906
907/**
908 * Transport info.
909 */
910typedef struct pjsua_transport_info
911{
912 /**
913 * PJSUA transport identification.
914 */
915 pjsua_transport_id id;
916
917 /**
918 * Transport type.
919 */
920 pjsip_transport_type_e type;
921
922 /**
923 * Transport type name.
924 */
925 pj_str_t type_name;
926
927 /**
928 * Transport string info/description.
929 */
930 pj_str_t info;
931
932 /**
933 * Transport flag (see ##pjsip_transport_flags_e).
934 */
935 unsigned flag;
936
937 /**
938 * Local address length.
939 */
940 unsigned addr_len;
941
942 /**
943 * Local/bound address.
944 */
945 pj_sockaddr local_addr;
946
947 /**
948 * Published address (or transport address name).
949 */
950 pjsip_host_port local_name;
951
952 /**
953 * Current number of objects currently referencing this transport.
954 */
955 unsigned usage_count;
956
957
958} pjsua_transport_info;
959
960
961/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000962 * Create SIP transport.
963 *
964 * @param type Transport type.
965 * @param cfg Transport configuration.
966 * @param p_id Optional pointer to receive transport ID.
967 *
968 * @return PJ_SUCCESS on success, or the appropriate error code.
969 */
970PJ_DECL(pj_status_t) pjsua_transport_create(pjsip_transport_type_e type,
971 const pjsua_transport_config *cfg,
972 pjsua_transport_id *p_id);
973
974/**
975 * Register transport that has been created by application.
976 *
977 * @param tp Transport instance.
978 * @param p_id Optional pointer to receive transport ID.
979 *
980 * @return PJ_SUCCESS on success, or the appropriate error code.
981 */
982PJ_DECL(pj_status_t) pjsua_transport_register(pjsip_transport *tp,
983 pjsua_transport_id *p_id);
984
985
986/**
987 * Enumerate all transports currently created in the system.
988 *
989 * @param id Array to receive transport ids.
990 * @param count In input, specifies the maximum number of elements.
991 * On return, it contains the actual number of elements.
992 *
993 * @return PJ_SUCCESS on success, or the appropriate error code.
994 */
995PJ_DECL(pj_status_t) pjsua_enum_transports( pjsua_transport_id id[],
996 unsigned *count );
997
998
999/**
1000 * Get information about transports.
1001 *
1002 * @param id Transport ID.
1003 * @param info Pointer to receive transport info.
1004 *
1005 * @return PJ_SUCCESS on success, or the appropriate error code.
1006 */
1007PJ_DECL(pj_status_t) pjsua_transport_get_info(pjsua_transport_id id,
1008 pjsua_transport_info *info);
1009
1010
1011/**
1012 * Disable a transport or re-enable it. By default transport is always
1013 * enabled after it is created. Disabling a transport does not necessarily
1014 * close the socket, it will only discard incoming messages and prevent
1015 * the transport from being used to send outgoing messages.
1016 *
1017 * @param id Transport ID.
1018 * @param enabled Non-zero to enable, zero to disable.
1019 *
1020 * @return PJ_SUCCESS on success, or the appropriate error code.
1021 */
1022PJ_DECL(pj_status_t) pjsua_transport_set_enable(pjsua_transport_id id,
1023 pj_bool_t enabled);
1024
1025
1026/**
1027 * Close the transport. If transport is forcefully closed, it will be
1028 * immediately closed, and any pending transactions that are using the
1029 * transport may not terminate properly. Otherwise, the system will wait
1030 * until all transactions are closed while preventing new users from
1031 * using the transport, and will close the transport when it is safe to
1032 * do so.
1033 *
1034 * @param id Transport ID.
1035 * @param force Non-zero to immediately close the transport. This
1036 * is not recommended!
1037 *
1038 * @return PJ_SUCCESS on success, or the appropriate error code.
1039 */
1040PJ_DECL(pj_status_t) pjsua_transport_close( pjsua_transport_id id,
1041 pj_bool_t force );
Benny Prijono9fc735d2006-05-28 14:58:12 +00001042
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001043/**
Benny Prijono312aff92006-06-17 04:08:30 +00001044 * @}
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001045 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001046
1047
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001048
1049
1050/*****************************************************************************
Benny Prijono312aff92006-06-17 04:08:30 +00001051 * ACCOUNT API
Benny Prijonoa91a0032006-02-26 21:23:45 +00001052 */
1053
Benny Prijono312aff92006-06-17 04:08:30 +00001054
1055/**
1056 * @defgroup PJSUA_LIB_ACC Account Management
1057 * @ingroup PJSUA_LIB
1058 * @brief PJSUA supports multiple accounts..
1059 * @{
1060 * PJSUA accounts provide identity (or identities) of the user who is currently
1061 * using the application. More than one account maybe created with PJSUA.
1062 *
1063 * Account may or may not have client registration associated with it.
1064 * An account is also associated with <b>route set</b> and some <b>authentication
1065 * credentials</b>, which are used when sending SIP request messages using the
1066 * account. An account also has presence's <b>online status</b>, which
1067 * will be reported to remote peer when the subscribe to the account's
1068 * presence.
1069 *
1070 * At least one account MUST be created in the application. If no user
1071 * association is required, application can create a userless account by
1072 * calling #pjsua_acc_add_local(). A userless account identifies local endpoint
1073 * instead of a particular user.
1074 *
1075 * Also one account must be set as the <b>default account</b>, which is used as
1076 * the account to use when PJSUA fails to match a request with any other
1077 * accounts.
1078 *
1079 * When sending outgoing SIP requests (such as making calls or sending
1080 * instant messages), normally PJSUA requires the application to specify
1081 * which account to use for the request. If no account is specified,
1082 * PJSUA may be able to select the account by matching the destination
1083 * domain name, and fall back to default account when no match is found.
1084 */
1085
1086/**
1087 * Maximum accounts.
1088 */
1089#ifndef PJSUA_MAX_ACC
1090# define PJSUA_MAX_ACC 8
1091#endif
1092
1093
1094/**
1095 * Default registration interval.
1096 */
1097#ifndef PJSUA_REG_INTERVAL
1098# define PJSUA_REG_INTERVAL 55
1099#endif
1100
1101
1102/**
Benny Prijono3a5e1ab2006-08-15 20:26:34 +00001103 * Default PUBLISH expiration
1104 */
1105#ifndef PJSUA_PUBLISH_EXPIRATION
1106# define PJSUA_PUBLISH_EXPIRATION 600
1107#endif
1108
1109
1110/**
Benny Prijono093d3022006-09-24 00:07:11 +00001111 * Default account priority.
1112 */
1113#ifndef PJSUA_DEFAULT_ACC_PRIORITY
1114# define PJSUA_DEFAULT_ACC_PRIORITY 0
1115#endif
1116
1117
1118/**
Benny Prijono312aff92006-06-17 04:08:30 +00001119 * Account configuration.
1120 */
1121typedef struct pjsua_acc_config
1122{
Benny Prijono093d3022006-09-24 00:07:11 +00001123 /**
1124 * Account priority, which is used to control the order of matching
1125 * incoming/outgoing requests. The higher the number means the higher
1126 * the priority is, and the account will be matched first.
1127 */
1128 int priority;
1129
Benny Prijono312aff92006-06-17 04:08:30 +00001130 /**
1131 * The full SIP URL for the account. The value can take name address or
1132 * URL format, and will look something like "sip:account@serviceprovider".
1133 *
1134 * This field is mandatory.
1135 */
1136 pj_str_t id;
1137
1138 /**
1139 * This is the URL to be put in the request URI for the registration,
1140 * and will look something like "sip:serviceprovider".
1141 *
1142 * This field should be specified if registration is desired. If the
1143 * value is empty, no account registration will be performed.
1144 */
1145 pj_str_t reg_uri;
1146
Benny Prijono3a5e1ab2006-08-15 20:26:34 +00001147 /**
1148 * Publish presence?
1149 */
1150 pj_bool_t publish_enabled;
1151
Benny Prijono312aff92006-06-17 04:08:30 +00001152 /**
1153 * Optional URI to be put as Contact for this account. It is recommended
1154 * that this field is left empty, so that the value will be calculated
1155 * automatically based on the transport address.
1156 */
Benny Prijonob4a17c92006-07-10 14:40:21 +00001157 pj_str_t force_contact;
Benny Prijono312aff92006-06-17 04:08:30 +00001158
1159 /**
1160 * Number of proxies in the proxy array below.
1161 */
1162 unsigned proxy_cnt;
1163
1164 /**
1165 * Optional URI of the proxies to be visited for all outgoing requests
1166 * that are using this account (REGISTER, INVITE, etc). Application need
1167 * to specify these proxies if the service provider requires that requests
1168 * destined towards its network should go through certain proxies first
1169 * (for example, border controllers).
1170 *
1171 * These proxies will be put in the route set for this account, with
1172 * maintaining the orders (the first proxy in the array will be visited
1173 * first).
1174 */
1175 pj_str_t proxy[PJSUA_ACC_MAX_PROXIES];
1176
1177 /**
1178 * Optional interval for registration, in seconds. If the value is zero,
1179 * default interval will be used (PJSUA_REG_INTERVAL, 55 seconds).
1180 */
1181 unsigned reg_timeout;
1182
1183 /**
1184 * Number of credentials in the credential array.
1185 */
1186 unsigned cred_count;
1187
1188 /**
1189 * Array of credentials. If registration is desired, normally there should
1190 * be at least one credential specified, to successfully authenticate
1191 * against the service provider. More credentials can be specified, for
1192 * example when the requests are expected to be challenged by the
1193 * proxies in the route set.
1194 */
1195 pjsip_cred_info cred_info[PJSUA_ACC_MAX_PROXIES];
1196
1197} pjsua_acc_config;
1198
1199
1200/**
1201 * Call this function to initialize account config with default values.
1202 *
1203 * @param cfg The account config to be initialized.
1204 */
1205PJ_INLINE(void) pjsua_acc_config_default(pjsua_acc_config *cfg)
1206{
Benny Prijonoac623b32006-07-03 15:19:31 +00001207 pj_bzero(cfg, sizeof(*cfg));
Benny Prijono312aff92006-06-17 04:08:30 +00001208
1209 cfg->reg_timeout = PJSUA_REG_INTERVAL;
1210}
1211
1212
1213
1214/**
1215 * Account info. Application can query account info by calling
1216 * #pjsua_acc_get_info().
1217 */
1218typedef struct pjsua_acc_info
1219{
1220 /**
1221 * The account ID.
1222 */
1223 pjsua_acc_id id;
1224
1225 /**
1226 * Flag to indicate whether this is the default account.
1227 */
1228 pj_bool_t is_default;
1229
1230 /**
1231 * Account URI
1232 */
1233 pj_str_t acc_uri;
1234
1235 /**
1236 * Flag to tell whether this account has registration setting
1237 * (reg_uri is not empty).
1238 */
1239 pj_bool_t has_registration;
1240
1241 /**
1242 * An up to date expiration interval for account registration session.
1243 */
1244 int expires;
1245
1246 /**
1247 * Last registration status code. If status code is zero, the account
1248 * is currently not registered. Any other value indicates the SIP
1249 * status code of the registration.
1250 */
1251 pjsip_status_code status;
1252
1253 /**
1254 * String describing the registration status.
1255 */
1256 pj_str_t status_text;
1257
1258 /**
1259 * Presence online status for this account.
1260 */
1261 pj_bool_t online_status;
1262
1263 /**
1264 * Buffer that is used internally to store the status text.
1265 */
1266 char buf_[PJ_ERR_MSG_SIZE];
1267
1268} pjsua_acc_info;
1269
1270
1271
1272/**
1273 * Get number of current accounts.
1274 *
1275 * @return Current number of accounts.
1276 */
1277PJ_DECL(unsigned) pjsua_acc_get_count(void);
1278
1279
1280/**
1281 * Check if the specified account ID is valid.
1282 *
1283 * @param acc_id Account ID to check.
1284 *
1285 * @return Non-zero if account ID is valid.
1286 */
1287PJ_DECL(pj_bool_t) pjsua_acc_is_valid(pjsua_acc_id acc_id);
1288
1289
1290/**
Benny Prijono21b9ad92006-08-15 13:11:22 +00001291 * Set default account to be used when incoming and outgoing
1292 * requests doesn't match any accounts.
1293 *
1294 * @param acc_id The account ID to be used as default.
1295 *
1296 * @return PJ_SUCCESS on success.
1297 */
1298PJ_DECL(pj_status_t) pjsua_acc_set_default(pjsua_acc_id acc_id);
1299
1300
1301/**
1302 * Get default account.
1303 *
1304 * @return The default account ID, or PJSUA_INVALID_ID if no
1305 * default account is configured.
1306 */
1307PJ_DECL(pjsua_acc_id) pjsua_acc_get_default(void);
1308
1309
1310/**
Benny Prijono312aff92006-06-17 04:08:30 +00001311 * Add a new account to pjsua. PJSUA must have been initialized (with
1312 * #pjsua_init()) before calling this function.
1313 *
1314 * @param cfg Account configuration.
1315 * @param is_default If non-zero, this account will be set as the default
1316 * account. The default account will be used when sending
1317 * outgoing requests (e.g. making call) when no account is
1318 * specified, and when receiving incoming requests when the
1319 * request does not match any accounts. It is recommended
1320 * that default account is set to local/LAN account.
1321 * @param p_acc_id Pointer to receive account ID of the new account.
1322 *
1323 * @return PJ_SUCCESS on success, or the appropriate error code.
1324 */
1325PJ_DECL(pj_status_t) pjsua_acc_add(const pjsua_acc_config *cfg,
1326 pj_bool_t is_default,
1327 pjsua_acc_id *p_acc_id);
1328
1329
1330/**
1331 * Add a local account. A local account is used to identify local endpoint
1332 * instead of a specific user, and for this reason, a transport ID is needed
1333 * to obtain the local address information.
1334 *
1335 * @param tid Transport ID to generate account address.
1336 * @param is_default If non-zero, this account will be set as the default
1337 * account. The default account will be used when sending
1338 * outgoing requests (e.g. making call) when no account is
1339 * specified, and when receiving incoming requests when the
1340 * request does not match any accounts. It is recommended
1341 * that default account is set to local/LAN account.
1342 * @param p_acc_id Pointer to receive account ID of the new account.
1343 *
1344 * @return PJ_SUCCESS on success, or the appropriate error code.
1345 */
1346PJ_DECL(pj_status_t) pjsua_acc_add_local(pjsua_transport_id tid,
1347 pj_bool_t is_default,
1348 pjsua_acc_id *p_acc_id);
1349
1350/**
1351 * Delete account.
1352 *
1353 * @param acc_id Id of the account to be deleted.
1354 *
1355 * @return PJ_SUCCESS on success, or the appropriate error code.
1356 */
1357PJ_DECL(pj_status_t) pjsua_acc_del(pjsua_acc_id acc_id);
1358
1359
1360/**
1361 * Modify account information.
1362 *
1363 * @param acc_id Id of the account to be modified.
1364 * @param cfg New account configuration.
1365 *
1366 * @return PJ_SUCCESS on success, or the appropriate error code.
1367 */
1368PJ_DECL(pj_status_t) pjsua_acc_modify(pjsua_acc_id acc_id,
1369 const pjsua_acc_config *cfg);
1370
1371
1372/**
1373 * Modify account's presence status to be advertised to remote/presence
1374 * subscribers.
1375 *
1376 * @param acc_id The account ID.
1377 * @param is_online True of false.
1378 *
1379 * @return PJ_SUCCESS on success, or the appropriate error code.
1380 */
1381PJ_DECL(pj_status_t) pjsua_acc_set_online_status(pjsua_acc_id acc_id,
1382 pj_bool_t is_online);
1383
1384
1385/**
1386 * Update registration or perform unregistration.
1387 *
1388 * @param acc_id The account ID.
1389 * @param renew If renew argument is zero, this will start
1390 * unregistration process.
1391 *
1392 * @return PJ_SUCCESS on success, or the appropriate error code.
1393 */
1394PJ_DECL(pj_status_t) pjsua_acc_set_registration(pjsua_acc_id acc_id,
1395 pj_bool_t renew);
1396
1397
1398/**
1399 * Get account information.
1400 *
1401 * @param acc_id Account identification.
1402 * @param info Pointer to receive account information.
1403 *
1404 * @return PJ_SUCCESS on success, or the appropriate error code.
1405 */
1406PJ_DECL(pj_status_t) pjsua_acc_get_info(pjsua_acc_id acc_id,
1407 pjsua_acc_info *info);
1408
1409
1410/**
1411 * Enum accounts all account ids.
1412 *
1413 * @param ids Array of account IDs to be initialized.
1414 * @param count In input, specifies the maximum number of elements.
1415 * On return, it contains the actual number of elements.
1416 *
1417 * @return PJ_SUCCESS on success, or the appropriate error code.
1418 */
1419PJ_DECL(pj_status_t) pjsua_enum_accs(pjsua_acc_id ids[],
1420 unsigned *count );
1421
1422
1423/**
1424 * Enum accounts info.
1425 *
1426 * @param info Array of account infos to be initialized.
1427 * @param count In input, specifies the maximum number of elements.
1428 * On return, it contains the actual number of elements.
1429 *
1430 * @return PJ_SUCCESS on success, or the appropriate error code.
1431 */
1432PJ_DECL(pj_status_t) pjsua_acc_enum_info( pjsua_acc_info info[],
1433 unsigned *count );
1434
1435
1436/**
1437 * This is an internal function to find the most appropriate account to
1438 * used to reach to the specified URL.
1439 *
1440 * @param url The remote URL to reach.
1441 *
1442 * @return Account id.
1443 */
1444PJ_DECL(pjsua_acc_id) pjsua_acc_find_for_outgoing(const pj_str_t *url);
1445
1446
1447/**
1448 * This is an internal function to find the most appropriate account to be
1449 * used to handle incoming calls.
1450 *
1451 * @param rdata The incoming request message.
1452 *
1453 * @return Account id.
1454 */
1455PJ_DECL(pjsua_acc_id) pjsua_acc_find_for_incoming(pjsip_rx_data *rdata);
1456
1457
Benny Prijonoc570f2d2006-07-18 00:33:02 +00001458/**
1459 * Create a suitable URI to be put as Contact based on the specified
1460 * target URI for the specified account.
1461 *
1462 * @param pool Pool to allocate memory for the string.
1463 * @param contact The string where the Contact URI will be stored.
1464 * @param acc_id Account ID.
1465 * @param uri Destination URI of the request.
1466 *
1467 * @return PJ_SUCCESS on success, other on error.
1468 */
1469PJ_DECL(pj_status_t) pjsua_acc_create_uac_contact( pj_pool_t *pool,
1470 pj_str_t *contact,
1471 pjsua_acc_id acc_id,
1472 const pj_str_t *uri);
1473
1474
1475
1476/**
1477 * Create a suitable URI to be put as Contact based on the information
1478 * in the incoming request.
1479 *
1480 * @param pool Pool to allocate memory for the string.
1481 * @param contact The string where the Contact URI will be stored.
1482 * @param acc_id Account ID.
1483 * @param rdata Incoming request.
1484 *
1485 * @return PJ_SUCCESS on success, other on error.
1486 */
1487PJ_DECL(pj_status_t) pjsua_acc_create_uas_contact( pj_pool_t *pool,
1488 pj_str_t *contact,
1489 pjsua_acc_id acc_id,
1490 pjsip_rx_data *rdata );
1491
1492
Benny Prijono312aff92006-06-17 04:08:30 +00001493
1494/**
1495 * @}
1496 */
1497
1498
1499/*****************************************************************************
1500 * CALLS API
1501 */
1502
1503
1504/**
1505 * @defgroup PJSUA_LIB_CALL Calls
1506 * @ingroup PJSUA_LIB
1507 * @brief Call manipulation.
1508 * @{
1509 */
1510
1511/**
1512 * Max simultaneous calls.
1513 */
1514#ifndef PJSUA_MAX_CALLS
1515# define PJSUA_MAX_CALLS 32
1516#endif
1517
1518
1519
1520/**
1521 * Call media status.
1522 */
1523typedef enum pjsua_call_media_status
1524{
1525 PJSUA_CALL_MEDIA_NONE,
1526 PJSUA_CALL_MEDIA_ACTIVE,
1527 PJSUA_CALL_MEDIA_LOCAL_HOLD,
1528 PJSUA_CALL_MEDIA_REMOTE_HOLD,
1529} pjsua_call_media_status;
1530
1531
1532/**
1533 * Call info.
1534 */
1535typedef struct pjsua_call_info
1536{
1537 /** Call identification. */
1538 pjsua_call_id id;
1539
1540 /** Initial call role (UAC == caller) */
1541 pjsip_role_e role;
1542
Benny Prijono90315512006-09-14 16:05:16 +00001543 /** The account ID where this call belongs. */
1544 pjsua_acc_id acc_id;
1545
Benny Prijono312aff92006-06-17 04:08:30 +00001546 /** Local URI */
1547 pj_str_t local_info;
1548
1549 /** Local Contact */
1550 pj_str_t local_contact;
1551
1552 /** Remote URI */
1553 pj_str_t remote_info;
1554
1555 /** Remote contact */
1556 pj_str_t remote_contact;
1557
1558 /** Dialog Call-ID string. */
1559 pj_str_t call_id;
1560
1561 /** Call state */
1562 pjsip_inv_state state;
1563
1564 /** Text describing the state */
1565 pj_str_t state_text;
1566
1567 /** Last status code heard, which can be used as cause code */
1568 pjsip_status_code last_status;
1569
1570 /** The reason phrase describing the status. */
1571 pj_str_t last_status_text;
1572
1573 /** Call media status. */
1574 pjsua_call_media_status media_status;
1575
1576 /** Media direction */
1577 pjmedia_dir media_dir;
1578
1579 /** The conference port number for the call */
1580 pjsua_conf_port_id conf_slot;
1581
1582 /** Up-to-date call connected duration (zero when call is not
1583 * established)
1584 */
1585 pj_time_val connect_duration;
1586
1587 /** Total call duration, including set-up time */
1588 pj_time_val total_duration;
1589
1590 /** Internal */
1591 struct {
1592 char local_info[128];
1593 char local_contact[128];
1594 char remote_info[128];
1595 char remote_contact[128];
1596 char call_id[128];
1597 char last_status_text[128];
1598 } buf_;
1599
1600} pjsua_call_info;
1601
1602
1603
Benny Prijonoa91a0032006-02-26 21:23:45 +00001604/**
Benny Prijono9fc735d2006-05-28 14:58:12 +00001605 * Get maximum number of calls configured in pjsua.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001606 *
1607 * @return Maximum number of calls configured.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001608 */
Benny Prijono8b1889b2006-06-06 18:40:40 +00001609PJ_DECL(unsigned) pjsua_call_get_max_count(void);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001610
1611/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001612 * Get number of currently active calls.
1613 *
1614 * @return Number of currently active calls.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001615 */
Benny Prijono8b1889b2006-06-06 18:40:40 +00001616PJ_DECL(unsigned) pjsua_call_get_count(void);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001617
1618/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001619 * Enumerate all active calls.
1620 *
1621 * @param ids Array of account IDs to be initialized.
1622 * @param count In input, specifies the maximum number of elements.
1623 * On return, it contains the actual number of elements.
1624 *
1625 * @return PJ_SUCCESS on success, or the appropriate error code.
1626 */
1627PJ_DECL(pj_status_t) pjsua_enum_calls(pjsua_call_id ids[],
1628 unsigned *count);
1629
1630
1631/**
1632 * Make outgoing call to the specified URI using the specified account.
1633 *
1634 * @param acc_id The account to be used.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001635 * @param dst_uri URI to be put in the To header (normally is the same
1636 * as the target URI).
1637 * @param options Options (must be zero at the moment).
1638 * @param user_data Arbitrary user data to be attached to the call, and
1639 * can be retrieved later.
1640 * @param msg_data Optional headers etc to be added to outgoing INVITE
1641 * request, or NULL if no custom header is desired.
1642 * @param p_call_id Pointer to receive call identification.
1643 *
1644 * @return PJ_SUCCESS on success, or the appropriate error code.
1645 */
1646PJ_DECL(pj_status_t) pjsua_call_make_call(pjsua_acc_id acc_id,
1647 const pj_str_t *dst_uri,
1648 unsigned options,
1649 void *user_data,
1650 const pjsua_msg_data *msg_data,
1651 pjsua_call_id *p_call_id);
1652
1653
1654/**
Benny Prijono9fc735d2006-05-28 14:58:12 +00001655 * Check if the specified call has active INVITE session and the INVITE
1656 * session has not been disconnected.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001657 *
1658 * @param call_id Call identification.
1659 *
1660 * @return Non-zero if call is active.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001661 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001662PJ_DECL(pj_bool_t) pjsua_call_is_active(pjsua_call_id call_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001663
1664
1665/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001666 * Check if call has an active media session.
1667 *
1668 * @param call_id Call identification.
1669 *
1670 * @return Non-zero if yes.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001671 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001672PJ_DECL(pj_bool_t) pjsua_call_has_media(pjsua_call_id call_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001673
1674
1675/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001676 * Get the conference port identification associated with the call.
1677 *
1678 * @param call_id Call identification.
1679 *
1680 * @return Conference port ID, or PJSUA_INVALID_ID when the
1681 * media has not been established or is not active.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001682 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001683PJ_DECL(pjsua_conf_port_id) pjsua_call_get_conf_port(pjsua_call_id call_id);
1684
1685/**
1686 * Obtain detail information about the specified call.
1687 *
1688 * @param call_id Call identification.
1689 * @param info Call info to be initialized.
1690 *
1691 * @return PJ_SUCCESS on success, or the appropriate error code.
1692 */
1693PJ_DECL(pj_status_t) pjsua_call_get_info(pjsua_call_id call_id,
Benny Prijono9fc735d2006-05-28 14:58:12 +00001694 pjsua_call_info *info);
1695
1696
1697/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001698 * Attach application specific data to the call.
1699 *
1700 * @param call_id Call identification.
1701 * @param user_data Arbitrary data to be attached to the call.
1702 *
1703 * @return The user data.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001704 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001705PJ_DECL(pj_status_t) pjsua_call_set_user_data(pjsua_call_id call_id,
1706 void *user_data);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001707
1708
1709/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001710 * Get user data attached to the call.
1711 *
1712 * @param call_id Call identification.
1713 *
1714 * @return The user data.
Benny Prijono268ca612006-02-07 12:34:11 +00001715 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001716PJ_DECL(void*) pjsua_call_get_user_data(pjsua_call_id call_id);
Benny Prijono84126ab2006-02-09 09:30:09 +00001717
1718
1719/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001720 * Send response to incoming INVITE request.
1721 *
1722 * @param call_id Incoming call identification.
1723 * @param code Status code, (100-699).
1724 * @param reason Optional reason phrase. If NULL, default text
1725 * will be used.
1726 * @param msg_data Optional list of headers etc to be added to outgoing
1727 * response message.
1728 *
1729 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonoa91a0032006-02-26 21:23:45 +00001730 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001731PJ_DECL(pj_status_t) pjsua_call_answer(pjsua_call_id call_id,
1732 unsigned code,
1733 const pj_str_t *reason,
1734 const pjsua_msg_data *msg_data);
Benny Prijonoa91a0032006-02-26 21:23:45 +00001735
1736/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001737 * Hangup call by using method that is appropriate according to the
1738 * call state.
1739 *
1740 * @param call_id Call identification.
1741 * @param code Optional status code to be sent when we're rejecting
1742 * incoming call. If the value is zero, "603/Decline"
1743 * will be sent.
1744 * @param reason Optional reason phrase to be sent when we're rejecting
1745 * incoming call. If NULL, default text will be used.
1746 * @param msg_data Optional list of headers etc to be added to outgoing
1747 * request/response message.
1748 *
1749 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono26ff9062006-02-21 23:47:00 +00001750 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001751PJ_DECL(pj_status_t) pjsua_call_hangup(pjsua_call_id call_id,
1752 unsigned code,
1753 const pj_str_t *reason,
1754 const pjsua_msg_data *msg_data);
Benny Prijono26ff9062006-02-21 23:47:00 +00001755
1756
1757/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001758 * Put the specified call on hold.
1759 *
1760 * @param call_id Call identification.
1761 * @param msg_data Optional message components to be sent with
1762 * the request.
1763 *
1764 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono26ff9062006-02-21 23:47:00 +00001765 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001766PJ_DECL(pj_status_t) pjsua_call_set_hold(pjsua_call_id call_id,
1767 const pjsua_msg_data *msg_data);
Benny Prijono26ff9062006-02-21 23:47:00 +00001768
1769
1770/**
1771 * Send re-INVITE (to release hold).
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001772 *
1773 * @param call_id Call identification.
1774 * @param unhold If this argument is non-zero and the call is locally
1775 * held, this will release the local hold.
1776 * @param msg_data Optional message components to be sent with
1777 * the request.
1778 *
1779 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono26ff9062006-02-21 23:47:00 +00001780 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001781PJ_DECL(pj_status_t) pjsua_call_reinvite(pjsua_call_id call_id,
1782 pj_bool_t unhold,
1783 const pjsua_msg_data *msg_data);
Benny Prijono26ff9062006-02-21 23:47:00 +00001784
1785
1786/**
Benny Prijono053f5222006-11-11 16:16:04 +00001787 * Initiate call transfer to the specified address. This function will send
1788 * REFER request to instruct remote call party to initiate a new INVITE
1789 * session to the specified destination/target.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001790 *
Benny Prijono053f5222006-11-11 16:16:04 +00001791 * @param call_id The call id to be transfered.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001792 * @param dest Address of new target to be contacted.
1793 * @param msg_data Optional message components to be sent with
1794 * the request.
1795 *
1796 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono26ff9062006-02-21 23:47:00 +00001797 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001798PJ_DECL(pj_status_t) pjsua_call_xfer(pjsua_call_id call_id,
1799 const pj_str_t *dest,
1800 const pjsua_msg_data *msg_data);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001801
1802/**
Benny Prijono053f5222006-11-11 16:16:04 +00001803 * Flag to indicate that "Require: replaces" should not be put in the
1804 * outgoing INVITE request caused by REFER request created by
1805 * #pjsua_call_xfer_replaces().
1806 */
1807#define PJSUA_XFER_NO_REQUIRE_REPLACES 1
1808
1809/**
1810 * Initiate attended call transfer. This function will send REFER request
1811 * to instruct remote call party to initiate new INVITE session to the URL
1812 * of \a dest_call_id. The party at \a dest_call_id then should "replace"
1813 * the call with us with the new call from the REFER recipient.
1814 *
1815 * @param call_id The call id to be transfered.
1816 * @param dest_call_id The call id to be replaced.
1817 * @param options Application may specify PJSUA_XFER_NO_REQUIRE_REPLACES
1818 * to suppress the inclusion of "Require: replaces" in
1819 * the outgoing INVITE request created by the REFER
1820 * request.
1821 * @param msg_data Optional message components to be sent with
1822 * the request.
1823 *
1824 * @return PJ_SUCCESS on success, or the appropriate error code.
1825 */
1826PJ_DECL(pj_status_t) pjsua_call_xfer_replaces(pjsua_call_id call_id,
1827 pjsua_call_id dest_call_id,
1828 unsigned options,
1829 const pjsua_msg_data *msg_data);
1830
1831/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001832 * Send DTMF digits to remote using RFC 2833 payload formats.
1833 *
1834 * @param call_id Call identification.
1835 * @param digits DTMF digits to be sent.
1836 *
1837 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001838 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001839PJ_DECL(pj_status_t) pjsua_call_dial_dtmf(pjsua_call_id call_id,
Benny Prijono9fc735d2006-05-28 14:58:12 +00001840 const pj_str_t *digits);
Benny Prijono26ff9062006-02-21 23:47:00 +00001841
Benny Prijono26ff9062006-02-21 23:47:00 +00001842/**
Benny Prijonob0808372006-03-02 21:18:58 +00001843 * Send instant messaging inside INVITE session.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001844 *
1845 * @param call_id Call identification.
1846 * @param mime_type Optional MIME type. If NULL, then "text/plain" is
1847 * assumed.
1848 * @param content The message content.
1849 * @param msg_data Optional list of headers etc to be included in outgoing
1850 * request. The body descriptor in the msg_data is
1851 * ignored.
1852 * @param user_data Optional user data, which will be given back when
1853 * the IM callback is called.
1854 *
1855 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonob0808372006-03-02 21:18:58 +00001856 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001857PJ_DECL(pj_status_t) pjsua_call_send_im( pjsua_call_id call_id,
1858 const pj_str_t *mime_type,
1859 const pj_str_t *content,
1860 const pjsua_msg_data *msg_data,
1861 void *user_data);
Benny Prijonob0808372006-03-02 21:18:58 +00001862
1863
1864/**
1865 * Send IM typing indication inside INVITE session.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001866 *
1867 * @param call_id Call identification.
1868 * @param is_typing Non-zero to indicate to remote that local person is
1869 * currently typing an IM.
1870 * @param msg_data Optional list of headers etc to be included in outgoing
1871 * request.
1872 *
1873 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonob0808372006-03-02 21:18:58 +00001874 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001875PJ_DECL(pj_status_t) pjsua_call_send_typing_ind(pjsua_call_id call_id,
1876 pj_bool_t is_typing,
1877 const pjsua_msg_data*msg_data);
Benny Prijonob0808372006-03-02 21:18:58 +00001878
1879/**
Benny Prijono834aee32006-02-19 01:38:06 +00001880 * Terminate all calls.
1881 */
Benny Prijonodc39fe82006-05-26 12:17:46 +00001882PJ_DECL(void) pjsua_call_hangup_all(void);
Benny Prijono834aee32006-02-19 01:38:06 +00001883
1884
Benny Prijonob9b32ab2006-06-01 12:28:44 +00001885/**
1886 * Dump call and media statistics to string.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001887 *
1888 * @param call_id Call identification.
1889 * @param with_media Non-zero to include media information too.
1890 * @param buffer Buffer where the statistics are to be written to.
1891 * @param maxlen Maximum length of buffer.
1892 * @param indent Spaces for left indentation.
1893 *
1894 * @return PJ_SUCCESS on success.
Benny Prijonob9b32ab2006-06-01 12:28:44 +00001895 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001896PJ_DECL(pj_status_t) pjsua_call_dump(pjsua_call_id call_id,
1897 pj_bool_t with_media,
1898 char *buffer,
1899 unsigned maxlen,
1900 const char *indent);
Benny Prijonob9b32ab2006-06-01 12:28:44 +00001901
Benny Prijono9fc735d2006-05-28 14:58:12 +00001902/**
Benny Prijono312aff92006-06-17 04:08:30 +00001903 * @}
Benny Prijono9fc735d2006-05-28 14:58:12 +00001904 */
Benny Prijono834aee32006-02-19 01:38:06 +00001905
1906
1907/*****************************************************************************
Benny Prijono312aff92006-06-17 04:08:30 +00001908 * BUDDY API
Benny Prijono834aee32006-02-19 01:38:06 +00001909 */
1910
Benny Prijono312aff92006-06-17 04:08:30 +00001911
1912/**
1913 * @defgroup PJSUA_LIB_BUDDY Buddy, Presence, and Instant Messaging
1914 * @ingroup PJSUA_LIB
1915 * @brief Buddy management, buddy's presence, and instant messaging.
1916 * @{
1917 */
1918
1919/**
1920 * Max buddies in buddy list.
1921 */
1922#ifndef PJSUA_MAX_BUDDIES
1923# define PJSUA_MAX_BUDDIES 256
1924#endif
1925
1926
1927/**
1928 * Buddy configuration.
1929 */
1930typedef struct pjsua_buddy_config
1931{
1932 /**
1933 * Buddy URL or name address.
1934 */
1935 pj_str_t uri;
1936
1937 /**
1938 * Specify whether presence subscription should start immediately.
1939 */
1940 pj_bool_t subscribe;
1941
1942} pjsua_buddy_config;
1943
1944
1945/**
1946 * Buddy's online status.
1947 */
1948typedef enum pjsua_buddy_status
1949{
1950 /**
1951 * Online status is unknown (possibly because no presence subscription
1952 * has been established).
1953 */
1954 PJSUA_BUDDY_STATUS_UNKNOWN,
1955
1956 /**
1957 * Buddy is known to be offline.
1958 */
1959 PJSUA_BUDDY_STATUS_ONLINE,
1960
1961 /**
1962 * Buddy is offline.
1963 */
1964 PJSUA_BUDDY_STATUS_OFFLINE,
1965
1966} pjsua_buddy_status;
1967
1968
1969
1970/**
1971 * Buddy info.
1972 */
1973typedef struct pjsua_buddy_info
1974{
1975 /**
1976 * The buddy ID.
1977 */
1978 pjsua_buddy_id id;
1979
1980 /**
1981 * The full URI of the buddy, as specified in the configuration.
1982 */
1983 pj_str_t uri;
1984
1985 /**
1986 * Buddy's Contact, only available when presence subscription has
1987 * been established to the buddy.
1988 */
1989 pj_str_t contact;
1990
1991 /**
1992 * Buddy's online status.
1993 */
1994 pjsua_buddy_status status;
1995
1996 /**
1997 * Text to describe buddy's online status.
1998 */
1999 pj_str_t status_text;
2000
2001 /**
2002 * Flag to indicate that we should monitor the presence information for
2003 * this buddy (normally yes, unless explicitly disabled).
2004 */
2005 pj_bool_t monitor_pres;
2006
2007 /**
2008 * Internal buffer.
2009 */
2010 char buf_[256];
2011
2012} pjsua_buddy_info;
2013
2014
Benny Prijono834aee32006-02-19 01:38:06 +00002015/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002016 * Get total number of buddies.
2017 *
2018 * @return Number of buddies.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002019 */
2020PJ_DECL(unsigned) pjsua_get_buddy_count(void);
2021
2022
2023/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002024 * Check if buddy ID is valid.
2025 *
2026 * @param buddy_id Buddy ID to check.
2027 *
2028 * @return Non-zero if buddy ID is valid.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002029 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002030PJ_DECL(pj_bool_t) pjsua_buddy_is_valid(pjsua_buddy_id buddy_id);
2031
2032
2033/**
2034 * Enum buddy IDs.
2035 *
2036 * @param ids Array of ids to be initialized.
2037 * @param count On input, specifies max elements in the array.
2038 * On return, it contains actual number of elements
2039 * that have been initialized.
2040 *
2041 * @return PJ_SUCCESS on success, or the appropriate error code.
2042 */
2043PJ_DECL(pj_status_t) pjsua_enum_buddies(pjsua_buddy_id ids[],
2044 unsigned *count);
2045
2046/**
2047 * Get detailed buddy info.
2048 *
2049 * @param buddy_id The buddy identification.
2050 * @param info Pointer to receive information about buddy.
2051 *
2052 * @return PJ_SUCCESS on success, or the appropriate error code.
2053 */
2054PJ_DECL(pj_status_t) pjsua_buddy_get_info(pjsua_buddy_id buddy_id,
Benny Prijono9fc735d2006-05-28 14:58:12 +00002055 pjsua_buddy_info *info);
2056
2057/**
2058 * Add new buddy.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002059 *
2060 * @param cfg Buddy configuration.
2061 * @param p_buddy_id Pointer to receive buddy ID.
2062 *
2063 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002064 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002065PJ_DECL(pj_status_t) pjsua_buddy_add(const pjsua_buddy_config *cfg,
2066 pjsua_buddy_id *p_buddy_id);
Benny Prijono8b1889b2006-06-06 18:40:40 +00002067
2068
2069/**
2070 * Delete buddy.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002071 *
2072 * @param buddy_id Buddy identification.
2073 *
2074 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono8b1889b2006-06-06 18:40:40 +00002075 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002076PJ_DECL(pj_status_t) pjsua_buddy_del(pjsua_buddy_id buddy_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002077
2078
2079/**
2080 * Enable/disable buddy's presence monitoring.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002081 *
2082 * @param buddy_id Buddy identification.
2083 * @param subscribe Specify non-zero to activate presence subscription to
2084 * the specified buddy.
2085 *
2086 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002087 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002088PJ_DECL(pj_status_t) pjsua_buddy_subscribe_pres(pjsua_buddy_id buddy_id,
2089 pj_bool_t subscribe);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002090
2091
2092/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002093 * Dump presence subscriptions to log file.
2094 *
2095 * @param verbose Yes or no.
Benny Prijono834aee32006-02-19 01:38:06 +00002096 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002097PJ_DECL(void) pjsua_pres_dump(pj_bool_t verbose);
Benny Prijono834aee32006-02-19 01:38:06 +00002098
2099
Benny Prijonob0808372006-03-02 21:18:58 +00002100/**
2101 * The MESSAGE method (defined in pjsua_im.c)
2102 */
2103extern const pjsip_method pjsip_message_method;
2104
2105
Benny Prijonob0808372006-03-02 21:18:58 +00002106
2107/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002108 * Send instant messaging outside dialog, using the specified account for
2109 * route set and authentication.
2110 *
2111 * @param acc_id Account ID to be used to send the request.
2112 * @param to Remote URI.
2113 * @param mime_type Optional MIME type. If NULL, then "text/plain" is
2114 * assumed.
2115 * @param content The message content.
2116 * @param msg_data Optional list of headers etc to be included in outgoing
2117 * request. The body descriptor in the msg_data is
2118 * ignored.
2119 * @param user_data Optional user data, which will be given back when
2120 * the IM callback is called.
2121 *
2122 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonob0808372006-03-02 21:18:58 +00002123 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002124PJ_DECL(pj_status_t) pjsua_im_send(pjsua_acc_id acc_id,
2125 const pj_str_t *to,
2126 const pj_str_t *mime_type,
2127 const pj_str_t *content,
2128 const pjsua_msg_data *msg_data,
2129 void *user_data);
Benny Prijonob0808372006-03-02 21:18:58 +00002130
2131
2132/**
2133 * Send typing indication outside dialog.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002134 *
2135 * @param acc_id Account ID to be used to send the request.
2136 * @param to Remote URI.
2137 * @param is_typing If non-zero, it tells remote person that local person
2138 * is currently composing an IM.
2139 * @param msg_data Optional list of headers etc to be added to outgoing
2140 * request.
2141 *
2142 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonob0808372006-03-02 21:18:58 +00002143 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002144PJ_DECL(pj_status_t) pjsua_im_typing(pjsua_acc_id acc_id,
2145 const pj_str_t *to,
2146 pj_bool_t is_typing,
2147 const pjsua_msg_data *msg_data);
Benny Prijonob0808372006-03-02 21:18:58 +00002148
2149
Benny Prijonof3195072006-02-14 21:15:30 +00002150
Benny Prijono312aff92006-06-17 04:08:30 +00002151/**
2152 * @}
Benny Prijono9fc735d2006-05-28 14:58:12 +00002153 */
2154
Benny Prijono312aff92006-06-17 04:08:30 +00002155
2156/*****************************************************************************
2157 * MEDIA API
2158 */
2159
2160
2161/**
2162 * @defgroup PJSUA_LIB_MEDIA Media
2163 * @ingroup PJSUA_LIB
2164 * @brief Media manipulation.
2165 * @{
2166 *
2167 * PJSUA has rather powerful media features, which are built around the
2168 * PJMEDIA conference bridge. Basically, all media termination (such as
2169 * calls, file players, file recorders, sound device, tone generators, etc)
2170 * are terminated in the conference bridge, and application can manipulate
2171 * the interconnection between these terminations freely. If more than
2172 * one media terminations are terminated in the same slot, the conference
2173 * bridge will mix the signal automatically.
2174 *
2175 * Application connects one media termination/slot to another by calling
2176 * #pjsua_conf_connect() function. This will establish <b>unidirectional</b>
2177 * media flow from the source termination to the sink termination. For
2178 * example, to stream a WAV file to remote call, application may use
2179 * the following steps:
2180 *
2181 \code
2182
2183 pj_status_t stream_to_call( pjsua_call_id call_id )
2184 {
2185 pjsua_player_id player_id;
2186
2187 status = pjsua_player_create("mysong.wav", 0, NULL, &player_id);
2188 if (status != PJ_SUCCESS)
2189 return status;
2190
2191 status = pjsua_conf_connect( pjsua_player_get_conf_port(),
2192 pjsua_call_get_conf_port() );
2193 }
2194 \endcode
2195 *
2196 *
2197 * Other features of PJSUA media:
2198 * - efficient N to M interconnections between media terminations.
2199 * - media termination can be connected to itself to create loopback
2200 * media.
2201 * - the media termination may have different clock rates, and resampling
2202 * will be done automatically by conference bridge.
2203 * - media terminations may also have different frame time; the
2204 * conference bridge will perform the necessary bufferring to adjust
2205 * the difference between terminations.
2206 * - interconnections are removed automatically when media termination
2207 * is removed from the bridge.
2208 * - sound device may be changed even when there are active media
2209 * interconnections.
2210 * - correctly report call's media quality (in #pjsua_call_dump()) from
2211 * RTCP packet exchange.
2212 */
2213
2214/**
2215 * Max ports in the conference bridge.
2216 */
2217#ifndef PJSUA_MAX_CONF_PORTS
2218# define PJSUA_MAX_CONF_PORTS 254
2219#endif
2220
Benny Prijono70972992006-08-05 11:13:58 +00002221#define PJSUA_DEFAULT_CLOCK_RATE 16000
2222#define PJSUA_DEFAULT_CODEC_QUALITY 5
2223#define PJSUA_DEFAULT_ILBC_MODE 20
Benny Prijono1d9b9a42006-09-25 13:40:12 +00002224#define PJSUA_DEFAULT_EC_TAIL_LEN 0
Benny Prijono312aff92006-06-17 04:08:30 +00002225
2226
2227/**
2228 * Media configuration.
2229 */
2230struct pjsua_media_config
2231{
2232 /**
2233 * Clock rate to be applied to the conference bridge.
2234 * If value is zero, default clock rate will be used (16KHz).
2235 */
2236 unsigned clock_rate;
2237
2238 /**
2239 * Specify maximum number of media ports to be created in the
2240 * conference bridge. Since all media terminate in the bridge
2241 * (calls, file player, file recorder, etc), the value must be
2242 * large enough to support all of them. However, the larger
2243 * the value, the more computations are performed.
2244 */
2245 unsigned max_media_ports;
2246
2247 /**
2248 * Specify whether the media manager should manage its own
2249 * ioqueue for the RTP/RTCP sockets. If yes, ioqueue will be created
2250 * and at least one worker thread will be created too. If no,
2251 * the RTP/RTCP sockets will share the same ioqueue as SIP sockets,
2252 * and no worker thread is needed.
2253 *
2254 * Normally application would say yes here, unless it wants to
2255 * run everything from a single thread.
2256 */
2257 pj_bool_t has_ioqueue;
2258
2259 /**
2260 * Specify the number of worker threads to handle incoming RTP
2261 * packets. A value of one is recommended for most applications.
2262 */
2263 unsigned thread_cnt;
2264
Benny Prijono0498d902006-06-19 14:49:14 +00002265 /**
2266 * Media quality, 0-10, according to this table:
Benny Prijono7ca96da2006-08-07 12:11:40 +00002267 * 5-10: resampling use large filter,
2268 * 3-4: resampling use small filter,
Benny Prijono0498d902006-06-19 14:49:14 +00002269 * 1-2: resampling use linear.
2270 * The media quality also sets speex codec quality/complexity to the
2271 * number.
2272 *
Benny Prijono70972992006-08-05 11:13:58 +00002273 * Default: 5 (PJSUA_DEFAULT_CODEC_QUALITY).
Benny Prijono0498d902006-06-19 14:49:14 +00002274 */
2275 unsigned quality;
Benny Prijono0a12f002006-07-26 17:05:39 +00002276
2277 /**
2278 * Specify default ptime.
2279 *
2280 * Default: 0 (codec specific)
2281 */
2282 unsigned ptime;
2283
2284 /**
2285 * Disable VAD?
2286 *
2287 * Default: 0 (no (meaning VAD is enabled))
2288 */
2289 pj_bool_t no_vad;
Benny Prijono00cae612006-07-31 15:19:36 +00002290
2291 /**
2292 * iLBC mode (20 or 30).
2293 *
Benny Prijono70972992006-08-05 11:13:58 +00002294 * Default: 20 (PJSUA_DEFAULT_ILBC_MODE)
Benny Prijono00cae612006-07-31 15:19:36 +00002295 */
2296 unsigned ilbc_mode;
2297
2298 /**
2299 * Percentage of RTP packet to drop in TX direction
2300 * (to simulate packet lost).
2301 *
2302 * Default: 0
2303 */
2304 unsigned tx_drop_pct;
2305
2306 /**
2307 * Percentage of RTP packet to drop in RX direction
2308 * (to simulate packet lost).
2309 *
2310 * Default: 0
2311 */
2312 unsigned rx_drop_pct;
2313
Benny Prijonoc8e24a12006-08-02 18:22:22 +00002314 /**
Benny Prijono5da50432006-08-07 10:24:52 +00002315 * Echo canceller options (see #pjmedia_echo_create())
2316 *
2317 * Default: 0.
2318 */
2319 unsigned ec_options;
2320
2321 /**
Benny Prijonoc8e24a12006-08-02 18:22:22 +00002322 * Echo canceller tail length, in miliseconds.
2323 *
Benny Prijono669643c2006-09-20 20:02:18 +00002324 * Default: PJSUA_DEFAULT_EC_TAIL_LEN
Benny Prijonoc8e24a12006-08-02 18:22:22 +00002325 */
2326 unsigned ec_tail_len;
Benny Prijono1d0ca0c2006-11-21 09:06:47 +00002327
2328 /**
2329 * Jitter buffer initial prefetch delay in msec. The value must be
2330 * between jb_min_pre and jb_max_pre below.
2331 *
2332 * Default: -1 (to use default stream settings, currently 150 msec)
2333 */
2334 int jb_init;
2335
2336 /**
2337 * Jitter buffer minimum prefetch delay in msec.
2338 *
2339 * Default: -1 (to use default stream settings, currently 60 msec)
2340 */
2341 int jb_min_pre;
2342
2343 /**
2344 * Jitter buffer maximum prefetch delay in msec.
2345 *
2346 * Default: -1 (to use default stream settings, currently 240 msec)
2347 */
2348 int jb_max_pre;
2349
2350 /**
2351 * Set maximum delay that can be accomodated by the jitter buffer msec.
2352 *
2353 * Default: -1 (to use default stream settings, currently 360 msec)
2354 */
2355 int jb_max;
2356
Benny Prijono312aff92006-06-17 04:08:30 +00002357};
2358
2359
2360/**
2361 * Use this function to initialize media config.
2362 *
2363 * @param cfg The media config to be initialized.
2364 */
2365PJ_INLINE(void) pjsua_media_config_default(pjsua_media_config *cfg)
2366{
Benny Prijonoac623b32006-07-03 15:19:31 +00002367 pj_bzero(cfg, sizeof(*cfg));
Benny Prijono312aff92006-06-17 04:08:30 +00002368
Benny Prijono70972992006-08-05 11:13:58 +00002369 cfg->clock_rate = PJSUA_DEFAULT_CLOCK_RATE;
Benny Prijono312aff92006-06-17 04:08:30 +00002370 cfg->max_media_ports = 32;
2371 cfg->has_ioqueue = PJ_TRUE;
2372 cfg->thread_cnt = 1;
Benny Prijono70972992006-08-05 11:13:58 +00002373 cfg->quality = PJSUA_DEFAULT_CODEC_QUALITY;
2374 cfg->ilbc_mode = PJSUA_DEFAULT_ILBC_MODE;
2375 cfg->ec_tail_len = PJSUA_DEFAULT_EC_TAIL_LEN;
Benny Prijono1d0ca0c2006-11-21 09:06:47 +00002376 cfg->jb_init = cfg->jb_min_pre = cfg->jb_max_pre = cfg->jb_max = -1;
Benny Prijono312aff92006-06-17 04:08:30 +00002377}
2378
2379
2380
2381/**
2382 * Codec config.
2383 */
2384typedef struct pjsua_codec_info
2385{
2386 /**
2387 * Codec unique identification.
2388 */
2389 pj_str_t codec_id;
2390
2391 /**
2392 * Codec priority (integer 0-255).
2393 */
2394 pj_uint8_t priority;
2395
2396 /**
2397 * Internal buffer.
2398 */
2399 char buf_[32];
2400
2401} pjsua_codec_info;
2402
2403
2404/**
2405 * Conference port info.
2406 */
2407typedef struct pjsua_conf_port_info
2408{
2409 /** Conference port number. */
2410 pjsua_conf_port_id slot_id;
2411
2412 /** Port name. */
2413 pj_str_t name;
2414
2415 /** Clock rate. */
2416 unsigned clock_rate;
2417
2418 /** Number of channels. */
2419 unsigned channel_count;
2420
2421 /** Samples per frame */
2422 unsigned samples_per_frame;
2423
2424 /** Bits per sample */
2425 unsigned bits_per_sample;
2426
2427 /** Number of listeners in the array. */
2428 unsigned listener_cnt;
2429
2430 /** Array of listeners (in other words, ports where this port is
2431 * transmitting to.
2432 */
2433 pjsua_conf_port_id listeners[PJSUA_MAX_CONF_PORTS];
2434
2435} pjsua_conf_port_info;
2436
2437
2438/**
2439 * This structure holds information about custom media transport to
2440 * be registered to pjsua.
2441 */
2442typedef struct pjsua_media_transport
2443{
2444 /**
2445 * Media socket information containing the address information
2446 * of the RTP and RTCP socket.
2447 */
2448 pjmedia_sock_info skinfo;
2449
2450 /**
2451 * The media transport instance.
2452 */
2453 pjmedia_transport *transport;
2454
2455} pjsua_media_transport;
2456
2457
2458
2459
Benny Prijono9fc735d2006-05-28 14:58:12 +00002460/**
2461 * Get maxinum number of conference ports.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002462 *
2463 * @return Maximum number of ports in the conference bridge.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002464 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002465PJ_DECL(unsigned) pjsua_conf_get_max_ports(void);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002466
2467
2468/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002469 * Get current number of active ports in the bridge.
2470 *
2471 * @return The number.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002472 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002473PJ_DECL(unsigned) pjsua_conf_get_active_ports(void);
2474
2475
2476/**
2477 * Enumerate all conference ports.
2478 *
2479 * @param id Array of conference port ID to be initialized.
2480 * @param count On input, specifies max elements in the array.
2481 * On return, it contains actual number of elements
2482 * that have been initialized.
2483 *
2484 * @return PJ_SUCCESS on success, or the appropriate error code.
2485 */
2486PJ_DECL(pj_status_t) pjsua_enum_conf_ports(pjsua_conf_port_id id[],
2487 unsigned *count);
Benny Prijono8b1889b2006-06-06 18:40:40 +00002488
2489
2490/**
2491 * Get information about the specified conference port
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002492 *
2493 * @param id Port identification.
2494 * @param info Pointer to store the port info.
2495 *
2496 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono8b1889b2006-06-06 18:40:40 +00002497 */
2498PJ_DECL(pj_status_t) pjsua_conf_get_port_info( pjsua_conf_port_id id,
2499 pjsua_conf_port_info *info);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002500
2501
2502/**
Benny Prijonoe909eac2006-07-27 22:04:56 +00002503 * Add arbitrary media port to PJSUA's conference bridge. Application
2504 * can use this function to add the media port that it creates. For
2505 * media ports that are created by PJSUA-LIB (such as calls, file player,
2506 * or file recorder), PJSUA-LIB will automatically add the port to
2507 * the bridge.
2508 *
2509 * @param pool Pool to use.
2510 * @param port Media port to be added to the bridge.
2511 * @param p_id Optional pointer to receive the conference
2512 * slot id.
2513 *
2514 * @return PJ_SUCCESS on success, or the appropriate error code.
2515 */
2516PJ_DECL(pj_status_t) pjsua_conf_add_port(pj_pool_t *pool,
2517 pjmedia_port *port,
2518 pjsua_conf_port_id *p_id);
2519
2520
2521/**
2522 * Remove arbitrary slot from the conference bridge. Application should only
2523 * call this function if it registered the port manually.
2524 *
2525 * @param id The slot id of the port to be removed.
2526 *
2527 * @return PJ_SUCCESS on success, or the appropriate error code.
2528 */
2529PJ_DECL(pj_status_t) pjsua_conf_remove_port(pjsua_conf_port_id id);
2530
2531
2532/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002533 * Establish unidirectional media flow from souce to sink. One source
2534 * may transmit to multiple destinations/sink. And if multiple
2535 * sources are transmitting to the same sink, the media will be mixed
2536 * together. Source and sink may refer to the same ID, effectively
2537 * looping the media.
2538 *
2539 * If bidirectional media flow is desired, application needs to call
2540 * this function twice, with the second one having the arguments
2541 * reversed.
2542 *
2543 * @param source Port ID of the source media/transmitter.
2544 * @param sink Port ID of the destination media/received.
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_conf_connect(pjsua_conf_port_id source,
2549 pjsua_conf_port_id sink);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002550
2551
2552/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002553 * Disconnect media flow from the source to destination port.
2554 *
2555 * @param source Port ID of the source media/transmitter.
2556 * @param sink Port ID of the destination media/received.
2557 *
2558 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002559 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002560PJ_DECL(pj_status_t) pjsua_conf_disconnect(pjsua_conf_port_id source,
2561 pjsua_conf_port_id sink);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002562
2563
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002564/*****************************************************************************
2565 * File player.
2566 */
2567
Benny Prijono9fc735d2006-05-28 14:58:12 +00002568/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002569 * Create a file player, and automatically connect this player to
2570 * the conference bridge.
2571 *
2572 * @param filename The filename to be played. Currently only
Benny Prijono312aff92006-06-17 04:08:30 +00002573 * WAV files are supported, and the WAV file MUST be
2574 * formatted as 16bit PCM mono/single channel (any
2575 * clock rate is supported).
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002576 * @param options Options (currently zero).
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002577 * @param p_id Pointer to receive player ID.
2578 *
2579 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002580 */
2581PJ_DECL(pj_status_t) pjsua_player_create(const pj_str_t *filename,
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002582 unsigned options,
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002583 pjsua_player_id *p_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002584
2585
2586/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002587 * Get conference port ID associated with player.
2588 *
2589 * @param id The file player ID.
2590 *
2591 * @return Conference port ID associated with this player.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002592 */
Benny Prijono8b1889b2006-06-06 18:40:40 +00002593PJ_DECL(pjsua_conf_port_id) pjsua_player_get_conf_port(pjsua_player_id id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002594
2595
2596/**
2597 * Set playback position.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002598 *
2599 * @param id The file player ID.
2600 * @param samples The playback position, in samples. Application can
2601 * specify zero to re-start the playback.
2602 *
2603 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002604 */
2605PJ_DECL(pj_status_t) pjsua_player_set_pos(pjsua_player_id id,
2606 pj_uint32_t samples);
2607
2608
2609/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002610 * Close the file, remove the player from the bridge, and free
2611 * resources associated with the file player.
2612 *
2613 * @param id The file player ID.
2614 *
2615 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002616 */
2617PJ_DECL(pj_status_t) pjsua_player_destroy(pjsua_player_id id);
2618
2619
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002620/*****************************************************************************
2621 * File recorder.
2622 */
Benny Prijono9fc735d2006-05-28 14:58:12 +00002623
2624/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002625 * Create a file recorder, and automatically connect this recorder to
Benny Prijono8f310522006-10-20 11:08:49 +00002626 * the conference bridge. The recorder currently supports recording WAV file,
2627 * and on Windows, MP3 file. The type of the recorder to use is determined
2628 * by the extension of the file (e.g. ".wav" or ".mp3").
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002629 *
Benny Prijonob3cdb2b2006-10-19 15:49:47 +00002630 * @param filename Output file name. The function will determine the
2631 * default format to be used based on the file extension.
2632 * Currently ".wav" is supported on all platforms, and
2633 * also ".mp3" is support on Windows.
Benny Prijono8f310522006-10-20 11:08:49 +00002634 * @param enc_type Optionally specify the type of encoder to be used to
2635 * compress the media, if the file can support different
2636 * encodings. This value must be zero for now.
2637 * @param enc_param Optionally specify codec specific parameter to be
2638 * passed to the file writer. For .MP3 recorder, this
2639 * can point to pjmedia_mp3_encoder_option structure to
2640 * specify additional settings for the .mp3 recorder.
2641 * For .WAV recorder, this value must be NULL.
2642 * @param max_size Maximum file size. Specify zero or -1 to remove size
2643 * limitation. This value must be zero or -1 for now.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002644 * @param options Optional options.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002645 * @param p_id Pointer to receive the recorder instance.
2646 *
2647 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002648 */
2649PJ_DECL(pj_status_t) pjsua_recorder_create(const pj_str_t *filename,
Benny Prijono8f310522006-10-20 11:08:49 +00002650 unsigned enc_type,
2651 void *enc_param,
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002652 pj_ssize_t max_size,
2653 unsigned options,
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002654 pjsua_recorder_id *p_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002655
2656
2657/**
2658 * Get conference port associated with recorder.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002659 *
2660 * @param id The recorder ID.
2661 *
2662 * @return Conference port ID associated with this recorder.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002663 */
Benny Prijono8b1889b2006-06-06 18:40:40 +00002664PJ_DECL(pjsua_conf_port_id) pjsua_recorder_get_conf_port(pjsua_recorder_id id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002665
2666
2667/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002668 * Destroy recorder (this will complete recording).
2669 *
2670 * @param id The recorder ID.
2671 *
2672 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002673 */
2674PJ_DECL(pj_status_t) pjsua_recorder_destroy(pjsua_recorder_id id);
2675
2676
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002677/*****************************************************************************
2678 * Sound devices.
2679 */
2680
Benny Prijono9fc735d2006-05-28 14:58:12 +00002681/**
2682 * Enum sound devices.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002683 *
2684 * @param info Array of info to be initialized.
2685 * @param count On input, specifies max elements in the array.
2686 * On return, it contains actual number of elements
2687 * that have been initialized.
2688 *
2689 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002690 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002691PJ_DECL(pj_status_t) pjsua_enum_snd_devs(pjmedia_snd_dev_info info[],
2692 unsigned *count);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002693
2694
Benny Prijonoa3cbb1c2006-08-25 12:41:05 +00002695
2696/**
2697 * Get currently active sound devices. If sound devices has not been created
2698 * (for example when pjsua_start() is not called), it is possible that
2699 * the function returns PJ_SUCCESS with -1 as device IDs.
2700 *
2701 * @param capture_dev On return it will be filled with device ID of the
2702 * capture device.
2703 * @param playback_dev On return it will be filled with device ID of the
2704 * device ID of the playback device.
2705 *
2706 * @return PJ_SUCCESS on success, or the appropriate error code.
2707 */
2708PJ_DECL(pj_status_t) pjsua_get_snd_dev(int *capture_dev,
2709 int *playback_dev);
2710
2711
Benny Prijono9fc735d2006-05-28 14:58:12 +00002712/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002713 * Select or change sound device. Application may call this function at
2714 * any time to replace current sound device.
2715 *
2716 * @param capture_dev Device ID of the capture device.
2717 * @param playback_dev Device ID of the playback device.
2718 *
2719 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002720 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002721PJ_DECL(pj_status_t) pjsua_set_snd_dev(int capture_dev,
2722 int playback_dev);
2723
2724
2725/**
2726 * Set pjsua to use null sound device. The null sound device only provides
2727 * the timing needed by the conference bridge, and will not interract with
2728 * any hardware.
2729 *
2730 * @return PJ_SUCCESS on success, or the appropriate error code.
2731 */
2732PJ_DECL(pj_status_t) pjsua_set_null_snd_dev(void);
2733
2734
Benny Prijonoe909eac2006-07-27 22:04:56 +00002735/**
2736 * Disconnect the main conference bridge from any sound devices, and let
2737 * application connect the bridge to it's own sound device/master port.
2738 *
2739 * @return The port interface of the conference bridge,
2740 * so that application can connect this to it's own
2741 * sound device or master port.
2742 */
2743PJ_DECL(pjmedia_port*) pjsua_set_no_snd_dev(void);
2744
2745
Benny Prijonof20687a2006-08-04 18:27:19 +00002746/**
Benny Prijono22dfe592006-08-06 12:07:13 +00002747 * Configure the echo canceller tail length of the sound port.
Benny Prijonof20687a2006-08-04 18:27:19 +00002748 *
2749 * @param tail_ms The tail length, in miliseconds. Set to zero to
2750 * disable AEC.
Benny Prijono5da50432006-08-07 10:24:52 +00002751 * @param options Options to be passed to #pjmedia_echo_create().
2752 * Normally the value should be zero.
Benny Prijonof20687a2006-08-04 18:27:19 +00002753 *
2754 * @return PJ_SUCCESS on success.
2755 */
Benny Prijono5da50432006-08-07 10:24:52 +00002756PJ_DECL(pj_status_t) pjsua_set_ec(unsigned tail_ms, unsigned options);
Benny Prijonof20687a2006-08-04 18:27:19 +00002757
2758
2759/**
Benny Prijono22dfe592006-08-06 12:07:13 +00002760 * Get current echo canceller tail length.
Benny Prijonof20687a2006-08-04 18:27:19 +00002761 *
2762 * @param p_tail_ms Pointer to receive the tail length, in miliseconds.
2763 * If AEC is disabled, the value will be zero.
2764 *
2765 * @return PJ_SUCCESS on success.
2766 */
Benny Prijono22dfe592006-08-06 12:07:13 +00002767PJ_DECL(pj_status_t) pjsua_get_ec_tail(unsigned *p_tail_ms);
Benny Prijonof20687a2006-08-04 18:27:19 +00002768
2769
2770
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002771/*****************************************************************************
2772 * Codecs.
2773 */
2774
2775/**
2776 * Enum all supported codecs in the system.
2777 *
2778 * @param id Array of ID to be initialized.
2779 * @param count On input, specifies max elements in the array.
2780 * On return, it contains actual number of elements
2781 * that have been initialized.
2782 *
2783 * @return PJ_SUCCESS on success, or the appropriate error code.
2784 */
2785PJ_DECL(pj_status_t) pjsua_enum_codecs( pjsua_codec_info id[],
2786 unsigned *count );
2787
2788
2789/**
2790 * Change codec priority.
2791 *
2792 * @param id Codec ID.
2793 * @param priority Codec priority, 0-255, where zero means to disable
2794 * the codec.
2795 *
2796 * @return PJ_SUCCESS on success, or the appropriate error code.
2797 */
2798PJ_DECL(pj_status_t) pjsua_codec_set_priority( const pj_str_t *id,
2799 pj_uint8_t priority );
2800
2801
2802/**
2803 * Get codec parameters.
2804 *
2805 * @param id Codec ID.
2806 * @param param Structure to receive codec parameters.
2807 *
2808 * @return PJ_SUCCESS on success, or the appropriate error code.
2809 */
2810PJ_DECL(pj_status_t) pjsua_codec_get_param( const pj_str_t *id,
2811 pjmedia_codec_param *param );
2812
2813
2814/**
2815 * Set codec parameters.
2816 *
2817 * @param id Codec ID.
2818 * @param param Codec parameter to set.
2819 *
2820 * @return PJ_SUCCESS on success, or the appropriate error code.
2821 */
2822PJ_DECL(pj_status_t) pjsua_codec_set_param( const pj_str_t *id,
2823 const pjmedia_codec_param *param);
2824
2825
2826
Benny Prijono9fc735d2006-05-28 14:58:12 +00002827
Benny Prijono312aff92006-06-17 04:08:30 +00002828/**
2829 * Create UDP media transports for all the calls. This function creates
2830 * one UDP media transport for each call.
Benny Prijonof3195072006-02-14 21:15:30 +00002831 *
Benny Prijono312aff92006-06-17 04:08:30 +00002832 * @param cfg Media transport configuration. The "port" field in the
2833 * configuration is used as the start port to bind the
2834 * sockets.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002835 *
2836 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonof3195072006-02-14 21:15:30 +00002837 */
Benny Prijono312aff92006-06-17 04:08:30 +00002838PJ_DECL(pj_status_t)
2839pjsua_media_transports_create(const pjsua_transport_config *cfg);
Benny Prijonof3195072006-02-14 21:15:30 +00002840
Benny Prijonodc39fe82006-05-26 12:17:46 +00002841
2842/**
Benny Prijono312aff92006-06-17 04:08:30 +00002843 * Register custom media transports to be used by calls. There must
2844 * enough media transports for all calls.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002845 *
Benny Prijono312aff92006-06-17 04:08:30 +00002846 * @param tp The media transport array.
2847 * @param count Number of elements in the array. This number MUST
2848 * match the number of maximum calls configured when
2849 * pjsua is created.
2850 * @param auto_delete Flag to indicate whether the transports should be
2851 * destroyed when pjsua is shutdown.
2852 *
2853 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonodc39fe82006-05-26 12:17:46 +00002854 */
Benny Prijono312aff92006-06-17 04:08:30 +00002855PJ_DECL(pj_status_t)
2856pjsua_media_transports_attach( pjsua_media_transport tp[],
2857 unsigned count,
2858 pj_bool_t auto_delete);
Benny Prijonodc39fe82006-05-26 12:17:46 +00002859
2860
Benny Prijono312aff92006-06-17 04:08:30 +00002861/**
2862 * @}
2863 */
2864
Benny Prijonof3195072006-02-14 21:15:30 +00002865
Benny Prijono268ca612006-02-07 12:34:11 +00002866
Benny Prijono1a01ad32006-02-07 21:13:28 +00002867PJ_END_DECL
2868
Benny Prijonof3195072006-02-14 21:15:30 +00002869
Benny Prijono312aff92006-06-17 04:08:30 +00002870/**
2871 * @}
2872 */
2873
2874
Benny Prijono268ca612006-02-07 12:34:11 +00002875#endif /* __PJSUA_H__ */