static int vaapi_vc1_start_frame(AVCodecContext *avctx, av_unused const uint8_t *buffer, av_unused uint32_t size)

{

    const VC1Context *v = avctx->priv_data;

    const MpegEncContext *s = &v->s;

    struct vaapi_context * const vactx = avctx->hwaccel_context;

    VAPictureParameterBufferVC1 *pic_param;



    vactx->slice_param_size = sizeof(VASliceParameterBufferVC1);



    /* Fill in VAPictureParameterBufferVC1 */

    pic_param = ff_vaapi_alloc_pic_param(vactx, sizeof(VAPictureParameterBufferVC1));

    if (!pic_param)

        return -1;

    pic_param->forward_reference_picture                            = VA_INVALID_ID;

    pic_param->backward_reference_picture                           = VA_INVALID_ID;

    pic_param->inloop_decoded_picture                               = VA_INVALID_ID;

    pic_param->sequence_fields.value                                = 0; /* reset all bits */

    pic_param->sequence_fields.bits.pulldown                        = v->broadcast;

    pic_param->sequence_fields.bits.interlace                       = v->interlace;

    pic_param->sequence_fields.bits.tfcntrflag                      = v->tfcntrflag;

    pic_param->sequence_fields.bits.finterpflag                     = v->finterpflag;

    pic_param->sequence_fields.bits.psf                             = v->psf;

    pic_param->sequence_fields.bits.multires                        = v->multires;

    pic_param->sequence_fields.bits.overlap                         = v->overlap;

    pic_param->sequence_fields.bits.syncmarker                      = v->resync_marker;

    pic_param->sequence_fields.bits.rangered                        = v->rangered;

    pic_param->sequence_fields.bits.max_b_frames                    = s->avctx->max_b_frames;

#if VA_CHECK_VERSION(0,32,0)

    pic_param->sequence_fields.bits.profile                         = v->profile;

#endif

    pic_param->coded_width                                          = s->avctx->coded_width;

    pic_param->coded_height                                         = s->avctx->coded_height;

    pic_param->entrypoint_fields.value                              = 0; /* reset all bits */

    pic_param->entrypoint_fields.bits.broken_link                   = v->broken_link;

    pic_param->entrypoint_fields.bits.closed_entry                  = v->closed_entry;

    pic_param->entrypoint_fields.bits.panscan_flag                  = v->panscanflag;

    pic_param->entrypoint_fields.bits.loopfilter                    = s->loop_filter;

    pic_param->conditional_overlap_flag                             = v->condover;

    pic_param->fast_uvmc_flag                                       = v->fastuvmc;

    pic_param->range_mapping_fields.value                           = 0; /* reset all bits */

    pic_param->range_mapping_fields.bits.luma_flag                  = v->range_mapy_flag;

    pic_param->range_mapping_fields.bits.luma                       = v->range_mapy;

    pic_param->range_mapping_fields.bits.chroma_flag                = v->range_mapuv_flag;

    pic_param->range_mapping_fields.bits.chroma                     = v->range_mapuv;

    pic_param->b_picture_fraction                                   = v->bfraction_lut_index;

    pic_param->cbp_table                                            = v->cbpcy_vlc ? v->cbpcy_vlc - ff_vc1_cbpcy_p_vlc : 0;

    pic_param->mb_mode_table                                        = 0; /* XXX: interlaced frame */

    pic_param->range_reduction_frame                                = v->rangeredfrm;

    pic_param->rounding_control                                     = v->rnd;

    pic_param->post_processing                                      = v->postproc;

    pic_param->picture_resolution_index                             = v->respic;

    pic_param->luma_scale                                           = v->lumscale;

    pic_param->luma_shift                                           = v->lumshift;

    pic_param->picture_fields.value                                 = 0; /* reset all bits */

    pic_param->picture_fields.bits.picture_type                     = vc1_get_PTYPE(v);

    pic_param->picture_fields.bits.frame_coding_mode                = v->fcm;

    pic_param->picture_fields.bits.top_field_first                  = v->tff;

    pic_param->picture_fields.bits.is_first_field                   = v->fcm == 0; /* XXX: interlaced frame */

    pic_param->picture_fields.bits.intensity_compensation           = v->mv_mode == MV_PMODE_INTENSITY_COMP;

    pic_param->raw_coding.value                                     = 0; /* reset all bits */

    pic_param->raw_coding.flags.mv_type_mb                          = v->mv_type_is_raw;

    pic_param->raw_coding.flags.direct_mb                           = v->dmb_is_raw;

    pic_param->raw_coding.flags.skip_mb                             = v->skip_is_raw;

    pic_param->raw_coding.flags.field_tx                            = 0; /* XXX: interlaced frame */

    pic_param->raw_coding.flags.forward_mb                          = 0; /* XXX: interlaced frame */

    pic_param->raw_coding.flags.ac_pred                             = v->acpred_is_raw;

    pic_param->raw_coding.flags.overflags                           = v->overflg_is_raw;

    pic_param->bitplane_present.value                               = 0; /* reset all bits */

    pic_param->bitplane_present.flags.bp_mv_type_mb                 = vc1_has_MVTYPEMB_bitplane(v);

    pic_param->bitplane_present.flags.bp_direct_mb                  = vc1_has_DIRECTMB_bitplane(v);

    pic_param->bitplane_present.flags.bp_skip_mb                    = vc1_has_SKIPMB_bitplane(v);

    pic_param->bitplane_present.flags.bp_field_tx                   = 0; /* XXX: interlaced frame */

    pic_param->bitplane_present.flags.bp_forward_mb                 = 0; /* XXX: interlaced frame */

    pic_param->bitplane_present.flags.bp_ac_pred                    = vc1_has_ACPRED_bitplane(v);

    pic_param->bitplane_present.flags.bp_overflags                  = vc1_has_OVERFLAGS_bitplane(v);

    pic_param->reference_fields.value                               = 0; /* reset all bits */

    pic_param->reference_fields.bits.reference_distance_flag        = v->refdist_flag;

    pic_param->reference_fields.bits.reference_distance             = 0; /* XXX: interlaced frame */

    pic_param->reference_fields.bits.num_reference_pictures         = 0; /* XXX: interlaced frame */

    pic_param->reference_fields.bits.reference_field_pic_indicator  = 0; /* XXX: interlaced frame */

    pic_param->mv_fields.value                                      = 0; /* reset all bits */

    pic_param->mv_fields.bits.mv_mode                               = vc1_get_MVMODE(v);

    pic_param->mv_fields.bits.mv_mode2                              = vc1_get_MVMODE2(v);

    pic_param->mv_fields.bits.mv_table                              = s->mv_table_index;

    pic_param->mv_fields.bits.two_mv_block_pattern_table            = 0; /* XXX: interlaced frame */

    pic_param->mv_fields.bits.four_mv_switch                        = 0; /* XXX: interlaced frame */

    pic_param->mv_fields.bits.four_mv_block_pattern_table           = 0; /* XXX: interlaced frame */

    pic_param->mv_fields.bits.extended_mv_flag                      = v->extended_mv;

    pic_param->mv_fields.bits.extended_mv_range                     = v->mvrange;

    pic_param->mv_fields.bits.extended_dmv_flag                     = v->extended_dmv;

    pic_param->mv_fields.bits.extended_dmv_range                    = 0; /* XXX: interlaced frame */

    pic_param->pic_quantizer_fields.value                           = 0; /* reset all bits */

    pic_param->pic_quantizer_fields.bits.dquant                     = v->dquant;

    pic_param->pic_quantizer_fields.bits.quantizer                  = v->quantizer_mode;

    pic_param->pic_quantizer_fields.bits.half_qp                    = v->halfpq;

    pic_param->pic_quantizer_fields.bits.pic_quantizer_scale        = v->pq;

    pic_param->pic_quantizer_fields.bits.pic_quantizer_type         = v->pquantizer;

    pic_param->pic_quantizer_fields.bits.dq_frame                   = v->dquantfrm;

    pic_param->pic_quantizer_fields.bits.dq_profile                 = v->dqprofile;

    pic_param->pic_quantizer_fields.bits.dq_sb_edge                 = v->dqprofile == DQPROFILE_SINGLE_EDGE  ? v->dqsbedge : 0;

    pic_param->pic_quantizer_fields.bits.dq_db_edge                 = v->dqprofile == DQPROFILE_DOUBLE_EDGES ? v->dqsbedge : 0;

    pic_param->pic_quantizer_fields.bits.dq_binary_level            = v->dqbilevel;

    pic_param->pic_quantizer_fields.bits.alt_pic_quantizer          = v->altpq;

    pic_param->transform_fields.value                               = 0; /* reset all bits */

    pic_param->transform_fields.bits.variable_sized_transform_flag  = v->vstransform;

    pic_param->transform_fields.bits.mb_level_transform_type_flag   = v->ttmbf;

    pic_param->transform_fields.bits.frame_level_transform_type     = vc1_get_TTFRM(v);

    pic_param->transform_fields.bits.transform_ac_codingset_idx1    = v->c_ac_table_index;

    pic_param->transform_fields.bits.transform_ac_codingset_idx2    = v->y_ac_table_index;

    pic_param->transform_fields.bits.intra_transform_dc_table       = v->s.dc_table_index;



    switch (s->pict_type) {

    case AV_PICTURE_TYPE_B:

        pic_param->backward_reference_picture = ff_vaapi_get_surface_id(s->next_picture.f);

        // fall-through

    case AV_PICTURE_TYPE_P:

        pic_param->forward_reference_picture = ff_vaapi_get_surface_id(s->last_picture.f);

        break;

    }



    if (pic_param->bitplane_present.value) {

        uint8_t *bitplane;

        const uint8_t *ff_bp[3];

        int x, y, n;



        switch (s->pict_type) {

        case AV_PICTURE_TYPE_P:

            ff_bp[0] = pic_param->bitplane_present.flags.bp_direct_mb  ? v->direct_mb_plane    : NULL;

            ff_bp[1] = pic_param->bitplane_present.flags.bp_skip_mb    ? s->mbskip_table       : NULL;

            ff_bp[2] = pic_param->bitplane_present.flags.bp_mv_type_mb ? v->mv_type_mb_plane   : NULL;

            break;

        case AV_PICTURE_TYPE_B:

            if (!v->bi_type) {

                ff_bp[0] = pic_param->bitplane_present.flags.bp_direct_mb ? v->direct_mb_plane : NULL;

                ff_bp[1] = pic_param->bitplane_present.flags.bp_skip_mb   ? s->mbskip_table    : NULL;

                ff_bp[2] = NULL; /* XXX: interlaced frame (FORWARD plane) */

                break;

            }

            /* fall-through (BI-type) */

        case AV_PICTURE_TYPE_I:

            ff_bp[0] = NULL; /* XXX: interlaced frame (FIELDTX plane) */

            ff_bp[1] = pic_param->bitplane_present.flags.bp_ac_pred    ? v->acpred_plane       : NULL;

            ff_bp[2] = pic_param->bitplane_present.flags.bp_overflags  ? v->over_flags_plane   : NULL;

            break;

        default:

            ff_bp[0] = NULL;

            ff_bp[1] = NULL;

            ff_bp[2] = NULL;

            break;

        }



        bitplane = ff_vaapi_alloc_bitplane(vactx, (s->mb_width * s->mb_height + 1) / 2);

        if (!bitplane)

            return -1;



        n = 0;

        for (y = 0; y < s->mb_height; y++)

            for (x = 0; x < s->mb_width; x++, n++)

                vc1_pack_bitplanes(bitplane, n, ff_bp, x, y, s->mb_stride);

        if (n & 1) /* move last nibble to the high order */

            bitplane[n/2] <<= 4;

    }

    return 0;

}

static int vaapi_vc1_start_frame(AVCodecContext *avctx, av_unused const uint8_t *buffer, av_unused uint32_t size)

{

    const VC1Context *v = avctx->priv_data;

    const MpegEncContext *s = &v->s;

    struct vaapi_context * const vactx = avctx->hwaccel_context;

    VAPictureParameterBufferVC1 *pic_param;



    vactx->slice_param_size = sizeof(VASliceParameterBufferVC1);



    

    pic_param = ff_vaapi_alloc_pic_param(vactx, sizeof(VAPictureParameterBufferVC1));

    if (!pic_param)

        return -1;

    pic_param->forward_reference_picture                            = VA_INVALID_ID;

    pic_param->backward_reference_picture                           = VA_INVALID_ID;

    pic_param->inloop_decoded_picture                               = VA_INVALID_ID;

    pic_param->sequence_fields.value                                = 0; 

    pic_param->sequence_fields.bits.pulldown                        = v->broadcast;

    pic_param->sequence_fields.bits.interlace                       = v->interlace;

    pic_param->sequence_fields.bits.tfcntrflag                      = v->tfcntrflag;

    pic_param->sequence_fields.bits.finterpflag                     = v->finterpflag;

    pic_param->sequence_fields.bits.psf                             = v->psf;

    pic_param->sequence_fields.bits.multires                        = v->multires;

    pic_param->sequence_fields.bits.overlap                         = v->overlap;

    pic_param->sequence_fields.bits.syncmarker                      = v->resync_marker;

    pic_param->sequence_fields.bits.rangered                        = v->rangered;

    pic_param->sequence_fields.bits.max_b_frames                    = s->avctx->max_b_frames;

#if VA_CHECK_VERSION(0,32,0)

    pic_param->sequence_fields.bits.profile                         = v->profile;

#endif

    pic_param->coded_width                                          = s->avctx->coded_width;

    pic_param->coded_height                                         = s->avctx->coded_height;

    pic_param->entrypoint_fields.value                              = 0; 

    pic_param->entrypoint_fields.bits.broken_link                   = v->broken_link;

    pic_param->entrypoint_fields.bits.closed_entry                  = v->closed_entry;

    pic_param->entrypoint_fields.bits.panscan_flag                  = v->panscanflag;

    pic_param->entrypoint_fields.bits.loopfilter                    = s->loop_filter;

    pic_param->conditional_overlap_flag                             = v->condover;

    pic_param->fast_uvmc_flag                                       = v->fastuvmc;

    pic_param->range_mapping_fields.value                           = 0; 

    pic_param->range_mapping_fields.bits.luma_flag                  = v->range_mapy_flag;

    pic_param->range_mapping_fields.bits.luma                       = v->range_mapy;

    pic_param->range_mapping_fields.bits.chroma_flag                = v->range_mapuv_flag;

    pic_param->range_mapping_fields.bits.chroma                     = v->range_mapuv;

    pic_param->b_picture_fraction                                   = v->bfraction_lut_index;

    pic_param->cbp_table                                            = v->cbpcy_vlc ? v->cbpcy_vlc - ff_vc1_cbpcy_p_vlc : 0;

    pic_param->mb_mode_table                                        = 0; 

    pic_param->range_reduction_frame                                = v->rangeredfrm;

    pic_param->rounding_control                                     = v->rnd;

    pic_param->post_processing                                      = v->postproc;

    pic_param->picture_resolution_index                             = v->respic;

    pic_param->luma_scale                                           = v->lumscale;

    pic_param->luma_shift                                           = v->lumshift;

    pic_param->picture_fields.value                                 = 0; 

    pic_param->picture_fields.bits.picture_type                     = vc1_get_PTYPE(v);

    pic_param->picture_fields.bits.frame_coding_mode                = v->fcm;

    pic_param->picture_fields.bits.top_field_first                  = v->tff;

    pic_param->picture_fields.bits.is_first_field                   = v->fcm == 0; 

    pic_param->picture_fields.bits.intensity_compensation           = v->mv_mode == MV_PMODE_INTENSITY_COMP;

    pic_param->raw_coding.value                                     = 0; 

    pic_param->raw_coding.flags.mv_type_mb                          = v->mv_type_is_raw;

    pic_param->raw_coding.flags.direct_mb                           = v->dmb_is_raw;

    pic_param->raw_coding.flags.skip_mb                             = v->skip_is_raw;

    pic_param->raw_coding.flags.field_tx                            = 0; 

    pic_param->raw_coding.flags.forward_mb                          = 0; 

    pic_param->raw_coding.flags.ac_pred                             = v->acpred_is_raw;

    pic_param->raw_coding.flags.overflags                           = v->overflg_is_raw;

    pic_param->bitplane_present.value                               = 0; 

    pic_param->bitplane_present.flags.bp_mv_type_mb                 = vc1_has_MVTYPEMB_bitplane(v);

    pic_param->bitplane_present.flags.bp_direct_mb                  = vc1_has_DIRECTMB_bitplane(v);

    pic_param->bitplane_present.flags.bp_skip_mb                    = vc1_has_SKIPMB_bitplane(v);

    pic_param->bitplane_present.flags.bp_field_tx                   = 0; 

    pic_param->bitplane_present.flags.bp_forward_mb                 = 0; 

    pic_param->bitplane_present.flags.bp_ac_pred                    = vc1_has_ACPRED_bitplane(v);

    pic_param->bitplane_present.flags.bp_overflags                  = vc1_has_OVERFLAGS_bitplane(v);

    pic_param->reference_fields.value                               = 0; 

    pic_param->reference_fields.bits.reference_distance_flag        = v->refdist_flag;

    pic_param->reference_fields.bits.reference_distance             = 0; 

    pic_param->reference_fields.bits.num_reference_pictures         = 0; 

    pic_param->reference_fields.bits.reference_field_pic_indicator  = 0; 

    pic_param->mv_fields.value                                      = 0; 

    pic_param->mv_fields.bits.mv_mode                               = vc1_get_MVMODE(v);

    pic_param->mv_fields.bits.mv_mode2                              = vc1_get_MVMODE2(v);

    pic_param->mv_fields.bits.mv_table                              = s->mv_table_index;

    pic_param->mv_fields.bits.two_mv_block_pattern_table            = 0; 

    pic_param->mv_fields.bits.four_mv_switch                        = 0; 

    pic_param->mv_fields.bits.four_mv_block_pattern_table           = 0; 

    pic_param->mv_fields.bits.extended_mv_flag                      = v->extended_mv;

    pic_param->mv_fields.bits.extended_mv_range                     = v->mvrange;

    pic_param->mv_fields.bits.extended_dmv_flag                     = v->extended_dmv;

    pic_param->mv_fields.bits.extended_dmv_range                    = 0; 

    pic_param->pic_quantizer_fields.value                           = 0; 

    pic_param->pic_quantizer_fields.bits.dquant                     = v->dquant;

    pic_param->pic_quantizer_fields.bits.quantizer                  = v->quantizer_mode;

    pic_param->pic_quantizer_fields.bits.half_qp                    = v->halfpq;

    pic_param->pic_quantizer_fields.bits.pic_quantizer_scale        = v->pq;

    pic_param->pic_quantizer_fields.bits.pic_quantizer_type         = v->pquantizer;

    pic_param->pic_quantizer_fields.bits.dq_frame                   = v->dquantfrm;

    pic_param->pic_quantizer_fields.bits.dq_profile                 = v->dqprofile;

    pic_param->pic_quantizer_fields.bits.dq_sb_edge                 = v->dqprofile == DQPROFILE_SINGLE_EDGE  ? v->dqsbedge : 0;

    pic_param->pic_quantizer_fields.bits.dq_db_edge                 = v->dqprofile == DQPROFILE_DOUBLE_EDGES ? v->dqsbedge : 0;

    pic_param->pic_quantizer_fields.bits.dq_binary_level            = v->dqbilevel;

    pic_param->pic_quantizer_fields.bits.alt_pic_quantizer          = v->altpq;

    pic_param->transform_fields.value                               = 0; 

    pic_param->transform_fields.bits.variable_sized_transform_flag  = v->vstransform;

    pic_param->transform_fields.bits.mb_level_transform_type_flag   = v->ttmbf;

    pic_param->transform_fields.bits.frame_level_transform_type     = vc1_get_TTFRM(v);

    pic_param->transform_fields.bits.transform_ac_codingset_idx1    = v->c_ac_table_index;

    pic_param->transform_fields.bits.transform_ac_codingset_idx2    = v->y_ac_table_index;

    pic_param->transform_fields.bits.intra_transform_dc_table       = v->s.dc_table_index;



    switch (s->pict_type) {

    case AV_PICTURE_TYPE_B:

        pic_param->backward_reference_picture = ff_vaapi_get_surface_id(s->next_picture.f);

        

    case AV_PICTURE_TYPE_P:

        pic_param->forward_reference_picture = ff_vaapi_get_surface_id(s->last_picture.f);

        break;

    }



    if (pic_param->bitplane_present.value) {

        uint8_t *bitplane;

        const uint8_t *ff_bp[3];

        int x, y, n;



        switch (s->pict_type) {

        case AV_PICTURE_TYPE_P:

            ff_bp[0] = pic_param->bitplane_present.flags.bp_direct_mb  ? v->direct_mb_plane    : NULL;

            ff_bp[1] = pic_param->bitplane_present.flags.bp_skip_mb    ? s->mbskip_table       : NULL;

            ff_bp[2] = pic_param->bitplane_present.flags.bp_mv_type_mb ? v->mv_type_mb_plane   : NULL;

            break;

        case AV_PICTURE_TYPE_B:

            if (!v->bi_type) {

                ff_bp[0] = pic_param->bitplane_present.flags.bp_direct_mb ? v->direct_mb_plane : NULL;

                ff_bp[1] = pic_param->bitplane_present.flags.bp_skip_mb   ? s->mbskip_table    : NULL;

                ff_bp[2] = NULL; 

                break;

            }

            

        case AV_PICTURE_TYPE_I:

            ff_bp[0] = NULL; 

            ff_bp[1] = pic_param->bitplane_present.flags.bp_ac_pred    ? v->acpred_plane       : NULL;

            ff_bp[2] = pic_param->bitplane_present.flags.bp_overflags  ? v->over_flags_plane   : NULL;

            break;

        default:

            ff_bp[0] = NULL;

            ff_bp[1] = NULL;

            ff_bp[2] = NULL;

            break;

        }



        bitplane = ff_vaapi_alloc_bitplane(vactx, (s->mb_width * s->mb_height + 1) / 2);

        if (!bitplane)

            return -1;



        n = 0;

        for (y = 0; y < s->mb_height; y++)

            for (x = 0; x < s->mb_width; x++, n++)

                vc1_pack_bitplanes(bitplane, n, ff_bp, x, y, s->mb_stride);

        if (n & 1) 

            bitplane[n/2] <<= 4;

    }

    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, av_unused const VAR_1 *buffer, av_unused uint32_t size)

{

    const VC1Context *VAR_2 = VAR_0->priv_data;

    const MpegEncContext *VAR_3 = &VAR_2->VAR_3;

    struct vaapi_context * const VAR_4 = VAR_0->hwaccel_context;

    VAPictureParameterBufferVC1 *pic_param;



    VAR_4->slice_param_size = sizeof(VASliceParameterBufferVC1);



    

    pic_param = ff_vaapi_alloc_pic_param(VAR_4, sizeof(VAPictureParameterBufferVC1));

    if (!pic_param)

        return -1;

    pic_param->forward_reference_picture                            = VA_INVALID_ID;

    pic_param->backward_reference_picture                           = VA_INVALID_ID;

    pic_param->inloop_decoded_picture                               = VA_INVALID_ID;

    pic_param->sequence_fields.value                                = 0; 

    pic_param->sequence_fields.bits.pulldown                        = VAR_2->broadcast;

    pic_param->sequence_fields.bits.interlace                       = VAR_2->interlace;

    pic_param->sequence_fields.bits.tfcntrflag                      = VAR_2->tfcntrflag;

    pic_param->sequence_fields.bits.finterpflag                     = VAR_2->finterpflag;

    pic_param->sequence_fields.bits.psf                             = VAR_2->psf;

    pic_param->sequence_fields.bits.multires                        = VAR_2->multires;

    pic_param->sequence_fields.bits.overlap                         = VAR_2->overlap;

    pic_param->sequence_fields.bits.syncmarker                      = VAR_2->resync_marker;

    pic_param->sequence_fields.bits.rangered                        = VAR_2->rangered;

    pic_param->sequence_fields.bits.max_b_frames                    = VAR_3->VAR_0->max_b_frames;

#if VA_CHECK_VERSION(0,32,0)

    pic_param->sequence_fields.bits.profile                         = VAR_2->profile;

#endif

    pic_param->coded_width                                          = VAR_3->VAR_0->coded_width;

    pic_param->coded_height                                         = VAR_3->VAR_0->coded_height;

    pic_param->entrypoint_fields.value                              = 0; 

    pic_param->entrypoint_fields.bits.broken_link                   = VAR_2->broken_link;

    pic_param->entrypoint_fields.bits.closed_entry                  = VAR_2->closed_entry;

    pic_param->entrypoint_fields.bits.panscan_flag                  = VAR_2->panscanflag;

    pic_param->entrypoint_fields.bits.loopfilter                    = VAR_3->loop_filter;

    pic_param->conditional_overlap_flag                             = VAR_2->condover;

    pic_param->fast_uvmc_flag                                       = VAR_2->fastuvmc;

    pic_param->range_mapping_fields.value                           = 0; 

    pic_param->range_mapping_fields.bits.luma_flag                  = VAR_2->range_mapy_flag;

    pic_param->range_mapping_fields.bits.luma                       = VAR_2->range_mapy;

    pic_param->range_mapping_fields.bits.chroma_flag                = VAR_2->range_mapuv_flag;

    pic_param->range_mapping_fields.bits.chroma                     = VAR_2->range_mapuv;

    pic_param->b_picture_fraction                                   = VAR_2->bfraction_lut_index;

    pic_param->cbp_table                                            = VAR_2->cbpcy_vlc ? VAR_2->cbpcy_vlc - ff_vc1_cbpcy_p_vlc : 0;

    pic_param->mb_mode_table                                        = 0; 

    pic_param->range_reduction_frame                                = VAR_2->rangeredfrm;

    pic_param->rounding_control                                     = VAR_2->rnd;

    pic_param->post_processing                                      = VAR_2->postproc;

    pic_param->picture_resolution_index                             = VAR_2->respic;

    pic_param->luma_scale                                           = VAR_2->lumscale;

    pic_param->luma_shift                                           = VAR_2->lumshift;

    pic_param->picture_fields.value                                 = 0; 

    pic_param->picture_fields.bits.picture_type                     = vc1_get_PTYPE(VAR_2);

    pic_param->picture_fields.bits.frame_coding_mode                = VAR_2->fcm;

    pic_param->picture_fields.bits.top_field_first                  = VAR_2->tff;

    pic_param->picture_fields.bits.is_first_field                   = VAR_2->fcm == 0; 

    pic_param->picture_fields.bits.intensity_compensation           = VAR_2->mv_mode == MV_PMODE_INTENSITY_COMP;

    pic_param->raw_coding.value                                     = 0; 

    pic_param->raw_coding.flags.mv_type_mb                          = VAR_2->mv_type_is_raw;

    pic_param->raw_coding.flags.direct_mb                           = VAR_2->dmb_is_raw;

    pic_param->raw_coding.flags.skip_mb                             = VAR_2->skip_is_raw;

    pic_param->raw_coding.flags.field_tx                            = 0; 

    pic_param->raw_coding.flags.forward_mb                          = 0; 

    pic_param->raw_coding.flags.ac_pred                             = VAR_2->acpred_is_raw;

    pic_param->raw_coding.flags.overflags                           = VAR_2->overflg_is_raw;

    pic_param->bitplane_present.value                               = 0; 

    pic_param->bitplane_present.flags.bp_mv_type_mb                 = vc1_has_MVTYPEMB_bitplane(VAR_2);

    pic_param->bitplane_present.flags.bp_direct_mb                  = vc1_has_DIRECTMB_bitplane(VAR_2);

    pic_param->bitplane_present.flags.bp_skip_mb                    = vc1_has_SKIPMB_bitplane(VAR_2);

    pic_param->bitplane_present.flags.bp_field_tx                   = 0; 

    pic_param->bitplane_present.flags.bp_forward_mb                 = 0; 

    pic_param->bitplane_present.flags.bp_ac_pred                    = vc1_has_ACPRED_bitplane(VAR_2);

    pic_param->bitplane_present.flags.bp_overflags                  = vc1_has_OVERFLAGS_bitplane(VAR_2);

    pic_param->reference_fields.value                               = 0; 

    pic_param->reference_fields.bits.reference_distance_flag        = VAR_2->refdist_flag;

    pic_param->reference_fields.bits.reference_distance             = 0; 

    pic_param->reference_fields.bits.num_reference_pictures         = 0; 

    pic_param->reference_fields.bits.reference_field_pic_indicator  = 0; 

    pic_param->mv_fields.value                                      = 0; 

    pic_param->mv_fields.bits.mv_mode                               = vc1_get_MVMODE(VAR_2);

    pic_param->mv_fields.bits.mv_mode2                              = vc1_get_MVMODE2(VAR_2);

    pic_param->mv_fields.bits.mv_table                              = VAR_3->mv_table_index;

    pic_param->mv_fields.bits.two_mv_block_pattern_table            = 0; 

    pic_param->mv_fields.bits.four_mv_switch                        = 0; 

    pic_param->mv_fields.bits.four_mv_block_pattern_table           = 0; 

    pic_param->mv_fields.bits.extended_mv_flag                      = VAR_2->extended_mv;

    pic_param->mv_fields.bits.extended_mv_range                     = VAR_2->mvrange;

    pic_param->mv_fields.bits.extended_dmv_flag                     = VAR_2->extended_dmv;

    pic_param->mv_fields.bits.extended_dmv_range                    = 0; 

    pic_param->pic_quantizer_fields.value                           = 0; 

    pic_param->pic_quantizer_fields.bits.dquant                     = VAR_2->dquant;

    pic_param->pic_quantizer_fields.bits.quantizer                  = VAR_2->quantizer_mode;

    pic_param->pic_quantizer_fields.bits.half_qp                    = VAR_2->halfpq;

    pic_param->pic_quantizer_fields.bits.pic_quantizer_scale        = VAR_2->pq;

    pic_param->pic_quantizer_fields.bits.pic_quantizer_type         = VAR_2->pquantizer;

    pic_param->pic_quantizer_fields.bits.dq_frame                   = VAR_2->dquantfrm;

    pic_param->pic_quantizer_fields.bits.dq_profile                 = VAR_2->dqprofile;

    pic_param->pic_quantizer_fields.bits.dq_sb_edge                 = VAR_2->dqprofile == DQPROFILE_SINGLE_EDGE  ? VAR_2->dqsbedge : 0;

    pic_param->pic_quantizer_fields.bits.dq_db_edge                 = VAR_2->dqprofile == DQPROFILE_DOUBLE_EDGES ? VAR_2->dqsbedge : 0;

    pic_param->pic_quantizer_fields.bits.dq_binary_level            = VAR_2->dqbilevel;

    pic_param->pic_quantizer_fields.bits.alt_pic_quantizer          = VAR_2->altpq;

    pic_param->transform_fields.value                               = 0; 

    pic_param->transform_fields.bits.variable_sized_transform_flag  = VAR_2->vstransform;

    pic_param->transform_fields.bits.mb_level_transform_type_flag   = VAR_2->ttmbf;

    pic_param->transform_fields.bits.frame_level_transform_type     = vc1_get_TTFRM(VAR_2);

    pic_param->transform_fields.bits.transform_ac_codingset_idx1    = VAR_2->c_ac_table_index;

    pic_param->transform_fields.bits.transform_ac_codingset_idx2    = VAR_2->y_ac_table_index;

    pic_param->transform_fields.bits.intra_transform_dc_table       = VAR_2->VAR_3.dc_table_index;



    switch (VAR_3->pict_type) {

    case AV_PICTURE_TYPE_B:

        pic_param->backward_reference_picture = ff_vaapi_get_surface_id(VAR_3->next_picture.f);

        

    case AV_PICTURE_TYPE_P:

        pic_param->forward_reference_picture = ff_vaapi_get_surface_id(VAR_3->last_picture.f);

        break;

    }



    if (pic_param->bitplane_present.value) {

        VAR_1 *bitplane;

        const VAR_1 *VAR_5[3];

        int VAR_6, VAR_7, VAR_8;



        switch (VAR_3->pict_type) {

        case AV_PICTURE_TYPE_P:

            VAR_5[0] = pic_param->bitplane_present.flags.bp_direct_mb  ? VAR_2->direct_mb_plane    : NULL;

            VAR_5[1] = pic_param->bitplane_present.flags.bp_skip_mb    ? VAR_3->mbskip_table       : NULL;

            VAR_5[2] = pic_param->bitplane_present.flags.bp_mv_type_mb ? VAR_2->mv_type_mb_plane   : NULL;

            break;

        case AV_PICTURE_TYPE_B:

            if (!VAR_2->bi_type) {

                VAR_5[0] = pic_param->bitplane_present.flags.bp_direct_mb ? VAR_2->direct_mb_plane : NULL;

                VAR_5[1] = pic_param->bitplane_present.flags.bp_skip_mb   ? VAR_3->mbskip_table    : NULL;

                VAR_5[2] = NULL; 

                break;

            }

            

        case AV_PICTURE_TYPE_I:

            VAR_5[0] = NULL; 

            VAR_5[1] = pic_param->bitplane_present.flags.bp_ac_pred    ? VAR_2->acpred_plane       : NULL;

            VAR_5[2] = pic_param->bitplane_present.flags.bp_overflags  ? VAR_2->over_flags_plane   : NULL;

            break;

        default:

            VAR_5[0] = NULL;

            VAR_5[1] = NULL;

            VAR_5[2] = NULL;

            break;

        }



        bitplane = ff_vaapi_alloc_bitplane(VAR_4, (VAR_3->mb_width * VAR_3->mb_height + 1) / 2);

        if (!bitplane)

            return -1;



        VAR_8 = 0;

        for (VAR_7 = 0; VAR_7 < VAR_3->mb_height; VAR_7++)

            for (VAR_6 = 0; VAR_6 < VAR_3->mb_width; VAR_6++, VAR_8++)

                vc1_pack_bitplanes(bitplane, VAR_8, VAR_5, VAR_6, VAR_7, VAR_3->mb_stride);

        if (VAR_8 & 1) 

            bitplane[VAR_8/2] <<= 4;

    }

    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, av_unused const VAR_1 *buffer, av_unused uint32_t size)
{ const VC1Context *VAR_2 = VAR_0->priv_data; const MpegEncContext *VAR_3 = &VAR_2->VAR_3; struct vaapi_context * const VAR_4 = VAR_0->hwaccel_context; VAPictureParameterBufferVC1 *pic_param; VAR_4->slice_param_size = sizeof(VASliceParameterBufferVC1); pic_param = ff_vaapi_alloc_pic_param(VAR_4, sizeof(VAPictureParameterBufferVC1)); if (!pic_param)
return -1; pic_param->forward_reference_picture                            = VA_INVALID_ID; pic_param->backward_reference_picture                           = VA_INVALID_ID; pic_param->inloop_decoded_picture                               = VA_INVALID_ID; pic_param->sequence_fields.value                                = 0; pic_param->sequence_fields.bits.pulldown                        = VAR_2->broadcast; pic_param->sequence_fields.bits.interlace                       = VAR_2->interlace; pic_param->sequence_fields.bits.tfcntrflag                      = VAR_2->tfcntrflag; pic_param->sequence_fields.bits.finterpflag                     = VAR_2->finterpflag; pic_param->sequence_fields.bits.psf                             = VAR_2->psf; pic_param->sequence_fields.bits.multires                        = VAR_2->multires; pic_param->sequence_fields.bits.overlap                         = VAR_2->overlap; pic_param->sequence_fields.bits.syncmarker                      = VAR_2->resync_marker; pic_param->sequence_fields.bits.rangered                        = VAR_2->rangered; pic_param->sequence_fields.bits.max_b_frames                    = VAR_3->VAR_0->max_b_frames; #if VA_CHECK_VERSION(0,32,0)
pic_param->sequence_fields.bits.profile                         = VAR_2->profile; #endif
pic_param->coded_width                                          = VAR_3->VAR_0->coded_width; pic_param->coded_height                                         = VAR_3->VAR_0->coded_height; pic_param->entrypoint_fields.value                              = 0; pic_param->entrypoint_fields.bits.broken_link                   = VAR_2->broken_link; pic_param->entrypoint_fields.bits.closed_entry                  = VAR_2->closed_entry; pic_param->entrypoint_fields.bits.panscan_flag                  = VAR_2->panscanflag; pic_param->entrypoint_fields.bits.loopfilter                    = VAR_3->loop_filter; pic_param->conditional_overlap_flag                             = VAR_2->condover; pic_param->fast_uvmc_flag                                       = VAR_2->fastuvmc; pic_param->range_mapping_fields.value                           = 0; pic_param->range_mapping_fields.bits.luma_flag                  = VAR_2->range_mapy_flag; pic_param->range_mapping_fields.bits.luma                       = VAR_2->range_mapy; pic_param->range_mapping_fields.bits.chroma_flag                = VAR_2->range_mapuv_flag; pic_param->range_mapping_fields.bits.chroma                     = VAR_2->range_mapuv; pic_param->b_picture_fraction                                   = VAR_2->bfraction_lut_index; pic_param->cbp_table                                            = VAR_2->cbpcy_vlc ? VAR_2->cbpcy_vlc - ff_vc1_cbpcy_p_vlc : 0; pic_param->mb_mode_table                                        = 0; pic_param->range_reduction_frame                                = VAR_2->rangeredfrm; pic_param->rounding_control                                     = VAR_2->rnd; pic_param->post_processing                                      = VAR_2->postproc; pic_param->picture_resolution_index                             = VAR_2->respic; pic_param->luma_scale                                           = VAR_2->lumscale; pic_param->luma_shift                                           = VAR_2->lumshift; pic_param->picture_fields.value                                 = 0; pic_param->picture_fields.bits.picture_type                     = vc1_get_PTYPE(VAR_2); pic_param->picture_fields.bits.frame_coding_mode                = VAR_2->fcm; pic_param->picture_fields.bits.top_field_first                  = VAR_2->tff; pic_param->picture_fields.bits.is_first_field                   = VAR_2->fcm == 0; pic_param->picture_fields.bits.intensity_compensation           = VAR_2->mv_mode == MV_PMODE_INTENSITY_COMP; pic_param->raw_coding.value                                     = 0; pic_param->raw_coding.flags.mv_type_mb                          = VAR_2->mv_type_is_raw; pic_param->raw_coding.flags.direct_mb                           = VAR_2->dmb_is_raw; pic_param->raw_coding.flags.skip_mb                             = VAR_2->skip_is_raw; pic_param->raw_coding.flags.field_tx                            = 0; pic_param->raw_coding.flags.forward_mb                          = 0; pic_param->raw_coding.flags.ac_pred                             = VAR_2->acpred_is_raw; pic_param->raw_coding.flags.overflags                           = VAR_2->overflg_is_raw; pic_param->bitplane_present.value                               = 0; pic_param->bitplane_present.flags.bp_mv_type_mb                 = vc1_has_MVTYPEMB_bitplane(VAR_2); pic_param->bitplane_present.flags.bp_direct_mb                  = vc1_has_DIRECTMB_bitplane(VAR_2); pic_param->bitplane_present.flags.bp_skip_mb                    = vc1_has_SKIPMB_bitplane(VAR_2); pic_param->bitplane_present.flags.bp_field_tx                   = 0; pic_param->bitplane_present.flags.bp_forward_mb                 = 0; pic_param->bitplane_present.flags.bp_ac_pred                    = vc1_has_ACPRED_bitplane(VAR_2); pic_param->bitplane_present.flags.bp_overflags                  = vc1_has_OVERFLAGS_bitplane(VAR_2); pic_param->reference_fields.value                               = 0; pic_param->reference_fields.bits.reference_distance_flag        = VAR_2->refdist_flag; pic_param->reference_fields.bits.reference_distance             = 0; pic_param->reference_fields.bits.num_reference_pictures         = 0; pic_param->reference_fields.bits.reference_field_pic_indicator  = 0; pic_param->mv_fields.value                                      = 0; pic_param->mv_fields.bits.mv_mode                               = vc1_get_MVMODE(VAR_2); pic_param->mv_fields.bits.mv_mode2                              = vc1_get_MVMODE2(VAR_2); pic_param->mv_fields.bits.mv_table                              = VAR_3->mv_table_index; pic_param->mv_fields.bits.two_mv_block_pattern_table            = 0; pic_param->mv_fields.bits.four_mv_switch                        = 0; pic_param->mv_fields.bits.four_mv_block_pattern_table           = 0; pic_param->mv_fields.bits.extended_mv_flag                      = VAR_2->extended_mv; pic_param->mv_fields.bits.extended_mv_range                     = VAR_2->mvrange; pic_param->mv_fields.bits.extended_dmv_flag                     = VAR_2->extended_dmv; pic_param->mv_fields.bits.extended_dmv_range                    = 0; pic_param->pic_quantizer_fields.value                           = 0; pic_param->pic_quantizer_fields.bits.dquant                     = VAR_2->dquant; pic_param->pic_quantizer_fields.bits.quantizer                  = VAR_2->quantizer_mode; pic_param->pic_quantizer_fields.bits.half_qp                    = VAR_2->halfpq; pic_param->pic_quantizer_fields.bits.pic_quantizer_scale        = VAR_2->pq; pic_param->pic_quantizer_fields.bits.pic_quantizer_type         = VAR_2->pquantizer; pic_param->pic_quantizer_fields.bits.dq_frame                   = VAR_2->dquantfrm; pic_param->pic_quantizer_fields.bits.dq_profile                 = VAR_2->dqprofile; pic_param->pic_quantizer_fields.bits.dq_sb_edge                 = VAR_2->dqprofile == DQPROFILE_SINGLE_EDGE  ? VAR_2->dqsbedge : 0; pic_param->pic_quantizer_fields.bits.dq_db_edge                 = VAR_2->dqprofile == DQPROFILE_DOUBLE_EDGES ? VAR_2->dqsbedge : 0; pic_param->pic_quantizer_fields.bits.dq_binary_level            = VAR_2->dqbilevel; pic_param->pic_quantizer_fields.bits.alt_pic_quantizer          = VAR_2->altpq; pic_param->transform_fields.value                               = 0; pic_param->transform_fields.bits.variable_sized_transform_flag  = VAR_2->vstransform; pic_param->transform_fields.bits.mb_level_transform_type_flag   = VAR_2->ttmbf; pic_param->transform_fields.bits.frame_level_transform_type     = vc1_get_TTFRM(VAR_2); pic_param->transform_fields.bits.transform_ac_codingset_idx1    = VAR_2->c_ac_table_index; pic_param->transform_fields.bits.transform_ac_codingset_idx2    = VAR_2->y_ac_table_index; pic_param->transform_fields.bits.intra_transform_dc_table       = VAR_2->VAR_3.dc_table_index; switch (VAR_3->pict_type) { case AV_PICTURE_TYPE_B:
pic_param->backward_reference_picture = ff_vaapi_get_surface_id(VAR_3->next_picture.f); case AV_PICTURE_TYPE_P:
pic_param->forward_reference_picture = ff_vaapi_get_surface_id(VAR_3->last_picture.f); break; } if (pic_param->bitplane_present.value) { VAR_1 *bitplane; const VAR_1 *VAR_5[3]; int VAR_6, VAR_7, VAR_8; switch (VAR_3->pict_type) { case AV_PICTURE_TYPE_P:
VAR_5[0] = pic_param->bitplane_present.flags.bp_direct_mb  ? VAR_2->direct_mb_plane    : NULL; VAR_5[1] = pic_param->bitplane_present.flags.bp_skip_mb    ? VAR_3->mbskip_table       : NULL; VAR_5[2] = pic_param->bitplane_present.flags.bp_mv_type_mb ? VAR_2->mv_type_mb_plane   : NULL; break; case AV_PICTURE_TYPE_B:
if (!VAR_2->bi_type) { VAR_5[0] = pic_param->bitplane_present.flags.bp_direct_mb ? VAR_2->direct_mb_plane : NULL; VAR_5[1] = pic_param->bitplane_present.flags.bp_skip_mb   ? VAR_3->mbskip_table    : NULL; VAR_5[2] = NULL; break; } case AV_PICTURE_TYPE_I:
VAR_5[0] = NULL; VAR_5[1] = pic_param->bitplane_present.flags.bp_ac_pred    ? VAR_2->acpred_plane       : NULL; VAR_5[2] = pic_param->bitplane_present.flags.bp_overflags  ? VAR_2->over_flags_plane   : NULL; break; default:
VAR_5[0] = NULL; VAR_5[1] = NULL; VAR_5[2] = NULL; break; } bitplane = ff_vaapi_alloc_bitplane(VAR_4, (VAR_3->mb_width * VAR_3->mb_height + 1) / 2); if (!bitplane)
return -1; VAR_8 = 0; for (VAR_7 = 0; VAR_7 < VAR_3->mb_height; VAR_7++) for (VAR_6 = 0; VAR_6 < VAR_3->mb_width; VAR_6++, VAR_8++) vc1_pack_bitplanes(bitplane, VAR_8, VAR_5, VAR_6, VAR_7, VAR_3->mb_stride); if (VAR_8 & 1)
bitplane[VAR_8/2] <<= 4; } return 0; }