QList<QStringList> WebcamDetectElement::webcams(QString dir)
{
    Sleep::msleep(250);
    QDir devicesDir(dir);

    QStringList devices = devicesDir.entryList(QStringList("video*"),
                                               QDir::System |
                                               QDir::Readable |
                                               QDir::Writable |
                                               QDir::NoSymLinks |
                                               QDir::NoDotAndDotDot |
                                               QDir::CaseSensitive,
                                               QDir::Name);

    QList<QStringList> webcams;
    struct v4l2_capability capability;

    foreach (QString device, devices)
    {
        QFile devicePath(devicesDir.absoluteFilePath(device));

        if (!devicePath.open(QIODevice::ReadWrite))
            continue;

        ioctl(devicePath.handle(), VIDIOC_QUERYCAP, &capability);

        if (capability.capabilities & V4L2_CAP_VIDEO_CAPTURE)
            webcams << (QStringList() << devicePath.fileName() << QString((const char *)capability.card));

        devicePath.close();
    }
예제 #2
0
QStringList CameraOutV4L2::webcams() const
{
    QDir devicesDir("/dev");

    QStringList devices = devicesDir.entryList(QStringList() << "video*",
                                               QDir::System
                                               | QDir::Readable
                                               | QDir::Writable
                                               | QDir::NoSymLinks
                                               | QDir::NoDotAndDotDot
                                               | QDir::CaseSensitive,
                                               QDir::Name);

    QStringList webcams;
    QFile device;
    v4l2_capability capability;
    memset(&capability, 0, sizeof(v4l2_capability));

    for (const QString &devicePath: devices) {
        device.setFileName(devicesDir.absoluteFilePath(devicePath));

        if (device.open(QIODevice::ReadWrite)) {
            this->xioctl(device.handle(), VIDIOC_QUERYCAP, &capability);

            if (capability.capabilities & V4L2_CAP_VIDEO_OUTPUT)
                webcams << device.fileName();

            device.close();
        }
    }

    return webcams;
}
예제 #3
0
void AudioDevOSS::updateDevices()
{
    QStringList inputs;
    QStringList outputs;
    QMap<QString, AkAudioCaps> pinCapsMap;
    QMap<QString, QString> pinDescriptionMap;
    QMap<QString, int> fragmentSizeMap;

    QDir devicesDir("/dev");

    QStringList devices = devicesDir.entryList(QStringList() << "mixer*",
                                               QDir::System
                                               | QDir::Readable
                                               | QDir::Writable
                                               | QDir::NoSymLinks
                                               | QDir::NoDotAndDotDot
                                               | QDir::CaseSensitive,
                                               QDir::Name);

    for (const auto &devicePath: devices) {
        auto mixerDevice = devicesDir.absoluteFilePath(devicePath);
        auto dspDevice = QString(mixerDevice).replace("mixer", "dsp");

        if (!QFile::exists(mixerDevice)
            || !QFile::exists(dspDevice))
            continue;

        QString description;
        QFile mixerFile(mixerDevice);

        if (!mixerFile.open(QIODevice::ReadWrite))
            continue;

        mixer_info mixerInfo;

        if (ioctl(mixerFile.handle(), SOUND_MIXER_INFO, &mixerInfo) < 0) {
            mixerFile.close();

            continue;
        }

        mixerFile.close();
        description = QString("%1, %2").arg(mixerInfo.id).arg(mixerInfo.name);

        auto input = dspDevice + ":Input";
        int fragmentSize = 0;
        auto caps = this->deviceCaps(input, &fragmentSize);

        if (!caps) {
            fragmentSize = this->m_fragmentSizeMap.value(input);
            caps = this->m_pinCapsMap.value(input);
        }

        if (caps) {
            inputs << input;
            pinDescriptionMap[input] = description;
            fragmentSizeMap[input] = fragmentSize;
            pinCapsMap[input] = caps;
        }

        auto output = dspDevice + ":Output";
        caps = this->deviceCaps(output, &fragmentSize);

        if (!caps) {
            fragmentSize = this->m_fragmentSizeMap.value(output);
            caps = this->m_pinCapsMap.value(output);
        }

        if (caps) {
            outputs << output;
            pinDescriptionMap[output] = description;
            fragmentSizeMap[output] = fragmentSize;
            pinCapsMap[output] = caps;
        }
    }

    if (this->m_pinCapsMap != pinCapsMap)
        this->m_pinCapsMap = pinCapsMap;

    if (this->m_pinDescriptionMap != pinDescriptionMap)
        this->m_pinDescriptionMap = pinDescriptionMap;

    if (this->m_fragmentSizeMap != fragmentSizeMap)
        this->m_fragmentSizeMap = fragmentSizeMap;

    if (this->m_sources != inputs) {
        this->m_sources = inputs;
        emit this->inputsChanged(inputs);
    }

    if (this->m_sinks != outputs) {
        this->m_sinks = outputs;
        emit this->outputsChanged(outputs);
    }

    QString defaultOutput = outputs.isEmpty()? "": outputs.first();
    QString defaultInput = inputs.isEmpty()? "": inputs.first();

    if (this->m_defaultSource != defaultInput) {
        this->m_defaultSource = defaultInput;
        emit this->defaultInputChanged(defaultInput);
    }

    if (this->m_defaultSink != defaultOutput) {
        this->m_defaultSink = defaultOutput;
        emit this->defaultOutputChanged(defaultOutput);
    }
}