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>
20#include <QtMultimedia/private/qhwvideobuffer_p.h>
21#include <QtMultimedia/private/qrhivaluemapper_p.h>
22
23#include <qshareddata.h>
24#include <memory>
25#include <functional>
26#include <mutex>
27
28QT_BEGIN_NAMESPACE
29
30class QRhi;
31class QRhiTexture;
33
34namespace QFFmpeg {
35
36// used for the get_format callback for the decoder
37AVPixelFormat getFormat(AVCodecContext *s, const AVPixelFormat *fmt);
38
39class HWAccel;
40
41class HWAccel;
43
44/**
45 * @brief The HwFrameContextData class contains custom belongings
46 * of hw frames context.
47 */
49{
50 using AVHWFramesContextDeleter = void (*)(struct AVHWFramesContext *ctx);
51 AVHWFramesContextDeleter avDeleter = nullptr;
52 void *avUserOpaque = nullptr;
53
55
56 /**
57 * @brief gets or creates an instance of the class, associated with
58 * the frames context of the specified frame. Note, AVFrame
59 * holds shared ownership of the frames context, so consider this
60 * when designing HwFrameContextData's lifetime.
61 */
62 static HwFrameContextData &ensure(AVFrame &hwFrame);
63};
64
66{
67 AVBufferUPtr m_hwDeviceContext;
68 AVBufferUPtr m_hwFramesContext;
69
70 mutable std::once_flag m_constraintsOnceFlag;
71 mutable AVHWFramesConstraintsUPtr m_constraints;
72
73public:
75
76 static HWAccelUPtr create(AVHWDeviceType deviceType);
77
79
81
82 AVBufferRef *hwDeviceContextAsBuffer() const { return m_hwDeviceContext.get(); }
84 AVPixelFormat hwFormat() const;
86
87 bool matchesSizeContraints(QSize size) const;
88
89 void createFramesContext(AVPixelFormat swFormat, const QSize &size);
90 AVBufferRef *hwFramesContextAsBuffer() const { return m_hwFramesContext.get(); }
91 AVHWFramesContext *hwFramesContext() const;
92
93 static AVPixelFormat format(AVFrame *frame);
95
97
98private:
99 HWAccel(AVBufferUPtr hwDeviceContext) : m_hwDeviceContext(std::move(hwDeviceContext)) { }
100};
101
102AVFrameUPtr copyFromHwPool(AVFrameUPtr frame);
103
104} // namespace QFFmpeg
105
106QT_END_NAMESPACE
107
108#endif
AVHWFramesContext * hwFramesContext() const
bool matchesSizeContraints(QSize size) const
static const std::vector< AVHWDeviceType > & decodingDeviceTypes()
AVBufferRef * hwFramesContextAsBuffer() const
static const std::vector< AVHWDeviceType > & encodingDeviceTypes()
void createFramesContext(AVPixelFormat swFormat, const QSize &size)
static AVPixelFormat format(AVFrame *frame)
AVBufferRef * hwDeviceContextAsBuffer() const
static HWAccelUPtr create(AVHWDeviceType deviceType)
const AVHWFramesConstraints * constraints() const
AVHWDeviceContext * hwDeviceContext() const
AVPixelFormat hwFormat() const
static std::pair< std::optional< Codec >, HWAccelUPtr > findDecoderWithHwAccel(AVCodecID id)
AVHWDeviceType deviceType() const
AVPixelFormat getFormat(AVCodecContext *s, const AVPixelFormat *fmt)
AVFrameUPtr copyFromHwPool(AVFrameUPtr frame)
bool findAndOpenAVDecoder(AVCodecID codecId, const std::function< AVScore(const Codec &)> &scoresGetter, const std::function< bool(const Codec &)> &codecOpener)
std::conditional_t< QT_FFMPEG_AVIO_WRITE_CONST, const uint8_t *, uint8_t * > AvioWriteBufferType
std::optional< Codec > findAVEncoder(AVCodecID codecId, const std::optional< PixelOrSampleFormat > &format={})
bool findAndOpenAVEncoder(AVCodecID codecId, const std::function< AVScore(const Codec &)> &scoresGetter, const std::function< bool(const Codec &)> &codecOpener)
std::optional< Codec > findAVDecoder(AVCodecID codecId, const std::optional< PixelOrSampleFormat > &format={})
#define qCDebug(category,...)
#define Q_STATIC_LOGGING_CATEGORY(name,...)
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