libavcodec/h264.c:4199: error: Integer Overflow L2
  ([0, +oo] - 1):unsigned32 by call to `field_end`.

libavcodec/h264.c:4178:17: Call
4176.     }
4177. 
4178.     buf_index = decode_nal_units(h, buf, buf_size, 0);
                      ^
4179.     if (buf_index < 0)
4180.         return -1;

libavcodec/h264.c:3823:1: Parameter `h->s.list_count`
  3821. }
  3822. 
  3823. static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size,
        ^
  3824.                             int parse_extradata)
  3825. {

libavcodec/h264.c:4199:9: Call
4197.             decode_postinit(h, 1);
4198. 
4199.         field_end(h, 0);
              ^
4200.         h->context_reinitialized = 0;
4201. 

libavcodec/h264.c:2282:1: Parameter `h->s.list_count`
  2280. }
  2281. 
  2282. static int field_end(H264Context *h, int in_setup)
        ^
  2283. {
  2284.     MpegEncContext *const s     = &h->s;

libavcodec/h264.c:2331:9: Call
  2329.      */
  2330.     if (!FIELD_PICTURE)
  2331.         ff_er_frame_end(s);
                ^
  2332. 
  2333.     ff_MPV_frame_end(s);

libavcodec/error_resilience.c:878:1: Parameter `s->list_count`
    876. }
    877. 
    878. void ff_er_frame_end(MpegEncContext *s)
         ^
    879. {
    880.     int i, mb_x, mb_y, error, error_type, dc_error, mv_error, ac_error;

libavcodec/error_resilience.c:1056:23: Call
    1054.            dc_error, ac_error, mv_error);
    1055. 
    1056.     is_intra_likely = is_intra_more_likely(s);
                                ^
    1057. 
    1058.     /* set unknown mb-type to most likely */

libavcodec/error_resilience.c:715:1: Parameter `s->list_count`
      713. }
      714. 
      715. static int is_intra_more_likely(MpegEncContext *s)
           ^
      716. {
      717.     int is_intra_likely, i, j, undamaged_count, skip_amount, mb_x, mb_y;

libavcodec/error_resilience.c:1121:13: Call
    1119.             s->mb_x = mb_x;
    1120.             s->mb_y = mb_y;
    1121.             decode_mb(s, 0 /* FIXME h264 partitioned slices need this set */);
                      ^
    1122.         }
    1123.     }

libavcodec/error_resilience.c:43:1: Parameter `s->list_count`
      41. #undef mb_intra
      42. 
      43. static void decode_mb(MpegEncContext *s, int ref)
          ^
      44. {
      45.     s->dest[0] = s->current_picture.f.data[0] + (s->mb_y *  16                       * s->linesize)   + s->mb_x *  16;

libavcodec/error_resilience.c:66:9: Call
      64.                        pack16to32(s->mv[0][0][0], s->mv[0][0][1]), 4);
      65.         assert(!FRAME_MBAFF);
      66.         ff_h264_hl_decode_mb(h);
                  ^
      67.     } else {
      68.         assert(ref == 0);

libavcodec/h264.c:1970:1: Parameter `h->list_count`
        1968. #include "h264_mb_template.c"
        1969. 
        1970. void ff_h264_hl_decode_mb(H264Context *h)
              ^
        1971. {
        1972.     MpegEncContext *const s = &h->s;

libavcodec/h264.c:1979:13: Call
        1977.     if (CHROMA444) {
        1978.         if (is_complex || h->pixel_shift)
        1979.             hl_decode_mb_444_complex(h);
                          ^
        1980.         else
        1981.             hl_decode_mb_444_simple_8(h);

libavcodec/h264_mb_template.c:278:1: Parameter `h->list_count`
          276. #include "h264_mc_template.c"
          277. 
          278. static av_noinline void FUNC(hl_decode_mb_444)(H264Context *h)
               ^
          279. {
          280.     MpegEncContext *const s = &h->s;

libavcodec/h264_mb_template.c:362:13: Call
          360.                                linesize, 0, 1, SIMPLE, PIXEL_SHIFT);
          361.         } else {
          362.             FUNC(hl_motion_444)(h, dest[0], dest[1], dest[2],
                           ^
          363.                       s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab,
          364.                       s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab,

libavcodec/h264_mc_template.c:61:1: Parameter `h->list_count`
            59. }
            60. 
            61. static void MCFUNC(hl_motion)(H264Context *h, uint8_t *dest_y,
                ^
            62.                               uint8_t *dest_cb, uint8_t *dest_cr,
            63.                               qpel_mc_func(*qpix_put)[16],

libavcodec/h264_mc_template.c:77:9: Call
            75. 
            76.     if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))
            77.         await_references(h);
                        ^
            78.     prefetch_motion(h, 0, PIXEL_SHIFT, CHROMA_IDC);
            79. 

libavcodec/h264.c:345:1: <LHS trace>
343.  * @param h the H264 context
344.  */
345. static void await_references(H264Context *h)
     ^
346. {
347.     MpegEncContext *const s = &h->s;

libavcodec/h264.c:345:1: Parameter `h->list_count`
              343.  * @param h the H264 context
              344.  */
              345. static void await_references(H264Context *h)
                   ^
              346. {
              347.     MpegEncContext *const s = &h->s;

libavcodec/h264.c:416:10: Binary operation: ([0, +oo] - 1):unsigned32 by call to `field_end` 
              414.     }
              415. 
              416.     for (list = h->list_count - 1; list >= 0; list--)
                            ^
              417.         for (ref = 0; ref < 48 && nrefs[list]; ref++) {
              418.             int row = refs[list][ref];

static void await_references(H264Context *h)
{
    MpegEncContext *const s = &h->s;
    const int mb_xy   = h->mb_xy;
    const int mb_type = s->current_picture.f.mb_type[mb_xy];
    int refs[2][48];
    int nrefs[2] = { 0 };
    int ref, list;
    memset(refs, -1, sizeof(refs));
    if (IS_16X16(mb_type)) {
        get_lowest_part_y(h, refs, 0, 16, 0,
                          IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);
    } else if (IS_16X8(mb_type)) {
        get_lowest_part_y(h, refs, 0, 8, 0,
                          IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);
        get_lowest_part_y(h, refs, 8, 8, 8,
                          IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs);
    } else if (IS_8X16(mb_type)) {
        get_lowest_part_y(h, refs, 0, 16, 0,
                          IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);
        get_lowest_part_y(h, refs, 4, 16, 0,
                          IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs);
    } else {
        int i;
        assert(IS_8X8(mb_type));
        for (i = 0; i < 4; i++) {
            const int sub_mb_type = h->sub_mb_type[i];
            const int n           = 4 * i;
            int y_offset          = (i & 2) << 2;
            if (IS_SUB_8X8(sub_mb_type)) {
                get_lowest_part_y(h, refs, n, 8, y_offset,
                                  IS_DIR(sub_mb_type, 0, 0),
                                  IS_DIR(sub_mb_type, 0, 1),
                                  nrefs);
            } else if (IS_SUB_8X4(sub_mb_type)) {
                get_lowest_part_y(h, refs, n, 4, y_offset,
                                  IS_DIR(sub_mb_type, 0, 0),
                                  IS_DIR(sub_mb_type, 0, 1),
                                  nrefs);
                get_lowest_part_y(h, refs, n + 2, 4, y_offset + 4,
                                  IS_DIR(sub_mb_type, 0, 0),
                                  IS_DIR(sub_mb_type, 0, 1),
                                  nrefs);
            } else if (IS_SUB_4X8(sub_mb_type)) {
                get_lowest_part_y(h, refs, n, 8, y_offset,
                                  IS_DIR(sub_mb_type, 0, 0),
                                  IS_DIR(sub_mb_type, 0, 1),
                                  nrefs);
                get_lowest_part_y(h, refs, n + 1, 8, y_offset,
                                  IS_DIR(sub_mb_type, 0, 0),
                                  IS_DIR(sub_mb_type, 0, 1),
                                  nrefs);
            } else {
                int j;
                assert(IS_SUB_4X4(sub_mb_type));
                for (j = 0; j < 4; j++) {
                    int sub_y_offset = y_offset + 2 * (j & 2);
                    get_lowest_part_y(h, refs, n + j, 4, sub_y_offset,
                                      IS_DIR(sub_mb_type, 0, 0),
                                      IS_DIR(sub_mb_type, 0, 1),
                                      nrefs);
                }
            }
        }
    }
    for (list = h->list_count - 1; list >= 0; list--)
        for (ref = 0; ref < 48 && nrefs[list]; ref++) {
            int row = refs[list][ref];
            if (row >= 0) {
                Picture *ref_pic      = &h->ref_list[list][ref];
                int ref_field         = ref_pic->f.reference - 1;
                int ref_field_picture = ref_pic->field_picture;
                int pic_height        = 16 * s->mb_height >> ref_field_picture;
                row <<= MB_MBAFF;
                nrefs[list]--;
                if (!FIELD_PICTURE && ref_field_picture) {
                    ff_thread_await_progress(&ref_pic->f,
                                             FFMIN((row >> 1) - !(row & 1),
                                                   pic_height - 1),
                                             1);
                    ff_thread_await_progress(&ref_pic->f,
                                             FFMIN((row >> 1), pic_height - 1),
                                             0);
                } else if (FIELD_PICTURE && !ref_field_picture) {
                    ff_thread_await_progress(&ref_pic->f,
                                             FFMIN(row * 2 + ref_field,
                                                   pic_height - 1),
                                             0);
                } else if (FIELD_PICTURE) {
                    ff_thread_await_progress(&ref_pic->f,
                                             FFMIN(row, pic_height - 1),
                                             ref_field);
                } else {
                    ff_thread_await_progress(&ref_pic->f,
                                             FFMIN(row, pic_height - 1),
                                             0);
                }
            }
        }
}
['static int 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    MpegEncContext *s  = &h->s;\n    AVFrame *pict      = data;\n    int buf_index      = 0;\n    s->flags  = avctx->flags;\n    s->flags2 = avctx->flags2;\nout:\n    if (buf_size == 0) {\n        Picture *out;\n        int i, out_idx;\n        s->current_picture_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            *got_frame = 1;\n            *pict      = out->f;\n        }\n        return buf_index;\n    }\n    buf_index = decode_nal_units(h, buf, buf_size, 0);\n    if (buf_index < 0)\n        return -1;\n    if (!s->current_picture_ptr && h->nal_unit_type == NAL_END_SEQUENCE) {\n        buf_size = 0;\n        goto out;\n    }\n    if (!(s->flags2 & CODEC_FLAG2_CHUNKS) && !s->current_picture_ptr) {\n        if (avctx->skip_frame >= AVDISCARD_NONREF)\n            return 0;\n        av_log(avctx, AV_LOG_ERROR, "no frame!\\n");\n        return -1;\n    }\n    if (!(s->flags2 & CODEC_FLAG2_CHUNKS) ||\n        (s->mb_y >= s->mb_height && s->mb_height)) {\n        if (s->flags2 & CODEC_FLAG2_CHUNKS)\n            decode_postinit(h, 1);\n        field_end(h, 0);\n        h->context_reinitialized = 0;\n        if (!h->next_output_pic) {\n            *got_frame = 0;\n        } else {\n            *got_frame = 1;\n            *pict      = h->next_output_pic->f;\n        }\n    }\n    assert(pict->data[0] || !*got_frame);\n    ff_print_debug_info(s, pict);\n    return get_consumed_bytes(s, buf_index, buf_size);\n}', 'static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size,\n                            int parse_extradata)\n{\n    MpegEncContext *const s     = &h->s;\n    AVCodecContext *const avctx = s->avctx;\n    H264Context *hx;\n    int buf_index;\n    int context_count;\n    int next_avc;\n    int pass = !(avctx->active_thread_type & FF_THREAD_FRAME);\n    int nals_needed = 0;\n    int nal_index;\n    h->max_contexts = s->slice_context_count;\n    if (!(s->flags2 & CODEC_FLAG2_CHUNKS)) {\n        h->current_slice = 0;\n        if (!s->first_field)\n            s->current_picture_ptr = NULL;\n        ff_h264_reset_sei(h);\n    }\n    for (; pass <= 1; pass++) {\n        buf_index     = 0;\n        context_count = 0;\n        next_avc      = h->is_avc ? 0 : buf_size;\n        nal_index     = 0;\n        for (;;) {\n            int consumed;\n            int dst_length;\n            int bit_length;\n            const uint8_t *ptr;\n            int i, nalsize = 0;\n            int err;\n            if (buf_index >= next_avc) {\n                if (buf_index >= buf_size - h->nal_length_size)\n                    break;\n                nalsize = 0;\n                for (i = 0; i < h->nal_length_size; i++)\n                    nalsize = (nalsize << 8) | buf[buf_index++];\n                if (nalsize <= 0 || nalsize > buf_size - buf_index) {\n                    av_log(h->s.avctx, AV_LOG_ERROR,\n                           "AVC: nal size %d\\n", nalsize);\n                    break;\n                }\n                next_avc = buf_index + nalsize;\n            } else {\n                for (; buf_index + 3 < next_avc; buf_index++)\n                    if (buf[buf_index]     == 0 &&\n                        buf[buf_index + 1] == 0 &&\n                        buf[buf_index + 2] == 1)\n                        break;\n                if (buf_index + 3 >= buf_size) {\n                    buf_index = buf_size;\n                    break;\n                }\n                buf_index += 3;\n                if (buf_index >= next_avc)\n                    continue;\n            }\n            hx = h->thread_context[context_count];\n            ptr = ff_h264_decode_nal(hx, buf + buf_index, &dst_length,\n                                     &consumed, next_avc - buf_index);\n            if (ptr == NULL || dst_length < 0) {\n                buf_index = -1;\n                goto end;\n            }\n            i = buf_index + consumed;\n            if ((s->workaround_bugs & FF_BUG_AUTODETECT) && i + 3 < next_avc &&\n                buf[i]     == 0x00 && buf[i + 1] == 0x00 &&\n                buf[i + 2] == 0x01 && buf[i + 3] == 0xE0)\n                s->workaround_bugs |= FF_BUG_TRUNCATED;\n            if (!(s->workaround_bugs & FF_BUG_TRUNCATED))\n                while (ptr[dst_length - 1] == 0 && dst_length > 0)\n                    dst_length--;\n            bit_length = !dst_length ? 0\n                                     : (8 * dst_length -\n                                        decode_rbsp_trailing(h, ptr + dst_length - 1));\n            if (s->avctx->debug & FF_DEBUG_STARTCODE)\n                av_log(h->s.avctx, AV_LOG_DEBUG,\n                       "NAL %d at %d/%d length %d\\n",\n                       hx->nal_unit_type, buf_index, buf_size, dst_length);\n            if (h->is_avc && (nalsize != consumed) && nalsize)\n                av_log(h->s.avctx, AV_LOG_DEBUG,\n                       "AVC: Consumed only %d bytes instead of %d\\n",\n                       consumed, nalsize);\n            buf_index += consumed;\n            nal_index++;\n            if (pass == 0) {\n                switch (hx->nal_unit_type) {\n                case NAL_SPS:\n                case NAL_PPS:\n                    nals_needed = nal_index;\n                    break;\n                case NAL_DPA:\n                case NAL_IDR_SLICE:\n                case NAL_SLICE:\n                    init_get_bits(&hx->s.gb, ptr, bit_length);\n                    if (!get_ue_golomb(&hx->s.gb))\n                        nals_needed = nal_index;\n                }\n                continue;\n            }\n            if (avctx->skip_frame >= AVDISCARD_NONREF && h->nal_ref_idc == 0)\n                continue;\nagain:\n            if (parse_extradata && HAVE_THREADS &&\n                (s->avctx->active_thread_type & FF_THREAD_FRAME) &&\n                (hx->nal_unit_type != NAL_PPS &&\n                 hx->nal_unit_type != NAL_SPS)) {\n                av_log(avctx, AV_LOG_INFO, "Ignoring NAL unit %d during "\n                       "extradata parsing\\n", hx->nal_unit_type);\n                hx->nal_unit_type = NAL_FF_IGNORE;\n            }\n            err = 0;\n            switch (hx->nal_unit_type) {\n            case NAL_IDR_SLICE:\n                if (h->nal_unit_type != NAL_IDR_SLICE) {\n                    av_log(h->s.avctx, AV_LOG_ERROR,\n                           "Invalid mix of idr and non-idr slices\\n");\n                    buf_index = -1;\n                    goto end;\n                }\n                idr(h);\n            case NAL_SLICE:\n                init_get_bits(&hx->s.gb, ptr, bit_length);\n                hx->intra_gb_ptr        =\n                    hx->inter_gb_ptr    = &hx->s.gb;\n                hx->s.data_partitioning = 0;\n                if ((err = decode_slice_header(hx, h)))\n                    break;\n                s->current_picture_ptr->f.key_frame |=\n                    (hx->nal_unit_type == NAL_IDR_SLICE) ||\n                    (h->sei_recovery_frame_cnt >= 0);\n                if (h->current_slice == 1) {\n                    if (!(s->flags2 & CODEC_FLAG2_CHUNKS))\n                        decode_postinit(h, nal_index >= nals_needed);\n                    if (s->avctx->hwaccel &&\n                        s->avctx->hwaccel->start_frame(s->avctx, NULL, 0) < 0)\n                        return -1;\n                    if (CONFIG_H264_VDPAU_DECODER &&\n                        s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)\n                        ff_vdpau_h264_picture_start(s);\n                }\n                if (hx->redundant_pic_count == 0 &&\n                    (avctx->skip_frame < AVDISCARD_NONREF ||\n                     hx->nal_ref_idc) &&\n                    (avctx->skip_frame < AVDISCARD_BIDIR  ||\n                     hx->slice_type_nos != AV_PICTURE_TYPE_B) &&\n                    (avctx->skip_frame < AVDISCARD_NONKEY ||\n                     hx->slice_type_nos == AV_PICTURE_TYPE_I) &&\n                    avctx->skip_frame < AVDISCARD_ALL) {\n                    if (avctx->hwaccel) {\n                        if (avctx->hwaccel->decode_slice(avctx,\n                                                         &buf[buf_index - consumed],\n                                                         consumed) < 0)\n                            return -1;\n                    } else if (CONFIG_H264_VDPAU_DECODER &&\n                               s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) {\n                        static const uint8_t start_code[] = {\n                            0x00, 0x00, 0x01 };\n                        ff_vdpau_add_data_chunk(s, start_code,\n                                                sizeof(start_code));\n                        ff_vdpau_add_data_chunk(s, &buf[buf_index - consumed],\n                                                consumed);\n                    } else\n                        context_count++;\n                }\n                break;\n            case NAL_DPA:\n                init_get_bits(&hx->s.gb, ptr, bit_length);\n                hx->intra_gb_ptr =\n                hx->inter_gb_ptr = NULL;\n                if ((err = decode_slice_header(hx, h)) < 0)\n                    break;\n                hx->s.data_partitioning = 1;\n                break;\n            case NAL_DPB:\n                init_get_bits(&hx->intra_gb, ptr, bit_length);\n                hx->intra_gb_ptr = &hx->intra_gb;\n                break;\n            case NAL_DPC:\n                init_get_bits(&hx->inter_gb, ptr, bit_length);\n                hx->inter_gb_ptr = &hx->inter_gb;\n                if (hx->redundant_pic_count == 0 &&\n                    hx->intra_gb_ptr &&\n                    hx->s.data_partitioning &&\n                    s->current_picture_ptr &&\n                    s->context_initialized &&\n                    (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc) &&\n                    (avctx->skip_frame < AVDISCARD_BIDIR  ||\n                     hx->slice_type_nos != AV_PICTURE_TYPE_B) &&\n                    (avctx->skip_frame < AVDISCARD_NONKEY ||\n                     hx->slice_type_nos == AV_PICTURE_TYPE_I) &&\n                    avctx->skip_frame < AVDISCARD_ALL)\n                    context_count++;\n                break;\n            case NAL_SEI:\n                init_get_bits(&s->gb, ptr, bit_length);\n                ff_h264_decode_sei(h);\n                break;\n            case NAL_SPS:\n                init_get_bits(&s->gb, ptr, bit_length);\n                if (ff_h264_decode_seq_parameter_set(h) < 0 &&\n                    h->is_avc && (nalsize != consumed) && nalsize) {\n                    av_log(h->s.avctx, AV_LOG_DEBUG,\n                           "SPS decoding failure, trying again with the complete NAL\\n");\n                    init_get_bits(&s->gb, buf + buf_index + 1 - consumed,\n                                  8 * (nalsize - 1));\n                    ff_h264_decode_seq_parameter_set(h);\n                }\n                if (h264_set_parameter_from_sps(h) < 0) {\n                    buf_index = -1;\n                    goto end;\n                }\n                break;\n            case NAL_PPS:\n                init_get_bits(&s->gb, ptr, bit_length);\n                ff_h264_decode_picture_parameter_set(h, bit_length);\n                break;\n            case NAL_AUD:\n            case NAL_END_SEQUENCE:\n            case NAL_END_STREAM:\n            case NAL_FILLER_DATA:\n            case NAL_SPS_EXT:\n            case NAL_AUXILIARY_SLICE:\n                break;\n            case NAL_FF_IGNORE:\n                break;\n            default:\n                av_log(avctx, AV_LOG_DEBUG, "Unknown NAL code: %d (%d bits)\\n",\n                       hx->nal_unit_type, bit_length);\n            }\n            if (context_count == h->max_contexts) {\n                execute_decode_slices(h, context_count);\n                context_count = 0;\n            }\n            if (err < 0)\n                av_log(h->s.avctx, AV_LOG_ERROR, "decode_slice_header error\\n");\n            else if (err == 1) {\n                h->nal_unit_type = hx->nal_unit_type;\n                h->nal_ref_idc   = hx->nal_ref_idc;\n                hx               = h;\n                goto again;\n            }\n        }\n    }\n    if (context_count)\n        execute_decode_slices(h, context_count);\nend:\n    if (s->current_picture_ptr && s->current_picture_ptr->owner2 == s &&\n        !s->droppable) {\n        ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX,\n                                  s->picture_structure == PICT_BOTTOM_FIELD);\n    }\n    return buf_index;\n}', 'static int field_end(H264Context *h, int in_setup)\n{\n    MpegEncContext *const s     = &h->s;\n    AVCodecContext *const avctx = s->avctx;\n    int err = 0;\n    s->mb_y = 0;\n    if (!in_setup && !s->droppable)\n        ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX,\n                                  s->picture_structure == PICT_BOTTOM_FIELD);\n    if (CONFIG_H264_VDPAU_DECODER &&\n        s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)\n        ff_vdpau_h264_set_reference_frames(s);\n    if (in_setup || !(avctx->active_thread_type & FF_THREAD_FRAME)) {\n        if (!s->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        h->outputed_poc          = h->next_outputed_poc;\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_H264_VDPAU_DECODER &&\n        s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)\n        ff_vdpau_h264_picture_complete(s);\n    if (!FIELD_PICTURE)\n        ff_er_frame_end(s);\n    ff_MPV_frame_end(s);\n    h->current_slice = 0;\n    return err;\n}', 'void ff_er_frame_end(MpegEncContext *s)\n{\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    int size = s->b8_stride * 2 * s->mb_height;\n    Picture *pic = s->current_picture_ptr;\n    if (!s->err_recognition || s->error_count == 0                     ||\n        s->avctx->hwaccel                                              ||\n        s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU          ||\n        s->picture_structure != PICT_FRAME                             ||\n        s->error_count == 3 * s->mb_width *\n                          (s->avctx->skip_top + s->avctx->skip_bottom)) {\n        return;\n    };\n    if (s->current_picture.f.motion_val[0] == NULL) {\n        av_log(s->avctx, AV_LOG_ERROR, "Warning MVs not available\\n");\n        for (i = 0; i < 2; i++) {\n            pic->f.ref_index[i]     = av_mallocz(s->mb_stride * s->mb_height * 4 * sizeof(uint8_t));\n            pic->motion_val_base[i] = av_mallocz((size + 4) * 2 * sizeof(uint16_t));\n            pic->f.motion_val[i]    = pic->motion_val_base[i] + 4;\n        }\n        pic->f.motion_subsample_log2 = 3;\n        s->current_picture = *s->current_picture_ptr;\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->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[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->current_picture.f.mb_type[mb_xy] = MB_TYPE_INTRA4x4;\n        else\n            s->current_picture.f.mb_type[mb_xy] = MB_TYPE_16x16 | MB_TYPE_L0;\n    }\n    if (!s->last_picture.f.data[0] && !s->next_picture.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->current_picture.f.mb_type[mb_xy]))\n                s->current_picture.f.mb_type[mb_xy] = MB_TYPE_INTRA4x4;\n        }\n    for (mb_y = 0; mb_y < s->mb_height; mb_y++) {\n        s->mb_x = 0;\n        s->mb_y = mb_y;\n        ff_init_block_index(s);\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->current_picture.f.mb_type[mb_xy];\n            int dir           = !s->last_picture.f.data[0];\n            ff_update_block_index(s);\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            s->mv_dir     = dir ? MV_DIR_BACKWARD : MV_DIR_FORWARD;\n            s->mb_intra   = 0;\n            s->mb_skipped = 0;\n            if (IS_8X8(mb_type)) {\n                int mb_index = mb_x * 2 + mb_y * 2 * s->b8_stride;\n                int j;\n                s->mv_type = MV_TYPE_8X8;\n                for (j = 0; j < 4; j++) {\n                    s->mv[0][j][0] = s->current_picture.f.motion_val[dir][mb_index + (j & 1) + (j >> 1) * s->b8_stride][0];\n                    s->mv[0][j][1] = s->current_picture.f.motion_val[dir][mb_index + (j & 1) + (j >> 1) * s->b8_stride][1];\n                }\n            } else {\n                s->mv_type     = MV_TYPE_16X16;\n                s->mv[0][0][0] = s->current_picture.f.motion_val[dir][mb_x * 2 + mb_y * 2 * s->b8_stride][0];\n                s->mv[0][0][1] = s->current_picture.f.motion_val[dir][mb_x * 2 + mb_y * 2 * s->b8_stride][1];\n            }\n            s->dsp.clear_blocks(s->block[0]);\n            s->mb_x = mb_x;\n            s->mb_y = mb_y;\n            decode_mb(s, 0  );\n        }\n    }\n    if (s->pict_type == AV_PICTURE_TYPE_B) {\n        for (mb_y = 0; mb_y < s->mb_height; mb_y++) {\n            s->mb_x = 0;\n            s->mb_y = mb_y;\n            ff_init_block_index(s);\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->current_picture.f.mb_type[mb_xy];\n                ff_update_block_index(s);\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                s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD;\n                if (!s->last_picture.f.data[0])\n                    s->mv_dir &= ~MV_DIR_FORWARD;\n                if (!s->next_picture.f.data[0])\n                    s->mv_dir &= ~MV_DIR_BACKWARD;\n                s->mb_intra   = 0;\n                s->mv_type    = MV_TYPE_16X16;\n                s->mb_skipped = 0;\n                if (s->pp_time) {\n                    int time_pp = s->pp_time;\n                    int time_pb = s->pb_time;\n                    if (s->avctx->codec_id == AV_CODEC_ID_H264) {\n                    } else {\n                        ff_thread_await_progress(&s->next_picture_ptr->f, mb_y, 0);\n                    }\n                    s->mv[0][0][0] = s->next_picture.f.motion_val[0][xy][0] *  time_pb            / time_pp;\n                    s->mv[0][0][1] = s->next_picture.f.motion_val[0][xy][1] *  time_pb            / time_pp;\n                    s->mv[1][0][0] = s->next_picture.f.motion_val[0][xy][0] * (time_pb - time_pp) / time_pp;\n                    s->mv[1][0][1] = s->next_picture.f.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->dsp.clear_blocks(s->block[0]);\n                s->mb_x = mb_x;\n                s->mb_y = mb_y;\n                decode_mb(s, 0);\n            }\n        }\n    } else\n        guess_mv(s);\n    if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration)\n        goto ec_clean;\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->current_picture.f.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->current_picture.f.data[0] + mb_x * 16 + mb_y * 16 * s->linesize;\n            dest_cb = s->current_picture.f.data[1] + mb_x *  8 + mb_y *  8 * s->uvlinesize;\n            dest_cr = s->current_picture.f.data[2] + mb_x *  8 + mb_y *  8 * s->uvlinesize;\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) * s->linesize];\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 * s->uvlinesize];\n                    dcv += dest_cr[x + y * s->uvlinesize];\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->current_picture.f.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->current_picture.f.data[0] + mb_x * 16 + mb_y * 16 * s->linesize;\n            dest_cb = s->current_picture.f.data[1] + mb_x *  8 + mb_y *  8 * s->uvlinesize;\n            dest_cr = s->current_picture.f.data[2] + mb_x *  8 + mb_y *  8 * s->uvlinesize;\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->current_picture.f.data[0], s->mb_width * 2,\n                       s->mb_height * 2, s->linesize, 1);\n        h_block_filter(s, s->current_picture.f.data[1], s->mb_width,\n                       s->mb_height  , s->uvlinesize, 0);\n        h_block_filter(s, s->current_picture.f.data[2], s->mb_width,\n                       s->mb_height  , s->uvlinesize, 0);\n        v_block_filter(s, s->current_picture.f.data[0], s->mb_width * 2,\n                       s->mb_height * 2, s->linesize, 1);\n        v_block_filter(s, s->current_picture.f.data[1], s->mb_width,\n                       s->mb_height  , s->uvlinesize, 0);\n        v_block_filter(s, s->current_picture.f.data[2], s->mb_width,\n                       s->mb_height  , s->uvlinesize, 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->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        s->mbintra_table[mb_xy] = 1;\n    }\n}', 'static int is_intra_more_likely(MpegEncContext *s)\n{\n    int is_intra_likely, i, j, undamaged_count, skip_amount, mb_x, mb_y;\n    if (!s->last_picture_ptr || !s->last_picture_ptr->f.data[0])\n        return 1;\n    undamaged_count = 0;\n    for (i = 0; i < s->mb_num; i++) {\n        const int mb_xy = s->mb_index2xy[i];\n        const int error = s->error_status_table[mb_xy];\n        if (!((error & ER_DC_ERROR) && (error & ER_MV_ERROR)))\n            undamaged_count++;\n    }\n    if (s->codec_id == AV_CODEC_ID_H264) {\n        H264Context *h = (void*) s;\n        if (h->list_count <= 0 || h->ref_count[0] <= 0 ||\n            !h->ref_list[0][0].f.data[0])\n            return 1;\n    }\n    if (undamaged_count < 5)\n        return 0;\n    if (CONFIG_MPEG_XVMC_DECODER    &&\n        s->avctx->xvmc_acceleration &&\n        s->pict_type == AV_PICTURE_TYPE_I)\n        return 1;\n    skip_amount     = FFMAX(undamaged_count / 50, 1);\n    is_intra_likely = 0;\n    j = 0;\n    for (mb_y = 0; mb_y < s->mb_height - 1; mb_y++) {\n        for (mb_x = 0; mb_x < s->mb_width; mb_x++) {\n            int error;\n            const int mb_xy = mb_x + mb_y * s->mb_stride;\n            error = s->error_status_table[mb_xy];\n            if ((error & ER_DC_ERROR) && (error & ER_MV_ERROR))\n                continue;\n            j++;\n            if ((j % skip_amount) != 0)\n                continue;\n            if (s->pict_type == AV_PICTURE_TYPE_I) {\n                uint8_t *mb_ptr      = s->current_picture.f.data[0] +\n                                       mb_x * 16 + mb_y * 16 * s->linesize;\n                uint8_t *last_mb_ptr = s->last_picture.f.data[0] +\n                                       mb_x * 16 + mb_y * 16 * s->linesize;\n                if (s->avctx->codec_id == AV_CODEC_ID_H264) {\n                } else {\n                    ff_thread_await_progress(&s->last_picture_ptr->f,\n                                             mb_y, 0);\n                }\n                is_intra_likely += s->dsp.sad[0](NULL, last_mb_ptr, mb_ptr,\n                                                 s->linesize, 16);\n                is_intra_likely -= s->dsp.sad[0](NULL, last_mb_ptr,\n                                                 last_mb_ptr + s->linesize * 16,\n                                                 s->linesize, 16);\n            } else {\n                if (IS_INTRA(s->current_picture.f.mb_type[mb_xy]))\n                   is_intra_likely++;\n                else\n                   is_intra_likely--;\n            }\n        }\n    }\n    return is_intra_likely > 0;\n}', 'static void decode_mb(MpegEncContext *s, int ref)\n{\n    s->dest[0] = s->current_picture.f.data[0] + (s->mb_y *  16                       * s->linesize)   + s->mb_x *  16;\n    s->dest[1] = s->current_picture.f.data[1] + (s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16 >> s->chroma_x_shift);\n    s->dest[2] = s->current_picture.f.data[2] + (s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16 >> s->chroma_x_shift);\n    if (CONFIG_H264_DECODER && s->codec_id == AV_CODEC_ID_H264) {\n        H264Context *h = (void*)s;\n        h->mb_xy = s->mb_x + s->mb_y * s->mb_stride;\n        memset(h->non_zero_count_cache, 0, sizeof(h->non_zero_count_cache));\n        assert(ref >= 0);\n        if (ref >= h->ref_count[0])\n            ref = 0;\n        fill_rectangle(&s->current_picture.f.ref_index[0][4 * h->mb_xy],\n                       2, 2, 2, ref, 1);\n        fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1);\n        fill_rectangle(h->mv_cache[0][scan8[0]], 4, 4, 8,\n                       pack16to32(s->mv[0][0][0], s->mv[0][0][1]), 4);\n        assert(!FRAME_MBAFF);\n        ff_h264_hl_decode_mb(h);\n    } else {\n        assert(ref == 0);\n        ff_MPV_decode_mb(s, s->block);\n    }\n}', 'void ff_h264_hl_decode_mb(H264Context *h)\n{\n    MpegEncContext *const s = &h->s;\n    const int mb_xy   = h->mb_xy;\n    const int mb_type = s->current_picture.f.mb_type[mb_xy];\n    int is_complex    = CONFIG_SMALL || h->is_complex || IS_INTRA_PCM(mb_type) || s->qscale == 0;\n    if (CHROMA444) {\n        if (is_complex || h->pixel_shift)\n            hl_decode_mb_444_complex(h);\n        else\n            hl_decode_mb_444_simple_8(h);\n    } else if (is_complex) {\n        hl_decode_mb_complex(h);\n    } else if (h->pixel_shift) {\n        hl_decode_mb_simple_16(h);\n    } else\n        hl_decode_mb_simple_8(h);\n}', 'static av_noinline void FUNC(hl_decode_mb_444)(H264Context *h)\n{\n    MpegEncContext *const s = &h->s;\n    const int mb_x    = s->mb_x;\n    const int mb_y    = s->mb_y;\n    const int mb_xy   = h->mb_xy;\n    const int mb_type = s->current_picture.f.mb_type[mb_xy];\n    uint8_t *dest[3];\n    int linesize;\n    int i, j, p;\n    int *block_offset = &h->block_offset[0];\n    const int transform_bypass = !SIMPLE && (s->qscale == 0 && h->sps.transform_bypass);\n    const int plane_count      = (SIMPLE || !CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) ? 3 : 1;\n    for (p = 0; p < plane_count; p++) {\n        dest[p] = s->current_picture.f.data[p] +\n                  ((mb_x << PIXEL_SHIFT) + mb_y * s->linesize) * 16;\n        s->dsp.prefetch(dest[p] + (s->mb_x & 3) * 4 * s->linesize + (64 << PIXEL_SHIFT),\n                        s->linesize, 4);\n    }\n    h->list_counts[mb_xy] = h->list_count;\n    if (!SIMPLE && MB_FIELD) {\n        linesize     = h->mb_linesize = h->mb_uvlinesize = s->linesize * 2;\n        block_offset = &h->block_offset[48];\n        if (mb_y & 1)\n            for (p = 0; p < 3; p++)\n                dest[p] -= s->linesize * 15;\n        if (FRAME_MBAFF) {\n            int list;\n            for (list = 0; list < h->list_count; list++) {\n                if (!USES_LIST(mb_type, list))\n                    continue;\n                if (IS_16X16(mb_type)) {\n                    int8_t *ref = &h->ref_cache[list][scan8[0]];\n                    fill_rectangle(ref, 4, 4, 8, (16 + *ref) ^ (s->mb_y & 1), 1);\n                } else {\n                    for (i = 0; i < 16; i += 4) {\n                        int ref = h->ref_cache[list][scan8[i]];\n                        if (ref >= 0)\n                            fill_rectangle(&h->ref_cache[list][scan8[i]], 2, 2,\n                                           8, (16 + ref) ^ (s->mb_y & 1), 1);\n                    }\n                }\n            }\n        }\n    } else {\n        linesize = h->mb_linesize = h->mb_uvlinesize = s->linesize;\n    }\n    if (!SIMPLE && IS_INTRA_PCM(mb_type)) {\n        if (PIXEL_SHIFT) {\n            const int bit_depth = h->sps.bit_depth_luma;\n            GetBitContext gb;\n            init_get_bits(&gb, (uint8_t *)h->mb, 768 * bit_depth);\n            for (p = 0; p < plane_count; p++)\n                for (i = 0; i < 16; i++) {\n                    uint16_t *tmp = (uint16_t *)(dest[p] + i * linesize);\n                    for (j = 0; j < 16; j++)\n                        tmp[j] = get_bits(&gb, bit_depth);\n                }\n        } else {\n            for (p = 0; p < plane_count; p++)\n                for (i = 0; i < 16; i++)\n                    memcpy(dest[p] + i * linesize,\n                           (uint8_t *)h->mb + p * 256 + i * 16, 16);\n        }\n    } else {\n        if (IS_INTRA(mb_type)) {\n            if (h->deblocking_filter)\n                xchg_mb_border(h, dest[0], dest[1], dest[2], linesize,\n                               linesize, 1, 1, SIMPLE, PIXEL_SHIFT);\n            for (p = 0; p < plane_count; p++)\n                hl_decode_mb_predict_luma(h, mb_type, 1, SIMPLE,\n                                          transform_bypass, PIXEL_SHIFT,\n                                          block_offset, linesize, dest[p], p);\n            if (h->deblocking_filter)\n                xchg_mb_border(h, dest[0], dest[1], dest[2], linesize,\n                               linesize, 0, 1, SIMPLE, PIXEL_SHIFT);\n        } else {\n            FUNC(hl_motion_444)(h, dest[0], dest[1], dest[2],\n                      s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab,\n                      s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab,\n                      h->h264dsp.weight_h264_pixels_tab,\n                      h->h264dsp.biweight_h264_pixels_tab);\n        }\n        for (p = 0; p < plane_count; p++)\n            hl_decode_mb_idct_luma(h, mb_type, 1, SIMPLE, transform_bypass,\n                                   PIXEL_SHIFT, block_offset, linesize,\n                                   dest[p], p);\n    }\n    if (h->cbp || IS_INTRA(mb_type)) {\n        s->dsp.clear_blocks(h->mb);\n        s->dsp.clear_blocks(h->mb + (24 * 16 << PIXEL_SHIFT));\n    }\n}', 'static void MCFUNC(hl_motion)(H264Context *h, uint8_t *dest_y,\n                              uint8_t *dest_cb, uint8_t *dest_cr,\n                              qpel_mc_func(*qpix_put)[16],\n                              h264_chroma_mc_func(*chroma_put),\n                              qpel_mc_func(*qpix_avg)[16],\n                              h264_chroma_mc_func(*chroma_avg),\n                              h264_weight_func *weight_op,\n                              h264_biweight_func *weight_avg)\n{\n    MpegEncContext *const s = &h->s;\n    const int mb_xy   = h->mb_xy;\n    const int mb_type = s->current_picture.f.mb_type[mb_xy];\n    assert(IS_INTER(mb_type));\n    if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))\n        await_references(h);\n    prefetch_motion(h, 0, PIXEL_SHIFT, CHROMA_IDC);\n    if (IS_16X16(mb_type)) {\n        mc_part(h, 0, 1, 16, 0, dest_y, dest_cb, dest_cr, 0, 0,\n                qpix_put[0], chroma_put[0], qpix_avg[0], chroma_avg[0],\n                weight_op, weight_avg,\n                IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1));\n    } else if (IS_16X8(mb_type)) {\n        mc_part(h, 0, 0, 8, 8 << PIXEL_SHIFT, dest_y, dest_cb, dest_cr, 0, 0,\n                qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],\n                weight_op, weight_avg,\n                IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1));\n        mc_part(h, 8, 0, 8, 8 << PIXEL_SHIFT, dest_y, dest_cb, dest_cr, 0, 4,\n                qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],\n                weight_op, weight_avg,\n                IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1));\n    } else if (IS_8X16(mb_type)) {\n        mc_part(h, 0, 0, 16, 8 * h->mb_linesize, dest_y, dest_cb, dest_cr, 0, 0,\n                qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],\n                &weight_op[1], &weight_avg[1],\n                IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1));\n        mc_part(h, 4, 0, 16, 8 * h->mb_linesize, dest_y, dest_cb, dest_cr, 4, 0,\n                qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],\n                &weight_op[1], &weight_avg[1],\n                IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1));\n    } else {\n        int i;\n        assert(IS_8X8(mb_type));\n        for (i = 0; i < 4; i++) {\n            const int sub_mb_type = h->sub_mb_type[i];\n            const int n  = 4 * i;\n            int x_offset = (i & 1) << 2;\n            int y_offset = (i & 2) << 1;\n            if (IS_SUB_8X8(sub_mb_type)) {\n                mc_part(h, n, 1, 8, 0, dest_y, dest_cb, dest_cr,\n                        x_offset, y_offset,\n                        qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],\n                        &weight_op[1], &weight_avg[1],\n                        IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));\n            } else if (IS_SUB_8X4(sub_mb_type)) {\n                mc_part(h, n, 0, 4, 4 << PIXEL_SHIFT, dest_y, dest_cb, dest_cr,\n                        x_offset, y_offset,\n                        qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],\n                        &weight_op[1], &weight_avg[1],\n                        IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));\n                mc_part(h, n + 2, 0, 4, 4 << PIXEL_SHIFT,\n                        dest_y, dest_cb, dest_cr, x_offset, y_offset + 2,\n                        qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],\n                        &weight_op[1], &weight_avg[1],\n                        IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));\n            } else if (IS_SUB_4X8(sub_mb_type)) {\n                mc_part(h, n, 0, 8, 4 * h->mb_linesize,\n                        dest_y, dest_cb, dest_cr, x_offset, y_offset,\n                        qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],\n                        &weight_op[2], &weight_avg[2],\n                        IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));\n                mc_part(h, n + 1, 0, 8, 4 * h->mb_linesize,\n                        dest_y, dest_cb, dest_cr, x_offset + 2, y_offset,\n                        qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],\n                        &weight_op[2], &weight_avg[2],\n                        IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));\n            } else {\n                int j;\n                assert(IS_SUB_4X4(sub_mb_type));\n                for (j = 0; j < 4; j++) {\n                    int sub_x_offset = x_offset + 2 * (j & 1);\n                    int sub_y_offset = y_offset + (j & 2);\n                    mc_part(h, n + j, 1, 4, 0,\n                            dest_y, dest_cb, dest_cr, sub_x_offset, sub_y_offset,\n                            qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],\n                            &weight_op[2], &weight_avg[2],\n                            IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));\n                }\n            }\n        }\n    }\n    prefetch_motion(h, 1, PIXEL_SHIFT, CHROMA_IDC);\n}', 'static void await_references(H264Context *h)\n{\n    MpegEncContext *const s = &h->s;\n    const int mb_xy   = h->mb_xy;\n    const int mb_type = s->current_picture.f.mb_type[mb_xy];\n    int refs[2][48];\n    int nrefs[2] = { 0 };\n    int ref, list;\n    memset(refs, -1, sizeof(refs));\n    if (IS_16X16(mb_type)) {\n        get_lowest_part_y(h, refs, 0, 16, 0,\n                          IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);\n    } else if (IS_16X8(mb_type)) {\n        get_lowest_part_y(h, refs, 0, 8, 0,\n                          IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);\n        get_lowest_part_y(h, refs, 8, 8, 8,\n                          IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs);\n    } else if (IS_8X16(mb_type)) {\n        get_lowest_part_y(h, refs, 0, 16, 0,\n                          IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);\n        get_lowest_part_y(h, refs, 4, 16, 0,\n                          IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs);\n    } else {\n        int i;\n        assert(IS_8X8(mb_type));\n        for (i = 0; i < 4; i++) {\n            const int sub_mb_type = h->sub_mb_type[i];\n            const int n           = 4 * i;\n            int y_offset          = (i & 2) << 2;\n            if (IS_SUB_8X8(sub_mb_type)) {\n                get_lowest_part_y(h, refs, n, 8, y_offset,\n                                  IS_DIR(sub_mb_type, 0, 0),\n                                  IS_DIR(sub_mb_type, 0, 1),\n                                  nrefs);\n            } else if (IS_SUB_8X4(sub_mb_type)) {\n                get_lowest_part_y(h, refs, n, 4, y_offset,\n                                  IS_DIR(sub_mb_type, 0, 0),\n                                  IS_DIR(sub_mb_type, 0, 1),\n                                  nrefs);\n                get_lowest_part_y(h, refs, n + 2, 4, y_offset + 4,\n                                  IS_DIR(sub_mb_type, 0, 0),\n                                  IS_DIR(sub_mb_type, 0, 1),\n                                  nrefs);\n            } else if (IS_SUB_4X8(sub_mb_type)) {\n                get_lowest_part_y(h, refs, n, 8, y_offset,\n                                  IS_DIR(sub_mb_type, 0, 0),\n                                  IS_DIR(sub_mb_type, 0, 1),\n                                  nrefs);\n                get_lowest_part_y(h, refs, n + 1, 8, y_offset,\n                                  IS_DIR(sub_mb_type, 0, 0),\n                                  IS_DIR(sub_mb_type, 0, 1),\n                                  nrefs);\n            } else {\n                int j;\n                assert(IS_SUB_4X4(sub_mb_type));\n                for (j = 0; j < 4; j++) {\n                    int sub_y_offset = y_offset + 2 * (j & 2);\n                    get_lowest_part_y(h, refs, n + j, 4, sub_y_offset,\n                                      IS_DIR(sub_mb_type, 0, 0),\n                                      IS_DIR(sub_mb_type, 0, 1),\n                                      nrefs);\n                }\n            }\n        }\n    }\n    for (list = h->list_count - 1; list >= 0; list--)\n        for (ref = 0; ref < 48 && nrefs[list]; ref++) {\n            int row = refs[list][ref];\n            if (row >= 0) {\n                Picture *ref_pic      = &h->ref_list[list][ref];\n                int ref_field         = ref_pic->f.reference - 1;\n                int ref_field_picture = ref_pic->field_picture;\n                int pic_height        = 16 * s->mb_height >> ref_field_picture;\n                row <<= MB_MBAFF;\n                nrefs[list]--;\n                if (!FIELD_PICTURE && ref_field_picture) {\n                    ff_thread_await_progress(&ref_pic->f,\n                                             FFMIN((row >> 1) - !(row & 1),\n                                                   pic_height - 1),\n                                             1);\n                    ff_thread_await_progress(&ref_pic->f,\n                                             FFMIN((row >> 1), pic_height - 1),\n                                             0);\n                } else if (FIELD_PICTURE && !ref_field_picture) {\n                    ff_thread_await_progress(&ref_pic->f,\n                                             FFMIN(row * 2 + ref_field,\n                                                   pic_height - 1),\n                                             0);\n                } else if (FIELD_PICTURE) {\n                    ff_thread_await_progress(&ref_pic->f,\n                                             FFMIN(row, pic_height - 1),\n                                             ref_field);\n                } else {\n                    ff_thread_await_progress(&ref_pic->f,\n                                             FFMIN(row, pic_height - 1),\n                                             0);\n                }\n            }\n        }\n}']