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

#include "VideoSettings.h"
11 12
#include "QGCApplication.h"
#include "VideoManager.h"
13 14

#include <QQmlEngine>
Don Gagne's avatar
Don Gagne committed
15
#include <QtQml>
16
#include <QVariantList>
Don Gagne's avatar
Don Gagne committed
17 18

#ifndef QGC_DISABLE_UVC
19
#include <QCameraInfo>
Don Gagne's avatar
Don Gagne committed
20
#endif
21

22 23 24
const char* VideoSettings::videoSourceNoVideo   = "No Video Available";
const char* VideoSettings::videoDisabled        = "Video Stream Disabled";
const char* VideoSettings::videoSourceRTSP      = "RTSP Video Stream";
Gus Grubba's avatar
Gus Grubba committed
25 26
const char* VideoSettings::videoSourceUDPH264   = "UDP h.264 Video Stream";
const char* VideoSettings::videoSourceUDPH265   = "UDP h.265 Video Stream";
27
const char* VideoSettings::videoSourceTCP       = "TCP-MPEG2 Video Stream";
28
const char* VideoSettings::videoSourceMPEGTS    = "MPEG-TS (h.264) Video Stream";
29

30
DECLARE_SETTINGGROUP(Video, "Video")
31 32
{
    qmlRegisterUncreatableType<VideoSettings>("QGroundControl.SettingsManager", 1, 0, "VideoSettings", "Reference only");
33 34 35 36

    // Setup enum values for videoSource settings into meta data
    QStringList videoSourceList;
#ifdef QGC_GST_STREAMING
37
    videoSourceList.append(videoSourceRTSP);
38
#ifndef NO_UDP_VIDEO
Gus Grubba's avatar
Gus Grubba committed
39 40
    videoSourceList.append(videoSourceUDPH264);
    videoSourceList.append(videoSourceUDPH265);
41
#endif
42
    videoSourceList.append(videoSourceTCP);
43
    videoSourceList.append(videoSourceMPEGTS);
44 45 46
#endif
#ifndef QGC_DISABLE_UVC
    QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
47
    for (const QCameraInfo &cameraInfo: cameras) {
48 49 50 51
        videoSourceList.append(cameraInfo.description());
    }
#endif
    if (videoSourceList.count() == 0) {
Gus Grubba's avatar
Gus Grubba committed
52
        _noVideo = true;
53
        videoSourceList.append(videoSourceNoVideo);
54 55
    } else {
        videoSourceList.insert(0, videoDisabled);
56 57
    }
    QVariantList videoSourceVarList;
58
    for (const QString& videoSource: videoSourceList) {
59 60 61 62
        videoSourceVarList.append(QVariant::fromValue(videoSource));
    }
    _nameToMetaDataMap[videoSourceName]->setEnumInfo(videoSourceList, videoSourceVarList);
    // Set default value for videoSource
Gus Grubba's avatar
Gus Grubba committed
63 64 65 66 67 68
    _setDefaults();
}

void VideoSettings::_setDefaults()
{
    if (_noVideo) {
69 70 71 72
        _nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoSourceNoVideo);
    } else {
        _nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoDisabled);
    }
73 74
}

75 76 77 78 79 80 81 82 83 84 85 86
DECLARE_SETTINGSFACT(VideoSettings, aspectRatio)
DECLARE_SETTINGSFACT(VideoSettings, videoFit)
DECLARE_SETTINGSFACT(VideoSettings, gridLines)
DECLARE_SETTINGSFACT(VideoSettings, showRecControl)
DECLARE_SETTINGSFACT(VideoSettings, recordingFormat)
DECLARE_SETTINGSFACT(VideoSettings, maxVideoSize)
DECLARE_SETTINGSFACT(VideoSettings, enableStorageLimit)
DECLARE_SETTINGSFACT(VideoSettings, rtspTimeout)
DECLARE_SETTINGSFACT(VideoSettings, streamEnabled)
DECLARE_SETTINGSFACT(VideoSettings, disableWhenDisarmed)

DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, videoSource)
87 88 89
{
    if (!_videoSourceFact) {
        _videoSourceFact = _createSettingsFact(videoSourceName);
Gus Grubba's avatar
Gus Grubba committed
90
        //-- Check for sources no longer available
91
        if(!_videoSourceFact->enumStrings().contains(_videoSourceFact->rawValue().toString())) {
Gus Grubba's avatar
Gus Grubba committed
92 93 94 95 96 97
            if (_noVideo) {
                _videoSourceFact->setRawValue(videoSourceNoVideo);
            } else {
                _videoSourceFact->setRawValue(videoDisabled);
            }
        }
98
        connect(_videoSourceFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
99 100 101 102
    }
    return _videoSourceFact;
}

103
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, udpPort)
104 105 106
{
    if (!_udpPortFact) {
        _udpPortFact = _createSettingsFact(udpPortName);
107
        connect(_udpPortFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
108 109 110 111
    }
    return _udpPortFact;
}

112
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, rtspUrl)
113 114 115
{
    if (!_rtspUrlFact) {
        _rtspUrlFact = _createSettingsFact(rtspUrlName);
116
        connect(_rtspUrlFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
117 118 119 120
    }
    return _rtspUrlFact;
}

121
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, tcpUrl)
122 123 124
{
    if (!_tcpUrlFact) {
        _tcpUrlFact = _createSettingsFact(tcpUrlName);
125
        connect(_tcpUrlFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
126 127 128 129
    }
    return _tcpUrlFact;
}

130 131 132 133 134
bool VideoSettings::streamConfigured(void)
{
#if !defined(QGC_GST_STREAMING)
    return false;
#endif
135
    //-- First, check if it's autoconfigured
136 137 138 139
    if(qgcApp()->toolbox()->videoManager()->autoStreamConfigured()) {
        qCDebug(VideoManagerLog) << "Stream auto configured";
        return true;
    }
140 141 142 143 144
    //-- Check if it's disabled
    QString vSource = videoSource()->rawValue().toString();
    if(vSource == videoSourceNoVideo || vSource == videoDisabled) {
        return false;
    }
145
    //-- If UDP, check if port is set
Gus Grubba's avatar
Gus Grubba committed
146
    if(vSource == videoSourceUDPH264 || vSource == videoSourceUDPH265) {
147
        qCDebug(VideoManagerLog) << "Testing configuration for UDP Stream:" << udpPort()->rawValue().toInt();
148 149 150 151
        return udpPort()->rawValue().toInt() != 0;
    }
    //-- If RTSP, check for URL
    if(vSource == videoSourceRTSP) {
152
        qCDebug(VideoManagerLog) << "Testing configuration for RTSP Stream:" << rtspUrl()->rawValue().toString();
153 154
        return !rtspUrl()->rawValue().toString().isEmpty();
    }
155 156 157 158
    //-- If TCP, check for URL
    if(vSource == videoSourceTCP) {
        qCDebug(VideoManagerLog) << "Testing configuration for TCP Stream:" << tcpUrl()->rawValue().toString();
        return !tcpUrl()->rawValue().toString().isEmpty();
159
    }
160 161 162 163 164
    //-- If MPEG-TS, check if port is set
    if(vSource == videoSourceMPEGTS) {
        qCDebug(VideoManagerLog) << "Testing configuration for MPEG-TS Stream:" << udpPort()->rawValue().toInt();
        return udpPort()->rawValue().toInt() != 0;
    }
165 166 167 168 169 170 171
    return false;
}

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