Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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#include <mutex>
24
26
27class QRhi;
28class QRhiTexture;
30
31namespace QFFmpeg {
32
33// used for the get_format callback for the decoder
34enum AVPixelFormat getFormat(struct AVCodecContext *s, const enum AVPixelFormat * fmt);
35
36class HWAccel;
37
39public:
40 // ### Should add QVideoFrameFormat::PixelFormat here
41 virtual ~TextureSet() {}
42 virtual qint64 textureHandle(QRhi *, int /*plane*/) { return 0; }
43};
44
46{
47public:
52 virtual TextureSet *getTextures(AVFrame * /*frame*/) { return nullptr; }
53
54 QRhi *rhi = nullptr;
55};
56
58{
59 class Data final
60 {
61 public:
62 QAtomicInt ref = 0;
63 QRhi *rhi = nullptr;
64 AVPixelFormat format = AV_PIX_FMT_NONE;
65 std::unique_ptr<TextureConverterBackend> backend;
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
81 QExplicitlySharedDataPointer<Data> d;
82};
83
85{
86 AVBufferUPtr m_hwDeviceContext;
87 AVBufferUPtr m_hwFramesContext;
88
89 mutable std::once_flag m_constraintsOnceFlag;
90 mutable AVHWFramesConstraintsUPtr m_constraints;
91
92public:
94
95 static std::unique_ptr<HWAccel> create(AVHWDeviceType deviceType);
96
97 static std::pair<const AVCodec *, std::unique_ptr<HWAccel>>
98 findEncoderWithHwAccel(AVCodecID id,
99 const std::function<bool(const HWAccel &)>& hwAccelPredicate = nullptr);
100
101 static std::pair<const AVCodec *, std::unique_ptr<HWAccel>>
102 findDecoderWithHwAccel(AVCodecID id,
103 const std::function<bool(const HWAccel &)>& hwAccelPredicate = nullptr);
104
105 AVHWDeviceType deviceType() const;
106
107 AVBufferRef *hwDeviceContextAsBuffer() const { return m_hwDeviceContext.get(); }
108 AVHWDeviceContext *hwDeviceContext() const;
109 AVPixelFormat hwFormat() const;
110 const AVHWFramesConstraints *constraints() const;
111
112 void createFramesContext(AVPixelFormat swFormat, const QSize &size);
113 AVBufferRef *hwFramesContextAsBuffer() const { return m_hwFramesContext.get(); }
114 AVHWFramesContext *hwFramesContext() const;
115
116 static AVPixelFormat format(AVFrame *frame);
117 static const std::vector<AVHWDeviceType> &encodingDeviceTypes();
118
119 static const std::vector<AVHWDeviceType> &decodingDeviceTypes();
120
121private:
122 HWAccel(AVBufferUPtr hwDeviceContext) : m_hwDeviceContext(std::move(hwDeviceContext)) { }
123};
124
125}
126
128
129#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
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
const AVHWFramesConstraints * constraints() const
AVHWDeviceContext * hwDeviceContext() const
AVPixelFormat hwFormat() const
AVHWDeviceType deviceType() const
virtual TextureSet * getTextures(AVFrame *)
TextureSet * getTextures(AVFrame *frame)
void init(AVFrame *frame)
TextureConverter(QRhi *rhi=nullptr)
virtual qint64 textureHandle(QRhi *, int)
\inmodule QtGui
Definition qrhi.h:895
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1804
\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:151
AVPixelFormat getFormat(AVCodecContext *codecContext, const AVPixelFormat *suggestedFormats)
std::unique_ptr< AVBufferRef, AVDeleter< decltype(&av_buffer_unref), &av_buffer_unref > > AVBufferUPtr
Definition qffmpeg_p.h:148
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:60
QVideoFrameFormat::PixelFormat fmt
QFrame frame
[0]
view create()