Commit c66f264d authored by Yaowu Xu's avatar Yaowu Xu Committed by Gerrit Code Review
Browse files

Merge "rans: Use symbol coding for motion vectors" into nextgenv2

parents 94df7ab1 3fc98e86
......@@ -11,7 +11,7 @@
#include "./aom_config.h"
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
#include <string.h>
#endif
......@@ -57,7 +57,7 @@ void aom_tree_merge_probs(const aom_tree_index *tree, const aom_prob *pre_probs,
tree_merge_probs_impl(0, tree, pre_probs, counts, probs);
}
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
typedef struct tree_node tree_node;
struct tree_node {
......@@ -86,7 +86,7 @@ static int tree_node_cmp(tree_node a, tree_node b) {
int i;
uint32_t pa;
uint32_t pb;
for (i = 0; i < OD_MINI(a.len, b.len) && a.probs[i] == b.probs[i]; i++) {
for (i = 0; i < AOMMIN(a.len, b.len) && a.probs[i] == b.probs[i]; i++) {
}
pa = tree_node_prob(a, i);
pb = tree_node_prob(b, i);
......
......@@ -96,7 +96,7 @@ static INLINE aom_prob mode_mv_merge_probs(aom_prob pre_prob,
void aom_tree_merge_probs(const aom_tree_index *tree, const aom_prob *pre_probs,
const unsigned int *counts, aom_prob *probs);
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
int tree_to_cdf(const aom_tree_index *tree, const aom_prob *probs,
aom_tree_index root, aom_cdf_prob *cdf, aom_tree_index *ind,
int *pth, int *len);
......
......@@ -43,21 +43,21 @@ const aom_tree_index av1_mv_fp_tree[TREE_SIZE(MV_FP_SIZE)] = { -0, 2, -1,
static const nmv_context default_nmv_context = {
{ 32, 64, 96 }, // joints
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
{ 0, 0, 0, 0 }, // joint_cdf is computed from joints in av1_init_mv_probs()
#endif
{ {
// Vertical component
128, // sign
{ 224, 144, 192, 168, 192, 176, 192, 198, 198, 245 }, // class
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
{ 0 }, // class_cdf is computed from class in av1_init_mv_probs()
#endif
{ 216 }, // class0
{ 136, 140, 148, 160, 176, 192, 224, 234, 234, 240 }, // bits
{ { 128, 128, 64 }, { 96, 112, 64 } }, // class0_fp
{ 64, 96, 64 }, // fp
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
{ { 0 }, { 0 } }, // class0_fp_cdf is computed in av1_init_mv_probs()
{ 0 }, // fp_cdf is computed from fp in av1_init_mv_probs()
#endif
......@@ -68,14 +68,14 @@ static const nmv_context default_nmv_context = {
// Horizontal component
128, // sign
{ 216, 128, 176, 160, 176, 176, 192, 198, 198, 208 }, // class
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
{ 0 }, // class_cdf is computed from class in av1_init_mv_probs()
#endif
{ 208 }, // class0
{ 136, 140, 148, 160, 176, 192, 224, 234, 234, 240 }, // bits
{ { 128, 128, 64 }, { 96, 112, 64 } }, // class0_fp
{ 64, 96, 64 }, // fp
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
{ { 0 }, { 0 } }, // class0_fp_cdf is computed in av1_init_mv_probs()
{ 0 }, // fp_cdf is computed from fp in av1_init_mv_probs()
#endif
......@@ -279,7 +279,7 @@ void av1_init_mv_probs(AV1_COMMON *cm) {
for (i = 0; i < NMV_CONTEXTS; ++i) cm->fc->nmvc[i] = default_nmv_context;
#else
cm->fc->nmvc = default_nmv_context;
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
{
int i, j;
av1_tree_to_cdf(av1_mv_joint_tree, cm->fc->nmvc.joints,
......
......@@ -85,14 +85,14 @@ extern const aom_tree_index av1_mv_fp_tree[];
typedef struct {
aom_prob sign;
aom_prob classes[MV_CLASSES - 1];
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
aom_cdf_prob class_cdf[MV_CLASSES];
#endif
aom_prob class0[CLASS0_SIZE - 1];
aom_prob bits[MV_OFFSET_BITS];
aom_prob class0_fp[CLASS0_SIZE][MV_FP_SIZE - 1];
aom_prob fp[MV_FP_SIZE - 1];
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
aom_cdf_prob class0_fp_cdf[CLASS0_SIZE][MV_FP_SIZE];
aom_cdf_prob fp_cdf[MV_FP_SIZE];
#endif
......@@ -102,7 +102,7 @@ typedef struct {
typedef struct {
aom_prob joints[MV_JOINTS - 1];
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
aom_cdf_prob joint_cdf[MV_JOINTS];
#endif
nmv_component comps[2];
......
......@@ -209,7 +209,7 @@ static void read_mv_probs(nmv_context *ctx, int allow_hp, aom_reader *r) {
int i, j;
update_mv_probs(ctx->joints, MV_JOINTS - 1, r);
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
av1_tree_to_cdf(av1_mv_joint_tree, ctx->joints, ctx->joint_cdf);
#endif
......@@ -219,7 +219,7 @@ static void read_mv_probs(nmv_context *ctx, int allow_hp, aom_reader *r) {
update_mv_probs(comp_ctx->classes, MV_CLASSES - 1, r);
update_mv_probs(comp_ctx->class0, CLASS0_SIZE - 1, r);
update_mv_probs(comp_ctx->bits, MV_OFFSET_BITS, r);
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
av1_tree_to_cdf(av1_mv_class_tree, comp_ctx->classes, comp_ctx->class_cdf);
#endif
}
......@@ -228,13 +228,13 @@ static void read_mv_probs(nmv_context *ctx, int allow_hp, aom_reader *r) {
nmv_component *const comp_ctx = &ctx->comps[i];
for (j = 0; j < CLASS0_SIZE; ++j) {
update_mv_probs(comp_ctx->class0_fp[j], MV_FP_SIZE - 1, r);
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
av1_tree_to_cdf(av1_mv_fp_tree, comp_ctx->class0_fp[j],
comp_ctx->class0_fp_cdf[j]);
#endif
}
update_mv_probs(comp_ctx->fp, MV_FP_SIZE - 1, r);
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
av1_tree_to_cdf(av1_mv_fp_tree, comp_ctx->fp, comp_ctx->fp_cdf);
#endif
}
......
......@@ -797,7 +797,7 @@ static int read_mv_component(aom_reader *r, const nmv_component *mvcomp,
int mag, d, fr, hp;
const int sign = aom_read(r, mvcomp->sign, ACCT_STR);
const int mv_class =
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
aom_read_symbol(r, mvcomp->class_cdf, MV_CLASSES, ACCT_STR);
#else
aom_read_tree(r, av1_mv_class_tree, mvcomp->classes, ACCT_STR);
......@@ -818,7 +818,7 @@ static int read_mv_component(aom_reader *r, const nmv_component *mvcomp,
}
// Fractional part
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
fr = aom_read_symbol(r, class0 ? mvcomp->class0_fp_cdf[d] : mvcomp->fp_cdf,
MV_FP_SIZE, ACCT_STR);
#else
......@@ -842,7 +842,7 @@ static INLINE void read_mv(aom_reader *r, MV *mv, const MV *ref,
const int use_hp = allow_hp && av1_use_mv_hp(ref);
MV diff = { 0, 0 };
joint_type =
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
(MV_JOINT_TYPE)aom_read_symbol(r, ctx->joint_cdf, MV_JOINTS, ACCT_STR);
#else
(MV_JOINT_TYPE)aom_read_tree(r, av1_mv_joint_tree, ctx->joints, ACCT_STR);
......
......@@ -46,7 +46,7 @@ static void encode_mv_component(aom_writer *w, int comp,
aom_write(w, sign, mvcomp->sign);
// Class
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
aom_write_symbol(w, mv_class, mvcomp->class_cdf, MV_CLASSES);
#else
av1_write_token(w, av1_mv_class_tree, mvcomp->classes,
......@@ -63,7 +63,7 @@ static void encode_mv_component(aom_writer *w, int comp,
}
// Fractional bits
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
aom_write_symbol(
w, fr, mv_class == MV_CLASS_0 ? mvcomp->class0_fp_cdf[d] : mvcomp->fp_cdf,
MV_FP_SIZE);
......@@ -204,7 +204,12 @@ void av1_write_nmv_probs(AV1_COMMON *cm, int usehp, aom_writer *w,
nmv_context *const mvc = &cm->fc->nmvc;
nmv_context_counts *const counts = nmv_counts;
#if !(CONFIG_DAALA_EC || CONFIG_RANS)
write_mv_update(av1_mv_joint_tree, mvc->joints, counts->joints, MV_JOINTS, w);
#if CONFIG_DAALA_EC || CONFIG_RANS
av1_tree_to_cdf(av1_mv_joint_tree, cm->fc->nmvc.joints,
cm->fc->nmvc.joint_cdf);
#endif
for (i = 0; i < 2; ++i) {
nmv_component *comp = &mvc->comps[i];
......@@ -213,7 +218,7 @@ void av1_write_nmv_probs(AV1_COMMON *cm, int usehp, aom_writer *w,
update_mv(w, comp_counts->sign, &comp->sign, MV_UPDATE_PROB);
write_mv_update(av1_mv_class_tree, comp->classes, comp_counts->classes,
MV_CLASSES, w);
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
av1_tree_to_cdf(av1_mv_class_tree, comp->classes, comp->class_cdf);
#endif
write_mv_update(av1_mv_class0_tree, comp->class0, comp_counts->class0,
......@@ -226,17 +231,18 @@ void av1_write_nmv_probs(AV1_COMMON *cm, int usehp, aom_writer *w,
for (j = 0; j < CLASS0_SIZE; ++j) {
write_mv_update(av1_mv_fp_tree, mvc->comps[i].class0_fp[j],
counts->comps[i].class0_fp[j], MV_FP_SIZE, w);
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
av1_tree_to_cdf(av1_mv_fp_tree, mvc->comps[i].class0_fp[j],
mvc->comps[i].class0_fp_cdf[j]);
#endif
}
write_mv_update(av1_mv_fp_tree, mvc->comps[i].fp, counts->comps[i].fp,
MV_FP_SIZE, w);
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
av1_tree_to_cdf(av1_mv_fp_tree, mvc->comps[i].fp, mvc->comps[i].fp_cdf);
#endif
}
#endif // !CONFIG_EC_ADAPT || !(CONFIG_DAALA_EC || CONFIG_RANS)
if (usehp) {
for (i = 0; i < 2; ++i) {
......@@ -259,7 +265,7 @@ void av1_encode_mv(AV1_COMP *cpi, aom_writer *w, const MV *mv, const MV *ref,
#if CONFIG_REF_MV
(void)is_compound;
#endif
#if CONFIG_DAALA_EC
#if CONFIG_DAALA_EC || CONFIG_RANS
aom_write_symbol(w, j, mvctx->joint_cdf, MV_JOINTS);
#else
av1_write_token(w, av1_mv_joint_tree, mvctx->joints, &mv_joint_encodings[j]);
......
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