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 |
Nathan E. Egge | 5f7fd7a | 2016-09-08 11:22:03 -0400 | [diff] [blame] | 47 | { 0, 0, 0, 0 }, // joint_cdf is computed from joints in av1_init_mv_probs() |
| 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 |
Nathan E. Egge | d7b893c | 2016-09-08 15:08:48 -0400 | [diff] [blame] | 54 | { 0 }, // class_cdf is computed from class in av1_init_mv_probs() |
| 55 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 56 | { 216 }, // class0 |
| 57 | { 136, 140, 148, 160, 176, 192, 224, 234, 234, 240 }, // bits |
| 58 | { { 128, 128, 64 }, { 96, 112, 64 } }, // class0_fp |
| 59 | { 64, 96, 64 }, // fp |
Alex Converse | aca9feb | 2016-10-10 11:08:10 -0700 | [diff] [blame] | 60 | #if CONFIG_EC_MULTISYMBOL |
Nathan E. Egge | 5f34b61 | 2016-09-08 15:59:53 -0400 | [diff] [blame] | 61 | { { 0 }, { 0 } }, // class0_fp_cdf is computed in av1_init_mv_probs() |
| 62 | { 0 }, // fp_cdf is computed from fp in av1_init_mv_probs() |
| 63 | #endif |
Angie Chiang | a1a753c | 2016-10-21 17:13:59 -0700 | [diff] [blame] | 64 | 160, // class0_hp bit |
| 65 | 128, // hp |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 66 | }, |
| 67 | { |
| 68 | // Horizontal component |
| 69 | 128, // sign |
| 70 | { 216, 128, 176, 160, 176, 176, 192, 198, 198, 208 }, // class |
Alex Converse | aca9feb | 2016-10-10 11:08:10 -0700 | [diff] [blame] | 71 | #if CONFIG_EC_MULTISYMBOL |
Nathan E. Egge | d7b893c | 2016-09-08 15:08:48 -0400 | [diff] [blame] | 72 | { 0 }, // class_cdf is computed from class in av1_init_mv_probs() |
| 73 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 74 | { 208 }, // class0 |
| 75 | { 136, 140, 148, 160, 176, 192, 224, 234, 234, 240 }, // bits |
| 76 | { { 128, 128, 64 }, { 96, 112, 64 } }, // class0_fp |
| 77 | { 64, 96, 64 }, // fp |
Alex Converse | aca9feb | 2016-10-10 11:08:10 -0700 | [diff] [blame] | 78 | #if CONFIG_EC_MULTISYMBOL |
Nathan E. Egge | 5f34b61 | 2016-09-08 15:59:53 -0400 | [diff] [blame] | 79 | { { 0 }, { 0 } }, // class0_fp_cdf is computed in av1_init_mv_probs() |
| 80 | { 0 }, // fp_cdf is computed from fp in av1_init_mv_probs() |
| 81 | #endif |
Angie Chiang | a1a753c | 2016-10-21 17:13:59 -0700 | [diff] [blame] | 82 | 160, // class0_hp bit |
| 83 | 128, // hp |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 84 | } }, |
| 85 | }; |
| 86 | |
| 87 | static const uint8_t log_in_base_2[] = { |
| 88 | 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, |
| 89 | 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, |
| 90 | 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, |
| 91 | 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, |
| 92 | 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, |
| 93 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
| 94 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
| 95 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
| 96 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 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 9, 9, 9, 9, 9, 9, 9, 9, |
| 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, 10 |
| 128 | }; |
| 129 | |
| 130 | #if CONFIG_GLOBAL_MOTION |
Debargha Mukherjee | 3fb33f0 | 2016-11-12 10:43:50 -0800 | [diff] [blame] | 131 | #if GLOBAL_TRANS_TYPES == 5 |
| 132 | const aom_tree_index av1_global_motion_types_tree[TREE_SIZE( |
Debargha Mukherjee | 949097c | 2016-11-15 17:27:38 -0800 | [diff] [blame] | 133 | GLOBAL_TRANS_TYPES)] = { -IDENTITY, 2, -TRANSLATION, 4, |
| 134 | -ROTZOOM, 6, -AFFINE, -HOMOGRAPHY }; |
Debargha Mukherjee | 3fb33f0 | 2016-11-12 10:43:50 -0800 | [diff] [blame] | 135 | |
| 136 | static const aom_prob default_global_motion_types_prob[GLOBAL_TRANS_TYPES - 1] = |
| 137 | { 224, 128, 192, 192 }; |
| 138 | |
| 139 | #elif GLOBAL_TRANS_TYPES == 4 |
David Barker | cf3d0b0 | 2016-11-10 10:14:49 +0000 | [diff] [blame] | 140 | const aom_tree_index av1_global_motion_types_tree[TREE_SIZE( |
| 141 | GLOBAL_TRANS_TYPES)] = { -IDENTITY, 2, -TRANSLATION, 4, -ROTZOOM, -AFFINE }; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 142 | |
David Barker | cf3d0b0 | 2016-11-10 10:14:49 +0000 | [diff] [blame] | 143 | static const aom_prob default_global_motion_types_prob[GLOBAL_TRANS_TYPES - 1] = |
| 144 | { 224, 128, 240 }; |
| 145 | |
| 146 | #elif GLOBAL_TRANS_TYPES == 3 |
| 147 | |
| 148 | const aom_tree_index av1_global_motion_types_tree[TREE_SIZE( |
| 149 | GLOBAL_TRANS_TYPES)] = { -IDENTITY, 2, -TRANSLATION, -ROTZOOM }; |
| 150 | |
| 151 | static const aom_prob default_global_motion_types_prob[GLOBAL_TRANS_TYPES - 1] = |
| 152 | { 224, 128 }; |
| 153 | #endif // GLOBAL_TRANS_TYPES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 154 | #endif // CONFIG_GLOBAL_MOTION |
| 155 | |
| 156 | static INLINE int mv_class_base(MV_CLASS_TYPE c) { |
| 157 | return c ? CLASS0_SIZE << (c + 2) : 0; |
| 158 | } |
| 159 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 160 | MV_CLASS_TYPE av1_get_mv_class(int z, int *offset) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 161 | const MV_CLASS_TYPE c = (z >= CLASS0_SIZE * 4096) |
| 162 | ? MV_CLASS_10 |
| 163 | : (MV_CLASS_TYPE)log_in_base_2[z >> 3]; |
| 164 | if (offset) *offset = z - mv_class_base(c); |
| 165 | return c; |
| 166 | } |
| 167 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 168 | static void inc_mv_component(int v, nmv_component_counts *comp_counts, int incr, |
| 169 | int usehp) { |
| 170 | int s, z, c, o, d, e, f; |
| 171 | assert(v != 0); /* should not be zero */ |
| 172 | s = v < 0; |
| 173 | comp_counts->sign[s] += incr; |
| 174 | z = (s ? -v : v) - 1; /* magnitude - 1 */ |
| 175 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 176 | c = av1_get_mv_class(z, &o); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 177 | comp_counts->classes[c] += incr; |
| 178 | |
| 179 | d = (o >> 3); /* int mv data */ |
| 180 | f = (o >> 1) & 3; /* fractional pel mv data */ |
| 181 | e = (o & 1); /* high precision mv data */ |
| 182 | |
| 183 | if (c == MV_CLASS_0) { |
| 184 | comp_counts->class0[d] += incr; |
| 185 | comp_counts->class0_fp[d][f] += incr; |
| 186 | if (usehp) comp_counts->class0_hp[e] += incr; |
| 187 | } else { |
| 188 | int i; |
| 189 | int b = c + CLASS0_BITS - 1; // number of bits |
| 190 | for (i = 0; i < b; ++i) comp_counts->bits[i][((d >> i) & 1)] += incr; |
| 191 | comp_counts->fp[f] += incr; |
| 192 | if (usehp) comp_counts->hp[e] += incr; |
| 193 | } |
| 194 | } |
| 195 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 196 | 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] | 197 | if (counts != NULL) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 198 | const MV_JOINT_TYPE j = av1_get_mv_joint(mv); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 199 | ++counts->joints[j]; |
| 200 | |
| 201 | if (mv_joint_vertical(j)) |
| 202 | inc_mv_component(mv->row, &counts->comps[0], 1, usehp); |
| 203 | |
| 204 | if (mv_joint_horizontal(j)) |
| 205 | inc_mv_component(mv->col, &counts->comps[1], 1, usehp); |
| 206 | } |
| 207 | } |
| 208 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 209 | void av1_adapt_mv_probs(AV1_COMMON *cm, int allow_hp) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 210 | int i, j; |
| 211 | #if CONFIG_REF_MV |
| 212 | int idx; |
| 213 | for (idx = 0; idx < NMV_CONTEXTS; ++idx) { |
| 214 | nmv_context *fc = &cm->fc->nmvc[idx]; |
| 215 | const nmv_context *pre_fc = |
| 216 | &cm->frame_contexts[cm->frame_context_idx].nmvc[idx]; |
| 217 | const nmv_context_counts *counts = &cm->counts.mv[idx]; |
| 218 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 219 | 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] | 220 | fc->joints); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 221 | for (i = 0; i < 2; ++i) { |
| 222 | nmv_component *comp = &fc->comps[i]; |
| 223 | const nmv_component *pre_comp = &pre_fc->comps[i]; |
| 224 | const nmv_component_counts *c = &counts->comps[i]; |
| 225 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 226 | comp->sign = av1_mode_mv_merge_probs(pre_comp->sign, c->sign); |
| 227 | 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] | 228 | comp->classes); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 229 | 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] | 230 | comp->class0); |
| 231 | |
| 232 | for (j = 0; j < MV_OFFSET_BITS; ++j) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 233 | 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] | 234 | |
| 235 | for (j = 0; j < CLASS0_SIZE; ++j) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 236 | 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] | 237 | c->class0_fp[j], comp->class0_fp[j]); |
| 238 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 239 | 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] | 240 | |
| 241 | if (allow_hp) { |
| 242 | comp->class0_hp = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 243 | av1_mode_mv_merge_probs(pre_comp->class0_hp, c->class0_hp); |
| 244 | comp->hp = av1_mode_mv_merge_probs(pre_comp->hp, c->hp); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | } |
| 248 | #else |
| 249 | nmv_context *fc = &cm->fc->nmvc; |
| 250 | const nmv_context *pre_fc = &cm->frame_contexts[cm->frame_context_idx].nmvc; |
| 251 | const nmv_context_counts *counts = &cm->counts.mv; |
| 252 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 253 | 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] | 254 | fc->joints); |
| 255 | |
| 256 | for (i = 0; i < 2; ++i) { |
| 257 | nmv_component *comp = &fc->comps[i]; |
| 258 | const nmv_component *pre_comp = &pre_fc->comps[i]; |
| 259 | const nmv_component_counts *c = &counts->comps[i]; |
| 260 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 261 | comp->sign = av1_mode_mv_merge_probs(pre_comp->sign, c->sign); |
| 262 | 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] | 263 | comp->classes); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 264 | 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] | 265 | comp->class0); |
| 266 | |
| 267 | for (j = 0; j < MV_OFFSET_BITS; ++j) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 268 | 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] | 269 | |
| 270 | for (j = 0; j < CLASS0_SIZE; ++j) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 271 | 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] | 272 | c->class0_fp[j], comp->class0_fp[j]); |
| 273 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 274 | 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] | 275 | |
| 276 | if (allow_hp) { |
| 277 | comp->class0_hp = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 278 | av1_mode_mv_merge_probs(pre_comp->class0_hp, c->class0_hp); |
| 279 | comp->hp = av1_mode_mv_merge_probs(pre_comp->hp, c->hp); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | #endif |
| 283 | } |
| 284 | |
Thomas Davies | 6519beb | 2016-10-19 14:46:07 +0100 | [diff] [blame] | 285 | #if CONFIG_EC_MULTISYMBOL |
| 286 | void av1_set_mv_cdfs(nmv_context *ctx) { |
| 287 | int i; |
| 288 | int j; |
| 289 | av1_tree_to_cdf(av1_mv_joint_tree, ctx->joints, ctx->joint_cdf); |
| 290 | |
| 291 | for (i = 0; i < 2; ++i) { |
| 292 | nmv_component *const comp_ctx = &ctx->comps[i]; |
| 293 | av1_tree_to_cdf(av1_mv_class_tree, comp_ctx->classes, comp_ctx->class_cdf); |
| 294 | |
| 295 | for (j = 0; j < CLASS0_SIZE; ++j) { |
| 296 | av1_tree_to_cdf(av1_mv_fp_tree, comp_ctx->class0_fp[j], |
| 297 | comp_ctx->class0_fp_cdf[j]); |
| 298 | } |
| 299 | av1_tree_to_cdf(av1_mv_fp_tree, comp_ctx->fp, comp_ctx->fp_cdf); |
| 300 | } |
| 301 | } |
| 302 | #endif |
| 303 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 304 | void av1_init_mv_probs(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 305 | #if CONFIG_REF_MV |
| 306 | int i; |
| 307 | for (i = 0; i < NMV_CONTEXTS; ++i) cm->fc->nmvc[i] = default_nmv_context; |
| 308 | #else |
| 309 | cm->fc->nmvc = default_nmv_context; |
Alex Converse | aca9feb | 2016-10-10 11:08:10 -0700 | [diff] [blame] | 310 | #if CONFIG_EC_MULTISYMBOL |
Thomas Davies | 6519beb | 2016-10-19 14:46:07 +0100 | [diff] [blame] | 311 | av1_set_mv_cdfs(&cm->fc->nmvc); |
Nathan E. Egge | 5f7fd7a | 2016-09-08 11:22:03 -0400 | [diff] [blame] | 312 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 313 | #endif |
| 314 | #if CONFIG_GLOBAL_MOTION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 315 | 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] | 316 | #endif // CONFIG_GLOBAL_MOTION |
| 317 | } |