QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QtMultimediaVideoReceiver.h
Go to the documentation of this file.
1#pragma once
2
3#include <optional>
4
5#include <QtCore/QByteArray>
6#include <QtCore/QElapsedTimer>
7#include <QtCore/QTimer>
8#include <QtCore/QUrl>
9#include <QtMultimedia/QMediaPlayer>
10
11#include "StreamSupervisor.h"
12#include "VideoReceiver.h"
14
15class QMediaCaptureSession;
16class QtVideoRecorder;
17class QVideoFrameInput;
18
31{
32 Q_OBJECT
33
35
36public:
38 struct Source
39 {
40 QUrl url;
41 QByteArray sdp;
43 bool rtspOverTcp = false;
45 bool streamsDescribed = false;
46 };
47
48 explicit QtMultimediaVideoReceiver(QObject* parent = nullptr);
50
54 static std::optional<Source> playerSource(const QString& uri);
55
56 bool encodesRecordings() const override { return true; }
57
58protected:
59 void onConfigChanged() override;
60 void onActiveChanged() override;
61 void onRestartRequested() override;
62 void onReconnectRequested() override;
63 void onVideoOutputChanged() override;
64 void onStartRecording(const QString& file, FileFormat format) override;
65 void onStopRecording() override;
66
67private:
70 void _startOver();
72 void _start();
74 void _open();
76 void _stopSession();
78 bool _awaitingSender() const;
81 void _fail(const QString& reason);
82 void _bindVideoSink();
83 void _onMediaStatusChanged(QMediaPlayer::MediaStatus status);
84 void _onVideoFrame(const QVideoFrame& frame);
86 void _sample();
88 void _recordFrame(const QVideoFrame& frame);
93 static qint64 recordingTimeUs(qint64 lastRecordedUs, qint64 lastStreamUs, qint64 streamUs, qint64 arrivalUs);
94
95 QMediaPlayer* _player = nullptr;
96 bool _openPending = false;
98 bool _closing = false;
100 Config _sessionConfig;
101 QMetaObject::Connection _frameConnection;
102 StreamSupervisor* const _supervisor;
103 QTimer _sampleTimer;
105 QElapsedTimer _sinceOpened;
107 QElapsedTimer _sinceFrame;
108 VideoStreamStatsSampler _statsSampler;
109 quint64 _frames = 0;
110 bool _gpuFrames = false;
111 QtVideoRecorder* const _recorder;
113 QMediaCaptureSession* _recordingSession = nullptr;
114 QVideoFrameInput* _frameInput = nullptr;
116 QElapsedTimer _sinceRecordingStarted;
118 qint64 _lastRecordedUs = -1;
119 qint64 _lastStreamUs = -1;
120};
QtMultimediaVideoReceiver(QObject *parent=nullptr)
void onVideoOutputChanged() override
Also called when the current output is set again.
void onStartRecording(const QString &file, FileFormat format) override
bool encodesRecordings() const override
static std::optional< Source > playerSource(const QString &uri)
The reconnect policy both receivers share: the phase a stream is in, when a failed one connects again...
VideoReceiver(QObject *parent=nullptr)
FileFormat
Values are persisted by VideoSettings::recordingFormat.
The VideoStreamStats a receiver publishes, sampled about once a second while it streams.
What QMediaPlayer plays for a stream URI: a URL, or for RTP over UDP an SDP description of it.
bool streamsDescribed
An SDP names the streams, this one's or the RTSP server's: FFmpeg needn't read the stream to find the...
bool rtspOverTcp
RTSP interleaved over its TCP connection, rather than over UDP with FFmpeg's fallback to TCP.