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
22#include <QtMultimedia/qmediarecorder.h>
23#include <QtMultimedia/qmediametadata.h>
24#include <QtMultimedia/qmediaformat.h>
25#include <QtCore/private/qglobal_p.h>
26
27QT_BEGIN_NAMESPACE
28
29class QUrl;
30QT_END_NAMESPACE
31
32QT_BEGIN_NAMESPACE
33
34class Q_MULTIMEDIA_EXPORT QMediaEncoderSettings
35{
36 QMediaRecorder::EncodingMode m_encodingMode = QMediaRecorder::ConstantQualityEncoding;
37 QMediaRecorder::Quality m_quality = QMediaRecorder::NormalQuality;
38
39 QMediaFormat m_format;
40 int m_audioBitrate = -1;
41 int m_audioSampleRate = -1;
42 int m_audioChannels = -1;
43
44 QSize m_videoResolution = QSize(-1, -1);
45 int m_videoFrameRate = -1;
46 int m_videoBitRate = -1;
47public:
48
49 QMediaFormat mediaFormat() const { return m_format; }
50 void setMediaFormat(const QMediaFormat &format) { m_format = format; }
51 void resolveFormat(QMediaFormat::ResolveFlags flags = QMediaFormat::NoFlags)
52 { m_format.resolveForEncoding(flags); }
53
54 QMediaFormat::FileFormat fileFormat() const { return mediaFormat().fileFormat(); }
55 QMediaFormat::VideoCodec videoCodec() const { return mediaFormat().videoCodec(); }
56 QMediaFormat::AudioCodec audioCodec() const { return mediaFormat().audioCodec(); }
57 QMimeType mimeType() const { return mediaFormat().mimeType(); }
58
59 QMediaRecorder::EncodingMode encodingMode() const { return m_encodingMode; }
60 void setEncodingMode(QMediaRecorder::EncodingMode mode) { m_encodingMode = mode; }
61
62 QMediaRecorder::Quality quality() const { return m_quality; }
63 void setQuality(QMediaRecorder::Quality quality) { m_quality = quality; }
64
65 QSize videoResolution() const { return m_videoResolution; }
66 void setVideoResolution(const QSize &size) { m_videoResolution = size; }
67
68 qreal videoFrameRate() const { return m_videoFrameRate; }
69 void setVideoFrameRate(qreal rate) { m_videoFrameRate = rate; }
70
71 int videoBitRate() const { return m_videoBitRate; }
72 void setVideoBitRate(int bitrate) { m_videoBitRate = bitrate; }
73
74 int audioBitRate() const { return m_audioBitrate; }
75 void setAudioBitRate(int bitrate) { m_audioBitrate = bitrate; }
76
77 int audioChannelCount() const { return m_audioChannels; }
78 void setAudioChannelCount(int channels) { m_audioChannels = channels; }
79
80 int audioSampleRate() const { return m_audioSampleRate; }
81 void setAudioSampleRate(int rate) { m_audioSampleRate = rate; }
82
83 bool operator==(const QMediaEncoderSettings &other) const
84 {
85 return m_format == other.m_format &&
86 m_encodingMode == other.m_encodingMode &&
87 m_quality == other.m_quality &&
88 m_audioBitrate == other.m_audioBitrate &&
89 m_audioSampleRate == other.m_audioSampleRate &&
90 m_audioChannels == other.m_audioChannels &&
91 m_videoResolution == other.m_videoResolution &&
92 m_videoFrameRate == other.m_videoFrameRate &&
93 m_videoBitRate == other.m_videoBitRate;
94 }
95
96 bool operator!=(const QMediaEncoderSettings &other) const
97 { return !operator==(other); }
98};
99
100class Q_MULTIMEDIA_EXPORT QPlatformMediaRecorder
101{
102public:
103 virtual ~QPlatformMediaRecorder() {}
104
105 virtual bool isLocationWritable(const QUrl &location) const = 0;
106
107 virtual QMediaRecorder::RecorderState state() const { return m_state; }
108 virtual void record(QMediaEncoderSettings &settings) = 0;
109 virtual void pause();
110 virtual void resume();
111 virtual void stop() = 0;
112
113 virtual qint64 duration() const { return m_duration; }
114
115 virtual void setMetaData(const QMediaMetaData &) {}
116 virtual QMediaMetaData metaData() const { return {}; }
117
118 QMediaRecorder::Error error() const { return m_error;}
119 QString errorString() const { return m_errorString; }
120
121 QUrl outputLocation() const { return m_outputLocation; }
122 virtual void setOutputLocation(const QUrl &location) { m_outputLocation = location; }
123 QUrl actualLocation() const { return m_actualLocation; }
124 void clearActualLocation() { m_actualLocation.clear(); }
125 void clearError() { error(error: QMediaRecorder::NoError, errorString: QString()); }
126
127protected:
128 explicit QPlatformMediaRecorder(QMediaRecorder *parent);
129
130 void stateChanged(QMediaRecorder::RecorderState state);
131 void durationChanged(qint64 position);
132 void actualLocationChanged(const QUrl &location);
133 void error(QMediaRecorder::Error error, const QString &errorString);
134 void metaDataChanged();
135
136 QMediaRecorder *mediaRecorder() { return q; }
137
138private:
139 QMediaRecorder *q = nullptr;
140 QMediaRecorder::Error m_error = QMediaRecorder::NoError;
141 QString m_errorString;
142 QUrl m_actualLocation;
143 QUrl m_outputLocation;
144 qint64 m_duration = 0;
145
146 QMediaRecorder::RecorderState m_state = QMediaRecorder::StoppedState;
147};
148
149QT_END_NAMESPACE
150
151#endif
152

source code of qtmultimedia/src/multimedia/platform/qplatformmediarecorder_p.h