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
qmultimediautils_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
4#ifndef QMULTIMEDIAUTILS_P_H
5#define QMULTIMEDIAUTILS_P_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 <QtMultimedia/qtmultimediaglobal.h>
19#include <QtMultimedia/private/qvideotransformation_p.h>
20#include <QtCore/private/qexpected_p.h>
21#include <QtCore/qlist.h>
22#include <QtCore/qsize.h>
23#include <QtCore/qurl.h>
24#include <QtGui/rhi/qrhi.h>
25
26#include <array>
27#include <memory>
28
29QT_BEGIN_NAMESPACE
30
31class QRhiSwapChain;
32class QFile;
33class QTemporaryFile;
34class QVideoFrame;
35class QVideoFrameFormat;
36
37struct Fraction {
40};
41
42Q_MULTIMEDIA_EXPORT Fraction qRealToFraction(qreal value);
43
44Q_MULTIMEDIA_EXPORT QSize qCalculateFrameSize(QSize resolution, Fraction pixelAspectRatio);
45
46// TODO: after adding pixel aspect ratio to QVideoFrameFormat, the function should
47// consider PAR as well as rotation
48Q_MULTIMEDIA_EXPORT QSize qRotatedFrameSize(QSize size, int rotation);
49
50inline QSize qRotatedFrameSize(QSize size, QtVideo::Rotation rotation)
51{
52 return qRotatedFrameSize(size, qToUnderlying(rotation));
53}
54
55Q_MULTIMEDIA_EXPORT QSize qRotatedFramePresentationSize(const QVideoFrame &frame);
56
57/* Pick the resolution from supportedResolutions that matches requested best.
58 *
59 * The aspect ratios are compared first, so scaling between resolutions doesn't
60 * require cropping or cause distortion. This comparison has a small tolerance
61 * added to it. Then the closest pixel count is picked among the candidates.
62 *
63 * Returns an invalid size if requested is empty, or if supportedResolutions
64 * doesn't contain any valid resolutions.
65 */
66Q_MULTIMEDIA_EXPORT QSize qClosestSupportedResolution(QSize requested,
67 QSpan<const QSize> supportedResolutions);
68
69Q_MULTIMEDIA_EXPORT QUrl qMediaFromUserInput(const QUrl &fileName);
70
72
73Q_MULTIMEDIA_EXPORT QRhiSwapChain::Format
74qGetRequiredSwapChainFormat(const QVideoFrameFormat &format);
75
77qShouldUpdateSwapChainFormat(QRhiSwapChain *swapChain,
78 QRhiSwapChain::Format requiredSwapChainFormat);
79
80Q_MULTIMEDIA_EXPORT VideoTransformation
81qNormalizedSurfaceTransformation(const QVideoFrameFormat &format);
82
83Q_MULTIMEDIA_EXPORT VideoTransformation qNormalizedFrameTransformation(
84 const QVideoFrame &frame, VideoTransformation videoOutputTransformation = {});
85
86Q_MULTIMEDIA_EXPORT QtVideo::Rotation
87qVideoRotationFromDegrees(int clockwiseDegrees);
88
90 int videoOutputRotation)
91{
92 return qNormalizedFrameTransformation(
93 frame, VideoTransformation{ qVideoRotationFromDegrees(videoOutputRotation) });
94}
95
96/* The function get mirroring and rotation from the specified QTransform.
97 *
98 * Matrix translation is not taken into consideration.
99 * Matrix negative scaling is interpreted as mirroring.
100 * Absolute X and Y scale values are not taken into consideration as
101 * QVideoFrame and QVideoFrameFormat don't support scaling transformations.
102 *
103 * Sheared matrixes are not supported,
104 * as shearing can make the transformation ambiguous
105 * (the same matrix can be reached by different angle,scaleX,scaleY,shearV,shearH).
106 *
107 * If the given matrix is invalid, or the scale sign is ambiguous,
108 * the function returns an empty optional value.
109 */
110Q_MULTIMEDIA_EXPORT VideoTransformationOpt qVideoTransformationFromMatrix(const QTransform &matrix);
111
112namespace QtMultimediaPrivate {
113
114template <class... Ts>
115struct qOverloadedVisitor : Ts...
116{
117 using Ts::operator()...;
118 constexpr qOverloadedVisitor(Ts... args) : Ts(std::move(args))... {}
119};
120template <class... Ts>
122
124{
125 void operator()(QObject *ptr) const
126 {
127 if (ptr)
128 ptr->deleteLater();
129 }
130};
131
132template <typename T, typename... Args>
133std::shared_ptr<T> makeSharedDeleteLater(Args &&...args)
134{
135 return std::shared_ptr<T>(new T(std::forward<Args>(args)...), DeleteLaterDeleter());
136}
137
143
144q23::expected<QrcMedia, QString> qCopyQrcToTemporaryFile(QFile &, const QUrl &);
145
146#ifdef Q_OS_UNIX
147Q_MULTIMEDIA_EXPORT int qt_safe_ioctl(int fd, int request, void *arg);
148#endif
149
150// clang-format off
151template <typename Key, typename Value, size_t N>
152#ifdef __cpp_concepts
154#endif
155class EnumMap : public std::array<Value, N>
156// clang-format on
157{
158 using Base = std::array<Value, N>;
159
160public:
161 using Base::operator[];
162
163 constexpr Value &operator[](Key key) { return Base::operator[](qToUnderlying(key)); }
164 constexpr const Value &operator[](Key key) const
165 {
166 return Base::operator[](qToUnderlying(key));
167 }
168};
169
170} // namespace QtMultimediaPrivate
171
172QT_END_NAMESPACE
173
174#endif // QMULTIMEDIAUTILS_P_H
\inmodule QtCore
Definition qsize.h:27
\inmodule QtCore
Definition qurl.h:95
constexpr Value & operator[](Key key)
constexpr const Value & operator[](Key key) const
q23::expected< QrcMedia, QString > qCopyQrcToTemporaryFile(QFile &qrcFile, const QUrl &qrcUrl)
std::shared_ptr< T > makeSharedDeleteLater(Args &&...args)
qOverloadedVisitor(Ts...) -> qOverloadedVisitor< Ts... >
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)
#define M_PI_2
Definition qmath.h:205
QRhiSwapChain::Format qGetRequiredSwapChainFormat(const QVideoFrameFormat &format)
QSize qClosestSupportedResolution(QSize requested, QSpan< const QSize > supportedResolutions)
QUrl qMediaFromUserInput(const QUrl &url)
QSize qRotatedFrameSize(QSize size, int rotation)
Fraction qRealToFraction(qreal value)
bool qIsAutoHdrEnabled()
QSize qRotatedFramePresentationSize(const QVideoFrame &frame)
QtVideo::Rotation qVideoRotationFromDegrees(int clockwiseDegrees)
VideoTransformationOpt qVideoTransformationFromMatrix(const QTransform &matrix)
VideoTransformation qNormalizedFrameTransformation(const QVideoFrame &frame, VideoTransformation videoOutputTransformation)
QSize qCalculateFrameSize(QSize resolution, Fraction par)
bool qShouldUpdateSwapChainFormat(QRhiSwapChain *swapChain, QRhiSwapChain::Format requiredSwapChainFormat)
std::optional< VideoTransformation > VideoTransformationOpt
std::unique_ptr< QTemporaryFile > file