#include <VideoReceiver.h>
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. | |
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.
|
strong |
Values are persisted by VideoSettings::recordingFormat.
| Enumerator | |
|---|---|
| Mkv | |
| Mov | |
| Mp4 | |
Definition at line 55 of file VideoReceiver.h.
|
strong |
Definition at line 45 of file VideoReceiver.h.
|
explicit |
Definition at line 16 of file VideoReceiver.cc.
References VideoReceiver().
Referenced by GstVideoReceiver::GstVideoReceiver(), QtMultimediaVideoReceiver::QtMultimediaVideoReceiver(), UVCCameraController::UVCCameraController(), and VideoReceiver().
|
overridedefault |
|
inline |
Definition at line 120 of file VideoReceiver.h.
Referenced by QtMultimediaVideoReceiver::onActiveChanged(), UVCCameraController::onActiveChanged(), and setActive().
|
inline |
Definition at line 116 of file VideoReceiver.h.
Referenced by UVCCameraController::device(), QtMultimediaVideoReceiver::onConfigChanged(), setConfig(), and setDisplayConfig().
|
inline |
Definition at line 128 of file VideoReceiver.h.
Referenced by decodingChanged(), onStopRecording(), and setDecoding().
|
signal |
References decoding().
Referenced by setDecoding(), and VideoStreamController::setReceiver().
|
inline |
Definition at line 118 of file VideoReceiver.h.
|
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.
|
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().
|
static |
"mkv", "mov" or "mp4".
Definition at line 27 of file VideoReceiver.cc.
Referenced by VideoRecordingService::pruneStorage(), and VideoRecordingService::recordingFile().
|
static |
Definition at line 40 of file VideoReceiver.cc.
Referenced by VideoRecordingService::startRecording().
|
inline |
Definition at line 111 of file VideoReceiver.h.
Referenced by QtMultimediaVideoReceiver::onStartRecording(), UVCCameraController::setFormat(), and setName().
|
protectedpure virtual |
Implemented in GstVideoReceiver, QtMultimediaVideoReceiver, and UVCCameraController.
Referenced by setActive().
|
protectedpure virtual |
Implemented in GstVideoReceiver, QtMultimediaVideoReceiver, and UVCCameraController.
Referenced by setConfig().
|
protectedpure virtual |
Implemented in GstVideoReceiver, QtMultimediaVideoReceiver, and UVCCameraController.
Referenced by reconnectNow().
|
protectedpure virtual |
Implemented in GstVideoReceiver, QtMultimediaVideoReceiver, and UVCCameraController.
Referenced by restart().
|
protectedpure virtual |
Implemented in GstVideoReceiver, QtMultimediaVideoReceiver, and UVCCameraController.
Referenced by startRecording().
|
protectedpure virtual |
Implemented in GstVideoReceiver, QtMultimediaVideoReceiver, and UVCCameraController.
References decoding(), recording(), state(), stats(), and Stopped.
Referenced by stopRecording().
|
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().
|
protectedpure virtual |
Also called when the current output is set again.
Implemented in GstVideoReceiver, QtMultimediaVideoReceiver, and UVCCameraController.
Referenced by setVideoOutput().
|
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.
| 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().
|
inline |
Definition at line 130 of file VideoReceiver.h.
Referenced by onStopRecording(), recordingChanged(), and setRecording().
|
signal |
References recording().
Referenced by VideoStreamController::setReceiver(), and setRecording().
|
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().
|
inline |
Definition at line 149 of file VideoReceiver.h.
Referenced by QtMultimediaVideoReceiver::onStartRecording(), and UVCCameraController::onStartRecording().
|
signal |
A recording file closed. error is empty when the file was finalized cleanly.
Referenced by GstVideoReceiver::GstVideoReceiver(), UVCCameraController::onStartRecording(), QtMultimediaVideoReceiver::QtMultimediaVideoReceiver(), VideoStreamController::setReceiver(), and UVCCameraController::UVCCameraController().
|
signal |
A recording file opened: the first one after startRecording(), or the recording's next part.
Referenced by GstVideoReceiver::GstVideoReceiver(), QtMultimediaVideoReceiver::QtMultimediaVideoReceiver(), VideoStreamController::setReceiver(), and UVCCameraController::UVCCameraController().
| 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().
| 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().
| 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().
|
protected |
Definition at line 196 of file VideoReceiver.cc.
References decoding(), and decodingChanged().
|
inline |
Stores config for the display sink restart() builds next.
Definition at line 143 of file VideoReceiver.h.
References config().
| 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().
|
protected |
Definition at line 204 of file VideoReceiver.cc.
References recording(), and recordingChanged().
Referenced by QtMultimediaVideoReceiver::QtMultimediaVideoReceiver(), and UVCCameraController::UVCCameraController().
|
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.
|
protected |
Definition at line 183 of file VideoReceiver.cc.
References state(), stateChanged(), streaming(), and streamingChanged().
Referenced by QtMultimediaVideoReceiver::QtMultimediaVideoReceiver().
|
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().
| 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().
|
protected |
Definition at line 212 of file VideoReceiver.cc.
References videoSizeChanged().
|
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().
| 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().
|
inline |
Definition at line 124 of file VideoReceiver.h.
Referenced by onStopRecording(), QtMultimediaVideoReceiver::QtMultimediaVideoReceiver(), setState(), and stateChanged().
|
signal |
References state().
Referenced by VideoStreamController::setReceiver(), and setState().
|
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().
|
signal |
References stats().
Referenced by VideoStreamController::setReceiver(), and setStats().
| void VideoReceiver::stopRecording | ( | ) |
Definition at line 137 of file VideoReceiver.cc.
References onStopRecording().
|
inline |
Definition at line 126 of file VideoReceiver.h.
References Streaming.
Referenced by setState(), and streamingChanged().
|
signal |
References streaming().
Referenced by setState().
| 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().
| QQuickItem * VideoReceiver::videoOutput | ( | ) | const |
Definition at line 95 of file VideoReceiver.cc.
Referenced by GstVideoReceiver::onVideoOutputChanged(), UVCCameraController::onVideoOutputChanged(), UVCCameraController::registerVideoOutput(), setVideoOutput(), and UVCCameraController::unregisterVideoOutput().
|
protected |
The VideoOutput's QVideoSink, or nullptr.
Definition at line 178 of file VideoReceiver.cc.
Referenced by GstVideoReceiver::GstVideoReceiverTestBase, GstVideoReceiver::onRestartRequested(), onTakeScreenshot(), GstVideoReceiver::onVideoOutputChanged(), QtMultimediaVideoReceiver::onVideoOutputChanged(), and takeScreenshot().
|
inline |
The size of the frames as they are presented, before the orientation the VideoOutput adds.
Definition at line 133 of file VideoReceiver.h.
|
signal |
Referenced by VideoStreamController::setReceiver(), and setVideoSize().