3

I trying get the devices from pjsua2 , I got it get all devices, but do not got split in capture device and playback device.

void AudioController::load(){
    Endpoint ep;
    ep.libCreate();
    // Initialize endpoint
    EpConfig ep_cfg;
    ep.libInit( ep_cfg );
    AudDevManager &manager  =  ep.audDevManager();
    manager.refreshDevs();
    this->input.clear();
    const AudioDevInfoVector &list = manager.enumDev();
    for(unsigned int i = 0;list.size() != i;i++){
        AudioDevInfo * info = list[i];
        GtAudioDevice * a = new GtAudioDevice();
        a->name = info->name.c_str();
        a->deviceId = i;
        qDebug() << info->name.c_str();
        qDebug() << info->driver.c_str();
         qDebug() << info->caps;
        this->input.append(a);
    }
    ep.libDestroy();
}

This is my output:

Wave mapper
WMME
23
Microfone (Dispositivo de High 
WMME
3
Alto-falantes (Dispositivo de H
WMME
21
Sileno Brito
  • 449
  • 1
  • 13
  • 31

2 Answers2

2

You can check the fields inputCount and outputCount inside AudioDevInfo.

According the documentation:

unsigned inputCount

Maximum number of input channels supported by this device. If the value is zero, the device does not support input operation (i.e. it is a playback only device).

And

unsigned outputCount

Maximum number of output channels supported by this device. If the value is zero, the device does not support output operation (i.e. it is an input only device).

So you could do something like this:

for(unsigned int i = 0;list.size() != i;i++){
    AudioDevInfo * info = list[i];
    GtAudioDevice * a = new GtAudioDevice();
    a->name = info->name.c_str();
    a->deviceId = i;
    if (info->inputCount > 0) {
        a->captureDevice = true;
    }
    if (info->outputCount > 0) {
        a->playbackDevice = true;
    }
    this->input.append(a);
}

Reference: http://www.pjsip.org/pjsip/docs/html/structpj_1_1AudioDevInfo.htm

Isma
  • 14,604
  • 5
  • 37
  • 51
0

Another way, you can check the field caps (capabilities). Something like this:

for (int i = 0; i < list.size(); i++)
{
    AudioDevInfo * info = list[i];
    if ((info.caps & (int)pjmedia_aud_dev_cap.PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY) != 0)
    {
        // Playback devices come here
    }
    if ((info.caps & (int)pjmedia_aud_dev_cap.PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY) != 0)
    {
        // Capture devices come here
    }
}

caps is combined from these possible values:

enum pjmedia_aud_dev_cap {
  PJMEDIA_AUD_DEV_CAP_EXT_FORMAT = 1,
  PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY = 2,
  PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY = 4,
  PJMEDIA_AUD_DEV_CAP_INPUT_VOLUME_SETTING = 8,
  PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING = 16,
  PJMEDIA_AUD_DEV_CAP_INPUT_SIGNAL_METER = 32,
  PJMEDIA_AUD_DEV_CAP_OUTPUT_SIGNAL_METER = 64,
  PJMEDIA_AUD_DEV_CAP_INPUT_ROUTE = 128,
  PJMEDIA_AUD_DEV_CAP_INPUT_SOURCE = 128,
  PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE = 256,
  PJMEDIA_AUD_DEV_CAP_EC = 512,
  PJMEDIA_AUD_DEV_CAP_EC_TAIL = 1024,
  PJMEDIA_AUD_DEV_CAP_VAD = 2048,
  PJMEDIA_AUD_DEV_CAP_CNG = 4096,
  PJMEDIA_AUD_DEV_CAP_PLC = 8192,
  PJMEDIA_AUD_DEV_CAP_MAX = 16384
}