VideoSettings.cc 3.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

#include "VideoSettings.h"

#include <QQmlEngine>
Don Gagne's avatar
Don Gagne committed
13
#include <QtQml>
14
#include <QVariantList>
Don Gagne's avatar
Don Gagne committed
15 16

#ifndef QGC_DISABLE_UVC
17
#include <QCameraInfo>
Don Gagne's avatar
Don Gagne committed
18
#endif
19

20 21 22 23 24 25 26 27 28 29
const char* VideoSettings::videoSettingsGroupName = "Video";

const char* VideoSettings::videoSourceName =    "VideoSource";
const char* VideoSettings::udpPortName =        "VideoUDPPort";
const char* VideoSettings::rtspUrlName =        "VideoRTSPUrl";
const char* VideoSettings::videoSavePathName =  "VideoSavePath";

const char* VideoSettings::videoSourceNoVideo = "No Video Available";
const char* VideoSettings::videoSourceUDP =     "UDP Video Stream";
const char* VideoSettings::videoSourceRTSP =    "RTSP Video Stream";
30 31

VideoSettings::VideoSettings(QObject* parent)
Don Gagne's avatar
Don Gagne committed
32
    : SettingsGroup(videoSettingsGroupName, QString() /* root settings group */, parent)
33 34 35 36
    , _videoSourceFact(NULL)
    , _udpPortFact(NULL)
    , _rtspUrlFact(NULL)
    , _videoSavePathFact(NULL)
37 38 39
{
    QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
    qmlRegisterUncreatableType<VideoSettings>("QGroundControl.SettingsManager", 1, 0, "VideoSettings", "Reference only");
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105

    // Setup enum values for videoSource settings into meta data
    QStringList videoSourceList;
#ifdef QGC_GST_STREAMING
#ifndef NO_UDP_VIDEO
    videoSourceList.append(videoSourceUDP);
#endif
    videoSourceList.append(videoSourceRTSP);
#endif
#ifndef QGC_DISABLE_UVC
    QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
    foreach (const QCameraInfo &cameraInfo, cameras) {
        videoSourceList.append(cameraInfo.description());
    }
#endif
    if (videoSourceList.count() == 0) {
        videoSourceList.append(videoSourceNoVideo);
    }
    QVariantList videoSourceVarList;
    foreach (const QString& videoSource, videoSourceList) {
        videoSourceVarList.append(QVariant::fromValue(videoSource));
    }
    _nameToMetaDataMap[videoSourceName]->setEnumInfo(videoSourceList, videoSourceVarList);

    // Set default value for videoSource
#if defined(NO_UDP_VIDEO)
    _nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoSourceRTSP);
#else
    _nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoSourceUDP);
#endif
}

Fact* VideoSettings::videoSource(void)
{
    if (!_videoSourceFact) {
        _videoSourceFact = _createSettingsFact(videoSourceName);
    }

    return _videoSourceFact;
}

Fact* VideoSettings::udpPort(void)
{
    if (!_udpPortFact) {
        _udpPortFact = _createSettingsFact(udpPortName);
    }

    return _udpPortFact;
}

Fact* VideoSettings::rtspUrl(void)
{
    if (!_rtspUrlFact) {
        _rtspUrlFact = _createSettingsFact(rtspUrlName);
    }

    return _rtspUrlFact;
}

Fact* VideoSettings::videoSavePath(void)
{
    if (!_videoSavePathFact) {
        _videoSavePathFact = _createSettingsFact(videoSavePathName);
    }

    return _videoSavePathFact;
106
}