Qt 6.x
The Qt SDK
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 "qffmpeg_p.h"
18#include "qvideoframeformat.h"
19#include <private/qabstractvideobuffer_p.h>
20#include <qshareddata.h>
21#include <memory>
22#include <functional>
23
25
26class QRhi;
27class QRhiTexture;
29
30namespace QFFmpeg {
31
32// used for the get_format callback for the decoder
33enum AVPixelFormat getFormat(struct AVCodecContext *s, const enum AVPixelFormat * fmt);
34
35class HWAccel;
36
38public:
39 // ### Should add QVideoFrameFormat::PixelFormat here
40 virtual ~TextureSet() {}
41 virtual qint64 textureHandle(int /*plane*/) { return 0; }
42};
43
45{
46public:
48 : rhi(rhi)
49 {}
51 virtual TextureSet *getTextures(AVFrame * /*frame*/) { return nullptr; }
52
53 QRhi *rhi = nullptr;
54};
55
57{
58 class Data final
59 {
60 public:
61 ~Data();
62 QAtomicInt ref = 0;
63 QRhi *rhi = nullptr;
64 AVPixelFormat format = AV_PIX_FMT_NONE;
65 TextureConverterBackend *backend = nullptr;
66 };
67public:
68 TextureConverter(QRhi *rhi = nullptr);
69
70 void init(AVFrame *frame) {
71 AVPixelFormat fmt = frame ? AVPixelFormat(frame->format) : AV_PIX_FMT_NONE;
72 if (fmt != d->format)
73 updateBackend(fmt);
74 }
75 TextureSet *getTextures(AVFrame *frame);
76 bool isNull() const { return !d->backend || !d->backend->rhi; }
77
78private:
79 void updateBackend(AVPixelFormat format);
80
82};
83
85{
86 AVBufferUPtr m_hwDeviceContext;
87 AVBufferUPtr m_hwFramesContext;
88
89public:
91
92 static std::unique_ptr<HWAccel> create(AVHWDeviceType deviceType);
93
94 static std::pair<const AVCodec *, std::unique_ptr<HWAccel>>
95 findEncoderWithHwAccel(AVCodecID id,
96 const std::function<bool(const HWAccel &)>& hwAccelPredicate = nullptr);
97
98 static std::pair<const AVCodec *, std::unique_ptr<HWAccel>>
99 findDecoderWithHwAccel(AVCodecID id,
100 const std::function<bool(const HWAccel &)>& hwAccelPredicate = nullptr);
101
102 AVHWDeviceType deviceType() const;
103
104 AVBufferRef *hwDeviceContextAsBuffer() const { return m_hwDeviceContext.get(); }
105 AVHWDeviceContext *hwDeviceContext() const;
106 AVPixelFormat hwFormat() const;
108
109 void createFramesContext(AVPixelFormat swFormat, const QSize &size);
110 AVBufferRef *hwFramesContextAsBuffer() const { return m_hwFramesContext.get(); }
111 AVHWFramesContext *hwFramesContext() const;
112
113 static AVPixelFormat format(AVFrame *frame);
114 static const std::vector<AVHWDeviceType> &encodingDeviceTypes();
115
116 static const std::vector<AVHWDeviceType> &decodingDeviceTypes();
117
118private:
119 HWAccel(AVBufferRef *hwDeviceContext, AVBufferRef *hwFrameContext = nullptr)
120 : m_hwDeviceContext(hwDeviceContext), m_hwFramesContext(hwFrameContext)
121 {}
122};
123
124}
125
127
128#endif
\inmodule QtCore
Definition qatomic.h:112
static std::pair< const AVCodec *, std::unique_ptr< HWAccel > > findDecoderWithHwAccel(AVCodecID id, const std::function< bool(const HWAccel &)> &hwAccelPredicate=nullptr)
AVHWFramesContext * hwFramesContext() const
AVHWFramesConstraintsUPtr constraints() const
static const std::vector< AVHWDeviceType > & decodingDeviceTypes()
AVBufferRef * hwFramesContextAsBuffer() const
static const std::vector< AVHWDeviceType > & encodingDeviceTypes()
void createFramesContext(AVPixelFormat swFormat, const QSize &size)
static std::pair< const AVCodec *, std::unique_ptr< HWAccel > > findEncoderWithHwAccel(AVCodecID id, const std::function< bool(const HWAccel &)> &hwAccelPredicate=nullptr)
AVBufferRef * hwDeviceContextAsBuffer() const
AVHWDeviceContext * hwDeviceContext() const
AVPixelFormat hwFormat() const
AVHWDeviceType deviceType() const
virtual TextureSet * getTextures(AVFrame *)
TextureSet * getTextures(AVFrame *frame)
void init(AVFrame *frame)
virtual qint64 textureHandle(int)
\inmodule QtGui
Definition qrhi.h:883
\inmodule QtGui
Definition qrhi.h:1767
\inmodule QtCore
Definition qsize.h:25
std::unique_ptr< AVHWFramesConstraints, AVDeleter< decltype(&av_hwframe_constraints_free), &av_hwframe_constraints_free > > AVHWFramesConstraintsUPtr
Definition qffmpeg_p.h:136
AVPixelFormat getFormat(AVCodecContext *codecContext, const AVPixelFormat *suggestedFormats)
std::unique_ptr< AVBufferRef, AVDeleter< decltype(&av_buffer_unref), &av_buffer_unref > > AVBufferUPtr
Definition qffmpeg_p.h:132
Combined button and popup list for selecting options.
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint ref
GLint GLsizei GLsizei GLenum format
GLdouble s
[6]
Definition qopenglext.h:235
long long qint64
Definition qtypes.h:55
QVideoFrameFormat::PixelFormat fmt
QFrame frame
[0]
view create()