Lines Matching refs:sl

131 static int alloc_scratch_buffers(H264SliceContext *sl, int linesize)
133 const H264Context *h = sl->h264;
136 av_fast_malloc(&sl->bipred_scratchpad, &sl->bipred_scratchpad_allocated, 16 * 6 * alloc_size);
139 av_fast_malloc(&sl->edge_emu_buffer, &sl->edge_emu_buffer_allocated, alloc_size * 2 * 21);
141 av_fast_mallocz(&sl->top_borders[0], &sl->top_borders_allocated[0],
143 av_fast_mallocz(&sl->top_borders[1], &sl->top_borders_allocated[1],
146 if (!sl->bipred_scratchpad || !sl->edge_emu_buffer ||
147 !sl->top_borders[0] || !sl->top_borders[1]) {
148 av_freep(&sl->bipred_scratchpad);
149 av_freep(&sl->edge_emu_buffer);
150 av_freep(&sl->top_borders[0]);
151 av_freep(&sl->top_borders[1]);
153 sl->bipred_scratchpad_allocated = 0;
154 sl->edge_emu_buffer_allocated = 0;
155 sl->top_borders_allocated[0] = 0;
156 sl->top_borders_allocated[1] = 0;
590 static av_always_inline void backup_mb_border(const H264Context *h, H264SliceContext *sl,
607 if (sl->mb_y & 1) {
608 if (!MB_MBAFF(sl)) {
609 top_border = sl->top_borders[0][sl->mb_x];
643 } else if (MB_MBAFF(sl)) {
649 top_border = sl->top_borders[top_idx][sl->mb_x];
692 static void implicit_weight_table(const H264Context *h, H264SliceContext *sl, int field)
697 sl->pwt.luma_weight_flag[i] = 0;
698 sl->pwt.chroma_weight_flag[i] = 0;
707 if (sl->ref_count[0] == 1 && sl->ref_count[1] == 1 && !FRAME_MBAFF(h) &&
708 sl->ref_list[0][0].poc + (int64_t)sl->ref_list[1][0].poc == 2LL * cur_poc) {
709 sl->pwt.use_weight = 0;
710 sl->pwt.use_weight_chroma = 0;
714 ref_count0 = sl->ref_count[0];
715 ref_count1 = sl->ref_count[1];
719 ref_count0 = 16 + 2 * sl->ref_count[0];
720 ref_count1 = 16 + 2 * sl->ref_count[1];
723 sl->pwt.use_weight = 2;
724 sl->pwt.use_weight_chroma = 2;
725 sl->pwt.luma_log2_weight_denom = 5;
726 sl->pwt.chroma_log2_weight_denom = 5;
729 int64_t poc0 = sl->ref_list[0][ref0].poc;
732 if (!sl->ref_list[0][ref0].parent->long_ref && !sl->ref_list[1][ref1].parent->long_ref) {
733 int poc1 = sl->ref_list[1][ref1].poc;
744 sl->pwt.implicit_weight[ref0][ref1][0] =
745 sl->pwt.implicit_weight[ref0][ref1][1] = w;
747 sl->pwt.implicit_weight[ref0][ref1][field] = w;
1010 H264SliceContext *sl = &h->slice_ctx[i];
1012 sl->h264 = h;
1013 sl->intra4x4_pred_mode = h->intra4x4_pred_mode + i * 8 * 2 * h->mb_stride;
1014 sl->mvd_table[0] = h->mvd_table[0] + i * 8 * 2 * h->mb_stride;
1015 sl->mvd_table[1] = h->mvd_table[1] + i * 8 * 2 * h->mb_stride;
1017 ff_h264_slice_context_init(h, sl);
1041 static int h264_init_ps(H264Context *h, const H264SliceContext *sl, int first_slice)
1049 h->ps.pps_ref = av_buffer_ref(h->ps.pps_list[sl->pps_id]);
1128 if (sl != h->slice_ctx) {
1540 static int h264_field_start(H264Context *h, const H264SliceContext *sl,
1548 ret = h264_init_ps(h, sl, first_slice);
1562 h->picture_structure = sl->picture_structure;
1564 h->poc.frame_num = sl->frame_num;
1565 h->poc.poc_lsb = sl->poc_lsb;
1566 h->poc.delta_poc_bottom = sl->delta_poc_bottom;
1567 h->poc.delta_poc[0] = sl->delta_poc[0];
1568 h->poc.delta_poc[1] = sl->delta_poc[1];
1571 h->poc_offset = sl->idr_pic_id;
1778 memcpy(h->mmco, sl->mmco, sl->nb_mmco * sizeof(*h->mmco));
1779 h->nb_mmco = sl->nb_mmco;
1780 h->explicit_ref_marking = sl->explicit_ref_marking;
1787 if (h->poc.frame_num != sei_recovery_frame_cnt || sl->slice_type_nos != AV_PICTURE_TYPE_I)
1832 static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl,
1840 int first_slice = sl == h->slice_ctx && !h->current_slice;
1846 sl->first_mb_addr = get_ue_golomb_long(&sl->gb);
1848 slice_type = get_ue_golomb_31(&sl->gb);
1852 slice_type, sl->first_mb_addr);
1857 sl->slice_type_fixed = 1;
1859 sl->slice_type_fixed = 0;
1862 sl->slice_type = slice_type;
1863 sl->slice_type_nos = slice_type & 3;
1866 sl->slice_type_nos != AV_PICTURE_TYPE_I) {
1871 sl->pps_id = get_ue_golomb(&sl->gb);
1872 if (sl->pps_id >= MAX_PPS_COUNT) {
1873 av_log(h->avctx, AV_LOG_ERROR, "pps_id %u out of range\n", sl->pps_id);
1876 if (!h->ps.pps_list[sl->pps_id]) {
1879 sl->pps_id);
1882 pps = (const PPS*)h->ps.pps_list[sl->pps_id]->data;
1885 sl->frame_num = get_bits(&sl->gb, sps->log2_max_frame_num);
1887 if (h->poc.frame_num != sl->frame_num) {
1889 h->poc.frame_num, sl->frame_num);
1894 sl->mb_mbaff = 0;
1903 field_pic_flag = get_bits1(&sl->gb);
1905 bottom_field_flag = get_bits1(&sl->gb);
1911 sl->picture_structure = picture_structure;
1912 sl->mb_field_decoding_flag = picture_structure != PICT_FRAME;
1915 sl->curr_pic_num = sl->frame_num;
1916 sl->max_pic_num = 1 << sps->log2_max_frame_num;
1918 sl->curr_pic_num = 2 * sl->frame_num + 1;
1919 sl->max_pic_num = 1 << (sps->log2_max_frame_num + 1);
1923 unsigned idr_pic_id = get_ue_golomb_long(&sl->gb);
1925 sl->idr_pic_id = idr_pic_id;
1930 sl->poc_lsb = 0;
1931 sl->delta_poc_bottom = 0;
1933 sl->poc_lsb = get_bits(&sl->gb, sps->log2_max_poc_lsb);
1936 sl->delta_poc_bottom = get_se_golomb(&sl->gb);
1939 sl->delta_poc[0] = sl->delta_poc[1] = 0;
1941 sl->delta_poc[0] = get_se_golomb(&sl->gb);
1944 sl->delta_poc[1] = get_se_golomb(&sl->gb);
1947 sl->redundant_pic_count = 0;
1949 sl->redundant_pic_count = get_ue_golomb(&sl->gb);
1951 if (sl->slice_type_nos == AV_PICTURE_TYPE_B)
1952 sl->direct_spatial_mv_pred = get_bits1(&sl->gb);
1954 ret = ff_h264_parse_ref_count(&sl->list_count, sl->ref_count,
1955 &sl->gb, pps, sl->slice_type_nos,
1960 if (sl->slice_type_nos != AV_PICTURE_TYPE_I) {
1961 ret = ff_h264_decode_ref_pic_list_reordering(sl, h->avctx);
1963 sl->ref_count[1] = sl->ref_count[0] = 0;
1968 sl->pwt.use_weight = 0;
1970 sl->pwt.luma_weight_flag[i] = 0;
1971 sl->pwt.chroma_weight_flag[i] = 0;
1973 if ((pps->weighted_pred && sl->slice_type_nos == AV_PICTURE_TYPE_P) ||
1975 sl->slice_type_nos == AV_PICTURE_TYPE_B)) {
1976 ret = ff_h264_pred_weight_table(&sl->gb, sps, sl->ref_count,
1977 sl->slice_type_nos, &sl->pwt,
1983 sl->explicit_ref_marking = 0;
1985 ret = ff_h264_decode_ref_pic_marking(sl, &sl->gb, nal, h->avctx);
1990 if (sl->slice_type_nos != AV_PICTURE_TYPE_I && pps->cabac) {
1991 tmp = get_ue_golomb_31(&sl->gb);
1996 sl->cabac_init_idc = tmp;
1999 sl->last_qscale_diff = 0;
2000 tmp = pps->init_qp + (unsigned)get_se_golomb(&sl->gb);
2005 sl->qscale = tmp;
2006 sl->chroma_qp[0] = get_chroma_qp(pps, 0, sl->qscale);
2007 sl->chroma_qp[1] = get_chroma_qp(pps, 1, sl->qscale);
2009 if (sl->slice_type == AV_PICTURE_TYPE_SP)
2010 get_bits1(&sl->gb); /* sp_for_switch_flag */
2011 if (sl->slice_type == AV_PICTURE_TYPE_SP ||
2012 sl->slice_type == AV_PICTURE_TYPE_SI)
2013 get_se_golomb(&sl->gb); /* slice_qs_delta */
2015 sl->deblocking_filter = 1;
2016 sl->slice_alpha_c0_offset = 0;
2017 sl->slice_beta_offset = 0;
2019 tmp = get_ue_golomb_31(&sl->gb);
2025 sl->deblocking_filter = tmp;
2026 if (sl->deblocking_filter < 2)
2027 sl->deblocking_filter ^= 1; // 1<->0
2029 if (sl->deblocking_filter) {
2030 int slice_alpha_c0_offset_div2 = get_se_golomb(&sl->gb);
2031 int slice_beta_offset_div2 = get_se_golomb(&sl->gb);
2041 sl->slice_alpha_c0_offset = slice_alpha_c0_offset_div2 * 2;
2042 sl->slice_beta_offset = slice_beta_offset_div2 * 2;
2051 static int h264_slice_init(H264Context *h, H264SliceContext *sl,
2062 if (sl->first_mb_addr << FIELD_OR_MBAFF_PICTURE(h) >= h->mb_num ||
2063 sl->first_mb_addr >= h->mb_num) {
2067 sl->resync_mb_x = sl->mb_x = sl->first_mb_addr % h->mb_width;
2068 sl->resync_mb_y = sl->mb_y = (sl->first_mb_addr / h->mb_width) <<
2071 sl->resync_mb_y = sl->mb_y = sl->mb_y + 1;
2072 av_assert1(sl->mb_y < h->mb_height);
2074 ret = ff_h264_build_ref_list(h, sl);
2079 sl->slice_type_nos == AV_PICTURE_TYPE_B) {
2080 implicit_weight_table(h, sl, -1);
2082 implicit_weight_table(h, sl, 0);
2083 implicit_weight_table(h, sl, 1);
2087 if (sl->slice_type_nos == AV_PICTURE_TYPE_B && !sl->direct_spatial_mv_pred)
2088 ff_h264_direct_dist_scale_factor(h, sl);
2090 ff_h264_direct_ref_list_init(h, sl);
2096 sl->slice_type_nos != AV_PICTURE_TYPE_I) ||
2098 sl->slice_type_nos == AV_PICTURE_TYPE_B) ||
2101 sl->deblocking_filter = 0;
2103 if (sl->deblocking_filter == 1 && h->nb_slice_ctx > 1) {
2107 sl->deblocking_filter = 2;
2112 sl->qp_thresh = 15 -
2113 FFMIN(sl->slice_alpha_c0_offset, sl->slice_beta_offset) -
2119 sl->slice_num = ++h->current_slice;
2121 if (sl->slice_num)
2122 h->slice_row[(sl->slice_num-1)&(MAX_SLICES-1)]= sl->resync_mb_y;
2123 if ( h->slice_row[sl->slice_num&(MAX_SLICES-1)] + 3 >= sl->resync_mb_y
2124 && h->slice_row[sl->slice_num&(MAX_SLICES-1)] <= sl->resync_mb_y
2125 && sl->slice_num >= MAX_SLICES) {
2127 av_log(h->avctx, AV_LOG_WARNING, "Possibly too many slices (%d >= %d), increase MAX_SLICES and recompile if there are artifacts\n", sl->slice_num, MAX_SLICES);
2132 int *ref2frm = h->ref2frm[sl->slice_num & (MAX_SLICES - 1)][j];
2135 if (j < sl->list_count && i < sl->ref_count[j] &&
2136 sl->ref_list[j][i].parent->f->buf[0]) {
2138 AVBuffer *buf = sl->ref_list[j][i].parent->f->buf[0]->buffer;
2155 ref2frm[i + 2] = 4 * id_list[i] + (sl->ref_list[j][i].reference & 3);
2160 (sl->ref_list[j][i].reference & 3);
2166 sl->slice_num,
2168 sl->mb_y * h->mb_width + sl->mb_x,
2169 av_get_picture_type_char(sl->slice_type),
2170 sl->slice_type_fixed ? " fix" : "",
2175 sl->ref_count[0], sl->ref_count[1],
2176 sl->qscale,
2177 sl->deblocking_filter,
2178 sl->slice_alpha_c0_offset, sl->slice_beta_offset,
2179 sl->pwt.use_weight,
2180 sl->pwt.use_weight == 1 && sl->pwt.use_weight_chroma ? "c" : "",
2181 sl->slice_type == AV_PICTURE_TYPE_B ? (sl->direct_spatial_mv_pred ? "SPAT" : "TEMP") : "");
2189 H264SliceContext *sl = h->slice_ctx + h->nb_slice_ctx_queued;
2190 int first_slice = sl == h->slice_ctx && !h->current_slice;
2193 sl->gb = nal->gb;
2195 ret = h264_slice_header_parse(h, sl, nal);
2200 if (sl->redundant_pic_count > 0) {
2201 sl->ref_count[0] = sl->ref_count[1] = 0;
2205 if (sl->first_mb_addr == 0 || !h->current_slice) {
2212 if (sl->first_mb_addr == 0) { // FIXME better field boundary detection
2224 memcpy(h->slice_ctx, sl, sizeof(tmp_ctx));
2225 memcpy(sl, &tmp_ctx, sizeof(tmp_ctx));
2226 sl = h->slice_ctx;
2255 av_assert0(sl == h->slice_ctx);
2260 (h->avctx->skip_frame >= AVDISCARD_BIDIR && sl->slice_type_nos == AV_PICTURE_TYPE_B) ||
2261 (h->avctx->skip_frame >= AVDISCARD_NONINTRA && sl->slice_type_nos != AV_PICTURE_TYPE_I) ||
2269 const PPS *pps = (const PPS*)h->ps.pps_list[sl->pps_id]->data;
2285 ret = h264_field_start(h, sl, nal, first_slice);
2289 if (h->picture_structure != sl->picture_structure ||
2293 h->picture_structure, sl->picture_structure);
2303 ret = h264_slice_init(h, sl, nal);
2312 int ff_h264_get_slice_type(const H264SliceContext *sl)
2314 switch (sl->slice_type) {
2331 H264SliceContext *sl,
2339 int16_t(*mv_dst)[2] = &sl->mv_cache[list][scan8[0]];
2340 int8_t *ref_cache = &sl->ref_cache[list][scan8[0]];
2345 const int *ref2frm = &h->ref2frm[h->slice_table[top_xy] & (MAX_SLICES - 1)][list][(MB_MBAFF(sl) ? 20 : 2)];
2360 const int *ref2frm = &h->ref2frm[h->slice_table[left_xy[LTOP]] & (MAX_SLICES - 1)][list][(MB_MBAFF(sl) ? 20 : 2)];
2393 const int *ref2frm = &h->ref2frm[sl->slice_num & (MAX_SLICES - 1)][list][(MB_MBAFF(sl) ? 20 : 2)];
2403 int16_t(*mv_src)[2] = &h->cur_pic.motion_val[list][4 * sl->mb_x + 4 * sl->mb_y * b_stride];
2414 static int fill_filter_caches(const H264Context *h, H264SliceContext *sl, int mb_type)
2416 const int mb_xy = sl->mb_xy;
2422 top_xy = mb_xy - (h->mb_stride << MB_FIELD(sl));
2428 if (sl->mb_y & 1) {
2440 sl->top_mb_xy = top_xy;
2441 sl->left_mb_xy[LTOP] = left_xy[LTOP];
2442 sl->left_mb_xy[LBOT] = left_xy[LBOT];
2447 int qp_thresh = sl->qp_thresh; // FIXME strictly we should store qp_thresh for each mb of a slice
2467 if (sl->deblocking_filter == 2) {
2468 if (h->slice_table[top_xy] != sl->slice_num)
2470 if (h->slice_table[left_xy[LBOT]] != sl->slice_num)
2478 sl->top_type = top_type;
2479 sl->left_type[LTOP] = left_type[LTOP];
2480 sl->left_type[LBOT] = left_type[LBOT];
2485 fill_filter_caches_inter(h, sl, mb_type, top_xy, left_xy,
2487 if (sl->list_count == 2)
2488 fill_filter_caches_inter(h, sl, mb_type, top_xy, left_xy,
2492 nnz_cache = sl->non_zero_count_cache;
2497 sl->cbp = h->cbp_table[mb_xy];
2534 nnz_cache[scan8[3]] = (sl->cbp & 0x1000) >> 12;
2539 nnz_cache[scan8[3 + 4]] = (sl->cbp & 0x2000) >> 12;
2544 nnz_cache[scan8[3 + 8]] = (sl->cbp & 0x4000) >> 12;
2549 nnz_cache[scan8[3 + 12]] = (sl->cbp & 0x8000) >> 12;
2556 static void loop_filter(const H264Context *h, H264SliceContext *sl, int start_x, int end_x)
2560 const int end_mb_y = sl->mb_y + FRAME_MBAFF(h);
2561 const int old_slice_type = sl->slice_type;
2568 if (sl->deblocking_filter) {
2572 mb_xy = sl->mb_xy = mb_x + mb_y * h->mb_stride;
2576 sl->mb_mbaff =
2577 sl->mb_field_decoding_flag = !!IS_INTERLACED(mb_type);
2579 sl->mb_x = mb_x;
2580 sl->mb_y = mb_y;
2582 ((mb_x << pixel_shift) + mb_y * sl->linesize) * 16;
2585 mb_y * sl->uvlinesize * block_h;
2588 mb_y * sl->uvlinesize * block_h;
2591 if (MB_FIELD(sl)) {
2592 linesize = sl->mb_linesize = sl->linesize * 2;
2593 uvlinesize = sl->mb_uvlinesize = sl->uvlinesize * 2;
2595 dest_y -= sl->linesize * 15;
2596 dest_cb -= sl->uvlinesize * (block_h - 1);
2597 dest_cr -= sl->uvlinesize * (block_h - 1);
2600 linesize = sl->mb_linesize = sl->linesize;
2601 uvlinesize = sl->mb_uvlinesize = sl->uvlinesize;
2603 backup_mb_border(h, sl, dest_y, dest_cb, dest_cr, linesize,
2605 if (fill_filter_caches(h, sl, mb_type))
2607 sl->chroma_qp[0] = get_chroma_qp(h->ps.pps, 0, h->cur_pic.qscale_table[mb_xy]);
2608 sl->chroma_qp[1] = get_chroma_qp(h->ps.pps, 1, h->cur_pic.qscale_table[mb_xy]);
2611 ff_h264_filter_mb(h, sl, mb_x, mb_y, dest_y, dest_cb, dest_cr,
2614 ff_h264_filter_mb_fast(h, sl, mb_x, mb_y, dest_y, dest_cb,
2619 sl->slice_type = old_slice_type;
2620 sl->mb_x = end_x;
2621 sl->mb_y = end_mb_y - FRAME_MBAFF(h);
2622 sl->chroma_qp[0] = get_chroma_qp(h->ps.pps, 0, sl->qscale);
2623 sl->chroma_qp[1] = get_chroma_qp(h->ps.pps, 1, sl->qscale);
2626 static void predict_field_decoding_flag(const H264Context *h, H264SliceContext *sl)
2628 const int mb_xy = sl->mb_x + sl->mb_y * h->mb_stride;
2629 int mb_type = (h->slice_table[mb_xy - 1] == sl->slice_num) ?
2631 (h->slice_table[mb_xy - h->mb_stride] == sl->slice_num) ?
2633 sl->mb_mbaff = sl->mb_field_decoding_flag = IS_INTERLACED(mb_type) ? 1 : 0;
2639 static void decode_finish_row(const H264Context *h, H264SliceContext *sl)
2641 int top = 16 * (sl->mb_y >> FIELD_PICTURE(h));
2646 if (sl->deblocking_filter) {
2661 ff_h264_draw_horiz_band(h, sl, top, height);
2670 static void er_add_slice(H264SliceContext *sl,
2674 if (!sl->h264->enable_er)
2678 ff_er_add_slice(sl->er, startx, starty, endx, endy, status);
2684 H264SliceContext *sl = arg;
2685 const H264Context *h = sl->h264;
2686 int lf_x_start = sl->mb_x;
2687 int orig_deblock = sl->deblocking_filter;
2690 sl->linesize = h->cur_pic_ptr->f->linesize[0];
2691 sl->uvlinesize = h->cur_pic_ptr->f->linesize[1];
2693 ret = alloc_scratch_buffers(sl, sl->linesize);
2697 sl->mb_skip_run = -1;
2699 av_assert0(h->block_offset[15] == (4 * ((scan8[15] - scan8[0]) & 7) << h->pixel_shift) + 4 * sl->linesize * ((scan8[15] - scan8[0]) >> 3));
2702 sl->deblocking_filter = 0;
2704 sl->is_complex = FRAME_MBAFF(h) || h->picture_structure != PICT_FRAME ||
2707 if (!(h->avctx->active_thread_type & FF_THREAD_SLICE) && h->picture_structure == PICT_FRAME && sl->er->error_status_table) {
2708 const int start_i = av_clip(sl->resync_mb_x + sl->resync_mb_y * h->mb_width, 0, h->mb_num - 1);
2710 int prev_status = sl->er->error_status_table[sl->er->mb_index2xy[start_i - 1]];
2713 sl->er->error_occurred = 1;
2719 align_get_bits(&sl->gb);
2722 ret = ff_init_cabac_decoder(&sl->cabac,
2723 sl->gb.buffer + get_bits_count(&sl->gb) / 8,
2724 (get_bits_left(&sl->gb) + 7) / 8);
2728 ff_h264_init_cabac_states(h, sl);
2732 if (sl->mb_x + sl->mb_y * h->mb_width >= sl->next_slice_idx) {
2734 sl->next_slice_idx);
2735 er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x,
2736 sl->mb_y, ER_MB_ERROR);
2740 ret = ff_h264_decode_mb_cabac(h, sl);
2743 ff_h264_hl_decode_mb(h, sl);
2747 sl->mb_y++;
2749 ret = ff_h264_decode_mb_cabac(h, sl);
2752 ff_h264_hl_decode_mb(h, sl);
2753 sl->mb_y--;
2755 eos = get_cabac_terminate(&sl->cabac);
2758 sl->cabac.bytestream > sl->cabac.bytestream_end + 2) {
2759 er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x - 1,
2760 sl->mb_y, ER_MB_END);
2761 if (sl->mb_x >= lf_x_start)
2762 loop_filter(h, sl, lf_x_start, sl->mb_x + 1);
2765 if (sl->cabac.bytestream > sl->cabac.bytestream_end + 2 )
2766 av_log(h->avctx, AV_LOG_DEBUG, "bytestream overread %"PTRDIFF_SPECIFIER"\n", sl->cabac.bytestream_end - sl->cabac.bytestream);
2767 if (ret < 0 || sl->cabac.bytestream > sl->cabac.bytestream_end + 4) {
2770 sl->mb_x, sl->mb_y,
2771 sl->cabac.bytestream_end - sl->cabac.bytestream);
2772 er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x,
2773 sl->mb_y, ER_MB_ERROR);
2777 if (++sl->mb_x >= h->mb_width) {
2778 loop_filter(h, sl, lf_x_start, sl->mb_x);
2779 sl->mb_x = lf_x_start = 0;
2780 decode_finish_row(h, sl);
2781 ++sl->mb_y;
2783 ++sl->mb_y;
2784 if (FRAME_MBAFF(h) && sl->mb_y < h->mb_height)
2785 predict_field_decoding_flag(h, sl);
2789 if (eos || sl->mb_y >= h->mb_height) {
2791 get_bits_count(&sl->gb), sl->gb.size_in_bits);
2792 er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x - 1,
2793 sl->mb_y, ER_MB_END);
2794 if (sl->mb_x > lf_x_start)
2795 loop_filter(h, sl, lf_x_start, sl->mb_x);
2803 if (sl->mb_x + sl->mb_y * h->mb_width >= sl->next_slice_idx) {
2805 sl->next_slice_idx);
2806 er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x,
2807 sl->mb_y, ER_MB_ERROR);
2811 ret = ff_h264_decode_mb_cavlc(h, sl);
2814 ff_h264_hl_decode_mb(h, sl);
2818 sl->mb_y++;
2819 ret = ff_h264_decode_mb_cavlc(h, sl);
2822 ff_h264_hl_decode_mb(h, sl);
2823 sl->mb_y--;
2828 "error while decoding MB %d %d\n", sl->mb_x, sl->mb_y);
2829 er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x,
2830 sl->mb_y, ER_MB_ERROR);
2834 if (++sl->mb_x >= h->mb_width) {
2835 loop_filter(h, sl, lf_x_start, sl->mb_x);
2836 sl->mb_x = lf_x_start = 0;
2837 decode_finish_row(h, sl);
2838 ++sl->mb_y;
2840 ++sl->mb_y;
2841 if (FRAME_MBAFF(h) && sl->mb_y < h->mb_height)
2842 predict_field_decoding_flag(h, sl);
2844 if (sl->mb_y >= h->mb_height) {
2846 get_bits_count(&sl->gb), sl->gb.size_in_bits);
2848 if ( get_bits_left(&sl->gb) == 0
2849 || get_bits_left(&sl->gb) > 0 && !(h->avctx->err_recognition & AV_EF_AGGRESSIVE)) {
2850 er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y,
2851 sl->mb_x - 1, sl->mb_y, ER_MB_END);
2855 er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y,
2856 sl->mb_x, sl->mb_y, ER_MB_END);
2863 if (get_bits_left(&sl->gb) <= 0 && sl->mb_skip_run <= 0) {
2865 get_bits_count(&sl->gb), sl->gb.size_in_bits);
2867 if (get_bits_left(&sl->gb) == 0) {
2868 er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y,
2869 sl->mb_x - 1, sl->mb_y, ER_MB_END);
2870 if (sl->mb_x > lf_x_start)
2871 loop_filter(h, sl, lf_x_start, sl->mb_x);
2875 er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x,
2876 sl->mb_y, ER_MB_ERROR);
2885 sl->deblocking_filter = orig_deblock;
2897 H264SliceContext *sl;
2924 sl = &h->slice_ctx[i];
2927 slice_idx = sl->mb_y * h->mb_width + sl->mb_x;
2936 sl->next_slice_idx = next_slice_idx;
2943 sl = &h->slice_ctx[context_count - 1];
2944 h->mb_y = sl->mb_y;
2952 sl = &h->slice_ctx[i];
2953 y_end = FFMIN(sl->mb_y + 1, h->mb_height);
2954 x_end = (sl->mb_y >= h->mb_height) ? h->mb_width : sl->mb_x;
2956 for (j = sl->resync_mb_y; j < y_end; j += 1 + FIELD_OR_MBAFF_PICTURE(h)) {
2957 sl->mb_y = j;
2958 loop_filter(h, sl, j > sl->resync_mb_y ? 0 : sl->resync_mb_x,