libavcodec/h264.c:3438: error: Buffer Overrun L2
  Offset: [0, 2] Size: 2 by call to `implicit_weight_table`.

libavcodec/h264.c:3155:9: Assignment
3153.     h->droppable       = h->nal_ref_idc == 0;
3154.     if (h->sps.frame_mbs_only_flag) {
3155.         h->picture_structure = PICT_FRAME;
              ^
3156.     } else {
3157.         if (get_bits1(&h->gb)) { // field_pic_flag

libavcodec/h264.c:3383:5: Call
3381.     }
3382. 
3383.     init_poc(h);
          ^
3384. 
3385.     if (h->pps.redundant_pic_cnt_present)

libavcodec/h264.c:2506:1: Parameter `h->picture_structure`
  2504. }
  2505. 
  2506. static int init_poc(H264Context *h)
        ^
  2507. {
  2508.     const int max_frame_num = 1 << h->sps.log2_max_frame_num;

libavcodec/h264.c:3438:9: Call
3436.     else if (h->pps.weighted_bipred_idc == 2 &&
3437.              h->slice_type_nos == AV_PICTURE_TYPE_B) {
3438.         implicit_weight_table(h, -1);
              ^
3439.     } else {
3440.         h->use_weight = 0;

libavcodec/h264.c:2384:1: <Offset trace>
2382.  *                -1 initializes the rest
2383.  */
2384. static void implicit_weight_table(H264Context *h, int field)
      ^
2385. {
2386.     int ref0, ref1, i, cur_poc, ref_start, ref_count0, ref_count1;

libavcodec/h264.c:2384:1: Parameter `h->picture_structure`
  2382.  *                -1 initializes the rest
  2383.  */
  2384. static void implicit_weight_table(H264Context *h, int field)
        ^
  2385. {
  2386.     int ref0, ref1, i, cur_poc, ref_start, ref_count0, ref_count1;

libavcodec/h264.c:2384:1: <Length trace>
2382.  *                -1 initializes the rest
2383.  */
2384. static void implicit_weight_table(H264Context *h, int field)
      ^
2385. {
2386.     int ref0, ref1, i, cur_poc, ref_start, ref_count0, ref_count1;

libavcodec/h264.c:2384:1: Parameter `h->cur_pic_ptr->field_poc[*]`
  2382.  *                -1 initializes the rest
  2383.  */
  2384. static void implicit_weight_table(H264Context *h, int field)
        ^
  2385. {
  2386.     int ref0, ref1, i, cur_poc, ref_start, ref_count0, ref_count1;

libavcodec/h264.c:2397:23: Array access: Offset: [0, 2] Size: 2 by call to `implicit_weight_table` 
  2395.             cur_poc = h->cur_pic_ptr->poc;
  2396.         } else {
  2397.             cur_poc = h->cur_pic_ptr->field_poc[h->picture_structure - 1];
                              ^
  2398.         }
  2399.         if (h->ref_count[0] == 1 && h->ref_count[1] == 1 && !FRAME_MBAFF &&

static void implicit_weight_table(H264Context *h, int field)
{
    int ref0, ref1, i, cur_poc, ref_start, ref_count0, ref_count1;
    for (i = 0; i < 2; i++) {
        h->luma_weight_flag[i]   = 0;
        h->chroma_weight_flag[i] = 0;
    }
    if (field < 0) {
        if (h->picture_structure == PICT_FRAME) {
            cur_poc = h->cur_pic_ptr->poc;
        } else {
            cur_poc = h->cur_pic_ptr->field_poc[h->picture_structure - 1];
        }
        if (h->ref_count[0] == 1 && h->ref_count[1] == 1 && !FRAME_MBAFF &&
            h->ref_list[0][0].poc + h->ref_list[1][0].poc == 2 * cur_poc) {
            h->use_weight = 0;
            h->use_weight_chroma = 0;
            return;
        }
        ref_start  = 0;
        ref_count0 = h->ref_count[0];
        ref_count1 = h->ref_count[1];
    } else {
        cur_poc    = h->cur_pic_ptr->field_poc[field];
        ref_start  = 16;
        ref_count0 = 16 + 2 * h->ref_count[0];
        ref_count1 = 16 + 2 * h->ref_count[1];
    }
    h->use_weight               = 2;
    h->use_weight_chroma        = 2;
    h->luma_log2_weight_denom   = 5;
    h->chroma_log2_weight_denom = 5;
    for (ref0 = ref_start; ref0 < ref_count0; ref0++) {
        int poc0 = h->ref_list[0][ref0].poc;
        for (ref1 = ref_start; ref1 < ref_count1; ref1++) {
            int w = 32;
            if (!h->ref_list[0][ref0].long_ref && !h->ref_list[1][ref1].long_ref) {
                int poc1 = h->ref_list[1][ref1].poc;
                int td   = av_clip(poc1 - poc0, -128, 127);
                if (td) {
                    int tb = av_clip(cur_poc - poc0, -128, 127);
                    int tx = (16384 + (FFABS(td) >> 1)) / td;
                    int dist_scale_factor = (tb * tx + 32) >> 8;
                    if (dist_scale_factor >= -64 && dist_scale_factor <= 128)
                        w = 64 - dist_scale_factor;
                }
            }
            if (field < 0) {
                h->implicit_weight[ref0][ref1][0] =
                h->implicit_weight[ref0][ref1][1] = w;
            } else {
                h->implicit_weight[ref0][ref1][field] = w;
            }
        }
    }
}
['static int decode_slice_header(H264Context *h, H264Context *h0)\n{\n    unsigned int first_mb_in_slice;\n    unsigned int pps_id;\n    int num_ref_idx_active_override_flag, max_refs, ret;\n    unsigned int slice_type, tmp, i, j;\n    int default_ref_list_done = 0;\n    int last_pic_structure, last_pic_droppable;\n    int needs_reinit = 0;\n    h->me.qpel_put = h->h264qpel.put_h264_qpel_pixels_tab;\n    h->me.qpel_avg = h->h264qpel.avg_h264_qpel_pixels_tab;\n    first_mb_in_slice = get_ue_golomb(&h->gb);\n    if (first_mb_in_slice == 0) {\n        if (h0->current_slice && FIELD_PICTURE) {\n            field_end(h, 1);\n        }\n        h0->current_slice = 0;\n        if (!h0->first_field) {\n            if (h->cur_pic_ptr && !h->droppable &&\n                h->cur_pic_ptr->owner2 == h) {\n                ff_thread_report_progress(&h->cur_pic_ptr->f, INT_MAX,\n                                          h->picture_structure == PICT_BOTTOM_FIELD);\n            }\n            h->cur_pic_ptr = NULL;\n        }\n    }\n    slice_type = get_ue_golomb_31(&h->gb);\n    if (slice_type > 9) {\n        av_log(h->avctx, AV_LOG_ERROR,\n               "slice type too large (%d) at %d %d\\n",\n               h->slice_type, h->mb_x, h->mb_y);\n        return -1;\n    }\n    if (slice_type > 4) {\n        slice_type -= 5;\n        h->slice_type_fixed = 1;\n    } else\n        h->slice_type_fixed = 0;\n    slice_type = golomb_to_pict_type[slice_type];\n    if (slice_type == AV_PICTURE_TYPE_I ||\n        (h0->current_slice != 0 && slice_type == h0->last_slice_type)) {\n        default_ref_list_done = 1;\n    }\n    h->slice_type     = slice_type;\n    h->slice_type_nos = slice_type & 3;\n    h->pict_type = h->slice_type;\n    pps_id = get_ue_golomb(&h->gb);\n    if (pps_id >= MAX_PPS_COUNT) {\n        av_log(h->avctx, AV_LOG_ERROR, "pps_id out of range\\n");\n        return -1;\n    }\n    if (!h0->pps_buffers[pps_id]) {\n        av_log(h->avctx, AV_LOG_ERROR,\n               "non-existing PPS %u referenced\\n",\n               pps_id);\n        return -1;\n    }\n    h->pps = *h0->pps_buffers[pps_id];\n    if (!h0->sps_buffers[h->pps.sps_id]) {\n        av_log(h->avctx, AV_LOG_ERROR,\n               "non-existing SPS %u referenced\\n",\n               h->pps.sps_id);\n        return -1;\n    }\n    if (h->pps.sps_id != h->current_sps_id ||\n        h0->sps_buffers[h->pps.sps_id]->new) {\n        h0->sps_buffers[h->pps.sps_id]->new = 0;\n        h->current_sps_id = h->pps.sps_id;\n        h->sps            = *h0->sps_buffers[h->pps.sps_id];\n        if (h->bit_depth_luma    != h->sps.bit_depth_luma ||\n            h->chroma_format_idc != h->sps.chroma_format_idc) {\n            h->bit_depth_luma    = h->sps.bit_depth_luma;\n            h->chroma_format_idc = h->sps.chroma_format_idc;\n            needs_reinit         = 1;\n        }\n        if ((ret = h264_set_parameter_from_sps(h)) < 0)\n            return ret;\n    }\n    h->avctx->profile = ff_h264_get_profile(&h->sps);\n    h->avctx->level   = h->sps.level_idc;\n    h->avctx->refs    = h->sps.ref_frame_count;\n    if (h->mb_width  != h->sps.mb_width ||\n        h->mb_height != h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag))\n        needs_reinit = 1;\n    h->mb_width  = h->sps.mb_width;\n    h->mb_height = h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag);\n    h->mb_num    = h->mb_width * h->mb_height;\n    h->mb_stride = h->mb_width + 1;\n    h->b_stride = h->mb_width * 4;\n    h->chroma_y_shift = h->sps.chroma_format_idc <= 1;\n    h->width = 16 * h->mb_width - (2 >> CHROMA444) * FFMIN(h->sps.crop_right, (8 << CHROMA444) - 1);\n    if (h->sps.frame_mbs_only_flag)\n        h->height = 16 * h->mb_height - (1 << h->chroma_y_shift) * FFMIN(h->sps.crop_bottom, (16 >> h->chroma_y_shift) - 1);\n    else\n        h->height = 16 * h->mb_height - (2 << h->chroma_y_shift) * FFMIN(h->sps.crop_bottom, (16 >> h->chroma_y_shift) - 1);\n    if (FFALIGN(h->avctx->width,  16) == h->width &&\n        FFALIGN(h->avctx->height, 16) == h->height) {\n        h->width  = h->avctx->width;\n        h->height = h->avctx->height;\n    }\n    if (h->sps.video_signal_type_present_flag) {\n        h->avctx->color_range = h->sps.full_range ? AVCOL_RANGE_JPEG\n                                                  : AVCOL_RANGE_MPEG;\n        if (h->sps.colour_description_present_flag) {\n            if (h->avctx->colorspace != h->sps.colorspace)\n                needs_reinit = 1;\n            h->avctx->color_primaries = h->sps.color_primaries;\n            h->avctx->color_trc       = h->sps.color_trc;\n            h->avctx->colorspace      = h->sps.colorspace;\n        }\n    }\n    if (h->context_initialized &&\n        (h->width  != h->avctx->width   ||\n         h->height != h->avctx->height  ||\n         needs_reinit)) {\n        if (h != h0) {\n            av_log(h->avctx, AV_LOG_ERROR, "changing width/height on "\n                   "slice %d\\n", h0->current_slice + 1);\n            return AVERROR_INVALIDDATA;\n        }\n        flush_change(h);\n        if ((ret = get_pixel_format(h)) < 0)\n            return ret;\n        h->avctx->pix_fmt = ret;\n        av_log(h->avctx, AV_LOG_INFO, "Reinit context to %dx%d, "\n               "pix_fmt: %d\\n", h->width, h->height, h->avctx->pix_fmt);\n        if ((ret = h264_slice_header_init(h, 1)) < 0) {\n            av_log(h->avctx, AV_LOG_ERROR,\n                   "h264_slice_header_init() failed\\n");\n            return ret;\n        }\n    }\n    if (!h->context_initialized) {\n        if (h != h0) {\n            av_log(h->avctx, AV_LOG_ERROR,\n                   "Cannot (re-)initialize context during parallel decoding.\\n");\n            return -1;\n        }\n        if ((ret = get_pixel_format(h)) < 0)\n            return ret;\n        h->avctx->pix_fmt = ret;\n        if ((ret = h264_slice_header_init(h, 0)) < 0) {\n            av_log(h->avctx, AV_LOG_ERROR,\n                   "h264_slice_header_init() failed\\n");\n            return ret;\n        }\n    }\n    if (h == h0 && h->dequant_coeff_pps != pps_id) {\n        h->dequant_coeff_pps = pps_id;\n        init_dequant_tables(h);\n    }\n    h->frame_num = get_bits(&h->gb, h->sps.log2_max_frame_num);\n    h->mb_mbaff        = 0;\n    h->mb_aff_frame    = 0;\n    last_pic_structure = h0->picture_structure;\n    last_pic_droppable = h0->droppable;\n    h->droppable       = h->nal_ref_idc == 0;\n    if (h->sps.frame_mbs_only_flag) {\n        h->picture_structure = PICT_FRAME;\n    } else {\n        if (get_bits1(&h->gb)) {\n            h->picture_structure = PICT_TOP_FIELD + get_bits1(&h->gb);\n        } else {\n            h->picture_structure = PICT_FRAME;\n            h->mb_aff_frame      = h->sps.mb_aff;\n        }\n    }\n    h->mb_field_decoding_flag = h->picture_structure != PICT_FRAME;\n    if (h0->current_slice != 0) {\n        if (last_pic_structure != h->picture_structure ||\n            last_pic_droppable != h->droppable) {\n            av_log(h->avctx, AV_LOG_ERROR,\n                   "Changing field mode (%d -> %d) between slices is not allowed\\n",\n                   last_pic_structure, h->picture_structure);\n            h->picture_structure = last_pic_structure;\n            h->droppable         = last_pic_droppable;\n            return AVERROR_INVALIDDATA;\n        } else if (!h0->cur_pic_ptr) {\n            av_log(h->avctx, AV_LOG_ERROR,\n                   "unset cur_pic_ptr on %d. slice\\n",\n                   h0->current_slice + 1);\n            return AVERROR_INVALIDDATA;\n        }\n    } else {\n        if (h->frame_num != h->prev_frame_num) {\n            int unwrap_prev_frame_num = h->prev_frame_num;\n            int max_frame_num         = 1 << h->sps.log2_max_frame_num;\n            if (unwrap_prev_frame_num > h->frame_num)\n                unwrap_prev_frame_num -= max_frame_num;\n            if ((h->frame_num - unwrap_prev_frame_num) > h->sps.ref_frame_count) {\n                unwrap_prev_frame_num = (h->frame_num - h->sps.ref_frame_count) - 1;\n                if (unwrap_prev_frame_num < 0)\n                    unwrap_prev_frame_num += max_frame_num;\n                h->prev_frame_num = unwrap_prev_frame_num;\n            }\n        }\n        if (h0->first_field) {\n            assert(h0->cur_pic_ptr);\n            assert(h0->cur_pic_ptr->f.data[0]);\n            assert(h0->cur_pic_ptr->f.reference != DELAYED_PIC_REF);\n            if (!last_pic_droppable && h0->cur_pic_ptr->owner2 == h0) {\n                ff_thread_report_progress(&h0->cur_pic_ptr->f, INT_MAX,\n                                          last_pic_structure == PICT_BOTTOM_FIELD);\n            }\n            if (!FIELD_PICTURE || h->picture_structure == last_pic_structure) {\n                if (!last_pic_droppable && last_pic_structure != PICT_FRAME) {\n                    ff_thread_report_progress(&h0->cur_pic_ptr->f, INT_MAX,\n                                              last_pic_structure == PICT_TOP_FIELD);\n                }\n            } else {\n                if (h0->cur_pic_ptr->frame_num != h->frame_num) {\n                    if (!last_pic_droppable && last_pic_structure != PICT_FRAME) {\n                        ff_thread_report_progress(&h0->cur_pic_ptr->f, INT_MAX,\n                                                  last_pic_structure == PICT_TOP_FIELD);\n                    }\n                } else {\n                    if (!((last_pic_structure   == PICT_TOP_FIELD &&\n                           h->picture_structure == PICT_BOTTOM_FIELD) ||\n                          (last_pic_structure   == PICT_BOTTOM_FIELD &&\n                           h->picture_structure == PICT_TOP_FIELD))) {\n                        av_log(h->avctx, AV_LOG_ERROR,\n                               "Invalid field mode combination %d/%d\\n",\n                               last_pic_structure, h->picture_structure);\n                        h->picture_structure = last_pic_structure;\n                        h->droppable         = last_pic_droppable;\n                        return AVERROR_INVALIDDATA;\n                    } else if (last_pic_droppable != h->droppable) {\n                        av_log(h->avctx, AV_LOG_ERROR,\n                               "Cannot combine reference and non-reference fields in the same frame\\n");\n                        av_log_ask_for_sample(h->avctx, NULL);\n                        h->picture_structure = last_pic_structure;\n                        h->droppable         = last_pic_droppable;\n                        return AVERROR_PATCHWELCOME;\n                    }\n                    h0->cur_pic_ptr->owner2 = h0;\n                }\n            }\n        }\n        while (h->frame_num != h->prev_frame_num &&\n               h->frame_num != (h->prev_frame_num + 1) % (1 << h->sps.log2_max_frame_num)) {\n            Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL;\n            av_log(h->avctx, AV_LOG_DEBUG, "Frame num gap %d %d\\n",\n                   h->frame_num, h->prev_frame_num);\n            if (ff_h264_frame_start(h) < 0)\n                return -1;\n            h->prev_frame_num++;\n            h->prev_frame_num %= 1 << h->sps.log2_max_frame_num;\n            h->cur_pic_ptr->frame_num = h->prev_frame_num;\n            ff_thread_report_progress(&h->cur_pic_ptr->f, INT_MAX, 0);\n            ff_thread_report_progress(&h->cur_pic_ptr->f, INT_MAX, 1);\n            if ((ret = ff_generate_sliding_window_mmcos(h, 1)) < 0 &&\n                h->avctx->err_recognition & AV_EF_EXPLODE)\n                return ret;\n            if (ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index) < 0 &&\n                (h->avctx->err_recognition & AV_EF_EXPLODE))\n                return AVERROR_INVALIDDATA;\n            if (h->short_ref_count) {\n                if (prev) {\n                    av_image_copy(h->short_ref[0]->f.data, h->short_ref[0]->f.linesize,\n                                  (const uint8_t **)prev->f.data, prev->f.linesize,\n                                  h->avctx->pix_fmt, h->mb_width * 16, h->mb_height * 16);\n                    h->short_ref[0]->poc = prev->poc + 2;\n                }\n                h->short_ref[0]->frame_num = h->prev_frame_num;\n            }\n        }\n        if (h0->first_field) {\n            assert(h0->cur_pic_ptr);\n            assert(h0->cur_pic_ptr->f.data[0]);\n            assert(h0->cur_pic_ptr->f.reference != DELAYED_PIC_REF);\n            if (!FIELD_PICTURE || h->picture_structure == last_pic_structure) {\n                h0->cur_pic_ptr = NULL;\n                h0->first_field = FIELD_PICTURE;\n            } else {\n                if (h0->cur_pic_ptr->frame_num != h->frame_num) {\n                    h0->first_field = 1;\n                    h0->cur_pic_ptr = NULL;\n                } else {\n                    h0->first_field = 0;\n                }\n            }\n        } else {\n            h0->first_field = FIELD_PICTURE;\n        }\n        if (!FIELD_PICTURE || h0->first_field) {\n            if (ff_h264_frame_start(h) < 0) {\n                h0->first_field = 0;\n                return -1;\n            }\n        } else {\n            release_unused_pictures(h, 0);\n        }\n    }\n    if (h != h0 && (ret = clone_slice(h, h0)) < 0)\n        return ret;\n    h->cur_pic_ptr->frame_num = h->frame_num;\n    assert(h->mb_num == h->mb_width * h->mb_height);\n    if (first_mb_in_slice << FIELD_OR_MBAFF_PICTURE >= h->mb_num ||\n        first_mb_in_slice >= h->mb_num) {\n        av_log(h->avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\\n");\n        return -1;\n    }\n    h->resync_mb_x = h->mb_x =  first_mb_in_slice % h->mb_width;\n    h->resync_mb_y = h->mb_y = (first_mb_in_slice / h->mb_width) << FIELD_OR_MBAFF_PICTURE;\n    if (h->picture_structure == PICT_BOTTOM_FIELD)\n        h->resync_mb_y = h->mb_y = h->mb_y + 1;\n    assert(h->mb_y < h->mb_height);\n    if (h->picture_structure == PICT_FRAME) {\n        h->curr_pic_num = h->frame_num;\n        h->max_pic_num  = 1 << h->sps.log2_max_frame_num;\n    } else {\n        h->curr_pic_num = 2 * h->frame_num + 1;\n        h->max_pic_num  = 1 << (h->sps.log2_max_frame_num + 1);\n    }\n    if (h->nal_unit_type == NAL_IDR_SLICE)\n        get_ue_golomb(&h->gb);\n    if (h->sps.poc_type == 0) {\n        h->poc_lsb = get_bits(&h->gb, h->sps.log2_max_poc_lsb);\n        if (h->pps.pic_order_present == 1 && h->picture_structure == PICT_FRAME)\n            h->delta_poc_bottom = get_se_golomb(&h->gb);\n    }\n    if (h->sps.poc_type == 1 && !h->sps.delta_pic_order_always_zero_flag) {\n        h->delta_poc[0] = get_se_golomb(&h->gb);\n        if (h->pps.pic_order_present == 1 && h->picture_structure == PICT_FRAME)\n            h->delta_poc[1] = get_se_golomb(&h->gb);\n    }\n    init_poc(h);\n    if (h->pps.redundant_pic_cnt_present)\n        h->redundant_pic_count = get_ue_golomb(&h->gb);\n    h->ref_count[0] = h->pps.ref_count[0];\n    h->ref_count[1] = h->pps.ref_count[1];\n    if (h->slice_type_nos != AV_PICTURE_TYPE_I) {\n        if (h->slice_type_nos == AV_PICTURE_TYPE_B)\n            h->direct_spatial_mv_pred = get_bits1(&h->gb);\n        num_ref_idx_active_override_flag = get_bits1(&h->gb);\n        if (num_ref_idx_active_override_flag) {\n            h->ref_count[0] = get_ue_golomb(&h->gb) + 1;\n            if (h->ref_count[0] < 1)\n                return AVERROR_INVALIDDATA;\n            if (h->slice_type_nos == AV_PICTURE_TYPE_B) {\n                h->ref_count[1] = get_ue_golomb(&h->gb) + 1;\n                if (h->ref_count[1] < 1)\n                    return AVERROR_INVALIDDATA;\n            }\n        }\n        if (h->slice_type_nos == AV_PICTURE_TYPE_B)\n            h->list_count = 2;\n        else\n            h->list_count = 1;\n    } else\n        h->list_count = 0;\n    max_refs = h->picture_structure == PICT_FRAME ? 16 : 32;\n    if (h->ref_count[0] > max_refs || h->ref_count[1] > max_refs) {\n        av_log(h->avctx, AV_LOG_ERROR, "reference overflow\\n");\n        h->ref_count[0] = h->ref_count[1] = 1;\n        return AVERROR_INVALIDDATA;\n    }\n    if (!default_ref_list_done)\n        ff_h264_fill_default_ref_list(h);\n    if (h->slice_type_nos != AV_PICTURE_TYPE_I &&\n        ff_h264_decode_ref_pic_list_reordering(h) < 0) {\n        h->ref_count[1] = h->ref_count[0] = 0;\n        return -1;\n    }\n    if ((h->pps.weighted_pred && h->slice_type_nos == AV_PICTURE_TYPE_P) ||\n        (h->pps.weighted_bipred_idc == 1 &&\n         h->slice_type_nos == AV_PICTURE_TYPE_B))\n        pred_weight_table(h);\n    else if (h->pps.weighted_bipred_idc == 2 &&\n             h->slice_type_nos == AV_PICTURE_TYPE_B) {\n        implicit_weight_table(h, -1);\n    } else {\n        h->use_weight = 0;\n        for (i = 0; i < 2; i++) {\n            h->luma_weight_flag[i]   = 0;\n            h->chroma_weight_flag[i] = 0;\n        }\n    }\n    if (h->nal_ref_idc &&\n        ff_h264_decode_ref_pic_marking(h0, &h->gb,\n                            !(h->avctx->active_thread_type & FF_THREAD_FRAME) ||\n                            h0->current_slice == 0) < 0 &&\n        (h->avctx->err_recognition & AV_EF_EXPLODE))\n        return AVERROR_INVALIDDATA;\n    if (FRAME_MBAFF) {\n        ff_h264_fill_mbaff_ref_list(h);\n        if (h->pps.weighted_bipred_idc == 2 && h->slice_type_nos == AV_PICTURE_TYPE_B) {\n            implicit_weight_table(h, 0);\n            implicit_weight_table(h, 1);\n        }\n    }\n    if (h->slice_type_nos == AV_PICTURE_TYPE_B && !h->direct_spatial_mv_pred)\n        ff_h264_direct_dist_scale_factor(h);\n    ff_h264_direct_ref_list_init(h);\n    if (h->slice_type_nos != AV_PICTURE_TYPE_I && h->pps.cabac) {\n        tmp = get_ue_golomb_31(&h->gb);\n        if (tmp > 2) {\n            av_log(h->avctx, AV_LOG_ERROR, "cabac_init_idc overflow\\n");\n            return -1;\n        }\n        h->cabac_init_idc = tmp;\n    }\n    h->last_qscale_diff = 0;\n    tmp = h->pps.init_qp + get_se_golomb(&h->gb);\n    if (tmp > 51 + 6 * (h->sps.bit_depth_luma - 8)) {\n        av_log(h->avctx, AV_LOG_ERROR, "QP %u out of range\\n", tmp);\n        return -1;\n    }\n    h->qscale       = tmp;\n    h->chroma_qp[0] = get_chroma_qp(h, 0, h->qscale);\n    h->chroma_qp[1] = get_chroma_qp(h, 1, h->qscale);\n    if (h->slice_type == AV_PICTURE_TYPE_SP)\n        get_bits1(&h->gb);\n    if (h->slice_type == AV_PICTURE_TYPE_SP ||\n        h->slice_type == AV_PICTURE_TYPE_SI)\n        get_se_golomb(&h->gb);\n    h->deblocking_filter     = 1;\n    h->slice_alpha_c0_offset = 52;\n    h->slice_beta_offset     = 52;\n    if (h->pps.deblocking_filter_parameters_present) {\n        tmp = get_ue_golomb_31(&h->gb);\n        if (tmp > 2) {\n            av_log(h->avctx, AV_LOG_ERROR,\n                   "deblocking_filter_idc %u out of range\\n", tmp);\n            return -1;\n        }\n        h->deblocking_filter = tmp;\n        if (h->deblocking_filter < 2)\n            h->deblocking_filter ^= 1;\n        if (h->deblocking_filter) {\n            h->slice_alpha_c0_offset += get_se_golomb(&h->gb) << 1;\n            h->slice_beta_offset     += get_se_golomb(&h->gb) << 1;\n            if (h->slice_alpha_c0_offset > 104U ||\n                h->slice_beta_offset     > 104U) {\n                av_log(h->avctx, AV_LOG_ERROR,\n                       "deblocking filter parameters %d %d out of range\\n",\n                       h->slice_alpha_c0_offset, h->slice_beta_offset);\n                return -1;\n            }\n        }\n    }\n    if (h->avctx->skip_loop_filter >= AVDISCARD_ALL ||\n        (h->avctx->skip_loop_filter >= AVDISCARD_NONKEY &&\n         h->slice_type_nos != AV_PICTURE_TYPE_I) ||\n        (h->avctx->skip_loop_filter >= AVDISCARD_BIDIR  &&\n         h->slice_type_nos == AV_PICTURE_TYPE_B) ||\n        (h->avctx->skip_loop_filter >= AVDISCARD_NONREF &&\n         h->nal_ref_idc == 0))\n        h->deblocking_filter = 0;\n    if (h->deblocking_filter == 1 && h0->max_contexts > 1) {\n        if (h->avctx->flags2 & CODEC_FLAG2_FAST) {\n            h->deblocking_filter = 2;\n        } else {\n            h0->max_contexts = 1;\n            if (!h0->single_decode_warning) {\n                av_log(h->avctx, AV_LOG_INFO,\n                       "Cannot parallelize deblocking type 1, decoding such frames in sequential order\\n");\n                h0->single_decode_warning = 1;\n            }\n            if (h != h0) {\n                av_log(h->avctx, AV_LOG_ERROR,\n                       "Deblocking switched inside frame.\\n");\n                return 1;\n            }\n        }\n    }\n    h->qp_thresh = 15 + 52 -\n                   FFMIN(h->slice_alpha_c0_offset, h->slice_beta_offset) -\n                   FFMAX3(0,\n                          h->pps.chroma_qp_index_offset[0],\n                          h->pps.chroma_qp_index_offset[1]) +\n                   6 * (h->sps.bit_depth_luma - 8);\n    h0->last_slice_type = slice_type;\n    h->slice_num = ++h0->current_slice;\n    if (h->slice_num >= MAX_SLICES) {\n        av_log(h->avctx, AV_LOG_ERROR,\n               "Too many slices, increase MAX_SLICES and recompile\\n");\n    }\n    for (j = 0; j < 2; j++) {\n        int id_list[16];\n        int *ref2frm = h->ref2frm[h->slice_num & (MAX_SLICES - 1)][j];\n        for (i = 0; i < 16; i++) {\n            id_list[i] = 60;\n            if (h->ref_list[j][i].f.data[0]) {\n                int k;\n                uint8_t *base = h->ref_list[j][i].f.base[0];\n                for (k = 0; k < h->short_ref_count; k++)\n                    if (h->short_ref[k]->f.base[0] == base) {\n                        id_list[i] = k;\n                        break;\n                    }\n                for (k = 0; k < h->long_ref_count; k++)\n                    if (h->long_ref[k] && h->long_ref[k]->f.base[0] == base) {\n                        id_list[i] = h->short_ref_count + k;\n                        break;\n                    }\n            }\n        }\n        ref2frm[0]     =\n            ref2frm[1] = -1;\n        for (i = 0; i < 16; i++)\n            ref2frm[i + 2] = 4 * id_list[i] +\n                             (h->ref_list[j][i].f.reference & 3);\n        ref2frm[18 + 0]     =\n            ref2frm[18 + 1] = -1;\n        for (i = 16; i < 48; i++)\n            ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] +\n                             (h->ref_list[j][i].f.reference & 3);\n    }\n    h->emu_edge_width  = (h->flags & CODEC_FLAG_EMU_EDGE ||\n                          (!h->sps.frame_mbs_only_flag &&\n                           h->avctx->active_thread_type))\n                         ? 0 : 16;\n    h->emu_edge_height = (FRAME_MBAFF || FIELD_PICTURE) ? 0 : h->emu_edge_width;\n    if (h->avctx->debug & FF_DEBUG_PICT_INFO) {\n        av_log(h->avctx, AV_LOG_DEBUG,\n               "slice:%d %s mb:%d %c%s%s pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\\n",\n               h->slice_num,\n               (h->picture_structure == PICT_FRAME ? "F" : h->picture_structure == PICT_TOP_FIELD ? "T" : "B"),\n               first_mb_in_slice,\n               av_get_picture_type_char(h->slice_type),\n               h->slice_type_fixed ? " fix" : "",\n               h->nal_unit_type == NAL_IDR_SLICE ? " IDR" : "",\n               pps_id, h->frame_num,\n               h->cur_pic_ptr->field_poc[0],\n               h->cur_pic_ptr->field_poc[1],\n               h->ref_count[0], h->ref_count[1],\n               h->qscale,\n               h->deblocking_filter,\n               h->slice_alpha_c0_offset / 2 - 26, h->slice_beta_offset / 2 - 26,\n               h->use_weight,\n               h->use_weight == 1 && h->use_weight_chroma ? "c" : "",\n               h->slice_type == AV_PICTURE_TYPE_B ? (h->direct_spatial_mv_pred ? "SPAT" : "TEMP") : "");\n    }\n    return 0;\n}', 'static int init_poc(H264Context *h)\n{\n    const int max_frame_num = 1 << h->sps.log2_max_frame_num;\n    int field_poc[2];\n    Picture *cur = h->cur_pic_ptr;\n    h->frame_num_offset = h->prev_frame_num_offset;\n    if (h->frame_num < h->prev_frame_num)\n        h->frame_num_offset += max_frame_num;\n    if (h->sps.poc_type == 0) {\n        const int max_poc_lsb = 1 << h->sps.log2_max_poc_lsb;\n        if (h->poc_lsb < h->prev_poc_lsb && h->prev_poc_lsb - h->poc_lsb >= max_poc_lsb / 2)\n            h->poc_msb = h->prev_poc_msb + max_poc_lsb;\n        else if (h->poc_lsb > h->prev_poc_lsb && h->prev_poc_lsb - h->poc_lsb < -max_poc_lsb / 2)\n            h->poc_msb = h->prev_poc_msb - max_poc_lsb;\n        else\n            h->poc_msb = h->prev_poc_msb;\n        field_poc[0] =\n        field_poc[1] = h->poc_msb + h->poc_lsb;\n        if (h->picture_structure == PICT_FRAME)\n            field_poc[1] += h->delta_poc_bottom;\n    } else if (h->sps.poc_type == 1) {\n        int abs_frame_num, expected_delta_per_poc_cycle, expectedpoc;\n        int i;\n        if (h->sps.poc_cycle_length != 0)\n            abs_frame_num = h->frame_num_offset + h->frame_num;\n        else\n            abs_frame_num = 0;\n        if (h->nal_ref_idc == 0 && abs_frame_num > 0)\n            abs_frame_num--;\n        expected_delta_per_poc_cycle = 0;\n        for (i = 0; i < h->sps.poc_cycle_length; i++)\n            expected_delta_per_poc_cycle += h->sps.offset_for_ref_frame[i];\n        if (abs_frame_num > 0) {\n            int poc_cycle_cnt          = (abs_frame_num - 1) / h->sps.poc_cycle_length;\n            int frame_num_in_poc_cycle = (abs_frame_num - 1) % h->sps.poc_cycle_length;\n            expectedpoc = poc_cycle_cnt * expected_delta_per_poc_cycle;\n            for (i = 0; i <= frame_num_in_poc_cycle; i++)\n                expectedpoc = expectedpoc + h->sps.offset_for_ref_frame[i];\n        } else\n            expectedpoc = 0;\n        if (h->nal_ref_idc == 0)\n            expectedpoc = expectedpoc + h->sps.offset_for_non_ref_pic;\n        field_poc[0] = expectedpoc + h->delta_poc[0];\n        field_poc[1] = field_poc[0] + h->sps.offset_for_top_to_bottom_field;\n        if (h->picture_structure == PICT_FRAME)\n            field_poc[1] += h->delta_poc[1];\n    } else {\n        int poc = 2 * (h->frame_num_offset + h->frame_num);\n        if (!h->nal_ref_idc)\n            poc--;\n        field_poc[0] = poc;\n        field_poc[1] = poc;\n    }\n    if (h->picture_structure != PICT_BOTTOM_FIELD)\n        h->cur_pic_ptr->field_poc[0] = field_poc[0];\n    if (h->picture_structure != PICT_TOP_FIELD)\n        h->cur_pic_ptr->field_poc[1] = field_poc[1];\n    cur->poc = FFMIN(cur->field_poc[0], cur->field_poc[1]);\n    return 0;\n}', 'static void implicit_weight_table(H264Context *h, int field)\n{\n    int ref0, ref1, i, cur_poc, ref_start, ref_count0, ref_count1;\n    for (i = 0; i < 2; i++) {\n        h->luma_weight_flag[i]   = 0;\n        h->chroma_weight_flag[i] = 0;\n    }\n    if (field < 0) {\n        if (h->picture_structure == PICT_FRAME) {\n            cur_poc = h->cur_pic_ptr->poc;\n        } else {\n            cur_poc = h->cur_pic_ptr->field_poc[h->picture_structure - 1];\n        }\n        if (h->ref_count[0] == 1 && h->ref_count[1] == 1 && !FRAME_MBAFF &&\n            h->ref_list[0][0].poc + h->ref_list[1][0].poc == 2 * cur_poc) {\n            h->use_weight = 0;\n            h->use_weight_chroma = 0;\n            return;\n        }\n        ref_start  = 0;\n        ref_count0 = h->ref_count[0];\n        ref_count1 = h->ref_count[1];\n    } else {\n        cur_poc    = h->cur_pic_ptr->field_poc[field];\n        ref_start  = 16;\n        ref_count0 = 16 + 2 * h->ref_count[0];\n        ref_count1 = 16 + 2 * h->ref_count[1];\n    }\n    h->use_weight               = 2;\n    h->use_weight_chroma        = 2;\n    h->luma_log2_weight_denom   = 5;\n    h->chroma_log2_weight_denom = 5;\n    for (ref0 = ref_start; ref0 < ref_count0; ref0++) {\n        int poc0 = h->ref_list[0][ref0].poc;\n        for (ref1 = ref_start; ref1 < ref_count1; ref1++) {\n            int w = 32;\n            if (!h->ref_list[0][ref0].long_ref && !h->ref_list[1][ref1].long_ref) {\n                int poc1 = h->ref_list[1][ref1].poc;\n                int td   = av_clip(poc1 - poc0, -128, 127);\n                if (td) {\n                    int tb = av_clip(cur_poc - poc0, -128, 127);\n                    int tx = (16384 + (FFABS(td) >> 1)) / td;\n                    int dist_scale_factor = (tb * tx + 32) >> 8;\n                    if (dist_scale_factor >= -64 && dist_scale_factor <= 128)\n                        w = 64 - dist_scale_factor;\n                }\n            }\n            if (field < 0) {\n                h->implicit_weight[ref0][ref1][0] =\n                h->implicit_weight[ref0][ref1][1] = w;\n            } else {\n                h->implicit_weight[ref0][ref1][field] = w;\n            }\n        }\n    }\n}']