libavcodec/h264.c:3461: error: Buffer Overrun L1
  Offset: [20, 51] Size: 2.

libavcodec/h264.c:3460:14: <Offset trace>
3458.         ref2frm[18 + 0]     =
3459.             ref2frm[18 + 1] = -1;
3460.         for (i = 16; i < 48; i++)
                   ^
3461.             ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] +
3462.                              (h->ref_list[j][i].f.reference & 3);

libavcodec/h264.c:3460:14: Assignment
3458.         ref2frm[18 + 0]     =
3459.             ref2frm[18 + 1] = -1;
3460.         for (i = 16; i < 48; i++)
                   ^
3461.             ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] +
3462.                              (h->ref_list[j][i].f.reference & 3);

libavcodec/h264.c:2865:1: <Length trace>
2863.  * @return 0 if okay, <0 if an error occurred, 1 if decoding must not be multithreaded
2864.  */
2865. static int decode_slice_header(H264Context *h, H264Context *h0)
      ^
2866. {
2867.     MpegEncContext *const s  = &h->s;

libavcodec/h264.c:2865:1: Parameter `h->ref2frm[*][*]`
2863.  * @return 0 if okay, <0 if an error occurred, 1 if decoding must not be multithreaded
2864.  */
2865. static int decode_slice_header(H264Context *h, H264Context *h0)
      ^
2866. {
2867.     MpegEncContext *const s  = &h->s;

libavcodec/h264.c:3434:9: Assignment
3432.     for (j = 0; j < 2; j++) {
3433.         int id_list[16];
3434.         int *ref2frm = h->ref2frm[h->slice_num & (MAX_SLICES - 1)][j];
              ^
3435.         for (i = 0; i < 16; i++) {
3436.             id_list[i] = 60;

libavcodec/h264.c:3461:13: Array access: Offset: [20, 51] Size: 2
3459.             ref2frm[18 + 1] = -1;
3460.         for (i = 16; i < 48; i++)
3461.             ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] +
                  ^
3462.                              (h->ref_list[j][i].f.reference & 3);
3463.     }

static int decode_slice_header(H264Context *h, H264Context *h0)
{
    MpegEncContext *const s  = &h->s;
    MpegEncContext *const s0 = &h0->s;
    unsigned int first_mb_in_slice;
    unsigned int pps_id;
    int num_ref_idx_active_override_flag;
    unsigned int slice_type, tmp, i, j;
    int default_ref_list_done = 0;
    int last_pic_structure;
    s->dropable = h->nal_ref_idc == 0;
    if ((s->avctx->flags2 & CODEC_FLAG2_FAST) &&
        !h->nal_ref_idc && !h->pixel_shift) {
        s->me.qpel_put = s->dsp.put_2tap_qpel_pixels_tab;
        s->me.qpel_avg = s->dsp.avg_2tap_qpel_pixels_tab;
    } else {
        s->me.qpel_put = s->dsp.put_h264_qpel_pixels_tab;
        s->me.qpel_avg = s->dsp.avg_h264_qpel_pixels_tab;
    }
    first_mb_in_slice = get_ue_golomb(&s->gb);
    if (first_mb_in_slice == 0) {
        if (h0->current_slice && FIELD_PICTURE) {
            field_end(h, 1);
        }
        h0->current_slice = 0;
        if (!s0->first_field)
            s->current_picture_ptr = NULL;
    }
    slice_type = get_ue_golomb_31(&s->gb);
    if (slice_type > 9) {
        av_log(h->s.avctx, AV_LOG_ERROR,
               "slice type too large (%d) at %d %d\n",
               h->slice_type, s->mb_x, s->mb_y);
        return -1;
    }
    if (slice_type > 4) {
        slice_type -= 5;
        h->slice_type_fixed = 1;
    } else
        h->slice_type_fixed = 0;
    slice_type = golomb_to_pict_type[slice_type];
    if (slice_type == AV_PICTURE_TYPE_I ||
        (h0->current_slice != 0 && slice_type == h0->last_slice_type)) {
        default_ref_list_done = 1;
    }
    h->slice_type     = slice_type;
    h->slice_type_nos = slice_type & 3;
    s->pict_type = h->slice_type;
    pps_id = get_ue_golomb(&s->gb);
    if (pps_id >= MAX_PPS_COUNT) {
        av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\n");
        return -1;
    }
    if (!h0->pps_buffers[pps_id]) {
        av_log(h->s.avctx, AV_LOG_ERROR,
               "non-existing PPS %u referenced\n",
               pps_id);
        return -1;
    }
    h->pps = *h0->pps_buffers[pps_id];
    if (!h0->sps_buffers[h->pps.sps_id]) {
        av_log(h->s.avctx, AV_LOG_ERROR,
               "non-existing SPS %u referenced\n",
               h->pps.sps_id);
        return -1;
    }
    h->sps = *h0->sps_buffers[h->pps.sps_id];
    s->avctx->profile = ff_h264_get_profile(&h->sps);
    s->avctx->level   = h->sps.level_idc;
    s->avctx->refs    = h->sps.ref_frame_count;
    s->mb_width  = h->sps.mb_width;
    s->mb_height = h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag);
    h->b_stride = s->mb_width * 4;
    s->chroma_y_shift = h->sps.chroma_format_idc <= 1;
    s->width = 16 * s->mb_width - (2 >> CHROMA444) * FFMIN(h->sps.crop_right, (8 << CHROMA444) - 1);
    if (h->sps.frame_mbs_only_flag)
        s->height = 16 * s->mb_height - (1 << s->chroma_y_shift) * FFMIN(h->sps.crop_bottom, (16 >> s->chroma_y_shift) - 1);
    else
        s->height = 16 * s->mb_height - (2 << s->chroma_y_shift) * FFMIN(h->sps.crop_bottom, (16 >> s->chroma_y_shift) - 1);
    if (s->context_initialized &&
        (s->width != s->avctx->width || s->height != s->avctx->height ||
         av_cmp_q(h->sps.sar, s->avctx->sample_aspect_ratio))) {
        if (h != h0) {
            av_log_missing_feature(s->avctx,
                                   "Width/height changing with threads is", 0);
            return -1;
        }
        free_tables(h, 0);
        flush_dpb(s->avctx);
        ff_MPV_common_end(s);
    }
    if (!s->context_initialized) {
        if (h != h0) {
            av_log(h->s.avctx, AV_LOG_ERROR,
                   "Cannot (re-)initialize context during parallel decoding.\n");
            return -1;
        }
        avcodec_set_dimensions(s->avctx, s->width, s->height);
        s->avctx->sample_aspect_ratio = h->sps.sar;
        av_assert0(s->avctx->sample_aspect_ratio.den);
        if (h->sps.video_signal_type_present_flag) {
            s->avctx->color_range = h->sps.full_range ? AVCOL_RANGE_JPEG
                                                      : AVCOL_RANGE_MPEG;
            if (h->sps.colour_description_present_flag) {
                s->avctx->color_primaries = h->sps.color_primaries;
                s->avctx->color_trc       = h->sps.color_trc;
                s->avctx->colorspace      = h->sps.colorspace;
            }
        }
        if (h->sps.timing_info_present_flag) {
            int64_t den = h->sps.time_scale;
            if (h->x264_build < 44U)
                den *= 2;
            av_reduce(&s->avctx->time_base.num, &s->avctx->time_base.den,
                      h->sps.num_units_in_tick, den, 1 << 30);
        }
        switch (h->sps.bit_depth_luma) {
        case 9:
            if (CHROMA444) {
                if (s->avctx->colorspace == AVCOL_SPC_RGB) {
                    s->avctx->pix_fmt = PIX_FMT_GBRP9;
                } else
                    s->avctx->pix_fmt = PIX_FMT_YUV444P9;
            } else if (CHROMA422)
                s->avctx->pix_fmt = PIX_FMT_YUV422P9;
            else
                s->avctx->pix_fmt = PIX_FMT_YUV420P9;
            break;
        case 10:
            if (CHROMA444) {
                if (s->avctx->colorspace == AVCOL_SPC_RGB) {
                    s->avctx->pix_fmt = PIX_FMT_GBRP10;
                } else
                    s->avctx->pix_fmt = PIX_FMT_YUV444P10;
            } else if (CHROMA422)
                s->avctx->pix_fmt = PIX_FMT_YUV422P10;
            else
                s->avctx->pix_fmt = PIX_FMT_YUV420P10;
            break;
        case 8:
            if (CHROMA444) {
                if (s->avctx->colorspace == AVCOL_SPC_RGB) {
                    s->avctx->pix_fmt = PIX_FMT_GBRP;
                } else
                    s->avctx->pix_fmt = s->avctx->color_range == AVCOL_RANGE_JPEG ? PIX_FMT_YUVJ444P
                                                                                  : PIX_FMT_YUV444P;
            } else if (CHROMA422) {
                s->avctx->pix_fmt = s->avctx->color_range == AVCOL_RANGE_JPEG ? PIX_FMT_YUVJ422P
                                                                              : PIX_FMT_YUV422P;
            } else {
                s->avctx->pix_fmt = s->avctx->get_format(s->avctx,
                                                         s->avctx->codec->pix_fmts ?
                                                         s->avctx->codec->pix_fmts :
                                                         s->avctx->color_range == AVCOL_RANGE_JPEG ?
                                                         hwaccel_pixfmt_list_h264_jpeg_420 :
                                                         ff_hwaccel_pixfmt_list_420);
            }
            break;
        default:
            av_log(s->avctx, AV_LOG_ERROR,
                   "Unsupported bit depth: %d\n", h->sps.bit_depth_luma);
            return AVERROR_INVALIDDATA;
        }
        s->avctx->hwaccel = ff_find_hwaccel(s->avctx->codec->id,
                                            s->avctx->pix_fmt);
        if (ff_MPV_common_init(s) < 0) {
            av_log(h->s.avctx, AV_LOG_ERROR, "ff_MPV_common_init() failed.\n");
            return -1;
        }
        s->first_field = 0;
        h->prev_interlaced_frame = 1;
        init_scan_tables(h);
        if (ff_h264_alloc_tables(h) < 0) {
            av_log(h->s.avctx, AV_LOG_ERROR,
                   "Could not allocate memory for h264\n");
            return AVERROR(ENOMEM);
        }
        if (!HAVE_THREADS || !(s->avctx->active_thread_type & FF_THREAD_SLICE)) {
            if (context_init(h) < 0) {
                av_log(h->s.avctx, AV_LOG_ERROR, "context_init() failed.\n");
                return -1;
            }
        } else {
            for (i = 1; i < s->slice_context_count; i++) {
                H264Context *c;
                c = h->thread_context[i] = av_malloc(sizeof(H264Context));
                memcpy(c, h->s.thread_context[i], sizeof(MpegEncContext));
                memset(&c->s + 1, 0, sizeof(H264Context) - sizeof(MpegEncContext));
                c->h264dsp     = h->h264dsp;
                c->sps         = h->sps;
                c->pps         = h->pps;
                c->pixel_shift = h->pixel_shift;
                init_scan_tables(c);
                clone_tables(c, h, i);
            }
            for (i = 0; i < s->slice_context_count; i++)
                if (context_init(h->thread_context[i]) < 0) {
                    av_log(h->s.avctx, AV_LOG_ERROR,
                           "context_init() failed.\n");
                    return -1;
                }
        }
    }
    if (h == h0 && h->dequant_coeff_pps != pps_id) {
        h->dequant_coeff_pps = pps_id;
        init_dequant_tables(h);
    }
    h->frame_num = get_bits(&s->gb, h->sps.log2_max_frame_num);
    h->mb_mbaff        = 0;
    h->mb_aff_frame    = 0;
    last_pic_structure = s0->picture_structure;
    if (h->sps.frame_mbs_only_flag) {
        s->picture_structure = PICT_FRAME;
    } else {
        if (get_bits1(&s->gb)) {
            s->picture_structure = PICT_TOP_FIELD + get_bits1(&s->gb);
        } else {
            s->picture_structure = PICT_FRAME;
            h->mb_aff_frame      = h->sps.mb_aff;
        }
    }
    h->mb_field_decoding_flag = s->picture_structure != PICT_FRAME;
    if (h0->current_slice == 0) {
        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;
            }
        }
        while (h->frame_num != h->prev_frame_num &&
               h->frame_num != (h->prev_frame_num + 1) % (1 << h->sps.log2_max_frame_num)) {
            Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL;
            av_log(h->s.avctx, AV_LOG_DEBUG, "Frame num gap %d %d\n",
                   h->frame_num, h->prev_frame_num);
            if (ff_h264_frame_start(h) < 0)
                return -1;
            h->prev_frame_num++;
            h->prev_frame_num %= 1 << h->sps.log2_max_frame_num;
            s->current_picture_ptr->frame_num = h->prev_frame_num;
            ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX, 0);
            ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX, 1);
            ff_generate_sliding_window_mmcos(h);
            if (ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index) < 0 &&
                (s->avctx->err_recognition & AV_EF_EXPLODE))
                return AVERROR_INVALIDDATA;
            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,
                                  s->avctx->pix_fmt, s->mb_width * 16, s->mb_height * 16);
                    h->short_ref[0]->poc = prev->poc + 2;
                }
                h->short_ref[0]->frame_num = h->prev_frame_num;
            }
        }
        if (s0->first_field) {
            assert(s0->current_picture_ptr);
            assert(s0->current_picture_ptr->f.data[0]);
            assert(s0->current_picture_ptr->f.reference != DELAYED_PIC_REF);
            if (!FIELD_PICTURE || s->picture_structure == last_pic_structure) {
                s0->current_picture_ptr = NULL;
                s0->first_field         = FIELD_PICTURE;
            } else {
                if (h->nal_ref_idc &&
                    s0->current_picture_ptr->f.reference &&
                    s0->current_picture_ptr->frame_num != h->frame_num) {
                    s0->first_field         = 1;
                    s0->current_picture_ptr = NULL;
                } else {
                    s0->first_field = 0;
                }
            }
        } else {
            assert(!s0->current_picture_ptr);
            s0->first_field = FIELD_PICTURE;
        }
        if (!FIELD_PICTURE || s0->first_field) {
            if (ff_h264_frame_start(h) < 0) {
                s0->first_field = 0;
                return -1;
            }
        } else {
            ff_release_unused_pictures(s, 0);
        }
    }
    if (h != h0)
        clone_slice(h, h0);
    s->current_picture_ptr->frame_num = h->frame_num;
    assert(s->mb_num == s->mb_width * s->mb_height);
    if (first_mb_in_slice << FIELD_OR_MBAFF_PICTURE >= s->mb_num ||
        first_mb_in_slice >= s->mb_num) {
        av_log(h->s.avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n");
        return -1;
    }
    s->resync_mb_x = s->mb_x =  first_mb_in_slice % s->mb_width;
    s->resync_mb_y = s->mb_y = (first_mb_in_slice / s->mb_width) << FIELD_OR_MBAFF_PICTURE;
    if (s->picture_structure == PICT_BOTTOM_FIELD)
        s->resync_mb_y = s->mb_y = s->mb_y + 1;
    assert(s->mb_y < s->mb_height);
    if (s->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(&s->gb);
    if (h->sps.poc_type == 0) {
        h->poc_lsb = get_bits(&s->gb, h->sps.log2_max_poc_lsb);
        if (h->pps.pic_order_present == 1 && s->picture_structure == PICT_FRAME)
            h->delta_poc_bottom = get_se_golomb(&s->gb);
    }
    if (h->sps.poc_type == 1 && !h->sps.delta_pic_order_always_zero_flag) {
        h->delta_poc[0] = get_se_golomb(&s->gb);
        if (h->pps.pic_order_present == 1 && s->picture_structure == PICT_FRAME)
            h->delta_poc[1] = get_se_golomb(&s->gb);
    }
    init_poc(h);
    if (h->pps.redundant_pic_cnt_present)
        h->redundant_pic_count = get_ue_golomb(&s->gb);
    h->ref_count[0] = h->pps.ref_count[0];
    h->ref_count[1] = h->pps.ref_count[1];
    if (h->slice_type_nos != AV_PICTURE_TYPE_I) {
        int max_refs = s->picture_structure == PICT_FRAME ? 16 : 32;
        if (h->slice_type_nos == AV_PICTURE_TYPE_B)
            h->direct_spatial_mv_pred = get_bits1(&s->gb);
        num_ref_idx_active_override_flag = get_bits1(&s->gb);
        if (num_ref_idx_active_override_flag) {
            h->ref_count[0] = get_ue_golomb(&s->gb) + 1;
            if (h->slice_type_nos == AV_PICTURE_TYPE_B)
                h->ref_count[1] = get_ue_golomb(&s->gb) + 1;
        }
        if (h->ref_count[0] > max_refs || h->ref_count[1] > max_refs) {
            av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\n");
            h->ref_count[0] = h->ref_count[1] = 1;
            return AVERROR_INVALIDDATA;
        }
        if (h->slice_type_nos == AV_PICTURE_TYPE_B)
            h->list_count = 2;
        else
            h->list_count = 1;
    } else
        h->list_count = 0;
    if (!default_ref_list_done)
        ff_h264_fill_default_ref_list(h);
    if (h->slice_type_nos != AV_PICTURE_TYPE_I &&
        ff_h264_decode_ref_pic_list_reordering(h) < 0) {
        h->ref_count[1] = h->ref_count[0] = 0;
        return -1;
    }
    if (h->slice_type_nos != AV_PICTURE_TYPE_I) {
        s->last_picture_ptr = &h->ref_list[0][0];
        ff_copy_picture(&s->last_picture, s->last_picture_ptr);
    }
    if (h->slice_type_nos == AV_PICTURE_TYPE_B) {
        s->next_picture_ptr = &h->ref_list[1][0];
        ff_copy_picture(&s->next_picture, s->next_picture_ptr);
    }
    if ((h->pps.weighted_pred && h->slice_type_nos == AV_PICTURE_TYPE_P) ||
        (h->pps.weighted_bipred_idc == 1 &&
         h->slice_type_nos == AV_PICTURE_TYPE_B))
        pred_weight_table(h);
    else if (h->pps.weighted_bipred_idc == 2 &&
             h->slice_type_nos == AV_PICTURE_TYPE_B) {
        implicit_weight_table(h, -1);
    } else {
        h->use_weight = 0;
        for (i = 0; i < 2; i++) {
            h->luma_weight_flag[i]   = 0;
            h->chroma_weight_flag[i] = 0;
        }
    }
    if (h->nal_ref_idc && ff_h264_decode_ref_pic_marking(h0, &s->gb) < 0 &&
        (s->avctx->err_recognition & AV_EF_EXPLODE))
        return AVERROR_INVALIDDATA;
    if (FRAME_MBAFF) {
        ff_h264_fill_mbaff_ref_list(h);
        if (h->pps.weighted_bipred_idc == 2 && h->slice_type_nos == AV_PICTURE_TYPE_B) {
            implicit_weight_table(h, 0);
            implicit_weight_table(h, 1);
        }
    }
    if (h->slice_type_nos == AV_PICTURE_TYPE_B && !h->direct_spatial_mv_pred)
        ff_h264_direct_dist_scale_factor(h);
    ff_h264_direct_ref_list_init(h);
    if (h->slice_type_nos != AV_PICTURE_TYPE_I && h->pps.cabac) {
        tmp = get_ue_golomb_31(&s->gb);
        if (tmp > 2) {
            av_log(s->avctx, AV_LOG_ERROR, "cabac_init_idc overflow\n");
            return -1;
        }
        h->cabac_init_idc = tmp;
    }
    h->last_qscale_diff = 0;
    tmp = h->pps.init_qp + get_se_golomb(&s->gb);
    if (tmp > 51 + 6 * (h->sps.bit_depth_luma - 8)) {
        av_log(s->avctx, AV_LOG_ERROR, "QP %u out of range\n", tmp);
        return -1;
    }
    s->qscale       = tmp;
    h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale);
    h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale);
    if (h->slice_type == AV_PICTURE_TYPE_SP)
        get_bits1(&s->gb);
    if (h->slice_type == AV_PICTURE_TYPE_SP ||
        h->slice_type == AV_PICTURE_TYPE_SI)
        get_se_golomb(&s->gb);
    h->deblocking_filter     = 1;
    h->slice_alpha_c0_offset = 52;
    h->slice_beta_offset     = 52;
    if (h->pps.deblocking_filter_parameters_present) {
        tmp = get_ue_golomb_31(&s->gb);
        if (tmp > 2) {
            av_log(s->avctx, AV_LOG_ERROR,
                   "deblocking_filter_idc %u out of range\n", tmp);
            return -1;
        }
        h->deblocking_filter = tmp;
        if (h->deblocking_filter < 2)
            h->deblocking_filter ^= 1;
        if (h->deblocking_filter) {
            h->slice_alpha_c0_offset += get_se_golomb(&s->gb) << 1;
            h->slice_beta_offset     += get_se_golomb(&s->gb) << 1;
            if (h->slice_alpha_c0_offset > 104U ||
                h->slice_beta_offset     > 104U) {
                av_log(s->avctx, AV_LOG_ERROR,
                       "deblocking filter parameters %d %d out of range\n",
                       h->slice_alpha_c0_offset, h->slice_beta_offset);
                return -1;
            }
        }
    }
    if (s->avctx->skip_loop_filter >= AVDISCARD_ALL ||
        (s->avctx->skip_loop_filter >= AVDISCARD_NONKEY &&
         h->slice_type_nos != AV_PICTURE_TYPE_I) ||
        (s->avctx->skip_loop_filter >= AVDISCARD_BIDIR  &&
         h->slice_type_nos == AV_PICTURE_TYPE_B) ||
        (s->avctx->skip_loop_filter >= AVDISCARD_NONREF &&
         h->nal_ref_idc == 0))
        h->deblocking_filter = 0;
    if (h->deblocking_filter == 1 && h0->max_contexts > 1) {
        if (s->avctx->flags2 & CODEC_FLAG2_FAST) {
            h->deblocking_filter = 2;
        } else {
            h0->max_contexts = 1;
            if (!h0->single_decode_warning) {
                av_log(s->avctx, AV_LOG_INFO,
                       "Cannot parallelize deblocking type 1, decoding such frames in sequential order\n");
                h0->single_decode_warning = 1;
            }
            if (h != h0) {
                av_log(h->s.avctx, AV_LOG_ERROR,
                       "Deblocking switched inside frame.\n");
                return 1;
            }
        }
    }
    h->qp_thresh = 15 + 52 -
                   FFMIN(h->slice_alpha_c0_offset, h->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);
    h0->last_slice_type = slice_type;
    h->slice_num = ++h0->current_slice;
    if (h->slice_num >= MAX_SLICES) {
        av_log(s->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 = h->ref2frm[h->slice_num & (MAX_SLICES - 1)][j];
        for (i = 0; i < 16; i++) {
            id_list[i] = 60;
            if (h->ref_list[j][i].f.data[0]) {
                int k;
                uint8_t *base = h->ref_list[j][i].f.base[0];
                for (k = 0; k < h->short_ref_count; k++)
                    if (h->short_ref[k]->f.base[0] == base) {
                        id_list[i] = k;
                        break;
                    }
                for (k = 0; k < h->long_ref_count; k++)
                    if (h->long_ref[k] && h->long_ref[k]->f.base[0] == base) {
                        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] +
                             (h->ref_list[j][i].f.reference & 3);
        ref2frm[18 + 0]     =
            ref2frm[18 + 1] = -1;
        for (i = 16; i < 48; i++)
            ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] +
                             (h->ref_list[j][i].f.reference & 3);
    }
    h->emu_edge_width  = (s->flags & CODEC_FLAG_EMU_EDGE ||
                          (!h->sps.frame_mbs_only_flag &&
                           s->avctx->active_thread_type))
                         ? 0 : 16;
    h->emu_edge_height = (FRAME_MBAFF || FIELD_PICTURE) ? 0 : h->emu_edge_width;
    if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
        av_log(h->s.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",
               h->slice_num,
               (s->picture_structure == PICT_FRAME ? "F" : s->picture_structure == PICT_TOP_FIELD ? "T" : "B"),
               first_mb_in_slice,
               av_get_picture_type_char(h->slice_type),
               h->slice_type_fixed ? " fix" : "",
               h->nal_unit_type == NAL_IDR_SLICE ? " IDR" : "",
               pps_id, h->frame_num,
               s->current_picture_ptr->field_poc[0],
               s->current_picture_ptr->field_poc[1],
               h->ref_count[0], h->ref_count[1],
               s->qscale,
               h->deblocking_filter,
               h->slice_alpha_c0_offset / 2 - 26, h->slice_beta_offset / 2 - 26,
               h->use_weight,
               h->use_weight == 1 && h->use_weight_chroma ? "c" : "",
               h->slice_type == AV_PICTURE_TYPE_B ? (h->direct_spatial_mv_pred ? "SPAT" : "TEMP") : "");
    }
    return 0;
}
['static int decode_slice_header(H264Context *h, H264Context *h0)\n{\n    MpegEncContext *const s  = &h->s;\n    MpegEncContext *const s0 = &h0->s;\n    unsigned int first_mb_in_slice;\n    unsigned int pps_id;\n    int num_ref_idx_active_override_flag;\n    unsigned int slice_type, tmp, i, j;\n    int default_ref_list_done = 0;\n    int last_pic_structure;\n    s->dropable = h->nal_ref_idc == 0;\n    if ((s->avctx->flags2 & CODEC_FLAG2_FAST) &&\n        !h->nal_ref_idc && !h->pixel_shift) {\n        s->me.qpel_put = s->dsp.put_2tap_qpel_pixels_tab;\n        s->me.qpel_avg = s->dsp.avg_2tap_qpel_pixels_tab;\n    } else {\n        s->me.qpel_put = s->dsp.put_h264_qpel_pixels_tab;\n        s->me.qpel_avg = s->dsp.avg_h264_qpel_pixels_tab;\n    }\n    first_mb_in_slice = get_ue_golomb(&s->gb);\n    if (first_mb_in_slice == 0) {\n        if (h0->current_slice && FIELD_PICTURE) {\n            field_end(h, 1);\n        }\n        h0->current_slice = 0;\n        if (!s0->first_field)\n            s->current_picture_ptr = NULL;\n    }\n    slice_type = get_ue_golomb_31(&s->gb);\n    if (slice_type > 9) {\n        av_log(h->s.avctx, AV_LOG_ERROR,\n               "slice type too large (%d) at %d %d\\n",\n               h->slice_type, s->mb_x, s->mb_y);\n        return -1;\n    }\n    if (slice_type > 4) {\n        slice_type -= 5;\n        h->slice_type_fixed = 1;\n    } else\n        h->slice_type_fixed = 0;\n    slice_type = golomb_to_pict_type[slice_type];\n    if (slice_type == AV_PICTURE_TYPE_I ||\n        (h0->current_slice != 0 && slice_type == h0->last_slice_type)) {\n        default_ref_list_done = 1;\n    }\n    h->slice_type     = slice_type;\n    h->slice_type_nos = slice_type & 3;\n    s->pict_type = h->slice_type;\n    pps_id = get_ue_golomb(&s->gb);\n    if (pps_id >= MAX_PPS_COUNT) {\n        av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\\n");\n        return -1;\n    }\n    if (!h0->pps_buffers[pps_id]) {\n        av_log(h->s.avctx, AV_LOG_ERROR,\n               "non-existing PPS %u referenced\\n",\n               pps_id);\n        return -1;\n    }\n    h->pps = *h0->pps_buffers[pps_id];\n    if (!h0->sps_buffers[h->pps.sps_id]) {\n        av_log(h->s.avctx, AV_LOG_ERROR,\n               "non-existing SPS %u referenced\\n",\n               h->pps.sps_id);\n        return -1;\n    }\n    h->sps = *h0->sps_buffers[h->pps.sps_id];\n    s->avctx->profile = ff_h264_get_profile(&h->sps);\n    s->avctx->level   = h->sps.level_idc;\n    s->avctx->refs    = h->sps.ref_frame_count;\n    s->mb_width  = h->sps.mb_width;\n    s->mb_height = h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag);\n    h->b_stride = s->mb_width * 4;\n    s->chroma_y_shift = h->sps.chroma_format_idc <= 1;\n    s->width = 16 * s->mb_width - (2 >> CHROMA444) * FFMIN(h->sps.crop_right, (8 << CHROMA444) - 1);\n    if (h->sps.frame_mbs_only_flag)\n        s->height = 16 * s->mb_height - (1 << s->chroma_y_shift) * FFMIN(h->sps.crop_bottom, (16 >> s->chroma_y_shift) - 1);\n    else\n        s->height = 16 * s->mb_height - (2 << s->chroma_y_shift) * FFMIN(h->sps.crop_bottom, (16 >> s->chroma_y_shift) - 1);\n    if (s->context_initialized &&\n        (s->width != s->avctx->width || s->height != s->avctx->height ||\n         av_cmp_q(h->sps.sar, s->avctx->sample_aspect_ratio))) {\n        if (h != h0) {\n            av_log_missing_feature(s->avctx,\n                                   "Width/height changing with threads is", 0);\n            return -1;\n        }\n        free_tables(h, 0);\n        flush_dpb(s->avctx);\n        ff_MPV_common_end(s);\n    }\n    if (!s->context_initialized) {\n        if (h != h0) {\n            av_log(h->s.avctx, AV_LOG_ERROR,\n                   "Cannot (re-)initialize context during parallel decoding.\\n");\n            return -1;\n        }\n        avcodec_set_dimensions(s->avctx, s->width, s->height);\n        s->avctx->sample_aspect_ratio = h->sps.sar;\n        av_assert0(s->avctx->sample_aspect_ratio.den);\n        if (h->sps.video_signal_type_present_flag) {\n            s->avctx->color_range = h->sps.full_range ? AVCOL_RANGE_JPEG\n                                                      : AVCOL_RANGE_MPEG;\n            if (h->sps.colour_description_present_flag) {\n                s->avctx->color_primaries = h->sps.color_primaries;\n                s->avctx->color_trc       = h->sps.color_trc;\n                s->avctx->colorspace      = h->sps.colorspace;\n            }\n        }\n        if (h->sps.timing_info_present_flag) {\n            int64_t den = h->sps.time_scale;\n            if (h->x264_build < 44U)\n                den *= 2;\n            av_reduce(&s->avctx->time_base.num, &s->avctx->time_base.den,\n                      h->sps.num_units_in_tick, den, 1 << 30);\n        }\n        switch (h->sps.bit_depth_luma) {\n        case 9:\n            if (CHROMA444) {\n                if (s->avctx->colorspace == AVCOL_SPC_RGB) {\n                    s->avctx->pix_fmt = PIX_FMT_GBRP9;\n                } else\n                    s->avctx->pix_fmt = PIX_FMT_YUV444P9;\n            } else if (CHROMA422)\n                s->avctx->pix_fmt = PIX_FMT_YUV422P9;\n            else\n                s->avctx->pix_fmt = PIX_FMT_YUV420P9;\n            break;\n        case 10:\n            if (CHROMA444) {\n                if (s->avctx->colorspace == AVCOL_SPC_RGB) {\n                    s->avctx->pix_fmt = PIX_FMT_GBRP10;\n                } else\n                    s->avctx->pix_fmt = PIX_FMT_YUV444P10;\n            } else if (CHROMA422)\n                s->avctx->pix_fmt = PIX_FMT_YUV422P10;\n            else\n                s->avctx->pix_fmt = PIX_FMT_YUV420P10;\n            break;\n        case 8:\n            if (CHROMA444) {\n                if (s->avctx->colorspace == AVCOL_SPC_RGB) {\n                    s->avctx->pix_fmt = PIX_FMT_GBRP;\n                } else\n                    s->avctx->pix_fmt = s->avctx->color_range == AVCOL_RANGE_JPEG ? PIX_FMT_YUVJ444P\n                                                                                  : PIX_FMT_YUV444P;\n            } else if (CHROMA422) {\n                s->avctx->pix_fmt = s->avctx->color_range == AVCOL_RANGE_JPEG ? PIX_FMT_YUVJ422P\n                                                                              : PIX_FMT_YUV422P;\n            } else {\n                s->avctx->pix_fmt = s->avctx->get_format(s->avctx,\n                                                         s->avctx->codec->pix_fmts ?\n                                                         s->avctx->codec->pix_fmts :\n                                                         s->avctx->color_range == AVCOL_RANGE_JPEG ?\n                                                         hwaccel_pixfmt_list_h264_jpeg_420 :\n                                                         ff_hwaccel_pixfmt_list_420);\n            }\n            break;\n        default:\n            av_log(s->avctx, AV_LOG_ERROR,\n                   "Unsupported bit depth: %d\\n", h->sps.bit_depth_luma);\n            return AVERROR_INVALIDDATA;\n        }\n        s->avctx->hwaccel = ff_find_hwaccel(s->avctx->codec->id,\n                                            s->avctx->pix_fmt);\n        if (ff_MPV_common_init(s) < 0) {\n            av_log(h->s.avctx, AV_LOG_ERROR, "ff_MPV_common_init() failed.\\n");\n            return -1;\n        }\n        s->first_field = 0;\n        h->prev_interlaced_frame = 1;\n        init_scan_tables(h);\n        if (ff_h264_alloc_tables(h) < 0) {\n            av_log(h->s.avctx, AV_LOG_ERROR,\n                   "Could not allocate memory for h264\\n");\n            return AVERROR(ENOMEM);\n        }\n        if (!HAVE_THREADS || !(s->avctx->active_thread_type & FF_THREAD_SLICE)) {\n            if (context_init(h) < 0) {\n                av_log(h->s.avctx, AV_LOG_ERROR, "context_init() failed.\\n");\n                return -1;\n            }\n        } else {\n            for (i = 1; i < s->slice_context_count; i++) {\n                H264Context *c;\n                c = h->thread_context[i] = av_malloc(sizeof(H264Context));\n                memcpy(c, h->s.thread_context[i], sizeof(MpegEncContext));\n                memset(&c->s + 1, 0, sizeof(H264Context) - sizeof(MpegEncContext));\n                c->h264dsp     = h->h264dsp;\n                c->sps         = h->sps;\n                c->pps         = h->pps;\n                c->pixel_shift = h->pixel_shift;\n                init_scan_tables(c);\n                clone_tables(c, h, i);\n            }\n            for (i = 0; i < s->slice_context_count; i++)\n                if (context_init(h->thread_context[i]) < 0) {\n                    av_log(h->s.avctx, AV_LOG_ERROR,\n                           "context_init() failed.\\n");\n                    return -1;\n                }\n        }\n    }\n    if (h == h0 && h->dequant_coeff_pps != pps_id) {\n        h->dequant_coeff_pps = pps_id;\n        init_dequant_tables(h);\n    }\n    h->frame_num = get_bits(&s->gb, h->sps.log2_max_frame_num);\n    h->mb_mbaff        = 0;\n    h->mb_aff_frame    = 0;\n    last_pic_structure = s0->picture_structure;\n    if (h->sps.frame_mbs_only_flag) {\n        s->picture_structure = PICT_FRAME;\n    } else {\n        if (get_bits1(&s->gb)) {\n            s->picture_structure = PICT_TOP_FIELD + get_bits1(&s->gb);\n        } else {\n            s->picture_structure = PICT_FRAME;\n            h->mb_aff_frame      = h->sps.mb_aff;\n        }\n    }\n    h->mb_field_decoding_flag = s->picture_structure != PICT_FRAME;\n    if (h0->current_slice == 0) {\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        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            Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL;\n            av_log(h->s.avctx, AV_LOG_DEBUG, "Frame num gap %d %d\\n",\n                   h->frame_num, h->prev_frame_num);\n            if (ff_h264_frame_start(h) < 0)\n                return -1;\n            h->prev_frame_num++;\n            h->prev_frame_num %= 1 << h->sps.log2_max_frame_num;\n            s->current_picture_ptr->frame_num = h->prev_frame_num;\n            ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX, 0);\n            ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX, 1);\n            ff_generate_sliding_window_mmcos(h);\n            if (ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index) < 0 &&\n                (s->avctx->err_recognition & AV_EF_EXPLODE))\n                return AVERROR_INVALIDDATA;\n            if (h->short_ref_count) {\n                if (prev) {\n                    av_image_copy(h->short_ref[0]->f.data, h->short_ref[0]->f.linesize,\n                                  (const uint8_t **)prev->f.data, prev->f.linesize,\n                                  s->avctx->pix_fmt, s->mb_width * 16, s->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 (s0->first_field) {\n            assert(s0->current_picture_ptr);\n            assert(s0->current_picture_ptr->f.data[0]);\n            assert(s0->current_picture_ptr->f.reference != DELAYED_PIC_REF);\n            if (!FIELD_PICTURE || s->picture_structure == last_pic_structure) {\n                s0->current_picture_ptr = NULL;\n                s0->first_field         = FIELD_PICTURE;\n            } else {\n                if (h->nal_ref_idc &&\n                    s0->current_picture_ptr->f.reference &&\n                    s0->current_picture_ptr->frame_num != h->frame_num) {\n                    s0->first_field         = 1;\n                    s0->current_picture_ptr = NULL;\n                } else {\n                    s0->first_field = 0;\n                }\n            }\n        } else {\n            assert(!s0->current_picture_ptr);\n            s0->first_field = FIELD_PICTURE;\n        }\n        if (!FIELD_PICTURE || s0->first_field) {\n            if (ff_h264_frame_start(h) < 0) {\n                s0->first_field = 0;\n                return -1;\n            }\n        } else {\n            ff_release_unused_pictures(s, 0);\n        }\n    }\n    if (h != h0)\n        clone_slice(h, h0);\n    s->current_picture_ptr->frame_num = h->frame_num;\n    assert(s->mb_num == s->mb_width * s->mb_height);\n    if (first_mb_in_slice << FIELD_OR_MBAFF_PICTURE >= s->mb_num ||\n        first_mb_in_slice >= s->mb_num) {\n        av_log(h->s.avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\\n");\n        return -1;\n    }\n    s->resync_mb_x = s->mb_x =  first_mb_in_slice % s->mb_width;\n    s->resync_mb_y = s->mb_y = (first_mb_in_slice / s->mb_width) << FIELD_OR_MBAFF_PICTURE;\n    if (s->picture_structure == PICT_BOTTOM_FIELD)\n        s->resync_mb_y = s->mb_y = s->mb_y + 1;\n    assert(s->mb_y < s->mb_height);\n    if (s->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(&s->gb);\n    if (h->sps.poc_type == 0) {\n        h->poc_lsb = get_bits(&s->gb, h->sps.log2_max_poc_lsb);\n        if (h->pps.pic_order_present == 1 && s->picture_structure == PICT_FRAME)\n            h->delta_poc_bottom = get_se_golomb(&s->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(&s->gb);\n        if (h->pps.pic_order_present == 1 && s->picture_structure == PICT_FRAME)\n            h->delta_poc[1] = get_se_golomb(&s->gb);\n    }\n    init_poc(h);\n    if (h->pps.redundant_pic_cnt_present)\n        h->redundant_pic_count = get_ue_golomb(&s->gb);\n    h->ref_count[0] = h->pps.ref_count[0];\n    h->ref_count[1] = h->pps.ref_count[1];\n    if (h->slice_type_nos != AV_PICTURE_TYPE_I) {\n        int max_refs = s->picture_structure == PICT_FRAME ? 16 : 32;\n        if (h->slice_type_nos == AV_PICTURE_TYPE_B)\n            h->direct_spatial_mv_pred = get_bits1(&s->gb);\n        num_ref_idx_active_override_flag = get_bits1(&s->gb);\n        if (num_ref_idx_active_override_flag) {\n            h->ref_count[0] = get_ue_golomb(&s->gb) + 1;\n            if (h->slice_type_nos == AV_PICTURE_TYPE_B)\n                h->ref_count[1] = get_ue_golomb(&s->gb) + 1;\n        }\n        if (h->ref_count[0] > max_refs || h->ref_count[1] > max_refs) {\n            av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\\n");\n            h->ref_count[0] = h->ref_count[1] = 1;\n            return AVERROR_INVALIDDATA;\n        }\n        if (h->slice_type_nos == AV_PICTURE_TYPE_B)\n            h->list_count = 2;\n        else\n            h->list_count = 1;\n    } else\n        h->list_count = 0;\n    if (!default_ref_list_done)\n        ff_h264_fill_default_ref_list(h);\n    if (h->slice_type_nos != AV_PICTURE_TYPE_I &&\n        ff_h264_decode_ref_pic_list_reordering(h) < 0) {\n        h->ref_count[1] = h->ref_count[0] = 0;\n        return -1;\n    }\n    if (h->slice_type_nos != AV_PICTURE_TYPE_I) {\n        s->last_picture_ptr = &h->ref_list[0][0];\n        ff_copy_picture(&s->last_picture, s->last_picture_ptr);\n    }\n    if (h->slice_type_nos == AV_PICTURE_TYPE_B) {\n        s->next_picture_ptr = &h->ref_list[1][0];\n        ff_copy_picture(&s->next_picture, s->next_picture_ptr);\n    }\n    if ((h->pps.weighted_pred && h->slice_type_nos == AV_PICTURE_TYPE_P) ||\n        (h->pps.weighted_bipred_idc == 1 &&\n         h->slice_type_nos == AV_PICTURE_TYPE_B))\n        pred_weight_table(h);\n    else if (h->pps.weighted_bipred_idc == 2 &&\n             h->slice_type_nos == AV_PICTURE_TYPE_B) {\n        implicit_weight_table(h, -1);\n    } else {\n        h->use_weight = 0;\n        for (i = 0; i < 2; i++) {\n            h->luma_weight_flag[i]   = 0;\n            h->chroma_weight_flag[i] = 0;\n        }\n    }\n    if (h->nal_ref_idc && ff_h264_decode_ref_pic_marking(h0, &s->gb) < 0 &&\n        (s->avctx->err_recognition & AV_EF_EXPLODE))\n        return AVERROR_INVALIDDATA;\n    if (FRAME_MBAFF) {\n        ff_h264_fill_mbaff_ref_list(h);\n        if (h->pps.weighted_bipred_idc == 2 && h->slice_type_nos == AV_PICTURE_TYPE_B) {\n            implicit_weight_table(h, 0);\n            implicit_weight_table(h, 1);\n        }\n    }\n    if (h->slice_type_nos == AV_PICTURE_TYPE_B && !h->direct_spatial_mv_pred)\n        ff_h264_direct_dist_scale_factor(h);\n    ff_h264_direct_ref_list_init(h);\n    if (h->slice_type_nos != AV_PICTURE_TYPE_I && h->pps.cabac) {\n        tmp = get_ue_golomb_31(&s->gb);\n        if (tmp > 2) {\n            av_log(s->avctx, AV_LOG_ERROR, "cabac_init_idc overflow\\n");\n            return -1;\n        }\n        h->cabac_init_idc = tmp;\n    }\n    h->last_qscale_diff = 0;\n    tmp = h->pps.init_qp + get_se_golomb(&s->gb);\n    if (tmp > 51 + 6 * (h->sps.bit_depth_luma - 8)) {\n        av_log(s->avctx, AV_LOG_ERROR, "QP %u out of range\\n", tmp);\n        return -1;\n    }\n    s->qscale       = tmp;\n    h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale);\n    h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale);\n    if (h->slice_type == AV_PICTURE_TYPE_SP)\n        get_bits1(&s->gb);\n    if (h->slice_type == AV_PICTURE_TYPE_SP ||\n        h->slice_type == AV_PICTURE_TYPE_SI)\n        get_se_golomb(&s->gb);\n    h->deblocking_filter     = 1;\n    h->slice_alpha_c0_offset = 52;\n    h->slice_beta_offset     = 52;\n    if (h->pps.deblocking_filter_parameters_present) {\n        tmp = get_ue_golomb_31(&s->gb);\n        if (tmp > 2) {\n            av_log(s->avctx, AV_LOG_ERROR,\n                   "deblocking_filter_idc %u out of range\\n", tmp);\n            return -1;\n        }\n        h->deblocking_filter = tmp;\n        if (h->deblocking_filter < 2)\n            h->deblocking_filter ^= 1;\n        if (h->deblocking_filter) {\n            h->slice_alpha_c0_offset += get_se_golomb(&s->gb) << 1;\n            h->slice_beta_offset     += get_se_golomb(&s->gb) << 1;\n            if (h->slice_alpha_c0_offset > 104U ||\n                h->slice_beta_offset     > 104U) {\n                av_log(s->avctx, AV_LOG_ERROR,\n                       "deblocking filter parameters %d %d out of range\\n",\n                       h->slice_alpha_c0_offset, h->slice_beta_offset);\n                return -1;\n            }\n        }\n    }\n    if (s->avctx->skip_loop_filter >= AVDISCARD_ALL ||\n        (s->avctx->skip_loop_filter >= AVDISCARD_NONKEY &&\n         h->slice_type_nos != AV_PICTURE_TYPE_I) ||\n        (s->avctx->skip_loop_filter >= AVDISCARD_BIDIR  &&\n         h->slice_type_nos == AV_PICTURE_TYPE_B) ||\n        (s->avctx->skip_loop_filter >= AVDISCARD_NONREF &&\n         h->nal_ref_idc == 0))\n        h->deblocking_filter = 0;\n    if (h->deblocking_filter == 1 && h0->max_contexts > 1) {\n        if (s->avctx->flags2 & CODEC_FLAG2_FAST) {\n            h->deblocking_filter = 2;\n        } else {\n            h0->max_contexts = 1;\n            if (!h0->single_decode_warning) {\n                av_log(s->avctx, AV_LOG_INFO,\n                       "Cannot parallelize deblocking type 1, decoding such frames in sequential order\\n");\n                h0->single_decode_warning = 1;\n            }\n            if (h != h0) {\n                av_log(h->s.avctx, AV_LOG_ERROR,\n                       "Deblocking switched inside frame.\\n");\n                return 1;\n            }\n        }\n    }\n    h->qp_thresh = 15 + 52 -\n                   FFMIN(h->slice_alpha_c0_offset, h->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    h0->last_slice_type = slice_type;\n    h->slice_num = ++h0->current_slice;\n    if (h->slice_num >= MAX_SLICES) {\n        av_log(s->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[h->slice_num & (MAX_SLICES - 1)][j];\n        for (i = 0; i < 16; i++) {\n            id_list[i] = 60;\n            if (h->ref_list[j][i].f.data[0]) {\n                int k;\n                uint8_t *base = h->ref_list[j][i].f.base[0];\n                for (k = 0; k < h->short_ref_count; k++)\n                    if (h->short_ref[k]->f.base[0] == base) {\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.base[0] == base) {\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] +\n                             (h->ref_list[j][i].f.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                             (h->ref_list[j][i].f.reference & 3);\n    }\n    h->emu_edge_width  = (s->flags & CODEC_FLAG_EMU_EDGE ||\n                          (!h->sps.frame_mbs_only_flag &&\n                           s->avctx->active_thread_type))\n                         ? 0 : 16;\n    h->emu_edge_height = (FRAME_MBAFF || FIELD_PICTURE) ? 0 : h->emu_edge_width;\n    if (s->avctx->debug & FF_DEBUG_PICT_INFO) {\n        av_log(h->s.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               h->slice_num,\n               (s->picture_structure == PICT_FRAME ? "F" : s->picture_structure == PICT_TOP_FIELD ? "T" : "B"),\n               first_mb_in_slice,\n               av_get_picture_type_char(h->slice_type),\n               h->slice_type_fixed ? " fix" : "",\n               h->nal_unit_type == NAL_IDR_SLICE ? " IDR" : "",\n               pps_id, h->frame_num,\n               s->current_picture_ptr->field_poc[0],\n               s->current_picture_ptr->field_poc[1],\n               h->ref_count[0], h->ref_count[1],\n               s->qscale,\n               h->deblocking_filter,\n               h->slice_alpha_c0_offset / 2 - 26, h->slice_beta_offset / 2 - 26,\n               h->use_weight,\n               h->use_weight == 1 && h->use_weight_chroma ? "c" : "",\n               h->slice_type == AV_PICTURE_TYPE_B ? (h->direct_spatial_mv_pred ? "SPAT" : "TEMP") : "");\n    }\n    return 0;\n}']