Search code examples
c++pjsua2

How is possible get only the device to capture or playback using pjsua2


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

Solution

  • 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