libavcodec/h264dec.c:735: error: Integer Overflow L2
  ([8, 2147483648] × 4):signed32 by call to `ff_h264_field_end`.

libavcodec/h264dec.c:717:17: Call
715.     }
716. 
717.     buf_index = decode_nal_units(h, buf, buf_size);
                     ^
718.     if (buf_index < 0)
719.         return AVERROR_INVALIDDATA;

libavcodec/h264dec.c:521:11: Call
  519.     }
  520. 
  521.     ret = ff_h2645_packet_split(&h->pkt, buf, buf_size, avctx, h->is_avc,
                 ^
  522.                                 h->nal_length_size, avctx->codec_id);
  523.     if (ret < 0) {

libavcodec/h2645_parse.c:301:15: Call
    299.         nal->size_bits = get_bit_length(nal, skip_trailing_zeros);
    300. 
    301.         ret = init_get_bits(&nal->gb, nal->data, nal->size_bits);
                       ^
    302.         if (ret < 0)
    303.             return ret;

libavcodec/get_bits.h:362:1: Parameter `bit_size`
      360.  * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
      361.  */
      362. static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,
           ^
      363.                                 int bit_size)
      364. {

libavcodec/get_bits.h:379:5: Assignment
      377.     s->size_in_bits       = bit_size;
      378. #if !UNCHECKED_BITSTREAM_READER
      379.     s->size_in_bits_plus8 = bit_size + 8;
               ^
      380. #endif
      381.     s->buffer_end         = buffer + buffer_size;

libavcodec/h264dec.c:735:9: Call
733.     if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS) ||
734.         (h->mb_y >= h->mb_height && h->mb_height)) {
735.         ff_h264_field_end(h, &h->slice_ctx[0], 0);
             ^
736. 
737.         *got_frame = 0;

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

libavcodec/h264_picture.c:190:9: Call
  188.         h264_set_erpic(&sl->er.next_pic,
  189.                        sl->ref_count[1] ? sl->ref_list[1][0].parent : NULL);
  190.         ff_er_frame_end(&sl->er);
               ^
  191.     }
  192. #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: ([8, 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    const uint8_t *new_extradata;\n    int new_extradata_size;\n    h->flags = avctx->flags;\n    h->setup_finished = 0;\n    h->nb_slice_ctx_queued = 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    new_extradata_size = 0;\n    new_extradata = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA,\n                                            &new_extradata_size);\n    if (new_extradata_size > 0 && new_extradata) {\n        ret = ff_h264_decode_extradata(new_extradata, new_extradata_size,\n                                       &h->ps, &h->is_avc, &h->nal_length_size,\n                                       avctx->err_recognition, avctx);\n        if (ret < 0)\n            return ret;\n    }\n    buf_index = decode_nal_units(h, buf, buf_size);\n    if (buf_index < 0)\n        return AVERROR_INVALIDDATA;\n    if (!h->cur_pic_ptr && h->nal_unit_type == H264_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        ff_h264_field_end(h, &h->slice_ctx[0], 0);\n        *got_frame = 0;\n        if (h->output_frame->buf[0]) {\n            ret = output_frame(h, pict, h->output_frame) ;\n            av_frame_unref(h->output_frame);\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 int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size)\n{\n    AVCodecContext *const avctx = h->avctx;\n    int nals_needed = 0;\n    int i, ret = 0;\n    if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) {\n        h->current_slice = 0;\n        if (!h->first_field)\n            h->cur_pic_ptr = NULL;\n        ff_h264_sei_uninit(&h->sei);\n    }\n    ret = ff_h2645_packet_split(&h->pkt, buf, buf_size, avctx, h->is_avc,\n                                h->nal_length_size, avctx->codec_id);\n    if (ret < 0) {\n        av_log(avctx, AV_LOG_ERROR,\n               "Error splitting the input into NAL units.\\n");\n        return ret;\n    }\n    if (avctx->active_thread_type & FF_THREAD_FRAME)\n        nals_needed = get_last_needed_nal(h);\n    for (i = 0; i < h->pkt.nb_nals; i++) {\n        H2645NAL *nal = &h->pkt.nals[i];\n        int max_slice_ctx, err;\n        if (avctx->skip_frame >= AVDISCARD_NONREF &&\n            nal->ref_idc == 0 && nal->type != H264_NAL_SEI)\n            continue;\n        h->nal_ref_idc   = nal->ref_idc;\n        h->nal_unit_type = nal->type;\n        err = 0;\n        switch (nal->type) {\n        case H264_NAL_IDR_SLICE:\n            idr(h);\n        case H264_NAL_SLICE:\n            if ((err = ff_h264_queue_decode_slice(h, nal)))\n                break;\n            if (avctx->active_thread_type & FF_THREAD_FRAME && !h->avctx->hwaccel &&\n                i >= nals_needed) {\n                ff_thread_finish_setup(avctx);\n                h->setup_finished = 1;\n            }\n            max_slice_ctx = avctx->hwaccel ? 1 : h->nb_slice_ctx;\n            if (h->nb_slice_ctx_queued == max_slice_ctx) {\n                if (avctx->hwaccel)\n                    ret = avctx->hwaccel->decode_slice(avctx, nal->raw_data, nal->raw_size);\n                else\n                    ret = ff_h264_execute_decode_slices(h);\n                if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n                    goto end;\n            }\n            break;\n        case H264_NAL_DPA:\n        case H264_NAL_DPB:\n        case H264_NAL_DPC:\n            avpriv_request_sample(avctx, "data partitioning");\n            ret = AVERROR(ENOSYS);\n            goto end;\n            break;\n        case H264_NAL_SEI:\n            ret = ff_h264_sei_decode(&h->sei, &nal->gb, &h->ps, avctx);\n            if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n                goto end;\n            break;\n        case H264_NAL_SPS:\n            ret = ff_h264_decode_seq_parameter_set(&nal->gb, avctx, &h->ps);\n            if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n                goto end;\n            break;\n        case H264_NAL_PPS:\n            ret = ff_h264_decode_picture_parameter_set(&nal->gb, avctx, &h->ps,\n                                                       nal->size_bits);\n            if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n                goto end;\n            break;\n        case H264_NAL_AUD:\n        case H264_NAL_END_SEQUENCE:\n        case H264_NAL_END_STREAM:\n        case H264_NAL_FILLER_DATA:\n        case H264_NAL_SPS_EXT:\n        case H264_NAL_AUXILIARY_SLICE:\n            break;\n        default:\n            av_log(avctx, AV_LOG_DEBUG, "Unknown NAL code: %d (%d bits)\\n",\n                   nal->type, nal->size_bits);\n        }\n        if (err < 0) {\n            av_log(h->avctx, AV_LOG_ERROR, "decode_slice_header error\\n");\n        }\n    }\n    ret = ff_h264_execute_decode_slices(h);\n    if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n        goto end;\n    ret = 0;\nend:\n    if (h->cur_pic_ptr && !h->droppable) {\n        ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,\n                                  h->picture_structure == PICT_BOTTOM_FIELD);\n    }\n    return (ret < 0) ? ret : buf_size;\n}', 'int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,\n                          void *logctx, int is_nalff, int nal_length_size,\n                          enum AVCodecID codec_id)\n{\n    int consumed, ret = 0;\n    const uint8_t *next_avc = buf + (is_nalff ? 0 : length);\n    pkt->nb_nals = 0;\n    while (length >= 4) {\n        H2645NAL *nal;\n        int extract_length = 0;\n        int skip_trailing_zeros = 1;\n        if (buf == next_avc) {\n            int i;\n            for (i = 0; i < nal_length_size; i++)\n                extract_length = (extract_length << 8) | buf[i];\n            if (extract_length > length) {\n                av_log(logctx, AV_LOG_ERROR,\n                       "Invalid NAL unit size (%d > %d).\\n",\n                       extract_length, length);\n                return AVERROR_INVALIDDATA;\n            }\n            buf     += nal_length_size;\n            length  -= nal_length_size;\n            next_avc = buf + extract_length;\n        } else {\n            int buf_index = find_next_start_code(buf, next_avc);\n            buf    += buf_index;\n            length -= buf_index;\n            if (buf == next_avc)\n                continue;\n            if (length > 0) {\n                extract_length = length;\n            } else if (pkt->nb_nals == 0) {\n                av_log(logctx, AV_LOG_ERROR, "No NAL unit found\\n");\n                return AVERROR_INVALIDDATA;\n            } else {\n                break;\n            }\n        }\n        if (pkt->nals_allocated < pkt->nb_nals + 1) {\n            int new_size = pkt->nals_allocated + 1;\n            H2645NAL *tmp = av_realloc_array(pkt->nals, new_size, sizeof(*tmp));\n            if (!tmp)\n                return AVERROR(ENOMEM);\n            pkt->nals = tmp;\n            memset(pkt->nals + pkt->nals_allocated, 0,\n                   (new_size - pkt->nals_allocated) * sizeof(*tmp));\n            pkt->nals_allocated = new_size;\n        }\n        nal = &pkt->nals[pkt->nb_nals++];\n        consumed = ff_h2645_extract_rbsp(buf, extract_length, nal);\n        if (consumed < 0)\n            return consumed;\n        if (consumed < length - 3 &&\n            buf[consumed]     == 0x00 && buf[consumed + 1] == 0x00 &&\n            buf[consumed + 2] == 0x01 && buf[consumed + 3] == 0xE0)\n            skip_trailing_zeros = 0;\n        nal->size_bits = get_bit_length(nal, skip_trailing_zeros);\n        ret = init_get_bits(&nal->gb, nal->data, nal->size_bits);\n        if (ret < 0)\n            return ret;\n        if (codec_id == AV_CODEC_ID_HEVC)\n            ret = hevc_parse_nal_header(nal, logctx);\n        else\n            ret = h264_parse_nal_header(nal, logctx);\n        if (ret <= 0) {\n            if (ret < 0) {\n                av_log(logctx, AV_LOG_ERROR, "Invalid NAL unit %d, skipping.\\n",\n                       nal->type);\n            }\n            pkt->nb_nals--;\n        }\n        buf    += consumed;\n        length -= consumed;\n    }\n    return 0;\n}', 'static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,\n                                int bit_size)\n{\n    int buffer_size;\n    int ret = 0;\n    if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {\n        bit_size    = 0;\n        buffer      = NULL;\n        ret         = AVERROR_INVALIDDATA;\n    }\n    buffer_size = (bit_size + 7) >> 3;\n    s->buffer             = buffer;\n    s->size_in_bits       = bit_size;\n#if !UNCHECKED_BITSTREAM_READER\n    s->size_in_bits_plus8 = bit_size + 8;\n#endif\n    s->buffer_end         = buffer + buffer_size;\n    s->index              = 0;\n    return ret;\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);\n            h->poc.prev_poc_msb = h->poc.poc_msb;\n            h->poc.prev_poc_lsb = h->poc.poc_lsb;\n        }\n        h->poc.prev_frame_num_offset = h->poc.frame_num_offset;\n        h->poc.prev_frame_num        = h->poc.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    }\n#if FF_API_XVMC\nec_clean:\n#endif\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}']