diff --git a/libavcodec/h264.c b/libavcodec/h264.c index a68a911cd4..a53be146e7 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -91,7 +91,7 @@ static void h264_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type, fill_rectangle(sl->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32((*mv)[0][0][0], (*mv)[0][0][1]), 4); h->mb_mbaff = - h->mb_field_decoding_flag = 0; + sl->mb_field_decoding_flag = 0; ff_h264_hl_decode_mb(h, &h->slice_ctx[0]); } diff --git a/libavcodec/h264.h b/libavcodec/h264.h index 0b44b441e7..e5a6a17c50 100644 --- a/libavcodec/h264.h +++ b/libavcodec/h264.h @@ -401,6 +401,8 @@ typedef struct H264SliceContext { int mb_skip_run; int is_complex; + int mb_field_decoding_flag; + int redundant_pic_count; /** @@ -537,7 +539,6 @@ typedef struct H264Context { // interlacing specific flags int mb_aff_frame; - int mb_field_decoding_flag; int mb_mbaff; ///< mb_aff_frame && mb_field_decoding_flag int picture_structure; int first_field; diff --git a/libavcodec/h264_cabac.c b/libavcodec/h264_cabac.c index 85fcf7f2a8..90dd9f9641 100644 --- a/libavcodec/h264_cabac.c +++ b/libavcodec/h264_cabac.c @@ -1288,7 +1288,7 @@ static int decode_cabac_field_decoding_flag(H264Context *h, H264SliceContext *sl unsigned long ctx = 0; - ctx += h->mb_field_decoding_flag & !!sl->mb_x; //for FMO:(s->current_picture.mb_type[mba_xy] >> 7) & (h->slice_table[mba_xy] == h->slice_num); + ctx += sl->mb_field_decoding_flag & !!sl->mb_x; //for FMO:(s->current_picture.mb_type[mba_xy] >> 7) & (h->slice_table[mba_xy] == h->slice_num); ctx += (h->cur_pic.mb_type[mbb_xy] >> 7) & (h->slice_table[mbb_xy] == sl->slice_num); return get_cabac_noinline( &sl->cabac, &(sl->cabac_state+70)[ctx] ); @@ -1337,9 +1337,9 @@ static int decode_cabac_mb_skip(H264Context *h, H264SliceContext *sl, mba_xy = mb_xy - 1; if( (mb_y&1) && h->slice_table[mba_xy] == sl->slice_num - && MB_FIELD(h) == !!IS_INTERLACED( h->cur_pic.mb_type[mba_xy] ) ) + && MB_FIELD(sl) == !!IS_INTERLACED( h->cur_pic.mb_type[mba_xy] ) ) mba_xy += h->mb_stride; - if (MB_FIELD(h)) { + if (MB_FIELD(sl)) { mbb_xy = mb_xy - h->mb_stride; if( !(mb_y&1) && h->slice_table[mbb_xy] == sl->slice_num @@ -1648,9 +1648,9 @@ decode_cabac_residual_internal(H264Context *h, H264SliceContext *sl, #endif significant_coeff_ctx_base = sl->cabac_state - + significant_coeff_flag_offset[MB_FIELD(h)][cat]; + + significant_coeff_flag_offset[MB_FIELD(sl)][cat]; last_coeff_ctx_base = sl->cabac_state - + last_coeff_flag_offset[MB_FIELD(h)][cat]; + + last_coeff_flag_offset[MB_FIELD(sl)][cat]; abs_level_m1_ctx_base = sl->cabac_state + coeff_abs_level_m1_offset[cat]; @@ -1670,7 +1670,7 @@ decode_cabac_residual_internal(H264Context *h, H264SliceContext *sl, if( last == max_coeff -1 ) {\ index[coeff_count++] = last;\ } - const uint8_t *sig_off = significant_coeff_flag_offset_8x8[MB_FIELD(h)]; + const uint8_t *sig_off = significant_coeff_flag_offset_8x8[MB_FIELD(sl)]; #ifdef decode_significance coeff_count = decode_significance_8x8(CC, significant_coeff_ctx_base, index, last_coeff_ctx_base, sig_off); @@ -1933,7 +1933,7 @@ int ff_h264_decode_mb_cabac(H264Context *h, H264SliceContext *sl) h->cur_pic.mb_type[mb_xy] = MB_TYPE_SKIP; sl->next_mb_skipped = decode_cabac_mb_skip(h, sl, sl->mb_x, sl->mb_y+1 ); if(!sl->next_mb_skipped) - h->mb_mbaff = h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h, sl); + h->mb_mbaff = sl->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h, sl); } decode_mb_skip(h, sl); @@ -1949,12 +1949,12 @@ int ff_h264_decode_mb_cabac(H264Context *h, H264SliceContext *sl) if (FRAME_MBAFF(h)) { if ((sl->mb_y & 1) == 0) h->mb_mbaff = - h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h, sl); + sl->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h, sl); } sl->prev_mb_skipped = 0; - fill_decode_neighbors(h, sl, -(MB_FIELD(h))); + fill_decode_neighbors(h, sl, -(MB_FIELD(sl))); if (sl->slice_type_nos == AV_PICTURE_TYPE_B) { int ctx = 0; @@ -2018,7 +2018,7 @@ decode_intra_mb: sl->intra16x16_pred_mode = i_mb_type_info[mb_type].pred_mode; mb_type= i_mb_type_info[mb_type].type; } - if(MB_FIELD(h)) + if (MB_FIELD(sl)) mb_type |= MB_TYPE_INTERLACED; h->slice_table[mb_xy] = sl->slice_num; diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c index 4ccfb4ce1d..45e2096849 100644 --- a/libavcodec/h264_cavlc.c +++ b/libavcodec/h264_cavlc.c @@ -723,7 +723,7 @@ int ff_h264_decode_mb_cavlc(H264Context *h, H264SliceContext *sl) if (sl->mb_skip_run--) { if (FRAME_MBAFF(h) && (sl->mb_y & 1) == 0) { if (sl->mb_skip_run == 0) - h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&sl->gb); + h->mb_mbaff = sl->mb_field_decoding_flag = get_bits1(&sl->gb); } decode_mb_skip(h, sl); return 0; @@ -731,7 +731,7 @@ int ff_h264_decode_mb_cavlc(H264Context *h, H264SliceContext *sl) } if (FRAME_MBAFF(h)) { if ((sl->mb_y & 1) == 0) - h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&sl->gb); + h->mb_mbaff = sl->mb_field_decoding_flag = get_bits1(&sl->gb); } sl->prev_mb_skipped = 0; @@ -768,7 +768,7 @@ decode_intra_mb: mb_type= i_mb_type_info[mb_type].type; } - if(MB_FIELD(h)) + if (MB_FIELD(sl)) mb_type |= MB_TYPE_INTERLACED; h->slice_table[mb_xy] = sl->slice_num; diff --git a/libavcodec/h264_loopfilter.c b/libavcodec/h264_loopfilter.c index f92cfc0beb..79aff5375b 100644 --- a/libavcodec/h264_loopfilter.c +++ b/libavcodec/h264_loopfilter.c @@ -757,9 +757,9 @@ void ff_h264_filter_mb(H264Context *h, H264SliceContext *sl, {3+4*0, 3+4*1, 3+4*2, 3+4*3, 3+4*0, 3+4*1, 3+4*2, 3+4*3}, } }; - const uint8_t *off= offset[MB_FIELD(h)][mb_y&1]; + const uint8_t *off= offset[MB_FIELD(sl)][mb_y&1]; for( i = 0; i < 8; i++ ) { - int j= MB_FIELD(h) ? i>>2 : i&1; + int j= MB_FIELD(sl) ? i>>2 : i&1; int mbn_xy = sl->left_mb_xy[LEFT(j)]; int mbn_type = sl->left_type[LEFT(j)]; @@ -768,7 +768,7 @@ void ff_h264_filter_mb(H264Context *h, H264SliceContext *sl, else{ bS[i] = 1 + !!(sl->non_zero_count_cache[12+8*(i>>1)] | ((!h->pps.cabac && IS_8x8DCT(mbn_type)) ? - (h->cbp_table[mbn_xy] & (((MB_FIELD(h) ? (i&2) : (mb_y&1)) ? 8 : 2) << 12)) + (h->cbp_table[mbn_xy] & (((MB_FIELD(sl) ? (i&2) : (mb_y&1)) ? 8 : 2) << 12)) : h->non_zero_count[mbn_xy][ off[i] ])); } @@ -792,7 +792,7 @@ void ff_h264_filter_mb(H264Context *h, H264SliceContext *sl, /* Filter edge */ tprintf(h->avctx, "filter mb:%d/%d MBAFF, QPy:%d/%d, QPb:%d/%d QPr:%d/%d ls:%d uvls:%d", mb_x, mb_y, qp[0], qp[1], bqp[0], bqp[1], rqp[0], rqp[1], linesize, uvlinesize); { int i; for (i = 0; i < 8; i++) tprintf(h->avctx, " bS[%d]:%d", i, bS[i]); tprintf(h->avctx, "\n"); } - if (MB_FIELD(h)) { + if (MB_FIELD(sl)) { filter_mb_mbaff_edgev ( h, img_y , linesize, bS , 1, qp [0], a, b, 1 ); filter_mb_mbaff_edgev ( h, img_y + 8* linesize, linesize, bS+4, 1, qp [1], a, b, 1 ); if (chroma){ diff --git a/libavcodec/h264_mb.c b/libavcodec/h264_mb.c index d33d23792e..dcd65a9464 100644 --- a/libavcodec/h264_mb.c +++ b/libavcodec/h264_mb.c @@ -57,7 +57,7 @@ static inline void get_lowest_part_y(const H264Context *h, H264SliceContext *sl, { int my; - y_offset += 16 * (sl->mb_y >> MB_FIELD(h)); + y_offset += 16 * (sl->mb_y >> MB_FIELD(sl)); if (list0) { int ref_n = sl->ref_cache[0][scan8[n]]; @@ -225,7 +225,7 @@ static av_always_inline void mc_dir_part(const H264Context *h, H264SliceContext const int full_mx = mx >> 2; const int full_my = my >> 2; const int pic_width = 16 * h->mb_width; - const int pic_height = 16 * h->mb_height >> MB_FIELD(h); + const int pic_height = 16 * h->mb_height >> MB_FIELD(sl); int ysh; if (mx & 7) @@ -285,7 +285,7 @@ static av_always_inline void mc_dir_part(const H264Context *h, H264SliceContext } ysh = 3 - (chroma_idc == 2 /* yuv422 */); - if (chroma_idc == 1 /* yuv420 */ && MB_FIELD(h)) { + if (chroma_idc == 1 /* yuv420 */ && MB_FIELD(sl)) { // chroma offset when predicting from a field of opposite parity my += 2 * ((sl->mb_y & 1) - (pic->reference - 1)); emu |= (my >> 3) < 0 || (my >> 3) + 8 >= (pic_height >> 1); @@ -346,7 +346,7 @@ static av_always_inline void mc_part_std(const H264Context *h, H264SliceContext dest_cr += (x_offset << pixel_shift) + y_offset * sl->mb_uvlinesize; } x_offset += 8 * sl->mb_x; - y_offset += 8 * (sl->mb_y >> MB_FIELD(h)); + y_offset += 8 * (sl->mb_y >> MB_FIELD(sl)); if (list0) { H264Picture *ref = &sl->ref_list[0][sl->ref_cache[0][scan8[n]]]; @@ -400,7 +400,7 @@ static av_always_inline void mc_part_weighted(const H264Context *h, H264SliceCon dest_cr += (x_offset << pixel_shift) + y_offset * sl->mb_uvlinesize; } x_offset += 8 * sl->mb_x; - y_offset += 8 * (sl->mb_y >> MB_FIELD(h)); + y_offset += 8 * (sl->mb_y >> MB_FIELD(sl)); if (list0 && list1) { /* don't optimize for luma-only case, since B-frames usually @@ -532,7 +532,7 @@ static av_always_inline void xchg_mb_border(const H264Context *h, H264SliceConte deblock_top = sl->top_type; } else { deblock_topleft = (sl->mb_x > 0); - deblock_top = (sl->mb_y > !!MB_FIELD(h)); + deblock_top = (sl->mb_y > !!MB_FIELD(sl)); } src_y -= linesize + 1 + pixel_shift; diff --git a/libavcodec/h264_mb_template.c b/libavcodec/h264_mb_template.c index 52d60be93b..a03bdc2ac5 100644 --- a/libavcodec/h264_mb_template.c +++ b/libavcodec/h264_mb_template.c @@ -66,7 +66,7 @@ static av_noinline void FUNC(hl_decode_mb)(const H264Context *h, H264SliceContex h->list_counts[mb_xy] = sl->list_count; - if (!SIMPLE && MB_FIELD(h)) { + if (!SIMPLE && MB_FIELD(sl)) { linesize = sl->mb_linesize = h->linesize * 2; uvlinesize = sl->mb_uvlinesize = h->uvlinesize * 2; block_offset = &h->block_offset[48]; @@ -291,7 +291,7 @@ static av_noinline void FUNC(hl_decode_mb_444)(const H264Context *h, H264SliceCo h->list_counts[mb_xy] = sl->list_count; - if (!SIMPLE && MB_FIELD(h)) { + if (!SIMPLE && MB_FIELD(sl)) { linesize = sl->mb_linesize = sl->mb_uvlinesize = h->linesize * 2; block_offset = &h->block_offset[48]; if (mb_y & 1) // FIXME move out of this function? diff --git a/libavcodec/h264_mvpred.h b/libavcodec/h264_mvpred.h index 99bea07eec..e7db550f15 100644 --- a/libavcodec/h264_mvpred.h +++ b/libavcodec/h264_mvpred.h @@ -62,11 +62,11 @@ static av_always_inline int fetch_diagonal_mv(const H264Context *h, H264SliceCon AV_ZERO32(sl->mv_cache[list][scan8[0] - 2]); *C = sl->mv_cache[list][scan8[0] - 2]; - if (!MB_FIELD(h) && IS_INTERLACED(sl->left_type[0])) { + if (!MB_FIELD(sl) && IS_INTERLACED(sl->left_type[0])) { SET_DIAG_MV(* 2, >> 1, sl->left_mb_xy[0] + h->mb_stride, (sl->mb_y & 1) * 2 + (i >> 5)); } - if (MB_FIELD(h) && !IS_INTERLACED(sl->left_type[0])) { + if (MB_FIELD(sl) && !IS_INTERLACED(sl->left_type[0])) { // left shift will turn LIST_NOT_USED into PART_NOT_AVAILABLE, but that's OK. SET_DIAG_MV(/ 2, << 1, sl->left_mb_xy[i >= 36], ((i >> 2)) & 3); } @@ -237,7 +237,7 @@ static av_always_inline void pred_8x16_motion(const H264Context *const h, #define FIX_MV_MBAFF(type, refn, mvn, idx) \ if (FRAME_MBAFF(h)) { \ - if (MB_FIELD(h)) { \ + if (MB_FIELD(sl)) { \ if (!IS_INTERLACED(type)) { \ refn <<= 1; \ AV_COPY32(mvbuf[idx], mvn); \ @@ -366,7 +366,7 @@ static void fill_decode_neighbors(const H264Context *h, H264SliceContext *sl, in sl->topleft_partition = -1; - top_xy = mb_xy - (h->mb_stride << MB_FIELD(h)); + top_xy = mb_xy - (h->mb_stride << MB_FIELD(sl)); /* Wow, what a mess, why didn't they simplify the interlacing & intra * stuff, I can't imagine that these complex rules are worth it. */ @@ -767,7 +767,7 @@ static void fill_decode_caches(const H264Context *h, H264SliceContext *sl, int m MAP_F2F(scan8[0] - 1 + 3 * 8, left_type[LBOT]) if (FRAME_MBAFF(h)) { - if (MB_FIELD(h)) { + if (MB_FIELD(sl)) { #define MAP_F2F(idx, mb_type) \ if (!IS_INTERLACED(mb_type) && sl->ref_cache[list][idx] >= 0) { \ @@ -807,7 +807,7 @@ static void av_unused decode_mb_skip(const H264Context *h, H264SliceContext *sl) memset(h->non_zero_count[mb_xy], 0, 48); - if (MB_FIELD(h)) + if (MB_FIELD(sl)) mb_type |= MB_TYPE_INTERLACED; if (sl->slice_type_nos == AV_PICTURE_TYPE_B) { diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 559c6a04e4..d81dd9077b 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -1553,7 +1553,7 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl, H264Contex h->picture_structure = picture_structure; h->droppable = droppable; h->frame_num = frame_num; - h->mb_field_decoding_flag = picture_structure != PICT_FRAME; + sl->mb_field_decoding_flag = picture_structure != PICT_FRAME; if (h0->current_slice == 0) { /* Shorten frame num gaps so we don't have to allocate reference @@ -2131,7 +2131,7 @@ static int fill_filter_caches(H264Context *h, H264SliceContext *sl, int mb_type) uint8_t *nnz; uint8_t *nnz_cache; - top_xy = mb_xy - (h->mb_stride << MB_FIELD(h)); + top_xy = mb_xy - (h->mb_stride << MB_FIELD(sl)); /* Wow, what a mess, why didn't they simplify the interlacing & intra * stuff, I can't imagine that these complex rules are worth it. */ @@ -2288,7 +2288,7 @@ static void loop_filter(H264Context *h, H264SliceContext *sl, int start_x, int e if (FRAME_MBAFF(h)) h->mb_mbaff = - h->mb_field_decoding_flag = !!IS_INTERLACED(mb_type); + sl->mb_field_decoding_flag = !!IS_INTERLACED(mb_type); sl->mb_x = mb_x; sl->mb_y = mb_y; @@ -2302,7 +2302,7 @@ static void loop_filter(H264Context *h, H264SliceContext *sl, int start_x, int e mb_y * h->uvlinesize * block_h; // FIXME simplify above - if (MB_FIELD(h)) { + if (MB_FIELD(sl)) { linesize = sl->mb_linesize = h->linesize * 2; uvlinesize = sl->mb_uvlinesize = h->uvlinesize * 2; if (mb_y & 1) { // FIXME move out of this function? @@ -2344,7 +2344,7 @@ static void predict_field_decoding_flag(H264Context *h, H264SliceContext *sl) h->cur_pic.mb_type[mb_xy - 1] : (h->slice_table[mb_xy - h->mb_stride] == sl->slice_num) ? h->cur_pic.mb_type[mb_xy - h->mb_stride] : 0; - h->mb_mbaff = h->mb_field_decoding_flag = IS_INTERLACED(mb_type) ? 1 : 0; + h->mb_mbaff = sl->mb_field_decoding_flag = IS_INTERLACED(mb_type) ? 1 : 0; } /**