Commit b732c1ea authored by Thomas Davies's avatar Thomas Davies

GLOBAL_MOTION: simplify parameter coding.

Remove deprecated tree coding for the global motion type.
Encoding with literals costs at most 0.8 bit per frame or
tile group for the identity type, and saves bits for other
types.

AWCY (objective-1-fast): PSNR +0.02%, PSNR-HVS/MSSSIM +0.03%.

Change-Id: I421a39fd8f830b2e40d105ea3c3688099a2b6d15
parent 1eb55ffc
......@@ -252,9 +252,6 @@ typedef struct frame_contexts {
#if CONFIG_FILTER_INTRA
aom_prob filter_intra_probs[PLANE_TYPES];
#endif // CONFIG_FILTER_INTRA
#if CONFIG_GLOBAL_MOTION
aom_prob global_motion_types_prob[GLOBAL_TRANS_TYPES - 1];
#endif // CONFIG_GLOBAL_MOTION
#if CONFIG_LOOP_RESTORATION
aom_prob switchable_restore_prob[RESTORE_SWITCHABLE_TYPES - 1];
#endif // CONFIG_LOOP_RESTORATION
......
......@@ -130,43 +130,6 @@ static const uint8_t log_in_base_2[] = {
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10
};
#if CONFIG_GLOBAL_MOTION
#if GLOBAL_TRANS_TYPES == 7 // All models
const aom_tree_index av1_global_motion_types_tree[TREE_SIZE(
GLOBAL_TRANS_TYPES)] = { -IDENTITY, 2, -TRANSLATION, 4,
-ROTZOOM, 6, -AFFINE, 8,
-HOMOGRAPHY, 10, -HORTRAPEZOID, -VERTRAPEZOID };
static const aom_prob default_global_motion_types_prob[GLOBAL_TRANS_TYPES - 1] =
{ 224, 128, 192, 192, 32, 128 };
#elif GLOBAL_TRANS_TYPES == 6 // Do not allow full homography
const aom_tree_index
av1_global_motion_types_tree[TREE_SIZE(GLOBAL_TRANS_TYPES)] = {
-IDENTITY, 2, -TRANSLATION, 4, -ROTZOOM, 6, -AFFINE, 8, -HORTRAPEZOID,
-VERTRAPEZOID
};
static const aom_prob default_global_motion_types_prob[GLOBAL_TRANS_TYPES - 1] =
{ 224, 128, 192, 192, 128 };
#elif GLOBAL_TRANS_TYPES == 4 // Upto Affine
const aom_tree_index av1_global_motion_types_tree[TREE_SIZE(
GLOBAL_TRANS_TYPES)] = { -IDENTITY, 2, -TRANSLATION, 4, -ROTZOOM, -AFFINE };
static const aom_prob default_global_motion_types_prob[GLOBAL_TRANS_TYPES - 1] =
{ 224, 128, 240 };
#elif GLOBAL_TRANS_TYPES == 3 // Upto rotation-zoom
const aom_tree_index av1_global_motion_types_tree[TREE_SIZE(
GLOBAL_TRANS_TYPES)] = { -IDENTITY, 2, -TRANSLATION, -ROTZOOM };
static const aom_prob default_global_motion_types_prob[GLOBAL_TRANS_TYPES - 1] =
{ 224, 128 };
#endif // GLOBAL_TRANS_TYPES
#endif // CONFIG_GLOBAL_MOTION
static INLINE int mv_class_base(MV_CLASS_TYPE c) {
return c ? CLASS0_SIZE << (c + 2) : 0;
}
......@@ -293,7 +256,4 @@ void av1_init_mv_probs(AV1_COMMON *cm) {
#if CONFIG_INTRABC
cm->fc->ndvc = default_nmv_context;
#endif // CONFIG_INTRABC
#if CONFIG_GLOBAL_MOTION
av1_copy(cm->fc->global_motion_types_prob, default_global_motion_types_prob);
#endif // CONFIG_GLOBAL_MOTION
}
......@@ -137,10 +137,6 @@ typedef enum {
void av1_inc_mv(const MV *mv, nmv_context_counts *mvctx,
MvSubpelPrecision precision);
#if CONFIG_GLOBAL_MOTION
extern const aom_tree_index
av1_global_motion_types_tree[TREE_SIZE(GLOBAL_TRANS_TYPES)];
#endif // CONFIG_GLOBAL_MOTION
#if !CONFIG_EC_ADAPT
void av1_set_mv_cdfs(nmv_context *ctx);
#endif
......
......@@ -88,6 +88,11 @@ typedef enum {
// GLOBAL_TRANS_TYPES 7 - up to full homography
#define GLOBAL_TRANS_TYPES 4
// First bit indicates whether using identity or not
// GLOBAL_TYPE_BITS=ceiling(log2(GLOBAL_TRANS_TYPES-1)) is the
// number of bits needed to cover the remaining possibilities
#define GLOBAL_TYPE_BITS (get_msb(2 * GLOBAL_TRANS_TYPES - 3))
typedef struct {
#if CONFIG_GLOBAL_MOTION
int global_warp_allowed;
......
......@@ -4790,10 +4790,9 @@ static void read_supertx_probs(FRAME_CONTEXT *fc, aom_reader *r) {
#if CONFIG_GLOBAL_MOTION
static void read_global_motion_params(WarpedMotionParams *params,
WarpedMotionParams *ref_params,
aom_prob *probs, aom_reader *r,
int allow_hp) {
TransformationType type =
aom_read_tree(r, av1_global_motion_types_tree, probs, ACCT_STR);
aom_reader *r, int allow_hp) {
TransformationType type = aom_read_bit(r, ACCT_STR);
if (type != IDENTITY) type += aom_read_literal(r, GLOBAL_TYPE_BITS, ACCT_STR);
int trans_bits;
int trans_dec_factor;
int trans_prec_diff;
......@@ -4878,9 +4877,9 @@ static void read_global_motion_params(WarpedMotionParams *params,
static void read_global_motion(AV1_COMMON *cm, aom_reader *r) {
int frame;
for (frame = LAST_FRAME; frame <= ALTREF_FRAME; ++frame) {
read_global_motion_params(
&cm->global_motion[frame], &cm->prev_frame->global_motion[frame],
cm->fc->global_motion_types_prob, r, cm->allow_high_precision_mv);
read_global_motion_params(&cm->global_motion[frame],
&cm->prev_frame->global_motion[frame], r,
cm->allow_high_precision_mv);
/*
printf("Dec Ref %d [%d/%d]: %d %d %d %d\n",
frame, cm->current_video_frame, cm->show_frame,
......
......@@ -103,9 +103,6 @@ static struct av1_token ext_tx_intra_encodings[EXT_TX_SETS_INTRA][TX_TYPES];
#else
static struct av1_token ext_tx_encodings[TX_TYPES];
#endif // CONFIG_EXT_TX
#if CONFIG_GLOBAL_MOTION
static struct av1_token global_motion_types_encodings[GLOBAL_TRANS_TYPES];
#endif // CONFIG_GLOBAL_MOTION
#if CONFIG_EXT_INTRA
#if CONFIG_INTRA_INTERP
static struct av1_token intra_filter_encodings[INTRA_FILTERS];
......@@ -178,10 +175,6 @@ void av1_encode_token_init(void) {
#if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
av1_tokens_from_tree(motion_mode_encodings, av1_motion_mode_tree);
#endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
#if CONFIG_GLOBAL_MOTION
av1_tokens_from_tree(global_motion_types_encodings,
av1_global_motion_types_tree);
#endif // CONFIG_GLOBAL_MOTION
#if CONFIG_LOOP_RESTORATION
av1_tokens_from_tree(switchable_restore_encodings,
av1_switchable_restore_tree);
......@@ -4704,13 +4697,13 @@ static void write_uncompressed_header(AV1_COMP *cpi,
#if CONFIG_GLOBAL_MOTION
static void write_global_motion_params(WarpedMotionParams *params,
WarpedMotionParams *ref_params,
aom_prob *probs, aom_writer *w,
int allow_hp) {
aom_writer *w, int allow_hp) {
TransformationType type = params->wmtype;
int trans_bits;
int trans_prec_diff;
av1_write_token(w, av1_global_motion_types_tree, probs,
&global_motion_types_encodings[type]);
aom_write_bit(w, type != IDENTITY);
if (type != IDENTITY) aom_write_literal(w, type - 1, GLOBAL_TYPE_BITS);
switch (type) {
case HOMOGRAPHY:
case HORTRAPEZOID:
......@@ -4776,9 +4769,9 @@ static void write_global_motion(AV1_COMP *cpi, aom_writer *w) {
AV1_COMMON *const cm = &cpi->common;
int frame;
for (frame = LAST_FRAME; frame <= ALTREF_FRAME; ++frame) {
write_global_motion_params(
&cm->global_motion[frame], &cm->prev_frame->global_motion[frame],
cm->fc->global_motion_types_prob, w, cm->allow_high_precision_mv);
write_global_motion_params(&cm->global_motion[frame],
&cm->prev_frame->global_motion[frame], w,
cm->allow_high_precision_mv);
/*
printf("Frame %d/%d: Enc Ref %d (used %d): %d %d %d %d\n",
cm->current_video_frame, cm->show_frame, frame,
......
......@@ -147,8 +147,9 @@ static void fill_mode_costs(AV1_COMP *cpi) {
av1_switchable_restore_tree);
#endif // CONFIG_LOOP_RESTORATION
#if CONFIG_GLOBAL_MOTION
av1_cost_tokens(cpi->gmtype_cost, fc->global_motion_types_prob,
av1_global_motion_types_tree);
for (i = 0; i < TRANS_TYPES; ++i)
cpi->gmtype_cost[i] = (1 + (i > 0 ? GLOBAL_TYPE_BITS : 0))
<< AV1_PROB_COST_SHIFT;
#endif // CONFIG_GLOBAL_MOTION
}
......
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