h264: move mb_field_decoding_flag into the per-slice context

This commit is contained in:
Anton Khirnov 2015-01-17 22:28:46 +01:00
parent 6490a0c0fb
commit bc98e8c0e0
8 changed files with 38 additions and 37 deletions

View File

@ -364,6 +364,8 @@ typedef struct H264SliceContext {
int mb_skip_run;
int is_complex;
int mb_field_decoding_flag;
int redundant_pic_count;
/**
@ -494,7 +496,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;

View File

@ -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
@ -1646,9 +1646,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];
@ -1668,7 +1668,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);
@ -1930,7 +1930,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);
@ -1946,12 +1946,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;
@ -2015,7 +2015,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;

View File

@ -715,7 +715,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;
@ -723,7 +723,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;
@ -760,7 +760,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;

View File

@ -755,9 +755,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)];
@ -766,7 +766,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] ]));
}
@ -790,7 +790,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){

View File

@ -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
@ -528,7 +528,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;

View File

@ -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];
@ -294,7 +294,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?

View File

@ -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) {

View File

@ -1373,7 +1373,7 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl, H264Contex
h->mb_aff_frame = h->sps.mb_aff;
}
}
h->mb_field_decoding_flag = h->picture_structure != PICT_FRAME;
sl->mb_field_decoding_flag = h->picture_structure != PICT_FRAME;
if (h0->current_slice != 0) {
if (last_pic_structure != h->picture_structure ||
@ -1914,7 +1914,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. */
@ -2071,7 +2071,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;
@ -2085,7 +2085,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?
@ -2127,7 +2127,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;
}
/**