libavcodec/h264.c:1058: error: Integer Overflow L2
  ([0, 4294967311] + 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->ref_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:854:24: Call
  852.             sl->gb = nal->gb;
  853. 
  854.             if ((err = ff_h264_decode_slice_header(h, sl)))
                              ^
  855.                 break;
  856. 

libavcodec/h264_slice.c:1422:1: Parameter `sl->ref_count[*]`
    1420.  * @return 0 if okay, <0 if an error occurred
    1421.  */
    1422. int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl)
          ^
    1423. {
    1424.     int i, j, ret = 0;

libavcodec/h264_slice.c:1426:11: Call
    1424.     int i, j, ret = 0;
    1425. 
    1426.     ret = h264_slice_header_parse(h, sl);
                    ^
    1427.     if (ret < 0)
    1428.         return ret;

libavcodec/h264_slice.c:1166:1: Parameter `sl->ref_count[*]`
      1164. }
      1165. 
      1166. static int h264_slice_header_parse(H264Context *h, H264SliceContext *sl)
            ^
      1167. {
      1168.     const SPS *sps;

libavcodec/h264_slice.c:1473:5: Call
    1471.     if (sl->slice_type_nos == AV_PICTURE_TYPE_B && !sl->direct_spatial_mv_pred)
    1472.         ff_h264_direct_dist_scale_factor(h, sl);
    1473.     ff_h264_direct_ref_list_init(h, sl);
              ^
    1474. 
    1475.     if (h->avctx->skip_loop_filter >= AVDISCARD_ALL ||

libavcodec/h264_direct.c:110:1: Parameter `sl->ref_count[*]`
      108. }
      109. 
      110. void ff_h264_direct_ref_list_init(const H264Context *const h, H264SliceContext *sl)
           ^
      111. {
      112.     H264Ref *const ref1 = &sl->ref_list[1][0];

libavcodec/h264_direct.c:154:9: Call
      152. 
      153.     for (list = 0; list < 2; list++) {
      154.         fill_colmap(h, sl, sl->map_col_to_list0, list, sidx, ref1sidx, 0);
                   ^
      155.         if (FRAME_MBAFF(h))
      156.             for (field = 0; field < 2; field++)

libavcodec/h264_direct.c:72:1: <LHS trace>
70. }
71. 
72. static void fill_colmap(const H264Context *h, H264SliceContext *sl,
    ^
73.                         int map[2][16 + 32], int list,
74.                         int field, int colfield, int mbafi)

libavcodec/h264_direct.c:72:1: Parameter `sl->ref_count[*]`
        70. }
        71. 
        72. static void fill_colmap(const H264Context *h, H264SliceContext *sl,
            ^
        73.                         int map[2][16 + 32], int list,
        74.                         int field, int colfield, int mbafi)

libavcodec/h264_direct.c:79:18: Assignment
        77.     int j, old_ref, rfield;
        78.     int start  = mbafi ? 16                       : 0;
        79.     int end    = mbafi ? 16 + 2 * sl->ref_count[0] : sl->ref_count[0];
                             ^
        80.     int interl = mbafi || h->picture_structure != PICT_FRAME;
        81. 

libavcodec/h264_direct.c:79:5: Assignment
        77.     int j, old_ref, rfield;
        78.     int start  = mbafi ? 16                       : 0;
        79.     int end    = mbafi ? 16 + 2 * sl->ref_count[0] : sl->ref_count[0];
                ^
        80.     int interl = mbafi || h->picture_structure != PICT_FRAME;
        81. 

libavcodec/h264_direct.c:95:38: Binary operation: ([0, 4294967311] + 1):signed32 by call to `decode_nal_units` 
        93.                 poc = (poc & ~3) + rfield + 1;
        94. 
        95.             for (j = start; j < end; j++) {
                                                 ^
        96.                 if (4 * sl->ref_list[0][j].parent->frame_num +
        97.                     (sl->ref_list[0][j].reference & 3) == poc) {

static void fill_colmap(const H264Context *h, H264SliceContext *sl,
                        int map[2][16 + 32], int list,
                        int field, int colfield, int mbafi)
{
    H264Picture *const ref1 = sl->ref_list[1][0].parent;
    int j, old_ref, rfield;
    int start  = mbafi ? 16                       : 0;
    int end    = mbafi ? 16 + 2 * sl->ref_count[0] : sl->ref_count[0];
    int interl = mbafi || h->picture_structure != PICT_FRAME;
    memset(map[list], 0, sizeof(map[list]));
    for (rfield = 0; rfield < 2; rfield++) {
        for (old_ref = 0; old_ref < ref1->ref_count[colfield][list]; old_ref++) {
            int poc = ref1->ref_poc[colfield][list][old_ref];
            if (!interl)
                poc |= 3;
            else if (interl && (poc & 3) == 3)
                poc = (poc & ~3) + rfield + 1;
            for (j = start; j < end; j++) {
                if (4 * sl->ref_list[0][j].parent->frame_num +
                    (sl->ref_list[0][j].reference & 3) == poc) {
                    int cur_ref = mbafi ? (j - 16) ^ field : j;
                    if (ref1->mbaff)
                        map[list][2 * old_ref + (rfield ^ field) + 16] = cur_ref;
                    if (rfield == field || !interl)
                        map[list][old_ref] = cur_ref;
                    break;
                }
            }
        }
    }
}
['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_decode_slice_header(H264Context *h, H264SliceContext *sl)\n{\n    int i, j, ret = 0;\n    ret = h264_slice_header_parse(h, sl);\n    if (ret < 0)\n        return ret;\n    if (h->current_slice == 0) {\n        ret = h264_field_start(h, sl);\n        if (ret < 0)\n            return ret;\n    }\n    assert(h->mb_num == h->mb_width * h->mb_height);\n    if (sl->first_mb_addr << FIELD_OR_MBAFF_PICTURE(h) >= h->mb_num ||\n        sl->first_mb_addr >= h->mb_num) {\n        av_log(h->avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    sl->resync_mb_x = sl->mb_x =  sl->first_mb_addr % h->mb_width;\n    sl->resync_mb_y = sl->mb_y = (sl->first_mb_addr / h->mb_width) <<\n                                 FIELD_OR_MBAFF_PICTURE(h);\n    if (h->picture_structure == PICT_BOTTOM_FIELD)\n        sl->resync_mb_y = sl->mb_y = sl->mb_y + 1;\n    assert(sl->mb_y < h->mb_height);\n    if (!h->setup_finished) {\n        ff_h264_init_poc(h->cur_pic_ptr->field_poc, &h->cur_pic_ptr->poc,\n                         h->ps.sps, &h->poc, h->picture_structure, h->nal_ref_idc);\n        memcpy(h->mmco, sl->mmco, sl->nb_mmco * sizeof(*h->mmco));\n        h->nb_mmco = sl->nb_mmco;\n        h->explicit_ref_marking = sl->explicit_ref_marking;\n    }\n    ret = ff_h264_build_ref_list(h, sl);\n    if (ret < 0)\n        return ret;\n    if (h->ps.pps->weighted_bipred_idc == 2 &&\n        sl->slice_type_nos == AV_PICTURE_TYPE_B) {\n        implicit_weight_table(h, sl, -1);\n        if (FRAME_MBAFF(h)) {\n            implicit_weight_table(h, sl, 0);\n            implicit_weight_table(h, sl, 1);\n        }\n    }\n    if (sl->slice_type_nos == AV_PICTURE_TYPE_B && !sl->direct_spatial_mv_pred)\n        ff_h264_direct_dist_scale_factor(h, sl);\n    ff_h264_direct_ref_list_init(h, sl);\n    if (h->avctx->skip_loop_filter >= AVDISCARD_ALL ||\n        (h->avctx->skip_loop_filter >= AVDISCARD_NONKEY &&\n         sl->slice_type_nos != AV_PICTURE_TYPE_I) ||\n        (h->avctx->skip_loop_filter >= AVDISCARD_BIDIR  &&\n         sl->slice_type_nos == AV_PICTURE_TYPE_B) ||\n        (h->avctx->skip_loop_filter >= AVDISCARD_NONREF &&\n         h->nal_ref_idc == 0))\n        sl->deblocking_filter = 0;\n    if (sl->deblocking_filter == 1 && h->nb_slice_ctx > 1) {\n        if (h->avctx->flags2 & AV_CODEC_FLAG2_FAST) {\n            sl->deblocking_filter = 2;\n        } else {\n            h->postpone_filter = 1;\n        }\n    }\n    sl->qp_thresh = 15 -\n                   FFMIN(sl->slice_alpha_c0_offset, sl->slice_beta_offset) -\n                   FFMAX3(0,\n                          h->ps.pps->chroma_qp_index_offset[0],\n                          h->ps.pps->chroma_qp_index_offset[1]) +\n                   6 * (h->ps.sps->bit_depth_luma - 8);\n    sl->slice_num       = ++h->current_slice;\n    if (sl->slice_num >= MAX_SLICES) {\n        av_log(h->avctx, AV_LOG_ERROR,\n               "Too many slices, increase MAX_SLICES and recompile\\n");\n    }\n    for (j = 0; j < 2; j++) {\n        int id_list[16];\n        int *ref2frm = h->ref2frm[sl->slice_num & (MAX_SLICES - 1)][j];\n        for (i = 0; i < 16; i++) {\n            id_list[i] = 60;\n            if (j < sl->list_count && i < sl->ref_count[j] &&\n                sl->ref_list[j][i].parent->f->buf[0]) {\n                int k;\n                AVBuffer *buf = sl->ref_list[j][i].parent->f->buf[0]->buffer;\n                for (k = 0; k < h->short_ref_count; k++)\n                    if (h->short_ref[k]->f->buf[0]->buffer == buf) {\n                        id_list[i] = k;\n                        break;\n                    }\n                for (k = 0; k < h->long_ref_count; k++)\n                    if (h->long_ref[k] && h->long_ref[k]->f->buf[0]->buffer == buf) {\n                        id_list[i] = h->short_ref_count + k;\n                        break;\n                    }\n            }\n        }\n        ref2frm[0] =\n        ref2frm[1] = -1;\n        for (i = 0; i < 16; i++)\n            ref2frm[i + 2] = 4 * id_list[i] + (sl->ref_list[j][i].reference & 3);\n        ref2frm[18 + 0] =\n        ref2frm[18 + 1] = -1;\n        for (i = 16; i < 48; i++)\n            ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] +\n                             (sl->ref_list[j][i].reference & 3);\n    }\n    if (h->avctx->debug & FF_DEBUG_PICT_INFO) {\n        av_log(h->avctx, AV_LOG_DEBUG,\n               "slice:%d %s mb:%d %c%s%s frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\\n",\n               sl->slice_num,\n               (h->picture_structure == PICT_FRAME ? "F" : h->picture_structure == PICT_TOP_FIELD ? "T" : "B"),\n               sl->mb_y * h->mb_width + sl->mb_x,\n               av_get_picture_type_char(sl->slice_type),\n               sl->slice_type_fixed ? " fix" : "",\n               h->nal_unit_type == NAL_IDR_SLICE ? " IDR" : "",\n               h->poc.frame_num,\n               h->cur_pic_ptr->field_poc[0],\n               h->cur_pic_ptr->field_poc[1],\n               sl->ref_count[0], sl->ref_count[1],\n               sl->qscale,\n               sl->deblocking_filter,\n               sl->slice_alpha_c0_offset, sl->slice_beta_offset,\n               sl->pwt.use_weight,\n               sl->pwt.use_weight == 1 && sl->pwt.use_weight_chroma ? "c" : "",\n               sl->slice_type == AV_PICTURE_TYPE_B ? (sl->direct_spatial_mv_pred ? "SPAT" : "TEMP") : "");\n    }\n    return 0;\n}', 'static int h264_slice_header_parse(H264Context *h, H264SliceContext *sl)\n{\n    const SPS *sps;\n    const PPS *pps;\n    int ret;\n    unsigned int slice_type, tmp, i;\n    int field_pic_flag, bottom_field_flag;\n    int frame_num, droppable, picture_structure;\n    int mb_aff_frame = 0;\n    sl->first_mb_addr = get_ue_golomb(&sl->gb);\n    if (sl->first_mb_addr == 0) {\n        if (h->current_slice && h->cur_pic_ptr && FIELD_PICTURE(h)) {\n            ff_h264_field_end(h, sl, 1);\n        }\n        h->current_slice = 0;\n        if (!h->first_field) {\n            if (h->cur_pic_ptr && !h->droppable) {\n                ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,\n                                          h->picture_structure == PICT_BOTTOM_FIELD);\n            }\n            h->cur_pic_ptr = NULL;\n        }\n    }\n    slice_type = get_ue_golomb_31(&sl->gb);\n    if (slice_type > 9) {\n        av_log(h->avctx, AV_LOG_ERROR,\n               "slice type %d too large at %d\\n",\n               slice_type, sl->first_mb_addr);\n        return AVERROR_INVALIDDATA;\n    }\n    if (slice_type > 4) {\n        slice_type -= 5;\n        sl->slice_type_fixed = 1;\n    } else\n        sl->slice_type_fixed = 0;\n    slice_type         = ff_h264_golomb_to_pict_type[slice_type];\n    sl->slice_type     = slice_type;\n    sl->slice_type_nos = slice_type & 3;\n    if (h->nal_unit_type  == NAL_IDR_SLICE &&\n        sl->slice_type_nos != AV_PICTURE_TYPE_I) {\n        av_log(h->avctx, AV_LOG_ERROR, "A non-intra slice in an IDR NAL unit.\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    sl->pps_id = get_ue_golomb(&sl->gb);\n    if (sl->pps_id >= MAX_PPS_COUNT) {\n        av_log(h->avctx, AV_LOG_ERROR, "pps_id %u out of range\\n", sl->pps_id);\n        return AVERROR_INVALIDDATA;\n    }\n    if (!h->ps.pps_list[sl->pps_id]) {\n        av_log(h->avctx, AV_LOG_ERROR,\n               "non-existing PPS %u referenced\\n",\n               sl->pps_id);\n        return AVERROR_INVALIDDATA;\n    }\n    if (h->current_slice > 0 &&\n        h->ps.pps != (const PPS*)h->ps.pps_list[sl->pps_id]->data) {\n        av_log(h->avctx, AV_LOG_ERROR, "PPS changed between slices\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    pps = (const PPS*)h->ps.pps_list[sl->pps_id]->data;\n    if (!h->ps.sps_list[pps->sps_id]) {\n        av_log(h->avctx, AV_LOG_ERROR,\n               "non-existing SPS %u referenced\\n", pps->sps_id);\n        return AVERROR_INVALIDDATA;\n    }\n    sps = (const SPS*)h->ps.sps_list[pps->sps_id]->data;\n    frame_num = get_bits(&sl->gb, sps->log2_max_frame_num);\n    if (!h->setup_finished)\n        h->poc.frame_num = frame_num;\n    sl->mb_mbaff       = 0;\n    droppable = h->nal_ref_idc == 0;\n    if (sps->frame_mbs_only_flag) {\n        picture_structure = PICT_FRAME;\n    } else {\n        field_pic_flag = get_bits1(&sl->gb);\n        if (field_pic_flag) {\n            bottom_field_flag = get_bits1(&sl->gb);\n            picture_structure = PICT_TOP_FIELD + bottom_field_flag;\n        } else {\n            picture_structure = PICT_FRAME;\n            mb_aff_frame      = sps->mb_aff;\n        }\n    }\n    if (!h->setup_finished) {\n        h->mb_aff_frame      = mb_aff_frame;\n    }\n    sl->picture_structure      = picture_structure;\n    sl->mb_field_decoding_flag = picture_structure != PICT_FRAME;\n    if (h->current_slice != 0) {\n        if (h->picture_structure != picture_structure ||\n            h->droppable         != droppable) {\n            av_log(h->avctx, AV_LOG_ERROR,\n                   "Changing field mode (%d -> %d) between slices is not allowed\\n",\n                   h->picture_structure, picture_structure);\n            return AVERROR_INVALIDDATA;\n        } else if (!h->cur_pic_ptr) {\n            av_log(h->avctx, AV_LOG_ERROR,\n                   "unset cur_pic_ptr on slice %d\\n",\n                   h->current_slice + 1);\n            return AVERROR_INVALIDDATA;\n        }\n    }\n    if (picture_structure == PICT_FRAME) {\n        h->curr_pic_num = h->poc.frame_num;\n        h->max_pic_num  = 1 << sps->log2_max_frame_num;\n    } else {\n        h->curr_pic_num = 2 * h->poc.frame_num + 1;\n        h->max_pic_num  = 1 << (sps->log2_max_frame_num + 1);\n    }\n    if (h->nal_unit_type == NAL_IDR_SLICE)\n        get_ue_golomb(&sl->gb);\n    if (sps->poc_type == 0) {\n        int poc_lsb = get_bits(&sl->gb, sps->log2_max_poc_lsb);\n        if (!h->setup_finished)\n            h->poc.poc_lsb = poc_lsb;\n        if (pps->pic_order_present == 1 && picture_structure == PICT_FRAME) {\n            int delta_poc_bottom = get_se_golomb(&sl->gb);\n            if (!h->setup_finished)\n                h->poc.delta_poc_bottom = delta_poc_bottom;\n        }\n    }\n    if (sps->poc_type == 1 && !sps->delta_pic_order_always_zero_flag) {\n        int delta_poc = get_se_golomb(&sl->gb);\n        if (!h->setup_finished)\n            h->poc.delta_poc[0] = delta_poc;\n        if (pps->pic_order_present == 1 && picture_structure == PICT_FRAME) {\n            delta_poc = get_se_golomb(&sl->gb);\n            if (!h->setup_finished)\n                h->poc.delta_poc[1] = delta_poc;\n        }\n    }\n    if (pps->redundant_pic_cnt_present)\n        sl->redundant_pic_count = get_ue_golomb(&sl->gb);\n    if (sl->slice_type_nos == AV_PICTURE_TYPE_B)\n        sl->direct_spatial_mv_pred = get_bits1(&sl->gb);\n    ret = ff_h264_parse_ref_count(&sl->list_count, sl->ref_count,\n                                  &sl->gb, pps, sl->slice_type_nos,\n                                  picture_structure);\n    if (ret < 0)\n        return ret;\n    if (sl->slice_type_nos != AV_PICTURE_TYPE_I) {\n       ret = ff_h264_decode_ref_pic_list_reordering(h, sl);\n       if (ret < 0) {\n           sl->ref_count[1] = sl->ref_count[0] = 0;\n           return ret;\n       }\n    }\n    sl->pwt.use_weight = 0;\n    for (i = 0; i < 2; i++) {\n        sl->pwt.luma_weight_flag[i]   = 0;\n        sl->pwt.chroma_weight_flag[i] = 0;\n    }\n    if ((pps->weighted_pred && sl->slice_type_nos == AV_PICTURE_TYPE_P) ||\n        (pps->weighted_bipred_idc == 1 &&\n         sl->slice_type_nos == AV_PICTURE_TYPE_B))\n        ff_h264_pred_weight_table(&sl->gb, sps, sl->ref_count,\n                                  sl->slice_type_nos, &sl->pwt);\n    sl->explicit_ref_marking = 0;\n    if (h->nal_ref_idc) {\n        ret = ff_h264_decode_ref_pic_marking(h, sl, &sl->gb);\n        if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n            return AVERROR_INVALIDDATA;\n    }\n    if (sl->slice_type_nos != AV_PICTURE_TYPE_I && pps->cabac) {\n        tmp = get_ue_golomb_31(&sl->gb);\n        if (tmp > 2) {\n            av_log(h->avctx, AV_LOG_ERROR, "cabac_init_idc %u overflow\\n", tmp);\n            return AVERROR_INVALIDDATA;\n        }\n        sl->cabac_init_idc = tmp;\n    }\n    sl->last_qscale_diff = 0;\n    tmp = pps->init_qp + get_se_golomb(&sl->gb);\n    if (tmp > 51 + 6 * (sps->bit_depth_luma - 8)) {\n        av_log(h->avctx, AV_LOG_ERROR, "QP %u out of range\\n", tmp);\n        return AVERROR_INVALIDDATA;\n    }\n    sl->qscale       = tmp;\n    sl->chroma_qp[0] = get_chroma_qp(pps, 0, sl->qscale);\n    sl->chroma_qp[1] = get_chroma_qp(pps, 1, sl->qscale);\n    if (sl->slice_type == AV_PICTURE_TYPE_SP)\n        get_bits1(&sl->gb);\n    if (sl->slice_type == AV_PICTURE_TYPE_SP ||\n        sl->slice_type == AV_PICTURE_TYPE_SI)\n        get_se_golomb(&sl->gb);\n    sl->deblocking_filter     = 1;\n    sl->slice_alpha_c0_offset = 0;\n    sl->slice_beta_offset     = 0;\n    if (pps->deblocking_filter_parameters_present) {\n        tmp = get_ue_golomb_31(&sl->gb);\n        if (tmp > 2) {\n            av_log(h->avctx, AV_LOG_ERROR,\n                   "deblocking_filter_idc %u out of range\\n", tmp);\n            return AVERROR_INVALIDDATA;\n        }\n        sl->deblocking_filter = tmp;\n        if (sl->deblocking_filter < 2)\n            sl->deblocking_filter ^= 1;\n        if (sl->deblocking_filter) {\n            sl->slice_alpha_c0_offset = get_se_golomb(&sl->gb) * 2;\n            sl->slice_beta_offset     = get_se_golomb(&sl->gb) * 2;\n            if (sl->slice_alpha_c0_offset >  12 ||\n                sl->slice_alpha_c0_offset < -12 ||\n                sl->slice_beta_offset >  12     ||\n                sl->slice_beta_offset < -12) {\n                av_log(h->avctx, AV_LOG_ERROR,\n                       "deblocking filter parameters %d %d out of range\\n",\n                       sl->slice_alpha_c0_offset, sl->slice_beta_offset);\n                return AVERROR_INVALIDDATA;\n            }\n        }\n    }\n    return 0;\n}', 'void ff_h264_direct_ref_list_init(const H264Context *const h, H264SliceContext *sl)\n{\n    H264Ref *const ref1 = &sl->ref_list[1][0];\n    H264Picture *const cur = h->cur_pic_ptr;\n    int list, j, field;\n    int sidx     = (h->picture_structure & 1) ^ 1;\n    int ref1sidx = (ref1->reference      & 1) ^ 1;\n    for (list = 0; list < sl->list_count; list++) {\n        cur->ref_count[sidx][list] = sl->ref_count[list];\n        for (j = 0; j < sl->ref_count[list]; j++)\n            cur->ref_poc[sidx][list][j] = 4 * sl->ref_list[list][j].parent->frame_num +\n                                          (sl->ref_list[list][j].reference & 3);\n    }\n    if (h->picture_structure == PICT_FRAME) {\n        memcpy(cur->ref_count[1], cur->ref_count[0], sizeof(cur->ref_count[0]));\n        memcpy(cur->ref_poc[1],   cur->ref_poc[0],   sizeof(cur->ref_poc[0]));\n    }\n    cur->mbaff = FRAME_MBAFF(h);\n    sl->col_fieldoff = 0;\n    if (sl->list_count != 2 || !sl->ref_count[1])\n        return;\n    if (h->picture_structure == PICT_FRAME) {\n        int cur_poc  = h->cur_pic_ptr->poc;\n        int *col_poc = sl->ref_list[1][0].parent->field_poc;\n        sl->col_parity = (FFABS(col_poc[0] - cur_poc) >=\n                          FFABS(col_poc[1] - cur_poc));\n        ref1sidx =\n        sidx     = sl->col_parity;\n    } else if (!(h->picture_structure & sl->ref_list[1][0].reference) &&\n               !sl->ref_list[1][0].parent->mbaff) {\n        sl->col_fieldoff = 2 * sl->ref_list[1][0].reference - 3;\n    }\n    if (sl->slice_type_nos != AV_PICTURE_TYPE_B || sl->direct_spatial_mv_pred)\n        return;\n    for (list = 0; list < 2; list++) {\n        fill_colmap(h, sl, sl->map_col_to_list0, list, sidx, ref1sidx, 0);\n        if (FRAME_MBAFF(h))\n            for (field = 0; field < 2; field++)\n                fill_colmap(h, sl, sl->map_col_to_list0_field[field], list, field,\n                            field, 1);\n    }\n}', 'static void fill_colmap(const H264Context *h, H264SliceContext *sl,\n                        int map[2][16 + 32], int list,\n                        int field, int colfield, int mbafi)\n{\n    H264Picture *const ref1 = sl->ref_list[1][0].parent;\n    int j, old_ref, rfield;\n    int start  = mbafi ? 16                       : 0;\n    int end    = mbafi ? 16 + 2 * sl->ref_count[0] : sl->ref_count[0];\n    int interl = mbafi || h->picture_structure != PICT_FRAME;\n    memset(map[list], 0, sizeof(map[list]));\n    for (rfield = 0; rfield < 2; rfield++) {\n        for (old_ref = 0; old_ref < ref1->ref_count[colfield][list]; old_ref++) {\n            int poc = ref1->ref_poc[colfield][list][old_ref];\n            if (!interl)\n                poc |= 3;\n            else if (interl && (poc & 3) == 3)\n                poc = (poc & ~3) + rfield + 1;\n            for (j = start; j < end; j++) {\n                if (4 * sl->ref_list[0][j].parent->frame_num +\n                    (sl->ref_list[0][j].reference & 3) == poc) {\n                    int cur_ref = mbafi ? (j - 16) ^ field : j;\n                    if (ref1->mbaff)\n                        map[list][2 * old_ref + (rfield ^ field) + 16] = cur_ref;\n                    if (rfield == field || !interl)\n                        map[list][old_ref] = cur_ref;\n                    break;\n                }\n            }\n        }\n    }\n}']