QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
PipelineSession.h
Go to the documentation of this file.
1#pragma once
2
3#include <atomic>
4#include <memory>
5#include <optional>
6
7#include <QtCore/QObject>
8#include <QtCore/QString>
9
10#include "DecodingBranch.h"
11#include "GstBusPump.h"
12#include "GstScoped.h"
13#include "PipelineStatsProbe.h"
14#include "RecordingBranch.h"
16
18class StreamWatchdog;
19struct VideoStreamStats;
20
21namespace GstQgc {
22struct PathStats;
23}
24
38class PipelineSession : public QObject
39{
40 Q_OBJECT
41
42public:
43 struct Settings
44 {
45 QString uri;
46 QString redactedUri;
47 bool lowLatency = false;
49 };
50
51 struct Failure
52 {
53 QString reason;
54 QString message;
55 bool permanent = false;
56 };
57
61 {
62 public:
64 virtual void onSessionStreaming() = 0;
66 virtual void onSessionFailed(const Failure& failure) = 0;
69 virtual void onSessionGraphicsDeviceLost() = 0;
70
71 protected:
72 ~Listener() = default;
73 };
74
75 PipelineSession(const Settings& settings, Listener& listener, StreamWatchdog& watchdog,
76 const PipelineDotDumper& dotDumper, QObject* parent = nullptr);
77 ~PipelineSession() override;
78
80 [[nodiscard]] std::optional<Failure> start();
81
82 void setVideoSink(GstElement* sink);
83 void setRecording(const std::optional<RecordingBranch::Request>& request);
84 void restartDecoder(const char* reason);
85
86 bool displaying() const;
88
93
94 GstElement* pipeline() const { return _pipeline.get(); }
95
97 void snapshot(const QString& tag) const;
98
102 void shutdown();
103
104private:
105 void _post(std::function<void()> task);
106 void _fail(const Failure& failure);
107
109 GstBusSyncReply _onBusSync(GstMessage* message);
110 void _handleMessage(GstMessage* message);
111 void _onBusError(GstMessage* message);
112 QString _takeStartError();
114 void _noteMissingPlugin(GstMessage* message);
115
116 void _linkSourcePad(GstPad* pad);
117 void _onFirstFrame();
118 void _logLatency();
119
120 static void _onSourcePadAdded(GstElement* source, GstPad* pad, gpointer data);
121 static GstPadProbeReturn _teeProbe(GstPad* pad, GstPadProbeInfo* info, gpointer data);
122 static GstPadProbeReturn _sourceEosProbe(GstPad* pad, GstPadProbeInfo* info, gpointer data);
123
124 const Settings _settings;
125 Listener& _listener;
126 StreamWatchdog& _watchdog;
127 const PipelineDotDumper& _dotDumper;
128
129 GStreamer::GstElementPtr _pipeline;
130 // Owned by the pipeline.
131 GstElement* _tee = nullptr;
132 GstElement* _source = nullptr;
133 // Fixed once the pipeline runs, so the sync handler may read them.
134 GstElement* _displayValve = nullptr;
135 GstElement* _recordingValve = nullptr;
136
137 GstBusPump _bus;
138
139 std::unique_ptr<DecodingBranch> _decoding;
140 std::unique_ptr<RecordingBranch> _recording;
141 GStreamer::PadProbe _teeFrameProbe;
142 GStreamer::PadProbe _sourceEos;
143 GStreamer::ScopedSignal _sourcePadAdded;
144
145 enum class Phase : uint8_t
146 {
147 Running,
148 Failed,
149 TearingDown,
150 Down,
151 };
152
153 bool _tearingDown() const { return _phase >= Phase::TearingDown; }
154
155 Phase _phase = Phase::Running;
156 bool _streaming = false;
158 QString _missingPlugin;
160 PipelineStatsProbe _statsProbe;
161};
struct _GstElement GstElement
A pipeline's bus, handled from the thread the pump lives on.
Definition GstBusPump.h:20
virtual void onSessionStreaming()=0
The first frame reached the tee.
virtual void onSessionGraphicsDeviceLost()=0
virtual void onSessionFailed(const Failure &failure)=0
The stream failed; the session ignores further failures until it is shut down.
std::optional< Failure > start()
Builds the pipeline and sets it PLAYING. Returns why when it can't; shut the session down then.
void snapshot(const QString &tag) const
Writes PipelineDotDumper::snapshot() of the pipeline under tag.
bool displaying() const
GstElement * pipeline() const
~PipelineSession() override
GstQgc::PathStats sinkPathStats() const
void restartDecoder(const char *reason)
void setRecording(const std::optional< RecordingBranch::Request > &request)
void setVideoSink(GstElement *sink)
PipelineSession(const Settings &settings, Listener &listener, StreamWatchdog &watchdog, const PipelineDotDumper &dotDumper, QObject *parent=nullptr)
void sampleStats(VideoStreamStatsMeter::Counters &counters, VideoStreamStats &stats)
PipelineBranch
The tee branch a pipeline element belongs to, so a bus message can be blamed on the part that failed.
@ None
The source, the tee, or the pipeline itself.
std::unique_ptr< GstElement, GstObjectDeleter > GstElementPtr
Definition GstScoped.h:60
GstVideoSink that pushes decoded frames into a Qt QVideoSink; sole sink in qgcvideosinkbin....
Formatted per-path frame counts + the total delivered through GPU paths.
QString message
For the user.
bool permanent
Retrying can't help: unsupported URI, missing plugin, refused credentials.
QString reason
For the log.