blob: b950be81ebc2578bfe945af2e37ebe9ec4e0dd25 [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{
254 pj_memset(cfg, 0, sizeof(*cfg));
255
256 cfg->msg_logging = PJ_TRUE;
257 cfg->level = 5;
258 cfg->console_level = 4;
259 cfg->decor = PJ_LOG_HAS_SENDER | PJ_LOG_HAS_TIME |
260 PJ_LOG_HAS_MICRO_SEC | PJ_LOG_HAS_NEWLINE;
261}
262
263/**
264 * Use this function to duplicate logging config.
265 *
266 * @param pool Pool to use.
267 * @param dst Destination config.
268 * @param src Source config.
269 */
270PJ_INLINE(void) pjsua_logging_config_dup(pj_pool_t *pool,
271 pjsua_logging_config *dst,
272 const pjsua_logging_config *src)
273{
274 pj_memcpy(dst, src, sizeof(*src));
275 pj_strdup_with_null(pool, &dst->log_filename, &src->log_filename);
276}
277
278
Benny Prijonodc39fe82006-05-26 12:17:46 +0000279
280/**
281 * Application callbacks.
282 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000283typedef struct pjsua_callback
Benny Prijonodc39fe82006-05-26 12:17:46 +0000284{
285 /**
Benny Prijono9fc735d2006-05-28 14:58:12 +0000286 * Notify application when invite state has changed.
287 * Application may then query the call info to get the
288 * detail call states.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000289 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000290 void (*on_call_state)(pjsua_call_id call_id, pjsip_event *e);
Benny Prijonodc39fe82006-05-26 12:17:46 +0000291
292 /**
Benny Prijono8b1889b2006-06-06 18:40:40 +0000293 * Notify application on incoming call.
294 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000295 void (*on_incoming_call)(pjsua_acc_id acc_id, pjsua_call_id call_id,
Benny Prijono8b1889b2006-06-06 18:40:40 +0000296 pjsip_rx_data *rdata);
297
298 /**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000299 * Notify application when media state in the call has changed.
300 * Normal application would need to implement this callback, e.g.
301 * to connect the call's media to sound device.
302 */
303 void (*on_call_media_state)(pjsua_call_id call_id);
304
305 /**
Benny Prijono9fc735d2006-05-28 14:58:12 +0000306 * Notify application on call being transfered.
307 * Application can decide to accept/reject transfer request
308 * by setting the code (default is 200). When this callback
309 * is not defined, the default behavior is to accept the
310 * transfer.
311 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000312 void (*on_call_transfered)(pjsua_call_id call_id,
Benny Prijono9fc735d2006-05-28 14:58:12 +0000313 const pj_str_t *dst,
314 pjsip_status_code *code);
315
316 /**
317 * Notify application when registration status has changed.
318 * Application may then query the account info to get the
319 * registration details.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000320 */
Benny Prijono8b1889b2006-06-06 18:40:40 +0000321 void (*on_reg_state)(pjsua_acc_id acc_id);
Benny Prijonodc39fe82006-05-26 12:17:46 +0000322
323 /**
Benny Prijono9fc735d2006-05-28 14:58:12 +0000324 * Notify application when the buddy state has changed.
325 * Application may then query the buddy into to get the details.
326 */
Benny Prijono8b1889b2006-06-06 18:40:40 +0000327 void (*on_buddy_state)(pjsua_buddy_id buddy_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +0000328
329 /**
330 * Notify application on incoming pager (i.e. MESSAGE request).
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000331 * Argument call_id will be -1 if MESSAGE request is not related to an
Benny Prijonodc39fe82006-05-26 12:17:46 +0000332 * existing call.
333 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000334 void (*on_pager)(pjsua_call_id call_id, const pj_str_t *from,
335 const pj_str_t *to, const pj_str_t *contact,
336 const pj_str_t *mime_type, const pj_str_t *body);
337
338 /**
339 * Notify application about the delivery status of outgoing pager
340 * request.
341 *
342 * @param call_id Containts the ID of the call where the IM was
343 * sent, or PJSUA_INVALID_ID if the IM was sent
344 * outside call context.
345 * @param to Destination URI.
346 * @param body Message body.
347 * @param user_data Arbitrary data that was specified when sending
348 * IM message.
349 * @param status Delivery status.
350 * @param reason Delivery status reason.
351 */
352 void (*on_pager_status)(pjsua_call_id call_id,
353 const pj_str_t *to,
354 const pj_str_t *body,
355 void *user_data,
356 pjsip_status_code status,
357 const pj_str_t *reason);
Benny Prijonodc39fe82006-05-26 12:17:46 +0000358
359 /**
Benny Prijono9fc735d2006-05-28 14:58:12 +0000360 * Notify application about typing indication.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000361 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000362 void (*on_typing)(pjsua_call_id call_id, const pj_str_t *from,
363 const pj_str_t *to, const pj_str_t *contact,
364 pj_bool_t is_typing);
Benny Prijonodc39fe82006-05-26 12:17:46 +0000365
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000366} pjsua_callback;
367
368
369
Benny Prijonodc39fe82006-05-26 12:17:46 +0000370
371/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000372 * PJSUA settings.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000373 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000374typedef struct pjsua_config
375{
376
377 /**
378 * Maximum calls to support (default: 4)
379 */
380 unsigned max_calls;
381
382 /**
383 * Number of worker threads. Normally application will want to have at
384 * least one worker thread, unless when it wants to poll the library
385 * periodically, which in this case the worker thread can be set to
386 * zero.
387 */
388 unsigned thread_cnt;
389
390 /**
391 * Number of outbound proxies in the array.
392 */
393 unsigned outbound_proxy_cnt;
394
395 /**
396 * Specify the URL of outbound proxies to visit for all outgoing requests.
397 * The outbound proxies will be used for all accounts, and it will
398 * be used to build the route set for outgoing requests. The final
399 * route set for outgoing requests will consists of the outbound proxies
400 * and the proxy configured in the account.
401 */
402 pj_str_t outbound_proxy[4];
403
404 /**
405 * Number of credentials in the credential array.
406 */
407 unsigned cred_count;
408
409 /**
410 * Array of credentials. These credentials will be used by all accounts,
411 * and can be used to authenticate against outbound proxies.
412 */
413 pjsip_cred_info cred_info[PJSUA_ACC_MAX_PROXIES];
414
415 /**
416 * Application callback.
417 */
418 pjsua_callback cb;
419
420} pjsua_config;
421
422
423/**
424 * Use this function to initialize pjsua config.
425 *
426 * @param cfg pjsua config to be initialized.
427 */
428PJ_INLINE(void) pjsua_config_default(pjsua_config *cfg)
429{
430 pj_memset(cfg, 0, sizeof(*cfg));
431
432 cfg->max_calls = 4;
433 cfg->thread_cnt = 1;
434}
435
436
437/**
438 * Duplicate credential.
439 */
440PJ_INLINE(void) pjsip_cred_dup( pj_pool_t *pool,
441 pjsip_cred_info *dst,
442 const pjsip_cred_info *src)
443{
444 pj_strdup_with_null(pool, &dst->realm, &src->realm);
445 pj_strdup_with_null(pool, &dst->scheme, &src->scheme);
446 pj_strdup_with_null(pool, &dst->username, &src->username);
447 pj_strdup_with_null(pool, &dst->data, &src->data);
448
449}
450
451
452/**
453 * Duplicate pjsua_config.
454 */
455PJ_INLINE(void) pjsua_config_dup(pj_pool_t *pool,
456 pjsua_config *dst,
457 const pjsua_config *src)
458{
459 unsigned i;
460
461 pj_memcpy(dst, src, sizeof(*src));
462
463 for (i=0; i<src->outbound_proxy_cnt; ++i) {
464 pj_strdup_with_null(pool, &dst->outbound_proxy[i],
465 &src->outbound_proxy[i]);
466 }
467
468 for (i=0; i<src->cred_count; ++i) {
469 pjsip_cred_dup(pool, &dst->cred_info[i], &src->cred_info[i]);
470 }
471}
472
473
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000474
475/**
476 * This structure describes additional information to be sent with
477 * outgoing SIP message.
478 */
479typedef struct pjsua_msg_data
480{
481 /**
482 * Additional message headers as linked list.
483 */
484 pjsip_hdr hdr_list;
485
486 /**
487 * MIME type of optional message body.
488 */
489 pj_str_t content_type;
490
491 /**
492 * Optional message body.
493 */
494 pj_str_t msg_body;
495
496} pjsua_msg_data;
497
498
499/**
500 * Initialize message data.
501 *
502 * @param msg_data Message data to be initialized.
503 */
504PJ_INLINE(void) pjsua_msg_data_init(pjsua_msg_data *msg_data)
505{
506 pj_memset(msg_data, 0, sizeof(*msg_data));
507 pj_list_init(&msg_data->hdr_list);
508}
Benny Prijono8b1889b2006-06-06 18:40:40 +0000509
Benny Prijono268ca612006-02-07 12:34:11 +0000510
Benny Prijono268ca612006-02-07 12:34:11 +0000511
512/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000513 * Instantiate pjsua application. Application must call this function before
514 * calling any other functions, to make sure that the underlying libraries
515 * are properly initialized. Once this function has returned success,
516 * application must call pjsua_destroy() before quitting.
517 *
518 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000519 */
520PJ_DECL(pj_status_t) pjsua_create(void);
521
522
523/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000524 * Initialize pjsua with the specified settings. All the settings are
525 * optional, and the default values will be used when the config is not
526 * specified.
Benny Prijonoccf95622006-02-07 18:48:01 +0000527 *
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000528 * @param ua_cfg User agent configuration.
529 * @param log_cfg Optional logging configuration.
530 * @param media_cfg Optional media configuration.
Benny Prijonoccf95622006-02-07 18:48:01 +0000531 *
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000532 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono268ca612006-02-07 12:34:11 +0000533 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000534PJ_DECL(pj_status_t) pjsua_init(const pjsua_config *ua_cfg,
535 const pjsua_logging_config *log_cfg,
536 const pjsua_media_config *media_cfg);
Benny Prijono268ca612006-02-07 12:34:11 +0000537
538
539/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000540 * Application is recommended to call this function after all initialization
541 * is done, so that the library can do additional checking set up
542 * additional
Benny Prijonoccf95622006-02-07 18:48:01 +0000543 *
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000544 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonoccf95622006-02-07 18:48:01 +0000545 */
Benny Prijonodc39fe82006-05-26 12:17:46 +0000546PJ_DECL(pj_status_t) pjsua_start(void);
Benny Prijonoccf95622006-02-07 18:48:01 +0000547
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000548
Benny Prijonoccf95622006-02-07 18:48:01 +0000549/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000550 * Destroy pjsua. This function must be called once PJSUA is created. To
551 * make it easier for application, application may call this function
552 * several times with no danger.
553 *
554 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono268ca612006-02-07 12:34:11 +0000555 */
Benny Prijonodc39fe82006-05-26 12:17:46 +0000556PJ_DECL(pj_status_t) pjsua_destroy(void);
Benny Prijonoa91a0032006-02-26 21:23:45 +0000557
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000558
Benny Prijono9fc735d2006-05-28 14:58:12 +0000559/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000560 * Poll pjsua for events, and if necessary block the caller thread for
561 * the specified maximum interval (in miliseconds).
562 *
563 * @param msec_timeout Maximum time to wait, in miliseconds.
564 *
565 * @return The number of events that have been handled during the
566 * poll. Negative value indicates error, and application
567 * can retrieve the error as (err = -return_value).
Benny Prijonob9b32ab2006-06-01 12:28:44 +0000568 */
569PJ_DECL(int) pjsua_handle_events(unsigned msec_timeout);
570
571
572/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000573 * Create memory pool.
574 *
575 * @param name Optional pool name.
Benny Prijono312aff92006-06-17 04:08:30 +0000576 * @param init_size Initial size of the pool.
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000577 * @param increment Increment size.
578 *
579 * @return The pool, or NULL when there's no memory.
580 */
581PJ_DECL(pj_pool_t*) pjsua_pool_create(const char *name, pj_size_t init_size,
582 pj_size_t increment);
583
584
585/**
586 * Application can call this function at any time (after pjsua_create(), of
587 * course) to change logging settings.
588 *
589 * @param c Logging configuration.
590 *
591 * @return PJ_SUCCESS on success, or the appropriate error code.
592 */
593PJ_DECL(pj_status_t) pjsua_reconfigure_logging(const pjsua_logging_config *c);
594
595
596/**
597 * Internal function to get SIP endpoint instance of pjsua, which is
598 * needed for example to register module, create transports, etc.
599 * Probably is only valid after #pjsua_init() is called.
600 *
601 * @return SIP endpoint instance.
Benny Prijono9fc735d2006-05-28 14:58:12 +0000602 */
603PJ_DECL(pjsip_endpoint*) pjsua_get_pjsip_endpt(void);
604
605/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000606 * Internal function to get media endpoint instance.
607 * Only valid after #pjsua_init() is called.
608 *
609 * @return Media endpoint instance.
Benny Prijono9fc735d2006-05-28 14:58:12 +0000610 */
611PJ_DECL(pjmedia_endpt*) pjsua_get_pjmedia_endpt(void);
612
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000613
614/*****************************************************************************
Benny Prijono312aff92006-06-17 04:08:30 +0000615 * Utilities.
616 *
Benny Prijono9fc735d2006-05-28 14:58:12 +0000617 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000618
619/**
Benny Prijono312aff92006-06-17 04:08:30 +0000620 * Verify that valid SIP url is given.
621 *
622 * @param c_url The URL, as NULL terminated string.
623 *
624 * @return PJ_SUCCESS on success, or the appropriate error code.
625 */
626PJ_DECL(pj_status_t) pjsua_verify_sip_url(const char *c_url);
627
628
629/**
630 * Display error message for the specified error code.
631 *
632 * @param sender The log sender field.
633 * @param title Message title for the error.
634 * @param status Status code.
635 */
636PJ_DECL(void) pjsua_perror(const char *sender, const char *title,
637 pj_status_t status);
638
639
640
641
642/**
643 * @}
644 */
645
646
647
648/*****************************************************************************
649 * TRANSPORT API
650 */
651
652/**
653 * @defgroup PJSUA_LIB_TRANSPORT Signaling Transport
654 * @ingroup PJSUA_LIB
655 * @brief API for managing SIP transports
656 * @{
657 * SIP transport must be created before adding an account. SIP transport is
658 * created by calling #pjsua_transport_create() function.
659 */
660
661
662/** SIP transport identification */
663typedef int pjsua_transport_id;
664
665
666/**
667 * STUN configuration.
668 */
669typedef struct pjsua_stun_config
670{
671 /**
672 * The first STUN server IP address or hostname.
673 */
674 pj_str_t stun_srv1;
675
676 /**
677 * Port number of the first STUN server.
678 * If zero, default STUN port will be used.
679 */
680 unsigned stun_port1;
681
682 /**
683 * Optional second STUN server IP address or hostname, for which the
684 * result of the mapping request will be compared to. If the value
685 * is empty, only one STUN server will be used.
686 */
687 pj_str_t stun_srv2;
688
689 /**
690 * Port number of the second STUN server.
691 * If zero, default STUN port will be used.
692 */
693 unsigned stun_port2;
694
695} pjsua_stun_config;
696
697
698
699/**
700 * Call this function to initialize STUN config with default values.
701 *
702 * @param cfg The STUN config to be initialized.
703 */
704PJ_INLINE(void) pjsua_stun_config_default(pjsua_stun_config *cfg)
705{
706 pj_memset(cfg, 0, sizeof(*cfg));
707}
708
709
710/**
711 * Transport configuration for creating UDP transports for both SIP
712 * and media.
713 */
714typedef struct pjsua_transport_config
715{
716 /**
717 * UDP port number to bind locally. This setting MUST be specified
718 * even when default port is desired. If the value is zero, the
719 * transport will be bound to any available port, and application
720 * can query the port by querying the transport info.
721 */
722 unsigned port;
723
724 /**
725 * Optional address where the socket should be bound.
726 */
727 pj_in_addr ip_addr;
728
729 /**
730 * Flag to indicate whether STUN should be used.
731 */
732 pj_bool_t use_stun;
733
734 /**
735 * STUN configuration, must be specified when STUN is used.
736 */
737 pjsua_stun_config stun_config;
738
739} pjsua_transport_config;
740
741
742/**
743 * Call this function to initialize UDP config with default values.
744 *
745 * @param cfg The UDP config to be initialized.
746 */
747PJ_INLINE(void) pjsua_transport_config_default(pjsua_transport_config *cfg)
748{
749 pj_memset(cfg, 0, sizeof(*cfg));
750}
751
752
753/**
754 * Normalize STUN config.
755 */
756PJ_INLINE(void) pjsua_normalize_stun_config( pjsua_stun_config *cfg )
757{
758 if (cfg->stun_srv1.slen) {
759
760 if (cfg->stun_port1 == 0)
761 cfg->stun_port1 = 3478;
762
763 if (cfg->stun_srv2.slen == 0) {
764 cfg->stun_srv2 = cfg->stun_srv1;
765 cfg->stun_port2 = cfg->stun_port1;
766 } else {
767 if (cfg->stun_port2 == 0)
768 cfg->stun_port2 = 3478;
769 }
770
771 } else {
772 cfg->stun_port1 = 0;
773 cfg->stun_srv2.slen = 0;
774 cfg->stun_port2 = 0;
775 }
776}
777
778
779/**
780 * Duplicate transport config.
781 */
782PJ_INLINE(void) pjsua_transport_config_dup(pj_pool_t *pool,
783 pjsua_transport_config *dst,
784 const pjsua_transport_config *src)
785{
786 pj_memcpy(dst, src, sizeof(*src));
787
788 if (src->stun_config.stun_srv1.slen) {
789 pj_strdup_with_null(pool, &dst->stun_config.stun_srv1,
790 &src->stun_config.stun_srv1);
791 }
792
793 if (src->stun_config.stun_srv2.slen) {
794 pj_strdup_with_null(pool, &dst->stun_config.stun_srv2,
795 &src->stun_config.stun_srv2);
796 }
797
798 pjsua_normalize_stun_config(&dst->stun_config);
799}
800
801
802
803/**
804 * Transport info.
805 */
806typedef struct pjsua_transport_info
807{
808 /**
809 * PJSUA transport identification.
810 */
811 pjsua_transport_id id;
812
813 /**
814 * Transport type.
815 */
816 pjsip_transport_type_e type;
817
818 /**
819 * Transport type name.
820 */
821 pj_str_t type_name;
822
823 /**
824 * Transport string info/description.
825 */
826 pj_str_t info;
827
828 /**
829 * Transport flag (see ##pjsip_transport_flags_e).
830 */
831 unsigned flag;
832
833 /**
834 * Local address length.
835 */
836 unsigned addr_len;
837
838 /**
839 * Local/bound address.
840 */
841 pj_sockaddr local_addr;
842
843 /**
844 * Published address (or transport address name).
845 */
846 pjsip_host_port local_name;
847
848 /**
849 * Current number of objects currently referencing this transport.
850 */
851 unsigned usage_count;
852
853
854} pjsua_transport_info;
855
856
857/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000858 * Create SIP transport.
859 *
860 * @param type Transport type.
861 * @param cfg Transport configuration.
862 * @param p_id Optional pointer to receive transport ID.
863 *
864 * @return PJ_SUCCESS on success, or the appropriate error code.
865 */
866PJ_DECL(pj_status_t) pjsua_transport_create(pjsip_transport_type_e type,
867 const pjsua_transport_config *cfg,
868 pjsua_transport_id *p_id);
869
870/**
871 * Register transport that has been created by application.
872 *
873 * @param tp Transport instance.
874 * @param p_id Optional pointer to receive transport ID.
875 *
876 * @return PJ_SUCCESS on success, or the appropriate error code.
877 */
878PJ_DECL(pj_status_t) pjsua_transport_register(pjsip_transport *tp,
879 pjsua_transport_id *p_id);
880
881
882/**
883 * Enumerate all transports currently created in the system.
884 *
885 * @param id Array to receive transport ids.
886 * @param count In input, specifies the maximum number of elements.
887 * On return, it contains the actual number of elements.
888 *
889 * @return PJ_SUCCESS on success, or the appropriate error code.
890 */
891PJ_DECL(pj_status_t) pjsua_enum_transports( pjsua_transport_id id[],
892 unsigned *count );
893
894
895/**
896 * Get information about transports.
897 *
898 * @param id Transport ID.
899 * @param info Pointer to receive transport info.
900 *
901 * @return PJ_SUCCESS on success, or the appropriate error code.
902 */
903PJ_DECL(pj_status_t) pjsua_transport_get_info(pjsua_transport_id id,
904 pjsua_transport_info *info);
905
906
907/**
908 * Disable a transport or re-enable it. By default transport is always
909 * enabled after it is created. Disabling a transport does not necessarily
910 * close the socket, it will only discard incoming messages and prevent
911 * the transport from being used to send outgoing messages.
912 *
913 * @param id Transport ID.
914 * @param enabled Non-zero to enable, zero to disable.
915 *
916 * @return PJ_SUCCESS on success, or the appropriate error code.
917 */
918PJ_DECL(pj_status_t) pjsua_transport_set_enable(pjsua_transport_id id,
919 pj_bool_t enabled);
920
921
922/**
923 * Close the transport. If transport is forcefully closed, it will be
924 * immediately closed, and any pending transactions that are using the
925 * transport may not terminate properly. Otherwise, the system will wait
926 * until all transactions are closed while preventing new users from
927 * using the transport, and will close the transport when it is safe to
928 * do so.
929 *
930 * @param id Transport ID.
931 * @param force Non-zero to immediately close the transport. This
932 * is not recommended!
933 *
934 * @return PJ_SUCCESS on success, or the appropriate error code.
935 */
936PJ_DECL(pj_status_t) pjsua_transport_close( pjsua_transport_id id,
937 pj_bool_t force );
Benny Prijono9fc735d2006-05-28 14:58:12 +0000938
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000939/**
Benny Prijono312aff92006-06-17 04:08:30 +0000940 * @}
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000941 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000942
943
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000944
945
946/*****************************************************************************
Benny Prijono312aff92006-06-17 04:08:30 +0000947 * ACCOUNT API
Benny Prijonoa91a0032006-02-26 21:23:45 +0000948 */
949
Benny Prijono312aff92006-06-17 04:08:30 +0000950
951/**
952 * @defgroup PJSUA_LIB_ACC Account Management
953 * @ingroup PJSUA_LIB
954 * @brief PJSUA supports multiple accounts..
955 * @{
956 * PJSUA accounts provide identity (or identities) of the user who is currently
957 * using the application. More than one account maybe created with PJSUA.
958 *
959 * Account may or may not have client registration associated with it.
960 * An account is also associated with <b>route set</b> and some <b>authentication
961 * credentials</b>, which are used when sending SIP request messages using the
962 * account. An account also has presence's <b>online status</b>, which
963 * will be reported to remote peer when the subscribe to the account's
964 * presence.
965 *
966 * At least one account MUST be created in the application. If no user
967 * association is required, application can create a userless account by
968 * calling #pjsua_acc_add_local(). A userless account identifies local endpoint
969 * instead of a particular user.
970 *
971 * Also one account must be set as the <b>default account</b>, which is used as
972 * the account to use when PJSUA fails to match a request with any other
973 * accounts.
974 *
975 * When sending outgoing SIP requests (such as making calls or sending
976 * instant messages), normally PJSUA requires the application to specify
977 * which account to use for the request. If no account is specified,
978 * PJSUA may be able to select the account by matching the destination
979 * domain name, and fall back to default account when no match is found.
980 */
981
982/**
983 * Maximum accounts.
984 */
985#ifndef PJSUA_MAX_ACC
986# define PJSUA_MAX_ACC 8
987#endif
988
989
990/**
991 * Default registration interval.
992 */
993#ifndef PJSUA_REG_INTERVAL
994# define PJSUA_REG_INTERVAL 55
995#endif
996
997
998/**
999 * Account configuration.
1000 */
1001typedef struct pjsua_acc_config
1002{
1003 /**
1004 * The full SIP URL for the account. The value can take name address or
1005 * URL format, and will look something like "sip:account@serviceprovider".
1006 *
1007 * This field is mandatory.
1008 */
1009 pj_str_t id;
1010
1011 /**
1012 * This is the URL to be put in the request URI for the registration,
1013 * and will look something like "sip:serviceprovider".
1014 *
1015 * This field should be specified if registration is desired. If the
1016 * value is empty, no account registration will be performed.
1017 */
1018 pj_str_t reg_uri;
1019
1020 /**
1021 * Optional URI to be put as Contact for this account. It is recommended
1022 * that this field is left empty, so that the value will be calculated
1023 * automatically based on the transport address.
1024 */
1025 pj_str_t contact;
1026
1027 /**
1028 * Number of proxies in the proxy array below.
1029 */
1030 unsigned proxy_cnt;
1031
1032 /**
1033 * Optional URI of the proxies to be visited for all outgoing requests
1034 * that are using this account (REGISTER, INVITE, etc). Application need
1035 * to specify these proxies if the service provider requires that requests
1036 * destined towards its network should go through certain proxies first
1037 * (for example, border controllers).
1038 *
1039 * These proxies will be put in the route set for this account, with
1040 * maintaining the orders (the first proxy in the array will be visited
1041 * first).
1042 */
1043 pj_str_t proxy[PJSUA_ACC_MAX_PROXIES];
1044
1045 /**
1046 * Optional interval for registration, in seconds. If the value is zero,
1047 * default interval will be used (PJSUA_REG_INTERVAL, 55 seconds).
1048 */
1049 unsigned reg_timeout;
1050
1051 /**
1052 * Number of credentials in the credential array.
1053 */
1054 unsigned cred_count;
1055
1056 /**
1057 * Array of credentials. If registration is desired, normally there should
1058 * be at least one credential specified, to successfully authenticate
1059 * against the service provider. More credentials can be specified, for
1060 * example when the requests are expected to be challenged by the
1061 * proxies in the route set.
1062 */
1063 pjsip_cred_info cred_info[PJSUA_ACC_MAX_PROXIES];
1064
1065} pjsua_acc_config;
1066
1067
1068/**
1069 * Call this function to initialize account config with default values.
1070 *
1071 * @param cfg The account config to be initialized.
1072 */
1073PJ_INLINE(void) pjsua_acc_config_default(pjsua_acc_config *cfg)
1074{
1075 pj_memset(cfg, 0, sizeof(*cfg));
1076
1077 cfg->reg_timeout = PJSUA_REG_INTERVAL;
1078}
1079
1080
1081
1082/**
1083 * Account info. Application can query account info by calling
1084 * #pjsua_acc_get_info().
1085 */
1086typedef struct pjsua_acc_info
1087{
1088 /**
1089 * The account ID.
1090 */
1091 pjsua_acc_id id;
1092
1093 /**
1094 * Flag to indicate whether this is the default account.
1095 */
1096 pj_bool_t is_default;
1097
1098 /**
1099 * Account URI
1100 */
1101 pj_str_t acc_uri;
1102
1103 /**
1104 * Flag to tell whether this account has registration setting
1105 * (reg_uri is not empty).
1106 */
1107 pj_bool_t has_registration;
1108
1109 /**
1110 * An up to date expiration interval for account registration session.
1111 */
1112 int expires;
1113
1114 /**
1115 * Last registration status code. If status code is zero, the account
1116 * is currently not registered. Any other value indicates the SIP
1117 * status code of the registration.
1118 */
1119 pjsip_status_code status;
1120
1121 /**
1122 * String describing the registration status.
1123 */
1124 pj_str_t status_text;
1125
1126 /**
1127 * Presence online status for this account.
1128 */
1129 pj_bool_t online_status;
1130
1131 /**
1132 * Buffer that is used internally to store the status text.
1133 */
1134 char buf_[PJ_ERR_MSG_SIZE];
1135
1136} pjsua_acc_info;
1137
1138
1139
1140/**
1141 * Get number of current accounts.
1142 *
1143 * @return Current number of accounts.
1144 */
1145PJ_DECL(unsigned) pjsua_acc_get_count(void);
1146
1147
1148/**
1149 * Check if the specified account ID is valid.
1150 *
1151 * @param acc_id Account ID to check.
1152 *
1153 * @return Non-zero if account ID is valid.
1154 */
1155PJ_DECL(pj_bool_t) pjsua_acc_is_valid(pjsua_acc_id acc_id);
1156
1157
1158/**
1159 * Add a new account to pjsua. PJSUA must have been initialized (with
1160 * #pjsua_init()) before calling this function.
1161 *
1162 * @param cfg Account configuration.
1163 * @param is_default If non-zero, this account will be set as the default
1164 * account. The default account will be used when sending
1165 * outgoing requests (e.g. making call) when no account is
1166 * specified, and when receiving incoming requests when the
1167 * request does not match any accounts. It is recommended
1168 * that default account is set to local/LAN account.
1169 * @param p_acc_id Pointer to receive account ID of the new account.
1170 *
1171 * @return PJ_SUCCESS on success, or the appropriate error code.
1172 */
1173PJ_DECL(pj_status_t) pjsua_acc_add(const pjsua_acc_config *cfg,
1174 pj_bool_t is_default,
1175 pjsua_acc_id *p_acc_id);
1176
1177
1178/**
1179 * Add a local account. A local account is used to identify local endpoint
1180 * instead of a specific user, and for this reason, a transport ID is needed
1181 * to obtain the local address information.
1182 *
1183 * @param tid Transport ID to generate account address.
1184 * @param is_default If non-zero, this account will be set as the default
1185 * account. The default account will be used when sending
1186 * outgoing requests (e.g. making call) when no account is
1187 * specified, and when receiving incoming requests when the
1188 * request does not match any accounts. It is recommended
1189 * that default account is set to local/LAN account.
1190 * @param p_acc_id Pointer to receive account ID of the new account.
1191 *
1192 * @return PJ_SUCCESS on success, or the appropriate error code.
1193 */
1194PJ_DECL(pj_status_t) pjsua_acc_add_local(pjsua_transport_id tid,
1195 pj_bool_t is_default,
1196 pjsua_acc_id *p_acc_id);
1197
1198/**
1199 * Delete account.
1200 *
1201 * @param acc_id Id of the account to be deleted.
1202 *
1203 * @return PJ_SUCCESS on success, or the appropriate error code.
1204 */
1205PJ_DECL(pj_status_t) pjsua_acc_del(pjsua_acc_id acc_id);
1206
1207
1208/**
1209 * Modify account information.
1210 *
1211 * @param acc_id Id of the account to be modified.
1212 * @param cfg New account configuration.
1213 *
1214 * @return PJ_SUCCESS on success, or the appropriate error code.
1215 */
1216PJ_DECL(pj_status_t) pjsua_acc_modify(pjsua_acc_id acc_id,
1217 const pjsua_acc_config *cfg);
1218
1219
1220/**
1221 * Modify account's presence status to be advertised to remote/presence
1222 * subscribers.
1223 *
1224 * @param acc_id The account ID.
1225 * @param is_online True of false.
1226 *
1227 * @return PJ_SUCCESS on success, or the appropriate error code.
1228 */
1229PJ_DECL(pj_status_t) pjsua_acc_set_online_status(pjsua_acc_id acc_id,
1230 pj_bool_t is_online);
1231
1232
1233/**
1234 * Update registration or perform unregistration.
1235 *
1236 * @param acc_id The account ID.
1237 * @param renew If renew argument is zero, this will start
1238 * unregistration process.
1239 *
1240 * @return PJ_SUCCESS on success, or the appropriate error code.
1241 */
1242PJ_DECL(pj_status_t) pjsua_acc_set_registration(pjsua_acc_id acc_id,
1243 pj_bool_t renew);
1244
1245
1246/**
1247 * Get account information.
1248 *
1249 * @param acc_id Account identification.
1250 * @param info Pointer to receive account information.
1251 *
1252 * @return PJ_SUCCESS on success, or the appropriate error code.
1253 */
1254PJ_DECL(pj_status_t) pjsua_acc_get_info(pjsua_acc_id acc_id,
1255 pjsua_acc_info *info);
1256
1257
1258/**
1259 * Enum accounts all account ids.
1260 *
1261 * @param ids Array of account IDs to be initialized.
1262 * @param count In input, specifies the maximum number of elements.
1263 * On return, it contains the actual number of elements.
1264 *
1265 * @return PJ_SUCCESS on success, or the appropriate error code.
1266 */
1267PJ_DECL(pj_status_t) pjsua_enum_accs(pjsua_acc_id ids[],
1268 unsigned *count );
1269
1270
1271/**
1272 * Enum accounts info.
1273 *
1274 * @param info Array of account infos to be initialized.
1275 * @param count In input, specifies the maximum number of elements.
1276 * On return, it contains the actual number of elements.
1277 *
1278 * @return PJ_SUCCESS on success, or the appropriate error code.
1279 */
1280PJ_DECL(pj_status_t) pjsua_acc_enum_info( pjsua_acc_info info[],
1281 unsigned *count );
1282
1283
1284/**
1285 * This is an internal function to find the most appropriate account to
1286 * used to reach to the specified URL.
1287 *
1288 * @param url The remote URL to reach.
1289 *
1290 * @return Account id.
1291 */
1292PJ_DECL(pjsua_acc_id) pjsua_acc_find_for_outgoing(const pj_str_t *url);
1293
1294
1295/**
1296 * This is an internal function to find the most appropriate account to be
1297 * used to handle incoming calls.
1298 *
1299 * @param rdata The incoming request message.
1300 *
1301 * @return Account id.
1302 */
1303PJ_DECL(pjsua_acc_id) pjsua_acc_find_for_incoming(pjsip_rx_data *rdata);
1304
1305
1306
1307/**
1308 * @}
1309 */
1310
1311
1312/*****************************************************************************
1313 * CALLS API
1314 */
1315
1316
1317/**
1318 * @defgroup PJSUA_LIB_CALL Calls
1319 * @ingroup PJSUA_LIB
1320 * @brief Call manipulation.
1321 * @{
1322 */
1323
1324/**
1325 * Max simultaneous calls.
1326 */
1327#ifndef PJSUA_MAX_CALLS
1328# define PJSUA_MAX_CALLS 32
1329#endif
1330
1331
1332
1333/**
1334 * Call media status.
1335 */
1336typedef enum pjsua_call_media_status
1337{
1338 PJSUA_CALL_MEDIA_NONE,
1339 PJSUA_CALL_MEDIA_ACTIVE,
1340 PJSUA_CALL_MEDIA_LOCAL_HOLD,
1341 PJSUA_CALL_MEDIA_REMOTE_HOLD,
1342} pjsua_call_media_status;
1343
1344
1345/**
1346 * Call info.
1347 */
1348typedef struct pjsua_call_info
1349{
1350 /** Call identification. */
1351 pjsua_call_id id;
1352
1353 /** Initial call role (UAC == caller) */
1354 pjsip_role_e role;
1355
1356 /** Local URI */
1357 pj_str_t local_info;
1358
1359 /** Local Contact */
1360 pj_str_t local_contact;
1361
1362 /** Remote URI */
1363 pj_str_t remote_info;
1364
1365 /** Remote contact */
1366 pj_str_t remote_contact;
1367
1368 /** Dialog Call-ID string. */
1369 pj_str_t call_id;
1370
1371 /** Call state */
1372 pjsip_inv_state state;
1373
1374 /** Text describing the state */
1375 pj_str_t state_text;
1376
1377 /** Last status code heard, which can be used as cause code */
1378 pjsip_status_code last_status;
1379
1380 /** The reason phrase describing the status. */
1381 pj_str_t last_status_text;
1382
1383 /** Call media status. */
1384 pjsua_call_media_status media_status;
1385
1386 /** Media direction */
1387 pjmedia_dir media_dir;
1388
1389 /** The conference port number for the call */
1390 pjsua_conf_port_id conf_slot;
1391
1392 /** Up-to-date call connected duration (zero when call is not
1393 * established)
1394 */
1395 pj_time_val connect_duration;
1396
1397 /** Total call duration, including set-up time */
1398 pj_time_val total_duration;
1399
1400 /** Internal */
1401 struct {
1402 char local_info[128];
1403 char local_contact[128];
1404 char remote_info[128];
1405 char remote_contact[128];
1406 char call_id[128];
1407 char last_status_text[128];
1408 } buf_;
1409
1410} pjsua_call_info;
1411
1412
1413
Benny Prijonoa91a0032006-02-26 21:23:45 +00001414/**
Benny Prijono9fc735d2006-05-28 14:58:12 +00001415 * Get maximum number of calls configured in pjsua.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001416 *
1417 * @return Maximum number of calls configured.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001418 */
Benny Prijono8b1889b2006-06-06 18:40:40 +00001419PJ_DECL(unsigned) pjsua_call_get_max_count(void);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001420
1421/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001422 * Get number of currently active calls.
1423 *
1424 * @return Number of currently active calls.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001425 */
Benny Prijono8b1889b2006-06-06 18:40:40 +00001426PJ_DECL(unsigned) pjsua_call_get_count(void);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001427
1428/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001429 * Enumerate all active calls.
1430 *
1431 * @param ids Array of account IDs to be initialized.
1432 * @param count In input, specifies the maximum number of elements.
1433 * On return, it contains the actual number of elements.
1434 *
1435 * @return PJ_SUCCESS on success, or the appropriate error code.
1436 */
1437PJ_DECL(pj_status_t) pjsua_enum_calls(pjsua_call_id ids[],
1438 unsigned *count);
1439
1440
1441/**
1442 * Make outgoing call to the specified URI using the specified account.
1443 *
1444 * @param acc_id The account to be used.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001445 * @param dst_uri URI to be put in the To header (normally is the same
1446 * as the target URI).
1447 * @param options Options (must be zero at the moment).
1448 * @param user_data Arbitrary user data to be attached to the call, and
1449 * can be retrieved later.
1450 * @param msg_data Optional headers etc to be added to outgoing INVITE
1451 * request, or NULL if no custom header is desired.
1452 * @param p_call_id Pointer to receive call identification.
1453 *
1454 * @return PJ_SUCCESS on success, or the appropriate error code.
1455 */
1456PJ_DECL(pj_status_t) pjsua_call_make_call(pjsua_acc_id acc_id,
1457 const pj_str_t *dst_uri,
1458 unsigned options,
1459 void *user_data,
1460 const pjsua_msg_data *msg_data,
1461 pjsua_call_id *p_call_id);
1462
1463
1464/**
Benny Prijono9fc735d2006-05-28 14:58:12 +00001465 * Check if the specified call has active INVITE session and the INVITE
1466 * session has not been disconnected.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001467 *
1468 * @param call_id Call identification.
1469 *
1470 * @return Non-zero if call is active.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001471 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001472PJ_DECL(pj_bool_t) pjsua_call_is_active(pjsua_call_id call_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001473
1474
1475/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001476 * Check if call has an active media session.
1477 *
1478 * @param call_id Call identification.
1479 *
1480 * @return Non-zero if yes.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001481 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001482PJ_DECL(pj_bool_t) pjsua_call_has_media(pjsua_call_id call_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001483
1484
1485/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001486 * Get the conference port identification associated with the call.
1487 *
1488 * @param call_id Call identification.
1489 *
1490 * @return Conference port ID, or PJSUA_INVALID_ID when the
1491 * media has not been established or is not active.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001492 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001493PJ_DECL(pjsua_conf_port_id) pjsua_call_get_conf_port(pjsua_call_id call_id);
1494
1495/**
1496 * Obtain detail information about the specified call.
1497 *
1498 * @param call_id Call identification.
1499 * @param info Call info to be initialized.
1500 *
1501 * @return PJ_SUCCESS on success, or the appropriate error code.
1502 */
1503PJ_DECL(pj_status_t) pjsua_call_get_info(pjsua_call_id call_id,
Benny Prijono9fc735d2006-05-28 14:58:12 +00001504 pjsua_call_info *info);
1505
1506
1507/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001508 * Attach application specific data to the call.
1509 *
1510 * @param call_id Call identification.
1511 * @param user_data Arbitrary data to be attached to the call.
1512 *
1513 * @return The user data.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001514 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001515PJ_DECL(pj_status_t) pjsua_call_set_user_data(pjsua_call_id call_id,
1516 void *user_data);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001517
1518
1519/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001520 * Get user data attached to the call.
1521 *
1522 * @param call_id Call identification.
1523 *
1524 * @return The user data.
Benny Prijono268ca612006-02-07 12:34:11 +00001525 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001526PJ_DECL(void*) pjsua_call_get_user_data(pjsua_call_id call_id);
Benny Prijono84126ab2006-02-09 09:30:09 +00001527
1528
1529/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001530 * Send response to incoming INVITE request.
1531 *
1532 * @param call_id Incoming call identification.
1533 * @param code Status code, (100-699).
1534 * @param reason Optional reason phrase. If NULL, default text
1535 * will be used.
1536 * @param msg_data Optional list of headers etc to be added to outgoing
1537 * response message.
1538 *
1539 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonoa91a0032006-02-26 21:23:45 +00001540 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001541PJ_DECL(pj_status_t) pjsua_call_answer(pjsua_call_id call_id,
1542 unsigned code,
1543 const pj_str_t *reason,
1544 const pjsua_msg_data *msg_data);
Benny Prijonoa91a0032006-02-26 21:23:45 +00001545
1546/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001547 * Hangup call by using method that is appropriate according to the
1548 * call state.
1549 *
1550 * @param call_id Call identification.
1551 * @param code Optional status code to be sent when we're rejecting
1552 * incoming call. If the value is zero, "603/Decline"
1553 * will be sent.
1554 * @param reason Optional reason phrase to be sent when we're rejecting
1555 * incoming call. If NULL, default text will be used.
1556 * @param msg_data Optional list of headers etc to be added to outgoing
1557 * request/response message.
1558 *
1559 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono26ff9062006-02-21 23:47:00 +00001560 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001561PJ_DECL(pj_status_t) pjsua_call_hangup(pjsua_call_id call_id,
1562 unsigned code,
1563 const pj_str_t *reason,
1564 const pjsua_msg_data *msg_data);
Benny Prijono26ff9062006-02-21 23:47:00 +00001565
1566
1567/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001568 * Put the specified call on hold.
1569 *
1570 * @param call_id Call identification.
1571 * @param msg_data Optional message components to be sent with
1572 * the request.
1573 *
1574 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono26ff9062006-02-21 23:47:00 +00001575 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001576PJ_DECL(pj_status_t) pjsua_call_set_hold(pjsua_call_id call_id,
1577 const pjsua_msg_data *msg_data);
Benny Prijono26ff9062006-02-21 23:47:00 +00001578
1579
1580/**
1581 * Send re-INVITE (to release hold).
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001582 *
1583 * @param call_id Call identification.
1584 * @param unhold If this argument is non-zero and the call is locally
1585 * held, this will release the local hold.
1586 * @param msg_data Optional message components to be sent with
1587 * the request.
1588 *
1589 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono26ff9062006-02-21 23:47:00 +00001590 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001591PJ_DECL(pj_status_t) pjsua_call_reinvite(pjsua_call_id call_id,
1592 pj_bool_t unhold,
1593 const pjsua_msg_data *msg_data);
Benny Prijono26ff9062006-02-21 23:47:00 +00001594
1595
1596/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001597 * Initiate call transfer to the specified address.
1598 *
1599 * @param call_id Call identification.
1600 * @param dest Address of new target to be contacted.
1601 * @param msg_data Optional message components to be sent with
1602 * the request.
1603 *
1604 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono26ff9062006-02-21 23:47:00 +00001605 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001606PJ_DECL(pj_status_t) pjsua_call_xfer(pjsua_call_id call_id,
1607 const pj_str_t *dest,
1608 const pjsua_msg_data *msg_data);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001609
1610/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001611 * Send DTMF digits to remote using RFC 2833 payload formats.
1612 *
1613 * @param call_id Call identification.
1614 * @param digits DTMF digits to be sent.
1615 *
1616 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001617 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001618PJ_DECL(pj_status_t) pjsua_call_dial_dtmf(pjsua_call_id call_id,
Benny Prijono9fc735d2006-05-28 14:58:12 +00001619 const pj_str_t *digits);
Benny Prijono26ff9062006-02-21 23:47:00 +00001620
Benny Prijono26ff9062006-02-21 23:47:00 +00001621/**
Benny Prijonob0808372006-03-02 21:18:58 +00001622 * Send instant messaging inside INVITE session.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001623 *
1624 * @param call_id Call identification.
1625 * @param mime_type Optional MIME type. If NULL, then "text/plain" is
1626 * assumed.
1627 * @param content The message content.
1628 * @param msg_data Optional list of headers etc to be included in outgoing
1629 * request. The body descriptor in the msg_data is
1630 * ignored.
1631 * @param user_data Optional user data, which will be given back when
1632 * the IM callback is called.
1633 *
1634 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonob0808372006-03-02 21:18:58 +00001635 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001636PJ_DECL(pj_status_t) pjsua_call_send_im( pjsua_call_id call_id,
1637 const pj_str_t *mime_type,
1638 const pj_str_t *content,
1639 const pjsua_msg_data *msg_data,
1640 void *user_data);
Benny Prijonob0808372006-03-02 21:18:58 +00001641
1642
1643/**
1644 * Send IM typing indication inside INVITE session.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001645 *
1646 * @param call_id Call identification.
1647 * @param is_typing Non-zero to indicate to remote that local person is
1648 * currently typing an IM.
1649 * @param msg_data Optional list of headers etc to be included in outgoing
1650 * request.
1651 *
1652 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonob0808372006-03-02 21:18:58 +00001653 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001654PJ_DECL(pj_status_t) pjsua_call_send_typing_ind(pjsua_call_id call_id,
1655 pj_bool_t is_typing,
1656 const pjsua_msg_data*msg_data);
Benny Prijonob0808372006-03-02 21:18:58 +00001657
1658/**
Benny Prijono834aee32006-02-19 01:38:06 +00001659 * Terminate all calls.
1660 */
Benny Prijonodc39fe82006-05-26 12:17:46 +00001661PJ_DECL(void) pjsua_call_hangup_all(void);
Benny Prijono834aee32006-02-19 01:38:06 +00001662
1663
Benny Prijonob9b32ab2006-06-01 12:28:44 +00001664/**
1665 * Dump call and media statistics to string.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001666 *
1667 * @param call_id Call identification.
1668 * @param with_media Non-zero to include media information too.
1669 * @param buffer Buffer where the statistics are to be written to.
1670 * @param maxlen Maximum length of buffer.
1671 * @param indent Spaces for left indentation.
1672 *
1673 * @return PJ_SUCCESS on success.
Benny Prijonob9b32ab2006-06-01 12:28:44 +00001674 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001675PJ_DECL(pj_status_t) pjsua_call_dump(pjsua_call_id call_id,
1676 pj_bool_t with_media,
1677 char *buffer,
1678 unsigned maxlen,
1679 const char *indent);
Benny Prijonob9b32ab2006-06-01 12:28:44 +00001680
Benny Prijono9fc735d2006-05-28 14:58:12 +00001681/**
Benny Prijono312aff92006-06-17 04:08:30 +00001682 * @}
Benny Prijono9fc735d2006-05-28 14:58:12 +00001683 */
Benny Prijono834aee32006-02-19 01:38:06 +00001684
1685
1686/*****************************************************************************
Benny Prijono312aff92006-06-17 04:08:30 +00001687 * BUDDY API
Benny Prijono834aee32006-02-19 01:38:06 +00001688 */
1689
Benny Prijono312aff92006-06-17 04:08:30 +00001690
1691/**
1692 * @defgroup PJSUA_LIB_BUDDY Buddy, Presence, and Instant Messaging
1693 * @ingroup PJSUA_LIB
1694 * @brief Buddy management, buddy's presence, and instant messaging.
1695 * @{
1696 */
1697
1698/**
1699 * Max buddies in buddy list.
1700 */
1701#ifndef PJSUA_MAX_BUDDIES
1702# define PJSUA_MAX_BUDDIES 256
1703#endif
1704
1705
1706/**
1707 * Buddy configuration.
1708 */
1709typedef struct pjsua_buddy_config
1710{
1711 /**
1712 * Buddy URL or name address.
1713 */
1714 pj_str_t uri;
1715
1716 /**
1717 * Specify whether presence subscription should start immediately.
1718 */
1719 pj_bool_t subscribe;
1720
1721} pjsua_buddy_config;
1722
1723
1724/**
1725 * Buddy's online status.
1726 */
1727typedef enum pjsua_buddy_status
1728{
1729 /**
1730 * Online status is unknown (possibly because no presence subscription
1731 * has been established).
1732 */
1733 PJSUA_BUDDY_STATUS_UNKNOWN,
1734
1735 /**
1736 * Buddy is known to be offline.
1737 */
1738 PJSUA_BUDDY_STATUS_ONLINE,
1739
1740 /**
1741 * Buddy is offline.
1742 */
1743 PJSUA_BUDDY_STATUS_OFFLINE,
1744
1745} pjsua_buddy_status;
1746
1747
1748
1749/**
1750 * Buddy info.
1751 */
1752typedef struct pjsua_buddy_info
1753{
1754 /**
1755 * The buddy ID.
1756 */
1757 pjsua_buddy_id id;
1758
1759 /**
1760 * The full URI of the buddy, as specified in the configuration.
1761 */
1762 pj_str_t uri;
1763
1764 /**
1765 * Buddy's Contact, only available when presence subscription has
1766 * been established to the buddy.
1767 */
1768 pj_str_t contact;
1769
1770 /**
1771 * Buddy's online status.
1772 */
1773 pjsua_buddy_status status;
1774
1775 /**
1776 * Text to describe buddy's online status.
1777 */
1778 pj_str_t status_text;
1779
1780 /**
1781 * Flag to indicate that we should monitor the presence information for
1782 * this buddy (normally yes, unless explicitly disabled).
1783 */
1784 pj_bool_t monitor_pres;
1785
1786 /**
1787 * Internal buffer.
1788 */
1789 char buf_[256];
1790
1791} pjsua_buddy_info;
1792
1793
Benny Prijono834aee32006-02-19 01:38:06 +00001794/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001795 * Get total number of buddies.
1796 *
1797 * @return Number of buddies.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001798 */
1799PJ_DECL(unsigned) pjsua_get_buddy_count(void);
1800
1801
1802/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001803 * Check if buddy ID is valid.
1804 *
1805 * @param buddy_id Buddy ID to check.
1806 *
1807 * @return Non-zero if buddy ID is valid.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001808 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001809PJ_DECL(pj_bool_t) pjsua_buddy_is_valid(pjsua_buddy_id buddy_id);
1810
1811
1812/**
1813 * Enum buddy IDs.
1814 *
1815 * @param ids Array of ids to be initialized.
1816 * @param count On input, specifies max elements in the array.
1817 * On return, it contains actual number of elements
1818 * that have been initialized.
1819 *
1820 * @return PJ_SUCCESS on success, or the appropriate error code.
1821 */
1822PJ_DECL(pj_status_t) pjsua_enum_buddies(pjsua_buddy_id ids[],
1823 unsigned *count);
1824
1825/**
1826 * Get detailed buddy info.
1827 *
1828 * @param buddy_id The buddy identification.
1829 * @param info Pointer to receive information about buddy.
1830 *
1831 * @return PJ_SUCCESS on success, or the appropriate error code.
1832 */
1833PJ_DECL(pj_status_t) pjsua_buddy_get_info(pjsua_buddy_id buddy_id,
Benny Prijono9fc735d2006-05-28 14:58:12 +00001834 pjsua_buddy_info *info);
1835
1836/**
1837 * Add new buddy.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001838 *
1839 * @param cfg Buddy configuration.
1840 * @param p_buddy_id Pointer to receive buddy ID.
1841 *
1842 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001843 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001844PJ_DECL(pj_status_t) pjsua_buddy_add(const pjsua_buddy_config *cfg,
1845 pjsua_buddy_id *p_buddy_id);
Benny Prijono8b1889b2006-06-06 18:40:40 +00001846
1847
1848/**
1849 * Delete buddy.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001850 *
1851 * @param buddy_id Buddy identification.
1852 *
1853 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono8b1889b2006-06-06 18:40:40 +00001854 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001855PJ_DECL(pj_status_t) pjsua_buddy_del(pjsua_buddy_id buddy_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001856
1857
1858/**
1859 * Enable/disable buddy's presence monitoring.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001860 *
1861 * @param buddy_id Buddy identification.
1862 * @param subscribe Specify non-zero to activate presence subscription to
1863 * the specified buddy.
1864 *
1865 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001866 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001867PJ_DECL(pj_status_t) pjsua_buddy_subscribe_pres(pjsua_buddy_id buddy_id,
1868 pj_bool_t subscribe);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001869
1870
1871/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001872 * Dump presence subscriptions to log file.
1873 *
1874 * @param verbose Yes or no.
Benny Prijono834aee32006-02-19 01:38:06 +00001875 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001876PJ_DECL(void) pjsua_pres_dump(pj_bool_t verbose);
Benny Prijono834aee32006-02-19 01:38:06 +00001877
1878
Benny Prijonob0808372006-03-02 21:18:58 +00001879/**
1880 * The MESSAGE method (defined in pjsua_im.c)
1881 */
1882extern const pjsip_method pjsip_message_method;
1883
1884
Benny Prijonob0808372006-03-02 21:18:58 +00001885
1886/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001887 * Send instant messaging outside dialog, using the specified account for
1888 * route set and authentication.
1889 *
1890 * @param acc_id Account ID to be used to send the request.
1891 * @param to Remote URI.
1892 * @param mime_type Optional MIME type. If NULL, then "text/plain" is
1893 * assumed.
1894 * @param content The message content.
1895 * @param msg_data Optional list of headers etc to be included in outgoing
1896 * request. The body descriptor in the msg_data is
1897 * ignored.
1898 * @param user_data Optional user data, which will be given back when
1899 * the IM callback is called.
1900 *
1901 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonob0808372006-03-02 21:18:58 +00001902 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001903PJ_DECL(pj_status_t) pjsua_im_send(pjsua_acc_id acc_id,
1904 const pj_str_t *to,
1905 const pj_str_t *mime_type,
1906 const pj_str_t *content,
1907 const pjsua_msg_data *msg_data,
1908 void *user_data);
Benny Prijonob0808372006-03-02 21:18:58 +00001909
1910
1911/**
1912 * Send typing indication outside dialog.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001913 *
1914 * @param acc_id Account ID to be used to send the request.
1915 * @param to Remote URI.
1916 * @param is_typing If non-zero, it tells remote person that local person
1917 * is currently composing an IM.
1918 * @param msg_data Optional list of headers etc to be added to outgoing
1919 * request.
1920 *
1921 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonob0808372006-03-02 21:18:58 +00001922 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001923PJ_DECL(pj_status_t) pjsua_im_typing(pjsua_acc_id acc_id,
1924 const pj_str_t *to,
1925 pj_bool_t is_typing,
1926 const pjsua_msg_data *msg_data);
Benny Prijonob0808372006-03-02 21:18:58 +00001927
1928
Benny Prijonof3195072006-02-14 21:15:30 +00001929
Benny Prijono312aff92006-06-17 04:08:30 +00001930/**
1931 * @}
Benny Prijono9fc735d2006-05-28 14:58:12 +00001932 */
1933
Benny Prijono312aff92006-06-17 04:08:30 +00001934
1935/*****************************************************************************
1936 * MEDIA API
1937 */
1938
1939
1940/**
1941 * @defgroup PJSUA_LIB_MEDIA Media
1942 * @ingroup PJSUA_LIB
1943 * @brief Media manipulation.
1944 * @{
1945 *
1946 * PJSUA has rather powerful media features, which are built around the
1947 * PJMEDIA conference bridge. Basically, all media termination (such as
1948 * calls, file players, file recorders, sound device, tone generators, etc)
1949 * are terminated in the conference bridge, and application can manipulate
1950 * the interconnection between these terminations freely. If more than
1951 * one media terminations are terminated in the same slot, the conference
1952 * bridge will mix the signal automatically.
1953 *
1954 * Application connects one media termination/slot to another by calling
1955 * #pjsua_conf_connect() function. This will establish <b>unidirectional</b>
1956 * media flow from the source termination to the sink termination. For
1957 * example, to stream a WAV file to remote call, application may use
1958 * the following steps:
1959 *
1960 \code
1961
1962 pj_status_t stream_to_call( pjsua_call_id call_id )
1963 {
1964 pjsua_player_id player_id;
1965
1966 status = pjsua_player_create("mysong.wav", 0, NULL, &player_id);
1967 if (status != PJ_SUCCESS)
1968 return status;
1969
1970 status = pjsua_conf_connect( pjsua_player_get_conf_port(),
1971 pjsua_call_get_conf_port() );
1972 }
1973 \endcode
1974 *
1975 *
1976 * Other features of PJSUA media:
1977 * - efficient N to M interconnections between media terminations.
1978 * - media termination can be connected to itself to create loopback
1979 * media.
1980 * - the media termination may have different clock rates, and resampling
1981 * will be done automatically by conference bridge.
1982 * - media terminations may also have different frame time; the
1983 * conference bridge will perform the necessary bufferring to adjust
1984 * the difference between terminations.
1985 * - interconnections are removed automatically when media termination
1986 * is removed from the bridge.
1987 * - sound device may be changed even when there are active media
1988 * interconnections.
1989 * - correctly report call's media quality (in #pjsua_call_dump()) from
1990 * RTCP packet exchange.
1991 */
1992
1993/**
1994 * Max ports in the conference bridge.
1995 */
1996#ifndef PJSUA_MAX_CONF_PORTS
1997# define PJSUA_MAX_CONF_PORTS 254
1998#endif
1999
2000
2001
2002/**
2003 * Media configuration.
2004 */
2005struct pjsua_media_config
2006{
2007 /**
2008 * Clock rate to be applied to the conference bridge.
2009 * If value is zero, default clock rate will be used (16KHz).
2010 */
2011 unsigned clock_rate;
2012
2013 /**
2014 * Specify maximum number of media ports to be created in the
2015 * conference bridge. Since all media terminate in the bridge
2016 * (calls, file player, file recorder, etc), the value must be
2017 * large enough to support all of them. However, the larger
2018 * the value, the more computations are performed.
2019 */
2020 unsigned max_media_ports;
2021
2022 /**
2023 * Specify whether the media manager should manage its own
2024 * ioqueue for the RTP/RTCP sockets. If yes, ioqueue will be created
2025 * and at least one worker thread will be created too. If no,
2026 * the RTP/RTCP sockets will share the same ioqueue as SIP sockets,
2027 * and no worker thread is needed.
2028 *
2029 * Normally application would say yes here, unless it wants to
2030 * run everything from a single thread.
2031 */
2032 pj_bool_t has_ioqueue;
2033
2034 /**
2035 * Specify the number of worker threads to handle incoming RTP
2036 * packets. A value of one is recommended for most applications.
2037 */
2038 unsigned thread_cnt;
2039
Benny Prijono0498d902006-06-19 14:49:14 +00002040 /**
2041 * Media quality, 0-10, according to this table:
2042 * 8-10: resampling use large filter,
2043 * 3-7: resampling use small filter,
2044 * 1-2: resampling use linear.
2045 * The media quality also sets speex codec quality/complexity to the
2046 * number.
2047 *
2048 * Default: 10.
2049 */
2050 unsigned quality;
Benny Prijono312aff92006-06-17 04:08:30 +00002051};
2052
2053
2054/**
2055 * Use this function to initialize media config.
2056 *
2057 * @param cfg The media config to be initialized.
2058 */
2059PJ_INLINE(void) pjsua_media_config_default(pjsua_media_config *cfg)
2060{
2061 pj_memset(cfg, 0, sizeof(*cfg));
2062
2063 cfg->clock_rate = 16000;
2064 cfg->max_media_ports = 32;
2065 cfg->has_ioqueue = PJ_TRUE;
2066 cfg->thread_cnt = 1;
Benny Prijono0498d902006-06-19 14:49:14 +00002067 cfg->quality = 10;
Benny Prijono312aff92006-06-17 04:08:30 +00002068}
2069
2070
2071
2072/**
2073 * Codec config.
2074 */
2075typedef struct pjsua_codec_info
2076{
2077 /**
2078 * Codec unique identification.
2079 */
2080 pj_str_t codec_id;
2081
2082 /**
2083 * Codec priority (integer 0-255).
2084 */
2085 pj_uint8_t priority;
2086
2087 /**
2088 * Internal buffer.
2089 */
2090 char buf_[32];
2091
2092} pjsua_codec_info;
2093
2094
2095/**
2096 * Conference port info.
2097 */
2098typedef struct pjsua_conf_port_info
2099{
2100 /** Conference port number. */
2101 pjsua_conf_port_id slot_id;
2102
2103 /** Port name. */
2104 pj_str_t name;
2105
2106 /** Clock rate. */
2107 unsigned clock_rate;
2108
2109 /** Number of channels. */
2110 unsigned channel_count;
2111
2112 /** Samples per frame */
2113 unsigned samples_per_frame;
2114
2115 /** Bits per sample */
2116 unsigned bits_per_sample;
2117
2118 /** Number of listeners in the array. */
2119 unsigned listener_cnt;
2120
2121 /** Array of listeners (in other words, ports where this port is
2122 * transmitting to.
2123 */
2124 pjsua_conf_port_id listeners[PJSUA_MAX_CONF_PORTS];
2125
2126} pjsua_conf_port_info;
2127
2128
2129/**
2130 * This structure holds information about custom media transport to
2131 * be registered to pjsua.
2132 */
2133typedef struct pjsua_media_transport
2134{
2135 /**
2136 * Media socket information containing the address information
2137 * of the RTP and RTCP socket.
2138 */
2139 pjmedia_sock_info skinfo;
2140
2141 /**
2142 * The media transport instance.
2143 */
2144 pjmedia_transport *transport;
2145
2146} pjsua_media_transport;
2147
2148
2149
2150
Benny Prijono9fc735d2006-05-28 14:58:12 +00002151/**
2152 * Get maxinum number of conference ports.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002153 *
2154 * @return Maximum number of ports in the conference bridge.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002155 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002156PJ_DECL(unsigned) pjsua_conf_get_max_ports(void);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002157
2158
2159/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002160 * Get current number of active ports in the bridge.
2161 *
2162 * @return The number.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002163 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002164PJ_DECL(unsigned) pjsua_conf_get_active_ports(void);
2165
2166
2167/**
2168 * Enumerate all conference ports.
2169 *
2170 * @param id Array of conference port ID to be initialized.
2171 * @param count On input, specifies max elements in the array.
2172 * On return, it contains actual number of elements
2173 * that have been initialized.
2174 *
2175 * @return PJ_SUCCESS on success, or the appropriate error code.
2176 */
2177PJ_DECL(pj_status_t) pjsua_enum_conf_ports(pjsua_conf_port_id id[],
2178 unsigned *count);
Benny Prijono8b1889b2006-06-06 18:40:40 +00002179
2180
2181/**
2182 * Get information about the specified conference port
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002183 *
2184 * @param id Port identification.
2185 * @param info Pointer to store the port info.
2186 *
2187 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono8b1889b2006-06-06 18:40:40 +00002188 */
2189PJ_DECL(pj_status_t) pjsua_conf_get_port_info( pjsua_conf_port_id id,
2190 pjsua_conf_port_info *info);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002191
2192
2193/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002194 * Establish unidirectional media flow from souce to sink. One source
2195 * may transmit to multiple destinations/sink. And if multiple
2196 * sources are transmitting to the same sink, the media will be mixed
2197 * together. Source and sink may refer to the same ID, effectively
2198 * looping the media.
2199 *
2200 * If bidirectional media flow is desired, application needs to call
2201 * this function twice, with the second one having the arguments
2202 * reversed.
2203 *
2204 * @param source Port ID of the source media/transmitter.
2205 * @param sink Port ID of the destination media/received.
2206 *
2207 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002208 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002209PJ_DECL(pj_status_t) pjsua_conf_connect(pjsua_conf_port_id source,
2210 pjsua_conf_port_id sink);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002211
2212
2213/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002214 * Disconnect media flow from the source to destination port.
2215 *
2216 * @param source Port ID of the source media/transmitter.
2217 * @param sink Port ID of the destination media/received.
2218 *
2219 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002220 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002221PJ_DECL(pj_status_t) pjsua_conf_disconnect(pjsua_conf_port_id source,
2222 pjsua_conf_port_id sink);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002223
2224
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002225/*****************************************************************************
2226 * File player.
2227 */
2228
Benny Prijono9fc735d2006-05-28 14:58:12 +00002229/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002230 * Create a file player, and automatically connect this player to
2231 * the conference bridge.
2232 *
2233 * @param filename The filename to be played. Currently only
Benny Prijono312aff92006-06-17 04:08:30 +00002234 * WAV files are supported, and the WAV file MUST be
2235 * formatted as 16bit PCM mono/single channel (any
2236 * clock rate is supported).
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002237 * @param options Options (currently zero).
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002238 * @param p_id Pointer to receive player ID.
2239 *
2240 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002241 */
2242PJ_DECL(pj_status_t) pjsua_player_create(const pj_str_t *filename,
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002243 unsigned options,
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002244 pjsua_player_id *p_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002245
2246
2247/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002248 * Get conference port ID associated with player.
2249 *
2250 * @param id The file player ID.
2251 *
2252 * @return Conference port ID associated with this player.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002253 */
Benny Prijono8b1889b2006-06-06 18:40:40 +00002254PJ_DECL(pjsua_conf_port_id) pjsua_player_get_conf_port(pjsua_player_id id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002255
2256
2257/**
2258 * Set playback position.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002259 *
2260 * @param id The file player ID.
2261 * @param samples The playback position, in samples. Application can
2262 * specify zero to re-start the playback.
2263 *
2264 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002265 */
2266PJ_DECL(pj_status_t) pjsua_player_set_pos(pjsua_player_id id,
2267 pj_uint32_t samples);
2268
2269
2270/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002271 * Close the file, remove the player from the bridge, and free
2272 * resources associated with the file player.
2273 *
2274 * @param id The file player ID.
2275 *
2276 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002277 */
2278PJ_DECL(pj_status_t) pjsua_player_destroy(pjsua_player_id id);
2279
2280
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002281/*****************************************************************************
2282 * File recorder.
2283 */
Benny Prijono9fc735d2006-05-28 14:58:12 +00002284
2285/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002286 * Create a file recorder, and automatically connect this recorder to
2287 * the conference bridge.
2288 *
2289 * @param filename Output file name.
2290 * @param file_format Specify the file format (currently only WAV is
2291 * supported, so the value MUST be zero).
2292 * @param encoding Specify the encoding to be applied to the file.
2293 * Currently only 16bit raw PCM is supported, so
2294 * the value must be NULL.
2295 * @param max_size Maximum file size. Specify -1 to remove size
2296 * limitation.
2297 * @param options Optional options.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002298 * @param p_id Pointer to receive the recorder instance.
2299 *
2300 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002301 */
2302PJ_DECL(pj_status_t) pjsua_recorder_create(const pj_str_t *filename,
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002303 unsigned file_format,
2304 const pj_str_t *encoding,
2305 pj_ssize_t max_size,
2306 unsigned options,
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002307 pjsua_recorder_id *p_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002308
2309
2310/**
2311 * Get conference port associated with recorder.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002312 *
2313 * @param id The recorder ID.
2314 *
2315 * @return Conference port ID associated with this recorder.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002316 */
Benny Prijono8b1889b2006-06-06 18:40:40 +00002317PJ_DECL(pjsua_conf_port_id) pjsua_recorder_get_conf_port(pjsua_recorder_id id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002318
2319
2320/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002321 * Destroy recorder (this will complete recording).
2322 *
2323 * @param id The recorder ID.
2324 *
2325 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002326 */
2327PJ_DECL(pj_status_t) pjsua_recorder_destroy(pjsua_recorder_id id);
2328
2329
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002330/*****************************************************************************
2331 * Sound devices.
2332 */
2333
Benny Prijono9fc735d2006-05-28 14:58:12 +00002334/**
2335 * Enum sound devices.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002336 *
2337 * @param info Array of info to be initialized.
2338 * @param count On input, specifies max elements in the array.
2339 * On return, it contains actual number of elements
2340 * that have been initialized.
2341 *
2342 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002343 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002344PJ_DECL(pj_status_t) pjsua_enum_snd_devs(pjmedia_snd_dev_info info[],
2345 unsigned *count);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002346
2347
2348/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002349 * Select or change sound device. Application may call this function at
2350 * any time to replace current sound device.
2351 *
2352 * @param capture_dev Device ID of the capture device.
2353 * @param playback_dev Device ID of the playback device.
2354 *
2355 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002356 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002357PJ_DECL(pj_status_t) pjsua_set_snd_dev(int capture_dev,
2358 int playback_dev);
2359
2360
2361/**
2362 * Set pjsua to use null sound device. The null sound device only provides
2363 * the timing needed by the conference bridge, and will not interract with
2364 * any hardware.
2365 *
2366 * @return PJ_SUCCESS on success, or the appropriate error code.
2367 */
2368PJ_DECL(pj_status_t) pjsua_set_null_snd_dev(void);
2369
2370
2371/*****************************************************************************
2372 * Codecs.
2373 */
2374
2375/**
2376 * Enum all supported codecs in the system.
2377 *
2378 * @param id Array of ID to be initialized.
2379 * @param count On input, specifies max elements in the array.
2380 * On return, it contains actual number of elements
2381 * that have been initialized.
2382 *
2383 * @return PJ_SUCCESS on success, or the appropriate error code.
2384 */
2385PJ_DECL(pj_status_t) pjsua_enum_codecs( pjsua_codec_info id[],
2386 unsigned *count );
2387
2388
2389/**
2390 * Change codec priority.
2391 *
2392 * @param id Codec ID.
2393 * @param priority Codec priority, 0-255, where zero means to disable
2394 * the codec.
2395 *
2396 * @return PJ_SUCCESS on success, or the appropriate error code.
2397 */
2398PJ_DECL(pj_status_t) pjsua_codec_set_priority( const pj_str_t *id,
2399 pj_uint8_t priority );
2400
2401
2402/**
2403 * Get codec parameters.
2404 *
2405 * @param id Codec ID.
2406 * @param param Structure to receive codec parameters.
2407 *
2408 * @return PJ_SUCCESS on success, or the appropriate error code.
2409 */
2410PJ_DECL(pj_status_t) pjsua_codec_get_param( const pj_str_t *id,
2411 pjmedia_codec_param *param );
2412
2413
2414/**
2415 * Set codec parameters.
2416 *
2417 * @param id Codec ID.
2418 * @param param Codec parameter to set.
2419 *
2420 * @return PJ_SUCCESS on success, or the appropriate error code.
2421 */
2422PJ_DECL(pj_status_t) pjsua_codec_set_param( const pj_str_t *id,
2423 const pjmedia_codec_param *param);
2424
2425
2426
Benny Prijono9fc735d2006-05-28 14:58:12 +00002427
Benny Prijono312aff92006-06-17 04:08:30 +00002428/**
2429 * Create UDP media transports for all the calls. This function creates
2430 * one UDP media transport for each call.
Benny Prijonof3195072006-02-14 21:15:30 +00002431 *
Benny Prijono312aff92006-06-17 04:08:30 +00002432 * @param cfg Media transport configuration. The "port" field in the
2433 * configuration is used as the start port to bind the
2434 * sockets.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002435 *
2436 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonof3195072006-02-14 21:15:30 +00002437 */
Benny Prijono312aff92006-06-17 04:08:30 +00002438PJ_DECL(pj_status_t)
2439pjsua_media_transports_create(const pjsua_transport_config *cfg);
Benny Prijonof3195072006-02-14 21:15:30 +00002440
Benny Prijonodc39fe82006-05-26 12:17:46 +00002441
2442/**
Benny Prijono312aff92006-06-17 04:08:30 +00002443 * Register custom media transports to be used by calls. There must
2444 * enough media transports for all calls.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002445 *
Benny Prijono312aff92006-06-17 04:08:30 +00002446 * @param tp The media transport array.
2447 * @param count Number of elements in the array. This number MUST
2448 * match the number of maximum calls configured when
2449 * pjsua is created.
2450 * @param auto_delete Flag to indicate whether the transports should be
2451 * destroyed when pjsua is shutdown.
2452 *
2453 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonodc39fe82006-05-26 12:17:46 +00002454 */
Benny Prijono312aff92006-06-17 04:08:30 +00002455PJ_DECL(pj_status_t)
2456pjsua_media_transports_attach( pjsua_media_transport tp[],
2457 unsigned count,
2458 pj_bool_t auto_delete);
Benny Prijonodc39fe82006-05-26 12:17:46 +00002459
2460
Benny Prijono312aff92006-06-17 04:08:30 +00002461/**
2462 * @}
2463 */
2464
Benny Prijonof3195072006-02-14 21:15:30 +00002465
Benny Prijono268ca612006-02-07 12:34:11 +00002466
Benny Prijono1a01ad32006-02-07 21:13:28 +00002467PJ_END_DECL
2468
Benny Prijonof3195072006-02-14 21:15:30 +00002469
Benny Prijono312aff92006-06-17 04:08:30 +00002470/**
2471 * @}
2472 */
2473
2474
Benny Prijono268ca612006-02-07 12:34:11 +00002475#endif /* __PJSUA_H__ */