VideoSettings.cc 7.08 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
const char* VideoSettings::videoSourceName =        "VideoSource";
const char* VideoSettings::udpPortName =            "VideoUDPPort";
const char* VideoSettings::rtspUrlName =            "VideoRTSPUrl";
25
const char* VideoSettings::tcpUrlName =             "VideoTCPUrl";
26
const char* VideoSettings::videoAspectRatioName =   "VideoAspectRatio";
27
const char* VideoSettings::videoGridLinesName =     "VideoGridLines";
28 29 30
const char* VideoSettings::showRecControlName =     "ShowRecControl";
const char* VideoSettings::recordingFormatName =    "RecordingFormat";
const char* VideoSettings::maxVideoSizeName =       "MaxVideoSize";
31
const char* VideoSettings::enableStorageLimitName = "EnableStorageLimit";
32
const char* VideoSettings::rtspTimeoutName =        "RtspTimeout";
33
const char* VideoSettings::streamEnabledName =      "StreamEnabled";
34
const char* VideoSettings::disableWhenDisarmedName ="DisableWhenDisarmed";
35

36
const char* VideoSettings::videoSourceNoVideo =     "No Video Available";
37
const char* VideoSettings::videoDisabled =          "Video Stream Disabled";
38 39
const char* VideoSettings::videoSourceUDP =         "UDP Video Stream";
const char* VideoSettings::videoSourceRTSP =        "RTSP Video Stream";
40
const char* VideoSettings::videoSourceTCP =         "TCP-MPEG2 Video Stream";
41 42

VideoSettings::VideoSettings(QObject* parent)
Don Gagne's avatar
Don Gagne committed
43
    : SettingsGroup(videoSettingsGroupName, QString() /* root settings group */, parent)
44 45
    , _videoSourceFact(NULL)
    , _udpPortFact(NULL)
46
    , _tcpUrlFact(NULL)
47
    , _rtspUrlFact(NULL)
48
    , _videoAspectRatioFact(NULL)
49
    , _gridLinesFact(NULL)
50 51 52
    , _showRecControlFact(NULL)
    , _recordingFormatFact(NULL)
    , _maxVideoSizeFact(NULL)
53
    , _enableStorageLimitFact(NULL)
54
    , _rtspTimeoutFact(NULL)
55
    , _streamEnabledFact(NULL)
56
    , _disableWhenDisarmedFact(NULL)
57 58 59
{
    QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
    qmlRegisterUncreatableType<VideoSettings>("QGroundControl.SettingsManager", 1, 0, "VideoSettings", "Reference only");
60 61

    // Setup enum values for videoSource settings into meta data
62
    bool noVideo = false;
63 64 65 66 67 68
    QStringList videoSourceList;
#ifdef QGC_GST_STREAMING
#ifndef NO_UDP_VIDEO
    videoSourceList.append(videoSourceUDP);
#endif
    videoSourceList.append(videoSourceRTSP);
69
    videoSourceList.append(videoSourceTCP);
70 71 72 73 74 75 76 77
#endif
#ifndef QGC_DISABLE_UVC
    QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
    foreach (const QCameraInfo &cameraInfo, cameras) {
        videoSourceList.append(cameraInfo.description());
    }
#endif
    if (videoSourceList.count() == 0) {
78
        noVideo = true;
79
        videoSourceList.append(videoSourceNoVideo);
80 81
    } else {
        videoSourceList.insert(0, videoDisabled);
82 83 84 85 86 87 88 89
    }
    QVariantList videoSourceVarList;
    foreach (const QString& videoSource, videoSourceList) {
        videoSourceVarList.append(QVariant::fromValue(videoSource));
    }
    _nameToMetaDataMap[videoSourceName]->setEnumInfo(videoSourceList, videoSourceVarList);

    // Set default value for videoSource
90 91 92 93 94
    if (noVideo) {
        _nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoSourceNoVideo);
    } else {
        _nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoDisabled);
    }
95 96 97 98 99 100
}

Fact* VideoSettings::videoSource(void)
{
    if (!_videoSourceFact) {
        _videoSourceFact = _createSettingsFact(videoSourceName);
101
        connect(_videoSourceFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
102 103 104 105 106 107 108 109
    }
    return _videoSourceFact;
}

Fact* VideoSettings::udpPort(void)
{
    if (!_udpPortFact) {
        _udpPortFact = _createSettingsFact(udpPortName);
110
        connect(_udpPortFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
111 112 113 114 115 116 117 118
    }
    return _udpPortFact;
}

Fact* VideoSettings::rtspUrl(void)
{
    if (!_rtspUrlFact) {
        _rtspUrlFact = _createSettingsFact(rtspUrlName);
119
        connect(_rtspUrlFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
120 121 122 123
    }
    return _rtspUrlFact;
}

124 125 126 127
Fact* VideoSettings::tcpUrl(void)
{
    if (!_tcpUrlFact) {
        _tcpUrlFact = _createSettingsFact(tcpUrlName);
128
        connect(_tcpUrlFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
129 130 131 132
    }
    return _tcpUrlFact;
}

133 134 135 136 137 138 139
Fact* VideoSettings::aspectRatio(void)
{
    if (!_videoAspectRatioFact) {
        _videoAspectRatioFact = _createSettingsFact(videoAspectRatioName);
    }
    return _videoAspectRatioFact;
}
140 141 142 143 144 145 146 147

Fact* VideoSettings::gridLines(void)
{
    if (!_gridLinesFact) {
        _gridLinesFact = _createSettingsFact(videoGridLinesName);
    }
    return _gridLinesFact;
}
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171

Fact* VideoSettings::showRecControl(void)
{
    if (!_showRecControlFact) {
        _showRecControlFact = _createSettingsFact(showRecControlName);
    }
    return _showRecControlFact;
}

Fact* VideoSettings::recordingFormat(void)
{
    if (!_recordingFormatFact) {
        _recordingFormatFact = _createSettingsFact(recordingFormatName);
    }
    return _recordingFormatFact;
}

Fact* VideoSettings::maxVideoSize(void)
{
    if (!_maxVideoSizeFact) {
        _maxVideoSizeFact = _createSettingsFact(maxVideoSizeName);
    }
    return _maxVideoSizeFact;
}
172

173 174 175 176 177 178 179 180
Fact* VideoSettings::enableStorageLimit(void)
{
    if (!_enableStorageLimitFact) {
        _enableStorageLimitFact = _createSettingsFact(enableStorageLimitName);
    }
    return _enableStorageLimitFact;
}

181 182 183 184 185 186 187
Fact* VideoSettings::rtspTimeout(void)
{
    if (!_rtspTimeoutFact) {
        _rtspTimeoutFact = _createSettingsFact(rtspTimeoutName);
    }
    return _rtspTimeoutFact;
}
188 189 190 191 192 193 194 195 196

Fact* VideoSettings::streamEnabled(void)
{
    if (!_streamEnabledFact) {
        _streamEnabledFact = _createSettingsFact(streamEnabledName);
    }
    return _streamEnabledFact;
}

197 198 199 200 201 202 203 204
Fact* VideoSettings::disableWhenDisarmed(void)
{
    if (!_disableWhenDisarmedFact) {
        _disableWhenDisarmedFact = _createSettingsFact(disableWhenDisarmedName);
    }
    return _disableWhenDisarmedFact;
}

205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
bool VideoSettings::streamConfigured(void)
{
#if !defined(QGC_GST_STREAMING)
    return false;
#endif
    QString vSource = videoSource()->rawValue().toString();
    if(vSource == videoSourceNoVideo || vSource == videoDisabled) {
        return false;
    }
    //-- If UDP, check if port is set
    if(vSource == videoSourceUDP) {
        return udpPort()->rawValue().toInt() != 0;
    }
    //-- If RTSP, check for URL
    if(vSource == videoSourceRTSP) {
        return !rtspUrl()->rawValue().toString().isEmpty();
    }
    //-- If TCP, check for URL
    if(vSource == videoSourceTCP) {
        return !tcpUrl()->rawValue().toString().isEmpty();
    }
    return false;
}

void VideoSettings::_configChanged(QVariant)
{
    emit streamConfiguredChanged();
}