| 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 <private/qtmultimediaglobal_p.h> | 
| 18 | #include <private/qmultimediautils_p.h> | 
| 19 | #include <qcapturablewindow.h> | 
| 20 | #include <qmediarecorder.h> | 
| 21 | #include <qstring.h> | 
| 22 | |
| 23 | #include <memory> | 
| 24 | #include <mutex> | 
| 25 | |
| 26 | QT_BEGIN_NAMESPACE | 
| 27 | |
| 28 | class QAudioDecoder; | 
| 29 | class QAudioFormat; | 
| 30 | class QAudioInput; | 
| 31 | class QAudioOutput; | 
| 32 | class QCamera; | 
| 33 | class QCameraDevice; | 
| 34 | class QCapturableWindow; | 
| 35 | class QImageCapture; | 
| 36 | class QMediaDevices; | 
| 37 | class QMediaPlayer; | 
| 38 | class QMediaRecorder; | 
| 39 | class QObject; | 
| 40 | class QPlatformAudioDecoder; | 
| 41 | class QPlatformAudioDevices; | 
| 42 | class QPlatformAudioInput; | 
| 43 | class QPlatformAudioOutput; | 
| 44 | class QPlatformAudioResampler; | 
| 45 | class QPlatformCamera; | 
| 46 | class QPlatformCapturableWindows; | 
| 47 | class QPlatformImageCapture; | 
| 48 | class QPlatformMediaCaptureSession; | 
| 49 | class QPlatformMediaFormatInfo; | 
| 50 | class QPlatformMediaPlayer; | 
| 51 | class QPlatformMediaRecorder; | 
| 52 | class QPlatformSurfaceCapture; | 
| 53 | class QPlatformVideoDevices; | 
| 54 | class QPlatformVideoSink; | 
| 55 | class QScreenCapture; | 
| 56 | class QVideoFrame; | 
| 57 | class QVideoSink; | 
| 58 | class QWindowCapture; | 
| 59 | |
| 60 | class Q_MULTIMEDIA_EXPORT QAbstractPlatformSpecificInterface | 
| 61 | { | 
| 62 | public: | 
| 63 | virtual ~QAbstractPlatformSpecificInterface() = default; | 
| 64 | }; | 
| 65 | |
| 66 | class Q_MULTIMEDIA_EXPORT QPlatformMediaIntegration : public QObject | 
| 67 | { | 
| 68 | Q_OBJECT | 
| 69 | inline static const QString notAvailable = QStringLiteral( "Not available"); | 
| 70 | public: | 
| 71 | static QPlatformMediaIntegration *instance(); | 
| 72 | |
| 73 | explicit QPlatformMediaIntegration(QLatin1String); | 
| 74 | ~QPlatformMediaIntegration() override; | 
| 75 | const QPlatformMediaFormatInfo *formatInfo(); | 
| 76 | |
| 77 | virtual QMaybe<QPlatformCamera *> createCamera(QCamera *) { return notAvailable; } | 
| 78 | virtual QPlatformSurfaceCapture *createScreenCapture(QScreenCapture *) { return nullptr; } | 
| 79 | virtual QPlatformSurfaceCapture *createWindowCapture(QWindowCapture *) { return nullptr; } | 
| 80 | |
| 81 | virtual QMaybe<QPlatformAudioDecoder *> createAudioDecoder(QAudioDecoder *) { return notAvailable; } | 
| 82 | virtual QMaybe<std::unique_ptr<QPlatformAudioResampler>> | 
| 83 | createAudioResampler(const QAudioFormat & /*inputFormat*/, | 
| 84 | const QAudioFormat & /*outputFormat*/); | 
| 85 | virtual QMaybe<QPlatformMediaCaptureSession *> createCaptureSession() { return notAvailable; } | 
| 86 | virtual QMaybe<QPlatformMediaPlayer *> createPlayer(QMediaPlayer *) { return notAvailable; } | 
| 87 | virtual QMaybe<QPlatformMediaRecorder *> createRecorder(QMediaRecorder *) { return notAvailable; } | 
| 88 | virtual QMaybe<QPlatformImageCapture *> createImageCapture(QImageCapture *) { return notAvailable; } | 
| 89 | |
| 90 | virtual QMaybe<QPlatformAudioInput *> createAudioInput(QAudioInput *); | 
| 91 | virtual QMaybe<QPlatformAudioOutput *> createAudioOutput(QAudioOutput *); | 
| 92 | |
| 93 | virtual QMaybe<QPlatformVideoSink *> createVideoSink(QVideoSink *) { return notAvailable; } | 
| 94 | |
| 95 | QList<QCapturableWindow> capturableWindowsList(); | 
| 96 | bool isCapturableWindowValid(const QCapturableWindowPrivate &); | 
| 97 | |
| 98 | QPlatformVideoDevices *videoDevices(); | 
| 99 | |
| 100 | QPlatformCapturableWindows *capturableWindows(); | 
| 101 | |
| 102 | QPlatformAudioDevices *audioDevices(); | 
| 103 | |
| 104 | static QStringList availableBackends(); | 
| 105 | QLatin1String name(); // for unit tests | 
| 106 | |
| 107 | // Convert a QVideoFrame to the destination format | 
| 108 | virtual QVideoFrame convertVideoFrame(QVideoFrame &, const QVideoFrameFormat &); | 
| 109 | |
| 110 | virtual QAbstractPlatformSpecificInterface *platformSpecificInterface() { return nullptr; } | 
| 111 | |
| 112 | static QLatin1String audioBackendName(); | 
| 113 | |
| 114 | protected: | 
| 115 | virtual QPlatformMediaFormatInfo *createFormatInfo(); | 
| 116 | |
| 117 | virtual QPlatformVideoDevices *createVideoDevices() { return nullptr; } | 
| 118 | |
| 119 | virtual QPlatformCapturableWindows *createCapturableWindows() { return nullptr; } | 
| 120 | |
| 121 | virtual std::unique_ptr<QPlatformAudioDevices> createAudioDevices(); | 
| 122 | |
| 123 | private: | 
| 124 | friend class QMockIntegration; | 
| 125 | void resetInstance(); // tests only | 
| 126 | |
| 127 | private: | 
| 128 | std::unique_ptr<QPlatformVideoDevices> m_videoDevices; | 
| 129 | std::once_flag m_videoDevicesOnceFlag; | 
| 130 | |
| 131 | std::unique_ptr<QPlatformCapturableWindows> m_capturableWindows; | 
| 132 | std::once_flag m_capturableWindowsOnceFlag; | 
| 133 | |
| 134 | mutable std::unique_ptr<QPlatformMediaFormatInfo> m_formatInfo; | 
| 135 | mutable std::once_flag m_formatInfoOnceFlg; | 
| 136 | |
| 137 | std::unique_ptr<QPlatformAudioDevices> m_audioDevices; | 
| 138 | std::once_flag m_audioDevicesOnceFlag; | 
| 139 | |
| 140 | const QLatin1String m_backendName; | 
| 141 | }; | 
| 142 | |
| 143 | QT_END_NAMESPACE | 
| 144 | |
| 145 | |
| 146 | #endif // QPLATFORMMEDIAINTERFACE_H | 
| 147 | 
