1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/****************************************************************************
*
* (c) 2009-2020 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 "QGCApplication.h"
#include "VideoManager.h"
#include <QQmlEngine>
#include <QtQml>
#include <QVariantList>
#ifndef QGC_DISABLE_UVC
#include <QCameraInfo>
#endif
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";
DECLARE_SETTINGGROUP(Video, "Video")
{
qmlRegisterUncreatableType<VideoSettings>("QGroundControl.SettingsManager", 1, 0, "VideoSettings", "Reference only");
// Setup enum values for videoSource settings into meta data
QStringList videoSourceList;
#ifdef QGC_GST_STREAMING
videoSourceList.append(videoSourceRTSP);
#ifndef NO_UDP_VIDEO
videoSourceList.append(videoSourceUDPH264);
videoSourceList.append(videoSourceUDPH265);
#endif
videoSourceList.append(videoSourceTCP);
videoSourceList.append(videoSourceMPEGTS);
#endif
#ifndef QGC_DISABLE_UVC
QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
for (const QCameraInfo &cameraInfo: cameras) {
videoSourceList.append(cameraInfo.description());
}
#endif
if (videoSourceList.count() == 0) {
_noVideo = true;
videoSourceList.append(videoSourceNoVideo);
} else {
videoSourceList.insert(0, videoDisabled);
}
QVariantList videoSourceVarList;
for (const QString& videoSource: videoSourceList) {
videoSourceVarList.append(QVariant::fromValue(videoSource));
}
_nameToMetaDataMap[videoSourceName]->setEnumInfo(videoSourceList, videoSourceVarList);
// Set default value for videoSource
_setDefaults();
}
void VideoSettings::_setDefaults()
{
if (_noVideo) {
_nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoSourceNoVideo);
} else {
_nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoDisabled);
}
}
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(VideoSettings, lowLatencyMode)
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, videoSource)
{
if (!_videoSourceFact) {
_videoSourceFact = _createSettingsFact(videoSourceName);
//-- Check for sources no longer available
if(!_videoSourceFact->enumStrings().contains(_videoSourceFact->rawValue().toString())) {
if (_noVideo) {
_videoSourceFact->setRawValue(videoSourceNoVideo);
} else {
_videoSourceFact->setRawValue(videoDisabled);
}
}
connect(_videoSourceFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
}
return _videoSourceFact;
}
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, udpPort)
{
if (!_udpPortFact) {
_udpPortFact = _createSettingsFact(udpPortName);
connect(_udpPortFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
}
return _udpPortFact;
}
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, rtspUrl)
{
if (!_rtspUrlFact) {
_rtspUrlFact = _createSettingsFact(rtspUrlName);
connect(_rtspUrlFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
}
return _rtspUrlFact;
}
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, tcpUrl)
{
if (!_tcpUrlFact) {
_tcpUrlFact = _createSettingsFact(tcpUrlName);
connect(_tcpUrlFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
}
return _tcpUrlFact;
}
bool VideoSettings::streamConfigured(void)
{
#if !defined(QGC_GST_STREAMING)
return false;
#endif
//-- First, check if it's autoconfigured
if(qgcApp()->toolbox()->videoManager()->autoStreamConfigured()) {
qCDebug(VideoManagerLog) << "Stream auto configured";
return true;
}
//-- Check if it's disabled
QString vSource = videoSource()->rawValue().toString();
if(vSource == videoSourceNoVideo || vSource == videoDisabled) {
return false;
}
//-- If UDP, check if port is set
if(vSource == videoSourceUDPH264 || vSource == videoSourceUDPH265) {
qCDebug(VideoManagerLog) << "Testing configuration for UDP Stream:" << udpPort()->rawValue().toInt();
return udpPort()->rawValue().toInt() != 0;
}
//-- If RTSP, check for URL
if(vSource == videoSourceRTSP) {
qCDebug(VideoManagerLog) << "Testing configuration for RTSP Stream:" << rtspUrl()->rawValue().toString();
return !rtspUrl()->rawValue().toString().isEmpty();
}
//-- If TCP, check for URL
if(vSource == videoSourceTCP) {
qCDebug(VideoManagerLog) << "Testing configuration for TCP Stream:" << tcpUrl()->rawValue().toString();
return !tcpUrl()->rawValue().toString().isEmpty();
}
//-- 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;
}
return false;
}
void VideoSettings::_configChanged(QVariant)
{
emit streamConfiguredChanged(streamConfigured());
}