QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
VideoReceiver.h
Go to the documentation of this file.
1#pragma once
2
3#include <atomic>
4
5#include <QtCore/QObject>
6#include <QtCore/QSize>
7#include <QtCore/QTimer>
8#include <QtQmlIntegration/QtQmlIntegration>
9
11class QQuickItem;
12
13class VideoReceiver : public QObject
14{
15 Q_OBJECT
16 QML_ELEMENT
17 QML_UNCREATABLE("")
18public:
20 using VideoSinkHandle = void *;
21
22 explicit VideoReceiver(QObject *parent = nullptr)
23 : QObject(parent)
24 {}
25
26 bool isThermal() const { return (_name == QStringLiteral("thermalVideo")); }
27
28 VideoSinkHandle sink() const { return _sink; }
29 QQuickItem *widget() { return _widget; }
30 QString name() const { return _name; }
31 QString uri() const { return _uri; }
32 bool started() const { return _started; }
33 bool lowLatency() const { return _lowLatency; }
35 bool autoReconnect() const { return _autoReconnect; }
37 QString recordingOutput() const { return _recordingOutput; }
38
39 virtual void setSink(VideoSinkHandle sink) { if (sink != _sink) { _sink = sink; emit sinkChanged(_sink); } }
40 virtual void setWidget(QQuickItem *widget) { if (widget != _widget) { _widget = widget; emit widgetChanged(_widget); } }
41 void setName(const QString &name) { if (name != _name) { _name = name; emit nameChanged(_name); } }
42 void setUri(const QString &uri) { if (uri != _uri) { _uri = uri; emit uriChanged(_uri); } }
46 void setAutoReconnect(bool enabled) { if (enabled != _autoReconnect) { _autoReconnect = enabled; emit autoReconnectChanged(_autoReconnect); } }
48
49 // QMediaFormat::FileFormat
57 Q_ENUM(FILE_FORMAT)
58 static bool isValidFileFormat(FILE_FORMAT format) { return ((format >= FILE_FORMAT_MIN) && (format <= FILE_FORMAT_MAX)); }
59
69 Q_ENUM(STATUS)
70 static bool isValidStatus(STATUS status) { return ((status >= STATUS_MIN) && (status <= STATUS_MAX)); }
71
72signals:
73 void timeout();
74 void streamingChanged(bool active);
75 void decodingChanged(bool active);
76 void recordingChanged(bool active);
77 void recordingStarted(const QString &filename);
78 void videoSizeChanged(QSize size);
79
81 void nameChanged(const QString &name);
82 void uriChanged(const QString &uri);
86 void autoReconnectChanged(bool enabled);
88 void widgetChanged(QQuickItem *widget);
89
90 void onStartComplete(STATUS status);
91 void onStopComplete(STATUS status);
97
98public slots:
99 virtual void start(uint32_t timeout) = 0;
100 virtual void stop() = 0;
102 virtual void stopDecoding() = 0;
103 virtual void startRecording(const QString &videoFile, FILE_FORMAT format) = 0;
104 virtual void stopRecording() = 0;
105 virtual void takeScreenshot(const QString &imageFile) = 0;
106
107protected:
109 QQuickItem *_widget = nullptr;
111 QString _name;
112 QString _uri;
113 bool _started = false;
114 // Flipped on streaming threads, read cross-thread (e.g. tee probe logging).
115 std::atomic<bool> _decoding = false;
116 bool _recording = false;
117 bool _streaming = false;
118 bool _lowLatency = false;
120 // Written live on the GUI thread, read on the receiver worker thread.
121 std::atomic<bool> _autoReconnect = true;
122 bool _resetVideoSink = false;
123 bool _endOfStream = false;
124 bool _removingDecoder = false;
125 bool _removingRecorder = false;
126 // buffer:
127 // -1 - disable buffer and video sync
128 // 0 - default buffer length
129 // N - buffer length, ms
130 int _buffer = 0;
131 // Written on streaming threads (pad probes), read/written by the watchdog on the worker thread.
132 std::atomic<qint64> _lastSourceFrameTime = 0;
133 std::atomic<qint64> _lastVideoFrameTime = 0;
136 uint32_t _timeout = 0;
138
139 // bool _initialized = false;
140 // bool _fullScreen = false;
141 // QSize _videoSize;
142 // QString _imageFile;
143};
Encapsulates the contents of a VIDEO_STREAM_INFORMATION message.
void recordingStarted(const QString &filename)
QTimer _watchdogTimer
std::atomic< qint64 > _lastSourceFrameTime
bool lowLatency() const
QGCVideoStreamInfo * _videoStreamInfo
void setLowLatency(bool lowLatency)
void setName(const QString &name)
std::atomic< qint64 > _lastVideoFrameTime
void * VideoSinkHandle
Backend-specific decoded-frame sink.
void videoSizeChanged(QSize size)
void streamingChanged(bool active)
void nameChanged(const QString &name)
virtual void stopRecording()=0
virtual void startRecording(const QString &videoFile, FILE_FORMAT format)=0
VideoSinkHandle _sink
void rtpJitterLatencyMsChanged(int ms)
static bool isValidStatus(STATUS status)
uint32_t _timeout
bool started() const
VideoReceiver(QObject *parent=nullptr)
QQuickItem * widget()
void lowLatencyChanged(bool lowLatency)
QString uri() const
QString _recordingOutput
void recordingChanged(bool active)
void sinkChanged(VideoSinkHandle sink)
std::atomic< bool > _decoding
void onStartRecordingComplete(STATUS status)
VideoSinkHandle sink() const
void videoStreamInfoChanged()
virtual void setSink(VideoSinkHandle sink)
bool isThermal() const
virtual void start(uint32_t timeout)=0
void onTakeScreenshotComplete(STATUS status)
bool autoReconnect() const
void decodingChanged(bool active)
void onStartComplete(STATUS status)
void startedChanged(bool started)
virtual void startDecoding(VideoSinkHandle sink)=0
void setStarted(bool started)
void setUri(const QString &uri)
static bool isValidFileFormat(FILE_FORMAT format)
void widgetChanged(QQuickItem *widget)
QString name() const
void onStopDecodingComplete(STATUS status)
virtual void setWidget(QQuickItem *widget)
void setAutoReconnect(bool enabled)
void onStopRecordingComplete(STATUS status)
void uriChanged(const QString &uri)
virtual void stopDecoding()=0
QString recordingOutput() const
void setVideoStreamInfo(QGCVideoStreamInfo *videoStreamInfo)
void onStartDecodingComplete(STATUS status)
QQuickItem * _widget
void setRtpJitterLatencyMs(int ms)
void onStopComplete(STATUS status)
int rtpJitterLatencyMs() const
virtual void stop()=0
virtual void takeScreenshot(const QString &imageFile)=0
QGCVideoStreamInfo * videoStreamInfo()
std::atomic< bool > _autoReconnect
RTSP/UDP auto-reconnect with exponential backoff on watchdog/error.
void autoReconnectChanged(bool enabled)