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
mediabackendutils_p.h
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef MEDIABACKENDUTILS_H
5#define MEDIABACKENDUTILS_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtGui/private/qguiapplication_p.h>
19#include <QtGui/qpa/qplatformintegration.h>
20
21#include <QtMultimedia/private/qplatformmediaintegration_p.h>
22
23#include <QtTest/qtestcase.h>
24
25#include <optional>
26
27namespace BackendUtilsImpl {
28
29using namespace Qt::Literals;
30
32{
33 return QPlatformMediaIntegration::instance()->name() == "gstreamer"_L1;
34}
35
36inline bool isQNXPlatform()
37{
38 return QPlatformMediaIntegration::instance()->name() == "qnx"_L1;
39}
40
41inline bool isDarwinPlatform()
42{
43 return QPlatformMediaIntegration::instance()->name() == "darwin"_L1;
44}
45
46inline bool isAndroidPlatform()
47{
48 return QPlatformMediaIntegration::instance()->name() == "android"_L1;
49}
50
51inline bool isOhosPlatform()
52{
53 return QPlatformMediaIntegration::instance()->name() == "ohos"_L1;
54}
55
56inline bool isFFMPEGPlatform()
57{
58 return QPlatformMediaIntegration::instance()->name() == "ffmpeg"_L1;
59}
60
61inline bool isWMFPlatform()
62{
63 return QPlatformMediaIntegration::instance()->name() == "windows"_L1;
64}
65
67{
68 return QPlatformMediaIntegration::instance()->name() != "fallback"_L1;
69}
70
71// Appends "<backend>-mediabackend" to QTEST_ENVIRONMENT, so that BLACKLIST files can
72// target a media backend, e.g. "macos darwin-mediabackend".
73void addMediaBackendToTestEnvironment(const QString &backend);
74
75// The backend requested by initIntegrationTestMain(). Unset if it was not called.
77{
78 static std::optional<QString> backend;
79 return backend;
80}
81
83{
84 QString backend = qEnvironmentVariable("QT_MEDIA_BACKEND");
85 if (backend.isEmpty())
86 backend = QPlatformMediaIntegration::defaultBackend();
87 QPlatformMediaIntegration::setBackend(backend);
88 addMediaBackendToTestEnvironment(backend);
89 intendedMediaBackend() = backend.toLower();
90}
91
92// Returns true if initialization is successful
94{
95 // VERIFY must be inside a void-returning function.
96 []() {
97 QVERIFY2(
99 "No media backend plugin was loaded; the fallback integration was used. "
100 "Integration tests require a real backend plugin.");
101
102 const std::optional<QString> &intended = intendedMediaBackend();
103 const QString loaded = QPlatformMediaIntegration::instance()->name();
104
105 QVERIFY2(!intended || loaded == *intended,
106 qPrintable(u"Expected media backend '%1', but '%2' was loaded."_s.arg(
107 intended.value_or(u"any"_s), loaded)));
108 }();
109 return !QTest::currentTestFailed();
110}
111
113{
114 return QGuiApplicationPrivate::platformIntegration()->hasCapability(
115 QPlatformIntegration::RhiBasedRendering);
116}
117
118inline bool isOpenGLSupported()
119{
120 return QGuiApplicationPrivate::platformIntegration()->hasCapability(
121 QPlatformIntegration::OpenGL);
122}
123
124inline bool isCI()
125{
126 return qEnvironmentVariable("QTEST_ENVIRONMENT").toLower().split(u' ').contains(u"ci"_s);
127}
128
129} // namespace BackendUtilsImpl
130
131using namespace BackendUtilsImpl;
132
133#define QSKIP_IF(checker, defaultMessage, /*messageOpt*/...)
134 do {
135 if (checker)
136 QSKIP(strlen(__VA_ARGS__ "") ? __VA_ARGS__ "" : defaultMessage);
137 } while (0)
138
139#define QSKIP_GSTREAMER(/*messageOpt*/...)
140 QSKIP_IF(isGStreamerPlatform(), "The feature is not supported on GStreamer", __VA_ARGS__)
141
142#define QSKIP_IF_NOT_FFMPEG(/*messageOpt*/...)
143 QSKIP_IF(!isFFMPEGPlatform(), "The feature is only supported on FFmpeg", __VA_ARGS__)
144
145#define QSKIP_FFMPEG(/*messageOpt*/...)
146 QSKIP_IF(isFFMPEGPlatform(), "The feature is not supported on FFmpeg", __VA_ARGS__)
147
148#define QSKIP_DARWIN(/*messageOpt*/...)
149 QSKIP_IF(isDarwinPlatform(), "The feature is not supported on Darwin", __VA_ARGS__)
150
151#define QSKIP_OHOS(/*messageOpt*/...)
152 QSKIP_IF(isOhosPlatform(), "The feature is not supported on HarmonyOS", __VA_ARGS__)
153
154#define QSKIP_WMF(/*messageOpt*/...)
155 QSKIP_IF(isWMFPlatform(), "The feature is not supported on Windows MediaEngine", __VA_ARGS__)
156
157#define QEXPECT_FAIL_GSTREAMER(dataIndex, comment, mode)
158 do {
159 if (isGStreamerPlatform())
160 QEXPECT_FAIL(dataIndex, comment, mode);
161 } while (0)
162
163#endif // MEDIABACKENDUTILS_H
The FrameGrabber stores frames that arrive from a surface capture, and is used to inspect captured fr...
std::vector< QVideoFrame > waitAndTakeVideoFrames(size_t minCount, std::optional< qreal > expectedFrameRate=std::nullopt, qint64 noOlderThanTime=0)
Same as waitAndTakeFrameInfos(), but returns the video frames themselves.
void onCaptureActiveChanged(bool active)
Starts tracking a new stream when the capture becomes active, so that tryWaitForFirstFrameInfo() wait...
std::vector< VideoFrameInfo > waitAndTakeFrameInfos(size_t minCount, std::optional< qreal > expectedFrameRate=std::nullopt, qint64 noOlderThanTime=0)
Wait for at least minCount frames that are no older than noOlderThanTime.
void setRetainFirstVideoFrame(bool retain)
std::optional< std::chrono::milliseconds > durationBetweenFrames(qsizetype frameCount=1, std::optional< qreal > expectedFrameRate=std::nullopt)
Measures the average duration between frameCount consecutive frames.
const std::vector< VideoFrameInfo > & getFrameInfos() const
std::optional< QVideoFrame > consumeFirstVideoFrame()
Same as tryWaitForFirstFrameInfo(), but returns the video frame itself, and consumes it.
std::optional< VideoFrameInfo > tryWaitForFirstFrameInfo()
Waits for the first frame of the current stream, and returns a copy of its info.
#define QSKIP_IF(checker, defaultMessage,...)
std::optional< QString > & intendedMediaBackend()
void addMediaBackendToTestEnvironment(const QString &backend)
static std::optional< std::chrono::milliseconds > maxFrameInterval(std::optional< qreal > frameRate)
static qint64 startTimeOf(const VideoFrameInfo &info)
static VideoFrameInfo makeVideoFrameInfo(const QVideoFrame &frame)
std::chrono::milliseconds surfaceCaptureTestTimeout()
static qint64 startTimeOf(const QVideoFrame &frame)
QVideoFrameFormat::PixelFormat pixelFormat