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
26
27 /** Translate FFmpeg MV modes to VA API */
29 {
30 switch (mv_mode) {
36 }
37 return 0;
38 }
39
40 /** Check whether the MVTYPEMB bitplane is present */
42 {
44 return 0;
49 }
50
51 /** Check whether the SKIPMB bitplane is present */
53 {
55 return 0;
58 }
59
60 /** Check whether the DIRECTMB bitplane is present */
62 {
64 return 0;
66 }
67
68 /** Check whether the ACPRED bitplane is present */
70 {
72 return 0;
76 }
77
78 /** Check whether the OVERFLAGS bitplane is present */
80 {
82 return 0;
88 }
89
90 /** Reconstruct bitstream PTYPE (7.1.1.4, index into Table-35) */
92 {
98 }
99 return 0;
100 }
101
102 /** Reconstruct bitstream MVMODE (7.1.1.32) */
104 {
108 return 0;
109 }
110
111 /** Reconstruct bitstream MVMODE2 (7.1.1.33) */
113 {
116 return 0;
117 }
118
119 /** Reconstruct bitstream TTFRM (7.1.1.41, Table-53) */
121 {
127 }
128 return 0;
129 }
130
131 /** Pack FFmpeg bitplanes into a VABitPlaneBuffer element */
133 {
134 const int bitplane_index = n / 2;
135 const int ff_bp_index = y * stride + x;
137 if (ff_bp[0])
138 v = ff_bp[0][ff_bp_index];
139 if (ff_bp[1])
140 v |= ff_bp[1][ff_bp_index] << 1;
141 if (ff_bp[2])
142 v |= ff_bp[2][ff_bp_index] << 2;
143 bitplane[bitplane_index] = (bitplane[bitplane_index] << 4) | v;
144 }
145
147 {
151 VAPictureParameterBufferVC1 *pic_param;
152
153 av_dlog(avctx,
"vaapi_vc1_start_frame()\n");
154
156
157 /* Fill in VAPictureParameterBufferVC1 */
159 if (!pic_param)
160 return -1;
161 pic_param->forward_reference_picture = VA_INVALID_ID;
162 pic_param->backward_reference_picture = VA_INVALID_ID;
163 pic_param->inloop_decoded_picture = VA_INVALID_ID;
164 pic_param->sequence_fields.value = 0; /* reset all bits */
165 pic_param->sequence_fields.bits.pulldown = v->
broadcast;
166 pic_param->sequence_fields.bits.interlace = v->
interlace;
167 pic_param->sequence_fields.bits.tfcntrflag = v->
tfcntrflag;
168 pic_param->sequence_fields.bits.finterpflag = v->
finterpflag;
169 pic_param->sequence_fields.bits.psf = v->
psf;
170 pic_param->sequence_fields.bits.multires = v->
multires;
171 pic_param->sequence_fields.bits.overlap = v->
overlap;
172 pic_param->sequence_fields.bits.syncmarker = s->
resync_marker;
173 pic_param->sequence_fields.bits.rangered = v->
rangered;
175 #if VA_CHECK_VERSION(0,32,0)
176 pic_param->sequence_fields.bits.profile = v->
profile;
177 #endif
180 pic_param->entrypoint_fields.value = 0; /* reset all bits */
181 pic_param->entrypoint_fields.bits.broken_link = v->
broken_link;
182 pic_param->entrypoint_fields.bits.closed_entry = v->
closed_entry;
183 pic_param->entrypoint_fields.bits.panscan_flag = v->
panscanflag;
184 pic_param->entrypoint_fields.bits.loopfilter = s->
loop_filter;
185 pic_param->conditional_overlap_flag = v->
condover;
186 pic_param->fast_uvmc_flag = v->
fastuvmc;
187 pic_param->range_mapping_fields.value = 0; /* reset all bits */
189 pic_param->range_mapping_fields.bits.luma = v->
range_mapy;
191 pic_param->range_mapping_fields.bits.chroma = v->
range_mapuv;
194 pic_param->mb_mode_table = 0; /* XXX: interlaced frame */
196 pic_param->rounding_control = v->
rnd;
197 pic_param->post_processing = v->
postproc;
198 pic_param->picture_resolution_index = v->
respic;
199 pic_param->luma_scale = v->
lumscale;
200 pic_param->luma_shift = v->
lumshift;
201 pic_param->picture_fields.value = 0; /* reset all bits */
202 pic_param->picture_fields.bits.picture_type =
vc1_get_PTYPE(v);
203 pic_param->picture_fields.bits.frame_coding_mode = v->
fcm;
204 pic_param->picture_fields.bits.top_field_first = v->
tff;
205 pic_param->picture_fields.bits.is_first_field = v->
fcm == 0;
/* XXX: interlaced frame */
207 pic_param->raw_coding.value = 0; /* reset all bits */
209 pic_param->raw_coding.flags.direct_mb = v->
dmb_is_raw;
210 pic_param->raw_coding.flags.skip_mb = v->
skip_is_raw;
211 pic_param->raw_coding.flags.field_tx = 0; /* XXX: interlaced frame */
212 pic_param->raw_coding.flags.forward_mb = 0; /* XXX: interlaced frame */
215 pic_param->bitplane_present.value = 0; /* reset all bits */
219 pic_param->bitplane_present.flags.bp_field_tx = 0; /* XXX: interlaced frame */
220 pic_param->bitplane_present.flags.bp_forward_mb = 0; /* XXX: interlaced frame */
223 pic_param->reference_fields.value = 0; /* reset all bits */
224 pic_param->reference_fields.bits.reference_distance_flag = v->
refdist_flag;
225 pic_param->reference_fields.bits.reference_distance = 0; /* XXX: interlaced frame */
226 pic_param->reference_fields.bits.num_reference_pictures = 0; /* XXX: interlaced frame */
227 pic_param->reference_fields.bits.reference_field_pic_indicator = 0; /* XXX: interlaced frame */
228 pic_param->mv_fields.value = 0; /* reset all bits */
232 pic_param->mv_fields.bits.two_mv_block_pattern_table = 0; /* XXX: interlaced frame */
233 pic_param->mv_fields.bits.four_mv_switch = 0; /* XXX: interlaced frame */
234 pic_param->mv_fields.bits.four_mv_block_pattern_table = 0; /* XXX: interlaced frame */
235 pic_param->mv_fields.bits.extended_mv_flag = v->
extended_mv;
236 pic_param->mv_fields.bits.extended_mv_range = v->
mvrange;
237 pic_param->mv_fields.bits.extended_dmv_flag = v->
extended_dmv;
238 pic_param->mv_fields.bits.extended_dmv_range = 0; /* XXX: interlaced frame */
239 pic_param->pic_quantizer_fields.value = 0; /* reset all bits */
240 pic_param->pic_quantizer_fields.bits.dquant = v->
dquant;
241 pic_param->pic_quantizer_fields.bits.quantizer = v->
quantizer_mode;
242 pic_param->pic_quantizer_fields.bits.half_qp = v->
halfpq;
243 pic_param->pic_quantizer_fields.bits.pic_quantizer_scale = v->
pq;
244 pic_param->pic_quantizer_fields.bits.pic_quantizer_type = v->
pquantizer;
245 pic_param->pic_quantizer_fields.bits.dq_frame = v->
dquantfrm;
246 pic_param->pic_quantizer_fields.bits.dq_profile = v->
dqprofile;
249 pic_param->pic_quantizer_fields.bits.dq_binary_level = v->
dqbilevel;
250 pic_param->pic_quantizer_fields.bits.alt_pic_quantizer = v->
altpq;
251 pic_param->transform_fields.value = 0; /* reset all bits */
252 pic_param->transform_fields.bits.variable_sized_transform_flag = v->
vstransform;
253 pic_param->transform_fields.bits.mb_level_transform_type_flag = v->
ttmbf;
254 pic_param->transform_fields.bits.frame_level_transform_type =
vc1_get_TTFRM(v);
255 pic_param->transform_fields.bits.transform_ac_codingset_idx1 = v->
c_ac_table_index;
256 pic_param->transform_fields.bits.transform_ac_codingset_idx2 = v->
y_ac_table_index;
257 pic_param->transform_fields.bits.intra_transform_dc_table = v->
s.
dc_table_index;
258
262 // fall-through
265 break;
266 }
267
268 if (pic_param->bitplane_present.value) {
272
275 ff_bp[0] = pic_param->bitplane_present.flags.bp_direct_mb ? v->
direct_mb_plane : NULL;
276 ff_bp[1] = pic_param->bitplane_present.flags.bp_skip_mb ? s->
mbskip_table : NULL;
277 ff_bp[2] = pic_param->bitplane_present.flags.bp_mv_type_mb ? v->
mv_type_mb_plane : NULL;
278 break;
281 ff_bp[0] = pic_param->bitplane_present.flags.bp_direct_mb ? v->
direct_mb_plane : NULL;
282 ff_bp[1] = pic_param->bitplane_present.flags.bp_skip_mb ? s->
mbskip_table : NULL;
283 ff_bp[2] = NULL; /* XXX: interlaced frame (FORWARD plane) */
284 break;
285 }
286 /* fall-through (BI-type) */
288 ff_bp[0] = NULL; /* XXX: interlaced frame (FIELDTX plane) */
289 ff_bp[1] = pic_param->bitplane_present.flags.bp_ac_pred ? v->
acpred_plane : NULL;
290 ff_bp[2] = pic_param->bitplane_present.flags.bp_overflags ? v->
over_flags_plane : NULL;
291 break;
292 default:
293 ff_bp[0] = NULL;
294 ff_bp[1] = NULL;
295 ff_bp[2] = NULL;
296 break;
297 }
298
300 if (!bitplane)
301 return -1;
302
303 n = 0;
305 for (x = 0; x < s->
mb_width; x++, n++)
307 if (n & 1) /* move last nibble to the high order */
308 bitplane[n/2] <<= 4;
309 }
310 return 0;
311 }
312
314 {
317 VASliceParameterBufferVC1 *slice_param;
318
319 av_dlog(avctx,
"vaapi_vc1_decode_slice(): buffer %p, size %d\n", buffer, size);
320
321 /* Current bit buffer is beyond any marker for VC-1, so skip it */
323 buffer += 4;
324 size -= 4;
325 }
326
327 /* Fill in VASliceParameterBufferVC1 */
329 if (!slice_param)
330 return -1;
332 slice_param->slice_vertical_position = s->
mb_y;
333 return 0;
334 }
335
336 #if CONFIG_WMV3_VAAPI_HWACCEL
338 .
name =
"wmv3_vaapi",
345 };
346 #endif
347
356 };