QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
VideoManager.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QFuture>
4#include <QtCore/QPromise>
5#include <QtCore/QObject>
6#include <QtCore/QSize>
7#include <QtQmlIntegration/QtQmlIntegration>
8
9#include <functional>
10#include <memory>
11
12class QQuickWindow;
13class SubtitleWriter;
14class Vehicle;
15class VideoReceiver;
16class VideoSettings;
17
18class VideoManager : public QObject
19{
20 Q_OBJECT
21 QML_ELEMENT
22 QML_UNCREATABLE("")
23 Q_MOC_INCLUDE("Vehicle.h")
24
25 Q_PROPERTY(bool gstreamerEnabled READ gstreamerEnabled CONSTANT)
26 Q_PROPERTY(bool qtmultimediaEnabled READ qtmultimediaEnabled CONSTANT)
27 Q_PROPERTY(bool uvcEnabled READ uvcEnabled CONSTANT)
29 Q_PROPERTY(bool decoding READ decoding NOTIFY decodingChanged)
30 Q_PROPERTY(bool fullScreen READ fullScreen WRITE setfullScreen NOTIFY fullScreenChanged)
31 Q_PROPERTY(bool hasThermal READ hasThermal NOTIFY decodingChanged)
32 Q_PROPERTY(bool hasVideo READ hasVideo NOTIFY hasVideoChanged)
33 Q_PROPERTY(bool isStreamSource READ isStreamSource NOTIFY isStreamSourceChanged)
34 Q_PROPERTY(bool isUvc READ isUvc NOTIFY isUvcChanged)
35 Q_PROPERTY(bool recording READ recording NOTIFY recordingChanged)
36 Q_PROPERTY(bool streaming READ streaming NOTIFY streamingChanged)
37 Q_PROPERTY(double aspectRatio READ aspectRatio NOTIFY aspectRatioChanged)
38 Q_PROPERTY(double hfov READ hfov NOTIFY aspectRatioChanged)
39 Q_PROPERTY(double thermalAspectRatio READ thermalAspectRatio NOTIFY aspectRatioChanged)
40 Q_PROPERTY(double thermalHfov READ thermalHfov NOTIFY aspectRatioChanged)
41 Q_PROPERTY(QSize videoSize READ videoSize NOTIFY videoSizeChanged)
42 Q_PROPERTY(QString imageFile READ imageFile NOTIFY imageFileChanged)
43 Q_PROPERTY(QString uvcVideoSourceID READ uvcVideoSourceID NOTIFY uvcVideoSourceIDChanged)
44
46
47public:
48 explicit VideoManager(QObject *parent = nullptr);
49 ~VideoManager();
50
51 static VideoManager *instance();
52
53 Q_INVOKABLE void grabImage(const QString &imageFile = QString());
54 Q_INVOKABLE void startRecording(const QString &videoFile = QString());
55 Q_INVOKABLE void startVideo();
56 Q_INVOKABLE void stopRecording();
57 Q_INVOKABLE void stopVideo();
58
59 void init(QQuickWindow *mainWindow);
60 void startGStreamerInit();
61 bool waitForGStreamerInit(int timeoutMs = 60000);
62 void cleanup();
63 bool autoStreamConfigured() const;
64 bool decoding() const { return _decoding; }
65 bool fullScreen() const { return _fullScreen; }
66 bool hasThermal() const;
67 bool hasVideo() const;
68 bool isStreamSource() const;
69 bool isUvc() const;
70 bool recording() const { return _recording; }
71 bool streaming() const { return _streaming; }
72 double aspectRatio() const;
73 double hfov() const;
74 double thermalAspectRatio() const;
75 double thermalHfov() const;
76 QSize videoSize() const { return _videoSize; }
77 QString imageFile() const { return _imageFile; }
78 QString uvcVideoSourceID() const { return _uvcVideoSourceID; }
79 void setfullScreen(bool on);
80 static bool gstreamerEnabled();
81 static bool qtmultimediaEnabled();
82 static bool uvcEnabled();
83
84signals:
90 void imageFileChanged(const QString &filename);
95 void recordingStarted(const QString &filename);
99
100private slots:
101 void _communicationLostChanged(bool communicationLost);
102 void _setActiveVehicle(Vehicle *vehicle);
103 void _videoSourceChanged();
104
105private:
106 enum class InitState : uint8_t {
107 NotStarted,
108 Pending,
109 GstReady,
110 QmlReady,
111 Running,
112 Failed
113 };
114
115 static bool _shouldSkipGStreamerForUnitTests();
116 void _initAfterQmlIsReady();
117 void _onGstInitComplete(bool success);
118 void _createVideoReceivers();
119 void _initVideoReceiver(VideoReceiver *receiver, QQuickWindow *window);
120 bool _updateAutoStream(VideoReceiver *receiver);
121 bool _updateUVC(VideoReceiver *receiver);
122 bool _updateSettings(VideoReceiver *receiver);
123 bool _updateVideoUri(VideoReceiver *receiver, const QString &uri);
124 void _restartAllVideos();
125 void _restartVideo(VideoReceiver *receiver);
126 void _startReceiver(VideoReceiver *receiver);
127 void _stopReceiver(VideoReceiver *receiver);
128 static void _cleanupOldVideos();
129
130 QList<VideoReceiver*> _videoReceivers;
131 SubtitleWriter *_subtitleWriter = nullptr;
132 VideoSettings *_videoSettings = nullptr;
133 QQuickWindow *_mainWindow = nullptr;
134 Vehicle *_activeVehicle = nullptr;
135
136 InitState _initState = InitState::NotStarted;
137 QFuture<bool> _gstInitFuture;
138#if defined(QGC_GST_STREAMING) && defined(Q_OS_ANDROID)
139#endif
140 bool _initialized = false;
141 bool _gstreamerDisabledForUnitTests = false;
142 bool _fullScreen = false;
143
144 QAtomicInteger<bool> _decoding = false;
145 QAtomicInteger<bool> _recording = false;
146 QAtomicInteger<bool> _streaming = false;
147 QSize _videoSize;
148 QString _imageFile;
149 QString _uvcVideoSourceID;
150
151#ifdef QGC_UNITTEST_BUILD
152 std::function<void()> _createVideoReceiversForTest;
153#endif
154};
void recordingStarted(const QString &filename)
bool isStreamSource() const
bool fullScreen() const
void decodingChanged()
static bool gstreamerEnabled()
bool isUvc() const
void setfullScreen(bool on)
static bool uvcEnabled()
double hfov() const
static bool qtmultimediaEnabled()
Q_INVOKABLE void stopRecording()
void hasVideoChanged()
void uvcVideoSourceIDChanged()
Q_INVOKABLE void startVideo()
bool hasThermal() const
bool autoStreamConfigured() const
Q_INVOKABLE void startRecording(const QString &videoFile=QString())
double thermalAspectRatio() const
void isStreamSourceChanged()
static VideoManager * instance()
QString uvcVideoSourceID() const
bool decoding() const
void autoStreamConfiguredChanged()
void startGStreamerInit()
void streamingChanged()
void fullScreenChanged()
bool hasVideo() const
void init(QQuickWindow *mainWindow)
bool recording() const
Q_INVOKABLE void stopVideo()
double aspectRatio() const
friend class VideoManagerInitTest
void isUvcChanged()
double thermalHfov() const
void imageFileChanged(const QString &filename)
bool waitForGStreamerInit(int timeoutMs=60000)
QSize videoSize() const
void recordingChanged(bool recording)
bool streaming() const
void isAutoStreamChanged()
void videoSizeChanged()
QString imageFile() const
void aspectRatioChanged()
Q_INVOKABLE void grabImage(const QString &imageFile=QString())