1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QMediaRecorder_H
5#define QMediaRecorder_H
6
7#include <QtCore/qobject.h>
8#include <QtCore/qsize.h>
9#include <QtMultimedia/qtmultimediaglobal.h>
10#include <QtMultimedia/qmediaenumdebug.h>
11#include <QtMultimedia/qmediametadata.h>
12
13#include <QtCore/qpair.h>
14
15QT_BEGIN_NAMESPACE
16
17class QUrl;
18class QSize;
19class QAudioFormat;
20class QCamera;
21class QCameraDevice;
22class QMediaFormat;
23class QAudioDevice;
24class QMediaCaptureSession;
25class QPlatformMediaRecorder;
26
27class QMediaRecorderPrivate;
28class Q_MULTIMEDIA_EXPORT QMediaRecorder : public QObject
29{
30 Q_OBJECT
31 Q_PROPERTY(QMediaRecorder::RecorderState recorderState READ recorderState NOTIFY recorderStateChanged)
32 Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged)
33 Q_PROPERTY(QUrl outputLocation READ outputLocation WRITE setOutputLocation)
34 Q_PROPERTY(QUrl actualLocation READ actualLocation NOTIFY actualLocationChanged)
35 Q_PROPERTY(QMediaMetaData metaData READ metaData WRITE setMetaData NOTIFY metaDataChanged)
36 Q_PROPERTY(QMediaRecorder::Error error READ error NOTIFY errorChanged)
37 Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged)
38 Q_PROPERTY(QMediaFormat mediaFormat READ mediaFormat WRITE setMediaFormat NOTIFY mediaFormatChanged)
39 Q_PROPERTY(Quality quality READ quality WRITE setQuality NOTIFY qualityChanged)
40 Q_PROPERTY(QMediaRecorder::EncodingMode encodingMode READ encodingMode WRITE setEncodingMode NOTIFY encodingModeChanged)
41 Q_PROPERTY(QSize videoResolution READ videoResolution WRITE setVideoResolution NOTIFY videoResolutionChanged)
42 Q_PROPERTY(qreal videoFrameRate READ videoFrameRate WRITE setVideoFrameRate NOTIFY videoFrameRateChanged)
43 Q_PROPERTY(int videoBitRate READ videoBitRate WRITE setVideoBitRate NOTIFY videoBitRateChanged)
44 Q_PROPERTY(int audioBitRate READ audioBitRate WRITE setAudioBitRate NOTIFY audioBitRateChanged)
45 Q_PROPERTY(int audioChannelCount READ audioChannelCount WRITE setAudioChannelCount NOTIFY audioChannelCountChanged)
46 Q_PROPERTY(int audioSampleRate READ audioSampleRate WRITE setAudioSampleRate NOTIFY audioSampleRateChanged)
47public:
48 enum Quality
49 {
50 VeryLowQuality,
51 LowQuality,
52 NormalQuality,
53 HighQuality,
54 VeryHighQuality
55 };
56 Q_ENUM(Quality)
57
58 enum EncodingMode
59 {
60 ConstantQualityEncoding,
61 ConstantBitRateEncoding,
62 AverageBitRateEncoding,
63 TwoPassEncoding
64 };
65 Q_ENUM(EncodingMode)
66
67 enum RecorderState
68 {
69 StoppedState,
70 RecordingState,
71 PausedState
72 };
73 Q_ENUM(RecorderState)
74
75 enum Error
76 {
77 NoError,
78 ResourceError,
79 FormatError,
80 OutOfSpaceError,
81 LocationNotWritable
82 };
83 Q_ENUM(Error)
84
85 QMediaRecorder(QObject *parent = nullptr);
86 ~QMediaRecorder();
87
88 bool isAvailable() const;
89
90 QUrl outputLocation() const;
91 void setOutputLocation(const QUrl &location);
92
93 QUrl actualLocation() const;
94
95 RecorderState recorderState() const;
96
97 Error error() const;
98 QString errorString() const;
99
100 qint64 duration() const;
101
102 QMediaFormat mediaFormat() const;
103 void setMediaFormat(const QMediaFormat &format);
104
105 EncodingMode encodingMode() const;
106 void setEncodingMode(EncodingMode);
107
108 Quality quality() const;
109 void setQuality(Quality quality);
110
111 QSize videoResolution() const;
112 void setVideoResolution(const QSize &);
113 void setVideoResolution(int width, int height) { setVideoResolution(QSize(width, height)); }
114
115 qreal videoFrameRate() const;
116 void setVideoFrameRate(qreal frameRate);
117
118 int videoBitRate() const;
119 void setVideoBitRate(int bitRate);
120
121 int audioBitRate() const;
122 void setAudioBitRate(int bitRate);
123
124 int audioChannelCount() const;
125 void setAudioChannelCount(int channels);
126
127 int audioSampleRate() const;
128 void setAudioSampleRate(int sampleRate);
129
130 QMediaMetaData metaData() const;
131 void setMetaData(const QMediaMetaData &metaData);
132 void addMetaData(const QMediaMetaData &metaData);
133
134 QMediaCaptureSession *captureSession() const;
135 QPlatformMediaRecorder *platformRecoder() const;
136
137public Q_SLOTS:
138 void record();
139 void pause();
140 void stop();
141
142Q_SIGNALS:
143 void recorderStateChanged(RecorderState state);
144 void durationChanged(qint64 duration);
145 void actualLocationChanged(const QUrl &location);
146 void encoderSettingsChanged();
147
148 void errorOccurred(Error error, const QString &errorString);
149 void errorChanged();
150
151 void metaDataChanged();
152
153 void mediaFormatChanged();
154 void encodingModeChanged();
155 void qualityChanged();
156 void videoResolutionChanged();
157 void videoFrameRateChanged();
158 void videoBitRateChanged();
159 void audioBitRateChanged();
160 void audioChannelCountChanged();
161 void audioSampleRateChanged();
162
163private:
164 QMediaRecorderPrivate *d_ptr;
165 friend class QMediaCaptureSession;
166 void setCaptureSession(QMediaCaptureSession *session);
167 Q_DISABLE_COPY(QMediaRecorder)
168 Q_DECLARE_PRIVATE(QMediaRecorder)
169};
170
171QT_END_NAMESPACE
172
173Q_MEDIA_ENUM_DEBUG(QMediaRecorder, RecorderState)
174Q_MEDIA_ENUM_DEBUG(QMediaRecorder, Error)
175
176#endif // QMediaRecorder_H
177

source code of qtmultimedia/src/multimedia/recording/qmediarecorder.h