QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GstReceiverWorker.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <optional>
5
6#include <QtCore/QObject>
7#include <QtCore/QString>
8
10#include "PipelineDotDumper.h"
11#include "PipelineSession.h"
12#include "RecordingPlan.h"
13#include "StreamSupervisor.h"
14#include "StreamWatchdog.h"
15#include "VideoReceiver.h"
16#include "VideoStreamStats.h"
18
19class QTimer;
20
26class GstReceiverWorker : public QObject, private PipelineSession::Listener
27{
28 Q_OBJECT
29
30public:
34
35 explicit GstReceiverWorker(QObject* parent = nullptr);
36 ~GstReceiverWorker() override;
37
39 void apply(const Request& request);
41 void shutdown();
42
45 void setMaxRecordingPartDuration(std::chrono::milliseconds duration) { _maxRecordingPartDuration = duration; }
46
47 GstElement* pipeline() const { return _session ? _session->pipeline() : nullptr; }
48
49signals:
50 void statusChanged(const GstReceiverStatus& status);
51 void recordingStarted(const QString& file);
52 void recordingFinished(const QString& file, const QString& error);
53 void errorOccurred(const QString& message);
59 void taskDone();
60
61private:
62 void _onActiveChanged();
63 void _onConfigChanged(const VideoReceiver::Config& previous);
64 void _startRecording(const RecordingRequest& request);
65 void _stopRecording();
66
67 template <typename T>
68 void _updateStatus(T Status::* field, const T& value)
69 {
70 if (_status.*field != value) {
71 _status.*field = value;
72 emit statusChanged(_status);
73 }
74 }
75
76 void _reconcile();
78 void _restartStream();
79 void _startSession();
80 void _stopSession();
82 void _recover(const PipelineSession::Failure& failure);
84 void _onHalted(const QString& message);
85 void _endRecording();
86 std::optional<RecordingBranch::Request> _recordingRequest() const;
87 void _onWatchdogTick();
88 void _sampleStats();
89 QString _redactedUri() const;
90
91 void onSessionStreaming() override;
92 void onSessionFailed(const PipelineSession::Failure& failure) override;
93 void onSessionGraphicsDeviceLost() override;
94 void onDecodingChanged(bool decoding) override;
95 void onDecoderNameChanged(const QString& name) override;
96 void onDecoderFailing() override;
97 void onRecordingFileOpened(const QString& file) override;
98 void onRecordingFileClosed(const QString& file, const QString& error) override;
99 void onRecordingFailed(const QString& file, const QString& error, bool fileOpened) override;
100 void onRecordingNeedsNewFile(const QString& file) override;
101
102 QTimer* const _watchdogTimer;
103 StreamSupervisor* const _supervisor;
104 StreamWatchdog _watchdog;
105 PipelineDotDumper _dotDumper;
106
107 Request _requested;
108 Status _status;
111 std::optional<RecordingPlan> _recording;
112 std::chrono::milliseconds _maxRecordingPartDuration = RecordingPlan::kMaxPartDuration;
113
114 PipelineSession* _session = nullptr;
115 int _statsTicks = 0;
116 VideoStreamStatsSampler _statsSampler;
117};
struct _GstElement GstElement
virtual void onDecoderFailing()=0
void statusChanged(const GstReceiverStatus &status)
GstReceiverStatus Status
void errorOccurred(const QString &message)
GstRecordingRequest RecordingRequest
void setMaxRecordingPartDuration(std::chrono::milliseconds duration)
GstReceiverRequest Request
void apply(const Request &request)
Steers the stream towards request, acting on what differs from the previous one.
GstReceiverWorker(QObject *parent=nullptr)
void recordingStarted(const QString &file)
void shutdown()
Stops everything and quits the thread.
~GstReceiverWorker() override
GstElement * pipeline() const
void graphicsDeviceLost()
void recordingFinished(const QString &file, const QString &error)
virtual void onSessionStreaming()=0
The first frame reached the tee.
virtual void onSessionGraphicsDeviceLost()=0
static constexpr std::chrono::minutes kMaxPartDuration
Everything the receiver asks for, as it stands after each of its requests.
What the worker reports, as it stands after each change.