Coverage Report

Created: 2026-01-17 06:08

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