VideoSettings.cc 7.12 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::name =                   "Video";
const char* VideoSettings::settingsGroup =          ""; // settings are in root group
22

23 24 25
const char* VideoSettings::videoSourceName =        "VideoSource";
const char* VideoSettings::udpPortName =            "VideoUDPPort";
const char* VideoSettings::rtspUrlName =            "VideoRTSPUrl";
26
const char* VideoSettings::tcpUrlName =             "VideoTCPUrl";
27
const char* VideoSettings::videoAspectRatioName =   "VideoAspectRatio";
28
const char* VideoSettings::videoGridLinesName =     "VideoGridLines";
29 30 31
const char* VideoSettings::showRecControlName =     "ShowRecControl";
const char* VideoSettings::recordingFormatName =    "RecordingFormat";
const char* VideoSettings::maxVideoSizeName =       "MaxVideoSize";
32
const char* VideoSettings::enableStorageLimitName = "EnableStorageLimit";
33
const char* VideoSettings::rtspTimeoutName =        "RtspTimeout";
34
const char* VideoSettings::streamEnabledName =      "StreamEnabled";
35
const char* VideoSettings::disableWhenDisarmedName ="DisableWhenDisarmed";
36

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

VideoSettings::VideoSettings(QObject* parent)
44
    : SettingsGroup(name, settingsGroup, parent)
45 46
    , _videoSourceFact(NULL)
    , _udpPortFact(NULL)
47
    , _tcpUrlFact(NULL)
48
    , _rtspUrlFact(NULL)
49
    , _videoAspectRatioFact(NULL)
50
    , _gridLinesFact(NULL)
51 52 53
    , _showRecControlFact(NULL)
    , _recordingFormatFact(NULL)
    , _maxVideoSizeFact(NULL)
54
    , _enableStorageLimitFact(NULL)
55
    , _rtspTimeoutFact(NULL)
56
    , _streamEnabledFact(NULL)
57
    , _disableWhenDisarmedFact(NULL)
58 59 60
{
    QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
    qmlRegisterUncreatableType<VideoSettings>("QGroundControl.SettingsManager", 1, 0, "VideoSettings", "Reference only");
61 62

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

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

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

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

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

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

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

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

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;
}
173

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

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

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

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

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 233
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();
}