1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QMEDIARECORDER_H |
41 | #define QMEDIARECORDER_H |
42 | |
43 | #include <QtMultimedia/qmultimedia.h> |
44 | #include <QtMultimedia/qmediaobject.h> |
45 | #include <QtMultimedia/qmediaencodersettings.h> |
46 | #include <QtMultimedia/qmediabindableinterface.h> |
47 | #include <QtMultimedia/qmediaenumdebug.h> |
48 | |
49 | #include <QtCore/qpair.h> |
50 | |
51 | QT_BEGIN_NAMESPACE |
52 | |
53 | class QUrl; |
54 | class QSize; |
55 | class QAudioFormat; |
56 | QT_END_NAMESPACE |
57 | |
58 | QT_BEGIN_NAMESPACE |
59 | |
60 | class QMediaRecorderService; |
61 | class QAudioEncoderSettings; |
62 | class QVideoEncoderSettings; |
63 | |
64 | class QMediaRecorderPrivate; |
65 | class Q_MULTIMEDIA_EXPORT QMediaRecorder : public QObject, public QMediaBindableInterface |
66 | { |
67 | Q_OBJECT |
68 | Q_INTERFACES(QMediaBindableInterface) |
69 | Q_ENUMS(State) |
70 | Q_ENUMS(Status) |
71 | Q_ENUMS(Error) |
72 | Q_PROPERTY(QMediaRecorder::State state READ state NOTIFY stateChanged) |
73 | Q_PROPERTY(QMediaRecorder::Status status READ status NOTIFY statusChanged) |
74 | Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged) |
75 | Q_PROPERTY(QUrl outputLocation READ outputLocation WRITE setOutputLocation) |
76 | Q_PROPERTY(QUrl actualLocation READ actualLocation NOTIFY actualLocationChanged) |
77 | Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged) |
78 | Q_PROPERTY(qreal volume READ volume WRITE setVolume NOTIFY volumeChanged) |
79 | Q_PROPERTY(bool metaDataAvailable READ isMetaDataAvailable NOTIFY metaDataAvailableChanged) |
80 | Q_PROPERTY(bool metaDataWritable READ isMetaDataWritable NOTIFY metaDataWritableChanged) |
81 | public: |
82 | |
83 | enum State |
84 | { |
85 | StoppedState, |
86 | RecordingState, |
87 | PausedState |
88 | }; |
89 | |
90 | enum Status { |
91 | UnavailableStatus, |
92 | UnloadedStatus, |
93 | LoadingStatus, |
94 | LoadedStatus, |
95 | StartingStatus, |
96 | RecordingStatus, |
97 | PausedStatus, |
98 | FinalizingStatus |
99 | }; |
100 | |
101 | enum Error |
102 | { |
103 | NoError, |
104 | ResourceError, |
105 | FormatError, |
106 | OutOfSpaceError |
107 | }; |
108 | |
109 | explicit QMediaRecorder(QMediaObject *mediaObject, QObject *parent = nullptr); |
110 | ~QMediaRecorder(); |
111 | |
112 | QMediaObject *mediaObject() const override; |
113 | |
114 | bool isAvailable() const; |
115 | QMultimedia::AvailabilityStatus availability() const; |
116 | |
117 | QUrl outputLocation() const; |
118 | bool setOutputLocation(const QUrl &location); |
119 | |
120 | QUrl actualLocation() const; |
121 | |
122 | State state() const; |
123 | Status status() const; |
124 | |
125 | Error error() const; |
126 | QString errorString() const; |
127 | |
128 | qint64 duration() const; |
129 | |
130 | bool isMuted() const; |
131 | qreal volume() const; |
132 | |
133 | QStringList supportedContainers() const; |
134 | QString containerDescription(const QString &format) const; |
135 | |
136 | QStringList supportedAudioCodecs() const; |
137 | QString audioCodecDescription(const QString &codecName) const; |
138 | |
139 | QList<int> supportedAudioSampleRates(const QAudioEncoderSettings &settings = QAudioEncoderSettings(), |
140 | bool *continuous = nullptr) const; |
141 | |
142 | QStringList supportedVideoCodecs() const; |
143 | QString videoCodecDescription(const QString &codecName) const; |
144 | |
145 | QList<QSize> supportedResolutions(const QVideoEncoderSettings &settings = QVideoEncoderSettings(), |
146 | bool *continuous = nullptr) const; |
147 | |
148 | QList<qreal> supportedFrameRates(const QVideoEncoderSettings &settings = QVideoEncoderSettings(), |
149 | bool *continuous = nullptr) const; |
150 | |
151 | QAudioEncoderSettings audioSettings() const; |
152 | QVideoEncoderSettings videoSettings() const; |
153 | QString containerFormat() const; |
154 | |
155 | void setAudioSettings(const QAudioEncoderSettings &audioSettings); |
156 | void setVideoSettings(const QVideoEncoderSettings &videoSettings); |
157 | void setContainerFormat(const QString &container); |
158 | |
159 | void setEncodingSettings(const QAudioEncoderSettings &audioSettings, |
160 | const QVideoEncoderSettings &videoSettings = QVideoEncoderSettings(), |
161 | const QString &containerMimeType = QString()); |
162 | |
163 | bool isMetaDataAvailable() const; |
164 | bool isMetaDataWritable() const; |
165 | |
166 | QVariant metaData(const QString &key) const; |
167 | void setMetaData(const QString &key, const QVariant &value); |
168 | QStringList availableMetaData() const; |
169 | |
170 | public Q_SLOTS: |
171 | void record(); |
172 | void pause(); |
173 | void stop(); |
174 | void setMuted(bool muted); |
175 | void setVolume(qreal volume); |
176 | |
177 | Q_SIGNALS: |
178 | void stateChanged(QMediaRecorder::State state); |
179 | void statusChanged(QMediaRecorder::Status status); |
180 | void durationChanged(qint64 duration); |
181 | void mutedChanged(bool muted); |
182 | void volumeChanged(qreal volume); |
183 | void actualLocationChanged(const QUrl &location); |
184 | |
185 | void error(QMediaRecorder::Error error); |
186 | |
187 | void metaDataAvailableChanged(bool available); |
188 | void metaDataWritableChanged(bool writable); |
189 | void metaDataChanged(); |
190 | void metaDataChanged(const QString &key, const QVariant &value); |
191 | |
192 | void availabilityChanged(bool available); |
193 | void availabilityChanged(QMultimedia::AvailabilityStatus availability); |
194 | |
195 | protected: |
196 | QMediaRecorder(QMediaRecorderPrivate &dd, QMediaObject *mediaObject, QObject *parent = nullptr); |
197 | bool setMediaObject(QMediaObject *object) override; |
198 | |
199 | QMediaRecorderPrivate *d_ptr; |
200 | private: |
201 | Q_DISABLE_COPY(QMediaRecorder) |
202 | Q_DECLARE_PRIVATE(QMediaRecorder) |
203 | Q_PRIVATE_SLOT(d_func(), void _q_stateChanged(QMediaRecorder::State)) |
204 | Q_PRIVATE_SLOT(d_func(), void _q_error(int, const QString &)) |
205 | Q_PRIVATE_SLOT(d_func(), void _q_serviceDestroyed()) |
206 | Q_PRIVATE_SLOT(d_func(), void _q_notify()) |
207 | Q_PRIVATE_SLOT(d_func(), void _q_updateActualLocation(const QUrl &)) |
208 | Q_PRIVATE_SLOT(d_func(), void _q_updateNotifyInterval(int)) |
209 | Q_PRIVATE_SLOT(d_func(), void _q_applySettings()) |
210 | Q_PRIVATE_SLOT(d_func(), void _q_availabilityChanged(QMultimedia::AvailabilityStatus)) |
211 | }; |
212 | |
213 | QT_END_NAMESPACE |
214 | |
215 | Q_DECLARE_METATYPE(QMediaRecorder::State) |
216 | Q_DECLARE_METATYPE(QMediaRecorder::Status) |
217 | Q_DECLARE_METATYPE(QMediaRecorder::Error) |
218 | |
219 | Q_MEDIA_ENUM_DEBUG(QMediaRecorder, State) |
220 | Q_MEDIA_ENUM_DEBUG(QMediaRecorder, Status) |
221 | Q_MEDIA_ENUM_DEBUG(QMediaRecorder, Error) |
222 | |
223 | #endif // QMEDIARECORDER_H |
224 | |