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
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
55
56 inline int strideForWidth(int width) const { return (width*strideFactor + 15) & ~15; }
57 inline int bytesForSize(QSize s) const { return bytesRequired(strideForWidth(s.width()), s.height()); }
58 int widthForPlane(int width, int plane) const
59 {
60 if (plane > nplanes) return 0;
61 return (width + sizeScale[plane].x - 1)/sizeScale[plane].x;
62 }
63 int heightForPlane(int height, int plane) const
64 {
65 if (plane > nplanes) return 0;
66 return (height + sizeScale[plane].y - 1)/sizeScale[plane].y;
67 }
68
69 /**
70 * \returns Plane scaling factors taking into account possible workarounds due to QRhi backend
71 * capabilities.
72 */
74 {
75 if (!rhi)
76 return sizeScale[plane];
77
78 // NOTE: We need to handle sizing difference when packing two-component textures to RGBA8,
79 // where width gets cut in half.
80 // Another option would be to compare QRhiImplementation::TextureFormatInfo to expected
81 // based on TextureDescription::Format.
84 return { sizeScale[plane].x * 2, sizeScale[plane].y };
85
86 return sizeScale[plane];
87 }
88
94
96 {
98 return f == format;
99 });
100 }
101
107};
108
109Q_MULTIMEDIA_EXPORT const TextureDescription *textureDescription(QVideoFrameFormat::PixelFormat format);
110
111Q_MULTIMEDIA_EXPORT QString vertexShaderFileName(const QVideoFrameFormat &format);
112Q_MULTIMEDIA_EXPORT QString
115Q_MULTIMEDIA_EXPORT void updateUniformData(QByteArray *dst, QRhi *rhi,
116 const QVideoFrameFormat &format,
117 const QVideoFrame &frame, const QMatrix4x4 &transform,
118 float opacity, float maxNits = 100);
119
120/**
121 * @brief Creates plane textures from texture handles set by the specified rhi.
122 * The result owns the specified handles set; the QRhiTexture(s), exposed by the result
123 * refer to the owned handles set.
124 * If the specified size is empty or pixelFormat is invalid, null is returned.
125 */
126Q_MULTIMEDIA_EXPORT QVideoFrameTexturesUPtr
129
130
131/**
132 * @brief Creates plane textures from a video frame by the specified rhi.
133 If possible, the function modifies 'oldTextures', which is the texture from the pool,
134 and returns the specified one or a new one with any taken data.
135 */
136Q_MULTIMEDIA_EXPORT QVideoFrameTexturesUPtr createTextures(const QVideoFrame &frame, QRhi &rhi,
139
140Q_MULTIMEDIA_EXPORT void
141setExcludedRhiTextureFormats(QList<QRhiTexture::Format> formats); // for tests only
142
153
154struct Q_MULTIMEDIA_EXPORT SubtitleLayout
155{
159
160 bool update(const QSize &frameSize, QString text);
161 void draw(QPainter *painter, const QPointF &translate) const;
162 QImage toImage() const;
163};
164
165}
166
167QT_END_NAMESPACE
168
169#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)
Combined button and popup list for selecting options.
Q_MULTIMEDIA_EXPORT void setExcludedRhiTextureFormats(QList< QRhiTexture::Format > formats)
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]