blob: 8d011ea40486cc609214819d2cb6cd629396823e [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Yaowu Xuc27fc142016-08-22 16:08:15 -070010 */
11
12#include "av1/common/onyxc_int.h"
13#include "av1/common/entropymv.h"
14
15// Integer pel reference mv threshold for use of high-precision 1/8 mv
16#define COMPANDED_MVREF_THRESH 8
17
Yaowu Xuf883b422016-08-30 14:01:10 -070018const aom_tree_index av1_mv_joint_tree[TREE_SIZE(MV_JOINTS)] = {
Yaowu Xuc27fc142016-08-22 16:08:15 -070019 -MV_JOINT_ZERO, 2, -MV_JOINT_HNZVZ, 4, -MV_JOINT_HZVNZ, -MV_JOINT_HNZVNZ
20};
21
22/* clang-format off */
Yaowu Xuf883b422016-08-30 14:01:10 -070023const aom_tree_index av1_mv_class_tree[TREE_SIZE(MV_CLASSES)] = {
Yaowu Xuc27fc142016-08-22 16:08:15 -070024 -MV_CLASS_0, 2,
25 -MV_CLASS_1, 4,
26 6, 8,
27 -MV_CLASS_2, -MV_CLASS_3,
28 10, 12,
29 -MV_CLASS_4, -MV_CLASS_5,
30 -MV_CLASS_6, 14,
31 16, 18,
32 -MV_CLASS_7, -MV_CLASS_8,
33 -MV_CLASS_9, -MV_CLASS_10,
34};
35/* clang-format on */
36
Yaowu Xuf883b422016-08-30 14:01:10 -070037const aom_tree_index av1_mv_class0_tree[TREE_SIZE(CLASS0_SIZE)] = {
Yaowu Xuc27fc142016-08-22 16:08:15 -070038 -0, -1,
39};
40
Yaowu Xuf883b422016-08-30 14:01:10 -070041const aom_tree_index av1_mv_fp_tree[TREE_SIZE(MV_FP_SIZE)] = { -0, 2, -1,
42 4, -2, -3 };
Yaowu Xuc27fc142016-08-22 16:08:15 -070043
44static const nmv_context default_nmv_context = {
Nathan E. Egge5f7fd7a2016-09-08 11:22:03 -040045 { 32, 64, 96 }, // joints
Alex Converseaca9feb2016-10-10 11:08:10 -070046#if CONFIG_EC_MULTISYMBOL
Thomas Davies05fdc392017-02-22 14:15:39 +000047 { 4096, 11264, 19328, 32768, 0 }, // joint_cdf
Nathan E. Egge5f7fd7a2016-09-08 11:22:03 -040048#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -070049 { {
50 // Vertical component
51 128, // sign
52 { 224, 144, 192, 168, 192, 176, 192, 198, 198, 245 }, // class
Alex Converseaca9feb2016-10-10 11:08:10 -070053#if CONFIG_EC_MULTISYMBOL
Thomas Davies05fdc392017-02-22 14:15:39 +000054 { 28672, 30976, 31858, 32320, 32551, 32656, 32740, 32757, 32762, 32767,
55 32768, 0 }, // class_cdf
Nathan E. Egged7b893c2016-09-08 15:08:48 -040056#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -070057 { 216 }, // class0
58 { 136, 140, 148, 160, 176, 192, 224, 234, 234, 240 }, // bits
59 { { 128, 128, 64 }, { 96, 112, 64 } }, // class0_fp
60 { 64, 96, 64 }, // fp
Alex Converseaca9feb2016-10-10 11:08:10 -070061#if CONFIG_EC_MULTISYMBOL
Thomas Davies05fdc392017-02-22 14:15:39 +000062 { { 16384, 24576, 26624, 32768, 0 },
63 { 12288, 21248, 24128, 32768, 0 } }, // class0_fp_cdf
64 { 8192, 17408, 21248, 32768, 0 }, // fp_cdf
Nathan E. Egge5f34b612016-09-08 15:59:53 -040065#endif
Angie Chianga1a753c2016-10-21 17:13:59 -070066 160, // class0_hp bit
67 128, // hp
Yaowu Xuc27fc142016-08-22 16:08:15 -070068 },
69 {
70 // Horizontal component
71 128, // sign
72 { 216, 128, 176, 160, 176, 176, 192, 198, 198, 208 }, // class
Alex Converseaca9feb2016-10-10 11:08:10 -070073#if CONFIG_EC_MULTISYMBOL
Thomas Davies05fdc392017-02-22 14:15:39 +000074 { 28672, 30976, 31858, 32320, 32551, 32656, 32740, 32757, 32762, 32767,
75 32768, 0 }, // class_cdf
Nathan E. Egged7b893c2016-09-08 15:08:48 -040076#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -070077 { 208 }, // class0
78 { 136, 140, 148, 160, 176, 192, 224, 234, 234, 240 }, // bits
79 { { 128, 128, 64 }, { 96, 112, 64 } }, // class0_fp
80 { 64, 96, 64 }, // fp
Alex Converseaca9feb2016-10-10 11:08:10 -070081#if CONFIG_EC_MULTISYMBOL
Thomas Davies05fdc392017-02-22 14:15:39 +000082 { { 16384, 24576, 26624, 32768, 0 },
83 { 12288, 21248, 24128, 32768, 0 } }, // class0_fp_cdf
84 { 8192, 17408, 21248, 32768, 0 }, // fp_cdf
Nathan E. Egge5f34b612016-09-08 15:59:53 -040085#endif
Angie Chianga1a753c2016-10-21 17:13:59 -070086 160, // class0_hp bit
87 128, // hp
Yaowu Xuc27fc142016-08-22 16:08:15 -070088 } },
89};
90
91static const uint8_t log_in_base_2[] = {
92 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
93 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
94 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
95 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
96 6, 6, 6, 6, 6, 6, 6, 6, 6,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 9,
122 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
123 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
124 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
125 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
126 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
127 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
128 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
129 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
130 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
131 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10
132};
133
134#if CONFIG_GLOBAL_MOTION
Debargha Mukherjee5dfa9302017-02-10 05:00:08 -0800135#if GLOBAL_TRANS_TYPES == 7 // All models
Debargha Mukherjee3fb33f02016-11-12 10:43:50 -0800136const aom_tree_index av1_global_motion_types_tree[TREE_SIZE(
Debargha Mukherjee5dfa9302017-02-10 05:00:08 -0800137 GLOBAL_TRANS_TYPES)] = { -IDENTITY, 2, -TRANSLATION, 4,
138 -ROTZOOM, 6, -AFFINE, 8,
139 -HOMOGRAPHY, 10, -HORTRAPEZOID, -VERTRAPEZOID };
Debargha Mukherjee3fb33f02016-11-12 10:43:50 -0800140
141static const aom_prob default_global_motion_types_prob[GLOBAL_TRANS_TYPES - 1] =
Debargha Mukherjee5dfa9302017-02-10 05:00:08 -0800142 { 224, 128, 192, 192, 32, 128 };
Debargha Mukherjee3fb33f02016-11-12 10:43:50 -0800143
Debargha Mukherjee5dfa9302017-02-10 05:00:08 -0800144#elif GLOBAL_TRANS_TYPES == 6 // Do not allow full homography
145const aom_tree_index
146 av1_global_motion_types_tree[TREE_SIZE(GLOBAL_TRANS_TYPES)] = {
147 -IDENTITY, 2, -TRANSLATION, 4, -ROTZOOM, 6, -AFFINE, 8, -HORTRAPEZOID,
148 -VERTRAPEZOID
149 };
150
151static const aom_prob default_global_motion_types_prob[GLOBAL_TRANS_TYPES - 1] =
152 { 224, 128, 192, 192, 128 };
153
154#elif GLOBAL_TRANS_TYPES == 4 // Upto Affine
David Barkercf3d0b02016-11-10 10:14:49 +0000155const aom_tree_index av1_global_motion_types_tree[TREE_SIZE(
156 GLOBAL_TRANS_TYPES)] = { -IDENTITY, 2, -TRANSLATION, 4, -ROTZOOM, -AFFINE };
Yaowu Xuc27fc142016-08-22 16:08:15 -0700157
David Barkercf3d0b02016-11-10 10:14:49 +0000158static const aom_prob default_global_motion_types_prob[GLOBAL_TRANS_TYPES - 1] =
159 { 224, 128, 240 };
160
Debargha Mukherjee5dfa9302017-02-10 05:00:08 -0800161#elif GLOBAL_TRANS_TYPES == 3 // Upto rotation-zoom
David Barkercf3d0b02016-11-10 10:14:49 +0000162
163const aom_tree_index av1_global_motion_types_tree[TREE_SIZE(
164 GLOBAL_TRANS_TYPES)] = { -IDENTITY, 2, -TRANSLATION, -ROTZOOM };
165
166static const aom_prob default_global_motion_types_prob[GLOBAL_TRANS_TYPES - 1] =
167 { 224, 128 };
Debargha Mukherjee5dfa9302017-02-10 05:00:08 -0800168#endif // GLOBAL_TRANS_TYPES
169#endif // CONFIG_GLOBAL_MOTION
Yaowu Xuc27fc142016-08-22 16:08:15 -0700170
171static INLINE int mv_class_base(MV_CLASS_TYPE c) {
172 return c ? CLASS0_SIZE << (c + 2) : 0;
173}
174
Yaowu Xuf883b422016-08-30 14:01:10 -0700175MV_CLASS_TYPE av1_get_mv_class(int z, int *offset) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700176 const MV_CLASS_TYPE c = (z >= CLASS0_SIZE * 4096)
177 ? MV_CLASS_10
178 : (MV_CLASS_TYPE)log_in_base_2[z >> 3];
179 if (offset) *offset = z - mv_class_base(c);
180 return c;
181}
182
Yaowu Xuc27fc142016-08-22 16:08:15 -0700183static void inc_mv_component(int v, nmv_component_counts *comp_counts, int incr,
184 int usehp) {
185 int s, z, c, o, d, e, f;
186 assert(v != 0); /* should not be zero */
187 s = v < 0;
188 comp_counts->sign[s] += incr;
189 z = (s ? -v : v) - 1; /* magnitude - 1 */
190
Yaowu Xuf883b422016-08-30 14:01:10 -0700191 c = av1_get_mv_class(z, &o);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700192 comp_counts->classes[c] += incr;
193
194 d = (o >> 3); /* int mv data */
195 f = (o >> 1) & 3; /* fractional pel mv data */
196 e = (o & 1); /* high precision mv data */
197
198 if (c == MV_CLASS_0) {
199 comp_counts->class0[d] += incr;
200 comp_counts->class0_fp[d][f] += incr;
201 if (usehp) comp_counts->class0_hp[e] += incr;
202 } else {
203 int i;
204 int b = c + CLASS0_BITS - 1; // number of bits
205 for (i = 0; i < b; ++i) comp_counts->bits[i][((d >> i) & 1)] += incr;
206 comp_counts->fp[f] += incr;
207 if (usehp) comp_counts->hp[e] += incr;
208 }
209}
210
Yaowu Xuf883b422016-08-30 14:01:10 -0700211void av1_inc_mv(const MV *mv, nmv_context_counts *counts, const int usehp) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700212 if (counts != NULL) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700213 const MV_JOINT_TYPE j = av1_get_mv_joint(mv);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700214 ++counts->joints[j];
215
216 if (mv_joint_vertical(j))
217 inc_mv_component(mv->row, &counts->comps[0], 1, usehp);
218
219 if (mv_joint_horizontal(j))
220 inc_mv_component(mv->col, &counts->comps[1], 1, usehp);
221 }
222}
223
Yaowu Xuf883b422016-08-30 14:01:10 -0700224void av1_adapt_mv_probs(AV1_COMMON *cm, int allow_hp) {
Joe Young947fa972017-03-16 10:34:32 -0700225 int i, j;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700226#if CONFIG_REF_MV
227 int idx;
228 for (idx = 0; idx < NMV_CONTEXTS; ++idx) {
229 nmv_context *fc = &cm->fc->nmvc[idx];
230 const nmv_context *pre_fc =
231 &cm->frame_contexts[cm->frame_context_idx].nmvc[idx];
232 const nmv_context_counts *counts = &cm->counts.mv[idx];
Yaowu Xuf883b422016-08-30 14:01:10 -0700233 aom_tree_merge_probs(av1_mv_joint_tree, pre_fc->joints, counts->joints,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700234 fc->joints);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700235 for (i = 0; i < 2; ++i) {
236 nmv_component *comp = &fc->comps[i];
237 const nmv_component *pre_comp = &pre_fc->comps[i];
238 const nmv_component_counts *c = &counts->comps[i];
239
Yaowu Xuf883b422016-08-30 14:01:10 -0700240 comp->sign = av1_mode_mv_merge_probs(pre_comp->sign, c->sign);
241 aom_tree_merge_probs(av1_mv_class_tree, pre_comp->classes, c->classes,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700242 comp->classes);
Yaowu Xuf883b422016-08-30 14:01:10 -0700243 aom_tree_merge_probs(av1_mv_class0_tree, pre_comp->class0, c->class0,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700244 comp->class0);
245
246 for (j = 0; j < MV_OFFSET_BITS; ++j)
Yaowu Xuf883b422016-08-30 14:01:10 -0700247 comp->bits[j] = av1_mode_mv_merge_probs(pre_comp->bits[j], c->bits[j]);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700248
249 for (j = 0; j < CLASS0_SIZE; ++j)
Yaowu Xuf883b422016-08-30 14:01:10 -0700250 aom_tree_merge_probs(av1_mv_fp_tree, pre_comp->class0_fp[j],
Yaowu Xuc27fc142016-08-22 16:08:15 -0700251 c->class0_fp[j], comp->class0_fp[j]);
252
Yaowu Xuf883b422016-08-30 14:01:10 -0700253 aom_tree_merge_probs(av1_mv_fp_tree, pre_comp->fp, c->fp, comp->fp);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700254
255 if (allow_hp) {
256 comp->class0_hp =
Yaowu Xuf883b422016-08-30 14:01:10 -0700257 av1_mode_mv_merge_probs(pre_comp->class0_hp, c->class0_hp);
258 comp->hp = av1_mode_mv_merge_probs(pre_comp->hp, c->hp);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700259 }
260 }
261 }
262#else
263 nmv_context *fc = &cm->fc->nmvc;
264 const nmv_context *pre_fc = &cm->frame_contexts[cm->frame_context_idx].nmvc;
265 const nmv_context_counts *counts = &cm->counts.mv;
266
Yaowu Xuf883b422016-08-30 14:01:10 -0700267 aom_tree_merge_probs(av1_mv_joint_tree, pre_fc->joints, counts->joints,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700268 fc->joints);
269
270 for (i = 0; i < 2; ++i) {
271 nmv_component *comp = &fc->comps[i];
272 const nmv_component *pre_comp = &pre_fc->comps[i];
273 const nmv_component_counts *c = &counts->comps[i];
274
Yaowu Xuf883b422016-08-30 14:01:10 -0700275 comp->sign = av1_mode_mv_merge_probs(pre_comp->sign, c->sign);
276 aom_tree_merge_probs(av1_mv_class_tree, pre_comp->classes, c->classes,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700277 comp->classes);
Yaowu Xuf883b422016-08-30 14:01:10 -0700278 aom_tree_merge_probs(av1_mv_class0_tree, pre_comp->class0, c->class0,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700279 comp->class0);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700280 for (j = 0; j < MV_OFFSET_BITS; ++j)
Yaowu Xuf883b422016-08-30 14:01:10 -0700281 comp->bits[j] = av1_mode_mv_merge_probs(pre_comp->bits[j], c->bits[j]);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700282
283 for (j = 0; j < CLASS0_SIZE; ++j)
Yaowu Xuf883b422016-08-30 14:01:10 -0700284 aom_tree_merge_probs(av1_mv_fp_tree, pre_comp->class0_fp[j],
Yaowu Xuc27fc142016-08-22 16:08:15 -0700285 c->class0_fp[j], comp->class0_fp[j]);
286
Yaowu Xuf883b422016-08-30 14:01:10 -0700287 aom_tree_merge_probs(av1_mv_fp_tree, pre_comp->fp, c->fp, comp->fp);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700288
289 if (allow_hp) {
290 comp->class0_hp =
Yaowu Xuf883b422016-08-30 14:01:10 -0700291 av1_mode_mv_merge_probs(pre_comp->class0_hp, c->class0_hp);
292 comp->hp = av1_mode_mv_merge_probs(pre_comp->hp, c->hp);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700293 }
294 }
295#endif
296}
297
Thomas Davies028b57f2017-02-22 16:42:11 +0000298#if CONFIG_EC_MULTISYMBOL && !CONFIG_EC_ADAPT
Thomas Davies6519beb2016-10-19 14:46:07 +0100299void av1_set_mv_cdfs(nmv_context *ctx) {
300 int i;
301 int j;
302 av1_tree_to_cdf(av1_mv_joint_tree, ctx->joints, ctx->joint_cdf);
303
304 for (i = 0; i < 2; ++i) {
305 nmv_component *const comp_ctx = &ctx->comps[i];
306 av1_tree_to_cdf(av1_mv_class_tree, comp_ctx->classes, comp_ctx->class_cdf);
307
308 for (j = 0; j < CLASS0_SIZE; ++j) {
309 av1_tree_to_cdf(av1_mv_fp_tree, comp_ctx->class0_fp[j],
310 comp_ctx->class0_fp_cdf[j]);
311 }
312 av1_tree_to_cdf(av1_mv_fp_tree, comp_ctx->fp, comp_ctx->fp_cdf);
313 }
314}
315#endif
316
Yaowu Xuf883b422016-08-30 14:01:10 -0700317void av1_init_mv_probs(AV1_COMMON *cm) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700318#if CONFIG_REF_MV
319 int i;
Thomas Davies05fdc392017-02-22 14:15:39 +0000320 for (i = 0; i < NMV_CONTEXTS; ++i) {
321 // NB: this sets CDFs too
322 cm->fc->nmvc[i] = default_nmv_context;
323 }
Yaowu Xuc27fc142016-08-22 16:08:15 -0700324#else
325 cm->fc->nmvc = default_nmv_context;
326#endif
327#if CONFIG_GLOBAL_MOTION
Yaowu Xuf883b422016-08-30 14:01:10 -0700328 av1_copy(cm->fc->global_motion_types_prob, default_global_motion_types_prob);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700329#endif // CONFIG_GLOBAL_MOTION
330}