entropymv.c 13.1 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1
/*
Yaowu Xu's avatar
Yaowu Xu committed
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jingning Han's avatar
Jingning Han committed
3
 *
Yaowu Xu's avatar
Yaowu Xu committed
4
5
6
7
8
9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Jingning Han's avatar
Jingning Han committed
10
11
 */

12
13
#include "av1/common/onyxc_int.h"
#include "av1/common/entropymv.h"
Jingning Han's avatar
Jingning Han committed
14
15
16
17

// Integer pel reference mv threshold for use of high-precision 1/8 mv
#define COMPANDED_MVREF_THRESH 8

Yaowu Xu's avatar
Yaowu Xu committed
18
const aom_tree_index av1_mv_joint_tree[TREE_SIZE(MV_JOINTS)] = {
clang-format's avatar
clang-format committed
19
  -MV_JOINT_ZERO, 2, -MV_JOINT_HNZVZ, 4, -MV_JOINT_HZVNZ, -MV_JOINT_HNZVNZ
Jingning Han's avatar
Jingning Han committed
20
21
};

clang-format's avatar
clang-format committed
22
/* clang-format off */
Yaowu Xu's avatar
Yaowu Xu committed
23
const aom_tree_index av1_mv_class_tree[TREE_SIZE(MV_CLASSES)] = {
Jingning Han's avatar
Jingning Han committed
24
25
26
27
28
29
30
31
32
33
34
  -MV_CLASS_0, 2,
  -MV_CLASS_1, 4,
  6, 8,
  -MV_CLASS_2, -MV_CLASS_3,
  10, 12,
  -MV_CLASS_4, -MV_CLASS_5,
  -MV_CLASS_6, 14,
  16, 18,
  -MV_CLASS_7, -MV_CLASS_8,
  -MV_CLASS_9, -MV_CLASS_10,
};
clang-format's avatar
clang-format committed
35
/* clang-format on */
Jingning Han's avatar
Jingning Han committed
36

Yaowu Xu's avatar
Yaowu Xu committed
37
const aom_tree_index av1_mv_class0_tree[TREE_SIZE(CLASS0_SIZE)] = {
Jingning Han's avatar
Jingning Han committed
38
39
40
  -0, -1,
};

Yaowu Xu's avatar
Yaowu Xu committed
41
42
const aom_tree_index av1_mv_fp_tree[TREE_SIZE(MV_FP_SIZE)] = { -0, 2,  -1,
                                                               4,  -2, -3 };
Jingning Han's avatar
Jingning Han committed
43
44

static const nmv_context default_nmv_context = {
45
  { 32, 64, 96 },  // joints
46
#if CONFIG_EC_MULTISYMBOL
47
  { 4096, 11264, 19328, 32768, 0 },  // joint_cdf
48
#endif
clang-format's avatar
clang-format committed
49
50
51
52
  { {
        // Vertical component
        128,                                                   // sign
        { 224, 144, 192, 168, 192, 176, 192, 198, 198, 245 },  // class
53
#if CONFIG_EC_MULTISYMBOL
54
55
        { 28672, 30976, 31858, 32320, 32551, 32656, 32740, 32757, 32762, 32767,
          32768, 0 },  // class_cdf
56
#endif
clang-format's avatar
clang-format committed
57
58
59
60
        { 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
61
#if CONFIG_EC_MULTISYMBOL
62
63
64
        { { 16384, 24576, 26624, 32768, 0 },
          { 12288, 21248, 24128, 32768, 0 } },  // class0_fp_cdf
        { 8192, 17408, 21248, 32768, 0 },       // fp_cdf
65
#endif
Angie Chiang's avatar
Angie Chiang committed
66
67
        160,  // class0_hp bit
        128,  // hp
Jingning Han's avatar
Jingning Han committed
68
    },
clang-format's avatar
clang-format committed
69
70
71
72
    {
        // Horizontal component
        128,                                                   // sign
        { 216, 128, 176, 160, 176, 176, 192, 198, 198, 208 },  // class
73
#if CONFIG_EC_MULTISYMBOL
74
75
        { 28672, 30976, 31858, 32320, 32551, 32656, 32740, 32757, 32762, 32767,
          32768, 0 },  // class_cdf
76
#endif
clang-format's avatar
clang-format committed
77
78
79
80
        { 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
81
#if CONFIG_EC_MULTISYMBOL
82
83
84
        { { 16384, 24576, 26624, 32768, 0 },
          { 12288, 21248, 24128, 32768, 0 } },  // class0_fp_cdf
        { 8192, 17408, 21248, 32768, 0 },       // fp_cdf
85
#endif
Angie Chiang's avatar
Angie Chiang committed
86
87
        160,  // class0_hp bit
        128,  // hp
clang-format's avatar
clang-format committed
88
    } },
Jingning Han's avatar
Jingning Han committed
89
90
91
};

static const uint8_t log_in_base_2[] = {
clang-format's avatar
clang-format committed
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
  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,
  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,
  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,
  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,
  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,
  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,
  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,
  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, 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, 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, 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, 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, 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, 9, 9, 9, 9, 9, 9,
  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10
Jingning Han's avatar
Jingning Han committed
132
133
};

134
#if CONFIG_GLOBAL_MOTION
135
#if GLOBAL_TRANS_TYPES == 7  // All models
136
const aom_tree_index av1_global_motion_types_tree[TREE_SIZE(
137
138
139
    GLOBAL_TRANS_TYPES)] = { -IDENTITY,   2,  -TRANSLATION,  4,
                             -ROTZOOM,    6,  -AFFINE,       8,
                             -HOMOGRAPHY, 10, -HORTRAPEZOID, -VERTRAPEZOID };
140
141

static const aom_prob default_global_motion_types_prob[GLOBAL_TRANS_TYPES - 1] =
142
    { 224, 128, 192, 192, 32, 128 };
143

144
145
146
147
148
149
150
151
152
153
154
#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
155
156
const aom_tree_index av1_global_motion_types_tree[TREE_SIZE(
    GLOBAL_TRANS_TYPES)] = { -IDENTITY, 2, -TRANSLATION, 4, -ROTZOOM, -AFFINE };
157

158
159
160
static const aom_prob default_global_motion_types_prob[GLOBAL_TRANS_TYPES - 1] =
    { 224, 128, 240 };

161
#elif GLOBAL_TRANS_TYPES == 3  // Upto rotation-zoom
162
163
164
165
166
167

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 };
168
169
#endif                         // GLOBAL_TRANS_TYPES
#endif                         // CONFIG_GLOBAL_MOTION
170

Jingning Han's avatar
Jingning Han committed
171
172
173
174
static INLINE int mv_class_base(MV_CLASS_TYPE c) {
  return c ? CLASS0_SIZE << (c + 2) : 0;
}

Yaowu Xu's avatar
Yaowu Xu committed
175
MV_CLASS_TYPE av1_get_mv_class(int z, int *offset) {
clang-format's avatar
clang-format committed
176
177
178
179
  const MV_CLASS_TYPE c = (z >= CLASS0_SIZE * 4096)
                              ? MV_CLASS_10
                              : (MV_CLASS_TYPE)log_in_base_2[z >> 3];
  if (offset) *offset = z - mv_class_base(c);
Jingning Han's avatar
Jingning Han committed
180
181
182
  return c;
}

clang-format's avatar
clang-format committed
183
184
static void inc_mv_component(int v, nmv_component_counts *comp_counts, int incr,
                             int usehp) {
Jingning Han's avatar
Jingning Han committed
185
  int s, z, c, o, d, e, f;
clang-format's avatar
clang-format committed
186
  assert(v != 0); /* should not be zero */
Jingning Han's avatar
Jingning Han committed
187
188
  s = v < 0;
  comp_counts->sign[s] += incr;
clang-format's avatar
clang-format committed
189
  z = (s ? -v : v) - 1; /* magnitude - 1 */
Jingning Han's avatar
Jingning Han committed
190

Yaowu Xu's avatar
Yaowu Xu committed
191
  c = av1_get_mv_class(z, &o);
Jingning Han's avatar
Jingning Han committed
192
193
  comp_counts->classes[c] += incr;

clang-format's avatar
clang-format committed
194
195
196
  d = (o >> 3);     /* int mv data */
  f = (o >> 1) & 3; /* fractional pel mv data */
  e = (o & 1);      /* high precision mv data */
Jingning Han's avatar
Jingning Han committed
197
198
199
200

  if (c == MV_CLASS_0) {
    comp_counts->class0[d] += incr;
    comp_counts->class0_fp[d][f] += incr;
clang-format's avatar
clang-format committed
201
    if (usehp) comp_counts->class0_hp[e] += incr;
Jingning Han's avatar
Jingning Han committed
202
203
204
  } else {
    int i;
    int b = c + CLASS0_BITS - 1;  // number of bits
clang-format's avatar
clang-format committed
205
    for (i = 0; i < b; ++i) comp_counts->bits[i][((d >> i) & 1)] += incr;
Jingning Han's avatar
Jingning Han committed
206
    comp_counts->fp[f] += incr;
clang-format's avatar
clang-format committed
207
    if (usehp) comp_counts->hp[e] += incr;
Jingning Han's avatar
Jingning Han committed
208
209
210
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
211
void av1_inc_mv(const MV *mv, nmv_context_counts *counts, const int usehp) {
Jingning Han's avatar
Jingning Han committed
212
  if (counts != NULL) {
Yaowu Xu's avatar
Yaowu Xu committed
213
    const MV_JOINT_TYPE j = av1_get_mv_joint(mv);
Jingning Han's avatar
Jingning Han committed
214
215
    ++counts->joints[j];

216
217
    if (mv_joint_vertical(j))
      inc_mv_component(mv->row, &counts->comps[0], 1, usehp);
Jingning Han's avatar
Jingning Han committed
218

219
220
    if (mv_joint_horizontal(j))
      inc_mv_component(mv->col, &counts->comps[1], 1, usehp);
Jingning Han's avatar
Jingning Han committed
221
222
223
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
224
void av1_adapt_mv_probs(AV1_COMMON *cm, int allow_hp) {
225
  int i;
226
227
#if CONFIG_REF_MV
  int idx;
228
  int j;
229
230
231
232
233
  for (idx = 0; idx < NMV_CONTEXTS; ++idx) {
    nmv_context *fc = &cm->fc->nmvc[idx];
    const nmv_context *pre_fc =
        &cm->frame_contexts[cm->frame_context_idx].nmvc[idx];
    const nmv_context_counts *counts = &cm->counts.mv[idx];
Yaowu Xu's avatar
Yaowu Xu committed
234
    aom_tree_merge_probs(av1_mv_joint_tree, pre_fc->joints, counts->joints,
235
236
237
238
239
240
                         fc->joints);
    for (i = 0; i < 2; ++i) {
      nmv_component *comp = &fc->comps[i];
      const nmv_component *pre_comp = &pre_fc->comps[i];
      const nmv_component_counts *c = &counts->comps[i];

Yaowu Xu's avatar
Yaowu Xu committed
241
242
      comp->sign = av1_mode_mv_merge_probs(pre_comp->sign, c->sign);
      aom_tree_merge_probs(av1_mv_class_tree, pre_comp->classes, c->classes,
243
                           comp->classes);
Yaowu Xu's avatar
Yaowu Xu committed
244
      aom_tree_merge_probs(av1_mv_class0_tree, pre_comp->class0, c->class0,
245
246
247
                           comp->class0);

      for (j = 0; j < MV_OFFSET_BITS; ++j)
Yaowu Xu's avatar
Yaowu Xu committed
248
        comp->bits[j] = av1_mode_mv_merge_probs(pre_comp->bits[j], c->bits[j]);
249
250

      for (j = 0; j < CLASS0_SIZE; ++j)
Yaowu Xu's avatar
Yaowu Xu committed
251
        aom_tree_merge_probs(av1_mv_fp_tree, pre_comp->class0_fp[j],
252
253
                             c->class0_fp[j], comp->class0_fp[j]);

Yaowu Xu's avatar
Yaowu Xu committed
254
      aom_tree_merge_probs(av1_mv_fp_tree, pre_comp->fp, c->fp, comp->fp);
255
256

      if (allow_hp) {
clang-format's avatar
clang-format committed
257
        comp->class0_hp =
Yaowu Xu's avatar
Yaowu Xu committed
258
259
            av1_mode_mv_merge_probs(pre_comp->class0_hp, c->class0_hp);
        comp->hp = av1_mode_mv_merge_probs(pre_comp->hp, c->hp);
260
261
262
263
      }
    }
  }
#else
Jingning Han's avatar
Jingning Han committed
264
265
266
267
  nmv_context *fc = &cm->fc->nmvc;
  const nmv_context *pre_fc = &cm->frame_contexts[cm->frame_context_idx].nmvc;
  const nmv_context_counts *counts = &cm->counts.mv;

Yaowu Xu's avatar
Yaowu Xu committed
268
  aom_tree_merge_probs(av1_mv_joint_tree, pre_fc->joints, counts->joints,
Jingning Han's avatar
Jingning Han committed
269
270
271
272
273
274
275
                       fc->joints);

  for (i = 0; i < 2; ++i) {
    nmv_component *comp = &fc->comps[i];
    const nmv_component *pre_comp = &pre_fc->comps[i];
    const nmv_component_counts *c = &counts->comps[i];

Yaowu Xu's avatar
Yaowu Xu committed
276
277
    comp->sign = av1_mode_mv_merge_probs(pre_comp->sign, c->sign);
    aom_tree_merge_probs(av1_mv_class_tree, pre_comp->classes, c->classes,
Jingning Han's avatar
Jingning Han committed
278
                         comp->classes);
Yaowu Xu's avatar
Yaowu Xu committed
279
    aom_tree_merge_probs(av1_mv_class0_tree, pre_comp->class0, c->class0,
Jingning Han's avatar
Jingning Han committed
280
281
                         comp->class0);
    for (j = 0; j < MV_OFFSET_BITS; ++j)
Yaowu Xu's avatar
Yaowu Xu committed
282
      comp->bits[j] = av1_mode_mv_merge_probs(pre_comp->bits[j], c->bits[j]);
Jingning Han's avatar
Jingning Han committed
283
284

    for (j = 0; j < CLASS0_SIZE; ++j)
Yaowu Xu's avatar
Yaowu Xu committed
285
      aom_tree_merge_probs(av1_mv_fp_tree, pre_comp->class0_fp[j],
Jingning Han's avatar
Jingning Han committed
286
287
                           c->class0_fp[j], comp->class0_fp[j]);

Yaowu Xu's avatar
Yaowu Xu committed
288
    aom_tree_merge_probs(av1_mv_fp_tree, pre_comp->fp, c->fp, comp->fp);
Jingning Han's avatar
Jingning Han committed
289
290

    if (allow_hp) {
clang-format's avatar
clang-format committed
291
      comp->class0_hp =
Yaowu Xu's avatar
Yaowu Xu committed
292
293
          av1_mode_mv_merge_probs(pre_comp->class0_hp, c->class0_hp);
      comp->hp = av1_mode_mv_merge_probs(pre_comp->hp, c->hp);
Jingning Han's avatar
Jingning Han committed
294
295
    }
  }
296
#endif
Jingning Han's avatar
Jingning Han committed
297
298
}

299
#if CONFIG_EC_MULTISYMBOL && !CONFIG_EC_ADAPT
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
void av1_set_mv_cdfs(nmv_context *ctx) {
  int i;
  int j;
  av1_tree_to_cdf(av1_mv_joint_tree, ctx->joints, ctx->joint_cdf);

  for (i = 0; i < 2; ++i) {
    nmv_component *const comp_ctx = &ctx->comps[i];
    av1_tree_to_cdf(av1_mv_class_tree, comp_ctx->classes, comp_ctx->class_cdf);

    for (j = 0; j < CLASS0_SIZE; ++j) {
      av1_tree_to_cdf(av1_mv_fp_tree, comp_ctx->class0_fp[j],
                      comp_ctx->class0_fp_cdf[j]);
    }
    av1_tree_to_cdf(av1_mv_fp_tree, comp_ctx->fp, comp_ctx->fp_cdf);
  }
}
#endif

Yaowu Xu's avatar
Yaowu Xu committed
318
void av1_init_mv_probs(AV1_COMMON *cm) {
319
320
#if CONFIG_REF_MV
  int i;
321
322
323
324
  for (i = 0; i < NMV_CONTEXTS; ++i) {
    // NB: this sets CDFs too
    cm->fc->nmvc[i] = default_nmv_context;
  }
325
#else
Jingning Han's avatar
Jingning Han committed
326
  cm->fc->nmvc = default_nmv_context;
327
#endif
328
#if CONFIG_GLOBAL_MOTION
Yaowu Xu's avatar
Yaowu Xu committed
329
  av1_copy(cm->fc->global_motion_types_prob, default_global_motion_types_prob);
330
#endif  // CONFIG_GLOBAL_MOTION
Jingning Han's avatar
Jingning Han committed
331
}