From 95eb35f30513e335990ad0d5dca6ddc318477291 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 17 Jan 2015 22:28:46 +0100 Subject: [PATCH] h264: move the ref lists variables into the per-slice context --- libavcodec/dxva2_h264.c | 15 ++--- libavcodec/h264.c | 27 ++++----- libavcodec/h264.h | 26 +++++---- libavcodec/h264_cabac.c | 24 ++++---- libavcodec/h264_cavlc.c | 24 ++++---- libavcodec/h264_direct.c | 104 +++++++++++++++++----------------- libavcodec/h264_loopfilter.c | 4 +- libavcodec/h264_mb.c | 20 +++---- libavcodec/h264_mb_template.c | 8 +-- libavcodec/h264_mvpred.h | 2 +- libavcodec/h264_parser.c | 4 +- libavcodec/h264_picture.c | 6 +- libavcodec/h264_refs.c | 50 ++++++++-------- libavcodec/h264_slice.c | 77 ++++++++++++------------- libavcodec/vaapi_h264.c | 13 +++-- libavcodec/vdpau_h264.c | 3 +- 16 files changed, 208 insertions(+), 199 deletions(-) diff --git a/libavcodec/dxva2_h264.c b/libavcodec/dxva2_h264.c index ef2fc3d898..fcd7b3a1f5 100644 --- a/libavcodec/dxva2_h264.c +++ b/libavcodec/dxva2_h264.c @@ -228,10 +228,10 @@ static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice, slice->slice_type += 5; slice->luma_log2_weight_denom = sl->luma_log2_weight_denom; slice->chroma_log2_weight_denom = sl->chroma_log2_weight_denom; - if (h->list_count > 0) - slice->num_ref_idx_l0_active_minus1 = h->ref_count[0] - 1; - if (h->list_count > 1) - slice->num_ref_idx_l1_active_minus1 = h->ref_count[1] - 1; + if (sl->list_count > 0) + slice->num_ref_idx_l0_active_minus1 = sl->ref_count[0] - 1; + if (sl->list_count > 1) + slice->num_ref_idx_l1_active_minus1 = sl->ref_count[1] - 1; slice->slice_alpha_c0_offset_div2 = h->slice_alpha_c0_offset / 2; slice->slice_beta_offset_div2 = h->slice_beta_offset / 2; slice->Reserved8Bits = 0; @@ -239,8 +239,8 @@ static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice, for (list = 0; list < 2; list++) { unsigned i; for (i = 0; i < FF_ARRAY_ELEMS(slice->RefPicList[list]); i++) { - if (list < h->list_count && i < h->ref_count[list]) { - const H264Picture *r = &h->ref_list[list][i]; + if (list < sl->list_count && i < sl->ref_count[list]) { + const H264Picture *r = &sl->ref_list[list][i]; unsigned plane; unsigned index; if (ctx->workaround & FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO) @@ -447,6 +447,7 @@ static int dxva2_h264_decode_slice(AVCodecContext *avctx, static int dxva2_h264_end_frame(AVCodecContext *avctx) { H264Context *h = avctx->priv_data; + H264SliceContext *sl = &h->slice_ctx[0]; struct dxva2_picture_context *ctx_pic = h->cur_pic_ptr->hwaccel_picture_private; int ret; @@ -458,7 +459,7 @@ static int dxva2_h264_end_frame(AVCodecContext *avctx) &ctx_pic->qm, sizeof(ctx_pic->qm), commit_bitstream_and_slice_buffer); if (!ret) - ff_h264_draw_horiz_band(h, 0, h->avctx->height); + ff_h264_draw_horiz_band(h, sl, 0, h->avctx->height); return ret; } diff --git a/libavcodec/h264.c b/libavcodec/h264.c index 8196fd4e6d..4a3ee34a63 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -67,7 +67,7 @@ static void h264_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type, * differ between slices. We take the easy approach and ignore * it for now. If this turns out to have any relevance in * practice then correct remapping should be added. */ - if (ref >= h->ref_count[0]) + if (ref >= sl->ref_count[0]) ref = 0; fill_rectangle(&h->cur_pic.ref_index[0][4 * h->mb_xy], 2, 2, 2, ref, 1); @@ -78,11 +78,12 @@ static void h264_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type, ff_h264_hl_decode_mb(h, &h->slice_ctx[0]); } -void ff_h264_draw_horiz_band(H264Context *h, int y, int height) +void ff_h264_draw_horiz_band(H264Context *h, H264SliceContext *sl, + int y, int height) { AVCodecContext *avctx = h->avctx; AVFrame *cur = &h->cur_pic.f; - AVFrame *last = h->ref_list[0][0].f.data[0] ? &h->ref_list[0][0].f : NULL; + AVFrame *last = sl->ref_list[0][0].f.data[0] ? &sl->ref_list[0][0].f : NULL; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt); int vshift = desc->log2_chroma_h; const int field_pic = h->picture_structure != PICT_FRAME; @@ -1019,7 +1020,7 @@ int ff_pred_weight_table(H264Context *h, H264SliceContext *sl) for (list = 0; list < 2; list++) { sl->luma_weight_flag[list] = 0; sl->chroma_weight_flag[list] = 0; - for (i = 0; i < h->ref_count[list]; i++) { + for (i = 0; i < sl->ref_count[list]; i++) { int luma_weight_flag, chroma_weight_flag; luma_weight_flag = get_bits1(&h->gb); @@ -1297,16 +1298,16 @@ int ff_set_ref_count(H264Context *h, H264SliceContext *sl) if (ref_count[0] > max_refs || ref_count[1] > max_refs) { av_log(h->avctx, AV_LOG_ERROR, "reference overflow\n"); - h->ref_count[0] = h->ref_count[1] = 0; + sl->ref_count[0] = sl->ref_count[1] = 0; return AVERROR_INVALIDDATA; } - if (list_count != h->list_count || - ref_count[0] != h->ref_count[0] || - ref_count[1] != h->ref_count[1]) { - h->ref_count[0] = ref_count[0]; - h->ref_count[1] = ref_count[1]; - h->list_count = list_count; + if (list_count != sl->list_count || + ref_count[0] != sl->ref_count[0] || + ref_count[1] != sl->ref_count[1]) { + sl->ref_count[0] = ref_count[0]; + sl->ref_count[1] = ref_count[1]; + sl->list_count = list_count; return 1; } @@ -1642,7 +1643,7 @@ again: if (err < 0) { av_log(h->avctx, AV_LOG_ERROR, "decode_slice_header error\n"); - h->ref_count[0] = h->ref_count[1] = h->list_count = 0; + sl->ref_count[0] = sl->ref_count[1] = sl->list_count = 0; } else if (err == 1) { /* Slice could not be decoded in parallel mode, copy down * NAL unit stuff to context 0 and restart. Note that @@ -1773,7 +1774,7 @@ out: if (avctx->flags2 & CODEC_FLAG2_CHUNKS) decode_postinit(h, 1); - ff_h264_field_end(h, 0); + ff_h264_field_end(h, &h->slice_ctx[0], 0); *got_frame = 0; if (h->next_output_pic && ((avctx->flags & CODEC_FLAG_OUTPUT_CORRUPT) || diff --git a/libavcodec/h264.h b/libavcodec/h264.h index 5221e2d64c..882aeb558f 100644 --- a/libavcodec/h264.h +++ b/libavcodec/h264.h @@ -364,6 +364,17 @@ typedef struct H264SliceContext { int map_col_to_list0[2][16 + 32]; int map_col_to_list0_field[2][2][16 + 32]; + /** + * num_ref_idx_l0/1_active_minus1 + 1 + */ + unsigned int ref_count[2]; ///< counts frames or fields, depending on current mb mode + unsigned int list_count; + H264Picture ref_list[2][48]; /**< 0..15: frame refs, 16..47: mbaff field refs. + * Reordered version of default_ref_list + * according to picture reordering in slice header */ + int ref2frm[MAX_SLICES][2][64]; ///< reference to frame number lists, used in the loop filter, the first 2 are for -2,-1 + + /** * non zero coeff count cache. * is 64 if not available. @@ -449,16 +460,7 @@ typedef struct H264Context { int picture_structure; int first_field; - /** - * num_ref_idx_l0/1_active_minus1 + 1 - */ - unsigned int ref_count[2]; ///< counts frames or fields, depending on current mb mode - unsigned int list_count; uint8_t *list_counts; ///< Array of list_count per MB specifying the slice type - H264Picture ref_list[2][48]; /**< 0..15: frame refs, 16..47: mbaff field refs. - * Reordered version of default_ref_list - * according to picture reordering in slice header */ - int ref2frm[MAX_SLICES][2][64]; ///< reference to frame number lists, used in the loop filter, the first 2 are for -2,-1 // data partitioning GetBitContext intra_gb; @@ -773,7 +775,7 @@ int ff_h264_alloc_tables(H264Context *h); */ int ff_h264_fill_default_ref_list(H264Context *h, H264SliceContext *sl); -int ff_h264_decode_ref_pic_list_reordering(H264Context *h); +int ff_h264_decode_ref_pic_list_reordering(H264Context *h, H264SliceContext *sl); void ff_h264_fill_mbaff_ref_list(H264Context *h, H264SliceContext *sl); void ff_h264_remove_all_refs(H264Context *h); @@ -1046,7 +1048,7 @@ static av_always_inline int get_dct8x8_allowed(H264Context *h, H264SliceContext 0x0001000100010001ULL)); } -int ff_h264_field_end(H264Context *h, int in_setup); +int ff_h264_field_end(H264Context *h, H264SliceContext *sl, int in_setup); int ff_h264_ref_picture(H264Context *h, H264Picture *dst, H264Picture *src); void ff_h264_unref_picture(H264Context *h, H264Picture *pic); @@ -1054,7 +1056,7 @@ void ff_h264_unref_picture(H264Context *h, H264Picture *pic); int ff_h264_context_init(H264Context *h); int ff_h264_set_parameter_from_sps(H264Context *h); -void ff_h264_draw_horiz_band(H264Context *h, int y, int height); +void ff_h264_draw_horiz_band(H264Context *h, H264SliceContext *sl, int y, int height); int ff_init_poc(H264Context *h, int pic_field_poc[2], int *pic_poc); int ff_pred_weight_table(H264Context *h, H264SliceContext *sl); int ff_set_ref_count(H264Context *h, H264SliceContext *sl); diff --git a/libavcodec/h264_cabac.c b/libavcodec/h264_cabac.c index 711b3de0dc..1c236095c0 100644 --- a/libavcodec/h264_cabac.c +++ b/libavcodec/h264_cabac.c @@ -2112,11 +2112,11 @@ decode_intra_mb: } } - for( list = 0; list < h->list_count; list++ ) { + for( list = 0; list < sl->list_count; list++ ) { for( i = 0; i < 4; i++ ) { if(IS_DIRECT(sl->sub_mb_type[i])) continue; if(IS_DIR(sl->sub_mb_type[i], 0, list)){ - int rc = h->ref_count[list] << MB_MBAFF(h); + int rc = sl->ref_count[list] << MB_MBAFF(h); if (rc > 1) { ref[list][i] = decode_cabac_mb_ref(h, sl, list, 4 * i); if (ref[list][i] >= (unsigned) rc) { @@ -2136,7 +2136,7 @@ decode_intra_mb: if(dct8x8_allowed) dct8x8_allowed = get_dct8x8_allowed(h, sl); - for(list=0; listlist_count; list++){ + for (list = 0; list < sl->list_count; list++) { for(i=0; i<4; i++){ sl->ref_cache[list][scan8[4 * i]] = sl->ref_cache[list][scan8[4 * i] + 1]; if(IS_DIRECT(sl->sub_mb_type[i])){ @@ -2200,9 +2200,9 @@ decode_intra_mb: } else { int list, i; if(IS_16X16(mb_type)){ - for(list=0; listlist_count; list++){ + for (list = 0; list < sl->list_count; list++) { if(IS_DIR(mb_type, 0, list)){ - int ref, rc = h->ref_count[list] << MB_MBAFF(h); + int ref, rc = sl->ref_count[list] << MB_MBAFF(h); if (rc > 1) { ref= decode_cabac_mb_ref(h, sl, list, 0); if (ref >= (unsigned) rc) { @@ -2214,7 +2214,7 @@ decode_intra_mb: fill_rectangle(&sl->ref_cache[list][ scan8[0] ], 4, 4, 8, ref, 1); } } - for(list=0; listlist_count; list++){ + for (list = 0; list < sl->list_count; list++) { if(IS_DIR(mb_type, 0, list)){ int mx,my,mpx,mpy; pred_motion(h, sl, 0, 4, list, sl->ref_cache[list][ scan8[0] ], &mx, &my); @@ -2227,10 +2227,10 @@ decode_intra_mb: } } else if(IS_16X8(mb_type)){ - for(list=0; listlist_count; list++){ + for (list = 0; list < sl->list_count; list++) { for(i=0; i<2; i++){ if(IS_DIR(mb_type, i, list)){ - int ref, rc = h->ref_count[list] << MB_MBAFF(h); + int ref, rc = sl->ref_count[list] << MB_MBAFF(h); if (rc > 1) { ref= decode_cabac_mb_ref(h, sl, list, 8 * i); if (ref >= (unsigned) rc) { @@ -2244,7 +2244,7 @@ decode_intra_mb: fill_rectangle(&sl->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (LIST_NOT_USED&0xFF), 1); } } - for(list=0; listlist_count; list++){ + for (list = 0; list < sl->list_count; list++) { for(i=0; i<2; i++){ if(IS_DIR(mb_type, i, list)){ int mx,my,mpx,mpy; @@ -2262,10 +2262,10 @@ decode_intra_mb: } }else{ assert(IS_8X16(mb_type)); - for(list=0; listlist_count; list++){ + for (list = 0; list < sl->list_count; list++) { for(i=0; i<2; i++){ if(IS_DIR(mb_type, i, list)){ //FIXME optimize - int ref, rc = h->ref_count[list] << MB_MBAFF(h); + int ref, rc = sl->ref_count[list] << MB_MBAFF(h); if (rc > 1) { ref= decode_cabac_mb_ref(h, sl, list, 4 * i); if (ref >= (unsigned) rc) { @@ -2279,7 +2279,7 @@ decode_intra_mb: fill_rectangle(&sl->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (LIST_NOT_USED&0xFF), 1); } } - for(list=0; listlist_count; list++){ + for (list = 0; list < sl->list_count; list++) { for(i=0; i<2; i++){ if(IS_DIR(mb_type, i, list)){ int mx,my,mpx,mpy; diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c index 98a20e16c1..63faabf2dd 100644 --- a/libavcodec/h264_cavlc.c +++ b/libavcodec/h264_cavlc.c @@ -864,8 +864,8 @@ decode_intra_mb: } } - for(list=0; listlist_count; list++){ - int ref_count = IS_REF0(mb_type) ? 1 : h->ref_count[list] << MB_MBAFF(h); + for (list = 0; list < sl->list_count; list++) { + int ref_count = IS_REF0(mb_type) ? 1 : sl->ref_count[list] << MB_MBAFF(h); for(i=0; i<4; i++){ if(IS_DIRECT(sl->sub_mb_type[i])) continue; if(IS_DIR(sl->sub_mb_type[i], 0, list)){ @@ -892,7 +892,7 @@ decode_intra_mb: if(dct8x8_allowed) dct8x8_allowed = get_dct8x8_allowed(h, sl); - for(list=0; listlist_count; list++){ + for (list = 0; list < sl->list_count; list++) { for(i=0; i<4; i++){ if(IS_DIRECT(sl->sub_mb_type[i])) { sl->ref_cache[list][ scan8[4*i] ] = sl->ref_cache[list][ scan8[4*i]+1 ]; @@ -942,10 +942,10 @@ decode_intra_mb: int list, mx, my, i; //FIXME we should set ref_idx_l? to 0 if we use that later ... if(IS_16X16(mb_type)){ - for(list=0; listlist_count; list++){ + for (list = 0; list < sl->list_count; list++) { unsigned int val; if(IS_DIR(mb_type, 0, list)){ - int rc = h->ref_count[list] << MB_MBAFF(h); + int rc = sl->ref_count[list] << MB_MBAFF(h); if (rc == 1) { val= 0; } else if (rc == 2) { @@ -960,7 +960,7 @@ decode_intra_mb: fill_rectangle(&sl->ref_cache[list][ scan8[0] ], 4, 4, 8, val, 1); } } - for(list=0; listlist_count; list++){ + for (list = 0; list < sl->list_count; list++) { if(IS_DIR(mb_type, 0, list)){ pred_motion(h, sl, 0, 4, list, sl->ref_cache[list][ scan8[0] ], &mx, &my); mx += get_se_golomb(&h->gb); @@ -972,11 +972,11 @@ decode_intra_mb: } } else if(IS_16X8(mb_type)){ - for(list=0; listlist_count; list++){ + for (list = 0; list < sl->list_count; list++) { for(i=0; i<2; i++){ unsigned int val; if(IS_DIR(mb_type, i, list)){ - int rc = h->ref_count[list] << MB_MBAFF(h); + int rc = sl->ref_count[list] << MB_MBAFF(h); if (rc == 1) { val= 0; } else if (rc == 2) { @@ -993,7 +993,7 @@ decode_intra_mb: fill_rectangle(&sl->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 1); } } - for(list=0; listlist_count; list++){ + for (list = 0; list < sl->list_count; list++) { for(i=0; i<2; i++){ unsigned int val; if(IS_DIR(mb_type, i, list)){ @@ -1010,11 +1010,11 @@ decode_intra_mb: } }else{ assert(IS_8X16(mb_type)); - for(list=0; listlist_count; list++){ + for (list = 0; list < sl->list_count; list++) { for(i=0; i<2; i++){ unsigned int val; if(IS_DIR(mb_type, i, list)){ //FIXME optimize - int rc = h->ref_count[list] << MB_MBAFF(h); + int rc = sl->ref_count[list] << MB_MBAFF(h); if (rc == 1) { val= 0; } else if (rc == 2) { @@ -1031,7 +1031,7 @@ decode_intra_mb: fill_rectangle(&sl->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 1); } } - for(list=0; listlist_count; list++){ + for (list = 0; list < sl->list_count; list++) { for(i=0; i<2; i++){ unsigned int val; if(IS_DIR(mb_type, i, list)){ diff --git a/libavcodec/h264_direct.c b/libavcodec/h264_direct.c index 08aacd3bb9..67d9faea78 100644 --- a/libavcodec/h264_direct.c +++ b/libavcodec/h264_direct.c @@ -34,11 +34,12 @@ #include -static int get_scale_factor(H264Context *const h, int poc, int poc1, int i) +static int get_scale_factor(H264Context *const h, H264SliceContext *sl, + int poc, int poc1, int i) { - int poc0 = h->ref_list[0][i].poc; + int poc0 = sl->ref_list[0][i].poc; int td = av_clip_int8(poc1 - poc0); - if (td == 0 || h->ref_list[0][i].long_ref) { + if (td == 0 || sl->ref_list[0][i].long_ref) { return 256; } else { int tb = av_clip_int8(poc - poc0); @@ -52,29 +53,30 @@ void ff_h264_direct_dist_scale_factor(H264Context *const h, { const int poc = FIELD_PICTURE(h) ? h->cur_pic_ptr->field_poc[h->picture_structure == PICT_BOTTOM_FIELD] : h->cur_pic_ptr->poc; - const int poc1 = h->ref_list[1][0].poc; + const int poc1 = sl->ref_list[1][0].poc; int i, field; if (FRAME_MBAFF(h)) for (field = 0; field < 2; field++) { const int poc = h->cur_pic_ptr->field_poc[field]; - const int poc1 = h->ref_list[1][0].field_poc[field]; - for (i = 0; i < 2 * h->ref_count[0]; i++) + const int poc1 = sl->ref_list[1][0].field_poc[field]; + for (i = 0; i < 2 * sl->ref_count[0]; i++) sl->dist_scale_factor_field[field][i ^ field] = - get_scale_factor(h, poc, poc1, i + 16); + get_scale_factor(h, sl, poc, poc1, i + 16); } - for (i = 0; i < h->ref_count[0]; i++) - sl->dist_scale_factor[i] = get_scale_factor(h, poc, poc1, i); + for (i = 0; i < sl->ref_count[0]; i++) + sl->dist_scale_factor[i] = get_scale_factor(h, sl, poc, poc1, i); } -static void fill_colmap(H264Context *h, int map[2][16 + 32], int list, +static void fill_colmap(H264Context *h, H264SliceContext *sl, + int map[2][16 + 32], int list, int field, int colfield, int mbafi) { - H264Picture *const ref1 = &h->ref_list[1][0]; + H264Picture *const ref1 = &sl->ref_list[1][0]; int j, old_ref, rfield; int start = mbafi ? 16 : 0; - int end = mbafi ? 16 + 2 * h->ref_count[0] : h->ref_count[0]; + int end = mbafi ? 16 + 2 * sl->ref_count[0] : sl->ref_count[0]; int interl = mbafi || h->picture_structure != PICT_FRAME; /* bogus; fills in for missing frames */ @@ -91,8 +93,8 @@ static void fill_colmap(H264Context *h, int map[2][16 + 32], int list, poc = (poc & ~3) + rfield + 1; for (j = start; j < end; j++) { - if (4 * h->ref_list[0][j].frame_num + - (h->ref_list[0][j].reference & 3) == poc) { + if (4 * sl->ref_list[0][j].frame_num + + (sl->ref_list[0][j].reference & 3) == poc) { int cur_ref = mbafi ? (j - 16) ^ field : j; if (ref1->mbaff) map[list][2 * old_ref + (rfield ^ field) + 16] = cur_ref; @@ -107,17 +109,17 @@ static void fill_colmap(H264Context *h, int map[2][16 + 32], int list, void ff_h264_direct_ref_list_init(H264Context *const h, H264SliceContext *sl) { - H264Picture *const ref1 = &h->ref_list[1][0]; + H264Picture *const ref1 = &sl->ref_list[1][0]; H264Picture *const cur = h->cur_pic_ptr; int list, j, field; int sidx = (h->picture_structure & 1) ^ 1; int ref1sidx = (ref1->reference & 1) ^ 1; for (list = 0; list < 2; list++) { - cur->ref_count[sidx][list] = h->ref_count[list]; - for (j = 0; j < h->ref_count[list]; j++) - cur->ref_poc[sidx][list][j] = 4 * h->ref_list[list][j].frame_num + - (h->ref_list[list][j].reference & 3); + cur->ref_count[sidx][list] = sl->ref_count[list]; + for (j = 0; j < sl->ref_count[list]; j++) + cur->ref_poc[sidx][list][j] = 4 * sl->ref_list[list][j].frame_num + + (sl->ref_list[list][j].reference & 3); } if (h->picture_structure == PICT_FRAME) { @@ -130,25 +132,25 @@ void ff_h264_direct_ref_list_init(H264Context *const h, H264SliceContext *sl) sl->col_fieldoff = 0; if (h->picture_structure == PICT_FRAME) { int cur_poc = h->cur_pic_ptr->poc; - int *col_poc = h->ref_list[1]->field_poc; + int *col_poc = sl->ref_list[1]->field_poc; sl->col_parity = (FFABS(col_poc[0] - cur_poc) >= FFABS(col_poc[1] - cur_poc)); ref1sidx = sidx = sl->col_parity; // FL -> FL & differ parity - } else if (!(h->picture_structure & h->ref_list[1][0].reference) && - !h->ref_list[1][0].mbaff) { - sl->col_fieldoff = 2 * h->ref_list[1][0].reference - 3; + } else if (!(h->picture_structure & sl->ref_list[1][0].reference) && + !sl->ref_list[1][0].mbaff) { + sl->col_fieldoff = 2 * sl->ref_list[1][0].reference - 3; } if (sl->slice_type_nos != AV_PICTURE_TYPE_B || sl->direct_spatial_mv_pred) return; for (list = 0; list < 2; list++) { - fill_colmap(h, sl->map_col_to_list0, list, sidx, ref1sidx, 0); + fill_colmap(h, sl, sl->map_col_to_list0, list, sidx, ref1sidx, 0); if (FRAME_MBAFF(h)) for (field = 0; field < 2; field++) - fill_colmap(h, sl->map_col_to_list0_field[field], list, field, + fill_colmap(h, sl, sl->map_col_to_list0_field[field], list, field, field, 1); } } @@ -188,9 +190,9 @@ static void pred_spatial_direct_motion(H264Context *const h, H264SliceContext *s int mv[2]; int list; - assert(h->ref_list[1][0].reference & 3); + assert(sl->ref_list[1][0].reference & 3); - await_reference_mb_row(h, &h->ref_list[1][0], + await_reference_mb_row(h, &sl->ref_list[1][0], h->mb_y + !!IS_INTERLACED(*mb_type)); #define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16 | MB_TYPE_INTRA4x4 | \ @@ -258,7 +260,7 @@ static void pred_spatial_direct_motion(H264Context *const h, H264SliceContext *s return; } - if (IS_INTERLACED(h->ref_list[1][0].mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL + if (IS_INTERLACED(sl->ref_list[1][0].mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL mb_y = (h->mb_y & ~1) + sl->col_parity; mb_xy = h->mb_x + @@ -273,8 +275,8 @@ static void pred_spatial_direct_motion(H264Context *const h, H264SliceContext *s if (IS_INTERLACED(*mb_type)) { // AFL /FL -> AFR/FR mb_y = h->mb_y & ~1; mb_xy = (h->mb_y & ~1) * h->mb_stride + h->mb_x; - mb_type_col[0] = h->ref_list[1][0].mb_type[mb_xy]; - mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy + h->mb_stride]; + mb_type_col[0] = sl->ref_list[1][0].mb_type[mb_xy]; + mb_type_col[1] = sl->ref_list[1][0].mb_type[mb_xy + h->mb_stride]; b8_stride = 2 + 4 * h->mb_stride; b4_stride *= 6; if (IS_INTERLACED(mb_type_col[0]) != @@ -294,7 +296,7 @@ static void pred_spatial_direct_motion(H264Context *const h, H264SliceContext *s } else { // AFR/FR -> AFR/FR single_col: mb_type_col[0] = - mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy]; + mb_type_col[1] = sl->ref_list[1][0].mb_type[mb_xy]; sub_mb_type |= MB_TYPE_16x16 | MB_TYPE_DIRECT2; /* B_SUB_8x8 */ if (!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)) { @@ -314,12 +316,12 @@ single_col: } } - await_reference_mb_row(h, &h->ref_list[1][0], mb_y); + await_reference_mb_row(h, &sl->ref_list[1][0], mb_y); - l1mv0 = &h->ref_list[1][0].motion_val[0][h->mb2b_xy[mb_xy]]; - l1mv1 = &h->ref_list[1][0].motion_val[1][h->mb2b_xy[mb_xy]]; - l1ref0 = &h->ref_list[1][0].ref_index[0][4 * mb_xy]; - l1ref1 = &h->ref_list[1][0].ref_index[1][4 * mb_xy]; + l1mv0 = &sl->ref_list[1][0].motion_val[0][h->mb2b_xy[mb_xy]]; + l1mv1 = &sl->ref_list[1][0].motion_val[1][h->mb2b_xy[mb_xy]]; + l1ref0 = &sl->ref_list[1][0].ref_index[0][4 * mb_xy]; + l1ref1 = &sl->ref_list[1][0].ref_index[1][4 * mb_xy]; if (!b8_stride) { if (h->mb_y & 1) { l1ref0 += 2; @@ -346,7 +348,7 @@ single_col: (uint8_t)ref[0], 1); fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8, (uint8_t)ref[1], 1); - if (!IS_INTRA(mb_type_col[y8]) && !h->ref_list[1][0].long_ref && + if (!IS_INTRA(mb_type_col[y8]) && !sl->ref_list[1][0].long_ref && ((l1ref0[xy8] == 0 && FFABS(l1mv0[xy4][0]) <= 1 && FFABS(l1mv0[xy4][1]) <= 1) || @@ -377,7 +379,7 @@ single_col: fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1); fill_rectangle(&sl->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1); - if (!IS_INTRA(mb_type_col[0]) && !h->ref_list[1][0].long_ref && + if (!IS_INTRA(mb_type_col[0]) && !sl->ref_list[1][0].long_ref && ((l1ref0[0] == 0 && FFABS(l1mv0[0][0]) <= 1 && FFABS(l1mv0[0][1]) <= 1) || @@ -415,7 +417,7 @@ single_col: assert(b8_stride == 2); /* col_zero_flag */ - if (!IS_INTRA(mb_type_col[0]) && !h->ref_list[1][0].long_ref && + if (!IS_INTRA(mb_type_col[0]) && !sl->ref_list[1][0].long_ref && (l1ref0[i8] == 0 || (l1ref0[i8] < 0 && l1ref1[i8] == 0 && @@ -471,12 +473,12 @@ static void pred_temp_direct_motion(H264Context *const h, H264SliceContext *sl, unsigned int sub_mb_type; int i8, i4; - assert(h->ref_list[1][0].reference & 3); + assert(sl->ref_list[1][0].reference & 3); - await_reference_mb_row(h, &h->ref_list[1][0], + await_reference_mb_row(h, &sl->ref_list[1][0], h->mb_y + !!IS_INTERLACED(*mb_type)); - if (IS_INTERLACED(h->ref_list[1][0].mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL + if (IS_INTERLACED(sl->ref_list[1][0].mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL mb_y = (h->mb_y & ~1) + sl->col_parity; mb_xy = h->mb_x + @@ -491,8 +493,8 @@ static void pred_temp_direct_motion(H264Context *const h, H264SliceContext *sl, if (IS_INTERLACED(*mb_type)) { // AFL /FL -> AFR/FR mb_y = h->mb_y & ~1; mb_xy = h->mb_x + (h->mb_y & ~1) * h->mb_stride; - mb_type_col[0] = h->ref_list[1][0].mb_type[mb_xy]; - mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy + h->mb_stride]; + mb_type_col[0] = sl->ref_list[1][0].mb_type[mb_xy]; + mb_type_col[1] = sl->ref_list[1][0].mb_type[mb_xy + h->mb_stride]; b8_stride = 2 + 4 * h->mb_stride; b4_stride *= 6; if (IS_INTERLACED(mb_type_col[0]) != @@ -515,7 +517,7 @@ static void pred_temp_direct_motion(H264Context *const h, H264SliceContext *sl, } else { // AFR/FR -> AFR/FR single_col: mb_type_col[0] = - mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy]; + mb_type_col[1] = sl->ref_list[1][0].mb_type[mb_xy]; sub_mb_type = MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P0L1 | MB_TYPE_DIRECT2; /* B_SUB_8x8 */ @@ -538,12 +540,12 @@ single_col: } } - await_reference_mb_row(h, &h->ref_list[1][0], mb_y); + await_reference_mb_row(h, &sl->ref_list[1][0], mb_y); - l1mv0 = &h->ref_list[1][0].motion_val[0][h->mb2b_xy[mb_xy]]; - l1mv1 = &h->ref_list[1][0].motion_val[1][h->mb2b_xy[mb_xy]]; - l1ref0 = &h->ref_list[1][0].ref_index[0][4 * mb_xy]; - l1ref1 = &h->ref_list[1][0].ref_index[1][4 * mb_xy]; + l1mv0 = &sl->ref_list[1][0].motion_val[0][h->mb2b_xy[mb_xy]]; + l1mv1 = &sl->ref_list[1][0].motion_val[1][h->mb2b_xy[mb_xy]]; + l1ref0 = &sl->ref_list[1][0].ref_index[0][4 * mb_xy]; + l1ref1 = &sl->ref_list[1][0].ref_index[1][4 * mb_xy]; if (!b8_stride) { if (h->mb_y & 1) { l1ref0 += 2; @@ -564,7 +566,7 @@ single_col: map_col_to_list0[1] = sl->map_col_to_list0_field[h->mb_y & 1][1]; dist_scale_factor = sl->dist_scale_factor_field[h->mb_y & 1]; } - ref_offset = (h->ref_list[1][0].mbaff << 4) & (mb_type_col[0] >> 3); + ref_offset = (sl->ref_list[1][0].mbaff << 4) & (mb_type_col[0] >> 3); if (IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])) { int y_shift = 2 * !IS_INTERLACED(*mb_type); diff --git a/libavcodec/h264_loopfilter.c b/libavcodec/h264_loopfilter.c index 4d34a29eb2..4ac04b14b4 100644 --- a/libavcodec/h264_loopfilter.c +++ b/libavcodec/h264_loopfilter.c @@ -372,7 +372,7 @@ static av_always_inline void h264_filter_mb_fast_internal(H264Context *h, int step = 1+(mb_type>>24); //IS_8x8DCT(mb_type) ? 2 : 1; edges = 4 - 3*((mb_type>>3) & !(h->cbp & 15)); //(mb_type & MB_TYPE_16x16) && !(h->cbp & 15) ? 1 : 4; h->h264dsp.h264_loop_filter_strength(bS, sl->non_zero_count_cache, sl->ref_cache, sl->mv_cache, - h->list_count==2, edges, step, mask_edge0, mask_edge1, FIELD_PICTURE(h)); + sl->list_count==2, edges, step, mask_edge0, mask_edge1, FIELD_PICTURE(h)); } if( IS_INTRA(left_type) ) AV_WN64A(bS[0][0], 0x0004000400040004ULL); @@ -447,7 +447,7 @@ static int check_mv(H264Context *h, H264SliceContext *sl, long b_idx, long bn_id v = sl->mv_cache[0][b_idx][0] - sl->mv_cache[0][bn_idx][0] + 3 >= 7U | FFABS(sl->mv_cache[0][b_idx][1] - sl->mv_cache[0][bn_idx][1]) >= mvy_limit; - if(h->list_count==2){ + if (sl->list_count == 2) { if(!v) v = sl->ref_cache[1][b_idx] != sl->ref_cache[1][bn_idx] | sl->mv_cache[1][b_idx][0] - sl->mv_cache[1][bn_idx][0] + 3 >= 7U | diff --git a/libavcodec/h264_mb.c b/libavcodec/h264_mb.c index 8d811a0028..27c0669fb3 100644 --- a/libavcodec/h264_mb.c +++ b/libavcodec/h264_mb.c @@ -61,7 +61,7 @@ static inline void get_lowest_part_y(H264Context *h, H264SliceContext *sl, if (list0) { int ref_n = sl->ref_cache[0][scan8[n]]; - H264Picture *ref = &h->ref_list[0][ref_n]; + H264Picture *ref = &sl->ref_list[0][ref_n]; // Error resilience puts the current picture in the ref list. // Don't try to wait on these as it will cause a deadlock. @@ -77,7 +77,7 @@ static inline void get_lowest_part_y(H264Context *h, H264SliceContext *sl, if (list1) { int ref_n = sl->ref_cache[1][scan8[n]]; - H264Picture *ref = &h->ref_list[1][ref_n]; + H264Picture *ref = &sl->ref_list[1][ref_n]; if (ref->tf.progress->data != h->cur_pic.tf.progress->data || (ref->reference & 3) != h->picture_structure) { @@ -164,11 +164,11 @@ static void await_references(H264Context *h, H264SliceContext *sl) } } - for (list = h->list_count - 1; list >= 0; list--) + for (list = sl->list_count - 1; list >= 0; list--) for (ref = 0; ref < 48 && nrefs[list]; ref++) { int row = refs[list][ref]; if (row >= 0) { - H264Picture *ref_pic = &h->ref_list[list][ref]; + H264Picture *ref_pic = &sl->ref_list[list][ref]; int ref_field = ref_pic->reference - 1; int ref_field_picture = ref_pic->field_picture; int pic_height = 16 * h->mb_height >> ref_field_picture; @@ -349,7 +349,7 @@ static av_always_inline void mc_part_std(H264Context *h, H264SliceContext *sl, y_offset += 8 * (h->mb_y >> MB_FIELD(h)); if (list0) { - H264Picture *ref = &h->ref_list[0][sl->ref_cache[0][scan8[n]]]; + H264Picture *ref = &sl->ref_list[0][sl->ref_cache[0][scan8[n]]]; mc_dir_part(h, sl, ref, n, square, height, delta, 0, dest_y, dest_cb, dest_cr, x_offset, y_offset, qpix_op, chroma_op, pixel_shift, chroma_idc); @@ -359,7 +359,7 @@ static av_always_inline void mc_part_std(H264Context *h, H264SliceContext *sl, } if (list1) { - H264Picture *ref = &h->ref_list[1][sl->ref_cache[1][scan8[n]]]; + H264Picture *ref = &sl->ref_list[1][sl->ref_cache[1][scan8[n]]]; mc_dir_part(h, sl, ref, n, square, height, delta, 1, dest_y, dest_cb, dest_cr, x_offset, y_offset, qpix_op, chroma_op, pixel_shift, chroma_idc); @@ -411,11 +411,11 @@ static av_always_inline void mc_part_weighted(H264Context *h, H264SliceContext * int refn0 = sl->ref_cache[0][scan8[n]]; int refn1 = sl->ref_cache[1][scan8[n]]; - mc_dir_part(h, sl, &h->ref_list[0][refn0], n, square, height, delta, 0, + mc_dir_part(h, sl, &sl->ref_list[0][refn0], n, square, height, delta, 0, dest_y, dest_cb, dest_cr, x_offset, y_offset, qpix_put, chroma_put, pixel_shift, chroma_idc); - mc_dir_part(h, sl, &h->ref_list[1][refn1], n, square, height, delta, 1, + mc_dir_part(h, sl, &sl->ref_list[1][refn1], n, square, height, delta, 1, tmp_y, tmp_cb, tmp_cr, x_offset, y_offset, qpix_put, chroma_put, pixel_shift, chroma_idc); @@ -452,7 +452,7 @@ static av_always_inline void mc_part_weighted(H264Context *h, H264SliceContext * } else { int list = list1 ? 1 : 0; int refn = sl->ref_cache[list][scan8[n]]; - H264Picture *ref = &h->ref_list[list][refn]; + H264Picture *ref = &sl->ref_list[list][refn]; mc_dir_part(h, sl, ref, n, square, height, delta, list, dest_y, dest_cb, dest_cr, x_offset, y_offset, qpix_put, chroma_put, pixel_shift, chroma_idc); @@ -484,7 +484,7 @@ static av_always_inline void prefetch_motion(H264Context *h, H264SliceContext *s if (refn >= 0) { const int mx = (sl->mv_cache[list][scan8[0]][0] >> 2) + 16 * h->mb_x + 8; const int my = (sl->mv_cache[list][scan8[0]][1] >> 2) + 16 * h->mb_y; - uint8_t **src = h->ref_list[list][refn].f.data; + uint8_t **src = sl->ref_list[list][refn].f.data; int off = (mx << pixel_shift) + (my + (h->mb_x & 3) * 4) * sl->mb_linesize + (64 << pixel_shift); diff --git a/libavcodec/h264_mb_template.c b/libavcodec/h264_mb_template.c index bca415ee99..7ce72baa00 100644 --- a/libavcodec/h264_mb_template.c +++ b/libavcodec/h264_mb_template.c @@ -64,7 +64,7 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h, H264SliceContext *sl) h->vdsp.prefetch(dest_y + (h->mb_x & 3) * 4 * h->linesize + (64 << PIXEL_SHIFT), h->linesize, 4); h->vdsp.prefetch(dest_cb + (h->mb_x & 7) * h->uvlinesize + (64 << PIXEL_SHIFT), dest_cr - dest_cb, 2); - h->list_counts[mb_xy] = h->list_count; + h->list_counts[mb_xy] = sl->list_count; if (!SIMPLE && MB_FIELD(h)) { linesize = sl->mb_linesize = h->linesize * 2; @@ -77,7 +77,7 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h, H264SliceContext *sl) } if (FRAME_MBAFF(h)) { int list; - for (list = 0; list < h->list_count; list++) { + for (list = 0; list < sl->list_count; list++) { if (!USES_LIST(mb_type, list)) continue; if (IS_16X16(mb_type)) { @@ -292,7 +292,7 @@ static av_noinline void FUNC(hl_decode_mb_444)(H264Context *h, H264SliceContext h->linesize, 4); } - h->list_counts[mb_xy] = h->list_count; + h->list_counts[mb_xy] = sl->list_count; if (!SIMPLE && MB_FIELD(h)) { linesize = sl->mb_linesize = sl->mb_uvlinesize = h->linesize * 2; @@ -302,7 +302,7 @@ static av_noinline void FUNC(hl_decode_mb_444)(H264Context *h, H264SliceContext dest[p] -= h->linesize * 15; if (FRAME_MBAFF(h)) { int list; - for (list = 0; list < h->list_count; list++) { + for (list = 0; list < sl->list_count; list++) { if (!USES_LIST(mb_type, list)) continue; if (IS_16X16(mb_type)) { diff --git a/libavcodec/h264_mvpred.h b/libavcodec/h264_mvpred.h index 73e136e757..4684077059 100644 --- a/libavcodec/h264_mvpred.h +++ b/libavcodec/h264_mvpred.h @@ -606,7 +606,7 @@ static void fill_decode_caches(H264Context *h, H264SliceContext *sl, int mb_type if (IS_INTER(mb_type) || (IS_DIRECT(mb_type) && sl->direct_spatial_mv_pred)) { int list; int b_stride = h->b_stride; - for (list = 0; list < h->list_count; list++) { + for (list = 0; list < sl->list_count; list++) { int8_t *ref_cache = &sl->ref_cache[list][scan8[0]]; int8_t *ref = h->cur_pic.ref_index[list]; int16_t(*mv_cache)[2] = &sl->mv_cache[list][scan8[0]]; diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c index f5dcc52b8f..0a38260739 100644 --- a/libavcodec/h264_parser.c +++ b/libavcodec/h264_parser.c @@ -114,7 +114,7 @@ static int scan_mmco_reset(AVCodecParserContext *s) if (sl->slice_type_nos != AV_PICTURE_TYPE_I) { int list; - for (list = 0; list < h->list_count; list++) { + for (list = 0; list < sl->list_count; list++) { if (get_bits1(&h->gb)) { int index; for (index = 0; ; index++) { @@ -130,7 +130,7 @@ static int scan_mmco_reset(AVCodecParserContext *s) } else break; - if (index >= h->ref_count[list]) { + if (index >= sl->ref_count[list]) { av_log(h->avctx, AV_LOG_ERROR, "reference count %d overflow\n", index); return AVERROR_INVALIDDATA; diff --git a/libavcodec/h264_picture.c b/libavcodec/h264_picture.c index 1d7461b799..89e83c9ac2 100644 --- a/libavcodec/h264_picture.c +++ b/libavcodec/h264_picture.c @@ -144,7 +144,7 @@ static void h264_set_erpic(ERPicture *dst, H264Picture *src) } #endif /* CONFIG_ERROR_RESILIENCE */ -int ff_h264_field_end(H264Context *h, int in_setup) +int ff_h264_field_end(H264Context *h, H264SliceContext *sl, int in_setup) { AVCodecContext *const avctx = h->avctx; int err = 0; @@ -187,9 +187,9 @@ int ff_h264_field_end(H264Context *h, int in_setup) if (!FIELD_PICTURE(h)) { h264_set_erpic(&h->er.cur_pic, h->cur_pic_ptr); h264_set_erpic(&h->er.last_pic, - h->ref_count[0] ? &h->ref_list[0][0] : NULL); + sl->ref_count[0] ? &sl->ref_list[0][0] : NULL); h264_set_erpic(&h->er.next_pic, - h->ref_count[1] ? &h->ref_list[1][0] : NULL); + sl->ref_count[1] ? &sl->ref_list[1][0] : NULL); ff_er_frame_end(&h->er); } #endif /* CONFIG_ERROR_RESILIENCE */ diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c index 5ecc9ee407..271264cba9 100644 --- a/libavcodec/h264_refs.c +++ b/libavcodec/h264_refs.c @@ -141,8 +141,8 @@ int ff_h264_fill_default_ref_list(H264Context *h, H264SliceContext *sl) FF_ARRAY_ELEMS(h->default_ref_list[0]) - len, h->long_ref, 16, 1, h->picture_structure); - if (len < h->ref_count[list]) - memset(&h->default_ref_list[list][len], 0, sizeof(H264Picture) * (h->ref_count[list] - len)); + if (len < sl->ref_count[list]) + memset(&h->default_ref_list[list][len], 0, sizeof(H264Picture) * (sl->ref_count[list] - len)); lens[list] = len; } @@ -164,18 +164,18 @@ int ff_h264_fill_default_ref_list(H264Context *h, H264SliceContext *sl) FF_ARRAY_ELEMS(h->default_ref_list[0]) - len, h-> long_ref, 16, 1, h->picture_structure); - if (len < h->ref_count[0]) - memset(&h->default_ref_list[0][len], 0, sizeof(H264Picture) * (h->ref_count[0] - len)); + if (len < sl->ref_count[0]) + memset(&h->default_ref_list[0][len], 0, sizeof(H264Picture) * (sl->ref_count[0] - len)); } #ifdef TRACE - for (i = 0; i < h->ref_count[0]; i++) { + for (i = 0; i < sl->ref_count[0]; i++) { tprintf(h->avctx, "List0: %s fn:%d 0x%p\n", (h->default_ref_list[0][i].long_ref ? "LT" : "ST"), h->default_ref_list[0][i].pic_id, h->default_ref_list[0][i].f.data[0]); } if (sl->slice_type_nos == AV_PICTURE_TYPE_B) { - for (i = 0; i < h->ref_count[1]; i++) { + for (i = 0; i < sl->ref_count[1]; i++) { tprintf(h->avctx, "List1: %s fn:%d 0x%p\n", (h->default_ref_list[1][i].long_ref ? "LT" : "ST"), h->default_ref_list[1][i].pic_id, @@ -212,16 +212,16 @@ static int pic_num_extract(H264Context *h, int pic_num, int *structure) return pic_num; } -int ff_h264_decode_ref_pic_list_reordering(H264Context *h) +int ff_h264_decode_ref_pic_list_reordering(H264Context *h, H264SliceContext *sl) { int list, index, pic_structure, i; print_short_term(h); print_long_term(h); - for (list = 0; list < h->list_count; list++) { - for (i = 0; i < h->ref_count[list]; i++) - COPY_PICTURE(&h->ref_list[list][i], &h->default_ref_list[list][i]); + for (list = 0; list < sl->list_count; list++) { + for (i = 0; i < sl->ref_count[list]; i++) + COPY_PICTURE(&sl->ref_list[list][i], &h->default_ref_list[list][i]); if (get_bits1(&h->gb)) { // ref_pic_list_modification_flag_l[01] int pred = h->curr_pic_num; @@ -235,7 +235,7 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h) if (modification_of_pic_nums_idc == 3) break; - if (index >= h->ref_count[list]) { + if (index >= sl->ref_count[list]) { av_log(h->avctx, AV_LOG_ERROR, "reference count overflow\n"); return -1; } @@ -304,30 +304,30 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h) if (i < 0) { av_log(h->avctx, AV_LOG_ERROR, "reference picture missing during reorder\n"); - memset(&h->ref_list[list][index], 0, sizeof(H264Picture)); // FIXME + memset(&sl->ref_list[list][index], 0, sizeof(H264Picture)); // FIXME } else { - for (i = index; i + 1 < h->ref_count[list]; i++) { - if (ref->long_ref == h->ref_list[list][i].long_ref && - ref->pic_id == h->ref_list[list][i].pic_id) + for (i = index; i + 1 < sl->ref_count[list]; i++) { + if (ref->long_ref == sl->ref_list[list][i].long_ref && + ref->pic_id == sl->ref_list[list][i].pic_id) break; } for (; i > index; i--) { - COPY_PICTURE(&h->ref_list[list][i], &h->ref_list[list][i - 1]); + COPY_PICTURE(&sl->ref_list[list][i], &sl->ref_list[list][i - 1]); } - COPY_PICTURE(&h->ref_list[list][index], ref); + COPY_PICTURE(&sl->ref_list[list][index], ref); if (FIELD_PICTURE(h)) { - pic_as_field(&h->ref_list[list][index], pic_structure); + pic_as_field(&sl->ref_list[list][index], pic_structure); } } } } } - for (list = 0; list < h->list_count; list++) { - for (index = 0; index < h->ref_count[list]; index++) { - if (!h->ref_list[list][index].f.buf[0]) { + for (list = 0; list < sl->list_count; list++) { + for (index = 0; index < sl->ref_count[list]; index++) { + if (!sl->ref_list[list][index].f.buf[0]) { av_log(h->avctx, AV_LOG_ERROR, "Missing reference picture\n"); if (h->default_ref_list[list][0].f.buf[0]) - COPY_PICTURE(&h->ref_list[list][index], &h->default_ref_list[list][0]); + COPY_PICTURE(&sl->ref_list[list][index], &h->default_ref_list[list][0]); else return -1; } @@ -341,9 +341,9 @@ void ff_h264_fill_mbaff_ref_list(H264Context *h, H264SliceContext *sl) { int list, i, j; for (list = 0; list < 2; list++) { //FIXME try list_count - for (i = 0; i < h->ref_count[list]; i++) { - H264Picture *frame = &h->ref_list[list][i]; - H264Picture *field = &h->ref_list[list][16 + 2 * i]; + for (i = 0; i < sl->ref_count[list]; i++) { + H264Picture *frame = &sl->ref_list[list][i]; + H264Picture *field = &sl->ref_list[list][16 + 2 * i]; COPY_PICTURE(field, frame); for (j = 0; j < 3; j++) field[0].f.linesize[j] <<= 1; diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index e1ec578bdd..67a8c85236 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -834,20 +834,20 @@ static void implicit_weight_table(H264Context *h, H264SliceContext *sl, int fiel } else { cur_poc = h->cur_pic_ptr->field_poc[h->picture_structure - 1]; } - if (h->ref_count[0] == 1 && h->ref_count[1] == 1 && !FRAME_MBAFF(h) && - h->ref_list[0][0].poc + h->ref_list[1][0].poc == 2 * cur_poc) { + if (sl->ref_count[0] == 1 && sl->ref_count[1] == 1 && !FRAME_MBAFF(h) && + sl->ref_list[0][0].poc + sl->ref_list[1][0].poc == 2 * cur_poc) { sl->use_weight = 0; sl->use_weight_chroma = 0; return; } ref_start = 0; - ref_count0 = h->ref_count[0]; - ref_count1 = h->ref_count[1]; + ref_count0 = sl->ref_count[0]; + ref_count1 = sl->ref_count[1]; } else { cur_poc = h->cur_pic_ptr->field_poc[field]; ref_start = 16; - ref_count0 = 16 + 2 * h->ref_count[0]; - ref_count1 = 16 + 2 * h->ref_count[1]; + ref_count0 = 16 + 2 * sl->ref_count[0]; + ref_count1 = 16 + 2 * sl->ref_count[1]; } sl->use_weight = 2; @@ -856,11 +856,11 @@ static void implicit_weight_table(H264Context *h, H264SliceContext *sl, int fiel sl->chroma_log2_weight_denom = 5; for (ref0 = ref_start; ref0 < ref_count0; ref0++) { - int poc0 = h->ref_list[0][ref0].poc; + int poc0 = sl->ref_list[0][ref0].poc; for (ref1 = ref_start; ref1 < ref_count1; ref1++) { int w = 32; - if (!h->ref_list[0][ref0].long_ref && !h->ref_list[1][ref1].long_ref) { - int poc1 = h->ref_list[1][ref1].poc; + if (!sl->ref_list[0][ref0].long_ref && !sl->ref_list[1][ref1].long_ref) { + int poc1 = sl->ref_list[1][ref1].poc; int td = av_clip_int8(poc1 - poc0); if (td) { int tb = av_clip_int8(cur_poc - poc0); @@ -1190,7 +1190,7 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl, H264Contex if (first_mb_in_slice == 0) { // FIXME better field boundary detection if (h0->current_slice && h->cur_pic_ptr && FIELD_PICTURE(h)) { - ff_h264_field_end(h, 1); + ff_h264_field_end(h, sl, 1); } h0->current_slice = 0; @@ -1602,9 +1602,9 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl, H264Contex 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); + ret = ff_h264_decode_ref_pic_list_reordering(h, sl); if (ret < 0) { - h->ref_count[1] = h->ref_count[0] = 0; + sl->ref_count[1] = sl->ref_count[0] = 0; return ret; } } @@ -1748,13 +1748,13 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl, H264Contex for (j = 0; j < 2; j++) { int id_list[16]; - int *ref2frm = h->ref2frm[sl->slice_num & (MAX_SLICES - 1)][j]; + int *ref2frm = sl->ref2frm[sl->slice_num & (MAX_SLICES - 1)][j]; for (i = 0; i < 16; i++) { id_list[i] = 60; - if (j < h->list_count && i < h->ref_count[j] && - h->ref_list[j][i].f.buf[0]) { + if (j < sl->list_count && i < sl->ref_count[j] && + sl->ref_list[j][i].f.buf[0]) { int k; - AVBuffer *buf = h->ref_list[j][i].f.buf[0]->buffer; + AVBuffer *buf = sl->ref_list[j][i].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; @@ -1771,12 +1771,12 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl, H264Contex ref2frm[0] = ref2frm[1] = -1; for (i = 0; i < 16; i++) - ref2frm[i + 2] = 4 * id_list[i] + (h->ref_list[j][i].reference & 3); + 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] + - (h->ref_list[j][i].reference & 3); + (sl->ref_list[j][i].reference & 3); } if (h->avctx->debug & FF_DEBUG_PICT_INFO) { @@ -1791,7 +1791,7 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl, H264Contex pps_id, h->frame_num, h->cur_pic_ptr->field_poc[0], h->cur_pic_ptr->field_poc[1], - h->ref_count[0], h->ref_count[1], + sl->ref_count[0], sl->ref_count[1], sl->qscale, h->deblocking_filter, h->slice_alpha_c0_offset, h->slice_beta_offset, @@ -1836,7 +1836,7 @@ static av_always_inline void fill_filter_caches_inter(H264Context *h, if (USES_LIST(top_type, list)) { const int b_xy = h->mb2b_xy[top_xy] + 3 * b_stride; const int b8_xy = 4 * top_xy + 2; - int (*ref2frm)[64] = h->ref2frm[h->slice_table[top_xy] & (MAX_SLICES - 1)][0] + (MB_MBAFF(h) ? 20 : 2); + int (*ref2frm)[64] = sl->ref2frm[h->slice_table[top_xy] & (MAX_SLICES - 1)][0] + (MB_MBAFF(h) ? 20 : 2); AV_COPY128(mv_dst - 1 * 8, h->cur_pic.motion_val[list][b_xy + 0]); ref_cache[0 - 1 * 8] = ref_cache[1 - 1 * 8] = ref2frm[list][h->cur_pic.ref_index[list][b8_xy + 0]]; @@ -1851,7 +1851,7 @@ static av_always_inline void fill_filter_caches_inter(H264Context *h, if (USES_LIST(left_type[LTOP], list)) { const int b_xy = h->mb2b_xy[left_xy[LTOP]] + 3; const int b8_xy = 4 * left_xy[LTOP] + 1; - int (*ref2frm)[64] = h->ref2frm[h->slice_table[left_xy[LTOP]] & (MAX_SLICES - 1)][0] + (MB_MBAFF(h) ? 20 : 2); + int (*ref2frm)[64] = sl->ref2frm[h->slice_table[left_xy[LTOP]] & (MAX_SLICES - 1)][0] + (MB_MBAFF(h) ? 20 : 2); AV_COPY32(mv_dst - 1 + 0, h->cur_pic.motion_val[list][b_xy + b_stride * 0]); AV_COPY32(mv_dst - 1 + 8, h->cur_pic.motion_val[list][b_xy + b_stride * 1]); AV_COPY32(mv_dst - 1 + 16, h->cur_pic.motion_val[list][b_xy + b_stride * 2]); @@ -1884,7 +1884,7 @@ static av_always_inline void fill_filter_caches_inter(H264Context *h, { int8_t *ref = &h->cur_pic.ref_index[list][4 * mb_xy]; - int (*ref2frm)[64] = h->ref2frm[sl->slice_num & (MAX_SLICES - 1)][0] + (MB_MBAFF(h) ? 20 : 2); + int (*ref2frm)[64] = sl->ref2frm[sl->slice_num & (MAX_SLICES - 1)][0] + (MB_MBAFF(h) ? 20 : 2); uint32_t ref01 = (pack16to32(ref2frm[list][ref[0]], ref2frm[list][ref[1]]) & 0x00FF00FF) * 0x0101; uint32_t ref23 = (pack16to32(ref2frm[list][ref[2]], ref2frm[list][ref[3]]) & 0x00FF00FF) * 0x0101; AV_WN32A(&ref_cache[0 * 8], ref01); @@ -1982,7 +1982,7 @@ static int fill_filter_caches(H264Context *h, H264SliceContext *sl, int mb_type) fill_filter_caches_inter(h, sl, mb_type, top_xy, left_xy, top_type, left_type, mb_xy, 0); - if (h->list_count == 2) + if (sl->list_count == 2) fill_filter_caches_inter(h, sl, mb_type, top_xy, left_xy, top_type, left_type, mb_xy, 1); @@ -2067,7 +2067,7 @@ static void loop_filter(H264Context *h, H264SliceContext *sl, int start_x, int e mb_xy = h->mb_xy = mb_x + mb_y * h->mb_stride; sl->slice_num = h->slice_table[mb_xy]; mb_type = h->cur_pic.mb_type[mb_xy]; - h->list_count = h->list_counts[mb_xy]; + sl->list_count = h->list_counts[mb_xy]; if (FRAME_MBAFF(h)) h->mb_mbaff = @@ -2133,7 +2133,7 @@ static void predict_field_decoding_flag(H264Context *h, H264SliceContext *sl) /** * Draw edges and report progress for the last MB row. */ -static void decode_finish_row(H264Context *h) +static void decode_finish_row(H264Context *h, H264SliceContext *sl) { int top = 16 * (h->mb_y >> FIELD_PICTURE(h)); int pic_height = 16 * h->mb_height >> FIELD_PICTURE(h); @@ -2155,7 +2155,7 @@ static void decode_finish_row(H264Context *h) top = 0; } - ff_h264_draw_horiz_band(h, top, height); + ff_h264_draw_horiz_band(h, sl, top, height); if (h->droppable) return; @@ -2164,13 +2164,14 @@ static void decode_finish_row(H264Context *h) h->picture_structure == PICT_BOTTOM_FIELD); } -static void er_add_slice(H264Context *h, int startx, int starty, +static void er_add_slice(H264Context *h, H264SliceContext *sl, + int startx, int starty, int endx, int endy, int status) { #if CONFIG_ERROR_RESILIENCE ERContext *er = &h->er; - er->ref_count = h->ref_count[0]; + er->ref_count = sl->ref_count[0]; ff_er_add_slice(er, startx, starty, endx, endy, status); #endif } @@ -2221,7 +2222,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg) if ((h->workaround_bugs & FF_BUG_TRUNCATED) && h->cabac.bytestream > h->cabac.bytestream_end + 2) { - er_add_slice(h, h->resync_mb_x, h->resync_mb_y, h->mb_x - 1, + er_add_slice(h, sl, h->resync_mb_x, h->resync_mb_y, h->mb_x - 1, h->mb_y, ER_MB_END); if (h->mb_x >= lf_x_start) loop_filter(h, sl, lf_x_start, h->mb_x + 1); @@ -2232,7 +2233,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg) "error while decoding MB %d %d, bytestream %td\n", h->mb_x, h->mb_y, h->cabac.bytestream_end - h->cabac.bytestream); - er_add_slice(h, h->resync_mb_x, h->resync_mb_y, h->mb_x, + er_add_slice(h, sl, h->resync_mb_x, h->resync_mb_y, h->mb_x, h->mb_y, ER_MB_ERROR); return AVERROR_INVALIDDATA; } @@ -2240,7 +2241,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg) if (++h->mb_x >= h->mb_width) { loop_filter(h, sl, lf_x_start, h->mb_x); h->mb_x = lf_x_start = 0; - decode_finish_row(h); + decode_finish_row(h, sl); ++h->mb_y; if (FIELD_OR_MBAFF_PICTURE(h)) { ++h->mb_y; @@ -2252,7 +2253,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg) if (eos || h->mb_y >= h->mb_height) { tprintf(h->avctx, "slice end %d %d\n", get_bits_count(&h->gb), h->gb.size_in_bits); - er_add_slice(h, h->resync_mb_x, h->resync_mb_y, h->mb_x - 1, + er_add_slice(h, sl, h->resync_mb_x, h->resync_mb_y, h->mb_x - 1, h->mb_y, ER_MB_END); if (h->mb_x > lf_x_start) loop_filter(h, sl, lf_x_start, h->mb_x); @@ -2279,7 +2280,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg) if (ret < 0) { av_log(h->avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", h->mb_x, h->mb_y); - er_add_slice(h, h->resync_mb_x, h->resync_mb_y, h->mb_x, + er_add_slice(h, sl, h->resync_mb_x, h->resync_mb_y, h->mb_x, h->mb_y, ER_MB_ERROR); return ret; } @@ -2287,7 +2288,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg) if (++h->mb_x >= h->mb_width) { loop_filter(h, sl, lf_x_start, h->mb_x); h->mb_x = lf_x_start = 0; - decode_finish_row(h); + decode_finish_row(h, sl); ++h->mb_y; if (FIELD_OR_MBAFF_PICTURE(h)) { ++h->mb_y; @@ -2299,12 +2300,12 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg) get_bits_count(&h->gb), h->gb.size_in_bits); if (get_bits_left(&h->gb) == 0) { - er_add_slice(h, h->resync_mb_x, h->resync_mb_y, + er_add_slice(h, sl, h->resync_mb_x, h->resync_mb_y, h->mb_x - 1, h->mb_y, ER_MB_END); return 0; } else { - er_add_slice(h, h->resync_mb_x, h->resync_mb_y, + er_add_slice(h, sl, h->resync_mb_x, h->resync_mb_y, h->mb_x - 1, h->mb_y, ER_MB_END); return AVERROR_INVALIDDATA; @@ -2317,14 +2318,14 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg) get_bits_count(&h->gb), h->gb.size_in_bits); if (get_bits_left(&h->gb) == 0) { - er_add_slice(h, h->resync_mb_x, h->resync_mb_y, + er_add_slice(h, sl, h->resync_mb_x, h->resync_mb_y, h->mb_x - 1, h->mb_y, ER_MB_END); if (h->mb_x > lf_x_start) loop_filter(h, sl, lf_x_start, h->mb_x); return 0; } else { - er_add_slice(h, h->resync_mb_x, h->resync_mb_y, h->mb_x, + er_add_slice(h, sl, h->resync_mb_x, h->resync_mb_y, h->mb_x, h->mb_y, ER_MB_ERROR); return AVERROR_INVALIDDATA; diff --git a/libavcodec/vaapi_h264.c b/libavcodec/vaapi_h264.c index 6823f6d7c6..6840e6d8e3 100644 --- a/libavcodec/vaapi_h264.c +++ b/libavcodec/vaapi_h264.c @@ -198,7 +198,7 @@ static void fill_vaapi_plain_pred_weight_table(H264Context *h, *luma_weight_flag = sl->luma_weight_flag[list]; *chroma_weight_flag = sl->chroma_weight_flag[list]; - for (i = 0; i < h->ref_count[list]; i++) { + for (i = 0; i < sl->ref_count[list]; i++) { /* VA API also wants the inferred (default) values, not only what is available in the bitstream (7.4.3.2). */ if (sl->luma_weight_flag[list]) { @@ -293,6 +293,7 @@ static int vaapi_h264_end_frame(AVCodecContext *avctx) { struct vaapi_context * const vactx = avctx->hwaccel_context; H264Context * const h = avctx->priv_data; + H264SliceContext *sl = &h->slice_ctx[0]; int ret; av_dlog(avctx, "vaapi_h264_end_frame()\n"); @@ -304,7 +305,7 @@ static int vaapi_h264_end_frame(AVCodecContext *avctx) if (ret < 0) goto finish; - ff_h264_draw_horiz_band(h, 0, h->avctx->height); + ff_h264_draw_horiz_band(h, sl, 0, h->avctx->height); finish: ff_vaapi_common_end_frame(avctx); @@ -331,8 +332,8 @@ static int vaapi_h264_decode_slice(AVCodecContext *avctx, slice_param->first_mb_in_slice = (h->mb_y >> FIELD_OR_MBAFF_PICTURE(h)) * h->mb_width + h->mb_x; slice_param->slice_type = ff_h264_get_slice_type(sl); slice_param->direct_spatial_mv_pred_flag = sl->slice_type == AV_PICTURE_TYPE_B ? sl->direct_spatial_mv_pred : 0; - slice_param->num_ref_idx_l0_active_minus1 = h->list_count > 0 ? h->ref_count[0] - 1 : 0; - slice_param->num_ref_idx_l1_active_minus1 = h->list_count > 1 ? h->ref_count[1] - 1 : 0; + slice_param->num_ref_idx_l0_active_minus1 = sl->list_count > 0 ? sl->ref_count[0] - 1 : 0; + slice_param->num_ref_idx_l1_active_minus1 = sl->list_count > 1 ? sl->ref_count[1] - 1 : 0; slice_param->cabac_init_idc = h->cabac_init_idc; slice_param->slice_qp_delta = sl->qscale - h->pps.init_qp; slice_param->disable_deblocking_filter_idc = h->deblocking_filter < 2 ? !h->deblocking_filter : h->deblocking_filter; @@ -341,8 +342,8 @@ static int vaapi_h264_decode_slice(AVCodecContext *avctx, slice_param->luma_log2_weight_denom = sl->luma_log2_weight_denom; slice_param->chroma_log2_weight_denom = sl->chroma_log2_weight_denom; - fill_vaapi_RefPicList(slice_param->RefPicList0, h->ref_list[0], h->list_count > 0 ? h->ref_count[0] : 0); - fill_vaapi_RefPicList(slice_param->RefPicList1, h->ref_list[1], h->list_count > 1 ? h->ref_count[1] : 0); + fill_vaapi_RefPicList(slice_param->RefPicList0, sl->ref_list[0], sl->list_count > 0 ? sl->ref_count[0] : 0); + fill_vaapi_RefPicList(slice_param->RefPicList1, sl->ref_list[1], sl->list_count > 1 ? sl->ref_count[1] : 0); fill_vaapi_plain_pred_weight_table(h, 0, &slice_param->luma_weight_l0_flag, slice_param->luma_weight_l0, slice_param->luma_offset_l0, diff --git a/libavcodec/vdpau_h264.c b/libavcodec/vdpau_h264.c index 742b648513..f8eab14850 100644 --- a/libavcodec/vdpau_h264.c +++ b/libavcodec/vdpau_h264.c @@ -198,6 +198,7 @@ static int vdpau_h264_decode_slice(AVCodecContext *avctx, static int vdpau_h264_end_frame(AVCodecContext *avctx) { H264Context *h = avctx->priv_data; + H264SliceContext *sl = &h->slice_ctx[0]; H264Picture *pic = h->cur_pic_ptr; struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private; int val; @@ -206,7 +207,7 @@ static int vdpau_h264_end_frame(AVCodecContext *avctx) if (val < 0) return val; - ff_h264_draw_horiz_band(h, 0, h->avctx->height); + ff_h264_draw_horiz_band(h, sl, 0, h->avctx->height); return 0; }