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_d3d11_p.h
Go to the documentation of this file.
1// Copyright (C) 2022 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_D3D11_P_H
4#define QFFMPEGHWACCEL_D3D11_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/qffmpeghwaccel_p.h>
18#include <QtCore/private/quniquehandle_types_p.h>
19#include <QtCore/private/qcomptr_p.h>
20
21#include <d3d11.h>
22#include <d3d11_1.h>
23
24#ifdef Q_OS_WINDOWS
25
26QT_BEGIN_NAMESPACE
27
28class QRhi;
29
30namespace QFFmpeg {
31
32using SharedTextureHandle = QUniqueWin32NullHandle;
33
34/*! \internal Utility class for synchronized transfer of a texture between two D3D devices
35 *
36 * This class is used to copy a texture from one device to another device. This
37 * is implemented using a shared texture, along with keyed mutexes to synchronize
38 * access to the texture.
39 *
40 * This is needed because we need to copy data from FFmpeg to RHI. FFmpeg and RHI
41 * uses different D3D devices.
42 */
43class TextureBridge final
44{
45public:
46 /** Copy a texture slice at position 'index' belonging to device 'dev'
47 * into a shared texture, limiting the texture size to the frame size */
48 bool copyToSharedTex(ID3D11Device *dev, ID3D11DeviceContext *ctx,
49 const ComPtr<ID3D11Texture2D> &tex, UINT index, const QSize &frameSize);
50
51 /** Obtain a copy of the texture on a second device 'dev'.
52 * NOTE: Will block until a texture is available (copyToSharedTex was called) */
53 ComPtr<ID3D11Texture2D> copyFromSharedTex(const ComPtr<ID3D11Device1> &dev,
54 const ComPtr<ID3D11DeviceContext> &ctx);
55
56private:
57 bool ensureDestTex(const ComPtr<ID3D11Device1> &dev);
58 bool ensureSrcTex(ID3D11Device *dev, const ComPtr<ID3D11Texture2D> &tex, const QSize &frameSize);
59 bool isSrcInitialized(const ID3D11Device *dev, const ComPtr<ID3D11Texture2D> &tex, const QSize &frameSize) const;
60 bool recreateSrc(ID3D11Device *dev, const ComPtr<ID3D11Texture2D> &tex, const QSize &frameSize);
61
62 SharedTextureHandle m_sharedHandle{};
63
64 const UINT m_srcKey = 0;
65 ComPtr<ID3D11Texture2D> m_srcTex;
66 ComPtr<IDXGIKeyedMutex> m_srcMutex;
67
68 const UINT m_destKey = 1;
69 ComPtr<ID3D11Device1> m_destDevice;
70 ComPtr<ID3D11Texture2D> m_destTex;
71 ComPtr<IDXGIKeyedMutex> m_destMutex;
72
73 ComPtr<ID3D11Texture2D> m_outputTex;
74};
75
76class D3D11TextureConverter : public TextureConverterBackend
77{
78public:
79 D3D11TextureConverter(QRhi *rhi);
80
81 QVideoFrameTexturesHandlesUPtr
82 createTextureHandles(AVFrame *frame, QVideoFrameTexturesHandlesUPtr oldHandles) override;
83
84 static void SetupDecoderTextures(AVCodecContext *s);
85
86private:
87 ComPtr<ID3D11Device1> m_rhiDevice;
88 ComPtr<ID3D11DeviceContext> m_rhiCtx;
89 TextureBridge m_bridge;
90};
91
92AVFrameUPtr copyFromHwPoolD3D11(AVFrameUPtr src);
93
94} // namespace QFFmpeg
95
96QT_END_NAMESPACE
97
98#endif
99
100#endif
AVFrameUPtr copyFromHwPoolD3D11(AVFrameUPtr src)
std::conditional_t< QT_FFMPEG_AVIO_WRITE_CONST, const uint8_t *, uint8_t * > AvioWriteBufferType
void freeTextureAndData(void *opaque, uint8_t *data)
AVBufferRef * wrapTextureAsBuffer(const ComPtr< ID3D11Texture2D > &tex)
ComPtr< ID3D11Device1 > GetD3DDevice(QRhi *rhi)
const AVD3D11VADeviceContext * getHwDeviceContext(const AVHWDeviceContext *ctx)
ComPtr< ID3D11Texture2D > getAvFrameTexture(const AVFrame *frame)
int getAvFramePoolIndex(const AVFrame *frame)
ComPtr< ID3D11Texture2D > copyTexture(const AVD3D11VADeviceContext *hwDevCtx, const AVFrame *src)
#define Q_LOGGING_CATEGORY(name,...)
#define qCCritical(category,...)
#define qCDebug(category,...)