x264-deblock逻辑
x264_fdec_filter_row:
//b_kept_as_ref定义在函数x264_encoder_encode中 int b_hpel = h->fdec->b_kept_as_ref;
//i_disable_deblocking_filter_idc定义在x264_slice_header_init中int b_deblock = h->sh.i_disable_deblocking_filter_idc != 1;b_deblock &= b_hpel || h->param.psz_dump_yuv; //psz_dump_yuv: filename for reconstructed frames */if( b_deblock )x264_frame_deblock_row( h, y );
x264_encoder_encode:
if( h->fenc->i_type == X264_TYPE_IDR ){
/* reset ref pictures */x264_reference_reset( h );i_nal_type = NAL_SLICE_IDR;i_nal_ref_idc = NAL_PRIORITY_HIGHEST;h->sh.i_type = SLICE_TYPE_I;}else if( h->fenc->i_type == X264_TYPE_I ){
i_nal_type = NAL_SLICE;i_nal_ref_idc = NAL_PRIORITY_HIGH; /* Not completely true but for now it is (as all I/P are kept as ref)*/h->sh.i_type = SLICE_TYPE_I;}else if( h->fenc->i_type == X264_TYPE_P ){
i_nal_type = NAL_SLICE;i_nal_ref_idc = NAL_PRIORITY_HIGH; /* Not completely true but for now it is (as all I/P are kept as ref)*/h->sh.i_type = SLICE_TYPE_P;}else if( h->fenc->i_type == X264_TYPE_BREF ){
i_nal_type = NAL_SLICE;i_nal_ref_idc = NAL_PRIORITY_HIGH; /* maybe add MMCO to forget it? -> low */h->sh.i_type = SLICE_TYPE_B;}else /* B frame */{
i_nal_type = NAL_SLICE;i_nal_ref_idc = NAL_PRIORITY_DISPOSABLE;h->sh.i_type = SLICE_TYPE_B;}h->fdec->b_kept_as_ref = i_nal_ref_idc != NAL_PRIORITY_DISPOSABLE && h->param.i_keyint_max > 1;
x264_slice_header_init:
//i_qp: 当前帧QP,假设命令行参数QP=18,此时IBP帧的QP在x264_ratecontrol_new中计算,若ipo_offset=3,此时I帧QP=15。//则在--deblock 0:0时,deblock_thresh=15,CQP时I帧不会dbk,但P帧会int deblock_thresh = i_qp + 2 * X264_MIN(param->i_deblocking_filter_alphac0, param->i_deblocking_filter_beta);/* If effective qp <= 15, deblocking would have no effect anyway *///b_variable_qp: whether qp is allowed to vary per macroblock 定义在函数x264_ratecontrol_new中if( param->b_deblocking_filter && (h->mb.b_variable_qp || 15 < deblock_thresh ) )sh->i_disable_deblocking_filter_idc = param->b_sliced_threads ? 2 : 0;elsesh->i_disable_deblocking_filter_idc = 1;
x264_ratecontrol_new:
h->mb.b_variable_qp = rc->b_vbv || h->param.rc.i_aq_mode;
···rc->qp_constant[SLICE_TYPE_P] = h->param.rc.i_qp_constant;rc->qp_constant[SLICE_TYPE_I] = x264_clip3( h->param.rc.i_qp_constant - rc->ip_offset + 0.5, 0, 51 );rc->qp_constant[SLICE_TYPE_B] = x264_clip3( h->param.rc.i_qp_constant + rc->pb_offset + 0.5, 0, 51 );