void vp9_loop_filter_frame_init(VP9_COMMON *const cm, MACROBLOCKD *const xd,
int default_filt_lvl) {
- int seg;
+ int seg_id;
// n_shift is the a multiplier for lf_deltas
// the multiplier is 1 for when filter_lvl is between 0 and 31;
// 2 when filter_lvl is between 32 and 63
const int n_shift = default_filt_lvl >> 5;
loop_filter_info_n *const lfi = &cm->lf_info;
- struct loopfilter *lf = &xd->lf;
+ struct loopfilter *const lf = &xd->lf;
+ struct segmentation *const seg = &xd->seg;
// update limits if sharpness has changed
if (lf->last_sharpness_level != lf->sharpness_level) {
lf->last_sharpness_level = lf->sharpness_level;
}
- for (seg = 0; seg < MAX_SEGMENTS; seg++) {
+ for (seg_id = 0; seg_id < MAX_SEGMENTS; seg_id++) {
int lvl_seg = default_filt_lvl, ref, mode, intra_lvl;
// Set the baseline filter values for each segment
- if (vp9_segfeature_active(&xd->seg, seg, SEG_LVL_ALT_LF)) {
- const int data = vp9_get_segdata(&xd->seg, seg, SEG_LVL_ALT_LF);
- lvl_seg = xd->seg.abs_delta == SEGMENT_ABSDATA
+ if (vp9_segfeature_active(&xd->seg, seg_id, SEG_LVL_ALT_LF)) {
+ const int data = vp9_get_segdata(seg, seg_id, SEG_LVL_ALT_LF);
+ lvl_seg = seg->abs_delta == SEGMENT_ABSDATA
? data
: clamp(default_filt_lvl + data, 0, MAX_LOOP_FILTER);
}
if (!lf->mode_ref_delta_enabled) {
// we could get rid of this if we assume that deltas are set to
// zero when not in use; encoder always uses deltas
- vpx_memset(lfi->lvl[seg][0], lvl_seg, 4 * 4);
+ vpx_memset(lfi->lvl[seg_id][0], lvl_seg, 4 * 4);
continue;
}
intra_lvl = lvl_seg + (lf->ref_deltas[INTRA_FRAME] << n_shift);
- lfi->lvl[seg][INTRA_FRAME][0] = clamp(intra_lvl, 0, MAX_LOOP_FILTER);
+ lfi->lvl[seg_id][INTRA_FRAME][0] = clamp(intra_lvl, 0, MAX_LOOP_FILTER);
for (ref = LAST_FRAME; ref < MAX_REF_FRAMES; ++ref)
for (mode = 0; mode < MAX_MODE_LF_DELTAS; ++mode) {
const int inter_lvl = lvl_seg + (lf->ref_deltas[ref] << n_shift)
+ (lf->mode_deltas[mode] << n_shift);
- lfi->lvl[seg][ref][mode] = clamp(inter_lvl, 0, MAX_LOOP_FILTER);
+ lfi->lvl[seg_id][ref][mode] = clamp(inter_lvl, 0, MAX_LOOP_FILTER);
}
}
}
static void setup_features(VP9_COMP *cpi) {
MACROBLOCKD *xd = &cpi->mb.e_mbd;
- struct loopfilter *lf = &xd->lf;
+ struct loopfilter *const lf = &xd->lf;
+ struct segmentation *const seg = &xd->seg;
// Set up default state for MB feature flags
- xd->seg.enabled = 0;
+ seg->enabled = 0;
- xd->seg.update_map = 0;
- xd->seg.update_data = 0;
- vpx_memset(xd->seg.tree_probs, 255, sizeof(xd->seg.tree_probs));
+ seg->update_map = 0;
+ seg->update_data = 0;
+ vpx_memset(seg->tree_probs, 255, sizeof(seg->tree_probs));
- vp9_clearall_segfeatures(&xd->seg);
+ vp9_clearall_segfeatures(seg);
lf->mode_ref_delta_enabled = 0;
lf->mode_ref_delta_update = 0;
static void configure_static_seg_features(VP9_COMP *cpi) {
VP9_COMMON *cm = &cpi->common;
MACROBLOCKD *xd = &cpi->mb.e_mbd;
+ struct segmentation *seg = &xd->seg;
int high_q = (int)(cpi->avg_q > 48.0);
int qi_delta;
if (cm->frame_type == KEY_FRAME) {
// Clear down the global segmentation map
vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
- xd->seg.update_map = 0;
- xd->seg.update_data = 0;
+ seg->update_map = 0;
+ seg->update_data = 0;
cpi->static_mb_pct = 0;
// Disable segmentation
vp9_disable_segmentation((VP9_PTR)cpi);
// Clear down the segment features.
- vp9_clearall_segfeatures(&xd->seg);
+ vp9_clearall_segfeatures(seg);
} else if (cpi->refresh_alt_ref_frame) {
// If this is an alt ref frame
// Clear down the global segmentation map
vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
- xd->seg.update_map = 0;
- xd->seg.update_data = 0;
+ seg->update_map = 0;
+ seg->update_data = 0;
cpi->static_mb_pct = 0;
// Disable segmentation and individual segment features by default
vp9_disable_segmentation((VP9_PTR)cpi);
- vp9_clearall_segfeatures(&xd->seg);
+ vp9_clearall_segfeatures(seg);
// Scan frames from current to arf frame.
// This function re-enables segmentation if appropriate.
// If segmentation was enabled set those features needed for the
// arf itself.
- if (xd->seg.enabled) {
- xd->seg.update_map = 1;
- xd->seg.update_data = 1;
+ if (seg->enabled) {
+ seg->update_map = 1;
+ seg->update_data = 1;
qi_delta = compute_qdelta(cpi, cpi->avg_q, (cpi->avg_q * 0.875));
- vp9_set_segdata(&xd->seg, 1, SEG_LVL_ALT_Q, (qi_delta - 2));
- vp9_set_segdata(&xd->seg, 1, SEG_LVL_ALT_LF, -2);
+ vp9_set_segdata(seg, 1, SEG_LVL_ALT_Q, (qi_delta - 2));
+ vp9_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2);
- vp9_enable_segfeature(&xd->seg, 1, SEG_LVL_ALT_Q);
- vp9_enable_segfeature(&xd->seg, 1, SEG_LVL_ALT_LF);
+ vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_Q);
+ vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_LF);
// Where relevant assume segment data is delta data
- xd->seg.abs_delta = SEGMENT_DELTADATA;
+ seg->abs_delta = SEGMENT_DELTADATA;
}
- } else if (xd->seg.enabled) {
+ } else if (seg->enabled) {
// All other frames if segmentation has been enabled
// First normal frame in a valid gf or alt ref group
if (cpi->frames_since_golden == 0) {
// Set up segment features for normal frames in an arf group
if (cpi->source_alt_ref_active) {
- xd->seg.update_map = 0;
- xd->seg.update_data = 1;
- xd->seg.abs_delta = SEGMENT_DELTADATA;
+ seg->update_map = 0;
+ seg->update_data = 1;
+ seg->abs_delta = SEGMENT_DELTADATA;
qi_delta = compute_qdelta(cpi, cpi->avg_q,
(cpi->avg_q * 1.125));
- vp9_set_segdata(&xd->seg, 1, SEG_LVL_ALT_Q, (qi_delta + 2));
- vp9_enable_segfeature(&xd->seg, 1, SEG_LVL_ALT_Q);
+ vp9_set_segdata(seg, 1, SEG_LVL_ALT_Q, (qi_delta + 2));
+ vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_Q);
- vp9_set_segdata(&xd->seg, 1, SEG_LVL_ALT_LF, -2);
- vp9_enable_segfeature(&xd->seg, 1, SEG_LVL_ALT_LF);
+ vp9_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2);
+ vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_LF);
// Segment coding disabled for compred testing
if (high_q || (cpi->static_mb_pct == 100)) {
- vp9_set_segdata(&xd->seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME);
- vp9_enable_segfeature(&xd->seg, 1, SEG_LVL_REF_FRAME);
- vp9_enable_segfeature(&xd->seg, 1, SEG_LVL_SKIP);
+ vp9_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME);
+ vp9_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME);
+ vp9_enable_segfeature(seg, 1, SEG_LVL_SKIP);
}
} else {
// Disable segmentation and clear down features if alt ref
vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
- xd->seg.update_map = 0;
- xd->seg.update_data = 0;
+ seg->update_map = 0;
+ seg->update_data = 0;
- vp9_clearall_segfeatures(&xd->seg);
+ vp9_clearall_segfeatures(seg);
}
} else if (cpi->is_src_frame_alt_ref) {
// Special case where we are coding over the top of a previous
// Segment coding disabled for compred testing
// Enable ref frame features for segment 0 as well
- vp9_enable_segfeature(&xd->seg, 0, SEG_LVL_REF_FRAME);
- vp9_enable_segfeature(&xd->seg, 1, SEG_LVL_REF_FRAME);
+ vp9_enable_segfeature(seg, 0, SEG_LVL_REF_FRAME);
+ vp9_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME);
// All mbs should use ALTREF_FRAME
- vp9_clear_segdata(&xd->seg, 0, SEG_LVL_REF_FRAME);
- vp9_set_segdata(&xd->seg, 0, SEG_LVL_REF_FRAME, ALTREF_FRAME);
- vp9_clear_segdata(&xd->seg, 1, SEG_LVL_REF_FRAME);
- vp9_set_segdata(&xd->seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME);
+ vp9_clear_segdata(seg, 0, SEG_LVL_REF_FRAME);
+ vp9_set_segdata(seg, 0, SEG_LVL_REF_FRAME, ALTREF_FRAME);
+ vp9_clear_segdata(seg, 1, SEG_LVL_REF_FRAME);
+ vp9_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME);
// Skip all MBs if high Q (0,0 mv and skip coeffs)
if (high_q) {
- vp9_enable_segfeature(&xd->seg, 0, SEG_LVL_SKIP);
- vp9_enable_segfeature(&xd->seg, 1, SEG_LVL_SKIP);
+ vp9_enable_segfeature(seg, 0, SEG_LVL_SKIP);
+ vp9_enable_segfeature(seg, 1, SEG_LVL_SKIP);
}
// Enable data update
- xd->seg.update_data = 1;
+ seg->update_data = 1;
} else {
// All other frames.
// No updates.. leave things as they are.
- xd->seg.update_map = 0;
- xd->seg.update_data = 0;
+ seg->update_map = 0;
+ seg->update_data = 0;
}
}
}
static void loopfilter_frame(VP9_COMP *cpi, VP9_COMMON *cm) {
MACROBLOCKD *xd = &cpi->mb.e_mbd;
+ struct loopfilter *lf = &xd->lf;
if (xd->lossless) {
- xd->lf.filter_level = 0;
+ lf->filter_level = 0;
} else {
struct vpx_usec_timer timer;
cpi->time_pick_lpf += vpx_usec_timer_elapsed(&timer);
}
- if (xd->lf.filter_level > 0) {
- vp9_set_alt_lf_level(cpi, xd->lf.filter_level);
- vp9_loop_filter_frame(cm, xd, xd->lf.filter_level, 0);
+ if (lf->filter_level > 0) {
+ vp9_set_alt_lf_level(cpi, lf->filter_level);
+ vp9_loop_filter_frame(cm, xd, lf->filter_level, 0);
}
vp9_extend_frame_inner_borders(cm->frame_to_show,
SPEED_FEATURES *sf = &cpi->sf;
unsigned int max_mv_def = MIN(cpi->common.width, cpi->common.height);
+ struct segmentation *seg = &xd->seg;
#if RESET_FOREACH_FILTER
int q_low0;
int q_high0;
setup_features(cpi);
// If segmentation is enabled force a map update for key frames
- if (xd->seg.enabled) {
- xd->seg.update_map = 1;
- xd->seg.update_data = 1;
+ if (seg->enabled) {
+ seg->update_map = 1;
+ seg->update_data = 1;
}
// The alternate reference frame cannot be active for a key frame
unsigned int threshold[MAX_SEGMENTS]) {
VP9_COMP *cpi = (VP9_COMP *) comp;
signed char feature_data[SEG_LVL_MAX][MAX_SEGMENTS];
- MACROBLOCKD *xd = &cpi->mb.e_mbd;
+ struct segmentation *seg = &cpi->mb.e_mbd.seg;
int i;
if (cpi->common.mb_rows != rows || cpi->common.mb_cols != cols)
// Enable the loop and quant changes in the feature mask
for (i = 0; i < MAX_SEGMENTS; i++) {
if (delta_q[i])
- vp9_enable_segfeature(&xd->seg, i, SEG_LVL_ALT_Q);
+ vp9_enable_segfeature(seg, i, SEG_LVL_ALT_Q);
else
- vp9_disable_segfeature(&xd->seg, i, SEG_LVL_ALT_Q);
+ vp9_disable_segfeature(seg, i, SEG_LVL_ALT_Q);
if (delta_lf[i])
- vp9_enable_segfeature(&xd->seg, i, SEG_LVL_ALT_LF);
+ vp9_enable_segfeature(seg, i, SEG_LVL_ALT_LF);
else
- vp9_disable_segfeature(&xd->seg, i, SEG_LVL_ALT_LF);
+ vp9_disable_segfeature(seg, i, SEG_LVL_ALT_LF);
}
// Initialise the feature data structure
VP9_COMMON *cm = &cpi->common;
MACROBLOCKD *xd = &x->e_mbd;
MB_MODE_INFO *mbmi = &xd->mode_info_context->mbmi;
+ const struct segmentation *seg = &xd->seg;
const BLOCK_SIZE_TYPE block_size = get_plane_block_size(bsize, &xd->plane[0]);
MB_PREDICTION_MODE this_mode;
MV_REFERENCE_FRAME ref_frame, second_ref_frame;
// Do not allow compound prediction if the segment level reference
// frame feature is in use as in this case there can only be one reference.
if ((second_ref_frame > INTRA_FRAME) &&
- vp9_segfeature_active(&xd->seg, segment_id, SEG_LVL_REF_FRAME))
+ vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME))
continue;
// Skip some checking based on small partitions' result.
// If the segment reference frame feature is enabled....
// then do nothing if the current ref frame is not allowed..
- if (vp9_segfeature_active(&xd->seg, segment_id, SEG_LVL_REF_FRAME) &&
- vp9_get_segdata(&xd->seg, segment_id, SEG_LVL_REF_FRAME) !=
+ if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) &&
+ vp9_get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) !=
(int)ref_frame) {
continue;
// If the segment skip feature is enabled....
// then do nothing if the current mode is not allowed..
- } else if (vp9_segfeature_active(&xd->seg, segment_id, SEG_LVL_SKIP) &&
+ } else if (vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP) &&
(this_mode != ZEROMV && ref_frame != INTRA_FRAME)) {
continue;
// Disable this drop out case if the ref frame
// segment level feature is enabled for this segment. This is to
// prevent the possibility that we end up unable to pick any mode.
- } else if (!vp9_segfeature_active(&xd->seg, segment_id,
+ } else if (!vp9_segfeature_active(seg, segment_id,
SEG_LVL_REF_FRAME)) {
// Only consider ZEROMV/ALTREF_FRAME for alt ref frame,
// unless ARNR filtering is enabled in which case we want
// necessary adjustment for rate. Ignore if skip is coded at
// segment level as the cost wont have been added in.
// Is Mb level skip allowed (i.e. not coded at segment level).
- const int mb_skip_allowed = !vp9_segfeature_active(&xd->seg, segment_id,
+ const int mb_skip_allowed = !vp9_segfeature_active(seg, segment_id,
SEG_LVL_SKIP);
if (skippable && bsize >= BLOCK_SIZE_SB8X8) {