| Line | Branch | Exec | Source |
|---|---|---|---|
| 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 | |||
| 25 | #include "libavutil/mem.h" | ||
| 26 | #include "hwaccel_internal.h" | ||
| 27 | #include "mpegvideodec.h" | ||
| 28 | #include "vaapi_decode.h" | ||
| 29 | #include "vc1.h" | ||
| 30 | |||
| 31 | /** Translate FFmpeg MV modes to VA API */ | ||
| 32 | ✗ | static int get_VAMvModeVC1(enum MVModes mv_mode) | |
| 33 | { | ||
| 34 | ✗ | switch (mv_mode) { | |
| 35 | ✗ | case MV_PMODE_1MV_HPEL_BILIN: return VAMvMode1MvHalfPelBilinear; | |
| 36 | ✗ | case MV_PMODE_1MV: return VAMvMode1Mv; | |
| 37 | ✗ | case MV_PMODE_1MV_HPEL: return VAMvMode1MvHalfPel; | |
| 38 | ✗ | case MV_PMODE_MIXED_MV: return VAMvModeMixedMv; | |
| 39 | ✗ | case MV_PMODE_INTENSITY_COMP: return VAMvModeIntensityCompensation; | |
| 40 | } | ||
| 41 | ✗ | return 0; | |
| 42 | } | ||
| 43 | |||
| 44 | /** Check whether the MVTYPEMB bitplane is present */ | ||
| 45 | ✗ | static inline int vc1_has_MVTYPEMB_bitplane(const VC1Context *v) | |
| 46 | { | ||
| 47 | ✗ | if (v->mv_type_is_raw) | |
| 48 | ✗ | return 0; | |
| 49 | ✗ | return v->fcm == PROGRESSIVE && | |
| 50 | ✗ | (v->s.pict_type == AV_PICTURE_TYPE_P && !v->p_frame_skipped) && | |
| 51 | ✗ | (v->mv_mode == MV_PMODE_MIXED_MV || | |
| 52 | ✗ | (v->mv_mode == MV_PMODE_INTENSITY_COMP && | |
| 53 | ✗ | v->mv_mode2 == MV_PMODE_MIXED_MV)); | |
| 54 | } | ||
| 55 | |||
| 56 | /** Check whether the SKIPMB bitplane is present */ | ||
| 57 | ✗ | static inline int vc1_has_SKIPMB_bitplane(const VC1Context *v) | |
| 58 | { | ||
| 59 | ✗ | if (v->skip_is_raw) | |
| 60 | ✗ | return 0; | |
| 61 | ✗ | return (v->fcm == PROGRESSIVE || v->fcm == ILACE_FRAME) && | |
| 62 | ✗ | ((v->s.pict_type == AV_PICTURE_TYPE_P && !v->p_frame_skipped) || | |
| 63 | ✗ | (v->s.pict_type == AV_PICTURE_TYPE_B && !v->bi_type)); | |
| 64 | } | ||
| 65 | |||
| 66 | /** Check whether the DIRECTMB bitplane is present */ | ||
| 67 | ✗ | static inline int vc1_has_DIRECTMB_bitplane(const VC1Context *v) | |
| 68 | { | ||
| 69 | ✗ | if (v->dmb_is_raw) | |
| 70 | ✗ | return 0; | |
| 71 | ✗ | return (v->fcm == PROGRESSIVE || v->fcm == ILACE_FRAME) && | |
| 72 | ✗ | (v->s.pict_type == AV_PICTURE_TYPE_B && !v->bi_type); | |
| 73 | } | ||
| 74 | |||
| 75 | /** Check whether the ACPRED bitplane is present */ | ||
| 76 | ✗ | static inline int vc1_has_ACPRED_bitplane(const VC1Context *v) | |
| 77 | { | ||
| 78 | ✗ | if (v->acpred_is_raw) | |
| 79 | ✗ | return 0; | |
| 80 | ✗ | return v->profile == PROFILE_ADVANCED && | |
| 81 | ✗ | (v->s.pict_type == AV_PICTURE_TYPE_I || | |
| 82 | ✗ | (v->s.pict_type == AV_PICTURE_TYPE_B && v->bi_type)); | |
| 83 | } | ||
| 84 | |||
| 85 | /** Check whether the OVERFLAGS bitplane is present */ | ||
| 86 | ✗ | static inline int vc1_has_OVERFLAGS_bitplane(const VC1Context *v) | |
| 87 | { | ||
| 88 | ✗ | if (v->overflg_is_raw) | |
| 89 | ✗ | return 0; | |
| 90 | ✗ | return v->profile == PROFILE_ADVANCED && | |
| 91 | ✗ | (v->s.pict_type == AV_PICTURE_TYPE_I || | |
| 92 | ✗ | (v->s.pict_type == AV_PICTURE_TYPE_B && v->bi_type)) && | |
| 93 | ✗ | (v->overlap && v->pq <= 8) && | |
| 94 | ✗ | v->condover == CONDOVER_SELECT; | |
| 95 | } | ||
| 96 | |||
| 97 | /** Check whether the FIELDTX bitplane is present */ | ||
| 98 | ✗ | static inline int vc1_has_FIELDTX_bitplane(const VC1Context *v) | |
| 99 | { | ||
| 100 | ✗ | if (v->fieldtx_is_raw) | |
| 101 | ✗ | return 0; | |
| 102 | ✗ | return v->fcm == ILACE_FRAME && | |
| 103 | ✗ | (v->s.pict_type == AV_PICTURE_TYPE_I || | |
| 104 | ✗ | (v->s.pict_type == AV_PICTURE_TYPE_B && v->bi_type)); | |
| 105 | } | ||
| 106 | |||
| 107 | /** Check whether the FORWARDMB bitplane is present */ | ||
| 108 | ✗ | static inline int vc1_has_FORWARDMB_bitplane(const VC1Context *v) | |
| 109 | { | ||
| 110 | ✗ | if (v->fmb_is_raw) | |
| 111 | ✗ | return 0; | |
| 112 | ✗ | return v->fcm == ILACE_FIELD && | |
| 113 | ✗ | (v->s.pict_type == AV_PICTURE_TYPE_B && !v->bi_type); | |
| 114 | } | ||
| 115 | |||
| 116 | /** Reconstruct bitstream PTYPE (7.1.1.4, index into Table-35) */ | ||
| 117 | ✗ | static int vc1_get_PTYPE(const VC1Context *v) | |
| 118 | { | ||
| 119 | ✗ | const MpegEncContext *s = &v->s; | |
| 120 | ✗ | switch (s->pict_type) { | |
| 121 | ✗ | case AV_PICTURE_TYPE_I: return 0; | |
| 122 | ✗ | case AV_PICTURE_TYPE_P: return v->p_frame_skipped ? 4 : 1; | |
| 123 | ✗ | case AV_PICTURE_TYPE_B: return v->bi_type ? 3 : 2; | |
| 124 | } | ||
| 125 | ✗ | return 0; | |
| 126 | } | ||
| 127 | |||
| 128 | /** Reconstruct bitstream FPTYPE (9.1.1.42, index into Table-105) */ | ||
| 129 | ✗ | static int vc1_get_FPTYPE(const VC1Context *v) | |
| 130 | { | ||
| 131 | ✗ | const MpegEncContext *s = &v->s; | |
| 132 | ✗ | switch (s->pict_type) { | |
| 133 | ✗ | case AV_PICTURE_TYPE_I: return 0; | |
| 134 | ✗ | case AV_PICTURE_TYPE_P: return 3; | |
| 135 | ✗ | case AV_PICTURE_TYPE_B: return v->bi_type ? 7 : 4; | |
| 136 | } | ||
| 137 | ✗ | return 0; | |
| 138 | } | ||
| 139 | |||
| 140 | /** Reconstruct bitstream MVMODE (7.1.1.32) */ | ||
| 141 | ✗ | static inline VAMvModeVC1 vc1_get_MVMODE(const VC1Context *v) | |
| 142 | { | ||
| 143 | ✗ | if ((v->fcm == PROGRESSIVE || v->fcm == ILACE_FIELD) && | |
| 144 | ✗ | ((v->s.pict_type == AV_PICTURE_TYPE_P && !v->p_frame_skipped) || | |
| 145 | ✗ | (v->s.pict_type == AV_PICTURE_TYPE_B && !v->bi_type))) | |
| 146 | ✗ | return get_VAMvModeVC1(v->mv_mode); | |
| 147 | ✗ | return 0; | |
| 148 | } | ||
| 149 | |||
| 150 | /** Reconstruct bitstream MVMODE2 (7.1.1.33) */ | ||
| 151 | ✗ | static inline VAMvModeVC1 vc1_get_MVMODE2(const VC1Context *v) | |
| 152 | { | ||
| 153 | ✗ | if ((v->fcm == PROGRESSIVE || v->fcm == ILACE_FIELD) && | |
| 154 | ✗ | (v->s.pict_type == AV_PICTURE_TYPE_P && !v->p_frame_skipped) && | |
| 155 | ✗ | v->mv_mode == MV_PMODE_INTENSITY_COMP) | |
| 156 | ✗ | return get_VAMvModeVC1(v->mv_mode2); | |
| 157 | ✗ | return 0; | |
| 158 | } | ||
| 159 | |||
| 160 | ✗ | av_unused static inline int vc1_get_INTCOMPFIELD(const VC1Context *v) | |
| 161 | { | ||
| 162 | ✗ | if ((v->s.pict_type == AV_PICTURE_TYPE_P && !v->p_frame_skipped) && | |
| 163 | ✗ | v->fcm == ILACE_FIELD && | |
| 164 | ✗ | v->mv_mode == MV_PMODE_INTENSITY_COMP) | |
| 165 | ✗ | switch (v->intcompfield) { | |
| 166 | ✗ | case 1: return 1; | |
| 167 | ✗ | case 2: return 2; | |
| 168 | ✗ | case 3: return 0; | |
| 169 | } | ||
| 170 | ✗ | return 0; | |
| 171 | } | ||
| 172 | |||
| 173 | ✗ | static inline int vc1_get_LUMSCALE(const VC1Context *v) | |
| 174 | { | ||
| 175 | ✗ | if (v->s.pict_type == AV_PICTURE_TYPE_P && !v->p_frame_skipped) { | |
| 176 | ✗ | if ((v->fcm == PROGRESSIVE && v->mv_mode == MV_PMODE_INTENSITY_COMP) || | |
| 177 | ✗ | (v->fcm == ILACE_FRAME && v->intcomp)) | |
| 178 | ✗ | return v->lumscale; | |
| 179 | ✗ | else if (v->fcm == ILACE_FIELD && v->mv_mode == MV_PMODE_INTENSITY_COMP) | |
| 180 | ✗ | switch (v->intcompfield) { | |
| 181 | ✗ | case 1: return v->lumscale; | |
| 182 | ✗ | case 2: return v->lumscale2; | |
| 183 | ✗ | case 3: return v->lumscale; | |
| 184 | } | ||
| 185 | } | ||
| 186 | ✗ | return 0; | |
| 187 | } | ||
| 188 | |||
| 189 | ✗ | static inline int vc1_get_LUMSHIFT(const VC1Context *v) | |
| 190 | { | ||
| 191 | ✗ | if (v->s.pict_type == AV_PICTURE_TYPE_P && !v->p_frame_skipped) { | |
| 192 | ✗ | if ((v->fcm == PROGRESSIVE && v->mv_mode == MV_PMODE_INTENSITY_COMP) || | |
| 193 | ✗ | (v->fcm == ILACE_FRAME && v->intcomp)) | |
| 194 | ✗ | return v->lumshift; | |
| 195 | ✗ | else if (v->fcm == ILACE_FIELD && v->mv_mode == MV_PMODE_INTENSITY_COMP) | |
| 196 | ✗ | switch (v->intcompfield) { | |
| 197 | ✗ | case 1: return v->lumshift; | |
| 198 | ✗ | case 2: return v->lumshift2; | |
| 199 | ✗ | case 3: return v->lumshift; | |
| 200 | } | ||
| 201 | } | ||
| 202 | ✗ | return 0; | |
| 203 | } | ||
| 204 | |||
| 205 | ✗ | av_unused static inline int vc1_get_LUMSCALE2(const VC1Context *v) | |
| 206 | { | ||
| 207 | ✗ | if ((v->s.pict_type == AV_PICTURE_TYPE_P && !v->p_frame_skipped) && | |
| 208 | ✗ | v->fcm == ILACE_FIELD && | |
| 209 | ✗ | v->mv_mode == MV_PMODE_INTENSITY_COMP && | |
| 210 | ✗ | v->intcompfield == 3) | |
| 211 | ✗ | return v->lumscale2; | |
| 212 | ✗ | return 0; | |
| 213 | } | ||
| 214 | |||
| 215 | ✗ | av_unused static inline int vc1_get_LUMSHIFT2(const VC1Context *v) | |
| 216 | { | ||
| 217 | ✗ | if ((v->s.pict_type == AV_PICTURE_TYPE_P && !v->p_frame_skipped) && | |
| 218 | ✗ | v->fcm == ILACE_FIELD && | |
| 219 | ✗ | v->mv_mode == MV_PMODE_INTENSITY_COMP && | |
| 220 | ✗ | v->intcompfield == 3) | |
| 221 | ✗ | return v->lumshift2; | |
| 222 | ✗ | return 0; | |
| 223 | } | ||
| 224 | |||
| 225 | /** Reconstruct bitstream TTFRM (7.1.1.41, Table-53) */ | ||
| 226 | ✗ | static inline int vc1_get_TTFRM(const VC1Context *v) | |
| 227 | { | ||
| 228 | ✗ | switch (v->ttfrm) { | |
| 229 | ✗ | case TT_8X8: return 0; | |
| 230 | ✗ | case TT_8X4: return 1; | |
| 231 | ✗ | case TT_4X8: return 2; | |
| 232 | ✗ | case TT_4X4: return 3; | |
| 233 | } | ||
| 234 | ✗ | return 0; | |
| 235 | } | ||
| 236 | |||
| 237 | /** Pack FFmpeg bitplanes into a VABitPlaneBuffer element */ | ||
| 238 | ✗ | static inline void vc1_pack_bitplanes(uint8_t *bitplane, int n, const uint8_t *ff_bp[3], int x, int y, int stride) | |
| 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 | |||
| 252 | ✗ | static int vaapi_vc1_start_frame(AVCodecContext *avctx, | |
| 253 | av_unused const AVBufferRef *buffer_ref, | ||
| 254 | av_unused const uint8_t *buffer, | ||
| 255 | av_unused uint32_t size) | ||
| 256 | { | ||
| 257 | ✗ | const VC1Context *v = avctx->priv_data; | |
| 258 | ✗ | const MpegEncContext *s = &v->s; | |
| 259 | ✗ | VAAPIDecodePicture *pic = s->cur_pic.ptr->hwaccel_picture_private; | |
| 260 | VAPictureParameterBufferVC1 pic_param; | ||
| 261 | int err; | ||
| 262 | |||
| 263 | ✗ | pic->output_surface = ff_vaapi_get_surface_id(s->cur_pic.ptr->f); | |
| 264 | |||
| 265 | ✗ | pic_param = (VAPictureParameterBufferVC1) { | |
| 266 | .forward_reference_picture = VA_INVALID_ID, | ||
| 267 | .backward_reference_picture = VA_INVALID_ID, | ||
| 268 | .inloop_decoded_picture = VA_INVALID_ID, | ||
| 269 | .sequence_fields.bits = { | ||
| 270 | ✗ | .pulldown = v->broadcast, | |
| 271 | ✗ | .interlace = v->interlace, | |
| 272 | ✗ | .tfcntrflag = v->tfcntrflag, | |
| 273 | ✗ | .finterpflag = v->finterpflag, | |
| 274 | ✗ | .psf = v->psf, | |
| 275 | ✗ | .multires = v->multires, | |
| 276 | ✗ | .overlap = v->overlap, | |
| 277 | ✗ | .syncmarker = v->resync_marker, | |
| 278 | ✗ | .rangered = v->rangered, | |
| 279 | ✗ | .max_b_frames = s->avctx->max_b_frames, | |
| 280 | ✗ | .profile = v->profile, | |
| 281 | }, | ||
| 282 | ✗ | .coded_width = s->avctx->coded_width, | |
| 283 | ✗ | .coded_height = s->avctx->coded_height, | |
| 284 | .entrypoint_fields.bits = { | ||
| 285 | ✗ | .broken_link = v->broken_link, | |
| 286 | ✗ | .closed_entry = v->closed_entry, | |
| 287 | ✗ | .panscan_flag = v->panscanflag, | |
| 288 | ✗ | .loopfilter = v->loop_filter, | |
| 289 | }, | ||
| 290 | ✗ | .conditional_overlap_flag = v->condover, | |
| 291 | ✗ | .fast_uvmc_flag = v->fastuvmc, | |
| 292 | .range_mapping_fields.bits = { | ||
| 293 | ✗ | .luma_flag = v->range_mapy_flag, | |
| 294 | ✗ | .luma = v->range_mapy, | |
| 295 | ✗ | .chroma_flag = v->range_mapuv_flag, | |
| 296 | ✗ | .chroma = v->range_mapuv, | |
| 297 | }, | ||
| 298 | ✗ | .b_picture_fraction = v->bfraction_lut_index, | |
| 299 | ✗ | .cbp_table = (v->fcm == PROGRESSIVE ? v->cbptab : v->icbptab), | |
| 300 | ✗ | .mb_mode_table = v->mbmodetab, | |
| 301 | ✗ | .range_reduction_frame = v->rangeredfrm, | |
| 302 | ✗ | .rounding_control = v->rnd, | |
| 303 | ✗ | .post_processing = v->postproc, | |
| 304 | ✗ | .picture_resolution_index = v->respic, | |
| 305 | .picture_fields.bits = { | ||
| 306 | ✗ | .picture_type = (v->fcm == ILACE_FIELD ? vc1_get_FPTYPE(v) : vc1_get_PTYPE(v)), | |
| 307 | ✗ | .frame_coding_mode = v->fcm, | |
| 308 | ✗ | .top_field_first = v->tff, | |
| 309 | ✗ | .is_first_field = !v->second_field, | |
| 310 | ✗ | .intensity_compensation = v->intcomp, | |
| 311 | }, | ||
| 312 | ✗ | .luma_scale = vc1_get_LUMSCALE(v), | |
| 313 | ✗ | .luma_shift = vc1_get_LUMSHIFT(v), | |
| 314 | #if VA_CHECK_VERSION(1, 1, 0) | ||
| 315 | ✗ | .luma_scale2 = vc1_get_LUMSCALE2(v), | |
| 316 | ✗ | .luma_shift2 = vc1_get_LUMSHIFT2(v), | |
| 317 | ✗ | .intensity_compensation_field = vc1_get_INTCOMPFIELD(v), | |
| 318 | #endif | ||
| 319 | .raw_coding.flags = { | ||
| 320 | ✗ | .mv_type_mb = v->mv_type_is_raw, | |
| 321 | ✗ | .direct_mb = v->dmb_is_raw, | |
| 322 | ✗ | .skip_mb = v->skip_is_raw, | |
| 323 | ✗ | .field_tx = v->fieldtx_is_raw, | |
| 324 | ✗ | .forward_mb = v->fmb_is_raw, | |
| 325 | ✗ | .ac_pred = v->acpred_is_raw, | |
| 326 | ✗ | .overflags = v->overflg_is_raw, | |
| 327 | }, | ||
| 328 | .bitplane_present.flags = { | ||
| 329 | ✗ | .bp_mv_type_mb = vc1_has_MVTYPEMB_bitplane(v), | |
| 330 | ✗ | .bp_direct_mb = vc1_has_DIRECTMB_bitplane(v), | |
| 331 | ✗ | .bp_skip_mb = vc1_has_SKIPMB_bitplane(v), | |
| 332 | ✗ | .bp_field_tx = vc1_has_FIELDTX_bitplane(v), | |
| 333 | ✗ | .bp_forward_mb = vc1_has_FORWARDMB_bitplane(v), | |
| 334 | ✗ | .bp_ac_pred = vc1_has_ACPRED_bitplane(v), | |
| 335 | ✗ | .bp_overflags = vc1_has_OVERFLAGS_bitplane(v), | |
| 336 | }, | ||
| 337 | .reference_fields.bits = { | ||
| 338 | ✗ | .reference_distance_flag = v->refdist_flag, | |
| 339 | ✗ | .reference_distance = v->refdist, | |
| 340 | ✗ | .num_reference_pictures = v->numref, | |
| 341 | ✗ | .reference_field_pic_indicator = v->reffield, | |
| 342 | }, | ||
| 343 | .mv_fields.bits = { | ||
| 344 | ✗ | .mv_mode = vc1_get_MVMODE(v), | |
| 345 | ✗ | .mv_mode2 = vc1_get_MVMODE2(v), | |
| 346 | ✗ | .mv_table = (v->fcm == PROGRESSIVE ? v->mv_table_index : v->imvtab), | |
| 347 | ✗ | .two_mv_block_pattern_table = v->twomvbptab, | |
| 348 | ✗ | .four_mv_switch = v->fourmvswitch, | |
| 349 | ✗ | .four_mv_block_pattern_table = v->fourmvbptab, | |
| 350 | ✗ | .extended_mv_flag = v->extended_mv, | |
| 351 | ✗ | .extended_mv_range = v->mvrange, | |
| 352 | ✗ | .extended_dmv_flag = v->extended_dmv, | |
| 353 | ✗ | .extended_dmv_range = v->dmvrange, | |
| 354 | }, | ||
| 355 | .pic_quantizer_fields.bits = { | ||
| 356 | ✗ | .dquant = v->dquant, | |
| 357 | ✗ | .quantizer = v->quantizer_mode, | |
| 358 | ✗ | .half_qp = v->halfpq, | |
| 359 | ✗ | .pic_quantizer_scale = v->pq, | |
| 360 | ✗ | .pic_quantizer_type = v->pquantizer, | |
| 361 | ✗ | .dq_frame = v->dquantfrm, | |
| 362 | ✗ | .dq_profile = v->dqprofile, | |
| 363 | ✗ | .dq_sb_edge = v->dqprofile == DQPROFILE_SINGLE_EDGE ? v->dqsbedge : 0, | |
| 364 | ✗ | .dq_db_edge = v->dqprofile == DQPROFILE_DOUBLE_EDGES ? v->dqsbedge : 0, | |
| 365 | ✗ | .dq_binary_level = v->dqbilevel, | |
| 366 | ✗ | .alt_pic_quantizer = v->altpq, | |
| 367 | }, | ||
| 368 | .transform_fields.bits = { | ||
| 369 | ✗ | .variable_sized_transform_flag = v->vstransform, | |
| 370 | ✗ | .mb_level_transform_type_flag = v->ttmbf, | |
| 371 | ✗ | .frame_level_transform_type = vc1_get_TTFRM(v), | |
| 372 | ✗ | .transform_ac_codingset_idx1 = v->c_ac_table_index, | |
| 373 | ✗ | .transform_ac_codingset_idx2 = v->y_ac_table_index, | |
| 374 | ✗ | .intra_transform_dc_table = v->dc_table_index, | |
| 375 | }, | ||
| 376 | }; | ||
| 377 | |||
| 378 | ✗ | switch (s->pict_type) { | |
| 379 | ✗ | case AV_PICTURE_TYPE_B: | |
| 380 | ✗ | if (s->next_pic.ptr) | |
| 381 | ✗ | pic_param.backward_reference_picture = ff_vaapi_get_surface_id(s->next_pic.ptr->f); | |
| 382 | // fall-through | ||
| 383 | case AV_PICTURE_TYPE_P: | ||
| 384 | ✗ | if (s->last_pic.ptr) | |
| 385 | ✗ | pic_param.forward_reference_picture = ff_vaapi_get_surface_id(s->last_pic.ptr->f); | |
| 386 | ✗ | break; | |
| 387 | } | ||
| 388 | |||
| 389 | ✗ | err = ff_vaapi_decode_make_param_buffer(avctx, pic, | |
| 390 | VAPictureParameterBufferType, | ||
| 391 | &pic_param, sizeof(pic_param)); | ||
| 392 | ✗ | if (err) | |
| 393 | ✗ | goto fail; | |
| 394 | |||
| 395 | ✗ | if (pic_param.bitplane_present.value & 0x7f) { | |
| 396 | uint8_t *bitplane; | ||
| 397 | const uint8_t *ff_bp[3]; | ||
| 398 | int x, y, n; | ||
| 399 | ✗ | size_t size = (s->mb_width * s->mb_height + 1) / 2; | |
| 400 | |||
| 401 | ✗ | bitplane = av_mallocz(size); | |
| 402 | ✗ | if (!bitplane) { | |
| 403 | ✗ | err = AVERROR(ENOMEM); | |
| 404 | ✗ | goto fail; | |
| 405 | } | ||
| 406 | |||
| 407 | ✗ | switch (s->pict_type) { | |
| 408 | ✗ | case AV_PICTURE_TYPE_P: | |
| 409 | ✗ | ff_bp[0] = pic_param.bitplane_present.flags.bp_direct_mb ? v->direct_mb_plane : NULL; | |
| 410 | ✗ | ff_bp[1] = pic_param.bitplane_present.flags.bp_skip_mb ? s->mbskip_table : NULL; | |
| 411 | ✗ | ff_bp[2] = pic_param.bitplane_present.flags.bp_mv_type_mb ? v->mv_type_mb_plane : NULL; | |
| 412 | ✗ | break; | |
| 413 | ✗ | case AV_PICTURE_TYPE_B: | |
| 414 | ✗ | if (!v->bi_type) { | |
| 415 | ✗ | ff_bp[0] = pic_param.bitplane_present.flags.bp_direct_mb ? v->direct_mb_plane : NULL; | |
| 416 | ✗ | ff_bp[1] = pic_param.bitplane_present.flags.bp_skip_mb ? s->mbskip_table : NULL; | |
| 417 | ✗ | ff_bp[2] = pic_param.bitplane_present.flags.bp_forward_mb ? v->forward_mb_plane : NULL; | |
| 418 | ✗ | break; | |
| 419 | } | ||
| 420 | /* fall-through (BI-type) */ | ||
| 421 | case AV_PICTURE_TYPE_I: | ||
| 422 | ✗ | ff_bp[0] = pic_param.bitplane_present.flags.bp_field_tx ? v->fieldtx_plane : NULL; | |
| 423 | ✗ | ff_bp[1] = pic_param.bitplane_present.flags.bp_ac_pred ? v->acpred_plane : NULL; | |
| 424 | ✗ | ff_bp[2] = pic_param.bitplane_present.flags.bp_overflags ? v->over_flags_plane : NULL; | |
| 425 | ✗ | break; | |
| 426 | ✗ | default: | |
| 427 | ✗ | ff_bp[0] = NULL; | |
| 428 | ✗ | ff_bp[1] = NULL; | |
| 429 | ✗ | ff_bp[2] = NULL; | |
| 430 | ✗ | break; | |
| 431 | } | ||
| 432 | |||
| 433 | ✗ | n = 0; | |
| 434 | ✗ | for (y = 0; y < s->mb_height; y++) | |
| 435 | ✗ | for (x = 0; x < s->mb_width; x++, n++) | |
| 436 | ✗ | vc1_pack_bitplanes(bitplane, n, ff_bp, x, y, s->mb_stride); | |
| 437 | ✗ | if (n & 1) /* move last nibble to the high order */ | |
| 438 | ✗ | bitplane[n/2] <<= 4; | |
| 439 | |||
| 440 | ✗ | err = ff_vaapi_decode_make_param_buffer(avctx, pic, | |
| 441 | VABitPlaneBufferType, | ||
| 442 | bitplane, size); | ||
| 443 | ✗ | av_free(bitplane); | |
| 444 | ✗ | if (err) | |
| 445 | ✗ | goto fail; | |
| 446 | } | ||
| 447 | ✗ | return 0; | |
| 448 | |||
| 449 | ✗ | fail: | |
| 450 | ✗ | ff_vaapi_decode_cancel(avctx, pic); | |
| 451 | ✗ | return err; | |
| 452 | } | ||
| 453 | |||
| 454 | ✗ | static int vaapi_vc1_end_frame(AVCodecContext *avctx) | |
| 455 | { | ||
| 456 | ✗ | VC1Context *v = avctx->priv_data; | |
| 457 | ✗ | MpegEncContext *s = &v->s; | |
| 458 | ✗ | VAAPIDecodePicture *pic = s->cur_pic.ptr->hwaccel_picture_private; | |
| 459 | int ret; | ||
| 460 | |||
| 461 | ✗ | ret = ff_vaapi_decode_issue(avctx, pic); | |
| 462 | ✗ | if (ret < 0) | |
| 463 | ✗ | goto fail; | |
| 464 | |||
| 465 | ✗ | fail: | |
| 466 | ✗ | return ret; | |
| 467 | } | ||
| 468 | |||
| 469 | ✗ | static int vaapi_vc1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size) | |
| 470 | { | ||
| 471 | ✗ | const VC1Context *v = avctx->priv_data; | |
| 472 | ✗ | const MpegEncContext *s = &v->s; | |
| 473 | ✗ | VAAPIDecodePicture *pic = s->cur_pic.ptr->hwaccel_picture_private; | |
| 474 | VASliceParameterBufferVC1 slice_param; | ||
| 475 | int mb_height; | ||
| 476 | int err; | ||
| 477 | |||
| 478 | /* Current bit buffer is beyond any marker for VC-1, so skip it */ | ||
| 479 | ✗ | if (avctx->codec_id == AV_CODEC_ID_VC1 && IS_MARKER(AV_RB32(buffer))) { | |
| 480 | ✗ | buffer += 4; | |
| 481 | ✗ | size -= 4; | |
| 482 | } | ||
| 483 | |||
| 484 | ✗ | if (v->fcm == ILACE_FIELD) | |
| 485 | ✗ | mb_height = avctx->coded_height + 31 >> 5; | |
| 486 | else | ||
| 487 | ✗ | mb_height = avctx->coded_height + 15 >> 4; | |
| 488 | |||
| 489 | ✗ | slice_param = (VASliceParameterBufferVC1) { | |
| 490 | .slice_data_size = size, | ||
| 491 | .slice_data_offset = 0, | ||
| 492 | .slice_data_flag = VA_SLICE_DATA_FLAG_ALL, | ||
| 493 | ✗ | .macroblock_offset = get_bits_count(&v->gb), | |
| 494 | ✗ | .slice_vertical_position = s->mb_y % mb_height, | |
| 495 | }; | ||
| 496 | |||
| 497 | ✗ | err = ff_vaapi_decode_make_slice_buffer(avctx, pic, | |
| 498 | &slice_param, 1, sizeof(slice_param), | ||
| 499 | buffer, size); | ||
| 500 | ✗ | if (err < 0) { | |
| 501 | ✗ | ff_vaapi_decode_cancel(avctx, pic); | |
| 502 | ✗ | return err; | |
| 503 | } | ||
| 504 | |||
| 505 | ✗ | return 0; | |
| 506 | } | ||
| 507 | |||
| 508 | #if CONFIG_WMV3_VAAPI_HWACCEL | ||
| 509 | const FFHWAccel ff_wmv3_vaapi_hwaccel = { | ||
| 510 | .p.name = "wmv3_vaapi", | ||
| 511 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
| 512 | .p.id = AV_CODEC_ID_WMV3, | ||
| 513 | .p.pix_fmt = AV_PIX_FMT_VAAPI, | ||
| 514 | .start_frame = &vaapi_vc1_start_frame, | ||
| 515 | .end_frame = &vaapi_vc1_end_frame, | ||
| 516 | .decode_slice = &vaapi_vc1_decode_slice, | ||
| 517 | .frame_priv_data_size = sizeof(VAAPIDecodePicture), | ||
| 518 | .init = &ff_vaapi_decode_init, | ||
| 519 | .uninit = &ff_vaapi_decode_uninit, | ||
| 520 | .frame_params = &ff_vaapi_common_frame_params, | ||
| 521 | .priv_data_size = sizeof(VAAPIDecodeContext), | ||
| 522 | .caps_internal = HWACCEL_CAP_ASYNC_SAFE, | ||
| 523 | }; | ||
| 524 | #endif | ||
| 525 | |||
| 526 | const FFHWAccel ff_vc1_vaapi_hwaccel = { | ||
| 527 | .p.name = "vc1_vaapi", | ||
| 528 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
| 529 | .p.id = AV_CODEC_ID_VC1, | ||
| 530 | .p.pix_fmt = AV_PIX_FMT_VAAPI, | ||
| 531 | .start_frame = &vaapi_vc1_start_frame, | ||
| 532 | .end_frame = &vaapi_vc1_end_frame, | ||
| 533 | .decode_slice = &vaapi_vc1_decode_slice, | ||
| 534 | .frame_priv_data_size = sizeof(VAAPIDecodePicture), | ||
| 535 | .init = &ff_vaapi_decode_init, | ||
| 536 | .uninit = &ff_vaapi_decode_uninit, | ||
| 537 | .frame_params = &ff_vaapi_common_frame_params, | ||
| 538 | .priv_data_size = sizeof(VAAPIDecodeContext), | ||
| 539 | .caps_internal = HWACCEL_CAP_ASYNC_SAFE, | ||
| 540 | }; | ||
| 541 |