| 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 | QString preferredSuffix() const { return mimeType().preferredSuffix(); } | 
| 62 | |
| 63 | QMediaRecorder::EncodingMode encodingMode() const { return m_encodingMode; } | 
| 64 | void setEncodingMode(QMediaRecorder::EncodingMode mode) { m_encodingMode = mode; } | 
| 65 | |
| 66 | QMediaRecorder::Quality quality() const { return m_quality; } | 
| 67 | void setQuality(QMediaRecorder::Quality quality) { m_quality = quality; } | 
| 68 | |
| 69 | QSize videoResolution() const { return m_videoResolution; } | 
| 70 | void setVideoResolution(const QSize &size) { m_videoResolution = size; } | 
| 71 | |
| 72 | qreal videoFrameRate() const { return m_videoFrameRate; } | 
| 73 | void setVideoFrameRate(qreal rate) { m_videoFrameRate = rate; } | 
| 74 | |
| 75 | int videoBitRate() const { return m_videoBitRate; } | 
| 76 | void setVideoBitRate(int bitrate) { m_videoBitRate = bitrate; } | 
| 77 | |
| 78 | int audioBitRate() const { return m_audioBitrate; } | 
| 79 | void setAudioBitRate(int bitrate) { m_audioBitrate = bitrate; } | 
| 80 | |
| 81 | int audioChannelCount() const { return m_audioChannels; } | 
| 82 | void setAudioChannelCount(int channels) { m_audioChannels = channels; } | 
| 83 | |
| 84 | int audioSampleRate() const { return m_audioSampleRate; } | 
| 85 | void setAudioSampleRate(int rate) { m_audioSampleRate = rate; } | 
| 86 | |
| 87 | bool operator==(const QMediaEncoderSettings &other) const | 
| 88 | { | 
| 89 | return m_format == other.m_format && | 
| 90 | m_encodingMode == other.m_encodingMode && | 
| 91 | m_quality == other.m_quality && | 
| 92 | m_audioBitrate == other.m_audioBitrate && | 
| 93 | m_audioSampleRate == other.m_audioSampleRate && | 
| 94 | m_audioChannels == other.m_audioChannels && | 
| 95 | m_videoResolution == other.m_videoResolution && | 
| 96 | m_videoFrameRate == other.m_videoFrameRate && | 
| 97 | m_videoBitRate == other.m_videoBitRate; | 
| 98 | } | 
| 99 | |
| 100 | bool operator!=(const QMediaEncoderSettings &other) const | 
| 101 | { return !operator==(other); } | 
| 102 | }; | 
| 103 | |
| 104 | class Q_MULTIMEDIA_EXPORT QPlatformMediaRecorder | 
| 105 | { | 
| 106 | public: | 
| 107 | virtual ~QPlatformMediaRecorder() {} | 
| 108 | |
| 109 | virtual bool isLocationWritable(const QUrl &location) const = 0; | 
| 110 | |
| 111 | virtual QMediaRecorder::RecorderState state() const { return m_state; } | 
| 112 | virtual void record(QMediaEncoderSettings &settings) = 0; | 
| 113 | virtual void pause(); | 
| 114 | virtual void resume(); | 
| 115 | virtual void stop() = 0; | 
| 116 | |
| 117 | virtual qint64 duration() const { return m_duration; } | 
| 118 | |
| 119 | virtual void setMetaData(const QMediaMetaData &) {} | 
| 120 | virtual QMediaMetaData metaData() const { return {}; } | 
| 121 | |
| 122 | QMediaRecorder::Error error() const { return m_error.code(); } | 
| 123 | QString errorString() const { return m_error.description(); } | 
| 124 | |
| 125 | QUrl outputLocation() const { return m_outputLocation; } | 
| 126 | virtual void setOutputLocation(const QUrl &location) { m_outputLocation = location; } | 
| 127 | QUrl actualLocation() const { return m_actualLocation; } | 
| 128 | void clearActualLocation() { m_actualLocation.clear(); } | 
| 129 | void clearError() { updateError(error: QMediaRecorder::NoError, errorString: QString()); } | 
| 130 | |
| 131 | QIODevice *outputDevice() const { return m_outputDevice; } | 
| 132 | void setOutputDevice(QIODevice *device) { m_outputDevice = device; } | 
| 133 | |
| 134 | virtual void updateAutoStop() { } | 
| 135 | |
| 136 | protected: | 
| 137 | explicit QPlatformMediaRecorder(QMediaRecorder *parent); | 
| 138 | |
| 139 | void stateChanged(QMediaRecorder::RecorderState state); | 
| 140 | void durationChanged(qint64 position); | 
| 141 | void actualLocationChanged(const QUrl &location); | 
| 142 | void updateError(QMediaRecorder::Error error, const QString &errorString); | 
| 143 | void metaDataChanged(); | 
| 144 | |
| 145 | QMediaRecorder *mediaRecorder() { return q; } | 
| 146 | |
| 147 | QString findActualLocation(const QMediaEncoderSettings &settings) const; | 
| 148 | |
| 149 | private: | 
| 150 | QMediaRecorder *q = nullptr; | 
| 151 | QErrorInfo<QMediaRecorder::Error> m_error; | 
| 152 | QUrl m_actualLocation; | 
| 153 | QUrl m_outputLocation; | 
| 154 | QPointer<QIODevice> m_outputDevice; | 
| 155 | qint64 m_duration = 0; | 
| 156 | |
| 157 | QMediaRecorder::RecorderState m_state = QMediaRecorder::StoppedState; | 
| 158 | }; | 
| 159 | |
| 160 | QT_END_NAMESPACE | 
| 161 | |
| 162 | #endif | 
| 163 | 
