bool DeviceManager::getAudioDevices(bool input, std::vector<Device>& devs)
{
    devs.clear();

#if defined(ANDROID)
    // Under Android, we don't access the device file directly.
    // Arbitrary use 0 for the mic and 1 for the output.
    // These ids are used in MediaEngine::SetSoundDevices(in, out);
    // The strings are for human consumption.
    if (input) {
        devs.push_back(Device("audioin", "audiorecord", 0));
    } else {
        devs.push_back(Device("audioout", "audiotrack", 1));
    }
    return true;
#elif defined(HAVE_RTAUDIO)

    // Since we are using RtAudio for audio capture it's best to
    // use RtAudio to enumerate devices to ensure indexes match.
    RtAudio audio;

    // Determine the number of devices available
    auto ndevices = audio.getDeviceCount();
    TraceS(this) << "Get audio devices: " << ndevices << endl;

    // Scan through devices for various capabilities
    RtAudio::DeviceInfo info;
    for (unsigned i = 0; i <= ndevices; i++) {
        try {
            info = audio.getDeviceInfo(i);    // may throw RtAudioError

            TraceS(this) << "Device:"
                << "\n\tName: " << info.name
                << "\n\tOutput Channels: " << info.outputChannels
                << "\n\tInput Channels: " << info.inputChannels
                << "\n\tDuplex Channels: " << info.duplexChannels
                << "\n\tDefault Output: " << info.isDefaultOutput
                << "\n\tDefault Input: " << info.isDefaultInput
                << "\n\tProbed: " << info.probed
                << endl;

            if (info.probed == true && (
                (input && info.inputChannels > 0) ||
                (!input && info.outputChannels > 0))) {

                TraceS(this) << "Adding device: " << info.name << endl;
                Device dev((input ? "audioin" : "audioout"), i, info.name, "",
                    (input ? info.isDefaultInput : info.isDefaultOutput));
                devs.push_back(dev);
            }
        }
        catch (RtAudioError& e) {
            ErrorS(this) << "Cannot probe audio device: " << e.getMessage() << endl;
        }
    }

    return filterDevices(devs, kFilteredAudioDevicesName);
#endif
}
Ejemplo n.º 2
0
bool MacDeviceManager::getCameras(std::vector<Device>& devices)
{
    devices.clear();
    if (!GetAVFoundationVideoDevices(&devices)) {
        return false;
    }
    return filterDevices(devices, kFilteredVideoDevicesName);
}
bool LinuxDeviceManager::getVideoCaptureDevices(std::vector<Device>& devices)
{
    devices.clear();
    ScanV4L2Devices(devices);
    return filterDevices(devices, kFilteredVideoDevicesName);
}