QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
VideoReceiver Class Referenceabstract

#include <VideoReceiver.h>

Inheritance diagram for VideoReceiver:
Collaboration diagram for VideoReceiver:

Classes

struct  Config
struct  DisplayConfig
 How the display sink presents frames. Construct-only: a change applies when restart() rebuilds the sink. More...
struct  RecordingEncoding

Public Types

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

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)

Public Member Functions

 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 Member Functions

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={})

Protected Member Functions

virtual void onConfigChanged ()=0
virtual void onActiveChanged ()=0
virtual void onRestartRequested ()=0
virtual void onReconnectRequested ()=0
virtual void onVideoOutputChanged ()=0
 Also called when the current output is set again.
virtual void onStartRecording (const QString &file, FileFormat format)=0
virtual void onStopRecording ()=0
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.

Detailed Description

One video source: a network stream, which a backend's receiver connects to at the config's URI, or a local camera (UVCCameraController), which the URI names. Shows it in a QML VideoOutput, records it and takes its screenshots.

Intent-based: callers state what they want (setConfig(), setActive(), setVideoOutput(), startRecording()) and the receiver gets there on its own, restarting after a config change and reconnecting after a failure. Call every method on the GUI thread; every signal is emitted there.

Backends implement the protected on*() hooks, which run after the base stored the new value, and publish their state through the protected setters.

Definition at line 31 of file VideoReceiver.h.

Member Enumeration Documentation

◆ FileFormat

enum class VideoReceiver::FileFormat : uint8_t
strong

Values are persisted by VideoSettings::recordingFormat.

Enumerator
Mkv 
Mov 
Mp4 

Definition at line 55 of file VideoReceiver.h.

◆ State

enum class VideoReceiver::State : uint8_t
strong
Enumerator
Stopped 

Inactive, no URI, or given up after a failure (autoReconnect off).

Connecting 

Pipeline running, no data yet.

Streaming 

Data is arriving.

Reconnecting 

Waiting out the backoff after a failure.

Definition at line 45 of file VideoReceiver.h.

Constructor & Destructor Documentation

◆ VideoReceiver()

VideoReceiver::VideoReceiver ( QObject * parent = nullptr)
explicit

◆ ~VideoReceiver()

VideoReceiver::~VideoReceiver ( )
overridedefault

Member Function Documentation

◆ active()

bool VideoReceiver::active ( ) const
inline

◆ config()

const Config & VideoReceiver::config ( ) const
inline

◆ decoding()

bool VideoReceiver::decoding ( ) const
inline

Definition at line 128 of file VideoReceiver.h.

Referenced by decodingChanged(), onStopRecording(), and setDecoding().

◆ decodingChanged

void VideoReceiver::decodingChanged ( bool decoding)
signal

◆ displayConfig()

const DisplayConfig & VideoReceiver::displayConfig ( ) const
inline

Definition at line 118 of file VideoReceiver.h.

◆ encodesRecordings()

virtual bool VideoReceiver::encodesRecordings ( ) const
inlinevirtual

True for a receiver that encodes its recordings anew, as recordingEncoding() says: a USB camera, or Qt Multimedia's player. False for one that records the stream as it arrives.

Reimplemented in QtMultimediaVideoReceiver, and UVCCameraController.

Definition at line 147 of file VideoReceiver.h.

◆ errorOccurred

void VideoReceiver::errorOccurred ( const QString & message)
signal

A failure worth telling the user about (stream error with autoReconnect off, recording error, a screenshot that couldn't be saved). Not emitted for failures the receiver recovers from by reconnecting.

Referenced by GstVideoReceiver::GstVideoReceiver(), onTakeScreenshot(), VideoStreamController::setReceiver(), and startRecording().

◆ fileExtension()

QString VideoReceiver::fileExtension ( FileFormat format)
static

"mkv", "mov" or "mp4".

Definition at line 27 of file VideoReceiver.cc.

References Mkv, Mov, and Mp4.

Referenced by VideoRecordingService::pruneStorage(), and VideoRecordingService::recordingFile().

◆ isValidFileFormat()

bool VideoReceiver::isValidFileFormat ( int format)
static

Definition at line 40 of file VideoReceiver.cc.

References Mkv, and Mp4.

Referenced by VideoRecordingService::startRecording().

◆ name()

QString VideoReceiver::name ( ) const
inline

◆ onActiveChanged()

virtual void VideoReceiver::onActiveChanged ( )
protectedpure virtual

◆ onConfigChanged()

virtual void VideoReceiver::onConfigChanged ( )
protectedpure virtual

◆ onReconnectRequested()

virtual void VideoReceiver::onReconnectRequested ( )
protectedpure virtual

◆ onRestartRequested()

virtual void VideoReceiver::onRestartRequested ( )
protectedpure virtual

◆ onStartRecording()

virtual void VideoReceiver::onStartRecording ( const QString & file,
FileFormat format )
protectedpure virtual

◆ onStopRecording()

virtual void VideoReceiver::onStopRecording ( )
protectedpure virtual

◆ onTakeScreenshot()

bool VideoReceiver::onTakeScreenshot ( const QString & file,
const VideoScreenshot::Exif & exif )
protectedvirtual

takeScreenshot() with an output set: saves the frame on display, unless overridden.

Reimplemented in UVCCameraController.

Definition at line 156 of file VideoReceiver.cc.

References VideoScreenshot::displayedImage(), errorOccurred(), VideoScreenshot::saveImage(), and videoSink().

Referenced by UVCCameraController::onTakeScreenshot(), and takeScreenshot().

◆ onVideoOutputChanged()

virtual void VideoReceiver::onVideoOutputChanged ( )
protectedpure virtual

Also called when the current output is set again.

Implemented in GstVideoReceiver, QtMultimediaVideoReceiver, and UVCCameraController.

Referenced by setVideoOutput().

◆ presentedSize()

QSize VideoReceiver::presentedSize ( const QVideoFrame & frame,
QSize pictureSize = {} )
static

The size frame is presented at: its format's viewport (the picture without decoder padding or crop), else the whole frame, turned by the rotation Qt presents it with. Invalid for an invalid frame. A valid pictureSize stands in for the viewport's, which is smaller where it leaves out the padding of a squeezed texture.

Definition at line 45 of file VideoReceiver.cc.

◆ reconnectNow()

void VideoReceiver::reconnectNow ( )

Connects again now when the stream is waiting out a reconnect backoff, and starts the backoff over: for when the stream's source is likely back, as when its vehicle's link returned. Nothing otherwise.

Definition at line 88 of file VideoReceiver.cc.

References onReconnectRequested().

◆ recording()

bool VideoReceiver::recording ( ) const
inline

Definition at line 130 of file VideoReceiver.h.

Referenced by onStopRecording(), recordingChanged(), and setRecording().

◆ recordingChanged

void VideoReceiver::recordingChanged ( bool recording)
signal

◆ recordingComment()

QString VideoReceiver::recordingComment ( )
static

The comment recordings carry, of GStreamer and of a USB camera alike: the application and its version.

Definition at line 22 of file VideoReceiver.cc.

Referenced by RecordingBranch::makeFileSink().

◆ recordingEncoding()

const RecordingEncoding & VideoReceiver::recordingEncoding ( ) const
inline

◆ recordingFinished

void VideoReceiver::recordingFinished ( const QString & file,
const QString & error )
signal

◆ recordingStarted

void VideoReceiver::recordingStarted ( const QString & file)
signal

◆ restart()

void VideoReceiver::restart ( )

Tears the stream down and connects again now, skipping any reconnect backoff, and rebuilds the display sink so construct-only sink settings apply. No-op while inactive.

Definition at line 81 of file VideoReceiver.cc.

References onRestartRequested().

Referenced by GstVideoReceiver::GstVideoReceiver().

◆ setActive()

void VideoReceiver::setActive ( bool active)

Streams while true and the URI is set. False stops the stream, any pending reconnect and any recording.

Definition at line 72 of file VideoReceiver.cc.

References active(), and onActiveChanged().

Referenced by shutDown().

◆ setConfig()

void VideoReceiver::setConfig ( const Config & config)

Stores config. While active, a change to anything but autoReconnect restarts the stream; an empty URI stops it until a URI is set again.

Definition at line 63 of file VideoReceiver.cc.

References config(), and onConfigChanged().

◆ setDecoding()

void VideoReceiver::setDecoding ( bool decoding)
protected

Definition at line 196 of file VideoReceiver.cc.

References decoding(), and decodingChanged().

◆ setDisplayConfig()

void VideoReceiver::setDisplayConfig ( const DisplayConfig & config)
inline

Stores config for the display sink restart() builds next.

Definition at line 143 of file VideoReceiver.h.

References config().

◆ setName()

void VideoReceiver::setName ( const QString & name)

Names the stream in logs and pipeline dumps. Call once, before the first setActive(true).

Definition at line 58 of file VideoReceiver.cc.

References name().

◆ setRecording()

void VideoReceiver::setRecording ( bool recording)
protected

◆ setRecordingEncoding()

void VideoReceiver::setRecordingEncoding ( const RecordingEncoding & encoding)
inline

Stores encoding for the recordings that start from now on; one in progress keeps its own.

Definition at line 152 of file VideoReceiver.h.

◆ setState()

void VideoReceiver::setState ( State state)
protected

◆ setStats()

void VideoReceiver::setStats ( const VideoStreamStats & stats)
protected

Backends publish a new measurement, and an invalid one once the stream stops or reconnects.

Definition at line 220 of file VideoReceiver.cc.

References stats(), and statsChanged().

Referenced by UVCCameraController::UVCCameraController().

◆ setVideoOutput()

void VideoReceiver::setVideoOutput ( QQuickItem * videoOutput)

Displays the stream in videoOutput, a QML VideoOutput; nullptr stops displaying. Decoding runs only while an output is set. Setting the current output again binds it anew, for one that moved to another window. The output's destruction is tracked: it detaches as if nullptr had been set.

Definition at line 100 of file VideoReceiver.cc.

References onVideoOutputChanged(), and videoOutput().

Referenced by UVCCameraController::registerVideoOutput(), and UVCCameraController::unregisterVideoOutput().

◆ setVideoSize()

void VideoReceiver::setVideoSize ( QSize size)
protected

Definition at line 212 of file VideoReceiver.cc.

References videoSizeChanged().

◆ shutDown()

void VideoReceiver::shutDown ( )
virtual

setActive(false) for a receiver that outlives its use, before the application goes away: once it has finished what the exit would cut short.

Reimplemented in UVCCameraController.

Definition at line 142 of file VideoReceiver.cc.

References setActive().

Referenced by UVCCameraController::shutDown().

◆ startRecording()

void VideoReceiver::startRecording ( const QString & file,
FileFormat format )

Records to file until stopRecording() or setActive(false). Accepted only while active (otherwise errorOccurred()); the file opens once streaming, at the next keyframe for a receiver that records the stream as it arrives. Such a receiver continues the recording after a reconnect, and after each hour, into "<base>_part<N>.<ext>", N counting from 2; one that encodes the frames anew, as recordingEncoding() says, keeps to the same file.

Definition at line 122 of file VideoReceiver.cc.

References errorOccurred(), and onStartRecording().

◆ state()

State VideoReceiver::state ( ) const
inline

◆ stateChanged

void VideoReceiver::stateChanged ( VideoReceiver::State state)
signal

References state().

Referenced by VideoStreamController::setReceiver(), and setState().

◆ stats()

VideoStreamStats VideoReceiver::stats ( ) const
inline

The stream's health, measured about once a second while it streams; invalid while it doesn't.

Definition at line 136 of file VideoReceiver.h.

Referenced by onStopRecording(), setStats(), and statsChanged().

◆ statsChanged

void VideoReceiver::statsChanged ( const VideoStreamStats & stats)
signal

References stats().

Referenced by VideoStreamController::setReceiver(), and setStats().

◆ stopRecording()

void VideoReceiver::stopRecording ( )

Definition at line 137 of file VideoReceiver.cc.

References onStopRecording().

◆ streaming()

bool VideoReceiver::streaming ( ) const
inline

Definition at line 126 of file VideoReceiver.h.

References Streaming.

Referenced by setState(), and streamingChanged().

◆ streamingChanged

void VideoReceiver::streamingChanged ( bool streaming)
signal

References streaming().

Referenced by setState().

◆ takeScreenshot()

bool VideoReceiver::takeScreenshot ( const QString & file,
const VideoScreenshot::Exif & exif = {} )

Saves the frame on display to file as shown: cropped to its format's viewport, rotated and mirrored as the frame and then the VideoOutput (its orientation and mirrored properties) say, with exif for a JPEG. The frame is converted here; it is encoded and written on the thread pool. Returns false, with a warning logged, when there is no output or no frame. A file that can't be written is reported later, through errorOccurred(). A receiver that takes photos saves one instead: see onTakeScreenshot().

Definition at line 147 of file VideoReceiver.cc.

References onTakeScreenshot(), and videoSink().

◆ videoOutput()

◆ videoSink()

QVideoSink * VideoReceiver::videoSink ( ) const
protected

◆ videoSize()

QSize VideoReceiver::videoSize ( ) const
inline

The size of the frames as they are presented, before the orientation the VideoOutput adds.

Definition at line 133 of file VideoReceiver.h.

◆ videoSizeChanged

void VideoReceiver::videoSizeChanged ( QSize size)
signal

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