怎么可能只让设备使用 pjsua2 进行捕获或播放

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

我尝试从 pjsua2 获取设备,我得到了所有设备,但没有在捕获设备和播放设备中拆分。

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();
}

这是我的输出:

Wave mapper
WMME
23
Microfone (Dispositivo de High 
WMME
3
Alto-falantes (Dispositivo de H
WMME
21

您可以检查 AudioDevInfo 中的 inputCountoutputCount 字段。

根据文档:

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).

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).

所以你可以这样做:

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);
}

参考:http://www.pjsip.org/pjsip/docs/html/structpj_1_1AudioDevInfo.htm

另一种方法,您可以检查字段caps(能力)。像这样:

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 由这些可能的值组合而成:

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
}