void vp9_init_mode_probs(FRAME_CONTEXT *fc) { vp9_copy(fc->uv_mode_prob, default_if_uv_probs); vp9_copy(fc->y_mode_prob, default_if_y_probs); vp9_copy(fc->switchable_interp_prob, default_switchable_interp_prob); vp9_copy(fc->partition_prob, default_partition_probs); vp9_copy(fc->intra_inter_prob, default_intra_inter_p); vp9_copy(fc->comp_inter_prob, default_comp_inter_p); vp9_copy(fc->comp_ref_prob, default_comp_ref_p); vp9_copy(fc->single_ref_prob, default_single_ref_p); fc->tx_probs = default_tx_probs; vp9_copy(fc->skip_probs, default_skip_probs); vp9_copy(fc->inter_mode_probs, default_inter_mode_probs); }
void vp9_init_mbmode_probs(VP9_COMMON *cm) { vp9_copy(cm->fc.uv_mode_prob, default_if_uv_probs); vp9_copy(cm->fc.y_mode_prob, default_if_y_probs); vp9_copy(cm->fc.switchable_interp_prob, default_switchable_interp_prob); vp9_copy(cm->fc.partition_prob, default_partition_probs); vp9_copy(cm->fc.intra_inter_prob, default_intra_inter_p); vp9_copy(cm->fc.comp_inter_prob, default_comp_inter_p); vp9_copy(cm->fc.comp_ref_prob, default_comp_ref_p); vp9_copy(cm->fc.single_ref_prob, default_single_ref_p); cm->fc.tx_probs = default_tx_probs; vp9_copy(cm->fc.skip_probs, default_skip_probs); vp9_copy(cm->fc.inter_mode_probs, default_inter_mode_probs); }
void vp9_setup_past_independence(VP9_COMMON *cm) { // Reset the segment feature data to the default stats: // Features disabled, 0, with delta coding (Default state). struct loopfilter *const lf = &cm->lf; int i; vp9_clearall_segfeatures(&cm->seg); cm->seg.abs_delta = SEGMENT_DELTADATA; if (cm->last_frame_seg_map) vpx_memset(cm->last_frame_seg_map, 0, (cm->mi_rows * cm->mi_cols)); // Reset the mode ref deltas for loop filter vp9_zero(lf->last_ref_deltas); vp9_zero(lf->last_mode_deltas); set_default_lf_deltas(lf); // To force update of the sharpness lf->last_sharpness_level = -1; vp9_default_coef_probs(cm); vp9_init_mbmode_probs(cm); vp9_init_mv_probs(cm); vp9_copy(cm->fc.inter_mode_probs, default_inter_mode_probs); if (cm->frame_type == KEY_FRAME || cm->error_resilient_mode || cm->reset_frame_context == 3) { // Reset all frame contexts. for (i = 0; i < NUM_FRAME_CONTEXTS; ++i) cm->frame_contexts[i] = cm->fc; } else if (cm->reset_frame_context == 2) { // Reset only the frame context specified in the frame header. cm->frame_contexts[cm->frame_context_idx] = cm->fc; } vpx_memset(cm->prev_mip, 0, cm->mode_info_stride * (cm->mi_rows + 1) * sizeof(MODE_INFO)); vpx_memset(cm->mip, 0, cm->mode_info_stride * (cm->mi_rows + 1) * sizeof(MODE_INFO)); vp9_update_mode_info_border(cm, cm->mip); vp9_update_mode_info_border(cm, cm->prev_mip); vp9_zero(cm->ref_frame_sign_bias); cm->frame_context_idx = 0; }
// Row-based multi-threaded loopfilter hook static int loop_filter_row_worker(thread_context *const thread_ctxt, void *unused) { VP9_COMP *const cpi = thread_ctxt->cpi; VP9_COMMON *const cm = &cpi->common; MACROBLOCKD *const xd = &cpi->mb.e_mbd; const YV12_BUFFER_CONFIG *const frame_buffer = cm->frame_to_show; struct macroblockd_plane planes[MAX_MB_PLANE]; const int num_planes = thread_ctxt->y_only ? 1 : MAX_MB_PLANE; int mi_row, mi_col; (void)unused; vp9_copy(planes, xd->plane); for (mi_row = thread_ctxt->mi_row_start; mi_row < thread_ctxt->mi_row_end; mi_row += thread_ctxt->mi_row_step) { const int sb_row = mi_row >> MI_BLOCK_SIZE_LOG2; MODE_INFO **const mi = cm->mi_grid_visible + mi_row * cm->mi_stride; for (mi_col = 0; mi_col < cm->mi_cols; mi_col += MI_BLOCK_SIZE) { const int sb_col = mi_col >> MI_BLOCK_SIZE_LOG2; LOOP_FILTER_MASK lfm; int plane; vp9_enc_sync_read(cpi, sb_row, sb_col); vp9_setup_dst_planes(planes, frame_buffer, mi_row, mi_col); vp9_setup_mask(cm, mi_row, mi_col, mi + mi_col, cm->mi_stride, &lfm); for (plane = 0; plane < num_planes; ++plane) { vp9_filter_block_plane(cm, &planes[plane], mi_row, &lfm); } vp9_enc_sync_write(cpi, sb_row); } } return 1; }
void vp9_restore_coding_context(VP9_COMP *cpi) { CODING_CONTEXT *const cc = &cpi->coding_context; VP9_COMMON *cm = &cpi->common; // Restore key state variables to the snapshot state stored in the // previous call to vp9_save_coding_context. vp9_copy(cpi->mb.nmvjointcost, cc->nmvjointcost); vp9_copy(cpi->mb.nmvcosts, cc->nmvcosts); vp9_copy(cpi->mb.nmvcosts_hp, cc->nmvcosts_hp); vp9_copy(cm->seg.pred_probs, cc->segment_pred_probs); vpx_memcpy(cm->last_frame_seg_map, cpi->coding_context.last_frame_seg_map_copy, (cm->mi_rows * cm->mi_cols)); vp9_copy(cm->lf.last_ref_deltas, cc->last_ref_lf_deltas); vp9_copy(cm->lf.last_mode_deltas, cc->last_mode_lf_deltas); cm->fc = cc->fc; }
void vp9_save_coding_context(VP9_COMP *cpi) { CODING_CONTEXT *const cc = &cpi->coding_context; VP9_COMMON *cm = &cpi->common; // Stores a snapshot of key state variables which can subsequently be // restored with a call to vp9_restore_coding_context. These functions are // intended for use in a re-code loop in vp9_compress_frame where the // quantizer value is adjusted between loop iterations. vp9_copy(cc->nmvjointcost, cpi->mb.nmvjointcost); vp9_copy(cc->nmvcosts, cpi->mb.nmvcosts); vp9_copy(cc->nmvcosts_hp, cpi->mb.nmvcosts_hp); vp9_copy(cc->segment_pred_probs, cm->seg.pred_probs); vpx_memcpy(cpi->coding_context.last_frame_seg_map_copy, cm->last_frame_seg_map, (cm->mi_rows * cm->mi_cols)); vp9_copy(cc->last_ref_lf_deltas, cm->lf.last_ref_deltas); vp9_copy(cc->last_mode_lf_deltas, cm->lf.last_mode_deltas); cc->fc = cm->fc; }
// VP9 decoder: Implement multi-threaded loopfilter that uses the tile // threads. void vp9_loop_filter_frame_mt(YV12_BUFFER_CONFIG *frame, VP9Decoder *pbi, VP9_COMMON *cm, int frame_filter_level, int y_only) { VP9LfSync *const lf_sync = &pbi->lf_row_sync; const VP9WorkerInterface *const winterface = vp9_get_worker_interface(); // Number of superblock rows and cols const int sb_rows = mi_cols_aligned_to_sb(cm->mi_rows) >> MI_BLOCK_SIZE_LOG2; const int tile_cols = 1 << cm->log2_tile_cols; const int num_workers = MIN(pbi->max_threads & ~1, tile_cols); int i; if (!frame_filter_level) return; if (!lf_sync->sync_range || cm->last_height != cm->height) { vp9_loop_filter_dealloc(lf_sync); vp9_loop_filter_alloc(lf_sync, cm, sb_rows, cm->width); } vp9_loop_filter_frame_init(cm, frame_filter_level); // Initialize cur_sb_col to -1 for all SB rows. vpx_memset(lf_sync->cur_sb_col, -1, sizeof(*lf_sync->cur_sb_col) * sb_rows); // Set up loopfilter thread data. // The decoder is using num_workers instead of pbi->num_tile_workers // because it has been observed that using more threads on the // loopfilter, than there are tile columns in the frame will hurt // performance on Android. This is because the system will only // schedule the tile decode workers on cores equal to the number // of tile columns. Then if the decoder tries to use more threads for the // loopfilter, it will hurt performance because of contention. If the // multithreading code changes in the future then the number of workers // used by the loopfilter should be revisited. for (i = 0; i < num_workers; ++i) { VP9Worker *const worker = &pbi->tile_workers[i]; TileWorkerData *const tile_data = (TileWorkerData*)worker->data1; LFWorkerData *const lf_data = &tile_data->lfdata; worker->hook = (VP9WorkerHook)loop_filter_row_worker; // Loopfilter data lf_data->frame_buffer = frame; lf_data->cm = cm; vp9_copy(lf_data->planes, pbi->mb.plane); lf_data->start = i; lf_data->stop = sb_rows; lf_data->y_only = y_only; // always do all planes in decoder lf_data->lf_sync = lf_sync; lf_data->num_lf_workers = num_workers; // Start loopfiltering if (i == num_workers - 1) { winterface->execute(worker); } else { winterface->launch(worker); } } // Wait till all rows are finished for (i = 0; i < num_workers; ++i) { winterface->sync(&pbi->tile_workers[i]); } }
void vp9_default_coef_probs(VP9_COMMON *cm) { vp9_copy(cm->fc.coef_probs[TX_4X4], default_coef_probs_4x4); vp9_copy(cm->fc.coef_probs[TX_8X8], default_coef_probs_8x8); vp9_copy(cm->fc.coef_probs[TX_16X16], default_coef_probs_16x16); vp9_copy(cm->fc.coef_probs[TX_32X32], default_coef_probs_32x32); }
void vp9_restore_coding_context(VP9_COMP *cpi) { CODING_CONTEXT *const cc = &cpi->coding_context; VP9_COMMON *cm = &cpi->common; MACROBLOCKD *xd = &cpi->mb.e_mbd; // Restore key state variables to the snapshot state stored in the // previous call to vp9_save_coding_context. cm->fc.nmvc = cc->nmvc; vp9_copy(cpi->mb.nmvjointcost, cc->nmvjointcost); vp9_copy(cpi->mb.nmvcosts, cc->nmvcosts); vp9_copy(cpi->mb.nmvcosts_hp, cc->nmvcosts_hp); vp9_copy(cm->fc.vp9_mode_contexts, cc->vp9_mode_contexts); vp9_copy(cm->fc.ymode_prob, cc->ymode_prob); vp9_copy(cm->fc.sb_ymode_prob, cc->sb_ymode_prob); vp9_copy(cm->fc.bmode_prob, cc->bmode_prob); vp9_copy(cm->fc.i8x8_mode_prob, cc->i8x8_mode_prob); vp9_copy(cm->fc.uv_mode_prob, cc->uv_mode_prob); vp9_copy(cm->fc.sub_mv_ref_prob, cc->sub_mv_ref_prob); vp9_copy(cm->fc.mbsplit_prob, cc->mbsplit_prob); // Stats #ifdef MODE_STATS vp9_copy(y_modes, cc->y_modes); vp9_copy(uv_modes, cc->uv_modes); vp9_copy(b_modes, cc->b_modes); vp9_copy(inter_y_modes, cc->inter_y_modes); vp9_copy(inter_uv_modes, cc->inter_uv_modes); vp9_copy(inter_b_modes, cc->inter_b_modes); #endif vp9_copy(cm->segment_pred_probs, cc->segment_pred_probs); vp9_copy(cpi->ref_pred_probs_update, cc->ref_pred_probs_update); vp9_copy(cm->ref_pred_probs, cc->ref_pred_probs); vp9_copy(cm->prob_comppred, cc->prob_comppred); vpx_memcpy(cm->last_frame_seg_map, cpi->coding_context.last_frame_seg_map_copy, (cm->mb_rows * cm->mb_cols)); vp9_copy(xd->last_ref_lf_deltas, cc->last_ref_lf_deltas); vp9_copy(xd->last_mode_lf_deltas, cc->last_mode_lf_deltas); vp9_copy(cm->fc.coef_probs_4x4, cc->coef_probs_4x4); vp9_copy(cm->fc.hybrid_coef_probs_4x4, cc->hybrid_coef_probs_4x4); vp9_copy(cm->fc.coef_probs_8x8, cc->coef_probs_8x8); vp9_copy(cm->fc.hybrid_coef_probs_8x8, cc->hybrid_coef_probs_8x8); vp9_copy(cm->fc.coef_probs_16x16, cc->coef_probs_16x16); vp9_copy(cm->fc.hybrid_coef_probs_16x16, cc->hybrid_coef_probs_16x16); vp9_copy(cm->fc.coef_probs_32x32, cc->coef_probs_32x32); vp9_copy(cm->fc.switchable_interp_prob, cc->switchable_interp_prob); #if CONFIG_COMP_INTERINTRA_PRED cm->fc.interintra_prob = cc->interintra_prob; #endif }
void vp9_save_coding_context(VP9_COMP *cpi) { CODING_CONTEXT *const cc = &cpi->coding_context; VP9_COMMON *cm = &cpi->common; MACROBLOCKD *xd = &cpi->mb.e_mbd; // Stores a snapshot of key state variables which can subsequently be // restored with a call to vp9_restore_coding_context. These functions are // intended for use in a re-code loop in vp9_compress_frame where the // quantizer value is adjusted between loop iterations. cc->nmvc = cm->fc.nmvc; vp9_copy(cc->nmvjointcost, cpi->mb.nmvjointcost); vp9_copy(cc->nmvcosts, cpi->mb.nmvcosts); vp9_copy(cc->nmvcosts_hp, cpi->mb.nmvcosts_hp); vp9_copy(cc->vp9_mode_contexts, cm->fc.vp9_mode_contexts); vp9_copy(cc->ymode_prob, cm->fc.ymode_prob); vp9_copy(cc->sb_ymode_prob, cm->fc.sb_ymode_prob); vp9_copy(cc->bmode_prob, cm->fc.bmode_prob); vp9_copy(cc->uv_mode_prob, cm->fc.uv_mode_prob); vp9_copy(cc->i8x8_mode_prob, cm->fc.i8x8_mode_prob); vp9_copy(cc->sub_mv_ref_prob, cm->fc.sub_mv_ref_prob); vp9_copy(cc->mbsplit_prob, cm->fc.mbsplit_prob); // Stats #ifdef MODE_STATS vp9_copy(cc->y_modes, y_modes); vp9_copy(cc->uv_modes, uv_modes); vp9_copy(cc->b_modes, b_modes); vp9_copy(cc->inter_y_modes, inter_y_modes); vp9_copy(cc->inter_uv_modes, inter_uv_modes); vp9_copy(cc->inter_b_modes, inter_b_modes); #endif vp9_copy(cc->segment_pred_probs, cm->segment_pred_probs); vp9_copy(cc->ref_pred_probs_update, cpi->ref_pred_probs_update); vp9_copy(cc->ref_pred_probs, cm->ref_pred_probs); vp9_copy(cc->prob_comppred, cm->prob_comppred); vpx_memcpy(cpi->coding_context.last_frame_seg_map_copy, cm->last_frame_seg_map, (cm->mb_rows * cm->mb_cols)); vp9_copy(cc->last_ref_lf_deltas, xd->last_ref_lf_deltas); vp9_copy(cc->last_mode_lf_deltas, xd->last_mode_lf_deltas); vp9_copy(cc->coef_probs_4x4, cm->fc.coef_probs_4x4); vp9_copy(cc->hybrid_coef_probs_4x4, cm->fc.hybrid_coef_probs_4x4); vp9_copy(cc->coef_probs_8x8, cm->fc.coef_probs_8x8); vp9_copy(cc->hybrid_coef_probs_8x8, cm->fc.hybrid_coef_probs_8x8); vp9_copy(cc->coef_probs_16x16, cm->fc.coef_probs_16x16); vp9_copy(cc->hybrid_coef_probs_16x16, cm->fc.hybrid_coef_probs_16x16); vp9_copy(cc->coef_probs_32x32, cm->fc.coef_probs_32x32); vp9_copy(cc->switchable_interp_prob, cm->fc.switchable_interp_prob); #if CONFIG_COMP_INTERINTRA_PRED cc->interintra_prob = cm->fc.interintra_prob; #endif }