Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qffmpegtextureconverter_p.h
Go to the documentation of this file.
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
QFFMPEGTEXTURECONVERTER_P_H
5
#
define
QFFMPEGTEXTURECONVERTER_P_H
6
7
#
include
<
QtFFmpegMediaPluginImpl
/
private
/
qffmpegdefs_p
.
h
>
8
#
include
<
QtMultimedia
/
private
/
qhwvideobuffer_p
.
h
>
9
10
#
include
<
memory
>
11
12
//
13
// W A R N I N G
14
// -------------
15
//
16
// This file is not part of the Qt API. It exists purely as an
17
// implementation detail. This header file may change from version to
18
// version without notice, or even be removed.
19
//
20
// We mean it.
21
//
22
23
QT_BEGIN_NAMESPACE
24
25
class
QRhi;
26
27
namespace
QFFmpeg
{
28
29
/**
30
* @brief The base class for platform-specific implementations of TextureConverter
31
* One of two virtual methods, createTextures and createTextureHandles, must be overridden.
32
* If the implementation operates with QRhiTexture under the hood, overriding of
33
* createTextures is prefferable, otherwise expose texture handles of native textures
34
* by createTextureHandles.
35
*/
36
class
TextureConverterBackend
:
public
std
::
enable_shared_from_this
<
TextureConverterBackend
>
37
{
38
public
:
39
TextureConverterBackend
(QRhi *rhi) :
rhi
(rhi) { }
40
41
virtual
~
TextureConverterBackend
();
42
43
virtual
QVideoFrameTexturesUPtr
createTextures
(AVFrame *hwFrame,
44
QVideoFrameTexturesUPtr &
/*oldTextures*/
)
45
{
46
return
createTextures(hwFrame);
47
}
48
virtual
QVideoFrameTexturesUPtr
createTextures
(AVFrame *
/*hwFrame*/
) {
return
nullptr
; }
49
50
virtual
QVideoFrameTexturesHandlesUPtr
51
createTextureHandles
(AVFrame *hwFrame,
QVideoFrameTexturesHandlesUPtr
/*oldHandles*/
)
52
{
53
return
createTextureHandles(hwFrame);
54
}
55
56
virtual
QVideoFrameTexturesHandlesUPtr
createTextureHandles
(AVFrame *
/*hwFrame*/
)
57
{
58
return
nullptr
;
59
}
60
61
/**
62
* @brief Points to the matching QRhi.
63
* If the constructor, createTextures, or createTextureHandles get failed without
64
* chances for recovery, it may set the pointer to nullptr, which will invalidate
65
* the parent TextureConverter, and textures creation won't be invoked anymore.
66
*/
67
QRhi *
rhi
=
nullptr
;
68
};
69
using
TextureConverterBackendPtr
=
std
::shared_ptr<
TextureConverterBackend
>;
70
71
/**
72
* @brief The TextureConverter class implements conversion of AVFrame hw textures to
73
* textures for rendering by the specified QRhi. Any instance of TextureConverter
74
* matches the pair of FFmpeg hw frames context + QRhi.
75
*/
76
class
TextureConverter
77
{
78
public
:
79
/**
80
* @brief Construct uninitialized texture converter for the specified QRhi
81
*/
82
TextureConverter
(QRhi &rhi);
83
84
/**
85
* @brief Initializes the instance of the texture converter for the frame context
86
* associated with the specified frame. The method tries to initialize
87
* the conversion backend during the first call with the specified frame format.
88
* If frame format is not changed, the method does nothing even if the first
89
* attempt failed.
90
* @return Whether the instance has been initialized.
91
*/
92
bool
init
(AVFrame &hwFrame);
93
94
/**
95
* @brief Creates video frame textures basing on the current hw frame and the previous textures
96
* from the texture pool. We should strive to reuse oldTextures if we can do so.
97
* If the method returns null, try createTextureHandles.
98
*/
99
QVideoFrameTexturesUPtr
createTextures
(AVFrame &hwFrame, QVideoFrameTexturesUPtr &oldTextures);
100
101
/**
102
* @brief Creates video frame texture handles basing on the current hw frame and the previous
103
* texture handles from the pool. We should strive to reuse oldHandles if we can do so.
104
*/
105
QVideoFrameTexturesHandlesUPtr
createTextureHandles
(AVFrame &hwFrame,
106
QVideoFrameTexturesHandlesUPtr oldHandles);
107
108
/**
109
* @brief Indicates whether the texture converter is not initialized or the initialization
110
* failed. If hw texture conversion is disabled, it always true.
111
*/
112
bool
isNull
()
const
{
return
!m_backend || !m_backend->rhi; }
113
114
/**
115
* @brief Applies platform-specific hw texture conversion presets for a decoder.
116
* The function is supposed to be invoked for the get_format callback.
117
*/
118
static
void
applyDecoderPreset
(AVPixelFormat format, AVCodecContext &codecContext);
119
120
/**
121
* @brief Indicates whether hw texture conversion is enabled for the application.
122
*/
123
static
bool
hwTextureConversionEnabled
();
124
125
/**
126
* @brief Indicates whether the matching textute converter backend can be created.
127
* If isBackendAvailable returns false, instances cannot be initialized with
128
* the specified frame. If it returns true, init will attempt to create backend,
129
* but it may fail if something goes wrong in the backend.
130
*/
131
static
bool
isBackendAvailable
(AVFrame &hwFrame, QRhi &rhi);
132
133
private
:
134
void
updateBackend(AVFrame &hwFrame);
135
136
private
:
137
QRhi &m_rhi;
138
AVPixelFormat m_format =
AV_PIX_FMT_NONE
;
139
TextureConverterBackendPtr
m_backend;
140
};
141
142
}
// namespace QFFmpeg
143
144
QT_END_NAMESPACE
145
146
#
endif
// QFFMPEGTEXTURECONVERTER_P_H
QFFmpeg::TextureConverterBackend
The base class for platform-specific implementations of TextureConverter One of two virtual methods,...
Definition
qffmpegtextureconverter_p.h:37
QFFmpeg::TextureConverterBackend::TextureConverterBackend
TextureConverterBackend(QRhi *rhi)
Definition
qffmpegtextureconverter_p.h:39
QFFmpeg::TextureConverterBackend::createTextureHandles
virtual QVideoFrameTexturesHandlesUPtr createTextureHandles(AVFrame *)
Definition
qffmpegtextureconverter_p.h:56
QFFmpeg::TextureConverterBackend::createTextureHandles
virtual QVideoFrameTexturesHandlesUPtr createTextureHandles(AVFrame *hwFrame, QVideoFrameTexturesHandlesUPtr)
Definition
qffmpegtextureconverter_p.h:51
QFFmpeg::TextureConverterBackend::~TextureConverterBackend
virtual ~TextureConverterBackend()
QFFmpeg::TextureConverterBackend::createTextures
virtual QVideoFrameTexturesUPtr createTextures(AVFrame *hwFrame, QVideoFrameTexturesUPtr &)
Definition
qffmpegtextureconverter_p.h:43
QFFmpeg::TextureConverterBackend::createTextures
virtual QVideoFrameTexturesUPtr createTextures(AVFrame *)
Definition
qffmpegtextureconverter_p.h:48
QFFmpeg::TextureConverterBackend::rhi
QRhi * rhi
Points to the matching QRhi. If the constructor, createTextures, or createTextureHandles get failed w...
Definition
qffmpegtextureconverter_p.h:67
QFFmpeg::TextureConverter
The TextureConverter class implements conversion of AVFrame hw textures to textures for rendering by ...
Definition
qffmpegtextureconverter_p.h:77
QFFmpeg::TextureConverter::createTextureHandles
QVideoFrameTexturesHandlesUPtr createTextureHandles(AVFrame &hwFrame, QVideoFrameTexturesHandlesUPtr oldHandles)
Creates video frame texture handles basing on the current hw frame and the previous texture handles f...
Definition
qffmpegtextureconverter.cpp:106
QFFmpeg::TextureConverter::TextureConverter
TextureConverter(QRhi &rhi)
Construct uninitialized texture converter for the specified QRhi.
Definition
qffmpegtextureconverter.cpp:85
QFFmpeg::TextureConverter::isNull
bool isNull() const
Indicates whether the texture converter is not initialized or the initialization failed....
Definition
qffmpegtextureconverter_p.h:112
QFFmpeg::TextureConverter::isBackendAvailable
static bool isBackendAvailable(AVFrame &hwFrame, QRhi &rhi)
Indicates whether the matching textute converter backend can be created. If isBackendAvailable return...
Definition
qffmpegtextureconverter.cpp:155
QFFmpeg::TextureConverter::applyDecoderPreset
static void applyDecoderPreset(AVPixelFormat format, AVCodecContext &codecContext)
Applies platform-specific hw texture conversion presets for a decoder. The function is supposed to be...
Definition
qffmpegtextureconverter.cpp:136
QFFmpeg::TextureConverter::init
bool init(AVFrame &hwFrame)
Initializes the instance of the texture converter for the frame context associated with the specified...
Definition
qffmpegtextureconverter.cpp:87
QFFmpeg::TextureConverter::createTextures
QVideoFrameTexturesUPtr createTextures(AVFrame &hwFrame, QVideoFrameTexturesUPtr &oldTextures)
Creates video frame textures basing on the current hw frame and the previous textures from the textur...
Definition
qffmpegtextureconverter.cpp:95
QFFmpeg::TextureConverter::hwTextureConversionEnabled
static bool hwTextureConversionEnabled()
Indicates whether hw texture conversion is enabled for the application.
Definition
qffmpegtextureconverter.cpp:126
QFFmpeg
Definition
qandroidcacertificates.cpp:26
QFFmpeg::TextureConverterBackendPtr
std::shared_ptr< TextureConverterBackend > TextureConverterBackendPtr
Definition
qffmpegtextureconverter_p.h:69
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
qtmultimedia
src
plugins
multimedia
ffmpeg
qffmpegtextureconverter_p.h
Generated on
for Qt by
1.18.0