1 /*
2 * DXVA2 VP9 HW acceleration.
3 *
4 * copyright (c) 2015 Hendrik Leppkes
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
27
31
33 DXVA_PicParams_VP9
pp;
37 };
38
41 {
44 }
45
47 DXVA_PicParams_VP9 *pp)
48 {
52
53 if (!pixdesc)
54 return -1;
55
56 memset(pp, 0, sizeof(*pp));
57
58 pp->profile =
h->h.profile;
59 pp->wFormatAndPictureInfoFlags = ((
h->h.keyframe == 0) << 0) |
60 ((
h->h.invisible == 0) << 1) |
61 (
h->h.errorres << 2) |
64 (0 << 5) | /* extra_plane */
65 (
h->h.refreshctx << 6) |
66 (
h->h.parallelmode << 7) |
67 (
h->h.intraonly << 8) |
68 (
h->h.framectxid << 9) |
69 (
h->h.resetctx << 11) |
70 ((
h->h.keyframe ? 0 :
h->h.highprecisionmvs) << 13) |
71 (0 << 14); /* ReservedFormatInfo2Bits */
72
73 pp->width = avctx->
width;
74 pp->height = avctx->
height;
75 pp->BitDepthMinus8Luma = pixdesc->
comp[0].
depth - 8;
76 pp->BitDepthMinus8Chroma = pixdesc->
comp[1].
depth - 8;
77 /* swap 0/1 to match the reference */
78 pp->interp_filter =
h->h.filtermode ^ (
h->h.filtermode <= 1);
79 pp->Reserved8Bits = 0;
80
81 for (
i = 0;
i < 8;
i++) {
84 pp->ref_frame_coded_width[
i] =
h->refs[
i].f->width;
85 pp->ref_frame_coded_height[
i] =
h->refs[
i].f->height;
86 } else
87 pp->ref_frame_map[
i].bPicEntry = 0xFF;
88 }
89
90 for (
i = 0;
i < 3;
i++) {
91 uint8_t refidx =
h->h.refidx[
i];
92 if (
h->refs[refidx].f)
94 else
95 pp->frame_refs[
i].bPicEntry = 0xFF;
96
97 pp->ref_frame_sign_bias[
i + 1] =
h->h.signbias[
i];
98 }
99
101
102 pp->filter_level =
h->h.filter.level;
103 pp->sharpness_level =
h->h.filter.sharpness;
104
105 pp->wControlInfoFlags = (
h->h.lf_delta.enabled << 0) |
106 (
h->h.lf_delta.updated << 1) |
107 (
h->h.use_last_frame_mvs << 2) |
108 (0 << 3); /* ReservedControlInfo5Bits */
109
110 for (
i = 0;
i < 4;
i++)
111 pp->ref_deltas[
i] =
h->h.lf_delta.ref[
i];
112
114 pp->mode_deltas[
i] =
h->h.lf_delta.mode[
i];
115
116 pp->base_qindex =
h->h.yac_qi;
117 pp->y_dc_delta_q =
h->h.ydc_qdelta;
118 pp->uv_dc_delta_q =
h->h.uvdc_qdelta;
119 pp->uv_ac_delta_q =
h->h.uvac_qdelta;
120
121 /* segmentation data */
122 pp->stVP9Segments.wSegmentInfoFlags = (
h->h.segmentation.enabled << 0) |
123 (
h->h.segmentation.update_map << 1) |
124 (
h->h.segmentation.temporal << 2) |
125 (
h->h.segmentation.absolute_vals << 3) |
126 (0 << 4); /* ReservedSegmentFlags4Bits */
127
128 for (
i = 0;
i < 7;
i++)
129 pp->stVP9Segments.tree_probs[
i] =
h->h.segmentation.prob[
i];
130
131 if (
h->h.segmentation.temporal)
132 for (
i = 0;
i < 3;
i++)
133 pp->stVP9Segments.pred_probs[
i] =
h->h.segmentation.pred_prob[
i];
134 else
135 memset(pp->stVP9Segments.pred_probs, 255, sizeof(pp->stVP9Segments.pred_probs));
136
137 for (
i = 0;
i < 8;
i++) {
138 pp->stVP9Segments.feature_mask[
i] = (
h->h.segmentation.feat[
i].q_enabled << 0) |
139 (
h->h.segmentation.feat[
i].lf_enabled << 1) |
140 (
h->h.segmentation.feat[
i].ref_enabled << 2) |
141 (
h->h.segmentation.feat[
i].skip_enabled << 3);
142
143 pp->stVP9Segments.feature_data[
i][0] =
h->h.segmentation.feat[
i].q_val;
144 pp->stVP9Segments.feature_data[
i][1] =
h->h.segmentation.feat[
i].lf_val;
145 pp->stVP9Segments.feature_data[
i][2] =
h->h.segmentation.feat[
i].ref_val;
146 pp->stVP9Segments.feature_data[
i][3] = 0;
/* no data for skip */
147 }
148
149 pp->log2_tile_cols =
h->h.tiling.log2_tile_cols;
150 pp->log2_tile_rows =
h->h.tiling.log2_tile_rows;
151
152 pp->uncompressed_header_size_byte_aligned =
h->h.uncompressed_header_size;
153 pp->first_partition_size =
h->h.compressed_header_size;
154
156 return 0;
157 }
158
160 unsigned position,
unsigned size)
161 {
162 memset(slice, 0, sizeof(*slice));
163 slice->BSNALunitDataLocation = position;
164 slice->SliceBytesInBuffer =
size;
165 slice->wBadSliceChopping = 0;
166 }
167
171 {
175 void *dxva_data_ptr =
NULL;
176 uint8_t *dxva_data;
177 unsigned dxva_size;
178 unsigned padding;
180
181 #if CONFIG_D3D11VA
183 type = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM;
187 &dxva_size, &dxva_data_ptr)))
188 return -1;
189 }
190 #endif
191 #if CONFIG_DXVA2
193 type = DXVA2_BitStreamDateBufferType;
196 &dxva_data_ptr, &dxva_size)))
197 return -1;
198 }
199 #endif
200
201 dxva_data = dxva_data_ptr;
202
203 if (!dxva_data || ctx_pic->
slice.SliceBytesInBuffer > dxva_size) {
205 return -1;
206 }
207
208 memcpy(dxva_data, ctx_pic->
bitstream, ctx_pic->
slice.SliceBytesInBuffer);
209
210 padding =
FFMIN(128 - ((ctx_pic->
slice.SliceBytesInBuffer) & 127), dxva_size - ctx_pic->
slice.SliceBytesInBuffer);
211 if (padding > 0) {
212 memset(dxva_data + ctx_pic->
slice.SliceBytesInBuffer, 0, padding);
213 ctx_pic->
slice.SliceBytesInBuffer += padding;
214 }
215
216 #if CONFIG_D3D11VA
219 return -1;
220 #endif
221 #if CONFIG_DXVA2
224 return -1;
225 #endif
226
227 #if CONFIG_D3D11VA
229 D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = bs;
230 memset(dsc11, 0, sizeof(*dsc11));
231 dsc11->BufferType =
type;
232 dsc11->DataSize = ctx_pic->
slice.SliceBytesInBuffer;
233 dsc11->NumMBsInBuffer = 0;
234
235 type = D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL;
236 }
237 #endif
238 #if CONFIG_DXVA2
240 DXVA2_DecodeBufferDesc *dsc2 = bs;
241 memset(dsc2, 0, sizeof(*dsc2));
242 dsc2->CompressedBufferType =
type;
243 dsc2->DataSize = ctx_pic->
slice.SliceBytesInBuffer;
244 dsc2->NumMBsInBuffer = 0;
245
246 type = DXVA2_SliceControlBufferType;
247 }
248 #endif
249
253 }
254
255
260 {
264
266 return -1;
268
269 /* Fill up DXVA_PicParams_VP9 */
271 return -1;
272
275 return 0;
276 }
277
281 {
284 unsigned position;
285
289
292
293 return 0;
294 }
295
297 {
301
303 return -1;
304
306 &ctx_pic->
pp,
sizeof(ctx_pic->
pp),
310 }
311
312 #if CONFIG_VP9_DXVA2_HWACCEL
314 .
p.
name =
"vp9_dxva2",
326 };
327 #endif
328
329 #if CONFIG_VP9_D3D11VA_HWACCEL
331 .
p.
name =
"vp9_d3d11va",
343 };
344 #endif
345
346 #if CONFIG_VP9_D3D11VA2_HWACCEL
348 .
p.
name =
"vp9_d3d11va2",
360 };
361 #endif