| 481 | |
| 482 | === How can I use multiple sound devices simultaneously? === #multi-snd |
| 483 | |
| 484 | You can use multiple audio devices simultaneously with PJSUA-LIB. The first sound device is managed by PJSUA-LIB as usual, and you access it as slot !#0 in the conference bridge. The following steps describe how to open and use the second and subsequent sound devices in your application: |
| 485 | 1. Create a [http://www.pjsip.org/pjmedia/docs/html/group__PJMED__SND__PORT.htm sound device port] for the sound device you want to use. |
| 486 | {{{ |
| 487 | pjmedia_snd_port *sndport; |
| 488 | pj_status_t status; |
| 489 | |
| 490 | status = pjmedia_snd_port_create(..., &sndport); |
| 491 | }}} |
| 492 | 2. Create a [http://www.pjsip.org/pjmedia/docs/html/group__PJMEDIA__SPLITCOMB.htm splitter/combiner] port. |
| 493 | {{{ |
| 494 | pjmedia_port *splitcomb; |
| 495 | |
| 496 | status = pjmedia_split_comb_create(..., &splitcomb); |
| 497 | }}} |
| 498 | 3. Create a ''reverse channel'' from the splitcomb. |
| 499 | {{{ |
| 500 | pjmedia_port *revch; |
| 501 | |
| 502 | status = pjmedia_splitcomb_create_rev_channel(pool, splitcomb, 0, 0, &revch); |
| 503 | }}} |
| 504 | 4. Register the reverse channel above to the conference bridge. |
| 505 | {{{ |
| 506 | int slot; |
| 507 | |
| 508 | status = pjsua_conf_add_port(pool, revch, &slot); |
| 509 | }}} |
| 510 | 5. Connect the sound device port to the splitcomb. |
| 511 | {{{ |
| 512 | status = pjmedia_snd_port_connect(sndport, splitcomb); |
| 513 | }}} |
| 514 | |
| 515 | After these, you can use the sound device (that you open in step 1 above) by using the slot number (step 4) just as you would with other media ports. For example, to play a media to the sound device, just connect (with ''pjsua_conf_connect()'') the slot number of that media to the slot number of the sound device, and vice versa. |
| 516 | |
| 517 | === How can I use the sound device in stereo? === #stereo |
| 518 | |
| 519 | There are two options for this, and each will be explained below. |
| 520 | |
| 521 | The first option is to configure PJSUA-LIB's media to stereo (or in fact any number of channels greater than 1), by setting {{{pjsua_media_config.channel_count}}} to 2 (or greater). This is what the '''{{{--stereo}}}''' option in [http://www.pjsip.org/pjsua.htm pjsua] does. With this, both the main sound device and the conference bridge will be opened in stereo mode. You may register mono or stereo media ports to the conference bridge; stereo media ports will be played back in stereo, while mono media ports will have the media duplicated to the right channel. |
| 522 | |
| 523 | The approach above is useful to playback/capture stereo media. However, it's difficult to control over what's playing on the left or right channel of the audio device, as you would have to use splitcomb to manually combine mono media ports into stereo. |
| 524 | |
| 525 | The second option is to configure PJSUA-LIB's media to mono, as usual, but to open the sound device in stereo. Connect the left channel of the sound device to conference bridge slot !#0, and the right channel to slot !#1 (for example). You will then be able to control what is played to left or right channel by connecting the media to the appropriate slot number of the sound device channel. |
| 526 | |
| 527 | See '''{{{stereo_demo()}}}''' function in {{{pjsua_app.c}}} for a sample code. |
| 528 | |
| 529 | The second option has some drawbacks though. First, despite the fact that the sound device is opened in stereo, you will not be able to playback stereo media in stereo, since the conference bridge is instantiated in mono, hence it will convert the stereo media ports into mono when it's connected to the bridge. And second, since you manage the sound device manually, it won't be opened/closed automatically by PJSUA-LIB as it would normally. |