📄 macroblock.c
字号:
}
else if( h->mb.i_partition == D_16x8 )
{
x264_mb_mc_0xywh( h, 0, 0, 4, 2 );
x264_mb_mc_0xywh( h, 0, 2, 4, 2 );
}
else if( h->mb.i_partition == D_8x16 )
{
x264_mb_mc_0xywh( h, 0, 0, 2, 4 );
x264_mb_mc_0xywh( h, 2, 0, 2, 4 );
}
}
else if( h->mb.i_type == P_8x8 || h->mb.i_type == B_8x8 )//若是宏块类型为P8*8或B8*8
{
int i;
for( i = 0; i < 4; i++ )
x264_mb_mc_8x8( h, i );//分为D_L0,D_L1以及B预测三大种情况进行讨论分别调用x264_mb_mc_0xywh、x264_mb_mc_1xywh、x264_mb_mc_01xywh、x264_mb_mc_direct8x8进行处理。
}
else if( h->mb.i_type == B_SKIP || h->mb.i_type == B_DIRECT )//是否是B跳过或直接模式
{
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* *///若为其他B模式
{
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 )//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 )//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 )//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;
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) );
/* 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 = (i ? 1 : h->param.i_frame_reference) + h->param.b_bframe_pyramid;
for( j=0; j < i_refs && j < 16; j++ )
CHECKED_MALLOC( h->mb.mvr[i][j], 2 * i_mb_count * sizeof(int16_t) );
}
/* init with not avaiable (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<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.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_macroblock_cache_load( x264_t *h, int i_mb_x, int i_mb_y )
{
const int i_mb_4x4 = 4*(i_mb_y * h->mb.i_b4_stride + i_mb_x);
const int i_mb_8x8 = 2*(i_mb_y * h->mb.i_b8_stride + i_mb_x);
int i_mb_xy = i_mb_y * h->mb.i_mb_stride + i_mb_x;
int i_top_xy = i_mb_xy - h->mb.i_mb_stride;
int i_left_xy = -1;
int i_top_type = -1; /* gcc warn */
int i_left_type= -1;
int i;
/* 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_neighbour = 0;
/* 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 uint8_t *plane_fdec = &h->fdec->plane[i][ w * (i_mb_x + i_mb_y * i_stride) ];
int j;
h->mb.pic.i_stride[i] = i_stride;
h->mc.copy[i?PIXEL_8x8:PIXEL_16x16]( h->mb.pic.p_fenc[i], FENC_STRIDE,
&h->fenc->plane[i][ w * (i_mb_x + i_mb_y * i_stride) ], i_stride, w );
memcpy( &h->mb.pic.p_fdec[i][-1-FDEC_STRIDE], &plane_fdec[-1-i_stride], 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_stride];
for( j = 0; j < h->i_ref0; j++ )
{
h->mb.pic.p_fref[0][j][i==0 ? 0:i+3] = &h->fref0[j]->plane[i][ w * ( i_mb_x + i_mb_y * i_stride )];
h->mb.pic.p_fref[0][j][i+1] = &h->fref0[j]->filtered[i+1][ 16 * ( i_mb_x + i_mb_y * h->fdec->i_stride[0] )];
}
for( j = 0; j < h->i_ref1; j++ )
{
h->mb.pic.p_fref[1][j][i==0 ? 0:i+3] = &h->fref1[j]->plane[i][ w * ( i_mb_x + i_mb_y * i_stride )];
h->mb.pic.p_fref[1][j][i+1] = &h->fref1[j]->filtered[i+1][ 16 * ( i_mb_x + i_mb_y * h->fdec->i_stride[0] )];
}
}
if( h->fdec->integral )
{
for( i = 0; i < h->i_ref0; 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->i_ref1; i++ )
h->mb.pic.p_integral[1][i] = &h->fref1[i]->integral[ 16 * ( i_mb_x + i_mb_y * h->fdec->i_stride[0] )];
}
/* load cache */
if( i_mb_xy >= h->sh.i_first_mb + h->mb.i_mb_stride )
{
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->param.analyse.b_transform_8x8 )
{
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] );
}
/* 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++ )
{
/*
h->mb.cache.ref[i_list][x264_scan8[5 ]+1] =
h->mb.cache.ref[i_list][x264_scan8[7 ]+1] =
h->mb.cache.ref[i_list][x264_scan8[13]+1] = -2;
*/
if( h->mb.i_neighbour & MB_TOPLEFT )
{
const int i8 = x264_scan8[0] - 1 - 1*8;
const int ir = i_mb_8x8 - s8x8 - 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -