📄 macroblock.c
字号:
for( i = 0; i < 4; i++ ) x264_mb_mc_8x8( h, i ); } else if( h->mb.i_type == B_SKIP || h->mb.i_type == B_DIRECT ) { x264_mb_mc_direct8x8( h, 0, 0 ); x264_mb_mc_direct8x8( h, 2, 0 ); x264_mb_mc_direct8x8( h, 0, 2 ); x264_mb_mc_direct8x8( h, 2, 2 ); } else /* B_*x* */ { int b_list0[2]; int b_list1[2]; int i; /* init ref list utilisations */ for( i = 0; i < 2; i++ ) { b_list0[i] = x264_mb_type_list0_table[h->mb.i_type][i]; b_list1[i] = x264_mb_type_list1_table[h->mb.i_type][i]; } if( h->mb.i_partition == D_16x16 ) { if( b_list0[0] && b_list1[0] ) x264_mb_mc_01xywh( h, 0, 0, 4, 4 ); else if( b_list0[0] ) x264_mb_mc_0xywh ( h, 0, 0, 4, 4 ); else if( b_list1[0] ) x264_mb_mc_1xywh ( h, 0, 0, 4, 4 ); } else if( h->mb.i_partition == D_16x8 ) { if( b_list0[0] && b_list1[0] ) x264_mb_mc_01xywh( h, 0, 0, 4, 2 ); else if( b_list0[0] ) x264_mb_mc_0xywh ( h, 0, 0, 4, 2 ); else if( b_list1[0] ) x264_mb_mc_1xywh ( h, 0, 0, 4, 2 ); if( b_list0[1] && b_list1[1] ) x264_mb_mc_01xywh( h, 0, 2, 4, 2 ); else if( b_list0[1] ) x264_mb_mc_0xywh ( h, 0, 2, 4, 2 ); else if( b_list1[1] ) x264_mb_mc_1xywh ( h, 0, 2, 4, 2 ); } else if( h->mb.i_partition == D_8x16 ) { if( b_list0[0] && b_list1[0] ) x264_mb_mc_01xywh( h, 0, 0, 2, 4 ); else if( b_list0[0] ) x264_mb_mc_0xywh ( h, 0, 0, 2, 4 ); else if( b_list1[0] ) x264_mb_mc_1xywh ( h, 0, 0, 2, 4 ); if( b_list0[1] && b_list1[1] ) x264_mb_mc_01xywh( h, 2, 0, 2, 4 ); else if( b_list0[1] ) x264_mb_mc_0xywh ( h, 2, 0, 2, 4 ); else if( b_list1[1] ) x264_mb_mc_1xywh ( h, 2, 0, 2, 4 ); } }}int x264_macroblock_cache_init( x264_t *h ){ int i, j; int i_mb_count = h->mb.i_mb_count; h->mb.i_mb_stride = h->sps->i_mb_width; h->mb.i_b8_stride = h->sps->i_mb_width * 2; h->mb.i_b4_stride = h->sps->i_mb_width * 4; h->mb.b_interlaced = h->param.b_interlaced; CHECKED_MALLOC( h->mb.qp, i_mb_count * sizeof(int8_t) ); CHECKED_MALLOC( h->mb.cbp, i_mb_count * sizeof(int16_t) ); CHECKED_MALLOC( h->mb.skipbp, i_mb_count * sizeof(int8_t) ); CHECKED_MALLOC( h->mb.mb_transform_size, i_mb_count * sizeof(int8_t) ); /* 0 -> 3 top(4), 4 -> 6 : left(3) */ CHECKED_MALLOC( h->mb.intra4x4_pred_mode, i_mb_count * 7 * sizeof(int8_t) ); /* all coeffs */ CHECKED_MALLOC( h->mb.non_zero_count, i_mb_count * 24 * sizeof(uint8_t) ); CHECKED_MALLOC( h->mb.nnz_backup, h->sps->i_mb_width * 4 * 16 * sizeof(uint8_t) ); if( h->param.b_cabac ) { CHECKED_MALLOC( h->mb.chroma_pred_mode, i_mb_count * sizeof(int8_t) ); CHECKED_MALLOC( h->mb.mvd[0], 2*16 * i_mb_count * sizeof(int16_t) ); CHECKED_MALLOC( h->mb.mvd[1], 2*16 * i_mb_count * sizeof(int16_t) ); } for( i=0; i<2; i++ ) { int i_refs = X264_MIN(16, (i ? 1 : h->param.i_frame_reference) + h->param.b_bframe_pyramid) << h->param.b_interlaced; for( j=0; j < i_refs; j++ ) CHECKED_MALLOC( h->mb.mvr[i][j], 2 * i_mb_count * sizeof(int16_t) ); } for( i=0; i<=h->param.b_interlaced; i++ ) for( j=0; j<3; j++ ) { CHECKED_MALLOC( h->mb.intra_border_backup[i][j], h->fdec->i_stride[j] ); h->mb.intra_border_backup[i][j] += 8; } /* init with not available (for top right idx=7,15) */ memset( h->mb.cache.ref[0], -2, X264_SCAN8_SIZE * sizeof( int8_t ) ); memset( h->mb.cache.ref[1], -2, X264_SCAN8_SIZE * sizeof( int8_t ) ); return 0;fail: return -1;}void x264_macroblock_cache_end( x264_t *h ){ int i, j; for( i=0; i<=h->param.b_interlaced; i++ ) for( j=0; j<3; j++ ) x264_free( h->mb.intra_border_backup[i][j] - 8 ); for( i=0; i<2; i++ ) { int i_refs = i ? 1 + h->param.b_bframe_pyramid : h->param.i_frame_reference; for( j=0; j < i_refs; j++ ) x264_free( h->mb.mvr[i][j] ); } if( h->param.b_cabac ) { x264_free( h->mb.chroma_pred_mode ); x264_free( h->mb.mvd[0] ); x264_free( h->mb.mvd[1] ); } x264_free( h->mb.intra4x4_pred_mode ); x264_free( h->mb.non_zero_count ); x264_free( h->mb.nnz_backup ); x264_free( h->mb.mb_transform_size ); x264_free( h->mb.skipbp ); x264_free( h->mb.cbp ); x264_free( h->mb.qp );}void x264_macroblock_slice_init( x264_t *h ){ int i, j; h->mb.mv[0] = h->fdec->mv[0]; h->mb.mv[1] = h->fdec->mv[1]; h->mb.ref[0] = h->fdec->ref[0]; h->mb.ref[1] = h->fdec->ref[1]; h->mb.type = h->fdec->mb_type; h->fdec->i_ref[0] = h->i_ref0; h->fdec->i_ref[1] = h->i_ref1; for( i = 0; i < h->i_ref0; i++ ) h->fdec->ref_poc[0][i] = h->fref0[i]->i_poc; if( h->sh.i_type == SLICE_TYPE_B ) { for( i = 0; i < h->i_ref1; i++ ) h->fdec->ref_poc[1][i] = h->fref1[i]->i_poc; h->mb.map_col_to_list0[-1] = -1; h->mb.map_col_to_list0[-2] = -2; for( i = 0; i < h->fref1[0]->i_ref[0]; i++ ) { int poc = h->fref1[0]->ref_poc[0][i]; h->mb.map_col_to_list0[i] = -2; for( j = 0; j < h->i_ref0; j++ ) if( h->fref0[j]->i_poc == poc ) { h->mb.map_col_to_list0[i] = j; break; } } } if( h->sh.i_type == SLICE_TYPE_P ) memset( h->mb.cache.skip, 0, X264_SCAN8_SIZE * sizeof( int8_t ) );}void x264_prefetch_fenc( x264_t *h, x264_frame_t *fenc, int i_mb_x, int i_mb_y ){ int stride_y = fenc->i_stride[0]; int stride_uv = fenc->i_stride[1]; int off_y = 16 * (i_mb_x + i_mb_y * stride_y); int off_uv = 8 * (i_mb_x + i_mb_y * stride_uv); h->mc.prefetch_fenc( fenc->plane[0]+off_y, stride_y, fenc->plane[1+(i_mb_x&1)]+off_uv, stride_uv, i_mb_x );}void x264_macroblock_cache_load( x264_t *h, int i_mb_x, int i_mb_y ){ int i_mb_xy = i_mb_y * h->mb.i_mb_stride + i_mb_x; int i_mb_4x4 = 4*(i_mb_y * h->mb.i_b4_stride + i_mb_x); int i_mb_8x8 = 2*(i_mb_y * h->mb.i_b8_stride + i_mb_x); int i_top_y = i_mb_y - (1 << h->mb.b_interlaced); int i_top_xy = i_top_y * h->mb.i_mb_stride + i_mb_x; int i_top_4x4 = (4*i_top_y+3) * h->mb.i_b4_stride + 4*i_mb_x; int i_top_8x8 = (2*i_top_y+1) * h->mb.i_b8_stride + 2*i_mb_x; int i_left_xy = -1; int i_top_type = -1; /* gcc warn */ int i_left_type= -1; int i; assert( h->mb.i_b8_stride == 2*h->mb.i_mb_stride ); assert( h->mb.i_b4_stride == 4*h->mb.i_mb_stride ); /* init index */ h->mb.i_mb_x = i_mb_x; h->mb.i_mb_y = i_mb_y; h->mb.i_mb_xy = i_mb_xy; h->mb.i_b8_xy = i_mb_8x8; h->mb.i_b4_xy = i_mb_4x4; h->mb.i_mb_top_xy = i_top_xy; h->mb.i_neighbour = 0; /* load cache */ if( i_top_xy >= h->sh.i_first_mb ) { h->mb.i_mb_type_top = i_top_type= h->mb.type[i_top_xy]; h->mb.i_neighbour |= MB_TOP; /* load intra4x4 */ h->mb.cache.intra4x4_pred_mode[x264_scan8[0] - 8] = h->mb.intra4x4_pred_mode[i_top_xy][0]; h->mb.cache.intra4x4_pred_mode[x264_scan8[1] - 8] = h->mb.intra4x4_pred_mode[i_top_xy][1]; h->mb.cache.intra4x4_pred_mode[x264_scan8[4] - 8] = h->mb.intra4x4_pred_mode[i_top_xy][2]; h->mb.cache.intra4x4_pred_mode[x264_scan8[5] - 8] = h->mb.intra4x4_pred_mode[i_top_xy][3]; /* load non_zero_count */ h->mb.cache.non_zero_count[x264_scan8[0] - 8] = h->mb.non_zero_count[i_top_xy][10]; h->mb.cache.non_zero_count[x264_scan8[1] - 8] = h->mb.non_zero_count[i_top_xy][11]; h->mb.cache.non_zero_count[x264_scan8[4] - 8] = h->mb.non_zero_count[i_top_xy][14]; h->mb.cache.non_zero_count[x264_scan8[5] - 8] = h->mb.non_zero_count[i_top_xy][15]; h->mb.cache.non_zero_count[x264_scan8[16+0] - 8] = h->mb.non_zero_count[i_top_xy][16+2]; h->mb.cache.non_zero_count[x264_scan8[16+1] - 8] = h->mb.non_zero_count[i_top_xy][16+3]; h->mb.cache.non_zero_count[x264_scan8[16+4+0] - 8] = h->mb.non_zero_count[i_top_xy][16+4+2]; h->mb.cache.non_zero_count[x264_scan8[16+4+1] - 8] = h->mb.non_zero_count[i_top_xy][16+4+3]; } else { h->mb.i_mb_type_top = -1; /* load intra4x4 */ h->mb.cache.intra4x4_pred_mode[x264_scan8[0] - 8] = h->mb.cache.intra4x4_pred_mode[x264_scan8[1] - 8] = h->mb.cache.intra4x4_pred_mode[x264_scan8[4] - 8] = h->mb.cache.intra4x4_pred_mode[x264_scan8[5] - 8] = -1; /* load non_zero_count */ h->mb.cache.non_zero_count[x264_scan8[0] - 8] = h->mb.cache.non_zero_count[x264_scan8[1] - 8] = h->mb.cache.non_zero_count[x264_scan8[4] - 8] = h->mb.cache.non_zero_count[x264_scan8[5] - 8] = h->mb.cache.non_zero_count[x264_scan8[16+0] - 8] = h->mb.cache.non_zero_count[x264_scan8[16+1] - 8] = h->mb.cache.non_zero_count[x264_scan8[16+4+0] - 8] = h->mb.cache.non_zero_count[x264_scan8[16+4+1] - 8] = 0x80; } if( i_mb_x > 0 && i_mb_xy > h->sh.i_first_mb ) { i_left_xy = i_mb_xy - 1; h->mb.i_mb_type_left = i_left_type = h->mb.type[i_left_xy]; h->mb.i_neighbour |= MB_LEFT; /* load intra4x4 */ h->mb.cache.intra4x4_pred_mode[x264_scan8[0 ] - 1] = h->mb.intra4x4_pred_mode[i_left_xy][4]; h->mb.cache.intra4x4_pred_mode[x264_scan8[2 ] - 1] = h->mb.intra4x4_pred_mode[i_left_xy][5]; h->mb.cache.intra4x4_pred_mode[x264_scan8[8 ] - 1] = h->mb.intra4x4_pred_mode[i_left_xy][6]; h->mb.cache.intra4x4_pred_mode[x264_scan8[10] - 1] = h->mb.intra4x4_pred_mode[i_left_xy][3]; /* load non_zero_count */ h->mb.cache.non_zero_count[x264_scan8[0 ] - 1] = h->mb.non_zero_count[i_left_xy][5]; h->mb.cache.non_zero_count[x264_scan8[2 ] - 1] = h->mb.non_zero_count[i_left_xy][7]; h->mb.cache.non_zero_count[x264_scan8[8 ] - 1] = h->mb.non_zero_count[i_left_xy][13]; h->mb.cache.non_zero_count[x264_scan8[10] - 1] = h->mb.non_zero_count[i_left_xy][15]; h->mb.cache.non_zero_count[x264_scan8[16+0] - 1] = h->mb.non_zero_count[i_left_xy][16+1]; h->mb.cache.non_zero_count[x264_scan8[16+2] - 1] = h->mb.non_zero_count[i_left_xy][16+3]; h->mb.cache.non_zero_count[x264_scan8[16+4+0] - 1] = h->mb.non_zero_count[i_left_xy][16+4+1]; h->mb.cache.non_zero_count[x264_scan8[16+4+2] - 1] = h->mb.non_zero_count[i_left_xy][16+4+3]; } else { h->mb.i_mb_type_left = -1; h->mb.cache.intra4x4_pred_mode[x264_scan8[0 ] - 1] = h->mb.cache.intra4x4_pred_mode[x264_scan8[2 ] - 1] = h->mb.cache.intra4x4_pred_mode[x264_scan8[8 ] - 1] = h->mb.cache.intra4x4_pred_mode[x264_scan8[10] - 1] = -1; /* load non_zero_count */ h->mb.cache.non_zero_count[x264_scan8[0 ] - 1] = h->mb.cache.non_zero_count[x264_scan8[2 ] - 1] = h->mb.cache.non_zero_count[x264_scan8[8 ] - 1] = h->mb.cache.non_zero_count[x264_scan8[10] - 1] = h->mb.cache.non_zero_count[x264_scan8[16+0] - 1] = h->mb.cache.non_zero_count[x264_scan8[16+2] - 1] = h->mb.cache.non_zero_count[x264_scan8[16+4+0] - 1] = h->mb.cache.non_zero_count[x264_scan8[16+4+2] - 1] = 0x80; } if( i_mb_x < h->sps->i_mb_width - 1 && i_top_xy + 1 >= h->sh.i_first_mb ) { h->mb.i_neighbour |= MB_TOPRIGHT; h->mb.i_mb_type_topright = h->mb.type[ i_top_xy + 1 ]; } else h->mb.i_mb_type_topright = -1; if( i_mb_x > 0 && i_top_xy - 1 >= h->sh.i_first_mb ) { h->mb.i_neighbour |= MB_TOPLEFT; h->mb.i_mb_type_topleft = h->mb.type[ i_top_xy - 1 ]; } else h->mb.i_mb_type_topleft = -1; if( h->pps->b_transform_8x8_mode ) { h->mb.cache.i_neighbour_transform_size = ( i_left_type >= 0 && h->mb.mb_transform_size[i_left_xy] ) + ( i_top_type >= 0 && h->mb.mb_transform_size[i_top_xy] ); } if( h->sh.b_mbaff ) { h->mb.pic.i_fref[0] = h->i_ref0 << h->mb.b_interlaced; h->mb.pic.i_fref[1] = h->i_ref1 << h->mb.b_interlaced; h->mb.cache.i_neighbour_interlaced = !!(h->mb.i_neighbour & MB_LEFT) + !!(h->mb.i_neighbour & MB_TOP); } /* fdec: fenc: * yyyyyyy * yYYYY YYYY * yYYYY YYYY * yYYYY YYYY * yYYYY YYYY * uuu vvv UUVV * uUU vVV UUVV * uUU vVV */ h->mb.pic.p_fenc[0] = h->mb.pic.fenc_buf; h->mb.pic.p_fenc[1] = h->mb.pic.fenc_buf + 16*FENC_STRIDE; h->mb.pic.p_fenc[2] = h->mb.pic.fenc_buf + 16*FENC_STRIDE + 8; h->mb.pic.p_fdec[0] = h->mb.pic.fdec_buf + 2*FDEC_STRIDE; h->mb.pic.p_fdec[1] = h->mb.pic.fdec_buf + 19*FDEC_STRIDE; h->mb.pic.p_fdec[2] = h->mb.pic.fdec_buf + 19*FDEC_STRIDE + 16; /* load picture pointers */ for( i = 0; i < 3; i++ ) { const int w = (i == 0 ? 16 : 8); const int i_stride = h->fdec->i_stride[i]; const int i_stride2 = i_stride << h->mb.b_interlaced; const int i_pix_offset = h->mb.b_interlaced ? w * (i_mb_x + (i_mb_y&~1) * i_stride) + (i_mb_y&1) * i_stride : w * (i_mb_x + i_mb_y * i_stride); int ref_pix_offset[2] = { i_pix_offset, i_pix_offset }; const uint8_t *plane_fdec = &h->fdec->plane[i][i_pix_offset]; const uint8_t *intra_fdec = &h->mb.intra_border_backup[i_mb_y & h->sh.b_mbaff][i][i_mb_x*16>>!!i]; x264_frame_t **fref[2] = { h->fref0, h->fref1 }; int j, k, l; if( h->mb.b_interlaced ) ref_pix_offset[1] += (1-2*(i_mb_y&1)) * i_stride; h->mb.pic.i_stride[i] = i_stride2; h->mc.copy[i?PIXEL_8x8:PIXEL_16x16]( h->mb.pic.p_fenc[i], FENC_STRIDE, &h->fenc->plane[i][i_pix_offset], i_stride2, w ); memcpy( &h->mb.pic.p_fdec[i][-1-FDEC_STRIDE], intra_fdec-1, w*3/2+1 ); for( j = 0; j < w; j++ ) h->mb.pic.p_fdec[i][-1+j*FDEC_STRIDE] = plane_fdec[-1+j*i_stride2]; for( l=0; l<2; l++ ) { for( j=0; j<h->mb.pic.i_fref[l]; j++ ) { h->mb.pic.p_fref[l][j][i==0 ? 0:i+3] = &fref[l][j >> h->mb.b_interlaced]->plane[i][ref_pix_offset[j&1]]; if( i == 0 ) for( k = 1; k < 4; k++ ) h->mb.pic.p_fref[l][j][k] = &fref[l][j >> h->mb.b_interlaced]->filtered[k][ref_pix_offset[j&1]]; } } } if( h->fdec->integral ) { assert( !h->mb.b_interlaced ); for( i = 0; i < h->mb.pic.i_fref[0]; i++ ) h->mb.pic.p_integral[0][i] = &h->fref0[i]->integral[ 16 * ( i_mb_x + i_mb_y * h->fdec->i_stride[0] )]; for( i = 0; i < h->mb.pic.i_fref[1]; i++ ) h->mb.pic.p_integral[1][i] = &h->fref1[i]->integral[ 16 * ( i_mb_x + i_mb_y * h->fdec->i_stride[0] )]; } x264_prefetch_fenc( h, h->fenc, i_mb_x, i_mb_y ); /* load ref/mv/mvd */ if( h->sh.i_type != SLICE_TYPE_I ) { const int s8x8 = h->mb.i_b8_stride; const int s4x4 = h->mb.i_b4_stride; int i_list; for( i_list = 0; i_list < (h->sh.i_type == SLICE_TYPE_B ? 2 : 1 ); i_list++ )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -