Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 4 | * 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 Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 18 | const aom_tree_index av1_mv_joint_tree[TREE_SIZE(MV_JOINTS)] = { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 19 | -MV_JOINT_ZERO, 2, -MV_JOINT_HNZVZ, 4, -MV_JOINT_HZVNZ, -MV_JOINT_HNZVNZ |
| 20 | }; |
| 21 | |
| 22 | /* clang-format off */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 23 | const aom_tree_index av1_mv_class_tree[TREE_SIZE(MV_CLASSES)] = { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 24 | -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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 37 | const aom_tree_index av1_mv_class0_tree[TREE_SIZE(CLASS0_SIZE)] = { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 38 | -0, -1, |
| 39 | }; |
| 40 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 41 | const aom_tree_index av1_mv_fp_tree[TREE_SIZE(MV_FP_SIZE)] = { -0, 2, -1, |
| 42 | 4, -2, -3 }; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 43 | |
| 44 | static const nmv_context default_nmv_context = { |
Nathan E. Egge | 5f7fd7a | 2016-09-08 11:22:03 -0400 | [diff] [blame] | 45 | { 32, 64, 96 }, // joints |
Alex Converse | aca9feb | 2016-10-10 11:08:10 -0700 | [diff] [blame] | 46 | #if CONFIG_EC_MULTISYMBOL |
Thomas Davies | 05fdc39 | 2017-02-22 14:15:39 +0000 | [diff] [blame] | 47 | { 4096, 11264, 19328, 32768, 0 }, // joint_cdf |
Nathan E. Egge | 5f7fd7a | 2016-09-08 11:22:03 -0400 | [diff] [blame] | 48 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 49 | { { |
| 50 | // Vertical component |
| 51 | 128, // sign |
| 52 | { 224, 144, 192, 168, 192, 176, 192, 198, 198, 245 }, // class |
Alex Converse | aca9feb | 2016-10-10 11:08:10 -0700 | [diff] [blame] | 53 | #if CONFIG_EC_MULTISYMBOL |
Thomas Davies | 05fdc39 | 2017-02-22 14:15:39 +0000 | [diff] [blame] | 54 | { 28672, 30976, 31858, 32320, 32551, 32656, 32740, 32757, 32762, 32767, |
| 55 | 32768, 0 }, // class_cdf |
Nathan E. Egge | d7b893c | 2016-09-08 15:08:48 -0400 | [diff] [blame] | 56 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 57 | { 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 Converse | aca9feb | 2016-10-10 11:08:10 -0700 | [diff] [blame] | 61 | #if CONFIG_EC_MULTISYMBOL |
Thomas Davies | 05fdc39 | 2017-02-22 14:15:39 +0000 | [diff] [blame] | 62 | { { 16384, 24576, 26624, 32768, 0 }, |
| 63 | { 12288, 21248, 24128, 32768, 0 } }, // class0_fp_cdf |
| 64 | { 8192, 17408, 21248, 32768, 0 }, // fp_cdf |
Nathan E. Egge | 5f34b61 | 2016-09-08 15:59:53 -0400 | [diff] [blame] | 65 | #endif |
Angie Chiang | a1a753c | 2016-10-21 17:13:59 -0700 | [diff] [blame] | 66 | 160, // class0_hp bit |
| 67 | 128, // hp |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 68 | }, |
| 69 | { |
| 70 | // Horizontal component |
| 71 | 128, // sign |
| 72 | { 216, 128, 176, 160, 176, 176, 192, 198, 198, 208 }, // class |
Alex Converse | aca9feb | 2016-10-10 11:08:10 -0700 | [diff] [blame] | 73 | #if CONFIG_EC_MULTISYMBOL |
Thomas Davies | 05fdc39 | 2017-02-22 14:15:39 +0000 | [diff] [blame] | 74 | { 28672, 30976, 31858, 32320, 32551, 32656, 32740, 32757, 32762, 32767, |
| 75 | 32768, 0 }, // class_cdf |
Nathan E. Egge | d7b893c | 2016-09-08 15:08:48 -0400 | [diff] [blame] | 76 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 77 | { 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 Converse | aca9feb | 2016-10-10 11:08:10 -0700 | [diff] [blame] | 81 | #if CONFIG_EC_MULTISYMBOL |
Thomas Davies | 05fdc39 | 2017-02-22 14:15:39 +0000 | [diff] [blame] | 82 | { { 16384, 24576, 26624, 32768, 0 }, |
| 83 | { 12288, 21248, 24128, 32768, 0 } }, // class0_fp_cdf |
| 84 | { 8192, 17408, 21248, 32768, 0 }, // fp_cdf |
Nathan E. Egge | 5f34b61 | 2016-09-08 15:59:53 -0400 | [diff] [blame] | 85 | #endif |
Angie Chiang | a1a753c | 2016-10-21 17:13:59 -0700 | [diff] [blame] | 86 | 160, // class0_hp bit |
| 87 | 128, // hp |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 88 | } }, |
| 89 | }; |
| 90 | |
| 91 | static 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, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 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|
| 121 | 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, |
| 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 Mukherjee | 5dfa930 | 2017-02-10 05:00:08 -0800 | [diff] [blame] | 135 | #if GLOBAL_TRANS_TYPES == 7 // All models |
Debargha Mukherjee | 3fb33f0 | 2016-11-12 10:43:50 -0800 | [diff] [blame] | 136 | const aom_tree_index av1_global_motion_types_tree[TREE_SIZE( |
Debargha Mukherjee | 5dfa930 | 2017-02-10 05:00:08 -0800 | [diff] [blame] | 137 | GLOBAL_TRANS_TYPES)] = { -IDENTITY, 2, -TRANSLATION, 4, |
| 138 | -ROTZOOM, 6, -AFFINE, 8, |
| 139 | -HOMOGRAPHY, 10, -HORTRAPEZOID, -VERTRAPEZOID }; |
Debargha Mukherjee | 3fb33f0 | 2016-11-12 10:43:50 -0800 | [diff] [blame] | 140 | |
| 141 | static const aom_prob default_global_motion_types_prob[GLOBAL_TRANS_TYPES - 1] = |
Debargha Mukherjee | 5dfa930 | 2017-02-10 05:00:08 -0800 | [diff] [blame] | 142 | { 224, 128, 192, 192, 32, 128 }; |
Debargha Mukherjee | 3fb33f0 | 2016-11-12 10:43:50 -0800 | [diff] [blame] | 143 | |
Debargha Mukherjee | 5dfa930 | 2017-02-10 05:00:08 -0800 | [diff] [blame] | 144 | #elif GLOBAL_TRANS_TYPES == 6 // Do not allow full homography |
| 145 | const 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 | |
| 151 | static 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 Barker | cf3d0b0 | 2016-11-10 10:14:49 +0000 | [diff] [blame] | 155 | const aom_tree_index av1_global_motion_types_tree[TREE_SIZE( |
| 156 | GLOBAL_TRANS_TYPES)] = { -IDENTITY, 2, -TRANSLATION, 4, -ROTZOOM, -AFFINE }; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 157 | |
David Barker | cf3d0b0 | 2016-11-10 10:14:49 +0000 | [diff] [blame] | 158 | static const aom_prob default_global_motion_types_prob[GLOBAL_TRANS_TYPES - 1] = |
| 159 | { 224, 128, 240 }; |
| 160 | |
Debargha Mukherjee | 5dfa930 | 2017-02-10 05:00:08 -0800 | [diff] [blame] | 161 | #elif GLOBAL_TRANS_TYPES == 3 // Upto rotation-zoom |
David Barker | cf3d0b0 | 2016-11-10 10:14:49 +0000 | [diff] [blame] | 162 | |
| 163 | const aom_tree_index av1_global_motion_types_tree[TREE_SIZE( |
| 164 | GLOBAL_TRANS_TYPES)] = { -IDENTITY, 2, -TRANSLATION, -ROTZOOM }; |
| 165 | |
| 166 | static const aom_prob default_global_motion_types_prob[GLOBAL_TRANS_TYPES - 1] = |
| 167 | { 224, 128 }; |
Debargha Mukherjee | 5dfa930 | 2017-02-10 05:00:08 -0800 | [diff] [blame] | 168 | #endif // GLOBAL_TRANS_TYPES |
| 169 | #endif // CONFIG_GLOBAL_MOTION |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 170 | |
| 171 | static INLINE int mv_class_base(MV_CLASS_TYPE c) { |
| 172 | return c ? CLASS0_SIZE << (c + 2) : 0; |
| 173 | } |
| 174 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 175 | MV_CLASS_TYPE av1_get_mv_class(int z, int *offset) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 176 | 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 Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 183 | static 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 191 | c = av1_get_mv_class(z, &o); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 192 | 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 211 | void av1_inc_mv(const MV *mv, nmv_context_counts *counts, const int usehp) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 212 | if (counts != NULL) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 213 | const MV_JOINT_TYPE j = av1_get_mv_joint(mv); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 214 | ++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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 224 | void av1_adapt_mv_probs(AV1_COMMON *cm, int allow_hp) { |
Joe Young | 947fa97 | 2017-03-16 10:34:32 -0700 | [diff] [blame] | 225 | int i, j; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 226 | #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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 233 | aom_tree_merge_probs(av1_mv_joint_tree, pre_fc->joints, counts->joints, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 234 | fc->joints); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 235 | 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 240 | 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 Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 242 | comp->classes); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 243 | aom_tree_merge_probs(av1_mv_class0_tree, pre_comp->class0, c->class0, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 244 | comp->class0); |
| 245 | |
| 246 | for (j = 0; j < MV_OFFSET_BITS; ++j) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 247 | comp->bits[j] = av1_mode_mv_merge_probs(pre_comp->bits[j], c->bits[j]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 248 | |
| 249 | for (j = 0; j < CLASS0_SIZE; ++j) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 250 | aom_tree_merge_probs(av1_mv_fp_tree, pre_comp->class0_fp[j], |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 251 | c->class0_fp[j], comp->class0_fp[j]); |
| 252 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 253 | aom_tree_merge_probs(av1_mv_fp_tree, pre_comp->fp, c->fp, comp->fp); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 254 | |
| 255 | if (allow_hp) { |
| 256 | comp->class0_hp = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 257 | 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 Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 259 | } |
| 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 267 | aom_tree_merge_probs(av1_mv_joint_tree, pre_fc->joints, counts->joints, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 268 | 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 275 | 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 Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 277 | comp->classes); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 278 | aom_tree_merge_probs(av1_mv_class0_tree, pre_comp->class0, c->class0, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 279 | comp->class0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 280 | for (j = 0; j < MV_OFFSET_BITS; ++j) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 281 | comp->bits[j] = av1_mode_mv_merge_probs(pre_comp->bits[j], c->bits[j]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 282 | |
| 283 | for (j = 0; j < CLASS0_SIZE; ++j) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 284 | aom_tree_merge_probs(av1_mv_fp_tree, pre_comp->class0_fp[j], |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 285 | c->class0_fp[j], comp->class0_fp[j]); |
| 286 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 287 | aom_tree_merge_probs(av1_mv_fp_tree, pre_comp->fp, c->fp, comp->fp); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 288 | |
| 289 | if (allow_hp) { |
| 290 | comp->class0_hp = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 291 | 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 Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | #endif |
| 296 | } |
| 297 | |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 298 | #if CONFIG_EC_MULTISYMBOL && !CONFIG_EC_ADAPT |
Thomas Davies | 6519beb | 2016-10-19 14:46:07 +0100 | [diff] [blame] | 299 | void 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 317 | void av1_init_mv_probs(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 318 | #if CONFIG_REF_MV |
| 319 | int i; |
Thomas Davies | 05fdc39 | 2017-02-22 14:15:39 +0000 | [diff] [blame] | 320 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 321 | // NB: this sets CDFs too |
| 322 | cm->fc->nmvc[i] = default_nmv_context; |
| 323 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 324 | #else |
| 325 | cm->fc->nmvc = default_nmv_context; |
| 326 | #endif |
| 327 | #if CONFIG_GLOBAL_MOTION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 328 | av1_copy(cm->fc->global_motion_types_prob, default_global_motion_types_prob); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 329 | #endif // CONFIG_GLOBAL_MOTION |
| 330 | } |