blob: 05fdc46ec6ad202a5cd684a70070de04306d17d4 [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
Thomas9ac55082016-09-23 18:04:17 +010038static PREDICTION_MODE read_intra_mode(aom_reader *r, aom_cdf_prob *cdf) {
Nathan E. Egge3ef926e2016-09-07 18:20:41 -040039 return (PREDICTION_MODE)
40 av1_intra_mode_inv[aom_read_symbol(r, cdf, INTRA_MODES, ACCT_STR)];
41}
Yaowu Xuc27fc142016-08-22 16:08:15 -070042
Thomas Daviesf6936102016-09-05 16:51:31 +010043#if CONFIG_DELTA_Q
44static int read_delta_qindex(AV1_COMMON *cm, MACROBLOCKD *xd, aom_reader *r,
45 MB_MODE_INFO *const mbmi, int mi_col, int mi_row) {
46 FRAME_COUNTS *counts = xd->counts;
47 int sign, abs, reduced_delta_qindex = 0;
48 BLOCK_SIZE bsize = mbmi->sb_type;
49 const int b_col = mi_col & MAX_MIB_MASK;
50 const int b_row = mi_row & MAX_MIB_MASK;
51 const int read_delta_q_flag = (b_col == 0 && b_row == 0);
Thomas Daviesd6ee8a82017-03-02 14:42:50 +000052 int rem_bits, thr;
53 int i, smallval;
Thomas Daviesd6ee8a82017-03-02 14:42:50 +000054 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
55 (void)cm;
Thomas Daviesf6936102016-09-05 16:51:31 +010056
Alex Converse68abef82017-03-23 14:50:33 -070057 if ((bsize != BLOCK_LARGEST || mbmi->skip == 0) && read_delta_q_flag) {
Thomas Daviesd6ee8a82017-03-02 14:42:50 +000058 abs = aom_read_symbol(r, ec_ctx->delta_q_cdf, DELTA_Q_PROBS + 1, ACCT_STR);
Thomas Daviesd6ee8a82017-03-02 14:42:50 +000059 smallval = (abs < DELTA_Q_SMALL);
60 if (counts) {
61 for (i = 0; i < abs; ++i) counts->delta_q[i][1]++;
62 if (smallval) counts->delta_q[abs][0]++;
63 }
64
65 if (!smallval) {
Thomas Daviesf6936102016-09-05 16:51:31 +010066 rem_bits = aom_read_literal(r, 3, ACCT_STR);
67 thr = (1 << rem_bits) + 1;
68 abs = aom_read_literal(r, rem_bits, ACCT_STR) + thr;
69 }
70
71 if (abs) {
72 sign = aom_read_bit(r, ACCT_STR);
73 } else {
74 sign = 1;
75 }
76
77 reduced_delta_qindex = sign ? -abs : abs;
78 }
79 return reduced_delta_qindex;
80}
Fangwen Fu231fe422017-04-24 17:52:29 -070081#if CONFIG_EXT_DELTA_Q
82static int read_delta_lflevel(AV1_COMMON *cm, MACROBLOCKD *xd, aom_reader *r,
83 MB_MODE_INFO *const mbmi, int mi_col,
84 int mi_row) {
85 FRAME_COUNTS *counts = xd->counts;
86 int sign, abs, reduced_delta_lflevel = 0;
87 BLOCK_SIZE bsize = mbmi->sb_type;
88 const int b_col = mi_col & MAX_MIB_MASK;
89 const int b_row = mi_row & MAX_MIB_MASK;
90 const int read_delta_lf_flag = (b_col == 0 && b_row == 0);
91 int rem_bits, thr;
92 int i, smallval;
Fangwen Fu231fe422017-04-24 17:52:29 -070093 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
94 (void)cm;
Fangwen Fu231fe422017-04-24 17:52:29 -070095
96 if ((bsize != BLOCK_64X64 || mbmi->skip == 0) && read_delta_lf_flag) {
Fangwen Fu231fe422017-04-24 17:52:29 -070097 abs =
98 aom_read_symbol(r, ec_ctx->delta_lf_cdf, DELTA_LF_PROBS + 1, ACCT_STR);
Fangwen Fu231fe422017-04-24 17:52:29 -070099 smallval = (abs < DELTA_LF_SMALL);
100 if (counts) {
101 for (i = 0; i < abs; ++i) counts->delta_lf[i][1]++;
102 if (smallval) counts->delta_lf[abs][0]++;
103 }
104 if (!smallval) {
105 rem_bits = aom_read_literal(r, 3, ACCT_STR);
106 thr = (1 << rem_bits) + 1;
107 abs = aom_read_literal(r, rem_bits, ACCT_STR) + thr;
108 }
109
110 if (abs) {
111 sign = aom_read_bit(r, ACCT_STR);
112 } else {
113 sign = 1;
114 }
115
116 reduced_delta_lflevel = sign ? -abs : abs;
117 }
118 return reduced_delta_lflevel;
119}
120#endif
Thomas Daviesf6936102016-09-05 16:51:31 +0100121#endif
122
Nathan E. Eggea1f80e32017-05-23 11:52:32 -0400123static PREDICTION_MODE read_intra_mode_y(FRAME_CONTEXT *ec_ctx, MACROBLOCKD *xd,
Yaowu Xuf883b422016-08-30 14:01:10 -0700124 aom_reader *r, int size_group) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700125 const PREDICTION_MODE y_mode =
Thomas Davies1bfb5ed2017-01-11 15:28:11 +0000126 read_intra_mode(r, ec_ctx->y_mode_cdf[size_group]);
Nathan E. Egge6bdc40f2017-06-18 19:02:23 -0400127#if CONFIG_ENTROPY_STATS
Yaowu Xuc27fc142016-08-22 16:08:15 -0700128 FRAME_COUNTS *counts = xd->counts;
129 if (counts) ++counts->y_mode[size_group][y_mode];
Nathan E. Egge5bb3a742017-06-30 12:47:43 -0400130#else
131 /* TODO(negge): Can we remove this parameter? */
132 (void)xd;
Nathan E. Egge6bdc40f2017-06-18 19:02:23 -0400133#endif // CONFIG_ENTROPY_STATS
Yaowu Xuc27fc142016-08-22 16:08:15 -0700134 return y_mode;
135}
136
Nathan E. Eggea1f80e32017-05-23 11:52:32 -0400137static PREDICTION_MODE read_intra_mode_uv(FRAME_CONTEXT *ec_ctx,
138 MACROBLOCKD *xd, aom_reader *r,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700139 PREDICTION_MODE y_mode) {
140 const PREDICTION_MODE uv_mode =
Thomas Davies1bfb5ed2017-01-11 15:28:11 +0000141 read_intra_mode(r, ec_ctx->uv_mode_cdf[y_mode]);
Nathan E. Egge6bdc40f2017-06-18 19:02:23 -0400142#if CONFIG_ENTROPY_STATS
Yaowu Xuc27fc142016-08-22 16:08:15 -0700143 FRAME_COUNTS *counts = xd->counts;
144 if (counts) ++counts->uv_mode[y_mode][uv_mode];
Nathan E. Egge5bb3a742017-06-30 12:47:43 -0400145#else
146 /* TODO(negge): Can we remove this parameter? */
147 (void)xd;
Nathan E. Egge6bdc40f2017-06-18 19:02:23 -0400148#endif // CONFIG_ENTROPY_STATS
Yaowu Xuc27fc142016-08-22 16:08:15 -0700149 return uv_mode;
150}
151
Luc Trudeauf5334002017-04-25 12:21:26 -0400152#if CONFIG_CFL
David Michael Barr23198662017-06-19 23:19:48 +0900153static int read_cfl_alphas(FRAME_CONTEXT *const ec_ctx, aom_reader *r,
Luc Trudeau2c317902017-04-28 11:06:50 -0400154 CFL_SIGN_TYPE signs_out[CFL_PRED_PLANES]) {
David Michael Barr23198662017-06-19 23:19:48 +0900155 const int ind =
156 aom_read_symbol(r, ec_ctx->cfl_alpha_cdf, CFL_ALPHABET_SIZE, "cfl:alpha");
157 // Signs are only coded for nonzero values
158 // sign == 0 implies negative alpha
159 // sign == 1 implies positive alpha
160 signs_out[CFL_PRED_U] = cfl_alpha_codes[ind][CFL_PRED_U]
161 ? aom_read_bit(r, "cfl:sign")
162 : CFL_SIGN_POS;
163 signs_out[CFL_PRED_V] = cfl_alpha_codes[ind][CFL_PRED_V]
164 ? aom_read_bit(r, "cfl:sign")
165 : CFL_SIGN_POS;
Luc Trudeauf5334002017-04-25 12:21:26 -0400166
David Michael Barr23198662017-06-19 23:19:48 +0900167 return ind;
Luc Trudeauf5334002017-04-25 12:21:26 -0400168}
169#endif
170
Yue Chen4d26acb2017-05-01 12:28:34 -0700171#if CONFIG_EXT_INTER && CONFIG_INTERINTRA
Yaowu Xuf883b422016-08-30 14:01:10 -0700172static INTERINTRA_MODE read_interintra_mode(AV1_COMMON *cm, MACROBLOCKD *xd,
173 aom_reader *r, int size_group) {
Thomas Davies299ff042017-06-27 13:41:59 +0100174 (void)cm;
175 const INTERINTRA_MODE ii_mode = (INTERINTRA_MODE)aom_read_symbol(
176 r, xd->tile_ctx->interintra_mode_cdf[size_group], INTERINTRA_MODES,
177 ACCT_STR);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700178 FRAME_COUNTS *counts = xd->counts;
179 if (counts) ++counts->interintra_mode[size_group][ii_mode];
180 return ii_mode;
181}
Yue Chen4d26acb2017-05-01 12:28:34 -0700182#endif // CONFIG_EXT_INTER && CONFIG_INTERINTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -0700183
Thomas Davies1de6c882017-01-11 17:47:49 +0000184static PREDICTION_MODE read_inter_mode(FRAME_CONTEXT *ec_ctx, MACROBLOCKD *xd,
Yaowu Xuf883b422016-08-30 14:01:10 -0700185 aom_reader *r, int16_t ctx) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700186 FRAME_COUNTS *counts = xd->counts;
187 int16_t mode_ctx = ctx & NEWMV_CTX_MASK;
Thomas Davies149eda52017-06-12 18:11:55 +0100188 int is_newmv, is_zeromv, is_refmv;
189#if CONFIG_NEW_MULTISYMBOL
190 is_newmv = aom_read_symbol(r, ec_ctx->newmv_cdf[mode_ctx], 2, ACCT_STR) == 0;
191#else
192 is_newmv = aom_read(r, ec_ctx->newmv_prob[mode_ctx], ACCT_STR) == 0;
193#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700194
Thomas Davies149eda52017-06-12 18:11:55 +0100195 if (is_newmv) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700196 if (counts) ++counts->newmv_mode[mode_ctx][0];
Zoe Liu7f24e1b2017-03-17 17:42:05 -0700197 return NEWMV;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700198 }
199 if (counts) ++counts->newmv_mode[mode_ctx][1];
200
201 if (ctx & (1 << ALL_ZERO_FLAG_OFFSET)) return ZEROMV;
202
203 mode_ctx = (ctx >> ZEROMV_OFFSET) & ZEROMV_CTX_MASK;
204
Thomas Davies149eda52017-06-12 18:11:55 +0100205#if CONFIG_NEW_MULTISYMBOL
206 is_zeromv =
207 aom_read_symbol(r, ec_ctx->zeromv_cdf[mode_ctx], 2, ACCT_STR) == 0;
208#else
209 is_zeromv = aom_read(r, ec_ctx->zeromv_prob[mode_ctx], ACCT_STR) == 0;
210#endif
211 if (is_zeromv) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700212 if (counts) ++counts->zeromv_mode[mode_ctx][0];
213 return ZEROMV;
214 }
215 if (counts) ++counts->zeromv_mode[mode_ctx][1];
216
217 mode_ctx = (ctx >> REFMV_OFFSET) & REFMV_CTX_MASK;
218
219 if (ctx & (1 << SKIP_NEARESTMV_OFFSET)) mode_ctx = 6;
220 if (ctx & (1 << SKIP_NEARMV_OFFSET)) mode_ctx = 7;
221 if (ctx & (1 << SKIP_NEARESTMV_SUB8X8_OFFSET)) mode_ctx = 8;
222
Thomas Davies149eda52017-06-12 18:11:55 +0100223#if CONFIG_NEW_MULTISYMBOL
224 is_refmv = aom_read_symbol(r, ec_ctx->refmv_cdf[mode_ctx], 2, ACCT_STR) == 0;
225#else
226 is_refmv = aom_read(r, ec_ctx->refmv_prob[mode_ctx], ACCT_STR) == 0;
227#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700228
Thomas Davies149eda52017-06-12 18:11:55 +0100229 if (is_refmv) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700230 if (counts) ++counts->refmv_mode[mode_ctx][0];
231
232 return NEARESTMV;
233 } else {
234 if (counts) ++counts->refmv_mode[mode_ctx][1];
235 return NEARMV;
236 }
237
238 // Invalid prediction mode.
239 assert(0);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700240}
241
Thomas Davies149eda52017-06-12 18:11:55 +0100242static void read_drl_idx(FRAME_CONTEXT *ec_ctx, MACROBLOCKD *xd,
Yaowu Xuf883b422016-08-30 14:01:10 -0700243 MB_MODE_INFO *mbmi, aom_reader *r) {
244 uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700245 mbmi->ref_mv_idx = 0;
246
David Barker404b2e82017-03-27 13:07:47 +0100247#if CONFIG_EXT_INTER
Zoe Liu85b66462017-04-20 14:28:19 -0700248#if CONFIG_COMPOUND_SINGLEREF
249 if (mbmi->mode == NEWMV || mbmi->mode == NEW_NEWMV ||
250 mbmi->mode == SR_NEW_NEWMV) {
251#else // !CONFIG_COMPOUND_SINGLEREF
David Barker404b2e82017-03-27 13:07:47 +0100252 if (mbmi->mode == NEWMV || mbmi->mode == NEW_NEWMV) {
Zoe Liu85b66462017-04-20 14:28:19 -0700253#endif // CONFIG_COMPOUND_SINGLEREF
254#else // !CONFIG_EXT_INTER
Yaowu Xuc27fc142016-08-22 16:08:15 -0700255 if (mbmi->mode == NEWMV) {
Zoe Liu85b66462017-04-20 14:28:19 -0700256#endif // CONFIG_EXT_INTER
Yaowu Xuc27fc142016-08-22 16:08:15 -0700257 int idx;
258 for (idx = 0; idx < 2; ++idx) {
259 if (xd->ref_mv_count[ref_frame_type] > idx + 1) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700260 uint8_t drl_ctx = av1_drl_ctx(xd->ref_mv_stack[ref_frame_type], idx);
Thomas Davies149eda52017-06-12 18:11:55 +0100261#if CONFIG_NEW_MULTISYMBOL
262 int drl_idx = aom_read_symbol(r, ec_ctx->drl_cdf[drl_ctx], 2, ACCT_STR);
263#else
264 int drl_idx = aom_read(r, ec_ctx->drl_prob[drl_ctx], ACCT_STR);
265#endif
266 mbmi->ref_mv_idx = idx + drl_idx;
267 if (xd->counts) ++xd->counts->drl_mode[drl_ctx][drl_idx];
268 if (!drl_idx) return;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700269 }
270 }
271 }
272
David Barker3dfba992017-04-03 16:10:09 +0100273 if (have_nearmv_in_inter_mode(mbmi->mode)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700274 int idx;
275 // Offset the NEARESTMV mode.
276 // TODO(jingning): Unify the two syntax decoding loops after the NEARESTMV
277 // mode is factored in.
278 for (idx = 1; idx < 3; ++idx) {
279 if (xd->ref_mv_count[ref_frame_type] > idx + 1) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700280 uint8_t drl_ctx = av1_drl_ctx(xd->ref_mv_stack[ref_frame_type], idx);
Thomas Davies149eda52017-06-12 18:11:55 +0100281#if CONFIG_NEW_MULTISYMBOL
282 int drl_idx = aom_read_symbol(r, ec_ctx->drl_cdf[drl_ctx], 2, ACCT_STR);
283#else
284 int drl_idx = aom_read(r, ec_ctx->drl_prob[drl_ctx], ACCT_STR);
285#endif
286 mbmi->ref_mv_idx = idx + drl_idx - 1;
287 if (xd->counts) ++xd->counts->drl_mode[drl_ctx][drl_idx];
288 if (!drl_idx) return;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700289 }
290 }
291 }
292}
Yaowu Xuc27fc142016-08-22 16:08:15 -0700293
Yaowu Xub24e1152016-10-31 16:28:32 -0700294#if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
295static MOTION_MODE read_motion_mode(AV1_COMMON *cm, MACROBLOCKD *xd,
Sarah Parker19234cc2017-03-10 16:43:25 -0800296 MODE_INFO *mi, aom_reader *r) {
297 MB_MODE_INFO *mbmi = &mi->mbmi;
Thomas Davies04e5aa72017-06-28 14:36:39 +0100298#if CONFIG_NEW_MULTISYMBOL
299 (void)cm;
300#endif
301
Wei-Ting Lind0f7ba12017-06-30 14:59:57 -0700302#if CONFIG_NCOBMC_ADAPT_WEIGHT
303 const MOTION_MODE last_motion_mode_allowed =
304 motion_mode_allowed_wrapper(0,
Sarah Parker0eea89f2017-07-11 11:56:36 -0700305#if CONFIG_GLOBAL_MOTION
Wei-Ting Lind0f7ba12017-06-30 14:59:57 -0700306 0, xd->global_motion,
Sarah Parker0eea89f2017-07-11 11:56:36 -0700307#endif // CONFIG_GLOBAL_MOTION
Yue Chen52c51732017-07-11 15:08:30 -0700308#if CONFIG_WARPED_MOTION
309 xd,
310#endif
Wei-Ting Lind0f7ba12017-06-30 14:59:57 -0700311 mi);
312#else
Sarah Parker19234cc2017-03-10 16:43:25 -0800313 const MOTION_MODE last_motion_mode_allowed = motion_mode_allowed(
Sarah Parker0eea89f2017-07-11 11:56:36 -0700314#if CONFIG_GLOBAL_MOTION
Sarah Parker19234cc2017-03-10 16:43:25 -0800315 0, xd->global_motion,
Sarah Parker0eea89f2017-07-11 11:56:36 -0700316#endif // CONFIG_GLOBAL_MOTION
Yue Chen52c51732017-07-11 15:08:30 -0700317#if CONFIG_WARPED_MOTION
318 xd,
319#endif
Sarah Parker19234cc2017-03-10 16:43:25 -0800320 mi);
Wei-Ting Lind0f7ba12017-06-30 14:59:57 -0700321#endif // CONFIG_NCOBMC_ADAPT_WEIGHT
Yue Chen69f18e12016-09-08 14:48:15 -0700322 int motion_mode;
323 FRAME_COUNTS *counts = xd->counts;
Yaowu Xub24e1152016-10-31 16:28:32 -0700324
Yue Chen69f18e12016-09-08 14:48:15 -0700325 if (last_motion_mode_allowed == SIMPLE_TRANSLATION) return SIMPLE_TRANSLATION;
326#if CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
327 if (last_motion_mode_allowed == OBMC_CAUSAL) {
Thomas Daviesd9b57262017-06-27 17:43:25 +0100328#if CONFIG_NEW_MULTISYMBOL
329 motion_mode =
330 aom_read_symbol(r, xd->tile_ctx->obmc_cdf[mbmi->sb_type], 2, ACCT_STR);
331#else
Yue Chen69f18e12016-09-08 14:48:15 -0700332 motion_mode = aom_read(r, cm->fc->obmc_prob[mbmi->sb_type], ACCT_STR);
Thomas Daviesd9b57262017-06-27 17:43:25 +0100333#endif
Yue Chen69f18e12016-09-08 14:48:15 -0700334 if (counts) ++counts->obmc[mbmi->sb_type][motion_mode];
335 return (MOTION_MODE)(SIMPLE_TRANSLATION + motion_mode);
336 } else {
337#endif // CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
Yaowu Xub24e1152016-10-31 16:28:32 -0700338 motion_mode =
Thomas Davies04e5aa72017-06-28 14:36:39 +0100339 aom_read_symbol(r, xd->tile_ctx->motion_mode_cdf[mbmi->sb_type],
340 MOTION_MODES, ACCT_STR);
Yaowu Xub24e1152016-10-31 16:28:32 -0700341 if (counts) ++counts->motion_mode[mbmi->sb_type][motion_mode];
342 return (MOTION_MODE)(SIMPLE_TRANSLATION + motion_mode);
Yue Chen69f18e12016-09-08 14:48:15 -0700343#if CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
Yaowu Xub24e1152016-10-31 16:28:32 -0700344 }
Yue Chen69f18e12016-09-08 14:48:15 -0700345#endif // CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
Yaowu Xub24e1152016-10-31 16:28:32 -0700346}
Wei-Ting Lin85a8f702017-06-22 13:55:15 -0700347
348#if CONFIG_NCOBMC_ADAPT_WEIGHT
Wei-Ting Linca710d62017-07-13 11:41:02 -0700349static void read_ncobmc_mode(MACROBLOCKD *xd, MODE_INFO *mi,
350#ifndef TRAINING_WEIGHTS
351 NCOBMC_MODE ncobmc_mode[2],
352#else
353 NCOBMC_MODE ncobmc_mode[][4],
354#endif
355 aom_reader *r) {
Wei-Ting Lin85a8f702017-06-22 13:55:15 -0700356 MB_MODE_INFO *mbmi = &mi->mbmi;
357 FRAME_COUNTS *counts = xd->counts;
358 ADAPT_OVERLAP_BLOCK ao_block = adapt_overlap_block_lookup[mbmi->sb_type];
Wei-Ting Lin77c41182017-07-12 15:58:35 -0700359 if (mbmi->motion_mode != NCOBMC_ADAPT_WEIGHT) return;
Wei-Ting Lin85a8f702017-06-22 13:55:15 -0700360
Wei-Ting Linca710d62017-07-13 11:41:02 -0700361#ifndef TRAINING_WEIGHTS
362 ncobmc_mode[0] = aom_read_symbol(r, xd->tile_ctx->ncobmc_mode_cdf[ao_block],
363 MAX_NCOBMC_MODES, ACCT_STR);
Wei-Ting Lin85a8f702017-06-22 13:55:15 -0700364 if (counts) ++counts->ncobmc_mode[ao_block][ncobmc_mode[0]];
365
366 if (mi_size_wide[mbmi->sb_type] != mi_size_high[mbmi->sb_type]) {
Wei-Ting Linca710d62017-07-13 11:41:02 -0700367 ncobmc_mode[1] = aom_read_symbol(r, xd->tile_ctx->ncobmc_mode_cdf[ao_block],
368 MAX_NCOBMC_MODES, ACCT_STR);
Wei-Ting Lin85a8f702017-06-22 13:55:15 -0700369 if (counts) ++counts->ncobmc_mode[ao_block][ncobmc_mode[1]];
370 }
Wei-Ting Linca710d62017-07-13 11:41:02 -0700371#else
372 int i;
373 for (i = 0; i < 4; ++i) {
374 ncobmc_mode[0][i] = aom_read_symbol(
375 r, xd->tile_ctx->ncobmc_mode_cdf[ao_block], MAX_NCOBMC_MODES, ACCT_STR);
376 if (counts) ++counts->ncobmc_mode[ao_block][ncobmc_mode[0][i]];
377 }
378 if (mi_size_wide[mbmi->sb_type] != mi_size_high[mbmi->sb_type]) {
379 for (i = 0; i < 4; ++i) {
380 ncobmc_mode[1][i] =
381 aom_read_symbol(r, xd->tile_ctx->ncobmc_mode_cdf[ao_block],
382 MAX_NCOBMC_MODES, ACCT_STR);
383 if (counts) ++counts->ncobmc_mode[ao_block][ncobmc_mode[1][i]];
384 }
385 }
386#endif
Wei-Ting Lin85a8f702017-06-22 13:55:15 -0700387}
388#endif
Yaowu Xub24e1152016-10-31 16:28:32 -0700389#endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
390
Yaowu Xuc27fc142016-08-22 16:08:15 -0700391#if CONFIG_EXT_INTER
Yaowu Xuf883b422016-08-30 14:01:10 -0700392static PREDICTION_MODE read_inter_compound_mode(AV1_COMMON *cm, MACROBLOCKD *xd,
393 aom_reader *r, int16_t ctx) {
Thomas Davies8c08a332017-06-26 17:30:34 +0100394 (void)cm;
395 const int mode =
396 aom_read_symbol(r, xd->tile_ctx->inter_compound_mode_cdf[ctx],
397 INTER_COMPOUND_MODES, ACCT_STR);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700398 FRAME_COUNTS *counts = xd->counts;
399
400 if (counts) ++counts->inter_compound_mode[ctx][mode];
401
402 assert(is_inter_compound_mode(NEAREST_NEARESTMV + mode));
403 return NEAREST_NEARESTMV + mode;
404}
Zoe Liu85b66462017-04-20 14:28:19 -0700405
406#if CONFIG_COMPOUND_SINGLEREF
Thomas Daviesb8b14a92017-07-12 15:11:49 +0100407static PREDICTION_MODE read_inter_singleref_comp_mode(MACROBLOCKD *xd,
Zoe Liu85b66462017-04-20 14:28:19 -0700408 aom_reader *r,
409 int16_t ctx) {
410 const int mode =
Thomas Daviesb8b14a92017-07-12 15:11:49 +0100411 aom_read_symbol(r, xd->tile_ctx->inter_singleref_comp_mode_cdf[ctx],
412 INTER_SINGLEREF_COMP_MODES, ACCT_STR);
Zoe Liu85b66462017-04-20 14:28:19 -0700413 FRAME_COUNTS *counts = xd->counts;
414
415 if (counts) ++counts->inter_singleref_comp_mode[ctx][mode];
416
417 assert(is_inter_singleref_comp_mode(SR_NEAREST_NEARMV + mode));
418 return SR_NEAREST_NEARMV + mode;
419}
420#endif // CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -0700421#endif // CONFIG_EXT_INTER
422
Thomas9ac55082016-09-23 18:04:17 +0100423static int read_segment_id(aom_reader *r, struct segmentation_probs *segp) {
Michael Bebenita6048d052016-08-25 14:40:54 -0700424 return aom_read_symbol(r, segp->tree_cdf, MAX_SEGMENTS, ACCT_STR);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700425}
426
427#if CONFIG_VAR_TX
Yaowu Xuf883b422016-08-30 14:01:10 -0700428static void read_tx_size_vartx(AV1_COMMON *cm, MACROBLOCKD *xd,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700429 MB_MODE_INFO *mbmi, FRAME_COUNTS *counts,
Jingning Han94d5bfc2016-10-21 10:14:36 -0700430 TX_SIZE tx_size, int depth, int blk_row,
431 int blk_col, aom_reader *r) {
Thomas Davies985bfc32017-06-27 16:51:26 +0100432#if CONFIG_NEW_MULTISYMBOL
433 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
434 (void)cm;
435#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700436 int is_split = 0;
437 const int tx_row = blk_row >> 1;
438 const int tx_col = blk_col >> 1;
Jingning Hanf64062f2016-11-02 16:22:18 -0700439 const int max_blocks_high = max_block_high(xd, mbmi->sb_type, 0);
440 const int max_blocks_wide = max_block_wide(xd, mbmi->sb_type, 0);
Jingning Han331662e2017-05-30 17:03:32 -0700441 int ctx = txfm_partition_context(xd->above_txfm_context + blk_col,
442 xd->left_txfm_context + blk_row,
Jingning Hanc8b89362016-11-01 10:28:53 -0700443 mbmi->sb_type, tx_size);
clang-format67948d32016-09-07 22:40:40 -0700444 TX_SIZE(*const inter_tx_size)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700445 [MAX_MIB_SIZE] =
446 (TX_SIZE(*)[MAX_MIB_SIZE]) & mbmi->inter_tx_size[tx_row][tx_col];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700447 if (blk_row >= max_blocks_high || blk_col >= max_blocks_wide) return;
448
Jingning Han571189c2016-10-24 10:38:43 -0700449 if (depth == MAX_VARTX_DEPTH) {
Jingning Han94d5bfc2016-10-21 10:14:36 -0700450 int idx, idy;
451 inter_tx_size[0][0] = tx_size;
Jingning Han65abc312016-10-27 13:04:21 -0700452 for (idy = 0; idy < tx_size_high_unit[tx_size] / 2; ++idy)
453 for (idx = 0; idx < tx_size_wide_unit[tx_size] / 2; ++idx)
Jingning Han94d5bfc2016-10-21 10:14:36 -0700454 inter_tx_size[idy][idx] = tx_size;
455 mbmi->tx_size = tx_size;
Jingning Hane67b38a2016-11-04 10:30:00 -0700456 mbmi->min_tx_size = AOMMIN(mbmi->min_tx_size, get_min_tx_size(tx_size));
Jingning Han94d5bfc2016-10-21 10:14:36 -0700457 if (counts) ++counts->txfm_partition[ctx][0];
Jingning Han331662e2017-05-30 17:03:32 -0700458 txfm_partition_update(xd->above_txfm_context + blk_col,
459 xd->left_txfm_context + blk_row, tx_size, tx_size);
Jingning Han94d5bfc2016-10-21 10:14:36 -0700460 return;
461 }
462
Thomas Davies985bfc32017-06-27 16:51:26 +0100463#if CONFIG_NEW_MULTISYMBOL
464 is_split = aom_read_symbol(r, ec_ctx->txfm_partition_cdf[ctx], 2, ACCT_STR);
465#else
Michael Bebenita6048d052016-08-25 14:40:54 -0700466 is_split = aom_read(r, cm->fc->txfm_partition_prob[ctx], ACCT_STR);
Thomas Davies985bfc32017-06-27 16:51:26 +0100467#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700468
469 if (is_split) {
Jingning Hanf64062f2016-11-02 16:22:18 -0700470 const TX_SIZE sub_txs = sub_tx_size_map[tx_size];
471 const int bsl = tx_size_wide_unit[sub_txs];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700472 int i;
473
474 if (counts) ++counts->txfm_partition[ctx][1];
475
476 if (tx_size == TX_8X8) {
Jingning Han9ca05b72017-01-03 14:41:36 -0800477 int idx, idy;
Jingning Hanab9ecba2017-01-13 09:11:58 -0800478 inter_tx_size[0][0] = sub_txs;
Jingning Han9ca05b72017-01-03 14:41:36 -0800479 for (idy = 0; idy < tx_size_high_unit[tx_size] / 2; ++idy)
480 for (idx = 0; idx < tx_size_wide_unit[tx_size] / 2; ++idx)
Jingning Han581d1692017-01-05 16:03:54 -0800481 inter_tx_size[idy][idx] = inter_tx_size[0][0];
Jingning Hanab9ecba2017-01-13 09:11:58 -0800482 mbmi->tx_size = sub_txs;
Jingning Hane67b38a2016-11-04 10:30:00 -0700483 mbmi->min_tx_size = get_min_tx_size(mbmi->tx_size);
Jingning Han331662e2017-05-30 17:03:32 -0700484 txfm_partition_update(xd->above_txfm_context + blk_col,
485 xd->left_txfm_context + blk_row, sub_txs, tx_size);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700486 return;
487 }
488
489 assert(bsl > 0);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700490 for (i = 0; i < 4; ++i) {
Jingning Hanf64062f2016-11-02 16:22:18 -0700491 int offsetr = blk_row + (i >> 1) * bsl;
492 int offsetc = blk_col + (i & 0x01) * bsl;
493 read_tx_size_vartx(cm, xd, mbmi, counts, sub_txs, depth + 1, offsetr,
Jingning Han94d5bfc2016-10-21 10:14:36 -0700494 offsetc, r);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700495 }
496 } else {
497 int idx, idy;
498 inter_tx_size[0][0] = tx_size;
Jingning Han65abc312016-10-27 13:04:21 -0700499 for (idy = 0; idy < tx_size_high_unit[tx_size] / 2; ++idy)
500 for (idx = 0; idx < tx_size_wide_unit[tx_size] / 2; ++idx)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700501 inter_tx_size[idy][idx] = tx_size;
502 mbmi->tx_size = tx_size;
Jingning Hane67b38a2016-11-04 10:30:00 -0700503 mbmi->min_tx_size = AOMMIN(mbmi->min_tx_size, get_min_tx_size(tx_size));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700504 if (counts) ++counts->txfm_partition[ctx][0];
Jingning Han331662e2017-05-30 17:03:32 -0700505 txfm_partition_update(xd->above_txfm_context + blk_col,
506 xd->left_txfm_context + blk_row, tx_size, tx_size);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700507 }
508}
509#endif
510
Yaowu Xuf883b422016-08-30 14:01:10 -0700511static TX_SIZE read_selected_tx_size(AV1_COMMON *cm, MACROBLOCKD *xd,
512 int tx_size_cat, aom_reader *r) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700513 FRAME_COUNTS *counts = xd->counts;
514 const int ctx = get_tx_size_context(xd);
Thomas Davies15580c52017-03-09 13:53:42 +0000515 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
516 (void)cm;
Thomas Davies15580c52017-03-09 13:53:42 +0000517
Nathan E. Egge476c63c2017-05-18 18:35:16 -0400518 const int depth = aom_read_symbol(r, ec_ctx->tx_size_cdf[tx_size_cat][ctx],
519 tx_size_cat + 2, ACCT_STR);
Urvang Joshifeb925f2016-12-05 10:37:29 -0800520 const TX_SIZE tx_size = depth_to_tx_size(depth);
521#if CONFIG_RECT_TX
522 assert(!is_rect_tx(tx_size));
523#endif // CONFIG_RECT_TX
Jingning Han906be072016-10-26 11:04:31 -0700524 if (counts) ++counts->tx_size[tx_size_cat][ctx][depth];
Jingning Han4e1737a2016-10-25 16:05:02 -0700525 return tx_size;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700526}
527
Urvang Joshifeb925f2016-12-05 10:37:29 -0800528static TX_SIZE read_tx_size(AV1_COMMON *cm, MACROBLOCKD *xd, int is_inter,
529 int allow_select_inter, aom_reader *r) {
530 const TX_MODE tx_mode = cm->tx_mode;
531 const BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700532 if (xd->lossless[xd->mi[0]->mbmi.segment_id]) return TX_4X4;
Debargha Mukherjee428bbb22017-03-17 07:30:24 -0700533#if CONFIG_CB4X4 && (CONFIG_VAR_TX || CONFIG_EXT_TX) && CONFIG_RECT_TX
Jingning Han3daa4fd2017-01-20 10:33:50 -0800534 if (bsize > BLOCK_4X4) {
Jingning Han4be1a4d2017-01-06 10:59:20 -0800535#else
Yaowu Xuc27fc142016-08-22 16:08:15 -0700536 if (bsize >= BLOCK_8X8) {
Urvang Joshifeb925f2016-12-05 10:37:29 -0800537#endif // CONFIG_CB4X4 && CONFIG_VAR_TX
538 if ((!is_inter || allow_select_inter) && tx_mode == TX_MODE_SELECT) {
539 const int32_t tx_size_cat = is_inter ? inter_tx_size_cat_lookup[bsize]
540 : intra_tx_size_cat_lookup[bsize];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700541 const TX_SIZE coded_tx_size =
Urvang Joshifeb925f2016-12-05 10:37:29 -0800542 read_selected_tx_size(cm, xd, tx_size_cat, r);
Yue Chen3ca7dd92017-05-23 16:03:39 -0700543#if CONFIG_RECT_TX && (CONFIG_EXT_TX || CONFIG_VAR_TX)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700544 if (coded_tx_size > max_txsize_lookup[bsize]) {
545 assert(coded_tx_size == max_txsize_lookup[bsize] + 1);
Yue Chen3ca7dd92017-05-23 16:03:39 -0700546#if CONFIG_EXT_TX && CONFIG_RECT_TX_EXT
Yue Chen56e226e2017-05-02 16:21:40 -0700547 if (is_quarter_tx_allowed(xd, &xd->mi[0]->mbmi, is_inter)) {
548 int quarter_tx = aom_read(r, cm->fc->quarter_tx_size_prob, ACCT_STR);
549 FRAME_COUNTS *counts = xd->counts;
550
551 if (counts) ++counts->quarter_tx_size[quarter_tx];
552 return quarter_tx ? quarter_txsize_lookup[bsize]
553 : max_txsize_rect_lookup[bsize];
554 }
Yue Chen3ca7dd92017-05-23 16:03:39 -0700555#endif // CONFIG_EXT_TX && CONFIG_RECT_TX_EXT
Yue Chen56e226e2017-05-02 16:21:40 -0700556
Yaowu Xuc27fc142016-08-22 16:08:15 -0700557 return max_txsize_rect_lookup[bsize];
558 }
Peter de Rivaza7c81462016-09-26 14:20:13 +0100559#else
560 assert(coded_tx_size <= max_txsize_lookup[bsize]);
Yue Chen3ca7dd92017-05-23 16:03:39 -0700561#endif // CONFIG_RECT_TX && (CONFIG_EXT_TX || CONFIG_VAR_TX)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700562 return coded_tx_size;
563 } else {
Urvang Joshifeb925f2016-12-05 10:37:29 -0800564 return tx_size_from_tx_mode(bsize, tx_mode, is_inter);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700565 }
566 } else {
567#if CONFIG_EXT_TX && CONFIG_RECT_TX
568 assert(IMPLIES(tx_mode == ONLY_4X4, bsize == BLOCK_4X4));
569 return max_txsize_rect_lookup[bsize];
570#else
571 return TX_4X4;
Urvang Joshifeb925f2016-12-05 10:37:29 -0800572#endif // CONFIG_EXT_TX && CONFIG_RECT_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -0700573 }
574}
575
Yaowu Xuf883b422016-08-30 14:01:10 -0700576static int dec_get_segment_id(const AV1_COMMON *cm, const uint8_t *segment_ids,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700577 int mi_offset, int x_mis, int y_mis) {
578 int x, y, segment_id = INT_MAX;
579
580 for (y = 0; y < y_mis; y++)
581 for (x = 0; x < x_mis; x++)
582 segment_id =
Yaowu Xuf883b422016-08-30 14:01:10 -0700583 AOMMIN(segment_id, segment_ids[mi_offset + y * cm->mi_cols + x]);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700584
585 assert(segment_id >= 0 && segment_id < MAX_SEGMENTS);
586 return segment_id;
587}
588
Yaowu Xuf883b422016-08-30 14:01:10 -0700589static void set_segment_id(AV1_COMMON *cm, int mi_offset, int x_mis, int y_mis,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700590 int segment_id) {
591 int x, y;
592
593 assert(segment_id >= 0 && segment_id < MAX_SEGMENTS);
594
595 for (y = 0; y < y_mis; y++)
596 for (x = 0; x < x_mis; x++)
597 cm->current_frame_seg_map[mi_offset + y * cm->mi_cols + x] = segment_id;
598}
599
Yaowu Xuf883b422016-08-30 14:01:10 -0700600static int read_intra_segment_id(AV1_COMMON *const cm, MACROBLOCKD *const xd,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700601 int mi_offset, int x_mis, int y_mis,
Yaowu Xuf883b422016-08-30 14:01:10 -0700602 aom_reader *r) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700603 struct segmentation *const seg = &cm->seg;
604 FRAME_COUNTS *counts = xd->counts;
Thomas Davies9f5cedd2017-07-10 09:20:32 +0100605 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
Thomas Davies9f5cedd2017-07-10 09:20:32 +0100606 struct segmentation_probs *const segp = &ec_ctx->seg;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700607 int segment_id;
608
609 if (!seg->enabled) return 0; // Default for disabled segmentation
610
611 assert(seg->update_map && !seg->temporal_update);
612
613 segment_id = read_segment_id(r, segp);
614 if (counts) ++counts->seg.tree_total[segment_id];
615 set_segment_id(cm, mi_offset, x_mis, y_mis, segment_id);
616 return segment_id;
617}
618
Yaowu Xuf883b422016-08-30 14:01:10 -0700619static void copy_segment_id(const AV1_COMMON *cm,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700620 const uint8_t *last_segment_ids,
621 uint8_t *current_segment_ids, int mi_offset,
622 int x_mis, int y_mis) {
623 int x, y;
624
625 for (y = 0; y < y_mis; y++)
626 for (x = 0; x < x_mis; x++)
627 current_segment_ids[mi_offset + y * cm->mi_cols + x] =
628 last_segment_ids ? last_segment_ids[mi_offset + y * cm->mi_cols + x]
629 : 0;
630}
631
Yaowu Xuf883b422016-08-30 14:01:10 -0700632static int read_inter_segment_id(AV1_COMMON *const cm, MACROBLOCKD *const xd,
633 int mi_row, int mi_col, aom_reader *r) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700634 struct segmentation *const seg = &cm->seg;
635 FRAME_COUNTS *counts = xd->counts;
Thomas Davies9f5cedd2017-07-10 09:20:32 +0100636 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
Thomas Davies9f5cedd2017-07-10 09:20:32 +0100637 struct segmentation_probs *const segp = &ec_ctx->seg;
638
Yaowu Xuc27fc142016-08-22 16:08:15 -0700639 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
640 int predicted_segment_id, segment_id;
641 const int mi_offset = mi_row * cm->mi_cols + mi_col;
Jingning Hanc709e1f2016-12-06 14:48:09 -0800642 const int bw = mi_size_wide[mbmi->sb_type];
643 const int bh = mi_size_high[mbmi->sb_type];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700644
645 // TODO(slavarnway): move x_mis, y_mis into xd ?????
Yaowu Xuf883b422016-08-30 14:01:10 -0700646 const int x_mis = AOMMIN(cm->mi_cols - mi_col, bw);
647 const int y_mis = AOMMIN(cm->mi_rows - mi_row, bh);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700648
649 if (!seg->enabled) return 0; // Default for disabled segmentation
650
651 predicted_segment_id = cm->last_frame_seg_map
652 ? dec_get_segment_id(cm, cm->last_frame_seg_map,
653 mi_offset, x_mis, y_mis)
654 : 0;
655
656 if (!seg->update_map) {
657 copy_segment_id(cm, cm->last_frame_seg_map, cm->current_frame_seg_map,
658 mi_offset, x_mis, y_mis);
659 return predicted_segment_id;
660 }
661
662 if (seg->temporal_update) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700663 const int ctx = av1_get_pred_context_seg_id(xd);
Thomas Davies00021352017-07-11 16:07:55 +0100664#if CONFIG_NEW_MULTISYMBOL
665 aom_cdf_prob *pred_cdf = segp->pred_cdf[ctx];
666 mbmi->seg_id_predicted = aom_read_symbol(r, pred_cdf, 2, ACCT_STR);
667#else
Yaowu Xuf883b422016-08-30 14:01:10 -0700668 const aom_prob pred_prob = segp->pred_probs[ctx];
Michael Bebenita6048d052016-08-25 14:40:54 -0700669 mbmi->seg_id_predicted = aom_read(r, pred_prob, ACCT_STR);
Thomas Davies00021352017-07-11 16:07:55 +0100670#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700671 if (counts) ++counts->seg.pred[ctx][mbmi->seg_id_predicted];
672 if (mbmi->seg_id_predicted) {
673 segment_id = predicted_segment_id;
674 } else {
675 segment_id = read_segment_id(r, segp);
676 if (counts) ++counts->seg.tree_mispred[segment_id];
677 }
678 } else {
679 segment_id = read_segment_id(r, segp);
680 if (counts) ++counts->seg.tree_total[segment_id];
681 }
682 set_segment_id(cm, mi_offset, x_mis, y_mis, segment_id);
683 return segment_id;
684}
685
Yaowu Xuf883b422016-08-30 14:01:10 -0700686static int read_skip(AV1_COMMON *cm, const MACROBLOCKD *xd, int segment_id,
687 aom_reader *r) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700688 if (segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)) {
689 return 1;
690 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700691 const int ctx = av1_get_skip_context(xd);
Thomas Davies61e3e372017-04-04 16:10:23 +0100692#if CONFIG_NEW_MULTISYMBOL
693 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
694 const int skip = aom_read_symbol(r, ec_ctx->skip_cdfs[ctx], 2, ACCT_STR);
695#else
Michael Bebenita6048d052016-08-25 14:40:54 -0700696 const int skip = aom_read(r, cm->fc->skip_probs[ctx], ACCT_STR);
Thomas Davies61e3e372017-04-04 16:10:23 +0100697#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700698 FRAME_COUNTS *counts = xd->counts;
699 if (counts) ++counts->skip[ctx][skip];
700 return skip;
701 }
702}
703
Urvang Joshib100db72016-10-12 16:28:56 -0700704#if CONFIG_PALETTE
hui su33567b22017-04-30 16:40:19 -0700705#if CONFIG_PALETTE_DELTA_ENCODING
hui su33567b22017-04-30 16:40:19 -0700706static int uint16_compare(const void *a, const void *b) {
Urvang Joshi0ba850e2017-05-12 17:05:45 -0700707 const uint16_t va = *(const uint16_t *)a;
708 const uint16_t vb = *(const uint16_t *)b;
hui su33567b22017-04-30 16:40:19 -0700709 return va - vb;
710}
hui su33567b22017-04-30 16:40:19 -0700711
712static void read_palette_colors_y(MACROBLOCKD *const xd, int bit_depth,
713 PALETTE_MODE_INFO *const pmi, aom_reader *r) {
714 uint16_t color_cache[2 * PALETTE_MAX_SIZE];
715 const MODE_INFO *const above_mi = xd->above_mi;
716 const MODE_INFO *const left_mi = xd->left_mi;
717 const int n_cache = av1_get_palette_cache(above_mi, left_mi, 0, color_cache);
718 const int n = pmi->palette_size[0];
719 int idx = 0;
720 for (int i = 0; i < n_cache && idx < n; ++i)
721 if (aom_read_bit(r, ACCT_STR)) pmi->palette_colors[idx++] = color_cache[i];
722 if (idx < n) {
723 pmi->palette_colors[idx++] = aom_read_literal(r, bit_depth, ACCT_STR);
724 if (idx < n) {
725 const int min_bits = bit_depth - 3;
726 int bits = min_bits + aom_read_literal(r, 2, ACCT_STR);
727 int range = (1 << bit_depth) - pmi->palette_colors[idx - 1] - 1;
728 for (; idx < n; ++idx) {
729 const int delta = aom_read_literal(r, bits, ACCT_STR) + 1;
730 pmi->palette_colors[idx] = pmi->palette_colors[idx - 1] + delta;
731 range -= delta;
732 bits = AOMMIN(bits, av1_ceil_log2(range));
733 }
734 }
735 }
hui su33567b22017-04-30 16:40:19 -0700736 qsort(pmi->palette_colors, n, sizeof(pmi->palette_colors[0]), uint16_compare);
hui su33567b22017-04-30 16:40:19 -0700737}
738
739static void read_palette_colors_uv(MACROBLOCKD *const xd, int bit_depth,
740 PALETTE_MODE_INFO *const pmi,
741 aom_reader *r) {
742 const int n = pmi->palette_size[1];
743 // U channel colors.
744 uint16_t color_cache[2 * PALETTE_MAX_SIZE];
745 const MODE_INFO *const above_mi = xd->above_mi;
746 const MODE_INFO *const left_mi = xd->left_mi;
747 const int n_cache = av1_get_palette_cache(above_mi, left_mi, 1, color_cache);
748 int idx = PALETTE_MAX_SIZE;
749 for (int i = 0; i < n_cache && idx < PALETTE_MAX_SIZE + n; ++i)
750 if (aom_read_bit(r, ACCT_STR)) pmi->palette_colors[idx++] = color_cache[i];
751 if (idx < PALETTE_MAX_SIZE + n) {
752 pmi->palette_colors[idx++] = aom_read_literal(r, bit_depth, ACCT_STR);
753 if (idx < PALETTE_MAX_SIZE + n) {
754 const int min_bits = bit_depth - 3;
755 int bits = min_bits + aom_read_literal(r, 2, ACCT_STR);
756 int range = (1 << bit_depth) - pmi->palette_colors[idx - 1];
757 for (; idx < PALETTE_MAX_SIZE + n; ++idx) {
758 const int delta = aom_read_literal(r, bits, ACCT_STR);
759 pmi->palette_colors[idx] = pmi->palette_colors[idx - 1] + delta;
760 range -= delta;
761 bits = AOMMIN(bits, av1_ceil_log2(range));
762 }
763 }
764 }
hui su33567b22017-04-30 16:40:19 -0700765 qsort(pmi->palette_colors + PALETTE_MAX_SIZE, n,
766 sizeof(pmi->palette_colors[0]), uint16_compare);
hui su33567b22017-04-30 16:40:19 -0700767
768 // V channel colors.
769 if (aom_read_bit(r, ACCT_STR)) { // Delta encoding.
770 const int min_bits_v = bit_depth - 4;
771 const int max_val = 1 << bit_depth;
772 int bits = min_bits_v + aom_read_literal(r, 2, ACCT_STR);
773 pmi->palette_colors[2 * PALETTE_MAX_SIZE] =
774 aom_read_literal(r, bit_depth, ACCT_STR);
775 for (int i = 1; i < n; ++i) {
776 int delta = aom_read_literal(r, bits, ACCT_STR);
777 if (delta && aom_read_bit(r, ACCT_STR)) delta = -delta;
778 int val = (int)pmi->palette_colors[2 * PALETTE_MAX_SIZE + i - 1] + delta;
779 if (val < 0) val += max_val;
780 if (val >= max_val) val -= max_val;
781 pmi->palette_colors[2 * PALETTE_MAX_SIZE + i] = val;
782 }
783 } else {
784 for (int i = 0; i < n; ++i) {
785 pmi->palette_colors[2 * PALETTE_MAX_SIZE + i] =
786 aom_read_literal(r, bit_depth, ACCT_STR);
787 }
788 }
789}
790#endif // CONFIG_PALETTE_DELTA_ENCODING
791
Yaowu Xuf883b422016-08-30 14:01:10 -0700792static void read_palette_mode_info(AV1_COMMON *const cm, MACROBLOCKD *const xd,
793 aom_reader *r) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700794 MODE_INFO *const mi = xd->mi[0];
795 MB_MODE_INFO *const mbmi = &mi->mbmi;
796 const MODE_INFO *const above_mi = xd->above_mi;
797 const MODE_INFO *const left_mi = xd->left_mi;
798 const BLOCK_SIZE bsize = mbmi->sb_type;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700799 PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info;
800
801 if (mbmi->mode == DC_PRED) {
Urvang Joshi23a61112017-01-30 14:59:27 -0800802 int palette_y_mode_ctx = 0;
hui su40b9e7f2017-07-13 18:15:56 -0700803 if (above_mi) {
Urvang Joshi23a61112017-01-30 14:59:27 -0800804 palette_y_mode_ctx +=
805 (above_mi->mbmi.palette_mode_info.palette_size[0] > 0);
hui su40b9e7f2017-07-13 18:15:56 -0700806 }
807 if (left_mi) {
Urvang Joshi23a61112017-01-30 14:59:27 -0800808 palette_y_mode_ctx +=
809 (left_mi->mbmi.palette_mode_info.palette_size[0] > 0);
hui su40b9e7f2017-07-13 18:15:56 -0700810 }
Urvang Joshi23a61112017-01-30 14:59:27 -0800811 if (aom_read(r, av1_default_palette_y_mode_prob[bsize - BLOCK_8X8]
812 [palette_y_mode_ctx],
813 ACCT_STR)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700814 pmi->palette_size[0] =
Thomas Daviesce7272d2017-07-04 16:11:08 +0100815#if CONFIG_NEW_MULTISYMBOL
816 aom_read_symbol(r,
817 xd->tile_ctx->palette_y_size_cdf[bsize - BLOCK_8X8],
818 PALETTE_SIZES, ACCT_STR) +
819 2;
820#else
Yaowu Xuf883b422016-08-30 14:01:10 -0700821 aom_read_tree(r, av1_palette_size_tree,
Michael Bebenita6048d052016-08-25 14:40:54 -0700822 av1_default_palette_y_size_prob[bsize - BLOCK_8X8],
823 ACCT_STR) +
Yaowu Xuc27fc142016-08-22 16:08:15 -0700824 2;
Thomas Daviesce7272d2017-07-04 16:11:08 +0100825#endif
hui sud13c24a2017-04-07 16:13:07 -0700826#if CONFIG_PALETTE_DELTA_ENCODING
hui su33567b22017-04-30 16:40:19 -0700827 read_palette_colors_y(xd, cm->bit_depth, pmi, r);
hui sud13c24a2017-04-07 16:13:07 -0700828#else
hui su40b9e7f2017-07-13 18:15:56 -0700829 for (int i = 0; i < pmi->palette_size[0]; ++i)
Michael Bebenita6048d052016-08-25 14:40:54 -0700830 pmi->palette_colors[i] = aom_read_literal(r, cm->bit_depth, ACCT_STR);
hui sud13c24a2017-04-07 16:13:07 -0700831#endif // CONFIG_PALETTE_DELTA_ENCODING
Yaowu Xuc27fc142016-08-22 16:08:15 -0700832 }
833 }
834
835 if (mbmi->uv_mode == DC_PRED) {
Urvang Joshi23a61112017-01-30 14:59:27 -0800836 const int palette_uv_mode_ctx = (pmi->palette_size[0] > 0);
837 if (aom_read(r, av1_default_palette_uv_mode_prob[palette_uv_mode_ctx],
Michael Bebenita6048d052016-08-25 14:40:54 -0700838 ACCT_STR)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700839 pmi->palette_size[1] =
Thomas Daviesce7272d2017-07-04 16:11:08 +0100840#if CONFIG_NEW_MULTISYMBOL
841 aom_read_symbol(r,
842 xd->tile_ctx->palette_uv_size_cdf[bsize - BLOCK_8X8],
843 PALETTE_SIZES, ACCT_STR) +
844 2;
845#else
Yaowu Xuf883b422016-08-30 14:01:10 -0700846 aom_read_tree(r, av1_palette_size_tree,
Michael Bebenita6048d052016-08-25 14:40:54 -0700847 av1_default_palette_uv_size_prob[bsize - BLOCK_8X8],
848 ACCT_STR) +
Yaowu Xuc27fc142016-08-22 16:08:15 -0700849 2;
Thomas Daviesce7272d2017-07-04 16:11:08 +0100850#endif
hui sud13c24a2017-04-07 16:13:07 -0700851#if CONFIG_PALETTE_DELTA_ENCODING
hui su33567b22017-04-30 16:40:19 -0700852 read_palette_colors_uv(xd, cm->bit_depth, pmi, r);
hui sud13c24a2017-04-07 16:13:07 -0700853#else
hui su40b9e7f2017-07-13 18:15:56 -0700854 for (int i = 0; i < pmi->palette_size[1]; ++i) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700855 pmi->palette_colors[PALETTE_MAX_SIZE + i] =
Michael Bebenita6048d052016-08-25 14:40:54 -0700856 aom_read_literal(r, cm->bit_depth, ACCT_STR);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700857 pmi->palette_colors[2 * PALETTE_MAX_SIZE + i] =
Michael Bebenita6048d052016-08-25 14:40:54 -0700858 aom_read_literal(r, cm->bit_depth, ACCT_STR);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700859 }
hui sud13c24a2017-04-07 16:13:07 -0700860#endif // CONFIG_PALETTE_DELTA_ENCODING
Yaowu Xuc27fc142016-08-22 16:08:15 -0700861 }
862 }
863}
Urvang Joshib100db72016-10-12 16:28:56 -0700864#endif // CONFIG_PALETTE
Yaowu Xuc27fc142016-08-22 16:08:15 -0700865
hui su5db97432016-10-14 16:10:14 -0700866#if CONFIG_FILTER_INTRA
867static void read_filter_intra_mode_info(AV1_COMMON *const cm,
Jingning Han62946d12017-05-26 11:29:30 -0700868 MACROBLOCKD *const xd, int mi_row,
869 int mi_col, aom_reader *r) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700870 MODE_INFO *const mi = xd->mi[0];
871 MB_MODE_INFO *const mbmi = &mi->mbmi;
872 FRAME_COUNTS *counts = xd->counts;
hui su5db97432016-10-14 16:10:14 -0700873 FILTER_INTRA_MODE_INFO *filter_intra_mode_info =
874 &mbmi->filter_intra_mode_info;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700875
Urvang Joshib100db72016-10-12 16:28:56 -0700876 if (mbmi->mode == DC_PRED
877#if CONFIG_PALETTE
878 && mbmi->palette_mode_info.palette_size[0] == 0
879#endif // CONFIG_PALETTE
880 ) {
hui su5db97432016-10-14 16:10:14 -0700881 filter_intra_mode_info->use_filter_intra_mode[0] =
882 aom_read(r, cm->fc->filter_intra_probs[0], ACCT_STR);
883 if (filter_intra_mode_info->use_filter_intra_mode[0]) {
884 filter_intra_mode_info->filter_intra_mode[0] =
hui su40b9e7f2017-07-13 18:15:56 -0700885 av1_read_uniform(r, FILTER_INTRA_MODES);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700886 }
hui su5db97432016-10-14 16:10:14 -0700887 if (counts) {
clang-format55ce9e02017-02-15 22:27:12 -0800888 ++counts
889 ->filter_intra[0][filter_intra_mode_info->use_filter_intra_mode[0]];
hui su5db97432016-10-14 16:10:14 -0700890 }
Yaowu Xuc27fc142016-08-22 16:08:15 -0700891 }
Jingning Han62946d12017-05-26 11:29:30 -0700892
893#if CONFIG_CB4X4
894 if (!is_chroma_reference(mi_row, mi_col, mbmi->sb_type,
895 xd->plane[1].subsampling_x,
896 xd->plane[1].subsampling_y))
897 return;
hui sub4ed1492017-05-31 17:25:42 -0700898#else
899 (void)mi_row;
900 (void)mi_col;
901#endif // CONFIG_CB4X4
Jingning Han62946d12017-05-26 11:29:30 -0700902
Urvang Joshib100db72016-10-12 16:28:56 -0700903 if (mbmi->uv_mode == DC_PRED
904#if CONFIG_PALETTE
905 && mbmi->palette_mode_info.palette_size[1] == 0
906#endif // CONFIG_PALETTE
907 ) {
hui su5db97432016-10-14 16:10:14 -0700908 filter_intra_mode_info->use_filter_intra_mode[1] =
909 aom_read(r, cm->fc->filter_intra_probs[1], ACCT_STR);
910 if (filter_intra_mode_info->use_filter_intra_mode[1]) {
911 filter_intra_mode_info->filter_intra_mode[1] =
hui su40b9e7f2017-07-13 18:15:56 -0700912 av1_read_uniform(r, FILTER_INTRA_MODES);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700913 }
hui su5db97432016-10-14 16:10:14 -0700914 if (counts) {
clang-format55ce9e02017-02-15 22:27:12 -0800915 ++counts
916 ->filter_intra[1][filter_intra_mode_info->use_filter_intra_mode[1]];
hui su5db97432016-10-14 16:10:14 -0700917 }
Yaowu Xuc27fc142016-08-22 16:08:15 -0700918 }
919}
hui su5db97432016-10-14 16:10:14 -0700920#endif // CONFIG_FILTER_INTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -0700921
hui su5db97432016-10-14 16:10:14 -0700922#if CONFIG_EXT_INTRA
Yaowu Xuf883b422016-08-30 14:01:10 -0700923static void read_intra_angle_info(AV1_COMMON *const cm, MACROBLOCKD *const xd,
924 aom_reader *r) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700925 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
926 const BLOCK_SIZE bsize = mbmi->sb_type;
hui sueda3d762016-12-06 16:58:23 -0800927#if CONFIG_INTRA_INTERP
hui sub4e25d22017-03-09 15:32:30 -0800928 FRAME_CONTEXT *const ec_ctx = xd->tile_ctx;
Yaowu Xuf883b422016-08-30 14:01:10 -0700929 const int ctx = av1_get_pred_context_intra_interp(xd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700930 int p_angle;
hui sueda3d762016-12-06 16:58:23 -0800931#endif // CONFIG_INTRA_INTERP
Yaowu Xuc27fc142016-08-22 16:08:15 -0700932
hui sueda3d762016-12-06 16:58:23 -0800933 (void)cm;
Joe Young830d4ce2017-05-30 17:48:13 -0700934
935 mbmi->angle_delta[0] = 0;
936 mbmi->angle_delta[1] = 0;
937
938 if (!av1_use_angle_delta(bsize)) return;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700939
hui su45dc5972016-12-08 17:42:50 -0800940 if (av1_is_directional_mode(mbmi->mode, bsize)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700941 mbmi->angle_delta[0] =
hui su40b9e7f2017-07-13 18:15:56 -0700942 av1_read_uniform(r, 2 * MAX_ANGLE_DELTA + 1) - MAX_ANGLE_DELTA;
hui sueda3d762016-12-06 16:58:23 -0800943#if CONFIG_INTRA_INTERP
hui su0a6731f2017-04-26 15:23:47 -0700944 p_angle = mode_to_angle_map[mbmi->mode] + mbmi->angle_delta[0] * ANGLE_STEP;
Yaowu Xuf883b422016-08-30 14:01:10 -0700945 if (av1_is_intra_filter_switchable(p_angle)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700946 FRAME_COUNTS *counts = xd->counts;
hui sub4e25d22017-03-09 15:32:30 -0800947 mbmi->intra_filter = aom_read_symbol(r, ec_ctx->intra_filter_cdf[ctx],
948 INTRA_FILTERS, ACCT_STR);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700949 if (counts) ++counts->intra_filter[ctx][mbmi->intra_filter];
950 } else {
951 mbmi->intra_filter = INTRA_FILTER_LINEAR;
952 }
hui sueda3d762016-12-06 16:58:23 -0800953#endif // CONFIG_INTRA_INTERP
Yaowu Xuc27fc142016-08-22 16:08:15 -0700954 }
955
hui su45dc5972016-12-08 17:42:50 -0800956 if (av1_is_directional_mode(mbmi->uv_mode, bsize)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700957 mbmi->angle_delta[1] =
hui su40b9e7f2017-07-13 18:15:56 -0700958 av1_read_uniform(r, 2 * MAX_ANGLE_DELTA + 1) - MAX_ANGLE_DELTA;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700959 }
960}
961#endif // CONFIG_EXT_INTRA
962
Angie Chianga9f9a312017-04-13 16:40:43 -0700963void av1_read_tx_type(const AV1_COMMON *const cm, MACROBLOCKD *xd,
Jingning Hanab7163d2016-11-04 09:46:35 -0700964#if CONFIG_SUPERTX
Angie Chianga9f9a312017-04-13 16:40:43 -0700965 int supertx_enabled,
Jingning Hanab7163d2016-11-04 09:46:35 -0700966#endif
Angie Chiangcd9b03f2017-04-16 13:37:13 -0700967#if CONFIG_TXK_SEL
Jingning Han19b5c8f2017-07-06 15:10:12 -0700968 int blk_row, int blk_col, int block, int plane,
969 TX_SIZE tx_size,
Angie Chianga9f9a312017-04-13 16:40:43 -0700970#endif
971 aom_reader *r) {
972 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
Jingning Hanab7163d2016-11-04 09:46:35 -0700973 const int inter_block = is_inter_block(mbmi);
Jingning Han243b66b2017-06-23 12:11:47 -0700974#if !CONFIG_TXK_SEL
Jingning Hane67b38a2016-11-04 10:30:00 -0700975#if CONFIG_VAR_TX
976 const TX_SIZE tx_size = inter_block ? mbmi->min_tx_size : mbmi->tx_size;
977#else
Jingning Hanab7163d2016-11-04 09:46:35 -0700978 const TX_SIZE tx_size = mbmi->tx_size;
Jingning Hane67b38a2016-11-04 10:30:00 -0700979#endif
Jingning Han243b66b2017-06-23 12:11:47 -0700980#endif // !CONFIG_TXK_SEL
Thomas Daviescef09622017-01-11 17:27:12 +0000981 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
Thomas Daviescef09622017-01-11 17:27:12 +0000982
Angie Chiangcd9b03f2017-04-16 13:37:13 -0700983#if !CONFIG_TXK_SEL
Angie Chianga9f9a312017-04-13 16:40:43 -0700984 TX_TYPE *tx_type = &mbmi->tx_type;
985#else
Angie Chiang39b06eb2017-04-14 09:52:29 -0700986 // only y plane's tx_type is transmitted
987 if (plane > 0) return;
Jingning Han19b5c8f2017-07-06 15:10:12 -0700988 (void)block;
989 TX_TYPE *tx_type = &mbmi->txk_type[(blk_row << 4) + blk_col];
Angie Chianga9f9a312017-04-13 16:40:43 -0700990#endif
991
Jingning Hanab7163d2016-11-04 09:46:35 -0700992 if (!FIXED_TX_TYPE) {
993#if CONFIG_EXT_TX
Urvang Joshifeb925f2016-12-05 10:37:29 -0800994 const TX_SIZE square_tx_size = txsize_sqr_map[tx_size];
Sarah Parkere68a3e42017-02-16 14:03:24 -0800995 if (get_ext_tx_types(tx_size, mbmi->sb_type, inter_block,
996 cm->reduced_tx_set_used) > 1 &&
Yue Cheneeacc4c2017-01-17 17:29:17 -0800997 ((!cm->seg.enabled && cm->base_qindex > 0) ||
998 (cm->seg.enabled && xd->qindex[mbmi->segment_id] > 0)) &&
999 !mbmi->skip &&
Jingning Hanab7163d2016-11-04 09:46:35 -07001000#if CONFIG_SUPERTX
1001 !supertx_enabled &&
1002#endif // CONFIG_SUPERTX
1003 !segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) {
Sarah Parkere68a3e42017-02-16 14:03:24 -08001004 const int eset = get_ext_tx_set(tx_size, mbmi->sb_type, inter_block,
1005 cm->reduced_tx_set_used);
Sarah Parker784596d2017-06-23 08:41:26 -07001006 // eset == 0 should correspond to a set with only DCT_DCT and
1007 // there is no need to read the tx_type
1008 assert(eset != 0);
Jingning Hanab7163d2016-11-04 09:46:35 -07001009 FRAME_COUNTS *counts = xd->counts;
1010
1011 if (inter_block) {
Sarah Parker784596d2017-06-23 08:41:26 -07001012 *tx_type = av1_ext_tx_inter_inv[eset][aom_read_symbol(
1013 r, ec_ctx->inter_ext_tx_cdf[eset][square_tx_size],
1014 ext_tx_cnt_inter[eset], ACCT_STR)];
1015 if (counts) ++counts->inter_ext_tx[eset][square_tx_size][*tx_type];
Jingning Hanab7163d2016-11-04 09:46:35 -07001016 } else if (ALLOW_INTRA_EXT_TX) {
Sarah Parker784596d2017-06-23 08:41:26 -07001017 *tx_type = av1_ext_tx_intra_inv[eset][aom_read_symbol(
1018 r, ec_ctx->intra_ext_tx_cdf[eset][square_tx_size][mbmi->mode],
1019 ext_tx_cnt_intra[eset], ACCT_STR)];
1020 if (counts)
1021 ++counts->intra_ext_tx[eset][square_tx_size][mbmi->mode][*tx_type];
Jingning Hanab7163d2016-11-04 09:46:35 -07001022 }
1023 } else {
Angie Chianga9f9a312017-04-13 16:40:43 -07001024 *tx_type = DCT_DCT;
Jingning Hanab7163d2016-11-04 09:46:35 -07001025 }
1026#else
Yue Cheneeacc4c2017-01-17 17:29:17 -08001027
1028 if (tx_size < TX_32X32 &&
1029 ((!cm->seg.enabled && cm->base_qindex > 0) ||
1030 (cm->seg.enabled && xd->qindex[mbmi->segment_id] > 0)) &&
1031 !mbmi->skip &&
Jingning Hanab7163d2016-11-04 09:46:35 -07001032#if CONFIG_SUPERTX
1033 !supertx_enabled &&
1034#endif // CONFIG_SUPERTX
1035 !segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) {
1036 FRAME_COUNTS *counts = xd->counts;
Yue Cheneeacc4c2017-01-17 17:29:17 -08001037
Jingning Hanab7163d2016-11-04 09:46:35 -07001038 if (inter_block) {
Angie Chianga9f9a312017-04-13 16:40:43 -07001039 *tx_type = av1_ext_tx_inv[aom_read_symbol(
Thomas Daviescef09622017-01-11 17:27:12 +00001040 r, ec_ctx->inter_ext_tx_cdf[tx_size], TX_TYPES, ACCT_STR)];
Angie Chianga9f9a312017-04-13 16:40:43 -07001041 if (counts) ++counts->inter_ext_tx[tx_size][*tx_type];
Jingning Hanab7163d2016-11-04 09:46:35 -07001042 } else {
1043 const TX_TYPE tx_type_nom = intra_mode_to_tx_type_context[mbmi->mode];
Angie Chianga9f9a312017-04-13 16:40:43 -07001044 *tx_type = av1_ext_tx_inv[aom_read_symbol(
Thomas Daviescef09622017-01-11 17:27:12 +00001045 r, ec_ctx->intra_ext_tx_cdf[tx_size][tx_type_nom], TX_TYPES,
Jingning Hanab7163d2016-11-04 09:46:35 -07001046 ACCT_STR)];
Angie Chianga9f9a312017-04-13 16:40:43 -07001047 if (counts) ++counts->intra_ext_tx[tx_size][tx_type_nom][*tx_type];
Jingning Hanab7163d2016-11-04 09:46:35 -07001048 }
1049 } else {
Angie Chianga9f9a312017-04-13 16:40:43 -07001050 *tx_type = DCT_DCT;
Jingning Hanab7163d2016-11-04 09:46:35 -07001051 }
1052#endif // CONFIG_EXT_TX
1053 }
Nathan E. Eggeebced372017-02-17 20:57:21 -05001054#if FIXED_TX_TYPE
1055 assert(mbmi->tx_type == DCT_DCT);
1056#endif
Jingning Hanab7163d2016-11-04 09:46:35 -07001057}
1058
Alex Converse28744302017-04-13 14:46:22 -07001059#if CONFIG_INTRABC
1060static INLINE void read_mv(aom_reader *r, MV *mv, const MV *ref,
1061 nmv_context *ctx, nmv_context_counts *counts,
Alex Converse6b2584c2017-05-02 09:51:21 -07001062 MvSubpelPrecision precision);
Alex Converse28744302017-04-13 14:46:22 -07001063
1064static INLINE int is_mv_valid(const MV *mv);
1065
1066static INLINE int assign_dv(AV1_COMMON *cm, MACROBLOCKD *xd, int_mv *mv,
1067 const int_mv *ref_mv, int mi_row, int mi_col,
1068 BLOCK_SIZE bsize, aom_reader *r) {
Alex Converse28744302017-04-13 14:46:22 -07001069 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
1070 (void)cm;
Alex Converse28744302017-04-13 14:46:22 -07001071 FRAME_COUNTS *counts = xd->counts;
1072 nmv_context_counts *const dv_counts = counts ? &counts->dv : NULL;
Alex Converse6b2584c2017-05-02 09:51:21 -07001073 read_mv(r, &mv->as_mv, &ref_mv->as_mv, &ec_ctx->ndvc, dv_counts,
1074 MV_SUBPEL_NONE);
Alex Converse28744302017-04-13 14:46:22 -07001075 int valid = is_mv_valid(&mv->as_mv) &&
1076 is_dv_valid(mv->as_mv, &xd->tile, mi_row, mi_col, bsize);
Alex Converse28744302017-04-13 14:46:22 -07001077 return valid;
1078}
1079#endif // CONFIG_INTRABC
1080
Yaowu Xuf883b422016-08-30 14:01:10 -07001081static void read_intra_frame_mode_info(AV1_COMMON *const cm,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001082 MACROBLOCKD *const xd, int mi_row,
Yaowu Xuf883b422016-08-30 14:01:10 -07001083 int mi_col, aom_reader *r) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001084 MODE_INFO *const mi = xd->mi[0];
1085 MB_MODE_INFO *const mbmi = &mi->mbmi;
1086 const MODE_INFO *above_mi = xd->above_mi;
1087 const MODE_INFO *left_mi = xd->left_mi;
1088 const BLOCK_SIZE bsize = mbmi->sb_type;
1089 int i;
1090 const int mi_offset = mi_row * cm->mi_cols + mi_col;
Jingning Han85dc03f2016-12-06 16:03:10 -08001091 const int bw = mi_size_wide[bsize];
1092 const int bh = mi_size_high[bsize];
Yaowu Xuc27fc142016-08-22 16:08:15 -07001093
1094 // TODO(slavarnway): move x_mis, y_mis into xd ?????
Yaowu Xuf883b422016-08-30 14:01:10 -07001095 const int x_mis = AOMMIN(cm->mi_cols - mi_col, bw);
1096 const int y_mis = AOMMIN(cm->mi_rows - mi_row, bh);
Thomas Davies1bfb5ed2017-01-11 15:28:11 +00001097 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001098
1099 mbmi->segment_id = read_intra_segment_id(cm, xd, mi_offset, x_mis, y_mis, r);
1100 mbmi->skip = read_skip(cm, xd, mbmi->segment_id, r);
Arild Fuldseth07441162016-08-15 15:07:52 +02001101
1102#if CONFIG_DELTA_Q
1103 if (cm->delta_q_present_flag) {
Thomas Daviesf6936102016-09-05 16:51:31 +01001104 xd->current_qindex =
1105 xd->prev_qindex +
1106 read_delta_qindex(cm, xd, r, mbmi, mi_col, mi_row) * cm->delta_q_res;
Arild Fuldseth (arilfuld)54de7d62017-03-20 13:07:11 +01001107 /* Normative: Clamp to [1,MAXQ] to not interfere with lossless mode */
1108 xd->current_qindex = clamp(xd->current_qindex, 1, MAXQ);
Thomas Daviesf6936102016-09-05 16:51:31 +01001109 xd->prev_qindex = xd->current_qindex;
Fangwen Fu231fe422017-04-24 17:52:29 -07001110#if CONFIG_EXT_DELTA_Q
1111 if (cm->delta_lf_present_flag) {
1112 mbmi->current_delta_lf_from_base = xd->current_delta_lf_from_base =
1113 xd->prev_delta_lf_from_base +
1114 read_delta_lflevel(cm, xd, r, mbmi, mi_col, mi_row) *
1115 cm->delta_lf_res;
1116 xd->prev_delta_lf_from_base = xd->current_delta_lf_from_base;
1117 }
1118#endif
Arild Fuldseth07441162016-08-15 15:07:52 +02001119 }
1120#endif
1121
Yaowu Xuc27fc142016-08-22 16:08:15 -07001122 mbmi->ref_frame[0] = INTRA_FRAME;
Emil Keyder01770b32017-01-20 18:03:11 -05001123 mbmi->ref_frame[1] = NONE_FRAME;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001124
Alex Converse28744302017-04-13 14:46:22 -07001125#if CONFIG_INTRABC
1126 if (bsize >= BLOCK_8X8 && cm->allow_screen_content_tools) {
Alex Converse7c412ea2017-06-01 15:16:22 -07001127 mbmi->use_intrabc = aom_read(r, ec_ctx->intrabc_prob, ACCT_STR);
Alex Converse28744302017-04-13 14:46:22 -07001128 if (mbmi->use_intrabc) {
Alex Conversef71808c2017-06-06 12:21:17 -07001129 mbmi->tx_size = read_tx_size(cm, xd, 1, !mbmi->skip, r);
Alex Converse28744302017-04-13 14:46:22 -07001130 mbmi->mode = mbmi->uv_mode = DC_PRED;
Jingning Hand6c17d92017-04-24 16:33:12 -07001131#if CONFIG_DUAL_FILTER
1132 for (int idx = 0; idx < 4; ++idx) mbmi->interp_filter[idx] = BILINEAR;
1133#else
Alex Converse28744302017-04-13 14:46:22 -07001134 mbmi->interp_filter = BILINEAR;
Jingning Hand6c17d92017-04-24 16:33:12 -07001135#endif
Alex Converse44c2bad2017-05-11 09:36:10 -07001136
1137 int16_t inter_mode_ctx[MODE_CTX_REF_FRAMES];
1138 int_mv ref_mvs[MAX_MV_REF_CANDIDATES] = {};
1139
1140 av1_find_mv_refs(cm, xd, mi, INTRA_FRAME, &xd->ref_mv_count[INTRA_FRAME],
1141 xd->ref_mv_stack[INTRA_FRAME],
1142#if CONFIG_EXT_INTER
Yue Chenf03907a2017-05-31 12:04:04 -07001143 NULL,
Alex Converse44c2bad2017-05-11 09:36:10 -07001144#endif // CONFIG_EXT_INTER
1145 ref_mvs, mi_row, mi_col, NULL, NULL, inter_mode_ctx);
1146
1147 int_mv nearestmv, nearmv;
1148 av1_find_best_ref_mvs(0, ref_mvs, &nearestmv, &nearmv);
1149
1150 int_mv dv_ref = nearestmv.as_int == 0 ? nearmv : nearestmv;
1151 if (dv_ref.as_int == 0) av1_find_ref_dv(&dv_ref, mi_row, mi_col);
1152
Alex Converse28744302017-04-13 14:46:22 -07001153 xd->corrupted |=
1154 !assign_dv(cm, xd, &mbmi->mv[0], &dv_ref, mi_row, mi_col, bsize, r);
Alex Conversee16b2662017-05-24 14:00:00 -07001155#if CONFIG_VAR_TX
1156 // TODO(aconverse@google.com): Evaluate allowing VAR TX on intrabc blocks
1157 const int width = block_size_wide[bsize] >> tx_size_wide_log2[0];
1158 const int height = block_size_high[bsize] >> tx_size_high_log2[0];
1159 int idx, idy;
1160 for (idy = 0; idy < height; ++idy)
1161 for (idx = 0; idx < width; ++idx)
1162 mbmi->inter_tx_size[idy >> 1][idx >> 1] = mbmi->tx_size;
1163 mbmi->min_tx_size = get_min_tx_size(mbmi->tx_size);
1164#endif // CONFIG_VAR_TX
Alex Conversedaa15e42017-05-02 14:27:16 -07001165#if CONFIG_EXT_TX && !CONFIG_TXK_SEL
1166 av1_read_tx_type(cm, xd,
1167#if CONFIG_SUPERTX
1168 0,
1169#endif
1170 r);
1171#endif // CONFIG_EXT_TX && !CONFIG_TXK_SEL
Alex Converse28744302017-04-13 14:46:22 -07001172 return;
1173 }
1174 }
1175#endif // CONFIG_INTRABC
1176
Alex Conversef71808c2017-06-06 12:21:17 -07001177 mbmi->tx_size = read_tx_size(cm, xd, 0, 1, r);
1178
Jingning Han52261842016-12-14 12:17:49 -08001179#if CONFIG_CB4X4
1180 (void)i;
1181 mbmi->mode =
Thomas Davies1bfb5ed2017-01-11 15:28:11 +00001182 read_intra_mode(r, get_y_mode_cdf(ec_ctx, mi, above_mi, left_mi, 0));
Jingning Han52261842016-12-14 12:17:49 -08001183#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001184 switch (bsize) {
1185 case BLOCK_4X4:
1186 for (i = 0; i < 4; ++i)
Nathan E. Egge476c63c2017-05-18 18:35:16 -04001187 mi->bmi[i].as_mode = read_intra_mode(
1188 r, get_y_mode_cdf(ec_ctx, mi, above_mi, left_mi, i));
Yaowu Xuc27fc142016-08-22 16:08:15 -07001189 mbmi->mode = mi->bmi[3].as_mode;
1190 break;
1191 case BLOCK_4X8:
1192 mi->bmi[0].as_mode = mi->bmi[2].as_mode =
Thomas Davies1bfb5ed2017-01-11 15:28:11 +00001193 read_intra_mode(r, get_y_mode_cdf(ec_ctx, mi, above_mi, left_mi, 0));
Yaowu Xuc27fc142016-08-22 16:08:15 -07001194 mi->bmi[1].as_mode = mi->bmi[3].as_mode = mbmi->mode =
Thomas Davies1bfb5ed2017-01-11 15:28:11 +00001195 read_intra_mode(r, get_y_mode_cdf(ec_ctx, mi, above_mi, left_mi, 1));
Yaowu Xuc27fc142016-08-22 16:08:15 -07001196 break;
1197 case BLOCK_8X4:
1198 mi->bmi[0].as_mode = mi->bmi[1].as_mode =
Thomas Davies1bfb5ed2017-01-11 15:28:11 +00001199 read_intra_mode(r, get_y_mode_cdf(ec_ctx, mi, above_mi, left_mi, 0));
Yaowu Xuc27fc142016-08-22 16:08:15 -07001200 mi->bmi[2].as_mode = mi->bmi[3].as_mode = mbmi->mode =
Thomas Davies1bfb5ed2017-01-11 15:28:11 +00001201 read_intra_mode(r, get_y_mode_cdf(ec_ctx, mi, above_mi, left_mi, 2));
Yaowu Xuc27fc142016-08-22 16:08:15 -07001202 break;
1203 default:
1204 mbmi->mode =
Thomas Davies1bfb5ed2017-01-11 15:28:11 +00001205 read_intra_mode(r, get_y_mode_cdf(ec_ctx, mi, above_mi, left_mi, 0));
Yaowu Xuc27fc142016-08-22 16:08:15 -07001206 }
Jingning Han52261842016-12-14 12:17:49 -08001207#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001208
Jingning Han36fe3202017-02-20 22:31:49 -08001209#if CONFIG_CB4X4
Jingning Hand3a64432017-04-06 17:04:17 -07001210 if (is_chroma_reference(mi_row, mi_col, bsize, xd->plane[1].subsampling_x,
Luc Trudeau2c317902017-04-28 11:06:50 -04001211 xd->plane[1].subsampling_y)) {
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001212 mbmi->uv_mode = read_intra_mode_uv(ec_ctx, xd, r, mbmi->mode);
Jingning Han36fe3202017-02-20 22:31:49 -08001213#else
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001214 mbmi->uv_mode = read_intra_mode_uv(ec_ctx, xd, r, mbmi->mode);
Jingning Han36fe3202017-02-20 22:31:49 -08001215#endif
1216
Luc Trudeauf5334002017-04-25 12:21:26 -04001217#if CONFIG_CFL
Luc Trudeau2c317902017-04-28 11:06:50 -04001218 // TODO(ltrudeau) support PALETTE
1219 if (mbmi->uv_mode == DC_PRED) {
David Michael Barr23198662017-06-19 23:19:48 +09001220 mbmi->cfl_alpha_idx = read_cfl_alphas(ec_ctx, r, mbmi->cfl_alpha_signs);
Luc Trudeauf5334002017-04-25 12:21:26 -04001221 }
Luc Trudeau2c317902017-04-28 11:06:50 -04001222#endif // CONFIG_CFL
1223
1224#if CONFIG_CB4X4
Joe Young830d4ce2017-05-30 17:48:13 -07001225 } else {
1226 // Avoid decoding angle_info if there is is no chroma prediction
1227 mbmi->uv_mode = DC_PRED;
Luc Trudeauf5334002017-04-25 12:21:26 -04001228 }
1229#endif
1230
Yaowu Xuc27fc142016-08-22 16:08:15 -07001231#if CONFIG_EXT_INTRA
1232 read_intra_angle_info(cm, xd, r);
1233#endif // CONFIG_EXT_INTRA
Urvang Joshib100db72016-10-12 16:28:56 -07001234#if CONFIG_PALETTE
Yaowu Xuc27fc142016-08-22 16:08:15 -07001235 mbmi->palette_mode_info.palette_size[0] = 0;
1236 mbmi->palette_mode_info.palette_size[1] = 0;
1237 if (bsize >= BLOCK_8X8 && cm->allow_screen_content_tools)
1238 read_palette_mode_info(cm, xd, r);
Urvang Joshib100db72016-10-12 16:28:56 -07001239#endif // CONFIG_PALETTE
hui su5db97432016-10-14 16:10:14 -07001240#if CONFIG_FILTER_INTRA
1241 mbmi->filter_intra_mode_info.use_filter_intra_mode[0] = 0;
1242 mbmi->filter_intra_mode_info.use_filter_intra_mode[1] = 0;
Jingning Han48b1cb32017-01-23 10:26:14 -08001243 if (bsize >= BLOCK_8X8 || CONFIG_CB4X4)
Jingning Han62946d12017-05-26 11:29:30 -07001244 read_filter_intra_mode_info(cm, xd, mi_row, mi_col, r);
hui su5db97432016-10-14 16:10:14 -07001245#endif // CONFIG_FILTER_INTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -07001246
Angie Chiangcd9b03f2017-04-16 13:37:13 -07001247#if !CONFIG_TXK_SEL
Angie Chianga9f9a312017-04-13 16:40:43 -07001248 av1_read_tx_type(cm, xd,
Jingning Hanab7163d2016-11-04 09:46:35 -07001249#if CONFIG_SUPERTX
Angie Chianga9f9a312017-04-13 16:40:43 -07001250 0,
Nathan E. Egge72762a22016-09-07 17:12:07 -04001251#endif
Angie Chianga9f9a312017-04-13 16:40:43 -07001252 r);
Angie Chiangcd9b03f2017-04-16 13:37:13 -07001253#endif // !CONFIG_TXK_SEL
Yaowu Xuc27fc142016-08-22 16:08:15 -07001254}
1255
Alex Converse6b2584c2017-05-02 09:51:21 -07001256static int read_mv_component(aom_reader *r, nmv_component *mvcomp,
1257#if CONFIG_INTRABC
1258 int use_subpel,
1259#endif // CONFIG_INTRABC
1260 int usehp) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001261 int mag, d, fr, hp;
Michael Bebenita6048d052016-08-25 14:40:54 -07001262 const int sign = aom_read(r, mvcomp->sign, ACCT_STR);
1263 const int mv_class =
Nathan E. Egged7b893c2016-09-08 15:08:48 -04001264 aom_read_symbol(r, mvcomp->class_cdf, MV_CLASSES, ACCT_STR);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001265 const int class0 = mv_class == MV_CLASS_0;
1266
1267 // Integer part
1268 if (class0) {
Nathan E. Egge45ea9632016-09-08 17:25:49 -04001269 d = aom_read(r, mvcomp->class0[0], ACCT_STR);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001270 mag = 0;
1271 } else {
1272 int i;
1273 const int n = mv_class + CLASS0_BITS - 1; // number of bits
1274
1275 d = 0;
Michael Bebenita6048d052016-08-25 14:40:54 -07001276 for (i = 0; i < n; ++i) d |= aom_read(r, mvcomp->bits[i], ACCT_STR) << i;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001277 mag = CLASS0_SIZE << (mv_class + 2);
1278 }
1279
Alex Converse6b2584c2017-05-02 09:51:21 -07001280#if CONFIG_INTRABC
1281 if (use_subpel) {
1282#endif // CONFIG_INTRABC
1283 // Fractional part
1284 fr = aom_read_symbol(r, class0 ? mvcomp->class0_fp_cdf[d] : mvcomp->fp_cdf,
1285 MV_FP_SIZE, ACCT_STR);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001286
Alex Converse6b2584c2017-05-02 09:51:21 -07001287 // High precision part (if hp is not used, the default value of the hp is 1)
1288 hp = usehp ? aom_read(r, class0 ? mvcomp->class0_hp : mvcomp->hp, ACCT_STR)
1289 : 1;
1290#if CONFIG_INTRABC
1291 } else {
1292 fr = 3;
1293 hp = 1;
1294 }
1295#endif // CONFIG_INTRABC
Yaowu Xuc27fc142016-08-22 16:08:15 -07001296
1297 // Result
1298 mag += ((d << 3) | (fr << 1) | hp) + 1;
1299 return sign ? -mag : mag;
1300}
1301
Yaowu Xuf883b422016-08-30 14:01:10 -07001302static INLINE void read_mv(aom_reader *r, MV *mv, const MV *ref,
Thomas9ac55082016-09-23 18:04:17 +01001303 nmv_context *ctx, nmv_context_counts *counts,
Alex Converse6b2584c2017-05-02 09:51:21 -07001304 MvSubpelPrecision precision) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001305 MV_JOINT_TYPE joint_type;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001306 MV diff = { 0, 0 };
Michael Bebenita6048d052016-08-25 14:40:54 -07001307 joint_type =
Nathan E. Egge5f7fd7a2016-09-08 11:22:03 -04001308 (MV_JOINT_TYPE)aom_read_symbol(r, ctx->joint_cdf, MV_JOINTS, ACCT_STR);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001309
1310 if (mv_joint_vertical(joint_type))
Alex Converse6b2584c2017-05-02 09:51:21 -07001311 diff.row = read_mv_component(r, &ctx->comps[0],
1312#if CONFIG_INTRABC
1313 precision > MV_SUBPEL_NONE,
1314#endif // CONFIG_INTRABC
1315 precision > MV_SUBPEL_LOW_PRECISION);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001316
1317 if (mv_joint_horizontal(joint_type))
Alex Converse6b2584c2017-05-02 09:51:21 -07001318 diff.col = read_mv_component(r, &ctx->comps[1],
1319#if CONFIG_INTRABC
1320 precision > MV_SUBPEL_NONE,
1321#endif // CONFIG_INTRABC
1322 precision > MV_SUBPEL_LOW_PRECISION);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001323
Alex Converse6b2584c2017-05-02 09:51:21 -07001324 av1_inc_mv(&diff, counts, precision);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001325
1326 mv->row = ref->row + diff.row;
1327 mv->col = ref->col + diff.col;
1328}
1329
Yaowu Xuf883b422016-08-30 14:01:10 -07001330static REFERENCE_MODE read_block_reference_mode(AV1_COMMON *cm,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001331 const MACROBLOCKD *xd,
Yaowu Xuf883b422016-08-30 14:01:10 -07001332 aom_reader *r) {
Jingning Han6b064722017-05-01 09:48:18 -07001333#if !SUB8X8_COMP_REF
Jingning Han69d21012017-05-14 16:51:27 -07001334 if (xd->mi[0]->mbmi.sb_type == BLOCK_4X4) return SINGLE_REFERENCE;
Jingning Han6b064722017-05-01 09:48:18 -07001335#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001336 if (cm->reference_mode == REFERENCE_MODE_SELECT) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001337 const int ctx = av1_get_reference_mode_context(cm, xd);
Thomas Davies8c9bcdf2017-06-21 10:12:48 +01001338#if CONFIG_NEW_MULTISYMBOL
1339 const REFERENCE_MODE mode = (REFERENCE_MODE)aom_read_symbol(
1340 r, xd->tile_ctx->comp_inter_cdf[ctx], 2, ACCT_STR);
1341#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001342 const REFERENCE_MODE mode =
Michael Bebenita6048d052016-08-25 14:40:54 -07001343 (REFERENCE_MODE)aom_read(r, cm->fc->comp_inter_prob[ctx], ACCT_STR);
Thomas Davies8c9bcdf2017-06-21 10:12:48 +01001344#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001345 FRAME_COUNTS *counts = xd->counts;
1346 if (counts) ++counts->comp_inter[ctx][mode];
1347 return mode; // SINGLE_REFERENCE or COMPOUND_REFERENCE
1348 } else {
1349 return cm->reference_mode;
1350 }
1351}
1352
Thomas Davies315f5782017-06-14 15:14:55 +01001353#if CONFIG_NEW_MULTISYMBOL
1354#define READ_REF_BIT(pname) \
Thomas Davies894cc812017-06-22 17:51:33 +01001355 aom_read_symbol(r, av1_get_pred_cdf_##pname(cm, xd), 2, ACCT_STR)
Thomas Davies315f5782017-06-14 15:14:55 +01001356#else
1357#define READ_REF_BIT(pname) \
1358 aom_read(r, av1_get_pred_prob_##pname(cm, xd), ACCT_STR)
1359#endif
1360
Zoe Liuc082bbc2017-05-17 13:31:37 -07001361#if CONFIG_EXT_COMP_REFS
1362static REFERENCE_MODE read_comp_reference_type(AV1_COMMON *cm,
1363 const MACROBLOCKD *xd,
1364 aom_reader *r) {
Zoe Liufcf5fa22017-06-26 16:00:38 -07001365 const int ctx = av1_get_comp_reference_type_context(xd);
Zoe Liuc082bbc2017-05-17 13:31:37 -07001366#if USE_UNI_COMP_REFS
Zoe Liufcf5fa22017-06-26 16:00:38 -07001367 COMP_REFERENCE_TYPE comp_ref_type;
1368#if CONFIG_VAR_REFS
1369 if ((L_OR_L2(cm) || L3_OR_G(cm)) && BWD_OR_ALT(cm))
1370 if (L_AND_L2(cm) || L_AND_L3(cm) || L_AND_G(cm) || BWD_AND_ALT(cm))
1371#endif // CONFIG_VAR_REFS
1372 comp_ref_type = (COMP_REFERENCE_TYPE)aom_read(
1373 r, cm->fc->comp_ref_type_prob[ctx], ACCT_STR);
1374#if CONFIG_VAR_REFS
1375 else
1376 comp_ref_type = BIDIR_COMP_REFERENCE;
1377 else
1378 comp_ref_type = UNIDIR_COMP_REFERENCE;
1379#endif // CONFIG_VAR_REFS
Zoe Liuc082bbc2017-05-17 13:31:37 -07001380#else // !USE_UNI_COMP_REFS
1381 // TODO(zoeliu): Temporarily turn off uni-directional comp refs
1382 const COMP_REFERENCE_TYPE comp_ref_type = BIDIR_COMP_REFERENCE;
1383#endif // USE_UNI_COMP_REFS
1384 FRAME_COUNTS *counts = xd->counts;
1385 if (counts) ++counts->comp_ref_type[ctx][comp_ref_type];
1386 return comp_ref_type; // UNIDIR_COMP_REFERENCE or BIDIR_COMP_REFERENCE
1387}
1388#endif // CONFIG_EXT_COMP_REFS
1389
Yaowu Xuc27fc142016-08-22 16:08:15 -07001390// Read the referncence frame
Yaowu Xuf883b422016-08-30 14:01:10 -07001391static void read_ref_frames(AV1_COMMON *const cm, MACROBLOCKD *const xd,
1392 aom_reader *r, int segment_id,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001393 MV_REFERENCE_FRAME ref_frame[2]) {
Thomas Davies894cc812017-06-22 17:51:33 +01001394#if CONFIG_EXT_COMP_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -07001395 FRAME_CONTEXT *const fc = cm->fc;
Thomas Davies894cc812017-06-22 17:51:33 +01001396#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001397 FRAME_COUNTS *counts = xd->counts;
1398
1399 if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) {
1400 ref_frame[0] = (MV_REFERENCE_FRAME)get_segdata(&cm->seg, segment_id,
1401 SEG_LVL_REF_FRAME);
Emil Keyder01770b32017-01-20 18:03:11 -05001402 ref_frame[1] = NONE_FRAME;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001403 } else {
1404 const REFERENCE_MODE mode = read_block_reference_mode(cm, xd, r);
1405 // FIXME(rbultje) I'm pretty sure this breaks segmentation ref frame coding
1406 if (mode == COMPOUND_REFERENCE) {
Zoe Liuc082bbc2017-05-17 13:31:37 -07001407#if CONFIG_EXT_COMP_REFS
1408 const COMP_REFERENCE_TYPE comp_ref_type =
1409 read_comp_reference_type(cm, xd, r);
1410
1411#if !USE_UNI_COMP_REFS
1412 // TODO(zoeliu): Temporarily turn off uni-directional comp refs
1413 assert(comp_ref_type == BIDIR_COMP_REFERENCE);
1414#endif // !USE_UNI_COMP_REFS
1415
1416 if (comp_ref_type == UNIDIR_COMP_REFERENCE) {
Zoe Liufcf5fa22017-06-26 16:00:38 -07001417 const int ctx = av1_get_pred_context_uni_comp_ref_p(xd);
1418 int bit;
1419#if CONFIG_VAR_REFS
1420 if ((L_AND_L2(cm) || L_AND_L3(cm) || L_AND_G(cm)) && BWD_AND_ALT(cm))
1421#endif // CONFIG_VAR_REFS
1422 bit = aom_read(r, fc->uni_comp_ref_prob[ctx][0], ACCT_STR);
1423#if CONFIG_VAR_REFS
1424 else
1425 bit = BWD_AND_ALT(cm);
1426#endif // CONFIG_VAR_REFS
Zoe Liuc082bbc2017-05-17 13:31:37 -07001427 if (counts) ++counts->uni_comp_ref[ctx][0][bit];
1428
1429 if (bit) {
1430 ref_frame[0] = BWDREF_FRAME;
1431 ref_frame[1] = ALTREF_FRAME;
1432 } else {
Zoe Liufcf5fa22017-06-26 16:00:38 -07001433 const int ctx1 = av1_get_pred_context_uni_comp_ref_p1(xd);
1434 int bit1;
1435#if CONFIG_VAR_REFS
1436 if (L_AND_L2(cm) && (L_AND_L3(cm) || L_AND_G(cm)))
1437#endif // CONFIG_VAR_REFS
1438 bit1 = aom_read(r, fc->uni_comp_ref_prob[ctx1][1], ACCT_STR);
1439#if CONFIG_VAR_REFS
1440 else
1441 bit1 = L_AND_L3(cm) || L_AND_G(cm);
1442#endif // CONFIG_VAR_REFS
Zoe Liuc082bbc2017-05-17 13:31:37 -07001443 if (counts) ++counts->uni_comp_ref[ctx1][1][bit1];
1444
1445 if (bit1) {
Zoe Liufcf5fa22017-06-26 16:00:38 -07001446 const int ctx2 = av1_get_pred_context_uni_comp_ref_p2(xd);
1447 int bit2;
1448#if CONFIG_VAR_REFS
1449 if (L_AND_L3(cm) && L_AND_G(cm))
1450#endif // CONFIG_VAR_REFS
1451 bit2 = aom_read(r, fc->uni_comp_ref_prob[ctx2][2], ACCT_STR);
1452#if CONFIG_VAR_REFS
1453 else
1454 bit2 = L_AND_G(cm);
1455#endif // CONFIG_VAR_REFS
1456 if (counts) ++counts->uni_comp_ref[ctx2][2][bit2];
1457
1458 if (bit2) {
1459 ref_frame[0] = LAST_FRAME;
1460 ref_frame[1] = GOLDEN_FRAME;
1461 } else {
1462 ref_frame[0] = LAST_FRAME;
1463 ref_frame[1] = LAST3_FRAME;
1464 }
Zoe Liuc082bbc2017-05-17 13:31:37 -07001465 } else {
1466 ref_frame[0] = LAST_FRAME;
1467 ref_frame[1] = LAST2_FRAME;
1468 }
1469 }
1470
1471 return;
1472 }
Zoe Liufcf5fa22017-06-26 16:00:38 -07001473
1474 assert(comp_ref_type == BIDIR_COMP_REFERENCE);
Zoe Liuc082bbc2017-05-17 13:31:37 -07001475#endif // CONFIG_EXT_COMP_REFS
1476
1477// Normative in decoder (for low delay)
1478#if CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS
Arild Fuldseth (arilfuld)38897302017-04-27 20:03:03 +02001479 const int idx = 1;
Zoe Liuc082bbc2017-05-17 13:31:37 -07001480#else // !(CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001481#if CONFIG_EXT_REFS
1482 const int idx = cm->ref_frame_sign_bias[cm->comp_bwd_ref[0]];
Zoe Liuc082bbc2017-05-17 13:31:37 -07001483#else // !CONFIG_EXT_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -07001484 const int idx = cm->ref_frame_sign_bias[cm->comp_fixed_ref];
1485#endif // CONFIG_EXT_REFS
Zoe Liuc082bbc2017-05-17 13:31:37 -07001486#endif // CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -07001487
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001488 const int ctx = av1_get_pred_context_comp_ref_p(cm, xd);
1489#if CONFIG_VAR_REFS
1490 int bit;
1491 // Test need to explicitly code (L,L2) vs (L3,G) branch node in tree
1492 if (L_OR_L2(cm) && L3_OR_G(cm))
Thomas Davies894cc812017-06-22 17:51:33 +01001493 bit = READ_REF_BIT(comp_ref_p);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001494 else
1495 bit = L3_OR_G(cm);
1496#else // !CONFIG_VAR_REFS
Thomas Davies894cc812017-06-22 17:51:33 +01001497 const int bit = READ_REF_BIT(comp_ref_p);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001498#endif // CONFIG_VAR_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -07001499 if (counts) ++counts->comp_ref[ctx][0][bit];
1500
1501#if CONFIG_EXT_REFS
1502 // Decode forward references.
1503 if (!bit) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001504 const int ctx1 = av1_get_pred_context_comp_ref_p1(cm, xd);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001505#if CONFIG_VAR_REFS
1506 int bit1;
1507 // Test need to explicitly code (L) vs (L2) branch node in tree
1508 if (L_AND_L2(cm))
Thomas Davies894cc812017-06-22 17:51:33 +01001509 bit1 = READ_REF_BIT(comp_ref_p1);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001510 else
1511 bit1 = LAST_IS_VALID(cm);
1512#else // !CONFIG_VAR_REFS
Thomas Davies894cc812017-06-22 17:51:33 +01001513 const int bit1 = READ_REF_BIT(comp_ref_p1);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001514#endif // CONFIG_VAR_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -07001515 if (counts) ++counts->comp_ref[ctx1][1][bit1];
1516 ref_frame[!idx] = cm->comp_fwd_ref[bit1 ? 0 : 1];
1517 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -07001518 const int ctx2 = av1_get_pred_context_comp_ref_p2(cm, xd);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001519#if CONFIG_VAR_REFS
1520 int bit2;
1521 // Test need to explicitly code (L3) vs (G) branch node in tree
1522 if (L3_AND_G(cm))
Thomas Davies894cc812017-06-22 17:51:33 +01001523 bit2 = READ_REF_BIT(comp_ref_p2);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001524 else
1525 bit2 = GOLDEN_IS_VALID(cm);
1526#else // !CONFIG_VAR_REFS
Thomas Davies894cc812017-06-22 17:51:33 +01001527 const int bit2 = READ_REF_BIT(comp_ref_p2);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001528#endif // CONFIG_VAR_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -07001529 if (counts) ++counts->comp_ref[ctx2][2][bit2];
1530 ref_frame[!idx] = cm->comp_fwd_ref[bit2 ? 3 : 2];
1531 }
1532
1533 // Decode backward references.
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001534 const int ctx_bwd = av1_get_pred_context_comp_bwdref_p(cm, xd);
1535#if CONFIG_VAR_REFS
1536 int bit_bwd;
1537 // Test need to explicitly code (BWD) vs (ALT) branch node in tree
1538 if (BWD_AND_ALT(cm))
Thomas Davies894cc812017-06-22 17:51:33 +01001539 bit_bwd = READ_REF_BIT(comp_bwdref_p);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001540 else
1541 bit_bwd = ALTREF_IS_VALID(cm);
Thomas Davies894cc812017-06-22 17:51:33 +01001542#else // !CONFIG_VAR_REFS
1543 const int bit_bwd = READ_REF_BIT(comp_bwdref_p);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001544#endif // CONFIG_VAR_REFS
1545 if (counts) ++counts->comp_bwdref[ctx_bwd][0][bit_bwd];
1546 ref_frame[idx] = cm->comp_bwd_ref[bit_bwd];
1547#else // !CONFIG_EXT_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -07001548 ref_frame[!idx] = cm->comp_var_ref[bit];
1549 ref_frame[idx] = cm->comp_fixed_ref;
1550#endif // CONFIG_EXT_REFS
1551 } else if (mode == SINGLE_REFERENCE) {
1552#if CONFIG_EXT_REFS
Yaowu Xuf883b422016-08-30 14:01:10 -07001553 const int ctx0 = av1_get_pred_context_single_ref_p1(xd);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001554#if CONFIG_VAR_REFS
1555 int bit0;
1556 // Test need to explicitly code (L,L2,L3,G) vs (BWD,ALT) branch node in
1557 // tree
1558 if ((L_OR_L2(cm) || L3_OR_G(cm)) && BWD_OR_ALT(cm))
Thomas Davies315f5782017-06-14 15:14:55 +01001559 bit0 = READ_REF_BIT(single_ref_p1);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001560 else
1561 bit0 = BWD_OR_ALT(cm);
1562#else // !CONFIG_VAR_REFS
Thomas Davies315f5782017-06-14 15:14:55 +01001563 const int bit0 = READ_REF_BIT(single_ref_p1);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001564#endif // CONFIG_VAR_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -07001565 if (counts) ++counts->single_ref[ctx0][0][bit0];
1566
1567 if (bit0) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001568 const int ctx1 = av1_get_pred_context_single_ref_p2(xd);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001569#if CONFIG_VAR_REFS
1570 int bit1;
1571 // Test need to explicitly code (BWD) vs (ALT) branch node in tree
1572 if (BWD_AND_ALT(cm))
Thomas Davies315f5782017-06-14 15:14:55 +01001573 bit1 = READ_REF_BIT(single_ref_p2);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001574 else
1575 bit1 = ALTREF_IS_VALID(cm);
Thomas Davies315f5782017-06-14 15:14:55 +01001576#else // !CONFIG_VAR_REFS
1577 const int bit1 = READ_REF_BIT(single_ref_p2);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001578#endif // CONFIG_VAR_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -07001579 if (counts) ++counts->single_ref[ctx1][1][bit1];
1580 ref_frame[0] = bit1 ? ALTREF_FRAME : BWDREF_FRAME;
1581 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -07001582 const int ctx2 = av1_get_pred_context_single_ref_p3(xd);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001583#if CONFIG_VAR_REFS
1584 int bit2;
1585 // Test need to explicitly code (L,L2) vs (L3,G) branch node in tree
1586 if (L_OR_L2(cm) && L3_OR_G(cm))
Thomas Davies315f5782017-06-14 15:14:55 +01001587 bit2 = READ_REF_BIT(single_ref_p3);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001588 else
1589 bit2 = L3_OR_G(cm);
Thomas Davies315f5782017-06-14 15:14:55 +01001590#else // !CONFIG_VAR_REFS
1591 const int bit2 = READ_REF_BIT(single_ref_p3);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001592#endif // CONFIG_VAR_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -07001593 if (counts) ++counts->single_ref[ctx2][2][bit2];
1594 if (bit2) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001595 const int ctx4 = av1_get_pred_context_single_ref_p5(xd);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001596#if CONFIG_VAR_REFS
1597 int bit4;
1598 // Test need to explicitly code (L3) vs (G) branch node in tree
1599 if (L3_AND_G(cm))
Thomas Davies315f5782017-06-14 15:14:55 +01001600 bit4 = READ_REF_BIT(single_ref_p5);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001601 else
1602 bit4 = GOLDEN_IS_VALID(cm);
Thomas Davies315f5782017-06-14 15:14:55 +01001603#else // !CONFIG_VAR_REFS
1604 const int bit4 = READ_REF_BIT(single_ref_p5);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001605#endif // CONFIG_VAR_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -07001606 if (counts) ++counts->single_ref[ctx4][4][bit4];
1607 ref_frame[0] = bit4 ? GOLDEN_FRAME : LAST3_FRAME;
1608 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -07001609 const int ctx3 = av1_get_pred_context_single_ref_p4(xd);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001610#if CONFIG_VAR_REFS
1611 int bit3;
1612 // Test need to explicitly code (L) vs (L2) branch node in tree
1613 if (L_AND_L2(cm))
Thomas Davies315f5782017-06-14 15:14:55 +01001614 bit3 = READ_REF_BIT(single_ref_p4);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001615 else
1616 bit3 = LAST2_IS_VALID(cm);
Thomas Davies315f5782017-06-14 15:14:55 +01001617#else // !CONFIG_VAR_REFS
1618 const int bit3 = READ_REF_BIT(single_ref_p4);
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001619#endif // CONFIG_VAR_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -07001620 if (counts) ++counts->single_ref[ctx3][3][bit3];
1621 ref_frame[0] = bit3 ? LAST2_FRAME : LAST_FRAME;
1622 }
1623 }
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07001624#else // !CONFIG_EXT_REFS
Yaowu Xuf883b422016-08-30 14:01:10 -07001625 const int ctx0 = av1_get_pred_context_single_ref_p1(xd);
Thomas Davies315f5782017-06-14 15:14:55 +01001626 const int bit0 = READ_REF_BIT(single_ref_p1);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001627 if (counts) ++counts->single_ref[ctx0][0][bit0];
1628
1629 if (bit0) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001630 const int ctx1 = av1_get_pred_context_single_ref_p2(xd);
Thomas Davies315f5782017-06-14 15:14:55 +01001631 const int bit1 = READ_REF_BIT(single_ref_p2);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001632 if (counts) ++counts->single_ref[ctx1][1][bit1];
1633 ref_frame[0] = bit1 ? ALTREF_FRAME : GOLDEN_FRAME;
1634 } else {
1635 ref_frame[0] = LAST_FRAME;
1636 }
1637#endif // CONFIG_EXT_REFS
1638
Emil Keyder01770b32017-01-20 18:03:11 -05001639 ref_frame[1] = NONE_FRAME;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001640 } else {
1641 assert(0 && "Invalid prediction mode.");
1642 }
1643 }
1644}
1645
Angie Chiang9c4f8952016-11-21 11:13:19 -08001646static INLINE void read_mb_interp_filter(AV1_COMMON *const cm,
1647 MACROBLOCKD *const xd,
1648 MB_MODE_INFO *const mbmi,
1649 aom_reader *r) {
1650 FRAME_COUNTS *counts = xd->counts;
Thomas Davies77c7c402017-01-11 17:58:54 +00001651 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
Thomas Davies77c7c402017-01-11 17:58:54 +00001652
Debargha Mukherjee0df711f2017-05-02 16:00:20 -07001653 if (!av1_is_interp_needed(xd)) {
1654 set_default_interp_filters(mbmi, cm->interp_filter);
Yue Chen19e7aa82016-11-30 14:05:39 -08001655 return;
1656 }
Yue Chen19e7aa82016-11-30 14:05:39 -08001657
1658#if CONFIG_DUAL_FILTER
Yaowu Xuc27fc142016-08-22 16:08:15 -07001659 if (cm->interp_filter != SWITCHABLE) {
Yue Chen19e7aa82016-11-30 14:05:39 -08001660 int dir;
1661
Angie Chiang9c4f8952016-11-21 11:13:19 -08001662 for (dir = 0; dir < 4; ++dir) mbmi->interp_filter[dir] = cm->interp_filter;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001663 } else {
Yue Chen19e7aa82016-11-30 14:05:39 -08001664 int dir;
1665
Angie Chiang9c4f8952016-11-21 11:13:19 -08001666 for (dir = 0; dir < 2; ++dir) {
1667 const int ctx = av1_get_pred_context_switchable_interp(xd, dir);
1668 mbmi->interp_filter[dir] = EIGHTTAP_REGULAR;
1669
1670 if (has_subpel_mv_component(xd->mi[0], xd, dir) ||
1671 (mbmi->ref_frame[1] > INTRA_FRAME &&
1672 has_subpel_mv_component(xd->mi[0], xd, dir + 2))) {
Angie Chiang9c4f8952016-11-21 11:13:19 -08001673 mbmi->interp_filter[dir] =
1674 (InterpFilter)av1_switchable_interp_inv[aom_read_symbol(
Thomas Davies77c7c402017-01-11 17:58:54 +00001675 r, ec_ctx->switchable_interp_cdf[ctx], SWITCHABLE_FILTERS,
Angie Chiang9c4f8952016-11-21 11:13:19 -08001676 ACCT_STR)];
Angie Chiang9c4f8952016-11-21 11:13:19 -08001677 if (counts) ++counts->switchable_interp[ctx][mbmi->interp_filter[dir]];
1678 }
1679 }
1680 // The index system works as:
1681 // (0, 1) -> (vertical, horizontal) filter types for the first ref frame.
1682 // (2, 3) -> (vertical, horizontal) filter types for the second ref frame.
1683 mbmi->interp_filter[2] = mbmi->interp_filter[0];
1684 mbmi->interp_filter[3] = mbmi->interp_filter[1];
1685 }
Nathan E. Egge476c63c2017-05-18 18:35:16 -04001686#else // CONFIG_DUAL_FILTER
Angie Chiang9c4f8952016-11-21 11:13:19 -08001687 if (cm->interp_filter != SWITCHABLE) {
1688 mbmi->interp_filter = cm->interp_filter;
1689 } else {
1690 const int ctx = av1_get_pred_context_switchable_interp(xd);
Angie Chiang9c4f8952016-11-21 11:13:19 -08001691 mbmi->interp_filter =
Michael Bebenita6048d052016-08-25 14:40:54 -07001692 (InterpFilter)av1_switchable_interp_inv[aom_read_symbol(
Thomas Davies77c7c402017-01-11 17:58:54 +00001693 r, ec_ctx->switchable_interp_cdf[ctx], SWITCHABLE_FILTERS,
Michael Bebenita6048d052016-08-25 14:40:54 -07001694 ACCT_STR)];
Angie Chiang9c4f8952016-11-21 11:13:19 -08001695 if (counts) ++counts->switchable_interp[ctx][mbmi->interp_filter];
Yaowu Xuc27fc142016-08-22 16:08:15 -07001696 }
Angie Chiang9c4f8952016-11-21 11:13:19 -08001697#endif // CONFIG_DUAL_FILTER
Yaowu Xuc27fc142016-08-22 16:08:15 -07001698}
1699
Jingning Han36fe3202017-02-20 22:31:49 -08001700static void read_intra_block_mode_info(AV1_COMMON *const cm, const int mi_row,
1701 const int mi_col, MACROBLOCKD *const xd,
1702 MODE_INFO *mi, aom_reader *r) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001703 MB_MODE_INFO *const mbmi = &mi->mbmi;
1704 const BLOCK_SIZE bsize = mi->mbmi.sb_type;
1705 int i;
1706
1707 mbmi->ref_frame[0] = INTRA_FRAME;
Emil Keyder01770b32017-01-20 18:03:11 -05001708 mbmi->ref_frame[1] = NONE_FRAME;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001709
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001710 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001711
Jingning Han52261842016-12-14 12:17:49 -08001712#if CONFIG_CB4X4
1713 (void)i;
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001714 mbmi->mode = read_intra_mode_y(ec_ctx, xd, r, size_group_lookup[bsize]);
Jingning Han52261842016-12-14 12:17:49 -08001715#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001716 switch (bsize) {
1717 case BLOCK_4X4:
1718 for (i = 0; i < 4; ++i)
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001719 mi->bmi[i].as_mode = read_intra_mode_y(ec_ctx, xd, r, 0);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001720 mbmi->mode = mi->bmi[3].as_mode;
1721 break;
1722 case BLOCK_4X8:
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001723 mi->bmi[0].as_mode = mi->bmi[2].as_mode =
1724 read_intra_mode_y(ec_ctx, xd, r, 0);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001725 mi->bmi[1].as_mode = mi->bmi[3].as_mode = mbmi->mode =
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001726 read_intra_mode_y(ec_ctx, xd, r, 0);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001727 break;
1728 case BLOCK_8X4:
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001729 mi->bmi[0].as_mode = mi->bmi[1].as_mode =
1730 read_intra_mode_y(ec_ctx, xd, r, 0);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001731 mi->bmi[2].as_mode = mi->bmi[3].as_mode = mbmi->mode =
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001732 read_intra_mode_y(ec_ctx, xd, r, 0);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001733 break;
1734 default:
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001735 mbmi->mode = read_intra_mode_y(ec_ctx, xd, r, size_group_lookup[bsize]);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001736 }
Jingning Han52261842016-12-14 12:17:49 -08001737#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001738
Jingning Han36fe3202017-02-20 22:31:49 -08001739#if CONFIG_CB4X4
Jingning Hand3a64432017-04-06 17:04:17 -07001740 if (is_chroma_reference(mi_row, mi_col, bsize, xd->plane[1].subsampling_x,
Luc Trudeaub09b55d2017-04-26 10:06:35 -04001741 xd->plane[1].subsampling_y)) {
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001742 mbmi->uv_mode = read_intra_mode_uv(ec_ctx, xd, r, mbmi->mode);
Jingning Han36fe3202017-02-20 22:31:49 -08001743#else
Nathan E. Eggea1f80e32017-05-23 11:52:32 -04001744 mbmi->uv_mode = read_intra_mode_uv(ec_ctx, xd, r, mbmi->mode);
Jingning Han36fe3202017-02-20 22:31:49 -08001745 (void)mi_row;
1746 (void)mi_col;
1747#endif
1748
Luc Trudeaub09b55d2017-04-26 10:06:35 -04001749#if CONFIG_CFL
1750 // TODO(ltrudeau) support PALETTE
1751 if (mbmi->uv_mode == DC_PRED) {
Nathan E. Egge6bdc40f2017-06-18 19:02:23 -04001752 mbmi->cfl_alpha_idx =
1753 read_cfl_alphas(xd->tile_ctx, r, mbmi->cfl_alpha_signs);
Luc Trudeaub09b55d2017-04-26 10:06:35 -04001754 }
1755#endif // CONFIG_CFL
1756
1757#if CONFIG_CB4X4
1758 }
1759#endif
1760
Yaowu Xuc27fc142016-08-22 16:08:15 -07001761#if CONFIG_EXT_INTRA
1762 read_intra_angle_info(cm, xd, r);
1763#endif // CONFIG_EXT_INTRA
Urvang Joshib100db72016-10-12 16:28:56 -07001764#if CONFIG_PALETTE
Yaowu Xuc27fc142016-08-22 16:08:15 -07001765 mbmi->palette_mode_info.palette_size[0] = 0;
1766 mbmi->palette_mode_info.palette_size[1] = 0;
1767 if (bsize >= BLOCK_8X8 && cm->allow_screen_content_tools)
1768 read_palette_mode_info(cm, xd, r);
Urvang Joshib100db72016-10-12 16:28:56 -07001769#endif // CONFIG_PALETTE
hui su5db97432016-10-14 16:10:14 -07001770#if CONFIG_FILTER_INTRA
1771 mbmi->filter_intra_mode_info.use_filter_intra_mode[0] = 0;
1772 mbmi->filter_intra_mode_info.use_filter_intra_mode[1] = 0;
Jingning Han48b1cb32017-01-23 10:26:14 -08001773 if (bsize >= BLOCK_8X8 || CONFIG_CB4X4)
Jingning Han62946d12017-05-26 11:29:30 -07001774 read_filter_intra_mode_info(cm, xd, mi_row, mi_col, r);
hui su5db97432016-10-14 16:10:14 -07001775#endif // CONFIG_FILTER_INTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -07001776}
1777
1778static INLINE int is_mv_valid(const MV *mv) {
1779 return mv->row > MV_LOW && mv->row < MV_UPP && mv->col > MV_LOW &&
1780 mv->col < MV_UPP;
1781}
1782
Yaowu Xuf883b422016-08-30 14:01:10 -07001783static INLINE int assign_mv(AV1_COMMON *cm, MACROBLOCKD *xd,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001784 PREDICTION_MODE mode,
Jingning Han5c60cdf2016-09-30 09:37:46 -07001785 MV_REFERENCE_FRAME ref_frame[2], int block,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001786 int_mv mv[2], int_mv ref_mv[2],
David Barker45390c12017-02-20 14:44:40 +00001787 int_mv nearest_mv[2], int_mv near_mv[2], int mi_row,
1788 int mi_col, int is_compound, int allow_hp,
1789 aom_reader *r) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001790 int i;
1791 int ret = 1;
Thomas Davies24523292017-01-11 16:56:47 +00001792 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
Debargha Mukherjeef6dd3c62017-02-23 13:21:23 -08001793 BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001794 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
Jingning Han5cfa6712016-12-14 09:53:38 -08001795#if CONFIG_CB4X4
1796 int_mv *pred_mv = mbmi->pred_mv;
1797 (void)block;
1798#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001799 int_mv *pred_mv =
Yaowu Xuf5bbbfa2016-09-26 09:13:38 -07001800 (bsize >= BLOCK_8X8) ? mbmi->pred_mv : xd->mi[0]->bmi[block].pred_mv;
Jingning Han5cfa6712016-12-14 09:53:38 -08001801#endif // CONFIG_CB4X4
Sarah Parkere5299862016-08-16 14:57:37 -07001802 (void)ref_frame;
Thomas Davies24523292017-01-11 16:56:47 +00001803 (void)cm;
David Barker45390c12017-02-20 14:44:40 +00001804 (void)mi_row;
1805 (void)mi_col;
Debargha Mukherjeef6dd3c62017-02-23 13:21:23 -08001806 (void)bsize;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001807
1808 switch (mode) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001809 case NEWMV: {
1810 FRAME_COUNTS *counts = xd->counts;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001811 for (i = 0; i < 1 + is_compound; ++i) {
Yaowu Xu4306b6e2016-09-27 12:55:32 -07001812 int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
1813 int nmv_ctx =
1814 av1_nmv_ctx(xd->ref_mv_count[rf_type], xd->ref_mv_stack[rf_type], i,
1815 mbmi->ref_mv_idx);
Alex Converse3d0bdc12017-05-01 15:19:58 -07001816 nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
Yaowu Xuc27fc142016-08-22 16:08:15 -07001817 nmv_context_counts *const mv_counts =
1818 counts ? &counts->mv[nmv_ctx] : NULL;
Alex Converse3d0bdc12017-05-01 15:19:58 -07001819 read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, nmvc, mv_counts, allow_hp);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001820 ret = ret && is_mv_valid(&mv[i].as_mv);
1821
Yaowu Xuc27fc142016-08-22 16:08:15 -07001822 pred_mv[i].as_int = ref_mv[i].as_int;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001823 }
1824 break;
1825 }
1826 case NEARESTMV: {
1827 mv[0].as_int = nearest_mv[0].as_int;
1828 if (is_compound) mv[1].as_int = nearest_mv[1].as_int;
1829
Yaowu Xuc27fc142016-08-22 16:08:15 -07001830 pred_mv[0].as_int = nearest_mv[0].as_int;
1831 if (is_compound) pred_mv[1].as_int = nearest_mv[1].as_int;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001832 break;
1833 }
1834 case NEARMV: {
1835 mv[0].as_int = near_mv[0].as_int;
1836 if (is_compound) mv[1].as_int = near_mv[1].as_int;
1837
Yaowu Xuc27fc142016-08-22 16:08:15 -07001838 pred_mv[0].as_int = near_mv[0].as_int;
1839 if (is_compound) pred_mv[1].as_int = near_mv[1].as_int;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001840 break;
1841 }
1842 case ZEROMV: {
Sarah Parkere5299862016-08-16 14:57:37 -07001843#if CONFIG_GLOBAL_MOTION
David Barkercdcac6d2016-12-01 17:04:16 +00001844 mv[0].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[0]],
Sarah Parkerae7c4582017-02-28 16:30:30 -08001845 cm->allow_high_precision_mv, bsize,
Debargha Mukherjeefebb59c2017-03-02 12:23:45 -08001846 mi_col, mi_row, block)
David Barkercdcac6d2016-12-01 17:04:16 +00001847 .as_int;
Sarah Parkere5299862016-08-16 14:57:37 -07001848 if (is_compound)
David Barkercdcac6d2016-12-01 17:04:16 +00001849 mv[1].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[1]],
Sarah Parkerae7c4582017-02-28 16:30:30 -08001850 cm->allow_high_precision_mv, bsize,
Debargha Mukherjeefebb59c2017-03-02 12:23:45 -08001851 mi_col, mi_row, block)
David Barkercdcac6d2016-12-01 17:04:16 +00001852 .as_int;
Sarah Parkere5299862016-08-16 14:57:37 -07001853#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001854 mv[0].as_int = 0;
1855 if (is_compound) mv[1].as_int = 0;
Sarah Parkere5299862016-08-16 14:57:37 -07001856#endif // CONFIG_GLOBAL_MOTION
Yaowu Xuc27fc142016-08-22 16:08:15 -07001857
Debargha Mukherjeefebb59c2017-03-02 12:23:45 -08001858 pred_mv[0].as_int = mv[0].as_int;
1859 if (is_compound) pred_mv[1].as_int = mv[1].as_int;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001860 break;
1861 }
1862#if CONFIG_EXT_INTER
Zoe Liu85b66462017-04-20 14:28:19 -07001863#if CONFIG_COMPOUND_SINGLEREF
1864 case SR_NEAREST_NEARMV: {
1865 assert(!is_compound);
1866 mv[0].as_int = nearest_mv[0].as_int;
1867 mv[1].as_int = near_mv[0].as_int;
1868 break;
1869 }
1870 /*
1871 case SR_NEAREST_NEWMV: {
1872 assert(!is_compound);
1873 mv[0].as_int = nearest_mv[0].as_int;
1874
1875 FRAME_COUNTS *counts = xd->counts;
1876 int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
1877 int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type],
1878 xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx);
1879 nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
1880 nmv_context_counts *const mv_counts =
1881 counts ? &counts->mv[nmv_ctx] : NULL;
1882 read_mv(r, &mv[1].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp);
1883 ret = ret && is_mv_valid(&mv[1].as_mv);
1884 break;
1885 }*/
1886 case SR_NEAR_NEWMV: {
1887 assert(!is_compound);
1888 mv[0].as_int = near_mv[0].as_int;
1889
1890 FRAME_COUNTS *counts = xd->counts;
1891 int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
1892 int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type],
1893 xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx);
1894 nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
1895 nmv_context_counts *const mv_counts =
1896 counts ? &counts->mv[nmv_ctx] : NULL;
1897 read_mv(r, &mv[1].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp);
1898 ret = ret && is_mv_valid(&mv[1].as_mv);
1899 break;
1900 }
1901 case SR_ZERO_NEWMV: {
1902 assert(!is_compound);
1903#if CONFIG_GLOBAL_MOTION
1904 mv[0].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[0]],
1905 cm->allow_high_precision_mv, bsize,
1906 mi_col, mi_row, block)
1907 .as_int;
1908#else
1909 mv[0].as_int = 0;
1910#endif // CONFIG_GLOBAL_MOTION
1911
1912 FRAME_COUNTS *counts = xd->counts;
1913 int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
1914 int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type],
1915 xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx);
1916 nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
1917 nmv_context_counts *const mv_counts =
1918 counts ? &counts->mv[nmv_ctx] : NULL;
1919 read_mv(r, &mv[1].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp);
1920 ret = ret && is_mv_valid(&mv[1].as_mv);
1921 break;
1922 }
1923 case SR_NEW_NEWMV: {
1924 assert(!is_compound);
1925
1926 FRAME_COUNTS *counts = xd->counts;
1927 for (i = 0; i < 2; ++i) {
1928 int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
1929 int nmv_ctx =
1930 av1_nmv_ctx(xd->ref_mv_count[rf_type], xd->ref_mv_stack[rf_type], 0,
1931 mbmi->ref_mv_idx);
1932 nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
1933 nmv_context_counts *const mv_counts =
1934 counts ? &counts->mv[nmv_ctx] : NULL;
1935 read_mv(r, &mv[i].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp);
1936 ret = ret && is_mv_valid(&mv[i].as_mv);
1937 }
1938 break;
1939 }
1940#endif // CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -07001941 case NEW_NEWMV: {
1942 FRAME_COUNTS *counts = xd->counts;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001943 assert(is_compound);
1944 for (i = 0; i < 2; ++i) {
Yaowu Xu4306b6e2016-09-27 12:55:32 -07001945 int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
1946 int nmv_ctx =
1947 av1_nmv_ctx(xd->ref_mv_count[rf_type], xd->ref_mv_stack[rf_type], i,
1948 mbmi->ref_mv_idx);
Alex Converse3d0bdc12017-05-01 15:19:58 -07001949 nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
Yaowu Xuc27fc142016-08-22 16:08:15 -07001950 nmv_context_counts *const mv_counts =
1951 counts ? &counts->mv[nmv_ctx] : NULL;
Alex Converse3d0bdc12017-05-01 15:19:58 -07001952 read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, nmvc, mv_counts, allow_hp);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001953 ret = ret && is_mv_valid(&mv[i].as_mv);
1954 }
1955 break;
1956 }
1957 case NEAREST_NEARESTMV: {
1958 assert(is_compound);
1959 mv[0].as_int = nearest_mv[0].as_int;
1960 mv[1].as_int = nearest_mv[1].as_int;
1961 break;
1962 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07001963 case NEAR_NEARMV: {
1964 assert(is_compound);
1965 mv[0].as_int = near_mv[0].as_int;
1966 mv[1].as_int = near_mv[1].as_int;
1967 break;
1968 }
1969 case NEW_NEARESTMV: {
1970 FRAME_COUNTS *counts = xd->counts;
Yaowu Xu4306b6e2016-09-27 12:55:32 -07001971 int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
1972 int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type],
1973 xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx);
Alex Converse3d0bdc12017-05-01 15:19:58 -07001974 nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
Yaowu Xuc27fc142016-08-22 16:08:15 -07001975 nmv_context_counts *const mv_counts =
1976 counts ? &counts->mv[nmv_ctx] : NULL;
Alex Converse3d0bdc12017-05-01 15:19:58 -07001977 read_mv(r, &mv[0].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001978 assert(is_compound);
1979 ret = ret && is_mv_valid(&mv[0].as_mv);
1980 mv[1].as_int = nearest_mv[1].as_int;
1981 break;
1982 }
1983 case NEAREST_NEWMV: {
1984 FRAME_COUNTS *counts = xd->counts;
Yaowu Xu4306b6e2016-09-27 12:55:32 -07001985 int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
1986 int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type],
1987 xd->ref_mv_stack[rf_type], 1, mbmi->ref_mv_idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001988 nmv_context_counts *const mv_counts =
1989 counts ? &counts->mv[nmv_ctx] : NULL;
Alex Converse3d0bdc12017-05-01 15:19:58 -07001990 nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
Alex Converse3d0bdc12017-05-01 15:19:58 -07001991 mv[0].as_int = nearest_mv[0].as_int;
1992 read_mv(r, &mv[1].as_mv, &ref_mv[1].as_mv, nmvc, mv_counts, allow_hp);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001993 assert(is_compound);
1994 ret = ret && is_mv_valid(&mv[1].as_mv);
1995 break;
1996 }
1997 case NEAR_NEWMV: {
1998 FRAME_COUNTS *counts = xd->counts;
Yaowu Xu4306b6e2016-09-27 12:55:32 -07001999 int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
2000 int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type],
2001 xd->ref_mv_stack[rf_type], 1, mbmi->ref_mv_idx);
Alex Converse3d0bdc12017-05-01 15:19:58 -07002002 nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
Yaowu Xuc27fc142016-08-22 16:08:15 -07002003 nmv_context_counts *const mv_counts =
2004 counts ? &counts->mv[nmv_ctx] : NULL;
Alex Converse3d0bdc12017-05-01 15:19:58 -07002005 mv[0].as_int = near_mv[0].as_int;
2006 read_mv(r, &mv[1].as_mv, &ref_mv[1].as_mv, nmvc, mv_counts, allow_hp);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002007 assert(is_compound);
2008
2009 ret = ret && is_mv_valid(&mv[1].as_mv);
2010 break;
2011 }
2012 case NEW_NEARMV: {
2013 FRAME_COUNTS *counts = xd->counts;
Yaowu Xu4306b6e2016-09-27 12:55:32 -07002014 int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
2015 int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type],
2016 xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx);
Alex Converse3d0bdc12017-05-01 15:19:58 -07002017 nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
Yaowu Xuc27fc142016-08-22 16:08:15 -07002018 nmv_context_counts *const mv_counts =
2019 counts ? &counts->mv[nmv_ctx] : NULL;
Alex Converse3d0bdc12017-05-01 15:19:58 -07002020 read_mv(r, &mv[0].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002021 assert(is_compound);
2022 ret = ret && is_mv_valid(&mv[0].as_mv);
2023 mv[1].as_int = near_mv[1].as_int;
2024 break;
2025 }
2026 case ZERO_ZEROMV: {
2027 assert(is_compound);
Sarah Parkerc2d38712017-01-24 15:15:41 -08002028#if CONFIG_GLOBAL_MOTION
2029 mv[0].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[0]],
Sarah Parkerae7c4582017-02-28 16:30:30 -08002030 cm->allow_high_precision_mv, bsize,
Debargha Mukherjeefebb59c2017-03-02 12:23:45 -08002031 mi_col, mi_row, block)
Sarah Parkerc2d38712017-01-24 15:15:41 -08002032 .as_int;
2033 mv[1].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[1]],
Sarah Parkerae7c4582017-02-28 16:30:30 -08002034 cm->allow_high_precision_mv, bsize,
Debargha Mukherjeefebb59c2017-03-02 12:23:45 -08002035 mi_col, mi_row, block)
Sarah Parkerc2d38712017-01-24 15:15:41 -08002036 .as_int;
2037#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07002038 mv[0].as_int = 0;
2039 mv[1].as_int = 0;
Sarah Parkerc2d38712017-01-24 15:15:41 -08002040#endif // CONFIG_GLOBAL_MOTION
Yaowu Xuc27fc142016-08-22 16:08:15 -07002041 break;
2042 }
2043#endif // CONFIG_EXT_INTER
2044 default: { return 0; }
2045 }
2046 return ret;
2047}
2048
Yaowu Xuf883b422016-08-30 14:01:10 -07002049static int read_is_inter_block(AV1_COMMON *const cm, MACROBLOCKD *const xd,
2050 int segment_id, aom_reader *r) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07002051 if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) {
2052 return get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME) != INTRA_FRAME;
2053 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -07002054 const int ctx = av1_get_intra_inter_context(xd);
Thomas Daviesf6ad9352017-04-19 11:38:06 +01002055#if CONFIG_NEW_MULTISYMBOL
Thomas Daviesf6ad9352017-04-19 11:38:06 +01002056 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
Thomas Daviesf6ad9352017-04-19 11:38:06 +01002057 const int is_inter =
2058 aom_read_symbol(r, ec_ctx->intra_inter_cdf[ctx], 2, ACCT_STR);
2059#else
Michael Bebenita6048d052016-08-25 14:40:54 -07002060 const int is_inter = aom_read(r, cm->fc->intra_inter_prob[ctx], ACCT_STR);
Thomas Daviesf6ad9352017-04-19 11:38:06 +01002061#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002062 FRAME_COUNTS *counts = xd->counts;
2063 if (counts) ++counts->intra_inter[ctx][is_inter];
2064 return is_inter;
2065 }
2066}
2067
Zoe Liu85b66462017-04-20 14:28:19 -07002068#if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
2069static int read_is_inter_singleref_comp_mode(AV1_COMMON *const cm,
2070 MACROBLOCKD *const xd,
2071 int segment_id, aom_reader *r) {
2072 if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) return 0;
2073
2074 const int ctx = av1_get_inter_mode_context(xd);
2075 const int is_singleref_comp_mode =
2076 aom_read(r, cm->fc->comp_inter_mode_prob[ctx], ACCT_STR);
2077 FRAME_COUNTS *counts = xd->counts;
2078
2079 if (counts) ++counts->comp_inter_mode[ctx][is_singleref_comp_mode];
2080 return is_singleref_comp_mode;
2081}
2082#endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
2083
Yaowu Xuc27fc142016-08-22 16:08:15 -07002084static void fpm_sync(void *const data, int mi_row) {
Yaowu Xuf883b422016-08-30 14:01:10 -07002085 AV1Decoder *const pbi = (AV1Decoder *)data;
2086 av1_frameworker_wait(pbi->frame_worker_owner, pbi->common.prev_frame,
2087 mi_row << pbi->common.mib_size_log2);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002088}
2089
Di Chen56586622017-06-09 13:49:44 -07002090#if DEC_MISMATCH_DEBUG
2091static void dec_dump_logs(AV1_COMMON *cm, MODE_INFO *const mi,
Zoe Liuf9333f52017-07-03 10:52:01 -07002092 MACROBLOCKD *const xd, int mi_row, int mi_col,
2093 int16_t inter_mode_ctx[MODE_CTX_REF_FRAMES],
2094 int16_t mode_ctx) {
Di Chen56586622017-06-09 13:49:44 -07002095 int_mv mv[2] = { { 0 } };
2096 int ref;
2097 MB_MODE_INFO *const mbmi = &mi->mbmi;
Di Chen56586622017-06-09 13:49:44 -07002098 for (ref = 0; ref < 1 + has_second_ref(mbmi); ++ref)
2099 mv[ref].as_mv = mbmi->mv[ref].as_mv;
2100
2101 int interp_ctx[2] = { -1 };
2102 int interp_filter[2] = { cm->interp_filter };
2103 if (cm->interp_filter == SWITCHABLE) {
2104 int dir;
2105 for (dir = 0; dir < 2; ++dir) {
2106 if (has_subpel_mv_component(xd->mi[0], xd, dir) ||
2107 (mbmi->ref_frame[1] > INTRA_FRAME &&
2108 has_subpel_mv_component(xd->mi[0], xd, dir + 2))) {
2109 interp_ctx[dir] = av1_get_pred_context_switchable_interp(xd, dir);
2110 interp_filter[dir] = mbmi->interp_filter[dir];
2111 } else {
2112 interp_filter[dir] = EIGHTTAP_REGULAR;
2113 }
2114 }
2115 }
2116
2117 const int16_t newmv_ctx = mode_ctx & NEWMV_CTX_MASK;
2118 int16_t zeromv_ctx = -1;
2119 int16_t refmv_ctx = -1;
2120 if (mbmi->mode != NEWMV) {
2121 if (mode_ctx & (1 << ALL_ZERO_FLAG_OFFSET)) assert(mbmi->mode == ZEROMV);
2122 zeromv_ctx = (mode_ctx >> ZEROMV_OFFSET) & ZEROMV_CTX_MASK;
2123 if (mbmi->mode != ZEROMV) {
2124 refmv_ctx = (mode_ctx >> REFMV_OFFSET) & REFMV_CTX_MASK;
2125 if (mode_ctx & (1 << SKIP_NEARESTMV_OFFSET)) refmv_ctx = 6;
2126 if (mode_ctx & (1 << SKIP_NEARMV_OFFSET)) refmv_ctx = 7;
2127 if (mode_ctx & (1 << SKIP_NEARESTMV_SUB8X8_OFFSET)) refmv_ctx = 8;
2128 }
2129 }
2130
2131 int8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
Zoe Liuf9333f52017-07-03 10:52:01 -07002132#define FRAME_TO_CHECK 1
Zoe Liufcf5fa22017-06-26 16:00:38 -07002133 if (cm->current_video_frame == FRAME_TO_CHECK /*&& cm->show_frame == 0*/) {
Zoe Liuf9333f52017-07-03 10:52:01 -07002134 printf(
2135 "=== DECODER ===: "
2136 "Frame=%d, (mi_row,mi_col)=(%d,%d), mode=%d, bsize=%d, "
2137 "show_frame=%d, mv[0]=(%d,%d), mv[1]=(%d,%d), ref[0]=%d, "
2138 "ref[1]=%d, motion_mode=%d, inter_mode_ctx=%d, mode_ctx=%d, "
2139 "interp_ctx=(%d,%d), interp_filter=(%d,%d), newmv_ctx=%d, "
2140 "zeromv_ctx=%d, refmv_ctx=%d\n",
2141 cm->current_video_frame, mi_row, mi_col, mbmi->mode, mbmi->sb_type,
2142 cm->show_frame, mv[0].as_mv.row, mv[0].as_mv.col, mv[1].as_mv.row,
2143 mv[1].as_mv.col, mbmi->ref_frame[0], mbmi->ref_frame[1],
2144 mbmi->motion_mode, inter_mode_ctx[ref_frame_type], mode_ctx,
2145 interp_ctx[0], interp_ctx[1], interp_filter[0], interp_filter[1],
2146 newmv_ctx, zeromv_ctx, refmv_ctx);
2147 }
Di Chen56586622017-06-09 13:49:44 -07002148}
2149#endif // DEC_MISMATCH_DEBUG
2150
Yaowu Xuf883b422016-08-30 14:01:10 -07002151static void read_inter_block_mode_info(AV1Decoder *const pbi,
Yaowu Xuc27fc142016-08-22 16:08:15 -07002152 MACROBLOCKD *const xd,
2153 MODE_INFO *const mi,
David Barker491983d2016-11-10 13:22:17 +00002154#if (CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION || CONFIG_EXT_INTER) && \
2155 CONFIG_SUPERTX
Yaowu Xuf883b422016-08-30 14:01:10 -07002156 int mi_row, int mi_col, aom_reader *r,
Yaowu Xuc27fc142016-08-22 16:08:15 -07002157 int supertx_enabled) {
2158#else
Yaowu Xuf883b422016-08-30 14:01:10 -07002159 int mi_row, int mi_col, aom_reader *r) {
Yue Chencb60b182016-10-13 15:18:22 -07002160#endif // CONFIG_MOTION_VAR && CONFIG_SUPERTX
Yaowu Xuf883b422016-08-30 14:01:10 -07002161 AV1_COMMON *const cm = &pbi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002162 MB_MODE_INFO *const mbmi = &mi->mbmi;
2163 const BLOCK_SIZE bsize = mbmi->sb_type;
2164 const int allow_hp = cm->allow_high_precision_mv;
Jingning Han5cfa6712016-12-14 09:53:38 -08002165 const int unify_bsize = CONFIG_CB4X4;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002166 int_mv nearestmv[2], nearmv[2];
2167 int_mv ref_mvs[MODE_CTX_REF_FRAMES][MAX_MV_REF_CANDIDATES];
Yaowu Xuc27fc142016-08-22 16:08:15 -07002168 int ref, is_compound;
Zoe Liu85b66462017-04-20 14:28:19 -07002169#if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
2170 int is_singleref_comp_mode = 0;
2171#endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -07002172 int16_t inter_mode_ctx[MODE_CTX_REF_FRAMES];
Sebastien Alaiwane140c502017-04-27 09:52:34 +02002173#if CONFIG_EXT_INTER
Yaowu Xuc27fc142016-08-22 16:08:15 -07002174 int16_t compound_inter_mode_ctx[MODE_CTX_REF_FRAMES];
Sebastien Alaiwane140c502017-04-27 09:52:34 +02002175#endif // CONFIG_EXT_INTER
Yaowu Xuc27fc142016-08-22 16:08:15 -07002176 int16_t mode_ctx = 0;
Yue Chen69f18e12016-09-08 14:48:15 -07002177#if CONFIG_WARPED_MOTION
Debargha Mukherjeee6eb3b52017-02-26 08:50:56 -08002178 int pts[SAMPLES_ARRAY_SIZE], pts_inref[SAMPLES_ARRAY_SIZE];
Yunqing Wang1bc82862017-06-28 15:49:48 -07002179#if WARPED_MOTION_SORT_SAMPLES
2180 int pts_mv[SAMPLES_ARRAY_SIZE];
2181#endif // WARPED_MOTION_SORT_SAMPLES
Yue Chen69f18e12016-09-08 14:48:15 -07002182#endif // CONFIG_WARPED_MOTION
Thomas Davies1de6c882017-01-11 17:47:49 +00002183 FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002184
Urvang Joshi5a9ea002017-05-22 15:25:18 -07002185 assert(NELEMENTS(mode_2_counter) == MB_MODE_COUNT);
2186
Urvang Joshib100db72016-10-12 16:28:56 -07002187#if CONFIG_PALETTE
Yaowu Xuc27fc142016-08-22 16:08:15 -07002188 mbmi->palette_mode_info.palette_size[0] = 0;
2189 mbmi->palette_mode_info.palette_size[1] = 0;
Urvang Joshib100db72016-10-12 16:28:56 -07002190#endif // CONFIG_PALETTE
Yaowu Xuc27fc142016-08-22 16:08:15 -07002191
Frederic Barbier7a84fd82017-03-02 18:08:15 +01002192 memset(ref_mvs, 0, sizeof(ref_mvs));
2193
Yaowu Xuc27fc142016-08-22 16:08:15 -07002194 read_ref_frames(cm, xd, r, mbmi->segment_id, mbmi->ref_frame);
2195 is_compound = has_second_ref(mbmi);
2196
Zoe Liuc082bbc2017-05-17 13:31:37 -07002197#if CONFIG_EXT_COMP_REFS
2198#if !USE_UNI_COMP_REFS
2199 // NOTE: uni-directional comp refs disabled
2200 if (is_compound)
2201 assert(mbmi->ref_frame[0] < BWDREF_FRAME &&
2202 mbmi->ref_frame[1] >= BWDREF_FRAME);
2203#endif // !USE_UNI_COMP_REFS
2204#endif // CONFIG_EXT_COMP_REFS
2205
Zoe Liu85b66462017-04-20 14:28:19 -07002206#if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
2207 if (!is_compound)
2208 is_singleref_comp_mode =
2209 read_is_inter_singleref_comp_mode(cm, xd, mbmi->segment_id, r);
2210#endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
2211
Yaowu Xuc27fc142016-08-22 16:08:15 -07002212 for (ref = 0; ref < 1 + is_compound; ++ref) {
2213 MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref];
Yaowu Xuc27fc142016-08-22 16:08:15 -07002214
Sebastien Alaiwane140c502017-04-27 09:52:34 +02002215 av1_find_mv_refs(
2216 cm, xd, mi, frame, &xd->ref_mv_count[frame], xd->ref_mv_stack[frame],
Yaowu Xuc27fc142016-08-22 16:08:15 -07002217#if CONFIG_EXT_INTER
Sebastien Alaiwane140c502017-04-27 09:52:34 +02002218 compound_inter_mode_ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -07002219#endif // CONFIG_EXT_INTER
Sebastien Alaiwane140c502017-04-27 09:52:34 +02002220 ref_mvs[frame], mi_row, mi_col, fpm_sync, (void *)pbi, inter_mode_ctx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002221 }
2222
Jingning Hanacddc032016-11-17 15:26:20 -08002223 if (is_compound) {
2224 MV_REFERENCE_FRAME ref_frame = av1_ref_frame_type(mbmi->ref_frame);
Yaowu Xu4306b6e2016-09-27 12:55:32 -07002225 av1_find_mv_refs(cm, xd, mi, ref_frame, &xd->ref_mv_count[ref_frame],
2226 xd->ref_mv_stack[ref_frame],
2227#if CONFIG_EXT_INTER
2228 compound_inter_mode_ctx,
2229#endif // CONFIG_EXT_INTER
2230 ref_mvs[ref_frame], mi_row, mi_col, fpm_sync, (void *)pbi,
2231 inter_mode_ctx);
2232
2233 if (xd->ref_mv_count[ref_frame] < 2) {
2234 MV_REFERENCE_FRAME rf[2];
David Barkercdcac6d2016-12-01 17:04:16 +00002235 int_mv zeromv[2];
Yaowu Xu4306b6e2016-09-27 12:55:32 -07002236 av1_set_ref_frame(rf, ref_frame);
David Barkercdcac6d2016-12-01 17:04:16 +00002237#if CONFIG_GLOBAL_MOTION
2238 zeromv[0].as_int = gm_get_motion_vector(&cm->global_motion[rf[0]],
David Barker45390c12017-02-20 14:44:40 +00002239 cm->allow_high_precision_mv,
Debargha Mukherjeefebb59c2017-03-02 12:23:45 -08002240 bsize, mi_col, mi_row, 0)
David Barkercdcac6d2016-12-01 17:04:16 +00002241 .as_int;
Sarah Parkerae7c4582017-02-28 16:30:30 -08002242 zeromv[1].as_int = (rf[1] != NONE_FRAME)
2243 ? gm_get_motion_vector(&cm->global_motion[rf[1]],
2244 cm->allow_high_precision_mv,
Debargha Mukherjeefebb59c2017-03-02 12:23:45 -08002245 bsize, mi_col, mi_row, 0)
Sarah Parkerae7c4582017-02-28 16:30:30 -08002246 .as_int
2247 : 0;
David Barkercdcac6d2016-12-01 17:04:16 +00002248#else
2249 zeromv[0].as_int = zeromv[1].as_int = 0;
2250#endif
Sarah Parker9923d1b2017-04-10 11:56:40 -07002251 for (ref = 0; ref < 2; ++ref) {
2252 if (rf[ref] == NONE_FRAME) continue;
Yaowu Xu4306b6e2016-09-27 12:55:32 -07002253 lower_mv_precision(&ref_mvs[rf[ref]][0].as_mv, allow_hp);
2254 lower_mv_precision(&ref_mvs[rf[ref]][1].as_mv, allow_hp);
Sarah Parker9923d1b2017-04-10 11:56:40 -07002255 if (ref_mvs[rf[ref]][0].as_int != zeromv[ref].as_int ||
2256 ref_mvs[rf[ref]][1].as_int != zeromv[ref].as_int)
2257 inter_mode_ctx[ref_frame] &= ~(1 << ALL_ZERO_FLAG_OFFSET);
Frederic Barbier72e2e982017-03-03 10:01:04 +01002258 }
Yaowu Xu4306b6e2016-09-27 12:55:32 -07002259 }
2260 }
2261
Yaowu Xuc27fc142016-08-22 16:08:15 -07002262#if CONFIG_EXT_INTER
Zoe Liu85b66462017-04-20 14:28:19 -07002263#if CONFIG_COMPOUND_SINGLEREF
2264 if (is_compound || is_singleref_comp_mode)
2265#else // !CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -07002266 if (is_compound)
Zoe Liu85b66462017-04-20 14:28:19 -07002267#endif // CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -07002268 mode_ctx = compound_inter_mode_ctx[mbmi->ref_frame[0]];
2269 else
2270#endif // CONFIG_EXT_INTER
2271 mode_ctx =
Yaowu Xuf883b422016-08-30 14:01:10 -07002272 av1_mode_context_analyzer(inter_mode_ctx, mbmi->ref_frame, bsize, -1);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002273 mbmi->ref_mv_idx = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002274
2275 if (segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) {
2276 mbmi->mode = ZEROMV;
Debargha Mukherjeec76f9dc2017-05-01 13:18:09 -07002277 if (bsize < BLOCK_8X8 && !unify_bsize) {
Yaowu Xuf883b422016-08-30 14:01:10 -07002278 aom_internal_error(xd->error_info, AOM_CODEC_UNSUP_BITSTREAM,
David Barker3409c0d2017-06-30 17:33:13 +01002279 "Invalid usage of segment feature on small blocks");
Yaowu Xuc27fc142016-08-22 16:08:15 -07002280 return;
2281 }
2282 } else {
Jingning Han5cfa6712016-12-14 09:53:38 -08002283 if (bsize >= BLOCK_8X8 || unify_bsize) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07002284#if CONFIG_EXT_INTER
2285 if (is_compound)
2286 mbmi->mode = read_inter_compound_mode(cm, xd, r, mode_ctx);
Zoe Liu85b66462017-04-20 14:28:19 -07002287#if CONFIG_COMPOUND_SINGLEREF
2288 else if (is_singleref_comp_mode)
Thomas Daviesb8b14a92017-07-12 15:11:49 +01002289 mbmi->mode = read_inter_singleref_comp_mode(xd, r, mode_ctx);
Zoe Liu85b66462017-04-20 14:28:19 -07002290#endif // CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -07002291 else
2292#endif // CONFIG_EXT_INTER
Zoe Liu7f24e1b2017-03-17 17:42:05 -07002293 mbmi->mode = read_inter_mode(ec_ctx, xd, r, mode_ctx);
David Barker404b2e82017-03-27 13:07:47 +01002294#if CONFIG_EXT_INTER
David Barker3dfba992017-04-03 16:10:09 +01002295 if (mbmi->mode == NEWMV || mbmi->mode == NEW_NEWMV ||
Zoe Liu85b66462017-04-20 14:28:19 -07002296#if CONFIG_COMPOUND_SINGLEREF
2297 mbmi->mode == SR_NEW_NEWMV ||
2298#endif // CONFIG_COMPOUND_SINGLEREF
David Barker3dfba992017-04-03 16:10:09 +01002299 have_nearmv_in_inter_mode(mbmi->mode))
Zoe Liu85b66462017-04-20 14:28:19 -07002300#else // !CONFIG_EXT_INTER
Yaowu Xuc27fc142016-08-22 16:08:15 -07002301 if (mbmi->mode == NEARMV || mbmi->mode == NEWMV)
Zoe Liu85b66462017-04-20 14:28:19 -07002302#endif // CONFIG_EXT_INTER
Thomas Davies149eda52017-06-12 18:11:55 +01002303 read_drl_idx(ec_ctx, xd, mbmi, r);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002304 }
2305 }
2306
2307#if CONFIG_EXT_INTER
Jingning Han5cfa6712016-12-14 09:53:38 -08002308 if ((bsize < BLOCK_8X8 && unify_bsize) ||
Yaowu Xuc27fc142016-08-22 16:08:15 -07002309 (mbmi->mode != ZEROMV && mbmi->mode != ZERO_ZEROMV)) {
2310#else
Jingning Han5cfa6712016-12-14 09:53:38 -08002311 if ((bsize < BLOCK_8X8 && !unify_bsize) || mbmi->mode != ZEROMV) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07002312#endif // CONFIG_EXT_INTER
2313 for (ref = 0; ref < 1 + is_compound; ++ref) {
Yaowu Xuf883b422016-08-30 14:01:10 -07002314 av1_find_best_ref_mvs(allow_hp, ref_mvs[mbmi->ref_frame[ref]],
2315 &nearestmv[ref], &nearmv[ref]);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002316 }
2317 }
2318
Yaowu Xuc27fc142016-08-22 16:08:15 -07002319 if (mbmi->ref_mv_idx > 0) {
2320 int_mv cur_mv =
2321 xd->ref_mv_stack[mbmi->ref_frame[0]][1 + mbmi->ref_mv_idx].this_mv;
2322 nearmv[0] = cur_mv;
2323 }
2324
2325#if CONFIG_EXT_INTER
Zoe Liu85b66462017-04-20 14:28:19 -07002326#if CONFIG_COMPOUND_SINGLEREF
2327 if ((is_compound || is_singleref_comp_mode) &&
2328 (bsize >= BLOCK_8X8 || unify_bsize) && mbmi->mode != ZERO_ZEROMV) {
2329#else // !CONFIG_COMPOUND_SINGLEREF
Jingning Han61418bb2017-01-23 17:12:48 -08002330 if (is_compound && (bsize >= BLOCK_8X8 || unify_bsize) &&
2331 mbmi->mode != ZERO_ZEROMV) {
Zoe Liu85b66462017-04-20 14:28:19 -07002332#endif // CONFIG_COMPOUND_SINGLEREF
2333#else // !CONFIG_EXT_INTER
Jingning Han5cfa6712016-12-14 09:53:38 -08002334 if (is_compound && (bsize >= BLOCK_8X8 || unify_bsize) &&
2335 mbmi->mode != NEWMV && mbmi->mode != ZEROMV) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07002336#endif // CONFIG_EXT_INTER
Yaowu Xuf883b422016-08-30 14:01:10 -07002337 uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002338
2339#if CONFIG_EXT_INTER
2340 if (xd->ref_mv_count[ref_frame_type] > 0) {
2341#else
2342 if (xd->ref_mv_count[ref_frame_type] == 1 && mbmi->mode == NEARESTMV) {
2343#endif // CONFIG_EXT_INTER
2344#if CONFIG_EXT_INTER
2345 if (mbmi->mode == NEAREST_NEARESTMV) {
2346#endif // CONFIG_EXT_INTER
2347 nearestmv[0] = xd->ref_mv_stack[ref_frame_type][0].this_mv;
2348 nearestmv[1] = xd->ref_mv_stack[ref_frame_type][0].comp_mv;
2349 lower_mv_precision(&nearestmv[0].as_mv, allow_hp);
2350 lower_mv_precision(&nearestmv[1].as_mv, allow_hp);
2351#if CONFIG_EXT_INTER
Zoe Liu85b66462017-04-20 14:28:19 -07002352 } else if (mbmi->mode == NEAREST_NEWMV
2353#if CONFIG_COMPOUND_SINGLEREF
2354 || mbmi->mode == SR_NEAREST_NEARMV
2355// || mbmi->mode == SR_NEAREST_NEWMV
2356#endif // CONFIG_COMPOUND_SINGLEREF
2357 ) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07002358 nearestmv[0] = xd->ref_mv_stack[ref_frame_type][0].this_mv;
2359 lower_mv_precision(&nearestmv[0].as_mv, allow_hp);
Debargha Mukherjeebb6e1342017-04-17 16:05:04 -07002360 } else if (mbmi->mode == NEW_NEARESTMV) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07002361 nearestmv[1] = xd->ref_mv_stack[ref_frame_type][0].comp_mv;
2362 lower_mv_precision(&nearestmv[1].as_mv, allow_hp);
2363 }
2364#endif // CONFIG_EXT_INTER
2365 }
2366
2367#if CONFIG_EXT_INTER
2368 if (xd->ref_mv_count[ref_frame_type] > 1) {
David Barker404b2e82017-03-27 13:07:47 +01002369 int ref_mv_idx = 1 + mbmi->ref_mv_idx;
Zoe Liu85b66462017-04-20 14:28:19 -07002370#if CONFIG_COMPOUND_SINGLEREF
2371 if (is_compound) {
2372#endif // CONFIG_COMPOUND_SINGLEREF
2373 if (compound_ref0_mode(mbmi->mode) == NEARMV) {
2374 nearmv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv;
2375 lower_mv_precision(&nearmv[0].as_mv, allow_hp);
2376 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07002377
Zoe Liu85b66462017-04-20 14:28:19 -07002378 if (compound_ref1_mode(mbmi->mode) == NEARMV) {
2379 nearmv[1] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].comp_mv;
2380 lower_mv_precision(&nearmv[1].as_mv, allow_hp);
2381 }
2382#if CONFIG_COMPOUND_SINGLEREF
2383 } else {
2384 assert(is_singleref_comp_mode);
2385 if (compound_ref0_mode(mbmi->mode) == NEARMV ||
2386 compound_ref1_mode(mbmi->mode) == NEARMV) {
2387 nearmv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv;
2388 lower_mv_precision(&nearmv[0].as_mv, allow_hp);
2389 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07002390 }
Zoe Liu85b66462017-04-20 14:28:19 -07002391#endif // CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -07002392 }
Zoe Liu85b66462017-04-20 14:28:19 -07002393#else // !CONFIG_EXT_INTER
Yaowu Xuc27fc142016-08-22 16:08:15 -07002394 if (xd->ref_mv_count[ref_frame_type] > 1) {
2395 int ref_mv_idx = 1 + mbmi->ref_mv_idx;
2396 nearestmv[0] = xd->ref_mv_stack[ref_frame_type][0].this_mv;
2397 nearestmv[1] = xd->ref_mv_stack[ref_frame_type][0].comp_mv;
2398 nearmv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv;
2399 nearmv[1] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].comp_mv;
2400 }
2401#endif // CONFIG_EXT_INTER
2402 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07002403
Yue Chen19e7aa82016-11-30 14:05:39 -08002404#if !CONFIG_DUAL_FILTER && !CONFIG_WARPED_MOTION && !CONFIG_GLOBAL_MOTION
Angie Chiang9c4f8952016-11-21 11:13:19 -08002405 read_mb_interp_filter(cm, xd, mbmi, r);
Angie Chiang1733f6b2017-01-05 09:52:20 -08002406#endif // !CONFIG_DUAL_FILTER && !CONFIG_WARPED_MOTION
Yaowu Xuc27fc142016-08-22 16:08:15 -07002407
Jingning Han5cfa6712016-12-14 09:53:38 -08002408 if (bsize < BLOCK_8X8 && !unify_bsize) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07002409 const int num_4x4_w = 1 << xd->bmode_blocks_wl;
2410 const int num_4x4_h = 1 << xd->bmode_blocks_hl;
2411 int idx, idy;
2412 PREDICTION_MODE b_mode;
2413 int_mv nearest_sub8x8[2], near_sub8x8[2];
2414#if CONFIG_EXT_INTER
2415 int_mv ref_mv[2][2];
2416#endif // CONFIG_EXT_INTER
2417 for (idy = 0; idy < 2; idy += num_4x4_h) {
2418 for (idx = 0; idx < 2; idx += num_4x4_w) {
2419 int_mv block[2];
2420 const int j = idy * 2 + idx;
2421 int_mv ref_mv_s8[2];
Yaowu Xuc27fc142016-08-22 16:08:15 -07002422#if CONFIG_EXT_INTER
2423 if (!is_compound)
2424#endif // CONFIG_EXT_INTER
Yaowu Xuf883b422016-08-30 14:01:10 -07002425 mode_ctx = av1_mode_context_analyzer(inter_mode_ctx, mbmi->ref_frame,
2426 bsize, j);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002427#if CONFIG_EXT_INTER
2428 if (is_compound)
2429 b_mode = read_inter_compound_mode(cm, xd, r, mode_ctx);
2430 else
2431#endif // CONFIG_EXT_INTER
Zoe Liu7f24e1b2017-03-17 17:42:05 -07002432 b_mode = read_inter_mode(ec_ctx, xd, r, mode_ctx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002433
2434#if CONFIG_EXT_INTER
Yaowu Xuc27fc142016-08-22 16:08:15 -07002435 if (b_mode != ZEROMV && b_mode != ZERO_ZEROMV) {
2436#else
2437 if (b_mode != ZEROMV) {
2438#endif // CONFIG_EXT_INTER
Yaowu Xuc27fc142016-08-22 16:08:15 -07002439 CANDIDATE_MV ref_mv_stack[2][MAX_REF_MV_STACK_SIZE];
2440 uint8_t ref_mv_count[2];
Yaowu Xuc27fc142016-08-22 16:08:15 -07002441 for (ref = 0; ref < 1 + is_compound; ++ref)
2442#if CONFIG_EXT_INTER
2443 {
2444 int_mv mv_ref_list[MAX_MV_REF_CANDIDATES];
Yaowu Xu531d6af2017-03-07 17:48:52 -08002445 av1_update_mv_context(cm, xd, mi, mbmi->ref_frame[ref], mv_ref_list,
2446 j, mi_row, mi_col, NULL);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002447#endif // CONFIG_EXT_INTER
Yaowu Xuf883b422016-08-30 14:01:10 -07002448 av1_append_sub8x8_mvs_for_idx(cm, xd, j, ref, mi_row, mi_col,
Yaowu Xuf883b422016-08-30 14:01:10 -07002449 ref_mv_stack[ref], &ref_mv_count[ref],
Yaowu Xuc27fc142016-08-22 16:08:15 -07002450#if CONFIG_EXT_INTER
Yaowu Xuf883b422016-08-30 14:01:10 -07002451 mv_ref_list,
Yaowu Xuc27fc142016-08-22 16:08:15 -07002452#endif // CONFIG_EXT_INTER
Yaowu Xuf883b422016-08-30 14:01:10 -07002453 &nearest_sub8x8[ref],
2454 &near_sub8x8[ref]);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002455#if CONFIG_EXT_INTER
2456 if (have_newmv_in_inter_mode(b_mode)) {
2457 mv_ref_list[0].as_int = nearest_sub8x8[ref].as_int;
2458 mv_ref_list[1].as_int = near_sub8x8[ref].as_int;
Yaowu Xuf883b422016-08-30 14:01:10 -07002459 av1_find_best_ref_mvs(allow_hp, mv_ref_list, &ref_mv[0][ref],
2460 &ref_mv[1][ref]);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002461 }
2462 }
2463#endif // CONFIG_EXT_INTER
2464 }
2465
2466 for (ref = 0; ref < 1 + is_compound && b_mode != ZEROMV; ++ref) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07002467 ref_mv_s8[ref] = nearest_sub8x8[ref];
2468 lower_mv_precision(&ref_mv_s8[ref].as_mv, allow_hp);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002469 }
2470#if CONFIG_EXT_INTER
2471 (void)ref_mv_s8;
2472#endif
2473
Jingning Han5c60cdf2016-09-30 09:37:46 -07002474 if (!assign_mv(cm, xd, b_mode, mbmi->ref_frame, j, block,
Yaowu Xuc27fc142016-08-22 16:08:15 -07002475#if CONFIG_EXT_INTER
Zoe Liu7f24e1b2017-03-17 17:42:05 -07002476 ref_mv[0],
2477#else // !CONFIG_EXT_INTER
Yaowu Xuc27fc142016-08-22 16:08:15 -07002478 ref_mv_s8,
2479#endif // CONFIG_EXT_INTER
David Barker45390c12017-02-20 14:44:40 +00002480 nearest_sub8x8, near_sub8x8, mi_row, mi_col, is_compound,
2481 allow_hp, r)) {
Angie Chiangd0916d92017-03-10 17:54:18 -08002482 aom_merge_corrupted_flag(&xd->corrupted, 1);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002483 break;
2484 };
2485
2486 mi->bmi[j].as_mv[0].as_int = block[0].as_int;
Sarah Parkerd7fa8542016-10-11 11:51:59 -07002487 mi->bmi[j].as_mode = b_mode;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002488 if (is_compound) mi->bmi[j].as_mv[1].as_int = block[1].as_int;
2489
2490 if (num_4x4_h == 2) mi->bmi[j + 2] = mi->bmi[j];
2491 if (num_4x4_w == 2) mi->bmi[j + 1] = mi->bmi[j];
2492 }
2493 }
2494
Yaowu Xuf5bbbfa2016-09-26 09:13:38 -07002495 mbmi->pred_mv[0].as_int = mi->bmi[3].pred_mv[0].as_int;
2496 mbmi->pred_mv[1].as_int = mi->bmi[3].pred_mv[1].as_int;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002497 mi->mbmi.mode = b_mode;
2498
2499 mbmi->mv[0].as_int = mi->bmi[3].as_mv[0].as_int;
2500 mbmi->mv[1].as_int = mi->bmi[3].as_mv[1].as_int;
2501 } else {
Yaowu Xuc27fc142016-08-22 16:08:15 -07002502 int_mv ref_mv[2];
2503 ref_mv[0] = nearestmv[0];
2504 ref_mv[1] = nearestmv[1];
2505
David Barker404b2e82017-03-27 13:07:47 +01002506#if CONFIG_EXT_INTER
David Barker3dfba992017-04-03 16:10:09 +01002507 if (is_compound) {
David Barker3dfba992017-04-03 16:10:09 +01002508 int ref_mv_idx = mbmi->ref_mv_idx;
2509 // Special case: NEAR_NEWMV and NEW_NEARMV modes use
2510 // 1 + mbmi->ref_mv_idx (like NEARMV) instead of
2511 // mbmi->ref_mv_idx (like NEWMV)
2512 if (mbmi->mode == NEAR_NEWMV || mbmi->mode == NEW_NEARMV)
2513 ref_mv_idx = 1 + mbmi->ref_mv_idx;
David Barker3dfba992017-04-03 16:10:09 +01002514
2515 if (compound_ref0_mode(mbmi->mode) == NEWMV) {
David Barker404b2e82017-03-27 13:07:47 +01002516 uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
2517 if (xd->ref_mv_count[ref_frame_type] > 1) {
David Barker3dfba992017-04-03 16:10:09 +01002518 ref_mv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv;
Jingning Han1b5bd002017-04-20 08:48:30 -07002519 clamp_mv_ref(&ref_mv[0].as_mv, xd->n8_w << MI_SIZE_LOG2,
David Barker404b2e82017-03-27 13:07:47 +01002520 xd->n8_h << MI_SIZE_LOG2, xd);
2521 }
David Barker3dfba992017-04-03 16:10:09 +01002522 nearestmv[0] = ref_mv[0];
David Barker404b2e82017-03-27 13:07:47 +01002523 }
David Barker3dfba992017-04-03 16:10:09 +01002524 if (compound_ref1_mode(mbmi->mode) == NEWMV) {
David Barker3dfba992017-04-03 16:10:09 +01002525 uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
2526 if (xd->ref_mv_count[ref_frame_type] > 1) {
2527 ref_mv[1] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].comp_mv;
Jingning Han1b5bd002017-04-20 08:48:30 -07002528 clamp_mv_ref(&ref_mv[1].as_mv, xd->n8_w << MI_SIZE_LOG2,
David Barker3dfba992017-04-03 16:10:09 +01002529 xd->n8_h << MI_SIZE_LOG2, xd);
2530 }
David Barker3dfba992017-04-03 16:10:09 +01002531 nearestmv[1] = ref_mv[1];
2532 }
Zoe Liu85b66462017-04-20 14:28:19 -07002533#if CONFIG_COMPOUND_SINGLEREF
2534 } else if (is_singleref_comp_mode) {
2535 int ref_mv_idx = mbmi->ref_mv_idx;
2536 // Special case: SR_NEAR_NEWMV use 1 + mbmi->ref_mv_idx (like NEARMV)
2537 // instead of mbmi->ref_mv_idx (like NEWMV)
2538 if (mbmi->mode == SR_NEAR_NEWMV) ref_mv_idx = 1 + mbmi->ref_mv_idx;
2539
2540 if (compound_ref0_mode(mbmi->mode) == NEWMV ||
2541 compound_ref1_mode(mbmi->mode) == NEWMV) {
2542 uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
2543 if (xd->ref_mv_count[ref_frame_type] > 1) {
2544 ref_mv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv;
2545 clamp_mv_ref(&ref_mv[0].as_mv, xd->n8_w << MI_SIZE_LOG2,
2546 xd->n8_h << MI_SIZE_LOG2, xd);
2547 }
2548 // TODO(zoeliu): To further investigate why this would not cause a
2549 // mismatch for the mode of SR_NEAREST_NEWMV.
2550 nearestmv[0] = ref_mv[0];
2551 }
2552#endif // CONFIG_COMPOUND_SINGLEREF
David Barker3dfba992017-04-03 16:10:09 +01002553 } else {
2554#endif // CONFIG_EXT_INTER
2555 if (mbmi->mode == NEWMV) {
2556 for (ref = 0; ref < 1 + is_compound; ++ref) {
David Barker3dfba992017-04-03 16:10:09 +01002557 uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
2558 if (xd->ref_mv_count[ref_frame_type] > 1) {
2559 ref_mv[ref] =
2560 (ref == 0)
2561 ? xd->ref_mv_stack[ref_frame_type][mbmi->ref_mv_idx].this_mv
2562 : xd->ref_mv_stack[ref_frame_type][mbmi->ref_mv_idx]
2563 .comp_mv;
2564 clamp_mv_ref(&ref_mv[ref].as_mv, xd->n8_w << MI_SIZE_LOG2,
2565 xd->n8_h << MI_SIZE_LOG2, xd);
2566 }
David Barker3dfba992017-04-03 16:10:09 +01002567 nearestmv[ref] = ref_mv[ref];
2568 }
2569 }
2570#if CONFIG_EXT_INTER
Yaowu Xuc27fc142016-08-22 16:08:15 -07002571 }
David Barker3dfba992017-04-03 16:10:09 +01002572#endif // CONFIG_EXT_INTER
Yaowu Xuc27fc142016-08-22 16:08:15 -07002573
Angie Chiangd0916d92017-03-10 17:54:18 -08002574 int mv_corrupted_flag =
Zoe Liu7f24e1b2017-03-17 17:42:05 -07002575 !assign_mv(cm, xd, mbmi->mode, mbmi->ref_frame, 0, mbmi->mv, ref_mv,
David Barker45390c12017-02-20 14:44:40 +00002576 nearestmv, nearmv, mi_row, mi_col, is_compound, allow_hp, r);
Angie Chiangd0916d92017-03-10 17:54:18 -08002577 aom_merge_corrupted_flag(&xd->corrupted, mv_corrupted_flag);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002578 }
2579
Yue Chen4d26acb2017-05-01 12:28:34 -07002580#if CONFIG_EXT_INTER && CONFIG_INTERINTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -07002581 mbmi->use_wedge_interintra = 0;
2582 if (cm->reference_mode != COMPOUND_REFERENCE &&
2583#if CONFIG_SUPERTX
2584 !supertx_enabled &&
2585#endif
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07002586 cm->allow_interintra_compound && is_interintra_allowed(mbmi)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07002587 const int bsize_group = size_group_lookup[bsize];
Thomas Daviescff91712017-07-07 11:49:55 +01002588#if CONFIG_NEW_MULTISYMBOL
2589 const int interintra =
2590 aom_read_symbol(r, ec_ctx->interintra_cdf[bsize_group], 2, ACCT_STR);
2591#else
Michael Bebenita6048d052016-08-25 14:40:54 -07002592 const int interintra =
2593 aom_read(r, cm->fc->interintra_prob[bsize_group], ACCT_STR);
Thomas Daviescff91712017-07-07 11:49:55 +01002594#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002595 if (xd->counts) xd->counts->interintra[bsize_group][interintra]++;
Emil Keyder01770b32017-01-20 18:03:11 -05002596 assert(mbmi->ref_frame[1] == NONE_FRAME);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002597 if (interintra) {
2598 const INTERINTRA_MODE interintra_mode =
2599 read_interintra_mode(cm, xd, r, bsize_group);
2600 mbmi->ref_frame[1] = INTRA_FRAME;
2601 mbmi->interintra_mode = interintra_mode;
2602#if CONFIG_EXT_INTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -07002603 mbmi->angle_delta[0] = 0;
2604 mbmi->angle_delta[1] = 0;
hui sueda3d762016-12-06 16:58:23 -08002605#if CONFIG_INTRA_INTERP
Yaowu Xuc27fc142016-08-22 16:08:15 -07002606 mbmi->intra_filter = INTRA_FILTER_LINEAR;
hui sueda3d762016-12-06 16:58:23 -08002607#endif // CONFIG_INTRA_INTERP
Yaowu Xuc27fc142016-08-22 16:08:15 -07002608#endif // CONFIG_EXT_INTRA
hui su5db97432016-10-14 16:10:14 -07002609#if CONFIG_FILTER_INTRA
2610 mbmi->filter_intra_mode_info.use_filter_intra_mode[0] = 0;
2611 mbmi->filter_intra_mode_info.use_filter_intra_mode[1] = 0;
2612#endif // CONFIG_FILTER_INTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -07002613 if (is_interintra_wedge_used(bsize)) {
Thomas Daviescff91712017-07-07 11:49:55 +01002614#if CONFIG_NEW_MULTISYMBOL
2615 mbmi->use_wedge_interintra = aom_read_symbol(
2616 r, ec_ctx->wedge_interintra_cdf[bsize], 2, ACCT_STR);
2617#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07002618 mbmi->use_wedge_interintra =
Michael Bebenita6048d052016-08-25 14:40:54 -07002619 aom_read(r, cm->fc->wedge_interintra_prob[bsize], ACCT_STR);
Thomas Daviescff91712017-07-07 11:49:55 +01002620#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002621 if (xd->counts)
2622 xd->counts->wedge_interintra[bsize][mbmi->use_wedge_interintra]++;
2623 if (mbmi->use_wedge_interintra) {
2624 mbmi->interintra_wedge_index =
Michael Bebenita6048d052016-08-25 14:40:54 -07002625 aom_read_literal(r, get_wedge_bits_lookup(bsize), ACCT_STR);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002626 mbmi->interintra_wedge_sign = 0;
2627 }
2628 }
2629 }
2630 }
Yue Chen4d26acb2017-05-01 12:28:34 -07002631#endif // CONFIG_EXT_INTER && CONFIG_INTERINTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -07002632
Yue Chen52c51732017-07-11 15:08:30 -07002633#if CONFIG_WARPED_MOTION
2634 for (ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) {
2635 const MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref];
2636 RefBuffer *ref_buf = &cm->frame_refs[frame - LAST_FRAME];
2637
2638 xd->block_refs[ref] = ref_buf;
2639 }
2640#endif
2641
Yue Chencb60b182016-10-13 15:18:22 -07002642#if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
2643 mbmi->motion_mode = SIMPLE_TRANSLATION;
Yue Chen69f18e12016-09-08 14:48:15 -07002644#if CONFIG_WARPED_MOTION
2645 if (mbmi->sb_type >= BLOCK_8X8 && !has_second_ref(mbmi))
Yunqing Wang1bc82862017-06-28 15:49:48 -07002646#if WARPED_MOTION_SORT_SAMPLES
2647 mbmi->num_proj_ref[0] =
2648 findSamples(cm, xd, mi_row, mi_col, pts, pts_inref, pts_mv);
2649#else
Yue Chen69f18e12016-09-08 14:48:15 -07002650 mbmi->num_proj_ref[0] = findSamples(cm, xd, mi_row, mi_col, pts, pts_inref);
Yunqing Wang1bc82862017-06-28 15:49:48 -07002651#endif // WARPED_MOTION_SORT_SAMPLES
Yue Chen69f18e12016-09-08 14:48:15 -07002652#endif // CONFIG_WARPED_MOTION
Yue Chen5329a2b2017-02-28 17:33:00 +08002653#if CONFIG_MOTION_VAR
2654 av1_count_overlappable_neighbors(cm, xd, mi_row, mi_col);
2655#endif
Yue Chen69f18e12016-09-08 14:48:15 -07002656
Yaowu Xuc27fc142016-08-22 16:08:15 -07002657#if CONFIG_SUPERTX
Yue Chen69f18e12016-09-08 14:48:15 -07002658 if (!supertx_enabled) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07002659#endif // CONFIG_SUPERTX
2660#if CONFIG_EXT_INTER
2661 if (mbmi->ref_frame[1] != INTRA_FRAME)
2662#endif // CONFIG_EXT_INTER
Sarah Parker19234cc2017-03-10 16:43:25 -08002663 mbmi->motion_mode = read_motion_mode(cm, xd, mi, r);
Wei-Ting Lin85a8f702017-06-22 13:55:15 -07002664
2665#if CONFIG_NCOBMC_ADAPT_WEIGHT
Wei-Ting Linca710d62017-07-13 11:41:02 -07002666 read_ncobmc_mode(xd, mi, mbmi->ncobmc_mode, r);
Wei-Ting Lin85a8f702017-06-22 13:55:15 -07002667#endif
2668
Zoe Liu85b66462017-04-20 14:28:19 -07002669#if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
2670 if (is_singleref_comp_mode) assert(mbmi->motion_mode == SIMPLE_TRANSLATION);
2671#endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
Yue Chen69f18e12016-09-08 14:48:15 -07002672#if CONFIG_WARPED_MOTION
2673 if (mbmi->motion_mode == WARPED_CAUSAL) {
2674 mbmi->wm_params[0].wmtype = DEFAULT_WMTYPE;
Yunqing Wang1bc82862017-06-28 15:49:48 -07002675
2676#if WARPED_MOTION_SORT_SAMPLES
2677 if (mbmi->num_proj_ref[0] > 1)
2678 mbmi->num_proj_ref[0] = sortSamples(pts_mv, &mbmi->mv[0].as_mv, pts,
2679 pts_inref, mbmi->num_proj_ref[0]);
2680#endif // WARPED_MOTION_SORT_SAMPLES
2681
Debargha Mukherjee0df711f2017-05-02 16:00:20 -07002682 if (find_projection(mbmi->num_proj_ref[0], pts, pts_inref, bsize,
2683 mbmi->mv[0].as_mv.row, mbmi->mv[0].as_mv.col,
2684 &mbmi->wm_params[0], mi_row, mi_col)) {
Yunqing Wang8657ad72017-06-20 14:46:08 -07002685 aom_internal_error(&cm->error, AOM_CODEC_ERROR, "Invalid Warped Model");
Debargha Mukherjee0df711f2017-05-02 16:00:20 -07002686 }
Yue Chen69f18e12016-09-08 14:48:15 -07002687 }
2688#endif // CONFIG_WARPED_MOTION
2689#if CONFIG_SUPERTX
2690 }
2691#endif // CONFIG_SUPERTX
Yue Chencb60b182016-10-13 15:18:22 -07002692#endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
Yaowu Xuc27fc142016-08-22 16:08:15 -07002693
2694#if CONFIG_EXT_INTER
Sarah Parker2d0e9b72017-05-04 01:34:16 +00002695 mbmi->interinter_compound_type = COMPOUND_AVERAGE;
Zoe Liu85b66462017-04-20 14:28:19 -07002696 if (
2697#if CONFIG_COMPOUND_SINGLEREF
Zoe Liu0c634c72017-06-19 07:06:28 -07002698 is_inter_anyref_comp_mode(mbmi->mode)
Zoe Liu85b66462017-04-20 14:28:19 -07002699#else // !CONFIG_COMPOUND_SINGLEREF
2700 cm->reference_mode != SINGLE_REFERENCE &&
Sarah Parker6fdc8532016-11-16 17:47:13 -08002701 is_inter_compound_mode(mbmi->mode)
Zoe Liu85b66462017-04-20 14:28:19 -07002702#endif // CONFIG_COMPOUND_SINGLEREF
Yue Chencb60b182016-10-13 15:18:22 -07002703#if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
Sarah Parker6fdc8532016-11-16 17:47:13 -08002704 && mbmi->motion_mode == SIMPLE_TRANSLATION
Yue Chencb60b182016-10-13 15:18:22 -07002705#endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
Sarah Parker6fdc8532016-11-16 17:47:13 -08002706 ) {
Sarah Parker42d96102017-01-31 21:05:27 -08002707 if (is_any_masked_compound_used(bsize)) {
Debargha Mukherjeec5f735f2017-04-26 03:25:28 +00002708#if CONFIG_COMPOUND_SEGMENT || CONFIG_WEDGE
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07002709 if (cm->allow_masked_compound) {
Thomas Daviesd8dac222017-06-27 11:23:15 +01002710 mbmi->interinter_compound_type = aom_read_symbol(
2711 r, ec_ctx->compound_type_cdf[bsize], COMPOUND_TYPES, ACCT_STR);
Debargha Mukherjeec5f735f2017-04-26 03:25:28 +00002712#if CONFIG_WEDGE
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07002713 if (mbmi->interinter_compound_type == COMPOUND_WEDGE) {
2714 mbmi->wedge_index =
2715 aom_read_literal(r, get_wedge_bits_lookup(bsize), ACCT_STR);
2716 mbmi->wedge_sign = aom_read_bit(r, ACCT_STR);
2717 }
Debargha Mukherjeec5f735f2017-04-26 03:25:28 +00002718#endif // CONFIG_WEDGE
Sarah Parker42d96102017-01-31 21:05:27 -08002719#if CONFIG_COMPOUND_SEGMENT
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07002720 if (mbmi->interinter_compound_type == COMPOUND_SEG) {
2721 mbmi->mask_type = aom_read_literal(r, MAX_SEG_MASK_BITS, ACCT_STR);
2722 }
Sarah Parker42d96102017-01-31 21:05:27 -08002723#endif // CONFIG_COMPOUND_SEGMENT
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07002724 }
2725#endif // CONFIG_COMPOUND_SEGMENT || CONFIG_WEDGE
Sarah Parker42d96102017-01-31 21:05:27 -08002726 } else {
Sarah Parker2d0e9b72017-05-04 01:34:16 +00002727 mbmi->interinter_compound_type = COMPOUND_AVERAGE;
Sarah Parker42d96102017-01-31 21:05:27 -08002728 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07002729 if (xd->counts)
Sarah Parker2d0e9b72017-05-04 01:34:16 +00002730 xd->counts->compound_interinter[bsize][mbmi->interinter_compound_type]++;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002731 }
2732#endif // CONFIG_EXT_INTER
2733
Yue Chen19e7aa82016-11-30 14:05:39 -08002734#if CONFIG_DUAL_FILTER || CONFIG_WARPED_MOTION || CONFIG_GLOBAL_MOTION
Debargha Mukherjee0df711f2017-05-02 16:00:20 -07002735 read_mb_interp_filter(cm, xd, mbmi, r);
Angie Chiang1733f6b2017-01-05 09:52:20 -08002736#endif // CONFIG_DUAL_FILTER || CONFIG_WARPED_MOTION
Zoe Liu85b66462017-04-20 14:28:19 -07002737
Di Chen56586622017-06-09 13:49:44 -07002738#if DEC_MISMATCH_DEBUG
2739 // NOTE(zoeliu): For debug
Zoe Liuf9333f52017-07-03 10:52:01 -07002740 dec_dump_logs(cm, mi, xd, mi_row, mi_col, inter_mode_ctx, mode_ctx);
Di Chen56586622017-06-09 13:49:44 -07002741#endif // DEC_MISMATCH_DEBUG
Yaowu Xuc27fc142016-08-22 16:08:15 -07002742}
2743
Yaowu Xuf883b422016-08-30 14:01:10 -07002744static void read_inter_frame_mode_info(AV1Decoder *const pbi,
Yaowu Xuc27fc142016-08-22 16:08:15 -07002745 MACROBLOCKD *const xd,
2746#if CONFIG_SUPERTX
2747 int supertx_enabled,
2748#endif // CONFIG_SUPERTX
Yaowu Xuf883b422016-08-30 14:01:10 -07002749 int mi_row, int mi_col, aom_reader *r) {
2750 AV1_COMMON *const cm = &pbi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002751 MODE_INFO *const mi = xd->mi[0];
2752 MB_MODE_INFO *const mbmi = &mi->mbmi;
2753 int inter_block = 1;
2754#if CONFIG_VAR_TX
2755 BLOCK_SIZE bsize = mbmi->sb_type;
2756#endif // CONFIG_VAR_TX
2757
2758 mbmi->mv[0].as_int = 0;
2759 mbmi->mv[1].as_int = 0;
2760 mbmi->segment_id = read_inter_segment_id(cm, xd, mi_row, mi_col, r);
2761#if CONFIG_SUPERTX
David Barker3aec8d62017-01-31 14:55:32 +00002762 if (!supertx_enabled)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002763#endif // CONFIG_SUPERTX
2764 mbmi->skip = read_skip(cm, xd, mbmi->segment_id, r);
David Barker3aec8d62017-01-31 14:55:32 +00002765
Arild Fuldseth07441162016-08-15 15:07:52 +02002766#if CONFIG_DELTA_Q
David Barker3aec8d62017-01-31 14:55:32 +00002767 if (cm->delta_q_present_flag) {
2768 xd->current_qindex =
2769 xd->prev_qindex +
2770 read_delta_qindex(cm, xd, r, mbmi, mi_col, mi_row) * cm->delta_q_res;
Arild Fuldseth (arilfuld)54de7d62017-03-20 13:07:11 +01002771 /* Normative: Clamp to [1,MAXQ] to not interfere with lossless mode */
2772 xd->current_qindex = clamp(xd->current_qindex, 1, MAXQ);
David Barker3aec8d62017-01-31 14:55:32 +00002773 xd->prev_qindex = xd->current_qindex;
Fangwen Fu231fe422017-04-24 17:52:29 -07002774#if CONFIG_EXT_DELTA_Q
2775 if (cm->delta_lf_present_flag) {
2776 mbmi->current_delta_lf_from_base = xd->current_delta_lf_from_base =
2777 xd->prev_delta_lf_from_base +
2778 read_delta_lflevel(cm, xd, r, mbmi, mi_col, mi_row) *
2779 cm->delta_lf_res;
2780 xd->prev_delta_lf_from_base = xd->current_delta_lf_from_base;
2781 }
2782#endif
David Barker3aec8d62017-01-31 14:55:32 +00002783 }
Arild Fuldseth07441162016-08-15 15:07:52 +02002784#endif
David Barker3aec8d62017-01-31 14:55:32 +00002785
2786#if CONFIG_SUPERTX
2787 if (!supertx_enabled) {
2788#endif // CONFIG_SUPERTX
Yaowu Xuc27fc142016-08-22 16:08:15 -07002789 inter_block = read_is_inter_block(cm, xd, mbmi->segment_id, r);
2790
2791#if CONFIG_VAR_TX
Jingning Han331662e2017-05-30 17:03:32 -07002792 xd->above_txfm_context =
2793 cm->above_txfm_context + (mi_col << TX_UNIT_WIDE_LOG2);
2794 xd->left_txfm_context = xd->left_txfm_context_buffer +
2795 ((mi_row & MAX_MIB_MASK) << TX_UNIT_HIGH_LOG2);
Jingning Han581d1692017-01-05 16:03:54 -08002796
2797 if (cm->tx_mode == TX_MODE_SELECT &&
2798#if CONFIG_CB4X4
Jingning Han3daa4fd2017-01-20 10:33:50 -08002799 bsize > BLOCK_4X4 &&
Jingning Han581d1692017-01-05 16:03:54 -08002800#else
2801 bsize >= BLOCK_8X8 &&
2802#endif
2803 !mbmi->skip && inter_block) {
Jingning Han70e5f3f2016-11-09 17:03:07 -08002804 const TX_SIZE max_tx_size = max_txsize_rect_lookup[bsize];
Jingning Hanf64062f2016-11-02 16:22:18 -07002805 const int bh = tx_size_high_unit[max_tx_size];
2806 const int bw = tx_size_wide_unit[max_tx_size];
Jingning Han65abc312016-10-27 13:04:21 -07002807 const int width = block_size_wide[bsize] >> tx_size_wide_log2[0];
2808 const int height = block_size_high[bsize] >> tx_size_wide_log2[0];
Yaowu Xuc27fc142016-08-22 16:08:15 -07002809 int idx, idy;
Yue Chena1e48dc2016-08-29 17:29:33 -07002810
Jingning Hanfe45b212016-11-22 10:30:23 -08002811 mbmi->min_tx_size = TX_SIZES_ALL;
2812 for (idy = 0; idy < height; idy += bh)
2813 for (idx = 0; idx < width; idx += bw)
2814 read_tx_size_vartx(cm, xd, mbmi, xd->counts, max_tx_size,
2815 height != width, idy, idx, r);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002816 } else {
Urvang Joshifeb925f2016-12-05 10:37:29 -08002817 mbmi->tx_size = read_tx_size(cm, xd, inter_block, !mbmi->skip, r);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002818
2819 if (inter_block) {
Jingning Han9ca05b72017-01-03 14:41:36 -08002820 const int width = block_size_wide[bsize] >> tx_size_wide_log2[0];
2821 const int height = block_size_high[bsize] >> tx_size_high_log2[0];
Yaowu Xuc27fc142016-08-22 16:08:15 -07002822 int idx, idy;
2823 for (idy = 0; idy < height; ++idy)
2824 for (idx = 0; idx < width; ++idx)
2825 mbmi->inter_tx_size[idy >> 1][idx >> 1] = mbmi->tx_size;
2826 }
Jingning Hane67b38a2016-11-04 10:30:00 -07002827 mbmi->min_tx_size = get_min_tx_size(mbmi->tx_size);
Jingning Han1b1dc932016-11-09 10:55:30 -08002828 set_txfm_ctxs(mbmi->tx_size, xd->n8_w, xd->n8_h, mbmi->skip, xd);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002829 }
2830#else
Urvang Joshifeb925f2016-12-05 10:37:29 -08002831 mbmi->tx_size = read_tx_size(cm, xd, inter_block, !mbmi->skip, r);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002832#endif // CONFIG_VAR_TX
2833#if CONFIG_SUPERTX
2834 }
2835#if CONFIG_VAR_TX
2836 else if (inter_block) {
2837 const int width = num_4x4_blocks_wide_lookup[bsize];
2838 const int height = num_4x4_blocks_high_lookup[bsize];
2839 int idx, idy;
2840 xd->mi[0]->mbmi.tx_size = xd->supertx_size;
2841 for (idy = 0; idy < height; ++idy)
2842 for (idx = 0; idx < width; ++idx)
2843 xd->mi[0]->mbmi.inter_tx_size[idy >> 1][idx >> 1] = xd->supertx_size;
2844 }
2845#endif // CONFIG_VAR_TX
2846#endif // CONFIG_SUPERTX
2847
2848 if (inter_block)
2849 read_inter_block_mode_info(pbi, xd,
David Barker491983d2016-11-10 13:22:17 +00002850#if (CONFIG_MOTION_VAR || CONFIG_EXT_INTER || CONFIG_WARPED_MOTION) && \
2851 CONFIG_SUPERTX
Yaowu Xuc27fc142016-08-22 16:08:15 -07002852
2853 mi, mi_row, mi_col, r, supertx_enabled);
2854#else
2855 mi, mi_row, mi_col, r);
Yue Chencb60b182016-10-13 15:18:22 -07002856#endif // CONFIG_MOTION_VAR && CONFIG_SUPERTX
Yaowu Xuc27fc142016-08-22 16:08:15 -07002857 else
Jingning Han36fe3202017-02-20 22:31:49 -08002858 read_intra_block_mode_info(cm, mi_row, mi_col, xd, mi, r);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002859
Angie Chiangcd9b03f2017-04-16 13:37:13 -07002860#if !CONFIG_TXK_SEL
Angie Chianga9f9a312017-04-13 16:40:43 -07002861 av1_read_tx_type(cm, xd,
Yaowu Xuc27fc142016-08-22 16:08:15 -07002862#if CONFIG_SUPERTX
Angie Chianga9f9a312017-04-13 16:40:43 -07002863 supertx_enabled,
Nathan E. Egge93878c42016-05-03 10:01:32 -04002864#endif
Angie Chianga9f9a312017-04-13 16:40:43 -07002865 r);
Angie Chiangcd9b03f2017-04-16 13:37:13 -07002866#endif // !CONFIG_TXK_SEL
Yaowu Xuc27fc142016-08-22 16:08:15 -07002867}
2868
Yaowu Xuf883b422016-08-30 14:01:10 -07002869void av1_read_mode_info(AV1Decoder *const pbi, MACROBLOCKD *xd,
Yaowu Xuc27fc142016-08-22 16:08:15 -07002870#if CONFIG_SUPERTX
Yaowu Xuf883b422016-08-30 14:01:10 -07002871 int supertx_enabled,
Yaowu Xuc27fc142016-08-22 16:08:15 -07002872#endif // CONFIG_SUPERTX
Yaowu Xuf883b422016-08-30 14:01:10 -07002873 int mi_row, int mi_col, aom_reader *r, int x_mis,
2874 int y_mis) {
2875 AV1_COMMON *const cm = &pbi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002876 MODE_INFO *const mi = xd->mi[0];
2877 MV_REF *frame_mvs = cm->cur_frame->mvs + mi_row * cm->mi_cols + mi_col;
2878 int w, h;
2879
Alex Converse28744302017-04-13 14:46:22 -07002880#if CONFIG_INTRABC
2881 mi->mbmi.use_intrabc = 0;
2882#endif // CONFIG_INTRABC
2883
Yaowu Xuc27fc142016-08-22 16:08:15 -07002884 if (frame_is_intra_only(cm)) {
2885 read_intra_frame_mode_info(cm, xd, mi_row, mi_col, r);
Yaowu Xuc27fc142016-08-22 16:08:15 -07002886 for (h = 0; h < y_mis; ++h) {
2887 MV_REF *const frame_mv = frame_mvs + h * cm->mi_cols;
2888 for (w = 0; w < x_mis; ++w) {
2889 MV_REF *const mv = frame_mv + w;
Emil Keyder01770b32017-01-20 18:03:11 -05002890 mv->ref_frame[0] = NONE_FRAME;
2891 mv->ref_frame[1] = NONE_FRAME;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002892 }
2893 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07002894 } else {
2895 read_inter_frame_mode_info(pbi, xd,
2896#if CONFIG_SUPERTX
2897 supertx_enabled,
2898#endif // CONFIG_SUPERTX
2899 mi_row, mi_col, r);
2900 for (h = 0; h < y_mis; ++h) {
2901 MV_REF *const frame_mv = frame_mvs + h * cm->mi_cols;
2902 for (w = 0; w < x_mis; ++w) {
2903 MV_REF *const mv = frame_mv + w;
2904 mv->ref_frame[0] = mi->mbmi.ref_frame[0];
2905 mv->ref_frame[1] = mi->mbmi.ref_frame[1];
2906 mv->mv[0].as_int = mi->mbmi.mv[0].as_int;
2907 mv->mv[1].as_int = mi->mbmi.mv[1].as_int;
Yaowu Xu4306b6e2016-09-27 12:55:32 -07002908 mv->pred_mv[0].as_int = mi->mbmi.pred_mv[0].as_int;
2909 mv->pred_mv[1].as_int = mi->mbmi.pred_mv[1].as_int;
Yaowu Xuc27fc142016-08-22 16:08:15 -07002910 }
2911 }
2912 }
2913}