Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qplatformmediaintegration_p.h
Go to the documentation of this file.
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 <QtMultimedia/private/qmultimediautils_p.h>
18#include <QtMultimedia/private/qtmultimediaglobal_p.h>
19#include <QtMultimedia/qcapturablewindow.h>
20#include <QtMultimedia/qmediarecorder.h>
21#include <QtCore/private/qexpected_p.h>
22#include <QtCore/qobject.h>
23#include <QtCore/qstring.h>
24
25#include <memory>
26#include <mutex>
27#include <variant>
28
29// NOLINTBEGIN (bugprone-reserved-identifier)
30typedef struct _GstElement GstElement;
31// NOLINTEND (bugprone-reserved-identifier)
32
33QT_BEGIN_NAMESPACE
34
35class QAudioDecoder;
36class QAudioFormat;
37class QAudioInput;
38class QAudioOutput;
39class QCamera;
40class QCameraDevice;
42class QImageCapture;
43class QMediaDevices;
44class QMediaPlayer;
45class QMediaRecorder;
46class QGStreamerVideoSource;
47class QPlatformAudioDecoder;
48class QPlatformAudioDevices;
49class QPlatformAudioInput;
50class QPlatformAudioOutput;
51class QPlatformAudioResampler;
52class QPlatformCamera;
54class QPlatformImageCapture;
55class QPlatformMediaCaptureSession;
56class QPlatformMediaFormatInfo;
57class QPlatformMediaPlayer;
58class QPlatformMediaRecorder;
59class QPlatformSurfaceCapture;
60class QPlatformVideoDevices;
61class QPlatformVideoSink;
62class QScreenCapture;
63class QVideoFrame;
64class QVideoSink;
65class QWindowCapture;
66
67using GstElementOrDescription = std::variant<QString, GstElement *>;
68
69class Q_MULTIMEDIA_EXPORT QAbstractPlatformSpecificInterface
70{
71public:
72 virtual ~QAbstractPlatformSpecificInterface() = default;
73};
74
75class Q_MULTIMEDIA_EXPORT QPlatformMediaIntegration : public QObject
76{
77 Q_OBJECT
78public:
79 static QPlatformMediaIntegration *instance();
80
81 explicit QPlatformMediaIntegration(QLatin1String);
82 ~QPlatformMediaIntegration() override;
83 const QPlatformMediaFormatInfo *formatInfo();
84
85 virtual q23::expected<QPlatformCamera *, QString> createCamera(QCamera *)
86 {
87 return q23::unexpected{ notAvailable };
88 }
89 virtual QPlatformSurfaceCapture *createScreenCapture(QScreenCapture *) { return nullptr; }
90 virtual QPlatformSurfaceCapture *createWindowCapture(QWindowCapture *) { return nullptr; }
91
92 virtual q23::expected<QPlatformAudioDecoder *, QString> createAudioDecoder(QAudioDecoder *)
93 {
94 return q23::unexpected{ notAvailable };
95 }
96 virtual q23::expected<std::unique_ptr<QPlatformAudioResampler>, QString>
97 createAudioResampler(const QAudioFormat & /*inputFormat*/,
98 const QAudioFormat & /*outputFormat*/);
99 virtual q23::expected<QPlatformMediaCaptureSession *, QString> createCaptureSession()
100 {
101 return q23::unexpected{ notAvailable };
102 }
103 virtual q23::expected<QPlatformMediaPlayer *, QString> createPlayer(QMediaPlayer *)
104 {
105 return q23::unexpected{ notAvailable };
106 }
107 virtual q23::expected<QPlatformMediaRecorder *, QString> createRecorder(QMediaRecorder *)
108 {
109 return q23::unexpected{ notAvailable };
110 }
111 virtual q23::expected<QPlatformImageCapture *, QString> createImageCapture(QImageCapture *)
112 {
113 return q23::unexpected{ notAvailable };
114 }
115
116 virtual q23::expected<QPlatformAudioInput *, QString> createAudioInput(QAudioInput *);
117 virtual q23::expected<QPlatformAudioOutput *, QString> createAudioOutput(QAudioOutput *);
118
119 virtual q23::expected<QPlatformVideoSink *, QString> createVideoSink(QVideoSink *)
120 {
121 return q23::unexpected{ notAvailable };
122 }
123
124 virtual q23::expected<QPlatformCamera *, QString>
125 createGStreamerVideoSource(QGStreamerVideoSource *, const GstElementOrDescription &)
126 {
127 return q23::unexpected{ notAvailable };
128 }
129
130 QList<QCapturableWindow> capturableWindowsList();
131 bool isCapturableWindowValid(const QCapturableWindowPrivate &);
132 [[nodiscard]] q23::expected<QCapturableWindow, QString> capturableWindowFromQWindow(QWindow *);
133
134 QPlatformVideoDevices *videoDevices();
135
136 QPlatformCapturableWindows *capturableWindows();
137
138 QPlatformAudioDevices *audioDevices();
139
140 static QStringList availableBackends();
141 QLatin1String name(); // for unit tests
142
143 // Convert a QVideoFrame to the destination format
144 virtual QVideoFrame convertVideoFrame(QVideoFrame &, const QVideoFrameFormat &);
145
146 virtual QAbstractPlatformSpecificInterface *platformSpecificInterface() { return nullptr; }
147
148 static QLatin1String audioBackendName();
149
150 virtual bool isCameraSwitchingDuringRecordingSupported() const { return true; }
151
152protected:
153 virtual QPlatformMediaFormatInfo *createFormatInfo();
154
155 virtual QPlatformVideoDevices *createVideoDevices() { return nullptr; }
156
157 virtual QPlatformCapturableWindows *createCapturableWindows() { return nullptr; }
158
159 virtual std::unique_ptr<QPlatformAudioDevices> createAudioDevices();
160
161 inline static const QString notAvailable = QStringLiteral("Not available");
162
163private:
164 friend class QMockIntegration;
165 void resetInstance(); // tests only
166
167private:
168 std::unique_ptr<QPlatformVideoDevices> m_videoDevices;
169 std::once_flag m_videoDevicesOnceFlag;
170
171 std::unique_ptr<QPlatformCapturableWindows> m_capturableWindows;
172 std::once_flag m_capturableWindowsOnceFlag;
173
174 mutable std::unique_ptr<QPlatformMediaFormatInfo> m_formatInfo;
175 mutable std::once_flag m_formatInfoOnceFlg;
176
177 std::unique_ptr<QPlatformAudioDevices> m_audioDevices;
178 std::once_flag m_audioDevicesOnceFlag;
179
180 const QLatin1String m_backendName;
181};
182
183QT_END_NAMESPACE
184
185#endif // QPLATFORMMEDIAINTERFACE_H
The QAudioFormat class stores audio stream parameter information.
\inmodule QtMultimedia