Merge "Removing redundant code mostly from vp9_pred_common.{h, c}."

This commit is contained in:
Dmitry Kovalev 2013-07-12 10:22:30 -07:00 committed by Gerrit Code Review
commit 727631873d
8 changed files with 100 additions and 149 deletions

View File

@ -17,7 +17,7 @@
#include "vp9/common/vp9_treecoder.h"
void vp9_set_pred_flag_seg_id(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize,
unsigned char pred_flag) {
unsigned char pred_flag) {
const int mis = xd->mode_info_stride;
const int bh = 1 << mi_height_log2(bsize);
const int bw = 1 << mi_width_log2(bsize);
@ -34,45 +34,40 @@ void vp9_set_pred_flag_seg_id(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize,
// Returns a context number for the given MB prediction signal
unsigned char vp9_get_pred_context_switchable_interp(const VP9_COMMON *cm,
const MACROBLOCKD *xd) {
int pred_context;
const MODE_INFO * const mi = xd->mode_info_context;
const MODE_INFO * const above_mi = mi - cm->mode_info_stride;
const MODE_INFO * const left_mi = mi - 1;
const int left_in_image = xd->left_available && left_mi->mbmi.mb_in_image;
const int above_in_image = xd->up_available && above_mi->mbmi.mb_in_image;
const MODE_INFO *const mi = xd->mode_info_context;
const MB_MODE_INFO *const above_mbmi = &mi[-cm->mode_info_stride].mbmi;
const MB_MODE_INFO *const left_mbmi = &mi[-1].mbmi;
const int left_in_image = xd->left_available && left_mbmi->mb_in_image;
const int above_in_image = xd->up_available && above_mbmi->mb_in_image;
// Note:
// The mode info data structure has a one element border above and to the
// left of the entries correpsonding to real macroblocks.
// The prediction flags in these dummy entries are initialised to 0.
// left
const int left_mv_pred = is_inter_mode(left_mi->mbmi.mode);
const int left_interp =
left_in_image && left_mv_pred ?
vp9_switchable_interp_map[left_mi->mbmi.interp_filter] :
const int left_mv_pred = is_inter_mode(left_mbmi->mode);
const int left_interp = left_in_image && left_mv_pred ?
vp9_switchable_interp_map[left_mbmi->interp_filter] :
VP9_SWITCHABLE_FILTERS;
// above
const int above_mv_pred = is_inter_mode(above_mi->mbmi.mode);
const int above_interp =
above_in_image && above_mv_pred ?
vp9_switchable_interp_map[above_mi->mbmi.interp_filter] :
const int above_mv_pred = is_inter_mode(above_mbmi->mode);
const int above_interp = above_in_image && above_mv_pred ?
vp9_switchable_interp_map[above_mbmi->interp_filter] :
VP9_SWITCHABLE_FILTERS;
assert(left_interp != -1);
assert(above_interp != -1);
if (left_interp == above_interp)
pred_context = left_interp;
else if (left_interp == VP9_SWITCHABLE_FILTERS
&& above_interp != VP9_SWITCHABLE_FILTERS)
pred_context = above_interp;
else if (left_interp != VP9_SWITCHABLE_FILTERS
&& above_interp == VP9_SWITCHABLE_FILTERS)
pred_context = left_interp;
return left_interp;
else if (left_interp == VP9_SWITCHABLE_FILTERS &&
above_interp != VP9_SWITCHABLE_FILTERS)
return above_interp;
else if (left_interp != VP9_SWITCHABLE_FILTERS &&
above_interp == VP9_SWITCHABLE_FILTERS)
return left_interp;
else
pred_context = VP9_SWITCHABLE_FILTERS;
return pred_context;
return VP9_SWITCHABLE_FILTERS;
}
// Returns a context number for the given MB prediction signal
unsigned char vp9_get_pred_context_intra_inter(const VP9_COMMON *cm,
@ -188,36 +183,30 @@ unsigned char vp9_get_pred_context_comp_ref_p(const VP9_COMMON *cm,
} else { // inter/inter
int l_sg = left_mi->mbmi.ref_frame[1] <= INTRA_FRAME;
int a_sg = above_mi->mbmi.ref_frame[1] <= INTRA_FRAME;
MV_REFERENCE_FRAME vrfa =
a_sg ?
above_mi->mbmi.ref_frame[0] :
above_mi->mbmi.ref_frame[var_ref_idx];
MV_REFERENCE_FRAME vrfl =
l_sg ?
left_mi->mbmi.ref_frame[0] : left_mi->mbmi.ref_frame[var_ref_idx];
MV_REFERENCE_FRAME vrfa = a_sg ? above_mi->mbmi.ref_frame[0]
: above_mi->mbmi.ref_frame[var_ref_idx];
MV_REFERENCE_FRAME vrfl = l_sg ? left_mi->mbmi.ref_frame[0]
: left_mi->mbmi.ref_frame[var_ref_idx];
if (vrfa == vrfl && cm->comp_var_ref[1] == vrfa) {
pred_context = 0;
} else if (l_sg && a_sg) { // single/single
if ((vrfa == cm->comp_fixed_ref && vrfl == cm->comp_var_ref[0])
|| (vrfl == cm->comp_fixed_ref && vrfa == cm->comp_var_ref[0])) {
|| (vrfl == cm->comp_fixed_ref && vrfa == cm->comp_var_ref[0]))
pred_context = 4;
} else if (vrfa == vrfl) {
else if (vrfa == vrfl)
pred_context = 3;
} else {
else
pred_context = 1;
}
} else if (l_sg || a_sg) { // single/comp
MV_REFERENCE_FRAME vrfc = l_sg ? vrfa : vrfl;
MV_REFERENCE_FRAME rfs = a_sg ? vrfa : vrfl;
if (vrfc == cm->comp_var_ref[1] && rfs != cm->comp_var_ref[1]) {
if (vrfc == cm->comp_var_ref[1] && rfs != cm->comp_var_ref[1])
pred_context = 1;
} else if (rfs == cm->comp_var_ref[1] && vrfc != cm->comp_var_ref[1]) {
else if (rfs == cm->comp_var_ref[1] && vrfc != cm->comp_var_ref[1])
pred_context = 2;
} else {
else
pred_context = 4;
}
} else if (vrfa == vrfl) { // comp/comp
pred_context = 4;
} else {
@ -419,10 +408,9 @@ unsigned char vp9_get_pred_context_single_ref_p2(const VP9_COMMON *cm,
// Returns a context number for the given MB prediction signal
unsigned char vp9_get_pred_context_tx_size(const VP9_COMMON *cm,
const MACROBLOCKD *xd) {
int pred_context;
const MODE_INFO * const mi = xd->mode_info_context;
const MODE_INFO * const above_mi = mi - cm->mode_info_stride;
const MODE_INFO * const left_mi = mi - 1;
const MODE_INFO *const mi = xd->mode_info_context;
const MODE_INFO *const above_mi = mi - cm->mode_info_stride;
const MODE_INFO *const left_mi = mi - 1;
const int left_in_image = xd->left_available && left_mi->mbmi.mb_in_image;
const int above_in_image = xd->up_available && above_mi->mbmi.mb_in_image;
// Note:
@ -439,30 +427,30 @@ unsigned char vp9_get_pred_context_tx_size(const VP9_COMMON *cm,
max_tx_size = TX_16X16;
else
max_tx_size = TX_32X32;
above_context = left_context = max_tx_size;
if (above_in_image) {
above_context = (
above_mi->mbmi.mb_skip_coeff ? max_tx_size : above_mi->mbmi.txfm_size);
}
if (left_in_image) {
left_context = (
left_mi->mbmi.mb_skip_coeff ? max_tx_size : left_mi->mbmi.txfm_size);
}
if (!left_in_image) {
left_context = above_context;
}
if (!above_in_image) {
above_context = left_context;
}
pred_context = (above_context + left_context > max_tx_size);
return pred_context;
above_context = left_context = max_tx_size;
if (above_in_image)
above_context = above_mi->mbmi.mb_skip_coeff ? max_tx_size
: above_mi->mbmi.txfm_size;
if (left_in_image)
left_context = left_mi->mbmi.mb_skip_coeff ? max_tx_size
: left_mi->mbmi.txfm_size;
if (!left_in_image)
left_context = above_context;
if (!above_in_image)
above_context = left_context;
return above_context + left_context > max_tx_size;
}
// This function sets the status of the given prediction signal.
// I.e. is the predicted value for the given signal correct.
void vp9_set_pred_flag_mbskip(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize,
unsigned char pred_flag) {
unsigned char pred_flag) {
const int mis = xd->mode_info_stride;
const int bh = 1 << mi_height_log2(bsize);
const int bw = 1 << mi_width_log2(bsize);

View File

@ -18,50 +18,40 @@ int vp9_get_segment_id(VP9_COMMON *cm, const uint8_t *segment_ids,
BLOCK_SIZE_TYPE bsize, int mi_row, int mi_col);
static INLINE unsigned char vp9_get_pred_context_seg_id(const VP9_COMMON *cm,
const MACROBLOCKD *xd) {
int pred_context;
const MODE_INFO * const mi = xd->mode_info_context;
const MODE_INFO * const above_mi = mi - cm->mode_info_stride;
const MODE_INFO * const left_mi = mi - 1;
pred_context = above_mi->mbmi.seg_id_predicted;
if (xd->left_available)
pred_context += left_mi->mbmi.seg_id_predicted;
return pred_context;
static INLINE int vp9_get_pred_context_seg_id(const MACROBLOCKD *xd) {
const MODE_INFO *const mi = xd->mode_info_context;
const MB_MODE_INFO *const above_mbmi = &mi[-xd->mode_info_stride].mbmi;
const MB_MODE_INFO *const left_mbmi = &mi[-1].mbmi;
return above_mbmi->seg_id_predicted +
(xd->left_available ? left_mbmi->seg_id_predicted : 0);
}
static INLINE vp9_prob vp9_get_pred_prob_seg_id(const VP9_COMMON *cm,
const MACROBLOCKD *xd) {
const int pred_context = vp9_get_pred_context_seg_id(cm, xd);
return xd->seg.pred_probs[pred_context];
}
static INLINE unsigned char vp9_get_pred_flag_seg_id(
const MACROBLOCKD * const xd) {
return xd->mode_info_context->mbmi.seg_id_predicted;
static INLINE vp9_prob vp9_get_pred_prob_seg_id(const MACROBLOCKD *xd) {
return xd->seg.pred_probs[vp9_get_pred_context_seg_id(xd)];
}
void vp9_set_pred_flag_seg_id(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize,
unsigned char pred_flag);
unsigned char pred_flag);
static INLINE unsigned char vp9_get_pred_context_mbskip(const VP9_COMMON *cm,
const MACROBLOCKD *xd) {
int pred_context;
const MODE_INFO * const mi = xd->mode_info_context;
const MODE_INFO * const above_mi = mi - cm->mode_info_stride;
const MODE_INFO * const left_mi = mi - 1;
pred_context = above_mi->mbmi.mb_skip_coeff;
if (xd->left_available)
pred_context += left_mi->mbmi.mb_skip_coeff;
return pred_context;
static INLINE int vp9_get_pred_context_mbskip(const MACROBLOCKD *xd) {
const MODE_INFO *const mi = xd->mode_info_context;
const MB_MODE_INFO *const above_mbmi = &mi[-xd->mode_info_stride].mbmi;
const MB_MODE_INFO *const left_mbmi = &mi[-1].mbmi;
return above_mbmi->mb_skip_coeff +
(xd->left_available ? left_mbmi->mb_skip_coeff : 0);
}
static INLINE vp9_prob vp9_get_pred_prob_mbskip(const VP9_COMMON *cm,
const MACROBLOCKD *xd) {
const int pred_context = vp9_get_pred_context_mbskip(cm, xd);
return cm->fc.mbskip_probs[pred_context];
return cm->fc.mbskip_probs[vp9_get_pred_context_mbskip(xd)];
}
static INLINE unsigned char vp9_get_pred_flag_mbskip(
const MACROBLOCKD * const xd) {
static INLINE unsigned char vp9_get_pred_flag_mbskip(const MACROBLOCKD *xd) {
return xd->mode_info_context->mbmi.mb_skip_coeff;
}
void vp9_set_pred_flag_mbskip(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize,
unsigned char pred_flag);
@ -69,17 +59,17 @@ unsigned char vp9_get_pred_context_switchable_interp(const VP9_COMMON *cm,
const MACROBLOCKD *xd);
static INLINE const vp9_prob *vp9_get_pred_probs_switchable_interp(
const VP9_COMMON *cm, const MACROBLOCKD * xd) {
const VP9_COMMON *cm, const MACROBLOCKD *xd) {
const int pred_context = vp9_get_pred_context_switchable_interp(cm, xd);
return &cm->fc.switchable_interp_prob[pred_context][0];
}
unsigned char vp9_get_pred_context_intra_inter(const VP9_COMMON *cm,
const MACROBLOCKD *xd);
static INLINE vp9_prob vp9_get_pred_prob_intra_inter(const VP9_COMMON *cm,
const MACROBLOCKD *xd) {
const int pred_context = vp9_get_pred_context_intra_inter(cm, xd);
return cm->fc.intra_inter_prob[pred_context];
}

View File

@ -123,7 +123,7 @@ static uint8_t read_skip_coeff(VP9D_COMP *pbi, int segment_id, vp9_reader *r) {
MACROBLOCKD *const xd = &pbi->mb;
int skip_coeff = vp9_segfeature_active(&xd->seg, segment_id, SEG_LVL_SKIP);
if (!skip_coeff) {
const uint8_t ctx = vp9_get_pred_context_mbskip(cm, xd);
const int ctx = vp9_get_pred_context_mbskip(xd);
skip_coeff = vp9_read(r, vp9_get_pred_prob_mbskip(cm, xd));
cm->fc.mbskip_count[ctx][skip_coeff]++;
}
@ -329,16 +329,6 @@ static void read_ref_frame(VP9D_COMP *pbi, vp9_reader *r,
}
}
#ifdef VPX_MODE_COUNT
unsigned int vp9_mv_cont_count[5][4] = {
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 }
};
#endif
static void read_switchable_interp_probs(FRAME_CONTEXT *fc, vp9_reader *r) {
int i, j;
for (j = 0; j < VP9_SWITCHABLE_FILTERS + 1; ++j)
@ -379,9 +369,8 @@ static int read_inter_segment_id(VP9D_COMP *pbi, int mi_row, int mi_col,
if (!seg->update_map)
return pred_segment_id;
if (seg->temporal_update) {
const vp9_prob pred_prob = vp9_get_pred_prob_seg_id(cm, xd);
const vp9_prob pred_prob = vp9_get_pred_prob_seg_id(xd);
const int pred_flag = vp9_read(r, pred_prob);
vp9_set_pred_flag_seg_id(xd, bsize, pred_flag);
segment_id = pred_flag ? pred_segment_id
@ -577,34 +566,21 @@ static void read_inter_mode_info(VP9D_COMP *pbi, MODE_INFO *mi,
if (ref1 > 0)
read_mv(r, &secondmv.as_mv, &best_mv_second.as_mv, nmvc,
&cm->fc.NMVcount, xd->allow_high_precision_mv);
#ifdef VPX_MODE_COUNT
vp9_mv_cont_count[mv_contz][3]++;
#endif
break;
case NEARESTMV:
blockmv.as_int = nearest.as_int;
if (ref1 > 0)
secondmv.as_int = nearest_second.as_int;
#ifdef VPX_MODE_COUNT
vp9_mv_cont_count[mv_contz][0]++;
#endif
break;
case NEARMV:
blockmv.as_int = nearby.as_int;
if (ref1 > 0)
secondmv.as_int = nearby_second.as_int;
#ifdef VPX_MODE_COUNT
vp9_mv_cont_count[mv_contz][1]++;
#endif
break;
case ZEROMV:
blockmv.as_int = 0;
if (ref1 > 0)
secondmv.as_int = 0;
#ifdef VPX_MODE_COUNT
vp9_mv_cont_count[mv_contz][2]++;
#endif
break;
default:
assert(!"Invalid inter mode value");

View File

@ -225,14 +225,13 @@ static int write_skip_coeff(const VP9_COMP *cpi, int segment_id, MODE_INFO *m,
}
}
void vp9_update_skip_probs(VP9_COMP *cpi, vp9_writer *bc) {
VP9_COMMON *const pc = &cpi->common;
void vp9_update_skip_probs(VP9_COMP *cpi, vp9_writer *w) {
FRAME_CONTEXT *const fc = &cpi->common.fc;
int k;
for (k = 0; k < MBSKIP_CONTEXTS; ++k) {
vp9_cond_prob_diff_update(bc, &pc->fc.mbskip_probs[k],
VP9_MODE_UPDATE_PROB, pc->fc.mbskip_count[k]);
}
for (k = 0; k < MBSKIP_CONTEXTS; ++k)
vp9_cond_prob_diff_update(w, &fc->mbskip_probs[k],
VP9_MODE_UPDATE_PROB, fc->mbskip_count[k]);
}
static void write_intra_mode(vp9_writer *bc, int m, const vp9_prob *p) {
@ -426,13 +425,13 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, MODE_INFO *m,
if (seg->update_map) {
if (seg->temporal_update) {
unsigned char prediction_flag = vp9_get_pred_flag_seg_id(xd);
vp9_prob pred_prob = vp9_get_pred_prob_seg_id(pc, xd);
vp9_write(bc, prediction_flag, pred_prob);
if (!prediction_flag)
write_segment_id(bc, seg, mi->segment_id);
const int pred_flag = xd->mode_info_context->mbmi.seg_id_predicted;
vp9_prob pred_prob = vp9_get_pred_prob_seg_id(xd);
vp9_write(bc, pred_flag, pred_prob);
if (!pred_flag)
write_segment_id(bc, seg, segment_id);
} else {
write_segment_id(bc, seg, mi->segment_id);
write_segment_id(bc, seg, segment_id);
}
}

View File

@ -2345,11 +2345,11 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled,
}
if (xd->mode_info_context->mbmi.ref_frame[0] == INTRA_FRAME) {
vp9_tokenize_sb(cpi, xd, t, !output_enabled,
vp9_tokenize_sb(cpi, t, !output_enabled,
(bsize < BLOCK_SIZE_SB8X8) ? BLOCK_SIZE_SB8X8 : bsize);
} else if (!x->skip) {
vp9_encode_sb(cm, x, (bsize < BLOCK_SIZE_SB8X8) ? BLOCK_SIZE_SB8X8 : bsize);
vp9_tokenize_sb(cpi, xd, t, !output_enabled,
vp9_tokenize_sb(cpi, t, !output_enabled,
(bsize < BLOCK_SIZE_SB8X8) ? BLOCK_SIZE_SB8X8 : bsize);
} else {
int mb_skip_context = xd->left_available ? (mi - 1)->mbmi.mb_skip_coeff : 0;

View File

@ -141,7 +141,7 @@ static void count_segs(VP9_COMP *cpi, MODE_INFO *mi,
const int pred_segment_id = vp9_get_segment_id(cm, cm->last_frame_seg_map,
bsize, mi_row, mi_col);
const int pred_flag = pred_segment_id == segment_id;
const int pred_context = vp9_get_pred_context_seg_id(cm, xd);
const int pred_context = vp9_get_pred_context_seg_id(xd);
// Store the prediction status for this mb and update counts
// as appropriate

View File

@ -266,21 +266,19 @@ int vp9_sbuv_is_skippable(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize) {
return result;
}
void vp9_tokenize_sb(VP9_COMP *cpi,
MACROBLOCKD *xd,
TOKENEXTRA **t,
int dry_run, BLOCK_SIZE_TYPE bsize) {
VP9_COMMON * const cm = &cpi->common;
MB_MODE_INFO * const mbmi = &xd->mode_info_context->mbmi;
void vp9_tokenize_sb(VP9_COMP *cpi, TOKENEXTRA **t, int dry_run,
BLOCK_SIZE_TYPE bsize) {
VP9_COMMON *const cm = &cpi->common;
MACROBLOCKD *const xd = &cpi->mb.e_mbd;
MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi;
TOKENEXTRA *t_backup = *t;
const int mb_skip_context = vp9_get_pred_context_mbskip(cm, xd);
const int mb_skip_context = vp9_get_pred_context_mbskip(xd);
const int skip_inc = !vp9_segfeature_active(&xd->seg, mbmi->segment_id,
SEG_LVL_SKIP);
const TX_SIZE txfm_size = mbmi->txfm_size;
struct tokenize_b_args arg = { cpi, xd, t, txfm_size, dry_run };
mbmi->mb_skip_coeff = vp9_sb_is_skippable(xd, bsize);
if (mbmi->mb_skip_coeff) {
if (!dry_run)
cm->fc.mbskip_count[mb_skip_context][1] += skip_inc;

View File

@ -36,8 +36,8 @@ int vp9_sby_is_skippable(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize);
int vp9_sbuv_is_skippable(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize);
struct VP9_COMP;
void vp9_tokenize_sb(struct VP9_COMP *cpi, MACROBLOCKD *xd,
TOKENEXTRA **t, int dry_run, BLOCK_SIZE_TYPE bsize);
void vp9_tokenize_sb(struct VP9_COMP *cpi, TOKENEXTRA **t, int dry_run,
BLOCK_SIZE_TYPE bsize);
#ifdef ENTROPY_STATS
void init_context_counters();