| 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 | #ifndef QPLATFORMMEDIAINTEGRATION_H |
| 4 | #define QPLATFORMMEDIAINTEGRATION_H |
| 5 | |
| 6 | // |
| 7 | // W A R N I N G |
| 8 | // ------------- |
| 9 | // |
| 10 | // This file is not part of the Qt API. It exists purely as an |
| 11 | // implementation detail. This header file may change from version to |
| 12 | // version without notice, or even be removed. |
| 13 | // |
| 14 | // We mean it. |
| 15 | // |
| 16 | |
| 17 | #include <QtCore/qstring.h> |
| 18 | #include <QtCore/private/qexpected_p.h> |
| 19 | |
| 20 | #include <QtMultimedia/qcapturablewindow.h> |
| 21 | #include <QtMultimedia/qmediarecorder.h> |
| 22 | #include <QtMultimedia/private/qmultimediautils_p.h> |
| 23 | #include <QtMultimedia/private/qtmultimediaglobal_p.h> |
| 24 | |
| 25 | #include <memory> |
| 26 | #include <mutex> |
| 27 | |
| 28 | QT_BEGIN_NAMESPACE |
| 29 | |
| 30 | class QAudioDecoder; |
| 31 | class QAudioFormat; |
| 32 | class QAudioInput; |
| 33 | class QAudioOutput; |
| 34 | class QCamera; |
| 35 | class QCameraDevice; |
| 36 | class QCapturableWindow; |
| 37 | class QImageCapture; |
| 38 | class QMediaDevices; |
| 39 | class QMediaPlayer; |
| 40 | class QMediaRecorder; |
| 41 | class QObject; |
| 42 | class QPlatformAudioDecoder; |
| 43 | class QPlatformAudioDevices; |
| 44 | class QPlatformAudioInput; |
| 45 | class QPlatformAudioOutput; |
| 46 | class QPlatformAudioResampler; |
| 47 | class QPlatformCamera; |
| 48 | class QPlatformCapturableWindows; |
| 49 | class QPlatformImageCapture; |
| 50 | class QPlatformMediaCaptureSession; |
| 51 | class QPlatformMediaFormatInfo; |
| 52 | class QPlatformMediaPlayer; |
| 53 | class QPlatformMediaRecorder; |
| 54 | class QPlatformSurfaceCapture; |
| 55 | class QPlatformVideoDevices; |
| 56 | class QPlatformVideoSink; |
| 57 | class QScreenCapture; |
| 58 | class QVideoFrame; |
| 59 | class QVideoSink; |
| 60 | class QWindowCapture; |
| 61 | |
| 62 | class Q_MULTIMEDIA_EXPORT QAbstractPlatformSpecificInterface |
| 63 | { |
| 64 | public: |
| 65 | virtual ~QAbstractPlatformSpecificInterface() = default; |
| 66 | }; |
| 67 | |
| 68 | class Q_MULTIMEDIA_EXPORT QPlatformMediaIntegration : public QObject |
| 69 | { |
| 70 | Q_OBJECT |
| 71 | public: |
| 72 | static QPlatformMediaIntegration *instance(); |
| 73 | |
| 74 | explicit QPlatformMediaIntegration(QLatin1String); |
| 75 | ~QPlatformMediaIntegration() override; |
| 76 | const QPlatformMediaFormatInfo *formatInfo(); |
| 77 | |
| 78 | virtual q23::expected<QPlatformCamera *, QString> createCamera(QCamera *) |
| 79 | { |
| 80 | return q23::unexpected{ notAvailable }; |
| 81 | } |
| 82 | virtual QPlatformSurfaceCapture *createScreenCapture(QScreenCapture *) { return nullptr; } |
| 83 | virtual QPlatformSurfaceCapture *createWindowCapture(QWindowCapture *) { return nullptr; } |
| 84 | |
| 85 | virtual q23::expected<QPlatformAudioDecoder *, QString> createAudioDecoder(QAudioDecoder *) |
| 86 | { |
| 87 | return q23::unexpected{ notAvailable }; |
| 88 | } |
| 89 | virtual q23::expected<std::unique_ptr<QPlatformAudioResampler>, QString> |
| 90 | createAudioResampler(const QAudioFormat & /*inputFormat*/, |
| 91 | const QAudioFormat & /*outputFormat*/); |
| 92 | virtual q23::expected<QPlatformMediaCaptureSession *, QString> createCaptureSession() |
| 93 | { |
| 94 | return q23::unexpected{ notAvailable }; |
| 95 | } |
| 96 | virtual q23::expected<QPlatformMediaPlayer *, QString> createPlayer(QMediaPlayer *) |
| 97 | { |
| 98 | return q23::unexpected{ notAvailable }; |
| 99 | } |
| 100 | virtual q23::expected<QPlatformMediaRecorder *, QString> createRecorder(QMediaRecorder *) |
| 101 | { |
| 102 | return q23::unexpected{ notAvailable }; |
| 103 | } |
| 104 | virtual q23::expected<QPlatformImageCapture *, QString> createImageCapture(QImageCapture *) |
| 105 | { |
| 106 | return q23::unexpected{ notAvailable }; |
| 107 | } |
| 108 | |
| 109 | virtual q23::expected<QPlatformAudioInput *, QString> createAudioInput(QAudioInput *); |
| 110 | virtual q23::expected<QPlatformAudioOutput *, QString> createAudioOutput(QAudioOutput *); |
| 111 | |
| 112 | virtual q23::expected<QPlatformVideoSink *, QString> createVideoSink(QVideoSink *) |
| 113 | { |
| 114 | return q23::unexpected{ notAvailable }; |
| 115 | } |
| 116 | |
| 117 | QList<QCapturableWindow> capturableWindowsList(); |
| 118 | bool isCapturableWindowValid(const QCapturableWindowPrivate &); |
| 119 | [[nodiscard]] q23::expected<QCapturableWindow, QString> capturableWindowFromQWindow(QWindow *); |
| 120 | |
| 121 | QPlatformVideoDevices *videoDevices(); |
| 122 | |
| 123 | QPlatformCapturableWindows *capturableWindows(); |
| 124 | |
| 125 | QPlatformAudioDevices *audioDevices(); |
| 126 | |
| 127 | static QStringList availableBackends(); |
| 128 | QLatin1String name(); // for unit tests |
| 129 | |
| 130 | // Convert a QVideoFrame to the destination format |
| 131 | virtual QVideoFrame convertVideoFrame(QVideoFrame &, const QVideoFrameFormat &); |
| 132 | |
| 133 | virtual QAbstractPlatformSpecificInterface *platformSpecificInterface() { return nullptr; } |
| 134 | |
| 135 | static QLatin1String audioBackendName(); |
| 136 | |
| 137 | protected: |
| 138 | virtual QPlatformMediaFormatInfo *createFormatInfo(); |
| 139 | |
| 140 | virtual QPlatformVideoDevices *createVideoDevices() { return nullptr; } |
| 141 | |
| 142 | virtual QPlatformCapturableWindows *createCapturableWindows() { return nullptr; } |
| 143 | |
| 144 | virtual std::unique_ptr<QPlatformAudioDevices> createAudioDevices(); |
| 145 | |
| 146 | inline static const QString notAvailable = QStringLiteral("Not available" ); |
| 147 | |
| 148 | private: |
| 149 | friend class QMockIntegration; |
| 150 | void resetInstance(); // tests only |
| 151 | |
| 152 | private: |
| 153 | std::unique_ptr<QPlatformVideoDevices> m_videoDevices; |
| 154 | std::once_flag m_videoDevicesOnceFlag; |
| 155 | |
| 156 | std::unique_ptr<QPlatformCapturableWindows> m_capturableWindows; |
| 157 | std::once_flag m_capturableWindowsOnceFlag; |
| 158 | |
| 159 | mutable std::unique_ptr<QPlatformMediaFormatInfo> m_formatInfo; |
| 160 | mutable std::once_flag m_formatInfoOnceFlg; |
| 161 | |
| 162 | std::unique_ptr<QPlatformAudioDevices> m_audioDevices; |
| 163 | std::once_flag m_audioDevicesOnceFlag; |
| 164 | |
| 165 | const QLatin1String m_backendName; |
| 166 | }; |
| 167 | |
| 168 | QT_END_NAMESPACE |
| 169 | |
| 170 | #endif // QPLATFORMMEDIAINTERFACE_H |
| 171 | |