Commit 03be30ba authored by Debargha Mukherjee's avatar Debargha Mukherjee

Some refactoring to support warped motion mode

Change-Id: I15d54a3ae48b2b33082668116792c6595bdb3ddb
parent f59bf76e
......@@ -202,11 +202,7 @@ typedef struct {
int interinter_wedge_index;
int interinter_wedge_sign;
#endif // CONFIG_EXT_INTER
#if CONFIG_OBMC
int8_t obmc;
#endif // CONFIG_OBMC
MOTION_VARIATION motion_variation;
int_mv mv[2];
int_mv pred_mv[2];
#if CONFIG_REF_MV
......@@ -710,8 +706,8 @@ static INLINE int is_interintra_pred(const MB_MODE_INFO *mbmi) {
}
#endif // CONFIG_EXT_INTER
#if CONFIG_OBMC
static INLINE int is_obmc_allowed(const MB_MODE_INFO *mbmi) {
#if CONFIG_OBMC || CONFIG_WARPED_MOTION
static INLINE int is_motvar_allowed(const MB_MODE_INFO *mbmi) {
#if CONFIG_EXT_INTER
return (mbmi->sb_type >= BLOCK_8X8 && mbmi->ref_frame[1] != INTRA_FRAME);
#else
......@@ -719,10 +715,12 @@ static INLINE int is_obmc_allowed(const MB_MODE_INFO *mbmi) {
#endif // CONFIG_EXT_INTER
}
#if CONFIG_OBMC
static INLINE int is_neighbor_overlappable(const MB_MODE_INFO *mbmi) {
return (is_inter_block(mbmi));
}
#endif // CONFIG_OBMC
#endif // CONFIG_OBMC || CONFIG_WARPED_MOTION
#ifdef __cplusplus
} // extern "C"
......
......@@ -295,15 +295,58 @@ static const vpx_prob default_wedge_interinter_prob[BLOCK_SIZES] = {
};
#endif // CONFIG_EXT_INTER
#if CONFIG_OBMC
static const vpx_prob default_obmc_prob[BLOCK_SIZES] = {
255, 255, 255, 151, 153, 144, 178, 165, 160, 207, 195, 168, 244,
// Change this section appropriately once warped motion is supported
#if CONFIG_OBMC && !CONFIG_WARPED_MOTION
const vpx_tree_index vp10_motvar_tree[TREE_SIZE(MOTION_VARIATIONS)] = {
-SIMPLE_TRANSLATION, -OBMC_CAUSAL
};
static
const vpx_prob default_motvar_prob[BLOCK_SIZES][MOTION_VARIATIONS - 1] = {
{255},
{255}, {255}, {151},
{153}, {144}, {178},
{165}, {160}, {207},
{195}, {168}, {244},
#if CONFIG_EXT_PARTITION
{252}, {252}, {252},
#endif // CONFIG_EXT_PARTITION
};
#elif !CONFIG_OBMC && CONFIG_WARPED_MOTION
const vpx_tree_index vp10_motvar_tree[TREE_SIZE(MOTION_VARIATIONS)] = {
-SIMPLE_TRANSLATION, -WARPED_CAUSAL
};
static
const vpx_prob default_motvar_prob[BLOCK_SIZES][MOTION_VARIATIONS - 1] = {
{255},
{255}, {255}, {151},
{153}, {144}, {178},
{165}, {160}, {207},
{195}, {168}, {244},
#if CONFIG_EXT_PARTITION
{252}, {252}, {252},
#endif // CONFIG_EXT_PARTITION
};
#elif CONFIG_OBMC && CONFIG_WARPED_MOTION
const vpx_tree_index vp10_motvar_tree[TREE_SIZE(MOTION_VARIATIONS)] = {
-SIMPLE_TRANSLATION, 2,
-OBMC_CAUSAL, -WARPED_CAUSAL,
};
static
const vpx_prob default_motvar_prob[BLOCK_SIZES][MOTION_VARIATIONS - 1] = {
{255, 200},
{255, 200}, {255, 200}, {151, 200},
{153, 200}, {144, 200}, {178, 200},
{165, 200}, {160, 200}, {207, 200},
{195, 200}, {168, 200}, {244, 200},
#if CONFIG_EXT_PARTITION
// TODO(debargha) What are the correct values for these?
192, 192, 192
{252, 200}, {252, 200}, {252, 200},
#endif // CONFIG_EXT_PARTITION
};
#endif // CONFIG_OBMC
#endif // CONFIG_OBMC || !CONFIG_WARPED_MOTION
/* Array indices are identical to previously-existing INTRAMODECONTEXTNODES. */
const vpx_tree_index vp10_intra_mode_tree[TREE_SIZE(INTRA_MODES)] = {
......@@ -1287,9 +1330,9 @@ static void init_mode_probs(FRAME_CONTEXT *fc) {
#endif // CONFIG_EXT_INTER
#endif // CONFIG_REF_MV
vp10_copy(fc->inter_mode_probs, default_inter_mode_probs);
#if CONFIG_OBMC
vp10_copy(fc->obmc_prob, default_obmc_prob);
#endif // CONFIG_OBMC
#if CONFIG_OBMC || CONFIG_WARPED_MOTION
vp10_copy(fc->motvar_prob, default_motvar_prob);
#endif // CONFIG_OBMC || CONFIG_WARPED_MOTION
#if CONFIG_EXT_INTER
vp10_copy(fc->inter_compound_mode_probs, default_inter_compound_mode_probs);
vp10_copy(fc->interintra_prob, default_interintra_prob);
......@@ -1381,14 +1424,14 @@ void vp10_adapt_inter_frame_probs(VP10_COMMON *cm) {
#else
for (i = 0; i < INTER_MODE_CONTEXTS; i++)
vpx_tree_merge_probs(vp10_inter_mode_tree, pre_fc->inter_mode_probs[i],
counts->inter_mode[i], fc->inter_mode_probs[i]);
counts->inter_mode[i], fc->inter_mode_probs[i]);
#endif
#if CONFIG_OBMC
#if CONFIG_OBMC || CONFIG_WARPED_MOTION
for (i = BLOCK_8X8; i < BLOCK_SIZES; ++i)
fc->obmc_prob[i] = vp10_mode_mv_merge_probs(pre_fc->obmc_prob[i],
counts->obmc[i]);
#endif // CONFIG_OBMC
vpx_tree_merge_probs(vp10_motvar_tree, pre_fc->motvar_prob[i],
counts->motvar[i], fc->motvar_prob[i]);
#endif // CONFIG_OBMC || CONFIG_WARPED_MOTION
#if CONFIG_SUPERTX
for (i = 0; i < PARTITION_SUPERTX_CONTEXTS; ++i) {
......
......@@ -79,9 +79,9 @@ typedef struct frame_contexts {
vpx_prob wedge_interintra_prob[BLOCK_SIZES];
vpx_prob wedge_interinter_prob[BLOCK_SIZES];
#endif // CONFIG_EXT_INTER
#if CONFIG_OBMC
vpx_prob obmc_prob[BLOCK_SIZES];
#endif // CONFIG_OBMC
#if CONFIG_OBMC || CONFIG_WARPED_MOTION
vpx_prob motvar_prob[BLOCK_SIZES][MOTION_VARIATIONS - 1];
#endif // CONFIG_OBMC || CONFIG_WARPED_MOTION
vpx_prob intra_inter_prob[INTRA_INTER_CONTEXTS];
vpx_prob comp_inter_prob[COMP_INTER_CONTEXTS];
vpx_prob single_ref_prob[REF_CONTEXTS][SINGLE_REFS-1];
......@@ -154,9 +154,9 @@ typedef struct FRAME_COUNTS {
unsigned int wedge_interintra[BLOCK_SIZES][2];
unsigned int wedge_interinter[BLOCK_SIZES][2];
#endif // CONFIG_EXT_INTER
#if CONFIG_OBMC
unsigned int obmc[BLOCK_SIZES][2];
#endif // CONFIG_OBMC
#if CONFIG_OBMC || CONFIG_WARPED_MOTION
unsigned int motvar[BLOCK_SIZES][MOTION_VARIATIONS];
#endif // CONFIG_OBMC || CONFIG_WARPED_MOTION
unsigned int intra_inter[INTRA_INTER_CONTEXTS][2];
unsigned int comp_inter[COMP_INTER_CONTEXTS][2];
unsigned int single_ref[REF_CONTEXTS][SINGLE_REFS-1][2];
......@@ -242,6 +242,9 @@ extern const vpx_tree_index
extern const vpx_tree_index
vp10_ext_tx_tree[TREE_SIZE(TX_TYPES)];
#endif // CONFIG_EXT_TX
#if CONFIG_OBMC || CONFIG_WARPED_MOTION
extern const vpx_tree_index vp10_motvar_tree[TREE_SIZE(MOTION_VARIATIONS)];
#endif // CONFIG_OBMC || CONFIG_WARPED_MOTION
void vp10_setup_past_independence(struct VP10Common *cm);
......
......@@ -281,6 +281,17 @@ typedef uint8_t PREDICTION_MODE;
#define INTRA_MODES (TM_PRED + 1)
typedef enum {
SIMPLE_TRANSLATION = 0,
#if CONFIG_OBMC
OBMC_CAUSAL, // 2-sided OBMC
#endif // CONFIG_OBMC
#if CONFIG_WARPED_MOTION
WARPED_CAUSAL, // 2-sided WARPED
#endif // CONFIG_WARPED_MOTION
MOTION_VARIATIONS
} MOTION_VARIATION;
#if CONFIG_EXT_INTER
typedef enum {
II_DC_PRED = 0,
......
......@@ -339,7 +339,6 @@ static const uint8_t *get_wedge_mask(int wedge_index,
return wedge_params_lookup[bsize].masks[neg][wedge_index];
}
const uint8_t *vp10_get_soft_mask(int wedge_index,
int wedge_sign,
BLOCK_SIZE sb_type,
......
......@@ -1319,7 +1319,7 @@ static void decode_block(VP10Decoder *const pbi, MACROBLOCKD *const xd,
vp10_build_inter_predictors_sb(xd, mi_row, mi_col,
VPXMAX(bsize, BLOCK_8X8));
#if CONFIG_OBMC
if (mbmi->obmc) {
if (mbmi->motion_variation == OBMC_CAUSAL) {
#if CONFIG_VP9_HIGHBITDEPTH
DECLARE_ALIGNED(16, uint8_t,
tmp_buf1[2 * MAX_MB_PLANE * MAX_SB_SQUARE]);
......@@ -3544,10 +3544,12 @@ static int read_compressed_header(VP10Decoder *pbi, const uint8_t *data,
}
#endif // CONFIG_EXT_INTER
#if CONFIG_OBMC
for (i = BLOCK_8X8; i < BLOCK_SIZES; ++i)
vp10_diff_update_prob(&r, &fc->obmc_prob[i]);
#endif // CONFIG_OBMC
#if CONFIG_OBMC || CONFIG_WARPED_MOTION
for (i = BLOCK_8X8; i < BLOCK_SIZES; ++i) {
for (j = 0; j < MOTION_VARIATIONS - 1; ++j)
vp10_diff_update_prob(&r, &fc->motvar_prob[i][j]);
}
#endif // CONFIG_OBMC || CONFIG_WARPED_MOTION
if (cm->interp_filter == SWITCHABLE)
read_switchable_interp_probs(fc, &r);
......@@ -3615,10 +3617,10 @@ static void debug_check_frame_counts(const VP10_COMMON *const cm) {
assert(!memcmp(cm->counts.wedge_interinter, zero_counts.wedge_interinter,
sizeof(cm->counts.wedge_interinter)));
#endif // CONFIG_EXT_INTER
#if CONFIG_OBMC
assert(!memcmp(cm->counts.obmc, zero_counts.obmc,
sizeof(cm->counts.obmc)));
#endif // CONFIG_OBMC
#if CONFIG_OBMC || CONFIG_WARPED_MOTION
assert(!memcmp(cm->counts.motvar, zero_counts.motvar,
sizeof(cm->counts.motvar)));
#endif // CONFIG_OBMC || CONFIG_WARPED_MOTION
assert(!memcmp(cm->counts.intra_inter, zero_counts.intra_inter,
sizeof(cm->counts.intra_inter)));
assert(!memcmp(cm->counts.comp_inter, zero_counts.comp_inter,
......
......@@ -883,23 +883,24 @@ static void read_ref_frames(VP10_COMMON *const cm, MACROBLOCKD *const xd,
}
#if CONFIG_OBMC
static int read_is_obmc_block(VP10_COMMON *const cm, MACROBLOCKD *const xd,
vp10_reader *r) {
#if CONFIG_OBMC || CONFIG_WARPED_MOTION
static MOTION_VARIATION read_motvar_block(
VP10_COMMON *const cm, MACROBLOCKD *const xd, vp10_reader *r) {
BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type;
FRAME_COUNTS *counts = xd->counts;
int is_obmc;
MOTION_VARIATION motvar;
if (is_obmc_allowed(&xd->mi[0]->mbmi)) {
is_obmc = vp10_read(r, cm->fc->obmc_prob[bsize]);
if (is_motvar_allowed(&xd->mi[0]->mbmi)) {
motvar = (MOTION_VARIATION)
vp10_read_tree(r, vp10_motvar_tree, cm->fc->motvar_prob[bsize]);
if (counts)
++counts->obmc[bsize][is_obmc];
return is_obmc;
++counts->motvar[bsize][motvar];
return motvar;
} else {
return 0;
return SIMPLE_TRANSLATION;
}
}
#endif // CONFIG_OBMC
#endif // CONFIG_OBMC || CONFIG_WARPED_MOTION
static INLINE INTERP_FILTER read_interp_filter(
VP10_COMMON *const cm, MACROBLOCKD *const xd,
......@@ -1599,24 +1600,25 @@ static void read_inter_block_mode_info(VP10Decoder *const pbi,
}
#endif // CONFIG_EXT_INTER
#if CONFIG_OBMC
mbmi->obmc = 0;
#if CONFIG_OBMC || CONFIG_WARPED_MOTION
mbmi->motion_variation = SIMPLE_TRANSLATION;
#if CONFIG_SUPERTX
if (!supertx_enabled)
#endif // CONFIG_SUPERTX
#if CONFIG_EXT_INTER
if (mbmi->ref_frame[1] != INTRA_FRAME)
#endif // CONFIG_EXT_INTER
mbmi->obmc = read_is_obmc_block(cm, xd, r);
#endif // CONFIG_OBMC
mbmi->motion_variation = read_motvar_block(cm, xd, r);
#endif // CONFIG_OBMC || CONFIG_WARPED_MOTION
#if CONFIG_EXT_INTER
mbmi->use_wedge_interinter = 0;
if (cm->reference_mode != SINGLE_REFERENCE &&
is_inter_compound_mode(mbmi->mode) &&
#if CONFIG_OBMC
!(is_obmc_allowed(mbmi) && mbmi->obmc) &&
#endif // CONFIG_OBMC
#if CONFIG_OBMC || CONFIG_WARPED_MOTION
!(is_motvar_allowed(mbmi) &&
mbmi->motion_variation != SIMPLE_TRANSLATION) &&
#endif // CONFIG_OBMC || CONFIG_WARPED_MOTION
is_interinter_wedge_used(bsize)) {
mbmi->use_wedge_interinter =
vp10_read(r, cm->fc->wedge_interinter_prob[bsize]);
......
......@@ -117,6 +117,9 @@ static struct vp10_token intra_filter_encodings[INTRA_FILTERS];
#if CONFIG_EXT_INTER
static struct vp10_token interintra_mode_encodings[INTERINTRA_MODES];
#endif // CONFIG_EXT_INTER
#if CONFIG_OBMC || CONFIG_WARPED_MOTION
static struct vp10_token motvar_encodings[MOTION_VARIATIONS];
#endif // CONFIG_OBMC || CONFIG_WARPED_MOTION
void vp10_encode_token_init() {
#if CONFIG_EXT_TX
......@@ -136,6 +139,9 @@ void vp10_encode_token_init() {
#if CONFIG_EXT_INTER
vp10_tokens_from_tree(interintra_mode_encodings, vp10_interintra_mode_tree);
#endif // CONFIG_EXT_INTER
#if CONFIG_OBMC || CONFIG_WARPED_MOTION
vp10_tokens_from_tree(motvar_encodings, vp10_motvar_tree);
#endif // CONFIG_OBMC || CONFIG_WARPED_MOTION
}
static void write_intra_mode(vp10_writer *w, PREDICTION_MODE mode,
......@@ -1370,22 +1376,24 @@ static void pack_inter_mode_mvs(VP10_COMP *cpi, const MODE_INFO *mi,
}
#endif // CONFIG_EXT_INTER
#if CONFIG_OBMC
#if CONFIG_OBMC || CONFIG_WARPED_MOTION
#if CONFIG_SUPERTX
if (!supertx_enabled)
#endif // CONFIG_SUPERTX
#if CONFIG_EXT_INTER
if (mbmi->ref_frame[1] != INTRA_FRAME)
#endif // CONFIG_EXT_INTER
if (is_obmc_allowed(mbmi))
vp10_write(w, mbmi->obmc, cm->fc->obmc_prob[bsize]);
#endif // CONFIG_OBMC
if (is_motvar_allowed(mbmi))
vp10_write_token(w, vp10_motvar_tree, cm->fc->motvar_prob[bsize],
&motvar_encodings[mbmi->motion_variation]);
#endif // CONFIG_OBMC || CONFIG_WARPED_MOTION
#if CONFIG_EXT_INTER
if (cpi->common.reference_mode != SINGLE_REFERENCE &&
is_inter_compound_mode(mbmi->mode) &&
#if CONFIG_OBMC
!(is_obmc_allowed(mbmi) && mbmi->obmc) &&
!(is_motvar_allowed(mbmi) &&
mbmi->motion_variation != SIMPLE_TRANSLATION) &&
#endif // CONFIG_OBMC
is_interinter_wedge_used(bsize)) {
vp10_write(w, mbmi->use_wedge_interinter,
......@@ -3283,11 +3291,11 @@ static uint32_t write_compressed_header(VP10_COMP *cpi, uint8_t *data) {
}
#endif // CONFIG_EXT_INTER
#if CONFIG_OBMC
#if CONFIG_OBMC || CONFIG_WARPED_MOTION
for (i = BLOCK_8X8; i < BLOCK_SIZES; ++i)
vp10_cond_prob_diff_update(header_bc, &fc->obmc_prob[i],
counts->obmc[i]);
#endif // CONFIG_OBMC
prob_diff_update(vp10_motvar_tree, fc->motvar_prob[i],
counts->motvar[i], MOTION_VARIATIONS, header_bc);
#endif // CONFIG_OBMC || CONFIG_WARPED_MOTION
if (cm->interp_filter == SWITCHABLE)
update_switchable_interp_probs(cm, header_bc, counts);
......
......@@ -1337,10 +1337,8 @@ static void update_state_supertx(VP10_COMP *cpi, ThreadData *td,
mbmi->inter_tx_size[idy][idx] = mbmi->tx_size;
}
#endif // CONFIG_VAR_TX
#if CONFIG_OBMC
// Turn OBMC off for supertx
mbmi->obmc = 0;
#endif // CONFIG_OBMC
// Turn motion variation off for supertx
mbmi->motion_variation = SIMPLE_TRANSLATION;
if (!output_enabled)
return;
......@@ -1966,23 +1964,24 @@ static void update_stats(VP10_COMMON *cm, ThreadData *td
}
#endif // CONFIG_EXT_INTER
#if CONFIG_OBMC
#if CONFIG_OBMC || CONFIG_WARPED_MOTION
#if CONFIG_SUPERTX
if (!supertx_enabled)
#endif // CONFIG_SUPERTX
#if CONFIG_EXT_INTER
if (mbmi->ref_frame[1] != INTRA_FRAME)
#endif // CONFIG_EXT_INTER
if (is_obmc_allowed(mbmi))
counts->obmc[mbmi->sb_type][mbmi->obmc]++;
#endif // CONFIG_OBMC
if (is_motvar_allowed(mbmi))
counts->motvar[mbmi->sb_type][mbmi->motion_variation]++;
#endif // CONFIG_OBMC || CONFIG_WARPED_MOTION
#if CONFIG_EXT_INTER
if (cm->reference_mode != SINGLE_REFERENCE &&
is_inter_compound_mode(mbmi->mode) &&
#if CONFIG_OBMC
!(is_obmc_allowed(mbmi) && mbmi->obmc) &&
#endif // CONFIG_OBMC
#if CONFIG_OBMC || CONFIG_WARPED_MOTION
!(is_motvar_allowed(mbmi) &&
mbmi->motion_variation != SIMPLE_TRANSLATION) &&
#endif // CONFIG_OBMC || CONFIG_WARPED_MOTION
is_interinter_wedge_used(bsize)) {
counts->wedge_interinter[bsize][mbmi->use_wedge_interinter]++;
}
......@@ -5034,7 +5033,7 @@ static void encode_superblock(VP10_COMP *cpi, ThreadData *td,
VPXMAX(bsize, BLOCK_8X8));
#if CONFIG_OBMC
if (mbmi->obmc) {
if (mbmi->motion_variation == OBMC_CAUSAL) {
#if CONFIG_VP9_HIGHBITDEPTH
DECLARE_ALIGNED(16, uint8_t, tmp_buf1[2 * MAX_MB_PLANE * MAX_SB_SQUARE]);
DECLARE_ALIGNED(16, uint8_t, tmp_buf2[2 * MAX_MB_PLANE * MAX_SB_SQUARE]);
......
......@@ -527,9 +527,9 @@ typedef struct VP10_COMP {
[INTER_COMPOUND_MODES];
unsigned int interintra_mode_cost[BLOCK_SIZE_GROUPS][INTERINTRA_MODES];
#endif // CONFIG_EXT_INTER
#if CONFIG_OBMC
int obmc_cost[BLOCK_SIZES][2];
#endif // CONFIG_OBMC
#if CONFIG_OBMC || CONFIG_WARPED_MOTION
int motvar_cost[BLOCK_SIZES][MOTION_VARIATIONS];
#endif // CONFIG_OBMC || CONFIG_WARPED_MOTION
int intra_uv_mode_cost[INTRA_MODES][INTRA_MODES];
int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES];
int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS];
......
......@@ -472,12 +472,12 @@ void vp10_initialize_rd_consts(VP10_COMP *cpi) {
cm->fc->interintra_mode_prob[i],
vp10_interintra_mode_tree);
#endif // CONFIG_EXT_INTER
#if CONFIG_OBMC
#if CONFIG_OBMC || CONFIG_WARPED_MOTION
for (i = BLOCK_8X8; i < BLOCK_SIZES; i++) {
cpi->obmc_cost[i][0] = vp10_cost_bit(cm->fc->obmc_prob[i], 0);
cpi->obmc_cost[i][1] = vp10_cost_bit(cm->fc->obmc_prob[i], 1);
vp10_cost_tokens((int *)cpi->motvar_cost[i],
cm->fc->motvar_prob[i], vp10_motvar_tree);
}
#endif // CONFIG_OBMC
#endif // CONFIG_OBMC || CONFIG_WARPED_MOTION
}
}
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment