1// Copyright (C) 2024 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 QHWVIDEOBUFFER_P_H
5#define QHWVIDEOBUFFER_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 "qabstractvideobuffer.h"
19#include "qvideoframe.h"
20
21#include <QtGui/qmatrix4x4.h>
22
23QT_BEGIN_NAMESPACE
24
25class QRhi;
26class QRhiTexture;
27class QVideoFrame;
28
29/**
30 * @brief QVideoFrameTexturesHandles is the base class, providing texture handles for frame planes.
31 * Instances of the class may own textures, share ownership, or refer to inner hw textures
32 * of QVideoFrame. Referencing to inner frame's textures without shared ownership is
33 * not recommended, we strive to get around it; if texture are referencing,
34 * the source frame must be kept in QVideoFrameTextures's instance
35 * (see QVideoFrameTextures::setSourceFrame).
36 */
37class Q_MULTIMEDIA_EXPORT QVideoFrameTexturesHandles
38{
39public:
40 virtual ~QVideoFrameTexturesHandles();
41
42 virtual quint64 textureHandle(QRhi &, int /*plane*/) { return 0; };
43};
44using QVideoFrameTexturesHandlesUPtr = std::unique_ptr<QVideoFrameTexturesHandles>;
45
46/**
47 * @brief QVideoFrameTextures is the base class representing an abstraction layer
48 * between QVideoFrame's texture(s) and rhi's plane textures.
49 * QVideoFrameTextures must own the inner rhi textures or
50 * share ownership. QVideoFrameTextures instances are propagated to
51 * QVideoFrameTexturesPool, where their lifetime is managed
52 * according to results of QRhi::currentFrameSlot upon rendering.
53 *
54 */
55class Q_MULTIMEDIA_EXPORT QVideoFrameTextures
56{
57public:
58 virtual ~QVideoFrameTextures();
59 virtual QRhiTexture *texture(uint plane) const = 0;
60
61 /**
62 * @brief The virtual method should be invoked after QRhi::endFrame to unmap and free
63 * internal resources that are not needed anymore.
64 */
65 virtual void onFrameEndInvoked() { }
66
67 virtual QVideoFrameTexturesHandlesUPtr takeHandles() { return nullptr; }
68
69 /**
70 * @brief Sets the source frame. It is a temporary solution to delegate
71 * frame's shared ownership to the instance.
72 * Ideally, the creators of QVideoFrameTextures's or QVideoFrameTexturesHandles's
73 * instances should manage ownership.
74 */
75 void setSourceFrame(QVideoFrame sourceFrame) { m_sourceFrame = std::move(sourceFrame); }
76
77private:
78 QVideoFrame m_sourceFrame;
79};
80using QVideoFrameTexturesUPtr = std::unique_ptr<QVideoFrameTextures>;
81
82class Q_MULTIMEDIA_EXPORT QHwVideoBuffer : public QAbstractVideoBuffer,
83 public QVideoFrameTexturesHandles
84{
85public:
86 QHwVideoBuffer(QVideoFrame::HandleType type, QRhi *rhi = nullptr);
87
88 ~QHwVideoBuffer() override;
89
90 QVideoFrame::HandleType handleType() const { return m_type; }
91 virtual QRhi *rhi() const { return m_rhi; }
92
93 QVideoFrameFormat format() const override { return {}; }
94
95 virtual QMatrix4x4 externalTextureMatrix() const { return {}; }
96
97 virtual QVideoFrameTexturesUPtr mapTextures(QRhi &, QVideoFrameTexturesUPtr& /*oldTextures*/) { return nullptr; };
98
99 virtual void initTextureConverter(QRhi &) { }
100
101protected:
102 QVideoFrame::HandleType m_type;
103 QRhi *m_rhi = nullptr;
104};
105
106QT_END_NAMESPACE
107
108#endif // QHWVIDEOBUFFER_P_H
109

source code of qtmultimedia/src/multimedia/video/qhwvideobuffer_p.h