VideoSettings.cc 3.7 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
const char* VideoSettings::videoSettingsGroupName = "Video";

22 23 24 25 26
const char* VideoSettings::videoSourceName =        "VideoSource";
const char* VideoSettings::udpPortName =            "VideoUDPPort";
const char* VideoSettings::rtspUrlName =            "VideoRTSPUrl";
const char* VideoSettings::videoSavePathName =      "VideoSavePath";
const char* VideoSettings::videoAspectRatioName =   "VideoAspectRatio";
27
const char* VideoSettings::videoGridLinesName =     "VideoGridLines";
28 29 30 31

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

VideoSettings::VideoSettings(QObject* parent)
Don Gagne's avatar
Don Gagne committed
34
    : SettingsGroup(videoSettingsGroupName, QString() /* root settings group */, parent)
35 36 37 38
    , _videoSourceFact(NULL)
    , _udpPortFact(NULL)
    , _rtspUrlFact(NULL)
    , _videoSavePathFact(NULL)
39
    , _videoAspectRatioFact(NULL)
40
    , _gridLinesFact(NULL)
41 42 43
{
    QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
    qmlRegisterUncreatableType<VideoSettings>("QGroundControl.SettingsManager", 1, 0, "VideoSettings", "Reference only");
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 106 107 108 109

    // 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;
110
}
111 112 113 114 115 116 117 118 119

Fact* VideoSettings::aspectRatio(void)
{
    if (!_videoAspectRatioFact) {
        _videoAspectRatioFact = _createSettingsFact(videoAspectRatioName);
    }

    return _videoAspectRatioFact;
}
120 121 122 123 124 125 126 127 128

Fact* VideoSettings::gridLines(void)
{
    if (!_gridLinesFact) {
        _gridLinesFact = _createSettingsFact(videoGridLinesName);
    }

    return _gridLinesFact;
}