libavcodec/h264dec.c:571: error: Integer Overflow L2
  ([0, max(2, `h->slice_ctx->list_count`)] - 1):unsigned32 by call to `ff_h264_execute_decode_slices`.

libavcodec/h264dec.c:515:1: Parameter `h->slice_ctx->list_count`
513. }
514. 
515. static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size)
     ^
516. {
517.     AVCodecContext *const avctx = h->avctx;

libavcodec/h264dec.c:556:24: Call
554.             idr(h); // FIXME ensure we don't lose some frames if there is reordering
555.         case H264_NAL_SLICE:
556.             if ((err = ff_h264_queue_decode_slice(h, nal)))
                            ^
557.                 break;
558. 

libavcodec/h264_slice.c:1852:1: Parameter `h->slice_ctx->list_count`
  1850. }
  1851. 
  1852. int ff_h264_queue_decode_slice(H264Context *h, const H2645NAL *nal)
        ^
  1853. {
  1854.     H264SliceContext *sl = h->slice_ctx + h->nb_slice_ctx_queued;

libavcodec/h264_slice.c:1859:11: Call
  1857.     sl->gb = nal->gb;
  1858. 
  1859.     ret = h264_slice_header_parse(sl, nal, &h->ps, h->avctx);
                  ^
  1860.     if (ret < 0)
  1861.         return ret;

libavcodec/h264_slice.c:1509:1: Parameter `sl->list_count`
    1507. }
    1508. 
    1509. static int h264_slice_header_parse(H264SliceContext *sl, const H2645NAL *nal,
          ^
    1510.                                    const H264ParamSets *ps, AVCodecContext *avctx)
    1511. {

libavcodec/h264dec.c:571:27: Call
569.                     h->nb_slice_ctx_queued = 0;
570.                 } else
571.                     ret = ff_h264_execute_decode_slices(h);
                               ^
572.                 if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
573.                     goto end;

libavcodec/h264_slice.c:2488:1: Parameter `h->slice_ctx->list_count`
  2486.  * @param h h264 master context
  2487.  */
  2488. int ff_h264_execute_decode_slices(H264Context *h)
        ^
  2489. {
  2490.     AVCodecContext *const avctx = h->avctx;

libavcodec/h264_slice.c:2503:15: Call
  2501.         h->postpone_filter = 0;
  2502. 
  2503.         ret = decode_slice(avctx, &h->slice_ctx[0]);
                      ^
  2504.         h->mb_y = h->slice_ctx[0].mb_y;
  2505.         if (ret < 0)

libavcodec/h264_slice.c:2294:1: Parameter `arg->list_count`
    2292. }
    2293. 
    2294. static int decode_slice(struct AVCodecContext *avctx, void *arg)
          ^
    2295. {
    2296.     H264SliceContext *sl = arg;

libavcodec/h264_slice.c:2338:19: Call
    2336.             }
    2337. 
    2338.             ret = ff_h264_decode_mb_cabac(h, sl);
                            ^
    2339.             // STOP_TIMER("decode_mb_cabac")
    2340. 

libavcodec/h264_cabac.c:1908:1: Parameter `sl->list_count`
      1906.  * @return 0 if OK, ER_AC_ERROR / ER_DC_ERROR / ER_MV_ERROR if an error is noticed
      1907.  */
      1908. int ff_h264_decode_mb_cabac(const H264Context *h, H264SliceContext *sl)
            ^
      1909. {
      1910.     const SPS *sps = h->ps.sps;

libavcodec/h264_slice.c:2342:17: Call
    2340. 
    2341.             if (ret >= 0)
    2342.                 ff_h264_hl_decode_mb(h, sl);
                          ^
    2343. 
    2344.             // FIXME optimal? or let mb_decode decode 16x32 ?

libavcodec/h264_mb.c:793:1: Parameter `sl->list_count`
      791. #include "h264_mb_template.c"
      792. 
      793. void ff_h264_hl_decode_mb(const H264Context *h, H264SliceContext *sl)
           ^
      794. {
      795.     const int mb_xy   = sl->mb_xy;

libavcodec/h264_mb.c:802:13: Call
      800.     if (CHROMA444(h)) {
      801.         if (is_complex || h->pixel_shift)
      802.             hl_decode_mb_444_complex(h, sl);
                       ^
      803.         else
      804.             hl_decode_mb_444_simple_8(h, sl);

libavcodec/h264_mb_template.c:259:1: Parameter `sl->list_count`
        257. #include "h264_mc_template.c"
        258. 
        259. static av_noinline void FUNC(hl_decode_mb_444)(const H264Context *h, H264SliceContext *sl)
             ^
        260. {
        261.     const int mb_x    = sl->mb_x;

libavcodec/h264_mb_template.c:342:13: Call
        340.                                linesize, 0, 1, SIMPLE, PIXEL_SHIFT);
        341.         } else {
        342.             FUNC(hl_motion_444)(h, sl, dest[0], dest[1], dest[2],
                         ^
        343.                       h->h264qpel.put_h264_qpel_pixels_tab,
        344.                       h->h264chroma.put_h264_chroma_pixels_tab,

libavcodec/h264_mc_template.c:64:1: Parameter `sl->list_count`
          62. }
          63. 
          64. static void MCFUNC(hl_motion)(const H264Context *h, H264SliceContext *sl,
              ^
          65.                               uint8_t *dest_y,
          66.                               uint8_t *dest_cb, uint8_t *dest_cr,

libavcodec/h264_mc_template.c:80:9: Call
          78. 
          79.     if (HAVE_THREADS && (h->avctx->active_thread_type & FF_THREAD_FRAME))
          80.         await_references(h, sl);
                      ^
          81.     prefetch_motion(h, sl, 0, PIXEL_SHIFT, CHROMA_IDC);
          82. 

libavcodec/h264_mb.c:96:1: <LHS trace>
94.  * @param h the H.264 context
95.  */
96. static void await_references(const H264Context *h, H264SliceContext *sl)
    ^
97. {
98.     const int mb_xy   = sl->mb_xy;

libavcodec/h264_mb.c:96:1: Parameter `sl->list_count`
            94.  * @param h the H.264 context
            95.  */
            96. static void await_references(const H264Context *h, H264SliceContext *sl)
                ^
            97. {
            98.     const int mb_xy   = sl->mb_xy;

libavcodec/h264_mb.c:166:10: Binary operation: ([0, max(2, h->slice_ctx->list_count)] - 1):unsigned32 by call to `ff_h264_execute_decode_slices` 
            164.     }
            165. 
            166.     for (list = sl->list_count - 1; list >= 0; list--)
                          ^
            167.         for (ref = 0; ref < 48 && nrefs[list]; ref++) {
            168.             int row = refs[list][ref];

static void await_references(const H264Context *h, H264SliceContext *sl)
{
    const int mb_xy   = sl->mb_xy;
    const int mb_type = h->cur_pic.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, sl, 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, sl, refs, 0, 8, 0,
                          IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);
        get_lowest_part_y(h, sl, 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, sl, refs, 0, 16, 0,
                          IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);
        get_lowest_part_y(h, sl, 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 = sl->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, sl, 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, sl, 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, sl, 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, sl, 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, sl, 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, sl, refs, n + j, 4, sub_y_offset,
                                      IS_DIR(sub_mb_type, 0, 0),
                                      IS_DIR(sub_mb_type, 0, 1),
                                      nrefs);
                }
            }
        }
    }
    for (list = sl->list_count - 1; list >= 0; list--)
        for (ref = 0; ref < 48 && nrefs[list]; ref++) {
            int row = refs[list][ref];
            if (row >= 0) {
                H264Ref *ref_pic  = &sl->ref_list[list][ref];
                int ref_field         = ref_pic->reference - 1;
                int ref_field_picture = ref_pic->parent->field_picture;
                int pic_height        = 16 * h->mb_height >> ref_field_picture;
                row <<= MB_MBAFF(sl);
                nrefs[list]--;
                if (!FIELD_PICTURE(h) && ref_field_picture) {
                    ff_thread_await_progress(&ref_pic->parent->tf,
                                             FFMIN((row >> 1) - !(row & 1),
                                                   pic_height - 1),
                                             1);
                    ff_thread_await_progress(&ref_pic->parent->tf,
                                             FFMIN((row >> 1), pic_height - 1),
                                             0);
                } else if (FIELD_PICTURE(h) && !ref_field_picture) {
                    ff_thread_await_progress(&ref_pic->parent->tf,
                                             FFMIN(row * 2 + ref_field,
                                                   pic_height - 1),
                                             0);
                } else if (FIELD_PICTURE(h)) {
                    ff_thread_await_progress(&ref_pic->parent->tf,
                                             FFMIN(row, pic_height - 1),
                                             ref_field);
                } else {
                    ff_thread_await_progress(&ref_pic->parent->tf,
                                             FFMIN(row, pic_height - 1),
                                             0);
                }
            }
        }
}
['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 && !h->setup_finished && h->cur_pic_ptr) {\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                    h->nb_slice_ctx_queued = 0;\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_h264_queue_decode_slice(H264Context *h, const H2645NAL *nal)\n{\n    H264SliceContext *sl = h->slice_ctx + h->nb_slice_ctx_queued;\n    int ret;\n    sl->gb = nal->gb;\n    ret = h264_slice_header_parse(sl, nal, &h->ps, h->avctx);\n    if (ret < 0)\n        return ret;\n    if (sl->redundant_pic_count > 0)\n        return 0;\n    if (!h->setup_finished) {\n        if (sl->first_mb_addr == 0) {\n            if (h->nb_slice_ctx_queued) {\n                H264SliceContext tmp_ctx;\n                ret = ff_h264_execute_decode_slices(h);\n                if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n                    return ret;\n                memcpy(&tmp_ctx, h->slice_ctx, sizeof(tmp_ctx));\n                memcpy(h->slice_ctx, sl, sizeof(tmp_ctx));\n                memcpy(sl, &tmp_ctx, sizeof(tmp_ctx));\n                sl = h->slice_ctx;\n            }\n            if (h->current_slice && h->cur_pic_ptr && FIELD_PICTURE(h)) {\n                ff_h264_field_end(h, sl, 1);\n            }\n            h->current_slice = 0;\n            if (!h->first_field) {\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                h->cur_pic_ptr = NULL;\n            }\n        }\n        if (h->current_slice == 0) {\n            ret = h264_field_start(h, sl, nal);\n            if (ret < 0)\n                return ret;\n        }\n    }\n    ret = h264_slice_init(h, sl, nal);\n    if (ret < 0)\n        return ret;\n    if ((h->avctx->skip_frame < AVDISCARD_NONREF || nal->ref_idc) &&\n        (h->avctx->skip_frame < AVDISCARD_BIDIR  ||\n         sl->slice_type_nos != AV_PICTURE_TYPE_B) &&\n        (h->avctx->skip_frame < AVDISCARD_NONKEY ||\n         h->cur_pic_ptr->f->key_frame) &&\n        h->avctx->skip_frame < AVDISCARD_ALL) {\n        h->nb_slice_ctx_queued++;\n    }\n    return 0;\n}', 'static int h264_slice_header_parse(H264SliceContext *sl, const H2645NAL *nal,\n                                   const H264ParamSets *ps, AVCodecContext *avctx)\n{\n    const SPS *sps;\n    const PPS *pps;\n    int ret;\n    unsigned int slice_type, tmp, i;\n    int field_pic_flag, bottom_field_flag, picture_structure;\n    sl->first_mb_addr = get_ue_golomb(&sl->gb);\n    slice_type = get_ue_golomb_31(&sl->gb);\n    if (slice_type > 9) {\n        av_log(avctx, AV_LOG_ERROR,\n               "slice type %d too large at %d\\n",\n               slice_type, sl->first_mb_addr);\n        return AVERROR_INVALIDDATA;\n    }\n    if (slice_type > 4) {\n        slice_type -= 5;\n        sl->slice_type_fixed = 1;\n    } else\n        sl->slice_type_fixed = 0;\n    slice_type         = ff_h264_golomb_to_pict_type[slice_type];\n    sl->slice_type     = slice_type;\n    sl->slice_type_nos = slice_type & 3;\n    if (nal->type  == H264_NAL_IDR_SLICE &&\n        sl->slice_type_nos != AV_PICTURE_TYPE_I) {\n        av_log(avctx, AV_LOG_ERROR, "A non-intra slice in an IDR NAL unit.\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    sl->pps_id = get_ue_golomb(&sl->gb);\n    if (sl->pps_id >= MAX_PPS_COUNT) {\n        av_log(avctx, AV_LOG_ERROR, "pps_id %u out of range\\n", sl->pps_id);\n        return AVERROR_INVALIDDATA;\n    }\n    if (!ps->pps_list[sl->pps_id]) {\n        av_log(avctx, AV_LOG_ERROR,\n               "non-existing PPS %u referenced\\n",\n               sl->pps_id);\n        return AVERROR_INVALIDDATA;\n    }\n    pps = (const PPS*)ps->pps_list[sl->pps_id]->data;\n    if (!ps->sps_list[pps->sps_id]) {\n        av_log(avctx, AV_LOG_ERROR,\n               "non-existing SPS %u referenced\\n", pps->sps_id);\n        return AVERROR_INVALIDDATA;\n    }\n    sps = (const SPS*)ps->sps_list[pps->sps_id]->data;\n    sl->frame_num = get_bits(&sl->gb, sps->log2_max_frame_num);\n    sl->mb_mbaff       = 0;\n    if (sps->frame_mbs_only_flag) {\n        picture_structure = PICT_FRAME;\n    } else {\n        field_pic_flag = get_bits1(&sl->gb);\n        if (field_pic_flag) {\n            bottom_field_flag = get_bits1(&sl->gb);\n            picture_structure = PICT_TOP_FIELD + bottom_field_flag;\n        } else {\n            picture_structure = PICT_FRAME;\n        }\n    }\n    sl->picture_structure      = picture_structure;\n    sl->mb_field_decoding_flag = picture_structure != PICT_FRAME;\n    if (picture_structure == PICT_FRAME) {\n        sl->curr_pic_num = sl->frame_num;\n        sl->max_pic_num  = 1 << sps->log2_max_frame_num;\n    } else {\n        sl->curr_pic_num = 2 * sl->frame_num + 1;\n        sl->max_pic_num  = 1 << (sps->log2_max_frame_num + 1);\n    }\n    if (nal->type == H264_NAL_IDR_SLICE)\n        get_ue_golomb(&sl->gb);\n    if (sps->poc_type == 0) {\n        sl->poc_lsb = get_bits(&sl->gb, sps->log2_max_poc_lsb);\n        if (pps->pic_order_present == 1 && picture_structure == PICT_FRAME)\n            sl->delta_poc_bottom = get_se_golomb(&sl->gb);\n    }\n    if (sps->poc_type == 1 && !sps->delta_pic_order_always_zero_flag) {\n        sl->delta_poc[0] = get_se_golomb(&sl->gb);\n        if (pps->pic_order_present == 1 && picture_structure == PICT_FRAME)\n            sl->delta_poc[1] = get_se_golomb(&sl->gb);\n    }\n    sl->redundant_pic_count = 0;\n    if (pps->redundant_pic_cnt_present)\n        sl->redundant_pic_count = get_ue_golomb(&sl->gb);\n    if (sl->slice_type_nos == AV_PICTURE_TYPE_B)\n        sl->direct_spatial_mv_pred = get_bits1(&sl->gb);\n    ret = ff_h264_parse_ref_count(&sl->list_count, sl->ref_count,\n                                  &sl->gb, pps, sl->slice_type_nos,\n                                  picture_structure);\n    if (ret < 0)\n        return ret;\n    if (sl->slice_type_nos != AV_PICTURE_TYPE_I) {\n       ret = ff_h264_decode_ref_pic_list_reordering(sl, avctx);\n       if (ret < 0) {\n           sl->ref_count[1] = sl->ref_count[0] = 0;\n           return ret;\n       }\n    }\n    sl->pwt.use_weight = 0;\n    for (i = 0; i < 2; i++) {\n        sl->pwt.luma_weight_flag[i]   = 0;\n        sl->pwt.chroma_weight_flag[i] = 0;\n    }\n    if ((pps->weighted_pred && sl->slice_type_nos == AV_PICTURE_TYPE_P) ||\n        (pps->weighted_bipred_idc == 1 &&\n         sl->slice_type_nos == AV_PICTURE_TYPE_B))\n        ff_h264_pred_weight_table(&sl->gb, sps, sl->ref_count,\n                                  sl->slice_type_nos, &sl->pwt);\n    sl->explicit_ref_marking = 0;\n    if (nal->ref_idc) {\n        ret = ff_h264_decode_ref_pic_marking(sl, &sl->gb, nal, avctx);\n        if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE))\n            return AVERROR_INVALIDDATA;\n    }\n    if (sl->slice_type_nos != AV_PICTURE_TYPE_I && pps->cabac) {\n        tmp = get_ue_golomb_31(&sl->gb);\n        if (tmp > 2) {\n            av_log(avctx, AV_LOG_ERROR, "cabac_init_idc %u overflow\\n", tmp);\n            return AVERROR_INVALIDDATA;\n        }\n        sl->cabac_init_idc = tmp;\n    }\n    sl->last_qscale_diff = 0;\n    tmp = pps->init_qp + get_se_golomb(&sl->gb);\n    if (tmp > 51 + 6 * (sps->bit_depth_luma - 8)) {\n        av_log(avctx, AV_LOG_ERROR, "QP %u out of range\\n", tmp);\n        return AVERROR_INVALIDDATA;\n    }\n    sl->qscale       = tmp;\n    sl->chroma_qp[0] = get_chroma_qp(pps, 0, sl->qscale);\n    sl->chroma_qp[1] = get_chroma_qp(pps, 1, sl->qscale);\n    if (sl->slice_type == AV_PICTURE_TYPE_SP)\n        get_bits1(&sl->gb);\n    if (sl->slice_type == AV_PICTURE_TYPE_SP ||\n        sl->slice_type == AV_PICTURE_TYPE_SI)\n        get_se_golomb(&sl->gb);\n    sl->deblocking_filter     = 1;\n    sl->slice_alpha_c0_offset = 0;\n    sl->slice_beta_offset     = 0;\n    if (pps->deblocking_filter_parameters_present) {\n        tmp = get_ue_golomb_31(&sl->gb);\n        if (tmp > 2) {\n            av_log(avctx, AV_LOG_ERROR,\n                   "deblocking_filter_idc %u out of range\\n", tmp);\n            return AVERROR_INVALIDDATA;\n        }\n        sl->deblocking_filter = tmp;\n        if (sl->deblocking_filter < 2)\n            sl->deblocking_filter ^= 1;\n        if (sl->deblocking_filter) {\n            sl->slice_alpha_c0_offset = get_se_golomb(&sl->gb) * 2;\n            sl->slice_beta_offset     = get_se_golomb(&sl->gb) * 2;\n            if (sl->slice_alpha_c0_offset >  12 ||\n                sl->slice_alpha_c0_offset < -12 ||\n                sl->slice_beta_offset >  12     ||\n                sl->slice_beta_offset < -12) {\n                av_log(avctx, AV_LOG_ERROR,\n                       "deblocking filter parameters %d %d out of range\\n",\n                       sl->slice_alpha_c0_offset, sl->slice_beta_offset);\n                return AVERROR_INVALIDDATA;\n            }\n        }\n    }\n    return 0;\n}', 'int ff_h264_execute_decode_slices(H264Context *h)\n{\n    AVCodecContext *const avctx = h->avctx;\n    H264SliceContext *sl;\n    int context_count = h->nb_slice_ctx_queued;\n    int ret = 0;\n    int i, j;\n    if (h->avctx->hwaccel || context_count < 1)\n        return 0;\n    if (context_count == 1) {\n        h->slice_ctx[0].next_slice_idx = h->mb_width * h->mb_height;\n        h->postpone_filter = 0;\n        ret = decode_slice(avctx, &h->slice_ctx[0]);\n        h->mb_y = h->slice_ctx[0].mb_y;\n        if (ret < 0)\n            goto finish;\n    } else {\n        for (i = 0; i < context_count; i++) {\n            int next_slice_idx = h->mb_width * h->mb_height;\n            int slice_idx;\n            sl                 = &h->slice_ctx[i];\n            sl->er.error_count = 0;\n            slice_idx = sl->mb_y * h->mb_width + sl->mb_x;\n            for (j = 0; j < context_count; j++) {\n                H264SliceContext *sl2 = &h->slice_ctx[j];\n                int        slice_idx2 = sl2->mb_y * h->mb_width + sl2->mb_x;\n                if (i == j || slice_idx2 < slice_idx)\n                    continue;\n                next_slice_idx = FFMIN(next_slice_idx, slice_idx2);\n            }\n            sl->next_slice_idx = next_slice_idx;\n        }\n        avctx->execute(avctx, decode_slice, h->slice_ctx,\n                       NULL, context_count, sizeof(h->slice_ctx[0]));\n        sl                   = &h->slice_ctx[context_count - 1];\n        h->mb_y              = sl->mb_y;\n        for (i = 1; i < context_count; i++)\n            h->slice_ctx[0].er.error_count += h->slice_ctx[i].er.error_count;\n        if (h->postpone_filter) {\n            h->postpone_filter = 0;\n            for (i = 0; i < context_count; i++) {\n                int y_end, x_end;\n                sl = &h->slice_ctx[i];\n                y_end = FFMIN(sl->mb_y + 1, h->mb_height);\n                x_end = (sl->mb_y >= h->mb_height) ? h->mb_width : sl->mb_x;\n                for (j = sl->resync_mb_y; j < y_end; j += 1 + FIELD_OR_MBAFF_PICTURE(h)) {\n                    sl->mb_y = j;\n                    loop_filter(h, sl, j > sl->resync_mb_y ? 0 : sl->resync_mb_x,\n                                j == y_end - 1 ? x_end : h->mb_width);\n                }\n            }\n        }\n    }\nfinish:\n    h->nb_slice_ctx_queued = 0;\n    return ret;\n}', 'static int decode_slice(struct AVCodecContext *avctx, void *arg)\n{\n    H264SliceContext *sl = arg;\n    const H264Context *h = sl->h264;\n    int lf_x_start = sl->mb_x;\n    int orig_deblock = sl->deblocking_filter;\n    int ret;\n    sl->linesize   = h->cur_pic_ptr->f->linesize[0];\n    sl->uvlinesize = h->cur_pic_ptr->f->linesize[1];\n    ret = alloc_scratch_buffers(sl, sl->linesize);\n    if (ret < 0)\n        return ret;\n    sl->mb_skip_run = -1;\n    if (h->postpone_filter)\n        sl->deblocking_filter = 0;\n    sl->is_complex = FRAME_MBAFF(h) || h->picture_structure != PICT_FRAME ||\n                     (CONFIG_GRAY && (h->flags & AV_CODEC_FLAG_GRAY));\n    if (h->ps.pps->cabac) {\n        align_get_bits(&sl->gb);\n        ff_init_cabac_decoder(&sl->cabac,\n                              sl->gb.buffer + get_bits_count(&sl->gb) / 8,\n                              (get_bits_left(&sl->gb) + 7) / 8);\n        ff_h264_init_cabac_states(h, sl);\n        for (;;) {\n            int ret, eos;\n            if (sl->mb_x + sl->mb_y * h->mb_width >= sl->next_slice_idx) {\n                av_log(h->avctx, AV_LOG_ERROR, "Slice overlaps with next at %d\\n",\n                       sl->next_slice_idx);\n                return AVERROR_INVALIDDATA;\n            }\n            ret = ff_h264_decode_mb_cabac(h, sl);\n            if (ret >= 0)\n                ff_h264_hl_decode_mb(h, sl);\n            if (ret >= 0 && FRAME_MBAFF(h)) {\n                sl->mb_y++;\n                ret = ff_h264_decode_mb_cabac(h, sl);\n                if (ret >= 0)\n                    ff_h264_hl_decode_mb(h, sl);\n                sl->mb_y--;\n            }\n            eos = get_cabac_terminate(&sl->cabac);\n            if ((h->workaround_bugs & FF_BUG_TRUNCATED) &&\n                sl->cabac.bytestream > sl->cabac.bytestream_end + 2) {\n                er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x - 1,\n                             sl->mb_y, ER_MB_END);\n                if (sl->mb_x >= lf_x_start)\n                    loop_filter(h, sl, lf_x_start, sl->mb_x + 1);\n                goto finish;\n            }\n            if (ret < 0 || sl->cabac.bytestream > sl->cabac.bytestream_end + 2) {\n                av_log(h->avctx, AV_LOG_ERROR,\n                       "error while decoding MB %d %d, bytestream %td\\n",\n                       sl->mb_x, sl->mb_y,\n                       sl->cabac.bytestream_end - sl->cabac.bytestream);\n                er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x,\n                             sl->mb_y, ER_MB_ERROR);\n                return AVERROR_INVALIDDATA;\n            }\n            if (++sl->mb_x >= h->mb_width) {\n                loop_filter(h, sl, lf_x_start, sl->mb_x);\n                sl->mb_x = lf_x_start = 0;\n                decode_finish_row(h, sl);\n                ++sl->mb_y;\n                if (FIELD_OR_MBAFF_PICTURE(h)) {\n                    ++sl->mb_y;\n                    if (FRAME_MBAFF(h) && sl->mb_y < h->mb_height)\n                        predict_field_decoding_flag(h, sl);\n                }\n            }\n            if (eos || sl->mb_y >= h->mb_height) {\n                ff_tlog(h->avctx, "slice end %d %d\\n",\n                        get_bits_count(&sl->gb), sl->gb.size_in_bits);\n                er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x - 1,\n                             sl->mb_y, ER_MB_END);\n                if (sl->mb_x > lf_x_start)\n                    loop_filter(h, sl, lf_x_start, sl->mb_x);\n                goto finish;\n            }\n        }\n    } else {\n        for (;;) {\n            int ret;\n            if (sl->mb_x + sl->mb_y * h->mb_width >= sl->next_slice_idx) {\n                av_log(h->avctx, AV_LOG_ERROR, "Slice overlaps with next at %d\\n",\n                       sl->next_slice_idx);\n                return AVERROR_INVALIDDATA;\n            }\n            ret = ff_h264_decode_mb_cavlc(h, sl);\n            if (ret >= 0)\n                ff_h264_hl_decode_mb(h, sl);\n            if (ret >= 0 && FRAME_MBAFF(h)) {\n                sl->mb_y++;\n                ret = ff_h264_decode_mb_cavlc(h, sl);\n                if (ret >= 0)\n                    ff_h264_hl_decode_mb(h, sl);\n                sl->mb_y--;\n            }\n            if (ret < 0) {\n                av_log(h->avctx, AV_LOG_ERROR,\n                       "error while decoding MB %d %d\\n", sl->mb_x, sl->mb_y);\n                er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x,\n                             sl->mb_y, ER_MB_ERROR);\n                return ret;\n            }\n            if (++sl->mb_x >= h->mb_width) {\n                loop_filter(h, sl, lf_x_start, sl->mb_x);\n                sl->mb_x = lf_x_start = 0;\n                decode_finish_row(h, sl);\n                ++sl->mb_y;\n                if (FIELD_OR_MBAFF_PICTURE(h)) {\n                    ++sl->mb_y;\n                    if (FRAME_MBAFF(h) && sl->mb_y < h->mb_height)\n                        predict_field_decoding_flag(h, sl);\n                }\n                if (sl->mb_y >= h->mb_height) {\n                    ff_tlog(h->avctx, "slice end %d %d\\n",\n                            get_bits_count(&sl->gb), sl->gb.size_in_bits);\n                    if (get_bits_left(&sl->gb) == 0) {\n                        er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y,\n                                     sl->mb_x - 1, sl->mb_y, ER_MB_END);\n                        goto finish;\n                    } else {\n                        er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y,\n                                     sl->mb_x - 1, sl->mb_y, ER_MB_END);\n                        return AVERROR_INVALIDDATA;\n                    }\n                }\n            }\n            if (get_bits_left(&sl->gb) <= 0 && sl->mb_skip_run <= 0) {\n                ff_tlog(h->avctx, "slice end %d %d\\n",\n                        get_bits_count(&sl->gb), sl->gb.size_in_bits);\n                if (get_bits_left(&sl->gb) == 0) {\n                    er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y,\n                                 sl->mb_x - 1, sl->mb_y, ER_MB_END);\n                    if (sl->mb_x > lf_x_start)\n                        loop_filter(h, sl, lf_x_start, sl->mb_x);\n                    goto finish;\n                } else {\n                    er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x,\n                                 sl->mb_y, ER_MB_ERROR);\n                    return AVERROR_INVALIDDATA;\n                }\n            }\n        }\n    }\nfinish:\n    sl->deblocking_filter = orig_deblock;\n    return 0;\n}', 'int ff_h264_decode_mb_cabac(const H264Context *h, H264SliceContext *sl)\n{\n    const SPS *sps = h->ps.sps;\n    int mb_xy;\n    int mb_type, partition_count, cbp = 0;\n    int dct8x8_allowed= h->ps.pps->transform_8x8_mode;\n    int decode_chroma = sps->chroma_format_idc == 1 || sps->chroma_format_idc == 2;\n    const int pixel_shift = h->pixel_shift;\n    mb_xy = sl->mb_xy = sl->mb_x + sl->mb_y*h->mb_stride;\n    if (sl->slice_type_nos != AV_PICTURE_TYPE_I) {\n        int skip;\n        if (FRAME_MBAFF(h) && (sl->mb_y & 1) == 1 && sl->prev_mb_skipped)\n            skip = sl->next_mb_skipped;\n        else\n            skip = decode_cabac_mb_skip(h, sl, sl->mb_x, sl->mb_y );\n        if( skip ) {\n            if (FRAME_MBAFF(h) && (sl->mb_y & 1) == 0) {\n                h->cur_pic.mb_type[mb_xy] = MB_TYPE_SKIP;\n                sl->next_mb_skipped = decode_cabac_mb_skip(h, sl, sl->mb_x, sl->mb_y+1 );\n                if(!sl->next_mb_skipped)\n                    sl->mb_mbaff = sl->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h, sl);\n            }\n            decode_mb_skip(h, sl);\n            h->cbp_table[mb_xy] = 0;\n            h->chroma_pred_mode_table[mb_xy] = 0;\n            sl->last_qscale_diff = 0;\n            return 0;\n        }\n    }\n    if (FRAME_MBAFF(h)) {\n        if ((sl->mb_y & 1) == 0)\n            sl->mb_mbaff =\n            sl->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h, sl);\n    }\n    sl->prev_mb_skipped = 0;\n    fill_decode_neighbors(h, sl, -(MB_FIELD(sl)));\n    if (sl->slice_type_nos == AV_PICTURE_TYPE_B) {\n        int ctx = 0;\n        assert(sl->slice_type_nos == AV_PICTURE_TYPE_B);\n        if (!IS_DIRECT(sl->left_type[LTOP] - 1))\n            ctx++;\n        if (!IS_DIRECT(sl->top_type - 1))\n            ctx++;\n        if( !get_cabac_noinline( &sl->cabac, &sl->cabac_state[27+ctx] ) ){\n            mb_type= 0;\n        }else if( !get_cabac_noinline( &sl->cabac, &sl->cabac_state[27+3] ) ) {\n            mb_type= 1 + get_cabac_noinline( &sl->cabac, &sl->cabac_state[27+5] );\n        }else{\n            int bits;\n            bits = get_cabac_noinline( &sl->cabac, &sl->cabac_state[27+4] ) << 3;\n            bits+= get_cabac_noinline( &sl->cabac, &sl->cabac_state[27+5] ) << 2;\n            bits+= get_cabac_noinline( &sl->cabac, &sl->cabac_state[27+5] ) << 1;\n            bits+= get_cabac_noinline( &sl->cabac, &sl->cabac_state[27+5] );\n            if( bits < 8 ){\n                mb_type= bits + 3;\n            }else if( bits == 13 ){\n                mb_type = decode_cabac_intra_mb_type(sl, 32, 0);\n                goto decode_intra_mb;\n            }else if( bits == 14 ){\n                mb_type= 11;\n            }else if( bits == 15 ){\n                mb_type= 22;\n            }else{\n                bits= ( bits<<1 ) + get_cabac_noinline( &sl->cabac, &sl->cabac_state[27+5] );\n                mb_type= bits - 4;\n            }\n        }\n            partition_count = ff_h264_b_mb_type_info[mb_type].partition_count;\n            mb_type         = ff_h264_b_mb_type_info[mb_type].type;\n    } else if (sl->slice_type_nos == AV_PICTURE_TYPE_P) {\n        if( get_cabac_noinline( &sl->cabac, &sl->cabac_state[14] ) == 0 ) {\n            if( get_cabac_noinline( &sl->cabac, &sl->cabac_state[15] ) == 0 ) {\n                mb_type= 3 * get_cabac_noinline( &sl->cabac, &sl->cabac_state[16] );\n            } else {\n                mb_type= 2 - get_cabac_noinline( &sl->cabac, &sl->cabac_state[17] );\n            }\n            partition_count = ff_h264_p_mb_type_info[mb_type].partition_count;\n            mb_type         = ff_h264_p_mb_type_info[mb_type].type;\n        } else {\n            mb_type = decode_cabac_intra_mb_type(sl, 17, 0);\n            goto decode_intra_mb;\n        }\n    } else {\n        mb_type = decode_cabac_intra_mb_type(sl, 3, 1);\n        if (sl->slice_type == AV_PICTURE_TYPE_SI && mb_type)\n            mb_type--;\n        assert(sl->slice_type_nos == AV_PICTURE_TYPE_I);\ndecode_intra_mb:\n        partition_count = 0;\n        cbp                      = ff_h264_i_mb_type_info[mb_type].cbp;\n        sl->intra16x16_pred_mode = ff_h264_i_mb_type_info[mb_type].pred_mode;\n        mb_type                  = ff_h264_i_mb_type_info[mb_type].type;\n    }\n    if (MB_FIELD(sl))\n        mb_type |= MB_TYPE_INTERLACED;\n    h->slice_table[mb_xy] = sl->slice_num;\n    if(IS_INTRA_PCM(mb_type)) {\n        const int mb_size = ff_h264_mb_sizes[sps->chroma_format_idc] *\n                            sps->bit_depth_luma >> 3;\n        const uint8_t *ptr;\n        ptr= sl->cabac.bytestream;\n        if(sl->cabac.low&0x1) ptr--;\n        if(CABAC_BITS==16){\n            if(sl->cabac.low&0x1FF) ptr--;\n        }\n        if ((int) (sl->cabac.bytestream_end - ptr) < mb_size)\n            return -1;\n        sl->intra_pcm_ptr = ptr;\n        ptr += mb_size;\n        ff_init_cabac_decoder(&sl->cabac, ptr, sl->cabac.bytestream_end - ptr);\n        h->cbp_table[mb_xy] = 0xf7ef;\n        h->chroma_pred_mode_table[mb_xy] = 0;\n        h->cur_pic.qscale_table[mb_xy] = 0;\n        memset(h->non_zero_count[mb_xy], 16, 48);\n        h->cur_pic.mb_type[mb_xy] = mb_type;\n        sl->last_qscale_diff = 0;\n        return 0;\n    }\n    fill_decode_caches(h, sl, mb_type);\n    if( IS_INTRA( mb_type ) ) {\n        int i, pred_mode;\n        if( IS_INTRA4x4( mb_type ) ) {\n            if (dct8x8_allowed && get_cabac_noinline(&sl->cabac, &sl->cabac_state[399 + sl->neighbor_transform_size])) {\n                mb_type |= MB_TYPE_8x8DCT;\n                for( i = 0; i < 16; i+=4 ) {\n                    int pred = pred_intra_mode(h, sl, i);\n                    int mode = decode_cabac_mb_intra4x4_pred_mode(sl, pred);\n                    fill_rectangle(&sl->intra4x4_pred_mode_cache[scan8[i]], 2, 2, 8, mode, 1);\n                }\n            } else {\n                for( i = 0; i < 16; i++ ) {\n                    int pred = pred_intra_mode(h, sl, i);\n                    sl->intra4x4_pred_mode_cache[scan8[i]] = decode_cabac_mb_intra4x4_pred_mode(sl, pred);\n                    ff_dlog(h->avctx, "i4x4 pred=%d mode=%d\\n", pred,\n                            sl->intra4x4_pred_mode_cache[scan8[i]]);\n                }\n            }\n            write_back_intra_pred_mode(h, sl);\n            if (ff_h264_check_intra4x4_pred_mode(sl->intra4x4_pred_mode_cache, h->avctx,\n                                                 sl->top_samples_available, sl->left_samples_available) < 0 )\n                return -1;\n        } else {\n            sl->intra16x16_pred_mode = ff_h264_check_intra_pred_mode(h->avctx, sl->top_samples_available,\n                                                                     sl->left_samples_available, sl->intra16x16_pred_mode, 0);\n            if (sl->intra16x16_pred_mode < 0) return -1;\n        }\n        if(decode_chroma){\n            h->chroma_pred_mode_table[mb_xy] =\n            pred_mode                        = decode_cabac_mb_chroma_pre_mode(h, sl);\n            pred_mode= ff_h264_check_intra_pred_mode(h->avctx, sl->top_samples_available,\n                                                     sl->left_samples_available, pred_mode, 1 );\n            if( pred_mode < 0 ) return -1;\n            sl->chroma_pred_mode = pred_mode;\n        } else {\n            sl->chroma_pred_mode = DC_128_PRED8x8;\n        }\n    } else if( partition_count == 4 ) {\n        int i, j, sub_partition_count[4], list, ref[2][4];\n        if (sl->slice_type_nos == AV_PICTURE_TYPE_B ) {\n            for( i = 0; i < 4; i++ ) {\n                sl->sub_mb_type[i] = decode_cabac_b_mb_sub_type(sl);\n                sub_partition_count[i] = ff_h264_b_sub_mb_type_info[sl->sub_mb_type[i]].partition_count;\n                sl->sub_mb_type[i]     = ff_h264_b_sub_mb_type_info[sl->sub_mb_type[i]].type;\n            }\n            if (IS_DIRECT(sl->sub_mb_type[0] | sl->sub_mb_type[1] |\n                          sl->sub_mb_type[2] | sl->sub_mb_type[3])) {\n                ff_h264_pred_direct_motion(h, sl, &mb_type);\n                sl->ref_cache[0][scan8[4]] =\n                sl->ref_cache[1][scan8[4]] =\n                sl->ref_cache[0][scan8[12]] =\n                sl->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;\n                    for( i = 0; i < 4; i++ )\n                        fill_rectangle(&sl->direct_cache[scan8[4*i]], 2, 2, 8, (sl->sub_mb_type[i] >> 1) & 0xFF, 1);\n            }\n        } else {\n            for( i = 0; i < 4; i++ ) {\n                sl->sub_mb_type[i] = decode_cabac_p_mb_sub_type(sl);\n                sub_partition_count[i] = ff_h264_p_sub_mb_type_info[sl->sub_mb_type[i]].partition_count;\n                sl->sub_mb_type[i]     = ff_h264_p_sub_mb_type_info[sl->sub_mb_type[i]].type;\n            }\n        }\n        for( list = 0; list < sl->list_count; list++ ) {\n                for( i = 0; i < 4; i++ ) {\n                    if(IS_DIRECT(sl->sub_mb_type[i])) continue;\n                    if(IS_DIR(sl->sub_mb_type[i], 0, list)){\n                        int rc = sl->ref_count[list] << MB_MBAFF(sl);\n                        if (rc > 1) {\n                            ref[list][i] = decode_cabac_mb_ref(sl, list, 4 * i);\n                            if (ref[list][i] >= (unsigned) rc) {\n                                av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref[list][i], rc);\n                                return -1;\n                            }\n                        }else\n                            ref[list][i] = 0;\n                    } else {\n                        ref[list][i] = -1;\n                    }\n                    sl->ref_cache[list][scan8[4 * i] + 1] =\n                    sl->ref_cache[list][scan8[4 * i] + 8] = sl->ref_cache[list][scan8[4 * i] + 9] = ref[list][i];\n                }\n        }\n        if(dct8x8_allowed)\n            dct8x8_allowed = get_dct8x8_allowed(h, sl);\n        for (list = 0; list < sl->list_count; list++) {\n            for(i=0; i<4; i++){\n                sl->ref_cache[list][scan8[4 * i]] = sl->ref_cache[list][scan8[4 * i] + 1];\n                if(IS_DIRECT(sl->sub_mb_type[i])){\n                    fill_rectangle(sl->mvd_cache[list][scan8[4*i]], 2, 2, 8, 0, 2);\n                    continue;\n                }\n                if(IS_DIR(sl->sub_mb_type[i], 0, list) && !IS_DIRECT(sl->sub_mb_type[i])){\n                    const int sub_mb_type= sl->sub_mb_type[i];\n                    const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1;\n                    for(j=0; j<sub_partition_count[i]; j++){\n                        int mpx, mpy;\n                        int mx, my;\n                        const int index= 4*i + block_width*j;\n                        int16_t (* mv_cache)[2] = &sl->mv_cache[list][ scan8[index] ];\n                        uint8_t (* mvd_cache)[2]= &sl->mvd_cache[list][ scan8[index] ];\n                        pred_motion(h, sl, index, block_width, list, sl->ref_cache[list][ scan8[index] ], &mx, &my);\n                        DECODE_CABAC_MB_MVD(sl, list, index)\n                        ff_tlog(h->avctx, "final mv:%d %d\\n", mx, my);\n                        if(IS_SUB_8X8(sub_mb_type)){\n                            mv_cache[ 1 ][0]=\n                            mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;\n                            mv_cache[ 1 ][1]=\n                            mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my;\n                            mvd_cache[ 1 ][0]=\n                            mvd_cache[ 8 ][0]= mvd_cache[ 9 ][0]= mpx;\n                            mvd_cache[ 1 ][1]=\n                            mvd_cache[ 8 ][1]= mvd_cache[ 9 ][1]= mpy;\n                        }else if(IS_SUB_8X4(sub_mb_type)){\n                            mv_cache[ 1 ][0]= mx;\n                            mv_cache[ 1 ][1]= my;\n                            mvd_cache[ 1 ][0]=  mpx;\n                            mvd_cache[ 1 ][1]= mpy;\n                        }else if(IS_SUB_4X8(sub_mb_type)){\n                            mv_cache[ 8 ][0]= mx;\n                            mv_cache[ 8 ][1]= my;\n                            mvd_cache[ 8 ][0]= mpx;\n                            mvd_cache[ 8 ][1]= mpy;\n                        }\n                        mv_cache[ 0 ][0]= mx;\n                        mv_cache[ 0 ][1]= my;\n                        mvd_cache[ 0 ][0]= mpx;\n                        mvd_cache[ 0 ][1]= mpy;\n                    }\n                }else{\n                    fill_rectangle(sl->mv_cache [list][ scan8[4*i] ], 2, 2, 8, 0, 4);\n                    fill_rectangle(sl->mvd_cache[list][ scan8[4*i] ], 2, 2, 8, 0, 2);\n                }\n            }\n        }\n    } else if( IS_DIRECT(mb_type) ) {\n        ff_h264_pred_direct_motion(h, sl, &mb_type);\n        fill_rectangle(sl->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 2);\n        fill_rectangle(sl->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 2);\n        dct8x8_allowed &= sps->direct_8x8_inference_flag;\n    } else {\n        int list, i;\n        if(IS_16X16(mb_type)){\n            for (list = 0; list < sl->list_count; list++) {\n                if(IS_DIR(mb_type, 0, list)){\n                    int ref, rc = sl->ref_count[list] << MB_MBAFF(sl);\n                    if (rc > 1) {\n                        ref= decode_cabac_mb_ref(sl, list, 0);\n                        if (ref >= (unsigned) rc) {\n                            av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref, rc);\n                            return -1;\n                        }\n                    }else\n                        ref=0;\n                    fill_rectangle(&sl->ref_cache[list][ scan8[0] ], 4, 4, 8, ref, 1);\n                }\n            }\n            for (list = 0; list < sl->list_count; list++) {\n                if(IS_DIR(mb_type, 0, list)){\n                    int mx,my,mpx,mpy;\n                    pred_motion(h, sl, 0, 4, list, sl->ref_cache[list][ scan8[0] ], &mx, &my);\n                    DECODE_CABAC_MB_MVD(sl, list, 0)\n                    ff_tlog(h->avctx, "final mv:%d %d\\n", mx, my);\n                    fill_rectangle(sl->mvd_cache[list][ scan8[0] ], 4, 4, 8, pack8to16(mpx,mpy), 2);\n                    fill_rectangle(sl->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4);\n                }\n            }\n        }\n        else if(IS_16X8(mb_type)){\n            for (list = 0; list < sl->list_count; list++) {\n                    for(i=0; i<2; i++){\n                        if(IS_DIR(mb_type, i, list)){\n                            int ref, rc = sl->ref_count[list] << MB_MBAFF(sl);\n                            if (rc > 1) {\n                                ref= decode_cabac_mb_ref(sl, list, 8 * i);\n                                if (ref >= (unsigned) rc) {\n                                    av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref, rc);\n                                    return -1;\n                                }\n                            }else\n                                ref=0;\n                            fill_rectangle(&sl->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, ref, 1);\n                        }else\n                            fill_rectangle(&sl->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (LIST_NOT_USED&0xFF), 1);\n                    }\n            }\n            for (list = 0; list < sl->list_count; list++) {\n                for(i=0; i<2; i++){\n                    if(IS_DIR(mb_type, i, list)){\n                        int mx,my,mpx,mpy;\n                        pred_16x8_motion(h, sl, 8*i, list, sl->ref_cache[list][scan8[0] + 16*i], &mx, &my);\n                        DECODE_CABAC_MB_MVD(sl, list, 8*i)\n                        ff_tlog(h->avctx, "final mv:%d %d\\n", mx, my);\n                        fill_rectangle(sl->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack8to16(mpx,mpy), 2);\n                        fill_rectangle(sl->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4);\n                    }else{\n                        fill_rectangle(sl->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 2);\n                        fill_rectangle(sl->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4);\n                    }\n                }\n            }\n        }else{\n            assert(IS_8X16(mb_type));\n            for (list = 0; list < sl->list_count; list++) {\n                    for(i=0; i<2; i++){\n                        if(IS_DIR(mb_type, i, list)){\n                            int ref, rc = sl->ref_count[list] << MB_MBAFF(sl);\n                            if (rc > 1) {\n                                ref = decode_cabac_mb_ref(sl, list, 4 * i);\n                                if (ref >= (unsigned) rc) {\n                                    av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref, rc);\n                                    return -1;\n                                }\n                            }else\n                                ref=0;\n                            fill_rectangle(&sl->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, ref, 1);\n                        }else\n                            fill_rectangle(&sl->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (LIST_NOT_USED&0xFF), 1);\n                    }\n            }\n            for (list = 0; list < sl->list_count; list++) {\n                for(i=0; i<2; i++){\n                    if(IS_DIR(mb_type, i, list)){\n                        int mx,my,mpx,mpy;\n                        pred_8x16_motion(h, sl, i*4, list, sl->ref_cache[list][ scan8[0] + 2*i ], &mx, &my);\n                        DECODE_CABAC_MB_MVD(sl, list, 4*i)\n                        ff_tlog(h->avctx, "final mv:%d %d\\n", mx, my);\n                        fill_rectangle(sl->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack8to16(mpx,mpy), 2);\n                        fill_rectangle(sl->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4);\n                    }else{\n                        fill_rectangle(sl->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 2);\n                        fill_rectangle(sl->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4);\n                    }\n                }\n            }\n        }\n    }\n   if( IS_INTER( mb_type ) ) {\n        h->chroma_pred_mode_table[mb_xy] = 0;\n        write_back_motion(h, sl, mb_type);\n   }\n    if( !IS_INTRA16x16( mb_type ) ) {\n        cbp  = decode_cabac_mb_cbp_luma(sl);\n        if(decode_chroma)\n            cbp |= decode_cabac_mb_cbp_chroma(sl) << 4;\n    }\n    h->cbp_table[mb_xy] = sl->cbp = cbp;\n    if( dct8x8_allowed && (cbp&15) && !IS_INTRA( mb_type ) ) {\n        mb_type |= MB_TYPE_8x8DCT * get_cabac_noinline(&sl->cabac, &sl->cabac_state[399 + sl->neighbor_transform_size]);\n    }\n    if (CHROMA444(h) && IS_8x8DCT(mb_type)){\n        int i;\n        uint8_t *nnz_cache = sl->non_zero_count_cache;\n        for (i = 0; i < 2; i++){\n            if (sl->left_type[LEFT(i)] && !IS_8x8DCT(sl->left_type[LEFT(i)])) {\n                nnz_cache[3+8* 1 + 2*8*i]=\n                nnz_cache[3+8* 2 + 2*8*i]=\n                nnz_cache[3+8* 6 + 2*8*i]=\n                nnz_cache[3+8* 7 + 2*8*i]=\n                nnz_cache[3+8*11 + 2*8*i]=\n                nnz_cache[3+8*12 + 2*8*i]= IS_INTRA(mb_type) ? 64 : 0;\n            }\n        }\n        if (sl->top_type && !IS_8x8DCT(sl->top_type)){\n            uint32_t top_empty = !IS_INTRA(mb_type) ? 0 : 0x40404040;\n            AV_WN32A(&nnz_cache[4+8* 0], top_empty);\n            AV_WN32A(&nnz_cache[4+8* 5], top_empty);\n            AV_WN32A(&nnz_cache[4+8*10], top_empty);\n        }\n    }\n    h->cur_pic.mb_type[mb_xy] = mb_type;\n    if( cbp || IS_INTRA16x16( mb_type ) ) {\n        const uint8_t *scan, *scan8x8;\n        const uint32_t *qmul;\n        if(IS_INTERLACED(mb_type)){\n            scan8x8 = sl->qscale ? h->field_scan8x8 : h->field_scan8x8_q0;\n            scan    = sl->qscale ? h->field_scan : h->field_scan_q0;\n        }else{\n            scan8x8 = sl->qscale ? h->zigzag_scan8x8 : h->zigzag_scan8x8_q0;\n            scan    = sl->qscale ? h->zigzag_scan : h->zigzag_scan_q0;\n        }\n        if(get_cabac_noinline( &sl->cabac, &sl->cabac_state[60 + (sl->last_qscale_diff != 0)])){\n            int val = 1;\n            int ctx= 2;\n            const int max_qp = 51 + 6*(sps->bit_depth_luma-8);\n            while( get_cabac_noinline( &sl->cabac, &sl->cabac_state[60 + ctx] ) ) {\n                ctx= 3;\n                val++;\n                if(val > 2*max_qp){\n                    av_log(h->avctx, AV_LOG_ERROR, "cabac decode of qscale diff failed at %d %d\\n", sl->mb_x, sl->mb_y);\n                    return -1;\n                }\n            }\n            if( val&0x01 )\n                val=   (val + 1)>>1 ;\n            else\n                val= -((val + 1)>>1);\n            sl->last_qscale_diff = val;\n            sl->qscale += val;\n            if (((unsigned)sl->qscale) > max_qp){\n                if (sl->qscale < 0) sl->qscale += max_qp + 1;\n                else                sl->qscale -= max_qp + 1;\n            }\n            sl->chroma_qp[0] = get_chroma_qp(h->ps.pps, 0, sl->qscale);\n            sl->chroma_qp[1] = get_chroma_qp(h->ps.pps, 1, sl->qscale);\n        }else\n            sl->last_qscale_diff=0;\n        decode_cabac_luma_residual(h, sl, scan, scan8x8, pixel_shift, mb_type, cbp, 0);\n        if (CHROMA444(h)) {\n            decode_cabac_luma_residual(h, sl, scan, scan8x8, pixel_shift, mb_type, cbp, 1);\n            decode_cabac_luma_residual(h, sl, scan, scan8x8, pixel_shift, mb_type, cbp, 2);\n        } else if (CHROMA422(h)) {\n            if( cbp&0x30 ){\n                int c;\n                for (c = 0; c < 2; c++)\n                    decode_cabac_residual_dc_422(h, sl, sl->mb + ((256 + 16*16*c) << pixel_shift), 3,\n                                                 CHROMA_DC_BLOCK_INDEX + c,\n                                                 ff_h264_chroma422_dc_scan, 8);\n            }\n            if( cbp&0x20 ) {\n                int c, i, i8x8;\n                for( c = 0; c < 2; c++ ) {\n                    int16_t *mb = sl->mb + (16*(16 + 16*c) << pixel_shift);\n                    qmul = h->ps.pps->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][sl->chroma_qp[c]];\n                    for (i8x8 = 0; i8x8 < 2; i8x8++) {\n                        for (i = 0; i < 4; i++) {\n                            const int index = 16 + 16 * c + 8*i8x8 + i;\n                            decode_cabac_residual_nondc(h, sl, mb, 4, index, scan + 1, qmul, 15);\n                            mb += 16<<pixel_shift;\n                        }\n                    }\n                }\n            } else {\n                fill_rectangle(&sl->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n                fill_rectangle(&sl->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\n            }\n        } else   {\n            if( cbp&0x30 ){\n                int c;\n                for (c = 0; c < 2; c++)\n                    decode_cabac_residual_dc(h, sl, sl->mb + ((256 + 16 * 16 * c) << pixel_shift),\n                                             3, CHROMA_DC_BLOCK_INDEX + c, ff_h264_chroma_dc_scan, 4);\n            }\n            if( cbp&0x20 ) {\n                int c, i;\n                for( c = 0; c < 2; c++ ) {\n                    qmul = h->ps.pps->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][sl->chroma_qp[c]];\n                    for( i = 0; i < 4; i++ ) {\n                        const int index = 16 + 16 * c + i;\n                        decode_cabac_residual_nondc(h, sl, sl->mb + (16*index << pixel_shift), 4, index, scan + 1, qmul, 15);\n                    }\n                }\n            } else {\n                fill_rectangle(&sl->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n                fill_rectangle(&sl->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\n            }\n        }\n    } else {\n        fill_rectangle(&sl->non_zero_count_cache[scan8[ 0]], 4, 4, 8, 0, 1);\n        fill_rectangle(&sl->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n        fill_rectangle(&sl->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\n        sl->last_qscale_diff = 0;\n    }\n    h->cur_pic.qscale_table[mb_xy] = sl->qscale;\n    write_back_non_zero_count(h, sl);\n    return 0;\n}', 'void ff_h264_hl_decode_mb(const H264Context *h, H264SliceContext *sl)\n{\n    const int mb_xy   = sl->mb_xy;\n    const int mb_type = h->cur_pic.mb_type[mb_xy];\n    int is_complex    = CONFIG_SMALL || sl->is_complex ||\n                        IS_INTRA_PCM(mb_type) || sl->qscale == 0;\n    if (CHROMA444(h)) {\n        if (is_complex || h->pixel_shift)\n            hl_decode_mb_444_complex(h, sl);\n        else\n            hl_decode_mb_444_simple_8(h, sl);\n    } else if (is_complex) {\n        hl_decode_mb_complex(h, sl);\n    } else if (h->pixel_shift) {\n        hl_decode_mb_simple_16(h, sl);\n    } else\n        hl_decode_mb_simple_8(h, sl);\n}', 'static av_noinline void FUNC(hl_decode_mb_444)(const H264Context *h, H264SliceContext *sl)\n{\n    const int mb_x    = sl->mb_x;\n    const int mb_y    = sl->mb_y;\n    const int mb_xy   = sl->mb_xy;\n    const int mb_type = h->cur_pic.mb_type[mb_xy];\n    uint8_t *dest[3];\n    int linesize;\n    int i, j, p;\n    const int *block_offset = &h->block_offset[0];\n    const int transform_bypass = !SIMPLE && (sl->qscale == 0 && h->ps.sps->transform_bypass);\n    const int plane_count      = (SIMPLE || !CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) ? 3 : 1;\n    for (p = 0; p < plane_count; p++) {\n        dest[p] = h->cur_pic.f->data[p] +\n                  ((mb_x << PIXEL_SHIFT) + mb_y * sl->linesize) * 16;\n        h->vdsp.prefetch(dest[p] + (sl->mb_x & 3) * 4 * sl->linesize + (64 << PIXEL_SHIFT),\n                         sl->linesize, 4);\n    }\n    h->list_counts[mb_xy] = sl->list_count;\n    if (!SIMPLE && MB_FIELD(sl)) {\n        linesize     = sl->mb_linesize = sl->mb_uvlinesize = sl->linesize * 2;\n        block_offset = &h->block_offset[48];\n        if (mb_y & 1)\n            for (p = 0; p < 3; p++)\n                dest[p] -= sl->linesize * 15;\n        if (FRAME_MBAFF(h)) {\n            int list;\n            for (list = 0; list < sl->list_count; list++) {\n                if (!USES_LIST(mb_type, list))\n                    continue;\n                if (IS_16X16(mb_type)) {\n                    int8_t *ref = &sl->ref_cache[list][scan8[0]];\n                    fill_rectangle(ref, 4, 4, 8, (16 + *ref) ^ (sl->mb_y & 1), 1);\n                } else {\n                    for (i = 0; i < 16; i += 4) {\n                        int ref = sl->ref_cache[list][scan8[i]];\n                        if (ref >= 0)\n                            fill_rectangle(&sl->ref_cache[list][scan8[i]], 2, 2,\n                                           8, (16 + ref) ^ (sl->mb_y & 1), 1);\n                    }\n                }\n            }\n        }\n    } else {\n        linesize = sl->mb_linesize = sl->mb_uvlinesize = sl->linesize;\n    }\n    if (!SIMPLE && IS_INTRA_PCM(mb_type)) {\n        if (PIXEL_SHIFT) {\n            const int bit_depth = h->ps.sps->bit_depth_luma;\n            GetBitContext gb;\n            init_get_bits(&gb, sl->intra_pcm_ptr, 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                           sl->intra_pcm_ptr + p * 256 + i * 16, 16);\n        }\n    } else {\n        if (IS_INTRA(mb_type)) {\n            if (sl->deblocking_filter)\n                xchg_mb_border(h, sl, 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, sl, mb_type, SIMPLE,\n                                          transform_bypass, PIXEL_SHIFT,\n                                          block_offset, linesize, dest[p], p);\n            if (sl->deblocking_filter)\n                xchg_mb_border(h, sl, dest[0], dest[1], dest[2], linesize,\n                               linesize, 0, 1, SIMPLE, PIXEL_SHIFT);\n        } else {\n            FUNC(hl_motion_444)(h, sl, dest[0], dest[1], dest[2],\n                      h->h264qpel.put_h264_qpel_pixels_tab,\n                      h->h264chroma.put_h264_chroma_pixels_tab,\n                      h->h264qpel.avg_h264_qpel_pixels_tab,\n                      h->h264chroma.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, sl, mb_type, SIMPLE, transform_bypass,\n                                   PIXEL_SHIFT, block_offset, linesize,\n                                   dest[p], p);\n    }\n}', 'static void MCFUNC(hl_motion)(const H264Context *h, H264SliceContext *sl,\n                              uint8_t *dest_y,\n                              uint8_t *dest_cb, uint8_t *dest_cr,\n                              const qpel_mc_func(*qpix_put)[16],\n                              const h264_chroma_mc_func(*chroma_put),\n                              const qpel_mc_func(*qpix_avg)[16],\n                              const h264_chroma_mc_func(*chroma_avg),\n                              const h264_weight_func *weight_op,\n                              const h264_biweight_func *weight_avg)\n{\n    const int mb_xy   = sl->mb_xy;\n    const int mb_type = h->cur_pic.mb_type[mb_xy];\n    assert(IS_INTER(mb_type));\n    if (HAVE_THREADS && (h->avctx->active_thread_type & FF_THREAD_FRAME))\n        await_references(h, sl);\n    prefetch_motion(h, sl, 0, PIXEL_SHIFT, CHROMA_IDC);\n    if (IS_16X16(mb_type)) {\n        mc_part(h, sl, 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, sl, 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, sl, 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, sl, 0, 0, 16, 8 * sl->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, sl, 4, 0, 16, 8 * sl->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 = sl->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, sl, 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, sl, 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, sl, 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, sl, n, 0, 8, 4 * sl->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, sl, n + 1, 0, 8, 4 * sl->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, sl, 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, sl, 1, PIXEL_SHIFT, CHROMA_IDC);\n}', 'static void await_references(const H264Context *h, H264SliceContext *sl)\n{\n    const int mb_xy   = sl->mb_xy;\n    const int mb_type = h->cur_pic.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, sl, 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, sl, refs, 0, 8, 0,\n                          IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);\n        get_lowest_part_y(h, sl, 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, sl, refs, 0, 16, 0,\n                          IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);\n        get_lowest_part_y(h, sl, 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 = sl->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, sl, 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, sl, 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, sl, 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, sl, 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, sl, 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, sl, 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 = sl->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                H264Ref *ref_pic  = &sl->ref_list[list][ref];\n                int ref_field         = ref_pic->reference - 1;\n                int ref_field_picture = ref_pic->parent->field_picture;\n                int pic_height        = 16 * h->mb_height >> ref_field_picture;\n                row <<= MB_MBAFF(sl);\n                nrefs[list]--;\n                if (!FIELD_PICTURE(h) && ref_field_picture) {\n                    ff_thread_await_progress(&ref_pic->parent->tf,\n                                             FFMIN((row >> 1) - !(row & 1),\n                                                   pic_height - 1),\n                                             1);\n                    ff_thread_await_progress(&ref_pic->parent->tf,\n                                             FFMIN((row >> 1), pic_height - 1),\n                                             0);\n                } else if (FIELD_PICTURE(h) && !ref_field_picture) {\n                    ff_thread_await_progress(&ref_pic->parent->tf,\n                                             FFMIN(row * 2 + ref_field,\n                                                   pic_height - 1),\n                                             0);\n                } else if (FIELD_PICTURE(h)) {\n                    ff_thread_await_progress(&ref_pic->parent->tf,\n                                             FFMIN(row, pic_height - 1),\n                                             ref_field);\n                } else {\n                    ff_thread_await_progress(&ref_pic->parent->tf,\n                                             FFMIN(row, pic_height - 1),\n                                             0);\n                }\n            }\n        }\n}']