QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
VideoStreamController.h
Go to the documentation of this file.
1#pragma once
2
3#include <optional>
4
5#include <QtCore/QObject>
6#include <QtCore/QPointer>
7#include <QtCore/QSize>
8#include <QtCore/QString>
9#include <QtQmlIntegration/QtQmlIntegration>
10
11#include "VideoReceiver.h"
12#include "VideoStreamResolver.h"
13
15class QQuickItem;
16class VideoSettings;
17
33class VideoStreamController : public QObject
34{
35 Q_OBJECT
36 QML_ELEMENT
37 QML_UNCREATABLE("")
38 Q_PROPERTY(VideoStreamResolver::Role role READ role NOTIFY roleChanged FINAL)
40 Q_PROPERTY(bool tile READ tile NOTIFY tileChanged FINAL)
42 Q_PROPERTY(QString displayName READ displayName NOTIFY displayNameChanged FINAL)
43 Q_PROPERTY(bool decoding READ decoding NOTIFY decodingChanged FINAL)
44 Q_PROPERTY(bool reconnecting READ reconnecting NOTIFY reconnectingChanged FINAL)
45 Q_PROPERTY(bool recording READ recording NOTIFY recordingChanged FINAL)
46 Q_PROPERTY(bool encodesRecordings READ encodesRecordings NOTIFY encodesRecordingsChanged FINAL)
47 Q_PROPERTY(QSize videoSize READ videoSize NOTIFY videoSizeChanged FINAL)
48 Q_PROPERTY(int rotation READ rotation NOTIFY rotationChanged FINAL)
49 Q_PROPERTY(double aspectRatio READ aspectRatio NOTIFY aspectRatioChanged FINAL)
50 Q_PROPERTY(VideoStreamStats stats READ stats NOTIFY statsChanged FINAL)
51 Q_PROPERTY(QGCVideoStreamInfo* streamInfo READ streamInfo NOTIFY streamInfoChanged FINAL)
52 Q_PROPERTY(QString uri READ uri NOTIFY uriChanged FINAL)
53 Q_PROPERTY(QString transport READ transport NOTIFY uriChanged FINAL)
54 Q_MOC_INCLUDE("QGCVideoStreamInfo.h")
55
56public:
58
60 VideoStreamController(Role role, VideoSettings* videoSettings, QObject* parent = nullptr,
61 VideoReceiver* ownReceiver = nullptr);
63
64 Role role() const { return _role; }
65
67 void setRole(Role role);
68
69 bool tile() const { return _tile; }
70
71 void setTile(bool tile);
72
73 QString displayName() const { return _displayName; }
74
75 void setDisplayName(const QString& displayName);
76
79 QString name() const { return _name; }
80
82 void setName(const QString& name) { _name = name; }
83
85 QString taggedFile(const QString& file) const;
86
87 VideoReceiver* receiver() const { return _receiver; }
88
94 void shutDown();
95
99
102 void setCamera(const QString& camera);
103
105 void setEnabled(bool enabled);
106
107 bool configured() const { return _resolvedConfig().has_value(); }
108
111 void scheduleApply();
113 void stop();
115 void restart();
117 void reconnectNow();
118
119 QQuickItem* videoOutput() const;
120
123 Q_INVOKABLE void registerVideoOutput(QQuickItem* videoOutput);
126 Q_INVOKABLE void unregisterVideoOutput(QQuickItem* videoOutput);
127
130 void setDisplaySuspended(bool suspended);
131
133 bool active() const;
134 void startRecording(const QString& file, VideoReceiver::FileFormat format);
135 void stopRecording();
136
139 bool encodesRecordings() const;
142
144 bool canTakeScreenshot() const;
145 bool takeScreenshot(const QString& file, const VideoScreenshot::Exif& exif = {}) const;
146
147 bool decoding() const;
148
151 bool reconnecting() const { return _reconnecting; }
152
153 bool recording() const;
154
158 int rotation() const { return _rotation; }
159
161 QSize videoSize() const;
164 double aspectRatio() const;
166 VideoStreamStats stats() const;
169 QString uri() const;
172 QString transport() const;
173
174signals:
188 void recordingStarted(const QString& file);
189 void recordingFinished(const QString& file, const QString& error);
190 void errorOccurred(const QString& message);
191
192private:
194 std::optional<VideoReceiver::Config> _resolvedConfig() const;
195 VideoReceiver::DisplayConfig _resolvedDisplayConfig() const;
196 void _apply();
197 void _onStreamInfoChanged();
199 void _detachVideoOutput();
200 void _onReceiverStateChanged(VideoReceiver::State state);
202 void _forgetDecoded();
203 void _updateReconnecting();
204
205 Role _role;
206 QString _name;
207 QString _displayName;
208 bool _tile = false;
209 VideoSettings* const _videoSettings;
210 VideoReceiver* _receiver = nullptr;
211 bool _hasOwnReceiver = false;
212 QPointer<QGCVideoStreamInfo> _streamInfo;
213 QString _camera;
214 QPointer<QQuickItem> _videoOutput;
215 bool _displaySuspended = false;
216 VideoReceiver::RecordingEncoding _recordingEncoding;
218 QString _uri;
219 bool _enabled = false;
220 bool _applyPending = false;
221 bool _decoded = false;
222 bool _reconnecting = false;
223 int _rotation = 0;
224};
Encapsulates the contents of a VIDEO_STREAM_INFORMATION message.
FileFormat
Values are persisted by VideoSettings::recordingFormat.
void setDisplaySuspended(bool suspended)
QGCVideoStreamInfo * streamInfo() const
void recordingStarted(const QString &file)
void setDisplayName(const QString &displayName)
QQuickItem * videoOutput() const
void recordingFinished(const QString &file, const QString &error)
void restart()
Reconnects now and rebuilds the receiver's display sink, so construct-only sink settings apply.
void setCamera(const QString &camera)
~VideoStreamController() override
void startRecording(const QString &file, VideoReceiver::FileFormat format)
VideoReceiver * receiver() const
QString taggedFile(const QString &file) const
file for this source: the thermal stream's name goes before the extension, "<base>....
bool takeScreenshot(const QString &file, const VideoScreenshot::Exif &exif={}) const
void setReceiver(VideoReceiver *receiver)
void setEnabled(bool enabled)
The stream plays while it is enabled and configured().
VideoStreamResolver::Role Role
The source is shown in a tile of the video view, rather than as the main picture or with it.
void setRecordingEncoding(const VideoReceiver::RecordingEncoding &encoding)
VideoReceiver::setRecordingEncoding(), for the receiver and for each one set later.
void reconnectNow()
VideoReceiver::reconnectNow(): the stream's source is likely back, so a reconnect doesn't wait out it...
QSize videoSize() const
The size the stream is shown at: the receiver's video size, turned by rotation().
void setName(const QString &name)
Names a source that has no receiver yet.
bool active() const
True when the receiver is active, accepting startRecording().
VideoStreamStats stats() const
The receiver's VideoReceiver::stats(); invalid without a receiver.
Q_INVOKABLE void registerVideoOutput(QQuickItem *videoOutput)
VideoStreamController(Role role, VideoSettings *videoSettings, QObject *parent=nullptr, VideoReceiver *ownReceiver=nullptr)
ownReceiver, when given, is the source's receiver for good; the source takes ownership of it.
Q_INVOKABLE void unregisterVideoOutput(QQuickItem *videoOutput)
void setRole(Role role)
Makes a stream in a tile the primary stream, or the reverse. What the source plays stays.
void recordingChanged(bool recording)
void setStreamInfo(QGCVideoStreamInfo *streamInfo)
The stream the camera advertises for this role, which takes precedence over the manual settings.
void stop()
Disables the stream and stops the receiver now.
void errorOccurred(const QString &message)
bool canTakeScreenshot() const
True while the stream is streaming into a registered output.
Role
What a video source, each with a VideoStreamController, is. VideoSourceRole.Primary,...
How the display sink presents frames. Construct-only: a change applies when restart() rebuilds the si...