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/QLoggingCategory>
4#include <QtCore/QObject>
5#include <QtCore/QRunnable>
6#include <QtCore/QSize>
7#include <QtQmlIntegration/QtQmlIntegration>
8
9Q_DECLARE_LOGGING_CATEGORY(VideoManagerLog)
10
11class 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)
28 Q_PROPERTY(bool autoStreamConfigured READ autoStreamConfigured NOTIFY autoStreamConfiguredChanged)
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
45public:
46 explicit VideoManager(QObject *parent = nullptr);
48
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 cleanup();
61 bool autoStreamConfigured() const;
62 bool decoding() const { return _decoding; }
63 bool fullScreen() const { return _fullScreen; }
64 bool hasThermal() const;
65 bool hasVideo() const;
66 bool isStreamSource() const;
67 bool isUvc() const;
68 bool recording() const { return _recording; }
69 bool streaming() const { return _streaming; }
70 double aspectRatio() const;
71 double hfov() const;
72 double thermalAspectRatio() const;
73 double thermalHfov() const;
74 QSize videoSize() const { return _videoSize; }
75 QString imageFile() const { return _imageFile; }
76 QString uvcVideoSourceID() const { return _uvcVideoSourceID; }
77 void setfullScreen(bool on);
78 static bool gstreamerEnabled();
79 static bool qtmultimediaEnabled();
80 static bool uvcEnabled();
81
82signals:
88 void imageFileChanged(const QString &filename);
92 void recordingChanged(bool recording);
93 void recordingStarted(const QString &filename);
97
98private slots:
99 void _communicationLostChanged(bool communicationLost);
100 void _setActiveVehicle(Vehicle *vehicle);
101 void _videoSourceChanged();
102
103private:
104 void _initAfterQmlIsReady();
105 void _initVideoReceiver(VideoReceiver *receiver, QQuickWindow *window);
106 bool _updateAutoStream(VideoReceiver *receiver);
107 bool _updateUVC(VideoReceiver *receiver);
108 bool _updateSettings(VideoReceiver *receiver);
109 bool _updateVideoUri(VideoReceiver *receiver, const QString &uri);
110 void _restartAllVideos();
111 void _restartVideo(VideoReceiver *receiver);
112 void _startReceiver(VideoReceiver *receiver);
113 void _stopReceiver(VideoReceiver *receiver);
114 static void _cleanupOldVideos();
115
116 QList<VideoReceiver*> _videoReceivers;
117
118 SubtitleWriter *_subtitleWriter = nullptr;
119 VideoSettings *_videoSettings = nullptr;
120
121 bool _initialized = false;
122 bool _initAfterQmlIsReadyDone = false;
123 bool _fullScreen = false;
124 QAtomicInteger<bool> _decoding = false;
125 QAtomicInteger<bool> _recording = false;
126 QAtomicInteger<bool> _streaming = false;
127 QSize _videoSize;
128 QString _imageFile;
129 QString _uvcVideoSourceID;
130 Vehicle *_activeVehicle = nullptr;
131 QQuickWindow *_mainWindow = nullptr;
132};
133
134/*===========================================================================*/
135
136class FinishVideoInitialization : public QRunnable
137{
138public:
141
142 void run() final;
143};
Q_DECLARE_LOGGING_CATEGORY(AndroidSerialLog)
void recordingStarted(const QString &filename)
void decodingChanged()
void hasVideoChanged()
void uvcVideoSourceIDChanged()
void isStreamSourceChanged()
void autoStreamConfiguredChanged()
void streamingChanged()
void fullScreenChanged()
void isUvcChanged()
void imageFileChanged(const QString &filename)
void recordingChanged(bool recording)
void isAutoStreamChanged()
void videoSizeChanged()
void aspectRatioChanged()