1 /*
2 * Direct3D12 WMV3/VC-1 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
33 #define MAX_SLICES 1024
34 #define INVALID_REF 0xffff
35
37 DXVA_PictureParameters
pp;
43
48 {
52
54 return -1;
55
57
59
62
66
67 return 0;
68 }
69
71 {
74
77 }
78
83 }
84
88
91
92 return 0;
93 }
94
96 {
100 D3D12_VIDEO_DECODE_FRAME_ARGUMENT *args = &input_args->FrameArguments[input_args->NumFrameArguments++];
101
102 const unsigned mb_count =
s->mb_width * (
s->mb_height >> v->
field_mode);
103 uint8_t *mapped_data, *mapped_ptr;
104
105 static const uint8_t
start_code[] = { 0, 0, 1, 0x0d };
106
107 if (FAILED(ID3D12Resource_Map(
buffer, 0,
NULL, (
void **)&mapped_data))) {
110 }
111
112 mapped_ptr = mapped_data;
114 DXVA_SliceInfo *slice = &ctx_pic->
slices[
i];
115 unsigned position = slice->dwSliceDataLocation;
116 unsigned size = slice->dwSliceBitsInBuffer / 8;
117
118 slice->dwSliceDataLocation = mapped_ptr - mapped_data;
119 if (i < ctx_pic->slice_count - 1)
120 slice->wNumberMBsInSlice = slice[1].wNumberMBsInSlice - slice[0].wNumberMBsInSlice;
121 else
122 slice->wNumberMBsInSlice = mb_count - slice[0].wNumberMBsInSlice;
123
127 mapped_ptr[3] = 0x0c;
129 mapped_ptr[3] = 0x0b;
130
132 slice->dwSliceBitsInBuffer +=
sizeof(
start_code) * 8;
133 }
134
137 }
138
140
141 args->Type = D3D12_VIDEO_DECODE_ARGUMENT_TYPE_SLICE_CONTROL;
142 args->Size =
sizeof(DXVA_SliceInfo) * ctx_pic->
slice_count;
143 args->pData = ctx_pic->
slices;
144
145 input_args->CompressedBitstream = (D3D12_VIDEO_DECODE_COMPRESSED_BITSTREAM){
147 .Offset = 0,
148 .Size = mapped_ptr - mapped_data,
149 };
150
151 return 0;
152 }
153
155 {
158
160 return -1;
161
163 &ctx_pic->
pp,
sizeof(ctx_pic->
pp),
166 }
167
169 {
172 ctx->cfg.DecodeProfile = D3D12_VIDEO_DECODE_PROFILE_VC1_D2010;
173
174 ctx->max_num_ref = 3;
175
178 ctx->cfg.DecodeProfile = D3D12_VIDEO_DECODE_PROFILE_VC1;
180 }
181
183 }
184
185 #if CONFIG_WMV3_D3D12VA_HWACCEL
187 .
p.
name =
"wmv3_d3d12va",
199 };
200 #endif
201
202 #if CONFIG_VC1_D3D12VA_HWACCEL
204 .
p.
name =
"vc1_d3d12va",
216 };
217 #endif