libavcodec/h264.c:1285: error: Integer Overflow L2
  ([0, 2147483648] × 4):signed32 by call to `ff_h264_field_end`.

libavcodec/h264.c:1283:13: Call
1281.         (h->mb_y >= h->mb_height && h->mb_height)) {
1282.         if (avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)
1283.             decode_postinit(h, 1);
                  ^
1284. 
1285.         ff_h264_field_end(h, &h->slice_ctx[0], 0);

libavcodec/h264.c:599:17: Assignment
  597.             if (h->sei_pic_struct == SEI_PIC_STRUCT_TOP_BOTTOM ||
  598.                 h->sei_pic_struct == SEI_PIC_STRUCT_TOP_BOTTOM_TOP)
  599.                 cur->f->top_field_first = 1;
                       ^
  600.             else
  601.                 cur->f->top_field_first = 0;

libavcodec/h264.c:1285:9: Call
1283.             decode_postinit(h, 1);
1284. 
1285.         ff_h264_field_end(h, &h->slice_ctx[0], 0);
              ^
1286. 
1287.         *got_frame = 0;

libavcodec/h264_picture.c:146:1: Parameter `sl->er.mb_width`
  144. #endif /* CONFIG_ERROR_RESILIENCE */
  145. 
  146. int ff_h264_field_end(H264Context *h, H264SliceContext *sl, int in_setup)
       ^
  147. {
  148.     AVCodecContext *const avctx = h->avctx;

libavcodec/h264_picture.c:191:9: Call
  189.         h264_set_erpic(&sl->er.next_pic,
  190.                        sl->ref_count[1] ? sl->ref_list[1][0].parent : NULL);
  191.         ff_er_frame_end(&sl->er);
               ^
  192.     }
  193. #endif /* CONFIG_ERROR_RESILIENCE */

libavcodec/error_resilience.c:1020:14: Assignment
    1018.     /* handle inter blocks with damaged AC */
    1019.     for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
    1020.         for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
                       ^
    1021.             const int mb_xy   = mb_x + mb_y * s->mb_stride;
    1022.             const int mb_type = s->cur_pic.mb_type[mb_xy];

libavcodec/error_resilience.c:1100:9: Call
    1098.         }
    1099.     } else
    1100.         guess_mv(s);
                  ^
    1101. 
    1102. #if FF_API_XVMC

libavcodec/error_resilience.c:356:1: Parameter `s->mb_width`
      354. }
      355. 
      356. static void guess_mv(ERContext *s)
           ^
      357. {
      358.     uint8_t *fixed = s->er_temp_buffer;

libavcodec/error_resilience.c:368:5: Call
      366.     int mb_x, mb_y, mot_step, mot_stride;
      367. 
      368.     set_mv_strides(s, &mot_step, &mot_stride);
               ^
      369. 
      370.     num_avail = 0;

libavcodec/error_resilience.c:44:1: <LHS trace>
42.  * @param mv_step the number of MVs per row or column in a macroblock
43.  */
44. static void set_mv_strides(ERContext *s, int *mv_step, int *stride)
    ^
45. {
46.     if (s->avctx->codec_id == AV_CODEC_ID_H264) {

libavcodec/error_resilience.c:44:1: Parameter `s->mb_width`
        42.  * @param mv_step the number of MVs per row or column in a macroblock
        43.  */
        44. static void set_mv_strides(ERContext *s, int *mv_step, int *stride)
            ^
        45. {
        46.     if (s->avctx->codec_id == AV_CODEC_ID_H264) {

libavcodec/error_resilience.c:49:9: Binary operation: ([0, 2147483648] × 4):signed32 by call to `ff_h264_field_end` 
        47.         assert(s->quarter_sample);
        48.         *mv_step = 4;
        49.         *stride  = s->mb_width * 4;
                    ^
        50.     } else {
        51.         *mv_step = 2;

static void set_mv_strides(ERContext *s, int *mv_step, int *stride)
{
    if (s->avctx->codec_id == AV_CODEC_ID_H264) {
        assert(s->quarter_sample);
        *mv_step = 4;
        *stride  = s->mb_width * 4;
    } else {
        *mv_step = 2;
        *stride  = s->b8_stride;
    }
}
['static int h264_decode_frame(AVCodecContext *avctx, void *data,\n                             int *got_frame, AVPacket *avpkt)\n{\n    const uint8_t *buf = avpkt->data;\n    int buf_size       = avpkt->size;\n    H264Context *h     = avctx->priv_data;\n    AVFrame *pict      = data;\n    int buf_index      = 0;\n    int ret;\n    h->flags = avctx->flags;\n    h->setup_finished = 0;\nout:\n    if (buf_size == 0) {\n        H264Picture *out;\n        int i, out_idx;\n        h->cur_pic_ptr = NULL;\n        out     = h->delayed_pic[0];\n        out_idx = 0;\n        for (i = 1;\n             h->delayed_pic[i] &&\n             !h->delayed_pic[i]->f->key_frame &&\n             !h->delayed_pic[i]->mmco_reset;\n             i++)\n            if (h->delayed_pic[i]->poc < out->poc) {\n                out     = h->delayed_pic[i];\n                out_idx = i;\n            }\n        for (i = out_idx; h->delayed_pic[i]; i++)\n            h->delayed_pic[i] = h->delayed_pic[i + 1];\n        if (out) {\n            ret = output_frame(h, pict, out->f);\n            if (ret < 0)\n                return ret;\n            *got_frame = 1;\n        }\n        return buf_index;\n    }\n    buf_index = decode_nal_units(h, buf, buf_size, 0);\n    if (buf_index < 0)\n        return AVERROR_INVALIDDATA;\n    if (!h->cur_pic_ptr && h->nal_unit_type == NAL_END_SEQUENCE) {\n        buf_size = 0;\n        goto out;\n    }\n    if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS) && !h->cur_pic_ptr) {\n        if (avctx->skip_frame >= AVDISCARD_NONREF)\n            return 0;\n        av_log(avctx, AV_LOG_ERROR, "no frame!\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS) ||\n        (h->mb_y >= h->mb_height && h->mb_height)) {\n        if (avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)\n            decode_postinit(h, 1);\n        ff_h264_field_end(h, &h->slice_ctx[0], 0);\n        *got_frame = 0;\n        if (h->next_output_pic && ((avctx->flags & AV_CODEC_FLAG_OUTPUT_CORRUPT) ||\n                                   h->next_output_pic->recovered)) {\n            if (!h->next_output_pic->recovered)\n                h->next_output_pic->f->flags |= AV_FRAME_FLAG_CORRUPT;\n            ret = output_frame(h, pict, h->next_output_pic->f);\n            if (ret < 0)\n                return ret;\n            *got_frame = 1;\n        }\n    }\n    assert(pict->buf[0] || !*got_frame);\n    return get_consumed_bytes(buf_index, buf_size);\n}', 'static void decode_postinit(H264Context *h, int setup_finished)\n{\n    H264Picture *out = h->cur_pic_ptr;\n    H264Picture *cur = h->cur_pic_ptr;\n    int i, pics, out_of_order, out_idx;\n    int invalid = 0, cnt = 0;\n    h->cur_pic_ptr->f->pict_type = h->pict_type;\n    if (h->next_output_pic)\n        return;\n    if (cur->field_poc[0] == INT_MAX || cur->field_poc[1] == INT_MAX) {\n        return;\n    }\n    cur->f->interlaced_frame = 0;\n    cur->f->repeat_pict      = 0;\n    if (h->sps.pic_struct_present_flag) {\n        switch (h->sei_pic_struct) {\n        case SEI_PIC_STRUCT_FRAME:\n            break;\n        case SEI_PIC_STRUCT_TOP_FIELD:\n        case SEI_PIC_STRUCT_BOTTOM_FIELD:\n            cur->f->interlaced_frame = 1;\n            break;\n        case SEI_PIC_STRUCT_TOP_BOTTOM:\n        case SEI_PIC_STRUCT_BOTTOM_TOP:\n            if (FIELD_OR_MBAFF_PICTURE(h))\n                cur->f->interlaced_frame = 1;\n            else\n                cur->f->interlaced_frame = h->prev_interlaced_frame;\n            break;\n        case SEI_PIC_STRUCT_TOP_BOTTOM_TOP:\n        case SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM:\n            cur->f->repeat_pict = 1;\n            break;\n        case SEI_PIC_STRUCT_FRAME_DOUBLING:\n            cur->f->repeat_pict = 2;\n            break;\n        case SEI_PIC_STRUCT_FRAME_TRIPLING:\n            cur->f->repeat_pict = 4;\n            break;\n        }\n        if ((h->sei_ct_type & 3) &&\n            h->sei_pic_struct <= SEI_PIC_STRUCT_BOTTOM_TOP)\n            cur->f->interlaced_frame = (h->sei_ct_type & (1 << 1)) != 0;\n    } else {\n        cur->f->interlaced_frame = FIELD_OR_MBAFF_PICTURE(h);\n    }\n    h->prev_interlaced_frame = cur->f->interlaced_frame;\n    if (cur->field_poc[0] != cur->field_poc[1]) {\n        cur->f->top_field_first = cur->field_poc[0] < cur->field_poc[1];\n    } else {\n        if (cur->f->interlaced_frame || h->sps.pic_struct_present_flag) {\n            if (h->sei_pic_struct == SEI_PIC_STRUCT_TOP_BOTTOM ||\n                h->sei_pic_struct == SEI_PIC_STRUCT_TOP_BOTTOM_TOP)\n                cur->f->top_field_first = 1;\n            else\n                cur->f->top_field_first = 0;\n        } else {\n            cur->f->top_field_first = 0;\n        }\n    }\n    if (h->sei_frame_packing_present &&\n        h->frame_packing_arrangement_type >= 0 &&\n        h->frame_packing_arrangement_type <= 6 &&\n        h->content_interpretation_type > 0 &&\n        h->content_interpretation_type < 3) {\n        AVStereo3D *stereo = av_stereo3d_create_side_data(cur->f);\n        if (!stereo)\n            return;\n        switch (h->frame_packing_arrangement_type) {\n        case 0:\n            stereo->type = AV_STEREO3D_CHECKERBOARD;\n            break;\n        case 1:\n            stereo->type = AV_STEREO3D_COLUMNS;\n            break;\n        case 2:\n            stereo->type = AV_STEREO3D_LINES;\n            break;\n        case 3:\n            if (h->quincunx_subsampling)\n                stereo->type = AV_STEREO3D_SIDEBYSIDE_QUINCUNX;\n            else\n                stereo->type = AV_STEREO3D_SIDEBYSIDE;\n            break;\n        case 4:\n            stereo->type = AV_STEREO3D_TOPBOTTOM;\n            break;\n        case 5:\n            stereo->type = AV_STEREO3D_FRAMESEQUENCE;\n            break;\n        case 6:\n            stereo->type = AV_STEREO3D_2D;\n            break;\n        }\n        if (h->content_interpretation_type == 2)\n            stereo->flags = AV_STEREO3D_FLAG_INVERT;\n    }\n    if (h->sei_display_orientation_present &&\n        (h->sei_anticlockwise_rotation || h->sei_hflip || h->sei_vflip)) {\n        double angle = h->sei_anticlockwise_rotation * 360 / (double) (1 << 16);\n        AVFrameSideData *rotation = av_frame_new_side_data(cur->f,\n                                                           AV_FRAME_DATA_DISPLAYMATRIX,\n                                                           sizeof(int32_t) * 9);\n        if (!rotation)\n            return;\n        av_display_rotation_set((int32_t *)rotation->data, angle);\n        av_display_matrix_flip((int32_t *)rotation->data,\n                               h->sei_hflip, h->sei_vflip);\n    }\n    if (h->sei_reguserdata_afd_present) {\n        AVFrameSideData *sd = av_frame_new_side_data(cur->f, AV_FRAME_DATA_AFD,\n                                                     sizeof(uint8_t));\n        if (!sd)\n            return;\n        *sd->data = h->active_format_description;\n        h->sei_reguserdata_afd_present = 0;\n    }\n    if (h->a53_caption) {\n        AVFrameSideData *sd = av_frame_new_side_data(cur->f,\n                                                     AV_FRAME_DATA_A53_CC,\n                                                     h->a53_caption_size);\n        if (!sd)\n            return;\n        memcpy(sd->data, h->a53_caption, h->a53_caption_size);\n        av_freep(&h->a53_caption);\n        h->a53_caption_size = 0;\n    }\n    if (h->sps.bitstream_restriction_flag ||\n        h->avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL) {\n        h->avctx->has_b_frames = FFMAX(h->avctx->has_b_frames, h->sps.num_reorder_frames);\n    }\n    h->low_delay = !h->avctx->has_b_frames;\n    pics = 0;\n    while (h->delayed_pic[pics])\n        pics++;\n    assert(pics <= MAX_DELAYED_PIC_COUNT);\n    h->delayed_pic[pics++] = cur;\n    if (cur->reference == 0)\n        cur->reference = DELAYED_PIC_REF;\n    for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++) {\n        cnt     += out->poc < h->last_pocs[i];\n        invalid += out->poc == INT_MIN;\n    }\n    if (!h->mmco_reset && !cur->f->key_frame &&\n        cnt + invalid == MAX_DELAYED_PIC_COUNT && cnt > 0) {\n        h->mmco_reset = 2;\n        if (pics > 1)\n            h->delayed_pic[pics - 2]->mmco_reset = 2;\n    }\n    if (h->mmco_reset || cur->f->key_frame) {\n        for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++)\n            h->last_pocs[i] = INT_MIN;\n        cnt     = 0;\n        invalid = MAX_DELAYED_PIC_COUNT;\n    }\n    out     = h->delayed_pic[0];\n    out_idx = 0;\n    for (i = 1; i < MAX_DELAYED_PIC_COUNT &&\n                h->delayed_pic[i] &&\n                !h->delayed_pic[i - 1]->mmco_reset &&\n                !h->delayed_pic[i]->f->key_frame;\n         i++)\n        if (h->delayed_pic[i]->poc < out->poc) {\n            out     = h->delayed_pic[i];\n            out_idx = i;\n        }\n    if (h->avctx->has_b_frames == 0 &&\n        (h->delayed_pic[0]->f->key_frame || h->mmco_reset))\n        h->next_outputed_poc = INT_MIN;\n    out_of_order = !out->f->key_frame && !h->mmco_reset &&\n                   (out->poc < h->next_outputed_poc);\n    if (h->sps.bitstream_restriction_flag &&\n        h->avctx->has_b_frames >= h->sps.num_reorder_frames) {\n    } else if (out_of_order && pics - 1 == h->avctx->has_b_frames &&\n               h->avctx->has_b_frames < MAX_DELAYED_PIC_COUNT) {\n        if (invalid + cnt < MAX_DELAYED_PIC_COUNT) {\n            h->avctx->has_b_frames = FFMAX(h->avctx->has_b_frames, cnt);\n        }\n        h->low_delay = 0;\n    } else if (h->low_delay &&\n               ((h->next_outputed_poc != INT_MIN &&\n                 out->poc > h->next_outputed_poc + 2) ||\n                cur->f->pict_type == AV_PICTURE_TYPE_B)) {\n        h->low_delay = 0;\n        h->avctx->has_b_frames++;\n    }\n    if (pics > h->avctx->has_b_frames) {\n        out->reference &= ~DELAYED_PIC_REF;\n        for (i = out_idx; h->delayed_pic[i]; i++)\n            h->delayed_pic[i] = h->delayed_pic[i + 1];\n    }\n    memmove(h->last_pocs, &h->last_pocs[1],\n            sizeof(*h->last_pocs) * (MAX_DELAYED_PIC_COUNT - 1));\n    h->last_pocs[MAX_DELAYED_PIC_COUNT - 1] = cur->poc;\n    if (!out_of_order && pics > h->avctx->has_b_frames) {\n        h->next_output_pic = out;\n        if (out->mmco_reset) {\n            if (out_idx > 0) {\n                h->next_outputed_poc                    = out->poc;\n                h->delayed_pic[out_idx - 1]->mmco_reset = out->mmco_reset;\n            } else {\n                h->next_outputed_poc = INT_MIN;\n            }\n        } else {\n            if (out_idx == 0 && pics > 1 && h->delayed_pic[0]->f->key_frame) {\n                h->next_outputed_poc = INT_MIN;\n            } else {\n                h->next_outputed_poc = out->poc;\n            }\n        }\n        h->mmco_reset = 0;\n    } else {\n        av_log(h->avctx, AV_LOG_DEBUG, "no picture\\n");\n    }\n    if (h->next_output_pic) {\n        if (h->next_output_pic->recovered) {\n            h->frame_recovered |= FRAME_RECOVERED_SEI;\n        }\n        h->next_output_pic->recovered |= !!(h->frame_recovered & FRAME_RECOVERED_SEI);\n    }\n    if (setup_finished && !h->avctx->hwaccel) {\n        ff_thread_finish_setup(h->avctx);\n        if (h->avctx->active_thread_type & FF_THREAD_FRAME)\n            h->setup_finished = 1;\n    }\n}', 'int ff_h264_field_end(H264Context *h, H264SliceContext *sl, int in_setup)\n{\n    AVCodecContext *const avctx = h->avctx;\n    int err = 0;\n    h->mb_y = 0;\n    if (!in_setup && !h->droppable)\n        ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,\n                                  h->picture_structure == PICT_BOTTOM_FIELD);\n    if (in_setup || !(avctx->active_thread_type & FF_THREAD_FRAME)) {\n        if (!h->droppable) {\n            err = ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);\n            h->prev_poc_msb = h->poc_msb;\n            h->prev_poc_lsb = h->poc_lsb;\n        }\n        h->prev_frame_num_offset = h->frame_num_offset;\n        h->prev_frame_num        = h->frame_num;\n    }\n    if (avctx->hwaccel) {\n        if (avctx->hwaccel->end_frame(avctx) < 0)\n            av_log(avctx, AV_LOG_ERROR,\n                   "hardware accelerator failed to decode picture\\n");\n    }\n#if CONFIG_ERROR_RESILIENCE\n    if (!FIELD_PICTURE(h) && h->enable_er) {\n        h264_set_erpic(&sl->er.cur_pic, h->cur_pic_ptr);\n        h264_set_erpic(&sl->er.last_pic,\n                       sl->ref_count[0] ? sl->ref_list[0][0].parent : NULL);\n        h264_set_erpic(&sl->er.next_pic,\n                       sl->ref_count[1] ? sl->ref_list[1][0].parent : NULL);\n        ff_er_frame_end(&sl->er);\n    }\n#endif\n    emms_c();\n    h->current_slice = 0;\n    return err;\n}', 'void ff_er_frame_end(ERContext *s)\n{\n    int *linesize = s->cur_pic.f->linesize;\n    int i, mb_x, mb_y, error, error_type, dc_error, mv_error, ac_error;\n    int distance;\n    int threshold_part[4] = { 100, 100, 100 };\n    int threshold = 50;\n    int is_intra_likely;\n    if (!s->avctx->error_concealment || s->error_count == 0            ||\n        s->avctx->hwaccel                                              ||\n        !s->cur_pic.f                                                  ||\n        s->cur_pic.field_picture                                       ||\n        s->error_count == 3 * s->mb_width *\n                          (s->avctx->skip_top + s->avctx->skip_bottom)) {\n        return;\n    };\n    if (!s->cur_pic.motion_val[0] || !s->cur_pic.ref_index[0]) {\n        av_log(s->avctx, AV_LOG_ERROR, "MVs not available, ER not possible.\\n");\n        return;\n    }\n    if (s->avctx->debug & FF_DEBUG_ER) {\n        for (mb_y = 0; mb_y < s->mb_height; mb_y++) {\n            for (mb_x = 0; mb_x < s->mb_width; mb_x++) {\n                int status = s->error_status_table[mb_x + mb_y * s->mb_stride];\n                av_log(s->avctx, AV_LOG_DEBUG, "%2X ", status);\n            }\n            av_log(s->avctx, AV_LOG_DEBUG, "\\n");\n        }\n    }\n    for (error_type = 1; error_type <= 3; error_type++) {\n        int end_ok = 0;\n        for (i = s->mb_num - 1; i >= 0; i--) {\n            const int mb_xy = s->mb_index2xy[i];\n            int error       = s->error_status_table[mb_xy];\n            if (error & (1 << error_type))\n                end_ok = 1;\n            if (error & (8 << error_type))\n                end_ok = 1;\n            if (!end_ok)\n                s->error_status_table[mb_xy] |= 1 << error_type;\n            if (error & VP_START)\n                end_ok = 0;\n        }\n    }\n    if (s->partitioned_frame) {\n        int end_ok = 0;\n        for (i = s->mb_num - 1; i >= 0; i--) {\n            const int mb_xy = s->mb_index2xy[i];\n            int error       = s->error_status_table[mb_xy];\n            if (error & ER_AC_END)\n                end_ok = 0;\n            if ((error & ER_MV_END) ||\n                (error & ER_DC_END) ||\n                (error & ER_AC_ERROR))\n                end_ok = 1;\n            if (!end_ok)\n                s->error_status_table[mb_xy]|= ER_AC_ERROR;\n            if (error & VP_START)\n                end_ok = 0;\n        }\n    }\n    if (s->avctx->err_recognition & AV_EF_EXPLODE) {\n        int end_ok = 1;\n        for (i = s->mb_num - 2; i >= s->mb_width + 100; i--) {\n            const int mb_xy = s->mb_index2xy[i];\n            int error1 = s->error_status_table[mb_xy];\n            int error2 = s->error_status_table[s->mb_index2xy[i + 1]];\n            if (error1 & VP_START)\n                end_ok = 1;\n            if (error2 == (VP_START | ER_MB_ERROR | ER_MB_END) &&\n                error1 != (VP_START | ER_MB_ERROR | ER_MB_END) &&\n                ((error1 & ER_AC_END) || (error1 & ER_DC_END) ||\n                (error1 & ER_MV_END))) {\n                end_ok = 0;\n            }\n            if (!end_ok)\n                s->error_status_table[mb_xy] |= ER_MB_ERROR;\n        }\n    }\n    distance = 9999999;\n    for (error_type = 1; error_type <= 3; error_type++) {\n        for (i = s->mb_num - 1; i >= 0; i--) {\n            const int mb_xy = s->mb_index2xy[i];\n            int       error = s->error_status_table[mb_xy];\n            if (s->mbskip_table && !s->mbskip_table[mb_xy])\n                distance++;\n            if (error & (1 << error_type))\n                distance = 0;\n            if (s->partitioned_frame) {\n                if (distance < threshold_part[error_type - 1])\n                    s->error_status_table[mb_xy] |= 1 << error_type;\n            } else {\n                if (distance < threshold)\n                    s->error_status_table[mb_xy] |= 1 << error_type;\n            }\n            if (error & VP_START)\n                distance = 9999999;\n        }\n    }\n    error = 0;\n    for (i = 0; i < s->mb_num; i++) {\n        const int mb_xy = s->mb_index2xy[i];\n        int old_error   = s->error_status_table[mb_xy];\n        if (old_error & VP_START) {\n            error = old_error & ER_MB_ERROR;\n        } else {\n            error |= old_error & ER_MB_ERROR;\n            s->error_status_table[mb_xy] |= error;\n        }\n    }\n    if (!s->partitioned_frame) {\n        for (i = 0; i < s->mb_num; i++) {\n            const int mb_xy = s->mb_index2xy[i];\n            error = s->error_status_table[mb_xy];\n            if (error & ER_MB_ERROR)\n                error |= ER_MB_ERROR;\n            s->error_status_table[mb_xy] = error;\n        }\n    }\n    dc_error = ac_error = mv_error = 0;\n    for (i = 0; i < s->mb_num; i++) {\n        const int mb_xy = s->mb_index2xy[i];\n        error = s->error_status_table[mb_xy];\n        if (error & ER_DC_ERROR)\n            dc_error++;\n        if (error & ER_AC_ERROR)\n            ac_error++;\n        if (error & ER_MV_ERROR)\n            mv_error++;\n    }\n    av_log(s->avctx, AV_LOG_INFO, "concealing %d DC, %d AC, %d MV errors\\n",\n           dc_error, ac_error, mv_error);\n    is_intra_likely = is_intra_more_likely(s);\n    for (i = 0; i < s->mb_num; i++) {\n        const int mb_xy = s->mb_index2xy[i];\n        error = s->error_status_table[mb_xy];\n        if (!((error & ER_DC_ERROR) && (error & ER_MV_ERROR)))\n            continue;\n        if (is_intra_likely)\n            s->cur_pic.mb_type[mb_xy] = MB_TYPE_INTRA4x4;\n        else\n            s->cur_pic.mb_type[mb_xy] = MB_TYPE_16x16 | MB_TYPE_L0;\n    }\n    if (!(s->last_pic.f && s->last_pic.f->data[0]) &&\n        !(s->next_pic.f && s->next_pic.f->data[0]))\n        for (i = 0; i < s->mb_num; i++) {\n            const int mb_xy = s->mb_index2xy[i];\n            if (!IS_INTRA(s->cur_pic.mb_type[mb_xy]))\n                s->cur_pic.mb_type[mb_xy] = MB_TYPE_INTRA4x4;\n        }\n    for (mb_y = 0; mb_y < s->mb_height; mb_y++) {\n        for (mb_x = 0; mb_x < s->mb_width; mb_x++) {\n            const int mb_xy   = mb_x + mb_y * s->mb_stride;\n            const int mb_type = s->cur_pic.mb_type[mb_xy];\n            const int dir     = !(s->last_pic.f && s->last_pic.f->data[0]);\n            const int mv_dir  = dir ? MV_DIR_BACKWARD : MV_DIR_FORWARD;\n            int mv_type;\n            error = s->error_status_table[mb_xy];\n            if (IS_INTRA(mb_type))\n                continue;\n            if (error & ER_MV_ERROR)\n                continue;\n            if (!(error & ER_AC_ERROR))\n                continue;\n            if (IS_8X8(mb_type)) {\n                int mb_index = mb_x * 2 + mb_y * 2 * s->b8_stride;\n                int j;\n                mv_type = MV_TYPE_8X8;\n                for (j = 0; j < 4; j++) {\n                    s->mv[0][j][0] = s->cur_pic.motion_val[dir][mb_index + (j & 1) + (j >> 1) * s->b8_stride][0];\n                    s->mv[0][j][1] = s->cur_pic.motion_val[dir][mb_index + (j & 1) + (j >> 1) * s->b8_stride][1];\n                }\n            } else {\n                mv_type     = MV_TYPE_16X16;\n                s->mv[0][0][0] = s->cur_pic.motion_val[dir][mb_x * 2 + mb_y * 2 * s->b8_stride][0];\n                s->mv[0][0][1] = s->cur_pic.motion_val[dir][mb_x * 2 + mb_y * 2 * s->b8_stride][1];\n            }\n            s->decode_mb(s->opaque, 0  ,\n                         mv_dir, mv_type, &s->mv, mb_x, mb_y, 0, 0);\n        }\n    }\n    if (s->cur_pic.f->pict_type == AV_PICTURE_TYPE_B) {\n        for (mb_y = 0; mb_y < s->mb_height; mb_y++) {\n            for (mb_x = 0; mb_x < s->mb_width; mb_x++) {\n                int       xy      = mb_x * 2 + mb_y * 2 * s->b8_stride;\n                const int mb_xy   = mb_x + mb_y * s->mb_stride;\n                const int mb_type = s->cur_pic.mb_type[mb_xy];\n                int mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD;\n                error = s->error_status_table[mb_xy];\n                if (IS_INTRA(mb_type))\n                    continue;\n                if (!(error & ER_MV_ERROR))\n                    continue;\n                if (!(error & ER_AC_ERROR))\n                    continue;\n                if (!(s->last_pic.f && s->last_pic.f->data[0]))\n                    mv_dir &= ~MV_DIR_FORWARD;\n                if (!(s->next_pic.f && s->next_pic.f->data[0]))\n                    mv_dir &= ~MV_DIR_BACKWARD;\n                if (s->pp_time) {\n                    int time_pp = s->pp_time;\n                    int time_pb = s->pb_time;\n                    ff_thread_await_progress(s->next_pic.tf, mb_y, 0);\n                    s->mv[0][0][0] = s->next_pic.motion_val[0][xy][0] *  time_pb            / time_pp;\n                    s->mv[0][0][1] = s->next_pic.motion_val[0][xy][1] *  time_pb            / time_pp;\n                    s->mv[1][0][0] = s->next_pic.motion_val[0][xy][0] * (time_pb - time_pp) / time_pp;\n                    s->mv[1][0][1] = s->next_pic.motion_val[0][xy][1] * (time_pb - time_pp) / time_pp;\n                } else {\n                    s->mv[0][0][0] = 0;\n                    s->mv[0][0][1] = 0;\n                    s->mv[1][0][0] = 0;\n                    s->mv[1][0][1] = 0;\n                }\n                s->decode_mb(s->opaque, 0, mv_dir, MV_TYPE_16X16, &s->mv,\n                             mb_x, mb_y, 0, 0);\n            }\n        }\n    } else\n        guess_mv(s);\n#if FF_API_XVMC\nFF_DISABLE_DEPRECATION_WARNINGS\n    if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration)\n        goto ec_clean;\nFF_ENABLE_DEPRECATION_WARNINGS\n#endif\n    for (mb_y = 0; mb_y < s->mb_height; mb_y++) {\n        for (mb_x = 0; mb_x < s->mb_width; mb_x++) {\n            int dc, dcu, dcv, y, n;\n            int16_t *dc_ptr;\n            uint8_t *dest_y, *dest_cb, *dest_cr;\n            const int mb_xy   = mb_x + mb_y * s->mb_stride;\n            const int mb_type = s->cur_pic.mb_type[mb_xy];\n            error = s->error_status_table[mb_xy];\n            if (IS_INTRA(mb_type) && s->partitioned_frame)\n                continue;\n            dest_y  = s->cur_pic.f->data[0] + mb_x * 16 + mb_y * 16 * linesize[0];\n            dest_cb = s->cur_pic.f->data[1] + mb_x *  8 + mb_y *  8 * linesize[1];\n            dest_cr = s->cur_pic.f->data[2] + mb_x *  8 + mb_y *  8 * linesize[2];\n            dc_ptr = &s->dc_val[0][mb_x * 2 + mb_y * 2 * s->b8_stride];\n            for (n = 0; n < 4; n++) {\n                dc = 0;\n                for (y = 0; y < 8; y++) {\n                    int x;\n                    for (x = 0; x < 8; x++)\n                       dc += dest_y[x + (n & 1) * 8 +\n                             (y + (n >> 1) * 8) * linesize[0]];\n                }\n                dc_ptr[(n & 1) + (n >> 1) * s->b8_stride] = (dc + 4) >> 3;\n            }\n            dcu = dcv = 0;\n            for (y = 0; y < 8; y++) {\n                int x;\n                for (x = 0; x < 8; x++) {\n                    dcu += dest_cb[x + y * linesize[1]];\n                    dcv += dest_cr[x + y * linesize[2]];\n                }\n            }\n            s->dc_val[1][mb_x + mb_y * s->mb_stride] = (dcu + 4) >> 3;\n            s->dc_val[2][mb_x + mb_y * s->mb_stride] = (dcv + 4) >> 3;\n        }\n    }\n    guess_dc(s, s->dc_val[0], s->mb_width * 2, s->mb_height * 2, s->b8_stride, 1);\n    guess_dc(s, s->dc_val[1], s->mb_width, s->mb_height, s->mb_stride, 0);\n    guess_dc(s, s->dc_val[2], s->mb_width, s->mb_height, s->mb_stride, 0);\n    filter181(s->dc_val[0], s->mb_width * 2, s->mb_height * 2, s->b8_stride);\n    for (mb_y = 0; mb_y < s->mb_height; mb_y++) {\n        for (mb_x = 0; mb_x < s->mb_width; mb_x++) {\n            uint8_t *dest_y, *dest_cb, *dest_cr;\n            const int mb_xy   = mb_x + mb_y * s->mb_stride;\n            const int mb_type = s->cur_pic.mb_type[mb_xy];\n            error = s->error_status_table[mb_xy];\n            if (IS_INTER(mb_type))\n                continue;\n            if (!(error & ER_AC_ERROR))\n                continue;\n            dest_y  = s->cur_pic.f->data[0] + mb_x * 16 + mb_y * 16 * linesize[0];\n            dest_cb = s->cur_pic.f->data[1] + mb_x *  8 + mb_y *  8 * linesize[1];\n            dest_cr = s->cur_pic.f->data[2] + mb_x *  8 + mb_y *  8 * linesize[2];\n            put_dc(s, dest_y, dest_cb, dest_cr, mb_x, mb_y);\n        }\n    }\n    if (s->avctx->error_concealment & FF_EC_DEBLOCK) {\n        h_block_filter(s, s->cur_pic.f->data[0], s->mb_width * 2,\n                       s->mb_height * 2, linesize[0], 1);\n        h_block_filter(s, s->cur_pic.f->data[1], s->mb_width,\n                       s->mb_height, linesize[1], 0);\n        h_block_filter(s, s->cur_pic.f->data[2], s->mb_width,\n                       s->mb_height, linesize[2], 0);\n        v_block_filter(s, s->cur_pic.f->data[0], s->mb_width * 2,\n                       s->mb_height * 2, linesize[0], 1);\n        v_block_filter(s, s->cur_pic.f->data[1], s->mb_width,\n                       s->mb_height, linesize[1], 0);\n        v_block_filter(s, s->cur_pic.f->data[2], s->mb_width,\n                       s->mb_height, linesize[2], 0);\n    }\nec_clean:\n    for (i = 0; i < s->mb_num; i++) {\n        const int mb_xy = s->mb_index2xy[i];\n        int       error = s->error_status_table[mb_xy];\n        if (s->mbskip_table && s->cur_pic.f->pict_type != AV_PICTURE_TYPE_B &&\n            (error & (ER_DC_ERROR | ER_MV_ERROR | ER_AC_ERROR))) {\n            s->mbskip_table[mb_xy] = 0;\n        }\n        if (s->mbintra_table)\n            s->mbintra_table[mb_xy] = 1;\n    }\n    memset(&s->cur_pic, 0, sizeof(ERPicture));\n    memset(&s->last_pic, 0, sizeof(ERPicture));\n    memset(&s->next_pic, 0, sizeof(ERPicture));\n}', 'static void guess_mv(ERContext *s)\n{\n    uint8_t *fixed = s->er_temp_buffer;\n#define MV_FROZEN    3\n#define MV_CHANGED   2\n#define MV_UNCHANGED 1\n    const int mb_stride = s->mb_stride;\n    const int mb_width  = s->mb_width;\n    const int mb_height = s->mb_height;\n    int i, depth, num_avail;\n    int mb_x, mb_y, mot_step, mot_stride;\n    set_mv_strides(s, &mot_step, &mot_stride);\n    num_avail = 0;\n    for (i = 0; i < s->mb_num; i++) {\n        const int mb_xy = s->mb_index2xy[i];\n        int f = 0;\n        int error = s->error_status_table[mb_xy];\n        if (IS_INTRA(s->cur_pic.mb_type[mb_xy]))\n            f = MV_FROZEN;\n        if (!(error & ER_MV_ERROR))\n            f = MV_FROZEN;\n        fixed[mb_xy] = f;\n        if (f == MV_FROZEN)\n            num_avail++;\n    }\n    if ((!(s->avctx->error_concealment&FF_EC_GUESS_MVS)) ||\n        num_avail <= mb_width / 2) {\n        for (mb_y = 0; mb_y < s->mb_height; mb_y++) {\n            for (mb_x = 0; mb_x < s->mb_width; mb_x++) {\n                const int mb_xy = mb_x + mb_y * s->mb_stride;\n                int mv_dir = (s->last_pic.f && s->last_pic.f->data[0]) ? MV_DIR_FORWARD : MV_DIR_BACKWARD;\n                if (IS_INTRA(s->cur_pic.mb_type[mb_xy]))\n                    continue;\n                if (!(s->error_status_table[mb_xy] & ER_MV_ERROR))\n                    continue;\n                s->mv[0][0][0] = 0;\n                s->mv[0][0][1] = 0;\n                s->decode_mb(s->opaque, 0, mv_dir, MV_TYPE_16X16, &s->mv,\n                             mb_x, mb_y, 0, 0);\n            }\n        }\n        return;\n    }\n    for (depth = 0; ; depth++) {\n        int changed, pass, none_left;\n        none_left = 1;\n        changed   = 1;\n        for (pass = 0; (changed || pass < 2) && pass < 10; pass++) {\n            int mb_x, mb_y;\n            int score_sum = 0;\n            changed = 0;\n            for (mb_y = 0; mb_y < s->mb_height; mb_y++) {\n                for (mb_x = 0; mb_x < s->mb_width; mb_x++) {\n                    const int mb_xy        = mb_x + mb_y * s->mb_stride;\n                    int mv_predictor[8][2] = { { 0 } };\n                    int ref[8]             = { 0 };\n                    int pred_count         = 0;\n                    int j;\n                    int best_score         = 256 * 256 * 256 * 64;\n                    int best_pred          = 0;\n                    const int mot_index    = (mb_x + mb_y * mot_stride) * mot_step;\n                    int prev_x = 0, prev_y = 0, prev_ref = 0;\n                    if ((mb_x ^ mb_y ^ pass) & 1)\n                        continue;\n                    if (fixed[mb_xy] == MV_FROZEN)\n                        continue;\n                    j = 0;\n                    if (mb_x > 0             && fixed[mb_xy - 1]         == MV_FROZEN)\n                        j = 1;\n                    if (mb_x + 1 < mb_width  && fixed[mb_xy + 1]         == MV_FROZEN)\n                        j = 1;\n                    if (mb_y > 0             && fixed[mb_xy - mb_stride] == MV_FROZEN)\n                        j = 1;\n                    if (mb_y + 1 < mb_height && fixed[mb_xy + mb_stride] == MV_FROZEN)\n                        j = 1;\n                    if (j == 0)\n                        continue;\n                    j = 0;\n                    if (mb_x > 0             && fixed[mb_xy - 1        ] == MV_CHANGED)\n                        j = 1;\n                    if (mb_x + 1 < mb_width  && fixed[mb_xy + 1        ] == MV_CHANGED)\n                        j = 1;\n                    if (mb_y > 0             && fixed[mb_xy - mb_stride] == MV_CHANGED)\n                        j = 1;\n                    if (mb_y + 1 < mb_height && fixed[mb_xy + mb_stride] == MV_CHANGED)\n                        j = 1;\n                    if (j == 0 && pass > 1)\n                        continue;\n                    none_left = 0;\n                    if (mb_x > 0 && fixed[mb_xy - 1]) {\n                        mv_predictor[pred_count][0] =\n                            s->cur_pic.motion_val[0][mot_index - mot_step][0];\n                        mv_predictor[pred_count][1] =\n                            s->cur_pic.motion_val[0][mot_index - mot_step][1];\n                        ref[pred_count] =\n                            s->cur_pic.ref_index[0][4 * (mb_xy - 1)];\n                        pred_count++;\n                    }\n                    if (mb_x + 1 < mb_width && fixed[mb_xy + 1]) {\n                        mv_predictor[pred_count][0] =\n                            s->cur_pic.motion_val[0][mot_index + mot_step][0];\n                        mv_predictor[pred_count][1] =\n                            s->cur_pic.motion_val[0][mot_index + mot_step][1];\n                        ref[pred_count] =\n                            s->cur_pic.ref_index[0][4 * (mb_xy + 1)];\n                        pred_count++;\n                    }\n                    if (mb_y > 0 && fixed[mb_xy - mb_stride]) {\n                        mv_predictor[pred_count][0] =\n                            s->cur_pic.motion_val[0][mot_index - mot_stride * mot_step][0];\n                        mv_predictor[pred_count][1] =\n                            s->cur_pic.motion_val[0][mot_index - mot_stride * mot_step][1];\n                        ref[pred_count] =\n                            s->cur_pic.ref_index[0][4 * (mb_xy - s->mb_stride)];\n                        pred_count++;\n                    }\n                    if (mb_y + 1<mb_height && fixed[mb_xy + mb_stride]) {\n                        mv_predictor[pred_count][0] =\n                            s->cur_pic.motion_val[0][mot_index + mot_stride * mot_step][0];\n                        mv_predictor[pred_count][1] =\n                            s->cur_pic.motion_val[0][mot_index + mot_stride * mot_step][1];\n                        ref[pred_count] =\n                            s->cur_pic.ref_index[0][4 * (mb_xy + s->mb_stride)];\n                        pred_count++;\n                    }\n                    if (pred_count == 0)\n                        continue;\n                    if (pred_count > 1) {\n                        int sum_x = 0, sum_y = 0, sum_r = 0;\n                        int max_x, max_y, min_x, min_y, max_r, min_r;\n                        for (j = 0; j < pred_count; j++) {\n                            sum_x += mv_predictor[j][0];\n                            sum_y += mv_predictor[j][1];\n                            sum_r += ref[j];\n                            if (j && ref[j] != ref[j - 1])\n                                goto skip_mean_and_median;\n                        }\n                        mv_predictor[pred_count][0] = sum_x / j;\n                        mv_predictor[pred_count][1] = sum_y / j;\n                                 ref[pred_count]    = sum_r / j;\n                        if (pred_count >= 3) {\n                            min_y = min_x = min_r =  99999;\n                            max_y = max_x = max_r = -99999;\n                        } else {\n                            min_x = min_y = max_x = max_y = min_r = max_r = 0;\n                        }\n                        for (j = 0; j < pred_count; j++) {\n                            max_x = FFMAX(max_x, mv_predictor[j][0]);\n                            max_y = FFMAX(max_y, mv_predictor[j][1]);\n                            max_r = FFMAX(max_r, ref[j]);\n                            min_x = FFMIN(min_x, mv_predictor[j][0]);\n                            min_y = FFMIN(min_y, mv_predictor[j][1]);\n                            min_r = FFMIN(min_r, ref[j]);\n                        }\n                        mv_predictor[pred_count + 1][0] = sum_x - max_x - min_x;\n                        mv_predictor[pred_count + 1][1] = sum_y - max_y - min_y;\n                                 ref[pred_count + 1]    = sum_r - max_r - min_r;\n                        if (pred_count == 4) {\n                            mv_predictor[pred_count + 1][0] /= 2;\n                            mv_predictor[pred_count + 1][1] /= 2;\n                                     ref[pred_count + 1]    /= 2;\n                        }\n                        pred_count += 2;\n                    }\nskip_mean_and_median:\n                    pred_count++;\n                    if (!fixed[mb_xy]) {\n                        if (s->avctx->codec_id == AV_CODEC_ID_H264) {\n                        } else {\n                            ff_thread_await_progress(s->last_pic.tf,\n                                                     mb_y, 0);\n                        }\n                        if (!s->last_pic.motion_val[0] ||\n                            !s->last_pic.ref_index[0])\n                            goto skip_last_mv;\n                        prev_x   = s->last_pic.motion_val[0][mot_index][0];\n                        prev_y   = s->last_pic.motion_val[0][mot_index][1];\n                        prev_ref = s->last_pic.ref_index[0][4 * mb_xy];\n                    } else {\n                        prev_x   = s->cur_pic.motion_val[0][mot_index][0];\n                        prev_y   = s->cur_pic.motion_val[0][mot_index][1];\n                        prev_ref = s->cur_pic.ref_index[0][4 * mb_xy];\n                    }\n                    mv_predictor[pred_count][0] = prev_x;\n                    mv_predictor[pred_count][1] = prev_y;\n                             ref[pred_count]    = prev_ref;\n                    pred_count++;\nskip_last_mv:\n                    for (j = 0; j < pred_count; j++) {\n                        int *linesize = s->cur_pic.f->linesize;\n                        int score = 0;\n                        uint8_t *src = s->cur_pic.f->data[0] +\n                                       mb_x * 16 + mb_y * 16 * linesize[0];\n                        s->cur_pic.motion_val[0][mot_index][0] =\n                            s->mv[0][0][0] = mv_predictor[j][0];\n                        s->cur_pic.motion_val[0][mot_index][1] =\n                            s->mv[0][0][1] = mv_predictor[j][1];\n                        if (ref[j] < 0)\n                            continue;\n                        s->decode_mb(s->opaque, ref[j], MV_DIR_FORWARD,\n                                     MV_TYPE_16X16, &s->mv, mb_x, mb_y, 0, 0);\n                        if (mb_x > 0 && fixed[mb_xy - 1]) {\n                            int k;\n                            for (k = 0; k < 16; k++)\n                                score += FFABS(src[k * linesize[0] - 1] -\n                                               src[k * linesize[0]]);\n                        }\n                        if (mb_x + 1 < mb_width && fixed[mb_xy + 1]) {\n                            int k;\n                            for (k = 0; k < 16; k++)\n                                score += FFABS(src[k * linesize[0] + 15] -\n                                               src[k * linesize[0] + 16]);\n                        }\n                        if (mb_y > 0 && fixed[mb_xy - mb_stride]) {\n                            int k;\n                            for (k = 0; k < 16; k++)\n                                score += FFABS(src[k - linesize[0]] - src[k]);\n                        }\n                        if (mb_y + 1 < mb_height && fixed[mb_xy + mb_stride]) {\n                            int k;\n                            for (k = 0; k < 16; k++)\n                                score += FFABS(src[k + linesize[0] * 15] -\n                                               src[k + linesize[0] * 16]);\n                        }\n                        if (score <= best_score) {\n                            best_score = score;\n                            best_pred  = j;\n                        }\n                    }\n                    score_sum += best_score;\n                    s->mv[0][0][0] = mv_predictor[best_pred][0];\n                    s->mv[0][0][1] = mv_predictor[best_pred][1];\n                    for (i = 0; i < mot_step; i++)\n                        for (j = 0; j < mot_step; j++) {\n                            s->cur_pic.motion_val[0][mot_index + i + j * mot_stride][0] = s->mv[0][0][0];\n                            s->cur_pic.motion_val[0][mot_index + i + j * mot_stride][1] = s->mv[0][0][1];\n                        }\n                    s->decode_mb(s->opaque, ref[best_pred], MV_DIR_FORWARD,\n                                 MV_TYPE_16X16, &s->mv, mb_x, mb_y, 0, 0);\n                    if (s->mv[0][0][0] != prev_x || s->mv[0][0][1] != prev_y) {\n                        fixed[mb_xy] = MV_CHANGED;\n                        changed++;\n                    } else\n                        fixed[mb_xy] = MV_UNCHANGED;\n                }\n            }\n        }\n        if (none_left)\n            return;\n        for (i = 0; i < s->mb_num; i++) {\n            int mb_xy = s->mb_index2xy[i];\n            if (fixed[mb_xy])\n                fixed[mb_xy] = MV_FROZEN;\n        }\n    }\n}', 'static void set_mv_strides(ERContext *s, int *mv_step, int *stride)\n{\n    if (s->avctx->codec_id == AV_CODEC_ID_H264) {\n        assert(s->quarter_sample);\n        *mv_step = 4;\n        *stride  = s->mb_width * 4;\n    } else {\n        *mv_step = 2;\n        *stride  = s->b8_stride;\n    }\n}']