Coverage Report

Created: 2026-06-13 06:53

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pjsip/pjmedia/include/pjmedia/conference.h
Line
Count
Source
1
/* 
2
 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3
 * Copyright (C) 2003-2008 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 __PJMEDIA_CONF_H__
20
#define __PJMEDIA_CONF_H__
21
22
23
/**
24
 * @file conference.h
25
 * @brief Conference bridge.
26
 */
27
#include <pjmedia/port.h>
28
29
/**
30
 * @defgroup PJMEDIA_CONF Conference Bridge
31
 * @ingroup PJMEDIA_PORT
32
 * @brief Audio conference bridge implementation
33
 * @{
34
 *
35
 * This describes the conference bridge implementation in PJMEDIA. The
36
 * conference bridge provides powerful and very efficient mechanism to
37
 * route the audio flow and mix the audio signal when required.
38
 *
39
 * Some more information about the media flow when conference bridge is
40
 * used is described in
41
 * https://docs.pjsip.org/en/latest/specific-guides/media/audio_flow.html .
42
 */
43
44
PJ_BEGIN_DECL
45
46
/* Since 1.3 pjmedia_conf_add_passive_port() has been deprecated
47
 * and replaced by splitcomb.
48
 * See also https://github.com/pjsip/pjproject/issues/2234.
49
 */
50
#ifndef DEPRECATED_FOR_TICKET_2234
51
#  define DEPRECATED_FOR_TICKET_2234    1
52
#endif
53
54
/**
55
 * The conference bridge signature in pjmedia_port_info.
56
 */
57
#define PJMEDIA_CONF_BRIDGE_SIGNATURE   PJMEDIA_SIG_PORT_CONF
58
59
/**
60
 * The audio switchboard signature in pjmedia_port_info.
61
 */
62
#define PJMEDIA_CONF_SWITCH_SIGNATURE   PJMEDIA_SIG_PORT_CONF_SWITCH
63
64
65
/**
66
 * Opaque type for conference bridge.
67
 */
68
typedef struct pjmedia_conf pjmedia_conf;
69
70
/**
71
 * Conference port info.
72
 */
73
typedef struct pjmedia_conf_port_info
74
{
75
    unsigned            slot;               /**< Slot number.               */
76
    pjmedia_dir         dir;                /**< Port direction.            */
77
    pjmedia_obj_sig     signature;          /**< Port signature.            */
78
    pj_str_t            name;               /**< Port name.                 */
79
    pjmedia_format      format;             /**< Format.                    */
80
    pjmedia_port_op     tx_setting;         /**< Transmit settings.         */
81
    pjmedia_port_op     rx_setting;         /**< Receive settings.          */
82
    unsigned            listener_cnt;       /**< Number of listeners.       */
83
    unsigned           *listener_slots;     /**< Array of listeners.        */
84
    unsigned           *listener_adj_level; /**< Array of listeners' level
85
                                                 adjustment                 */
86
    unsigned            transmitter_cnt;    /**< Number of transmitter.     */
87
    unsigned            clock_rate;         /**< Clock rate of the port.    */
88
    unsigned            channel_count;      /**< Number of channels.        */
89
    unsigned            samples_per_frame;  /**< Samples per frame          */
90
    unsigned            bits_per_sample;    /**< Bits per sample.           */
91
    int                 tx_adj_level;       /**< Tx level adjustment.       */
92
    int                 rx_adj_level;       /**< Rx level adjustment.       */
93
} pjmedia_conf_port_info;
94
95
/** 
96
 * Conference operation type enumeration.
97
 */
98
typedef enum pjmedia_conf_op_type
99
{
100
    /**
101
     * The operation is unknown.
102
     */
103
    PJMEDIA_CONF_OP_UNKNOWN,
104
105
    /**
106
     * The adding port operation.
107
     */
108
    PJMEDIA_CONF_OP_ADD_PORT,
109
110
    /**
111
     * The remove port operation.
112
     */
113
    PJMEDIA_CONF_OP_REMOVE_PORT,
114
115
    /**
116
     * The connect ports (start transmit) operation.
117
     */
118
    PJMEDIA_CONF_OP_CONNECT_PORTS,
119
120
    /**
121
     * The disconnect ports (stop transmit) operation.
122
     */
123
    PJMEDIA_CONF_OP_DISCONNECT_PORTS,
124
125
    /**
126
     * The adjust connection level operation.
127
     */
128
    PJMEDIA_CONF_OP_ADJUST_CONN_LEVEL
129
130
} pjmedia_conf_op_type;
131
132
/**
133
 * Conference operation parameter.
134
 */
135
typedef union pjmedia_conf_op_param
136
{
137
    /**
138
     * The information for adding port operation.
139
     */
140
    struct {
141
        unsigned port;      /**< The port id.                           */
142
    } add_port;
143
144
    /**
145
     * The information for removing port operation.
146
     */
147
    struct {
148
        unsigned port;      /**< The port id.                           */
149
    } remove_port;
150
151
    /**
152
     * The information for connecting port operation.
153
     */
154
    struct {
155
        unsigned src;       /**< The source port id.                    */
156
        unsigned sink;      /**< The destination port id.               */
157
        int adj_level;      /**< The adjustment level.                  */
158
    } connect_ports;
159
160
    /**
161
     * The information for disconnecting port operation.
162
     */
163
    struct {
164
        unsigned src;       /**< The source port id. For multiple port
165
                                 operation, this will be set to -1.     */
166
        unsigned sink;      /**< The destination port id. For multiple
167
                                 port operation, this will be set
168
                                 to -1.                                 */
169
    } disconnect_ports;
170
171
    /**
172
     * The information for adjusting connection level operation.
173
     */
174
    struct {
175
        unsigned src;       /**< The source port id.                    */
176
        unsigned sink;      /**< The destination port id.               */
177
        int adj_level;      /**< The adjustment level.                  */
178
    } adjust_conn_level;
179
180
} pjmedia_conf_op_param;
181
182
/**
183
 * This will contain the information of the conference operation.
184
 */
185
typedef struct pjmedia_conf_op_info
186
{
187
    /**
188
     * The conference instance.
189
     */
190
    pjmedia_conf           *conf;
191
192
    /**
193
     * The operation type.
194
     */
195
    pjmedia_conf_op_type    op_type;
196
197
    /**
198
     * The operation return status.
199
     */
200
    pj_status_t             status;
201
202
    /**
203
     * The operation data.
204
     */
205
    pjmedia_conf_op_param   op_param;
206
207
} pjmedia_conf_op_info;
208
209
/**
210
  * The callback type to be called upon the completion of a conference 
211
  * port operation.
212
  *
213
  * @param info      The conference op callback param.
214
  *
215
  */
216
typedef void (*pjmedia_conf_op_cb)(const pjmedia_conf_op_info *info);
217
218
/**
219
 * Conference port options. The values here can be combined in bitmask to
220
 * be specified when the conference bridge is created.
221
 */
222
enum pjmedia_conf_option
223
{
224
    PJMEDIA_CONF_NO_MIC  = 1,   /**< Disable audio streams from the
225
                                     microphone device.                     */
226
    PJMEDIA_CONF_NO_DEVICE = 2, /**< Do not create sound device.            */
227
    PJMEDIA_CONF_SMALL_FILTER=4,/**< Use small filter table when resampling */
228
    PJMEDIA_CONF_USE_LINEAR=8   /**< Use linear resampling instead of filter
229
                                     based.                                 */
230
};
231
232
/**
233
 * This structure specifies the conference bridge creation parameters.
234
 */
235
typedef struct pjmedia_conf_param
236
{
237
    /**
238
     * Maximum number of slots/ports to be created in
239
     * the bridge. Note that the bridge internally uses
240
     * one port for the sound device, so the actual 
241
     * maximum number of ports will be less one than
242
     * this value.
243
     */
244
    unsigned max_slots;
245
246
    /**
247
     * Set the sampling rate of the bridge. This value
248
     * is also used to set the sampling rate of the
249
     * sound device.
250
     */
251
    unsigned sampling_rate;
252
253
    /**
254
     * Number of channels in the PCM stream. Normally
255
     * the value will be 1 for mono, but application may
256
     * specify a value of 2 for stereo. Note that all
257
     * ports that will be connected to the bridge MUST 
258
     * have the same number of channels as the bridge.
259
     */
260
    unsigned channel_count;
261
262
    /**
263
     * Set the number of samples per frame. This value
264
     * is also used to set the sound device.
265
     */
266
    unsigned samples_per_frame;
267
268
    /**
269
     * Set the number of bits per sample. This value
270
     * is also used to set the sound device. Currently
271
     * only 16bit per sample is supported.
272
     */
273
    unsigned bits_per_sample;
274
275
    /**
276
     * Bitmask options to be set for the bridge. The
277
     * options are constructed from #pjmedia_conf_option
278
     * enumeration.
279
     * The default value is zero.
280
     */
281
    unsigned options;
282
283
    /** 
284
     * The number of worker threads to use by conference bridge.
285
     * Zero means the operations will be done only by get_frame() thread, 
286
     * i.e. conference bridge will be sequential.
287
     * Set this parameter to non-zero value to enable parallel processing.
288
     * The number of worker threads should be less than or equal to the number 
289
     * of the processor cores. However, the optimal number of worker threads
290
     * is application and hardware dependent.
291
     * The default value is zero - sequential conference bridge.
292
     * This value is compatible with previous behavior.
293
     * At compile time application developer can change the default value by 
294
     * setting #PJMEDIA_CONF_THREADS macro in the config_site.h.
295
     * PJMEDIA_CONF_THREADS is total number of conference bridge threads 
296
     * including get_frame() thread. worker_threads is the number of conference
297
     * bridge threads excluding get_frame() thread. 
298
     * As a general rule worker_threads is 1 less than PJMEDIA_CONF_THREADS.
299
     * This value is ignored by all conference backends except for the 
300
     * multithreaded conference bridge backend
301
     * (PJMEDIA_CONF_PARALLEL_BRIDGE_BACKEND).
302
     * 
303
     * The total number of conference bridge threads can be configured at the
304
     * pjsua level using the pjsua_media_config::conf_threads parameter, or at
305
     * the pjsua2 level using the pjsua2::MediaConfig::confThreads parameter.
306
     */
307
    unsigned worker_threads;
308
} pjmedia_conf_param;
309
310
311
/**
312
 * Initialize conference bridge creation parameters.
313
 */
314
PJ_INLINE(void) pjmedia_conf_param_default(pjmedia_conf_param *param)
315
0
{
316
0
    pj_bzero(param, sizeof(pjmedia_conf_param));
317
0
    /* Set the default values */
318
0
#if defined(PJMEDIA_CONF_THREADS) && PJMEDIA_CONF_THREADS > 1
319
0
    param->worker_threads = PJMEDIA_CONF_THREADS-1;
320
0
#endif
321
0
}
Unexecuted instantiation: fuzz-sdp.c:pjmedia_conf_param_default
Unexecuted instantiation: fuzz-rtp.c:pjmedia_conf_param_default
Unexecuted instantiation: fuzz-stream.c:pjmedia_conf_param_default
Unexecuted instantiation: fuzz-audio.c:pjmedia_conf_param_default
Unexecuted instantiation: fuzz-srtp.c:pjmedia_conf_param_default
Unexecuted instantiation: fuzz-sdes.c:pjmedia_conf_param_default
322
323
/**
324
 * Create conference bridge with the specified parameters. The sampling rate,
325
 * samples per frame, and bits per sample will be used for the internal
326
 * operation of the bridge (e.g. when mixing audio frames). However, ports 
327
 * with different configuration may be connected to the bridge. In this case,
328
 * the bridge is able to perform sampling rate conversion, and buffering in 
329
 * case the samples per frame is different.
330
 *
331
 * For this version of PJMEDIA, only 16bits per sample is supported.
332
 *
333
 * For this version of PJMEDIA, the channel count of the ports MUST match
334
 * the channel count of the bridge.
335
 *
336
 * Under normal operation (i.e. when PJMEDIA_CONF_NO_DEVICE option is NOT
337
 * specified), the bridge internally create an instance of sound device
338
 * and connect the sound device to port zero of the bridge. 
339
 *
340
 * If PJMEDIA_CONF_NO_DEVICE options is specified, no sound device will
341
 * be created in the conference bridge. Application MUST acquire the port
342
 * interface of the bridge by calling #pjmedia_conf_get_master_port(), and
343
 * connect this port interface to a sound device port by calling
344
 * #pjmedia_snd_port_connect(), or to a master port (pjmedia_master_port)
345
 * if application doesn't want to instantiate any sound devices.
346
 *
347
 * The sound device or master port are crucial for the bridge's operation, 
348
 * because it provides the bridge with necessary clock to process the audio
349
 * frames periodically. Internally, the bridge runs when get_frame() to 
350
 * port zero is called.
351
 *
352
 * @param pool              Pool to use to allocate the bridge and 
353
 *                          additional buffers for the sound device.
354
 * @param max_slots         Maximum number of slots/ports to be created in
355
 *                          the bridge. Note that the bridge internally uses
356
 *                          one port for the sound device, so the actual 
357
 *                          maximum number of ports will be less one than
358
 *                          this value.
359
 * @param sampling_rate     Set the sampling rate of the bridge. This value
360
 *                          is also used to set the sampling rate of the
361
 *                          sound device.
362
 * @param channel_count     Number of channels in the PCM stream. Normally
363
 *                          the value will be 1 for mono, but application may
364
 *                          specify a value of 2 for stereo. Note that all
365
 *                          ports that will be connected to the bridge MUST 
366
 *                          have the same number of channels as the bridge.
367
 * @param samples_per_frame Set the number of samples per frame. This value
368
 *                          is also used to set the sound device.
369
 * @param bits_per_sample   Set the number of bits per sample. This value
370
 *                          is also used to set the sound device. Currently
371
 *                          only 16bit per sample is supported.
372
 * @param options           Bitmask options to be set for the bridge. The
373
 *                          options are constructed from #pjmedia_conf_option
374
 *                          enumeration.
375
 * @param p_conf            Pointer to receive the conference bridge instance.
376
 *
377
 * @return                  PJ_SUCCESS if conference bridge can be created.
378
 */
379
PJ_DECL(pj_status_t) pjmedia_conf_create( pj_pool_t *pool,
380
                                          unsigned max_slots,
381
                                          unsigned sampling_rate,
382
                                          unsigned channel_count,
383
                                          unsigned samples_per_frame,
384
                                          unsigned bits_per_sample,
385
                                          unsigned options,
386
                                          pjmedia_conf **p_conf );
387
388
/**
389
 * Create conference bridge with the specified parameters. The sampling rate,
390
 * samples per frame, and bits per sample will be used for the internal
391
 * operation of the bridge (e.g. when mixing audio frames). However, ports
392
 * with different configuration may be connected to the bridge. In this case,
393
 * the bridge is able to perform sampling rate conversion, and buffering in
394
 * case the samples per frame is different.
395
 *
396
 * For this version of PJMEDIA, only 16bits per sample is supported.
397
 *
398
 * For this version of PJMEDIA, the channel count of the ports MUST match
399
 * the channel count of the bridge.
400
 *
401
 * Under normal operation (i.e. when PJMEDIA_CONF_NO_DEVICE option is NOT
402
 * specified), the bridge internally create an instance of sound device
403
 * and connect the sound device to port zero of the bridge.
404
 *
405
 * If PJMEDIA_CONF_NO_DEVICE options is specified, no sound device will
406
 * be created in the conference bridge. Application MUST acquire the port
407
 * interface of the bridge by calling #pjmedia_conf_get_master_port(), and
408
 * connect this port interface to a sound device port by calling
409
 * #pjmedia_snd_port_connect(), or to a master port (pjmedia_master_port)
410
 * if application doesn't want to instantiate any sound devices.
411
 *
412
 * The sound device or master port are crucial for the bridge's operation,
413
 * because it provides the bridge with necessary clock to process the audio
414
 * frames periodically. Internally, the bridge runs when get_frame() to
415
 * port zero is called.
416
 *
417
 * @param pool              Pool to use to allocate the bridge and
418
 *                          additional buffers for the sound device.
419
 * @param param             The conference bridge creation parameters.
420
 *                          See #pjmedia_conf_param for more information.
421
 * @param p_conf            Pointer to receive the conference bridge instance.
422
 *
423
 * @return                  PJ_SUCCESS if conference bridge can be created.
424
 */
425
PJ_DECL(pj_status_t) pjmedia_conf_create2(pj_pool_t *pool,
426
                                          const pjmedia_conf_param *param,
427
                                          pjmedia_conf **p_conf);
428
429
430
/**
431
 * Destroy conference bridge. This will also remove any port, thus application
432
 * might get notified from the callback set from #pjmedia_conf_set_op_cb(). 
433
 *
434
 * @param conf              The conference bridge.
435
 *
436
 * @return                  PJ_SUCCESS on success.
437
 */
438
PJ_DECL(pj_status_t) pjmedia_conf_destroy( pjmedia_conf *conf );
439
440
/**
441
 * Register the callback to be called when a port operation has been
442
 * completed.
443
 * 
444
 * The callback will most likely be called from media threads,
445
 * thus application must not perform long/blocking processing in this callback.
446
 * 
447
 * @param conf          The conference bridge.
448
 * @param cb            Callback to be called. Set this to NULL to unregister
449
 *                      the callback.
450
 *
451
 * @return              PJ_SUCCESS on success.
452
 */
453
PJ_DECL(pj_status_t) pjmedia_conf_set_op_cb(pjmedia_conf *conf,
454
                                            pjmedia_conf_op_cb cb);
455
456
/**
457
 * Get the master port interface of the conference bridge. The master port
458
 * corresponds to the port zero of the bridge. This is only usefull when 
459
 * application wants to manage the sound device by itself, instead of 
460
 * allowing the bridge to automatically create a sound device implicitly.
461
 *
462
 * This function will only return a port interface if PJMEDIA_CONF_NO_DEVICE
463
 * option was specified when the bridge was created.
464
 *
465
 * Application can connect the port returned by this function to a 
466
 * sound device by calling #pjmedia_snd_port_connect().
467
 *
468
 * @param conf              The conference bridge.
469
 *
470
 * @return                  The port interface of port zero of the bridge,
471
 *                          only when PJMEDIA_CONF_NO_DEVICE options was
472
 *                          specified when the bridge was created.
473
 */
474
PJ_DECL(pjmedia_port*) pjmedia_conf_get_master_port(pjmedia_conf *conf);
475
476
477
/**
478
 * Set master port name.
479
 *
480
 * @param conf              The conference bridge.
481
 * @param name              Name to be assigned.
482
 *
483
 * @return                  PJ_SUCCESS on success.
484
 */
485
PJ_DECL(pj_status_t) pjmedia_conf_set_port0_name(pjmedia_conf *conf,
486
                                                 const pj_str_t *name);
487
488
489
/**
490
 * Add media port to the conference bridge.
491
 *
492
 * By default, the new conference port will have both TX and RX enabled, 
493
 * but it is not connected to any other ports. Application SHOULD call 
494
 * #pjmedia_conf_connect_port() to  enable audio transmission and receipt 
495
 * to/from this port.
496
 *
497
 * Once the media port is connected to other port(s) in the bridge,
498
 * the bridge will continuosly call get_frame() and put_frame() to the
499
 * port, allowing media to flow to/from the port.
500
 * 
501
 * This operation executes asynchronously, use the callback set from
502
 * #pjmedia_conf_set_op_cb() to receive notification upon completion.
503
 * 
504
 * Note: Sample rate and ptime (frame duration) settings must be compatible.
505
 * Configurations resulting in a fractional number of samples per frame
506
 * are not supported and will cause the function to fail.
507
 * For example, a sample rate of 22050 Hz and a frame duration (ptime) of 10 ms
508
 * will result in 220.5 samples per frame, which is not an integer, 
509
 * so port creation will fail.
510
 *
511
 * @param conf          The conference bridge.
512
 * @param pool          Pool to allocate buffers for this port.
513
 * @param strm_port     Stream port interface.
514
 * @param name          Optional name for the port. If this value is NULL,
515
 *                      the name will be taken from the name in the port 
516
 *                      info.
517
 * @param p_slot        Pointer to receive the slot index of the port in
518
 *                      the conference bridge.
519
 *
520
 * @return              PJ_SUCCESS on success.
521
 */
522
PJ_DECL(pj_status_t) pjmedia_conf_add_port( pjmedia_conf *conf,
523
                                            pj_pool_t *pool,
524
                                            pjmedia_port *strm_port,
525
                                            const pj_str_t *name,
526
                                            unsigned *p_slot );
527
528
529
#if !DEPRECATED_FOR_TICKET_2234
530
/**
531
 * <i><b>Warning:</b> This API has been deprecated since 1.3 and will be
532
 * removed in the future release, use @ref PJMEDIA_SPLITCOMB instead.</i>
533
 *
534
 * Create and add a passive media port to the conference bridge. Unlike
535
 * "normal" media port that is added with #pjmedia_conf_add_port(), media
536
 * port created with this function will not have its get_frame() and
537
 * put_frame() called by the bridge; instead, application MUST continuosly
538
 * call these functions to the port, to allow media to flow from/to the
539
 * port.
540
 *
541
 * Upon return of this function, application will be given two objects:
542
 * the slot number of the port in the bridge, and pointer to the media
543
 * port where application MUST start calling get_frame() and put_frame()
544
 * to the port.
545
 *
546
 * @param conf              The conference bridge.
547
 * @param pool              Pool to allocate buffers etc for this port.
548
 * @param name              Name to be assigned to the port.
549
 * @param clock_rate        Clock rate/sampling rate.
550
 * @param channel_count     Number of channels.
551
 * @param samples_per_frame Number of samples per frame.
552
 * @param bits_per_sample   Number of bits per sample.
553
 * @param options           Options (should be zero at the moment).
554
 * @param p_slot            Pointer to receive the slot index of the port in
555
 *                          the conference bridge.
556
 * @param p_port            Pointer to receive the port instance.
557
 *
558
 * @return                  PJ_SUCCESS on success, or the appropriate error 
559
 *                          code.
560
 */
561
PJ_DECL(pj_status_t) pjmedia_conf_add_passive_port( pjmedia_conf *conf,
562
                                                    pj_pool_t *pool,
563
                                                    const pj_str_t *name,
564
                                                    unsigned clock_rate,
565
                                                    unsigned channel_count,
566
                                                    unsigned samples_per_frame,
567
                                                    unsigned bits_per_sample,
568
                                                    unsigned options,
569
                                                    unsigned *p_slot,
570
                                                    pjmedia_port **p_port );
571
572
#endif
573
574
/**
575
 * Change TX and RX settings for the port.
576
 *
577
 * @param conf          The conference bridge.
578
 * @param slot          Port number/slot in the conference bridge.
579
 * @param tx            Settings for the transmission TO this port.
580
 * @param rx            Settings for the receipt FROM this port.
581
 *
582
 * @return              PJ_SUCCESS on success.
583
 */
584
PJ_DECL(pj_status_t) pjmedia_conf_configure_port( pjmedia_conf *conf,
585
                                                  unsigned slot,
586
                                                  pjmedia_port_op tx,
587
                                                  pjmedia_port_op rx);
588
589
590
/**
591
 * Enable unidirectional audio from the specified source slot to the specified
592
 * sink slot.
593
 * Application may adjust the level to make signal transmitted from the source
594
 * slot to the sink slot either louder or more quiet. The level adjustment is
595
 * calculated with this formula:
596
 * <b><tt>output = input * (adj_level+128) / 128</tt></b>. Using this, zero
597
 * indicates no adjustment, the value -128 will mute the signal, and the value
598
 * of +128 will make the signal 100% louder, +256 will make it 200% louder,
599
 * etc.
600
 *
601
 * The level adjustment will apply to a specific connection only (i.e. only
602
 * for the signal from the source to the sink), as compared to
603
 * pjmedia_conf_adjust_tx_level()/pjmedia_conf_adjust_rx_level() which
604
 * applies to all signals from/to that port. The signal adjustment
605
 * will be cumulative, in this following order:
606
 * signal from the source will be adjusted with the level specified
607
 * in pjmedia_conf_adjust_rx_level(), then with the level specified
608
 * via this API, and finally with the level specified to the sink's
609
 * pjmedia_conf_adjust_tx_level().
610
 * 
611
 * This operation executes asynchronously, use the callback set from
612
 * #pjmedia_conf_set_op_cb() to receive notification upon completion.
613
 *
614
 * @param conf          The conference bridge.
615
 * @param src_slot      Source slot.
616
 * @param sink_slot     Sink slot.
617
 * @param adj_level     Adjustment level, which must be greater than or equal
618
 *                      to -128. A value of zero means there is no level
619
 *                      adjustment to be made, the value -128 will mute the
620
 *                      signal, and the value of +128 will make the signal
621
 *                      100% louder, +256 will make it 200% louder, etc.
622
 *                      See the function description for the formula.
623
 *
624
 * @return              PJ_SUCCES on success.
625
 */
626
PJ_DECL(pj_status_t) pjmedia_conf_connect_port( pjmedia_conf *conf,
627
                                                unsigned src_slot,
628
                                                unsigned sink_slot,
629
                                                int adj_level );
630
631
632
/**
633
 * Disconnect unidirectional audio from the specified source to the specified
634
 * sink slot.
635
 *
636
 * Note that the operation will be done asynchronously, so application
637
 * should not assume that the port will no longer receive/send audio frame
638
 * after this function has returned. Use the callback set from
639
 * #pjmedia_conf_set_op_cb() to receive notification upon completion.
640
 *
641
 * @param conf          The conference bridge.
642
 * @param src_slot      Source slot.
643
 * @param sink_slot     Sink slot.
644
 *
645
 * @return              PJ_SUCCESS on success.
646
 */
647
PJ_DECL(pj_status_t) pjmedia_conf_disconnect_port( pjmedia_conf *conf,
648
                                                   unsigned src_slot,
649
                                                   unsigned sink_slot );
650
651
652
/**
653
 * Disconnect unidirectional audio from all sources to the specified sink slot.
654
 *
655
 * Note that the operation will be done asynchronously, so application
656
 * should not assume that the port will no longer receive/send audio frame
657
 * after this function has returned. Use the callback set from
658
 * #pjmedia_conf_set_op_cb() to receive notification upon completion.
659
 *
660
 * @param conf          The conference bridge.
661
 * @param sink_slot     Sink slot.
662
 *
663
 * @return              PJ_SUCCESS on success.
664
 */
665
PJ_DECL(pj_status_t)
666
pjmedia_conf_disconnect_port_from_sources( pjmedia_conf *conf,
667
                                           unsigned sink_slot);
668
669
670
/**
671
 * Disconnect unidirectional audio from the specified source to all sink slots.
672
 *
673
 * Note that the operation will be done asynchronously, so application
674
 * should not assume that the port will no longer receive/send audio frame
675
 * after this function has returned. Use the callback set from
676
 * #pjmedia_conf_set_op_cb() to receive notification upon completion.
677
 *
678
 * @param conf          The conference bridge.
679
 * @param src_slot      Source slot.
680
 *
681
 * @return              PJ_SUCCESS on success.
682
 */
683
PJ_DECL(pj_status_t)
684
pjmedia_conf_disconnect_port_from_sinks( pjmedia_conf *conf,
685
                                         unsigned src_slot);
686
687
688
/**
689
 * Get number of ports currently registered to the conference bridge.
690
 *
691
 * @param conf          The conference bridge.
692
 *
693
 * @return              Number of ports currently registered to the conference
694
 *                      bridge.
695
 */
696
PJ_DECL(unsigned) pjmedia_conf_get_port_count(pjmedia_conf *conf);
697
698
699
/**
700
 * Get total number of ports connections currently set up in the bridge.
701
 * 
702
 * @param conf          The conference bridge.
703
 *
704
 * @return              PJ_SUCCESS on success.
705
 */
706
PJ_DECL(unsigned) pjmedia_conf_get_connect_count(pjmedia_conf *conf);
707
708
709
/**
710
 * Remove the specified port from the conference bridge.
711
 *
712
 * Note that the operation will be done asynchronously, so application
713
 * should not assume that the port will no longer receive/send audio frame
714
 * after this function has returned.
715
 *
716
 * If the port uses any app's resources, application should maintain
717
 * the resources validity until the port is completely removed. Application
718
 * can schedule the resource release via #pjmedia_conf_add_destroy_handler().
719
 * 
720
 * This operation executes asynchronously, use the callback set from
721
 * #pjmedia_conf_set_op_cb() to receive notification upon completion.
722
 *
723
 * @param conf          The conference bridge.
724
 * @param slot          The port index to be removed.
725
 *
726
 * @return              PJ_SUCCESS on success.
727
 */
728
PJ_DECL(pj_status_t) pjmedia_conf_remove_port( pjmedia_conf *conf,
729
                                               unsigned slot );
730
731
732
733
/**
734
 * Enumerate occupied ports in the bridge.
735
 *
736
 * @param conf          The conference bridge.
737
 * @param ports         Array of port numbers to be filled in.
738
 * @param count         On input, specifies the maximum number of ports
739
 *                      in the array. On return, it will be filled with
740
 *                      the actual number of ports.
741
 *
742
 * @return              PJ_SUCCESS on success.
743
 */
744
PJ_DECL(pj_status_t) pjmedia_conf_enum_ports( pjmedia_conf *conf,
745
                                              unsigned ports[],
746
                                              unsigned *count );
747
748
749
/**
750
 * Get port info.
751
 *
752
 * @param conf          The conference bridge.
753
 * @param slot          Port index.
754
 * @param info          Pointer to receive the info.
755
 *
756
 * @return              PJ_SUCCESS on success.
757
 */
758
PJ_DECL(pj_status_t) pjmedia_conf_get_port_info( pjmedia_conf *conf,
759
                                                 unsigned slot,
760
                                                 pjmedia_conf_port_info *info);
761
762
763
/**
764
 * Get occupied ports info.
765
 *
766
 * @param conf          The conference bridge.
767
 * @param size          On input, contains maximum number of infos
768
 *                      to be retrieved. On output, contains the actual
769
 *                      number of infos that have been copied.
770
 * @param info          Array of info.
771
 *
772
 * @return              PJ_SUCCESS on success.
773
 */
774
PJ_DECL(pj_status_t) pjmedia_conf_get_ports_info(pjmedia_conf *conf,
775
                                                 unsigned *size,
776
                                                 pjmedia_conf_port_info info[]
777
                                                 );
778
779
780
/**
781
 * Get last signal level transmitted to or received from the specified port.
782
 * This will retrieve the "real-time" signal level of the audio as they are
783
 * transmitted or received by the specified port. Application may call this
784
 * function periodically to display the signal level to a VU meter.
785
 *
786
 * The signal level is an integer value in zero to 255, with zero indicates
787
 * no signal, and 255 indicates the loudest signal level.
788
 *
789
 * @param conf          The conference bridge.
790
 * @param slot          Slot number.
791
 * @param tx_level      Optional argument to receive the level of signal
792
 *                      transmitted to the specified port (i.e. the direction
793
 *                      is from the bridge to the port).
794
 * @param rx_level      Optional argument to receive the level of signal
795
 *                      received from the port (i.e. the direction is from the
796
 *                      port to the bridge).
797
 *
798
 * @return              PJ_SUCCESS on success.
799
 */
800
PJ_DECL(pj_status_t) pjmedia_conf_get_signal_level(pjmedia_conf *conf,
801
                                                   unsigned slot,
802
                                                   unsigned *tx_level,
803
                                                   unsigned *rx_level);
804
805
806
/**
807
 * Adjust the level of signal received from the specified port.
808
 * Application may adjust the level to make signal received from the port
809
 * either louder or more quiet. The level adjustment is calculated with this
810
 * formula: <b><tt>output = input * (adj_level+128) / 128</tt></b>. Using 
811
 * this, zero indicates no adjustment, the value -128 will mute the signal, 
812
 * and the value of +128 will make the signal 100% louder, +256 will make it
813
 * 200% louder, etc.
814
 *
815
 * The level adjustment value will stay with the port until the port is
816
 * removed from the bridge or new adjustment value is set. The current
817
 * level adjustment value is reported in the media port info when
818
 * the #pjmedia_conf_get_port_info() function is called.
819
 *
820
 * @param conf          The conference bridge.
821
 * @param slot          Slot number of the port.
822
 * @param adj_level     Adjustment level, which must be greater than or equal
823
 *                      to -128. A value of zero means there is no level
824
 *                      adjustment to be made, the value -128 will mute the 
825
 *                      signal, and the value of +128 will make the signal 
826
 *                      100% louder, +256 will make it 200% louder, etc. 
827
 *                      See the function description for the formula.
828
 *
829
 * @return              PJ_SUCCESS on success.
830
 */
831
PJ_DECL(pj_status_t) pjmedia_conf_adjust_rx_level( pjmedia_conf *conf,
832
                                                   unsigned slot,
833
                                                   int adj_level );
834
835
836
/**
837
 * Adjust the level of signal to be transmitted to the specified port.
838
 * Application may adjust the level to make signal transmitted to the port
839
 * either louder or more quiet. The level adjustment is calculated with this
840
 * formula: <b><tt>output = input * (adj_level+128) / 128</tt></b>. Using 
841
 * this, zero indicates no adjustment, the value -128 will mute the signal, 
842
 * and the value of +128 will make the signal 100% louder, +256 will make it
843
 * 200% louder, etc.
844
 *
845
 * The level adjustment value will stay with the port until the port is
846
 * removed from the bridge or new adjustment value is set. The current
847
 * level adjustment value is reported in the media port info when
848
 * the #pjmedia_conf_get_port_info() function is called.
849
 *
850
 * @param conf          The conference bridge.
851
 * @param slot          Slot number of the port.
852
 * @param adj_level     Adjustment level, which must be greater than or equal
853
 *                      to -128. A value of zero means there is no level
854
 *                      adjustment to be made, the value -128 will mute the 
855
 *                      signal, and the value of +128 will make the signal 
856
 *                      100% louder, +256 will make it 200% louder, etc. 
857
 *                      See the function description for the formula.
858
 *
859
 * @return              PJ_SUCCESS on success.
860
 */
861
PJ_DECL(pj_status_t) pjmedia_conf_adjust_tx_level( pjmedia_conf *conf,
862
                                                   unsigned slot,
863
                                                   int adj_level );
864
865
866
/**
867
 * Adjust the level of signal to be transmitted from the source slot to the
868
 * sink slot.
869
 * Application may adjust the level to make signal transmitted from the source
870
 * slot to the sink slot either louder or more quiet. The level adjustment is
871
 * calculated with this formula:
872
 * <b><tt>output = input * (adj_level+128) / 128</tt></b>. Using this, zero
873
 * indicates no adjustment, the value -128 will mute the signal, and the value
874
 * of +128 will make the signal 100% louder, +256 will make it 200% louder,
875
 * etc.
876
 *
877
 * The level adjustment value will stay with the connection until the
878
 * connection is removed or new adjustment value is set. The current level
879
 * adjustment value is reported in the media port info when the
880
 * #pjmedia_conf_get_port_info() function is called.
881
 *
882
 * Note that the operation is queued and will be executed asynchronously
883
 * by the conference bridge clock thread (similar to connect/disconnect
884
 * operations). The return value indicates whether the operation was
885
 * successfully queued, not whether the adjustment was applied. The actual
886
 * completion status is reported via the operation callback if one is set
887
 * with #pjmedia_conf_set_op_cb().
888
 *
889
 * @param conf          The conference bridge.
890
 * @param src_slot      Source slot.
891
 * @param sink_slot     Sink slot.
892
 * @param adj_level     Adjustment level, which must be greater than or equal
893
 *                      to -128. A value of zero means there is no level
894
 *                      adjustment to be made, the value -128 will mute the
895
 *                      signal, and the value of +128 will make the signal
896
 *                      100% louder, +256 will make it 200% louder, etc.
897
 *                      See the function description for the formula.
898
 *
899
 * @return              PJ_SUCCESS if the operation was queued successfully.
900
 */
901
PJ_DECL(pj_status_t) pjmedia_conf_adjust_conn_level( pjmedia_conf *conf,
902
                                                     unsigned src_slot,
903
                                                     unsigned sink_slot,
904
                                                     int adj_level );
905
906
907
/**
908
 * Add port destructor handler.
909
 *
910
 * Application can use this function to schedule resource release.
911
 * Note that application cannot release any app's resources used by the port,
912
 * e.g: memory pool, database connection, immediately after removing the port
913
 * from the conference bridge as port removal is asynchronous.
914
 *
915
 * Usually this function is called after adding the port to the conference
916
 * bridge.
917
 *
918
 * @param conf              The conference bridge.
919
 * @param slot              The port slot index.
920
 * @param member            A pointer to be passed to the handler.
921
 * @param handler           The destroy handler.
922
 *
923
 * @return                  PJ_SUCCESS on success.
924
 */
925
PJ_DECL(pj_status_t) pjmedia_conf_add_destroy_handler(
926
                                            pjmedia_conf* conf,
927
                                            unsigned slot,
928
                                            void* member,
929
                                            pj_grp_lock_handler handler);
930
931
932
/**
933
 * Remove previously registered destructor handler.
934
 *
935
 * @param conf              The conference bridge.
936
 * @param slot              The port slot index.
937
 * @param member            A pointer to be passed to the handler.
938
 * @param handler           The destroy handler.
939
 *
940
 * @return                  PJ_SUCCESS on success.
941
 */
942
PJ_DECL(pj_status_t) pjmedia_conf_del_destroy_handler(
943
                                            pjmedia_conf* conf,
944
                                            unsigned slot,
945
                                            void* member,
946
                                            pj_grp_lock_handler handler);
947
948
949
PJ_END_DECL
950
951
952
/**
953
 * @}
954
 */
955
956
957
#endif  /* __PJMEDIA_CONF_H__ */
958