| 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/qmaybe_p.h> |
| 20 | #include <QtMultimedia/private/qvideotransformation_p.h> |
| 21 | #include <QtCore/qsize.h> |
| 22 | #include <QtCore/qurl.h> |
| 23 | #include <QtGui/rhi/qrhi.h> |
| 24 | |
| 25 | QT_BEGIN_NAMESPACE |
| 26 | |
| 27 | class QRhiSwapChain; |
| 28 | class QVideoFrame; |
| 29 | class QVideoFrameFormat; |
| 30 | |
| 31 | struct Fraction { |
| 32 | int numerator; |
| 33 | int denominator; |
| 34 | }; |
| 35 | |
| 36 | Q_MULTIMEDIA_EXPORT Fraction qRealToFraction(qreal value); |
| 37 | |
| 38 | Q_MULTIMEDIA_EXPORT QSize qCalculateFrameSize(QSize resolution, Fraction pixelAspectRatio); |
| 39 | |
| 40 | // TODO: after adding pixel aspect ratio to QVideoFrameFormat, the function should |
| 41 | // consider PAR as well as rotation |
| 42 | Q_MULTIMEDIA_EXPORT QSize qRotatedFrameSize(QSize size, int rotation); |
| 43 | |
| 44 | inline QSize qRotatedFrameSize(QSize size, QtVideo::Rotation rotation) |
| 45 | { |
| 46 | return qRotatedFrameSize(size, rotation: qToUnderlying(e: rotation)); |
| 47 | } |
| 48 | |
| 49 | Q_MULTIMEDIA_EXPORT QSize qRotatedFramePresentationSize(const QVideoFrame &frame); |
| 50 | |
| 51 | Q_MULTIMEDIA_EXPORT QUrl qMediaFromUserInput(QUrl fileName); |
| 52 | |
| 53 | Q_MULTIMEDIA_EXPORT bool qIsAutoHdrEnabled(); |
| 54 | |
| 55 | Q_MULTIMEDIA_EXPORT QRhiSwapChain::Format |
| 56 | qGetRequiredSwapChainFormat(const QVideoFrameFormat &format); |
| 57 | |
| 58 | Q_MULTIMEDIA_EXPORT bool |
| 59 | qShouldUpdateSwapChainFormat(QRhiSwapChain *swapChain, |
| 60 | QRhiSwapChain::Format requiredSwapChainFormat); |
| 61 | |
| 62 | Q_MULTIMEDIA_EXPORT VideoTransformation |
| 63 | qNormalizedSurfaceTransformation(const QVideoFrameFormat &format); |
| 64 | |
| 65 | Q_MULTIMEDIA_EXPORT VideoTransformation qNormalizedFrameTransformation( |
| 66 | const QVideoFrame &frame, VideoTransformation videoOutputTransformation = {}); |
| 67 | |
| 68 | Q_MULTIMEDIA_EXPORT QtVideo::Rotation |
| 69 | qVideoRotationFromDegrees(int clockwiseDegrees); |
| 70 | |
| 71 | inline VideoTransformation qNormalizedFrameTransformation(const QVideoFrame &frame, |
| 72 | int videoOutputRotation) |
| 73 | { |
| 74 | return qNormalizedFrameTransformation( |
| 75 | frame, videoOutputTransformation: VideoTransformation{ .rotation: qVideoRotationFromDegrees(clockwiseDegrees: videoOutputRotation) }); |
| 76 | } |
| 77 | |
| 78 | /* The function get mirroring and rotation from the specified QTransform. |
| 79 | * |
| 80 | * Matrix translation is not taken into consideration. |
| 81 | * Matrix negative scaling is interpreted as mirroring. |
| 82 | * Absolute X and Y scale values are not taken into consideration as |
| 83 | * QVideoFrame and QVideoFrameFormat don't support scaling transformations. |
| 84 | * |
| 85 | * Sheared matrixes are not supported, |
| 86 | * as shearing can make the transformation ambiguous |
| 87 | * (the same matrix can be reached by different angle,scaleX,scaleY,shearV,shearH). |
| 88 | * |
| 89 | * If the given matrix is invalid, or the scale sign is ambiguous, |
| 90 | * the function returns an empty optional value. |
| 91 | */ |
| 92 | Q_MULTIMEDIA_EXPORT VideoTransformationOpt qVideoTransformationFromMatrix(const QTransform &matrix); |
| 93 | |
| 94 | QT_END_NAMESPACE |
| 95 | |
| 96 | #endif // QMULTIMEDIAUTILS_P_H |
| 97 | |
| 98 | |