libavcodec/h264_slice.c:1669: error: Buffer Overrun L2
  Offset: [16, 47] Size: 32.

libavcodec/h264_slice.c:1667:14: <Offset trace>
1665.         ref2frm[18 + 0] =
1666.         ref2frm[18 + 1] = -1;
1667.         for (i = 16; i < 48; i++)
                   ^
1668.             ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] +
1669.                              (sl->ref_list[j][i].reference & 3);

libavcodec/h264_slice.c:1667:14: Assignment
1665.         ref2frm[18 + 0] =
1666.         ref2frm[18 + 1] = -1;
1667.         for (i = 16; i < 48; i++)
                   ^
1668.             ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] +
1669.                              (sl->ref_list[j][i].reference & 3);

libavcodec/h264_slice.c:1067:1: <Length trace>
1065.  * @return 0 if okay, <0 if an error occurred, 1 if decoding must not be multithreaded
1066.  */
1067. int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl)
      ^
1068. {
1069.     unsigned int first_mb_in_slice;

libavcodec/h264_slice.c:1067:1: Parameter `sl->ref_list[*][*]`
1065.  * @return 0 if okay, <0 if an error occurred, 1 if decoding must not be multithreaded
1066.  */
1067. int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl)
      ^
1068. {
1069.     unsigned int first_mb_in_slice;

libavcodec/h264_slice.c:1669:31: Array access: Offset: [16, 47] Size: 32
1667.         for (i = 16; i < 48; i++)
1668.             ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] +
1669.                              (sl->ref_list[j][i].reference & 3);
                                    ^
1670.     }
1671. 

int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl)
{
    unsigned int first_mb_in_slice;
    unsigned int pps_id;
    int ret;
    unsigned int slice_type, tmp, i, j;
    int default_ref_list_done = 0;
    int last_pic_structure, last_pic_droppable;
    int needs_reinit = 0;
    int field_pic_flag, bottom_field_flag;
    h->qpel_put = h->h264qpel.put_h264_qpel_pixels_tab;
    h->qpel_avg = h->h264qpel.avg_h264_qpel_pixels_tab;
    first_mb_in_slice = get_ue_golomb(&sl->gb);
    if (first_mb_in_slice == 0) {
        if (h->current_slice && h->cur_pic_ptr && FIELD_PICTURE(h)) {
            ff_h264_field_end(h, sl, 1);
        }
        h->current_slice = 0;
        if (!h->first_field) {
            if (h->cur_pic_ptr && !h->droppable) {
                ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,
                                          h->picture_structure == PICT_BOTTOM_FIELD);
            }
            h->cur_pic_ptr = NULL;
        }
    }
    slice_type = get_ue_golomb_31(&sl->gb);
    if (slice_type > 9) {
        av_log(h->avctx, AV_LOG_ERROR,
               "slice type %d too large at %d\n",
               slice_type, first_mb_in_slice);
        return AVERROR_INVALIDDATA;
    }
    if (slice_type > 4) {
        slice_type -= 5;
        sl->slice_type_fixed = 1;
    } else
        sl->slice_type_fixed = 0;
    slice_type = golomb_to_pict_type[slice_type];
    if (slice_type == AV_PICTURE_TYPE_I ||
        (h->current_slice != 0 && slice_type == h->last_slice_type)) {
        default_ref_list_done = 1;
    }
    sl->slice_type     = slice_type;
    sl->slice_type_nos = slice_type & 3;
    if (h->nal_unit_type  == NAL_IDR_SLICE &&
        sl->slice_type_nos != AV_PICTURE_TYPE_I) {
        av_log(h->avctx, AV_LOG_ERROR, "A non-intra slice in an IDR NAL unit.\n");
        return AVERROR_INVALIDDATA;
    }
    h->pict_type = sl->slice_type;
    pps_id = get_ue_golomb(&sl->gb);
    if (pps_id >= MAX_PPS_COUNT) {
        av_log(h->avctx, AV_LOG_ERROR, "pps_id %u out of range\n", pps_id);
        return AVERROR_INVALIDDATA;
    }
    if (!h->pps_buffers[pps_id]) {
        av_log(h->avctx, AV_LOG_ERROR,
               "non-existing PPS %u referenced\n",
               pps_id);
        return AVERROR_INVALIDDATA;
    }
    h->pps = *h->pps_buffers[pps_id];
    if (!h->sps_buffers[h->pps.sps_id]) {
        av_log(h->avctx, AV_LOG_ERROR,
               "non-existing SPS %u referenced\n",
               h->pps.sps_id);
        return AVERROR_INVALIDDATA;
    }
    if (h->pps.sps_id != h->sps.sps_id ||
        h->sps_buffers[h->pps.sps_id]->new) {
        h->sps_buffers[h->pps.sps_id]->new = 0;
        h->sps = *h->sps_buffers[h->pps.sps_id];
        if (h->bit_depth_luma    != h->sps.bit_depth_luma ||
            h->chroma_format_idc != h->sps.chroma_format_idc) {
            h->bit_depth_luma    = h->sps.bit_depth_luma;
            h->chroma_format_idc = h->sps.chroma_format_idc;
            needs_reinit         = 1;
        }
        if ((ret = ff_h264_set_parameter_from_sps(h)) < 0)
            return ret;
    }
    h->avctx->profile = ff_h264_get_profile(&h->sps);
    h->avctx->level   = h->sps.level_idc;
    h->avctx->refs    = h->sps.ref_frame_count;
    if (h->mb_width  != h->sps.mb_width ||
        h->mb_height != h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag))
        needs_reinit = 1;
    h->mb_width  = h->sps.mb_width;
    h->mb_height = h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag);
    h->mb_num    = h->mb_width * h->mb_height;
    h->mb_stride = h->mb_width + 1;
    h->b_stride = h->mb_width * 4;
    h->chroma_y_shift = h->sps.chroma_format_idc <= 1;
    h->width  = 16 * h->mb_width;
    h->height = 16 * h->mb_height;
    ret = init_dimensions(h);
    if (ret < 0)
        return ret;
    if (h->sps.video_signal_type_present_flag) {
        h->avctx->color_range = h->sps.full_range ? AVCOL_RANGE_JPEG
                                                  : AVCOL_RANGE_MPEG;
        if (h->sps.colour_description_present_flag) {
            if (h->avctx->colorspace != h->sps.colorspace)
                needs_reinit = 1;
            h->avctx->color_primaries = h->sps.color_primaries;
            h->avctx->color_trc       = h->sps.color_trc;
            h->avctx->colorspace      = h->sps.colorspace;
        }
    }
    if (h->context_initialized && needs_reinit) {
        if (sl != h->slice_ctx) {
            av_log(h->avctx, AV_LOG_ERROR,
                   "changing width %d -> %d / height %d -> %d on "
                   "slice %d\n",
                   h->width, h->avctx->coded_width,
                   h->height, h->avctx->coded_height,
                   h->current_slice + 1);
            return AVERROR_INVALIDDATA;
        }
        ff_h264_flush_change(h);
        if ((ret = get_pixel_format(h)) < 0)
            return ret;
        h->avctx->pix_fmt = ret;
        av_log(h->avctx, AV_LOG_INFO, "Reinit context to %dx%d, "
               "pix_fmt: %d\n", h->width, h->height, h->avctx->pix_fmt);
        if ((ret = h264_slice_header_init(h, 1)) < 0) {
            av_log(h->avctx, AV_LOG_ERROR,
                   "h264_slice_header_init() failed\n");
            return ret;
        }
    }
    if (!h->context_initialized) {
        if (sl != h->slice_ctx) {
            av_log(h->avctx, AV_LOG_ERROR,
                   "Cannot (re-)initialize context during parallel decoding.\n");
            return AVERROR_PATCHWELCOME;
        }
        if ((ret = get_pixel_format(h)) < 0)
            return ret;
        h->avctx->pix_fmt = ret;
        if ((ret = h264_slice_header_init(h, 0)) < 0) {
            av_log(h->avctx, AV_LOG_ERROR,
                   "h264_slice_header_init() failed\n");
            return ret;
        }
    }
    if (sl == h->slice_ctx && h->dequant_coeff_pps != pps_id) {
        h->dequant_coeff_pps = pps_id;
        h264_init_dequant_tables(h);
    }
    h->frame_num = get_bits(&sl->gb, h->sps.log2_max_frame_num);
    sl->mb_mbaff       = 0;
    h->mb_aff_frame    = 0;
    last_pic_structure = h->picture_structure;
    last_pic_droppable = h->droppable;
    h->droppable       = h->nal_ref_idc == 0;
    if (h->sps.frame_mbs_only_flag) {
        h->picture_structure = PICT_FRAME;
    } else {
        field_pic_flag = get_bits1(&sl->gb);
        if (field_pic_flag) {
            bottom_field_flag = get_bits1(&sl->gb);
            h->picture_structure = PICT_TOP_FIELD + bottom_field_flag;
        } else {
            h->picture_structure = PICT_FRAME;
            h->mb_aff_frame      = h->sps.mb_aff;
        }
    }
    sl->mb_field_decoding_flag = h->picture_structure != PICT_FRAME;
    if (h->current_slice != 0) {
        if (last_pic_structure != h->picture_structure ||
            last_pic_droppable != h->droppable) {
            av_log(h->avctx, AV_LOG_ERROR,
                   "Changing field mode (%d -> %d) between slices is not allowed\n",
                   last_pic_structure, h->picture_structure);
            h->picture_structure = last_pic_structure;
            h->droppable         = last_pic_droppable;
            return AVERROR_INVALIDDATA;
        } else if (!h->cur_pic_ptr) {
            av_log(h->avctx, AV_LOG_ERROR,
                   "unset cur_pic_ptr on slice %d\n",
                   h->current_slice + 1);
            return AVERROR_INVALIDDATA;
        }
    } else {
        if (h->frame_num != h->prev_frame_num) {
            int unwrap_prev_frame_num = h->prev_frame_num;
            int max_frame_num         = 1 << h->sps.log2_max_frame_num;
            if (unwrap_prev_frame_num > h->frame_num)
                unwrap_prev_frame_num -= max_frame_num;
            if ((h->frame_num - unwrap_prev_frame_num) > h->sps.ref_frame_count) {
                unwrap_prev_frame_num = (h->frame_num - h->sps.ref_frame_count) - 1;
                if (unwrap_prev_frame_num < 0)
                    unwrap_prev_frame_num += max_frame_num;
                h->prev_frame_num = unwrap_prev_frame_num;
            }
        }
        if (h->first_field) {
            assert(h->cur_pic_ptr);
            assert(h->cur_pic_ptr->f.buf[0]);
            assert(h->cur_pic_ptr->reference != DELAYED_PIC_REF);
            if (!FIELD_PICTURE(h) || h->picture_structure == last_pic_structure) {
                if (!last_pic_droppable && last_pic_structure != PICT_FRAME) {
                    ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,
                                              last_pic_structure == PICT_TOP_FIELD);
                }
            } else {
                if (h->cur_pic_ptr->frame_num != h->frame_num) {
                    if (!last_pic_droppable && last_pic_structure != PICT_FRAME) {
                        ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,
                                                  last_pic_structure == PICT_TOP_FIELD);
                    }
                } else {
                    if (!((last_pic_structure   == PICT_TOP_FIELD &&
                           h->picture_structure == PICT_BOTTOM_FIELD) ||
                          (last_pic_structure   == PICT_BOTTOM_FIELD &&
                           h->picture_structure == PICT_TOP_FIELD))) {
                        av_log(h->avctx, AV_LOG_ERROR,
                               "Invalid field mode combination %d/%d\n",
                               last_pic_structure, h->picture_structure);
                        h->picture_structure = last_pic_structure;
                        h->droppable         = last_pic_droppable;
                        return AVERROR_INVALIDDATA;
                    } else if (last_pic_droppable != h->droppable) {
                        avpriv_request_sample(h->avctx,
                                              "Found reference and non-reference fields in the same frame, which");
                        h->picture_structure = last_pic_structure;
                        h->droppable         = last_pic_droppable;
                        return AVERROR_PATCHWELCOME;
                    }
                }
            }
        }
        while (h->frame_num != h->prev_frame_num &&
               h->frame_num != (h->prev_frame_num + 1) % (1 << h->sps.log2_max_frame_num)) {
            H264Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL;
            av_log(h->avctx, AV_LOG_DEBUG, "Frame num gap %d %d\n",
                   h->frame_num, h->prev_frame_num);
            ret = h264_frame_start(h);
            if (ret < 0) {
                h->first_field = 0;
                return ret;
            }
            h->prev_frame_num++;
            h->prev_frame_num        %= 1 << h->sps.log2_max_frame_num;
            h->cur_pic_ptr->frame_num = h->prev_frame_num;
            ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 0);
            ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 1);
            ret = ff_generate_sliding_window_mmcos(h, 1);
            if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
                return ret;
            ret = ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);
            if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
                return ret;
            if (h->short_ref_count) {
                if (prev) {
                    av_image_copy(h->short_ref[0]->f.data,
                                  h->short_ref[0]->f.linesize,
                                  (const uint8_t **)prev->f.data,
                                  prev->f.linesize,
                                  h->avctx->pix_fmt,
                                  h->mb_width  * 16,
                                  h->mb_height * 16);
                    h->short_ref[0]->poc = prev->poc + 2;
                }
                h->short_ref[0]->frame_num = h->prev_frame_num;
            }
        }
        if (h->first_field) {
            assert(h->cur_pic_ptr);
            assert(h->cur_pic_ptr->f.buf[0]);
            assert(h->cur_pic_ptr->reference != DELAYED_PIC_REF);
            if (!FIELD_PICTURE(h) || h->picture_structure == last_pic_structure) {
                h->cur_pic_ptr = NULL;
                h->first_field = FIELD_PICTURE(h);
            } else {
                if (h->cur_pic_ptr->frame_num != h->frame_num) {
                    h->first_field = 1;
                    h->cur_pic_ptr = NULL;
                } else {
                    h->first_field = 0;
                }
            }
        } else {
            h->first_field = FIELD_PICTURE(h);
        }
        if (!FIELD_PICTURE(h) || h->first_field) {
            if (h264_frame_start(h) < 0) {
                h->first_field = 0;
                return AVERROR_INVALIDDATA;
            }
        } else {
            release_unused_pictures(h, 0);
        }
    }
    h->cur_pic_ptr->frame_num = h->frame_num;
    assert(h->mb_num == h->mb_width * h->mb_height);
    if (first_mb_in_slice << FIELD_OR_MBAFF_PICTURE(h) >= h->mb_num ||
        first_mb_in_slice >= h->mb_num) {
        av_log(h->avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n");
        return AVERROR_INVALIDDATA;
    }
    sl->resync_mb_x = sl->mb_x =  first_mb_in_slice % h->mb_width;
    sl->resync_mb_y = sl->mb_y = (first_mb_in_slice / h->mb_width) <<
                                 FIELD_OR_MBAFF_PICTURE(h);
    if (h->picture_structure == PICT_BOTTOM_FIELD)
        sl->resync_mb_y = sl->mb_y = sl->mb_y + 1;
    assert(sl->mb_y < h->mb_height);
    if (h->picture_structure == PICT_FRAME) {
        h->curr_pic_num = h->frame_num;
        h->max_pic_num  = 1 << h->sps.log2_max_frame_num;
    } else {
        h->curr_pic_num = 2 * h->frame_num + 1;
        h->max_pic_num  = 1 << (h->sps.log2_max_frame_num + 1);
    }
    if (h->nal_unit_type == NAL_IDR_SLICE)
        get_ue_golomb(&sl->gb);
    if (h->sps.poc_type == 0) {
        h->poc_lsb = get_bits(&sl->gb, h->sps.log2_max_poc_lsb);
        if (h->pps.pic_order_present == 1 && h->picture_structure == PICT_FRAME)
            h->delta_poc_bottom = get_se_golomb(&sl->gb);
    }
    if (h->sps.poc_type == 1 && !h->sps.delta_pic_order_always_zero_flag) {
        h->delta_poc[0] = get_se_golomb(&sl->gb);
        if (h->pps.pic_order_present == 1 && h->picture_structure == PICT_FRAME)
            h->delta_poc[1] = get_se_golomb(&sl->gb);
    }
    ff_init_poc(h, h->cur_pic_ptr->field_poc, &h->cur_pic_ptr->poc);
    if (h->pps.redundant_pic_cnt_present)
        sl->redundant_pic_count = get_ue_golomb(&sl->gb);
    ret = ff_set_ref_count(h, sl);
    if (ret < 0)
        return ret;
    else if (ret == 1)
        default_ref_list_done = 0;
    if (!default_ref_list_done)
        ff_h264_fill_default_ref_list(h, sl);
    if (sl->slice_type_nos != AV_PICTURE_TYPE_I) {
       ret = ff_h264_decode_ref_pic_list_reordering(h, sl);
       if (ret < 0) {
           sl->ref_count[1] = sl->ref_count[0] = 0;
           return ret;
       }
    }
    if ((h->pps.weighted_pred && sl->slice_type_nos == AV_PICTURE_TYPE_P) ||
        (h->pps.weighted_bipred_idc == 1 &&
         sl->slice_type_nos == AV_PICTURE_TYPE_B))
        ff_pred_weight_table(h, sl);
    else if (h->pps.weighted_bipred_idc == 2 &&
             sl->slice_type_nos == AV_PICTURE_TYPE_B) {
        implicit_weight_table(h, sl, -1);
    } else {
        sl->use_weight = 0;
        for (i = 0; i < 2; i++) {
            sl->luma_weight_flag[i]   = 0;
            sl->chroma_weight_flag[i] = 0;
        }
    }
    if (h->nal_ref_idc) {
        ret = ff_h264_decode_ref_pic_marking(h, &sl->gb,
                                             !(h->avctx->active_thread_type & FF_THREAD_FRAME) ||
                                             h->current_slice == 0);
        if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
            return AVERROR_INVALIDDATA;
    }
    if (FRAME_MBAFF(h)) {
        ff_h264_fill_mbaff_ref_list(h, sl);
        if (h->pps.weighted_bipred_idc == 2 && sl->slice_type_nos == AV_PICTURE_TYPE_B) {
            implicit_weight_table(h, sl, 0);
            implicit_weight_table(h, sl, 1);
        }
    }
    if (sl->slice_type_nos == AV_PICTURE_TYPE_B && !sl->direct_spatial_mv_pred)
        ff_h264_direct_dist_scale_factor(h, sl);
    ff_h264_direct_ref_list_init(h, sl);
    if (sl->slice_type_nos != AV_PICTURE_TYPE_I && h->pps.cabac) {
        tmp = get_ue_golomb_31(&sl->gb);
        if (tmp > 2) {
            av_log(h->avctx, AV_LOG_ERROR, "cabac_init_idc %u overflow\n", tmp);
            return AVERROR_INVALIDDATA;
        }
        sl->cabac_init_idc = tmp;
    }
    sl->last_qscale_diff = 0;
    tmp = h->pps.init_qp + get_se_golomb(&sl->gb);
    if (tmp > 51 + 6 * (h->sps.bit_depth_luma - 8)) {
        av_log(h->avctx, AV_LOG_ERROR, "QP %u out of range\n", tmp);
        return AVERROR_INVALIDDATA;
    }
    sl->qscale       = tmp;
    sl->chroma_qp[0] = get_chroma_qp(h, 0, sl->qscale);
    sl->chroma_qp[1] = get_chroma_qp(h, 1, sl->qscale);
    if (sl->slice_type == AV_PICTURE_TYPE_SP)
        get_bits1(&sl->gb);
    if (sl->slice_type == AV_PICTURE_TYPE_SP ||
        sl->slice_type == AV_PICTURE_TYPE_SI)
        get_se_golomb(&sl->gb);
    sl->deblocking_filter     = 1;
    sl->slice_alpha_c0_offset = 0;
    sl->slice_beta_offset     = 0;
    if (h->pps.deblocking_filter_parameters_present) {
        tmp = get_ue_golomb_31(&sl->gb);
        if (tmp > 2) {
            av_log(h->avctx, AV_LOG_ERROR,
                   "deblocking_filter_idc %u out of range\n", tmp);
            return AVERROR_INVALIDDATA;
        }
        sl->deblocking_filter = tmp;
        if (sl->deblocking_filter < 2)
            sl->deblocking_filter ^= 1;
        if (sl->deblocking_filter) {
            sl->slice_alpha_c0_offset = get_se_golomb(&sl->gb) * 2;
            sl->slice_beta_offset     = get_se_golomb(&sl->gb) * 2;
            if (sl->slice_alpha_c0_offset >  12 ||
                sl->slice_alpha_c0_offset < -12 ||
                sl->slice_beta_offset >  12     ||
                sl->slice_beta_offset < -12) {
                av_log(h->avctx, AV_LOG_ERROR,
                       "deblocking filter parameters %d %d out of range\n",
                       sl->slice_alpha_c0_offset, sl->slice_beta_offset);
                return AVERROR_INVALIDDATA;
            }
        }
    }
    if (h->avctx->skip_loop_filter >= AVDISCARD_ALL ||
        (h->avctx->skip_loop_filter >= AVDISCARD_NONKEY &&
         sl->slice_type_nos != AV_PICTURE_TYPE_I) ||
        (h->avctx->skip_loop_filter >= AVDISCARD_BIDIR  &&
         sl->slice_type_nos == AV_PICTURE_TYPE_B) ||
        (h->avctx->skip_loop_filter >= AVDISCARD_NONREF &&
         h->nal_ref_idc == 0))
        sl->deblocking_filter = 0;
    if (sl->deblocking_filter == 1 && h->max_contexts > 1) {
        if (h->avctx->flags2 & CODEC_FLAG2_FAST) {
            sl->deblocking_filter = 2;
        } else {
            h->max_contexts = 1;
            if (!h->single_decode_warning) {
                av_log(h->avctx, AV_LOG_INFO,
                       "Cannot parallelize deblocking type 1, decoding such frames in sequential order\n");
                h->single_decode_warning = 1;
            }
            if (sl != h->slice_ctx) {
                av_log(h->avctx, AV_LOG_ERROR,
                       "Deblocking switched inside frame.\n");
                return 1;
            }
        }
    }
    sl->qp_thresh = 15 -
                   FFMIN(sl->slice_alpha_c0_offset, sl->slice_beta_offset) -
                   FFMAX3(0,
                          h->pps.chroma_qp_index_offset[0],
                          h->pps.chroma_qp_index_offset[1]) +
                   6 * (h->sps.bit_depth_luma - 8);
    h->last_slice_type = slice_type;
    sl->slice_num       = ++h->current_slice;
    if (sl->slice_num >= MAX_SLICES) {
        av_log(h->avctx, AV_LOG_ERROR,
               "Too many slices, increase MAX_SLICES and recompile\n");
    }
    for (j = 0; j < 2; j++) {
        int id_list[16];
        int *ref2frm = sl->ref2frm[sl->slice_num & (MAX_SLICES - 1)][j];
        for (i = 0; i < 16; i++) {
            id_list[i] = 60;
            if (j < sl->list_count && i < sl->ref_count[j] &&
                sl->ref_list[j][i].parent->f.buf[0]) {
                int k;
                AVBuffer *buf = sl->ref_list[j][i].parent->f.buf[0]->buffer;
                for (k = 0; k < h->short_ref_count; k++)
                    if (h->short_ref[k]->f.buf[0]->buffer == buf) {
                        id_list[i] = k;
                        break;
                    }
                for (k = 0; k < h->long_ref_count; k++)
                    if (h->long_ref[k] && h->long_ref[k]->f.buf[0]->buffer == buf) {
                        id_list[i] = h->short_ref_count + k;
                        break;
                    }
            }
        }
        ref2frm[0] =
        ref2frm[1] = -1;
        for (i = 0; i < 16; i++)
            ref2frm[i + 2] = 4 * id_list[i] + (sl->ref_list[j][i].reference & 3);
        ref2frm[18 + 0] =
        ref2frm[18 + 1] = -1;
        for (i = 16; i < 48; i++)
            ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] +
                             (sl->ref_list[j][i].reference & 3);
    }
    if (h->avctx->debug & FF_DEBUG_PICT_INFO) {
        av_log(h->avctx, AV_LOG_DEBUG,
               "slice:%d %s mb:%d %c%s%s pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\n",
               sl->slice_num,
               (h->picture_structure == PICT_FRAME ? "F" : h->picture_structure == PICT_TOP_FIELD ? "T" : "B"),
               first_mb_in_slice,
               av_get_picture_type_char(sl->slice_type),
               sl->slice_type_fixed ? " fix" : "",
               h->nal_unit_type == NAL_IDR_SLICE ? " IDR" : "",
               pps_id, h->frame_num,
               h->cur_pic_ptr->field_poc[0],
               h->cur_pic_ptr->field_poc[1],
               sl->ref_count[0], sl->ref_count[1],
               sl->qscale,
               sl->deblocking_filter,
               sl->slice_alpha_c0_offset, sl->slice_beta_offset,
               sl->use_weight,
               sl->use_weight == 1 && sl->use_weight_chroma ? "c" : "",
               sl->slice_type == AV_PICTURE_TYPE_B ? (sl->direct_spatial_mv_pred ? "SPAT" : "TEMP") : "");
    }
    return 0;
}
['int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl)\n{\n    unsigned int first_mb_in_slice;\n    unsigned int pps_id;\n    int ret;\n    unsigned int slice_type, tmp, i, j;\n    int default_ref_list_done = 0;\n    int last_pic_structure, last_pic_droppable;\n    int needs_reinit = 0;\n    int field_pic_flag, bottom_field_flag;\n    h->qpel_put = h->h264qpel.put_h264_qpel_pixels_tab;\n    h->qpel_avg = h->h264qpel.avg_h264_qpel_pixels_tab;\n    first_mb_in_slice = get_ue_golomb(&sl->gb);\n    if (first_mb_in_slice == 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, first_mb_in_slice);\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 = golomb_to_pict_type[slice_type];\n    if (slice_type == AV_PICTURE_TYPE_I ||\n        (h->current_slice != 0 && slice_type == h->last_slice_type)) {\n        default_ref_list_done = 1;\n    }\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    h->pict_type = sl->slice_type;\n    pps_id = get_ue_golomb(&sl->gb);\n    if (pps_id >= MAX_PPS_COUNT) {\n        av_log(h->avctx, AV_LOG_ERROR, "pps_id %u out of range\\n", pps_id);\n        return AVERROR_INVALIDDATA;\n    }\n    if (!h->pps_buffers[pps_id]) {\n        av_log(h->avctx, AV_LOG_ERROR,\n               "non-existing PPS %u referenced\\n",\n               pps_id);\n        return AVERROR_INVALIDDATA;\n    }\n    h->pps = *h->pps_buffers[pps_id];\n    if (!h->sps_buffers[h->pps.sps_id]) {\n        av_log(h->avctx, AV_LOG_ERROR,\n               "non-existing SPS %u referenced\\n",\n               h->pps.sps_id);\n        return AVERROR_INVALIDDATA;\n    }\n    if (h->pps.sps_id != h->sps.sps_id ||\n        h->sps_buffers[h->pps.sps_id]->new) {\n        h->sps_buffers[h->pps.sps_id]->new = 0;\n        h->sps = *h->sps_buffers[h->pps.sps_id];\n        if (h->bit_depth_luma    != h->sps.bit_depth_luma ||\n            h->chroma_format_idc != h->sps.chroma_format_idc) {\n            h->bit_depth_luma    = h->sps.bit_depth_luma;\n            h->chroma_format_idc = h->sps.chroma_format_idc;\n            needs_reinit         = 1;\n        }\n        if ((ret = ff_h264_set_parameter_from_sps(h)) < 0)\n            return ret;\n    }\n    h->avctx->profile = ff_h264_get_profile(&h->sps);\n    h->avctx->level   = h->sps.level_idc;\n    h->avctx->refs    = h->sps.ref_frame_count;\n    if (h->mb_width  != h->sps.mb_width ||\n        h->mb_height != h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag))\n        needs_reinit = 1;\n    h->mb_width  = h->sps.mb_width;\n    h->mb_height = h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag);\n    h->mb_num    = h->mb_width * h->mb_height;\n    h->mb_stride = h->mb_width + 1;\n    h->b_stride = h->mb_width * 4;\n    h->chroma_y_shift = h->sps.chroma_format_idc <= 1;\n    h->width  = 16 * h->mb_width;\n    h->height = 16 * h->mb_height;\n    ret = init_dimensions(h);\n    if (ret < 0)\n        return ret;\n    if (h->sps.video_signal_type_present_flag) {\n        h->avctx->color_range = h->sps.full_range ? AVCOL_RANGE_JPEG\n                                                  : AVCOL_RANGE_MPEG;\n        if (h->sps.colour_description_present_flag) {\n            if (h->avctx->colorspace != h->sps.colorspace)\n                needs_reinit = 1;\n            h->avctx->color_primaries = h->sps.color_primaries;\n            h->avctx->color_trc       = h->sps.color_trc;\n            h->avctx->colorspace      = h->sps.colorspace;\n        }\n    }\n    if (h->context_initialized && needs_reinit) {\n        if (sl != h->slice_ctx) {\n            av_log(h->avctx, AV_LOG_ERROR,\n                   "changing width %d -> %d / height %d -> %d on "\n                   "slice %d\\n",\n                   h->width, h->avctx->coded_width,\n                   h->height, h->avctx->coded_height,\n                   h->current_slice + 1);\n            return AVERROR_INVALIDDATA;\n        }\n        ff_h264_flush_change(h);\n        if ((ret = get_pixel_format(h)) < 0)\n            return ret;\n        h->avctx->pix_fmt = ret;\n        av_log(h->avctx, AV_LOG_INFO, "Reinit context to %dx%d, "\n               "pix_fmt: %d\\n", h->width, h->height, h->avctx->pix_fmt);\n        if ((ret = h264_slice_header_init(h, 1)) < 0) {\n            av_log(h->avctx, AV_LOG_ERROR,\n                   "h264_slice_header_init() failed\\n");\n            return ret;\n        }\n    }\n    if (!h->context_initialized) {\n        if (sl != h->slice_ctx) {\n            av_log(h->avctx, AV_LOG_ERROR,\n                   "Cannot (re-)initialize context during parallel decoding.\\n");\n            return AVERROR_PATCHWELCOME;\n        }\n        if ((ret = get_pixel_format(h)) < 0)\n            return ret;\n        h->avctx->pix_fmt = ret;\n        if ((ret = h264_slice_header_init(h, 0)) < 0) {\n            av_log(h->avctx, AV_LOG_ERROR,\n                   "h264_slice_header_init() failed\\n");\n            return ret;\n        }\n    }\n    if (sl == h->slice_ctx && h->dequant_coeff_pps != pps_id) {\n        h->dequant_coeff_pps = pps_id;\n        h264_init_dequant_tables(h);\n    }\n    h->frame_num = get_bits(&sl->gb, h->sps.log2_max_frame_num);\n    sl->mb_mbaff       = 0;\n    h->mb_aff_frame    = 0;\n    last_pic_structure = h->picture_structure;\n    last_pic_droppable = h->droppable;\n    h->droppable       = h->nal_ref_idc == 0;\n    if (h->sps.frame_mbs_only_flag) {\n        h->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            h->picture_structure = PICT_TOP_FIELD + bottom_field_flag;\n        } else {\n            h->picture_structure = PICT_FRAME;\n            h->mb_aff_frame      = h->sps.mb_aff;\n        }\n    }\n    sl->mb_field_decoding_flag = h->picture_structure != PICT_FRAME;\n    if (h->current_slice != 0) {\n        if (last_pic_structure != h->picture_structure ||\n            last_pic_droppable != h->droppable) {\n            av_log(h->avctx, AV_LOG_ERROR,\n                   "Changing field mode (%d -> %d) between slices is not allowed\\n",\n                   last_pic_structure, h->picture_structure);\n            h->picture_structure = last_pic_structure;\n            h->droppable         = last_pic_droppable;\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    } else {\n        if (h->frame_num != h->prev_frame_num) {\n            int unwrap_prev_frame_num = h->prev_frame_num;\n            int max_frame_num         = 1 << h->sps.log2_max_frame_num;\n            if (unwrap_prev_frame_num > h->frame_num)\n                unwrap_prev_frame_num -= max_frame_num;\n            if ((h->frame_num - unwrap_prev_frame_num) > h->sps.ref_frame_count) {\n                unwrap_prev_frame_num = (h->frame_num - h->sps.ref_frame_count) - 1;\n                if (unwrap_prev_frame_num < 0)\n                    unwrap_prev_frame_num += max_frame_num;\n                h->prev_frame_num = unwrap_prev_frame_num;\n            }\n        }\n        if (h->first_field) {\n            assert(h->cur_pic_ptr);\n            assert(h->cur_pic_ptr->f.buf[0]);\n            assert(h->cur_pic_ptr->reference != DELAYED_PIC_REF);\n            if (!FIELD_PICTURE(h) || h->picture_structure == last_pic_structure) {\n                if (!last_pic_droppable && last_pic_structure != PICT_FRAME) {\n                    ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,\n                                              last_pic_structure == PICT_TOP_FIELD);\n                }\n            } else {\n                if (h->cur_pic_ptr->frame_num != h->frame_num) {\n                    if (!last_pic_droppable && last_pic_structure != PICT_FRAME) {\n                        ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,\n                                                  last_pic_structure == PICT_TOP_FIELD);\n                    }\n                } else {\n                    if (!((last_pic_structure   == PICT_TOP_FIELD &&\n                           h->picture_structure == PICT_BOTTOM_FIELD) ||\n                          (last_pic_structure   == PICT_BOTTOM_FIELD &&\n                           h->picture_structure == PICT_TOP_FIELD))) {\n                        av_log(h->avctx, AV_LOG_ERROR,\n                               "Invalid field mode combination %d/%d\\n",\n                               last_pic_structure, h->picture_structure);\n                        h->picture_structure = last_pic_structure;\n                        h->droppable         = last_pic_droppable;\n                        return AVERROR_INVALIDDATA;\n                    } else if (last_pic_droppable != h->droppable) {\n                        avpriv_request_sample(h->avctx,\n                                              "Found reference and non-reference fields in the same frame, which");\n                        h->picture_structure = last_pic_structure;\n                        h->droppable         = last_pic_droppable;\n                        return AVERROR_PATCHWELCOME;\n                    }\n                }\n            }\n        }\n        while (h->frame_num != h->prev_frame_num &&\n               h->frame_num != (h->prev_frame_num + 1) % (1 << h->sps.log2_max_frame_num)) {\n            H264Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL;\n            av_log(h->avctx, AV_LOG_DEBUG, "Frame num gap %d %d\\n",\n                   h->frame_num, h->prev_frame_num);\n            ret = h264_frame_start(h);\n            if (ret < 0) {\n                h->first_field = 0;\n                return ret;\n            }\n            h->prev_frame_num++;\n            h->prev_frame_num        %= 1 << h->sps.log2_max_frame_num;\n            h->cur_pic_ptr->frame_num = h->prev_frame_num;\n            ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 0);\n            ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 1);\n            ret = ff_generate_sliding_window_mmcos(h, 1);\n            if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n                return ret;\n            ret = ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);\n            if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n                return ret;\n            if (h->short_ref_count) {\n                if (prev) {\n                    av_image_copy(h->short_ref[0]->f.data,\n                                  h->short_ref[0]->f.linesize,\n                                  (const uint8_t **)prev->f.data,\n                                  prev->f.linesize,\n                                  h->avctx->pix_fmt,\n                                  h->mb_width  * 16,\n                                  h->mb_height * 16);\n                    h->short_ref[0]->poc = prev->poc + 2;\n                }\n                h->short_ref[0]->frame_num = h->prev_frame_num;\n            }\n        }\n        if (h->first_field) {\n            assert(h->cur_pic_ptr);\n            assert(h->cur_pic_ptr->f.buf[0]);\n            assert(h->cur_pic_ptr->reference != DELAYED_PIC_REF);\n            if (!FIELD_PICTURE(h) || h->picture_structure == last_pic_structure) {\n                h->cur_pic_ptr = NULL;\n                h->first_field = FIELD_PICTURE(h);\n            } else {\n                if (h->cur_pic_ptr->frame_num != h->frame_num) {\n                    h->first_field = 1;\n                    h->cur_pic_ptr = NULL;\n                } else {\n                    h->first_field = 0;\n                }\n            }\n        } else {\n            h->first_field = FIELD_PICTURE(h);\n        }\n        if (!FIELD_PICTURE(h) || h->first_field) {\n            if (h264_frame_start(h) < 0) {\n                h->first_field = 0;\n                return AVERROR_INVALIDDATA;\n            }\n        } else {\n            release_unused_pictures(h, 0);\n        }\n    }\n    h->cur_pic_ptr->frame_num = h->frame_num;\n    assert(h->mb_num == h->mb_width * h->mb_height);\n    if (first_mb_in_slice << FIELD_OR_MBAFF_PICTURE(h) >= h->mb_num ||\n        first_mb_in_slice >= 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 =  first_mb_in_slice % h->mb_width;\n    sl->resync_mb_y = sl->mb_y = (first_mb_in_slice / 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->picture_structure == PICT_FRAME) {\n        h->curr_pic_num = h->frame_num;\n        h->max_pic_num  = 1 << h->sps.log2_max_frame_num;\n    } else {\n        h->curr_pic_num = 2 * h->frame_num + 1;\n        h->max_pic_num  = 1 << (h->sps.log2_max_frame_num + 1);\n    }\n    if (h->nal_unit_type == NAL_IDR_SLICE)\n        get_ue_golomb(&sl->gb);\n    if (h->sps.poc_type == 0) {\n        h->poc_lsb = get_bits(&sl->gb, h->sps.log2_max_poc_lsb);\n        if (h->pps.pic_order_present == 1 && h->picture_structure == PICT_FRAME)\n            h->delta_poc_bottom = get_se_golomb(&sl->gb);\n    }\n    if (h->sps.poc_type == 1 && !h->sps.delta_pic_order_always_zero_flag) {\n        h->delta_poc[0] = get_se_golomb(&sl->gb);\n        if (h->pps.pic_order_present == 1 && h->picture_structure == PICT_FRAME)\n            h->delta_poc[1] = get_se_golomb(&sl->gb);\n    }\n    ff_init_poc(h, h->cur_pic_ptr->field_poc, &h->cur_pic_ptr->poc);\n    if (h->pps.redundant_pic_cnt_present)\n        sl->redundant_pic_count = get_ue_golomb(&sl->gb);\n    ret = ff_set_ref_count(h, sl);\n    if (ret < 0)\n        return ret;\n    else if (ret == 1)\n        default_ref_list_done = 0;\n    if (!default_ref_list_done)\n        ff_h264_fill_default_ref_list(h, sl);\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    if ((h->pps.weighted_pred && sl->slice_type_nos == AV_PICTURE_TYPE_P) ||\n        (h->pps.weighted_bipred_idc == 1 &&\n         sl->slice_type_nos == AV_PICTURE_TYPE_B))\n        ff_pred_weight_table(h, sl);\n    else if (h->pps.weighted_bipred_idc == 2 &&\n             sl->slice_type_nos == AV_PICTURE_TYPE_B) {\n        implicit_weight_table(h, sl, -1);\n    } else {\n        sl->use_weight = 0;\n        for (i = 0; i < 2; i++) {\n            sl->luma_weight_flag[i]   = 0;\n            sl->chroma_weight_flag[i] = 0;\n        }\n    }\n    if (h->nal_ref_idc) {\n        ret = ff_h264_decode_ref_pic_marking(h, &sl->gb,\n                                             !(h->avctx->active_thread_type & FF_THREAD_FRAME) ||\n                                             h->current_slice == 0);\n        if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n            return AVERROR_INVALIDDATA;\n    }\n    if (FRAME_MBAFF(h)) {\n        ff_h264_fill_mbaff_ref_list(h, sl);\n        if (h->pps.weighted_bipred_idc == 2 && sl->slice_type_nos == AV_PICTURE_TYPE_B) {\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 (sl->slice_type_nos != AV_PICTURE_TYPE_I && h->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 = h->pps.init_qp + get_se_golomb(&sl->gb);\n    if (tmp > 51 + 6 * (h->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(h, 0, sl->qscale);\n    sl->chroma_qp[1] = get_chroma_qp(h, 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 (h->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    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->max_contexts > 1) {\n        if (h->avctx->flags2 & CODEC_FLAG2_FAST) {\n            sl->deblocking_filter = 2;\n        } else {\n            h->max_contexts = 1;\n            if (!h->single_decode_warning) {\n                av_log(h->avctx, AV_LOG_INFO,\n                       "Cannot parallelize deblocking type 1, decoding such frames in sequential order\\n");\n                h->single_decode_warning = 1;\n            }\n            if (sl != h->slice_ctx) {\n                av_log(h->avctx, AV_LOG_ERROR,\n                       "Deblocking switched inside frame.\\n");\n                return 1;\n            }\n        }\n    }\n    sl->qp_thresh = 15 -\n                   FFMIN(sl->slice_alpha_c0_offset, sl->slice_beta_offset) -\n                   FFMAX3(0,\n                          h->pps.chroma_qp_index_offset[0],\n                          h->pps.chroma_qp_index_offset[1]) +\n                   6 * (h->sps.bit_depth_luma - 8);\n    h->last_slice_type = slice_type;\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 = sl->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 pps:%u 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               first_mb_in_slice,\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               pps_id, h->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->use_weight,\n               sl->use_weight == 1 && sl->use_weight_chroma ? "c" : "",\n               sl->slice_type == AV_PICTURE_TYPE_B ? (sl->direct_spatial_mv_pred ? "SPAT" : "TEMP") : "");\n    }\n    return 0;\n}']