QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QtVideoRecorder.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4
5#include <QtCore/QList>
6#include <QtCore/QObject>
7#include <QtCore/QString>
8#include <QtCore/QStringList>
9#include <QtMultimedia/QMediaFormat>
10#include <QtMultimedia/QMediaRecorder>
11
12#include "VideoReceiver.h"
13
22class QtVideoRecorder : public QObject
23{
24 Q_OBJECT
25
26 friend class QtVideoRecorderTest;
27
28public:
30 static constexpr std::chrono::seconds kFinishTimeout{5};
31
32 explicit QtVideoRecorder(QObject* parent = nullptr);
33 ~QtVideoRecorder() override;
34
35 QMediaRecorder* mediaRecorder() const { return _recorder; }
36
38 bool recording() const { return _recording; }
39
41 bool active() const { return _recorder->recorderState() != QMediaRecorder::StoppedState; }
42
47 void start(const QString& file, QMediaFormat::FileFormat container,
48 QMediaFormat::VideoCodec codec = QMediaFormat::VideoCodec::Unspecified,
49 QMediaRecorder::Quality quality = QMediaRecorder::HighQuality);
50 void stop();
53 void stopAndWait(std::chrono::milliseconds timeout = kFinishTimeout);
54
58 static QList<QMediaFormat> recordingFormats(QMediaFormat::FileFormat container,
59 QMediaFormat::VideoCodec codec = QMediaFormat::VideoCodec::Unspecified);
63 static QStringList recordingCodecs();
65 static QMediaFormat::VideoCodec recordingCodec(const QString& key);
67 static QString recordingCodecName(const QString& key);
69 static QMediaFormat::FileFormat container(VideoReceiver::FileFormat format);
71 static QMediaRecorder::Quality recordingQuality(int value);
72
73signals:
75 void recordingStarted(const QString& file);
77 void recordingFinished(const QString& file, const QString& error);
78
79private:
81 void _recordNextFormat();
83 void _retryNextFormat();
84 void _onRecorderStateChanged(QMediaRecorder::RecorderState state);
85 void _onRecorderError(const QString& errorString);
87 void _onRecordingNotStarted();
88
89 QMediaRecorder* const _recorder;
90 QList<QMediaFormat> _pendingFormats;
91 QMediaRecorder::Quality _quality = QMediaRecorder::HighQuality;
93 QString _recordingBase;
94 QString _recordingFile;
95 QString _recordingError;
96 bool _recording = false;
97 bool _stopRequested = false;
98};
friend class QtVideoRecorderTest
static QList< QMediaFormat > recordingFormats(QMediaFormat::FileFormat container, QMediaFormat::VideoCodec codec=QMediaFormat::VideoCodec::Unspecified)
bool recording() const
From the first encoded frame until the recorder stops.
void recordingChanged(bool recording)
static QMediaFormat::VideoCodec recordingCodec(const QString &key)
The codec of key key, as recordingCodecs() names it; Unspecified for an empty or unknown key.
static QMediaFormat::FileFormat container(VideoReceiver::FileFormat format)
The container of format.
static constexpr std::chrono::seconds kFinishTimeout
How long an owner going away waits for a recording's file to be finished.
void recordingFinished(const QString &file, const QString &error)
error is empty for a recording that finished normally.
QtVideoRecorder(QObject *parent=nullptr)
static QStringList recordingCodecs()
void recordingStarted(const QString &file)
void stopAndWait(std::chrono::milliseconds timeout=kFinishTimeout)
static QMediaRecorder::Quality recordingQuality(int value)
The quality of value value, one of VideoSettings::uvcRecordingQuality's; HighQuality for any other.
static QString recordingCodecName(const QString &key)
The name of the codec of key key, such as "H.264", for display.
void start(const QString &file, QMediaFormat::FileFormat container, QMediaFormat::VideoCodec codec=QMediaFormat::VideoCodec::Unspecified, QMediaRecorder::Quality quality=QMediaRecorder::HighQuality)
~QtVideoRecorder() override
QMediaRecorder * mediaRecorder() const
bool active() const
Recording, or waiting for the first frame to encode.
FileFormat
Values are persisted by VideoSettings::recordingFormat.