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
qffmpeghwaccel_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#ifndef QFFMPEGHWACCEL_P_H
4#define QFFMPEGHWACCEL_P_H
5
6//
7// W A R N I N G
8// -------------
9//
10// This file is not part of the Qt API. It exists purely as an
11// implementation detail. This header file may change from version to
12// version without notice, or even be removed.
13//
14// We mean it.
15//
16
17#include <QtFFmpegMediaPluginImpl/private/qffmpeg_p.h>
18#include <QtFFmpegMediaPluginImpl/private/qffmpegtextureconverter_p.h>
19#include <QtMultimedia/qvideoframeformat.h>
20#include <QtMultimedia/private/qhwvideobuffer_p.h>
21#include <QtMultimedia/private/qrhivaluemapper_p.h>
22#include <QtCore/qspan.h>
23
24#include <memory>
25#include <mutex>
26
27QT_BEGIN_NAMESPACE
28
29class QRhi;
30class QRhiTexture;
32
33namespace QFFmpeg {
34
35// used for the get_format callback for the decoder
36AVPixelFormat getFormat(AVCodecContext *s, const AVPixelFormat *fmt);
37
38class HWAccel;
40
41/**
42 * @brief The HwFrameContextData class contains custom belongings
43 * of hw frames context.
44 */
46{
47 using AVHWFramesContextDeleter = void (*)(struct AVHWFramesContext *ctx);
48 AVHWFramesContextDeleter avDeleter = nullptr;
49 void *avUserOpaque = nullptr;
50
52
53 /**
54 * @brief gets or creates an instance of the class, associated with
55 * the frames context of the specified frame. Note, AVFrame
56 * holds shared ownership of the frames context, so consider this
57 * when designing HwFrameContextData's lifetime.
58 */
59 static HwFrameContextData &ensure(AVFrame &hwFrame);
60};
61
63{
64 const AVBufferUPtr m_hwDeviceContext;
65 AVBufferUPtr m_hwFramesContext;
66
67 mutable std::once_flag m_constraintsOnceFlag;
68 mutable AVHWFramesConstraintsUPtr m_constraints;
69
70public:
72
73 static HWAccelUPtr create(AVHWDeviceType deviceType);
74
75 static std::pair<std::optional<Codec>, HWAccelUPtr> findDecoderWithHwAccel(AVCodecID id);
76
78
79 AVBufferRef *hwDeviceContextAsBuffer() const { return m_hwDeviceContext.get(); }
81 AVPixelFormat hwFormat() const;
83
84 bool matchesSizeContraints(QSize size) const;
85
86 void createFramesContext(AVPixelFormat swFormat, const QSize &size);
88 void updateFramesContext(AVPixelFormat swFormat, const QSize &size);
89 AVBufferRef *hwFramesContextAsBuffer() const { return m_hwFramesContext.get(); }
90 AVHWFramesContext *hwFramesContext() const;
91
92 static AVPixelFormat format(AVFrame *frame);
95
96private:
97 HWAccel(AVBufferUPtr hwDeviceContext) : m_hwDeviceContext(std::move(hwDeviceContext)) { }
98};
99
100AVFrameUPtr copyFromHwPool(AVFrameUPtr frame);
101
102} // namespace QFFmpeg
103
104QT_END_NAMESPACE
105
106#endif
AVHWFramesContext * hwFramesContext() const
static QSpan< const AVHWDeviceType > encodingDeviceTypes()
bool matchesSizeContraints(QSize size) const
AVBufferRef * hwFramesContextAsBuffer() const
static QSpan< const AVHWDeviceType > decodingDeviceTypes()
void createFramesContext(AVPixelFormat swFormat, const QSize &size)
static AVPixelFormat format(AVFrame *frame)
AVBufferRef * hwDeviceContextAsBuffer() const
static HWAccelUPtr create(AVHWDeviceType deviceType)
const AVHWFramesConstraints * constraints() const
void updateFramesContext(AVPixelFormat swFormat, const QSize &size)
AVHWDeviceContext * hwDeviceContext() const
AVPixelFormat hwFormat() const
AVHWDeviceType deviceType() const
AVCodecCapabilities
Definition qffmpeg_p.h:354
AVFrameUPtr copyFromHwPool(AVFrameUPtr frame)
AVPixelFormat getFormat(AVCodecContext *codecContext, const AVPixelFormat *fmt)
Definition qcompare.h:111
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)
The HwFrameContextData class contains custom belongings of hw frames context.
static HwFrameContextData & ensure(AVFrame &hwFrame)
gets or creates an instance of the class, associated with the frames context of the specified frame....
AVHWFramesContextDeleter avDeleter
QRhiValueMapper< TextureConverter > textureConverterMapper