3#include <QtConcurrent/QtConcurrentRun>
4#include <QtCore/QCoreApplication>
5#include <QtCore/QFileInfo>
7#include <QtMultimedia/QVideoFrame>
8#include <QtMultimedia/QVideoSink>
9#include <QtQuick/QQuickItem>
24 return QStringLiteral(
"%1 %2").arg(QCoreApplication::applicationName(), QCoreApplication::applicationVersion());
31 return QStringLiteral(
"mkv");
33 return QStringLiteral(
"mov");
35 return QStringLiteral(
"mp4");
37 return QStringLiteral(
"mkv");
47 if (!frame.isValid()) {
50 const QVideoFrameFormat format = frame.surfaceFormat();
51 const QRect viewport = format.viewport();
52 const QSize size = pictureSize.isValid() ? pictureSize : (viewport.isValid() ? viewport.size() : frame.size());
54 const int degrees =
static_cast<int>(frame.rotation()) +
static_cast<int>(format.rotation());
55 return ((degrees % 180) != 0) ? size.transposed() : size;
106 (void) disconnect(_videoOutputDestroyed);
109 _videoOutputDestroyed =
110 connect(
videoOutput, &QObject::destroyed,
this, &VideoReceiver::_onVideoOutputDestroyed);
116void VideoReceiver::_onVideoOutputDestroyed()
118 _videoOutput =
nullptr;
125 qCWarning(VideoReceiverLog) <<
"Not recording" << _name <<
"- the stream is not active";
126 emit
errorOccurred(tr(
"Unable to record video: the video stream is not active."));
129 if (file.isEmpty()) {
130 qCWarning(VideoReceiverLog) <<
"Not recording" << _name <<
"- no file name";
131 emit
errorOccurred(tr(
"Unable to record video: no file name."));
150 qCWarning(VideoReceiverLog) <<
"No video output to take a screenshot from" << _name;
159 const int orientation = _videoOutput->property(
"orientation").toInt() % 360;
160 const auto outputRotation =
static_cast<QtVideo::Rotation
>((orientation < 0) ? (orientation + 360) : orientation);
161 const bool outputMirrored = _videoOutput->property(
"mirrored").toBool();
164 if (image.isNull()) {
165 qCWarning(VideoReceiverLog) <<
"No video frame to take a screenshot from" << _name;
168 (void) QtConcurrent::run([image, file, exif] {
170 }).then(
this, [
this, file](
bool saved) {
172 emit
errorOccurred(tr(
"Unable to save the photo %1.").arg(QFileInfo(file).fileName()));
180 return _videoOutput ? _videoOutput->property(
"videoSink").value<QVideoSink*>() :
nullptr;
185 if (
state == _state) {
214 if (size != _videoSize) {
222 if (
stats != _stats) {
#define QGC_LOGGING_CATEGORY(name, categoryStr)
void statsChanged(const VideoStreamStats &stats)
void setVideoSize(QSize size)
void setName(const QString &name)
Names the stream in logs and pipeline dumps. Call once, before the first setActive(true).
QQuickItem * videoOutput() const
void videoSizeChanged(QSize size)
virtual void onStopRecording()=0
void recordingChanged(bool recording)
virtual void onVideoOutputChanged()=0
Also called when the current output is set again.
void setConfig(const Config &config)
void startRecording(const QString &file, FileFormat format)
void setVideoOutput(QQuickItem *videoOutput)
VideoReceiver(QObject *parent=nullptr)
virtual void onStartRecording(const QString &file, FileFormat format)=0
void stateChanged(VideoReceiver::State state)
void streamingChanged(bool streaming)
void setStats(const VideoStreamStats &stats)
Backends publish a new measurement, and an invalid one once the stream stops or reconnects.
QVideoSink * videoSink() const
The VideoOutput's QVideoSink, or nullptr.
virtual void onActiveChanged()=0
static QSize presentedSize(const QVideoFrame &frame, QSize pictureSize={})
FileFormat
Values are persisted by VideoSettings::recordingFormat.
void setActive(bool active)
Streams while true and the URI is set. False stops the stream, any pending reconnect and any recordin...
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)
virtual void onConfigChanged()=0
void setDecoding(bool decoding)
void decodingChanged(bool decoding)
void setRecording(bool recording)
bool takeScreenshot(const QString &file, const VideoScreenshot::Exif &exif={})
void setState(State state)
static QString fileExtension(FileFormat format)
"mkv", "mov" or "mp4".
VideoStreamStats stats() const
The stream's health, measured about once a second while it streams; invalid while it doesn't.
virtual void onReconnectRequested()=0
const Config & config() const
~VideoReceiver() override
void errorOccurred(const QString &message)
virtual void onRestartRequested()=0
virtual bool onTakeScreenshot(const QString &file, const VideoScreenshot::Exif &exif)
takeScreenshot() with an output set: saves the frame on display, unless overridden.
bool saveImage(const QImage &image, const QString &file, const Exif &exif={})
QImage displayedImage(const QVideoFrame &frame, QtVideo::Rotation outputRotation=QtVideo::Rotation::None, bool outputMirrored=false)