FFmpeg
Loading...
Searching...
No Matches
d3d12va_decode.h
Go to the documentation of this file.
1/*
2 * Direct3D 12 HW acceleration video decoder
3 *
4 * copyright (c) 2022-2023 Wu Jianhua <toqsxw@outlook.com>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#ifndef AVCODEC_D3D12VA_DECODE_H
24#define AVCODEC_D3D12VA_DECODE_H
25
26#include "libavutil/fifo.h"
27#include "libavutil/hwcontext.h"
29#include "avcodec.h"
30#include "internal.h"
31#include "hwaccel_internal.h"
32
33/**
34 * @brief This structure is used to provide the necessary configurations and data
35 * to the FFmpeg Direct3D 12 HWAccel implementation for video decoder.
36 */
37typedef struct D3D12VADecodeContext {
39
40 /**
41 * D3D12 video decoder
42 */
43 ID3D12VideoDecoder *decoder;
44
45 /**
46 * D3D12 video decoder heap
47 */
48 ID3D12VideoDecoderHeap *decoder_heap;
49
50 /**
51 * D3D12 configuration used to create the decoder
52 *
53 * Specified by decoders
54 */
55 D3D12_VIDEO_DECODE_CONFIGURATION cfg;
56
57 /**
58 * A cached queue for reusing the D3D12 command allocators and upload buffers
59 *
60 * @see https://learn.microsoft.com/en-us/windows/win32/direct3d12/recording-command-lists-and-bundles#id3d12commandallocator
61 */
63
64 /**
65 * D3D12 command queue
66 */
67 ID3D12CommandQueue *command_queue;
68
69 /**
70 * D3D12 video decode command list
71 */
72 ID3D12VideoDecodeCommandList *command_list;
73
74 /**
75 * The array of resources used for reference frames
76 *
77 * The ref_resources.length is the same as D3D12VADecodeContext.max_num_ref
78 */
79 ID3D12Resource **ref_resources;
80
81 /**
82 * The array of subresources used for reference frames
83 *
84 * The ref_subresources.length is the same as D3D12VADecodeContext.max_num_ref
85 */
87
88 /**
89 * Maximum number of reference frames
90 */
92
93 /**
94 * Used mask used to record reference frames indices
95 */
97
98 /**
99 * Bitstream size for each frame
100 */
102
103 /**
104 * The sync context used to sync command queue
105 */
107
108 /**
109 * A pointer to AVD3D12VADeviceContext used to create D3D12 objects
110 */
112
113 /**
114 * Pixel format
115 */
117
118 /**
119 * Private to the FFmpeg AVHWAccel implementation
120 */
121 unsigned report_id;
122
123 /**
124 * The Reference-Only feature in DirectX 12 is a memory optimization
125 * technique designed for video decoding/encoding scenarios.
126 * This feature requires that reference resources must be allocated
127 * with the `D3D12_RESOURCE_FLAG_VIDEO_DECODE_REFERENCE_ONLY` resource flag.
128 * Reference textures must also be separated from output textures.
129 * reference_only_map used as a storage for reference only frames
130 * ref_only_resources used as a shadow for ref_resources
131 */
133 ID3D12Resource **ref_only_resources;
134
136
137/**
138 * @}
139 */
140#define D3D12VA_VIDEO_DEC_ASYNC_DEPTH 36
141#define D3D12VA_DECODE_CONTEXT(avctx) ((D3D12VADecodeContext *)((avctx)->internal->hwaccel_priv_data))
142#define D3D12VA_FRAMES_CONTEXT(avctx) ((AVHWFramesContext *)(avctx)->hw_frames_ctx->data)
143
144/**
145 * @brief Get a suitable maximum bitstream size
146 *
147 * Creating and destroying a resource on d3d12 needs sync and reallocation, so use this function
148 * to help allocate a big enough bitstream buffer to avoid recreating resources when decoding.
149 *
150 * @return the suitable size
151 */
153
154/**
155 * @brief init D3D12VADecodeContext
156 *
157 * @return Error code (ret < 0 if failed)
158 */
160
161/**
162 * @brief uninit D3D12VADecodeContext
163 *
164 * @return Error code (ret < 0 if failed)
165 */
167
168/**
169 * @brief d3d12va common frame params
170 *
171 * @return Error code (ret < 0 if failed)
172 */
174
175/**
176 * @brief d3d12va common end frame
177 *
178 * @param avctx codec context
179 * @param frame current output frame
180 * @param pp picture parameters
181 * @param pp_size the size of the picture parameters
182 * @param qm quantization matrix
183 * @param qm_size the size of the quantization matrix
184 * @param callback update decoder-specified input stream arguments
185 * @return Error code (ret < 0 if failed)
186 */
188 const void *pp, unsigned pp_size,
189 const void *qm, unsigned qm_size,
190 int(*)(AVCodecContext *, D3D12_VIDEO_DECODE_INPUT_STREAM_ARGUMENTS *, ID3D12Resource *));
191
192#endif /* AVCODEC_D3D12VA_DEC_H */
Libavcodec external API header.
int ff_d3d12va_decode_uninit(AVCodecContext *avctx)
uninit D3D12VADecodeContext
int ff_d3d12va_common_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
d3d12va common frame params
int ff_d3d12va_decode_init(AVCodecContext *avctx)
init D3D12VADecodeContext
int ff_d3d12va_get_suitable_max_bitstream_size(AVCodecContext *avctx)
Get a suitable maximum bitstream size.
int ff_d3d12va_common_end_frame(AVCodecContext *avctx, AVFrame *frame, const void *pp, unsigned pp_size, const void *qm, unsigned qm_size, int(*)(AVCodecContext *, D3D12_VIDEO_DECODE_INPUT_STREAM_ARGUMENTS *, ID3D12Resource *))
d3d12va common end frame
static AVFrame * frame
A generic FIFO API.
An API-specific header for AV_HWDEVICE_TYPE_D3D12VA.
common internal api header.
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
A reference to a data buffer.
Definition buffer.h:82
main external API structure.
Definition avcodec.h:443
This struct is allocated as AVHWDeviceContext.hwctx.
This struct is used to sync d3d12 execution.
Definition fifo.c:35
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
This structure is used to provide the necessary configurations and data to the FFmpeg Direct3D 12 HWA...
AVFifo * objects_queue
A cached queue for reusing the D3D12 command allocators and upload buffers.
D3D12_VIDEO_DECODE_CONFIGURATION cfg
D3D12 configuration used to create the decoder.
enum AVPixelFormat pix_fmt
Pixel format.
ID3D12CommandQueue * command_queue
D3D12 command queue.
ID3D12VideoDecodeCommandList * command_list
D3D12 video decode command list.
AVD3D12VASyncContext sync_ctx
The sync context used to sync command queue.
ID3D12VideoDecoderHeap * decoder_heap
D3D12 video decoder heap.
unsigned report_id
Private to the FFmpeg AVHWAccel implementation.
ID3D12VideoDecoder * decoder
D3D12 video decoder.
UINT max_num_ref
Maximum number of reference frames.
UINT * ref_subresources
The array of subresources used for reference frames.
AVBufferRef * decoder_ref
ID3D12Resource ** ref_only_resources
UINT bitstream_size
Bitstream size for each frame.
AVD3D12VADeviceContext * device_ctx
A pointer to AVD3D12VADeviceContext used to create D3D12 objects.
ID3D12Resource ** ref_resources
The array of resources used for reference frames.
UINT used_mask
Used mask used to record reference frames indices.
void * reference_only_map
The Reference-Only feature in DirectX 12 is a memory optimization technique designed for video decodi...