1 | // Copyright (C) 2021 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 | // |
5 | // W A R N I N G |
6 | // ------------- |
7 | // |
8 | // This file is not part of the Qt API. It exists purely as an |
9 | // implementation detail. This header file may change from version to |
10 | // version without notice, or even be removed. |
11 | // |
12 | // We mean it. |
13 | // |
14 | |
15 | #ifndef QPLATFORMMEDIARECORDER_H |
16 | #define QPLATFORMMEDIARECORDER_H |
17 | |
18 | #include <QtCore/qurl.h> |
19 | #include <QtCore/qsize.h> |
20 | #include <QtCore/qmimetype.h> |
21 | #include <QtCore/qpointer.h> |
22 | #include <QtCore/qiodevice.h> |
23 | |
24 | #include <QtMultimedia/qmediarecorder.h> |
25 | #include <QtMultimedia/qmediametadata.h> |
26 | #include <QtMultimedia/qmediaformat.h> |
27 | #include <QtMultimedia/private/qerrorinfo_p.h> |
28 | #include <QtCore/private/qglobal_p.h> |
29 | |
30 | QT_BEGIN_NAMESPACE |
31 | |
32 | class QUrl; |
33 | QT_END_NAMESPACE |
34 | |
35 | QT_BEGIN_NAMESPACE |
36 | |
37 | class Q_MULTIMEDIA_EXPORT QMediaEncoderSettings |
38 | { |
39 | QMediaRecorder::EncodingMode m_encodingMode = QMediaRecorder::ConstantQualityEncoding; |
40 | QMediaRecorder::Quality m_quality = QMediaRecorder::NormalQuality; |
41 | |
42 | QMediaFormat m_format; |
43 | int m_audioBitrate = -1; |
44 | int m_audioSampleRate = -1; |
45 | int m_audioChannels = -1; |
46 | |
47 | QSize m_videoResolution = QSize(-1, -1); |
48 | int m_videoFrameRate = -1; |
49 | int m_videoBitRate = -1; |
50 | public: |
51 | |
52 | QMediaFormat mediaFormat() const { return m_format; } |
53 | void setMediaFormat(const QMediaFormat &format) { m_format = format; } |
54 | void resolveFormat(QMediaFormat::ResolveFlags flags = QMediaFormat::NoFlags) |
55 | { m_format.resolveForEncoding(flags); } |
56 | |
57 | QMediaFormat::FileFormat fileFormat() const { return mediaFormat().fileFormat(); } |
58 | QMediaFormat::VideoCodec videoCodec() const { return mediaFormat().videoCodec(); } |
59 | QMediaFormat::AudioCodec audioCodec() const { return mediaFormat().audioCodec(); } |
60 | QMimeType mimeType() const { return mediaFormat().mimeType(); } |
61 | |
62 | QMediaRecorder::EncodingMode encodingMode() const { return m_encodingMode; } |
63 | void setEncodingMode(QMediaRecorder::EncodingMode mode) { m_encodingMode = mode; } |
64 | |
65 | QMediaRecorder::Quality quality() const { return m_quality; } |
66 | void setQuality(QMediaRecorder::Quality quality) { m_quality = quality; } |
67 | |
68 | QSize videoResolution() const { return m_videoResolution; } |
69 | void setVideoResolution(const QSize &size) { m_videoResolution = size; } |
70 | |
71 | qreal videoFrameRate() const { return m_videoFrameRate; } |
72 | void setVideoFrameRate(qreal rate) { m_videoFrameRate = rate; } |
73 | |
74 | int videoBitRate() const { return m_videoBitRate; } |
75 | void setVideoBitRate(int bitrate) { m_videoBitRate = bitrate; } |
76 | |
77 | int audioBitRate() const { return m_audioBitrate; } |
78 | void setAudioBitRate(int bitrate) { m_audioBitrate = bitrate; } |
79 | |
80 | int audioChannelCount() const { return m_audioChannels; } |
81 | void setAudioChannelCount(int channels) { m_audioChannels = channels; } |
82 | |
83 | int audioSampleRate() const { return m_audioSampleRate; } |
84 | void setAudioSampleRate(int rate) { m_audioSampleRate = rate; } |
85 | |
86 | bool operator==(const QMediaEncoderSettings &other) const |
87 | { |
88 | return m_format == other.m_format && |
89 | m_encodingMode == other.m_encodingMode && |
90 | m_quality == other.m_quality && |
91 | m_audioBitrate == other.m_audioBitrate && |
92 | m_audioSampleRate == other.m_audioSampleRate && |
93 | m_audioChannels == other.m_audioChannels && |
94 | m_videoResolution == other.m_videoResolution && |
95 | m_videoFrameRate == other.m_videoFrameRate && |
96 | m_videoBitRate == other.m_videoBitRate; |
97 | } |
98 | |
99 | bool operator!=(const QMediaEncoderSettings &other) const |
100 | { return !operator==(other); } |
101 | }; |
102 | |
103 | class Q_MULTIMEDIA_EXPORT QPlatformMediaRecorder |
104 | { |
105 | public: |
106 | virtual ~QPlatformMediaRecorder() {} |
107 | |
108 | virtual bool isLocationWritable(const QUrl &location) const = 0; |
109 | |
110 | virtual QMediaRecorder::RecorderState state() const { return m_state; } |
111 | virtual void record(QMediaEncoderSettings &settings) = 0; |
112 | virtual void pause(); |
113 | virtual void resume(); |
114 | virtual void stop() = 0; |
115 | |
116 | virtual qint64 duration() const { return m_duration; } |
117 | |
118 | virtual void setMetaData(const QMediaMetaData &) {} |
119 | virtual QMediaMetaData metaData() const { return {}; } |
120 | |
121 | QMediaRecorder::Error error() const { return m_error.code(); } |
122 | QString errorString() const { return m_error.description(); } |
123 | |
124 | QUrl outputLocation() const { return m_outputLocation; } |
125 | virtual void setOutputLocation(const QUrl &location) { m_outputLocation = location; } |
126 | QUrl actualLocation() const { return m_actualLocation; } |
127 | void clearActualLocation() { m_actualLocation.clear(); } |
128 | void clearError() { updateError(error: QMediaRecorder::NoError, errorString: QString()); } |
129 | |
130 | QIODevice *outputDevice() const { return m_outputDevice; } |
131 | void setOutputDevice(QIODevice *device) { m_outputDevice = device; } |
132 | |
133 | virtual void updateAutoStop() { } |
134 | |
135 | protected: |
136 | explicit QPlatformMediaRecorder(QMediaRecorder *parent); |
137 | |
138 | void stateChanged(QMediaRecorder::RecorderState state); |
139 | void durationChanged(qint64 position); |
140 | void actualLocationChanged(const QUrl &location); |
141 | void updateError(QMediaRecorder::Error error, const QString &errorString); |
142 | void metaDataChanged(); |
143 | |
144 | QMediaRecorder *mediaRecorder() { return q; } |
145 | |
146 | QString findActualLocation(const QMediaEncoderSettings &settings) const; |
147 | |
148 | private: |
149 | QMediaRecorder *q = nullptr; |
150 | QErrorInfo<QMediaRecorder::Error> m_error; |
151 | QUrl m_actualLocation; |
152 | QUrl m_outputLocation; |
153 | QPointer<QIODevice> m_outputDevice; |
154 | qint64 m_duration = 0; |
155 | |
156 | QMediaRecorder::RecorderState m_state = QMediaRecorder::StoppedState; |
157 | }; |
158 | |
159 | QT_END_NAMESPACE |
160 | |
161 | #endif |
162 |
Definitions
- QMediaEncoderSettings
- mediaFormat
- setMediaFormat
- resolveFormat
- fileFormat
- videoCodec
- audioCodec
- mimeType
- encodingMode
- setEncodingMode
- quality
- setQuality
- videoResolution
- setVideoResolution
- videoFrameRate
- setVideoFrameRate
- videoBitRate
- setVideoBitRate
- audioBitRate
- setAudioBitRate
- audioChannelCount
- setAudioChannelCount
- audioSampleRate
- setAudioSampleRate
- operator==
- operator!=
- QPlatformMediaRecorder
- ~QPlatformMediaRecorder
- state
- duration
- setMetaData
- metaData
- error
- errorString
- outputLocation
- setOutputLocation
- actualLocation
- clearActualLocation
- clearError
- outputDevice
- setOutputDevice
- updateAutoStop
Learn Advanced QML with KDAB
Find out more