-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Expand file tree
/
Copy pathVideoSettings.cc
More file actions
383 lines (343 loc) · 13.6 KB
/
Copy pathVideoSettings.cc
File metadata and controls
383 lines (343 loc) · 13.6 KB
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#include "VideoSettings.h"
#include "VideoManager.h"
#include "QGCLoggingCategory.h"
#include "QGCNetworkHelper.h"
#include <QtCore/QSettings>
#include <QtCore/QVariantList>
QGC_LOGGING_CATEGORY(VideoSettingsLog, "Settings.VideoSettings")
#ifdef QGC_GST_STREAMING
#include "GStreamer.h"
static constexpr bool kGstEnabled = true;
#else
static constexpr bool kGstEnabled = false;
#endif
#include "UVCReceiver.h"
DECLARE_SETTINGGROUP(Video, "Video")
{
// Setup enum values for videoSource settings into meta data
QVariantList videoSourceList;
videoSourceList.append(videoSourceRTSP);
if (kGstEnabled) {
videoSourceList.append(videoSourceHTTPMJPEG);
}
videoSourceList.append(videoSourceUDPH264);
videoSourceList.append(videoSourceUDPH265);
videoSourceList.append(videoSourceTCP);
videoSourceList.append(videoSourceMPEGTS);
videoSourceList.append(videoSource3DRSolo);
videoSourceList.append(videoSourceParrotDiscovery);
videoSourceList.append(videoSourceYuneecMantisG);
#ifdef QGC_HERELINK_AIRUNIT_VIDEO
videoSourceList.append(videoSourceHerelinkAirUnit);
#else
videoSourceList.append(videoSourceHerelinkHotspot);
#endif
QStringList uvcDevices = UVCReceiver::getDeviceNameList();
for (const QString& device : uvcDevices) {
videoSourceList.append(device);
}
if (videoSourceList.count() == 0) {
_noVideo = true;
videoSourceList.append(videoSourceNoVideo);
setUserVisible(false);
} else {
videoSourceList.insert(0, videoDisabled);
}
// make translated strings
QStringList videoSourceCookedList;
for (const QVariant& videoSource: videoSourceList) {
videoSourceCookedList.append( VideoSettings::tr(videoSource.toString().toStdString().c_str()) );
}
_nameToMetaDataMap[videoSourceName]->setEnumInfo(videoSourceCookedList, videoSourceList);
_setForceVideoDecodeList();
// Migrate legacy gpuZeroCopyEnabled (pre-rename) into the new force-CPU semantics.
{
QSettings settings;
settings.beginGroup(settingsGroup);
const bool hasLegacy = settings.contains(QStringLiteral("gpuZeroCopyEnabled"));
const bool hasNew = settings.contains(forceCpuVideoPathName);
if (hasLegacy) {
if (!hasNew) {
const bool gpuZeroCopy = settings.value(QStringLiteral("gpuZeroCopyEnabled")).toBool();
forceCpuVideoPath()->setRawValue(!gpuZeroCopy);
}
settings.remove(QStringLiteral("gpuZeroCopyEnabled"));
}
settings.endGroup();
}
// 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, streamEnabled)
DECLARE_SETTINGSFACT(VideoSettings, disableWhenDisarmed)
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, videoSource)
{
if (!_videoSourceFact) {
_videoSourceFact = _createSettingsFact(videoSourceName);
//-- Check for sources no longer available
if(!_videoSourceFact->enumValues().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, forceVideoDecoder)
{
if (!_forceVideoDecoderFact) {
_forceVideoDecoderFact = _createSettingsFact(forceVideoDecoderName);
_forceVideoDecoderFact->setUserVisible(kGstEnabled);
connect(_forceVideoDecoderFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
}
return _forceVideoDecoderFact;
}
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, lowLatencyMode)
{
if (!_lowLatencyModeFact) {
_lowLatencyModeFact = _createSettingsFact(lowLatencyModeName);
_lowLatencyModeFact->setUserVisible(kGstEnabled);
connect(_lowLatencyModeFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
}
return _lowLatencyModeFact;
}
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, rtpJitterLatencyMs)
{
if (!_rtpJitterLatencyMsFact) {
_rtpJitterLatencyMsFact = _createSettingsFact(rtpJitterLatencyMsName);
_rtpJitterLatencyMsFact->setUserVisible(kGstEnabled);
connect(_rtpJitterLatencyMsFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
}
return _rtpJitterLatencyMsFact;
}
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, rtspAutoReconnect)
{
if (!_rtspAutoReconnectFact) {
_rtspAutoReconnectFact = _createSettingsFact(rtspAutoReconnectName);
_rtspAutoReconnectFact->setUserVisible(kGstEnabled);
connect(_rtspAutoReconnectFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
}
return _rtspAutoReconnectFact;
}
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, forceCpuVideoPath)
{
if (!_forceCpuVideoPathFact) {
_forceCpuVideoPathFact = _createSettingsFact(forceCpuVideoPathName);
#if defined(QGC_HAS_ANY_GPU_PATH)
_forceCpuVideoPathFact->setUserVisible(kGstEnabled);
#else
_forceCpuVideoPathFact->setUserVisible(false);
#endif
}
return _forceCpuVideoPathFact;
}
// videoConversionElement / disablePixelAspectRatio are read by VideoBackend::createSink()
// into a VideoSinkConfig and passed as construct-only bin properties — no env-var indirection.
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, videoConversionElement)
{
if (!_videoConversionElementFact) {
_videoConversionElementFact = _createSettingsFact(videoConversionElementName);
_videoConversionElementFact->setUserVisible(kGstEnabled);
}
return _videoConversionElementFact;
}
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, disablePixelAspectRatio)
{
if (!_disablePixelAspectRatioFact) {
_disablePixelAspectRatioFact = _createSettingsFact(disablePixelAspectRatioName);
_disablePixelAspectRatioFact->setUserVisible(kGstEnabled);
}
return _disablePixelAspectRatioFact;
}
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, rtspTimeout)
{
if (!_rtspTimeoutFact) {
_rtspTimeoutFact = _createSettingsFact(rtspTimeoutName);
_rtspTimeoutFact->setUserVisible(kGstEnabled);
connect(_rtspTimeoutFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
}
return _rtspTimeoutFact;
}
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, udpUrl)
{
if (!_udpUrlFact) {
_udpUrlFact = _createSettingsFact(udpUrlName);
connect(_udpUrlFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
}
return _udpUrlFact;
}
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, httpMjpegUrl)
{
if (!_httpMjpegUrlFact) {
_httpMjpegUrlFact = _createSettingsFact(httpMjpegUrlName);
connect(_httpMjpegUrlFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
}
return _httpMjpegUrlFact;
}
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, tcpUrl)
{
if (!_tcpUrlFact) {
_tcpUrlFact = _createSettingsFact(tcpUrlName);
connect(_tcpUrlFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
}
return _tcpUrlFact;
}
bool VideoSettings::streamConfigured(void)
{
//-- First, check if it's autoconfigured
if(VideoManager::instance()->autoStreamConfigured()) {
qCDebug(VideoSettingsLog) << "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 for URL
if(vSource == videoSourceUDPH264 || vSource == videoSourceUDPH265) {
const QString url = udpUrl()->rawValue().toString();
qCDebug(VideoSettingsLog) << "Testing configuration for UDP Stream:"
<< QGCNetworkHelper::redactedUrlForLogging(url);
return !url.isEmpty();
}
//-- If RTSP, check for URL
if(vSource == videoSourceRTSP) {
const QString url = rtspUrl()->rawValue().toString();
qCDebug(VideoSettingsLog) << "Testing configuration for RTSP Stream:"
<< QGCNetworkHelper::redactedUrlForLogging(url);
return !url.isEmpty();
}
//-- If HTTP MJPEG, check for URL
if (vSource == videoSourceHTTPMJPEG) {
qCDebug(VideoSettingsLog) << "Testing configuration for HTTP MJPEG Stream";
return !httpMjpegUrl()->rawValue().toString().isEmpty();
}
//-- If TCP, check for URL
if(vSource == videoSourceTCP) {
const QString url = tcpUrl()->rawValue().toString();
qCDebug(VideoSettingsLog) << "Testing configuration for TCP Stream:"
<< QGCNetworkHelper::redactedUrlForLogging(url);
return !url.isEmpty();
}
//-- If MPEG-TS, check for URL
if(vSource == videoSourceMPEGTS) {
const QString url = udpUrl()->rawValue().toString();
qCDebug(VideoSettingsLog) << "Testing configuration for MPEG-TS Stream:"
<< QGCNetworkHelper::redactedUrlForLogging(url);
return !url.isEmpty();
}
//-- If Herelink Air unit, good to go
if(vSource == videoSourceHerelinkAirUnit) {
qCDebug(VideoSettingsLog) << "Stream configured for Herelink Air Unit";
return true;
}
//-- If Herelink Hotspot, good to go
if(vSource == videoSourceHerelinkHotspot) {
qCDebug(VideoSettingsLog) << "Stream configured for Herelink Hotspot";
return true;
}
if (UVCReceiver::enabled() && UVCReceiver::deviceExists(vSource)) {
qCDebug(VideoSettingsLog) << "Stream configured for UVC";
return true;
}
return false;
}
void VideoSettings::_configChanged(QVariant)
{
emit streamConfiguredChanged(streamConfigured());
}
void VideoSettings::_setForceVideoDecodeList()
{
#ifdef QGC_GST_STREAMING
static const QList<GStreamer::VideoDecoderOptions> removeForceVideoDecodeList{
#if defined(Q_OS_ANDROID)
GStreamer::VideoDecoderOptions::ForceVideoDecoderDirectX3D,
GStreamer::VideoDecoderOptions::ForceVideoDecoderVideoToolbox,
GStreamer::VideoDecoderOptions::ForceVideoDecoderVAAPI,
GStreamer::VideoDecoderOptions::ForceVideoDecoderNVIDIA,
GStreamer::VideoDecoderOptions::ForceVideoDecoderIntel,
#elif defined(Q_OS_LINUX)
GStreamer::VideoDecoderOptions::ForceVideoDecoderDirectX3D,
GStreamer::VideoDecoderOptions::ForceVideoDecoderVideoToolbox,
#elif defined(Q_OS_WIN)
GStreamer::VideoDecoderOptions::ForceVideoDecoderVideoToolbox,
GStreamer::VideoDecoderOptions::ForceVideoDecoderVulkan,
#elif defined(Q_OS_MACOS)
GStreamer::VideoDecoderOptions::ForceVideoDecoderDirectX3D,
GStreamer::VideoDecoderOptions::ForceVideoDecoderVAAPI,
#elif defined(Q_OS_IOS)
GStreamer::VideoDecoderOptions::ForceVideoDecoderDirectX3D,
GStreamer::VideoDecoderOptions::ForceVideoDecoderVAAPI,
GStreamer::VideoDecoderOptions::ForceVideoDecoderNVIDIA,
GStreamer::VideoDecoderOptions::ForceVideoDecoderIntel,
#endif
};
for (const auto &value : removeForceVideoDecodeList) {
_nameToMetaDataMap[forceVideoDecoderName]->removeEnumInfo(value);
}
#endif
}
void VideoSettings::pruneUnavailableDecoders()
{
#ifdef QGC_GST_STREAMING
static const QList<GStreamer::VideoDecoderOptions> hardwareFamilies{
GStreamer::VideoDecoderOptions::ForceVideoDecoderNVIDIA,
GStreamer::VideoDecoderOptions::ForceVideoDecoderVAAPI,
GStreamer::VideoDecoderOptions::ForceVideoDecoderDirectX3D,
GStreamer::VideoDecoderOptions::ForceVideoDecoderVideoToolbox,
GStreamer::VideoDecoderOptions::ForceVideoDecoderIntel,
GStreamer::VideoDecoderOptions::ForceVideoDecoderVulkan,
};
const QList<GStreamer::VideoDecoderOptions> available = GStreamer::availableDecoderFamilies();
const auto metaIt = _nameToMetaDataMap.constFind(forceVideoDecoderName);
if (metaIt == _nameToMetaDataMap.constEnd() || !metaIt.value()) {
return;
}
FactMetaData* const metaData = metaIt.value();
bool pruned = false;
for (const auto family : hardwareFamilies) {
// removeEnumInfo() qWarns on an absent value, so skip families not in the enum; values are
// stored as QVariant(int), so match that representation.
const QVariant familyValue = static_cast<int>(family);
if (!available.contains(family) && metaData->enumValues().contains(familyValue)) {
metaData->removeEnumInfo(familyValue);
pruned = true;
}
}
Fact* const fact = forceVideoDecoder();
if (pruned) {
// Backend init is async — refresh any live FactComboBox bound to this fact.
emit fact->enumsChanged();
}
if (!metaData->enumValues().contains(fact->rawValue())) {
fact->setRawValue(GStreamer::VideoDecoderOptions::ForceVideoDecoderDefault);
}
#endif
}