VideoSettings.cc 6.38 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 25 26 27 28 29 30
const char* VideoSettings::videoSourceNoVideo           = "No Video Available";
const char* VideoSettings::videoDisabled                = "Video Stream Disabled";
const char* VideoSettings::videoSourceRTSP              = "RTSP Video Stream";
const char* VideoSettings::videoSourceUDPH264           = "UDP h.264 Video Stream";
const char* VideoSettings::videoSourceUDPH265           = "UDP h.265 Video Stream";
const char* VideoSettings::videoSourceTCP               = "TCP-MPEG2 Video Stream";
const char* VideoSettings::videoSourceMPEGTS            = "MPEG-TS (h.264) Video Stream";
const char* VideoSettings::videoSource3DRSolo           = "3DR Solo";
const char* VideoSettings::videoSourceParrotDiscovery   = "Parrot Discovery";
31

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

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

void VideoSettings::_setDefaults()
{
    if (_noVideo) {
73 74 75 76
        _nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoSourceNoVideo);
    } else {
        _nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoDisabled);
    }
77 78
}

79 80 81 82 83 84 85 86 87 88
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)
89
DECLARE_SETTINGSFACT(VideoSettings, lowLatencyMode)
90 91

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

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

117
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, rtspUrl)
118 119 120
{
    if (!_rtspUrlFact) {
        _rtspUrlFact = _createSettingsFact(rtspUrlName);
121
        connect(_rtspUrlFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
122 123 124 125
    }
    return _rtspUrlFact;
}

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

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

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