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 "qvideoframeformat.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;
32class QFFmpegVideoBuffer;
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;
42using HWAccelUPtr = std::unique_ptr<HWAccel>;
43
44/**
45 * @brief The HwFrameContextData class contains custom belongings
46 * of hw frames context.
47 */
48struct HwFrameContextData
49{
50 QRhiValueMapper<TextureConverter> textureConverterMapper;
51
52 /**
53 * @brief gets or creates an instance of the class, associated with
54 * the frames context of the specified frame. Note, AVFrame
55 * holds shared ownership of the frames context, so consider this
56 * when designing HwFrameContextData's lifetime.
57 */
58 static HwFrameContextData &ensure(AVFrame &hwFrame);
59};
60
61class HWAccel
62{
63 AVBufferUPtr m_hwDeviceContext;
64 AVBufferUPtr m_hwFramesContext;
65
66 mutable std::once_flag m_constraintsOnceFlag;
67 mutable AVHWFramesConstraintsUPtr m_constraints;
68
69public:
70 ~HWAccel();
71
72 static HWAccelUPtr create(AVHWDeviceType deviceType);
73
74 static std::pair<std::optional<Codec>, HWAccelUPtr> findDecoderWithHwAccel(AVCodecID id);
75
76 AVHWDeviceType deviceType() const;
77
78 AVBufferRef *hwDeviceContextAsBuffer() const { return m_hwDeviceContext.get(); }
79 AVHWDeviceContext *hwDeviceContext() const;
80 AVPixelFormat hwFormat() const;
81 const AVHWFramesConstraints *constraints() const;
82
83 bool matchesSizeContraints(QSize size) const;
84
85 void createFramesContext(AVPixelFormat swFormat, const QSize &size);
86 AVBufferRef *hwFramesContextAsBuffer() const { return m_hwFramesContext.get(); }
87 AVHWFramesContext *hwFramesContext() const;
88
89 static AVPixelFormat format(AVFrame *frame);
90 static const std::vector<AVHWDeviceType> &encodingDeviceTypes();
91
92 static const std::vector<AVHWDeviceType> &decodingDeviceTypes();
93
94private:
95 HWAccel(AVBufferUPtr hwDeviceContext) : m_hwDeviceContext(std::move(hwDeviceContext)) { }
96};
97
98AVFrameUPtr copyFromHwPool(AVFrameUPtr frame);
99
100} // namespace QFFmpeg
101
102QT_END_NAMESPACE
103
104#endif
105

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of qtmultimedia/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_p.h