📄 macroblock1.c
字号:
{ i_ref = bs_read_te( s, ref_count[list] ); } else { i_ref = REF_NOT_USED; } h->mb.cache.ref[list][x264_scan8[4*i]] = 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] = i_ref; } } 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])) { continue; } if(FF_IS_DIR(h->mb.i_sub_mb_type[i], 0, list)) { 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]; const int index = 4*i + block_width*i_sub; int16_t (* mv_cache)[2]= &h->mb.cache.mv[list][x264_scan8[index]]; x264_mb_predict_mv( h, list, index, block_width, mv ); //x264_log(h, X264_LOG_DEBUG, "pmv %d %d ", mv[0], mv[1]); mv[0] += bs_read_se( s ); mv[1] += bs_read_se( s ); //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]; } 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]; } 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]; } else { mv_cache[ 0 ][0]= mv[0]; mv_cache[ 0 ][1]= mv[1]; } } } else { uint32_t *p= (uint32_t *)&h->mb.cache.mv[list][x264_scan8[4*i]][0]; p[0] = p[1] = p[8] = p[9] = 0; } } } } else if( h->mb.i_type == B_DIRECT ) { x264_mb_predict_mv_direct( h ); } else { int list, i_ref; int ref_count[2]; ref_count[0] = h->sh.i_num_ref_idx_l0_active - 1; ref_count[1] = h->sh.i_num_ref_idx_l1_active - 1; if( h->mb.i_partition == D_16x16 ) { for(list = 0; list < 2; list++) { if(FF_IS_DIR(h->mb.i_mb_type, 0, list)) { i_ref = bs_read_te( s, ref_count[list] ); x264_fill_rectangle(&h->mb.cache.ref[list][X264_SCAN8_0], 4, 4, 8, i_ref, 1); } else { //i_ref = REF_NOT_USED; x264_fill_rectangle(&h->mb.cache.ref[list][X264_SCAN8_0], 4, 4, 8, (REF_NOT_USED&0xFF), 1); } //x264_macroblock_cache_ref( h, 0, 0, 4, 4, list, i_ref ); } for(list = 0; list < 2; list++) { int mv[2] = {0}; if(FF_IS_DIR(h->mb.i_mb_type, 0, list)) { x264_mb_predict_mv( h, list, 0, 4, mv ); mv[0] += bs_read_se( s ); mv[1] += bs_read_se( s ); //x264_log(h, X264_LOG_DEBUG, "mv %d %d list %d\n", mv[0], mv[1], list); } //x264_macroblock_cache_mv( h, 0, 0, 4, 4, list, mv[0], mv[1] ); x264_fill_rectangle(h->mb.cache.mv[list][X264_SCAN8_0], 4, 4, 8, pack16to32(mv[0],mv[1]), 4); } } else if( h->mb.i_partition == D_16x8 ) { for(list = 0; list < 2; list++) { for( i = 0; i < 2; i++ ) { if(FF_IS_DIR(h->mb.i_mb_type, i, list)) { i_ref = bs_read_te( s, ref_count[list] ); x264_fill_rectangle(&h->mb.cache.ref[list][X264_SCAN8_0 + 16*i], 4, 2, 8, i_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); } //x264_macroblock_cache_ref( h, 0, 2*i, 4, 2, list, i_ref ); } } for(list = 0; list < 2; list++) { for( i = 0; i < 2; i++ ) { int mv[2] = {0}; if(FF_IS_DIR(h->mb.i_mb_type, i, list)) { x264_mb_predict_mv( h, list, 8*i, 4, mv ); mv[0] += bs_read_se( s ); mv[1] += bs_read_se( s ); //x264_log(h, X264_LOG_DEBUG, "mv %d %d list %d p %d\n", // mv[0], mv[1], list, i); } //x264_macroblock_cache_mv( h, 0, 2*i, 4, 2, list, mv[0], mv[1] ); x264_fill_rectangle(h->mb.cache.mv[list][X264_SCAN8_0 + 16*i], 4, 2, 8, pack16to32(mv[0],mv[1]), 4); } } } else { //assert(h->mb.i_partition == D_8x16); for(list = 0; list < 2; list++) { for( i = 0; i < 2; i++ ) { if(FF_IS_DIR(h->mb.i_mb_type, i, list)) { i_ref = bs_read_te( s, ref_count[list] ); x264_fill_rectangle(&h->mb.cache.ref[list][X264_SCAN8_0 + 2*i], 2, 4, 8, i_ref, 1); } else { //i_ref = REF_NOT_USED; x264_fill_rectangle(&h->mb.cache.ref[list][X264_SCAN8_0 + 2*i], 2, 4, 8, (REF_NOT_USED&0xFF), 1); } //x264_macroblock_cache_ref( h, 2*i, 0, 2, 4, list, i_ref ); //if( list == 0 && i_ref >= 0 ) // x264_log(h, X264_LOG_DEBUG, "ref %d list %d p %d poc %d\n", // i_ref, list, i, h->fref0[i_ref]->i_poc); } } for(list = 0; list < 2; list++) { for( i = 0; i < 2; i++ ) { int mv[2] = {0}; if(FF_IS_DIR(h->mb.i_mb_type, i, list)) { x264_mb_predict_mv( h, list, 4*i, 2, mv ); mv[0] += bs_read_se( s ); mv[1] += bs_read_se( s ); //x264_log(h, X264_LOG_DEBUG, "mv %d %d list %d p %d\n", // mv[0], mv[1], list, i); } //x264_macroblock_cache_mv( h, 2*i, 0, 2, 4, list, mv[0], mv[1] ); x264_fill_rectangle(h->mb.cache.mv[list][X264_SCAN8_0 + 2*i ], 2, 4, 8, pack16to32(mv[0],mv[1]), 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 0 { int i; if (!IS_INTRA( h->mb.i_type )) { for( i = 0; i < 16; i++ ) { int j = h->mb.cache.ref[0][x264_scan8[i]]; x264_log(h, X264_LOG_DEBUG, "block %d\n", i/4); x264_log(h, X264_LOG_DEBUG, "list0 ref %d\n%d %d\n", j<0?-1: h->fref0[j]->i_poc, h->mb.cache.mv[0][x264_scan8[i]][0], h->mb.cache.mv[0][x264_scan8[i]][1]); j = h->mb.cache.ref[1][x264_scan8[i]]; x264_log(h, X264_LOG_DEBUG, "list1 ref %d\n%d %d\n", j, h->mb.cache.mv[1][x264_scan8[i]][0], h->mb.cache.mv[1][x264_scan8[i]][1]); } } }#endif if( h->mb.i_type != I_16x16 ) { int i_cbp; i_cbp = bs_read_ue( s ); if( i_cbp >= 48 ) { fprintf( stderr, "invalid cbp\n" ); return -1; } if( h->mb.i_type == I_4x4 ) { i_cbp = golomb_to_intra4x4_cbp[i_cbp]; } else { i_cbp = golomb_to_inter_cbp[i_cbp]; } h->mb.i_cbp_luma = i_cbp&0x0f; h->mb.i_cbp_chroma = i_cbp >> 4; } if( h->mb.i_cbp_luma > 0 || h->mb.i_cbp_chroma > 0 || h->mb.i_type == I_16x16 ) { h->mb.i_qp = bs_read_se( s ) + 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); /* write residual */ if( h->mb.i_type == I_16x16 ) { /* DC Luma */ if( block_residual_read_cavlc( h, s, BLOCK_INDEX_LUMA_DC , h->dct.luma16x16_dc, 16 ) < 0 ) { return -1; } if( h->mb.i_cbp_luma != 0 ) { /* AC Luma */ for( i = 0; i < 16; i++ ) { if( block_residual_read_cavlc( h, s, i, h->dct.block[i].residual_ac, 15 ) < 0 ) { return -1; } } } else { for( i = 0; i < 16; i++ ) { //h->mb.block[i].i_non_zero_count = 0; h->mb.cache.non_zero_count[x264_scan8[i]] = 0; array_zero_set( h->dct.block[i].residual_ac, 15 ); } } } else { for( i = 0; i < 16; i++ ) { if( h->mb.i_cbp_luma & ( 1 << ( i / 4 ) ) ) { if( block_residual_read_cavlc( h, s, i, h->dct.block[i].luma4x4, 16 ) < 0 ) { return -1; } #if 0 { int j; x264_log(h, X264_LOG_DEBUG, "block %d\n", i); printf("block %d\n", i); for( j = 0; j < 16; j++ ) { //if ( j%4 == 0 ) // x264_log(h, X264_LOG_DEBUG, "\n"); x264_log(h, X264_LOG_DEBUG, "%d ", h->dct.block[i].luma4x4[j] ); printf("%d ", h->dct.block[i].luma4x4[j]); } x264_log(h, X264_LOG_DEBUG, "\n"); printf("\n"); } #endif } else { //h->mb.block[i].i_non_zero_count = 0; h->mb.cache.non_zero_count[x264_scan8[i]] = 0; array_zero_set( h->dct.block[i].luma4x4, 16 ); } } } if( h->mb.i_cbp_chroma &0x03 ) /* Chroma DC residual present */ { if( block_residual_read_cavlc( h, s, BLOCK_INDEX_CHROMA_DC, h->dct.chroma_dc[0], 4 ) < 0 || block_residual_read_cavlc( h, s, BLOCK_INDEX_CHROMA_DC, h->dct.chroma_dc[1], 4 ) < 0 ) { return -1; } } else { array_zero_set( h->dct.chroma_dc[0], 4 ); array_zero_set( h->dct.chroma_dc[1], 4 ); } if( h->mb.i_cbp_chroma&0x02 ) /* Chroma AC residual present */ { for( i = 0; i < 8; i++ ) { if( block_residual_read_cavlc( h, s, 16 + i, h->dct.block[16+i].residual_ac, 15 ) < 0 ) { return -1; } } } else { for( i = 0; i < 8; i++ ) { //h->mb.block[16+i].i_non_zero_count = 0; h->mb.cache.non_zero_count[x264_scan8[16+i]] = 0; array_zero_set( h->dct.block[16+i].residual_ac, 15 ); } } } else { h->mb.i_qp = h->pps->i_pic_init_qp + h->sh.i_qp_delta; for( i = 0; i < 16; i++ ) { //h->mb.block[i].i_non_zero_count = 0; h->mb.cache.non_zero_count[x264_scan8[i]] = 0; array_zero_set( h->dct.block[i].luma4x4, 16 ); } array_zero_set( h->dct.chroma_dc[0], 4 ); array_zero_set( h->dct.chroma_dc[1], 4 ); for( i = 0; i < 8; i++ ) { array_zero_set( h->dct.block[16+i].residual_ac, 15 ); //h->mb.block[16+i].i_non_zero_count = 0; h->mb.cache.non_zero_count[x264_scan8[16+i]] = 0; } } //fprintf( stderr, "mb read type=%d\n", h->mb.i_type );#if 0 x264_log(h, X264_LOG_DEBUG, "mb read type=%d\n", h->mb.i_type ); if (h->mb.i_type != I_16x16) { for( i = 0; i < 16; i++ ) { int j; for( j = 0; j < 16; j++ ) { //if ( j%4 == 0 ) // x264_log(h, X264_LOG_DEBUG, "\n"); x264_log(h, X264_LOG_DEBUG, "%d ", h->dct.block[i].luma4x4[j] ); } x264_log(h, X264_LOG_DEBUG, "\n"); } x264_log(h, X264_LOG_DEBUG, "\n"); }#endif return 0;}static int x264_mb_pred_mode16x16_valid( x264_t *h, int i_mode ){ if( ( h->mb.i_neighbour & (MB_LEFT|MB_TOP) ) == (MB_LEFT|MB_TOP) ) { return i_mode; } else if( ( h->mb.i_neighbour & MB_LEFT ) ) { if( i_mode == I_PRED_16x16_DC ) { return I_PRED_16x16_DC_LEFT; } else if( i_mode == I_PRED_16x16_H ) { return I_PRED_16x16_H; } fprintf( stderr, "invalid 16x16 prediction\n" ); return I_PRED_16x16_DC_LEFT; } else if( ( h->mb.i_neighbour & MB_TOP ) ) { if( i_mode == I_PRED_16x16_DC ) { return I_PRED_16x16_DC_TOP; } else if( i_mode == I_PRED_16x16_V ) { return I_PRED_16x16_V; } fprintf( stderr, "invalid 16x16 prediction\n" ); return I_PRED_16x16_DC_TOP; } else { return I_PRED_16x16_DC_128; }}static int x264_mb_pred_mode8x8_valid( x264_t *h, int i_mode ){ //printf( " \nh->mb.i_neighbour %d ",h->mb.i_neighbour); //printf( " \n cur %d ",h->mb.i_mb_xy); //printf( " \n left %d ",h->mb.chroma_pred_mode[h->mb.i_mb_xy - 1]); //printf( " \n top %d ",h->mb.chroma_pred_mode[h->mb.i_mb_xy - 8]); if( ( h->mb.i_neighbour & (MB_LEFT|MB_TOP) ) == (MB_LEFT|MB_TOP) ) { return i_mode; } else if( ( h->mb.i_neighbour & MB_LEFT ) ) { if( i_mode == I_PRED_CHROMA_DC ) { return I_PRED_CHROMA_DC_LEFT; } else if( i_mode == I_PRED_CHROMA_H ) { return I_PRED_CHROMA_H; } fprintf( stderr, "invalid 8x8 prediction\n" ); return I_PRED_CHROMA_DC_LEFT; } else if( ( h->mb.i_neighbour & MB_TOP ) ) { if( i_mode == I_PRED_CHROMA_DC ) { return I_PRED_CHROMA_DC_TOP; } else if( i_mode == I_PRED_CHROMA_V ) { return I_PRED_CHROMA_V; } fprintf( stderr, "invalid 8x8 prediction\n" ); return I_PRED_CHROMA_DC_TOP; } else { r
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -