1 /*
2 * Direct3D 12 h264 HW acceleration
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 #include "config_components.h"
32 #include <dxva.h>
33
35 DXVA_PicParams_H264
pp;
42
44 unsigned position,
unsigned size)
45 {
46 memset(slice, 0, sizeof(*slice));
47 slice->BSNALunitDataLocation = position;
48 slice->SliceBytesInBuffer =
size;
49 slice->wBadSliceChopping = 0;
50 }
51
56 {
60
62 return -1;
63
65
67
69
71
75
76 return 0;
77 }
78
80 {
81 unsigned position;
86
89
93
97
99 ctx_pic->
pp.wBitFields &= ~(1 << 15);
/* Set IntraPicFlag to 0 */
100
101 return 0;
102 }
103
104 #define START_CODE 65536
105 #define START_CODE_SIZE 3
107 {
111
113 uint8_t *mapped_data, *mapped_ptr;
114 DXVA_Slice_H264_Short *slice;
115 D3D12_VIDEO_DECODE_FRAME_ARGUMENT *args;
116
117 if (FAILED(ID3D12Resource_Map(
buffer, 0,
NULL, (
void **)&mapped_data))) {
120 }
121
122 mapped_ptr = mapped_data;
126
127 position = slice->BSNALunitDataLocation;
128 size = slice->SliceBytesInBuffer;
129
131 slice->BSNALunitDataLocation = mapped_ptr - mapped_data;
132
135
138 }
139
141
142 input_args->CompressedBitstream = (D3D12_VIDEO_DECODE_COMPRESSED_BITSTREAM){
144 .Offset = 0,
145 .Size = mapped_ptr - mapped_data,
146 };
147
148 args = &input_args->FrameArguments[input_args->NumFrameArguments++];
149 args->Type = D3D12_VIDEO_DECODE_ARGUMENT_TYPE_SLICE_CONTROL;
150 args->Size =
sizeof(DXVA_Slice_H264_Short) * ctx_pic->
slice_count;
152
153 return 0;
154 }
155
157 {
161
163
165 return -1;
166
168 &ctx_pic->
pp,
sizeof(ctx_pic->
pp),
169 &ctx_pic->
qm,
sizeof(ctx_pic->
qm),
173
175 }
176
178 {
180 DXVA_PicParams_H264 pp;
181
182 ctx->cfg.DecodeProfile = D3D12_VIDEO_DECODE_PROFILE_H264;
183
185
187 }
188
189 #if CONFIG_H264_D3D12VA_HWACCEL
191 .
p.
name =
"h264_d3d12va",
203 };
204 #endif