blob: 7ae37eed69d2e3a18b5fe9b0252bda5c50e1ecaf [file] [log] [blame]
Benny Prijono268ca612006-02-07 12:34:11 +00001/* $Id$ */
2/*
3 * Copyright (C) 2003-2006 Benny Prijono <benny@prijono.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#ifndef __PJSUA_H__
20#define __PJSUA_H__
21
Benny Prijono312aff92006-06-17 04:08:30 +000022/**
23 * @file pjsua.h
24 * @brief PJSUA API.
25 */
26
27
Benny Prijono268ca612006-02-07 12:34:11 +000028/* Include all PJSIP core headers. */
29#include <pjsip.h>
30
31/* Include all PJMEDIA headers. */
32#include <pjmedia.h>
33
Benny Prijono1f9afba2006-02-10 15:57:32 +000034/* Include all PJMEDIA-CODEC headers. */
35#include <pjmedia-codec.h>
36
Benny Prijono268ca612006-02-07 12:34:11 +000037/* Include all PJSIP-UA headers */
38#include <pjsip_ua.h>
39
Benny Prijono834aee32006-02-19 01:38:06 +000040/* Include all PJSIP-SIMPLE headers */
41#include <pjsip_simple.h>
42
Benny Prijono268ca612006-02-07 12:34:11 +000043/* Include all PJLIB-UTIL headers. */
44#include <pjlib-util.h>
45
46/* Include all PJLIB headers. */
47#include <pjlib.h>
48
49
Benny Prijono312aff92006-06-17 04:08:30 +000050/**
51 * @defgroup PJSUA_LIB PJSUA API
52 * @ingroup PJSIP
53 * @brief Very high level API for constructing SIP UA applications.
54 * @{
55 *
56 * PJSUA API is very high level API for constructing SIP user agent
57 * applications. It wraps together the signaling and media functionalities
58 * into an easy to use call API, provides account management, buddy
59 * management, presence, instant messaging, along with multimedia
60 * features such as conferencing, file streaming, local playback,
61 * voice recording, and so on.
62 *
63 * Application must link with <b>pjsua-lib</b> to use this API. In addition,
64 * this library depends on the following libraries:
65 * - <b>pjsip-ua</b>,
66 * - <b>pjsip-simple</b>,
67 * - <b>pjsip-core</b>,
68 * - <b>pjmedia</b>,
69 * - <b>pjmedia-codec</b>,
70 * - <b>pjlib-util</b>, and
71 * - <b>pjlib</b>,
72 *
73 * so application must also link with these libraries as well.
74 *
75 * @section root_using_pjsua_lib Using PJSUA API
76 *
77 * Please refer to @ref using_pjsua_lib on how to use PJSUA API.
78 */
79
Benny Prijono1a01ad32006-02-07 21:13:28 +000080PJ_BEGIN_DECL
81
Benny Prijono632ce712006-02-09 14:01:40 +000082
Benny Prijono312aff92006-06-17 04:08:30 +000083/** Forward declaration */
84typedef struct pjsua_media_config pjsua_media_config;
Benny Prijonoa91a0032006-02-26 21:23:45 +000085
Benny Prijonof3195072006-02-14 21:15:30 +000086
Benny Prijono312aff92006-06-17 04:08:30 +000087/*****************************************************************************
88 * BASE API
89 */
90
Benny Prijonof04ffdd2006-02-21 00:11:18 +000091/**
Benny Prijono312aff92006-06-17 04:08:30 +000092 * @defgroup PJSUA_LIB_BASE Base API
93 * @ingroup PJSUA_LIB
94 * @brief Basic application creation/initialization, logging configuration, etc.
95 * @{
96 *
97 * The base PJSUA API controls PJSUA creation, initialization, and startup, and
98 * also provides various auxiliary functions.
99 *
100 * @section using_pjsua_lib Using PJSUA Library
101 *
102 * @subsection creating_pjsua_lib Creating PJSUA
103 *
104 * Before anything else, application must create PJSUA by calling #pjsua_create().
105 * This, among other things, will initialize PJLIB, which is crucial before
106 * any PJLIB functions can be called.
107 *
108 * @subsection init_pjsua_lib Initializing PJSUA
109 *
110 * After PJSUA is created, application can initialize PJSUA by calling
111 * #pjsua_init(). This function takes several configuration settings in the
112 * argument, so application normally would want to set these configuration
113 * before passing them to #pjsua_init().
114 *
115 * Sample code to initialize PJSUA:
116 \code
117
118 pjsua_config ua_cfg;
119 pjsua_logging_config log_cfg;
120 pjsua_media_config media_cfg;
121
122 // Initialize configs with default settings.
123 pjsua_config_default(&ua_cfg);
124 pjsua_logging_config_default(&log_cfg);
125 pjsua_media_config_default(&media_cfg);
126
127 // At the very least, application would want to override
128 // the call callbacks in pjsua_config:
129 ua_cfg.cb.on_incoming_call = ...
130 ua_cfg.cb.on_call_state = ..
131 ...
132
133 // Customize other settings (or initialize them from application specific
134 // configuration file):
135 ...
136
137 // Initialize pjsua
138 status = pjsua_init(&ua_cfg, &log_cfg, &media_cfg);
139 if (status != PJ_SUCCESS) {
140 pjsua_perror(THIS_FILE, "Error initializing pjsua", status);
141 return status;
142 }
143 ..
144
145 \endcode
146 *
147 * @subsection other_init_pjsua_lib Other Initialization
148 *
149 * After PJSUA is initialized with #pjsua_init(), application will normally
150 * need/want to perform the following tasks:
151 *
152 * - create SIP transport with #pjsua_transport_create(). Please see
153 * @ref PJSUA_LIB_TRANSPORT section for more info.
154 * - create one or more SIP accounts with #pjsua_acc_add() or
155 * #pjsua_acc_add_local(). Please see @ref PJSUA_LIB_ACC for more info.
156 * - add one or more buddies with #pjsua_buddy_add(). Please see
157 * @ref PJSUA_LIB_BUDDY section for more info.
158 * - optionally configure the sound device, codec settings, and other
159 * media settings. Please see @ref PJSUA_LIB_MEDIA for more info.
160 *
161 *
162 * @subsection starting_pjsua_lib Starting PJSUA
163 *
164 * After all initializations have been done, application must call
165 * #pjsua_start() to start PJSUA. This function will check that all settings
166 * are properly configured, and apply default settings when it's not, or
167 * report error status when it is unable to recover from missing setting.
168 *
169 * Most settings can be changed during run-time. For example, application
170 * may add, modify, or delete accounts, buddies, or change media settings
171 * during run-time.
Benny Prijonof04ffdd2006-02-21 00:11:18 +0000172 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000173
Benny Prijono312aff92006-06-17 04:08:30 +0000174/** Constant to identify invalid ID for all sorts of IDs. */
175#define PJSUA_INVALID_ID (-1)
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000176
177/** Call identification */
178typedef int pjsua_call_id;
179
Benny Prijono312aff92006-06-17 04:08:30 +0000180/** Account identification */
181typedef int pjsua_acc_id;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000182
183/** Buddy identification */
Benny Prijono8b1889b2006-06-06 18:40:40 +0000184typedef int pjsua_buddy_id;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000185
186/** File player identification */
Benny Prijono8b1889b2006-06-06 18:40:40 +0000187typedef int pjsua_player_id;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000188
189/** File recorder identification */
Benny Prijono8b1889b2006-06-06 18:40:40 +0000190typedef int pjsua_recorder_id;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000191
192/** Conference port identification */
Benny Prijono8b1889b2006-06-06 18:40:40 +0000193typedef int pjsua_conf_port_id;
194
195
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000196
Benny Prijonoa91a0032006-02-26 21:23:45 +0000197/**
Benny Prijono312aff92006-06-17 04:08:30 +0000198 * Maximum proxies in account.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000199 */
Benny Prijono312aff92006-06-17 04:08:30 +0000200#ifndef PJSUA_ACC_MAX_PROXIES
201# define PJSUA_ACC_MAX_PROXIES 8
202#endif
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000203
204
205
206/**
207 * Logging configuration.
208 */
209typedef struct pjsua_logging_config
210{
211 /**
212 * Log incoming and outgoing SIP message? Yes!
213 */
214 pj_bool_t msg_logging;
215
216 /**
217 * Input verbosity level. Value 5 is reasonable.
218 */
219 unsigned level;
220
221 /**
222 * Verbosity level for console. Value 4 is reasonable.
223 */
224 unsigned console_level;
225
226 /**
227 * Log decoration.
228 */
229 unsigned decor;
230
231 /**
232 * Optional log filename.
233 */
234 pj_str_t log_filename;
235
236 /**
237 * Optional callback function to be called to write log to
238 * application specific device. This function will be called for
239 * log messages on input verbosity level.
240 */
241 void (*cb)(int level, const char *data, pj_size_t len);
242
243
244} pjsua_logging_config;
245
246
247/**
248 * Use this function to initialize logging config.
249 *
250 * @param cfg The logging config to be initialized.
251 */
252PJ_INLINE(void) pjsua_logging_config_default(pjsua_logging_config *cfg)
253{
Benny Prijonoac623b32006-07-03 15:19:31 +0000254 pj_bzero(cfg, sizeof(*cfg));
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000255
256 cfg->msg_logging = PJ_TRUE;
257 cfg->level = 5;
258 cfg->console_level = 4;
259 cfg->decor = PJ_LOG_HAS_SENDER | PJ_LOG_HAS_TIME |
260 PJ_LOG_HAS_MICRO_SEC | PJ_LOG_HAS_NEWLINE;
261}
262
263/**
264 * Use this function to duplicate logging config.
265 *
266 * @param pool Pool to use.
267 * @param dst Destination config.
268 * @param src Source config.
269 */
270PJ_INLINE(void) pjsua_logging_config_dup(pj_pool_t *pool,
271 pjsua_logging_config *dst,
272 const pjsua_logging_config *src)
273{
274 pj_memcpy(dst, src, sizeof(*src));
275 pj_strdup_with_null(pool, &dst->log_filename, &src->log_filename);
276}
277
278
Benny Prijonodc39fe82006-05-26 12:17:46 +0000279
280/**
281 * Application callbacks.
282 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000283typedef struct pjsua_callback
Benny Prijonodc39fe82006-05-26 12:17:46 +0000284{
285 /**
Benny Prijono9fc735d2006-05-28 14:58:12 +0000286 * Notify application when invite state has changed.
287 * Application may then query the call info to get the
288 * detail call states.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000289 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000290 void (*on_call_state)(pjsua_call_id call_id, pjsip_event *e);
Benny Prijonodc39fe82006-05-26 12:17:46 +0000291
292 /**
Benny Prijono8b1889b2006-06-06 18:40:40 +0000293 * Notify application on incoming call.
294 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000295 void (*on_incoming_call)(pjsua_acc_id acc_id, pjsua_call_id call_id,
Benny Prijono8b1889b2006-06-06 18:40:40 +0000296 pjsip_rx_data *rdata);
297
298 /**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000299 * Notify application when media state in the call has changed.
300 * Normal application would need to implement this callback, e.g.
301 * to connect the call's media to sound device.
302 */
303 void (*on_call_media_state)(pjsua_call_id call_id);
304
305 /**
Benny Prijono9fc735d2006-05-28 14:58:12 +0000306 * Notify application on call being transfered.
307 * Application can decide to accept/reject transfer request
308 * by setting the code (default is 200). When this callback
309 * is not defined, the default behavior is to accept the
310 * transfer.
311 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000312 void (*on_call_transfered)(pjsua_call_id call_id,
Benny Prijono9fc735d2006-05-28 14:58:12 +0000313 const pj_str_t *dst,
314 pjsip_status_code *code);
315
316 /**
317 * Notify application when registration status has changed.
318 * Application may then query the account info to get the
319 * registration details.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000320 */
Benny Prijono8b1889b2006-06-06 18:40:40 +0000321 void (*on_reg_state)(pjsua_acc_id acc_id);
Benny Prijonodc39fe82006-05-26 12:17:46 +0000322
323 /**
Benny Prijono9fc735d2006-05-28 14:58:12 +0000324 * Notify application when the buddy state has changed.
325 * Application may then query the buddy into to get the details.
326 */
Benny Prijono8b1889b2006-06-06 18:40:40 +0000327 void (*on_buddy_state)(pjsua_buddy_id buddy_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +0000328
329 /**
330 * Notify application on incoming pager (i.e. MESSAGE request).
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000331 * Argument call_id will be -1 if MESSAGE request is not related to an
Benny Prijonodc39fe82006-05-26 12:17:46 +0000332 * existing call.
333 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000334 void (*on_pager)(pjsua_call_id call_id, const pj_str_t *from,
335 const pj_str_t *to, const pj_str_t *contact,
336 const pj_str_t *mime_type, const pj_str_t *body);
337
338 /**
339 * Notify application about the delivery status of outgoing pager
340 * request.
341 *
342 * @param call_id Containts the ID of the call where the IM was
343 * sent, or PJSUA_INVALID_ID if the IM was sent
344 * outside call context.
345 * @param to Destination URI.
346 * @param body Message body.
347 * @param user_data Arbitrary data that was specified when sending
348 * IM message.
349 * @param status Delivery status.
350 * @param reason Delivery status reason.
351 */
352 void (*on_pager_status)(pjsua_call_id call_id,
353 const pj_str_t *to,
354 const pj_str_t *body,
355 void *user_data,
356 pjsip_status_code status,
357 const pj_str_t *reason);
Benny Prijonodc39fe82006-05-26 12:17:46 +0000358
359 /**
Benny Prijono9fc735d2006-05-28 14:58:12 +0000360 * Notify application about typing indication.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000361 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000362 void (*on_typing)(pjsua_call_id call_id, const pj_str_t *from,
363 const pj_str_t *to, const pj_str_t *contact,
364 pj_bool_t is_typing);
Benny Prijonodc39fe82006-05-26 12:17:46 +0000365
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000366} pjsua_callback;
367
368
369
Benny Prijonodc39fe82006-05-26 12:17:46 +0000370
371/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000372 * PJSUA settings.
Benny Prijonodc39fe82006-05-26 12:17:46 +0000373 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000374typedef struct pjsua_config
375{
376
377 /**
378 * Maximum calls to support (default: 4)
379 */
380 unsigned max_calls;
381
382 /**
383 * Number of worker threads. Normally application will want to have at
384 * least one worker thread, unless when it wants to poll the library
385 * periodically, which in this case the worker thread can be set to
386 * zero.
387 */
388 unsigned thread_cnt;
389
390 /**
391 * Number of outbound proxies in the array.
392 */
393 unsigned outbound_proxy_cnt;
394
395 /**
396 * Specify the URL of outbound proxies to visit for all outgoing requests.
397 * The outbound proxies will be used for all accounts, and it will
398 * be used to build the route set for outgoing requests. The final
399 * route set for outgoing requests will consists of the outbound proxies
400 * and the proxy configured in the account.
401 */
402 pj_str_t outbound_proxy[4];
403
404 /**
405 * Number of credentials in the credential array.
406 */
407 unsigned cred_count;
408
409 /**
410 * Array of credentials. These credentials will be used by all accounts,
411 * and can be used to authenticate against outbound proxies.
412 */
413 pjsip_cred_info cred_info[PJSUA_ACC_MAX_PROXIES];
414
415 /**
416 * Application callback.
417 */
418 pjsua_callback cb;
419
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{
Benny Prijonoac623b32006-07-03 15:19:31 +0000430 pj_bzero(cfg, sizeof(*cfg));
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000431
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{
Benny Prijonoac623b32006-07-03 15:19:31 +0000506 pj_bzero(msg_data, sizeof(*msg_data));
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000507 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{
Benny Prijonoac623b32006-07-03 15:19:31 +0000706 pj_bzero(cfg, sizeof(*cfg));
Benny Prijono312aff92006-06-17 04:08:30 +0000707}
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{
Benny Prijonoac623b32006-07-03 15:19:31 +0000749 pj_bzero(cfg, sizeof(*cfg));
Benny Prijono312aff92006-06-17 04:08:30 +0000750}
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 */
Benny Prijonob4a17c92006-07-10 14:40:21 +00001025 pj_str_t force_contact;
Benny Prijono312aff92006-06-17 04:08:30 +00001026
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{
Benny Prijonoac623b32006-07-03 15:19:31 +00001075 pj_bzero(cfg, sizeof(*cfg));
Benny Prijono312aff92006-06-17 04:08:30 +00001076
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
Benny Prijonoc570f2d2006-07-18 00:33:02 +00001306/**
1307 * Create a suitable URI to be put as Contact based on the specified
1308 * target URI for the specified account.
1309 *
1310 * @param pool Pool to allocate memory for the string.
1311 * @param contact The string where the Contact URI will be stored.
1312 * @param acc_id Account ID.
1313 * @param uri Destination URI of the request.
1314 *
1315 * @return PJ_SUCCESS on success, other on error.
1316 */
1317PJ_DECL(pj_status_t) pjsua_acc_create_uac_contact( pj_pool_t *pool,
1318 pj_str_t *contact,
1319 pjsua_acc_id acc_id,
1320 const pj_str_t *uri);
1321
1322
1323
1324/**
1325 * Create a suitable URI to be put as Contact based on the information
1326 * in the incoming request.
1327 *
1328 * @param pool Pool to allocate memory for the string.
1329 * @param contact The string where the Contact URI will be stored.
1330 * @param acc_id Account ID.
1331 * @param rdata Incoming request.
1332 *
1333 * @return PJ_SUCCESS on success, other on error.
1334 */
1335PJ_DECL(pj_status_t) pjsua_acc_create_uas_contact( pj_pool_t *pool,
1336 pj_str_t *contact,
1337 pjsua_acc_id acc_id,
1338 pjsip_rx_data *rdata );
1339
1340
Benny Prijono312aff92006-06-17 04:08:30 +00001341
1342/**
1343 * @}
1344 */
1345
1346
1347/*****************************************************************************
1348 * CALLS API
1349 */
1350
1351
1352/**
1353 * @defgroup PJSUA_LIB_CALL Calls
1354 * @ingroup PJSUA_LIB
1355 * @brief Call manipulation.
1356 * @{
1357 */
1358
1359/**
1360 * Max simultaneous calls.
1361 */
1362#ifndef PJSUA_MAX_CALLS
1363# define PJSUA_MAX_CALLS 32
1364#endif
1365
1366
1367
1368/**
1369 * Call media status.
1370 */
1371typedef enum pjsua_call_media_status
1372{
1373 PJSUA_CALL_MEDIA_NONE,
1374 PJSUA_CALL_MEDIA_ACTIVE,
1375 PJSUA_CALL_MEDIA_LOCAL_HOLD,
1376 PJSUA_CALL_MEDIA_REMOTE_HOLD,
1377} pjsua_call_media_status;
1378
1379
1380/**
1381 * Call info.
1382 */
1383typedef struct pjsua_call_info
1384{
1385 /** Call identification. */
1386 pjsua_call_id id;
1387
1388 /** Initial call role (UAC == caller) */
1389 pjsip_role_e role;
1390
1391 /** Local URI */
1392 pj_str_t local_info;
1393
1394 /** Local Contact */
1395 pj_str_t local_contact;
1396
1397 /** Remote URI */
1398 pj_str_t remote_info;
1399
1400 /** Remote contact */
1401 pj_str_t remote_contact;
1402
1403 /** Dialog Call-ID string. */
1404 pj_str_t call_id;
1405
1406 /** Call state */
1407 pjsip_inv_state state;
1408
1409 /** Text describing the state */
1410 pj_str_t state_text;
1411
1412 /** Last status code heard, which can be used as cause code */
1413 pjsip_status_code last_status;
1414
1415 /** The reason phrase describing the status. */
1416 pj_str_t last_status_text;
1417
1418 /** Call media status. */
1419 pjsua_call_media_status media_status;
1420
1421 /** Media direction */
1422 pjmedia_dir media_dir;
1423
1424 /** The conference port number for the call */
1425 pjsua_conf_port_id conf_slot;
1426
1427 /** Up-to-date call connected duration (zero when call is not
1428 * established)
1429 */
1430 pj_time_val connect_duration;
1431
1432 /** Total call duration, including set-up time */
1433 pj_time_val total_duration;
1434
1435 /** Internal */
1436 struct {
1437 char local_info[128];
1438 char local_contact[128];
1439 char remote_info[128];
1440 char remote_contact[128];
1441 char call_id[128];
1442 char last_status_text[128];
1443 } buf_;
1444
1445} pjsua_call_info;
1446
1447
1448
Benny Prijonoa91a0032006-02-26 21:23:45 +00001449/**
Benny Prijono9fc735d2006-05-28 14:58:12 +00001450 * Get maximum number of calls configured in pjsua.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001451 *
1452 * @return Maximum number of calls configured.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001453 */
Benny Prijono8b1889b2006-06-06 18:40:40 +00001454PJ_DECL(unsigned) pjsua_call_get_max_count(void);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001455
1456/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001457 * Get number of currently active calls.
1458 *
1459 * @return Number of currently active calls.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001460 */
Benny Prijono8b1889b2006-06-06 18:40:40 +00001461PJ_DECL(unsigned) pjsua_call_get_count(void);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001462
1463/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001464 * Enumerate all active calls.
1465 *
1466 * @param ids Array of account IDs to be initialized.
1467 * @param count In input, specifies the maximum number of elements.
1468 * On return, it contains the actual number of elements.
1469 *
1470 * @return PJ_SUCCESS on success, or the appropriate error code.
1471 */
1472PJ_DECL(pj_status_t) pjsua_enum_calls(pjsua_call_id ids[],
1473 unsigned *count);
1474
1475
1476/**
1477 * Make outgoing call to the specified URI using the specified account.
1478 *
1479 * @param acc_id The account to be used.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001480 * @param dst_uri URI to be put in the To header (normally is the same
1481 * as the target URI).
1482 * @param options Options (must be zero at the moment).
1483 * @param user_data Arbitrary user data to be attached to the call, and
1484 * can be retrieved later.
1485 * @param msg_data Optional headers etc to be added to outgoing INVITE
1486 * request, or NULL if no custom header is desired.
1487 * @param p_call_id Pointer to receive call identification.
1488 *
1489 * @return PJ_SUCCESS on success, or the appropriate error code.
1490 */
1491PJ_DECL(pj_status_t) pjsua_call_make_call(pjsua_acc_id acc_id,
1492 const pj_str_t *dst_uri,
1493 unsigned options,
1494 void *user_data,
1495 const pjsua_msg_data *msg_data,
1496 pjsua_call_id *p_call_id);
1497
1498
1499/**
Benny Prijono9fc735d2006-05-28 14:58:12 +00001500 * Check if the specified call has active INVITE session and the INVITE
1501 * session has not been disconnected.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001502 *
1503 * @param call_id Call identification.
1504 *
1505 * @return Non-zero if call is active.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001506 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001507PJ_DECL(pj_bool_t) pjsua_call_is_active(pjsua_call_id call_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001508
1509
1510/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001511 * Check if call has an active media session.
1512 *
1513 * @param call_id Call identification.
1514 *
1515 * @return Non-zero if yes.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001516 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001517PJ_DECL(pj_bool_t) pjsua_call_has_media(pjsua_call_id call_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001518
1519
1520/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001521 * Get the conference port identification associated with the call.
1522 *
1523 * @param call_id Call identification.
1524 *
1525 * @return Conference port ID, or PJSUA_INVALID_ID when the
1526 * media has not been established or is not active.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001527 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001528PJ_DECL(pjsua_conf_port_id) pjsua_call_get_conf_port(pjsua_call_id call_id);
1529
1530/**
1531 * Obtain detail information about the specified call.
1532 *
1533 * @param call_id Call identification.
1534 * @param info Call info to be initialized.
1535 *
1536 * @return PJ_SUCCESS on success, or the appropriate error code.
1537 */
1538PJ_DECL(pj_status_t) pjsua_call_get_info(pjsua_call_id call_id,
Benny Prijono9fc735d2006-05-28 14:58:12 +00001539 pjsua_call_info *info);
1540
1541
1542/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001543 * Attach application specific data to the call.
1544 *
1545 * @param call_id Call identification.
1546 * @param user_data Arbitrary data to be attached to the call.
1547 *
1548 * @return The user data.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001549 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001550PJ_DECL(pj_status_t) pjsua_call_set_user_data(pjsua_call_id call_id,
1551 void *user_data);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001552
1553
1554/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001555 * Get user data attached to the call.
1556 *
1557 * @param call_id Call identification.
1558 *
1559 * @return The user data.
Benny Prijono268ca612006-02-07 12:34:11 +00001560 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001561PJ_DECL(void*) pjsua_call_get_user_data(pjsua_call_id call_id);
Benny Prijono84126ab2006-02-09 09:30:09 +00001562
1563
1564/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001565 * Send response to incoming INVITE request.
1566 *
1567 * @param call_id Incoming call identification.
1568 * @param code Status code, (100-699).
1569 * @param reason Optional reason phrase. If NULL, default text
1570 * will be used.
1571 * @param msg_data Optional list of headers etc to be added to outgoing
1572 * response message.
1573 *
1574 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonoa91a0032006-02-26 21:23:45 +00001575 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001576PJ_DECL(pj_status_t) pjsua_call_answer(pjsua_call_id call_id,
1577 unsigned code,
1578 const pj_str_t *reason,
1579 const pjsua_msg_data *msg_data);
Benny Prijonoa91a0032006-02-26 21:23:45 +00001580
1581/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001582 * Hangup call by using method that is appropriate according to the
1583 * call state.
1584 *
1585 * @param call_id Call identification.
1586 * @param code Optional status code to be sent when we're rejecting
1587 * incoming call. If the value is zero, "603/Decline"
1588 * will be sent.
1589 * @param reason Optional reason phrase to be sent when we're rejecting
1590 * incoming call. If NULL, default text will be used.
1591 * @param msg_data Optional list of headers etc to be added to outgoing
1592 * request/response message.
1593 *
1594 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono26ff9062006-02-21 23:47:00 +00001595 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001596PJ_DECL(pj_status_t) pjsua_call_hangup(pjsua_call_id call_id,
1597 unsigned code,
1598 const pj_str_t *reason,
1599 const pjsua_msg_data *msg_data);
Benny Prijono26ff9062006-02-21 23:47:00 +00001600
1601
1602/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001603 * Put the specified call on hold.
1604 *
1605 * @param call_id Call identification.
1606 * @param msg_data Optional message components to be sent with
1607 * the request.
1608 *
1609 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono26ff9062006-02-21 23:47:00 +00001610 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001611PJ_DECL(pj_status_t) pjsua_call_set_hold(pjsua_call_id call_id,
1612 const pjsua_msg_data *msg_data);
Benny Prijono26ff9062006-02-21 23:47:00 +00001613
1614
1615/**
1616 * Send re-INVITE (to release hold).
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001617 *
1618 * @param call_id Call identification.
1619 * @param unhold If this argument is non-zero and the call is locally
1620 * held, this will release the local hold.
1621 * @param msg_data Optional message components to be sent with
1622 * the request.
1623 *
1624 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono26ff9062006-02-21 23:47:00 +00001625 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001626PJ_DECL(pj_status_t) pjsua_call_reinvite(pjsua_call_id call_id,
1627 pj_bool_t unhold,
1628 const pjsua_msg_data *msg_data);
Benny Prijono26ff9062006-02-21 23:47:00 +00001629
1630
1631/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001632 * Initiate call transfer to the specified address.
1633 *
1634 * @param call_id Call identification.
1635 * @param dest Address of new target to be contacted.
1636 * @param msg_data Optional message components to be sent with
1637 * the request.
1638 *
1639 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono26ff9062006-02-21 23:47:00 +00001640 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001641PJ_DECL(pj_status_t) pjsua_call_xfer(pjsua_call_id call_id,
1642 const pj_str_t *dest,
1643 const pjsua_msg_data *msg_data);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001644
1645/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001646 * Send DTMF digits to remote using RFC 2833 payload formats.
1647 *
1648 * @param call_id Call identification.
1649 * @param digits DTMF digits to be sent.
1650 *
1651 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001652 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001653PJ_DECL(pj_status_t) pjsua_call_dial_dtmf(pjsua_call_id call_id,
Benny Prijono9fc735d2006-05-28 14:58:12 +00001654 const pj_str_t *digits);
Benny Prijono26ff9062006-02-21 23:47:00 +00001655
Benny Prijono26ff9062006-02-21 23:47:00 +00001656/**
Benny Prijonob0808372006-03-02 21:18:58 +00001657 * Send instant messaging inside INVITE session.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001658 *
1659 * @param call_id Call identification.
1660 * @param mime_type Optional MIME type. If NULL, then "text/plain" is
1661 * assumed.
1662 * @param content The message content.
1663 * @param msg_data Optional list of headers etc to be included in outgoing
1664 * request. The body descriptor in the msg_data is
1665 * ignored.
1666 * @param user_data Optional user data, which will be given back when
1667 * the IM callback is called.
1668 *
1669 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonob0808372006-03-02 21:18:58 +00001670 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001671PJ_DECL(pj_status_t) pjsua_call_send_im( pjsua_call_id call_id,
1672 const pj_str_t *mime_type,
1673 const pj_str_t *content,
1674 const pjsua_msg_data *msg_data,
1675 void *user_data);
Benny Prijonob0808372006-03-02 21:18:58 +00001676
1677
1678/**
1679 * Send IM typing indication inside INVITE session.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001680 *
1681 * @param call_id Call identification.
1682 * @param is_typing Non-zero to indicate to remote that local person is
1683 * currently typing an IM.
1684 * @param msg_data Optional list of headers etc to be included in outgoing
1685 * request.
1686 *
1687 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonob0808372006-03-02 21:18:58 +00001688 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001689PJ_DECL(pj_status_t) pjsua_call_send_typing_ind(pjsua_call_id call_id,
1690 pj_bool_t is_typing,
1691 const pjsua_msg_data*msg_data);
Benny Prijonob0808372006-03-02 21:18:58 +00001692
1693/**
Benny Prijono834aee32006-02-19 01:38:06 +00001694 * Terminate all calls.
1695 */
Benny Prijonodc39fe82006-05-26 12:17:46 +00001696PJ_DECL(void) pjsua_call_hangup_all(void);
Benny Prijono834aee32006-02-19 01:38:06 +00001697
1698
Benny Prijonob9b32ab2006-06-01 12:28:44 +00001699/**
1700 * Dump call and media statistics to string.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001701 *
1702 * @param call_id Call identification.
1703 * @param with_media Non-zero to include media information too.
1704 * @param buffer Buffer where the statistics are to be written to.
1705 * @param maxlen Maximum length of buffer.
1706 * @param indent Spaces for left indentation.
1707 *
1708 * @return PJ_SUCCESS on success.
Benny Prijonob9b32ab2006-06-01 12:28:44 +00001709 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001710PJ_DECL(pj_status_t) pjsua_call_dump(pjsua_call_id call_id,
1711 pj_bool_t with_media,
1712 char *buffer,
1713 unsigned maxlen,
1714 const char *indent);
Benny Prijonob9b32ab2006-06-01 12:28:44 +00001715
Benny Prijono9fc735d2006-05-28 14:58:12 +00001716/**
Benny Prijono312aff92006-06-17 04:08:30 +00001717 * @}
Benny Prijono9fc735d2006-05-28 14:58:12 +00001718 */
Benny Prijono834aee32006-02-19 01:38:06 +00001719
1720
1721/*****************************************************************************
Benny Prijono312aff92006-06-17 04:08:30 +00001722 * BUDDY API
Benny Prijono834aee32006-02-19 01:38:06 +00001723 */
1724
Benny Prijono312aff92006-06-17 04:08:30 +00001725
1726/**
1727 * @defgroup PJSUA_LIB_BUDDY Buddy, Presence, and Instant Messaging
1728 * @ingroup PJSUA_LIB
1729 * @brief Buddy management, buddy's presence, and instant messaging.
1730 * @{
1731 */
1732
1733/**
1734 * Max buddies in buddy list.
1735 */
1736#ifndef PJSUA_MAX_BUDDIES
1737# define PJSUA_MAX_BUDDIES 256
1738#endif
1739
1740
1741/**
1742 * Buddy configuration.
1743 */
1744typedef struct pjsua_buddy_config
1745{
1746 /**
1747 * Buddy URL or name address.
1748 */
1749 pj_str_t uri;
1750
1751 /**
1752 * Specify whether presence subscription should start immediately.
1753 */
1754 pj_bool_t subscribe;
1755
1756} pjsua_buddy_config;
1757
1758
1759/**
1760 * Buddy's online status.
1761 */
1762typedef enum pjsua_buddy_status
1763{
1764 /**
1765 * Online status is unknown (possibly because no presence subscription
1766 * has been established).
1767 */
1768 PJSUA_BUDDY_STATUS_UNKNOWN,
1769
1770 /**
1771 * Buddy is known to be offline.
1772 */
1773 PJSUA_BUDDY_STATUS_ONLINE,
1774
1775 /**
1776 * Buddy is offline.
1777 */
1778 PJSUA_BUDDY_STATUS_OFFLINE,
1779
1780} pjsua_buddy_status;
1781
1782
1783
1784/**
1785 * Buddy info.
1786 */
1787typedef struct pjsua_buddy_info
1788{
1789 /**
1790 * The buddy ID.
1791 */
1792 pjsua_buddy_id id;
1793
1794 /**
1795 * The full URI of the buddy, as specified in the configuration.
1796 */
1797 pj_str_t uri;
1798
1799 /**
1800 * Buddy's Contact, only available when presence subscription has
1801 * been established to the buddy.
1802 */
1803 pj_str_t contact;
1804
1805 /**
1806 * Buddy's online status.
1807 */
1808 pjsua_buddy_status status;
1809
1810 /**
1811 * Text to describe buddy's online status.
1812 */
1813 pj_str_t status_text;
1814
1815 /**
1816 * Flag to indicate that we should monitor the presence information for
1817 * this buddy (normally yes, unless explicitly disabled).
1818 */
1819 pj_bool_t monitor_pres;
1820
1821 /**
1822 * Internal buffer.
1823 */
1824 char buf_[256];
1825
1826} pjsua_buddy_info;
1827
1828
Benny Prijono834aee32006-02-19 01:38:06 +00001829/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001830 * Get total number of buddies.
1831 *
1832 * @return Number of buddies.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001833 */
1834PJ_DECL(unsigned) pjsua_get_buddy_count(void);
1835
1836
1837/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001838 * Check if buddy ID is valid.
1839 *
1840 * @param buddy_id Buddy ID to check.
1841 *
1842 * @return Non-zero if buddy ID is valid.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001843 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001844PJ_DECL(pj_bool_t) pjsua_buddy_is_valid(pjsua_buddy_id buddy_id);
1845
1846
1847/**
1848 * Enum buddy IDs.
1849 *
1850 * @param ids Array of ids to be initialized.
1851 * @param count On input, specifies max elements in the array.
1852 * On return, it contains actual number of elements
1853 * that have been initialized.
1854 *
1855 * @return PJ_SUCCESS on success, or the appropriate error code.
1856 */
1857PJ_DECL(pj_status_t) pjsua_enum_buddies(pjsua_buddy_id ids[],
1858 unsigned *count);
1859
1860/**
1861 * Get detailed buddy info.
1862 *
1863 * @param buddy_id The buddy identification.
1864 * @param info Pointer to receive information about buddy.
1865 *
1866 * @return PJ_SUCCESS on success, or the appropriate error code.
1867 */
1868PJ_DECL(pj_status_t) pjsua_buddy_get_info(pjsua_buddy_id buddy_id,
Benny Prijono9fc735d2006-05-28 14:58:12 +00001869 pjsua_buddy_info *info);
1870
1871/**
1872 * Add new buddy.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001873 *
1874 * @param cfg Buddy configuration.
1875 * @param p_buddy_id Pointer to receive buddy ID.
1876 *
1877 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001878 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001879PJ_DECL(pj_status_t) pjsua_buddy_add(const pjsua_buddy_config *cfg,
1880 pjsua_buddy_id *p_buddy_id);
Benny Prijono8b1889b2006-06-06 18:40:40 +00001881
1882
1883/**
1884 * Delete buddy.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001885 *
1886 * @param buddy_id Buddy identification.
1887 *
1888 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono8b1889b2006-06-06 18:40:40 +00001889 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001890PJ_DECL(pj_status_t) pjsua_buddy_del(pjsua_buddy_id buddy_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001891
1892
1893/**
1894 * Enable/disable buddy's presence monitoring.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001895 *
1896 * @param buddy_id Buddy identification.
1897 * @param subscribe Specify non-zero to activate presence subscription to
1898 * the specified buddy.
1899 *
1900 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00001901 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001902PJ_DECL(pj_status_t) pjsua_buddy_subscribe_pres(pjsua_buddy_id buddy_id,
1903 pj_bool_t subscribe);
Benny Prijono9fc735d2006-05-28 14:58:12 +00001904
1905
1906/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001907 * Dump presence subscriptions to log file.
1908 *
1909 * @param verbose Yes or no.
Benny Prijono834aee32006-02-19 01:38:06 +00001910 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001911PJ_DECL(void) pjsua_pres_dump(pj_bool_t verbose);
Benny Prijono834aee32006-02-19 01:38:06 +00001912
1913
Benny Prijonob0808372006-03-02 21:18:58 +00001914/**
1915 * The MESSAGE method (defined in pjsua_im.c)
1916 */
1917extern const pjsip_method pjsip_message_method;
1918
1919
Benny Prijonob0808372006-03-02 21:18:58 +00001920
1921/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001922 * Send instant messaging outside dialog, using the specified account for
1923 * route set and authentication.
1924 *
1925 * @param acc_id Account ID to be used to send the request.
1926 * @param to Remote URI.
1927 * @param mime_type Optional MIME type. If NULL, then "text/plain" is
1928 * assumed.
1929 * @param content The message content.
1930 * @param msg_data Optional list of headers etc to be included in outgoing
1931 * request. The body descriptor in the msg_data is
1932 * ignored.
1933 * @param user_data Optional user data, which will be given back when
1934 * the IM callback is called.
1935 *
1936 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonob0808372006-03-02 21:18:58 +00001937 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001938PJ_DECL(pj_status_t) pjsua_im_send(pjsua_acc_id acc_id,
1939 const pj_str_t *to,
1940 const pj_str_t *mime_type,
1941 const pj_str_t *content,
1942 const pjsua_msg_data *msg_data,
1943 void *user_data);
Benny Prijonob0808372006-03-02 21:18:58 +00001944
1945
1946/**
1947 * Send typing indication outside dialog.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001948 *
1949 * @param acc_id Account ID to be used to send the request.
1950 * @param to Remote URI.
1951 * @param is_typing If non-zero, it tells remote person that local person
1952 * is currently composing an IM.
1953 * @param msg_data Optional list of headers etc to be added to outgoing
1954 * request.
1955 *
1956 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonob0808372006-03-02 21:18:58 +00001957 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001958PJ_DECL(pj_status_t) pjsua_im_typing(pjsua_acc_id acc_id,
1959 const pj_str_t *to,
1960 pj_bool_t is_typing,
1961 const pjsua_msg_data *msg_data);
Benny Prijonob0808372006-03-02 21:18:58 +00001962
1963
Benny Prijonof3195072006-02-14 21:15:30 +00001964
Benny Prijono312aff92006-06-17 04:08:30 +00001965/**
1966 * @}
Benny Prijono9fc735d2006-05-28 14:58:12 +00001967 */
1968
Benny Prijono312aff92006-06-17 04:08:30 +00001969
1970/*****************************************************************************
1971 * MEDIA API
1972 */
1973
1974
1975/**
1976 * @defgroup PJSUA_LIB_MEDIA Media
1977 * @ingroup PJSUA_LIB
1978 * @brief Media manipulation.
1979 * @{
1980 *
1981 * PJSUA has rather powerful media features, which are built around the
1982 * PJMEDIA conference bridge. Basically, all media termination (such as
1983 * calls, file players, file recorders, sound device, tone generators, etc)
1984 * are terminated in the conference bridge, and application can manipulate
1985 * the interconnection between these terminations freely. If more than
1986 * one media terminations are terminated in the same slot, the conference
1987 * bridge will mix the signal automatically.
1988 *
1989 * Application connects one media termination/slot to another by calling
1990 * #pjsua_conf_connect() function. This will establish <b>unidirectional</b>
1991 * media flow from the source termination to the sink termination. For
1992 * example, to stream a WAV file to remote call, application may use
1993 * the following steps:
1994 *
1995 \code
1996
1997 pj_status_t stream_to_call( pjsua_call_id call_id )
1998 {
1999 pjsua_player_id player_id;
2000
2001 status = pjsua_player_create("mysong.wav", 0, NULL, &player_id);
2002 if (status != PJ_SUCCESS)
2003 return status;
2004
2005 status = pjsua_conf_connect( pjsua_player_get_conf_port(),
2006 pjsua_call_get_conf_port() );
2007 }
2008 \endcode
2009 *
2010 *
2011 * Other features of PJSUA media:
2012 * - efficient N to M interconnections between media terminations.
2013 * - media termination can be connected to itself to create loopback
2014 * media.
2015 * - the media termination may have different clock rates, and resampling
2016 * will be done automatically by conference bridge.
2017 * - media terminations may also have different frame time; the
2018 * conference bridge will perform the necessary bufferring to adjust
2019 * the difference between terminations.
2020 * - interconnections are removed automatically when media termination
2021 * is removed from the bridge.
2022 * - sound device may be changed even when there are active media
2023 * interconnections.
2024 * - correctly report call's media quality (in #pjsua_call_dump()) from
2025 * RTCP packet exchange.
2026 */
2027
2028/**
2029 * Max ports in the conference bridge.
2030 */
2031#ifndef PJSUA_MAX_CONF_PORTS
2032# define PJSUA_MAX_CONF_PORTS 254
2033#endif
2034
2035
2036
2037/**
2038 * Media configuration.
2039 */
2040struct pjsua_media_config
2041{
2042 /**
2043 * Clock rate to be applied to the conference bridge.
2044 * If value is zero, default clock rate will be used (16KHz).
2045 */
2046 unsigned clock_rate;
2047
2048 /**
2049 * Specify maximum number of media ports to be created in the
2050 * conference bridge. Since all media terminate in the bridge
2051 * (calls, file player, file recorder, etc), the value must be
2052 * large enough to support all of them. However, the larger
2053 * the value, the more computations are performed.
2054 */
2055 unsigned max_media_ports;
2056
2057 /**
2058 * Specify whether the media manager should manage its own
2059 * ioqueue for the RTP/RTCP sockets. If yes, ioqueue will be created
2060 * and at least one worker thread will be created too. If no,
2061 * the RTP/RTCP sockets will share the same ioqueue as SIP sockets,
2062 * and no worker thread is needed.
2063 *
2064 * Normally application would say yes here, unless it wants to
2065 * run everything from a single thread.
2066 */
2067 pj_bool_t has_ioqueue;
2068
2069 /**
2070 * Specify the number of worker threads to handle incoming RTP
2071 * packets. A value of one is recommended for most applications.
2072 */
2073 unsigned thread_cnt;
2074
Benny Prijono0498d902006-06-19 14:49:14 +00002075 /**
2076 * Media quality, 0-10, according to this table:
2077 * 8-10: resampling use large filter,
2078 * 3-7: resampling use small filter,
2079 * 1-2: resampling use linear.
2080 * The media quality also sets speex codec quality/complexity to the
2081 * number.
2082 *
Benny Prijono18e49822006-06-22 22:28:28 +00002083 * Default: 3.
Benny Prijono0498d902006-06-19 14:49:14 +00002084 */
2085 unsigned quality;
Benny Prijono312aff92006-06-17 04:08:30 +00002086};
2087
2088
2089/**
2090 * Use this function to initialize media config.
2091 *
2092 * @param cfg The media config to be initialized.
2093 */
2094PJ_INLINE(void) pjsua_media_config_default(pjsua_media_config *cfg)
2095{
Benny Prijonoac623b32006-07-03 15:19:31 +00002096 pj_bzero(cfg, sizeof(*cfg));
Benny Prijono312aff92006-06-17 04:08:30 +00002097
2098 cfg->clock_rate = 16000;
2099 cfg->max_media_ports = 32;
2100 cfg->has_ioqueue = PJ_TRUE;
2101 cfg->thread_cnt = 1;
Benny Prijono18e49822006-06-22 22:28:28 +00002102 cfg->quality = 3;
Benny Prijono312aff92006-06-17 04:08:30 +00002103}
2104
2105
2106
2107/**
2108 * Codec config.
2109 */
2110typedef struct pjsua_codec_info
2111{
2112 /**
2113 * Codec unique identification.
2114 */
2115 pj_str_t codec_id;
2116
2117 /**
2118 * Codec priority (integer 0-255).
2119 */
2120 pj_uint8_t priority;
2121
2122 /**
2123 * Internal buffer.
2124 */
2125 char buf_[32];
2126
2127} pjsua_codec_info;
2128
2129
2130/**
2131 * Conference port info.
2132 */
2133typedef struct pjsua_conf_port_info
2134{
2135 /** Conference port number. */
2136 pjsua_conf_port_id slot_id;
2137
2138 /** Port name. */
2139 pj_str_t name;
2140
2141 /** Clock rate. */
2142 unsigned clock_rate;
2143
2144 /** Number of channels. */
2145 unsigned channel_count;
2146
2147 /** Samples per frame */
2148 unsigned samples_per_frame;
2149
2150 /** Bits per sample */
2151 unsigned bits_per_sample;
2152
2153 /** Number of listeners in the array. */
2154 unsigned listener_cnt;
2155
2156 /** Array of listeners (in other words, ports where this port is
2157 * transmitting to.
2158 */
2159 pjsua_conf_port_id listeners[PJSUA_MAX_CONF_PORTS];
2160
2161} pjsua_conf_port_info;
2162
2163
2164/**
2165 * This structure holds information about custom media transport to
2166 * be registered to pjsua.
2167 */
2168typedef struct pjsua_media_transport
2169{
2170 /**
2171 * Media socket information containing the address information
2172 * of the RTP and RTCP socket.
2173 */
2174 pjmedia_sock_info skinfo;
2175
2176 /**
2177 * The media transport instance.
2178 */
2179 pjmedia_transport *transport;
2180
2181} pjsua_media_transport;
2182
2183
2184
2185
Benny Prijono9fc735d2006-05-28 14:58:12 +00002186/**
2187 * Get maxinum number of conference ports.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002188 *
2189 * @return Maximum number of ports in the conference bridge.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002190 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002191PJ_DECL(unsigned) pjsua_conf_get_max_ports(void);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002192
2193
2194/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002195 * Get current number of active ports in the bridge.
2196 *
2197 * @return The number.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002198 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002199PJ_DECL(unsigned) pjsua_conf_get_active_ports(void);
2200
2201
2202/**
2203 * Enumerate all conference ports.
2204 *
2205 * @param id Array of conference port ID to be initialized.
2206 * @param count On input, specifies max elements in the array.
2207 * On return, it contains actual number of elements
2208 * that have been initialized.
2209 *
2210 * @return PJ_SUCCESS on success, or the appropriate error code.
2211 */
2212PJ_DECL(pj_status_t) pjsua_enum_conf_ports(pjsua_conf_port_id id[],
2213 unsigned *count);
Benny Prijono8b1889b2006-06-06 18:40:40 +00002214
2215
2216/**
2217 * Get information about the specified conference port
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002218 *
2219 * @param id Port identification.
2220 * @param info Pointer to store the port info.
2221 *
2222 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono8b1889b2006-06-06 18:40:40 +00002223 */
2224PJ_DECL(pj_status_t) pjsua_conf_get_port_info( pjsua_conf_port_id id,
2225 pjsua_conf_port_info *info);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002226
2227
2228/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002229 * Establish unidirectional media flow from souce to sink. One source
2230 * may transmit to multiple destinations/sink. And if multiple
2231 * sources are transmitting to the same sink, the media will be mixed
2232 * together. Source and sink may refer to the same ID, effectively
2233 * looping the media.
2234 *
2235 * If bidirectional media flow is desired, application needs to call
2236 * this function twice, with the second one having the arguments
2237 * reversed.
2238 *
2239 * @param source Port ID of the source media/transmitter.
2240 * @param sink Port ID of the destination media/received.
2241 *
2242 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002243 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002244PJ_DECL(pj_status_t) pjsua_conf_connect(pjsua_conf_port_id source,
2245 pjsua_conf_port_id sink);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002246
2247
2248/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002249 * Disconnect media flow from the source to destination port.
2250 *
2251 * @param source Port ID of the source media/transmitter.
2252 * @param sink Port ID of the destination media/received.
2253 *
2254 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002255 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002256PJ_DECL(pj_status_t) pjsua_conf_disconnect(pjsua_conf_port_id source,
2257 pjsua_conf_port_id sink);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002258
2259
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002260/*****************************************************************************
2261 * File player.
2262 */
2263
Benny Prijono9fc735d2006-05-28 14:58:12 +00002264/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002265 * Create a file player, and automatically connect this player to
2266 * the conference bridge.
2267 *
2268 * @param filename The filename to be played. Currently only
Benny Prijono312aff92006-06-17 04:08:30 +00002269 * WAV files are supported, and the WAV file MUST be
2270 * formatted as 16bit PCM mono/single channel (any
2271 * clock rate is supported).
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002272 * @param options Options (currently zero).
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002273 * @param p_id Pointer to receive player ID.
2274 *
2275 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002276 */
2277PJ_DECL(pj_status_t) pjsua_player_create(const pj_str_t *filename,
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002278 unsigned options,
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002279 pjsua_player_id *p_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002280
2281
2282/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002283 * Get conference port ID associated with player.
2284 *
2285 * @param id The file player ID.
2286 *
2287 * @return Conference port ID associated with this player.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002288 */
Benny Prijono8b1889b2006-06-06 18:40:40 +00002289PJ_DECL(pjsua_conf_port_id) pjsua_player_get_conf_port(pjsua_player_id id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002290
2291
2292/**
2293 * Set playback position.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002294 *
2295 * @param id The file player ID.
2296 * @param samples The playback position, in samples. Application can
2297 * specify zero to re-start the playback.
2298 *
2299 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002300 */
2301PJ_DECL(pj_status_t) pjsua_player_set_pos(pjsua_player_id id,
2302 pj_uint32_t samples);
2303
2304
2305/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002306 * Close the file, remove the player from the bridge, and free
2307 * resources associated with the file player.
2308 *
2309 * @param id The file player ID.
2310 *
2311 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002312 */
2313PJ_DECL(pj_status_t) pjsua_player_destroy(pjsua_player_id id);
2314
2315
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002316/*****************************************************************************
2317 * File recorder.
2318 */
Benny Prijono9fc735d2006-05-28 14:58:12 +00002319
2320/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002321 * Create a file recorder, and automatically connect this recorder to
2322 * the conference bridge.
2323 *
2324 * @param filename Output file name.
2325 * @param file_format Specify the file format (currently only WAV is
2326 * supported, so the value MUST be zero).
2327 * @param encoding Specify the encoding to be applied to the file.
2328 * Currently only 16bit raw PCM is supported, so
2329 * the value must be NULL.
2330 * @param max_size Maximum file size. Specify -1 to remove size
2331 * limitation.
2332 * @param options Optional options.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002333 * @param p_id Pointer to receive the recorder instance.
2334 *
2335 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002336 */
2337PJ_DECL(pj_status_t) pjsua_recorder_create(const pj_str_t *filename,
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002338 unsigned file_format,
2339 const pj_str_t *encoding,
2340 pj_ssize_t max_size,
2341 unsigned options,
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002342 pjsua_recorder_id *p_id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002343
2344
2345/**
2346 * Get conference port associated with recorder.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002347 *
2348 * @param id The recorder ID.
2349 *
2350 * @return Conference port ID associated with this recorder.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002351 */
Benny Prijono8b1889b2006-06-06 18:40:40 +00002352PJ_DECL(pjsua_conf_port_id) pjsua_recorder_get_conf_port(pjsua_recorder_id id);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002353
2354
2355/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002356 * Destroy recorder (this will complete recording).
2357 *
2358 * @param id The recorder ID.
2359 *
2360 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002361 */
2362PJ_DECL(pj_status_t) pjsua_recorder_destroy(pjsua_recorder_id id);
2363
2364
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002365/*****************************************************************************
2366 * Sound devices.
2367 */
2368
Benny Prijono9fc735d2006-05-28 14:58:12 +00002369/**
2370 * Enum sound devices.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002371 *
2372 * @param info Array of info to be initialized.
2373 * @param count On input, specifies max elements in the array.
2374 * On return, it contains actual number of elements
2375 * that have been initialized.
2376 *
2377 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002378 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002379PJ_DECL(pj_status_t) pjsua_enum_snd_devs(pjmedia_snd_dev_info info[],
2380 unsigned *count);
Benny Prijono9fc735d2006-05-28 14:58:12 +00002381
2382
2383/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002384 * Select or change sound device. Application may call this function at
2385 * any time to replace current sound device.
2386 *
2387 * @param capture_dev Device ID of the capture device.
2388 * @param playback_dev Device ID of the playback device.
2389 *
2390 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijono9fc735d2006-05-28 14:58:12 +00002391 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002392PJ_DECL(pj_status_t) pjsua_set_snd_dev(int capture_dev,
2393 int playback_dev);
2394
2395
2396/**
2397 * Set pjsua to use null sound device. The null sound device only provides
2398 * the timing needed by the conference bridge, and will not interract with
2399 * any hardware.
2400 *
2401 * @return PJ_SUCCESS on success, or the appropriate error code.
2402 */
2403PJ_DECL(pj_status_t) pjsua_set_null_snd_dev(void);
2404
2405
2406/*****************************************************************************
2407 * Codecs.
2408 */
2409
2410/**
2411 * Enum all supported codecs in the system.
2412 *
2413 * @param id Array of ID to be initialized.
2414 * @param count On input, specifies max elements in the array.
2415 * On return, it contains actual number of elements
2416 * that have been initialized.
2417 *
2418 * @return PJ_SUCCESS on success, or the appropriate error code.
2419 */
2420PJ_DECL(pj_status_t) pjsua_enum_codecs( pjsua_codec_info id[],
2421 unsigned *count );
2422
2423
2424/**
2425 * Change codec priority.
2426 *
2427 * @param id Codec ID.
2428 * @param priority Codec priority, 0-255, where zero means to disable
2429 * the codec.
2430 *
2431 * @return PJ_SUCCESS on success, or the appropriate error code.
2432 */
2433PJ_DECL(pj_status_t) pjsua_codec_set_priority( const pj_str_t *id,
2434 pj_uint8_t priority );
2435
2436
2437/**
2438 * Get codec parameters.
2439 *
2440 * @param id Codec ID.
2441 * @param param Structure to receive codec parameters.
2442 *
2443 * @return PJ_SUCCESS on success, or the appropriate error code.
2444 */
2445PJ_DECL(pj_status_t) pjsua_codec_get_param( const pj_str_t *id,
2446 pjmedia_codec_param *param );
2447
2448
2449/**
2450 * Set codec parameters.
2451 *
2452 * @param id Codec ID.
2453 * @param param Codec parameter to set.
2454 *
2455 * @return PJ_SUCCESS on success, or the appropriate error code.
2456 */
2457PJ_DECL(pj_status_t) pjsua_codec_set_param( const pj_str_t *id,
2458 const pjmedia_codec_param *param);
2459
2460
2461
Benny Prijono9fc735d2006-05-28 14:58:12 +00002462
Benny Prijono312aff92006-06-17 04:08:30 +00002463/**
2464 * Create UDP media transports for all the calls. This function creates
2465 * one UDP media transport for each call.
Benny Prijonof3195072006-02-14 21:15:30 +00002466 *
Benny Prijono312aff92006-06-17 04:08:30 +00002467 * @param cfg Media transport configuration. The "port" field in the
2468 * configuration is used as the start port to bind the
2469 * sockets.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002470 *
2471 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonof3195072006-02-14 21:15:30 +00002472 */
Benny Prijono312aff92006-06-17 04:08:30 +00002473PJ_DECL(pj_status_t)
2474pjsua_media_transports_create(const pjsua_transport_config *cfg);
Benny Prijonof3195072006-02-14 21:15:30 +00002475
Benny Prijonodc39fe82006-05-26 12:17:46 +00002476
2477/**
Benny Prijono312aff92006-06-17 04:08:30 +00002478 * Register custom media transports to be used by calls. There must
2479 * enough media transports for all calls.
Benny Prijonoeebe9af2006-06-13 22:57:13 +00002480 *
Benny Prijono312aff92006-06-17 04:08:30 +00002481 * @param tp The media transport array.
2482 * @param count Number of elements in the array. This number MUST
2483 * match the number of maximum calls configured when
2484 * pjsua is created.
2485 * @param auto_delete Flag to indicate whether the transports should be
2486 * destroyed when pjsua is shutdown.
2487 *
2488 * @return PJ_SUCCESS on success, or the appropriate error code.
Benny Prijonodc39fe82006-05-26 12:17:46 +00002489 */
Benny Prijono312aff92006-06-17 04:08:30 +00002490PJ_DECL(pj_status_t)
2491pjsua_media_transports_attach( pjsua_media_transport tp[],
2492 unsigned count,
2493 pj_bool_t auto_delete);
Benny Prijonodc39fe82006-05-26 12:17:46 +00002494
2495
Benny Prijono312aff92006-06-17 04:08:30 +00002496/**
2497 * @}
2498 */
2499
Benny Prijonof3195072006-02-14 21:15:30 +00002500
Benny Prijono268ca612006-02-07 12:34:11 +00002501
Benny Prijono1a01ad32006-02-07 21:13:28 +00002502PJ_END_DECL
2503
Benny Prijonof3195072006-02-14 21:15:30 +00002504
Benny Prijono312aff92006-06-17 04:08:30 +00002505/**
2506 * @}
2507 */
2508
2509
Benny Prijono268ca612006-02-07 12:34:11 +00002510#endif /* __PJSUA_H__ */