| 13 | |
| 14 | === Sample code using PJSUA === |
| 15 | {{{ |
| 16 | enum { EXTRA_SND_DEV_ID = 3; }; |
| 17 | |
| 18 | pjmedia_snd_port_param ext_param; |
| 19 | pjsua_ext_snd_dev *ext_snd_dev; |
| 20 | pjsua_conf_port_id ext_id; |
| 21 | |
| 22 | /* Generate params (with default values) */ |
| 23 | status = pjmedia_snd_port_param_default(&ext_param); |
| 24 | status = pjmedia_aud_dev_default_param(EXTRA_SND_DEV_ID, &ext_param.base); |
| 25 | |
| 26 | /* Create the extra audio device */ |
| 27 | status = pjsua_ext_snd_dev_create(&ext_param, &ext_snd_dev); |
| 28 | ext_id = pjsua_ext_snd_dev_get_conf_port(ext_snd_dev); |
| 29 | |
| 30 | /* Connect extra audio dev mic to main audio dev */ |
| 31 | status = pjsua_conf_connect(ext_id, 0); |
| 32 | |
| 33 | /* Connect main audio dev mic to extra audio dev */ |
| 34 | status = pjsua_conf_connect(0, ext_id); |
| 35 | |
| 36 | ... |
| 37 | |
| 38 | /* Destroy extra audio dev (after no longer used) */ |
| 39 | pjsua_ext_snd_dev_destroy(ext_snd_dev); |
| 40 | }}} |
| 41 | |
| 42 | === Sample code using PJSUA2 === |
| 43 | {{{ |
| 44 | /* Use Null Audio Device as main media clock. This is useful for improving |
| 45 | * media clock (see also https://trac.pjsip.org/repos/wiki/FAQ#tx-timing) |
| 46 | * especially when sound device clock is jittery. |
| 47 | */ |
| 48 | ep.audDevManager().setNullDev(); |
| 49 | |
| 50 | /* Install extra audio device */ |
| 51 | ExtraAudioDevice *auddev2 = new ExtraAudioDevice(-1, -1); |
| 52 | try { |
| 53 | auddev2->open(); |
| 54 | } catch (...) { |
| 55 | std::cout << "Extra sound device failed" << std::endl; |
| 56 | } |
| 57 | |
| 58 | /* Create WAV player and play the WAV to extra audio speaker */ |
| 59 | AudioMediaPlayer amp; |
| 60 | amp.createPlayer(PATH_TO_WAV_FILE); |
| 61 | if (auddev2->isOpened()) |
| 62 | amp.startTransmit(*auddev2); |
| 63 | |
| 64 | /* Wait for the WAV playback */ |
| 65 | pj_thread_sleep(5000); |
| 66 | |
| 67 | ... |
| 68 | |
| 69 | /* Destroy extra audio device (after no longer used) */ |
| 70 | delete auddev2; |
| 71 | }}} |