static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl,

                                   const H2645NAL *nal)

{

    const SPS *sps;

    const PPS *pps;

    int ret;

    unsigned int slice_type, tmp, i;

    int field_pic_flag, bottom_field_flag;

    int droppable, picture_structure;



    sl->first_mb_addr = get_ue_golomb(&sl->gb);



    slice_type = get_ue_golomb_31(&sl->gb);

    if (slice_type > 9) {

        av_log(h->avctx, AV_LOG_ERROR,

               "slice type %d too large at %d\n",

               slice_type, sl->first_mb_addr);

        return AVERROR_INVALIDDATA;

    }

    if (slice_type > 4) {

        slice_type -= 5;

        sl->slice_type_fixed = 1;

    } else

        sl->slice_type_fixed = 0;



    slice_type         = ff_h264_golomb_to_pict_type[slice_type];

    sl->slice_type     = slice_type;

    sl->slice_type_nos = slice_type & 3;



    if (nal->type  == NAL_IDR_SLICE &&

        sl->slice_type_nos != AV_PICTURE_TYPE_I) {

        av_log(h->avctx, AV_LOG_ERROR, "A non-intra slice in an IDR NAL unit.\n");

        return AVERROR_INVALIDDATA;

    }



    sl->pps_id = get_ue_golomb(&sl->gb);

    if (sl->pps_id >= MAX_PPS_COUNT) {

        av_log(h->avctx, AV_LOG_ERROR, "pps_id %u out of range\n", sl->pps_id);

        return AVERROR_INVALIDDATA;

    }

    if (!h->ps.pps_list[sl->pps_id]) {

        av_log(h->avctx, AV_LOG_ERROR,

               "non-existing PPS %u referenced\n",

               sl->pps_id);

        return AVERROR_INVALIDDATA;

    }

    pps = (const PPS*)h->ps.pps_list[sl->pps_id]->data;



    if (!h->ps.sps_list[pps->sps_id]) {

        av_log(h->avctx, AV_LOG_ERROR,

               "non-existing SPS %u referenced\n", pps->sps_id);

        return AVERROR_INVALIDDATA;

    }

    sps = (const SPS*)h->ps.sps_list[pps->sps_id]->data;



    sl->frame_num = get_bits(&sl->gb, sps->log2_max_frame_num);



    sl->mb_mbaff       = 0;



    droppable = nal->ref_idc == 0;

    if (sps->frame_mbs_only_flag) {

        picture_structure = PICT_FRAME;

    } else {

        field_pic_flag = get_bits1(&sl->gb);

        if (field_pic_flag) {

            bottom_field_flag = get_bits1(&sl->gb);

            picture_structure = PICT_TOP_FIELD + bottom_field_flag;

        } else {

            picture_structure = PICT_FRAME;

        }

    }

    sl->picture_structure      = picture_structure;

    sl->mb_field_decoding_flag = picture_structure != PICT_FRAME;



    if (picture_structure == PICT_FRAME) {

        sl->curr_pic_num = sl->frame_num;

        sl->max_pic_num  = 1 << sps->log2_max_frame_num;

    } else {

        sl->curr_pic_num = 2 * sl->frame_num + 1;

        sl->max_pic_num  = 1 << (sps->log2_max_frame_num + 1);

    }



    if (nal->type == NAL_IDR_SLICE)

        get_ue_golomb(&sl->gb); /* idr_pic_id */



    if (sps->poc_type == 0) {

        sl->poc_lsb = get_bits(&sl->gb, sps->log2_max_poc_lsb);



        if (pps->pic_order_present == 1 && picture_structure == PICT_FRAME)

            sl->delta_poc_bottom = get_se_golomb(&sl->gb);

    }



    if (sps->poc_type == 1 && !sps->delta_pic_order_always_zero_flag) {

        sl->delta_poc[0] = get_se_golomb(&sl->gb);



        if (pps->pic_order_present == 1 && picture_structure == PICT_FRAME)

            sl->delta_poc[1] = get_se_golomb(&sl->gb);

    }



    if (pps->redundant_pic_cnt_present)

        sl->redundant_pic_count = get_ue_golomb(&sl->gb);



    if (sl->slice_type_nos == AV_PICTURE_TYPE_B)

        sl->direct_spatial_mv_pred = get_bits1(&sl->gb);



    ret = ff_h264_parse_ref_count(&sl->list_count, sl->ref_count,

                                  &sl->gb, pps, sl->slice_type_nos,

                                  picture_structure);

    if (ret < 0)

        return ret;



    if (sl->slice_type_nos != AV_PICTURE_TYPE_I) {

       ret = ff_h264_decode_ref_pic_list_reordering(h, sl);

       if (ret < 0) {

           sl->ref_count[1] = sl->ref_count[0] = 0;

           return ret;

       }

    }



    sl->pwt.use_weight = 0;

    for (i = 0; i < 2; i++) {

        sl->pwt.luma_weight_flag[i]   = 0;

        sl->pwt.chroma_weight_flag[i] = 0;

    }

    if ((pps->weighted_pred && sl->slice_type_nos == AV_PICTURE_TYPE_P) ||

        (pps->weighted_bipred_idc == 1 &&

         sl->slice_type_nos == AV_PICTURE_TYPE_B))

        ff_h264_pred_weight_table(&sl->gb, sps, sl->ref_count,

                                  sl->slice_type_nos, &sl->pwt);



    sl->explicit_ref_marking = 0;

    if (nal->ref_idc) {

        ret = ff_h264_decode_ref_pic_marking(h, sl, &sl->gb);

        if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))

            return AVERROR_INVALIDDATA;

    }



    if (sl->slice_type_nos != AV_PICTURE_TYPE_I && pps->cabac) {

        tmp = get_ue_golomb_31(&sl->gb);

        if (tmp > 2) {

            av_log(h->avctx, AV_LOG_ERROR, "cabac_init_idc %u overflow\n", tmp);

            return AVERROR_INVALIDDATA;

        }

        sl->cabac_init_idc = tmp;

    }



    sl->last_qscale_diff = 0;

    tmp = pps->init_qp + get_se_golomb(&sl->gb);

    if (tmp > 51 + 6 * (sps->bit_depth_luma - 8)) {

        av_log(h->avctx, AV_LOG_ERROR, "QP %u out of range\n", tmp);

        return AVERROR_INVALIDDATA;

    }

    sl->qscale       = tmp;

    sl->chroma_qp[0] = get_chroma_qp(pps, 0, sl->qscale);

    sl->chroma_qp[1] = get_chroma_qp(pps, 1, sl->qscale);

    // FIXME qscale / qp ... stuff

    if (sl->slice_type == AV_PICTURE_TYPE_SP)

        get_bits1(&sl->gb); /* sp_for_switch_flag */

    if (sl->slice_type == AV_PICTURE_TYPE_SP ||

        sl->slice_type == AV_PICTURE_TYPE_SI)

        get_se_golomb(&sl->gb); /* slice_qs_delta */



    sl->deblocking_filter     = 1;

    sl->slice_alpha_c0_offset = 0;

    sl->slice_beta_offset     = 0;

    if (pps->deblocking_filter_parameters_present) {

        tmp = get_ue_golomb_31(&sl->gb);

        if (tmp > 2) {

            av_log(h->avctx, AV_LOG_ERROR,

                   "deblocking_filter_idc %u out of range\n", tmp);

            return AVERROR_INVALIDDATA;

        }

        sl->deblocking_filter = tmp;

        if (sl->deblocking_filter < 2)

            sl->deblocking_filter ^= 1;  // 1<->0



        if (sl->deblocking_filter) {

            sl->slice_alpha_c0_offset = get_se_golomb(&sl->gb) * 2;

            sl->slice_beta_offset     = get_se_golomb(&sl->gb) * 2;

            if (sl->slice_alpha_c0_offset >  12 ||

                sl->slice_alpha_c0_offset < -12 ||

                sl->slice_beta_offset >  12     ||

                sl->slice_beta_offset < -12) {

                av_log(h->avctx, AV_LOG_ERROR,

                       "deblocking filter parameters %d %d out of range\n",

                       sl->slice_alpha_c0_offset, sl->slice_beta_offset);

                return AVERROR_INVALIDDATA;

            }

        }

    }



    return 0;

}

static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl,

                                   const H2645NAL *nal)

{

    const SPS *sps;

    const PPS *pps;

    int ret;

    unsigned int slice_type, tmp, i;

    int field_pic_flag, bottom_field_flag;

    int droppable, picture_structure;



    sl->first_mb_addr = get_ue_golomb(&sl->gb);



    slice_type = get_ue_golomb_31(&sl->gb);

    if (slice_type > 9) {

        av_log(h->avctx, AV_LOG_ERROR,

               "slice type %d too large at %d\n",

               slice_type, sl->first_mb_addr);

        return AVERROR_INVALIDDATA;

    }

    if (slice_type > 4) {

        slice_type -= 5;

        sl->slice_type_fixed = 1;

    } else

        sl->slice_type_fixed = 0;



    slice_type         = ff_h264_golomb_to_pict_type[slice_type];

    sl->slice_type     = slice_type;

    sl->slice_type_nos = slice_type & 3;



    if (nal->type  == NAL_IDR_SLICE &&

        sl->slice_type_nos != AV_PICTURE_TYPE_I) {

        av_log(h->avctx, AV_LOG_ERROR, "A non-intra slice in an IDR NAL unit.\n");

        return AVERROR_INVALIDDATA;

    }



    sl->pps_id = get_ue_golomb(&sl->gb);

    if (sl->pps_id >= MAX_PPS_COUNT) {

        av_log(h->avctx, AV_LOG_ERROR, "pps_id %u out of range\n", sl->pps_id);

        return AVERROR_INVALIDDATA;

    }

    if (!h->ps.pps_list[sl->pps_id]) {

        av_log(h->avctx, AV_LOG_ERROR,

               "non-existing PPS %u referenced\n",

               sl->pps_id);

        return AVERROR_INVALIDDATA;

    }

    pps = (const PPS*)h->ps.pps_list[sl->pps_id]->data;



    if (!h->ps.sps_list[pps->sps_id]) {

        av_log(h->avctx, AV_LOG_ERROR,

               "non-existing SPS %u referenced\n", pps->sps_id);

        return AVERROR_INVALIDDATA;

    }

    sps = (const SPS*)h->ps.sps_list[pps->sps_id]->data;



    sl->frame_num = get_bits(&sl->gb, sps->log2_max_frame_num);



    sl->mb_mbaff       = 0;



    droppable = nal->ref_idc == 0;

    if (sps->frame_mbs_only_flag) {

        picture_structure = PICT_FRAME;

    } else {

        field_pic_flag = get_bits1(&sl->gb);

        if (field_pic_flag) {

            bottom_field_flag = get_bits1(&sl->gb);

            picture_structure = PICT_TOP_FIELD + bottom_field_flag;

        } else {

            picture_structure = PICT_FRAME;

        }

    }

    sl->picture_structure      = picture_structure;

    sl->mb_field_decoding_flag = picture_structure != PICT_FRAME;



    if (picture_structure == PICT_FRAME) {

        sl->curr_pic_num = sl->frame_num;

        sl->max_pic_num  = 1 << sps->log2_max_frame_num;

    } else {

        sl->curr_pic_num = 2 * sl->frame_num + 1;

        sl->max_pic_num  = 1 << (sps->log2_max_frame_num + 1);

    }



    if (nal->type == NAL_IDR_SLICE)

        get_ue_golomb(&sl->gb); 



    if (sps->poc_type == 0) {

        sl->poc_lsb = get_bits(&sl->gb, sps->log2_max_poc_lsb);



        if (pps->pic_order_present == 1 && picture_structure == PICT_FRAME)

            sl->delta_poc_bottom = get_se_golomb(&sl->gb);

    }



    if (sps->poc_type == 1 && !sps->delta_pic_order_always_zero_flag) {

        sl->delta_poc[0] = get_se_golomb(&sl->gb);



        if (pps->pic_order_present == 1 && picture_structure == PICT_FRAME)

            sl->delta_poc[1] = get_se_golomb(&sl->gb);

    }



    if (pps->redundant_pic_cnt_present)

        sl->redundant_pic_count = get_ue_golomb(&sl->gb);



    if (sl->slice_type_nos == AV_PICTURE_TYPE_B)

        sl->direct_spatial_mv_pred = get_bits1(&sl->gb);



    ret = ff_h264_parse_ref_count(&sl->list_count, sl->ref_count,

                                  &sl->gb, pps, sl->slice_type_nos,

                                  picture_structure);

    if (ret < 0)

        return ret;



    if (sl->slice_type_nos != AV_PICTURE_TYPE_I) {

       ret = ff_h264_decode_ref_pic_list_reordering(h, sl);

       if (ret < 0) {

           sl->ref_count[1] = sl->ref_count[0] = 0;

           return ret;

       }

    }



    sl->pwt.use_weight = 0;

    for (i = 0; i < 2; i++) {

        sl->pwt.luma_weight_flag[i]   = 0;

        sl->pwt.chroma_weight_flag[i] = 0;

    }

    if ((pps->weighted_pred && sl->slice_type_nos == AV_PICTURE_TYPE_P) ||

        (pps->weighted_bipred_idc == 1 &&

         sl->slice_type_nos == AV_PICTURE_TYPE_B))

        ff_h264_pred_weight_table(&sl->gb, sps, sl->ref_count,

                                  sl->slice_type_nos, &sl->pwt);



    sl->explicit_ref_marking = 0;

    if (nal->ref_idc) {

        ret = ff_h264_decode_ref_pic_marking(h, sl, &sl->gb);

        if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))

            return AVERROR_INVALIDDATA;

    }



    if (sl->slice_type_nos != AV_PICTURE_TYPE_I && pps->cabac) {

        tmp = get_ue_golomb_31(&sl->gb);

        if (tmp > 2) {

            av_log(h->avctx, AV_LOG_ERROR, "cabac_init_idc %u overflow\n", tmp);

            return AVERROR_INVALIDDATA;

        }

        sl->cabac_init_idc = tmp;

    }



    sl->last_qscale_diff = 0;

    tmp = pps->init_qp + get_se_golomb(&sl->gb);

    if (tmp > 51 + 6 * (sps->bit_depth_luma - 8)) {

        av_log(h->avctx, AV_LOG_ERROR, "QP %u out of range\n", tmp);

        return AVERROR_INVALIDDATA;

    }

    sl->qscale       = tmp;

    sl->chroma_qp[0] = get_chroma_qp(pps, 0, sl->qscale);

    sl->chroma_qp[1] = get_chroma_qp(pps, 1, sl->qscale);

    

    if (sl->slice_type == AV_PICTURE_TYPE_SP)

        get_bits1(&sl->gb); 

    if (sl->slice_type == AV_PICTURE_TYPE_SP ||

        sl->slice_type == AV_PICTURE_TYPE_SI)

        get_se_golomb(&sl->gb); 



    sl->deblocking_filter     = 1;

    sl->slice_alpha_c0_offset = 0;

    sl->slice_beta_offset     = 0;

    if (pps->deblocking_filter_parameters_present) {

        tmp = get_ue_golomb_31(&sl->gb);

        if (tmp > 2) {

            av_log(h->avctx, AV_LOG_ERROR,

                   "deblocking_filter_idc %u out of range\n", tmp);

            return AVERROR_INVALIDDATA;

        }

        sl->deblocking_filter = tmp;

        if (sl->deblocking_filter < 2)

            sl->deblocking_filter ^= 1;  



        if (sl->deblocking_filter) {

            sl->slice_alpha_c0_offset = get_se_golomb(&sl->gb) * 2;

            sl->slice_beta_offset     = get_se_golomb(&sl->gb) * 2;

            if (sl->slice_alpha_c0_offset >  12 ||

                sl->slice_alpha_c0_offset < -12 ||

                sl->slice_beta_offset >  12     ||

                sl->slice_beta_offset < -12) {

                av_log(h->avctx, AV_LOG_ERROR,

                       "deblocking filter parameters %d %d out of range\n",

                       sl->slice_alpha_c0_offset, sl->slice_beta_offset);

                return AVERROR_INVALIDDATA;

            }

        }

    }



    return 0;

}

static int FUNC_0(const H264Context *VAR_0, H264SliceContext *VAR_1,

                                   const H2645NAL *VAR_2)

{

    const SPS *VAR_3;

    const PPS *VAR_4;

    int VAR_5;

    unsigned int VAR_6, VAR_7, VAR_8;

    int VAR_9, VAR_10;

    int VAR_11, VAR_12;



    VAR_1->first_mb_addr = get_ue_golomb(&VAR_1->gb);



    VAR_6 = get_ue_golomb_31(&VAR_1->gb);

    if (VAR_6 > 9) {

        av_log(VAR_0->avctx, AV_LOG_ERROR,

               "slice type %d too large at %d\n",

               VAR_6, VAR_1->first_mb_addr);

        return AVERROR_INVALIDDATA;

    }

    if (VAR_6 > 4) {

        VAR_6 -= 5;

        VAR_1->slice_type_fixed = 1;

    } else

        VAR_1->slice_type_fixed = 0;



    VAR_6         = ff_h264_golomb_to_pict_type[VAR_6];

    VAR_1->VAR_6     = VAR_6;

    VAR_1->slice_type_nos = VAR_6 & 3;



    if (VAR_2->type  == NAL_IDR_SLICE &&

        VAR_1->slice_type_nos != AV_PICTURE_TYPE_I) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "A non-intra slice in an IDR NAL unit.\n");

        return AVERROR_INVALIDDATA;

    }



    VAR_1->pps_id = get_ue_golomb(&VAR_1->gb);

    if (VAR_1->pps_id >= MAX_PPS_COUNT) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "pps_id %u out of range\n", VAR_1->pps_id);

        return AVERROR_INVALIDDATA;

    }

    if (!VAR_0->ps.pps_list[VAR_1->pps_id]) {

        av_log(VAR_0->avctx, AV_LOG_ERROR,

               "non-existing PPS %u referenced\n",

               VAR_1->pps_id);

        return AVERROR_INVALIDDATA;

    }

    VAR_4 = (const PPS*)VAR_0->ps.pps_list[VAR_1->pps_id]->data;



    if (!VAR_0->ps.sps_list[VAR_4->sps_id]) {

        av_log(VAR_0->avctx, AV_LOG_ERROR,

               "non-existing SPS %u referenced\n", VAR_4->sps_id);

        return AVERROR_INVALIDDATA;

    }

    VAR_3 = (const SPS*)VAR_0->ps.sps_list[VAR_4->sps_id]->data;



    VAR_1->frame_num = get_bits(&VAR_1->gb, VAR_3->log2_max_frame_num);



    VAR_1->mb_mbaff       = 0;



    VAR_11 = VAR_2->ref_idc == 0;

    if (VAR_3->frame_mbs_only_flag) {

        VAR_12 = PICT_FRAME;

    } else {

        VAR_9 = get_bits1(&VAR_1->gb);

        if (VAR_9) {

            VAR_10 = get_bits1(&VAR_1->gb);

            VAR_12 = PICT_TOP_FIELD + VAR_10;

        } else {

            VAR_12 = PICT_FRAME;

        }

    }

    VAR_1->VAR_12      = VAR_12;

    VAR_1->mb_field_decoding_flag = VAR_12 != PICT_FRAME;



    if (VAR_12 == PICT_FRAME) {

        VAR_1->curr_pic_num = VAR_1->frame_num;

        VAR_1->max_pic_num  = 1 << VAR_3->log2_max_frame_num;

    } else {

        VAR_1->curr_pic_num = 2 * VAR_1->frame_num + 1;

        VAR_1->max_pic_num  = 1 << (VAR_3->log2_max_frame_num + 1);

    }



    if (VAR_2->type == NAL_IDR_SLICE)

        get_ue_golomb(&VAR_1->gb); 



    if (VAR_3->poc_type == 0) {

        VAR_1->poc_lsb = get_bits(&VAR_1->gb, VAR_3->log2_max_poc_lsb);



        if (VAR_4->pic_order_present == 1 && VAR_12 == PICT_FRAME)

            VAR_1->delta_poc_bottom = get_se_golomb(&VAR_1->gb);

    }



    if (VAR_3->poc_type == 1 && !VAR_3->delta_pic_order_always_zero_flag) {

        VAR_1->delta_poc[0] = get_se_golomb(&VAR_1->gb);



        if (VAR_4->pic_order_present == 1 && VAR_12 == PICT_FRAME)

            VAR_1->delta_poc[1] = get_se_golomb(&VAR_1->gb);

    }



    if (VAR_4->redundant_pic_cnt_present)

        VAR_1->redundant_pic_count = get_ue_golomb(&VAR_1->gb);



    if (VAR_1->slice_type_nos == AV_PICTURE_TYPE_B)

        VAR_1->direct_spatial_mv_pred = get_bits1(&VAR_1->gb);



    VAR_5 = ff_h264_parse_ref_count(&VAR_1->list_count, VAR_1->ref_count,

                                  &VAR_1->gb, VAR_4, VAR_1->slice_type_nos,

                                  VAR_12);

    if (VAR_5 < 0)

        return VAR_5;



    if (VAR_1->slice_type_nos != AV_PICTURE_TYPE_I) {

       VAR_5 = ff_h264_decode_ref_pic_list_reordering(VAR_0, VAR_1);

       if (VAR_5 < 0) {

           VAR_1->ref_count[1] = VAR_1->ref_count[0] = 0;

           return VAR_5;

       }

    }



    VAR_1->pwt.use_weight = 0;

    for (VAR_8 = 0; VAR_8 < 2; VAR_8++) {

        VAR_1->pwt.luma_weight_flag[VAR_8]   = 0;

        VAR_1->pwt.chroma_weight_flag[VAR_8] = 0;

    }

    if ((VAR_4->weighted_pred && VAR_1->slice_type_nos == AV_PICTURE_TYPE_P) ||

        (VAR_4->weighted_bipred_idc == 1 &&

         VAR_1->slice_type_nos == AV_PICTURE_TYPE_B))

        ff_h264_pred_weight_table(&VAR_1->gb, VAR_3, VAR_1->ref_count,

                                  VAR_1->slice_type_nos, &VAR_1->pwt);



    VAR_1->explicit_ref_marking = 0;

    if (VAR_2->ref_idc) {

        VAR_5 = ff_h264_decode_ref_pic_marking(VAR_0, VAR_1, &VAR_1->gb);

        if (VAR_5 < 0 && (VAR_0->avctx->err_recognition & AV_EF_EXPLODE))

            return AVERROR_INVALIDDATA;

    }



    if (VAR_1->slice_type_nos != AV_PICTURE_TYPE_I && VAR_4->cabac) {

        VAR_7 = get_ue_golomb_31(&VAR_1->gb);

        if (VAR_7 > 2) {

            av_log(VAR_0->avctx, AV_LOG_ERROR, "cabac_init_idc %u overflow\n", VAR_7);

            return AVERROR_INVALIDDATA;

        }

        VAR_1->cabac_init_idc = VAR_7;

    }



    VAR_1->last_qscale_diff = 0;

    VAR_7 = VAR_4->init_qp + get_se_golomb(&VAR_1->gb);

    if (VAR_7 > 51 + 6 * (VAR_3->bit_depth_luma - 8)) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "QP %u out of range\n", VAR_7);

        return AVERROR_INVALIDDATA;

    }

    VAR_1->qscale       = VAR_7;

    VAR_1->chroma_qp[0] = get_chroma_qp(VAR_4, 0, VAR_1->qscale);

    VAR_1->chroma_qp[1] = get_chroma_qp(VAR_4, 1, VAR_1->qscale);

    

    if (VAR_1->VAR_6 == AV_PICTURE_TYPE_SP)

        get_bits1(&VAR_1->gb); 

    if (VAR_1->VAR_6 == AV_PICTURE_TYPE_SP ||

        VAR_1->VAR_6 == AV_PICTURE_TYPE_SI)

        get_se_golomb(&VAR_1->gb); 



    VAR_1->deblocking_filter     = 1;

    VAR_1->slice_alpha_c0_offset = 0;

    VAR_1->slice_beta_offset     = 0;

    if (VAR_4->deblocking_filter_parameters_present) {

        VAR_7 = get_ue_golomb_31(&VAR_1->gb);

        if (VAR_7 > 2) {

            av_log(VAR_0->avctx, AV_LOG_ERROR,

                   "deblocking_filter_idc %u out of range\n", VAR_7);

            return AVERROR_INVALIDDATA;

        }

        VAR_1->deblocking_filter = VAR_7;

        if (VAR_1->deblocking_filter < 2)

            VAR_1->deblocking_filter ^= 1;  



        if (VAR_1->deblocking_filter) {

            VAR_1->slice_alpha_c0_offset = get_se_golomb(&VAR_1->gb) * 2;

            VAR_1->slice_beta_offset     = get_se_golomb(&VAR_1->gb) * 2;

            if (VAR_1->slice_alpha_c0_offset >  12 ||

                VAR_1->slice_alpha_c0_offset < -12 ||

                VAR_1->slice_beta_offset >  12     ||

                VAR_1->slice_beta_offset < -12) {

                av_log(VAR_0->avctx, AV_LOG_ERROR,

                       "deblocking filter parameters %d %d out of range\n",

                       VAR_1->slice_alpha_c0_offset, VAR_1->slice_beta_offset);

                return AVERROR_INVALIDDATA;

            }

        }

    }



    return 0;

}

static int FUNC_0(const H264Context *VAR_0, H264SliceContext *VAR_1,
const H2645NAL *VAR_2)
{ const SPS *VAR_3; const PPS *VAR_4; int VAR_5; unsigned int VAR_6, VAR_7, VAR_8; int VAR_9, VAR_10; int VAR_11, VAR_12; VAR_1->first_mb_addr = get_ue_golomb(&VAR_1->gb); VAR_6 = get_ue_golomb_31(&VAR_1->gb); if (VAR_6 > 9) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"slice type %d too large at %d\n",
VAR_6, VAR_1->first_mb_addr); return AVERROR_INVALIDDATA; } if (VAR_6 > 4) { VAR_6 -= 5; VAR_1->slice_type_fixed = 1; } else VAR_1->slice_type_fixed = 0; VAR_6         = ff_h264_golomb_to_pict_type[VAR_6]; VAR_1->VAR_6     = VAR_6; VAR_1->slice_type_nos = VAR_6 & 3; if (VAR_2->type  == NAL_IDR_SLICE &&
VAR_1->slice_type_nos != AV_PICTURE_TYPE_I) { av_log(VAR_0->avctx, AV_LOG_ERROR, "A non-intra slice in an IDR NAL unit.\n"); return AVERROR_INVALIDDATA; } VAR_1->pps_id = get_ue_golomb(&VAR_1->gb); if (VAR_1->pps_id >= MAX_PPS_COUNT) { av_log(VAR_0->avctx, AV_LOG_ERROR, "pps_id %u out of range\n", VAR_1->pps_id); return AVERROR_INVALIDDATA; } if (!VAR_0->ps.pps_list[VAR_1->pps_id]) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"non-existing PPS %u referenced\n",
VAR_1->pps_id); return AVERROR_INVALIDDATA; } VAR_4 = (const PPS*)VAR_0->ps.pps_list[VAR_1->pps_id]->data; if (!VAR_0->ps.sps_list[VAR_4->sps_id]) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"non-existing SPS %u referenced\n", VAR_4->sps_id); return AVERROR_INVALIDDATA; } VAR_3 = (const SPS*)VAR_0->ps.sps_list[VAR_4->sps_id]->data; VAR_1->frame_num = get_bits(&VAR_1->gb, VAR_3->log2_max_frame_num); VAR_1->mb_mbaff       = 0; VAR_11 = VAR_2->ref_idc == 0; if (VAR_3->frame_mbs_only_flag) { VAR_12 = PICT_FRAME; } else { VAR_9 = get_bits1(&VAR_1->gb); if (VAR_9) { VAR_10 = get_bits1(&VAR_1->gb); VAR_12 = PICT_TOP_FIELD + VAR_10; } else { VAR_12 = PICT_FRAME; } } VAR_1->VAR_12      = VAR_12; VAR_1->mb_field_decoding_flag = VAR_12 != PICT_FRAME; if (VAR_12 == PICT_FRAME) { VAR_1->curr_pic_num = VAR_1->frame_num; VAR_1->max_pic_num  = 1 << VAR_3->log2_max_frame_num; } else { VAR_1->curr_pic_num = 2 * VAR_1->frame_num + 1; VAR_1->max_pic_num  = 1 << (VAR_3->log2_max_frame_num + 1); } if (VAR_2->type == NAL_IDR_SLICE)
get_ue_golomb(&VAR_1->gb); if (VAR_3->poc_type == 0) { VAR_1->poc_lsb = get_bits(&VAR_1->gb, VAR_3->log2_max_poc_lsb); if (VAR_4->pic_order_present == 1 && VAR_12 == PICT_FRAME)
VAR_1->delta_poc_bottom = get_se_golomb(&VAR_1->gb); } if (VAR_3->poc_type == 1 && !VAR_3->delta_pic_order_always_zero_flag) { VAR_1->delta_poc[0] = get_se_golomb(&VAR_1->gb); if (VAR_4->pic_order_present == 1 && VAR_12 == PICT_FRAME)
VAR_1->delta_poc[1] = get_se_golomb(&VAR_1->gb); } if (VAR_4->redundant_pic_cnt_present)
VAR_1->redundant_pic_count = get_ue_golomb(&VAR_1->gb); if (VAR_1->slice_type_nos == AV_PICTURE_TYPE_B)
VAR_1->direct_spatial_mv_pred = get_bits1(&VAR_1->gb); VAR_5 = ff_h264_parse_ref_count(&VAR_1->list_count, VAR_1->ref_count,
&VAR_1->gb, VAR_4, VAR_1->slice_type_nos,
VAR_12); if (VAR_5 < 0)
return VAR_5; if (VAR_1->slice_type_nos != AV_PICTURE_TYPE_I) { VAR_5 = ff_h264_decode_ref_pic_list_reordering(VAR_0, VAR_1); if (VAR_5 < 0) { VAR_1->ref_count[1] = VAR_1->ref_count[0] = 0; return VAR_5; } } VAR_1->pwt.use_weight = 0; for (VAR_8 = 0; VAR_8 < 2; VAR_8++) { VAR_1->pwt.luma_weight_flag[VAR_8]   = 0; VAR_1->pwt.chroma_weight_flag[VAR_8] = 0; } if ((VAR_4->weighted_pred && VAR_1->slice_type_nos == AV_PICTURE_TYPE_P) ||
(VAR_4->weighted_bipred_idc == 1 &&
VAR_1->slice_type_nos == AV_PICTURE_TYPE_B))
ff_h264_pred_weight_table(&VAR_1->gb, VAR_3, VAR_1->ref_count,
VAR_1->slice_type_nos, &VAR_1->pwt); VAR_1->explicit_ref_marking = 0; if (VAR_2->ref_idc) { VAR_5 = ff_h264_decode_ref_pic_marking(VAR_0, VAR_1, &VAR_1->gb); if (VAR_5 < 0 && (VAR_0->avctx->err_recognition & AV_EF_EXPLODE))
return AVERROR_INVALIDDATA; } if (VAR_1->slice_type_nos != AV_PICTURE_TYPE_I && VAR_4->cabac) { VAR_7 = get_ue_golomb_31(&VAR_1->gb); if (VAR_7 > 2) { av_log(VAR_0->avctx, AV_LOG_ERROR, "cabac_init_idc %u overflow\n", VAR_7); return AVERROR_INVALIDDATA; } VAR_1->cabac_init_idc = VAR_7; } VAR_1->last_qscale_diff = 0; VAR_7 = VAR_4->init_qp + get_se_golomb(&VAR_1->gb); if (VAR_7 > 51 + 6 * (VAR_3->bit_depth_luma - 8)) { av_log(VAR_0->avctx, AV_LOG_ERROR, "QP %u out of range\n", VAR_7); return AVERROR_INVALIDDATA; } VAR_1->qscale       = VAR_7; VAR_1->chroma_qp[0] = get_chroma_qp(VAR_4, 0, VAR_1->qscale); VAR_1->chroma_qp[1] = get_chroma_qp(VAR_4, 1, VAR_1->qscale); if (VAR_1->VAR_6 == AV_PICTURE_TYPE_SP)
get_bits1(&VAR_1->gb); if (VAR_1->VAR_6 == AV_PICTURE_TYPE_SP ||
VAR_1->VAR_6 == AV_PICTURE_TYPE_SI)
get_se_golomb(&VAR_1->gb); VAR_1->deblocking_filter     = 1; VAR_1->slice_alpha_c0_offset = 0; VAR_1->slice_beta_offset     = 0; if (VAR_4->deblocking_filter_parameters_present) { VAR_7 = get_ue_golomb_31(&VAR_1->gb); if (VAR_7 > 2) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"deblocking_filter_idc %u out of range\n", VAR_7); return AVERROR_INVALIDDATA; } VAR_1->deblocking_filter = VAR_7; if (VAR_1->deblocking_filter < 2)
VAR_1->deblocking_filter ^= 1; if (VAR_1->deblocking_filter) { VAR_1->slice_alpha_c0_offset = get_se_golomb(&VAR_1->gb) * 2; VAR_1->slice_beta_offset     = get_se_golomb(&VAR_1->gb) * 2; if (VAR_1->slice_alpha_c0_offset >  12 ||
VAR_1->slice_alpha_c0_offset < -12 ||
VAR_1->slice_beta_offset >  12     ||
VAR_1->slice_beta_offset < -12) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"deblocking filter parameters %d %d out of range\n",
VAR_1->slice_alpha_c0_offset, VAR_1->slice_beta_offset); return AVERROR_INVALIDDATA; } } } return 0; }