libavcodec/h264dec.c:742: error: Integer Overflow L2
  ([8, 2147483648] + [8, 2147483648]):signed32 by call to `decode_nal_units`.

libavcodec/h264dec.c:742:17: Call
740.     }
741. 
742.     buf_index = decode_nal_units(h, buf, buf_size);
                     ^
743.     if (buf_index < 0)
744.         return AVERROR_INVALIDDATA;

libavcodec/h264dec.c:528:11: Call
  526.     }
  527. 
  528.     ret = ff_h2645_packet_split(&h->pkt, buf, buf_size, avctx, h->is_avc,
                 ^
  529.                                 h->nal_length_size, avctx->codec_id);
  530.     if (ret < 0) {

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

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

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

libavcodec/h264dec.c:742:17: Call
740.     }
741. 
742.     buf_index = decode_nal_units(h, buf, buf_size);
                     ^
743.     if (buf_index < 0)
744.         return AVERROR_INVALIDDATA;

libavcodec/h264dec.c:515:1: Parameter `*h->cur_pic.qscale_table`
  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:633:11: Call
  631.     }
  632. 
  633.     ret = ff_h264_execute_decode_slices(h);
                 ^
  634.     if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
  635.         goto end;

libavcodec/h264_slice.c:2488:1: Parameter `*h->cur_pic.qscale_table`
    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:2549:21: Call
    2547.                 for (j = sl->resync_mb_y; j < y_end; j += 1 + FIELD_OR_MBAFF_PICTURE(h)) {
    2548.                     sl->mb_y = j;
    2549.                     loop_filter(h, sl, j > sl->resync_mb_y ? 0 : sl->resync_mb_x,
                              ^
    2550.                                 j == y_end - 1 ? x_end : h->mb_width);
    2551.                 }

libavcodec/h264_slice.c:2165:1: Parameter `*h->cur_pic.qscale_table`
      2163. }
      2164. 
      2165. static void loop_filter(const H264Context *h, H264SliceContext *sl, int start_x, int end_x)
            ^
      2166. {
      2167.     uint8_t *dest_y, *dest_cb, *dest_cr;

libavcodec/h264_slice.c:2214:21: Call
      2212.                 backup_mb_border(h, sl, dest_y, dest_cb, dest_cr, linesize,
      2213.                                  uvlinesize, 0);
      2214.                 if (fill_filter_caches(h, sl, mb_type))
                                ^
      2215.                     continue;
      2216.                 sl->chroma_qp[0] = get_chroma_qp(h->ps.pps, 0, h->cur_pic.qscale_table[mb_xy]);

libavcodec/h264_slice.c:2023:1: <LHS trace>
2021.  * @return non zero if the loop filter can be skipped
2022.  */
2023. static int fill_filter_caches(const H264Context *h, H264SliceContext *sl, int mb_type)
      ^
2024. {
2025.     const int mb_xy = sl->mb_xy;

libavcodec/h264_slice.c:2023:1: Parameter `sl->qp_thresh`
        2021.  * @return non zero if the loop filter can be skipped
        2022.  */
        2023. static int fill_filter_caches(const H264Context *h, H264SliceContext *sl, int mb_type)
              ^
        2024. {
        2025.     const int mb_xy = sl->mb_xy;

libavcodec/h264_slice.c:2056:9: Assignment
        2054.          * This is a conservative estimate: could also check beta_offset
        2055.          * and more accurate chroma_qp. */
        2056.         int qp_thresh = sl->qp_thresh; // FIXME strictly we should store qp_thresh for each mb of a slice
                      ^
        2057.         int qp        = h->cur_pic.qscale_table[mb_xy];
        2058.         if (qp <= qp_thresh &&

libavcodec/h264_slice.c:2023:1: <RHS trace>
2021.  * @return non zero if the loop filter can be skipped
2022.  */
2023. static int fill_filter_caches(const H264Context *h, H264SliceContext *sl, int mb_type)
      ^
2024. {
2025.     const int mb_xy = sl->mb_xy;

libavcodec/h264_slice.c:2023:1: Parameter `*h->cur_pic.qscale_table`
        2021.  * @return non zero if the loop filter can be skipped
        2022.  */
        2023. static int fill_filter_caches(const H264Context *h, H264SliceContext *sl, int mb_type)
              ^
        2024. {
        2025.     const int mb_xy = sl->mb_xy;

libavcodec/h264_slice.c:2060:14: Binary operation: ([8, 2147483648] + [8, 2147483648]):signed32 by call to `decode_nal_units` 
        2058.         if (qp <= qp_thresh &&
        2059.             (left_xy[LTOP] < 0 ||
        2060.              ((qp + h->cur_pic.qscale_table[left_xy[LTOP]] + 1) >> 1) <= qp_thresh) &&
                           ^
        2061.             (top_xy < 0 ||
        2062.              ((qp + h->cur_pic.qscale_table[top_xy] + 1) >> 1) <= qp_thresh)) {

static int fill_filter_caches(const H264Context *h, H264SliceContext *sl, int mb_type)
{
    const int mb_xy = sl->mb_xy;
    int top_xy, left_xy[LEFT_MBS];
    int top_type, left_type[LEFT_MBS];
    uint8_t *nnz;
    uint8_t *nnz_cache;
    top_xy = mb_xy - (h->mb_stride << MB_FIELD(sl));
    left_xy[LBOT] = left_xy[LTOP] = mb_xy - 1;
    if (FRAME_MBAFF(h)) {
        const int left_mb_field_flag = IS_INTERLACED(h->cur_pic.mb_type[mb_xy - 1]);
        const int curr_mb_field_flag = IS_INTERLACED(mb_type);
        if (sl->mb_y & 1) {
            if (left_mb_field_flag != curr_mb_field_flag)
                left_xy[LTOP] -= h->mb_stride;
        } else {
            if (curr_mb_field_flag)
                top_xy += h->mb_stride &
                          (((h->cur_pic.mb_type[top_xy] >> 7) & 1) - 1);
            if (left_mb_field_flag != curr_mb_field_flag)
                left_xy[LBOT] += h->mb_stride;
        }
    }
    sl->top_mb_xy        = top_xy;
    sl->left_mb_xy[LTOP] = left_xy[LTOP];
    sl->left_mb_xy[LBOT] = left_xy[LBOT];
    {
        int qp_thresh = sl->qp_thresh;
        int qp        = h->cur_pic.qscale_table[mb_xy];
        if (qp <= qp_thresh &&
            (left_xy[LTOP] < 0 ||
             ((qp + h->cur_pic.qscale_table[left_xy[LTOP]] + 1) >> 1) <= qp_thresh) &&
            (top_xy < 0 ||
             ((qp + h->cur_pic.qscale_table[top_xy] + 1) >> 1) <= qp_thresh)) {
            if (!FRAME_MBAFF(h))
                return 1;
            if ((left_xy[LTOP] < 0 ||
                 ((qp + h->cur_pic.qscale_table[left_xy[LBOT]] + 1) >> 1) <= qp_thresh) &&
                (top_xy < h->mb_stride ||
                 ((qp + h->cur_pic.qscale_table[top_xy - h->mb_stride] + 1) >> 1) <= qp_thresh))
                return 1;
        }
    }
    top_type        = h->cur_pic.mb_type[top_xy];
    left_type[LTOP] = h->cur_pic.mb_type[left_xy[LTOP]];
    left_type[LBOT] = h->cur_pic.mb_type[left_xy[LBOT]];
    if (sl->deblocking_filter == 2) {
        if (h->slice_table[top_xy] != sl->slice_num)
            top_type = 0;
        if (h->slice_table[left_xy[LBOT]] != sl->slice_num)
            left_type[LTOP] = left_type[LBOT] = 0;
    } else {
        if (h->slice_table[top_xy] == 0xFFFF)
            top_type = 0;
        if (h->slice_table[left_xy[LBOT]] == 0xFFFF)
            left_type[LTOP] = left_type[LBOT] = 0;
    }
    sl->top_type        = top_type;
    sl->left_type[LTOP] = left_type[LTOP];
    sl->left_type[LBOT] = left_type[LBOT];
    if (IS_INTRA(mb_type))
        return 0;
    fill_filter_caches_inter(h, sl, mb_type, top_xy, left_xy,
                             top_type, left_type, mb_xy, 0);
    if (sl->list_count == 2)
        fill_filter_caches_inter(h, sl, mb_type, top_xy, left_xy,
                                 top_type, left_type, mb_xy, 1);
    nnz       = h->non_zero_count[mb_xy];
    nnz_cache = sl->non_zero_count_cache;
    AV_COPY32(&nnz_cache[4 + 8 * 1], &nnz[0]);
    AV_COPY32(&nnz_cache[4 + 8 * 2], &nnz[4]);
    AV_COPY32(&nnz_cache[4 + 8 * 3], &nnz[8]);
    AV_COPY32(&nnz_cache[4 + 8 * 4], &nnz[12]);
    sl->cbp = h->cbp_table[mb_xy];
    if (top_type) {
        nnz = h->non_zero_count[top_xy];
        AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[3 * 4]);
    }
    if (left_type[LTOP]) {
        nnz = h->non_zero_count[left_xy[LTOP]];
        nnz_cache[3 + 8 * 1] = nnz[3 + 0 * 4];
        nnz_cache[3 + 8 * 2] = nnz[3 + 1 * 4];
        nnz_cache[3 + 8 * 3] = nnz[3 + 2 * 4];
        nnz_cache[3 + 8 * 4] = nnz[3 + 3 * 4];
    }
    if (!CABAC(h) && h->ps.pps->transform_8x8_mode) {
        if (IS_8x8DCT(top_type)) {
            nnz_cache[4 + 8 * 0] =
            nnz_cache[5 + 8 * 0] = (h->cbp_table[top_xy] & 0x4000) >> 12;
            nnz_cache[6 + 8 * 0] =
            nnz_cache[7 + 8 * 0] = (h->cbp_table[top_xy] & 0x8000) >> 12;
        }
        if (IS_8x8DCT(left_type[LTOP])) {
            nnz_cache[3 + 8 * 1] =
            nnz_cache[3 + 8 * 2] = (h->cbp_table[left_xy[LTOP]] & 0x2000) >> 12;
        }
        if (IS_8x8DCT(left_type[LBOT])) {
            nnz_cache[3 + 8 * 3] =
            nnz_cache[3 + 8 * 4] = (h->cbp_table[left_xy[LBOT]] & 0x8000) >> 12;
        }
        if (IS_8x8DCT(mb_type)) {
            nnz_cache[scan8[0]] =
            nnz_cache[scan8[1]] =
            nnz_cache[scan8[2]] =
            nnz_cache[scan8[3]] = (sl->cbp & 0x1000) >> 12;
            nnz_cache[scan8[0 + 4]] =
            nnz_cache[scan8[1 + 4]] =
            nnz_cache[scan8[2 + 4]] =
            nnz_cache[scan8[3 + 4]] = (sl->cbp & 0x2000) >> 12;
            nnz_cache[scan8[0 + 8]] =
            nnz_cache[scan8[1 + 8]] =
            nnz_cache[scan8[2 + 8]] =
            nnz_cache[scan8[3 + 8]] = (sl->cbp & 0x4000) >> 12;
            nnz_cache[scan8[0 + 12]] =
            nnz_cache[scan8[1 + 12]] =
            nnz_cache[scan8[2 + 12]] =
            nnz_cache[scan8[3 + 12]] = (sl->cbp & 0x8000) >> 12;
        }
    }
    return 0;
}
['static int h264_decode_frame(AVCodecContext *avctx, void *data,\n                             int *got_frame, AVPacket *avpkt)\n{\n    const uint8_t *buf = avpkt->data;\n    int buf_size       = avpkt->size;\n    H264Context *h     = avctx->priv_data;\n    AVFrame *pict      = data;\n    int buf_index      = 0;\n    int ret;\n    const uint8_t *new_extradata;\n    int new_extradata_size;\n    h->flags = avctx->flags;\n    h->setup_finished = 0;\n    h->nb_slice_ctx_queued = 0;\nout:\n    if (buf_size == 0) {\n        H264Picture *out;\n        int i, out_idx;\n        h->cur_pic_ptr = NULL;\n        out     = h->delayed_pic[0];\n        out_idx = 0;\n        for (i = 1;\n             h->delayed_pic[i] &&\n             !h->delayed_pic[i]->f->key_frame &&\n             !h->delayed_pic[i]->mmco_reset;\n             i++)\n            if (h->delayed_pic[i]->poc < out->poc) {\n                out     = h->delayed_pic[i];\n                out_idx = i;\n            }\n        for (i = out_idx; h->delayed_pic[i]; i++)\n            h->delayed_pic[i] = h->delayed_pic[i + 1];\n        if (out) {\n            ret = output_frame(h, pict, out->f);\n            if (ret < 0)\n                return ret;\n            *got_frame = 1;\n        }\n        return buf_index;\n    }\n    new_extradata_size = 0;\n    new_extradata = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA,\n                                            &new_extradata_size);\n    if (new_extradata_size > 0 && new_extradata) {\n        ret = ff_h264_decode_extradata(new_extradata, new_extradata_size,\n                                       &h->ps, &h->is_avc, &h->nal_length_size,\n                                       avctx->err_recognition, avctx);\n        if (ret < 0)\n            return ret;\n    }\n    buf_index = decode_nal_units(h, buf, buf_size);\n    if (buf_index < 0)\n        return AVERROR_INVALIDDATA;\n    if (!h->cur_pic_ptr && h->nal_unit_type == H264_NAL_END_SEQUENCE) {\n        buf_size = 0;\n        goto out;\n    }\n    if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS) && !h->cur_pic_ptr) {\n        if (avctx->skip_frame >= AVDISCARD_NONREF)\n            return 0;\n        av_log(avctx, AV_LOG_ERROR, "no frame!\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS) ||\n        (h->mb_y >= h->mb_height && h->mb_height)) {\n        ff_h264_field_end(h, &h->slice_ctx[0], 0);\n        *got_frame = 0;\n        if (h->output_frame->buf[0]) {\n            ret = output_frame(h, pict, h->output_frame) ;\n            av_frame_unref(h->output_frame);\n            if (ret < 0)\n                return ret;\n            *got_frame = 1;\n        }\n    }\n    assert(pict->buf[0] || !*got_frame);\n    return get_consumed_bytes(buf_index, buf_size);\n}', 'static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size)\n{\n    AVCodecContext *const avctx = h->avctx;\n    int nals_needed = 0;\n    int i, ret = 0;\n    if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) {\n        h->current_slice = 0;\n        if (!h->first_field)\n            h->cur_pic_ptr = NULL;\n        ff_h264_sei_uninit(&h->sei);\n    }\n    ret = ff_h2645_packet_split(&h->pkt, buf, buf_size, avctx, h->is_avc,\n                                h->nal_length_size, avctx->codec_id);\n    if (ret < 0) {\n        av_log(avctx, AV_LOG_ERROR,\n               "Error splitting the input into NAL units.\\n");\n        if (h->is_avc && !(avctx->err_recognition & AV_EF_EXPLODE)) {\n            int err = ff_h2645_packet_split(&h->pkt, buf, buf_size, avctx, 0, 0,\n                                            avctx->codec_id);\n            if (err >= 0) {\n                av_log(avctx, AV_LOG_WARNING,\n                       "The stream seems to contain AVCC extradata with Annex B "\n                       "formatted data, which is invalid.");\n                h->is_avc = 0;\n                ret       = 0;\n            }\n        }\n        if (ret < 0)\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_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,\n                          void *logctx, int is_nalff, int nal_length_size,\n                          enum AVCodecID codec_id)\n{\n    int consumed, ret = 0;\n    const uint8_t *next_avc = buf + (is_nalff ? 0 : length);\n    pkt->nb_nals = 0;\n    while (length >= 4) {\n        H2645NAL *nal;\n        int extract_length = 0;\n        int skip_trailing_zeros = 1;\n        if (buf == next_avc) {\n            int i;\n            for (i = 0; i < nal_length_size; i++)\n                extract_length = (extract_length << 8) | buf[i];\n            if (extract_length > length) {\n                av_log(logctx, AV_LOG_ERROR,\n                       "Invalid NAL unit size (%d > %d).\\n",\n                       extract_length, length);\n                return AVERROR_INVALIDDATA;\n            }\n            buf     += nal_length_size;\n            length  -= nal_length_size;\n            next_avc = buf + extract_length;\n        } else {\n            int buf_index = find_next_start_code(buf, next_avc);\n            buf    += buf_index;\n            length -= buf_index;\n            if (buf == next_avc)\n                continue;\n            if (length > 0) {\n                extract_length = length;\n            } else if (pkt->nb_nals == 0) {\n                av_log(logctx, AV_LOG_ERROR, "No NAL unit found\\n");\n                return AVERROR_INVALIDDATA;\n            } else {\n                break;\n            }\n        }\n        if (pkt->nals_allocated < pkt->nb_nals + 1) {\n            int new_size = pkt->nals_allocated + 1;\n            H2645NAL *tmp = av_realloc_array(pkt->nals, new_size, sizeof(*tmp));\n            if (!tmp)\n                return AVERROR(ENOMEM);\n            pkt->nals = tmp;\n            memset(pkt->nals + pkt->nals_allocated, 0,\n                   (new_size - pkt->nals_allocated) * sizeof(*tmp));\n            pkt->nals_allocated = new_size;\n        }\n        nal = &pkt->nals[pkt->nb_nals++];\n        consumed = ff_h2645_extract_rbsp(buf, extract_length, nal);\n        if (consumed < 0)\n            return consumed;\n        if (consumed < length - 3 &&\n            buf[consumed]     == 0x00 && buf[consumed + 1] == 0x00 &&\n            buf[consumed + 2] == 0x01 && buf[consumed + 3] == 0xE0)\n            skip_trailing_zeros = 0;\n        nal->size_bits = get_bit_length(nal, skip_trailing_zeros);\n        ret = init_get_bits(&nal->gb, nal->data, nal->size_bits);\n        if (ret < 0)\n            return ret;\n        if (codec_id == AV_CODEC_ID_HEVC)\n            ret = hevc_parse_nal_header(nal, logctx);\n        else\n            ret = h264_parse_nal_header(nal, logctx);\n        if (ret <= 0) {\n            if (ret < 0) {\n                av_log(logctx, AV_LOG_ERROR, "Invalid NAL unit %d, skipping.\\n",\n                       nal->type);\n            }\n            pkt->nb_nals--;\n        }\n        buf    += consumed;\n        length -= consumed;\n    }\n    return 0;\n}', 'static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,\n                                int bit_size)\n{\n    int buffer_size;\n    int ret = 0;\n    if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {\n        bit_size    = 0;\n        buffer      = NULL;\n        ret         = AVERROR_INVALIDDATA;\n    }\n    buffer_size = (bit_size + 7) >> 3;\n    s->buffer             = buffer;\n    s->size_in_bits       = bit_size;\n#if !UNCHECKED_BITSTREAM_READER\n    s->size_in_bits_plus8 = bit_size + 8;\n#endif\n    s->buffer_end         = buffer + buffer_size;\n    s->index              = 0;\n    return ret;\n}', 'int ff_h264_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 void loop_filter(const H264Context *h, H264SliceContext *sl, int start_x, int end_x)\n{\n    uint8_t *dest_y, *dest_cb, *dest_cr;\n    int linesize, uvlinesize, mb_x, mb_y;\n    const int end_mb_y       = sl->mb_y + FRAME_MBAFF(h);\n    const int old_slice_type = sl->slice_type;\n    const int pixel_shift    = h->pixel_shift;\n    const int block_h        = 16 >> h->chroma_y_shift;\n    if (h->postpone_filter)\n        return;\n    if (sl->deblocking_filter) {\n        for (mb_x = start_x; mb_x < end_x; mb_x++)\n            for (mb_y = end_mb_y - FRAME_MBAFF(h); mb_y <= end_mb_y; mb_y++) {\n                int mb_xy, mb_type;\n                mb_xy         = sl->mb_xy = mb_x + mb_y * h->mb_stride;\n                mb_type       = h->cur_pic.mb_type[mb_xy];\n                if (FRAME_MBAFF(h))\n                    sl->mb_mbaff               =\n                    sl->mb_field_decoding_flag = !!IS_INTERLACED(mb_type);\n                sl->mb_x = mb_x;\n                sl->mb_y = mb_y;\n                dest_y  = h->cur_pic.f->data[0] +\n                          ((mb_x << pixel_shift) + mb_y * sl->linesize) * 16;\n                dest_cb = h->cur_pic.f->data[1] +\n                          (mb_x << pixel_shift) * (8 << CHROMA444(h)) +\n                          mb_y * sl->uvlinesize * block_h;\n                dest_cr = h->cur_pic.f->data[2] +\n                          (mb_x << pixel_shift) * (8 << CHROMA444(h)) +\n                          mb_y * sl->uvlinesize * block_h;\n                if (MB_FIELD(sl)) {\n                    linesize   = sl->mb_linesize   = sl->linesize   * 2;\n                    uvlinesize = sl->mb_uvlinesize = sl->uvlinesize * 2;\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                } else {\n                    linesize   = sl->mb_linesize   = sl->linesize;\n                    uvlinesize = sl->mb_uvlinesize = sl->uvlinesize;\n                }\n                backup_mb_border(h, sl, dest_y, dest_cb, dest_cr, linesize,\n                                 uvlinesize, 0);\n                if (fill_filter_caches(h, sl, mb_type))\n                    continue;\n                sl->chroma_qp[0] = get_chroma_qp(h->ps.pps, 0, h->cur_pic.qscale_table[mb_xy]);\n                sl->chroma_qp[1] = get_chroma_qp(h->ps.pps, 1, h->cur_pic.qscale_table[mb_xy]);\n                if (FRAME_MBAFF(h)) {\n                    ff_h264_filter_mb(h, sl, mb_x, mb_y, dest_y, dest_cb, dest_cr,\n                                      linesize, uvlinesize);\n                } else {\n                    ff_h264_filter_mb_fast(h, sl, mb_x, mb_y, dest_y, dest_cb,\n                                           dest_cr, linesize, uvlinesize);\n                }\n            }\n    }\n    sl->slice_type  = old_slice_type;\n    sl->mb_x         = end_x;\n    sl->mb_y         = end_mb_y - FRAME_MBAFF(h);\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}', 'static int fill_filter_caches(const H264Context *h, H264SliceContext *sl, int mb_type)\n{\n    const int mb_xy = sl->mb_xy;\n    int top_xy, left_xy[LEFT_MBS];\n    int top_type, left_type[LEFT_MBS];\n    uint8_t *nnz;\n    uint8_t *nnz_cache;\n    top_xy = mb_xy - (h->mb_stride << MB_FIELD(sl));\n    left_xy[LBOT] = left_xy[LTOP] = mb_xy - 1;\n    if (FRAME_MBAFF(h)) {\n        const int left_mb_field_flag = IS_INTERLACED(h->cur_pic.mb_type[mb_xy - 1]);\n        const int curr_mb_field_flag = IS_INTERLACED(mb_type);\n        if (sl->mb_y & 1) {\n            if (left_mb_field_flag != curr_mb_field_flag)\n                left_xy[LTOP] -= h->mb_stride;\n        } else {\n            if (curr_mb_field_flag)\n                top_xy += h->mb_stride &\n                          (((h->cur_pic.mb_type[top_xy] >> 7) & 1) - 1);\n            if (left_mb_field_flag != curr_mb_field_flag)\n                left_xy[LBOT] += h->mb_stride;\n        }\n    }\n    sl->top_mb_xy        = top_xy;\n    sl->left_mb_xy[LTOP] = left_xy[LTOP];\n    sl->left_mb_xy[LBOT] = left_xy[LBOT];\n    {\n        int qp_thresh = sl->qp_thresh;\n        int qp        = h->cur_pic.qscale_table[mb_xy];\n        if (qp <= qp_thresh &&\n            (left_xy[LTOP] < 0 ||\n             ((qp + h->cur_pic.qscale_table[left_xy[LTOP]] + 1) >> 1) <= qp_thresh) &&\n            (top_xy < 0 ||\n             ((qp + h->cur_pic.qscale_table[top_xy] + 1) >> 1) <= qp_thresh)) {\n            if (!FRAME_MBAFF(h))\n                return 1;\n            if ((left_xy[LTOP] < 0 ||\n                 ((qp + h->cur_pic.qscale_table[left_xy[LBOT]] + 1) >> 1) <= qp_thresh) &&\n                (top_xy < h->mb_stride ||\n                 ((qp + h->cur_pic.qscale_table[top_xy - h->mb_stride] + 1) >> 1) <= qp_thresh))\n                return 1;\n        }\n    }\n    top_type        = h->cur_pic.mb_type[top_xy];\n    left_type[LTOP] = h->cur_pic.mb_type[left_xy[LTOP]];\n    left_type[LBOT] = h->cur_pic.mb_type[left_xy[LBOT]];\n    if (sl->deblocking_filter == 2) {\n        if (h->slice_table[top_xy] != sl->slice_num)\n            top_type = 0;\n        if (h->slice_table[left_xy[LBOT]] != sl->slice_num)\n            left_type[LTOP] = left_type[LBOT] = 0;\n    } else {\n        if (h->slice_table[top_xy] == 0xFFFF)\n            top_type = 0;\n        if (h->slice_table[left_xy[LBOT]] == 0xFFFF)\n            left_type[LTOP] = left_type[LBOT] = 0;\n    }\n    sl->top_type        = top_type;\n    sl->left_type[LTOP] = left_type[LTOP];\n    sl->left_type[LBOT] = left_type[LBOT];\n    if (IS_INTRA(mb_type))\n        return 0;\n    fill_filter_caches_inter(h, sl, mb_type, top_xy, left_xy,\n                             top_type, left_type, mb_xy, 0);\n    if (sl->list_count == 2)\n        fill_filter_caches_inter(h, sl, mb_type, top_xy, left_xy,\n                                 top_type, left_type, mb_xy, 1);\n    nnz       = h->non_zero_count[mb_xy];\n    nnz_cache = sl->non_zero_count_cache;\n    AV_COPY32(&nnz_cache[4 + 8 * 1], &nnz[0]);\n    AV_COPY32(&nnz_cache[4 + 8 * 2], &nnz[4]);\n    AV_COPY32(&nnz_cache[4 + 8 * 3], &nnz[8]);\n    AV_COPY32(&nnz_cache[4 + 8 * 4], &nnz[12]);\n    sl->cbp = h->cbp_table[mb_xy];\n    if (top_type) {\n        nnz = h->non_zero_count[top_xy];\n        AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[3 * 4]);\n    }\n    if (left_type[LTOP]) {\n        nnz = h->non_zero_count[left_xy[LTOP]];\n        nnz_cache[3 + 8 * 1] = nnz[3 + 0 * 4];\n        nnz_cache[3 + 8 * 2] = nnz[3 + 1 * 4];\n        nnz_cache[3 + 8 * 3] = nnz[3 + 2 * 4];\n        nnz_cache[3 + 8 * 4] = nnz[3 + 3 * 4];\n    }\n    if (!CABAC(h) && h->ps.pps->transform_8x8_mode) {\n        if (IS_8x8DCT(top_type)) {\n            nnz_cache[4 + 8 * 0] =\n            nnz_cache[5 + 8 * 0] = (h->cbp_table[top_xy] & 0x4000) >> 12;\n            nnz_cache[6 + 8 * 0] =\n            nnz_cache[7 + 8 * 0] = (h->cbp_table[top_xy] & 0x8000) >> 12;\n        }\n        if (IS_8x8DCT(left_type[LTOP])) {\n            nnz_cache[3 + 8 * 1] =\n            nnz_cache[3 + 8 * 2] = (h->cbp_table[left_xy[LTOP]] & 0x2000) >> 12;\n        }\n        if (IS_8x8DCT(left_type[LBOT])) {\n            nnz_cache[3 + 8 * 3] =\n            nnz_cache[3 + 8 * 4] = (h->cbp_table[left_xy[LBOT]] & 0x8000) >> 12;\n        }\n        if (IS_8x8DCT(mb_type)) {\n            nnz_cache[scan8[0]] =\n            nnz_cache[scan8[1]] =\n            nnz_cache[scan8[2]] =\n            nnz_cache[scan8[3]] = (sl->cbp & 0x1000) >> 12;\n            nnz_cache[scan8[0 + 4]] =\n            nnz_cache[scan8[1 + 4]] =\n            nnz_cache[scan8[2 + 4]] =\n            nnz_cache[scan8[3 + 4]] = (sl->cbp & 0x2000) >> 12;\n            nnz_cache[scan8[0 + 8]] =\n            nnz_cache[scan8[1 + 8]] =\n            nnz_cache[scan8[2 + 8]] =\n            nnz_cache[scan8[3 + 8]] = (sl->cbp & 0x4000) >> 12;\n            nnz_cache[scan8[0 + 12]] =\n            nnz_cache[scan8[1 + 12]] =\n            nnz_cache[scan8[2 + 12]] =\n            nnz_cache[scan8[3 + 12]] = (sl->cbp & 0x8000) >> 12;\n        }\n    }\n    return 0;\n}']