1 /*
2 * VC-1 HW decode acceleration through VA API
3 *
4 * Copyright (C) 2008-2009 Splitted-Desktop Systems
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
30
31 /** Translate FFmpeg MV modes to VA API */
33 {
34 switch (mv_mode) {
40 }
41 return 0;
42 }
43
44 /** Check whether the MVTYPEMB bitplane is present */
46 {
48 return 0;
54 }
55
56 /** Check whether the SKIPMB bitplane is present */
58 {
60 return 0;
64 }
65
66 /** Check whether the DIRECTMB bitplane is present */
68 {
70 return 0;
73 }
74
75 /** Check whether the ACPRED bitplane is present */
77 {
79 return 0;
83 }
84
85 /** Check whether the OVERFLAGS bitplane is present */
87 {
89 return 0;
95 }
96
97 /** Check whether the FIELDTX bitplane is present */
99 {
101 return 0;
105 }
106
107 /** Check whether the FORWARDMB bitplane is present */
109 {
111 return 0;
114 }
115
116 /** Reconstruct bitstream PTYPE (7.1.1.4, index into Table-35) */
118 {
120 switch (
s->pict_type) {
124 }
125 return 0;
126 }
127
128 /** Reconstruct bitstream FPTYPE (9.1.1.42, index into Table-105) */
130 {
132 switch (
s->pict_type) {
136 }
137 return 0;
138 }
139
140 /** Reconstruct bitstream MVMODE (7.1.1.32) */
142 {
147 return 0;
148 }
149
150 /** Reconstruct bitstream MVMODE2 (7.1.1.33) */
152 {
157 return 0;
158 }
159
161 {
166 case 1: return 1;
167 case 2: return 2;
168 case 3: return 0;
169 }
170 return 0;
171 }
172
174 {
184 }
185 }
186 return 0;
187 }
188
190 {
200 }
201 }
202 return 0;
203 }
204
206 {
212 return 0;
213 }
214
216 {
222 return 0;
223 }
224
225 /** Reconstruct bitstream TTFRM (7.1.1.41, Table-53) */
227 {
233 }
234 return 0;
235 }
236
237 /** Pack FFmpeg bitplanes into a VABitPlaneBuffer element */
239 {
240 const int bitplane_index = n / 2;
241 const int ff_bp_index = y *
stride + x;
242 uint8_t v = 0;
243 if (ff_bp[0])
244 v = ff_bp[0][ff_bp_index];
245 if (ff_bp[1])
246 v |= ff_bp[1][ff_bp_index] << 1;
247 if (ff_bp[2])
248 v |= ff_bp[2][ff_bp_index] << 2;
249 bitplane[bitplane_index] = (bitplane[bitplane_index] << 4) | v;
250 }
251
253 {
257 VAPictureParameterBufferVC1 pic_param;
258 int err;
259
261
262 pic_param = (VAPictureParameterBufferVC1) {
263 .forward_reference_picture = VA_INVALID_ID,
264 .backward_reference_picture = VA_INVALID_ID,
265 .inloop_decoded_picture = VA_INVALID_ID,
266 .sequence_fields.bits = {
276 .max_b_frames =
s->avctx->max_b_frames,
278 },
279 .coded_width =
s->avctx->coded_width,
280 .coded_height =
s->avctx->coded_height,
281 .entrypoint_fields.bits = {
285 .loopfilter =
s->loop_filter,
286 },
287 .conditional_overlap_flag = v->
condover,
289 .range_mapping_fields.bits = {
294 },
299 .rounding_control = v->
rnd,
301 .picture_resolution_index = v->
respic,
302 .picture_fields.bits = {
304 .frame_coding_mode = v->
fcm,
305 .top_field_first = v->
tff,
307 .intensity_compensation = v->
intcomp,
308 },
311 #if VA_CHECK_VERSION(1, 1, 0)
315 #endif
316 .raw_coding.flags = {
324 },
325 .bitplane_present.flags = {
333 },
334 .reference_fields.bits = {
336 .reference_distance = v->
refdist,
337 .num_reference_pictures = v->
numref,
338 .reference_field_pic_indicator = v->
reffield,
339 },
340 .mv_fields.bits = {
348 .extended_mv_range = v->
mvrange,
351 },
352 .pic_quantizer_fields.bits = {
356 .pic_quantizer_scale = v->
pq,
363 .alt_pic_quantizer = v->
altpq,
364 },
365 .transform_fields.bits = {
367 .mb_level_transform_type_flag = v->
ttmbf,
372 },
373 };
374
375 switch (
s->pict_type) {
378 // fall-through
381 break;
382 }
383
385 VAPictureParameterBufferType,
386 &pic_param, sizeof(pic_param));
387 if (err)
389
390 if (pic_param.bitplane_present.value & 0x7f) {
391 uint8_t *bitplane;
392 const uint8_t *ff_bp[3];
393 int x, y, n;
394 size_t size = (
s->mb_width *
s->mb_height + 1) / 2;
395
397 if (!bitplane) {
400 }
401
402 switch (
s->pict_type) {
404 ff_bp[0] = pic_param.bitplane_present.flags.bp_direct_mb ? v->direct_mb_plane :
NULL;
405 ff_bp[1] = pic_param.bitplane_present.flags.bp_skip_mb ?
s->mbskip_table :
NULL;
406 ff_bp[2] = pic_param.bitplane_present.flags.bp_mv_type_mb ? v->mv_type_mb_plane :
NULL;
407 break;
409 if (!v->bi_type) {
410 ff_bp[0] = pic_param.bitplane_present.flags.bp_direct_mb ? v->direct_mb_plane :
NULL;
411 ff_bp[1] = pic_param.bitplane_present.flags.bp_skip_mb ?
s->mbskip_table :
NULL;
412 ff_bp[2] = pic_param.bitplane_present.flags.bp_forward_mb ? v->forward_mb_plane :
NULL;
413 break;
414 }
415 /* fall-through (BI-type) */
417 ff_bp[0] = pic_param.bitplane_present.flags.bp_field_tx ? v->fieldtx_plane :
NULL;
418 ff_bp[1] = pic_param.bitplane_present.flags.bp_ac_pred ? v->acpred_plane :
NULL;
419 ff_bp[2] = pic_param.bitplane_present.flags.bp_overflags ? v->over_flags_plane :
NULL;
420 break;
421 default:
425 break;
426 }
427
428 n = 0;
429 for (y = 0; y <
s->mb_height; y++)
430 for (x = 0; x <
s->mb_width; x++, n++)
432 if (n & 1) /* move last nibble to the high order */
433 bitplane[n/2] <<= 4;
434
436 VABitPlaneBufferType,
439 if (err)
441 }
442 return 0;
443
446 return err;
447 }
448
450 {
455
459
462 }
463
465 {
469 VASliceParameterBufferVC1 slice_param;
470 int mb_height;
471 int err;
472
473 /* Current bit buffer is beyond any marker for VC-1, so skip it */
477 }
478
481 else
483
484 slice_param = (VASliceParameterBufferVC1) {
485 .slice_data_size =
size,
486 .slice_data_offset = 0,
487 .slice_data_flag = VA_SLICE_DATA_FLAG_ALL,
489 .slice_vertical_position =
s->mb_y % mb_height,
490 };
491
493 &slice_param, sizeof(slice_param),
495 if (err < 0) {
497 return err;
498 }
499
500 return 0;
501 }
502
503 #if CONFIG_WMV3_VAAPI_HWACCEL
505 .
name =
"wmv3_vaapi",
518 };
519 #endif
520
535 };