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;
66class QGStreamerInterface;
67
68using GstElementOrDescription = std::variant<QString, GstElement *>;
69
70class Q_MULTIMEDIA_EXPORT QAbstractPlatformSpecificInterface
71{
72public:
73 virtual ~QAbstractPlatformSpecificInterface() = default;
74};
75
76class Q_MULTIMEDIA_EXPORT QPlatformMediaIntegration : public QObject
77{
78 Q_OBJECT
79public:
80 static QPlatformMediaIntegration *instance();
81
82 explicit QPlatformMediaIntegration(QLatin1String);
83 ~QPlatformMediaIntegration() override;
84 const QPlatformMediaFormatInfo *formatInfo();
85
86 virtual q23::expected<QPlatformCamera *, QString> createCamera(QCamera *)
87 {
88 return q23::unexpected{ notAvailable };
89 }
90 virtual QPlatformSurfaceCapture *createScreenCapture(QScreenCapture *) { return nullptr; }
91 virtual QPlatformSurfaceCapture *createWindowCapture(QWindowCapture *) { return nullptr; }
92
93 virtual q23::expected<QPlatformAudioDecoder *, QString> createAudioDecoder(QAudioDecoder *)
94 {
95 return q23::unexpected{ notAvailable };
96 }
97 virtual q23::expected<std::unique_ptr<QPlatformAudioResampler>, QString>
98 createAudioResampler(const QAudioFormat & /*inputFormat*/,
99 const QAudioFormat & /*outputFormat*/);
100 virtual q23::expected<QPlatformMediaCaptureSession *, QString> createCaptureSession()
101 {
102 return q23::unexpected{ notAvailable };
103 }
104 virtual q23::expected<QPlatformMediaPlayer *, QString> createPlayer(QMediaPlayer *)
105 {
106 return q23::unexpected{ notAvailable };
107 }
108 virtual q23::expected<QPlatformMediaRecorder *, QString> createRecorder(QMediaRecorder *)
109 {
110 return q23::unexpected{ notAvailable };
111 }
112 virtual q23::expected<QPlatformImageCapture *, QString> createImageCapture(QImageCapture *)
113 {
114 return q23::unexpected{ notAvailable };
115 }
116
117 virtual q23::expected<QPlatformAudioInput *, QString> createAudioInput(QAudioInput *);
118 virtual q23::expected<QPlatformAudioOutput *, QString> createAudioOutput(QAudioOutput *);
119
120 virtual q23::expected<QPlatformVideoSink *, QString> createVideoSink(QVideoSink *)
121 {
122 return q23::unexpected{ notAvailable };
123 }
124
125 QList<QCapturableWindow> capturableWindowsList();
126 bool isCapturableWindowValid(const QCapturableWindowPrivate &);
127 [[nodiscard]] q23::expected<QCapturableWindow, QString> capturableWindowFromQWindow(QWindow *);
128
129 QPlatformVideoDevices *videoDevices();
130
131 QPlatformCapturableWindows *capturableWindows();
132
133 QPlatformAudioDevices *audioDevices();
134
135 static QStringList availableBackends();
136 QLatin1String name(); // for unit tests
137
138 // Convert a QVideoFrame to the destination format
139 virtual QVideoFrame convertVideoFrame(QVideoFrame &, const QVideoFrameFormat &);
140
141 static QLatin1String audioBackendName();
142
143 virtual bool isCameraSwitchingDuringRecordingSupported() const { return true; }
144
145 virtual q23::expected<QPlatformCamera *, QString>
146 createGStreamerVideoSource(QGStreamerVideoSource *, const GstElementOrDescription &)
147 {
148 return q23::unexpected{ notAvailable };
149 }
150
151 virtual QGStreamerInterface *gstreamerInterface() { return nullptr; }
152
153 void resetInstance(); // tests only
154
155protected:
156 virtual QPlatformMediaFormatInfo *createFormatInfo();
157
158 virtual QPlatformVideoDevices *createVideoDevices() { return nullptr; }
159
160 virtual QPlatformCapturableWindows *createCapturableWindows() { return nullptr; }
161
162 virtual std::unique_ptr<QPlatformAudioDevices> createAudioDevices();
163
164 inline static const QString notAvailable = QStringLiteral("Not available");
165
166private:
167 friend class QMockIntegration;
168
169private:
170 std::unique_ptr<QPlatformVideoDevices> m_videoDevices;
171 std::once_flag m_videoDevicesOnceFlag;
172
173 std::unique_ptr<QPlatformCapturableWindows> m_capturableWindows;
174 std::once_flag m_capturableWindowsOnceFlag;
175
176 mutable std::unique_ptr<QPlatformMediaFormatInfo> m_formatInfo;
177 mutable std::once_flag m_formatInfoOnceFlg;
178
179 std::unique_ptr<QPlatformAudioDevices> m_audioDevices;
180 std::once_flag m_audioDevicesOnceFlag;
181
182 const QLatin1String m_backendName;
183};
184
185QT_END_NAMESPACE
186
187#endif // QPLATFORMMEDIAINTERFACE_H
The QAudioFormat class stores audio stream parameter information.
\inmodule QtMultimedia