libavcodec/h264.c:1058: error: Integer Overflow L2
  ([0, 2147483647] + 1):signed32 by call to `decode_nal_units`.

libavcodec/h264.c:1058:17: Call
1056.     }
1057. 
1058.     buf_index = decode_nal_units(h, buf, buf_size);
                      ^
1059.     if (buf_index < 0)
1060.         return AVERROR_INVALIDDATA;

libavcodec/h264.c:817:11: Call
  815.     }
  816. 
  817.     ret = ff_h2645_packet_split(&h->pkt, buf, buf_size, avctx, h->is_avc,
                 ^
  818.                                 h->nal_length_size, avctx->codec_id);
  819.     if (ret < 0) {

libavcodec/h2645_parse.c:260:15: Call
    258.         nal->size_bits = get_bit_length(nal, skip_trailing_zeros);
    259. 
    260.         ret = init_get_bits(&nal->gb, nal->data, nal->size_bits);
                       ^
    261.         if (ret < 0)
    262.             return ret;

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

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

libavcodec/h264.c:1058:17: Call
1056.     }
1057. 
1058.     buf_index = decode_nal_units(h, buf, buf_size);
                      ^
1059.     if (buf_index < 0)
1060.         return AVERROR_INVALIDDATA;

libavcodec/h264.c:803:1: Parameter `h->slice_ctx->list_count`
  801. }
  802. 
  803. static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size)
       ^
  804. {
  805.     AVCodecContext *const avctx = h->avctx;

libavcodec/h264.c:937:19: Call
  935. 
  936.         if (context_count == h->nb_slice_ctx) {
  937.             ret = ff_h264_execute_decode_slices(h, context_count);
                         ^
  938.             if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
  939.                 goto end;

libavcodec/h264_slice.c:2132:1: Parameter `h->slice_ctx->list_count`
    2130.  * @param context_count number of contexts to execute
    2131.  */
    2132. int ff_h264_execute_decode_slices(H264Context *h, unsigned context_count)
          ^
    2133. {
    2134.     AVCodecContext *const avctx = h->avctx;

libavcodec/h264_slice.c:2146:15: Call
    2144.         h->postpone_filter = 0;
    2145. 
    2146.         ret = decode_slice(avctx, &h->slice_ctx[0]);
                        ^
    2147.         h->mb_y = h->slice_ctx[0].mb_y;
    2148.         return ret;

libavcodec/h264_slice.c:1936:1: Parameter `arg->list_count`
      1934. }
      1935. 
      1936. static int decode_slice(struct AVCodecContext *avctx, void *arg)
            ^
      1937. {
      1938.     H264SliceContext *sl = arg;

libavcodec/h264_slice.c:1981:19: Call
      1979.             }
      1980. 
      1981.             ret = ff_h264_decode_mb_cabac(h, sl);
                              ^
      1982.             // STOP_TIMER("decode_mb_cabac")
      1983. 

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:1985:17: Call
      1983. 
      1984.             if (ret >= 0)
      1985.                 ff_h264_hl_decode_mb(h, sl);
                            ^
      1986. 
      1987.             // FIXME optimal? or let mb_decode decode 16x32 ?

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

libavcodec/h264_mb.c:805:9: Call
        803.             hl_decode_mb_444_simple_8(h, sl);
        804.     } else if (is_complex) {
        805.         hl_decode_mb_complex(h, sl);
                     ^
        806.     } else if (h->pixel_shift) {
        807.         hl_decode_mb_simple_16(h, sl);

libavcodec/h264_mb_template.c:41:1: <LHS trace>
39. #include "h264_mc_template.c"
40. 
41. static av_noinline void FUNC(hl_decode_mb)(const H264Context *h, H264SliceContext *sl)
    ^
42. {
43.     const int mb_x    = sl->mb_x;

libavcodec/h264_mb_template.c:41:1: Parameter `sl->list_count`
          39. #include "h264_mc_template.c"
          40. 
          41. static av_noinline void FUNC(hl_decode_mb)(const H264Context *h, H264SliceContext *sl)
              ^
          42. {
          43.     const int mb_x    = sl->mb_x;

libavcodec/h264_mb_template.c:76:51: Binary operation: ([0, 2147483647] + 1):signed32 by call to `decode_nal_units` 
          74.         if (FRAME_MBAFF(h)) {
          75.             int list;
          76.             for (list = 0; list < sl->list_count; list++) {
                                                                ^
          77.                 if (!USES_LIST(mb_type, list))
          78.                     continue;

static av_noinline void FUNC(hl_decode_mb)(const H264Context *h, H264SliceContext *sl)
{
    const int mb_x    = sl->mb_x;
    const int mb_y    = sl->mb_y;
    const int mb_xy   = sl->mb_xy;
    const int mb_type = h->cur_pic.mb_type[mb_xy];
    uint8_t *dest_y, *dest_cb, *dest_cr;
    int linesize, uvlinesize  ;
    int i, j;
    const int *block_offset = &h->block_offset[0];
    const int transform_bypass = !SIMPLE && (sl->qscale == 0 && h->ps.sps->transform_bypass);
    void (*idct_add)(uint8_t *dst, int16_t *block, int stride);
    const int block_h   = 16 >> h->chroma_y_shift;
    const int chroma422 = CHROMA422(h);
    dest_y  = h->cur_pic.f->data[0] + ((mb_x << PIXEL_SHIFT)     + mb_y * sl->linesize)  * 16;
    dest_cb = h->cur_pic.f->data[1] +  (mb_x << PIXEL_SHIFT) * 8 + mb_y * sl->uvlinesize * block_h;
    dest_cr = h->cur_pic.f->data[2] +  (mb_x << PIXEL_SHIFT) * 8 + mb_y * sl->uvlinesize * block_h;
    h->vdsp.prefetch(dest_y  + (sl->mb_x & 3) * 4 * sl->linesize   + (64 << PIXEL_SHIFT), sl->linesize,       4);
    h->vdsp.prefetch(dest_cb + (sl->mb_x & 7)     * sl->uvlinesize + (64 << PIXEL_SHIFT), dest_cr - dest_cb, 2);
    h->list_counts[mb_xy] = sl->list_count;
    if (!SIMPLE && MB_FIELD(sl)) {
        linesize     = sl->mb_linesize = sl->linesize * 2;
        uvlinesize   = sl->mb_uvlinesize = sl->uvlinesize * 2;
        block_offset = &h->block_offset[48];
        if (mb_y & 1) {
            dest_y  -= sl->linesize * 15;
            dest_cb -= sl->uvlinesize * (block_h - 1);
            dest_cr -= sl->uvlinesize * (block_h - 1);
        }
        if (FRAME_MBAFF(h)) {
            int list;
            for (list = 0; list < sl->list_count; list++) {
                if (!USES_LIST(mb_type, list))
                    continue;
                if (IS_16X16(mb_type)) {
                    int8_t *ref = &sl->ref_cache[list][scan8[0]];
                    fill_rectangle(ref, 4, 4, 8, (16 + *ref) ^ (sl->mb_y & 1), 1);
                } else {
                    for (i = 0; i < 16; i += 4) {
                        int ref = sl->ref_cache[list][scan8[i]];
                        if (ref >= 0)
                            fill_rectangle(&sl->ref_cache[list][scan8[i]], 2, 2,
                                           8, (16 + ref) ^ (sl->mb_y & 1), 1);
                    }
                }
            }
        }
    } else {
        linesize   = sl->mb_linesize   = sl->linesize;
        uvlinesize = sl->mb_uvlinesize = sl->uvlinesize;
    }
    if (!SIMPLE && IS_INTRA_PCM(mb_type)) {
        if (PIXEL_SHIFT) {
            const int bit_depth = h->ps.sps->bit_depth_luma;
            int j;
            GetBitContext gb;
            init_get_bits(&gb, sl->intra_pcm_ptr,
                          ff_h264_mb_sizes[h->ps.sps->chroma_format_idc] * bit_depth);
            for (i = 0; i < 16; i++) {
                uint16_t *tmp_y = (uint16_t *)(dest_y + i * linesize);
                for (j = 0; j < 16; j++)
                    tmp_y[j] = get_bits(&gb, bit_depth);
            }
            if (SIMPLE || !CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) {
                if (!h->ps.sps->chroma_format_idc) {
                    for (i = 0; i < block_h; i++) {
                        uint16_t *tmp_cb = (uint16_t *)(dest_cb + i * uvlinesize);
                        for (j = 0; j < 8; j++)
                            tmp_cb[j] = 1 << (bit_depth - 1);
                    }
                    for (i = 0; i < block_h; i++) {
                        uint16_t *tmp_cr = (uint16_t *)(dest_cr + i * uvlinesize);
                        for (j = 0; j < 8; j++)
                            tmp_cr[j] = 1 << (bit_depth - 1);
                    }
                } else {
                    for (i = 0; i < block_h; i++) {
                        uint16_t *tmp_cb = (uint16_t *)(dest_cb + i * uvlinesize);
                        for (j = 0; j < 8; j++)
                            tmp_cb[j] = get_bits(&gb, bit_depth);
                    }
                    for (i = 0; i < block_h; i++) {
                        uint16_t *tmp_cr = (uint16_t *)(dest_cr + i * uvlinesize);
                        for (j = 0; j < 8; j++)
                            tmp_cr[j] = get_bits(&gb, bit_depth);
                    }
                }
            }
        } else {
            for (i = 0; i < 16; i++)
                memcpy(dest_y + i * linesize, sl->intra_pcm_ptr + i * 16, 16);
            if (SIMPLE || !CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) {
                if (!h->ps.sps->chroma_format_idc) {
                    for (i = 0; i < block_h; i++) {
                        memset(dest_cb + i * uvlinesize, 128, 8);
                        memset(dest_cr + i * uvlinesize, 128, 8);
                    }
                } else {
                    const uint8_t *src_cb = sl->intra_pcm_ptr + 256;
                    const uint8_t *src_cr = sl->intra_pcm_ptr + 256 + block_h * 8;
                    for (i = 0; i < block_h; i++) {
                        memcpy(dest_cb + i * uvlinesize, src_cb + i * 8, 8);
                        memcpy(dest_cr + i * uvlinesize, src_cr + i * 8, 8);
                    }
                }
            }
        }
    } else {
        if (IS_INTRA(mb_type)) {
            if (sl->deblocking_filter)
                xchg_mb_border(h, sl, dest_y, dest_cb, dest_cr, linesize,
                               uvlinesize, 1, 0, SIMPLE, PIXEL_SHIFT);
            if (SIMPLE || !CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) {
                h->hpc.pred8x8[sl->chroma_pred_mode](dest_cb, uvlinesize);
                h->hpc.pred8x8[sl->chroma_pred_mode](dest_cr, uvlinesize);
            }
            hl_decode_mb_predict_luma(h, sl, mb_type, SIMPLE,
                                      transform_bypass, PIXEL_SHIFT,
                                      block_offset, linesize, dest_y, 0);
            if (sl->deblocking_filter)
                xchg_mb_border(h, sl, dest_y, dest_cb, dest_cr, linesize,
                               uvlinesize, 0, 0, SIMPLE, PIXEL_SHIFT);
        } else {
            if (chroma422) {
                FUNC(hl_motion_422)(h, sl, dest_y, dest_cb, dest_cr,
                              h->h264qpel.put_h264_qpel_pixels_tab,
                              h->h264chroma.put_h264_chroma_pixels_tab,
                              h->h264qpel.avg_h264_qpel_pixels_tab,
                              h->h264chroma.avg_h264_chroma_pixels_tab,
                              h->h264dsp.weight_h264_pixels_tab,
                              h->h264dsp.biweight_h264_pixels_tab);
            } else {
                FUNC(hl_motion_420)(h, sl, dest_y, dest_cb, dest_cr,
                              h->h264qpel.put_h264_qpel_pixels_tab,
                              h->h264chroma.put_h264_chroma_pixels_tab,
                              h->h264qpel.avg_h264_qpel_pixels_tab,
                              h->h264chroma.avg_h264_chroma_pixels_tab,
                              h->h264dsp.weight_h264_pixels_tab,
                              h->h264dsp.biweight_h264_pixels_tab);
            }
        }
        hl_decode_mb_idct_luma(h, sl, mb_type, SIMPLE, transform_bypass,
                               PIXEL_SHIFT, block_offset, linesize, dest_y, 0);
        if ((SIMPLE || !CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) &&
            (sl->cbp & 0x30)) {
            uint8_t *dest[2] = { dest_cb, dest_cr };
            if (transform_bypass) {
                if (IS_INTRA(mb_type) && h->ps.sps->profile_idc == 244 &&
                    (sl->chroma_pred_mode == VERT_PRED8x8 ||
                     sl->chroma_pred_mode == HOR_PRED8x8)) {
                    h->hpc.pred8x8_add[sl->chroma_pred_mode](dest[0],
                                                            block_offset + 16,
                                                            sl->mb + (16 * 16 * 1 << PIXEL_SHIFT),
                                                            uvlinesize);
                    h->hpc.pred8x8_add[sl->chroma_pred_mode](dest[1],
                                                            block_offset + 32,
                                                            sl->mb + (16 * 16 * 2 << PIXEL_SHIFT),
                                                            uvlinesize);
                } else {
                    idct_add = h->h264dsp.h264_add_pixels4_clear;
                    for (j = 1; j < 3; j++) {
                        for (i = j * 16; i < j * 16 + 4; i++)
                            if (sl->non_zero_count_cache[scan8[i]] ||
                                dctcoef_get(sl->mb, PIXEL_SHIFT, i * 16))
                                idct_add(dest[j - 1] + block_offset[i],
                                         sl->mb + (i * 16 << PIXEL_SHIFT),
                                         uvlinesize);
                        if (chroma422) {
                            for (i = j * 16 + 4; i < j * 16 + 8; i++)
                                if (sl->non_zero_count_cache[scan8[i + 4]] ||
                                    dctcoef_get(sl->mb, PIXEL_SHIFT, i * 16))
                                    idct_add(dest[j - 1] + block_offset[i + 4],
                                             sl->mb + (i * 16 << PIXEL_SHIFT),
                                             uvlinesize);
                        }
                    }
                }
            } else {
                int qp[2];
                if (chroma422) {
                    qp[0] = sl->chroma_qp[0] + 3;
                    qp[1] = sl->chroma_qp[1] + 3;
                } else {
                    qp[0] = sl->chroma_qp[0];
                    qp[1] = sl->chroma_qp[1];
                }
                if (sl->non_zero_count_cache[scan8[CHROMA_DC_BLOCK_INDEX + 0]])
                    h->h264dsp.h264_chroma_dc_dequant_idct(sl->mb + (16 * 16 * 1 << PIXEL_SHIFT),
                                                           h->ps.pps->dequant4_coeff[IS_INTRA(mb_type) ? 1 : 4][qp[0]][0]);
                if (sl->non_zero_count_cache[scan8[CHROMA_DC_BLOCK_INDEX + 1]])
                    h->h264dsp.h264_chroma_dc_dequant_idct(sl->mb + (16 * 16 * 2 << PIXEL_SHIFT),
                                                           h->ps.pps->dequant4_coeff[IS_INTRA(mb_type) ? 2 : 5][qp[1]][0]);
                h->h264dsp.h264_idct_add8(dest, block_offset,
                                          sl->mb, uvlinesize,
                                          sl->non_zero_count_cache);
            }
        }
    }
}
['static int h264_decode_frame(AVCodecContext *avctx, void *data,\n                             int *got_frame, AVPacket *avpkt)\n{\n    const uint8_t *buf = avpkt->data;\n    int buf_size       = avpkt->size;\n    H264Context *h     = avctx->priv_data;\n    AVFrame *pict      = data;\n    int buf_index      = 0;\n    int ret;\n    const uint8_t *new_extradata;\n    int new_extradata_size;\n    h->flags = avctx->flags;\n    h->setup_finished = 0;\nout:\n    if (buf_size == 0) {\n        H264Picture *out;\n        int i, out_idx;\n        h->cur_pic_ptr = NULL;\n        out     = h->delayed_pic[0];\n        out_idx = 0;\n        for (i = 1;\n             h->delayed_pic[i] &&\n             !h->delayed_pic[i]->f->key_frame &&\n             !h->delayed_pic[i]->mmco_reset;\n             i++)\n            if (h->delayed_pic[i]->poc < out->poc) {\n                out     = h->delayed_pic[i];\n                out_idx = i;\n            }\n        for (i = out_idx; h->delayed_pic[i]; i++)\n            h->delayed_pic[i] = h->delayed_pic[i + 1];\n        if (out) {\n            ret = output_frame(h, pict, out->f);\n            if (ret < 0)\n                return ret;\n            *got_frame = 1;\n        }\n        return buf_index;\n    }\n    new_extradata_size = 0;\n    new_extradata = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA,\n                                            &new_extradata_size);\n    if (new_extradata_size > 0 && new_extradata) {\n        ret = ff_h264_decode_extradata(new_extradata, new_extradata_size,\n                                       &h->ps, &h->is_avc, &h->nal_length_size,\n                                       avctx->err_recognition, avctx);\n        if (ret < 0)\n            return ret;\n    }\n    buf_index = decode_nal_units(h, buf, buf_size);\n    if (buf_index < 0)\n        return AVERROR_INVALIDDATA;\n    if (!h->cur_pic_ptr && h->nal_unit_type == NAL_END_SEQUENCE) {\n        buf_size = 0;\n        goto out;\n    }\n    if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS) && !h->cur_pic_ptr) {\n        if (avctx->skip_frame >= AVDISCARD_NONREF)\n            return 0;\n        av_log(avctx, AV_LOG_ERROR, "no frame!\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS) ||\n        (h->mb_y >= h->mb_height && h->mb_height)) {\n        if (avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)\n            decode_postinit(h, 1);\n        ff_h264_field_end(h, &h->slice_ctx[0], 0);\n        *got_frame = 0;\n        if (h->next_output_pic && ((avctx->flags & AV_CODEC_FLAG_OUTPUT_CORRUPT) ||\n                                   h->next_output_pic->recovered)) {\n            if (!h->next_output_pic->recovered)\n                h->next_output_pic->f->flags |= AV_FRAME_FLAG_CORRUPT;\n            ret = output_frame(h, pict, h->next_output_pic->f);\n            if (ret < 0)\n                return ret;\n            *got_frame = 1;\n        }\n    }\n    assert(pict->buf[0] || !*got_frame);\n    return get_consumed_bytes(buf_index, buf_size);\n}', 'static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size)\n{\n    AVCodecContext *const avctx = h->avctx;\n    unsigned context_count = 0;\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        H264SliceContext *sl = &h->slice_ctx[context_count];\n        int err;\n        if (avctx->skip_frame >= AVDISCARD_NONREF &&\n            nal->ref_idc == 0 && nal->type != 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 NAL_IDR_SLICE:\n            if (nal->type != NAL_IDR_SLICE) {\n                av_log(h->avctx, AV_LOG_ERROR,\n                       "Invalid mix of idr and non-idr slices\\n");\n                ret = -1;\n                goto end;\n            }\n            idr(h);\n        case NAL_SLICE:\n            sl->gb = nal->gb;\n            if ((err = ff_h264_decode_slice_header(h, sl)))\n                break;\n            if (h->sei.recovery_point.recovery_frame_cnt >= 0 && h->recovery_frame < 0) {\n                h->recovery_frame = (h->poc.frame_num + h->sei.recovery_point.recovery_frame_cnt) &\n                                    ((1 << h->ps.sps->log2_max_frame_num) - 1);\n            }\n            h->cur_pic_ptr->f->key_frame |=\n                (nal->type == NAL_IDR_SLICE) || (h->sei.recovery_point.recovery_frame_cnt >= 0);\n            if (nal->type == NAL_IDR_SLICE || h->recovery_frame == h->poc.frame_num) {\n                h->recovery_frame         = -1;\n                h->cur_pic_ptr->recovered = 1;\n            }\n            if (nal->type == NAL_IDR_SLICE)\n                h->frame_recovered |= FRAME_RECOVERED_IDR;\n            h->cur_pic_ptr->recovered |= !!(h->frame_recovered & FRAME_RECOVERED_IDR);\n            if (h->current_slice == 1) {\n                if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS))\n                    decode_postinit(h, i >= nals_needed);\n                if (h->avctx->hwaccel &&\n                    (ret = h->avctx->hwaccel->start_frame(h->avctx, NULL, 0)) < 0)\n                    return ret;\n            }\n            if (sl->redundant_pic_count == 0 &&\n                (avctx->skip_frame < AVDISCARD_NONREF || nal->ref_idc) &&\n                (avctx->skip_frame < AVDISCARD_BIDIR  ||\n                 sl->slice_type_nos != AV_PICTURE_TYPE_B) &&\n                (avctx->skip_frame < AVDISCARD_NONKEY ||\n                 h->cur_pic_ptr->f->key_frame) &&\n                avctx->skip_frame < AVDISCARD_ALL) {\n                if (avctx->hwaccel) {\n                    ret = avctx->hwaccel->decode_slice(avctx, nal->raw_data, nal->raw_size);\n                    if (ret < 0)\n                        return ret;\n                } else\n                    context_count++;\n            }\n            break;\n        case NAL_DPA:\n        case NAL_DPB:\n        case NAL_DPC:\n            avpriv_request_sample(avctx, "data partitioning");\n            ret = AVERROR(ENOSYS);\n            goto end;\n            break;\n        case 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 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 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 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                   nal->type, nal->size_bits);\n        }\n        if (context_count == h->nb_slice_ctx) {\n            ret = ff_h264_execute_decode_slices(h, context_count);\n            if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n                goto end;\n            context_count = 0;\n        }\n        if (err < 0) {\n            av_log(h->avctx, AV_LOG_ERROR, "decode_slice_header error\\n");\n            sl->ref_count[0] = sl->ref_count[1] = sl->list_count = 0;\n        }\n    }\n    if (context_count) {\n        ret = ff_h264_execute_decode_slices(h, context_count);\n        if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n            goto end;\n    }\n    ret = 0;\nend:\n    if (h->cur_pic_ptr && !h->droppable) {\n        ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,\n                                  h->picture_structure == PICT_BOTTOM_FIELD);\n    }\n    return (ret < 0) ? ret : buf_size;\n}', 'int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,\n                          void *logctx, int is_nalff, int nal_length_size,\n                          enum AVCodecID codec_id)\n{\n    int consumed, ret = 0;\n    pkt->nb_nals = 0;\n    while (length >= 4) {\n        H2645NAL *nal;\n        int extract_length = 0;\n        int skip_trailing_zeros = 1;\n        if (is_nalff) {\n            int i;\n            for (i = 0; i < nal_length_size; i++)\n                extract_length = (extract_length << 8) | buf[i];\n            buf    += nal_length_size;\n            length -= nal_length_size;\n            if (extract_length > length) {\n                av_log(logctx, AV_LOG_ERROR, "Invalid NAL unit size.\\n");\n                return AVERROR_INVALIDDATA;\n            }\n        } else {\n            if (buf[2] == 0) {\n                length--;\n                buf++;\n                continue;\n            }\n            if (buf[0] != 0 || buf[1] != 0 || buf[2] != 1)\n                return AVERROR_INVALIDDATA;\n            buf           += 3;\n            length        -= 3;\n            extract_length = length;\n        }\n        if (pkt->nals_allocated < pkt->nb_nals + 1) {\n            int new_size = pkt->nals_allocated + 1;\n            H2645NAL *tmp = av_realloc_array(pkt->nals, new_size, sizeof(*tmp));\n            if (!tmp)\n                return AVERROR(ENOMEM);\n            pkt->nals = tmp;\n            memset(pkt->nals + pkt->nals_allocated, 0,\n                   (new_size - pkt->nals_allocated) * sizeof(*tmp));\n            pkt->nals_allocated = new_size;\n        }\n        nal = &pkt->nals[pkt->nb_nals++];\n        consumed = ff_h2645_extract_rbsp(buf, extract_length, nal);\n        if (consumed < 0)\n            return consumed;\n        if (consumed < length - 3 &&\n            buf[consumed]     == 0x00 && buf[consumed + 1] == 0x00 &&\n            buf[consumed + 2] == 0x01 && buf[consumed + 3] == 0xE0)\n            skip_trailing_zeros = 0;\n        nal->size_bits = get_bit_length(nal, skip_trailing_zeros);\n        ret = init_get_bits(&nal->gb, nal->data, nal->size_bits);\n        if (ret < 0)\n            return ret;\n        if (codec_id == AV_CODEC_ID_HEVC)\n            ret = hevc_parse_nal_header(nal, logctx);\n        else\n            ret = h264_parse_nal_header(nal, logctx);\n        if (ret <= 0) {\n            if (ret < 0) {\n                av_log(logctx, AV_LOG_ERROR, "Invalid NAL unit %d, skipping.\\n",\n                       nal->type);\n            }\n            pkt->nb_nals--;\n        }\n        buf    += consumed;\n        length -= consumed;\n    }\n    return 0;\n}', 'static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,\n                                int bit_size)\n{\n    int buffer_size;\n    int ret = 0;\n    if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {\n        bit_size    = 0;\n        buffer      = NULL;\n        ret         = AVERROR_INVALIDDATA;\n    }\n    buffer_size = (bit_size + 7) >> 3;\n    s->buffer             = buffer;\n    s->size_in_bits       = bit_size;\n#if !UNCHECKED_BITSTREAM_READER\n    s->size_in_bits_plus8 = bit_size + 8;\n#endif\n    s->buffer_end         = buffer + buffer_size;\n    s->index              = 0;\n    return ret;\n}', 'int ff_h264_execute_decode_slices(H264Context *h, unsigned context_count)\n{\n    AVCodecContext *const avctx = h->avctx;\n    H264SliceContext *sl;\n    int i, j;\n    if (h->avctx->hwaccel)\n        return 0;\n    if (context_count == 1) {\n        int ret;\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        return ret;\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    }\n    return 0;\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                     avctx->codec_id != AV_CODEC_ID_H264 ||\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 = CABAC(h) && !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)(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_y, *dest_cb, *dest_cr;\n    int linesize, uvlinesize  ;\n    int i, j;\n    const int *block_offset = &h->block_offset[0];\n    const int transform_bypass = !SIMPLE && (sl->qscale == 0 && h->ps.sps->transform_bypass);\n    void (*idct_add)(uint8_t *dst, int16_t *block, int stride);\n    const int block_h   = 16 >> h->chroma_y_shift;\n    const int chroma422 = CHROMA422(h);\n    dest_y  = h->cur_pic.f->data[0] + ((mb_x << PIXEL_SHIFT)     + mb_y * sl->linesize)  * 16;\n    dest_cb = h->cur_pic.f->data[1] +  (mb_x << PIXEL_SHIFT) * 8 + mb_y * sl->uvlinesize * block_h;\n    dest_cr = h->cur_pic.f->data[2] +  (mb_x << PIXEL_SHIFT) * 8 + mb_y * sl->uvlinesize * block_h;\n    h->vdsp.prefetch(dest_y  + (sl->mb_x & 3) * 4 * sl->linesize   + (64 << PIXEL_SHIFT), sl->linesize,       4);\n    h->vdsp.prefetch(dest_cb + (sl->mb_x & 7)     * sl->uvlinesize + (64 << PIXEL_SHIFT), dest_cr - dest_cb, 2);\n    h->list_counts[mb_xy] = sl->list_count;\n    if (!SIMPLE && MB_FIELD(sl)) {\n        linesize     = sl->mb_linesize = sl->linesize * 2;\n        uvlinesize   = sl->mb_uvlinesize = sl->uvlinesize * 2;\n        block_offset = &h->block_offset[48];\n        if (mb_y & 1) {\n            dest_y  -= sl->linesize * 15;\n            dest_cb -= sl->uvlinesize * (block_h - 1);\n            dest_cr -= sl->uvlinesize * (block_h - 1);\n        }\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->linesize;\n        uvlinesize = sl->mb_uvlinesize = sl->uvlinesize;\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            int j;\n            GetBitContext gb;\n            init_get_bits(&gb, sl->intra_pcm_ptr,\n                          ff_h264_mb_sizes[h->ps.sps->chroma_format_idc] * bit_depth);\n            for (i = 0; i < 16; i++) {\n                uint16_t *tmp_y = (uint16_t *)(dest_y + i * linesize);\n                for (j = 0; j < 16; j++)\n                    tmp_y[j] = get_bits(&gb, bit_depth);\n            }\n            if (SIMPLE || !CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) {\n                if (!h->ps.sps->chroma_format_idc) {\n                    for (i = 0; i < block_h; i++) {\n                        uint16_t *tmp_cb = (uint16_t *)(dest_cb + i * uvlinesize);\n                        for (j = 0; j < 8; j++)\n                            tmp_cb[j] = 1 << (bit_depth - 1);\n                    }\n                    for (i = 0; i < block_h; i++) {\n                        uint16_t *tmp_cr = (uint16_t *)(dest_cr + i * uvlinesize);\n                        for (j = 0; j < 8; j++)\n                            tmp_cr[j] = 1 << (bit_depth - 1);\n                    }\n                } else {\n                    for (i = 0; i < block_h; i++) {\n                        uint16_t *tmp_cb = (uint16_t *)(dest_cb + i * uvlinesize);\n                        for (j = 0; j < 8; j++)\n                            tmp_cb[j] = get_bits(&gb, bit_depth);\n                    }\n                    for (i = 0; i < block_h; i++) {\n                        uint16_t *tmp_cr = (uint16_t *)(dest_cr + i * uvlinesize);\n                        for (j = 0; j < 8; j++)\n                            tmp_cr[j] = get_bits(&gb, bit_depth);\n                    }\n                }\n            }\n        } else {\n            for (i = 0; i < 16; i++)\n                memcpy(dest_y + i * linesize, sl->intra_pcm_ptr + i * 16, 16);\n            if (SIMPLE || !CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) {\n                if (!h->ps.sps->chroma_format_idc) {\n                    for (i = 0; i < block_h; i++) {\n                        memset(dest_cb + i * uvlinesize, 128, 8);\n                        memset(dest_cr + i * uvlinesize, 128, 8);\n                    }\n                } else {\n                    const uint8_t *src_cb = sl->intra_pcm_ptr + 256;\n                    const uint8_t *src_cr = sl->intra_pcm_ptr + 256 + block_h * 8;\n                    for (i = 0; i < block_h; i++) {\n                        memcpy(dest_cb + i * uvlinesize, src_cb + i * 8, 8);\n                        memcpy(dest_cr + i * uvlinesize, src_cr + i * 8, 8);\n                    }\n                }\n            }\n        }\n    } else {\n        if (IS_INTRA(mb_type)) {\n            if (sl->deblocking_filter)\n                xchg_mb_border(h, sl, dest_y, dest_cb, dest_cr, linesize,\n                               uvlinesize, 1, 0, SIMPLE, PIXEL_SHIFT);\n            if (SIMPLE || !CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) {\n                h->hpc.pred8x8[sl->chroma_pred_mode](dest_cb, uvlinesize);\n                h->hpc.pred8x8[sl->chroma_pred_mode](dest_cr, uvlinesize);\n            }\n            hl_decode_mb_predict_luma(h, sl, mb_type, SIMPLE,\n                                      transform_bypass, PIXEL_SHIFT,\n                                      block_offset, linesize, dest_y, 0);\n            if (sl->deblocking_filter)\n                xchg_mb_border(h, sl, dest_y, dest_cb, dest_cr, linesize,\n                               uvlinesize, 0, 0, SIMPLE, PIXEL_SHIFT);\n        } else {\n            if (chroma422) {\n                FUNC(hl_motion_422)(h, sl, dest_y, dest_cb, dest_cr,\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            } else {\n                FUNC(hl_motion_420)(h, sl, dest_y, dest_cb, dest_cr,\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        }\n        hl_decode_mb_idct_luma(h, sl, mb_type, SIMPLE, transform_bypass,\n                               PIXEL_SHIFT, block_offset, linesize, dest_y, 0);\n        if ((SIMPLE || !CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) &&\n            (sl->cbp & 0x30)) {\n            uint8_t *dest[2] = { dest_cb, dest_cr };\n            if (transform_bypass) {\n                if (IS_INTRA(mb_type) && h->ps.sps->profile_idc == 244 &&\n                    (sl->chroma_pred_mode == VERT_PRED8x8 ||\n                     sl->chroma_pred_mode == HOR_PRED8x8)) {\n                    h->hpc.pred8x8_add[sl->chroma_pred_mode](dest[0],\n                                                            block_offset + 16,\n                                                            sl->mb + (16 * 16 * 1 << PIXEL_SHIFT),\n                                                            uvlinesize);\n                    h->hpc.pred8x8_add[sl->chroma_pred_mode](dest[1],\n                                                            block_offset + 32,\n                                                            sl->mb + (16 * 16 * 2 << PIXEL_SHIFT),\n                                                            uvlinesize);\n                } else {\n                    idct_add = h->h264dsp.h264_add_pixels4_clear;\n                    for (j = 1; j < 3; j++) {\n                        for (i = j * 16; i < j * 16 + 4; i++)\n                            if (sl->non_zero_count_cache[scan8[i]] ||\n                                dctcoef_get(sl->mb, PIXEL_SHIFT, i * 16))\n                                idct_add(dest[j - 1] + block_offset[i],\n                                         sl->mb + (i * 16 << PIXEL_SHIFT),\n                                         uvlinesize);\n                        if (chroma422) {\n                            for (i = j * 16 + 4; i < j * 16 + 8; i++)\n                                if (sl->non_zero_count_cache[scan8[i + 4]] ||\n                                    dctcoef_get(sl->mb, PIXEL_SHIFT, i * 16))\n                                    idct_add(dest[j - 1] + block_offset[i + 4],\n                                             sl->mb + (i * 16 << PIXEL_SHIFT),\n                                             uvlinesize);\n                        }\n                    }\n                }\n            } else {\n                int qp[2];\n                if (chroma422) {\n                    qp[0] = sl->chroma_qp[0] + 3;\n                    qp[1] = sl->chroma_qp[1] + 3;\n                } else {\n                    qp[0] = sl->chroma_qp[0];\n                    qp[1] = sl->chroma_qp[1];\n                }\n                if (sl->non_zero_count_cache[scan8[CHROMA_DC_BLOCK_INDEX + 0]])\n                    h->h264dsp.h264_chroma_dc_dequant_idct(sl->mb + (16 * 16 * 1 << PIXEL_SHIFT),\n                                                           h->ps.pps->dequant4_coeff[IS_INTRA(mb_type) ? 1 : 4][qp[0]][0]);\n                if (sl->non_zero_count_cache[scan8[CHROMA_DC_BLOCK_INDEX + 1]])\n                    h->h264dsp.h264_chroma_dc_dequant_idct(sl->mb + (16 * 16 * 2 << PIXEL_SHIFT),\n                                                           h->ps.pps->dequant4_coeff[IS_INTRA(mb_type) ? 2 : 5][qp[1]][0]);\n                h->h264dsp.h264_idct_add8(dest, block_offset,\n                                          sl->mb, uvlinesize,\n                                          sl->non_zero_count_cache);\n            }\n        }\n    }\n}']