QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GstVideoReceiver Class Reference

Also logs the receiver's worker, its PipelineSession with the branches, and PipelineDotDumper. More...

#include <GstVideoReceiver.h>

Inheritance diagram for GstVideoReceiver:
Collaboration diagram for GstVideoReceiver:

Public Member Functions

 GstVideoReceiver (QObject *parent=nullptr)
 ~GstVideoReceiver () override
 Finalizes a recording and stops the pipeline, waiting at most a few seconds for the worker.
QString decoderName () const
void setHeartbeatInterval (std::chrono::milliseconds interval)
Public Member Functions inherited from VideoReceiver
 VideoReceiver (QObject *parent=nullptr)
 ~VideoReceiver () override
QString name () const
void setName (const QString &name)
 Names the stream in logs and pipeline dumps. Call once, before the first setActive(true).
const Config & config () const
const DisplayConfig & displayConfig () const
bool active () const
QQuickItem * videoOutput () const
State state () const
bool streaming () const
bool decoding () const
bool recording () const
QSize videoSize () const
 The size of the frames as they are presented, before the orientation the VideoOutput adds.
VideoStreamStats stats () const
 The stream's health, measured about once a second while it streams; invalid while it doesn't.
void setConfig (const Config &config)
void setDisplayConfig (const DisplayConfig &config)
 Stores config for the display sink restart() builds next.
virtual bool encodesRecordings () const
const RecordingEncoding & recordingEncoding () const
void setRecordingEncoding (const RecordingEncoding &encoding)
 Stores encoding for the recordings that start from now on; one in progress keeps its own.
void setActive (bool active)
 Streams while true and the URI is set. False stops the stream, any pending reconnect and any recording.
virtual void shutDown ()
void restart ()
void reconnectNow ()
void setVideoOutput (QQuickItem *videoOutput)
void startRecording (const QString &file, FileFormat format)
void stopRecording ()
bool takeScreenshot (const QString &file, const VideoScreenshot::Exif &exif={})

Static Public Attributes

static constexpr std::chrono::seconds kHeartbeatInterval {10}

Protected Member Functions

void onConfigChanged () override
void onActiveChanged () override
void onRestartRequested () override
void onReconnectRequested () override
void onVideoOutputChanged () override
 Also called when the current output is set again.
void onStartRecording (const QString &file, FileFormat format) override
void onStopRecording () override
Protected Member Functions inherited from VideoReceiver
virtual bool onTakeScreenshot (const QString &file, const VideoScreenshot::Exif &exif)
 takeScreenshot() with an output set: saves the frame on display, unless overridden.
QVideoSink * videoSink () const
 The VideoOutput's QVideoSink, or nullptr.
void setState (State state)
void setDecoding (bool decoding)
void setRecording (bool recording)
void setVideoSize (QSize size)
void setStats (const VideoStreamStats &stats)
 Backends publish a new measurement, and an invalid one once the stream stops or reconnects.

Friends

class GstVideoReceiverTestBase

Additional Inherited Members

Public Types inherited from VideoReceiver
enum class  State : uint8_t { Stopped , Connecting , Streaming , Reconnecting }
enum class  FileFormat : uint8_t { Mkv = 0 , Mov = 1 , Mp4 = 2 }
 Values are persisted by VideoSettings::recordingFormat. More...
Signals inherited from VideoReceiver
void stateChanged (VideoReceiver::State state)
void streamingChanged (bool streaming)
void decodingChanged (bool decoding)
void recordingChanged (bool recording)
void recordingStarted (const QString &file)
 A recording file opened: the first one after startRecording(), or the recording's next part.
void recordingFinished (const QString &file, const QString &error)
 A recording file closed. error is empty when the file was finalized cleanly.
void videoSizeChanged (QSize size)
void statsChanged (const VideoStreamStats &stats)
void errorOccurred (const QString &message)
Static Public Member Functions inherited from VideoReceiver
static QString fileExtension (FileFormat format)
 "mkv", "mov" or "mp4".
static QString recordingComment ()
 The comment recordings carry, of GStreamer and of a USB camera alike: the application and its version.
static bool isValidFileFormat (int format)
static QSize presentedSize (const QVideoFrame &frame, QSize pictureSize={})

Detailed Description

Also logs the receiver's worker, its PipelineSession with the branches, and PipelineDotDumper.

The GStreamer VideoReceiver.

This GUI-thread facade owns the display sink, built from VideoSettings once there is an output to show and rebuilt by restart(), and binds it to the output's QVideoSink through a QGCQVideoSinkController. After every request it hands the whole GstReceiverRequest to a GstReceiverWorker on a thread of its own, which runs the pipeline (one PipelineSession per connection) and steers it towards what was asked for: reconnecting with backoff, replacing a failed decoder, resuming a recording in a new part. The worker reports its GstReceiverStatus and events back through queued signals, so every signal is emitted on the GUI thread.

A worker that waits for a streaming thread that never returns (a decoder deadlocked in its library, a recorder stuck in the kernel) serves no request any more, and nothing can stop its pipeline. The receiver notices that the worker runs none of the tasks it posts to it, which are its requests and, between them, a heartbeat: it then tells the user, once, through errorOccurred(), and reports State::Stopped without decoding unless frames still reach the output. It follows the worker again when that runs a task after all.

Definition at line 37 of file GstVideoReceiver.h.

Constructor & Destructor Documentation

◆ GstVideoReceiver()

◆ ~GstVideoReceiver()

GstVideoReceiver::~GstVideoReceiver ( )
override

Finalizes a recording and stops the pipeline, waiting at most a few seconds for the worker.

Definition at line 61 of file GstVideoReceiver.cc.

References GstReceiverWorker::shutdown().

Member Function Documentation

◆ decoderName()

QString GstVideoReceiver::decoderName ( ) const
inline

Factory name of the decoder decodebin3 plugged last; empty while the stream has no decoder: before it streams, without a video output, and while a decoder is being replaced. For tests.

Definition at line 53 of file GstVideoReceiver.h.

◆ onActiveChanged()

void GstVideoReceiver::onActiveChanged ( )
overrideprotectedvirtual

Implements VideoReceiver.

Definition at line 92 of file GstVideoReceiver.cc.

◆ onConfigChanged()

void GstVideoReceiver::onConfigChanged ( )
overrideprotectedvirtual

Implements VideoReceiver.

Definition at line 87 of file GstVideoReceiver.cc.

◆ onReconnectRequested()

void GstVideoReceiver::onReconnectRequested ( )
overrideprotectedvirtual

Implements VideoReceiver.

Definition at line 108 of file GstVideoReceiver.cc.

◆ onRestartRequested()

void GstVideoReceiver::onRestartRequested ( )
overrideprotectedvirtual

Implements VideoReceiver.

Definition at line 97 of file GstVideoReceiver.cc.

References VideoReceiver::videoSink().

◆ onStartRecording()

void GstVideoReceiver::onStartRecording ( const QString & file,
FileFormat format )
overrideprotectedvirtual

Implements VideoReceiver.

Definition at line 133 of file GstVideoReceiver.cc.

◆ onStopRecording()

void GstVideoReceiver::onStopRecording ( )
overrideprotectedvirtual

Implements VideoReceiver.

Definition at line 140 of file GstVideoReceiver.cc.

◆ onVideoOutputChanged()

void GstVideoReceiver::onVideoOutputChanged ( )
overrideprotectedvirtual

Also called when the current output is set again.

Implements VideoReceiver.

Definition at line 114 of file GstVideoReceiver.cc.

References VideoReceiver::videoOutput(), and VideoReceiver::videoSink().

◆ setHeartbeatInterval()

void GstVideoReceiver::setHeartbeatInterval ( std::chrono::milliseconds interval)

Checks the worker every interval from now on, instead of kHeartbeatInterval. For tests, which can't wait that long.

Definition at line 82 of file GstVideoReceiver.cc.

◆ GstVideoReceiverTestBase

friend class GstVideoReceiverTestBase
friend

Definition at line 69 of file GstVideoReceiver.h.

References GstVideoReceiverTestBase, and VideoReceiver::videoSink().

Referenced by GstVideoReceiverTestBase.

Member Data Documentation

◆ kHeartbeatInterval

std::chrono::seconds GstVideoReceiver::kHeartbeatInterval {10}
staticconstexpr

How often the receiver checks that its worker runs what it is posted, and posts it a heartbeat when that is nothing else.

Definition at line 45 of file GstVideoReceiver.h.

Referenced by GstVideoReceiver().


The documentation for this class was generated from the following files: