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
qvideotexturehelper_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 QVIDEOTEXTUREHELPER_H
5#define QVIDEOTEXTUREHELPER_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 <qvideoframeformat.h>
19#include <rhi/qrhi.h>
20
21#include <QtGui/qtextlayout.h>
22
24
25class QVideoFrame;
26class QTextLayout;
27class QVideoFrameTextures;
28using QVideoFrameTexturesUPtr = std::unique_ptr<QVideoFrameTextures>;
29class QVideoFrameTexturesHandles;
30using QVideoFrameTexturesHandlesUPtr = std::unique_ptr<QVideoFrameTexturesHandles>;
31
32namespace QVideoTextureHelper
33{
34
35struct Q_MULTIMEDIA_EXPORT TextureDescription
36{
37 static constexpr int maxPlanes = 3;
38 struct SizeScale {
39 int x;
40 int y;
41 };
42 using BytesRequired = int(*)(int stride, int height);
43
53
54 enum class FallbackPolicy {
57 };
58
60 QRhi *rhi,
62
63 inline int strideForWidth(int width) const { return (width*strideFactor + 15) & ~15; }
64 inline int bytesForSize(QSize s) const { return bytesRequired(strideForWidth(s.width()), s.height()); }
65 int widthForPlane(int width, int plane) const
66 {
67 if (plane > nplanes) return 0;
68 return (width + sizeScale[plane].x - 1)/sizeScale[plane].x;
69 }
70 int heightForPlane(int height, int plane) const
71 {
72 if (plane > nplanes) return 0;
73 return (height + sizeScale[plane].y - 1)/sizeScale[plane].y;
74 }
75
76 /**
77 * \returns Plane scaling factors taking into account possible workarounds due to QRhi backend
78 * capabilities.
79 */
81 {
82 if (!rhi)
83 return sizeScale[plane];
84
85 // NOTE: We need to handle sizing difference when packing two-component textures to RGBA8,
86 // where width gets cut in half.
87 // Another option would be to compare QRhiImplementation::TextureFormatInfo to expected
88 // based on TextureDescription::Format.
92 return { sizeScale[plane].x * 2, sizeScale[plane].y };
93
94 return sizeScale[plane];
95 }
96
102
104 {
106 return f == format;
107 });
108 }
109
115};
116
117Q_MULTIMEDIA_EXPORT const TextureDescription *textureDescription(QVideoFrameFormat::PixelFormat format);
118
119Q_MULTIMEDIA_EXPORT QString vertexShaderFileName(const QVideoFrameFormat &format);
120Q_MULTIMEDIA_EXPORT QString
123Q_MULTIMEDIA_EXPORT void updateUniformData(QByteArray *dst, QRhi *rhi,
124 const QVideoFrameFormat &format,
125 const QVideoFrame &frame, const QMatrix4x4 &transform,
126 float opacity, float maxNits = 100);
127
128/**
129 * @brief Creates plane textures from texture handles set by the specified rhi.
130 * The result owns the specified handles set; the QRhiTexture(s), exposed by the result
131 * refer to the owned handles set.
132 * If the specified size is empty or pixelFormat is invalid, null is returned.
133 */
134Q_MULTIMEDIA_EXPORT QVideoFrameTexturesUPtr
137
138
139/**
140 * @brief Creates plane textures from a video frame by the specified rhi.
141 If possible, the function modifies 'oldTextures', which is the texture from the pool,
142 and returns the specified one or a new one with any taken data.
143 */
144Q_MULTIMEDIA_EXPORT QVideoFrameTexturesUPtr createTextures(const QVideoFrame &frame, QRhi &rhi,
147
148/**
149 * @brief Returns a QRhiTexture::Format taking into account rhi capabilities and explicitly excluded
150 * formats using a chain of pre-defined fallback texture formats. If no valid fallback is
151 * determined, will return the format argument.
152 */
155
156Q_MULTIMEDIA_EXPORT void
157setExcludedRhiTextureFormats(QList<QRhiTexture::Format> formats); // for tests only
158
159Q_MULTIMEDIA_EXPORT bool
161
172
173struct Q_MULTIMEDIA_EXPORT SubtitleLayout
174{
178
179 bool update(const QSize &frameSize, QString text);
180 void draw(QPainter *painter, const QPointF &translate) const;
181 QImage toImage() const;
182};
183
184}
185
186QT_END_NAMESPACE
187
188#endif
QVideoFrameFormat format
QVideoFrame::MapMode mapMode
static QVideoFramePrivate * handle(QVideoFrame &frame)
static QAbstractVideoBuffer * buffer(const QVideoFrame &frame)
QAbstractVideoBuffer::MapData mapData
QVideoFramePrivate()=default
QHwVideoBuffer * hwVideoBuffer
QVideoFrame adoptThisByVideoFrame()
static QVideoFrame createFrame(std::unique_ptr< Buffer > buffer, QVideoFrameFormat format)
std::unique_ptr< QAbstractVideoBuffer > videoBuffer
VideoTransformation presentationTransformation
QVideoFramePrivate(QVideoFrameFormat format, std::unique_ptr< Buffer > buffer=nullptr)
static QHwVideoBuffer * hwBuffer(const QVideoFrame &frame)
static bool hasDmaBuf(const QVideoFrame &frame)
Q_MULTIMEDIA_EXPORT void setExcludedRhiTextureFormats(QList< QRhiTexture::Format > formats)
Q_MULTIMEDIA_EXPORT bool forceGlTextureExternalOesIsSet()
Q_MULTIMEDIA_EXPORT void updateUniformData(QByteArray *dst, QRhi *rhi, const QVideoFrameFormat &format, const QVideoFrame &frame, const QMatrix4x4 &transform, float opacity, float maxNits=100)
static QString qFormatTimeStamps(qint64 start, qint64 end)
int planeFormats[TextureDescription::maxPlanes]