QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
PipelineSession.cc
Go to the documentation of this file.
1#include "PipelineSession.h"
2
3#include <gst/gst.h>
4#include <gst/pbutils/missing-plugins.h>
5#include <utility>
6
7#include <QtCore/QDeadlineTimer>
8
9#include "GStreamerHelpers.h"
10#include "GstSourceFactory.h"
11#include "GstVideoReceiver.h"
12#include "HwBuffers/HwBuffers.h"
13#include "PipelineDotDumper.h"
14#include "StreamWatchdog.h"
15#include "VideoStreamStats.h"
17
18namespace {
19
20// Source flow is logged every this many frames.
21constexpr quint64 kSourceFlowLogIntervalFrames = 300;
22// Retransmission needs playout latency left over after the source factory's 25 ms rtx-delay; with less, recovered
23// packets arrive too late and only add load.
24constexpr int kMinRetransmissionLatencyMs = 40;
25
26void logBusWarning(GstMessage* message)
27{
28 // GStreamer posts WARNING for caps mismatches, decoder fallbacks, clock drift: surfacing keeps these visible
29 // without failing the stream.
30 const auto [error, debug] = GStreamer::parseMessageError(message);
31 qCWarning(GstVideoReceiverLog) << "GStreamer warning:" << (error ? error->message : "(no message)")
32 << "debug:" << (debug ? debug.get() : "(none)");
33}
34
37void logSourceProgress(GstMessage* message)
38{
39 if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_ELEMENT) {
40 if (gst_message_has_name(message, "GstRTSPSrcTimeout")) {
41 gint stream = -1;
42 (void) gst_structure_get_int(gst_message_get_structure(message), "stream-number", &stream);
43 qCDebug(GstVideoReceiverLog) << "The sender of RTSP stream" << stream << "timed out";
44 }
45 return;
46 }
47 GstProgressType type = GST_PROGRESS_TYPE_START;
48 gchar* rawCode = nullptr;
49 gchar* rawText = nullptr;
50 gst_message_parse_progress(message, &type, &rawCode, &rawText);
51 const GStreamer::GCharPtr code = GStreamer::adoptGChar(rawCode);
52 const GStreamer::GCharPtr text = GStreamer::adoptGChar(rawText);
53 // The connect step's text is "Connecting to <address>", and the log shows that address redacted.
54 const bool connect = (g_strcmp0(code.get(), "connect") == 0);
55 qCDebug(GstVideoReceiverLog) << "Source progress:" << (code ? code.get() : "(none)")
56 << (connect ? "Connecting" : (text ? text.get() : ""));
57}
58
59bool isRecoverableH265PaciError(GstMessage* msg, const GError* error, const gchar* debug)
60{
61 if (!msg || !error || (error->domain != GST_STREAM_ERROR) || (error->code != GST_STREAM_ERROR_FORMAT) || !debug ||
62 !g_strrstr(debug, "NAL unit type 50 not supported yet")) {
63 return false;
64 }
65 return g_strcmp0(GStreamer::factoryNameOf(GST_MESSAGE_SRC(msg)), "rtph265depay") == 0;
66}
67
68bool postedByRtspSrc(GstMessage* message)
69{
70 return g_strcmp0(GStreamer::factoryNameOf(GST_MESSAGE_SRC(message)), "rtspsrc") == 0;
71}
72
74bool isUnauthorizedError(const GError* error)
75{
76 return g_error_matches(error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_NOT_AUTHORIZED);
77}
78
80bool isPermanentError(GstMessage* message, const GError* error)
81{
82 if (g_error_matches(error, GST_STREAM_ERROR, GST_STREAM_ERROR_CODEC_NOT_FOUND)) {
83 // rtspsrc's means it set up no stream at all, as when the server refused every transport: not a codec that
84 // is missing, and the next attempt may get one.
85 return !postedByRtspSrc(message);
86 }
87 return g_error_matches(error, GST_CORE_ERROR, GST_CORE_ERROR_MISSING_PLUGIN) || isUnauthorizedError(error);
88}
89
93QString debugCause(const gchar* debug)
94{
95 const gchar* const separator = debug ? g_strstr_len(debug, -1, ":\n") : nullptr;
96 return separator ? QString::fromUtf8(separator + 2).simplified() : QString();
97}
98
101QString rtspStatus(GstMessage* message)
102{
103 const GstStructure* details = nullptr;
104 gst_message_parse_error_details(message, &details);
105 guint code = 0;
106 if (!details || !gst_structure_get_uint(details, "rtsp-status-code", &code)) {
107 return {};
108 }
109 const gchar* const reason = gst_structure_get_string(details, "rtsp-status-reason");
110 return QStringLiteral("RTSP %1 %2").arg(QString::number(code), QString::fromUtf8(reason ? reason : "")).trimmed();
111}
112
115QString describeError(GstMessage* message, const QString& text, const gchar* debug,
116 const QString& missingPlugin = QString())
117{
118 QString cause = missingPlugin;
119 if (cause.isEmpty()) {
120 cause = rtspStatus(message);
121 }
122 if (cause.isEmpty()) {
123 cause = debugCause(debug);
124 }
125 // The cause can quote the far end (a server's reason phrase), and the message is shown where markup is rendered.
126 cause.remove(QLatin1Char('<'));
127 return cause.isEmpty() ? text : QStringLiteral("%1 (%2)").arg(text, cause);
128}
129
130bool pipelineEnteredPlaying(GstMessage* message)
131{
132 // Only our pipeline is a GstPipeline on its own bus.
133 if (!GST_IS_PIPELINE(GST_MESSAGE_SRC(message))) {
134 return false;
135 }
136 GstState oldState = GST_STATE_NULL, newState = GST_STATE_NULL;
137 gst_message_parse_state_changed(message, &oldState, &newState, nullptr);
138 return (newState == GST_STATE_PLAYING) && (oldState != GST_STATE_PLAYING);
139}
140
141QString messageSourcePath(GstMessage* message)
142{
144 GST_MESSAGE_SRC(message) ? gst_object_get_path_string(GST_MESSAGE_SRC(message)) : nullptr);
145 return QString::fromUtf8(path ? path.get() : "(unknown)");
146}
147
148} // namespace
149
151 const PipelineDotDumper& dotDumper, QObject* parent)
152 : QObject(parent)
153 , _settings(settings)
154 , _listener(listener)
155 , _watchdog(watchdog)
156 , _dotDumper(dotDumper)
157{}
158
163
164std::optional<PipelineSession::Failure> PipelineSession::start()
165{
166 qCDebug(GstVideoReceiverLog) << "Starting" << _settings.redactedUri << "lowLatency" << _settings.lowLatency;
167
168 _pipeline = GStreamer::adoptFloating(gst_pipeline_new(_dotDumper.pipelineName().constData()));
169 // The sync handler is in place before anything can post: the context bridges must see NEED_CONTEXT, which upstream
170 // queries during PAUSED->PLAYING.
171 if (!_pipeline || !_bus.attach(
172 _pipeline.get(), [this](GstMessage* message) { return _onBusSync(message); },
173 [this](GstMessage* message) {
174 if (_phase != Phase::Down) {
175 _handleMessage(message);
176 }
177 })) {
178 return Failure{.reason = QStringLiteral("pipeline creation failed"),
179 .message = tr("Unable to create the video pipeline."),
180 .permanent = true};
181 }
182 // Branch EOS reaches the bus wrapped in GstBinForwarded, so the recorder's own EOS can be told apart.
183 g_object_set(_pipeline.get(), "message-forward", TRUE, nullptr);
184
185 _tee = GStreamer::addToBin(_pipeline.get(), GStreamer::makeElement("tee"), "tee");
186 const GStreamer::GstPadPtr teeSink = GStreamer::adoptPad(_tee ? gst_element_get_static_pad(_tee, "sink") : nullptr);
187 // The probe feeds the watchdog; without it the watchdog fires spuriously instead of reporting a real failure.
188 if (!teeSink || !_teeFrameProbe.add(teeSink.get(), GST_PAD_PROBE_TYPE_BUFFER, _teeProbe, this)) {
189 return Failure{.reason = QStringLiteral("tee creation failed"),
190 .message = tr("Unable to create the video pipeline."),
191 .permanent = true};
192 }
193
194 const BranchContext context{
195 .pipeline = _pipeline.get(),
196 .tee = _tee,
197 .redactedUri = _settings.redactedUri,
198 .dotDumper = &_dotDumper,
199 .watchdog = &_watchdog,
200 .post = [this](std::function<void()> task) { _post(std::move(task)); },
201 };
202 _decoding = std::make_unique<DecodingBranch>(context, _listener, _settings.lowLatency);
203 _recording = std::make_unique<RecordingBranch>(context, _listener);
204 if (!_decoding->build() || !_recording->build()) {
205 return Failure{.reason = QStringLiteral("branch creation failed"),
206 .message = tr("Unable to create the video pipeline."),
207 .permanent = true};
208 }
209 _displayValve = _decoding->valve();
210 _recordingValve = _recording->valve();
211
213 sourceConfig.jitterBuffer = _settings.lowLatency ? GStreamer::SourceFactory::JitterBuffer::None
215 sourceConfig.latencyMs = _settings.rtpJitterLatencyMs;
216 sourceConfig.doRetransmission = (_settings.rtpJitterLatencyMs >= kMinRetransmissionLatencyMs) &&
218 // Floating: the pipeline takes it over.
219 _source = GStreamer::SourceFactory::create(_settings.uri, sourceConfig);
220 if (!_source || !gst_bin_add(GST_BIN(_pipeline.get()), _source)) {
221 _source = nullptr;
222 return Failure{.reason = QStringLiteral("no source for the URI"),
223 .message = tr("The video stream %1 is not supported, or a GStreamer plugin it needs is missing.")
224 .arg(_settings.redactedUri),
225 .permanent = true};
226 }
227
228 if (const GStreamer::GstPadPtr srcPad = GStreamer::firstSrcPad(_source)) {
229 _linkSourcePad(srcPad.get());
230 } else {
231 (void) _sourcePadAdded.connect(_source, "pad-added", G_CALLBACK(_onSourcePadAdded), this);
232 }
233
234 _dotDumper.dump(_pipeline.get(), "pipeline-initial");
235 if (gst_element_set_state(_pipeline.get(), GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
236 const QString error = _takeStartError();
237 qCWarning(GstVideoReceiverLog) << "Failed to start" << _settings.redactedUri;
238 return Failure{.reason = QStringLiteral("start failure"),
239 .message = tr("Unable to start the video stream: %1").arg(error),
240 .permanent = false};
241 }
242
243 _dotDumper.dump(_pipeline.get(), "pipeline-started");
244 qCDebug(GstVideoReceiverLog) << "Started" << _settings.redactedUri;
245 return std::nullopt;
246}
247
249{
250 if (_decoding && !_tearingDown()) {
251 _decoding->setVideoSink(sink);
252 }
253}
254
255void PipelineSession::setRecording(const std::optional<RecordingBranch::Request>& request)
256{
257 if (_recording && !_tearingDown()) {
258 _recording->setRequest(request);
259 }
260}
261
262void PipelineSession::restartDecoder(const char* reason)
263{
264 if (_decoding && !_tearingDown()) {
265 _decoding->restartDecoder(reason);
266 }
267}
268
270{
271 return _decoding && _decoding->displaying();
272}
273
275{
276 return _decoding ? _decoding->sinkPathStats() : GstQgc::PathStats{};
277}
278
280{
281 if (_decoding) {
282 const DecodingBranch::StatsSample display = _decoding->sampleStats();
283 counters.framesDisplayed = display.framesDisplayed;
284 counters.framesDropped = display.framesDropped;
285 stats.gpuPath = display.displayPath;
286 stats.decoder = _decoding->decoderName();
287 stats.hardwareDecoder = _decoding->hardwareDecoder();
288 stats.gpuFallbacks = static_cast<qint64>(display.gpuFallbacks);
289 stats.decoderRestarts = static_cast<qint64>(display.decoderRestarts);
290 }
291
292 _statsProbe.sample(_pipeline.get(), _source, _tee, counters, stats);
293}
294
295void PipelineSession::snapshot(const QString& tag) const
296{
297 _dotDumper.snapshot(_pipeline.get(), tag);
298}
299
301{
302 if (_phase == Phase::Down) {
303 return;
304 }
305 _phase = Phase::TearingDown;
306
307 if (_recording && _pipeline && _recording->beginTeardown()) {
308 // Handles the recorder's messages until it is finalized. The pump discards every other type, which
309 // _handleMessage() ignores anyway while tearing down.
310 _bus.pumpUntil(
311 static_cast<GstMessageType>(GST_MESSAGE_ERROR | GST_MESSAGE_ELEMENT),
312 [this]() { return !_recording->finalizing(); }, QDeadlineTimer(RecordingBranch::kFinalizeTimeout));
313 _recording->completeTeardown();
314 }
315 // From here on, work queued by streaming threads is stale.
316 _phase = Phase::Down;
317
318 const GstQgc::PathStats hwStats = sinkPathStats();
319
320 if (_pipeline) {
321 // Synchronous: the streaming threads have stopped when this returns.
322 (void) gst_element_set_state(_pipeline.get(), GST_STATE_NULL);
323 }
324 _bus.detach();
325
326 _teeFrameProbe.remove();
327 _sourceEos.remove();
328 _sourcePadAdded.disconnect();
329 if (_decoding) {
330 _decoding->reset();
331 }
332 if (_recording) {
333 _recording->reset();
334 }
335
336 if (hwStats.totalDelivered > 0) {
337 qCDebug(GstVideoReceiverLog).noquote() << "GPU path stats" << _settings.redactedUri << hwStats.line;
338 }
339
340 if (_pipeline) {
341 _dotDumper.dump(_pipeline.get(), "pipeline-stopped");
342 qCDebug(GstVideoReceiverLog) << "Stopped" << _settings.redactedUri;
343 }
344 _pipeline.reset();
345 _tee = nullptr;
346 _source = nullptr;
347}
348
349void PipelineSession::_post(std::function<void()> task)
350{
351 (void) QMetaObject::invokeMethod(
352 this,
353 [this, task = std::move(task)]() {
354 if (_phase != Phase::Down) {
355 task();
356 }
357 },
358 Qt::QueuedConnection);
359}
360
361void PipelineSession::_fail(const Failure& failure)
362{
363 if (_phase != Phase::Running) {
364 return;
365 }
366 _phase = Phase::Failed;
367 _post([this, failure]() { _listener.onSessionFailed(failure); });
368}
369
370void PipelineSession::_handleMessage(GstMessage* message)
371{
372 if (!_decoding || !_recording) {
373 return;
374 }
375 switch (GST_MESSAGE_TYPE(message)) {
376 case GST_MESSAGE_ERROR:
377 _onBusError(message);
378 break;
379 case GST_MESSAGE_WARNING:
380 if (!_tearingDown()) {
381 logBusWarning(message);
382 }
383 break;
384 case GST_MESSAGE_ELEMENT:
385 if (gst_message_has_name(message, HwBuffers::kGraphicsDeviceServedMessage)) {
386 if (!_tearingDown()) {
387 _decoding->onGraphicsDeviceServed();
388 }
389 break;
390 }
391 if (gst_message_has_name(message, HwBuffers::kGraphicsDeviceLostMessage)) {
392 if (_phase == Phase::Running) {
393 qCDebug(GstVideoReceiverLog) << "The graphics device is gone" << _settings.redactedUri;
394 _post([this]() { _listener.onSessionGraphicsDeviceLost(); });
395 }
396 break;
397 }
398 _noteMissingPlugin(message);
400 _recording->onBusElement(message);
401 logSourceProgress(message);
402 break;
403 case GST_MESSAGE_PROGRESS:
404 logSourceProgress(message);
405 break;
406 case GST_MESSAGE_STATE_CHANGED:
407 if (!_tearingDown() && pipelineEnteredPlaying(message)) {
408 _logLatency();
409 }
410 break;
411 case GST_MESSAGE_LATENCY:
412 // Recalculation hands the sinks their new latency in a LATENCY event.
413 if (!_tearingDown()) {
414 (void) gst_bin_recalculate_latency(GST_BIN(_pipeline.get()));
415 }
416 break;
417 default:
418 break;
419 }
420}
421
422void PipelineSession::_onBusError(GstMessage* message)
423{
424 const auto [error, debug] = GStreamer::parseMessageError(message);
425 const QString text = QString::fromUtf8(error ? error->message : "(no message)");
426
427 if (isRecoverableH265PaciError(message, error.get(), debug.get())) {
428 qCWarning(GstVideoReceiverLog) << "Ignoring unsupported H.265 RTP PACI packet from rtph265depay:" << text;
429 return;
430 }
431
432 const GStreamer::PipelineBranch branch = GStreamer::branchOf(GST_MESSAGE_SRC(message));
434 _recording->onBusError(message, error.get(), text, debug.get());
435 return;
436 }
437
438 const char* const debugText = debug ? debug.get() : "(none)";
439 if (_phase != Phase::Running) {
440 qCDebug(GstVideoReceiverLog) << "Ignoring an error after the stream ended:" << text << "debug:" << debugText;
441 return;
442 }
443 const bool namesMissingPlugin =
444 g_error_matches(error.get(), GST_CORE_ERROR, GST_CORE_ERROR_MISSING_PLUGIN) && (branch == _missingPluginBranch);
445 const QString description =
446 describeError(message, text, debug.get(), namesMissingPlugin ? _missingPlugin : QString());
447
449 if (!_decoding->isCurrent(GST_MESSAGE_SRC(message))) {
450 qCDebug(GstVideoReceiverLog) << "Ignoring an error from a replaced decoder:" << text
451 << "debug:" << debugText;
452 return;
453 }
454 qCWarning(GstVideoReceiverLog) << "Decoder error from" << messageSourcePath(message) << ":" << text
455 << "debug:" << debugText;
456 if (isPermanentError(message, error.get())) {
457 _fail({.reason = QStringLiteral("decoder error"),
458 .message = tr("Unable to decode the video: %1").arg(description),
459 .permanent = true});
460 } else {
461 _decoding->restartDecoder("decoder error");
462 }
463 return;
464 }
465
466 qCWarning(GstVideoReceiverLog) << "GStreamer error from" << messageSourcePath(message) << ":" << text
467 << "debug:" << debugText;
468 _dotDumper.snapshot(_pipeline.get(), QStringLiteral("pipeline-error"));
469 const QString userMessage =
470 isUnauthorizedError(error.get())
471 ? tr("The video stream refused the connection: its user name or password is missing or wrong.")
472 : tr("Video stream error: %1").arg(description);
473 _fail({.reason = QStringLiteral("pipeline error"),
474 .message = userMessage,
475 .permanent = isPermanentError(message, error.get())});
476}
477
478QString PipelineSession::_takeStartError()
479{
480 // The state change posted why it failed; nothing else in the queue matters for a pipeline that never ran: pop()
481 // discards what was queued before the error, and shutdown() flushes the rest.
482 const GStreamer::GstMessagePtr message = _bus.pop(GST_MESSAGE_ERROR);
483 if (!message) {
484 return tr("unknown error");
485 }
486 const auto [error, debug] = GStreamer::parseMessageError(message.get());
487 const QString text = QString::fromUtf8(error ? error->message : "(no message)");
488 qCWarning(GstVideoReceiverLog) << "GStreamer error from" << messageSourcePath(message.get()) << ":" << text
489 << "debug:" << (debug ? debug.get() : "(none)");
490 return describeError(message.get(), text, debug.get());
491}
492
493void PipelineSession::_noteMissingPlugin(GstMessage* message)
494{
495 if (!gst_is_missing_plugin_message(message)) {
496 return;
497 }
498 const GStreamer::GCharPtr description = GStreamer::adoptGChar(gst_missing_plugin_message_get_description(message));
499 _missingPlugin = QString::fromUtf8(description ? description.get() : "");
500 _missingPluginBranch = GStreamer::branchOf(GST_MESSAGE_SRC(message));
501 qCWarning(GstVideoReceiverLog) << "Missing GStreamer plugin:" << _missingPlugin << "for"
502 << messageSourcePath(message);
503}
504
505void PipelineSession::_linkSourcePad(GstPad* pad)
506{
507 const GStreamer::GstPadPtr teeSink = GStreamer::adoptPad(gst_element_get_static_pad(_tee, "sink"));
508 const GstPadLinkReturn linkResult = teeSink ? gst_pad_link(pad, teeSink.get()) : GST_PAD_LINK_WRONG_HIERARCHY;
509 if (linkResult != GST_PAD_LINK_OK) {
510 qCWarning(GstVideoReceiverLog) << "Unable to link source:" << gst_pad_link_get_name(linkResult);
511 return;
512 }
513 // Streaming is reported from the first frame, not from here: a static source pad exists before any data does.
514 (void) _sourceEos.add(pad, GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, _sourceEosProbe, this);
515 _dotDumper.dump(_pipeline.get(), "pipeline-with-new-source-pad");
516}
517
518void PipelineSession::_onFirstFrame()
519{
520 if (_streaming) {
521 return;
522 }
523 _streaming = true;
524 qCDebug(GstVideoReceiverLog) << "Streaming started" << _settings.redactedUri;
525 _decoding->onSourceStreaming();
526 _recording->onSourceStreaming();
527 _listener.onSessionStreaming();
528}
529
530void PipelineSession::_logLatency()
531{
532 GstClockTime min = 0, max = 0;
533 (void) PipelineStatsProbe::queryLatency(_pipeline.get(), min, max);
534 qCDebug(GstVideoReceiverLog).noquote()
535 << "Pipeline PLAYING:" << _settings.redactedUri << "min-latency:" << GST_TIME_AS_MSECONDS(min) << "ms"
536 << "max-latency:" << GST_TIME_AS_MSECONDS(max) << "ms";
537}
538
539GstBusSyncReply PipelineSession::_onBusSync(GstMessage* message)
540{
541 // The context bridges answer NEED_CONTEXT synchronously and consume (unref) the requests they handle.
542 if (HwBuffers::onBusSyncMessage(message) == GST_BUS_DROP) {
543 return GST_BUS_DROP;
544 }
545
546 if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_ERROR) {
547 // Closed now, before the failing element returns its flow error: the valve reports OK for a push that fails
548 // after drop was set, which keeps the error out of the tee and so out of the other branch.
549 const GStreamer::PipelineBranch branch = GStreamer::branchOf(GST_MESSAGE_SRC(message));
550 GstElement* const valve = (branch == GStreamer::PipelineBranch::Decoding)
551 ? _displayValve
552 : ((branch == GStreamer::PipelineBranch::Recording) ? _recordingValve : nullptr);
553 if (valve) {
554 g_object_set(valve, "drop", TRUE, nullptr);
555 }
556 }
557 return GST_BUS_PASS;
558}
559
560void PipelineSession::_onSourcePadAdded(GstElement* source, GstPad* pad, gpointer data)
561{
562 auto* const self = static_cast<PipelineSession*>(data);
563
564 // Runs on a streaming thread; the pipeline is only changed on the worker.
565 self->_post(GStreamer::holdPadUntilLinked(pad, [self, padSource = GStreamer::shareObject(source)](GstPad* newPad) {
566 if (padSource.get() == self->_source) {
567 self->_linkSourcePad(newPad);
568 }
569 }));
570}
571
572GstPadProbeReturn PipelineSession::_teeProbe(GstPad* /*pad*/, GstPadProbeInfo* info, gpointer data)
573{
574 auto* const self = static_cast<PipelineSession*>(data);
575 if (GstBuffer* const buffer = GST_PAD_PROBE_INFO_BUFFER(info)) {
576 self->_statsProbe.noteBuffer(buffer);
577 }
578 const quint64 frames = self->_watchdog.noteSourceFrame(StreamWatchdog::now());
579 if (frames == 1) {
580 self->_post([self]() { self->_onFirstFrame(); });
581 } else if ((frames % kSourceFlowLogIntervalFrames) == 0) {
582 qCDebug(GstVideoReceiverLog).noquote() << "Source flow: teeFrames=" << frames << self->_settings.redactedUri;
583 }
584 return GST_PAD_PROBE_OK;
585}
586
587GstPadProbeReturn PipelineSession::_sourceEosProbe(GstPad* /*pad*/, GstPadProbeInfo* info, gpointer data)
588{
589 const GstEvent* const event = gst_pad_probe_info_get_event(info);
590 if (event && (GST_EVENT_TYPE(event) == GST_EVENT_EOS)) {
591 auto* const self = static_cast<PipelineSession*>(data);
592 self->_post([self]() {
593 self->_fail({.reason = QStringLiteral("end of stream"),
594 .message = tr("The video stream ended."),
595 .permanent = false});
596 });
597 }
598 return GST_PAD_PROBE_OK;
599}
struct _GstElement GstElement
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
~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)
static void noteElementMessage(GstMessage *message)
static bool queryLatency(GstElement *pipeline, GstClockTime &min, GstClockTime &max)
The latency pipeline reports; false when it doesn't answer the latency query.
static constexpr std::chrono::seconds kFinalizeTimeout
static qint64 now()
GstElement * create(const QString &uri, const Config &config)
@ None
No playout buffering; omits an explicit buffer or sets rtspsrc latency to zero.
@ DropOnLatency
rtpjitterbuffer with drop-on-latency=TRUE.
GstPadPtr firstSrcPad(GstElement *element)
element's first src pad, or null when it has none (yet).
GCharPtr adoptGChar(gchar *str) noexcept
Definition GstScoped.h:134
std::function< void()> holdPadUntilLinked(GstPad *pad, std::function< void(GstPad *pad)> link)
GstElementPtr makeElement(const char *factory, const char *name=nullptr)
Definition GstScoped.h:178
const char * factoryNameOf(GstObject *object)
The name of the factory that made object ("rtph264depay"); null when it is no element or has no facto...
PipelineBranch
The tee branch a pipeline element belongs to, so a bus message can be blamed on the part that failed.
GstElement * addToBin(GstElement *bin, GstElementPtr element, const char *what)
std::unique_ptr< T, GstObjectDeleter > adoptFloating(T *object) noexcept
Sinks the floating ref of a new object (pipeline, bin, pad, element) and owns it. Null for null.
Definition GstScoped.h:171
PipelineBranch branchOf(GstObject *object)
The branch of object's nearest marked ancestor (itself included). Thread-safe.
std::shared_ptr< T > shareObject(T *object)
A copyable owner of a new ref on object, for tasks that must be copyable (std::function).
Definition GstScoped.h:164
MessageError parseMessageError(GstMessage *message)
gst_message_parse_error(), or gst_message_parse_warning() for a WARNING message.
Definition GstScoped.h:152
std::unique_ptr< GstPad, GstObjectDeleter > GstPadPtr
Definition GstScoped.h:61
std::unique_ptr< GstMessage, GstMessageDeleter > GstMessagePtr
Definition GstScoped.h:67
std::unique_ptr< gchar, GFreeDeleter > GCharPtr
Definition GstScoped.h:71
GstPadPtr adoptPad(GstPad *pad) noexcept
Definition GstScoped.h:84
constexpr char kGraphicsDeviceLostMessage[]
Definition HwBuffers.h:27
GstBusSyncReply onBusSyncMessage(GstMessage *msg) noexcept
Definition HwBuffers.cc:59
constexpr char kGraphicsDeviceServedMessage[]
Definition HwBuffers.h:22
What the branch measured for VideoStreamStats.
quint64 framesDisplayed
Since the branch was built: frames the video sink delivered that no newer frame replaced before displ...
quint64 gpuFallbacks
Since the branch was built: frames a GPU path was tried for but the CPU delivered.
quint64 decoderRestarts
Since the branch was built: decoders replaced by restartDecoder().
bool doRetransmission
RTSP only: plain UDP/TCP sources have no RTCP back-channel for NACKs.
Formatted per-path frame counts + the total delivered through GPU paths.
qint64 decoderRestarts
Since the stream started: times the decoder was replaced after an error or a stall.
QString decoder
The decoder's element factory, e.g. "avdec_h264".
qint64 gpuFallbacks
Since the stream started: frames a zero-copy GPU path was tried for but the CPU delivered.