📄 macroblock1.c
字号:
h->mb.i_type = x264_b_mb_type_info[i_type].type; // for ffmpeg code h->mb.i_partition_count = b_mb_type_info[i_type].partition_count; h->mb.i_mb_type = b_mb_type_info[i_type].type; } else { i_type -= i_mb_p_offset; h->mb.i_partition = x264_p_mb_type_info[i_type].partition; h->mb.i_type = x264_p_mb_type_info[i_type].type; // b_sub_ref0 = i_type == 4 ? 1 : 0; // for ffmpeg code h->mb.i_partition_count = p_mb_type_info[i_type].partition_count; h->mb.i_mb_type = p_mb_type_info[i_type].type; printf("\nmb_type %d", h->mb.i_type ); printf(" \nafter mb_type %d %d",*h->cabac.s->p,h->cabac.s->i_left); } } else { i_type -= i_mb_i_offset; if( i_type == 0 ) { h->mb.i_type = I_4x4; } else if( i_type < 25 ) { h->mb.i_type = I_16x16; h->mb.i_intra16x16_pred_mode = (i_type - 1)%4; h->mb.i_cbp_chroma = ( (i_type-1) / 4 )%3; h->mb.i_cbp_luma = ((i_type-1) / 12) ? 0x0f : 0x00; } else if( i_type == 25 ) { h->mb.i_type = I_PCM; } else { fprintf( stderr, "invalid mb type (%d)\n", i_type ); return -1; } } if( h->mb.i_type == I_PCM ) { return x264_macroblock_decode_ipcm( h, s ); } if( IS_INTRA( h->mb.i_type ) ) { if( h->mb.i_type == I_4x4 ) { for( i = 0; i < 16; i++ ) { int i_predicted_mode; int i_mode; //printf(" \nbefore 4*4 %d %d",*h->cabac.s->p,h->cabac.s->i_left); i_predicted_mode = x264_mb_predict_intra4x4_mode( h, i ); i_mode = x264_cabac_decode_mb_intra4x4_pred_mode( h, i_predicted_mode); //printf(" \nafter chroma pre %d %d",*h->cabac.s->p,h->cabac.s->i_left); //x264_log(h, X264_LOG_DEBUG, "coded %d predicted_mode %d i_mode %d\n", b_coded,i_predicted_mode,i_mode); //printf("i_mode %d\n", i_mode); h->mb.cache.intra4x4_pred_mode[x264_scan8[i]] = i_mode; } } printf(" \nbefore chroma pre %d %d",*h->cabac.s->p,h->cabac.s->i_left); h->mb.i_chroma_pred_mode = x264_cabac_decode_mb_intra8x8_pred_mode( h ); printf("\ni_chroma_mode %d", h->mb.i_chroma_pred_mode); printf(" \nafter chroma pre %d %d",h->cabac.s->i_left,*h->cabac.s->p); } else if( h->mb.i_type == P_8x8 || h->mb.i_type == B_8x8 ) { //int i_ref_max = h->i_ref0; int sub,tmp; int i, sub_partition_count[4], list, ref[2][4]; int ref_count[2]; ref_count[0] = h->sh.i_num_ref_idx_l0_active ; ref_count[1] = h->sh.i_num_ref_idx_l1_active ; if(h->sh.i_type == SLICE_TYPE_B) { for( i = 0; i < 4; i++ ) { tmp = x264_cabac_mb_sub_b_partition( h ); h->mb.i_sub_partition[i] = x264_b_sub_mb_type_info[tmp].partition; sub_partition_count[i]= b_sub_mb_type_info[ tmp ].partition_count; h->mb.i_sub_mb_type[i]= b_sub_mb_type_info[ tmp ].type; } if( FF_IS_DIRECT(h->mb.i_sub_mb_type[0]) || FF_IS_DIRECT(h->mb.i_sub_mb_type[1]) || FF_IS_DIRECT(h->mb.i_sub_mb_type[2]) || FF_IS_DIRECT(h->mb.i_sub_mb_type[3]) ) { x264_mb_predict_mv_direct( h ); if( ref_count[0] > 1 || ref_count[1] > 1 ) { for( i = 0; i < 4; i++ ) if( IS_DIRECT(h->mb.i_sub_mb_type[i]) ) x264_fill_rectangle( &h->mb.cache.skip[x264_scan8[4*i]], 2, 2, 8, 1, 1 ); } } } else { for( sub= 0;sub< 4;sub++) { /* sub mb type */ tmp = x264_cabac_mb_sub_p_partition( h ); h->mb.i_sub_partition[sub] = x264_p_sub_mb_type_info[tmp].partition; sub_partition_count[sub]= p_sub_mb_type_info[ tmp ].partition_count; h->mb.i_sub_mb_type[sub]= p_sub_mb_type_info[ tmp ].type; } } for(list = 0; list < 2; list++) { if(ref_count[list] > 0) { for( i = 0; i < 4; i++ ) { //int i_ref; if(FF_IS_DIRECT(h->mb.i_sub_mb_type[i])) { //FIXME: need update ref_cache? continue; } // if (b_sub_ref0) // { // ref[list][i] = 0; // } else if (FF_IS_DIR(h->mb.i_sub_mb_type[i], 0, list)) { if( ref_count[list] > 1 ) ref[list][i] = x264_cabac_mb_ref( h, list, 4*i ); else ref[list][i] = 0; } else { ref[list][i] = REF_NOT_USED; } h->mb.cache.ref[list][x264_scan8[4*i] + 1] = h->mb.cache.ref[list][x264_scan8[4*i] + 8] = h->mb.cache.ref[list][x264_scan8[4*i] + 9] = ref[list][i]; } } } for(list = 0; list < 2; list++) { for( i = 0; i < 4; i++ ) { int i_sub; if(FF_IS_DIRECT(h->mb.i_sub_mb_type[i])) { x264_fill_rectangle(h->mb.cache.mvd[list][x264_scan8[4*i]], 2, 2, 8, 0, 4); continue; } h->mb.cache.ref[list][x264_scan8[4*i]] = h->mb.cache.ref[list][x264_scan8[4*i] + 1]; if(FF_IS_DIR(h->mb.i_sub_mb_type[i], 0, list)&&!FF_IS_DIRECT(h->mb.i_sub_mb_type[i])) { const int sub_mb_type = h->mb.i_sub_mb_type[i]; const int block_width = (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1; //x264_log(h, X264_LOG_DEBUG, "subtype %d width %d\n", h->mb.i_sub_partition[i], block_width); for( i_sub = 0; i_sub < sub_partition_count[i]; i_sub++ ) { int mv[2]= {0}; int mvp[2] = {0}; int index = 4*i + block_width*i_sub; int16_t (* mv_cache)[2]= &h->mb.cache.mv[list][x264_scan8[index]]; int16_t (* mvd_cache)[2]= &h->mb.cache.mvd[list][x264_scan8[index]]; // x264_mb_predict_mv( h, list, index, block_width, mvp); pred_motion(h, index, block_width, list, h->mb.cache.ref[list][ x264_scan8[index] ], &mvp[0], &mvp[1]); //x264_log(h, X264_LOG_DEBUG, "pmv %d %d ", mv[0], mv[1]); mv[0] = mvp[0] + x264_cabac_mb_mvd( h, list, index, 0 ); mv[1] = mvp[1] + x264_cabac_mb_mvd( h, list, index, 1 ); //x264_log(h, X264_LOG_DEBUG, "mv %d %d\n", mv[0], mv[1]); //printf("mv %d %d %d %d\n", mv[0], mv[1], mvd0, mvd1); if(FF_IS_SUB_8X8(sub_mb_type)) { mv_cache[ 0 ][0]= mv_cache[ 1 ][0]= mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mv[0]; mv_cache[ 0 ][1]= mv_cache[ 1 ][1]= mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= mv[1]; mvd_cache[ 0 ][0]= mvd_cache[ 1 ][0]= mvd_cache[ 8 ][0]= mvd_cache[ 9 ][0]= mv[0]- mvp[0]; mvd_cache[ 0 ][1]= mvd_cache[ 1 ][1]= mvd_cache[ 8 ][1]= mvd_cache[ 9 ][1]= mv[1]- mvp[1]; } else if(FF_IS_SUB_8X4(sub_mb_type)) { mv_cache[ 0 ][0]= mv_cache[ 1 ][0]= mv[0]; mv_cache[ 0 ][1]= mv_cache[ 1 ][1]= mv[1]; mvd_cache[ 0 ][0]= mvd_cache[ 1 ][0]= mv[0]- mvp[0]; mvd_cache[ 0 ][1]= mvd_cache[ 1 ][1]= mv[1]- mvp[1]; } else if(FF_IS_SUB_4X8(sub_mb_type)) { mv_cache[ 0 ][0]= mv_cache[ 8 ][0]= mv[0]; mv_cache[ 0 ][1]= mv_cache[ 8 ][1]= mv[1]; mvd_cache[ 0 ][0]= mvd_cache[ 8 ][0]= mv[0]- mvp[0]; mvd_cache[ 0 ][1]= mvd_cache[ 8 ][1]= mv[1]- mvp[1]; } else { assert(FF_IS_SUB_4X4(sub_mb_type)); mv_cache[ 0 ][0]= mv[0]; mv_cache[ 0 ][1]= mv[1]; mvd_cache[ 0 ][0]= mv[0]- mvp[0]; mvd_cache[ 0 ][1]= mv[1]- mvp[1]; } } } else { uint32_t *p= (uint32_t *)&h->mb.cache.mv[list][x264_scan8[4*i]][0]; uint32_t *pd= (uint32_t *)&h->mb.cache.mvd[list][x264_scan8[4*i]][0]; p[0] = p[1] = p[8] = p[9] = 0; pd[0]= pd[1]= pd[8]= pd[9]= 0; } } } } else if( h->mb.i_type == B_DIRECT ) { x264_mb_predict_mv_direct( h ); x264_fill_rectangle(h->mb.cache.mvd[0][X264_SCAN8_0], 4, 4, 8, 0, 4); x264_fill_rectangle(h->mb.cache.mvd[1][X264_SCAN8_0], 4, 4, 8, 0, 4); //dct8x8_allowed &= h->sps.direct_8x8_inference_flag; } else { int list; int ref_count[2]; ref_count[0] = h->sh.i_num_ref_idx_l0_active ; ref_count[1] = h->sh.i_num_ref_idx_l1_active ; if( h->mb.i_partition == D_16x16 ) { for(list = 0; list < 2; list++) { if(FF_IS_DIR(h->mb.i_mb_type, 0, list)) { if( ref_count[list] > 0 ) { int ref ; ref= ref_count[list] > 1 ? x264_cabac_mb_ref( h, list, 0 ) : 0; x264_fill_rectangle(&h->mb.cache.ref[list][X264_SCAN8_0], 4, 4, 8, ref, 1); } } else { //i_ref = REF_NOT_USED; x264_fill_rectangle(&h->mb.cache.ref[list][X264_SCAN8_0], 4, 4, 8, (uint8_t)REF_NOT_USED, 1); } } for(list = 0; list < 2; list++) { int mv[2] = {0}; int mvp[2] = {0}; if(FF_IS_DIR(h->mb.i_mb_type, 0, list)) { // x264_mb_predict_mv( h, list, 0, 4, mvp); pred_motion(h, 0, 4, list, h->mb.cache.ref[list][ x264_scan8[0] ], &mvp[0], &mvp[1]); mv[0] = mvp[0] + x264_cabac_mb_mvd( h, list, 0, 0 ); mv[1] = mvp[1] + x264_cabac_mb_mvd( h, list, 0, 1 ); x264_fill_rectangle(h->mb.cache.mvd[list][X264_SCAN8_0], 4, 4, 8, pack16to32(mv[0]-mvp[0],mv[1]-mvp[1]), 4); x264_fill_rectangle(h->mb.cache.mv[list][X264_SCAN8_0], 4, 4, 8, pack16to32(mv[0],mv[1]), 4); } else { x264_fill_rectangle(h->mb.cache.mvd[list][X264_SCAN8_0], 4, 4, 8, 0, 4); x264_fill_rectangle(h->mb.cache.mv[list][X264_SCAN8_0], 4, 4, 8, 0, 4); } } } else if( h->mb.i_partition == D_16x8 ) { for(list=0; list<2; list++) { if( ref_count[list]>0) { for(i=0; i<2; i++) { if(FF_IS_DIR(h->mb.i_mb_type, i, list)) { int ref; if( ref_count[list] > 1) ref = x264_cabac_mb_ref( h, list, 8*i ); else ref = 0; x264_fill_rectangle(&h->mb.cache.ref[list][X264_SCAN8_0 + 16*i], 4, 2, 8, ref, 1); } else { //i_ref = REF_NOT_USED; x264_fill_rectangle(&h->mb.cache.ref[list][X264_SCAN8_0 + 16*i], 4, 2, 8, (REF_NOT_USED&0xFF), 1); } } } } for(list=0; list<2; list++) { for(i=0; i<2; i++) { int mv[2] = {0}; int mvp[2] = {0}; if(FF_IS_DIR(h->mb.i_mb_type, i, list)) { // x264_mb_predict_mv( h, list, 8*i, 4, mvp); pred_16x8_motion(h, 8*i, list, h->mb.cache.ref[list][x264_scan8[0] + 16*i], &mvp[0], &mvp[1]); mv[0] = mvp[0] + x264_cabac_mb_mvd( h, list, 8*i, 0 ); mv[1] = mvp[1] + x264_cabac_mb_mvd( h, list, 8*i, 1 ); x264_fill_rectangle(h->mb.cache.mvd[list][ X264_SCAN8_0 + 16*i ], 4, 2, 8, pack16to32(mv[0]-mvp[0],mv[1]-mvp[1]), 4); x264_fill_rectangle(h->mb.cache.mv[list][ X264_SCAN8_0 + 16*i ], 4, 2, 8, pack16to32(mv[0],mv[1]), 4); } else { x264_fill_rectangle(h->mb.cache.mvd[list][ X264_SCAN8_0 + 16*i ], 4, 2, 8, 0, 4); x264_fill_rectangle(h->mb.cache.mv[list][ X264_SCAN8_0 + 16*i ], 4, 2, 8, 0, 4); } } } } else { assert(h->mb.i_partition == D_8x16); for(list=0; list<2; list++) { if(ref_count[list]>0) { for(i=0; i<2; i++) { if(FF_IS_DIR(h->mb.i_mb_type, i, list)) { int ref = ref_count[list] > 1 ? x264_cabac_mb_ref( h, list, 4*i ) : 0; x264_fill_rectangle(&h->mb.cache.ref[list][X264_SCAN8_0 + 2*i], 2, 4, 8, ref, 1); } else x264_fill_rectangle(&h->mb.cache.ref[list][X264_SCAN8_0 + 2*i], 2, 4, 8, (REF_NOT_USED&0xFF), 1); } } } for(list=0; list<2; list++) { for(i=0; i<2; i++) { int mv[2] = {0}; int mvp[2] = {0}; if(FF_IS_DIR(h->mb.i_mb_type, i, list)) { // x264_mb_predict_mv( h, list, 4*i, 2, mv ); pred_8x16_motion(h, i*4, list, h->mb.cache.ref[list][ x264_scan8[0] + 2*i ], &mvp[0], &mvp[1]); mv[0] = mvp[0] + x264_cabac_mb_mvd( h, list, 4*i, 0 ); mv[1] = mvp[1] + x264_cabac_mb_mvd( h, list, 4*i, 1 ); x264_fill_rectangle(h->mb.cache.mvd[list][ X264_SCAN8_0 + 2*i ], 2, 4, 8, pack16to32(mv[0]-mvp[0],mv[1]-mvp[1]), 4); x264_fill_rectangle(h->mb.cache.mv[list][ X264_SCAN8_0 + 2*i ], 2, 4, 8, pack16to32(mv[0],mv[1]), 4); } else { x264_fill_rectangle(h->mb.cache.mvd[list][ X264_SCAN8_0 + 2*i ], 2, 4, 8, 0, 4); x264_fill_rectangle(h->mb.cache.mv[list][ X264_SCAN8_0 + 2*i ], 2, 4, 8, 0, 4); } } } } } #ifdef PROFILE count = x264_get_ts() - count; h->type_cycles += count; fprintf(logout, "mb %d %d\n", h->mb.i_mb_xy, h->type_cycles); #endif if( h->mb.i_type != I_16x16 ) { printf(" \nbefore cbp 4*4 %d %d",h->cabac.s->i_left,*h->cabac.s->p); h->mb.i_cbp_luma = x264_cabac_decode_mb_cbp_luma( h ); printf(" \nafter luma cbp 4*4 %d %d",h->cabac.s->i_left,*h->cabac.s->p); h->mb.i_cbp_chroma = x264_cabac_decode_mb_cbp_chroma( h ); printf(" \nafter chroma cbp 4*4 %d %d",h->cabac.s->i_left,*h->cabac.s->p); } printf(" \nluma cbp %d", h->mb.i_cbp_luma); printf("\n chroma cbp %d",h->mb.i_cbp_chroma); /* if( h->mb.cache.b_transform_8x8_allowed && h->mb.i_cbp_luma && !IS_INTRA(h->mb.i_type) ) { x264_cabac_mb_transform_size( h, cb ); }*/ i_cbp_dc = 0x00; array_zero_set( h->dct.luma16x16_dc, 16); for(i = 0;i < 16;i++) { array_zero_set( h->dct.block[i].residual_ac, 15 ); array_zero_set( h->dct.block[i].luma4x4, 16 ); } for( i = 0; i < 8; i++ ) { array_zero_set( h->dct.block[16+i].residual_ac, 15 ); } array_zero_set( h->dct.chroma_dc[0], 4 ); array_zero_set( h->dct.chroma_dc[1], 4 ); if( h->mb.i_cbp_luma > 0 || h->mb.i_cbp_chroma > 0 || h->mb.i_type == I_16x16 ) { h->mb.i_qp = x264_cabac_decode_mb_qp_delta( h ) + h->pps->i_pic_init_qp + h->sh.i_qp_delta; //x264_log(h, X264_LOG_DEBUG, "qp %d cbp %d\n", h->mb.i_qp - h->pps->i_pic_init_qp - h->sh.i_qp_delta // , h->mb.i_cbp_luma); printf(" \nafter dqp %d %d",h->cabac.s->i_left,*h->cabac.s->p); //getchar(); /* write residual */ if( h->mb.i_type == I_16x16 ) { //printf(" \nbefore_dcluma_16*16 %d %d",h->cabac.s->i_left,*s->p); /* DC Luma */ block_residual_read_cabac( h, 0, 0, h->dct.luma16x16_dc, 16 ); //printf(" \nafter residual 16*16DC %d %d",h->cabac.s->i_left,*h->cabac.s->p); /* AC Luma */ for( i = 0; i < 16; i++ ) { if( h->mb.i_cbp_luma != 0 ) { block_residual_read_cabac( h, 1, i, h->dct.block[i].residual_ac, 15 ); //h->dct.block[i].luma4x4[0] = h->dct.luma16x16_dc[i]; } else { h->mb.cache.non_zero_count[x264_scan8[i]] = 0; //array_zero_set( h->dct.block[i].residual_ac, 15 ); } } if( array_non_zero_count( h->dct.luma16x16_dc, 16 ) > 0 ) i_cbp_dc = 0x01; } else { for( i = 0; i < 16; i++ ) { if( h->mb.i_cbp_luma & ( 1 << ( i / 4 ) ) ) { array_zero_set( h->dct.block[i].luma4x4, 16 ); // printf(" \n i before_dc luma_4*4 %d %d %d",i,h->cabac.s->i_left,*s->p); block_residual_read_cabac( h, 2, i, h->dct.block[i].luma4x4,16 ); // printf(" \n after_dc_luma_4*4 %d %d",h->cabac.s->i_left,*h->cabac.s->p); } else { h->mb.cache.non_zero_count[x264_scan8[i]] = 0; //array_zero_set( h->dct.block[i].luma4x4, 16 ); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -