QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
VideoSettings.cc
Go to the documentation of this file.
1#include "VideoSettings.h"
2
3#include <QtCore/QVariantList>
4#include <QtMultimedia/QMediaDevices>
5
6#include "UVCDevices.h"
7#include "VideoBackend.h"
8
9namespace {
10
11bool hasStreaming()
12{
14}
15
16bool hasPipelineSettings()
17{
19}
20
21} // namespace
22
23DECLARE_SETTINGGROUP(Video, "Video")
24{
25 _updateVideoSources();
26 (void) connect(new QMediaDevices(this), &QMediaDevices::videoInputsChanged, this,
27 &VideoSettings::_updateVideoSources);
28
29 _setForceVideoDecodeList();
30
31 _nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoDisabled);
32}
33
34void VideoSettings::_updateVideoSources()
35{
36 static constexpr const char* fixedSources[] = {
46#ifdef QGC_HERELINK_AIRUNIT_VIDEO
48#else
50#endif
51 };
52
53 const QStringList cameras = _cameraNames ? _cameraNames() : UVCDevices::deviceNames();
54
55 if (FactMetaData* const metaData = _nameToMetaDataMap.value(videoSourceName)) {
56 QVariantList sources;
57 QStringList labels;
58 for (const char* const source : fixedSources) {
59 sources.append(QString::fromLatin1(source));
60 labels.append(tr(source));
61 }
62 // A settings override file or a custom build that replaced the sources, as the Fact was created, keeps its
63 // list.
64 const QVariantList listed = metaData->enumValues();
65 if (listed.isEmpty() || (listed.mid(0, sources.size()) == sources)) {
66 _offerCameras(metaData, _videoSourceFact, sources, labels, cameras);
67 }
68 }
69
70 if (FactMetaData* const metaData = _nameToMetaDataMap.value(uvcTileCameraName)) {
71 _offerCameras(metaData, _uvcTileCameraFact, {QString()}, {tr("None")}, cameras);
72 }
73}
74
75void VideoSettings::_offerCameras(FactMetaData* metaData, Fact* fact, QVariantList values, QStringList labels,
76 const QStringList& cameras)
77{
78 for (const QString& camera : cameras) {
79 values.append(camera);
80 labels.append(camera);
81 }
82 const QString selected = fact ? fact->rawValue().toString() : QString();
83 if (!selected.isEmpty() && !values.contains(selected)) {
84 values.append(selected);
85 labels.append(tr("%1 (not connected)").arg(selected));
86 }
87
88 if ((values == metaData->enumValues()) && (labels == metaData->enumStrings())) {
89 return;
90 }
91 if (fact) {
92 // Tells the settings page's combo box as well.
93 fact->setEnumInfo(labels, values);
94 } else {
95 metaData->setEnumInfo(labels, values);
96 }
97}
98
102DECLARE_SETTINGSFACT(VideoSettings, showTelemetryOverlay)
103DECLARE_SETTINGSFACT(VideoSettings, showRecControl)
104DECLARE_SETTINGSFACT(VideoSettings, recordingFormat)
106DECLARE_SETTINGSFACT(VideoSettings, enableStorageLimit)
107DECLARE_SETTINGSFACT(VideoSettings, disableWhenDisarmed)
112DECLARE_SETTINGSFACT(VideoSettings, uvcTileCameraAsMainPicture)
113DECLARE_SETTINGSFACT(VideoSettings, uvcCameraFormat)
114DECLARE_SETTINGSFACT(VideoSettings, uvcCameraRotation)
115DECLARE_SETTINGSFACT(VideoSettings, uvcCameraMirror)
116DECLARE_SETTINGSFACT(VideoSettings, uvcWhiteBalance)
118DECLARE_SETTINGSFACT(VideoSettings, uvcExposureCompensation)
120DECLARE_SETTINGSFACT(VideoSettings, uvcRecordingCodec)
121DECLARE_SETTINGSFACT(VideoSettings, uvcRecordingQuality)
122
124{
125 if (!_videoSourceFact) {
126 _videoSourceFact = _createSettingsFact(videoSourceName);
127 // The stored source may be a camera that isn't attached, which is listed only while it is selected. Queued:
128 // the combo box that sets the source deletes its items when its model changes, which it mustn't do while one
129 // of them reports its click.
130 _updateVideoSources();
131 (void) connect(_videoSourceFact, &Fact::rawValueChanged, this, &VideoSettings::_updateVideoSources,
132 Qt::QueuedConnection);
133 }
134 return _videoSourceFact;
135}
136
138{
139 if (!_uvcTileCameraFact) {
140 _uvcTileCameraFact = _createSettingsFact(uvcTileCameraName);
141 // As for videoSource: the stored camera may not be attached, and the list changes only after the click.
142 _updateVideoSources();
143 (void) connect(_uvcTileCameraFact, &Fact::rawValueChanged, this, &VideoSettings::_updateVideoSources,
144 Qt::QueuedConnection);
145 }
146 return _uvcTileCameraFact;
147}
148
149// DECLARE_SETTINGSFACT for a setting shown only where VISIBLE holds, read as the Fact is created.
150#define DECLARE_VIDEO_SETTINGSFACT_VISIBLE(NAME, VISIBLE) \
151 DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, NAME) \
152 { \
153 if (!_##NAME##Fact) { \
154 _##NAME##Fact = _createSettingsFact(NAME##Name); \
155 _##NAME##Fact->setUserVisible(VISIBLE); \
156 } \
157 return _##NAME##Fact; \
158 }
159
160// Only a GStreamer build offers a choice: without GStreamer, Qt Multimedia plays the streams.
161DECLARE_VIDEO_SETTINGSFACT_VISIBLE(videoBackend, hasPipelineSettings())
162
163DECLARE_VIDEO_SETTINGSFACT_VISIBLE(forceVideoDecoder, hasPipelineSettings())
164DECLARE_VIDEO_SETTINGSFACT_VISIBLE(lowLatencyMode, hasStreaming())
165DECLARE_VIDEO_SETTINGSFACT_VISIBLE(rtpJitterLatencyMs, hasPipelineSettings())
166DECLARE_VIDEO_SETTINGSFACT_VISIBLE(rtspAutoReconnect, hasStreaming())
167DECLARE_VIDEO_SETTINGSFACT_VISIBLE(forceCpuVideoPath, VideoBackend::instance().capabilities().gpuVideoPath)
168
169// videoConversionElement / disablePixelAspectRatio reach the receivers' display sinks as construct-only properties
170// (VideoStreamResolver::displayConfig()); VideoManager restarts the streams, which rebuilds the sinks, when they
171// change.
172DECLARE_VIDEO_SETTINGSFACT_VISIBLE(videoConversionElement, hasPipelineSettings())
173DECLARE_VIDEO_SETTINGSFACT_VISIBLE(disablePixelAspectRatio, hasPipelineSettings())
174
175DECLARE_VIDEO_SETTINGSFACT_VISIBLE(rtspTimeout, hasStreaming())
176
177#undef DECLARE_VIDEO_SETTINGSFACT_VISIBLE
178
179void VideoSettings::_setForceVideoDecodeList()
180{
181 if (!hasPipelineSettings()) {
182 return;
183 }
184 static const QList<VideoDecoderOption> removeForceVideoDecodeList{
185#if defined(Q_OS_ANDROID)
188#elif defined(Q_OS_LINUX)
191#elif defined(Q_OS_WIN)
194#elif defined(Q_OS_MACOS)
197#elif defined(Q_OS_IOS)
202#endif
203 };
204
205 for (const VideoDecoderOption option : removeForceVideoDecodeList) {
206 _nameToMetaDataMap[forceVideoDecoderName]->removeEnumInfo(static_cast<int>(option));
207 }
208}
209
211{
212 if (!hasPipelineSettings()) {
213 return;
214 }
215 static const QList<VideoDecoderOption> hardwareFamilies{
218 };
219
220 const QList<VideoDecoderOption> available = VideoBackend::instance().availableDecoderFamilies();
221 const auto metaIt = _nameToMetaDataMap.constFind(forceVideoDecoderName);
222 if (metaIt == _nameToMetaDataMap.constEnd() || !metaIt.value()) {
223 return;
224 }
225 FactMetaData* const metaData = metaIt.value();
226 bool pruned = false;
227 for (const auto family : hardwareFamilies) {
228 // removeEnumInfo() qWarns on an absent value, so skip families not in the enum; values are
229 // stored as QVariant(int), so match that representation.
230 const QVariant familyValue = static_cast<int>(family);
231 if (!available.contains(family) && metaData->enumValues().contains(familyValue)) {
232 metaData->removeEnumInfo(familyValue);
233 pruned = true;
234 }
235 }
236
237 Fact* const fact = forceVideoDecoder();
238 if (pruned) {
239 // Backend init is async — refresh any live FactComboBox bound to this fact.
240 emit fact->enumsChanged();
241 }
242 if (!metaData->enumValues().contains(fact->rawValue())) {
243 fact->setRawValue(static_cast<int>(VideoDecoderOption::Default));
244 }
245}
#define DECLARE_SETTINGSFACT_NO_FUNC(CLASS, NAME)
#define DECLARE_SETTINGSFACT(CLASS, NAME)
#define DECLARE_SETTINGGROUP(NAME, GROUP)
VideoDecoderOption
The decoders VideoSettings' forceVideoDecoder can force. The values are persisted.
#define DECLARE_VIDEO_SETTINGSFACT_VISIBLE(NAME, VISIBLE)
Holds the meta data associated with a Fact.
QStringList enumStrings() const
QVariantList enumValues() const
void setEnumInfo(const QStringList &strings, const QVariantList &values)
void removeEnumInfo(const QVariant &value)
Used to remove values from the enum lists after the meta data has been loaded.
A Fact is used to hold a single value within the system.
Definition Fact.h:15
void setEnumInfo(const QStringList &strings, const QVariantList &values)
Generally this is done during parsing. But if you know what you are doing, you can.
Definition Fact.cc:314
void rawValueChanged(const QVariant &value)
void setRawValue(const QVariant &value)
Definition Fact.cc:135
void enumsChanged()
QVariant rawValue() const
Definition Fact.h:87
QMap< QString, FactMetaData * > _nameToMetaDataMap
static VideoBackend & instance()
virtual QList< VideoDecoderOption > availableDecoderFamilies()
The hardware decoder families present, as forceVideoDecoder values (never Default or Software).
virtual Capabilities capabilities() const =0
static constexpr const char * videoSource3DRSolo
static constexpr const char * videoSourceParrotDiscovery
static constexpr const char * videoSourceTCP
static constexpr const char * videoSourceUDPH264
static constexpr const char * videoSourceHerelinkHotspot
static constexpr const char * videoSourceRTSP
static constexpr const char * videoDisabled
void pruneUnavailableDecoders()
static constexpr const char * videoSourceYuneecMantisG
static constexpr const char * videoSourceUDPH265
static constexpr const char * videoSourceMPEGTS
static constexpr const char * videoSourceHerelinkAirUnit
QStringList deviceNames()
Descriptions of the attached cameras.
Definition UVCDevices.cc:12
bool streaming
Plays network video streams; their settings are shown only then.