VideoSettings.cc 6.08 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
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)
85
DECLARE_SETTINGSFACT(VideoSettings, lowLatencyMode)
86 87

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

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

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

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

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

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