Opened 22 months ago

Closed 22 months ago

Last modified 14 months ago

#2077 closed enhancement (fixed)

New PJSUA & PJSUA2 APIs for instantiating extra audio device

Reported by: nanang Owned by: bennylp
Priority: normal Milestone: release-2.8
Component: pjsua-lib Version: trunk
Keywords: Cc:
Backport to 1.x milestone: Backported: no

Description (last modified by nanang)

The APIs will be useful for application that needs to work with multiple sound devices concurrently. It can also help application to simplify the tasks of improving media framework clock as described here.

Specifications

  1. Audio device configuration settings to be supported:
  2. Application can apply further settings whenever needed by:
    • PJSUA: querying the sound device port and apply further settings directly to it using PJMEDIA Sound Device Port APIs.
    • PJSUA2: inheriting class ExtraAudioDevice and apply the settings using the same approach as PJSUA above. This needs be done in C++.
  3. Audio device must be registered to the conference bridge:
    • PJSUA: it must have API to query the conference bridge port.
    • PJSUA2: it must be a descendant of AudioMedia.

Sample code using PJSUA

enum { EXTRA_SND_DEV_ID  = 3; };

pjmedia_snd_port_param ext_param;
pjsua_ext_snd_dev *ext_snd_dev;
pjsua_conf_port_id ext_id;

/* Generate params (with default values) */
status = pjmedia_snd_port_param_default(&ext_param);
status = pjmedia_aud_dev_default_param(EXTRA_SND_DEV_ID, &ext_param.base);

/* Create the extra audio device */
status = pjsua_ext_snd_dev_create(&ext_param, &ext_snd_dev);
ext_id = pjsua_ext_snd_dev_get_conf_port(ext_snd_dev);

/* Connect extra audio dev mic to main audio dev */
status = pjsua_conf_connect(ext_id, 0);

/* Connect main audio dev mic to extra audio dev */
status = pjsua_conf_connect(0, ext_id);

...

/* Destroy extra audio dev (after no longer used) */
pjsua_ext_snd_dev_destroy(ext_snd_dev);

Sample code using PJSUA2

/* Use Null Audio Device as main media clock. This is useful for improving
 * media clock (see also https://trac.pjsip.org/repos/wiki/FAQ#tx-timing)
 * especially when sound device clock is jittery.
 */
ep.audDevManager().setNullDev();

/* Install extra audio device */
ExtraAudioDevice *auddev2 = new ExtraAudioDevice(-1, -1);
try {
    auddev2->open();
} catch (...) {
    std::cout << "Extra sound device failed" << std::endl;
}

/* Create WAV player and play the WAV to extra audio speaker */
AudioMediaPlayer amp;
amp.createPlayer(PATH_TO_WAV_FILE);
if (auddev2->isOpened())
    amp.startTransmit(*auddev2);

/* Wait for the WAV playback */
pj_thread_sleep(5000);

...

/* Destroy extra audio device (after no longer used) */
delete auddev2;

Change History (3)

comment:1 Changed 22 months ago by nanang

  • Resolution set to fixed
  • Status changed from new to closed

In 5717:

Close #2077: New PJSUA & PJSUA2 APIs for instantiating extra audio device.

comment:2 Changed 22 months ago by nanang

  • Description modified (diff)

comment:3 Changed 14 months ago by nanang

  • Description modified (diff)
Note: See TracTickets for help on using tickets.