* commit '8b00f4df20f4a8ab0656fdaf7d00233a6515a052': h264: move some neighbour information into the per-slice context Conflicts: libavcodec/h264_cabac.c libavcodec/h264_cavlc.c Merged-by: Michael Niedermayer <michaelni@gmx.at>tags/n2.7
| @@ -357,6 +357,19 @@ typedef struct H264SliceContext { | |||
| int chroma_pred_mode; | |||
| int intra16x16_pred_mode; | |||
| int topleft_mb_xy; | |||
| int top_mb_xy; | |||
| int topright_mb_xy; | |||
| int left_mb_xy[LEFT_MBS]; | |||
| int topleft_type; | |||
| int top_type; | |||
| int topright_type; | |||
| int left_type[LEFT_MBS]; | |||
| const uint8_t *left_block; | |||
| int topleft_partition; | |||
| } H264SliceContext; | |||
| /** | |||
| @@ -396,19 +409,6 @@ typedef struct H264Context { | |||
| int workaround_bugs; | |||
| // prediction stuff | |||
| int topleft_mb_xy; | |||
| int top_mb_xy; | |||
| int topright_mb_xy; | |||
| int left_mb_xy[LEFT_MBS]; | |||
| int topleft_type; | |||
| int top_type; | |||
| int topright_type; | |||
| int left_type[LEFT_MBS]; | |||
| const uint8_t *left_block; | |||
| int topleft_partition; | |||
| int8_t intra4x4_pred_mode_cache[5 * 8]; | |||
| int8_t(*intra4x4_pred_mode); | |||
| H264PredContext hpc; | |||
| @@ -1293,15 +1293,17 @@ static int decode_cabac_field_decoding_flag(H264Context *h) { | |||
| return get_cabac_noinline( &h->cabac, &(h->cabac_state+70)[ctx] ); | |||
| } | |||
| static int decode_cabac_intra_mb_type(H264Context *h, int ctx_base, int intra_slice) { | |||
| static int decode_cabac_intra_mb_type(H264Context *h, H264SliceContext *sl, | |||
| int ctx_base, int intra_slice) | |||
| { | |||
| uint8_t *state= &h->cabac_state[ctx_base]; | |||
| int mb_type; | |||
| if(intra_slice){ | |||
| int ctx=0; | |||
| if( h->left_type[LTOP] & (MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)) | |||
| if (sl->left_type[LTOP] & (MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)) | |||
| ctx++; | |||
| if( h->top_type & (MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)) | |||
| if (sl->top_type & (MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)) | |||
| ctx++; | |||
| if( get_cabac_noinline( &h->cabac, &state[ctx] ) == 0 ) | |||
| return 0; /* I4x4 */ | |||
| @@ -1371,17 +1373,18 @@ static int decode_cabac_mb_intra4x4_pred_mode( H264Context *h, int pred_mode ) { | |||
| return mode + ( mode >= pred_mode ); | |||
| } | |||
| static int decode_cabac_mb_chroma_pre_mode( H264Context *h) { | |||
| const int mba_xy = h->left_mb_xy[0]; | |||
| const int mbb_xy = h->top_mb_xy; | |||
| static int decode_cabac_mb_chroma_pre_mode(H264Context *h, H264SliceContext *sl) | |||
| { | |||
| const int mba_xy = sl->left_mb_xy[0]; | |||
| const int mbb_xy = sl->top_mb_xy; | |||
| int ctx = 0; | |||
| /* No need to test for IS_INTRA4x4 and IS_INTRA16x16, as we set chroma_pred_mode_table to 0 */ | |||
| if( h->left_type[LTOP] && h->chroma_pred_mode_table[mba_xy] != 0 ) | |||
| if (sl->left_type[LTOP] && h->chroma_pred_mode_table[mba_xy] != 0) | |||
| ctx++; | |||
| if( h->top_type && h->chroma_pred_mode_table[mbb_xy] != 0 ) | |||
| if (sl->top_type && h->chroma_pred_mode_table[mbb_xy] != 0) | |||
| ctx++; | |||
| if( get_cabac_noinline( &h->cabac, &h->cabac_state[64+ctx] ) == 0 ) | |||
| @@ -1931,15 +1934,15 @@ int ff_h264_decode_mb_cabac(H264Context *h, H264SliceContext *sl) | |||
| sl->prev_mb_skipped = 0; | |||
| fill_decode_neighbors(h, -(MB_FIELD(h))); | |||
| fill_decode_neighbors(h, sl, -(MB_FIELD(h))); | |||
| if( h->slice_type_nos == AV_PICTURE_TYPE_B ) { | |||
| int ctx = 0; | |||
| av_assert2(h->slice_type_nos == AV_PICTURE_TYPE_B); | |||
| if( !IS_DIRECT( h->left_type[LTOP]-1 ) ) | |||
| if (!IS_DIRECT(sl->left_type[LTOP] - 1)) | |||
| ctx++; | |||
| if( !IS_DIRECT( h->top_type-1 ) ) | |||
| if (!IS_DIRECT(sl->top_type - 1)) | |||
| ctx++; | |||
| if( !get_cabac_noinline( &h->cabac, &h->cabac_state[27+ctx] ) ){ | |||
| @@ -1955,7 +1958,7 @@ int ff_h264_decode_mb_cabac(H264Context *h, H264SliceContext *sl) | |||
| if( bits < 8 ){ | |||
| mb_type= bits + 3; /* B_Bi_16x16 through B_L1_L0_16x8 */ | |||
| }else if( bits == 13 ){ | |||
| mb_type= decode_cabac_intra_mb_type(h, 32, 0); | |||
| mb_type = decode_cabac_intra_mb_type(h, sl, 32, 0); | |||
| goto decode_intra_mb; | |||
| }else if( bits == 14 ){ | |||
| mb_type= 11; /* B_L1_L0_8x16 */ | |||
| @@ -1981,11 +1984,11 @@ int ff_h264_decode_mb_cabac(H264Context *h, H264SliceContext *sl) | |||
| partition_count= p_mb_type_info[mb_type].partition_count; | |||
| mb_type= p_mb_type_info[mb_type].type; | |||
| } else { | |||
| mb_type= decode_cabac_intra_mb_type(h, 17, 0); | |||
| mb_type = decode_cabac_intra_mb_type(h, sl, 17, 0); | |||
| goto decode_intra_mb; | |||
| } | |||
| } else { | |||
| mb_type= decode_cabac_intra_mb_type(h, 3, 1); | |||
| mb_type = decode_cabac_intra_mb_type(h, sl, 3, 1); | |||
| if(h->slice_type == AV_PICTURE_TYPE_SI && mb_type) | |||
| mb_type--; | |||
| av_assert2(h->slice_type_nos == AV_PICTURE_TYPE_I); | |||
| @@ -2037,7 +2040,7 @@ decode_intra_mb: | |||
| local_ref_count[0] = h->ref_count[0] << MB_MBAFF(h); | |||
| local_ref_count[1] = h->ref_count[1] << MB_MBAFF(h); | |||
| fill_decode_caches(h, mb_type); | |||
| fill_decode_caches(h, sl, mb_type); | |||
| if( IS_INTRA( mb_type ) ) { | |||
| int i, pred_mode; | |||
| @@ -2066,7 +2069,7 @@ decode_intra_mb: | |||
| } | |||
| if(decode_chroma){ | |||
| h->chroma_pred_mode_table[mb_xy] = | |||
| pred_mode = decode_cabac_mb_chroma_pre_mode( h ); | |||
| pred_mode = decode_cabac_mb_chroma_pre_mode(h, sl); | |||
| pred_mode= ff_h264_check_intra_pred_mode( h, pred_mode, 1 ); | |||
| if( pred_mode < 0 ) return -1; | |||
| @@ -2141,7 +2144,7 @@ decode_intra_mb: | |||
| const int index= 4*i + block_width*j; | |||
| int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ]; | |||
| uint8_t (* mvd_cache)[2]= &h->mvd_cache[list][ scan8[index] ]; | |||
| pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my); | |||
| pred_motion(h, sl, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my); | |||
| DECODE_CABAC_MB_MVD( h, list, index) | |||
| tprintf(h->avctx, "final mv:%d %d\n", mx, my); | |||
| @@ -2205,7 +2208,7 @@ decode_intra_mb: | |||
| for(list=0; list<h->list_count; list++){ | |||
| if(IS_DIR(mb_type, 0, list)){ | |||
| int mx,my,mpx,mpy; | |||
| pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my); | |||
| pred_motion(h, sl, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my); | |||
| DECODE_CABAC_MB_MVD( h, list, 0) | |||
| tprintf(h->avctx, "final mv:%d %d\n", mx, my); | |||
| @@ -2236,7 +2239,7 @@ decode_intra_mb: | |||
| for(i=0; i<2; i++){ | |||
| if(IS_DIR(mb_type, i, list)){ | |||
| int mx,my,mpx,mpy; | |||
| pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my); | |||
| pred_16x8_motion(h, sl, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my); | |||
| DECODE_CABAC_MB_MVD( h, list, 8*i) | |||
| tprintf(h->avctx, "final mv:%d %d\n", mx, my); | |||
| @@ -2271,7 +2274,7 @@ decode_intra_mb: | |||
| for(i=0; i<2; i++){ | |||
| if(IS_DIR(mb_type, i, list)){ | |||
| int mx,my,mpx,mpy; | |||
| pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my); | |||
| pred_8x16_motion(h, sl, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my); | |||
| DECODE_CABAC_MB_MVD( h, list, 4*i) | |||
| tprintf(h->avctx, "final mv:%d %d\n", mx, my); | |||
| @@ -2314,7 +2317,7 @@ decode_intra_mb: | |||
| int i; | |||
| uint8_t *nnz_cache = h->non_zero_count_cache; | |||
| for (i = 0; i < 2; i++){ | |||
| if (h->left_type[LEFT(i)] && !IS_8x8DCT(h->left_type[LEFT(i)])){ | |||
| if (sl->left_type[LEFT(i)] && !IS_8x8DCT(sl->left_type[LEFT(i)])) { | |||
| nnz_cache[3+8* 1 + 2*8*i]= | |||
| nnz_cache[3+8* 2 + 2*8*i]= | |||
| nnz_cache[3+8* 6 + 2*8*i]= | |||
| @@ -2323,7 +2326,7 @@ decode_intra_mb: | |||
| nnz_cache[3+8*12 + 2*8*i]= IS_INTRA(mb_type) ? 64 : 0; | |||
| } | |||
| } | |||
| if (h->top_type && !IS_8x8DCT(h->top_type)){ | |||
| if (sl->top_type && !IS_8x8DCT(sl->top_type)){ | |||
| uint32_t top_empty = CABAC(h) && !IS_INTRA(mb_type) ? 0 : 0x40404040; | |||
| AV_WN32A(&nnz_cache[4+8* 0], top_empty); | |||
| AV_WN32A(&nnz_cache[4+8* 5], top_empty); | |||
| @@ -792,8 +792,8 @@ decode_intra_mb: | |||
| local_ref_count[0] = h->ref_count[0] << MB_MBAFF(h); | |||
| local_ref_count[1] = h->ref_count[1] << MB_MBAFF(h); | |||
| fill_decode_neighbors(h, mb_type); | |||
| fill_decode_caches(h, mb_type); | |||
| fill_decode_neighbors(h, sl, mb_type); | |||
| fill_decode_caches(h, sl, mb_type); | |||
| //mb_pred | |||
| if(IS_INTRA(mb_type)){ | |||
| @@ -914,7 +914,7 @@ decode_intra_mb: | |||
| int mx, my; | |||
| const int index= 4*i + block_width*j; | |||
| int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ]; | |||
| pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my); | |||
| pred_motion(h, sl, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my); | |||
| mx += get_se_golomb(&h->gb); | |||
| my += get_se_golomb(&h->gb); | |||
| tprintf(h->avctx, "final mv:%d %d\n", mx, my); | |||
| @@ -967,7 +967,7 @@ decode_intra_mb: | |||
| } | |||
| for(list=0; list<h->list_count; list++){ | |||
| if(IS_DIR(mb_type, 0, list)){ | |||
| pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my); | |||
| pred_motion(h, sl, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my); | |||
| mx += get_se_golomb(&h->gb); | |||
| my += get_se_golomb(&h->gb); | |||
| tprintf(h->avctx, "final mv:%d %d\n", mx, my); | |||
| @@ -1001,7 +1001,7 @@ decode_intra_mb: | |||
| for(i=0; i<2; i++){ | |||
| unsigned int val; | |||
| if(IS_DIR(mb_type, i, list)){ | |||
| pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my); | |||
| pred_16x8_motion(h, sl, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my); | |||
| mx += get_se_golomb(&h->gb); | |||
| my += get_se_golomb(&h->gb); | |||
| tprintf(h->avctx, "final mv:%d %d\n", mx, my); | |||
| @@ -1038,7 +1038,7 @@ decode_intra_mb: | |||
| for(i=0; i<2; i++){ | |||
| unsigned int val; | |||
| if(IS_DIR(mb_type, i, list)){ | |||
| pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my); | |||
| pred_8x16_motion(h, sl, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my); | |||
| mx += get_se_golomb(&h->gb); | |||
| my += get_se_golomb(&h->gb); | |||
| tprintf(h->avctx, "final mv:%d %d\n", mx, my); | |||
| @@ -233,6 +233,7 @@ static av_always_inline void filter_mb_edgech(uint8_t *pix, int stride, | |||
| } | |||
| static av_always_inline void h264_filter_mb_fast_internal(H264Context *h, | |||
| H264SliceContext *sl, | |||
| int mb_x, int mb_y, | |||
| uint8_t *img_y, | |||
| uint8_t *img_cb, | |||
| @@ -246,8 +247,8 @@ static av_always_inline void h264_filter_mb_fast_internal(H264Context *h, | |||
| int chroma422 = CHROMA422(h); | |||
| int mb_xy = h->mb_xy; | |||
| int left_type= h->left_type[LTOP]; | |||
| int top_type= h->top_type; | |||
| int left_type = sl->left_type[LTOP]; | |||
| int top_type = sl->top_type; | |||
| int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8); | |||
| int a = 52 + h->slice_alpha_c0_offset - qp_bd_offset; | |||
| @@ -256,7 +257,7 @@ static av_always_inline void h264_filter_mb_fast_internal(H264Context *h, | |||
| int mb_type = h->cur_pic.mb_type[mb_xy]; | |||
| int qp = h->cur_pic.qscale_table[mb_xy]; | |||
| int qp0 = h->cur_pic.qscale_table[mb_xy - 1]; | |||
| int qp1 = h->cur_pic.qscale_table[h->top_mb_xy]; | |||
| int qp1 = h->cur_pic.qscale_table[sl->top_mb_xy]; | |||
| int qpc = get_chroma_qp( h, 0, qp ); | |||
| int qpc0 = get_chroma_qp( h, 0, qp0 ); | |||
| int qpc1 = get_chroma_qp( h, 0, qp1 ); | |||
| @@ -425,12 +426,12 @@ void ff_h264_filter_mb_fast(H264Context *h, H264SliceContext *sl, | |||
| } | |||
| #if CONFIG_SMALL | |||
| h264_filter_mb_fast_internal(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, h->pixel_shift); | |||
| h264_filter_mb_fast_internal(h, sl, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, h->pixel_shift); | |||
| #else | |||
| if(h->pixel_shift){ | |||
| h264_filter_mb_fast_internal(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, 1); | |||
| h264_filter_mb_fast_internal(h, sl, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, 1); | |||
| }else{ | |||
| h264_filter_mb_fast_internal(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, 0); | |||
| h264_filter_mb_fast_internal(h, sl, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, 0); | |||
| } | |||
| #endif | |||
| } | |||
| @@ -476,8 +477,8 @@ static av_always_inline void filter_mb_dir(H264Context *h, H264SliceContext *sl, | |||
| int chroma_qp_avg[2]; | |||
| int chroma444 = CHROMA444(h); | |||
| int chroma422 = CHROMA422(h); | |||
| const int mbm_xy = dir == 0 ? mb_xy -1 : h->top_mb_xy; | |||
| const int mbm_type = dir == 0 ? h->left_type[LTOP] : h->top_type; | |||
| const int mbm_xy = dir == 0 ? mb_xy -1 : sl->top_mb_xy; | |||
| const int mbm_type = dir == 0 ? sl->left_type[LTOP] : sl->top_type; | |||
| // how often to recheck mv-based bS when iterating between edges | |||
| static const uint8_t mask_edge_tab[2][8]={{0,3,3,3,1,1,1,1}, | |||
| @@ -728,9 +729,9 @@ void ff_h264_filter_mb(H264Context *h, H264SliceContext *sl, | |||
| if (FRAME_MBAFF(h) | |||
| // and current and left pair do not have the same interlaced type | |||
| && IS_INTERLACED(mb_type^h->left_type[LTOP]) | |||
| && IS_INTERLACED(mb_type ^ sl->left_type[LTOP]) | |||
| // and left mb is in available to us | |||
| && h->left_type[LTOP]) { | |||
| && sl->left_type[LTOP]) { | |||
| /* First vertical edge is different in MBAFF frames | |||
| * There are 8 different bS to compute and 2 different Qp | |||
| */ | |||
| @@ -758,8 +759,8 @@ void ff_h264_filter_mb(H264Context *h, H264SliceContext *sl, | |||
| const uint8_t *off= offset[MB_FIELD(h)][mb_y&1]; | |||
| for( i = 0; i < 8; i++ ) { | |||
| int j= MB_FIELD(h) ? i>>2 : i&1; | |||
| int mbn_xy = h->left_mb_xy[LEFT(j)]; | |||
| int mbn_type= h->left_type[LEFT(j)]; | |||
| int mbn_xy = sl->left_mb_xy[LEFT(j)]; | |||
| int mbn_type = sl->left_type[LEFT(j)]; | |||
| if( IS_INTRA( mbn_type ) ) | |||
| bS[i] = 4; | |||
| @@ -774,8 +775,8 @@ void ff_h264_filter_mb(H264Context *h, H264SliceContext *sl, | |||
| } | |||
| mb_qp = h->cur_pic.qscale_table[mb_xy]; | |||
| mbn0_qp = h->cur_pic.qscale_table[h->left_mb_xy[0]]; | |||
| mbn1_qp = h->cur_pic.qscale_table[h->left_mb_xy[1]]; | |||
| mbn0_qp = h->cur_pic.qscale_table[sl->left_mb_xy[0]]; | |||
| mbn1_qp = h->cur_pic.qscale_table[sl->left_mb_xy[1]]; | |||
| qp[0] = ( mb_qp + mbn0_qp + 1 ) >> 1; | |||
| bqp[0] = ( get_chroma_qp( h, 0, mb_qp ) + | |||
| get_chroma_qp( h, 0, mbn0_qp ) + 1 ) >> 1; | |||
| @@ -500,7 +500,8 @@ static av_always_inline void prefetch_motion(H264Context *h, int list, | |||
| } | |||
| } | |||
| static av_always_inline void xchg_mb_border(H264Context *h, uint8_t *src_y, | |||
| static av_always_inline void xchg_mb_border(H264Context *h, H264SliceContext *sl, | |||
| uint8_t *src_y, | |||
| uint8_t *src_cb, uint8_t *src_cr, | |||
| int linesize, int uvlinesize, | |||
| int xchg, int chroma444, | |||
| @@ -523,7 +524,7 @@ static av_always_inline void xchg_mb_border(H264Context *h, uint8_t *src_y, | |||
| if (h->deblocking_filter == 2) { | |||
| deblock_topleft = h->slice_table[h->mb_xy - 1 - h->mb_stride] == h->slice_num; | |||
| deblock_top = h->top_type; | |||
| deblock_top = sl->top_type; | |||
| } else { | |||
| deblock_topleft = (h->mb_x > 0); | |||
| deblock_top = (h->mb_y > !!MB_FIELD(h)); | |||
| @@ -156,7 +156,7 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h, H264SliceContext *sl) | |||
| } else { | |||
| if (IS_INTRA(mb_type)) { | |||
| if (h->deblocking_filter) | |||
| xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, | |||
| xchg_mb_border(h, sl, dest_y, dest_cb, dest_cr, linesize, | |||
| uvlinesize, 1, 0, SIMPLE, PIXEL_SHIFT); | |||
| if (SIMPLE || !CONFIG_GRAY || !(h->flags & CODEC_FLAG_GRAY)) { | |||
| @@ -169,7 +169,7 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h, H264SliceContext *sl) | |||
| block_offset, linesize, dest_y, 0); | |||
| if (h->deblocking_filter) | |||
| xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, | |||
| xchg_mb_border(h, sl, dest_y, dest_cb, dest_cr, linesize, | |||
| uvlinesize, 0, 0, SIMPLE, PIXEL_SHIFT); | |||
| } else if (is_h264) { | |||
| if (chroma422) { | |||
| @@ -340,7 +340,7 @@ static av_noinline void FUNC(hl_decode_mb_444)(H264Context *h, H264SliceContext | |||
| } else { | |||
| if (IS_INTRA(mb_type)) { | |||
| if (h->deblocking_filter) | |||
| xchg_mb_border(h, dest[0], dest[1], dest[2], linesize, | |||
| xchg_mb_border(h, sl, dest[0], dest[1], dest[2], linesize, | |||
| linesize, 1, 1, SIMPLE, PIXEL_SHIFT); | |||
| for (p = 0; p < plane_count; p++) | |||
| @@ -349,7 +349,7 @@ static av_noinline void FUNC(hl_decode_mb_444)(H264Context *h, H264SliceContext | |||
| block_offset, linesize, dest[p], p); | |||
| if (h->deblocking_filter) | |||
| xchg_mb_border(h, dest[0], dest[1], dest[2], linesize, | |||
| xchg_mb_border(h, sl, dest[0], dest[1], dest[2], linesize, | |||
| linesize, 0, 1, SIMPLE, PIXEL_SHIFT); | |||
| } else { | |||
| FUNC(hl_motion_444)(h, sl, dest[0], dest[1], dest[2], | |||
| @@ -35,7 +35,8 @@ | |||
| #include "libavutil/avassert.h" | |||
| static av_always_inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, | |||
| static av_always_inline int fetch_diagonal_mv(H264Context *h, H264SliceContext *sl, | |||
| const int16_t **C, | |||
| int i, int list, int part_width) | |||
| { | |||
| const int topright_ref = h->ref_cache[list][i - 8 + part_width]; | |||
| @@ -61,13 +62,13 @@ static av_always_inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, | |||
| AV_ZERO32(h->mv_cache[list][scan8[0] - 2]); | |||
| *C = h->mv_cache[list][scan8[0] - 2]; | |||
| if (!MB_FIELD(h) && IS_INTERLACED(h->left_type[0])) { | |||
| SET_DIAG_MV(* 2, >> 1, h->left_mb_xy[0] + h->mb_stride, | |||
| if (!MB_FIELD(h) && IS_INTERLACED(sl->left_type[0])) { | |||
| SET_DIAG_MV(* 2, >> 1, sl->left_mb_xy[0] + h->mb_stride, | |||
| (h->mb_y & 1) * 2 + (i >> 5)); | |||
| } | |||
| if (MB_FIELD(h) && !IS_INTERLACED(h->left_type[0])) { | |||
| if (MB_FIELD(h) && !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, h->left_mb_xy[i >= 36], ((i >> 2)) & 3); | |||
| SET_DIAG_MV(/ 2, << 1, sl->left_mb_xy[i >= 36], ((i >> 2)) & 3); | |||
| } | |||
| } | |||
| #undef SET_DIAG_MV | |||
| @@ -91,7 +92,9 @@ static av_always_inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, | |||
| * @param mx the x component of the predicted motion vector | |||
| * @param my the y component of the predicted motion vector | |||
| */ | |||
| static av_always_inline void pred_motion(H264Context *const h, int n, | |||
| static av_always_inline void pred_motion(H264Context *const h, | |||
| H264SliceContext *sl, | |||
| int n, | |||
| int part_width, int list, int ref, | |||
| int *const mx, int *const my) | |||
| { | |||
| @@ -113,7 +116,7 @@ static av_always_inline void pred_motion(H264Context *const h, int n, | |||
| * . . . L . . . . | |||
| */ | |||
| diagonal_ref = fetch_diagonal_mv(h, &C, index8, list, part_width); | |||
| diagonal_ref = fetch_diagonal_mv(h, sl, &C, index8, list, part_width); | |||
| match_count = (diagonal_ref == ref) + (top_ref == ref) + (left_ref == ref); | |||
| tprintf(h->avctx, "pred_motion match_count=%d\n", match_count); | |||
| if (match_count > 1) { //most common | |||
| @@ -155,6 +158,7 @@ static av_always_inline void pred_motion(H264Context *const h, int n, | |||
| * @param my the y component of the predicted motion vector | |||
| */ | |||
| static av_always_inline void pred_16x8_motion(H264Context *const h, | |||
| H264SliceContext *sl, | |||
| int n, int list, int ref, | |||
| int *const mx, int *const my) | |||
| { | |||
| @@ -185,7 +189,7 @@ static av_always_inline void pred_16x8_motion(H264Context *const h, | |||
| } | |||
| //RARE | |||
| pred_motion(h, n, 4, list, ref, mx, my); | |||
| pred_motion(h, sl, n, 4, list, ref, mx, my); | |||
| } | |||
| /** | |||
| @@ -195,6 +199,7 @@ static av_always_inline void pred_16x8_motion(H264Context *const h, | |||
| * @param my the y component of the predicted motion vector | |||
| */ | |||
| static av_always_inline void pred_8x16_motion(H264Context *const h, | |||
| H264SliceContext *sl, | |||
| int n, int list, int ref, | |||
| int *const mx, int *const my) | |||
| { | |||
| @@ -214,7 +219,7 @@ static av_always_inline void pred_8x16_motion(H264Context *const h, | |||
| const int16_t *C; | |||
| int diagonal_ref; | |||
| diagonal_ref = fetch_diagonal_mv(h, &C, scan8[4], list, 2); | |||
| diagonal_ref = fetch_diagonal_mv(h, sl, &C, scan8[4], list, 2); | |||
| tprintf(h->avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", | |||
| diagonal_ref, C[0], C[1], h->mb_x, h->mb_y, n, list); | |||
| @@ -227,7 +232,7 @@ static av_always_inline void pred_8x16_motion(H264Context *const h, | |||
| } | |||
| //RARE | |||
| pred_motion(h, n, 2, list, ref, mx, my); | |||
| pred_motion(h, sl, n, 2, list, ref, mx, my); | |||
| } | |||
| #define FIX_MV_MBAFF(type, refn, mvn, idx) \ | |||
| @@ -249,7 +254,8 @@ static av_always_inline void pred_8x16_motion(H264Context *const h, | |||
| } \ | |||
| } | |||
| static av_always_inline void pred_pskip_motion(H264Context *const h) | |||
| static av_always_inline void pred_pskip_motion(H264Context *const h, | |||
| H264SliceContext *sl) | |||
| { | |||
| DECLARE_ALIGNED(4, static const int16_t, zeromv)[2] = { 0 }; | |||
| DECLARE_ALIGNED(4, int16_t, mvbuf)[3][2]; | |||
| @@ -266,26 +272,26 @@ static av_always_inline void pred_pskip_motion(H264Context *const h) | |||
| * FIXME: this is a partial duplicate of the logic in fill_decode_caches, | |||
| * but it's faster this way. Is there a way to avoid this duplication? | |||
| */ | |||
| if (USES_LIST(h->left_type[LTOP], 0)) { | |||
| left_ref = ref[4 * h->left_mb_xy[LTOP] + 1 + (h->left_block[0] & ~1)]; | |||
| A = mv[h->mb2b_xy[h->left_mb_xy[LTOP]] + 3 + b_stride * h->left_block[0]]; | |||
| FIX_MV_MBAFF(h->left_type[LTOP], left_ref, A, 0); | |||
| if (USES_LIST(sl->left_type[LTOP], 0)) { | |||
| left_ref = ref[4 * sl->left_mb_xy[LTOP] + 1 + (sl->left_block[0] & ~1)]; | |||
| A = mv[h->mb2b_xy[sl->left_mb_xy[LTOP]] + 3 + b_stride * sl->left_block[0]]; | |||
| FIX_MV_MBAFF(sl->left_type[LTOP], left_ref, A, 0); | |||
| if (!(left_ref | AV_RN32A(A))) | |||
| goto zeromv; | |||
| } else if (h->left_type[LTOP]) { | |||
| } else if (sl->left_type[LTOP]) { | |||
| left_ref = LIST_NOT_USED; | |||
| A = zeromv; | |||
| } else { | |||
| goto zeromv; | |||
| } | |||
| if (USES_LIST(h->top_type, 0)) { | |||
| top_ref = ref[4 * h->top_mb_xy + 2]; | |||
| B = mv[h->mb2b_xy[h->top_mb_xy] + 3 * b_stride]; | |||
| FIX_MV_MBAFF(h->top_type, top_ref, B, 1); | |||
| if (USES_LIST(sl->top_type, 0)) { | |||
| top_ref = ref[4 * sl->top_mb_xy + 2]; | |||
| B = mv[h->mb2b_xy[sl->top_mb_xy] + 3 * b_stride]; | |||
| FIX_MV_MBAFF(sl->top_type, top_ref, B, 1); | |||
| if (!(top_ref | AV_RN32A(B))) | |||
| goto zeromv; | |||
| } else if (h->top_type) { | |||
| } else if (sl->top_type) { | |||
| top_ref = LIST_NOT_USED; | |||
| B = zeromv; | |||
| } else { | |||
| @@ -295,21 +301,21 @@ static av_always_inline void pred_pskip_motion(H264Context *const h) | |||
| tprintf(h->avctx, "pred_pskip: (%d) (%d) at %2d %2d\n", | |||
| top_ref, left_ref, h->mb_x, h->mb_y); | |||
| if (USES_LIST(h->topright_type, 0)) { | |||
| diagonal_ref = ref[4 * h->topright_mb_xy + 2]; | |||
| C = mv[h->mb2b_xy[h->topright_mb_xy] + 3 * b_stride]; | |||
| FIX_MV_MBAFF(h->topright_type, diagonal_ref, C, 2); | |||
| } else if (h->topright_type) { | |||
| if (USES_LIST(sl->topright_type, 0)) { | |||
| diagonal_ref = ref[4 * sl->topright_mb_xy + 2]; | |||
| C = mv[h->mb2b_xy[sl->topright_mb_xy] + 3 * b_stride]; | |||
| FIX_MV_MBAFF(sl->topright_type, diagonal_ref, C, 2); | |||
| } else if (sl->topright_type) { | |||
| diagonal_ref = LIST_NOT_USED; | |||
| C = zeromv; | |||
| } else { | |||
| if (USES_LIST(h->topleft_type, 0)) { | |||
| diagonal_ref = ref[4 * h->topleft_mb_xy + 1 + | |||
| (h->topleft_partition & 2)]; | |||
| C = mv[h->mb2b_xy[h->topleft_mb_xy] + 3 + b_stride + | |||
| (h->topleft_partition & 2 * b_stride)]; | |||
| FIX_MV_MBAFF(h->topleft_type, diagonal_ref, C, 2); | |||
| } else if (h->topleft_type) { | |||
| if (USES_LIST(sl->topleft_type, 0)) { | |||
| diagonal_ref = ref[4 * sl->topleft_mb_xy + 1 + | |||
| (sl->topleft_partition & 2)]; | |||
| C = mv[h->mb2b_xy[sl->topleft_mb_xy] + 3 + b_stride + | |||
| (sl->topleft_partition & 2 * b_stride)]; | |||
| FIX_MV_MBAFF(sl->topleft_type, diagonal_ref, C, 2); | |||
| } else if (sl->topleft_type) { | |||
| diagonal_ref = LIST_NOT_USED; | |||
| C = zeromv; | |||
| } else { | |||
| @@ -347,7 +353,7 @@ zeromv: | |||
| return; | |||
| } | |||
| static void fill_decode_neighbors(H264Context *h, int mb_type) | |||
| static void fill_decode_neighbors(H264Context *h, H264SliceContext *sl, int mb_type) | |||
| { | |||
| const int mb_xy = h->mb_xy; | |||
| int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS]; | |||
| @@ -358,7 +364,7 @@ static void fill_decode_neighbors(H264Context *h, int mb_type) | |||
| { 0, 2, 0, 2, 7, 10, 7, 10, 3 + 0 * 4, 3 + 2 * 4, 3 + 0 * 4, 3 + 2 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 4 * 4, 1 + 8 * 4 } | |||
| }; | |||
| h->topleft_partition = -1; | |||
| sl->topleft_partition = -1; | |||
| top_xy = mb_xy - (h->mb_stride << MB_FIELD(h)); | |||
| @@ -368,7 +374,7 @@ static void fill_decode_neighbors(H264Context *h, int mb_type) | |||
| topleft_xy = top_xy - 1; | |||
| topright_xy = top_xy + 1; | |||
| left_xy[LBOT] = left_xy[LTOP] = mb_xy - 1; | |||
| h->left_block = left_block_options[0]; | |||
| sl->left_block = left_block_options[0]; | |||
| if (FRAME_MBAFF(h)) { | |||
| const int left_mb_field_flag = IS_INTERLACED(h->cur_pic.mb_type[mb_xy - 1]); | |||
| const int curr_mb_field_flag = IS_INTERLACED(mb_type); | |||
| @@ -377,13 +383,13 @@ static void fill_decode_neighbors(H264Context *h, int mb_type) | |||
| left_xy[LBOT] = left_xy[LTOP] = mb_xy - h->mb_stride - 1; | |||
| if (curr_mb_field_flag) { | |||
| left_xy[LBOT] += h->mb_stride; | |||
| h->left_block = left_block_options[3]; | |||
| sl->left_block = left_block_options[3]; | |||
| } else { | |||
| topleft_xy += h->mb_stride; | |||
| /* take top left mv from the middle of the mb, as opposed | |||
| * to all other modes which use the bottom right partition */ | |||
| h->topleft_partition = 0; | |||
| h->left_block = left_block_options[1]; | |||
| sl->topleft_partition = 0; | |||
| sl->left_block = left_block_options[1]; | |||
| } | |||
| } | |||
| } else { | |||
| @@ -395,66 +401,66 @@ static void fill_decode_neighbors(H264Context *h, int mb_type) | |||
| if (left_mb_field_flag != curr_mb_field_flag) { | |||
| if (curr_mb_field_flag) { | |||
| left_xy[LBOT] += h->mb_stride; | |||
| h->left_block = left_block_options[3]; | |||
| sl->left_block = left_block_options[3]; | |||
| } else { | |||
| h->left_block = left_block_options[2]; | |||
| sl->left_block = left_block_options[2]; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| h->topleft_mb_xy = topleft_xy; | |||
| h->top_mb_xy = top_xy; | |||
| h->topright_mb_xy = topright_xy; | |||
| h->left_mb_xy[LTOP] = left_xy[LTOP]; | |||
| h->left_mb_xy[LBOT] = left_xy[LBOT]; | |||
| sl->topleft_mb_xy = topleft_xy; | |||
| sl->top_mb_xy = top_xy; | |||
| sl->topright_mb_xy = topright_xy; | |||
| sl->left_mb_xy[LTOP] = left_xy[LTOP]; | |||
| sl->left_mb_xy[LBOT] = left_xy[LBOT]; | |||
| //FIXME do we need all in the context? | |||
| h->topleft_type = h->cur_pic.mb_type[topleft_xy]; | |||
| h->top_type = h->cur_pic.mb_type[top_xy]; | |||
| h->topright_type = h->cur_pic.mb_type[topright_xy]; | |||
| h->left_type[LTOP] = h->cur_pic.mb_type[left_xy[LTOP]]; | |||
| h->left_type[LBOT] = h->cur_pic.mb_type[left_xy[LBOT]]; | |||
| sl->topleft_type = h->cur_pic.mb_type[topleft_xy]; | |||
| sl->top_type = h->cur_pic.mb_type[top_xy]; | |||
| sl->topright_type = h->cur_pic.mb_type[topright_xy]; | |||
| sl->left_type[LTOP] = h->cur_pic.mb_type[left_xy[LTOP]]; | |||
| sl->left_type[LBOT] = h->cur_pic.mb_type[left_xy[LBOT]]; | |||
| if (FMO) { | |||
| if (h->slice_table[topleft_xy] != h->slice_num) | |||
| h->topleft_type = 0; | |||
| sl->topleft_type = 0; | |||
| if (h->slice_table[top_xy] != h->slice_num) | |||
| h->top_type = 0; | |||
| sl->top_type = 0; | |||
| if (h->slice_table[left_xy[LTOP]] != h->slice_num) | |||
| h->left_type[LTOP] = h->left_type[LBOT] = 0; | |||
| sl->left_type[LTOP] = sl->left_type[LBOT] = 0; | |||
| } else { | |||
| if (h->slice_table[topleft_xy] != h->slice_num) { | |||
| h->topleft_type = 0; | |||
| sl->topleft_type = 0; | |||
| if (h->slice_table[top_xy] != h->slice_num) | |||
| h->top_type = 0; | |||
| sl->top_type = 0; | |||
| if (h->slice_table[left_xy[LTOP]] != h->slice_num) | |||
| h->left_type[LTOP] = h->left_type[LBOT] = 0; | |||
| sl->left_type[LTOP] = sl->left_type[LBOT] = 0; | |||
| } | |||
| } | |||
| if (h->slice_table[topright_xy] != h->slice_num) | |||
| h->topright_type = 0; | |||
| sl->topright_type = 0; | |||
| } | |||
| static void fill_decode_caches(H264Context *h, int mb_type) | |||
| static void fill_decode_caches(H264Context *h, H264SliceContext *sl, int mb_type) | |||
| { | |||
| int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS]; | |||
| int topleft_type, top_type, topright_type, left_type[LEFT_MBS]; | |||
| const uint8_t *left_block = h->left_block; | |||
| const uint8_t *left_block = sl->left_block; | |||
| int i; | |||
| uint8_t *nnz; | |||
| uint8_t *nnz_cache; | |||
| topleft_xy = h->topleft_mb_xy; | |||
| top_xy = h->top_mb_xy; | |||
| topright_xy = h->topright_mb_xy; | |||
| left_xy[LTOP] = h->left_mb_xy[LTOP]; | |||
| left_xy[LBOT] = h->left_mb_xy[LBOT]; | |||
| topleft_type = h->topleft_type; | |||
| top_type = h->top_type; | |||
| topright_type = h->topright_type; | |||
| left_type[LTOP] = h->left_type[LTOP]; | |||
| left_type[LBOT] = h->left_type[LBOT]; | |||
| topleft_xy = sl->topleft_mb_xy; | |||
| top_xy = sl->top_mb_xy; | |||
| topright_xy = sl->topright_mb_xy; | |||
| left_xy[LTOP] = sl->left_mb_xy[LTOP]; | |||
| left_xy[LBOT] = sl->left_mb_xy[LBOT]; | |||
| topleft_type = sl->topleft_type; | |||
| top_type = sl->top_type; | |||
| topright_type = sl->topright_type; | |||
| left_type[LTOP] = sl->left_type[LTOP]; | |||
| left_type[LBOT] = sl->left_type[LBOT]; | |||
| if (!IS_SKIP(mb_type)) { | |||
| if (IS_INTRA(mb_type)) { | |||
| @@ -667,8 +673,8 @@ static void fill_decode_caches(H264Context *h, int mb_type) | |||
| if(ref_cache[2 - 1*8] < 0 || ref_cache[4 - 1 * 8] < 0) { | |||
| if (USES_LIST(topleft_type, list)) { | |||
| const int b_xy = h->mb2b_xy[topleft_xy] + 3 + b_stride + | |||
| (h->topleft_partition & 2 * b_stride); | |||
| const int b8_xy = 4 * topleft_xy + 1 + (h->topleft_partition & 2); | |||
| (sl->topleft_partition & 2 * b_stride); | |||
| const int b8_xy = 4 * topleft_xy + 1 + (sl->topleft_partition & 2); | |||
| AV_COPY32(mv_cache[-1 - 1 * 8], mv[b_xy]); | |||
| ref_cache[-1 - 1 * 8] = ref[b8_xy]; | |||
| } else { | |||
| @@ -808,16 +814,16 @@ static void av_unused decode_mb_skip(H264Context *h, H264SliceContext *sl) | |||
| // just for fill_caches. pred_direct_motion will set the real mb_type | |||
| mb_type |= MB_TYPE_L0L1 | MB_TYPE_DIRECT2 | MB_TYPE_SKIP; | |||
| if (h->direct_spatial_mv_pred) { | |||
| fill_decode_neighbors(h, mb_type); | |||
| fill_decode_caches(h, mb_type); //FIXME check what is needed and what not ... | |||
| fill_decode_neighbors(h, sl, mb_type); | |||
| fill_decode_caches(h, sl, mb_type); //FIXME check what is needed and what not ... | |||
| } | |||
| ff_h264_pred_direct_motion(h, &mb_type); | |||
| mb_type |= MB_TYPE_SKIP; | |||
| } else { | |||
| mb_type |= MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P1L0 | MB_TYPE_SKIP; | |||
| fill_decode_neighbors(h, mb_type); | |||
| pred_pskip_motion(h); | |||
| fill_decode_neighbors(h, sl, mb_type); | |||
| pred_pskip_motion(h, sl); | |||
| } | |||
| write_back_motion(h, mb_type); | |||
| @@ -2153,9 +2153,9 @@ static int fill_filter_caches(H264Context *h, H264SliceContext *sl, int mb_type) | |||
| } | |||
| } | |||
| h->top_mb_xy = top_xy; | |||
| h->left_mb_xy[LTOP] = left_xy[LTOP]; | |||
| h->left_mb_xy[LBOT] = left_xy[LBOT]; | |||
| sl->top_mb_xy = top_xy; | |||
| sl->left_mb_xy[LTOP] = left_xy[LTOP]; | |||
| sl->left_mb_xy[LBOT] = left_xy[LBOT]; | |||
| { | |||
| /* For sufficiently low qp, filtering wouldn't do anything. | |||
| * This is a conservative estimate: could also check beta_offset | |||
| @@ -2191,9 +2191,9 @@ static int fill_filter_caches(H264Context *h, H264SliceContext *sl, int mb_type) | |||
| if (h->slice_table[left_xy[LBOT]] == 0xFFFF) | |||
| left_type[LTOP] = left_type[LBOT] = 0; | |||
| } | |||
| h->top_type = top_type; | |||
| h->left_type[LTOP] = left_type[LTOP]; | |||
| h->left_type[LBOT] = left_type[LBOT]; | |||
| sl->top_type = top_type; | |||
| sl->left_type[LTOP] = left_type[LTOP]; | |||
| sl->left_type[LBOT] = left_type[LBOT]; | |||
| if (IS_INTRA(mb_type)) | |||
| return 0; | |||
| @@ -376,6 +376,7 @@ static inline int svq3_mc_dir(SVQ3Context *s, int size, int mode, | |||
| { | |||
| int i, j, k, mx, my, dx, dy, x, y; | |||
| H264Context *h = &s->h; | |||
| H264SliceContext *sl = &h->slice_ctx[0]; | |||
| const int part_width = ((size & 5) == 4) ? 4 : 16 >> (size & 1); | |||
| const int part_height = 16 >> ((unsigned)(size + 1) / 3); | |||
| const int extra_width = (mode == PREDICT_MODE) ? -16 * 6 : 0; | |||
| @@ -393,7 +394,7 @@ static inline int svq3_mc_dir(SVQ3Context *s, int size, int mode, | |||
| (j >> 1 & 4) + (i & 8); | |||
| if (mode != PREDICT_MODE) { | |||
| pred_motion(h, k, part_width >> 2, dir, 1, &mx, &my); | |||
| pred_motion(h, sl, k, part_width >> 2, dir, 1, &mx, &my); | |||
| } else { | |||
| mx = s->next_pic->motion_val[0][b_xy][0] << 1; | |||
| my = s->next_pic->motion_val[0][b_xy][1] << 1; | |||