1 /*
2 * Direct3D 12 HEVC 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"
24
31 #include <dxva.h>
32
33 #define MAX_SLICES 256
34
36 DXVA_PicParams_HEVC
pp;
43
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 {
82 const HEVCFrame *current_picture =
h->cur_frame;
84 unsigned position;
85
88
92
96
97 return 0;
98 }
99
100 #define START_CODE 65536
101 #define START_CODE_SIZE 3
103 {
105 const HEVCFrame *current_picture =
h->cur_frame;
107
109 uint8_t *mapped_data, *mapped_ptr;
110 DXVA_Slice_HEVC_Short *slice;
111 D3D12_VIDEO_DECODE_FRAME_ARGUMENT *args;
112
113 if (FAILED(ID3D12Resource_Map(
buffer, 0,
NULL, (
void **)&mapped_data))) {
116 }
117
118 mapped_ptr = mapped_data;
122
123 position = slice->BSNALunitDataLocation;
124 size = slice->SliceBytesInBuffer;
125
127 slice->BSNALunitDataLocation = mapped_ptr - mapped_data;
128
131
134 }
135
137
138 input_args->CompressedBitstream = (D3D12_VIDEO_DECODE_COMPRESSED_BITSTREAM){
140 .Offset = 0,
141 .Size = mapped_ptr - mapped_data,
142 };
143
144 args = &input_args->FrameArguments[input_args->NumFrameArguments++];
145 args->Type = D3D12_VIDEO_DECODE_ARGUMENT_TYPE_SLICE_CONTROL;
146 args->Size =
sizeof(DXVA_Slice_HEVC_Short) * ctx_pic->
slice_count;
148
149 return 0;
150 }
151
153 {
156
157 int scale = ctx_pic->
pp.dwCodingParamToolFlags & 1;
158
160 return -1;
161
164 }
165
167 {
169 DXVA_PicParams_HEVC pp;
170
173 ctx->cfg.DecodeProfile = D3D12_VIDEO_DECODE_PROFILE_HEVC_MAIN10;
174 break;
175
178 ctx->cfg.DecodeProfile = D3D12_VIDEO_DECODE_PROFILE_HEVC_MAIN;
179 break;
180 } else {
181 av_log(avctx,
AV_LOG_ERROR,
"D3D12 doesn't support PROFILE_HEVC_MAIN_STILL_PICTURE!\n");
183 }
184
186 default:
187 ctx->cfg.DecodeProfile = D3D12_VIDEO_DECODE_PROFILE_HEVC_MAIN;
188 break;
189 };
190
192
194 }
195
196 #if CONFIG_HEVC_D3D12VA_HWACCEL
198 .
p.
name =
"hevc_d3d12va",
210 };
211 #endif