mode_estimation字面意思就是模式估计,实质上是对帧内和帧间的模式进行遍历。帧内预测选取了13种模式,主要是DC模式、角度模式和新加入的PAETH模式。帧间对7个参考帧进行遍历,寻找COST最优的块,并记录下运动矢量和参考帧编号。tpl_stats是用来存储当前块的各种信息,包含上述的变量,以便在后续调用函数时使用。
static void mode_estimation(AV1_COMP *cpi, MACROBLOCK *x, MACROBLOCKD *xd,
struct scale_factors *sf, int frame_idx,
int16_t *src_diff, tran_low_t *coeff, int use_satd,
int mi_row, int mi_col, BLOCK_SIZE bsize,
TX_SIZE tx_size, YV12_BUFFER_CONFIG *ref_frame[],
uint8_t *predictor, TplDepStats *tpl_stats) {
AV1_COMMON *cm = &cpi->common;
const GF_GROUP *gf_group = &cpi->twopass.gf_group;
const int bw = 4 << mi_size_wide_log2[bsize];
const int bh = 4 << mi_size_high_log2[bsize];
const int pix_num = bw * bh;//因为是16×16的块,所有像素数量是256
const InterpFilters kernel =
av1_make_interp_filters(EIGHTTAP_REGULAR, EIGHTTAP_REGULAR);
int64_t best_intra_cost = INT64_MAX;
int64_t intra_cost;
PREDICTION_MODE mode;
//偏移值,定位16×16块的左上角
int mb_y_offset = mi_row * MI_SIZE * xd->cur_buf->y_stride + mi_col * MI_SIZE;
memset(tpl_stats, 0, sizeof(*tpl_stats));
xd->above_mbmi = NULL;
xd->left_mbmi = NULL;
xd->mi[0]->sb_type = bsize;
xd->mi[0]->motion_mode = SIMPLE_TRANSLATION