blob: 166721b1370896e2dbc3d71f0039e4552d1f7505 [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 <assert.h>
13
14#include "av1/common/common.h"
15#include "av1/common/entropy.h"
16#include "av1/common/entropymode.h"
17#include "av1/common/entropymv.h"
18#include "av1/common/mvref_common.h"
19#include "av1/common/pred_common.h"
20#include "av1/common/reconinter.h"
hui su45dc5972016-12-08 17:42:50 -080021#if CONFIG_EXT_INTRA
22#include "av1/common/reconintra.h"
23#endif // CONFIG_EXT_INTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -070024#include "av1/common/seg_common.h"
Yue Chen69f18e12016-09-08 14:48:15 -070025#if CONFIG_WARPED_MOTION
26#include "av1/common/warped_motion.h"
27#endif // CONFIG_WARPED_MOTION
Yaowu Xuc27fc142016-08-22 16:08:15 -070028
Yaowu Xuc27fc142016-08-22 16:08:15 -070029#include "av1/decoder/decodeframe.h"
Jingning Han1aab8182016-06-03 11:09:06 -070030#include "av1/decoder/decodemv.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070031
Yaowu Xuf883b422016-08-30 14:01:10 -070032#include "aom_dsp/aom_dsp_common.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070033
Michael Bebenita6048d052016-08-25 14:40:54 -070034#define ACCT_STR __func__
Zoe Liu85b66462017-04-20 14:28:19 -070035
Di Chen56586622017-06-09 13:49:44 -070036#define DEC_MISMATCH_DEBUG 0
Zoe Liu85b66462017-04-20 14:28:19 -070037
hui su5db97432016-10-14 16:10:14 -070038#if CONFIG_EXT_INTRA || CONFIG_FILTER_INTRA || CONFIG_PALETTE
Yaowu Xuf883b422016-08-30 14:01:10 -070039static INLINE int read_uniform(aom_reader *r, int n) {
hui su37499292017-04-26 09:49:53 -070040 const int l = get_unsigned_bits(n);
41 const int m = (1 << l) - n;
42 const int v = aom_read_literal(r, l - 1, ACCT_STR);
Yaowu Xuc27fc142016-08-22 16:08:15 -070043 assert(l != 0);
Yaowu Xuc27fc142016-08-22 16:08:15 -070044 if (v < m)
45 return v;
46 else
Michael Bebenita6048d052016-08-25 14:40:54 -070047 return (v << 1) - m + aom_read_literal(r, 1, ACCT_STR);
Yaowu Xuc27fc142016-08-22 16:08:15 -070048}
hui su5db97432016-10-14 16:10:14 -070049#endif // CONFIG_EXT_INTRA || CONFIG_FILTER_INTRA || CONFIG_PALETTE
Yaowu Xuc27fc142016-08-22 16:08:15 -070050
Thomas9ac55082016-09-23 18:04:17 +010051static PREDICTION_MODE read_intra_mode(aom_reader *r, aom_cdf_prob *cdf) {
Nathan E. Egge3ef926e2016-09-07 18:20:41 -040052 return (PREDICTION_MODE)
53 av1_intra_mode_inv[aom_read_symbol(r, cdf, INTRA_MODES, ACCT_STR)];
54}
Yaowu Xuc27fc142016-08-22 16:08:15 -070055
Thomas Daviesf6936102016-09-05 16:51:31 +010056#if CONFIG_DELTA_Q
57static int read_delta_qindex(AV1_COMMON *cm, MACROBLOCKD *xd, aom_reader *r,
58 MB_MODE_INFO *const mbmi, int mi_col, int mi_row) {
59 FRAME_COUNTS *counts = xd->counts;
60 int sign, abs, reduced_delta_qindex = 0;
61 BLOCK_SIZE bsize = mbmi->sb_type;
62 const int b_col = mi_col & MAX_MIB_MASK;
63 const int b_row = mi_row & MAX_MIB_MASK;
64 const int read_delta_q_flag = (b_col == 0 && b_row == 0);
Thomas Daviesd6ee8a82017-03-02 14:42:50 +000065 int rem_bits, thr;
66 int i, smallval;
Thomas Daviesd6ee8a82017-03-02 14:42:50 +000067 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
68 (void)cm;
Thomas Daviesf6936102016-09-05 16:51:31 +010069
Alex Converse68abef82017-03-23 14:50:33 -070070 if ((bsize != BLOCK_LARGEST || mbmi->skip == 0) && read_delta_q_flag) {
Thomas Daviesd6ee8a82017-03-02 14:42:50 +000071 abs = aom_read_symbol(r, ec_ctx->delta_q_cdf, DELTA_Q_PROBS + 1, ACCT_STR);
Thomas Daviesd6ee8a82017-03-02 14:42:50 +000072 smallval = (abs < DELTA_Q_SMALL);
73 if (counts) {
74 for (i = 0; i < abs; ++i) counts->delta_q[i][1]++;
75 if (smallval) counts->delta_q[abs][0]++;
76 }
77
78 if (!smallval) {
Thomas Daviesf6936102016-09-05 16:51:31 +010079 rem_bits = aom_read_literal(r, 3, ACCT_STR);
80 thr = (1 << rem_bits) + 1;
81 abs = aom_read_literal(r, rem_bits, ACCT_STR) + thr;
82 }
83
84 if (abs) {
85 sign = aom_read_bit(r, ACCT_STR);
86 } else {
87 sign = 1;
88 }
89
90 reduced_delta_qindex = sign ? -abs : abs;
91 }
92 return reduced_delta_qindex;
93}
Fangwen Fu231fe422017-04-24 17:52:29 -070094#if CONFIG_EXT_DELTA_Q
95static int read_delta_lflevel(AV1_COMMON *cm, MACROBLOCKD *xd, aom_reader *r,
96 MB_MODE_INFO *const mbmi, int mi_col,
97 int mi_row) {
98 FRAME_COUNTS *counts = xd->counts;
99 int sign, abs, reduced_delta_lflevel = 0;
100 BLOCK_SIZE bsize = mbmi->sb_type;
101 const int b_col = mi_col & MAX_MIB_MASK;
102 const int b_row = mi_row & MAX_MIB_MASK;
103 const int read_delta_lf_flag = (b_col == 0 && b_row == 0);
104 int rem_bits, thr;
105 int i, smallval;
Fangwen Fu231fe422017-04-24 17:52:29 -0700106 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
107 (void)cm;
Fangwen Fu231fe422017-04-24 17:52:29 -0700108
109 if ((bsize != BLOCK_64X64 || mbmi->skip == 0) && read_delta_lf_flag) {
Fangwen Fu231fe422017-04-24 17:52:29 -0700110 abs =
111 aom_read_symbol(r, ec_ctx->delta_lf_cdf, DELTA_LF_PROBS + 1, ACCT_STR);
Fangwen Fu231fe422017-04-24 17:52:29 -0700112 smallval = (abs < DELTA_LF_SMALL);
113 if (counts) {
114 for (i = 0; i < abs; ++i) counts->delta_lf[i][1]++;
115 if (smallval) counts->delta_lf[abs][0]++;
116 }
117 if (!smallval) {
118 rem_bits = aom_read_literal(r, 3, ACCT_STR);
119 thr = (1 << rem_bits) + 1;
120 abs = aom_read_literal(r, rem_bits, ACCT_STR) + thr;
121 }
122
123 if (abs) {
124 sign = aom_read_bit(r, ACCT_STR);
125 } else {
126 sign = 1;
127 }
128
129 reduced_delta_lflevel = sign ? -abs : abs;
130 }
131 return reduced_delta_lflevel;
132}
133#endif
Thomas Daviesf6936102016-09-05 16:51:31 +0100134#endif
135
Nathan E. Eggea1f80e32017-05-23 11:52:32 -0400136static PREDICTION_MODE read_intra_mode_y(FRAME_CONTEXT *ec_ctx, MACROBLOCKD *xd,
Yaowu Xuf883b422016-08-30 14:01:10 -0700137 aom_reader *r, int size_group) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700138 const PREDICTION_MODE y_mode =
Thomas Davies1bfb5ed2017-01-11 15:28:11 +0000139 read_intra_mode(r, ec_ctx->y_mode_cdf[size_group]);
Nathan E. Egge6bdc40f2017-06-18 19:02:23 -0400140#if CONFIG_ENTROPY_STATS
Yaowu Xuc27fc142016-08-22 16:08:15 -0700141 FRAME_COUNTS *counts = xd->counts;
142 if (counts) ++counts->y_mode[size_group][y_mode];
Nathan E. Egge5bb3a742017-06-30 12:47:43 -0400143#else
144 /* TODO(negge): Can we remove this parameter? */
145 (void)xd;
Nathan E. Egge6bdc40f2017-06-18 19:02:23 -0400146#endif // CONFIG_ENTROPY_STATS
Yaowu Xuc27fc142016-08-22 16:08:15 -0700147 return y_mode;
148}
149
Nathan E. Eggea1f80e32017-05-23 11:52:32 -0400150static PREDICTION_MODE read_intra_mode_uv(FRAME_CONTEXT *ec_ctx,
151 MACROBLOCKD *xd, aom_reader *r,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700152 PREDICTION_MODE y_mode) {
153 const PREDICTION_MODE uv_mode =
Thomas Davies1bfb5ed2017-01-11 15:28:11 +0000154 read_intra_mode(r, ec_ctx->uv_mode_cdf[y_mode]);
Nathan E. Egge6bdc40f2017-06-18 19:02:23 -0400155#if CONFIG_ENTROPY_STATS
Yaowu Xuc27fc142016-08-22 16:08:15 -0700156 FRAME_COUNTS *counts = xd->counts;
157 if (counts) ++counts->uv_mode[y_mode][uv_mode];
Nathan E. Egge5bb3a742017-06-30 12:47:43 -0400158#else
159 /* TODO(negge): Can we remove this parameter? */
160 (void)xd;
Nathan E. Egge6bdc40f2017-06-18 19:02:23 -0400161#endif // CONFIG_ENTROPY_STATS
Yaowu Xuc27fc142016-08-22 16:08:15 -0700162 return uv_mode;
163}
164
Luc Trudeauf5334002017-04-25 12:21:26 -0400165#if CONFIG_CFL
David Michael Barr23198662017-06-19 23:19:48 +0900166static int read_cfl_alphas(FRAME_CONTEXT *const ec_ctx, aom_reader *r,
Luc Trudeau2c317902017-04-28 11:06:50 -0400167 CFL_SIGN_TYPE signs_out[CFL_PRED_PLANES]) {
David Michael Barr23198662017-06-19 23:19:48 +0900168 const int ind =
169 aom_read_symbol(r, ec_ctx->cfl_alpha_cdf, CFL_ALPHABET_SIZE, "cfl:alpha");
170 // Signs are only coded for nonzero values
171 // sign == 0 implies negative alpha
172 // sign == 1 implies positive alpha
173 signs_out[CFL_PRED_U] = cfl_alpha_codes[ind][CFL_PRED_U]
174 ? aom_read_bit(r, "cfl:sign")
175 : CFL_SIGN_POS;
176 signs_out[CFL_PRED_V] = cfl_alpha_codes[ind][CFL_PRED_V]
177 ? aom_read_bit(r, "cfl:sign")
178 : CFL_SIGN_POS;
Luc Trudeauf5334002017-04-25 12:21:26 -0400179
David Michael Barr23198662017-06-19 23:19:48 +0900180 return ind;
Luc Trudeauf5334002017-04-25 12:21:26 -0400181}
182#endif
183
Yue Chen4d26acb2017-05-01 12:28:34 -0700184#if CONFIG_EXT_INTER && CONFIG_INTERINTRA
Yaowu Xuf883b422016-08-30 14:01:10 -0700185static INTERINTRA_MODE read_interintra_mode(AV1_COMMON *cm, MACROBLOCKD *xd,
186 aom_reader *r, int size_group) {
Thomas Davies299ff042017-06-27 13:41:59 +0100187 (void)cm;
188 const INTERINTRA_MODE ii_mode = (INTERINTRA_MODE)aom_read_symbol(
189 r, xd->tile_ctx->interintra_mode_cdf[size_group], INTERINTRA_MODES,
190 ACCT_STR);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700191 FRAME_COUNTS *counts = xd->counts;
192 if (counts) ++counts->interintra_mode[size_group][ii_mode];
193 return ii_mode;
194}
Yue Chen4d26acb2017-05-01 12:28:34 -0700195#endif // CONFIG_EXT_INTER && CONFIG_INTERINTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -0700196
Thomas Davies1de6c882017-01-11 17:47:49 +0000197static PREDICTION_MODE read_inter_mode(FRAME_CONTEXT *ec_ctx, MACROBLOCKD *xd,
Yaowu Xuf883b422016-08-30 14:01:10 -0700198 aom_reader *r, int16_t ctx) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700199 FRAME_COUNTS *counts = xd->counts;
200 int16_t mode_ctx = ctx & NEWMV_CTX_MASK;
Thomas Davies149eda52017-06-12 18:11:55 +0100201 int is_newmv, is_zeromv, is_refmv;
202#if CONFIG_NEW_MULTISYMBOL
203 is_newmv = aom_read_symbol(r, ec_ctx->newmv_cdf[mode_ctx], 2, ACCT_STR) == 0;
204#else
205 is_newmv = aom_read(r, ec_ctx->newmv_prob[mode_ctx], ACCT_STR) == 0;
206#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700207
Thomas Davies149eda52017-06-12 18:11:55 +0100208 if (is_newmv) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700209 if (counts) ++counts->newmv_mode[mode_ctx][0];
Zoe Liu7f24e1b2017-03-17 17:42:05 -0700210 return NEWMV;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700211 }
212 if (counts) ++counts->newmv_mode[mode_ctx][1];
213
214 if (ctx & (1 << ALL_ZERO_FLAG_OFFSET)) return ZEROMV;
215
216 mode_ctx = (ctx >> ZEROMV_OFFSET) & ZEROMV_CTX_MASK;
217
Thomas Davies149eda52017-06-12 18:11:55 +0100218#if CONFIG_NEW_MULTISYMBOL
219 is_zeromv =
220 aom_read_symbol(r, ec_ctx->zeromv_cdf[mode_ctx], 2, ACCT_STR) == 0;
221#else
222 is_zeromv = aom_read(r, ec_ctx->zeromv_prob[mode_ctx], ACCT_STR) == 0;
223#endif
224 if (is_zeromv) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700225 if (counts) ++counts->zeromv_mode[mode_ctx][0];
226 return ZEROMV;
227 }
228 if (counts) ++counts->zeromv_mode[mode_ctx][1];
229
230 mode_ctx = (ctx >> REFMV_OFFSET) & REFMV_CTX_MASK;
231
232 if (ctx & (1 << SKIP_NEARESTMV_OFFSET)) mode_ctx = 6;
233 if (ctx & (1 << SKIP_NEARMV_OFFSET)) mode_ctx = 7;
234 if (ctx & (1 << SKIP_NEARESTMV_SUB8X8_OFFSET)) mode_ctx = 8;
235
Thomas Davies149eda52017-06-12 18:11:55 +0100236#if CONFIG_NEW_MULTISYMBOL
237 is_refmv = aom_read_symbol(r, ec_ctx->refmv_cdf[mode_ctx], 2, ACCT_STR) == 0;
238#else
239 is_refmv = aom_read(r, ec_ctx->refmv_prob[mode_ctx], ACCT_STR) == 0;
240#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700241
Thomas Davies149eda52017-06-12 18:11:55 +0100242 if (is_refmv) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700243 if (counts) ++counts->refmv_mode[mode_ctx][0];
244
245 return NEARESTMV;
246 } else {
247 if (counts) ++counts->refmv_mode[mode_ctx][1];
248 return NEARMV;
249 }
250
251 // Invalid prediction mode.
252 assert(0);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700253}
254
Thomas Davies149eda52017-06-12 18:11:55 +0100255static void read_drl_idx(FRAME_CONTEXT *ec_ctx, MACROBLOCKD *xd,
Yaowu Xuf883b422016-08-30 14:01:10 -0700256 MB_MODE_INFO *mbmi, aom_reader *r) {
257 uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700258 mbmi->ref_mv_idx = 0;
259
David Barker404b2e82017-03-27 13:07:47 +0100260#if CONFIG_EXT_INTER
Zoe Liu85b66462017-04-20 14:28:19 -0700261#if CONFIG_COMPOUND_SINGLEREF
262 if (mbmi->mode == NEWMV || mbmi->mode == NEW_NEWMV ||
263 mbmi->mode == SR_NEW_NEWMV) {
264#else // !CONFIG_COMPOUND_SINGLEREF
David Barker404b2e82017-03-27 13:07:47 +0100265 if (mbmi->mode == NEWMV || mbmi->mode == NEW_NEWMV) {
Zoe Liu85b66462017-04-20 14:28:19 -0700266#endif // CONFIG_COMPOUND_SINGLEREF
267#else // !CONFIG_EXT_INTER
Yaowu Xuc27fc142016-08-22 16:08:15 -0700268 if (mbmi->mode == NEWMV) {
Zoe Liu85b66462017-04-20 14:28:19 -0700269#endif // CONFIG_EXT_INTER
Yaowu Xuc27fc142016-08-22 16:08:15 -0700270 int idx;
271 for (idx = 0; idx < 2; ++idx) {
272 if (xd->ref_mv_count[ref_frame_type] > idx + 1) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700273 uint8_t drl_ctx = av1_drl_ctx(xd->ref_mv_stack[ref_frame_type], idx);
Thomas Davies149eda52017-06-12 18:11:55 +0100274#if CONFIG_NEW_MULTISYMBOL
275 int drl_idx = aom_read_symbol(r, ec_ctx->drl_cdf[drl_ctx], 2, ACCT_STR);
276#else
277 int drl_idx = aom_read(r, ec_ctx->drl_prob[drl_ctx], ACCT_STR);
278#endif
279 mbmi->ref_mv_idx = idx + drl_idx;
280 if (xd->counts) ++xd->counts->drl_mode[drl_ctx][drl_idx];
281 if (!drl_idx) return;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700282 }
283 }
284 }
285
David Barker3dfba992017-04-03 16:10:09 +0100286 if (have_nearmv_in_inter_mode(mbmi->mode)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700287 int idx;
288 // Offset the NEARESTMV mode.
289 // TODO(jingning): Unify the two syntax decoding loops after the NEARESTMV
290 // mode is factored in.
291 for (idx = 1; idx < 3; ++idx) {
292 if (xd->ref_mv_count[ref_frame_type] > idx + 1) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700293 uint8_t drl_ctx = av1_drl_ctx(xd->ref_mv_stack[ref_frame_type], idx);
Thomas Davies149eda52017-06-12 18:11:55 +0100294#if CONFIG_NEW_MULTISYMBOL
295 int drl_idx = aom_read_symbol(r, ec_ctx->drl_cdf[drl_ctx], 2, ACCT_STR);
296#else
297 int drl_idx = aom_read(r, ec_ctx->drl_prob[drl_ctx], ACCT_STR);
298#endif
299 mbmi->ref_mv_idx = idx + drl_idx - 1;
300 if (xd->counts) ++xd->counts->drl_mode[drl_ctx][drl_idx];
301 if (!drl_idx) return;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700302 }
303 }
304 }
305}
Yaowu Xuc27fc142016-08-22 16:08:15 -0700306
Yaowu Xub24e1152016-10-31 16:28:32 -0700307#if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
308static MOTION_MODE read_motion_mode(AV1_COMMON *cm, MACROBLOCKD *xd,
Sarah Parker19234cc2017-03-10 16:43:25 -0800309 MODE_INFO *mi, aom_reader *r) {
310 MB_MODE_INFO *mbmi = &mi->mbmi;
Thomas Davies04e5aa72017-06-28 14:36:39 +0100311#if CONFIG_NEW_MULTISYMBOL
312 (void)cm;
313#endif
314
Wei-Ting Lind0f7ba12017-06-30 14:59:57 -0700315#if CONFIG_NCOBMC_ADAPT_WEIGHT
316 const MOTION_MODE last_motion_mode_allowed =
317 motion_mode_allowed_wrapper(0,
Sarah Parker0eea89f2017-07-11 11:56:36 -0700318#if CONFIG_GLOBAL_MOTION
Wei-Ting Lind0f7ba12017-06-30 14:59:57 -0700319 0, xd->global_motion,
Sarah Parker0eea89f2017-07-11 11:56:36 -0700320#endif // CONFIG_GLOBAL_MOTION
Yue Chen52c51732017-07-11 15:08:30 -0700321#if CONFIG_WARPED_MOTION
322 xd,
323#endif
Wei-Ting Lind0f7ba12017-06-30 14:59:57 -0700324 mi);
325#else
Sarah Parker19234cc2017-03-10 16:43:25 -0800326 const MOTION_MODE last_motion_mode_allowed = motion_mode_allowed(
Sarah Parker0eea89f2017-07-11 11:56:36 -0700327#if CONFIG_GLOBAL_MOTION
Sarah Parker19234cc2017-03-10 16:43:25 -0800328 0, xd->global_motion,
Sarah Parker0eea89f2017-07-11 11:56:36 -0700329#endif // CONFIG_GLOBAL_MOTION
Yue Chen52c51732017-07-11 15:08:30 -0700330#if CONFIG_WARPED_MOTION
331 xd,
332#endif
Sarah Parker19234cc2017-03-10 16:43:25 -0800333 mi);
Wei-Ting Lind0f7ba12017-06-30 14:59:57 -0700334#endif // CONFIG_NCOBMC_ADAPT_WEIGHT
Yue Chen69f18e12016-09-08 14:48:15 -0700335 int motion_mode;
336 FRAME_COUNTS *counts = xd->counts;
Yaowu Xub24e1152016-10-31 16:28:32 -0700337
Yue Chen69f18e12016-09-08 14:48:15 -0700338 if (last_motion_mode_allowed == SIMPLE_TRANSLATION) return SIMPLE_TRANSLATION;
339#if CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
340 if (last_motion_mode_allowed == OBMC_CAUSAL) {
Thomas Daviesd9b57262017-06-27 17:43:25 +0100341#if CONFIG_NEW_MULTISYMBOL
342 motion_mode =
343 aom_read_symbol(r, xd->tile_ctx->obmc_cdf[mbmi->sb_type], 2, ACCT_STR);
344#else
Yue Chen69f18e12016-09-08 14:48:15 -0700345 motion_mode = aom_read(r, cm->fc->obmc_prob[mbmi->sb_type], ACCT_STR);
Thomas Daviesd9b57262017-06-27 17:43:25 +0100346#endif
Yue Chen69f18e12016-09-08 14:48:15 -0700347 if (counts) ++counts->obmc[mbmi->sb_type][motion_mode];
348 return (MOTION_MODE)(SIMPLE_TRANSLATION + motion_mode);
349 } else {
350#endif // CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
Yaowu Xub24e1152016-10-31 16:28:32 -0700351 motion_mode =
Thomas Davies04e5aa72017-06-28 14:36:39 +0100352 aom_read_symbol(r, xd->tile_ctx->motion_mode_cdf[mbmi->sb_type],
353 MOTION_MODES, ACCT_STR);
Yaowu Xub24e1152016-10-31 16:28:32 -0700354 if (counts) ++counts->motion_mode[mbmi->sb_type][motion_mode];
355 return (MOTION_MODE)(SIMPLE_TRANSLATION + motion_mode);
Yue Chen69f18e12016-09-08 14:48:15 -0700356#if CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
Yaowu Xub24e1152016-10-31 16:28:32 -0700357 }
Yue Chen69f18e12016-09-08 14:48:15 -0700358#endif // CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
Yaowu Xub24e1152016-10-31 16:28:32 -0700359}
Wei-Ting Lin85a8f702017-06-22 13:55:15 -0700360
361#if CONFIG_NCOBMC_ADAPT_WEIGHT
Wei-Ting Linca710d62017-07-13 11:41:02 -0700362static void read_ncobmc_mode(MACROBLOCKD *xd, MODE_INFO *mi,
363#ifndef TRAINING_WEIGHTS
364 NCOBMC_MODE ncobmc_mode[2],
365#else
366 NCOBMC_MODE ncobmc_mode[][4],
367#endif
368 aom_reader *r) {
Wei-Ting Lin85a8f702017-06-22 13:55:15 -0700369 MB_MODE_INFO *mbmi = &mi->mbmi;
370 FRAME_COUNTS *counts = xd->counts;
371 ADAPT_OVERLAP_BLOCK ao_block = adapt_overlap_block_lookup[mbmi->sb_type];
Wei-Ting Lin77c41182017-07-12 15:58:35 -0700372 if (mbmi->motion_mode != NCOBMC_ADAPT_WEIGHT) return;
Wei-Ting Lin85a8f702017-06-22 13:55:15 -0700373
Wei-Ting Linca710d62017-07-13 11:41:02 -0700374#ifndef TRAINING_WEIGHTS
375 ncobmc_mode[0] = aom_read_symbol(r, xd->tile_ctx->ncobmc_mode_cdf[ao_block],
376 MAX_NCOBMC_MODES, ACCT_STR);
Wei-Ting Lin85a8f702017-06-22 13:55:15 -0700377 if (counts) ++counts->ncobmc_mode[ao_block][ncobmc_mode[0]];
378
379 if (mi_size_wide[mbmi->sb_type] != mi_size_high[mbmi->sb_type]) {
Wei-Ting Linca710d62017-07-13 11:41:02 -0700380 ncobmc_mode[1] = aom_read_symbol(r, xd->tile_ctx->ncobmc_mode_cdf[ao_block],
381 MAX_NCOBMC_MODES, ACCT_STR);
Wei-Ting Lin85a8f702017-06-22 13:55:15 -0700382 if (counts) ++counts->ncobmc_mode[ao_block][ncobmc_mode[1]];
383 }
Wei-Ting Linca710d62017-07-13 11:41:02 -0700384#else
385 int i;
386 for (i = 0; i < 4; ++i) {
387 ncobmc_mode[0][i] = aom_read_symbol(
388 r, xd->tile_ctx->ncobmc_mode_cdf[ao_block], MAX_NCOBMC_MODES, ACCT_STR);
389 if (counts) ++counts->ncobmc_mode[ao_block][ncobmc_mode[0][i]];
390 }
391 if (mi_size_wide[mbmi->sb_type] != mi_size_high[mbmi->sb_type]) {
392 for (i = 0; i < 4; ++i) {
393 ncobmc_mode[1][i] =
394 aom_read_symbol(r, xd->tile_ctx->ncobmc_mode_cdf[ao_block],
395 MAX_NCOBMC_MODES, ACCT_STR);
396 if (counts) ++counts->ncobmc_mode[ao_block][ncobmc_mode[1][i]];
397 }
398 }
399#endif
Wei-Ting Lin85a8f702017-06-22 13:55:15 -0700400}
401#endif
Yaowu Xub24e1152016-10-31 16:28:32 -0700402#endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
403
Yaowu Xuc27fc142016-08-22 16:08:15 -0700404#if CONFIG_EXT_INTER
Yaowu Xuf883b422016-08-30 14:01:10 -0700405static PREDICTION_MODE read_inter_compound_mode(AV1_COMMON *cm, MACROBLOCKD *xd,
406 aom_reader *r, int16_t ctx) {
Thomas Davies8c08a332017-06-26 17:30:34 +0100407 (void)cm;
408 const int mode =
409 aom_read_symbol(r, xd->tile_ctx->inter_compound_mode_cdf[ctx],
410 INTER_COMPOUND_MODES, ACCT_STR);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700411 FRAME_COUNTS *counts = xd->counts;
412
413 if (counts) ++counts->inter_compound_mode[ctx][mode];
414
415 assert(is_inter_compound_mode(NEAREST_NEARESTMV + mode));
416 return NEAREST_NEARESTMV + mode;
417}
Zoe Liu85b66462017-04-20 14:28:19 -0700418
419#if CONFIG_COMPOUND_SINGLEREF
Thomas Daviesb8b14a92017-07-12 15:11:49 +0100420static PREDICTION_MODE read_inter_singleref_comp_mode(MACROBLOCKD *xd,
Zoe Liu85b66462017-04-20 14:28:19 -0700421 aom_reader *r,
422 int16_t ctx) {
423 const int mode =
Thomas Daviesb8b14a92017-07-12 15:11:49 +0100424 aom_read_symbol(r, xd->tile_ctx->inter_singleref_comp_mode_cdf[ctx],
425 INTER_SINGLEREF_COMP_MODES, ACCT_STR);
Zoe Liu85b66462017-04-20 14:28:19 -0700426 FRAME_COUNTS *counts = xd->counts;
427
428 if (counts) ++counts->inter_singleref_comp_mode[ctx][mode];
429
430 assert(is_inter_singleref_comp_mode(SR_NEAREST_NEARMV + mode));
431 return SR_NEAREST_NEARMV + mode;
432}
433#endif // CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -0700434#endif // CONFIG_EXT_INTER
435
Thomas9ac55082016-09-23 18:04:17 +0100436static int read_segment_id(aom_reader *r, struct segmentation_probs *segp) {
Michael Bebenita6048d052016-08-25 14:40:54 -0700437 return aom_read_symbol(r, segp->tree_cdf, MAX_SEGMENTS, ACCT_STR);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700438}
439
440#if CONFIG_VAR_TX
Yaowu Xuf883b422016-08-30 14:01:10 -0700441static void read_tx_size_vartx(AV1_COMMON *cm, MACROBLOCKD *xd,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700442 MB_MODE_INFO *mbmi, FRAME_COUNTS *counts,
Jingning Han94d5bfc2016-10-21 10:14:36 -0700443 TX_SIZE tx_size, int depth, int blk_row,
444 int blk_col, aom_reader *r) {
Thomas Davies985bfc32017-06-27 16:51:26 +0100445#if CONFIG_NEW_MULTISYMBOL
446 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
447 (void)cm;
448#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700449 int is_split = 0;
450 const int tx_row = blk_row >> 1;
451 const int tx_col = blk_col >> 1;
Jingning Hanf64062f2016-11-02 16:22:18 -0700452 const int max_blocks_high = max_block_high(xd, mbmi->sb_type, 0);
453 const int max_blocks_wide = max_block_wide(xd, mbmi->sb_type, 0);
Jingning Han331662e2017-05-30 17:03:32 -0700454 int ctx = txfm_partition_context(xd->above_txfm_context + blk_col,
455 xd->left_txfm_context + blk_row,
Jingning Hanc8b89362016-11-01 10:28:53 -0700456 mbmi->sb_type, tx_size);
clang-format67948d32016-09-07 22:40:40 -0700457 TX_SIZE(*const inter_tx_size)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700458 [MAX_MIB_SIZE] =
459 (TX_SIZE(*)[MAX_MIB_SIZE]) & mbmi->inter_tx_size[tx_row][tx_col];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700460 if (blk_row >= max_blocks_high || blk_col >= max_blocks_wide) return;
461
Jingning Han571189c2016-10-24 10:38:43 -0700462 if (depth == MAX_VARTX_DEPTH) {
Jingning Han94d5bfc2016-10-21 10:14:36 -0700463 int idx, idy;
464 inter_tx_size[0][0] = tx_size;
Jingning Han65abc312016-10-27 13:04:21 -0700465 for (idy = 0; idy < tx_size_high_unit[tx_size] / 2; ++idy)
466 for (idx = 0; idx < tx_size_wide_unit[tx_size] / 2; ++idx)
Jingning Han94d5bfc2016-10-21 10:14:36 -0700467 inter_tx_size[idy][idx] = tx_size;
468 mbmi->tx_size = tx_size;
Jingning Hane67b38a2016-11-04 10:30:00 -0700469 mbmi->min_tx_size = AOMMIN(mbmi->min_tx_size, get_min_tx_size(tx_size));
Jingning Han94d5bfc2016-10-21 10:14:36 -0700470 if (counts) ++counts->txfm_partition[ctx][0];
Jingning Han331662e2017-05-30 17:03:32 -0700471 txfm_partition_update(xd->above_txfm_context + blk_col,
472 xd->left_txfm_context + blk_row, tx_size, tx_size);
Jingning Han94d5bfc2016-10-21 10:14:36 -0700473 return;
474 }
475
Thomas Davies985bfc32017-06-27 16:51:26 +0100476#if CONFIG_NEW_MULTISYMBOL
477 is_split = aom_read_symbol(r, ec_ctx->txfm_partition_cdf[ctx], 2, ACCT_STR);
478#else
Michael Bebenita6048d052016-08-25 14:40:54 -0700479 is_split = aom_read(r, cm->fc->txfm_partition_prob[ctx], ACCT_STR);
Thomas Davies985bfc32017-06-27 16:51:26 +0100480#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700481
482 if (is_split) {
Jingning Hanf64062f2016-11-02 16:22:18 -0700483 const TX_SIZE sub_txs = sub_tx_size_map[tx_size];
484 const int bsl = tx_size_wide_unit[sub_txs];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700485 int i;
486
487 if (counts) ++counts->txfm_partition[ctx][1];
488
489 if (tx_size == TX_8X8) {
Jingning Han9ca05b72017-01-03 14:41:36 -0800490 int idx, idy;
Jingning Hanab9ecba2017-01-13 09:11:58 -0800491 inter_tx_size[0][0] = sub_txs;
Jingning Han9ca05b72017-01-03 14:41:36 -0800492 for (idy = 0; idy < tx_size_high_unit[tx_size] / 2; ++idy)
493 for (idx = 0; idx < tx_size_wide_unit[tx_size] / 2; ++idx)
Jingning Han581d1692017-01-05 16:03:54 -0800494 inter_tx_size[idy][idx] = inter_tx_size[0][0];
Jingning Hanab9ecba2017-01-13 09:11:58 -0800495 mbmi->tx_size = sub_txs;
Jingning Hane67b38a2016-11-04 10:30:00 -0700496 mbmi->min_tx_size = get_min_tx_size(mbmi->tx_size);
Jingning Han331662e2017-05-30 17:03:32 -0700497 txfm_partition_update(xd->above_txfm_context + blk_col,
498 xd->left_txfm_context + blk_row, sub_txs, tx_size);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700499 return;
500 }
501
502 assert(bsl > 0);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700503 for (i = 0; i < 4; ++i) {
Jingning Hanf64062f2016-11-02 16:22:18 -0700504 int offsetr = blk_row + (i >> 1) * bsl;
505 int offsetc = blk_col + (i & 0x01) * bsl;
506 read_tx_size_vartx(cm, xd, mbmi, counts, sub_txs, depth + 1, offsetr,
Jingning Han94d5bfc2016-10-21 10:14:36 -0700507 offsetc, r);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700508 }
509 } else {
510 int idx, idy;
511 inter_tx_size[0][0] = tx_size;
Jingning Han65abc312016-10-27 13:04:21 -0700512 for (idy = 0; idy < tx_size_high_unit[tx_size] / 2; ++idy)
513 for (idx = 0; idx < tx_size_wide_unit[tx_size] / 2; ++idx)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700514 inter_tx_size[idy][idx] = tx_size;
515 mbmi->tx_size = tx_size;
Jingning Hane67b38a2016-11-04 10:30:00 -0700516 mbmi->min_tx_size = AOMMIN(mbmi->min_tx_size, get_min_tx_size(tx_size));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700517 if (counts) ++counts->txfm_partition[ctx][0];
Jingning Han331662e2017-05-30 17:03:32 -0700518 txfm_partition_update(xd->above_txfm_context + blk_col,
519 xd->left_txfm_context + blk_row, tx_size, tx_size);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700520 }
521}
522#endif
523
Yaowu Xuf883b422016-08-30 14:01:10 -0700524static TX_SIZE read_selected_tx_size(AV1_COMMON *cm, MACROBLOCKD *xd,
525 int tx_size_cat, aom_reader *r) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700526 FRAME_COUNTS *counts = xd->counts;
527 const int ctx = get_tx_size_context(xd);
Thomas Davies15580c52017-03-09 13:53:42 +0000528 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
529 (void)cm;
Thomas Davies15580c52017-03-09 13:53:42 +0000530
Nathan E. Egge476c63c2017-05-18 18:35:16 -0400531 const int depth = aom_read_symbol(r, ec_ctx->tx_size_cdf[tx_size_cat][ctx],
532 tx_size_cat + 2, ACCT_STR);
Urvang Joshifeb925f2016-12-05 10:37:29 -0800533 const TX_SIZE tx_size = depth_to_tx_size(depth);
534#if CONFIG_RECT_TX
535 assert(!is_rect_tx(tx_size));
536#endif // CONFIG_RECT_TX
Jingning Han906be072016-10-26 11:04:31 -0700537 if (counts) ++counts->tx_size[tx_size_cat][ctx][depth];
Jingning Han4e1737a2016-10-25 16:05:02 -0700538 return tx_size;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700539}
540
Urvang Joshifeb925f2016-12-05 10:37:29 -0800541static TX_SIZE read_tx_size(AV1_COMMON *cm, MACROBLOCKD *xd, int is_inter,
542 int allow_select_inter, aom_reader *r) {
543 const TX_MODE tx_mode = cm->tx_mode;
544 const BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700545 if (xd->lossless[xd->mi[0]->mbmi.segment_id]) return TX_4X4;
Debargha Mukherjee428bbb22017-03-17 07:30:24 -0700546#if CONFIG_CB4X4 && (CONFIG_VAR_TX || CONFIG_EXT_TX) && CONFIG_RECT_TX
Jingning Han3daa4fd2017-01-20 10:33:50 -0800547 if (bsize > BLOCK_4X4) {
Jingning Han4be1a4d2017-01-06 10:59:20 -0800548#else
Yaowu Xuc27fc142016-08-22 16:08:15 -0700549 if (bsize >= BLOCK_8X8) {
Urvang Joshifeb925f2016-12-05 10:37:29 -0800550#endif // CONFIG_CB4X4 && CONFIG_VAR_TX
551 if ((!is_inter || allow_select_inter) && tx_mode == TX_MODE_SELECT) {
552 const int32_t tx_size_cat = is_inter ? inter_tx_size_cat_lookup[bsize]
553 : intra_tx_size_cat_lookup[bsize];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700554 const TX_SIZE coded_tx_size =
Urvang Joshifeb925f2016-12-05 10:37:29 -0800555 read_selected_tx_size(cm, xd, tx_size_cat, r);
Yue Chen3ca7dd92017-05-23 16:03:39 -0700556#if CONFIG_RECT_TX && (CONFIG_EXT_TX || CONFIG_VAR_TX)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700557 if (coded_tx_size > max_txsize_lookup[bsize]) {
558 assert(coded_tx_size == max_txsize_lookup[bsize] + 1);
Yue Chen3ca7dd92017-05-23 16:03:39 -0700559#if CONFIG_EXT_TX && CONFIG_RECT_TX_EXT
Yue Chen56e226e2017-05-02 16:21:40 -0700560 if (is_quarter_tx_allowed(xd, &xd->mi[0]->mbmi, is_inter)) {
561 int quarter_tx = aom_read(r, cm->fc->quarter_tx_size_prob, ACCT_STR);
562 FRAME_COUNTS *counts = xd->counts;
563
564 if (counts) ++counts->quarter_tx_size[quarter_tx];
565 return quarter_tx ? quarter_txsize_lookup[bsize]
566 : max_txsize_rect_lookup[bsize];
567 }
Yue Chen3ca7dd92017-05-23 16:03:39 -0700568#endif // CONFIG_EXT_TX && CONFIG_RECT_TX_EXT
Yue Chen56e226e2017-05-02 16:21:40 -0700569
Yaowu Xuc27fc142016-08-22 16:08:15 -0700570 return max_txsize_rect_lookup[bsize];
571 }
Peter de Rivaza7c81462016-09-26 14:20:13 +0100572#else
573 assert(coded_tx_size <= max_txsize_lookup[bsize]);
Yue Chen3ca7dd92017-05-23 16:03:39 -0700574#endif // CONFIG_RECT_TX && (CONFIG_EXT_TX || CONFIG_VAR_TX)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700575 return coded_tx_size;
576 } else {
Urvang Joshifeb925f2016-12-05 10:37:29 -0800577 return tx_size_from_tx_mode(bsize, tx_mode, is_inter);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700578 }
579 } else {
580#if CONFIG_EXT_TX && CONFIG_RECT_TX
581 assert(IMPLIES(tx_mode == ONLY_4X4, bsize == BLOCK_4X4));
582 return max_txsize_rect_lookup[bsize];
583#else
584 return TX_4X4;
Urvang Joshifeb925f2016-12-05 10:37:29 -0800585#endif // CONFIG_EXT_TX && CONFIG_RECT_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -0700586 }
587}
588
Yaowu Xuf883b422016-08-30 14:01:10 -0700589static int dec_get_segment_id(const AV1_COMMON *cm, const uint8_t *segment_ids,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700590 int mi_offset, int x_mis, int y_mis) {
591 int x, y, segment_id = INT_MAX;
592
593 for (y = 0; y < y_mis; y++)
594 for (x = 0; x < x_mis; x++)
595 segment_id =
Yaowu Xuf883b422016-08-30 14:01:10 -0700596 AOMMIN(segment_id, segment_ids[mi_offset + y * cm->mi_cols + x]);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700597
598 assert(segment_id >= 0 && segment_id < MAX_SEGMENTS);
599 return segment_id;
600}
601
Yaowu Xuf883b422016-08-30 14:01:10 -0700602static void set_segment_id(AV1_COMMON *cm, int mi_offset, int x_mis, int y_mis,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700603 int segment_id) {
604 int x, y;
605
606 assert(segment_id >= 0 && segment_id < MAX_SEGMENTS);
607
608 for (y = 0; y < y_mis; y++)
609 for (x = 0; x < x_mis; x++)
610 cm->current_frame_seg_map[mi_offset + y * cm->mi_cols + x] = segment_id;
611}
612
Yaowu Xuf883b422016-08-30 14:01:10 -0700613static int read_intra_segment_id(AV1_COMMON *const cm, MACROBLOCKD *const xd,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700614 int mi_offset, int x_mis, int y_mis,
Yaowu Xuf883b422016-08-30 14:01:10 -0700615 aom_reader *r) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700616 struct segmentation *const seg = &cm->seg;
617 FRAME_COUNTS *counts = xd->counts;
Thomas Davies9f5cedd2017-07-10 09:20:32 +0100618 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
Thomas Davies9f5cedd2017-07-10 09:20:32 +0100619 struct segmentation_probs *const segp = &ec_ctx->seg;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700620 int segment_id;
621
622 if (!seg->enabled) return 0; // Default for disabled segmentation
623
624 assert(seg->update_map && !seg->temporal_update);
625
626 segment_id = read_segment_id(r, segp);
627 if (counts) ++counts->seg.tree_total[segment_id];
628 set_segment_id(cm, mi_offset, x_mis, y_mis, segment_id);
629 return segment_id;
630}
631
Yaowu Xuf883b422016-08-30 14:01:10 -0700632static void copy_segment_id(const AV1_COMMON *cm,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700633 const uint8_t *last_segment_ids,
634 uint8_t *current_segment_ids, int mi_offset,
635 int x_mis, int y_mis) {
636 int x, y;
637
638 for (y = 0; y < y_mis; y++)
639 for (x = 0; x < x_mis; x++)
640 current_segment_ids[mi_offset + y * cm->mi_cols + x] =
641 last_segment_ids ? last_segment_ids[mi_offset + y * cm->mi_cols + x]
642 : 0;
643}
644
Yaowu Xuf883b422016-08-30 14:01:10 -0700645static int read_inter_segment_id(AV1_COMMON *const cm, MACROBLOCKD *const xd,
646 int mi_row, int mi_col, aom_reader *r) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700647 struct segmentation *const seg = &cm->seg;
648 FRAME_COUNTS *counts = xd->counts;
Thomas Davies9f5cedd2017-07-10 09:20:32 +0100649 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
Thomas Davies9f5cedd2017-07-10 09:20:32 +0100650 struct segmentation_probs *const segp = &ec_ctx->seg;
651
Yaowu Xuc27fc142016-08-22 16:08:15 -0700652 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
653 int predicted_segment_id, segment_id;
654 const int mi_offset = mi_row * cm->mi_cols + mi_col;
Jingning Hanc709e1f2016-12-06 14:48:09 -0800655 const int bw = mi_size_wide[mbmi->sb_type];
656 const int bh = mi_size_high[mbmi->sb_type];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700657
658 // TODO(slavarnway): move x_mis, y_mis into xd ?????
Yaowu Xuf883b422016-08-30 14:01:10 -0700659 const int x_mis = AOMMIN(cm->mi_cols - mi_col, bw);
660 const int y_mis = AOMMIN(cm->mi_rows - mi_row, bh);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700661
662 if (!seg->enabled) return 0; // Default for disabled segmentation
663
664 predicted_segment_id = cm->last_frame_seg_map
665 ? dec_get_segment_id(cm, cm->last_frame_seg_map,
666 mi_offset, x_mis, y_mis)
667 : 0;
668
669 if (!seg->update_map) {
670 copy_segment_id(cm, cm->last_frame_seg_map, cm->current_frame_seg_map,
671 mi_offset, x_mis, y_mis);
672 return predicted_segment_id;
673 }
674
675 if (seg->temporal_update) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700676 const int ctx = av1_get_pred_context_seg_id(xd);
Thomas Davies00021352017-07-11 16:07:55 +0100677#if CONFIG_NEW_MULTISYMBOL
678 aom_cdf_prob *pred_cdf = segp->pred_cdf[ctx];
679 mbmi->seg_id_predicted = aom_read_symbol(r, pred_cdf, 2, ACCT_STR);
680#else
Yaowu Xuf883b422016-08-30 14:01:10 -0700681 const aom_prob pred_prob = segp->pred_probs[ctx];
Michael Bebenita6048d052016-08-25 14:40:54 -0700682 mbmi->seg_id_predicted = aom_read(r, pred_prob, ACCT_STR);
Thomas Davies00021352017-07-11 16:07:55 +0100683#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700684 if (counts) ++counts->seg.pred[ctx][mbmi->seg_id_predicted];
685 if (mbmi->seg_id_predicted) {
686 segment_id = predicted_segment_id;
687 } else {
688 segment_id = read_segment_id(r, segp);
689 if (counts) ++counts->seg.tree_mispred[segment_id];
690 }
691 } else {
692 segment_id = read_segment_id(r, segp);
693 if (counts) ++counts->seg.tree_total[segment_id];
694 }
695 set_segment_id(cm, mi_offset, x_mis, y_mis, segment_id);
696 return segment_id;
697}
698
Yaowu Xuf883b422016-08-30 14:01:10 -0700699static int read_skip(AV1_COMMON *cm, const MACROBLOCKD *xd, int segment_id,
700 aom_reader *r) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700701 if (segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)) {
702 return 1;
703 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700704 const int ctx = av1_get_skip_context(xd);
Thomas Davies61e3e372017-04-04 16:10:23 +0100705#if CONFIG_NEW_MULTISYMBOL
706 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
707 const int skip = aom_read_symbol(r, ec_ctx->skip_cdfs[ctx], 2, ACCT_STR);
708#else
Michael Bebenita6048d052016-08-25 14:40:54 -0700709 const int skip = aom_read(r, cm->fc->skip_probs[ctx], ACCT_STR);
Thomas Davies61e3e372017-04-04 16:10:23 +0100710#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700711 FRAME_COUNTS *counts = xd->counts;
712 if (counts) ++counts->skip[ctx][skip];
713 return skip;
714 }
715}
716
Urvang Joshib100db72016-10-12 16:28:56 -0700717#if CONFIG_PALETTE
hui su33567b22017-04-30 16:40:19 -0700718#if CONFIG_PALETTE_DELTA_ENCODING
hui su33567b22017-04-30 16:40:19 -0700719static int uint16_compare(const void *a, const void *b) {
Urvang Joshi0ba850e2017-05-12 17:05:45 -0700720 const uint16_t va = *(const uint16_t *)a;
721 const uint16_t vb = *(const uint16_t *)b;
hui su33567b22017-04-30 16:40:19 -0700722 return va - vb;
723}
hui su33567b22017-04-30 16:40:19 -0700724
725static void read_palette_colors_y(MACROBLOCKD *const xd, int bit_depth,
726 PALETTE_MODE_INFO *const pmi, aom_reader *r) {
727 uint16_t color_cache[2 * PALETTE_MAX_SIZE];
728 const MODE_INFO *const above_mi = xd->above_mi;
729 const MODE_INFO *const left_mi = xd->left_mi;
730 const int n_cache = av1_get_palette_cache(above_mi, left_mi, 0, color_cache);
731 const int n = pmi->palette_size[0];
732 int idx = 0;
733 for (int i = 0; i < n_cache && idx < n; ++i)
734 if (aom_read_bit(r, ACCT_STR)) pmi->palette_colors[idx++] = color_cache[i];
735 if (idx < n) {
736 pmi->palette_colors[idx++] = aom_read_literal(r, bit_depth, ACCT_STR);
737 if (idx < n) {
738 const int min_bits = bit_depth - 3;
739 int bits = min_bits + aom_read_literal(r, 2, ACCT_STR);
740 int range = (1 << bit_depth) - pmi->palette_colors[idx - 1] - 1;
741 for (; idx < n; ++idx) {
742 const int delta = aom_read_literal(r, bits, ACCT_STR) + 1;
743 pmi->palette_colors[idx] = pmi->palette_colors[idx - 1] + delta;
744 range -= delta;
745 bits = AOMMIN(bits, av1_ceil_log2(range));
746 }
747 }
748 }
hui su33567b22017-04-30 16:40:19 -0700749 qsort(pmi->palette_colors, n, sizeof(pmi->palette_colors[0]), uint16_compare);
hui su33567b22017-04-30 16:40:19 -0700750}
751
752static void read_palette_colors_uv(MACROBLOCKD *const xd, int bit_depth,
753 PALETTE_MODE_INFO *const pmi,
754 aom_reader *r) {
755 const int n = pmi->palette_size[1];
756 // U channel colors.
757 uint16_t color_cache[2 * PALETTE_MAX_SIZE];
758 const MODE_INFO *const above_mi = xd->above_mi;
759 const MODE_INFO *const left_mi = xd->left_mi;
760 const int n_cache = av1_get_palette_cache(above_mi, left_mi, 1, color_cache);
761 int idx = PALETTE_MAX_SIZE;
762 for (int i = 0; i < n_cache && idx < PALETTE_MAX_SIZE + n; ++i)
763 if (aom_read_bit(r, ACCT_STR)) pmi->palette_colors[idx++] = color_cache[i];
764 if (idx < PALETTE_MAX_SIZE + n) {
765 pmi->palette_colors[idx++] = aom_read_literal(r, bit_depth, ACCT_STR);
766 if (idx < PALETTE_MAX_SIZE + n) {
767 const int min_bits = bit_depth - 3;
768 int bits = min_bits + aom_read_literal(r, 2, ACCT_STR);
769 int range = (1 << bit_depth) - pmi->palette_colors[idx - 1];
770 for (; idx < PALETTE_MAX_SIZE + n; ++idx) {
771 const int delta = aom_read_literal(r, bits, ACCT_STR);
772 pmi->palette_colors[idx] = pmi->palette_colors[idx - 1] + delta;
773 range -= delta;
774 bits = AOMMIN(bits, av1_ceil_log2(range));
775 }
776 }
777 }
hui su33567b22017-04-30 16:40:19 -0700778 qsort(pmi->palette_colors + PALETTE_MAX_SIZE, n,
779 sizeof(pmi->palette_colors[0]), uint16_compare);
hui su33567b22017-04-30 16:40:19 -0700780
781 // V channel colors.
782 if (aom_read_bit(r, ACCT_STR)) { // Delta encoding.
783 const int min_bits_v = bit_depth - 4;
784 const int max_val = 1 << bit_depth;
785 int bits = min_bits_v + aom_read_literal(r, 2, ACCT_STR);
786 pmi->palette_colors[2 * PALETTE_MAX_SIZE] =
787 aom_read_literal(r, bit_depth, ACCT_STR);
788 for (int i = 1; i < n; ++i) {
789 int delta = aom_read_literal(r, bits, ACCT_STR);
790 if (delta && aom_read_bit(r, ACCT_STR)) delta = -delta;
791 int val = (int)pmi->palette_colors[2 * PALETTE_MAX_SIZE + i - 1] + delta;
792 if (val < 0) val += max_val;
793 if (val >= max_val) val -= max_val;
794 pmi->palette_colors[2 * PALETTE_MAX_SIZE + i] = val;
795 }
796 } else {
797 for (int i = 0; i < n; ++i) {
798 pmi->palette_colors[2 * PALETTE_MAX_SIZE + i] =
799 aom_read_literal(r, bit_depth, ACCT_STR);
800 }
801 }
802}
803#endif // CONFIG_PALETTE_DELTA_ENCODING
804
Yaowu Xuf883b422016-08-30 14:01:10 -0700805static void read_palette_mode_info(AV1_COMMON *const cm, MACROBLOCKD *const xd,
806 aom_reader *r) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700807 MODE_INFO *const mi = xd->mi[0];
808 MB_MODE_INFO *const mbmi = &mi->mbmi;
809 const MODE_INFO *const above_mi = xd->above_mi;
810 const MODE_INFO *const left_mi = xd->left_mi;
811 const BLOCK_SIZE bsize = mbmi->sb_type;
hui su33567b22017-04-30 16:40:19 -0700812 int n;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700813 PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info;
814
815 if (mbmi->mode == DC_PRED) {
Urvang Joshi23a61112017-01-30 14:59:27 -0800816 int palette_y_mode_ctx = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700817 if (above_mi)
Urvang Joshi23a61112017-01-30 14:59:27 -0800818 palette_y_mode_ctx +=
819 (above_mi->mbmi.palette_mode_info.palette_size[0] > 0);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700820 if (left_mi)
Urvang Joshi23a61112017-01-30 14:59:27 -0800821 palette_y_mode_ctx +=
822 (left_mi->mbmi.palette_mode_info.palette_size[0] > 0);
823 if (aom_read(r, av1_default_palette_y_mode_prob[bsize - BLOCK_8X8]
824 [palette_y_mode_ctx],
825 ACCT_STR)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700826 pmi->palette_size[0] =
Thomas Daviesce7272d2017-07-04 16:11:08 +0100827#if CONFIG_NEW_MULTISYMBOL
828 aom_read_symbol(r,
829 xd->tile_ctx->palette_y_size_cdf[bsize - BLOCK_8X8],
830 PALETTE_SIZES, ACCT_STR) +
831 2;
832#else
Yaowu Xuf883b422016-08-30 14:01:10 -0700833 aom_read_tree(r, av1_palette_size_tree,
Michael Bebenita6048d052016-08-25 14:40:54 -0700834 av1_default_palette_y_size_prob[bsize - BLOCK_8X8],
835 ACCT_STR) +
Yaowu Xuc27fc142016-08-22 16:08:15 -0700836 2;
Thomas Daviesce7272d2017-07-04 16:11:08 +0100837#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700838 n = pmi->palette_size[0];
hui sud13c24a2017-04-07 16:13:07 -0700839#if CONFIG_PALETTE_DELTA_ENCODING
hui su33567b22017-04-30 16:40:19 -0700840 read_palette_colors_y(xd, cm->bit_depth, pmi, r);
hui sud13c24a2017-04-07 16:13:07 -0700841#else
hui su33567b22017-04-30 16:40:19 -0700842 int i;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700843 for (i = 0; i < n; ++i)
Michael Bebenita6048d052016-08-25 14:40:54 -0700844 pmi->palette_colors[i] = aom_read_literal(r, cm->bit_depth, ACCT_STR);
hui sud13c24a2017-04-07 16:13:07 -0700845#endif // CONFIG_PALETTE_DELTA_ENCODING
Yaowu Xuc27fc142016-08-22 16:08:15 -0700846 xd->plane[0].color_index_map[0] = read_uniform(r, n);
847 assert(xd->plane[0].color_index_map[0] < n);
848 }
849 }
850
851 if (mbmi->uv_mode == DC_PRED) {
Urvang Joshi23a61112017-01-30 14:59:27 -0800852 const int palette_uv_mode_ctx = (pmi->palette_size[0] > 0);
853 if (aom_read(r, av1_default_palette_uv_mode_prob[palette_uv_mode_ctx],
Michael Bebenita6048d052016-08-25 14:40:54 -0700854 ACCT_STR)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700855 pmi->palette_size[1] =
Thomas Daviesce7272d2017-07-04 16:11:08 +0100856#if CONFIG_NEW_MULTISYMBOL
857 aom_read_symbol(r,
858 xd->tile_ctx->palette_uv_size_cdf[bsize - BLOCK_8X8],
859 PALETTE_SIZES, ACCT_STR) +
860 2;
861#else
Yaowu Xuf883b422016-08-30 14:01:10 -0700862 aom_read_tree(r, av1_palette_size_tree,
Michael Bebenita6048d052016-08-25 14:40:54 -0700863 av1_default_palette_uv_size_prob[bsize - BLOCK_8X8],
864 ACCT_STR) +
Yaowu Xuc27fc142016-08-22 16:08:15 -0700865 2;
Thomas Daviesce7272d2017-07-04 16:11:08 +0100866#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700867 n = pmi->palette_size[1];
hui sud13c24a2017-04-07 16:13:07 -0700868#if CONFIG_PALETTE_DELTA_ENCODING
hui su33567b22017-04-30 16:40:19 -0700869 read_palette_colors_uv(xd, cm->bit_depth, pmi, r);
hui sud13c24a2017-04-07 16:13:07 -0700870#else
hui su33567b22017-04-30 16:40:19 -0700871 int i;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700872 for (i = 0; i < n; ++i) {
873 pmi->palette_colors[PALETTE_MAX_SIZE + i] =
Michael Bebenita6048d052016-08-25 14:40:54 -0700874 aom_read_literal(r, cm->bit_depth, ACCT_STR);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700875 pmi->palette_colors[2 * PALETTE_MAX_SIZE + i] =
Michael Bebenita6048d052016-08-25 14:40:54 -0700876 aom_read_literal(r, cm->bit_depth, ACCT_STR);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700877 }
hui sud13c24a2017-04-07 16:13:07 -0700878#endif // CONFIG_PALETTE_DELTA_ENCODING
Yaowu Xuc27fc142016-08-22 16:08:15 -0700879 xd->plane[1].color_index_map[0] = read_uniform(r, n);
880 assert(xd->plane[1].color_index_map[0] < n);
881 }
882 }
883}
Urvang Joshib100db72016-10-12 16:28:56 -0700884#endif // CONFIG_PALETTE
Yaowu Xuc27fc142016-08-22 16:08:15 -0700885
hui su5db97432016-10-14 16:10:14 -0700886#if CONFIG_FILTER_INTRA
887static void read_filter_intra_mode_info(AV1_COMMON *const cm,
Jingning Han62946d12017-05-26 11:29:30 -0700888 MACROBLOCKD *const xd, int mi_row,
889 int mi_col, aom_reader *r) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700890 MODE_INFO *const mi = xd->mi[0];
891 MB_MODE_INFO *const mbmi = &mi->mbmi;
892 FRAME_COUNTS *counts = xd->counts;
hui su5db97432016-10-14 16:10:14 -0700893 FILTER_INTRA_MODE_INFO *filter_intra_mode_info =
894 &mbmi->filter_intra_mode_info;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700895
Urvang Joshib100db72016-10-12 16:28:56 -0700896 if (mbmi->mode == DC_PRED
897#if CONFIG_PALETTE
898 && mbmi->palette_mode_info.palette_size[0] == 0
899#endif // CONFIG_PALETTE
900 ) {
hui su5db97432016-10-14 16:10:14 -0700901 filter_intra_mode_info->use_filter_intra_mode[0] =
902 aom_read(r, cm->fc->filter_intra_probs[0], ACCT_STR);
903 if (filter_intra_mode_info->use_filter_intra_mode[0]) {
904 filter_intra_mode_info->filter_intra_mode[0] =
Yaowu Xuc27fc142016-08-22 16:08:15 -0700905 read_uniform(r, FILTER_INTRA_MODES);
906 }
hui su5db97432016-10-14 16:10:14 -0700907 if (counts) {
clang-format55ce9e02017-02-15 22:27:12 -0800908 ++counts
909 ->filter_intra[0][filter_intra_mode_info->use_filter_intra_mode[0]];
hui su5db97432016-10-14 16:10:14 -0700910 }
Yaowu Xuc27fc142016-08-22 16:08:15 -0700911 }
Jingning Han62946d12017-05-26 11:29:30 -0700912
913#if CONFIG_CB4X4
914 if (!is_chroma_reference(mi_row, mi_col, mbmi->sb_type,
915 xd->plane[1].subsampling_x,
916 xd->plane[1].subsampling_y))
917 return;
hui sub4ed1492017-05-31 17:25:42 -0700918#else
919 (void)mi_row;
920 (void)mi_col;
921#endif // CONFIG_CB4X4
Jingning Han62946d12017-05-26 11:29:30 -0700922
Urvang Joshib100db72016-10-12 16:28:56 -0700923 if (mbmi->uv_mode == DC_PRED
924#if CONFIG_PALETTE
925 && mbmi->palette_mode_info.palette_size[1] == 0
926#endif // CONFIG_PALETTE
927 ) {
hui su5db97432016-10-14 16:10:14 -0700928 filter_intra_mode_info->use_filter_intra_mode[1] =
929 aom_read(r, cm->fc->filter_intra_probs[1], ACCT_STR);
930 if (filter_intra_mode_info->use_filter_intra_mode[1]) {
931 filter_intra_mode_info->filter_intra_mode[1] =
Yaowu Xuc27fc142016-08-22 16:08:15 -0700932 read_uniform(r, FILTER_INTRA_MODES);
933 }
hui su5db97432016-10-14 16:10:14 -0700934 if (counts) {
clang-format55ce9e02017-02-15 22:27:12 -0800935 ++counts
936 ->filter_intra[1][filter_intra_mode_info->use_filter_intra_mode[1]];
hui su5db97432016-10-14 16:10:14 -0700937 }
Yaowu Xuc27fc142016-08-22 16:08:15 -0700938 }
939}
hui su5db97432016-10-14 16:10:14 -0700940#endif // CONFIG_FILTER_INTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -0700941
hui su5db97432016-10-14 16:10:14 -0700942#if CONFIG_EXT_INTRA
Yaowu Xuf883b422016-08-30 14:01:10 -0700943static void read_intra_angle_info(AV1_COMMON *const cm, MACROBLOCKD *const xd,
944 aom_reader *r) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700945 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
946 const BLOCK_SIZE bsize = mbmi->sb_type;
hui sueda3d762016-12-06 16:58:23 -0800947#if CONFIG_INTRA_INTERP
hui sub4e25d22017-03-09 15:32:30 -0800948 FRAME_CONTEXT *const ec_ctx = xd->tile_ctx;
Yaowu Xuf883b422016-08-30 14:01:10 -0700949 const int ctx = av1_get_pred_context_intra_interp(xd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700950 int p_angle;
hui sueda3d762016-12-06 16:58:23 -0800951#endif // CONFIG_INTRA_INTERP
Yaowu Xuc27fc142016-08-22 16:08:15 -0700952
hui sueda3d762016-12-06 16:58:23 -0800953 (void)cm;
Joe Young830d4ce2017-05-30 17:48:13 -0700954
955 mbmi->angle_delta[0] = 0;
956 mbmi->angle_delta[1] = 0;
957
958 if (!av1_use_angle_delta(bsize)) return;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700959
hui su45dc5972016-12-08 17:42:50 -0800960 if (av1_is_directional_mode(mbmi->mode, bsize)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700961 mbmi->angle_delta[0] =
hui su0a6731f2017-04-26 15:23:47 -0700962 read_uniform(r, 2 * MAX_ANGLE_DELTA + 1) - MAX_ANGLE_DELTA;
hui sueda3d762016-12-06 16:58:23 -0800963#if CONFIG_INTRA_INTERP
hui su0a6731f2017-04-26 15:23:47 -0700964 p_angle = mode_to_angle_map[mbmi->mode] + mbmi->angle_delta[0] * ANGLE_STEP;
Yaowu Xuf883b422016-08-30 14:01:10 -0700965 if (av1_is_intra_filter_switchable(p_angle)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700966 FRAME_COUNTS *counts = xd->counts;
hui sub4e25d22017-03-09 15:32:30 -0800967 mbmi->intra_filter = aom_read_symbol(r, ec_ctx->intra_filter_cdf[ctx],
968 INTRA_FILTERS, ACCT_STR);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700969 if (counts) ++counts->intra_filter[ctx][mbmi->intra_filter];
970 } else {
971 mbmi->intra_filter = INTRA_FILTER_LINEAR;
972 }
hui sueda3d762016-12-06 16:58:23 -0800973#endif // CONFIG_INTRA_INTERP
Yaowu Xuc27fc142016-08-22 16:08:15 -0700974 }
975
hui su45dc5972016-12-08 17:42:50 -0800976 if (av1_is_directional_mode(mbmi->uv_mode, bsize)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700977 mbmi->angle_delta[1] =
hui su0a6731f2017-04-26 15:23:47 -0700978 read_uniform(r, 2 * MAX_ANGLE_DELTA + 1) - MAX_ANGLE_DELTA;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700979 }
980}
981#endif // CONFIG_EXT_INTRA
982
Angie Chianga9f9a312017-04-13 16:40:43 -0700983void av1_read_tx_type(const AV1_COMMON *const cm, MACROBLOCKD *xd,
Jingning Hanab7163d2016-11-04 09:46:35 -0700984#if CONFIG_SUPERTX
Angie Chianga9f9a312017-04-13 16:40:43 -0700985 int supertx_enabled,
Jingning Hanab7163d2016-11-04 09:46:35 -0700986#endif
Angie Chiangcd9b03f2017-04-16 13:37:13 -0700987#if CONFIG_TXK_SEL
Jingning Han19b5c8f2017-07-06 15:10:12 -0700988 int blk_row, int blk_col, int block, int plane,
989 TX_SIZE tx_size,
Angie Chianga9f9a312017-04-13 16:40:43 -0700990#endif
991 aom_reader *r) {
992 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
Jingning Hanab7163d2016-11-04 09:46:35 -0700993 const int inter_block = is_inter_block(mbmi);
Jingning Han243b66b2017-06-23 12:11:47 -0700994#if !CONFIG_TXK_SEL
Jingning Hane67b38a2016-11-04 10:30:00 -0700995#if CONFIG_VAR_TX
996 const TX_SIZE tx_size = inter_block ? mbmi->min_tx_size : mbmi->tx_size;
997#else
Jingning Hanab7163d2016-11-04 09:46:35 -0700998 const TX_SIZE tx_size = mbmi->tx_size;
Jingning Hane67b38a2016-11-04 10:30:00 -0700999#endif
Jingning Han243b66b2017-06-23 12:11:47 -07001000#endif // !CONFIG_TXK_SEL
Thomas Daviescef09622017-01-11 17:27:12 +00001001 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
Thomas Daviescef09622017-01-11 17:27:12 +00001002
Angie Chiangcd9b03f2017-04-16 13:37:13 -07001003#if !CONFIG_TXK_SEL
Angie Chianga9f9a312017-04-13 16:40:43 -07001004 TX_TYPE *tx_type = &mbmi->tx_type;
1005#else
Angie Chiang39b06eb2017-04-14 09:52:29 -07001006 // only y plane's tx_type is transmitted
1007 if (plane > 0) return;
Jingning Han19b5c8f2017-07-06 15:10:12 -07001008 (void)block;
1009 TX_TYPE *tx_type = &mbmi->txk_type[(blk_row << 4) + blk_col];
Angie Chianga9f9a312017-04-13 16:40:43 -07001010#endif
1011
Jingning Hanab7163d2016-11-04 09:46:35 -07001012 if (!FIXED_TX_TYPE) {
1013#if CONFIG_EXT_TX
Urvang Joshifeb925f2016-12-05 10:37:29 -08001014 const TX_SIZE square_tx_size = txsize_sqr_map[tx_size];
Sarah Parkere68a3e42017-02-16 14:03:24 -08001015 if (get_ext_tx_types(tx_size, mbmi->sb_type, inter_block,
1016 cm->reduced_tx_set_used) > 1 &&
Yue Cheneeacc4c2017-01-17 17:29:17 -08001017 ((!cm->seg.enabled && cm->base_qindex > 0) ||
1018 (cm->seg.enabled && xd->qindex[mbmi->segment_id] > 0)) &&
1019 !mbmi->skip &&
Jingning Hanab7163d2016-11-04 09:46:35 -07001020#if CONFIG_SUPERTX
1021 !supertx_enabled &&
1022#endif // CONFIG_SUPERTX
1023 !segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) {
Sarah Parkere68a3e42017-02-16 14:03:24 -08001024 const int eset = get_ext_tx_set(tx_size, mbmi->sb_type, inter_block,
1025 cm->reduced_tx_set_used);
Sarah Parker784596d2017-06-23 08:41:26 -07001026 // eset == 0 should correspond to a set with only DCT_DCT and
1027 // there is no need to read the tx_type
1028 assert(eset != 0);
Jingning Hanab7163d2016-11-04 09:46:35 -07001029 FRAME_COUNTS *counts = xd->counts;
1030
1031 if (inter_block) {
Sarah Parker784596d2017-06-23 08:41:26 -07001032 *tx_type = av1_ext_tx_inter_inv[eset][aom_read_symbol(
1033 r, ec_ctx->inter_ext_tx_cdf[eset][square_tx_size],
1034 ext_tx_cnt_inter[eset], ACCT_STR)];
1035 if (counts) ++counts->inter_ext_tx[eset][square_tx_size][*tx_type];
Jingning Hanab7163d2016-11-04 09:46:35 -07001036 } else if (ALLOW_INTRA_EXT_TX) {
Sarah Parker784596d2017-06-23 08:41:26 -07001037 *tx_type = av1_ext_tx_intra_inv[eset][aom_read_symbol(
1038 r, ec_ctx->intra_ext_tx_cdf[eset][square_tx_size][mbmi->mode],
1039 ext_tx_cnt_intra[eset], ACCT_STR)];
1040 if (counts)
1041 ++counts->intra_ext_tx[eset][square_tx_size][mbmi->mode][*tx_type];
Jingning Hanab7163d2016-11-04 09:46:35 -07001042 }
1043 } else {
Angie Chianga9f9a312017-04-13 16:40:43 -07001044 *tx_type = DCT_DCT;
Jingning Hanab7163d2016-11-04 09:46:35 -07001045 }
1046#else
Yue Cheneeacc4c2017-01-17 17:29:17 -08001047
1048 if (tx_size < TX_32X32 &&
1049 ((!cm->seg.enabled && cm->base_qindex > 0) ||
1050 (cm->seg.enabled && xd->qindex[mbmi->segment_id] > 0)) &&
1051 !mbmi->skip &&
Jingning Hanab7163d2016-11-04 09:46:35 -07001052#if CONFIG_SUPERTX
1053 !supertx_enabled &&
1054#endif // CONFIG_SUPERTX
1055 !segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) {
1056 FRAME_COUNTS *counts = xd->counts;
Yue Cheneeacc4c2017-01-17 17:29:17 -08001057
Jingning Hanab7163d2016-11-04 09:46:35 -07001058 if (inter_block) {
Angie Chianga9f9a312017-04-13 16:40:43 -07001059 *tx_type = av1_ext_tx_inv[aom_read_symbol(
Thomas Daviescef09622017-01-11 17:27:12 +00001060 r, ec_ctx->inter_ext_tx_cdf[tx_size], TX_TYPES, ACCT_STR)];
Angie Chianga9f9a312017-04-13 16:40:43 -07001061 if (counts) ++counts->inter_ext_tx[tx_size][*tx_type];
Jingning Hanab7163d2016-11-04 09:46:35 -07001062 } else {
1063 const TX_TYPE tx_type_nom = intra_mode_to_tx_type_context[mbmi->mode];
Angie Chianga9f9a312017-04-13 16:40:43 -07001064 *tx_type = av1_ext_tx_inv[aom_read_symbol(
Thomas Daviescef09622017-01-11 17:27:12 +00001065 r, ec_ctx->intra_ext_tx_cdf[tx_size][tx_type_nom], TX_TYPES,
Jingning Hanab7163d2016-11-04 09:46:35 -07001066 ACCT_STR)];
Angie Chianga9f9a312017-04-13 16:40:43 -07001067 if (counts) ++counts->intra_ext_tx[tx_size][tx_type_nom][*tx_type];
Jingning Hanab7163d2016-11-04 09:46:35 -07001068 }
1069 } else {
Angie Chianga9f9a312017-04-13 16:40:43 -07001070 *tx_type = DCT_DCT;
Jingning Hanab7163d2016-11-04 09:46:35 -07001071 }
1072#endif // CONFIG_EXT_TX
1073 }
Nathan E. Eggeebced372017-02-17 20:57:21 -05001074#if FIXED_TX_TYPE
1075 assert(mbmi->tx_type == DCT_DCT);
1076#endif
Jingning Hanab7163d2016-11-04 09:46:35 -07001077}
1078
Alex Converse28744302017-04-13 14:46:22 -07001079#if CONFIG_INTRABC
1080static INLINE void read_mv(aom_reader *r, MV *mv, const MV *ref,
1081 nmv_context *ctx, nmv_context_counts *counts,
Alex Converse6b2584c2017-05-02 09:51:21 -07001082 MvSubpelPrecision precision);
Alex Converse28744302017-04-13 14:46:22 -07001083
1084static INLINE int is_mv_valid(const MV *mv);
1085
1086static INLINE int assign_dv(AV1_COMMON *cm, MACROBLOCKD *xd, int_mv *mv,
1087 const int_mv *ref_mv, int mi_row, int mi_col,
1088 BLOCK_SIZE bsize, aom_reader *r) {
Alex Converse28744302017-04-13 14:46:22 -07001089 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
1090 (void)cm;
Alex Converse28744302017-04-13 14:46:22 -07001091 FRAME_COUNTS *counts = xd->counts;
1092 nmv_context_counts *const dv_counts = counts ? &counts->dv : NULL;
Alex Converse6b2584c2017-05-02 09:51:21 -07001093 read_mv(r, &mv->as_mv, &ref_mv->as_mv, &ec_ctx->ndvc, dv_counts,
1094 MV_SUBPEL_NONE);
Alex Converse28744302017-04-13 14:46:22 -07001095 int valid = is_mv_valid(&mv->as_mv) &&
1096 is_dv_valid(mv->as_mv, &xd->tile, mi_row, mi_col, bsize);
Alex Converse28744302017-04-13 14:46:22 -07001097 return valid;
1098}
1099#endif // CONFIG_INTRABC
1100
Yaowu Xuf883b422016-08-30 14:01:10 -07001101static void read_intra_frame_mode_info(AV1_COMMON *const cm,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001102 MACROBLOCKD *const xd, int mi_row,
Yaowu Xuf883b422016-08-30 14:01:10 -07001103 int mi_col, aom_reader *r) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001104 MODE_INFO *const mi = xd->mi[0];
1105 MB_MODE_INFO *const mbmi = &mi->mbmi;
1106 const MODE_INFO *above_mi = xd->above_mi;
1107 const MODE_INFO *left_mi = xd->left_mi;
1108 const BLOCK_SIZE bsize = mbmi->sb_type;
1109 int i;
1110 const int mi_offset = mi_row * cm->mi_cols + mi_col;
Jingning Han85dc03f2016-12-06 16:03:10 -08001111 const int bw = mi_size_wide[bsize];
1112 const int bh = mi_size_high[bsize];
Yaowu Xuc27fc142016-08-22 16:08:15 -07001113
1114 // TODO(slavarnway): move x_mis, y_mis into xd ?????
Yaowu Xuf883b422016-08-30 14:01:10 -07001115 const int x_mis = AOMMIN(cm->mi_cols - mi_col, bw);
1116 const int y_mis = AOMMIN(cm->mi_rows - mi_row, bh);
Thomas Davies1bfb5ed2017-01-11 15:28:11 +00001117 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001118
1119 mbmi->segment_id = read_intra_segment_id(cm, xd, mi_offset, x_mis, y_mis, r);
1120 mbmi->skip = read_skip(cm, xd, mbmi->segment_id, r);
Arild Fuldseth07441162016-08-15 15:07:52 +02001121
1122#if CONFIG_DELTA_Q
1123 if (cm->delta_q_present_flag) {
Thomas Daviesf6936102016-09-05 16:51:31 +01001124 xd->current_qindex =
1125 xd->prev_qindex +
1126 read_delta_qindex(cm, xd, r, mbmi, mi_col, mi_row) * cm->delta_q_res;
Arild Fuldseth (arilfuld)54de7d62017-03-20 13:07:11 +01001127 /* Normative: Clamp to [1,MAXQ] to not interfere with lossless mode */
1128 xd->current_qindex = clamp(xd->current_qindex, 1, MAXQ);
Thomas Daviesf6936102016-09-05 16:51:31 +01001129 xd->prev_qindex = xd->current_qindex;
Fangwen Fu231fe422017-04-24 17:52:29 -07001130#if CONFIG_EXT_DELTA_Q
1131 if (cm->delta_lf_present_flag) {
1132 mbmi->current_delta_lf_from_base = xd->current_delta_lf_from_base =
1133 xd->prev_delta_lf_from_base +
1134 read_delta_lflevel(cm, xd, r, mbmi, mi_col, mi_row) *
1135 cm->delta_lf_res;
1136 xd->prev_delta_lf_from_base = xd->current_delta_lf_from_base;
1137 }
1138#endif
Arild Fuldseth07441162016-08-15 15:07:52 +02001139 }
1140#endif
1141
Yaowu Xuc27fc142016-08-22 16:08:15 -07001142 mbmi->ref_frame[0] = INTRA_FRAME;
Emil Keyder01770b32017-01-20 18:03:11 -05001143 mbmi->ref_frame[1] = NONE_FRAME;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001144
Alex Converse28744302017-04-13 14:46:22 -07001145#if CONFIG_INTRABC
1146 if (bsize >= BLOCK_8X8 && cm->allow_screen_content_tools) {
Alex Converse7c412ea2017-06-01 15:16:22 -07001147 mbmi->use_intrabc = aom_read(r, ec_ctx->intrabc_prob, ACCT_STR);
Alex Converse28744302017-04-13 14:46:22 -07001148 if (mbmi->use_intrabc) {
Alex Conversef71808c2017-06-06 12:21:17 -07001149 mbmi->tx_size = read_tx_size(cm, xd, 1, !mbmi->skip, r);
Alex Converse28744302017-04-13 14:46:22 -07001150 mbmi->mode = mbmi->uv_mode = DC_PRED;
Jingning Hand6c17d92017-04-24 16:33:12 -07001151#if CONFIG_DUAL_FILTER
1152 for (int idx = 0; idx < 4; ++idx) mbmi->interp_filter[idx] = BILINEAR;
1153#else
Alex Converse28744302017-04-13 14:46:22 -07001154 mbmi->interp_filter = BILINEAR;
Jingning Hand6c17d92017-04-24 16:33:12 -07001155#endif
Alex Converse44c2bad2017-05-11 09:36:10 -07001156
1157 int16_t inter_mode_ctx[MODE_CTX_REF_FRAMES];
1158 int_mv ref_mvs[MAX_MV_REF_CANDIDATES] = {};
1159
1160 av1_find_mv_refs(cm, xd, mi, INTRA_FRAME, &xd->ref_mv_count[INTRA_FRAME],
1161 xd->ref_mv_stack[INTRA_FRAME],
1162#if CONFIG_EXT_INTER
Yue Chenf03907a2017-05-31 12:04:04 -07001163 NULL,
Alex Converse44c2bad2017-05-11 09:36:10 -07001164#endif // CONFIG_EXT_INTER
1165 ref_mvs, mi_row, mi_col, NULL, NULL, inter_mode_ctx);
1166
1167 int_mv nearestmv, nearmv;
1168 av1_find_best_ref_mvs(0, ref_mvs, &nearestmv, &nearmv);
1169
1170 int_mv dv_ref = nearestmv.as_int == 0 ? nearmv : nearestmv;
1171 if (dv_ref.as_int == 0) av1_find_ref_dv(&dv_ref, mi_row, mi_col);
1172
Alex Converse28744302017-04-13 14:46:22 -07001173 xd->corrupted |=
1174 !assign_dv(cm, xd, &mbmi->mv[0], &dv_ref, mi_row, mi_col, bsize, r);
Alex Conversee16b2662017-05-24 14:00:00 -07001175#if CONFIG_VAR_TX
1176 // TODO(aconverse@google.com): Evaluate allowing VAR TX on intrabc blocks
1177 const int width = block_size_wide[bsize] >> tx_size_wide_log2[0];
1178 const int height = block_size_high[bsize] >> tx_size_high_log2[0];
1179 int idx, idy;
1180 for (idy = 0; idy < height; ++idy)
1181 for (idx = 0; idx < width; ++idx)
1182 mbmi->inter_tx_size[idy >> 1][idx >> 1] = mbmi->tx_size;
1183 mbmi->min_tx_size = get_min_tx_size(mbmi->tx_size);
1184#endif // CONFIG_VAR_TX
Alex Conversedaa15e42017-05-02 14:27:16 -07001185#if CONFIG_EXT_TX && !CONFIG_TXK_SEL
1186 av1_read_tx_type(cm, xd,
1187#if CONFIG_SUPERTX
1188 0,
1189#endif
1190 r);
1191#endif // CONFIG_EXT_TX && !CONFIG_TXK_SEL
Alex Converse28744302017-04-13 14:46:22 -07001192 return;
1193 }
1194 }
1195#endif // CONFIG_INTRABC
1196
Alex Conversef71808c2017-06-06 12:21:17 -07001197 mbmi->tx_size = read_tx_size(cm, xd, 0, 1, r);
1198
Jingning Han52261842016-12-14 12:17:49 -08001199#if CONFIG_CB4X4
1200 (void)i;
1201 mbmi->mode =
Thomas Davies1bfb5ed2017-01-11 15:28:11 +00001202 read_intra_mode(r, get_y_mode_cdf(ec_ctx, mi, above_mi, left_mi, 0));
Jingning Han52261842016-12-14 12:17:49 -08001203#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001204 switch (bsize) {
1205 case BLOCK_4X4:
1206 for (i = 0; i < 4; ++i)
Nathan E. Egge476c63c2017-05-18 18:35:16 -04001207 mi->bmi[i].as_mode = read_intra_mode(
1208 r, get_y_mode_cdf(ec_ctx, mi, above_mi, left_mi, i));
Yaowu Xuc27fc142016-08-22 16:08:15 -07001209 mbmi->mode = mi->bmi[3].as_mode;
1210 break;
1211 case BLOCK_4X8:
1212 mi->bmi[0].as_mode = mi->bmi[2].as_mode =
Thomas Davies1bfb5ed2017-01-11 15:28:11 +00001213 read_intra_mode(r, get_y_mode_cdf(ec_ctx, mi, above_mi, left_mi, 0));
Yaowu Xuc27fc142016-08-22 16:08:15 -07001214 mi->bmi[1].as_mode = mi->bmi[3].as_mode = mbmi->mode =
Thomas Davies1bfb5ed2017-01-11 15:28:11 +00001215 read_intra_mode(r, get_y_mode_cdf(ec_ctx, mi, above_mi, left_mi, 1));
Yaowu Xuc27fc142016-08-22 16:08:15 -07001216 break;
1217 case BLOCK_8X4:
1218 mi->bmi[0].as_mode = mi->bmi[1].as_mode =
Thomas Davies1bfb5ed2017-01-11 15:28:11 +00001219 read_intra_mode(r, get_y_mode_cdf(ec_ctx, mi, above_mi, left_mi, 0));
Yaowu Xuc27fc142016-08-22 16:08:15 -07001220 mi->bmi[2].as_mode = mi->bmi[3].as_mode = mbmi->mode =
Thomas Davies1bfb5ed2017-01-11 15:28:11 +00001221 read_intra_mode(r, get_y_mode_cdf(ec_ctx, mi, above_mi, left_mi, 2));
Yaowu Xuc27fc142016-08-22 16:08:15 -07001222 break;
1223 default:
1224 mbmi->mode =
Thomas Davies1bfb5ed2017-01-11 15:28:11 +00001225 read_intra_mode(r, get_y_mode_cdf(ec_ctx, mi, above_mi, left_mi, 0));
Yaowu Xuc27fc142016-08-22 16:08:15 -07001226 }
Jingning Han52261842016-12-14 12:17:49 -08001227#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001228
Jingning Han36fe3202017-02-20 22:31:49 -08001229#if CONFIG_CB4X4
Jingning Hand3a64432017-04-06 17:04:17 -07001230 if (is_chroma_reference(mi_row, mi_col, bsize, xd->plane[1].subsampling_x,
Luc Trudeau2c317902017-04-28 11:06:50 -04001231 xd->plane[1].subsampling_y)) {
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001232 mbmi->uv_mode = read_intra_mode_uv(ec_ctx, xd, r, mbmi->mode);
Jingning Han36fe3202017-02-20 22:31:49 -08001233#else
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001234 mbmi->uv_mode = read_intra_mode_uv(ec_ctx, xd, r, mbmi->mode);
Jingning Han36fe3202017-02-20 22:31:49 -08001235#endif
1236
Luc Trudeauf5334002017-04-25 12:21:26 -04001237#if CONFIG_CFL
Luc Trudeau2c317902017-04-28 11:06:50 -04001238 // TODO(ltrudeau) support PALETTE
1239 if (mbmi->uv_mode == DC_PRED) {
David Michael Barr23198662017-06-19 23:19:48 +09001240 mbmi->cfl_alpha_idx = read_cfl_alphas(ec_ctx, r, mbmi->cfl_alpha_signs);
Luc Trudeauf5334002017-04-25 12:21:26 -04001241 }
Luc Trudeau2c317902017-04-28 11:06:50 -04001242#endif // CONFIG_CFL
1243
1244#if CONFIG_CB4X4
Joe Young830d4ce2017-05-30 17:48:13 -07001245 } else {
1246 // Avoid decoding angle_info if there is is no chroma prediction
1247 mbmi->uv_mode = DC_PRED;
Luc Trudeauf5334002017-04-25 12:21:26 -04001248 }
1249#endif
1250
Yaowu Xuc27fc142016-08-22 16:08:15 -07001251#if CONFIG_EXT_INTRA
1252 read_intra_angle_info(cm, xd, r);
1253#endif // CONFIG_EXT_INTRA
Urvang Joshib100db72016-10-12 16:28:56 -07001254#if CONFIG_PALETTE
Yaowu Xuc27fc142016-08-22 16:08:15 -07001255 mbmi->palette_mode_info.palette_size[0] = 0;
1256 mbmi->palette_mode_info.palette_size[1] = 0;
1257 if (bsize >= BLOCK_8X8 && cm->allow_screen_content_tools)
1258 read_palette_mode_info(cm, xd, r);
Urvang Joshib100db72016-10-12 16:28:56 -07001259#endif // CONFIG_PALETTE
hui su5db97432016-10-14 16:10:14 -07001260#if CONFIG_FILTER_INTRA
1261 mbmi->filter_intra_mode_info.use_filter_intra_mode[0] = 0;
1262 mbmi->filter_intra_mode_info.use_filter_intra_mode[1] = 0;
Jingning Han48b1cb32017-01-23 10:26:14 -08001263 if (bsize >= BLOCK_8X8 || CONFIG_CB4X4)
Jingning Han62946d12017-05-26 11:29:30 -07001264 read_filter_intra_mode_info(cm, xd, mi_row, mi_col, r);
hui su5db97432016-10-14 16:10:14 -07001265#endif // CONFIG_FILTER_INTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -07001266
Angie Chiangcd9b03f2017-04-16 13:37:13 -07001267#if !CONFIG_TXK_SEL
Angie Chianga9f9a312017-04-13 16:40:43 -07001268 av1_read_tx_type(cm, xd,
Jingning Hanab7163d2016-11-04 09:46:35 -07001269#if CONFIG_SUPERTX
Angie Chianga9f9a312017-04-13 16:40:43 -07001270 0,
Nathan E. Egge72762a22016-09-07 17:12:07 -04001271#endif
Angie Chianga9f9a312017-04-13 16:40:43 -07001272 r);
Angie Chiangcd9b03f2017-04-16 13:37:13 -07001273#endif // !CONFIG_TXK_SEL
Yaowu Xuc27fc142016-08-22 16:08:15 -07001274}
1275
Alex Converse6b2584c2017-05-02 09:51:21 -07001276static int read_mv_component(aom_reader *r, nmv_component *mvcomp,
1277#if CONFIG_INTRABC
1278 int use_subpel,
1279#endif // CONFIG_INTRABC
1280 int usehp) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001281 int mag, d, fr, hp;
Michael Bebenita6048d052016-08-25 14:40:54 -07001282 const int sign = aom_read(r, mvcomp->sign, ACCT_STR);
1283 const int mv_class =
Nathan E. Egged7b893c2016-09-08 15:08:48 -04001284 aom_read_symbol(r, mvcomp->class_cdf, MV_CLASSES, ACCT_STR);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001285 const int class0 = mv_class == MV_CLASS_0;
1286
1287 // Integer part
1288 if (class0) {
Nathan E. Egge45ea9632016-09-08 17:25:49 -04001289 d = aom_read(r, mvcomp->class0[0], ACCT_STR);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001290 mag = 0;
1291 } else {
1292 int i;
1293 const int n = mv_class + CLASS0_BITS - 1; // number of bits
1294
1295 d = 0;
Michael Bebenita6048d052016-08-25 14:40:54 -07001296 for (i = 0; i < n; ++i) d |= aom_read(r, mvcomp->bits[i], ACCT_STR) << i;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001297 mag = CLASS0_SIZE << (mv_class + 2);
1298 }
1299
Alex Converse6b2584c2017-05-02 09:51:21 -07001300#if CONFIG_INTRABC
1301 if (use_subpel) {
1302#endif // CONFIG_INTRABC
1303 // Fractional part
1304 fr = aom_read_symbol(r, class0 ? mvcomp->class0_fp_cdf[d] : mvcomp->fp_cdf,
1305 MV_FP_SIZE, ACCT_STR);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001306
Alex Converse6b2584c2017-05-02 09:51:21 -07001307 // High precision part (if hp is not used, the default value of the hp is 1)
1308 hp = usehp ? aom_read(r, class0 ? mvcomp->class0_hp : mvcomp->hp, ACCT_STR)
1309 : 1;
1310#if CONFIG_INTRABC
1311 } else {
1312 fr = 3;
1313 hp = 1;
1314 }
1315#endif // CONFIG_INTRABC
Yaowu Xuc27fc142016-08-22 16:08:15 -07001316
1317 // Result
1318 mag += ((d << 3) | (fr << 1) | hp) + 1;
1319 return sign ? -mag : mag;
1320}
1321
Yaowu Xuf883b422016-08-30 14:01:10 -07001322static INLINE void read_mv(aom_reader *r, MV *mv, const MV *ref,
Thomas9ac55082016-09-23 18:04:17 +01001323 nmv_context *ctx, nmv_context_counts *counts,
Alex Converse6b2584c2017-05-02 09:51:21 -07001324 MvSubpelPrecision precision) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001325 MV_JOINT_TYPE joint_type;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001326 MV diff = { 0, 0 };
Michael Bebenita6048d052016-08-25 14:40:54 -07001327 joint_type =
Nathan E. Egge5f7fd7a2016-09-08 11:22:03 -04001328 (MV_JOINT_TYPE)aom_read_symbol(r, ctx->joint_cdf, MV_JOINTS, ACCT_STR);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001329
1330 if (mv_joint_vertical(joint_type))
Alex Converse6b2584c2017-05-02 09:51:21 -07001331 diff.row = read_mv_component(r, &ctx->comps[0],
1332#if CONFIG_INTRABC
1333 precision > MV_SUBPEL_NONE,
1334#endif // CONFIG_INTRABC
1335 precision > MV_SUBPEL_LOW_PRECISION);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001336
1337 if (mv_joint_horizontal(joint_type))
Alex Converse6b2584c2017-05-02 09:51:21 -07001338 diff.col = read_mv_component(r, &ctx->comps[1],
1339#if CONFIG_INTRABC
1340 precision > MV_SUBPEL_NONE,
1341#endif // CONFIG_INTRABC
1342 precision > MV_SUBPEL_LOW_PRECISION);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001343
Alex Converse6b2584c2017-05-02 09:51:21 -07001344 av1_inc_mv(&diff, counts, precision);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001345
1346 mv->row = ref->row + diff.row;
1347 mv->col = ref->col + diff.col;
1348}
1349
Yaowu Xuf883b422016-08-30 14:01:10 -07001350static REFERENCE_MODE read_block_reference_mode(AV1_COMMON *cm,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001351 const MACROBLOCKD *xd,
Yaowu Xuf883b422016-08-30 14:01:10 -07001352 aom_reader *r) {
Jingning Han6b064722017-05-01 09:48:18 -07001353#if !SUB8X8_COMP_REF
Jingning Han69d21012017-05-14 16:51:27 -07001354 if (xd->mi[0]->mbmi.sb_type == BLOCK_4X4) return SINGLE_REFERENCE;
Jingning Han6b064722017-05-01 09:48:18 -07001355#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001356 if (cm->reference_mode == REFERENCE_MODE_SELECT) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001357 const int ctx = av1_get_reference_mode_context(cm, xd);
Thomas Davies8c9bcdf2017-06-21 10:12:48 +01001358#if CONFIG_NEW_MULTISYMBOL
1359 const REFERENCE_MODE mode = (REFERENCE_MODE)aom_read_symbol(
1360 r, xd->tile_ctx->comp_inter_cdf[ctx], 2, ACCT_STR);
1361#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001362 const REFERENCE_MODE mode =
Michael Bebenita6048d052016-08-25 14:40:54 -07001363 (REFERENCE_MODE)aom_read(r, cm->fc->comp_inter_prob[ctx], ACCT_STR);
Thomas Davies8c9bcdf2017-06-21 10:12:48 +01001364#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001365 FRAME_COUNTS *counts = xd->counts;
1366 if (counts) ++counts->comp_inter[ctx][mode];
1367 return mode; // SINGLE_REFERENCE or COMPOUND_REFERENCE
1368 } else {
1369 return cm->reference_mode;
1370 }
1371}
1372
Thomas Davies315f5782017-06-14 15:14:55 +01001373#if CONFIG_NEW_MULTISYMBOL
1374#define READ_REF_BIT(pname) \
Thomas Davies894cc812017-06-22 17:51:33 +01001375 aom_read_symbol(r, av1_get_pred_cdf_##pname(cm, xd), 2, ACCT_STR)
Thomas Davies315f5782017-06-14 15:14:55 +01001376#else
1377#define READ_REF_BIT(pname) \
1378 aom_read(r, av1_get_pred_prob_##pname(cm, xd), ACCT_STR)
1379#endif
1380
Zoe Liuc082bbc2017-05-17 13:31:37 -07001381#if CONFIG_EXT_COMP_REFS
1382static REFERENCE_MODE read_comp_reference_type(AV1_COMMON *cm,
1383 const MACROBLOCKD *xd,
1384 aom_reader *r) {
Zoe Liufcf5fa22017-06-26 16:00:38 -07001385 const int ctx = av1_get_comp_reference_type_context(xd);
Zoe Liuc082bbc2017-05-17 13:31:37 -07001386#if USE_UNI_COMP_REFS
Zoe Liufcf5fa22017-06-26 16:00:38 -07001387 COMP_REFERENCE_TYPE comp_ref_type;
1388#if CONFIG_VAR_REFS
1389 if ((L_OR_L2(cm) || L3_OR_G(cm)) && BWD_OR_ALT(cm))
1390 if (L_AND_L2(cm) || L_AND_L3(cm) || L_AND_G(cm) || BWD_AND_ALT(cm))
1391#endif // CONFIG_VAR_REFS
1392 comp_ref_type = (COMP_REFERENCE_TYPE)aom_read(
1393 r, cm->fc->comp_ref_type_prob[ctx], ACCT_STR);
1394#if CONFIG_VAR_REFS
1395 else
1396 comp_ref_type = BIDIR_COMP_REFERENCE;
1397 else
1398 comp_ref_type = UNIDIR_COMP_REFERENCE;
1399#endif // CONFIG_VAR_REFS
Zoe Liuc082bbc2017-05-17 13:31:37 -07001400#else // !USE_UNI_COMP_REFS
1401 // TODO(zoeliu): Temporarily turn off uni-directional comp refs
1402 const COMP_REFERENCE_TYPE comp_ref_type = BIDIR_COMP_REFERENCE;
1403#endif // USE_UNI_COMP_REFS
1404 FRAME_COUNTS *counts = xd->counts;
1405 if (counts) ++counts->comp_ref_type[ctx][comp_ref_type];
1406 return comp_ref_type; // UNIDIR_COMP_REFERENCE or BIDIR_COMP_REFERENCE
1407}
1408#endif // CONFIG_EXT_COMP_REFS
1409
Yaowu Xuc27fc142016-08-22 16:08:15 -07001410// Read the referncence frame
Yaowu Xuf883b422016-08-30 14:01:10 -07001411static void read_ref_frames(AV1_COMMON *const cm, MACROBLOCKD *const xd,
1412 aom_reader *r, int segment_id,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001413 MV_REFERENCE_FRAME ref_frame[2]) {
Thomas Davies894cc812017-06-22 17:51:33 +01001414#if CONFIG_EXT_COMP_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -07001415 FRAME_CONTEXT *const fc = cm->fc;
Thomas Davies894cc812017-06-22 17:51:33 +01001416#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001417 FRAME_COUNTS *counts = xd->counts;
1418
1419 if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) {
1420 ref_frame[0] = (MV_REFERENCE_FRAME)get_segdata(&cm->seg, segment_id,
1421 SEG_LVL_REF_FRAME);
Emil Keyder01770b32017-01-20 18:03:11 -05001422 ref_frame[1] = NONE_FRAME;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001423 } else {
1424 const REFERENCE_MODE mode = read_block_reference_mode(cm, xd, r);
1425 // FIXME(rbultje) I'm pretty sure this breaks segmentation ref frame coding
1426 if (mode == COMPOUND_REFERENCE) {
Zoe Liuc082bbc2017-05-17 13:31:37 -07001427#if CONFIG_EXT_COMP_REFS
1428 const COMP_REFERENCE_TYPE comp_ref_type =
1429 read_comp_reference_type(cm, xd, r);
1430
1431#if !USE_UNI_COMP_REFS
1432 // TODO(zoeliu): Temporarily turn off uni-directional comp refs
1433 assert(comp_ref_type == BIDIR_COMP_REFERENCE);
1434#endif // !USE_UNI_COMP_REFS
1435
1436 if (comp_ref_type == UNIDIR_COMP_REFERENCE) {
Zoe Liufcf5fa22017-06-26 16:00:38 -07001437 const int ctx = av1_get_pred_context_uni_comp_ref_p(xd);
1438 int bit;
1439#if CONFIG_VAR_REFS
1440 if ((L_AND_L2(cm) || L_AND_L3(cm) || L_AND_G(cm)) && BWD_AND_ALT(cm))
1441#endif // CONFIG_VAR_REFS
1442 bit = aom_read(r, fc->uni_comp_ref_prob[ctx][0], ACCT_STR);
1443#if CONFIG_VAR_REFS
1444 else
1445 bit = BWD_AND_ALT(cm);
1446#endif // CONFIG_VAR_REFS
Zoe Liuc082bbc2017-05-17 13:31:37 -07001447 if (counts) ++counts->uni_comp_ref[ctx][0][bit];
1448
1449 if (bit) {
1450 ref_frame[0] = BWDREF_FRAME;
1451 ref_frame[1] = ALTREF_FRAME;
1452 } else {
Zoe Liufcf5fa22017-06-26 16:00:38 -07001453 const int ctx1 = av1_get_pred_context_uni_comp_ref_p1(xd);
1454 int bit1;
1455#if CONFIG_VAR_REFS
1456 if (L_AND_L2(cm) && (L_AND_L3(cm) || L_AND_G(cm)))
1457#endif // CONFIG_VAR_REFS
1458 bit1 = aom_read(r, fc->uni_comp_ref_prob[ctx1][1], ACCT_STR);
1459#if CONFIG_VAR_REFS
1460 else
1461 bit1 = L_AND_L3(cm) || L_AND_G(cm);
1462#endif // CONFIG_VAR_REFS
Zoe Liuc082bbc2017-05-17 13:31:37 -07001463 if (counts) ++counts->uni_comp_ref[ctx1][1][bit1];
1464
1465 if (bit1) {
Zoe Liufcf5fa22017-06-26 16:00:38 -07001466 const int ctx2 = av1_get_pred_context_uni_comp_ref_p2(xd);
1467 int bit2;
1468#if CONFIG_VAR_REFS
1469 if (L_AND_L3(cm) && L_AND_G(cm))
1470#endif // CONFIG_VAR_REFS
1471 bit2 = aom_read(r, fc->uni_comp_ref_prob[ctx2][2], ACCT_STR);
1472#if CONFIG_VAR_REFS
1473 else
1474 bit2 = L_AND_G(cm);
1475#endif // CONFIG_VAR_REFS
1476 if (counts) ++counts->uni_comp_ref[ctx2][2][bit2];
1477
1478 if (bit2) {
1479 ref_frame[0] = LAST_FRAME;
1480 ref_frame[1] = GOLDEN_FRAME;
1481 } else {
1482 ref_frame[0] = LAST_FRAME;
1483 ref_frame[1] = LAST3_FRAME;
1484 }
Zoe Liuc082bbc2017-05-17 13:31:37 -07001485 } else {
1486 ref_frame[0] = LAST_FRAME;
1487 ref_frame[1] = LAST2_FRAME;
1488 }
1489 }
1490
1491 return;
1492 }
Zoe Liufcf5fa22017-06-26 16:00:38 -07001493
1494 assert(comp_ref_type == BIDIR_COMP_REFERENCE);
Zoe Liuc082bbc2017-05-17 13:31:37 -07001495#endif // CONFIG_EXT_COMP_REFS
1496
1497// Normative in decoder (for low delay)
1498#if CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS
Arild Fuldseth (arilfuld)38897302017-04-27 20:03:03 +02001499 const int idx = 1;
Zoe Liuc082bbc2017-05-17 13:31:37 -07001500#else // !(CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001501#if CONFIG_EXT_REFS
1502 const int idx = cm->ref_frame_sign_bias[cm->comp_bwd_ref[0]];
Zoe Liuc082bbc2017-05-17 13:31:37 -07001503#else // !CONFIG_EXT_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -07001504 const int idx = cm->ref_frame_sign_bias[cm->comp_fixed_ref];
1505#endif // CONFIG_EXT_REFS
Zoe Liuc082bbc2017-05-17 13:31:37 -07001506#endif // CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -07001507
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001508 const int ctx = av1_get_pred_context_comp_ref_p(cm, xd);
1509#if CONFIG_VAR_REFS
1510 int bit;
1511 // Test need to explicitly code (L,L2) vs (L3,G) branch node in tree
1512 if (L_OR_L2(cm) && L3_OR_G(cm))
Thomas Davies894cc812017-06-22 17:51:33 +01001513 bit = READ_REF_BIT(comp_ref_p);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001514 else
1515 bit = L3_OR_G(cm);
1516#else // !CONFIG_VAR_REFS
Thomas Davies894cc812017-06-22 17:51:33 +01001517 const int bit = READ_REF_BIT(comp_ref_p);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001518#endif // CONFIG_VAR_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -07001519 if (counts) ++counts->comp_ref[ctx][0][bit];
1520
1521#if CONFIG_EXT_REFS
1522 // Decode forward references.
1523 if (!bit) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001524 const int ctx1 = av1_get_pred_context_comp_ref_p1(cm, xd);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001525#if CONFIG_VAR_REFS
1526 int bit1;
1527 // Test need to explicitly code (L) vs (L2) branch node in tree
1528 if (L_AND_L2(cm))
Thomas Davies894cc812017-06-22 17:51:33 +01001529 bit1 = READ_REF_BIT(comp_ref_p1);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001530 else
1531 bit1 = LAST_IS_VALID(cm);
1532#else // !CONFIG_VAR_REFS
Thomas Davies894cc812017-06-22 17:51:33 +01001533 const int bit1 = READ_REF_BIT(comp_ref_p1);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001534#endif // CONFIG_VAR_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -07001535 if (counts) ++counts->comp_ref[ctx1][1][bit1];
1536 ref_frame[!idx] = cm->comp_fwd_ref[bit1 ? 0 : 1];
1537 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -07001538 const int ctx2 = av1_get_pred_context_comp_ref_p2(cm, xd);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001539#if CONFIG_VAR_REFS
1540 int bit2;
1541 // Test need to explicitly code (L3) vs (G) branch node in tree
1542 if (L3_AND_G(cm))
Thomas Davies894cc812017-06-22 17:51:33 +01001543 bit2 = READ_REF_BIT(comp_ref_p2);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001544 else
1545 bit2 = GOLDEN_IS_VALID(cm);
1546#else // !CONFIG_VAR_REFS
Thomas Davies894cc812017-06-22 17:51:33 +01001547 const int bit2 = READ_REF_BIT(comp_ref_p2);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001548#endif // CONFIG_VAR_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -07001549 if (counts) ++counts->comp_ref[ctx2][2][bit2];
1550 ref_frame[!idx] = cm->comp_fwd_ref[bit2 ? 3 : 2];
1551 }
1552
1553 // Decode backward references.
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001554 const int ctx_bwd = av1_get_pred_context_comp_bwdref_p(cm, xd);
1555#if CONFIG_VAR_REFS
1556 int bit_bwd;
1557 // Test need to explicitly code (BWD) vs (ALT) branch node in tree
1558 if (BWD_AND_ALT(cm))
Thomas Davies894cc812017-06-22 17:51:33 +01001559 bit_bwd = READ_REF_BIT(comp_bwdref_p);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001560 else
1561 bit_bwd = ALTREF_IS_VALID(cm);
Thomas Davies894cc812017-06-22 17:51:33 +01001562#else // !CONFIG_VAR_REFS
1563 const int bit_bwd = READ_REF_BIT(comp_bwdref_p);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001564#endif // CONFIG_VAR_REFS
1565 if (counts) ++counts->comp_bwdref[ctx_bwd][0][bit_bwd];
1566 ref_frame[idx] = cm->comp_bwd_ref[bit_bwd];
1567#else // !CONFIG_EXT_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -07001568 ref_frame[!idx] = cm->comp_var_ref[bit];
1569 ref_frame[idx] = cm->comp_fixed_ref;
1570#endif // CONFIG_EXT_REFS
1571 } else if (mode == SINGLE_REFERENCE) {
1572#if CONFIG_EXT_REFS
Yaowu Xuf883b422016-08-30 14:01:10 -07001573 const int ctx0 = av1_get_pred_context_single_ref_p1(xd);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001574#if CONFIG_VAR_REFS
1575 int bit0;
1576 // Test need to explicitly code (L,L2,L3,G) vs (BWD,ALT) branch node in
1577 // tree
1578 if ((L_OR_L2(cm) || L3_OR_G(cm)) && BWD_OR_ALT(cm))
Thomas Davies315f5782017-06-14 15:14:55 +01001579 bit0 = READ_REF_BIT(single_ref_p1);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001580 else
1581 bit0 = BWD_OR_ALT(cm);
1582#else // !CONFIG_VAR_REFS
Thomas Davies315f5782017-06-14 15:14:55 +01001583 const int bit0 = READ_REF_BIT(single_ref_p1);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001584#endif // CONFIG_VAR_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -07001585 if (counts) ++counts->single_ref[ctx0][0][bit0];
1586
1587 if (bit0) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001588 const int ctx1 = av1_get_pred_context_single_ref_p2(xd);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001589#if CONFIG_VAR_REFS
1590 int bit1;
1591 // Test need to explicitly code (BWD) vs (ALT) branch node in tree
1592 if (BWD_AND_ALT(cm))
Thomas Davies315f5782017-06-14 15:14:55 +01001593 bit1 = READ_REF_BIT(single_ref_p2);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001594 else
1595 bit1 = ALTREF_IS_VALID(cm);
Thomas Davies315f5782017-06-14 15:14:55 +01001596#else // !CONFIG_VAR_REFS
1597 const int bit1 = READ_REF_BIT(single_ref_p2);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001598#endif // CONFIG_VAR_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -07001599 if (counts) ++counts->single_ref[ctx1][1][bit1];
1600 ref_frame[0] = bit1 ? ALTREF_FRAME : BWDREF_FRAME;
1601 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -07001602 const int ctx2 = av1_get_pred_context_single_ref_p3(xd);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001603#if CONFIG_VAR_REFS
1604 int bit2;
1605 // Test need to explicitly code (L,L2) vs (L3,G) branch node in tree
1606 if (L_OR_L2(cm) && L3_OR_G(cm))
Thomas Davies315f5782017-06-14 15:14:55 +01001607 bit2 = READ_REF_BIT(single_ref_p3);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001608 else
1609 bit2 = L3_OR_G(cm);
Thomas Davies315f5782017-06-14 15:14:55 +01001610#else // !CONFIG_VAR_REFS
1611 const int bit2 = READ_REF_BIT(single_ref_p3);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001612#endif // CONFIG_VAR_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -07001613 if (counts) ++counts->single_ref[ctx2][2][bit2];
1614 if (bit2) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001615 const int ctx4 = av1_get_pred_context_single_ref_p5(xd);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001616#if CONFIG_VAR_REFS
1617 int bit4;
1618 // Test need to explicitly code (L3) vs (G) branch node in tree
1619 if (L3_AND_G(cm))
Thomas Davies315f5782017-06-14 15:14:55 +01001620 bit4 = READ_REF_BIT(single_ref_p5);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001621 else
1622 bit4 = GOLDEN_IS_VALID(cm);
Thomas Davies315f5782017-06-14 15:14:55 +01001623#else // !CONFIG_VAR_REFS
1624 const int bit4 = READ_REF_BIT(single_ref_p5);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001625#endif // CONFIG_VAR_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -07001626 if (counts) ++counts->single_ref[ctx4][4][bit4];
1627 ref_frame[0] = bit4 ? GOLDEN_FRAME : LAST3_FRAME;
1628 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -07001629 const int ctx3 = av1_get_pred_context_single_ref_p4(xd);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001630#if CONFIG_VAR_REFS
1631 int bit3;
1632 // Test need to explicitly code (L) vs (L2) branch node in tree
1633 if (L_AND_L2(cm))
Thomas Davies315f5782017-06-14 15:14:55 +01001634 bit3 = READ_REF_BIT(single_ref_p4);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001635 else
1636 bit3 = LAST2_IS_VALID(cm);
Thomas Davies315f5782017-06-14 15:14:55 +01001637#else // !CONFIG_VAR_REFS
1638 const int bit3 = READ_REF_BIT(single_ref_p4);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001639#endif // CONFIG_VAR_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -07001640 if (counts) ++counts->single_ref[ctx3][3][bit3];
1641 ref_frame[0] = bit3 ? LAST2_FRAME : LAST_FRAME;
1642 }
1643 }
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001644#else // !CONFIG_EXT_REFS
Yaowu Xuf883b422016-08-30 14:01:10 -07001645 const int ctx0 = av1_get_pred_context_single_ref_p1(xd);
Thomas Davies315f5782017-06-14 15:14:55 +01001646 const int bit0 = READ_REF_BIT(single_ref_p1);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001647 if (counts) ++counts->single_ref[ctx0][0][bit0];
1648
1649 if (bit0) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001650 const int ctx1 = av1_get_pred_context_single_ref_p2(xd);
Thomas Davies315f5782017-06-14 15:14:55 +01001651 const int bit1 = READ_REF_BIT(single_ref_p2);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001652 if (counts) ++counts->single_ref[ctx1][1][bit1];
1653 ref_frame[0] = bit1 ? ALTREF_FRAME : GOLDEN_FRAME;
1654 } else {
1655 ref_frame[0] = LAST_FRAME;
1656 }
1657#endif // CONFIG_EXT_REFS
1658
Emil Keyder01770b32017-01-20 18:03:11 -05001659 ref_frame[1] = NONE_FRAME;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001660 } else {
1661 assert(0 && "Invalid prediction mode.");
1662 }
1663 }
1664}
1665
Angie Chiang9c4f8952016-11-21 11:13:19 -08001666static INLINE void read_mb_interp_filter(AV1_COMMON *const cm,
1667 MACROBLOCKD *const xd,
1668 MB_MODE_INFO *const mbmi,
1669 aom_reader *r) {
1670 FRAME_COUNTS *counts = xd->counts;
Thomas Davies77c7c402017-01-11 17:58:54 +00001671 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
Thomas Davies77c7c402017-01-11 17:58:54 +00001672
Debargha Mukherjee0df711f2017-05-02 16:00:20 -07001673 if (!av1_is_interp_needed(xd)) {
1674 set_default_interp_filters(mbmi, cm->interp_filter);
Yue Chen19e7aa82016-11-30 14:05:39 -08001675 return;
1676 }
Yue Chen19e7aa82016-11-30 14:05:39 -08001677
1678#if CONFIG_DUAL_FILTER
Yaowu Xuc27fc142016-08-22 16:08:15 -07001679 if (cm->interp_filter != SWITCHABLE) {
Yue Chen19e7aa82016-11-30 14:05:39 -08001680 int dir;
1681
Angie Chiang9c4f8952016-11-21 11:13:19 -08001682 for (dir = 0; dir < 4; ++dir) mbmi->interp_filter[dir] = cm->interp_filter;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001683 } else {
Yue Chen19e7aa82016-11-30 14:05:39 -08001684 int dir;
1685
Angie Chiang9c4f8952016-11-21 11:13:19 -08001686 for (dir = 0; dir < 2; ++dir) {
1687 const int ctx = av1_get_pred_context_switchable_interp(xd, dir);
1688 mbmi->interp_filter[dir] = EIGHTTAP_REGULAR;
1689
1690 if (has_subpel_mv_component(xd->mi[0], xd, dir) ||
1691 (mbmi->ref_frame[1] > INTRA_FRAME &&
1692 has_subpel_mv_component(xd->mi[0], xd, dir + 2))) {
Angie Chiang9c4f8952016-11-21 11:13:19 -08001693 mbmi->interp_filter[dir] =
1694 (InterpFilter)av1_switchable_interp_inv[aom_read_symbol(
Thomas Davies77c7c402017-01-11 17:58:54 +00001695 r, ec_ctx->switchable_interp_cdf[ctx], SWITCHABLE_FILTERS,
Angie Chiang9c4f8952016-11-21 11:13:19 -08001696 ACCT_STR)];
Angie Chiang9c4f8952016-11-21 11:13:19 -08001697 if (counts) ++counts->switchable_interp[ctx][mbmi->interp_filter[dir]];
1698 }
1699 }
1700 // The index system works as:
1701 // (0, 1) -> (vertical, horizontal) filter types for the first ref frame.
1702 // (2, 3) -> (vertical, horizontal) filter types for the second ref frame.
1703 mbmi->interp_filter[2] = mbmi->interp_filter[0];
1704 mbmi->interp_filter[3] = mbmi->interp_filter[1];
1705 }
Nathan E. Egge476c63c2017-05-18 18:35:16 -04001706#else // CONFIG_DUAL_FILTER
Angie Chiang9c4f8952016-11-21 11:13:19 -08001707 if (cm->interp_filter != SWITCHABLE) {
1708 mbmi->interp_filter = cm->interp_filter;
1709 } else {
1710 const int ctx = av1_get_pred_context_switchable_interp(xd);
Angie Chiang9c4f8952016-11-21 11:13:19 -08001711 mbmi->interp_filter =
Michael Bebenita6048d052016-08-25 14:40:54 -07001712 (InterpFilter)av1_switchable_interp_inv[aom_read_symbol(
Thomas Davies77c7c402017-01-11 17:58:54 +00001713 r, ec_ctx->switchable_interp_cdf[ctx], SWITCHABLE_FILTERS,
Michael Bebenita6048d052016-08-25 14:40:54 -07001714 ACCT_STR)];
Angie Chiang9c4f8952016-11-21 11:13:19 -08001715 if (counts) ++counts->switchable_interp[ctx][mbmi->interp_filter];
Yaowu Xuc27fc142016-08-22 16:08:15 -07001716 }
Angie Chiang9c4f8952016-11-21 11:13:19 -08001717#endif // CONFIG_DUAL_FILTER
Yaowu Xuc27fc142016-08-22 16:08:15 -07001718}
1719
Jingning Han36fe3202017-02-20 22:31:49 -08001720static void read_intra_block_mode_info(AV1_COMMON *const cm, const int mi_row,
1721 const int mi_col, MACROBLOCKD *const xd,
1722 MODE_INFO *mi, aom_reader *r) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001723 MB_MODE_INFO *const mbmi = &mi->mbmi;
1724 const BLOCK_SIZE bsize = mi->mbmi.sb_type;
1725 int i;
1726
1727 mbmi->ref_frame[0] = INTRA_FRAME;
Emil Keyder01770b32017-01-20 18:03:11 -05001728 mbmi->ref_frame[1] = NONE_FRAME;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001729
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001730 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001731
Jingning Han52261842016-12-14 12:17:49 -08001732#if CONFIG_CB4X4
1733 (void)i;
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001734 mbmi->mode = read_intra_mode_y(ec_ctx, xd, r, size_group_lookup[bsize]);
Jingning Han52261842016-12-14 12:17:49 -08001735#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001736 switch (bsize) {
1737 case BLOCK_4X4:
1738 for (i = 0; i < 4; ++i)
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001739 mi->bmi[i].as_mode = read_intra_mode_y(ec_ctx, xd, r, 0);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001740 mbmi->mode = mi->bmi[3].as_mode;
1741 break;
1742 case BLOCK_4X8:
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001743 mi->bmi[0].as_mode = mi->bmi[2].as_mode =
1744 read_intra_mode_y(ec_ctx, xd, r, 0);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001745 mi->bmi[1].as_mode = mi->bmi[3].as_mode = mbmi->mode =
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001746 read_intra_mode_y(ec_ctx, xd, r, 0);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001747 break;
1748 case BLOCK_8X4:
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001749 mi->bmi[0].as_mode = mi->bmi[1].as_mode =
1750 read_intra_mode_y(ec_ctx, xd, r, 0);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001751 mi->bmi[2].as_mode = mi->bmi[3].as_mode = mbmi->mode =
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001752 read_intra_mode_y(ec_ctx, xd, r, 0);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001753 break;
1754 default:
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001755 mbmi->mode = read_intra_mode_y(ec_ctx, xd, r, size_group_lookup[bsize]);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001756 }
Jingning Han52261842016-12-14 12:17:49 -08001757#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001758
Jingning Han36fe3202017-02-20 22:31:49 -08001759#if CONFIG_CB4X4
Jingning Hand3a64432017-04-06 17:04:17 -07001760 if (is_chroma_reference(mi_row, mi_col, bsize, xd->plane[1].subsampling_x,
Luc Trudeaub09b55d2017-04-26 10:06:35 -04001761 xd->plane[1].subsampling_y)) {
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001762 mbmi->uv_mode = read_intra_mode_uv(ec_ctx, xd, r, mbmi->mode);
Jingning Han36fe3202017-02-20 22:31:49 -08001763#else
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001764 mbmi->uv_mode = read_intra_mode_uv(ec_ctx, xd, r, mbmi->mode);
Jingning Han36fe3202017-02-20 22:31:49 -08001765 (void)mi_row;
1766 (void)mi_col;
1767#endif
1768
Luc Trudeaub09b55d2017-04-26 10:06:35 -04001769#if CONFIG_CFL
1770 // TODO(ltrudeau) support PALETTE
1771 if (mbmi->uv_mode == DC_PRED) {
Nathan E. Egge6bdc40f2017-06-18 19:02:23 -04001772 mbmi->cfl_alpha_idx =
1773 read_cfl_alphas(xd->tile_ctx, r, mbmi->cfl_alpha_signs);
Luc Trudeaub09b55d2017-04-26 10:06:35 -04001774 }
1775#endif // CONFIG_CFL
1776
1777#if CONFIG_CB4X4
1778 }
1779#endif
1780
Yaowu Xuc27fc142016-08-22 16:08:15 -07001781#if CONFIG_EXT_INTRA
1782 read_intra_angle_info(cm, xd, r);
1783#endif // CONFIG_EXT_INTRA
Urvang Joshib100db72016-10-12 16:28:56 -07001784#if CONFIG_PALETTE
Yaowu Xuc27fc142016-08-22 16:08:15 -07001785 mbmi->palette_mode_info.palette_size[0] = 0;
1786 mbmi->palette_mode_info.palette_size[1] = 0;
1787 if (bsize >= BLOCK_8X8 && cm->allow_screen_content_tools)
1788 read_palette_mode_info(cm, xd, r);
Urvang Joshib100db72016-10-12 16:28:56 -07001789#endif // CONFIG_PALETTE
hui su5db97432016-10-14 16:10:14 -07001790#if CONFIG_FILTER_INTRA
1791 mbmi->filter_intra_mode_info.use_filter_intra_mode[0] = 0;
1792 mbmi->filter_intra_mode_info.use_filter_intra_mode[1] = 0;
Jingning Han48b1cb32017-01-23 10:26:14 -08001793 if (bsize >= BLOCK_8X8 || CONFIG_CB4X4)
Jingning Han62946d12017-05-26 11:29:30 -07001794 read_filter_intra_mode_info(cm, xd, mi_row, mi_col, r);
hui su5db97432016-10-14 16:10:14 -07001795#endif // CONFIG_FILTER_INTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -07001796}
1797
1798static INLINE int is_mv_valid(const MV *mv) {
1799 return mv->row > MV_LOW && mv->row < MV_UPP && mv->col > MV_LOW &&
1800 mv->col < MV_UPP;
1801}
1802
Yaowu Xuf883b422016-08-30 14:01:10 -07001803static INLINE int assign_mv(AV1_COMMON *cm, MACROBLOCKD *xd,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001804 PREDICTION_MODE mode,
Jingning Han5c60cdf2016-09-30 09:37:46 -07001805 MV_REFERENCE_FRAME ref_frame[2], int block,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001806 int_mv mv[2], int_mv ref_mv[2],
David Barker45390c12017-02-20 14:44:40 +00001807 int_mv nearest_mv[2], int_mv near_mv[2], int mi_row,
1808 int mi_col, int is_compound, int allow_hp,
1809 aom_reader *r) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001810 int i;
1811 int ret = 1;
Thomas Davies24523292017-01-11 16:56:47 +00001812 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
Debargha Mukherjeef6dd3c62017-02-23 13:21:23 -08001813 BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001814 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
Jingning Han5cfa6712016-12-14 09:53:38 -08001815#if CONFIG_CB4X4
1816 int_mv *pred_mv = mbmi->pred_mv;
1817 (void)block;
1818#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001819 int_mv *pred_mv =
Yaowu Xuf5bbbfa2016-09-26 09:13:38 -07001820 (bsize >= BLOCK_8X8) ? mbmi->pred_mv : xd->mi[0]->bmi[block].pred_mv;
Jingning Han5cfa6712016-12-14 09:53:38 -08001821#endif // CONFIG_CB4X4
Sarah Parkere5299862016-08-16 14:57:37 -07001822 (void)ref_frame;
Thomas Davies24523292017-01-11 16:56:47 +00001823 (void)cm;
David Barker45390c12017-02-20 14:44:40 +00001824 (void)mi_row;
1825 (void)mi_col;
Debargha Mukherjeef6dd3c62017-02-23 13:21:23 -08001826 (void)bsize;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001827
1828 switch (mode) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001829 case NEWMV: {
1830 FRAME_COUNTS *counts = xd->counts;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001831 for (i = 0; i < 1 + is_compound; ++i) {
Yaowu Xu4306b6e2016-09-27 12:55:32 -07001832 int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
1833 int nmv_ctx =
1834 av1_nmv_ctx(xd->ref_mv_count[rf_type], xd->ref_mv_stack[rf_type], i,
1835 mbmi->ref_mv_idx);
Alex Converse3d0bdc12017-05-01 15:19:58 -07001836 nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
Yaowu Xuc27fc142016-08-22 16:08:15 -07001837 nmv_context_counts *const mv_counts =
1838 counts ? &counts->mv[nmv_ctx] : NULL;
Alex Converse3d0bdc12017-05-01 15:19:58 -07001839 read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, nmvc, mv_counts, allow_hp);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001840 ret = ret && is_mv_valid(&mv[i].as_mv);
1841
Yaowu Xuc27fc142016-08-22 16:08:15 -07001842 pred_mv[i].as_int = ref_mv[i].as_int;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001843 }
1844 break;
1845 }
1846 case NEARESTMV: {
1847 mv[0].as_int = nearest_mv[0].as_int;
1848 if (is_compound) mv[1].as_int = nearest_mv[1].as_int;
1849
Yaowu Xuc27fc142016-08-22 16:08:15 -07001850 pred_mv[0].as_int = nearest_mv[0].as_int;
1851 if (is_compound) pred_mv[1].as_int = nearest_mv[1].as_int;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001852 break;
1853 }
1854 case NEARMV: {
1855 mv[0].as_int = near_mv[0].as_int;
1856 if (is_compound) mv[1].as_int = near_mv[1].as_int;
1857
Yaowu Xuc27fc142016-08-22 16:08:15 -07001858 pred_mv[0].as_int = near_mv[0].as_int;
1859 if (is_compound) pred_mv[1].as_int = near_mv[1].as_int;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001860 break;
1861 }
1862 case ZEROMV: {
Sarah Parkere5299862016-08-16 14:57:37 -07001863#if CONFIG_GLOBAL_MOTION
David Barkercdcac6d2016-12-01 17:04:16 +00001864 mv[0].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[0]],
Sarah Parkerae7c4582017-02-28 16:30:30 -08001865 cm->allow_high_precision_mv, bsize,
Debargha Mukherjeefebb59c2017-03-02 12:23:45 -08001866 mi_col, mi_row, block)
David Barkercdcac6d2016-12-01 17:04:16 +00001867 .as_int;
Sarah Parkere5299862016-08-16 14:57:37 -07001868 if (is_compound)
David Barkercdcac6d2016-12-01 17:04:16 +00001869 mv[1].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[1]],
Sarah Parkerae7c4582017-02-28 16:30:30 -08001870 cm->allow_high_precision_mv, bsize,
Debargha Mukherjeefebb59c2017-03-02 12:23:45 -08001871 mi_col, mi_row, block)
David Barkercdcac6d2016-12-01 17:04:16 +00001872 .as_int;
Sarah Parkere5299862016-08-16 14:57:37 -07001873#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001874 mv[0].as_int = 0;
1875 if (is_compound) mv[1].as_int = 0;
Sarah Parkere5299862016-08-16 14:57:37 -07001876#endif // CONFIG_GLOBAL_MOTION
Yaowu Xuc27fc142016-08-22 16:08:15 -07001877
Debargha Mukherjeefebb59c2017-03-02 12:23:45 -08001878 pred_mv[0].as_int = mv[0].as_int;
1879 if (is_compound) pred_mv[1].as_int = mv[1].as_int;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001880 break;
1881 }
1882#if CONFIG_EXT_INTER
Zoe Liu85b66462017-04-20 14:28:19 -07001883#if CONFIG_COMPOUND_SINGLEREF
1884 case SR_NEAREST_NEARMV: {
1885 assert(!is_compound);
1886 mv[0].as_int = nearest_mv[0].as_int;
1887 mv[1].as_int = near_mv[0].as_int;
1888 break;
1889 }
1890 /*
1891 case SR_NEAREST_NEWMV: {
1892 assert(!is_compound);
1893 mv[0].as_int = nearest_mv[0].as_int;
1894
1895 FRAME_COUNTS *counts = xd->counts;
1896 int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
1897 int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type],
1898 xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx);
1899 nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
1900 nmv_context_counts *const mv_counts =
1901 counts ? &counts->mv[nmv_ctx] : NULL;
1902 read_mv(r, &mv[1].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp);
1903 ret = ret && is_mv_valid(&mv[1].as_mv);
1904 break;
1905 }*/
1906 case SR_NEAR_NEWMV: {
1907 assert(!is_compound);
1908 mv[0].as_int = near_mv[0].as_int;
1909
1910 FRAME_COUNTS *counts = xd->counts;
1911 int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
1912 int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type],
1913 xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx);
1914 nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
1915 nmv_context_counts *const mv_counts =
1916 counts ? &counts->mv[nmv_ctx] : NULL;
1917 read_mv(r, &mv[1].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp);
1918 ret = ret && is_mv_valid(&mv[1].as_mv);
1919 break;
1920 }
1921 case SR_ZERO_NEWMV: {
1922 assert(!is_compound);
1923#if CONFIG_GLOBAL_MOTION
1924 mv[0].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[0]],
1925 cm->allow_high_precision_mv, bsize,
1926 mi_col, mi_row, block)
1927 .as_int;
1928#else
1929 mv[0].as_int = 0;
1930#endif // CONFIG_GLOBAL_MOTION
1931
1932 FRAME_COUNTS *counts = xd->counts;
1933 int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
1934 int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type],
1935 xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx);
1936 nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
1937 nmv_context_counts *const mv_counts =
1938 counts ? &counts->mv[nmv_ctx] : NULL;
1939 read_mv(r, &mv[1].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp);
1940 ret = ret && is_mv_valid(&mv[1].as_mv);
1941 break;
1942 }
1943 case SR_NEW_NEWMV: {
1944 assert(!is_compound);
1945
1946 FRAME_COUNTS *counts = xd->counts;
1947 for (i = 0; i < 2; ++i) {
1948 int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
1949 int nmv_ctx =
1950 av1_nmv_ctx(xd->ref_mv_count[rf_type], xd->ref_mv_stack[rf_type], 0,
1951 mbmi->ref_mv_idx);
1952 nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
1953 nmv_context_counts *const mv_counts =
1954 counts ? &counts->mv[nmv_ctx] : NULL;
1955 read_mv(r, &mv[i].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp);
1956 ret = ret && is_mv_valid(&mv[i].as_mv);
1957 }
1958 break;
1959 }
1960#endif // CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -07001961 case NEW_NEWMV: {
1962 FRAME_COUNTS *counts = xd->counts;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001963 assert(is_compound);
1964 for (i = 0; i < 2; ++i) {
Yaowu Xu4306b6e2016-09-27 12:55:32 -07001965 int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
1966 int nmv_ctx =
1967 av1_nmv_ctx(xd->ref_mv_count[rf_type], xd->ref_mv_stack[rf_type], i,
1968 mbmi->ref_mv_idx);
Alex Converse3d0bdc12017-05-01 15:19:58 -07001969 nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
Yaowu Xuc27fc142016-08-22 16:08:15 -07001970 nmv_context_counts *const mv_counts =
1971 counts ? &counts->mv[nmv_ctx] : NULL;
Alex Converse3d0bdc12017-05-01 15:19:58 -07001972 read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, nmvc, mv_counts, allow_hp);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001973 ret = ret && is_mv_valid(&mv[i].as_mv);
1974 }
1975 break;
1976 }
1977 case NEAREST_NEARESTMV: {
1978 assert(is_compound);
1979 mv[0].as_int = nearest_mv[0].as_int;
1980 mv[1].as_int = nearest_mv[1].as_int;
1981 break;
1982 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07001983 case NEAR_NEARMV: {
1984 assert(is_compound);
1985 mv[0].as_int = near_mv[0].as_int;
1986 mv[1].as_int = near_mv[1].as_int;
1987 break;
1988 }
1989 case NEW_NEARESTMV: {
1990 FRAME_COUNTS *counts = xd->counts;
Yaowu Xu4306b6e2016-09-27 12:55:32 -07001991 int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
1992 int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type],
1993 xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx);
Alex Converse3d0bdc12017-05-01 15:19:58 -07001994 nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
Yaowu Xuc27fc142016-08-22 16:08:15 -07001995 nmv_context_counts *const mv_counts =
1996 counts ? &counts->mv[nmv_ctx] : NULL;
Alex Converse3d0bdc12017-05-01 15:19:58 -07001997 read_mv(r, &mv[0].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001998 assert(is_compound);
1999 ret = ret && is_mv_valid(&mv[0].as_mv);
2000 mv[1].as_int = nearest_mv[1].as_int;
2001 break;
2002 }
2003 case NEAREST_NEWMV: {
2004 FRAME_COUNTS *counts = xd->counts;
Yaowu Xu4306b6e2016-09-27 12:55:32 -07002005 int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
2006 int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type],
2007 xd->ref_mv_stack[rf_type], 1, mbmi->ref_mv_idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002008 nmv_context_counts *const mv_counts =
2009 counts ? &counts->mv[nmv_ctx] : NULL;
Alex Converse3d0bdc12017-05-01 15:19:58 -07002010 nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
Alex Converse3d0bdc12017-05-01 15:19:58 -07002011 mv[0].as_int = nearest_mv[0].as_int;
2012 read_mv(r, &mv[1].as_mv, &ref_mv[1].as_mv, nmvc, mv_counts, allow_hp);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002013 assert(is_compound);
2014 ret = ret && is_mv_valid(&mv[1].as_mv);
2015 break;
2016 }
2017 case NEAR_NEWMV: {
2018 FRAME_COUNTS *counts = xd->counts;
Yaowu Xu4306b6e2016-09-27 12:55:32 -07002019 int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
2020 int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type],
2021 xd->ref_mv_stack[rf_type], 1, mbmi->ref_mv_idx);
Alex Converse3d0bdc12017-05-01 15:19:58 -07002022 nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
Yaowu Xuc27fc142016-08-22 16:08:15 -07002023 nmv_context_counts *const mv_counts =
2024 counts ? &counts->mv[nmv_ctx] : NULL;
Alex Converse3d0bdc12017-05-01 15:19:58 -07002025 mv[0].as_int = near_mv[0].as_int;
2026 read_mv(r, &mv[1].as_mv, &ref_mv[1].as_mv, nmvc, mv_counts, allow_hp);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002027 assert(is_compound);
2028
2029 ret = ret && is_mv_valid(&mv[1].as_mv);
2030 break;
2031 }
2032 case NEW_NEARMV: {
2033 FRAME_COUNTS *counts = xd->counts;
Yaowu Xu4306b6e2016-09-27 12:55:32 -07002034 int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
2035 int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type],
2036 xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx);
Alex Converse3d0bdc12017-05-01 15:19:58 -07002037 nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
Yaowu Xuc27fc142016-08-22 16:08:15 -07002038 nmv_context_counts *const mv_counts =
2039 counts ? &counts->mv[nmv_ctx] : NULL;
Alex Converse3d0bdc12017-05-01 15:19:58 -07002040 read_mv(r, &mv[0].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002041 assert(is_compound);
2042 ret = ret && is_mv_valid(&mv[0].as_mv);
2043 mv[1].as_int = near_mv[1].as_int;
2044 break;
2045 }
2046 case ZERO_ZEROMV: {
2047 assert(is_compound);
Sarah Parkerc2d38712017-01-24 15:15:41 -08002048#if CONFIG_GLOBAL_MOTION
2049 mv[0].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[0]],
Sarah Parkerae7c4582017-02-28 16:30:30 -08002050 cm->allow_high_precision_mv, bsize,
Debargha Mukherjeefebb59c2017-03-02 12:23:45 -08002051 mi_col, mi_row, block)
Sarah Parkerc2d38712017-01-24 15:15:41 -08002052 .as_int;
2053 mv[1].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[1]],
Sarah Parkerae7c4582017-02-28 16:30:30 -08002054 cm->allow_high_precision_mv, bsize,
Debargha Mukherjeefebb59c2017-03-02 12:23:45 -08002055 mi_col, mi_row, block)
Sarah Parkerc2d38712017-01-24 15:15:41 -08002056 .as_int;
2057#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07002058 mv[0].as_int = 0;
2059 mv[1].as_int = 0;
Sarah Parkerc2d38712017-01-24 15:15:41 -08002060#endif // CONFIG_GLOBAL_MOTION
Yaowu Xuc27fc142016-08-22 16:08:15 -07002061 break;
2062 }
2063#endif // CONFIG_EXT_INTER
2064 default: { return 0; }
2065 }
2066 return ret;
2067}
2068
Yaowu Xuf883b422016-08-30 14:01:10 -07002069static int read_is_inter_block(AV1_COMMON *const cm, MACROBLOCKD *const xd,
2070 int segment_id, aom_reader *r) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07002071 if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) {
2072 return get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME) != INTRA_FRAME;
2073 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -07002074 const int ctx = av1_get_intra_inter_context(xd);
Thomas Daviesf6ad9352017-04-19 11:38:06 +01002075#if CONFIG_NEW_MULTISYMBOL
Thomas Daviesf6ad9352017-04-19 11:38:06 +01002076 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
Thomas Daviesf6ad9352017-04-19 11:38:06 +01002077 const int is_inter =
2078 aom_read_symbol(r, ec_ctx->intra_inter_cdf[ctx], 2, ACCT_STR);
2079#else
Michael Bebenita6048d052016-08-25 14:40:54 -07002080 const int is_inter = aom_read(r, cm->fc->intra_inter_prob[ctx], ACCT_STR);
Thomas Daviesf6ad9352017-04-19 11:38:06 +01002081#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002082 FRAME_COUNTS *counts = xd->counts;
2083 if (counts) ++counts->intra_inter[ctx][is_inter];
2084 return is_inter;
2085 }
2086}
2087
Zoe Liu85b66462017-04-20 14:28:19 -07002088#if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
2089static int read_is_inter_singleref_comp_mode(AV1_COMMON *const cm,
2090 MACROBLOCKD *const xd,
2091 int segment_id, aom_reader *r) {
2092 if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) return 0;
2093
2094 const int ctx = av1_get_inter_mode_context(xd);
2095 const int is_singleref_comp_mode =
2096 aom_read(r, cm->fc->comp_inter_mode_prob[ctx], ACCT_STR);
2097 FRAME_COUNTS *counts = xd->counts;
2098
2099 if (counts) ++counts->comp_inter_mode[ctx][is_singleref_comp_mode];
2100 return is_singleref_comp_mode;
2101}
2102#endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
2103
Yaowu Xuc27fc142016-08-22 16:08:15 -07002104static void fpm_sync(void *const data, int mi_row) {
Yaowu Xuf883b422016-08-30 14:01:10 -07002105 AV1Decoder *const pbi = (AV1Decoder *)data;
2106 av1_frameworker_wait(pbi->frame_worker_owner, pbi->common.prev_frame,
2107 mi_row << pbi->common.mib_size_log2);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002108}
2109
Di Chen56586622017-06-09 13:49:44 -07002110#if DEC_MISMATCH_DEBUG
2111static void dec_dump_logs(AV1_COMMON *cm, MODE_INFO *const mi,
Zoe Liuf9333f52017-07-03 10:52:01 -07002112 MACROBLOCKD *const xd, int mi_row, int mi_col,
2113 int16_t inter_mode_ctx[MODE_CTX_REF_FRAMES],
2114 int16_t mode_ctx) {
Di Chen56586622017-06-09 13:49:44 -07002115 int_mv mv[2] = { { 0 } };
2116 int ref;
2117 MB_MODE_INFO *const mbmi = &mi->mbmi;
Di Chen56586622017-06-09 13:49:44 -07002118 for (ref = 0; ref < 1 + has_second_ref(mbmi); ++ref)
2119 mv[ref].as_mv = mbmi->mv[ref].as_mv;
2120
2121 int interp_ctx[2] = { -1 };
2122 int interp_filter[2] = { cm->interp_filter };
2123 if (cm->interp_filter == SWITCHABLE) {
2124 int dir;
2125 for (dir = 0; dir < 2; ++dir) {
2126 if (has_subpel_mv_component(xd->mi[0], xd, dir) ||
2127 (mbmi->ref_frame[1] > INTRA_FRAME &&
2128 has_subpel_mv_component(xd->mi[0], xd, dir + 2))) {
2129 interp_ctx[dir] = av1_get_pred_context_switchable_interp(xd, dir);
2130 interp_filter[dir] = mbmi->interp_filter[dir];
2131 } else {
2132 interp_filter[dir] = EIGHTTAP_REGULAR;
2133 }
2134 }
2135 }
2136
2137 const int16_t newmv_ctx = mode_ctx & NEWMV_CTX_MASK;
2138 int16_t zeromv_ctx = -1;
2139 int16_t refmv_ctx = -1;
2140 if (mbmi->mode != NEWMV) {
2141 if (mode_ctx & (1 << ALL_ZERO_FLAG_OFFSET)) assert(mbmi->mode == ZEROMV);
2142 zeromv_ctx = (mode_ctx >> ZEROMV_OFFSET) & ZEROMV_CTX_MASK;
2143 if (mbmi->mode != ZEROMV) {
2144 refmv_ctx = (mode_ctx >> REFMV_OFFSET) & REFMV_CTX_MASK;
2145 if (mode_ctx & (1 << SKIP_NEARESTMV_OFFSET)) refmv_ctx = 6;
2146 if (mode_ctx & (1 << SKIP_NEARMV_OFFSET)) refmv_ctx = 7;
2147 if (mode_ctx & (1 << SKIP_NEARESTMV_SUB8X8_OFFSET)) refmv_ctx = 8;
2148 }
2149 }
2150
2151 int8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
Zoe Liuf9333f52017-07-03 10:52:01 -07002152#define FRAME_TO_CHECK 1
Zoe Liufcf5fa22017-06-26 16:00:38 -07002153 if (cm->current_video_frame == FRAME_TO_CHECK /*&& cm->show_frame == 0*/) {
Zoe Liuf9333f52017-07-03 10:52:01 -07002154 printf(
2155 "=== DECODER ===: "
2156 "Frame=%d, (mi_row,mi_col)=(%d,%d), mode=%d, bsize=%d, "
2157 "show_frame=%d, mv[0]=(%d,%d), mv[1]=(%d,%d), ref[0]=%d, "
2158 "ref[1]=%d, motion_mode=%d, inter_mode_ctx=%d, mode_ctx=%d, "
2159 "interp_ctx=(%d,%d), interp_filter=(%d,%d), newmv_ctx=%d, "
2160 "zeromv_ctx=%d, refmv_ctx=%d\n",
2161 cm->current_video_frame, mi_row, mi_col, mbmi->mode, mbmi->sb_type,
2162 cm->show_frame, mv[0].as_mv.row, mv[0].as_mv.col, mv[1].as_mv.row,
2163 mv[1].as_mv.col, mbmi->ref_frame[0], mbmi->ref_frame[1],
2164 mbmi->motion_mode, inter_mode_ctx[ref_frame_type], mode_ctx,
2165 interp_ctx[0], interp_ctx[1], interp_filter[0], interp_filter[1],
2166 newmv_ctx, zeromv_ctx, refmv_ctx);
2167 }
Di Chen56586622017-06-09 13:49:44 -07002168}
2169#endif // DEC_MISMATCH_DEBUG
2170
Yaowu Xuf883b422016-08-30 14:01:10 -07002171static void read_inter_block_mode_info(AV1Decoder *const pbi,
Yaowu Xuc27fc142016-08-22 16:08:15 -07002172 MACROBLOCKD *const xd,
2173 MODE_INFO *const mi,
David Barker491983d2016-11-10 13:22:17 +00002174#if (CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION || CONFIG_EXT_INTER) && \
2175 CONFIG_SUPERTX
Yaowu Xuf883b422016-08-30 14:01:10 -07002176 int mi_row, int mi_col, aom_reader *r,
Yaowu Xuc27fc142016-08-22 16:08:15 -07002177 int supertx_enabled) {
2178#else
Yaowu Xuf883b422016-08-30 14:01:10 -07002179 int mi_row, int mi_col, aom_reader *r) {
Yue Chencb60b182016-10-13 15:18:22 -07002180#endif // CONFIG_MOTION_VAR && CONFIG_SUPERTX
Yaowu Xuf883b422016-08-30 14:01:10 -07002181 AV1_COMMON *const cm = &pbi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002182 MB_MODE_INFO *const mbmi = &mi->mbmi;
2183 const BLOCK_SIZE bsize = mbmi->sb_type;
2184 const int allow_hp = cm->allow_high_precision_mv;
Jingning Han5cfa6712016-12-14 09:53:38 -08002185 const int unify_bsize = CONFIG_CB4X4;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002186 int_mv nearestmv[2], nearmv[2];
2187 int_mv ref_mvs[MODE_CTX_REF_FRAMES][MAX_MV_REF_CANDIDATES];
Yaowu Xuc27fc142016-08-22 16:08:15 -07002188 int ref, is_compound;
Zoe Liu85b66462017-04-20 14:28:19 -07002189#if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
2190 int is_singleref_comp_mode = 0;
2191#endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -07002192 int16_t inter_mode_ctx[MODE_CTX_REF_FRAMES];
Sebastien Alaiwane140c502017-04-27 09:52:34 +02002193#if CONFIG_EXT_INTER
Yaowu Xuc27fc142016-08-22 16:08:15 -07002194 int16_t compound_inter_mode_ctx[MODE_CTX_REF_FRAMES];
Sebastien Alaiwane140c502017-04-27 09:52:34 +02002195#endif // CONFIG_EXT_INTER
Yaowu Xuc27fc142016-08-22 16:08:15 -07002196 int16_t mode_ctx = 0;
Yue Chen69f18e12016-09-08 14:48:15 -07002197#if CONFIG_WARPED_MOTION
Debargha Mukherjeee6eb3b52017-02-26 08:50:56 -08002198 int pts[SAMPLES_ARRAY_SIZE], pts_inref[SAMPLES_ARRAY_SIZE];
Yunqing Wang1bc82862017-06-28 15:49:48 -07002199#if WARPED_MOTION_SORT_SAMPLES
2200 int pts_mv[SAMPLES_ARRAY_SIZE];
2201#endif // WARPED_MOTION_SORT_SAMPLES
Yue Chen69f18e12016-09-08 14:48:15 -07002202#endif // CONFIG_WARPED_MOTION
Thomas Davies1de6c882017-01-11 17:47:49 +00002203 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002204
Urvang Joshi5a9ea002017-05-22 15:25:18 -07002205 assert(NELEMENTS(mode_2_counter) == MB_MODE_COUNT);
2206
Urvang Joshib100db72016-10-12 16:28:56 -07002207#if CONFIG_PALETTE
Yaowu Xuc27fc142016-08-22 16:08:15 -07002208 mbmi->palette_mode_info.palette_size[0] = 0;
2209 mbmi->palette_mode_info.palette_size[1] = 0;
Urvang Joshib100db72016-10-12 16:28:56 -07002210#endif // CONFIG_PALETTE
Yaowu Xuc27fc142016-08-22 16:08:15 -07002211
Frederic Barbier7a84fd82017-03-02 18:08:15 +01002212 memset(ref_mvs, 0, sizeof(ref_mvs));
2213
Yaowu Xuc27fc142016-08-22 16:08:15 -07002214 read_ref_frames(cm, xd, r, mbmi->segment_id, mbmi->ref_frame);
2215 is_compound = has_second_ref(mbmi);
2216
Zoe Liuc082bbc2017-05-17 13:31:37 -07002217#if CONFIG_EXT_COMP_REFS
2218#if !USE_UNI_COMP_REFS
2219 // NOTE: uni-directional comp refs disabled
2220 if (is_compound)
2221 assert(mbmi->ref_frame[0] < BWDREF_FRAME &&
2222 mbmi->ref_frame[1] >= BWDREF_FRAME);
2223#endif // !USE_UNI_COMP_REFS
2224#endif // CONFIG_EXT_COMP_REFS
2225
Zoe Liu85b66462017-04-20 14:28:19 -07002226#if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
2227 if (!is_compound)
2228 is_singleref_comp_mode =
2229 read_is_inter_singleref_comp_mode(cm, xd, mbmi->segment_id, r);
2230#endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
2231
Yaowu Xuc27fc142016-08-22 16:08:15 -07002232 for (ref = 0; ref < 1 + is_compound; ++ref) {
2233 MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref];
Yaowu Xuc27fc142016-08-22 16:08:15 -07002234
Sebastien Alaiwane140c502017-04-27 09:52:34 +02002235 av1_find_mv_refs(
2236 cm, xd, mi, frame, &xd->ref_mv_count[frame], xd->ref_mv_stack[frame],
Yaowu Xuc27fc142016-08-22 16:08:15 -07002237#if CONFIG_EXT_INTER
Sebastien Alaiwane140c502017-04-27 09:52:34 +02002238 compound_inter_mode_ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -07002239#endif // CONFIG_EXT_INTER
Sebastien Alaiwane140c502017-04-27 09:52:34 +02002240 ref_mvs[frame], mi_row, mi_col, fpm_sync, (void *)pbi, inter_mode_ctx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002241 }
2242
Jingning Hanacddc032016-11-17 15:26:20 -08002243 if (is_compound) {
2244 MV_REFERENCE_FRAME ref_frame = av1_ref_frame_type(mbmi->ref_frame);
Yaowu Xu4306b6e2016-09-27 12:55:32 -07002245 av1_find_mv_refs(cm, xd, mi, ref_frame, &xd->ref_mv_count[ref_frame],
2246 xd->ref_mv_stack[ref_frame],
2247#if CONFIG_EXT_INTER
2248 compound_inter_mode_ctx,
2249#endif // CONFIG_EXT_INTER
2250 ref_mvs[ref_frame], mi_row, mi_col, fpm_sync, (void *)pbi,
2251 inter_mode_ctx);
2252
2253 if (xd->ref_mv_count[ref_frame] < 2) {
2254 MV_REFERENCE_FRAME rf[2];
David Barkercdcac6d2016-12-01 17:04:16 +00002255 int_mv zeromv[2];
Yaowu Xu4306b6e2016-09-27 12:55:32 -07002256 av1_set_ref_frame(rf, ref_frame);
David Barkercdcac6d2016-12-01 17:04:16 +00002257#if CONFIG_GLOBAL_MOTION
2258 zeromv[0].as_int = gm_get_motion_vector(&cm->global_motion[rf[0]],
David Barker45390c12017-02-20 14:44:40 +00002259 cm->allow_high_precision_mv,
Debargha Mukherjeefebb59c2017-03-02 12:23:45 -08002260 bsize, mi_col, mi_row, 0)
David Barkercdcac6d2016-12-01 17:04:16 +00002261 .as_int;
Sarah Parkerae7c4582017-02-28 16:30:30 -08002262 zeromv[1].as_int = (rf[1] != NONE_FRAME)
2263 ? gm_get_motion_vector(&cm->global_motion[rf[1]],
2264 cm->allow_high_precision_mv,
Debargha Mukherjeefebb59c2017-03-02 12:23:45 -08002265 bsize, mi_col, mi_row, 0)
Sarah Parkerae7c4582017-02-28 16:30:30 -08002266 .as_int
2267 : 0;
David Barkercdcac6d2016-12-01 17:04:16 +00002268#else
2269 zeromv[0].as_int = zeromv[1].as_int = 0;
2270#endif
Sarah Parker9923d1b2017-04-10 11:56:40 -07002271 for (ref = 0; ref < 2; ++ref) {
2272 if (rf[ref] == NONE_FRAME) continue;
Yaowu Xu4306b6e2016-09-27 12:55:32 -07002273 lower_mv_precision(&ref_mvs[rf[ref]][0].as_mv, allow_hp);
2274 lower_mv_precision(&ref_mvs[rf[ref]][1].as_mv, allow_hp);
Sarah Parker9923d1b2017-04-10 11:56:40 -07002275 if (ref_mvs[rf[ref]][0].as_int != zeromv[ref].as_int ||
2276 ref_mvs[rf[ref]][1].as_int != zeromv[ref].as_int)
2277 inter_mode_ctx[ref_frame] &= ~(1 << ALL_ZERO_FLAG_OFFSET);
Frederic Barbier72e2e982017-03-03 10:01:04 +01002278 }
Yaowu Xu4306b6e2016-09-27 12:55:32 -07002279 }
2280 }
2281
Yaowu Xuc27fc142016-08-22 16:08:15 -07002282#if CONFIG_EXT_INTER
Zoe Liu85b66462017-04-20 14:28:19 -07002283#if CONFIG_COMPOUND_SINGLEREF
2284 if (is_compound || is_singleref_comp_mode)
2285#else // !CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -07002286 if (is_compound)
Zoe Liu85b66462017-04-20 14:28:19 -07002287#endif // CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -07002288 mode_ctx = compound_inter_mode_ctx[mbmi->ref_frame[0]];
2289 else
2290#endif // CONFIG_EXT_INTER
2291 mode_ctx =
Yaowu Xuf883b422016-08-30 14:01:10 -07002292 av1_mode_context_analyzer(inter_mode_ctx, mbmi->ref_frame, bsize, -1);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002293 mbmi->ref_mv_idx = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002294
2295 if (segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) {
2296 mbmi->mode = ZEROMV;
Debargha Mukherjeec76f9dc2017-05-01 13:18:09 -07002297 if (bsize < BLOCK_8X8 && !unify_bsize) {
Yaowu Xuf883b422016-08-30 14:01:10 -07002298 aom_internal_error(xd->error_info, AOM_CODEC_UNSUP_BITSTREAM,
David Barker3409c0d2017-06-30 17:33:13 +01002299 "Invalid usage of segment feature on small blocks");
Yaowu Xuc27fc142016-08-22 16:08:15 -07002300 return;
2301 }
2302 } else {
Jingning Han5cfa6712016-12-14 09:53:38 -08002303 if (bsize >= BLOCK_8X8 || unify_bsize) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07002304#if CONFIG_EXT_INTER
2305 if (is_compound)
2306 mbmi->mode = read_inter_compound_mode(cm, xd, r, mode_ctx);
Zoe Liu85b66462017-04-20 14:28:19 -07002307#if CONFIG_COMPOUND_SINGLEREF
2308 else if (is_singleref_comp_mode)
Thomas Daviesb8b14a92017-07-12 15:11:49 +01002309 mbmi->mode = read_inter_singleref_comp_mode(xd, r, mode_ctx);
Zoe Liu85b66462017-04-20 14:28:19 -07002310#endif // CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -07002311 else
2312#endif // CONFIG_EXT_INTER
Zoe Liu7f24e1b2017-03-17 17:42:05 -07002313 mbmi->mode = read_inter_mode(ec_ctx, xd, r, mode_ctx);
David Barker404b2e82017-03-27 13:07:47 +01002314#if CONFIG_EXT_INTER
David Barker3dfba992017-04-03 16:10:09 +01002315 if (mbmi->mode == NEWMV || mbmi->mode == NEW_NEWMV ||
Zoe Liu85b66462017-04-20 14:28:19 -07002316#if CONFIG_COMPOUND_SINGLEREF
2317 mbmi->mode == SR_NEW_NEWMV ||
2318#endif // CONFIG_COMPOUND_SINGLEREF
David Barker3dfba992017-04-03 16:10:09 +01002319 have_nearmv_in_inter_mode(mbmi->mode))
Zoe Liu85b66462017-04-20 14:28:19 -07002320#else // !CONFIG_EXT_INTER
Yaowu Xuc27fc142016-08-22 16:08:15 -07002321 if (mbmi->mode == NEARMV || mbmi->mode == NEWMV)
Zoe Liu85b66462017-04-20 14:28:19 -07002322#endif // CONFIG_EXT_INTER
Thomas Davies149eda52017-06-12 18:11:55 +01002323 read_drl_idx(ec_ctx, xd, mbmi, r);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002324 }
2325 }
2326
2327#if CONFIG_EXT_INTER
Jingning Han5cfa6712016-12-14 09:53:38 -08002328 if ((bsize < BLOCK_8X8 && unify_bsize) ||
Yaowu Xuc27fc142016-08-22 16:08:15 -07002329 (mbmi->mode != ZEROMV && mbmi->mode != ZERO_ZEROMV)) {
2330#else
Jingning Han5cfa6712016-12-14 09:53:38 -08002331 if ((bsize < BLOCK_8X8 && !unify_bsize) || mbmi->mode != ZEROMV) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07002332#endif // CONFIG_EXT_INTER
2333 for (ref = 0; ref < 1 + is_compound; ++ref) {
Yaowu Xuf883b422016-08-30 14:01:10 -07002334 av1_find_best_ref_mvs(allow_hp, ref_mvs[mbmi->ref_frame[ref]],
2335 &nearestmv[ref], &nearmv[ref]);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002336 }
2337 }
2338
Yaowu Xuc27fc142016-08-22 16:08:15 -07002339 if (mbmi->ref_mv_idx > 0) {
2340 int_mv cur_mv =
2341 xd->ref_mv_stack[mbmi->ref_frame[0]][1 + mbmi->ref_mv_idx].this_mv;
2342 nearmv[0] = cur_mv;
2343 }
2344
2345#if CONFIG_EXT_INTER
Zoe Liu85b66462017-04-20 14:28:19 -07002346#if CONFIG_COMPOUND_SINGLEREF
2347 if ((is_compound || is_singleref_comp_mode) &&
2348 (bsize >= BLOCK_8X8 || unify_bsize) && mbmi->mode != ZERO_ZEROMV) {
2349#else // !CONFIG_COMPOUND_SINGLEREF
Jingning Han61418bb2017-01-23 17:12:48 -08002350 if (is_compound && (bsize >= BLOCK_8X8 || unify_bsize) &&
2351 mbmi->mode != ZERO_ZEROMV) {
Zoe Liu85b66462017-04-20 14:28:19 -07002352#endif // CONFIG_COMPOUND_SINGLEREF
2353#else // !CONFIG_EXT_INTER
Jingning Han5cfa6712016-12-14 09:53:38 -08002354 if (is_compound && (bsize >= BLOCK_8X8 || unify_bsize) &&
2355 mbmi->mode != NEWMV && mbmi->mode != ZEROMV) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07002356#endif // CONFIG_EXT_INTER
Yaowu Xuf883b422016-08-30 14:01:10 -07002357 uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002358
2359#if CONFIG_EXT_INTER
2360 if (xd->ref_mv_count[ref_frame_type] > 0) {
2361#else
2362 if (xd->ref_mv_count[ref_frame_type] == 1 && mbmi->mode == NEARESTMV) {
2363#endif // CONFIG_EXT_INTER
2364#if CONFIG_EXT_INTER
2365 if (mbmi->mode == NEAREST_NEARESTMV) {
2366#endif // CONFIG_EXT_INTER
2367 nearestmv[0] = xd->ref_mv_stack[ref_frame_type][0].this_mv;
2368 nearestmv[1] = xd->ref_mv_stack[ref_frame_type][0].comp_mv;
2369 lower_mv_precision(&nearestmv[0].as_mv, allow_hp);
2370 lower_mv_precision(&nearestmv[1].as_mv, allow_hp);
2371#if CONFIG_EXT_INTER
Zoe Liu85b66462017-04-20 14:28:19 -07002372 } else if (mbmi->mode == NEAREST_NEWMV
2373#if CONFIG_COMPOUND_SINGLEREF
2374 || mbmi->mode == SR_NEAREST_NEARMV
2375// || mbmi->mode == SR_NEAREST_NEWMV
2376#endif // CONFIG_COMPOUND_SINGLEREF
2377 ) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07002378 nearestmv[0] = xd->ref_mv_stack[ref_frame_type][0].this_mv;
2379 lower_mv_precision(&nearestmv[0].as_mv, allow_hp);
Debargha Mukherjeebb6e1342017-04-17 16:05:04 -07002380 } else if (mbmi->mode == NEW_NEARESTMV) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07002381 nearestmv[1] = xd->ref_mv_stack[ref_frame_type][0].comp_mv;
2382 lower_mv_precision(&nearestmv[1].as_mv, allow_hp);
2383 }
2384#endif // CONFIG_EXT_INTER
2385 }
2386
2387#if CONFIG_EXT_INTER
2388 if (xd->ref_mv_count[ref_frame_type] > 1) {
David Barker404b2e82017-03-27 13:07:47 +01002389 int ref_mv_idx = 1 + mbmi->ref_mv_idx;
Zoe Liu85b66462017-04-20 14:28:19 -07002390#if CONFIG_COMPOUND_SINGLEREF
2391 if (is_compound) {
2392#endif // CONFIG_COMPOUND_SINGLEREF
2393 if (compound_ref0_mode(mbmi->mode) == NEARMV) {
2394 nearmv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv;
2395 lower_mv_precision(&nearmv[0].as_mv, allow_hp);
2396 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07002397
Zoe Liu85b66462017-04-20 14:28:19 -07002398 if (compound_ref1_mode(mbmi->mode) == NEARMV) {
2399 nearmv[1] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].comp_mv;
2400 lower_mv_precision(&nearmv[1].as_mv, allow_hp);
2401 }
2402#if CONFIG_COMPOUND_SINGLEREF
2403 } else {
2404 assert(is_singleref_comp_mode);
2405 if (compound_ref0_mode(mbmi->mode) == NEARMV ||
2406 compound_ref1_mode(mbmi->mode) == NEARMV) {
2407 nearmv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv;
2408 lower_mv_precision(&nearmv[0].as_mv, allow_hp);
2409 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07002410 }
Zoe Liu85b66462017-04-20 14:28:19 -07002411#endif // CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -07002412 }
Zoe Liu85b66462017-04-20 14:28:19 -07002413#else // !CONFIG_EXT_INTER
Yaowu Xuc27fc142016-08-22 16:08:15 -07002414 if (xd->ref_mv_count[ref_frame_type] > 1) {
2415 int ref_mv_idx = 1 + mbmi->ref_mv_idx;
2416 nearestmv[0] = xd->ref_mv_stack[ref_frame_type][0].this_mv;
2417 nearestmv[1] = xd->ref_mv_stack[ref_frame_type][0].comp_mv;
2418 nearmv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv;
2419 nearmv[1] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].comp_mv;
2420 }
2421#endif // CONFIG_EXT_INTER
2422 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07002423
Yue Chen19e7aa82016-11-30 14:05:39 -08002424#if !CONFIG_DUAL_FILTER && !CONFIG_WARPED_MOTION && !CONFIG_GLOBAL_MOTION
Angie Chiang9c4f8952016-11-21 11:13:19 -08002425 read_mb_interp_filter(cm, xd, mbmi, r);
Angie Chiang1733f6b2017-01-05 09:52:20 -08002426#endif // !CONFIG_DUAL_FILTER && !CONFIG_WARPED_MOTION
Yaowu Xuc27fc142016-08-22 16:08:15 -07002427
Jingning Han5cfa6712016-12-14 09:53:38 -08002428 if (bsize < BLOCK_8X8 && !unify_bsize) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07002429 const int num_4x4_w = 1 << xd->bmode_blocks_wl;
2430 const int num_4x4_h = 1 << xd->bmode_blocks_hl;
2431 int idx, idy;
2432 PREDICTION_MODE b_mode;
2433 int_mv nearest_sub8x8[2], near_sub8x8[2];
2434#if CONFIG_EXT_INTER
2435 int_mv ref_mv[2][2];
2436#endif // CONFIG_EXT_INTER
2437 for (idy = 0; idy < 2; idy += num_4x4_h) {
2438 for (idx = 0; idx < 2; idx += num_4x4_w) {
2439 int_mv block[2];
2440 const int j = idy * 2 + idx;
2441 int_mv ref_mv_s8[2];
Yaowu Xuc27fc142016-08-22 16:08:15 -07002442#if CONFIG_EXT_INTER
2443 if (!is_compound)
2444#endif // CONFIG_EXT_INTER
Yaowu Xuf883b422016-08-30 14:01:10 -07002445 mode_ctx = av1_mode_context_analyzer(inter_mode_ctx, mbmi->ref_frame,
2446 bsize, j);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002447#if CONFIG_EXT_INTER
2448 if (is_compound)
2449 b_mode = read_inter_compound_mode(cm, xd, r, mode_ctx);
2450 else
2451#endif // CONFIG_EXT_INTER
Zoe Liu7f24e1b2017-03-17 17:42:05 -07002452 b_mode = read_inter_mode(ec_ctx, xd, r, mode_ctx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002453
2454#if CONFIG_EXT_INTER
Yaowu Xuc27fc142016-08-22 16:08:15 -07002455 if (b_mode != ZEROMV && b_mode != ZERO_ZEROMV) {
2456#else
2457 if (b_mode != ZEROMV) {
2458#endif // CONFIG_EXT_INTER
Yaowu Xuc27fc142016-08-22 16:08:15 -07002459 CANDIDATE_MV ref_mv_stack[2][MAX_REF_MV_STACK_SIZE];
2460 uint8_t ref_mv_count[2];
Yaowu Xuc27fc142016-08-22 16:08:15 -07002461 for (ref = 0; ref < 1 + is_compound; ++ref)
2462#if CONFIG_EXT_INTER
2463 {
2464 int_mv mv_ref_list[MAX_MV_REF_CANDIDATES];
Yaowu Xu531d6af2017-03-07 17:48:52 -08002465 av1_update_mv_context(cm, xd, mi, mbmi->ref_frame[ref], mv_ref_list,
2466 j, mi_row, mi_col, NULL);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002467#endif // CONFIG_EXT_INTER
Yaowu Xuf883b422016-08-30 14:01:10 -07002468 av1_append_sub8x8_mvs_for_idx(cm, xd, j, ref, mi_row, mi_col,
Yaowu Xuf883b422016-08-30 14:01:10 -07002469 ref_mv_stack[ref], &ref_mv_count[ref],
Yaowu Xuc27fc142016-08-22 16:08:15 -07002470#if CONFIG_EXT_INTER
Yaowu Xuf883b422016-08-30 14:01:10 -07002471 mv_ref_list,
Yaowu Xuc27fc142016-08-22 16:08:15 -07002472#endif // CONFIG_EXT_INTER
Yaowu Xuf883b422016-08-30 14:01:10 -07002473 &nearest_sub8x8[ref],
2474 &near_sub8x8[ref]);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002475#if CONFIG_EXT_INTER
2476 if (have_newmv_in_inter_mode(b_mode)) {
2477 mv_ref_list[0].as_int = nearest_sub8x8[ref].as_int;
2478 mv_ref_list[1].as_int = near_sub8x8[ref].as_int;
Yaowu Xuf883b422016-08-30 14:01:10 -07002479 av1_find_best_ref_mvs(allow_hp, mv_ref_list, &ref_mv[0][ref],
2480 &ref_mv[1][ref]);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002481 }
2482 }
2483#endif // CONFIG_EXT_INTER
2484 }
2485
2486 for (ref = 0; ref < 1 + is_compound && b_mode != ZEROMV; ++ref) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07002487 ref_mv_s8[ref] = nearest_sub8x8[ref];
2488 lower_mv_precision(&ref_mv_s8[ref].as_mv, allow_hp);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002489 }
2490#if CONFIG_EXT_INTER
2491 (void)ref_mv_s8;
2492#endif
2493
Jingning Han5c60cdf2016-09-30 09:37:46 -07002494 if (!assign_mv(cm, xd, b_mode, mbmi->ref_frame, j, block,
Yaowu Xuc27fc142016-08-22 16:08:15 -07002495#if CONFIG_EXT_INTER
Zoe Liu7f24e1b2017-03-17 17:42:05 -07002496 ref_mv[0],
2497#else // !CONFIG_EXT_INTER
Yaowu Xuc27fc142016-08-22 16:08:15 -07002498 ref_mv_s8,
2499#endif // CONFIG_EXT_INTER
David Barker45390c12017-02-20 14:44:40 +00002500 nearest_sub8x8, near_sub8x8, mi_row, mi_col, is_compound,
2501 allow_hp, r)) {
Angie Chiangd0916d92017-03-10 17:54:18 -08002502 aom_merge_corrupted_flag(&xd->corrupted, 1);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002503 break;
2504 };
2505
2506 mi->bmi[j].as_mv[0].as_int = block[0].as_int;
Sarah Parkerd7fa8542016-10-11 11:51:59 -07002507 mi->bmi[j].as_mode = b_mode;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002508 if (is_compound) mi->bmi[j].as_mv[1].as_int = block[1].as_int;
2509
2510 if (num_4x4_h == 2) mi->bmi[j + 2] = mi->bmi[j];
2511 if (num_4x4_w == 2) mi->bmi[j + 1] = mi->bmi[j];
2512 }
2513 }
2514
Yaowu Xuf5bbbfa2016-09-26 09:13:38 -07002515 mbmi->pred_mv[0].as_int = mi->bmi[3].pred_mv[0].as_int;
2516 mbmi->pred_mv[1].as_int = mi->bmi[3].pred_mv[1].as_int;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002517 mi->mbmi.mode = b_mode;
2518
2519 mbmi->mv[0].as_int = mi->bmi[3].as_mv[0].as_int;
2520 mbmi->mv[1].as_int = mi->bmi[3].as_mv[1].as_int;
2521 } else {
Yaowu Xuc27fc142016-08-22 16:08:15 -07002522 int_mv ref_mv[2];
2523 ref_mv[0] = nearestmv[0];
2524 ref_mv[1] = nearestmv[1];
2525
David Barker404b2e82017-03-27 13:07:47 +01002526#if CONFIG_EXT_INTER
David Barker3dfba992017-04-03 16:10:09 +01002527 if (is_compound) {
David Barker3dfba992017-04-03 16:10:09 +01002528 int ref_mv_idx = mbmi->ref_mv_idx;
2529 // Special case: NEAR_NEWMV and NEW_NEARMV modes use
2530 // 1 + mbmi->ref_mv_idx (like NEARMV) instead of
2531 // mbmi->ref_mv_idx (like NEWMV)
2532 if (mbmi->mode == NEAR_NEWMV || mbmi->mode == NEW_NEARMV)
2533 ref_mv_idx = 1 + mbmi->ref_mv_idx;
David Barker3dfba992017-04-03 16:10:09 +01002534
2535 if (compound_ref0_mode(mbmi->mode) == NEWMV) {
David Barker404b2e82017-03-27 13:07:47 +01002536 uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
2537 if (xd->ref_mv_count[ref_frame_type] > 1) {
David Barker3dfba992017-04-03 16:10:09 +01002538 ref_mv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv;
Jingning Han1b5bd002017-04-20 08:48:30 -07002539 clamp_mv_ref(&ref_mv[0].as_mv, xd->n8_w << MI_SIZE_LOG2,
David Barker404b2e82017-03-27 13:07:47 +01002540 xd->n8_h << MI_SIZE_LOG2, xd);
2541 }
David Barker3dfba992017-04-03 16:10:09 +01002542 nearestmv[0] = ref_mv[0];
David Barker404b2e82017-03-27 13:07:47 +01002543 }
David Barker3dfba992017-04-03 16:10:09 +01002544 if (compound_ref1_mode(mbmi->mode) == NEWMV) {
David Barker3dfba992017-04-03 16:10:09 +01002545 uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
2546 if (xd->ref_mv_count[ref_frame_type] > 1) {
2547 ref_mv[1] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].comp_mv;
Jingning Han1b5bd002017-04-20 08:48:30 -07002548 clamp_mv_ref(&ref_mv[1].as_mv, xd->n8_w << MI_SIZE_LOG2,
David Barker3dfba992017-04-03 16:10:09 +01002549 xd->n8_h << MI_SIZE_LOG2, xd);
2550 }
David Barker3dfba992017-04-03 16:10:09 +01002551 nearestmv[1] = ref_mv[1];
2552 }
Zoe Liu85b66462017-04-20 14:28:19 -07002553#if CONFIG_COMPOUND_SINGLEREF
2554 } else if (is_singleref_comp_mode) {
2555 int ref_mv_idx = mbmi->ref_mv_idx;
2556 // Special case: SR_NEAR_NEWMV use 1 + mbmi->ref_mv_idx (like NEARMV)
2557 // instead of mbmi->ref_mv_idx (like NEWMV)
2558 if (mbmi->mode == SR_NEAR_NEWMV) ref_mv_idx = 1 + mbmi->ref_mv_idx;
2559
2560 if (compound_ref0_mode(mbmi->mode) == NEWMV ||
2561 compound_ref1_mode(mbmi->mode) == NEWMV) {
2562 uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
2563 if (xd->ref_mv_count[ref_frame_type] > 1) {
2564 ref_mv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv;
2565 clamp_mv_ref(&ref_mv[0].as_mv, xd->n8_w << MI_SIZE_LOG2,
2566 xd->n8_h << MI_SIZE_LOG2, xd);
2567 }
2568 // TODO(zoeliu): To further investigate why this would not cause a
2569 // mismatch for the mode of SR_NEAREST_NEWMV.
2570 nearestmv[0] = ref_mv[0];
2571 }
2572#endif // CONFIG_COMPOUND_SINGLEREF
David Barker3dfba992017-04-03 16:10:09 +01002573 } else {
2574#endif // CONFIG_EXT_INTER
2575 if (mbmi->mode == NEWMV) {
2576 for (ref = 0; ref < 1 + is_compound; ++ref) {
David Barker3dfba992017-04-03 16:10:09 +01002577 uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
2578 if (xd->ref_mv_count[ref_frame_type] > 1) {
2579 ref_mv[ref] =
2580 (ref == 0)
2581 ? xd->ref_mv_stack[ref_frame_type][mbmi->ref_mv_idx].this_mv
2582 : xd->ref_mv_stack[ref_frame_type][mbmi->ref_mv_idx]
2583 .comp_mv;
2584 clamp_mv_ref(&ref_mv[ref].as_mv, xd->n8_w << MI_SIZE_LOG2,
2585 xd->n8_h << MI_SIZE_LOG2, xd);
2586 }
David Barker3dfba992017-04-03 16:10:09 +01002587 nearestmv[ref] = ref_mv[ref];
2588 }
2589 }
2590#if CONFIG_EXT_INTER
Yaowu Xuc27fc142016-08-22 16:08:15 -07002591 }
David Barker3dfba992017-04-03 16:10:09 +01002592#endif // CONFIG_EXT_INTER
Yaowu Xuc27fc142016-08-22 16:08:15 -07002593
Angie Chiangd0916d92017-03-10 17:54:18 -08002594 int mv_corrupted_flag =
Zoe Liu7f24e1b2017-03-17 17:42:05 -07002595 !assign_mv(cm, xd, mbmi->mode, mbmi->ref_frame, 0, mbmi->mv, ref_mv,
David Barker45390c12017-02-20 14:44:40 +00002596 nearestmv, nearmv, mi_row, mi_col, is_compound, allow_hp, r);
Angie Chiangd0916d92017-03-10 17:54:18 -08002597 aom_merge_corrupted_flag(&xd->corrupted, mv_corrupted_flag);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002598 }
2599
Yue Chen4d26acb2017-05-01 12:28:34 -07002600#if CONFIG_EXT_INTER && CONFIG_INTERINTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -07002601 mbmi->use_wedge_interintra = 0;
2602 if (cm->reference_mode != COMPOUND_REFERENCE &&
2603#if CONFIG_SUPERTX
2604 !supertx_enabled &&
2605#endif
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07002606 cm->allow_interintra_compound && is_interintra_allowed(mbmi)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07002607 const int bsize_group = size_group_lookup[bsize];
Thomas Daviescff91712017-07-07 11:49:55 +01002608#if CONFIG_NEW_MULTISYMBOL
2609 const int interintra =
2610 aom_read_symbol(r, ec_ctx->interintra_cdf[bsize_group], 2, ACCT_STR);
2611#else
Michael Bebenita6048d052016-08-25 14:40:54 -07002612 const int interintra =
2613 aom_read(r, cm->fc->interintra_prob[bsize_group], ACCT_STR);
Thomas Daviescff91712017-07-07 11:49:55 +01002614#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002615 if (xd->counts) xd->counts->interintra[bsize_group][interintra]++;
Emil Keyder01770b32017-01-20 18:03:11 -05002616 assert(mbmi->ref_frame[1] == NONE_FRAME);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002617 if (interintra) {
2618 const INTERINTRA_MODE interintra_mode =
2619 read_interintra_mode(cm, xd, r, bsize_group);
2620 mbmi->ref_frame[1] = INTRA_FRAME;
2621 mbmi->interintra_mode = interintra_mode;
2622#if CONFIG_EXT_INTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -07002623 mbmi->angle_delta[0] = 0;
2624 mbmi->angle_delta[1] = 0;
hui sueda3d762016-12-06 16:58:23 -08002625#if CONFIG_INTRA_INTERP
Yaowu Xuc27fc142016-08-22 16:08:15 -07002626 mbmi->intra_filter = INTRA_FILTER_LINEAR;
hui sueda3d762016-12-06 16:58:23 -08002627#endif // CONFIG_INTRA_INTERP
Yaowu Xuc27fc142016-08-22 16:08:15 -07002628#endif // CONFIG_EXT_INTRA
hui su5db97432016-10-14 16:10:14 -07002629#if CONFIG_FILTER_INTRA
2630 mbmi->filter_intra_mode_info.use_filter_intra_mode[0] = 0;
2631 mbmi->filter_intra_mode_info.use_filter_intra_mode[1] = 0;
2632#endif // CONFIG_FILTER_INTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -07002633 if (is_interintra_wedge_used(bsize)) {
Thomas Daviescff91712017-07-07 11:49:55 +01002634#if CONFIG_NEW_MULTISYMBOL
2635 mbmi->use_wedge_interintra = aom_read_symbol(
2636 r, ec_ctx->wedge_interintra_cdf[bsize], 2, ACCT_STR);
2637#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07002638 mbmi->use_wedge_interintra =
Michael Bebenita6048d052016-08-25 14:40:54 -07002639 aom_read(r, cm->fc->wedge_interintra_prob[bsize], ACCT_STR);
Thomas Daviescff91712017-07-07 11:49:55 +01002640#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002641 if (xd->counts)
2642 xd->counts->wedge_interintra[bsize][mbmi->use_wedge_interintra]++;
2643 if (mbmi->use_wedge_interintra) {
2644 mbmi->interintra_wedge_index =
Michael Bebenita6048d052016-08-25 14:40:54 -07002645 aom_read_literal(r, get_wedge_bits_lookup(bsize), ACCT_STR);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002646 mbmi->interintra_wedge_sign = 0;
2647 }
2648 }
2649 }
2650 }
Yue Chen4d26acb2017-05-01 12:28:34 -07002651#endif // CONFIG_EXT_INTER && CONFIG_INTERINTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -07002652
Yue Chen52c51732017-07-11 15:08:30 -07002653#if CONFIG_WARPED_MOTION
2654 for (ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) {
2655 const MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref];
2656 RefBuffer *ref_buf = &cm->frame_refs[frame - LAST_FRAME];
2657
2658 xd->block_refs[ref] = ref_buf;
2659 }
2660#endif
2661
Yue Chencb60b182016-10-13 15:18:22 -07002662#if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
2663 mbmi->motion_mode = SIMPLE_TRANSLATION;
Yue Chen69f18e12016-09-08 14:48:15 -07002664#if CONFIG_WARPED_MOTION
2665 if (mbmi->sb_type >= BLOCK_8X8 && !has_second_ref(mbmi))
Yunqing Wang1bc82862017-06-28 15:49:48 -07002666#if WARPED_MOTION_SORT_SAMPLES
2667 mbmi->num_proj_ref[0] =
2668 findSamples(cm, xd, mi_row, mi_col, pts, pts_inref, pts_mv);
2669#else
Yue Chen69f18e12016-09-08 14:48:15 -07002670 mbmi->num_proj_ref[0] = findSamples(cm, xd, mi_row, mi_col, pts, pts_inref);
Yunqing Wang1bc82862017-06-28 15:49:48 -07002671#endif // WARPED_MOTION_SORT_SAMPLES
Yue Chen69f18e12016-09-08 14:48:15 -07002672#endif // CONFIG_WARPED_MOTION
Yue Chen5329a2b2017-02-28 17:33:00 +08002673#if CONFIG_MOTION_VAR
2674 av1_count_overlappable_neighbors(cm, xd, mi_row, mi_col);
2675#endif
Yue Chen69f18e12016-09-08 14:48:15 -07002676
Yaowu Xuc27fc142016-08-22 16:08:15 -07002677#if CONFIG_SUPERTX
Yue Chen69f18e12016-09-08 14:48:15 -07002678 if (!supertx_enabled) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07002679#endif // CONFIG_SUPERTX
2680#if CONFIG_EXT_INTER
2681 if (mbmi->ref_frame[1] != INTRA_FRAME)
2682#endif // CONFIG_EXT_INTER
Sarah Parker19234cc2017-03-10 16:43:25 -08002683 mbmi->motion_mode = read_motion_mode(cm, xd, mi, r);
Wei-Ting Lin85a8f702017-06-22 13:55:15 -07002684
2685#if CONFIG_NCOBMC_ADAPT_WEIGHT
Wei-Ting Linca710d62017-07-13 11:41:02 -07002686 read_ncobmc_mode(xd, mi, mbmi->ncobmc_mode, r);
Wei-Ting Lin85a8f702017-06-22 13:55:15 -07002687#endif
2688
Zoe Liu85b66462017-04-20 14:28:19 -07002689#if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
2690 if (is_singleref_comp_mode) assert(mbmi->motion_mode == SIMPLE_TRANSLATION);
2691#endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
Yue Chen69f18e12016-09-08 14:48:15 -07002692#if CONFIG_WARPED_MOTION
2693 if (mbmi->motion_mode == WARPED_CAUSAL) {
2694 mbmi->wm_params[0].wmtype = DEFAULT_WMTYPE;
Yunqing Wang1bc82862017-06-28 15:49:48 -07002695
2696#if WARPED_MOTION_SORT_SAMPLES
2697 if (mbmi->num_proj_ref[0] > 1)
2698 mbmi->num_proj_ref[0] = sortSamples(pts_mv, &mbmi->mv[0].as_mv, pts,
2699 pts_inref, mbmi->num_proj_ref[0]);
2700#endif // WARPED_MOTION_SORT_SAMPLES
2701
Debargha Mukherjee0df711f2017-05-02 16:00:20 -07002702 if (find_projection(mbmi->num_proj_ref[0], pts, pts_inref, bsize,
2703 mbmi->mv[0].as_mv.row, mbmi->mv[0].as_mv.col,
2704 &mbmi->wm_params[0], mi_row, mi_col)) {
Yunqing Wang8657ad72017-06-20 14:46:08 -07002705 aom_internal_error(&cm->error, AOM_CODEC_ERROR, "Invalid Warped Model");
Debargha Mukherjee0df711f2017-05-02 16:00:20 -07002706 }
Yue Chen69f18e12016-09-08 14:48:15 -07002707 }
2708#endif // CONFIG_WARPED_MOTION
2709#if CONFIG_SUPERTX
2710 }
2711#endif // CONFIG_SUPERTX
Yue Chencb60b182016-10-13 15:18:22 -07002712#endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
Yaowu Xuc27fc142016-08-22 16:08:15 -07002713
2714#if CONFIG_EXT_INTER
Sarah Parker2d0e9b72017-05-04 01:34:16 +00002715 mbmi->interinter_compound_type = COMPOUND_AVERAGE;
Zoe Liu85b66462017-04-20 14:28:19 -07002716 if (
2717#if CONFIG_COMPOUND_SINGLEREF
Zoe Liu0c634c72017-06-19 07:06:28 -07002718 is_inter_anyref_comp_mode(mbmi->mode)
Zoe Liu85b66462017-04-20 14:28:19 -07002719#else // !CONFIG_COMPOUND_SINGLEREF
2720 cm->reference_mode != SINGLE_REFERENCE &&
Sarah Parker6fdc8532016-11-16 17:47:13 -08002721 is_inter_compound_mode(mbmi->mode)
Zoe Liu85b66462017-04-20 14:28:19 -07002722#endif // CONFIG_COMPOUND_SINGLEREF
Yue Chencb60b182016-10-13 15:18:22 -07002723#if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
Sarah Parker6fdc8532016-11-16 17:47:13 -08002724 && mbmi->motion_mode == SIMPLE_TRANSLATION
Yue Chencb60b182016-10-13 15:18:22 -07002725#endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
Sarah Parker6fdc8532016-11-16 17:47:13 -08002726 ) {
Sarah Parker42d96102017-01-31 21:05:27 -08002727 if (is_any_masked_compound_used(bsize)) {
Debargha Mukherjeec5f735f2017-04-26 03:25:28 +00002728#if CONFIG_COMPOUND_SEGMENT || CONFIG_WEDGE
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07002729 if (cm->allow_masked_compound) {
Thomas Daviesd8dac222017-06-27 11:23:15 +01002730 mbmi->interinter_compound_type = aom_read_symbol(
2731 r, ec_ctx->compound_type_cdf[bsize], COMPOUND_TYPES, ACCT_STR);
Debargha Mukherjeec5f735f2017-04-26 03:25:28 +00002732#if CONFIG_WEDGE
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07002733 if (mbmi->interinter_compound_type == COMPOUND_WEDGE) {
2734 mbmi->wedge_index =
2735 aom_read_literal(r, get_wedge_bits_lookup(bsize), ACCT_STR);
2736 mbmi->wedge_sign = aom_read_bit(r, ACCT_STR);
2737 }
Debargha Mukherjeec5f735f2017-04-26 03:25:28 +00002738#endif // CONFIG_WEDGE
Sarah Parker42d96102017-01-31 21:05:27 -08002739#if CONFIG_COMPOUND_SEGMENT
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07002740 if (mbmi->interinter_compound_type == COMPOUND_SEG) {
2741 mbmi->mask_type = aom_read_literal(r, MAX_SEG_MASK_BITS, ACCT_STR);
2742 }
Sarah Parker42d96102017-01-31 21:05:27 -08002743#endif // CONFIG_COMPOUND_SEGMENT
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07002744 }
2745#endif // CONFIG_COMPOUND_SEGMENT || CONFIG_WEDGE
Sarah Parker42d96102017-01-31 21:05:27 -08002746 } else {
Sarah Parker2d0e9b72017-05-04 01:34:16 +00002747 mbmi->interinter_compound_type = COMPOUND_AVERAGE;
Sarah Parker42d96102017-01-31 21:05:27 -08002748 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07002749 if (xd->counts)
Sarah Parker2d0e9b72017-05-04 01:34:16 +00002750 xd->counts->compound_interinter[bsize][mbmi->interinter_compound_type]++;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002751 }
2752#endif // CONFIG_EXT_INTER
2753
Yue Chen19e7aa82016-11-30 14:05:39 -08002754#if CONFIG_DUAL_FILTER || CONFIG_WARPED_MOTION || CONFIG_GLOBAL_MOTION
Debargha Mukherjee0df711f2017-05-02 16:00:20 -07002755 read_mb_interp_filter(cm, xd, mbmi, r);
Angie Chiang1733f6b2017-01-05 09:52:20 -08002756#endif // CONFIG_DUAL_FILTER || CONFIG_WARPED_MOTION
Zoe Liu85b66462017-04-20 14:28:19 -07002757
Di Chen56586622017-06-09 13:49:44 -07002758#if DEC_MISMATCH_DEBUG
2759 // NOTE(zoeliu): For debug
Zoe Liuf9333f52017-07-03 10:52:01 -07002760 dec_dump_logs(cm, mi, xd, mi_row, mi_col, inter_mode_ctx, mode_ctx);
Di Chen56586622017-06-09 13:49:44 -07002761#endif // DEC_MISMATCH_DEBUG
Yaowu Xuc27fc142016-08-22 16:08:15 -07002762}
2763
Yaowu Xuf883b422016-08-30 14:01:10 -07002764static void read_inter_frame_mode_info(AV1Decoder *const pbi,
Yaowu Xuc27fc142016-08-22 16:08:15 -07002765 MACROBLOCKD *const xd,
2766#if CONFIG_SUPERTX
2767 int supertx_enabled,
2768#endif // CONFIG_SUPERTX
Yaowu Xuf883b422016-08-30 14:01:10 -07002769 int mi_row, int mi_col, aom_reader *r) {
2770 AV1_COMMON *const cm = &pbi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002771 MODE_INFO *const mi = xd->mi[0];
2772 MB_MODE_INFO *const mbmi = &mi->mbmi;
2773 int inter_block = 1;
2774#if CONFIG_VAR_TX
2775 BLOCK_SIZE bsize = mbmi->sb_type;
2776#endif // CONFIG_VAR_TX
2777
2778 mbmi->mv[0].as_int = 0;
2779 mbmi->mv[1].as_int = 0;
2780 mbmi->segment_id = read_inter_segment_id(cm, xd, mi_row, mi_col, r);
2781#if CONFIG_SUPERTX
David Barker3aec8d62017-01-31 14:55:32 +00002782 if (!supertx_enabled)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002783#endif // CONFIG_SUPERTX
2784 mbmi->skip = read_skip(cm, xd, mbmi->segment_id, r);
David Barker3aec8d62017-01-31 14:55:32 +00002785
Arild Fuldseth07441162016-08-15 15:07:52 +02002786#if CONFIG_DELTA_Q
David Barker3aec8d62017-01-31 14:55:32 +00002787 if (cm->delta_q_present_flag) {
2788 xd->current_qindex =
2789 xd->prev_qindex +
2790 read_delta_qindex(cm, xd, r, mbmi, mi_col, mi_row) * cm->delta_q_res;
Arild Fuldseth (arilfuld)54de7d62017-03-20 13:07:11 +01002791 /* Normative: Clamp to [1,MAXQ] to not interfere with lossless mode */
2792 xd->current_qindex = clamp(xd->current_qindex, 1, MAXQ);
David Barker3aec8d62017-01-31 14:55:32 +00002793 xd->prev_qindex = xd->current_qindex;
Fangwen Fu231fe422017-04-24 17:52:29 -07002794#if CONFIG_EXT_DELTA_Q
2795 if (cm->delta_lf_present_flag) {
2796 mbmi->current_delta_lf_from_base = xd->current_delta_lf_from_base =
2797 xd->prev_delta_lf_from_base +
2798 read_delta_lflevel(cm, xd, r, mbmi, mi_col, mi_row) *
2799 cm->delta_lf_res;
2800 xd->prev_delta_lf_from_base = xd->current_delta_lf_from_base;
2801 }
2802#endif
David Barker3aec8d62017-01-31 14:55:32 +00002803 }
Arild Fuldseth07441162016-08-15 15:07:52 +02002804#endif
David Barker3aec8d62017-01-31 14:55:32 +00002805
2806#if CONFIG_SUPERTX
2807 if (!supertx_enabled) {
2808#endif // CONFIG_SUPERTX
Yaowu Xuc27fc142016-08-22 16:08:15 -07002809 inter_block = read_is_inter_block(cm, xd, mbmi->segment_id, r);
2810
2811#if CONFIG_VAR_TX
Jingning Han331662e2017-05-30 17:03:32 -07002812 xd->above_txfm_context =
2813 cm->above_txfm_context + (mi_col << TX_UNIT_WIDE_LOG2);
2814 xd->left_txfm_context = xd->left_txfm_context_buffer +
2815 ((mi_row & MAX_MIB_MASK) << TX_UNIT_HIGH_LOG2);
Jingning Han581d1692017-01-05 16:03:54 -08002816
2817 if (cm->tx_mode == TX_MODE_SELECT &&
2818#if CONFIG_CB4X4
Jingning Han3daa4fd2017-01-20 10:33:50 -08002819 bsize > BLOCK_4X4 &&
Jingning Han581d1692017-01-05 16:03:54 -08002820#else
2821 bsize >= BLOCK_8X8 &&
2822#endif
2823 !mbmi->skip && inter_block) {
Jingning Han70e5f3f2016-11-09 17:03:07 -08002824 const TX_SIZE max_tx_size = max_txsize_rect_lookup[bsize];
Jingning Hanf64062f2016-11-02 16:22:18 -07002825 const int bh = tx_size_high_unit[max_tx_size];
2826 const int bw = tx_size_wide_unit[max_tx_size];
Jingning Han65abc312016-10-27 13:04:21 -07002827 const int width = block_size_wide[bsize] >> tx_size_wide_log2[0];
2828 const int height = block_size_high[bsize] >> tx_size_wide_log2[0];
Yaowu Xuc27fc142016-08-22 16:08:15 -07002829 int idx, idy;
Yue Chena1e48dc2016-08-29 17:29:33 -07002830
Jingning Hanfe45b212016-11-22 10:30:23 -08002831 mbmi->min_tx_size = TX_SIZES_ALL;
2832 for (idy = 0; idy < height; idy += bh)
2833 for (idx = 0; idx < width; idx += bw)
2834 read_tx_size_vartx(cm, xd, mbmi, xd->counts, max_tx_size,
2835 height != width, idy, idx, r);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002836 } else {
Urvang Joshifeb925f2016-12-05 10:37:29 -08002837 mbmi->tx_size = read_tx_size(cm, xd, inter_block, !mbmi->skip, r);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002838
2839 if (inter_block) {
Jingning Han9ca05b72017-01-03 14:41:36 -08002840 const int width = block_size_wide[bsize] >> tx_size_wide_log2[0];
2841 const int height = block_size_high[bsize] >> tx_size_high_log2[0];
Yaowu Xuc27fc142016-08-22 16:08:15 -07002842 int idx, idy;
2843 for (idy = 0; idy < height; ++idy)
2844 for (idx = 0; idx < width; ++idx)
2845 mbmi->inter_tx_size[idy >> 1][idx >> 1] = mbmi->tx_size;
2846 }
Jingning Hane67b38a2016-11-04 10:30:00 -07002847 mbmi->min_tx_size = get_min_tx_size(mbmi->tx_size);
Jingning Han1b1dc932016-11-09 10:55:30 -08002848 set_txfm_ctxs(mbmi->tx_size, xd->n8_w, xd->n8_h, mbmi->skip, xd);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002849 }
2850#else
Urvang Joshifeb925f2016-12-05 10:37:29 -08002851 mbmi->tx_size = read_tx_size(cm, xd, inter_block, !mbmi->skip, r);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002852#endif // CONFIG_VAR_TX
2853#if CONFIG_SUPERTX
2854 }
2855#if CONFIG_VAR_TX
2856 else if (inter_block) {
2857 const int width = num_4x4_blocks_wide_lookup[bsize];
2858 const int height = num_4x4_blocks_high_lookup[bsize];
2859 int idx, idy;
2860 xd->mi[0]->mbmi.tx_size = xd->supertx_size;
2861 for (idy = 0; idy < height; ++idy)
2862 for (idx = 0; idx < width; ++idx)
2863 xd->mi[0]->mbmi.inter_tx_size[idy >> 1][idx >> 1] = xd->supertx_size;
2864 }
2865#endif // CONFIG_VAR_TX
2866#endif // CONFIG_SUPERTX
2867
2868 if (inter_block)
2869 read_inter_block_mode_info(pbi, xd,
David Barker491983d2016-11-10 13:22:17 +00002870#if (CONFIG_MOTION_VAR || CONFIG_EXT_INTER || CONFIG_WARPED_MOTION) && \
2871 CONFIG_SUPERTX
Yaowu Xuc27fc142016-08-22 16:08:15 -07002872
2873 mi, mi_row, mi_col, r, supertx_enabled);
2874#else
2875 mi, mi_row, mi_col, r);
Yue Chencb60b182016-10-13 15:18:22 -07002876#endif // CONFIG_MOTION_VAR && CONFIG_SUPERTX
Yaowu Xuc27fc142016-08-22 16:08:15 -07002877 else
Jingning Han36fe3202017-02-20 22:31:49 -08002878 read_intra_block_mode_info(cm, mi_row, mi_col, xd, mi, r);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002879
Angie Chiangcd9b03f2017-04-16 13:37:13 -07002880#if !CONFIG_TXK_SEL
Angie Chianga9f9a312017-04-13 16:40:43 -07002881 av1_read_tx_type(cm, xd,
Yaowu Xuc27fc142016-08-22 16:08:15 -07002882#if CONFIG_SUPERTX
Angie Chianga9f9a312017-04-13 16:40:43 -07002883 supertx_enabled,
Nathan E. Egge93878c42016-05-03 10:01:32 -04002884#endif
Angie Chianga9f9a312017-04-13 16:40:43 -07002885 r);
Angie Chiangcd9b03f2017-04-16 13:37:13 -07002886#endif // !CONFIG_TXK_SEL
Yaowu Xuc27fc142016-08-22 16:08:15 -07002887}
2888
Yaowu Xuf883b422016-08-30 14:01:10 -07002889void av1_read_mode_info(AV1Decoder *const pbi, MACROBLOCKD *xd,
Yaowu Xuc27fc142016-08-22 16:08:15 -07002890#if CONFIG_SUPERTX
Yaowu Xuf883b422016-08-30 14:01:10 -07002891 int supertx_enabled,
Yaowu Xuc27fc142016-08-22 16:08:15 -07002892#endif // CONFIG_SUPERTX
Yaowu Xuf883b422016-08-30 14:01:10 -07002893 int mi_row, int mi_col, aom_reader *r, int x_mis,
2894 int y_mis) {
2895 AV1_COMMON *const cm = &pbi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002896 MODE_INFO *const mi = xd->mi[0];
2897 MV_REF *frame_mvs = cm->cur_frame->mvs + mi_row * cm->mi_cols + mi_col;
2898 int w, h;
2899
Alex Converse28744302017-04-13 14:46:22 -07002900#if CONFIG_INTRABC
2901 mi->mbmi.use_intrabc = 0;
2902#endif // CONFIG_INTRABC
2903
Yaowu Xuc27fc142016-08-22 16:08:15 -07002904 if (frame_is_intra_only(cm)) {
2905 read_intra_frame_mode_info(cm, xd, mi_row, mi_col, r);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002906 for (h = 0; h < y_mis; ++h) {
2907 MV_REF *const frame_mv = frame_mvs + h * cm->mi_cols;
2908 for (w = 0; w < x_mis; ++w) {
2909 MV_REF *const mv = frame_mv + w;
Emil Keyder01770b32017-01-20 18:03:11 -05002910 mv->ref_frame[0] = NONE_FRAME;
2911 mv->ref_frame[1] = NONE_FRAME;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002912 }
2913 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07002914 } else {
2915 read_inter_frame_mode_info(pbi, xd,
2916#if CONFIG_SUPERTX
2917 supertx_enabled,
2918#endif // CONFIG_SUPERTX
2919 mi_row, mi_col, r);
2920 for (h = 0; h < y_mis; ++h) {
2921 MV_REF *const frame_mv = frame_mvs + h * cm->mi_cols;
2922 for (w = 0; w < x_mis; ++w) {
2923 MV_REF *const mv = frame_mv + w;
2924 mv->ref_frame[0] = mi->mbmi.ref_frame[0];
2925 mv->ref_frame[1] = mi->mbmi.ref_frame[1];
2926 mv->mv[0].as_int = mi->mbmi.mv[0].as_int;
2927 mv->mv[1].as_int = mi->mbmi.mv[1].as_int;
Yaowu Xu4306b6e2016-09-27 12:55:32 -07002928 mv->pred_mv[0].as_int = mi->mbmi.pred_mv[0].as_int;
2929 mv->pred_mv[1].as_int = mi->mbmi.pred_mv[1].as_int;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002930 }
2931 }
2932 }
2933}