Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <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 su | 45dc597 | 2016-12-08 17:42:50 -0800 | [diff] [blame] | 21 | #if CONFIG_EXT_INTRA |
| 22 | #include "av1/common/reconintra.h" |
| 23 | #endif // CONFIG_EXT_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 24 | #include "av1/common/seg_common.h" |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 25 | #if CONFIG_WARPED_MOTION |
| 26 | #include "av1/common/warped_motion.h" |
| 27 | #endif // CONFIG_WARPED_MOTION |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 28 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 29 | #include "av1/decoder/decodeframe.h" |
Jingning Han | 1aab818 | 2016-06-03 11:09:06 -0700 | [diff] [blame] | 30 | #include "av1/decoder/decodemv.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 31 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 32 | #include "aom_dsp/aom_dsp_common.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 33 | |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 34 | #define ACCT_STR __func__ |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 35 | |
Di Chen | 5658662 | 2017-06-09 13:49:44 -0700 | [diff] [blame] | 36 | #define DEC_MISMATCH_DEBUG 0 |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 37 | |
Thomas | 9ac5508 | 2016-09-23 18:04:17 +0100 | [diff] [blame] | 38 | static PREDICTION_MODE read_intra_mode(aom_reader *r, aom_cdf_prob *cdf) { |
Nathan E. Egge | 3ef926e | 2016-09-07 18:20:41 -0400 | [diff] [blame] | 39 | return (PREDICTION_MODE) |
| 40 | av1_intra_mode_inv[aom_read_symbol(r, cdf, INTRA_MODES, ACCT_STR)]; |
| 41 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 42 | |
Thomas Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 43 | #if CONFIG_DELTA_Q |
| 44 | static 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 Davies | d6ee8a8 | 2017-03-02 14:42:50 +0000 | [diff] [blame] | 52 | int rem_bits, thr; |
| 53 | int i, smallval; |
Thomas Davies | d6ee8a8 | 2017-03-02 14:42:50 +0000 | [diff] [blame] | 54 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
| 55 | (void)cm; |
Thomas Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 56 | |
Alex Converse | 68abef8 | 2017-03-23 14:50:33 -0700 | [diff] [blame] | 57 | if ((bsize != BLOCK_LARGEST || mbmi->skip == 0) && read_delta_q_flag) { |
Thomas Davies | d6ee8a8 | 2017-03-02 14:42:50 +0000 | [diff] [blame] | 58 | abs = aom_read_symbol(r, ec_ctx->delta_q_cdf, DELTA_Q_PROBS + 1, ACCT_STR); |
Thomas Davies | d6ee8a8 | 2017-03-02 14:42:50 +0000 | [diff] [blame] | 59 | 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 Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 66 | 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 Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 81 | #if CONFIG_EXT_DELTA_Q |
| 82 | static 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 Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 93 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
| 94 | (void)cm; |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 95 | |
| 96 | if ((bsize != BLOCK_64X64 || mbmi->skip == 0) && read_delta_lf_flag) { |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 97 | abs = |
| 98 | aom_read_symbol(r, ec_ctx->delta_lf_cdf, DELTA_LF_PROBS + 1, ACCT_STR); |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 99 | 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 Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 121 | #endif |
| 122 | |
Nathan E. Egge | a1f80e3 | 2017-05-23 11:52:32 -0400 | [diff] [blame] | 123 | static PREDICTION_MODE read_intra_mode_y(FRAME_CONTEXT *ec_ctx, MACROBLOCKD *xd, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 124 | aom_reader *r, int size_group) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 125 | const PREDICTION_MODE y_mode = |
Thomas Davies | 1bfb5ed | 2017-01-11 15:28:11 +0000 | [diff] [blame] | 126 | read_intra_mode(r, ec_ctx->y_mode_cdf[size_group]); |
Nathan E. Egge | 6bdc40f | 2017-06-18 19:02:23 -0400 | [diff] [blame] | 127 | #if CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 128 | FRAME_COUNTS *counts = xd->counts; |
| 129 | if (counts) ++counts->y_mode[size_group][y_mode]; |
Nathan E. Egge | 5bb3a74 | 2017-06-30 12:47:43 -0400 | [diff] [blame] | 130 | #else |
| 131 | /* TODO(negge): Can we remove this parameter? */ |
| 132 | (void)xd; |
Nathan E. Egge | 6bdc40f | 2017-06-18 19:02:23 -0400 | [diff] [blame] | 133 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 134 | return y_mode; |
| 135 | } |
| 136 | |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 137 | static UV_PREDICTION_MODE read_intra_mode_uv(FRAME_CONTEXT *ec_ctx, |
| 138 | MACROBLOCKD *xd, aom_reader *r, |
| 139 | PREDICTION_MODE y_mode) { |
| 140 | const UV_PREDICTION_MODE uv_mode = |
Luc Trudeau | 6e1cd78 | 2017-06-21 13:52:36 -0400 | [diff] [blame] | 141 | #if CONFIG_CFL |
| 142 | aom_read_symbol(r, ec_ctx->uv_mode_cdf[y_mode], UV_INTRA_MODES, ACCT_STR); |
| 143 | #else |
Thomas Davies | 1bfb5ed | 2017-01-11 15:28:11 +0000 | [diff] [blame] | 144 | read_intra_mode(r, ec_ctx->uv_mode_cdf[y_mode]); |
Luc Trudeau | 6e1cd78 | 2017-06-21 13:52:36 -0400 | [diff] [blame] | 145 | #endif // CONFIG_CFL |
| 146 | |
Nathan E. Egge | 6bdc40f | 2017-06-18 19:02:23 -0400 | [diff] [blame] | 147 | #if CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 148 | FRAME_COUNTS *counts = xd->counts; |
| 149 | if (counts) ++counts->uv_mode[y_mode][uv_mode]; |
Nathan E. Egge | 5bb3a74 | 2017-06-30 12:47:43 -0400 | [diff] [blame] | 150 | #else |
| 151 | /* TODO(negge): Can we remove this parameter? */ |
| 152 | (void)xd; |
Nathan E. Egge | 6bdc40f | 2017-06-18 19:02:23 -0400 | [diff] [blame] | 153 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 154 | return uv_mode; |
| 155 | } |
| 156 | |
Luc Trudeau | f533400 | 2017-04-25 12:21:26 -0400 | [diff] [blame] | 157 | #if CONFIG_CFL |
David Michael Barr | 2319866 | 2017-06-19 23:19:48 +0900 | [diff] [blame] | 158 | static int read_cfl_alphas(FRAME_CONTEXT *const ec_ctx, aom_reader *r, |
David Michael Barr | f6eaa15 | 2017-07-19 19:42:28 +0900 | [diff] [blame] | 159 | int *signs_out) { |
| 160 | const int joint_sign = |
| 161 | aom_read_symbol(r, ec_ctx->cfl_sign_cdf, CFL_JOINT_SIGNS, "cfl:signs"); |
| 162 | int idx = 0; |
| 163 | // Magnitudes are only coded for nonzero values |
| 164 | if (CFL_SIGN_U(joint_sign) != CFL_SIGN_ZERO) { |
| 165 | aom_cdf_prob *cdf_u = ec_ctx->cfl_alpha_cdf[CFL_CONTEXT_U(joint_sign)]; |
| 166 | idx = aom_read_symbol(r, cdf_u, CFL_ALPHABET_SIZE, "cfl:alpha_u") |
| 167 | << CFL_ALPHABET_SIZE_LOG2; |
| 168 | } |
| 169 | if (CFL_SIGN_V(joint_sign) != CFL_SIGN_ZERO) { |
| 170 | aom_cdf_prob *cdf_v = ec_ctx->cfl_alpha_cdf[CFL_CONTEXT_V(joint_sign)]; |
| 171 | idx += aom_read_symbol(r, cdf_v, CFL_ALPHABET_SIZE, "cfl:alpha_v"); |
| 172 | } |
| 173 | *signs_out = joint_sign; |
| 174 | return idx; |
Luc Trudeau | f533400 | 2017-04-25 12:21:26 -0400 | [diff] [blame] | 175 | } |
| 176 | #endif |
| 177 | |
Yue Chen | 4d26acb | 2017-05-01 12:28:34 -0700 | [diff] [blame] | 178 | #if CONFIG_EXT_INTER && CONFIG_INTERINTRA |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 179 | static INTERINTRA_MODE read_interintra_mode(AV1_COMMON *cm, MACROBLOCKD *xd, |
| 180 | aom_reader *r, int size_group) { |
Thomas Davies | 299ff04 | 2017-06-27 13:41:59 +0100 | [diff] [blame] | 181 | (void)cm; |
| 182 | const INTERINTRA_MODE ii_mode = (INTERINTRA_MODE)aom_read_symbol( |
| 183 | r, xd->tile_ctx->interintra_mode_cdf[size_group], INTERINTRA_MODES, |
| 184 | ACCT_STR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 185 | FRAME_COUNTS *counts = xd->counts; |
| 186 | if (counts) ++counts->interintra_mode[size_group][ii_mode]; |
| 187 | return ii_mode; |
| 188 | } |
Yue Chen | 4d26acb | 2017-05-01 12:28:34 -0700 | [diff] [blame] | 189 | #endif // CONFIG_EXT_INTER && CONFIG_INTERINTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 190 | |
Thomas Davies | 1de6c88 | 2017-01-11 17:47:49 +0000 | [diff] [blame] | 191 | static PREDICTION_MODE read_inter_mode(FRAME_CONTEXT *ec_ctx, MACROBLOCKD *xd, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 192 | aom_reader *r, int16_t ctx) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 193 | FRAME_COUNTS *counts = xd->counts; |
| 194 | int16_t mode_ctx = ctx & NEWMV_CTX_MASK; |
Thomas Davies | 149eda5 | 2017-06-12 18:11:55 +0100 | [diff] [blame] | 195 | int is_newmv, is_zeromv, is_refmv; |
| 196 | #if CONFIG_NEW_MULTISYMBOL |
| 197 | is_newmv = aom_read_symbol(r, ec_ctx->newmv_cdf[mode_ctx], 2, ACCT_STR) == 0; |
| 198 | #else |
| 199 | is_newmv = aom_read(r, ec_ctx->newmv_prob[mode_ctx], ACCT_STR) == 0; |
| 200 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 201 | |
Thomas Davies | 149eda5 | 2017-06-12 18:11:55 +0100 | [diff] [blame] | 202 | if (is_newmv) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 203 | if (counts) ++counts->newmv_mode[mode_ctx][0]; |
Zoe Liu | 7f24e1b | 2017-03-17 17:42:05 -0700 | [diff] [blame] | 204 | return NEWMV; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 205 | } |
| 206 | if (counts) ++counts->newmv_mode[mode_ctx][1]; |
| 207 | |
| 208 | if (ctx & (1 << ALL_ZERO_FLAG_OFFSET)) return ZEROMV; |
| 209 | |
| 210 | mode_ctx = (ctx >> ZEROMV_OFFSET) & ZEROMV_CTX_MASK; |
| 211 | |
Thomas Davies | 149eda5 | 2017-06-12 18:11:55 +0100 | [diff] [blame] | 212 | #if CONFIG_NEW_MULTISYMBOL |
| 213 | is_zeromv = |
| 214 | aom_read_symbol(r, ec_ctx->zeromv_cdf[mode_ctx], 2, ACCT_STR) == 0; |
| 215 | #else |
| 216 | is_zeromv = aom_read(r, ec_ctx->zeromv_prob[mode_ctx], ACCT_STR) == 0; |
| 217 | #endif |
| 218 | if (is_zeromv) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 219 | if (counts) ++counts->zeromv_mode[mode_ctx][0]; |
| 220 | return ZEROMV; |
| 221 | } |
| 222 | if (counts) ++counts->zeromv_mode[mode_ctx][1]; |
| 223 | |
| 224 | mode_ctx = (ctx >> REFMV_OFFSET) & REFMV_CTX_MASK; |
| 225 | |
| 226 | if (ctx & (1 << SKIP_NEARESTMV_OFFSET)) mode_ctx = 6; |
| 227 | if (ctx & (1 << SKIP_NEARMV_OFFSET)) mode_ctx = 7; |
| 228 | if (ctx & (1 << SKIP_NEARESTMV_SUB8X8_OFFSET)) mode_ctx = 8; |
| 229 | |
Thomas Davies | 149eda5 | 2017-06-12 18:11:55 +0100 | [diff] [blame] | 230 | #if CONFIG_NEW_MULTISYMBOL |
| 231 | is_refmv = aom_read_symbol(r, ec_ctx->refmv_cdf[mode_ctx], 2, ACCT_STR) == 0; |
| 232 | #else |
| 233 | is_refmv = aom_read(r, ec_ctx->refmv_prob[mode_ctx], ACCT_STR) == 0; |
| 234 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 235 | |
Thomas Davies | 149eda5 | 2017-06-12 18:11:55 +0100 | [diff] [blame] | 236 | if (is_refmv) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 237 | if (counts) ++counts->refmv_mode[mode_ctx][0]; |
| 238 | |
| 239 | return NEARESTMV; |
| 240 | } else { |
| 241 | if (counts) ++counts->refmv_mode[mode_ctx][1]; |
| 242 | return NEARMV; |
| 243 | } |
| 244 | |
| 245 | // Invalid prediction mode. |
| 246 | assert(0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Thomas Davies | 149eda5 | 2017-06-12 18:11:55 +0100 | [diff] [blame] | 249 | static void read_drl_idx(FRAME_CONTEXT *ec_ctx, MACROBLOCKD *xd, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 250 | MB_MODE_INFO *mbmi, aom_reader *r) { |
| 251 | uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 252 | mbmi->ref_mv_idx = 0; |
| 253 | |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 254 | if (mbmi->mode == NEWMV |
David Barker | 404b2e8 | 2017-03-27 13:07:47 +0100 | [diff] [blame] | 255 | #if CONFIG_EXT_INTER |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 256 | || mbmi->mode == NEW_NEWMV |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 257 | #if CONFIG_COMPOUND_SINGLEREF |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 258 | || mbmi->mode == SR_NEW_NEWMV |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 259 | #endif // CONFIG_COMPOUND_SINGLEREF |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 260 | #endif // CONFIG_EXT_INTER |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 261 | ) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 262 | int idx; |
| 263 | for (idx = 0; idx < 2; ++idx) { |
| 264 | if (xd->ref_mv_count[ref_frame_type] > idx + 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 265 | uint8_t drl_ctx = av1_drl_ctx(xd->ref_mv_stack[ref_frame_type], idx); |
Thomas Davies | 149eda5 | 2017-06-12 18:11:55 +0100 | [diff] [blame] | 266 | #if CONFIG_NEW_MULTISYMBOL |
| 267 | int drl_idx = aom_read_symbol(r, ec_ctx->drl_cdf[drl_ctx], 2, ACCT_STR); |
| 268 | #else |
| 269 | int drl_idx = aom_read(r, ec_ctx->drl_prob[drl_ctx], ACCT_STR); |
| 270 | #endif |
| 271 | mbmi->ref_mv_idx = idx + drl_idx; |
| 272 | if (xd->counts) ++xd->counts->drl_mode[drl_ctx][drl_idx]; |
| 273 | if (!drl_idx) return; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 274 | } |
| 275 | } |
| 276 | } |
| 277 | |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 278 | if (have_nearmv_in_inter_mode(mbmi->mode)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 279 | int idx; |
| 280 | // Offset the NEARESTMV mode. |
| 281 | // TODO(jingning): Unify the two syntax decoding loops after the NEARESTMV |
| 282 | // mode is factored in. |
| 283 | for (idx = 1; idx < 3; ++idx) { |
| 284 | if (xd->ref_mv_count[ref_frame_type] > idx + 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 285 | uint8_t drl_ctx = av1_drl_ctx(xd->ref_mv_stack[ref_frame_type], idx); |
Thomas Davies | 149eda5 | 2017-06-12 18:11:55 +0100 | [diff] [blame] | 286 | #if CONFIG_NEW_MULTISYMBOL |
| 287 | int drl_idx = aom_read_symbol(r, ec_ctx->drl_cdf[drl_ctx], 2, ACCT_STR); |
| 288 | #else |
| 289 | int drl_idx = aom_read(r, ec_ctx->drl_prob[drl_ctx], ACCT_STR); |
| 290 | #endif |
| 291 | mbmi->ref_mv_idx = idx + drl_idx - 1; |
| 292 | if (xd->counts) ++xd->counts->drl_mode[drl_ctx][drl_idx]; |
| 293 | if (!drl_idx) return; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | } |
| 297 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 298 | |
Yaowu Xu | b24e115 | 2016-10-31 16:28:32 -0700 | [diff] [blame] | 299 | #if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION |
| 300 | static MOTION_MODE read_motion_mode(AV1_COMMON *cm, MACROBLOCKD *xd, |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 301 | MODE_INFO *mi, aom_reader *r) { |
| 302 | MB_MODE_INFO *mbmi = &mi->mbmi; |
Wei-Ting Lin | 7daf042 | 2017-08-03 11:42:37 -0700 | [diff] [blame] | 303 | #if CONFIG_NEW_MULTISYMBOL || CONFIG_NCOBMC_ADAPT_WEIGHT |
Thomas Davies | 04e5aa7 | 2017-06-28 14:36:39 +0100 | [diff] [blame] | 304 | (void)cm; |
| 305 | #endif |
| 306 | |
Wei-Ting Lin | d0f7ba1 | 2017-06-30 14:59:57 -0700 | [diff] [blame] | 307 | #if CONFIG_NCOBMC_ADAPT_WEIGHT |
| 308 | const MOTION_MODE last_motion_mode_allowed = |
| 309 | motion_mode_allowed_wrapper(0, |
Sarah Parker | 0eea89f | 2017-07-11 11:56:36 -0700 | [diff] [blame] | 310 | #if CONFIG_GLOBAL_MOTION |
Wei-Ting Lin | d0f7ba1 | 2017-06-30 14:59:57 -0700 | [diff] [blame] | 311 | 0, xd->global_motion, |
Sarah Parker | 0eea89f | 2017-07-11 11:56:36 -0700 | [diff] [blame] | 312 | #endif // CONFIG_GLOBAL_MOTION |
Yue Chen | 52c5173 | 2017-07-11 15:08:30 -0700 | [diff] [blame] | 313 | #if CONFIG_WARPED_MOTION |
| 314 | xd, |
| 315 | #endif |
Wei-Ting Lin | d0f7ba1 | 2017-06-30 14:59:57 -0700 | [diff] [blame] | 316 | mi); |
| 317 | #else |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 318 | const MOTION_MODE last_motion_mode_allowed = motion_mode_allowed( |
Sarah Parker | 0eea89f | 2017-07-11 11:56:36 -0700 | [diff] [blame] | 319 | #if CONFIG_GLOBAL_MOTION |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 320 | 0, xd->global_motion, |
Sarah Parker | 0eea89f | 2017-07-11 11:56:36 -0700 | [diff] [blame] | 321 | #endif // CONFIG_GLOBAL_MOTION |
Yue Chen | 52c5173 | 2017-07-11 15:08:30 -0700 | [diff] [blame] | 322 | #if CONFIG_WARPED_MOTION |
| 323 | xd, |
| 324 | #endif |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 325 | mi); |
Wei-Ting Lin | d0f7ba1 | 2017-06-30 14:59:57 -0700 | [diff] [blame] | 326 | #endif // CONFIG_NCOBMC_ADAPT_WEIGHT |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 327 | int motion_mode; |
| 328 | FRAME_COUNTS *counts = xd->counts; |
Yaowu Xu | b24e115 | 2016-10-31 16:28:32 -0700 | [diff] [blame] | 329 | |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 330 | if (last_motion_mode_allowed == SIMPLE_TRANSLATION) return SIMPLE_TRANSLATION; |
| 331 | #if CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION |
| 332 | if (last_motion_mode_allowed == OBMC_CAUSAL) { |
Thomas Davies | d9b5726 | 2017-06-27 17:43:25 +0100 | [diff] [blame] | 333 | #if CONFIG_NEW_MULTISYMBOL |
| 334 | motion_mode = |
| 335 | aom_read_symbol(r, xd->tile_ctx->obmc_cdf[mbmi->sb_type], 2, ACCT_STR); |
| 336 | #else |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 337 | motion_mode = aom_read(r, cm->fc->obmc_prob[mbmi->sb_type], ACCT_STR); |
Thomas Davies | d9b5726 | 2017-06-27 17:43:25 +0100 | [diff] [blame] | 338 | #endif |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 339 | if (counts) ++counts->obmc[mbmi->sb_type][motion_mode]; |
| 340 | return (MOTION_MODE)(SIMPLE_TRANSLATION + motion_mode); |
| 341 | } else { |
| 342 | #endif // CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION |
Yaowu Xu | b24e115 | 2016-10-31 16:28:32 -0700 | [diff] [blame] | 343 | motion_mode = |
Thomas Davies | 04e5aa7 | 2017-06-28 14:36:39 +0100 | [diff] [blame] | 344 | aom_read_symbol(r, xd->tile_ctx->motion_mode_cdf[mbmi->sb_type], |
| 345 | MOTION_MODES, ACCT_STR); |
Yaowu Xu | b24e115 | 2016-10-31 16:28:32 -0700 | [diff] [blame] | 346 | if (counts) ++counts->motion_mode[mbmi->sb_type][motion_mode]; |
| 347 | return (MOTION_MODE)(SIMPLE_TRANSLATION + motion_mode); |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 348 | #if CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION |
Yaowu Xu | b24e115 | 2016-10-31 16:28:32 -0700 | [diff] [blame] | 349 | } |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 350 | #endif // CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION |
Yaowu Xu | b24e115 | 2016-10-31 16:28:32 -0700 | [diff] [blame] | 351 | } |
Wei-Ting Lin | 85a8f70 | 2017-06-22 13:55:15 -0700 | [diff] [blame] | 352 | |
| 353 | #if CONFIG_NCOBMC_ADAPT_WEIGHT |
Wei-Ting Lin | ca710d6 | 2017-07-13 11:41:02 -0700 | [diff] [blame] | 354 | static void read_ncobmc_mode(MACROBLOCKD *xd, MODE_INFO *mi, |
Wei-Ting Lin | 7daf042 | 2017-08-03 11:42:37 -0700 | [diff] [blame] | 355 | NCOBMC_MODE ncobmc_mode[2], aom_reader *r) { |
Wei-Ting Lin | 85a8f70 | 2017-06-22 13:55:15 -0700 | [diff] [blame] | 356 | 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 Lin | 77c4118 | 2017-07-12 15:58:35 -0700 | [diff] [blame] | 359 | if (mbmi->motion_mode != NCOBMC_ADAPT_WEIGHT) return; |
Wei-Ting Lin | 85a8f70 | 2017-06-22 13:55:15 -0700 | [diff] [blame] | 360 | |
Wei-Ting Lin | ca710d6 | 2017-07-13 11:41:02 -0700 | [diff] [blame] | 361 | ncobmc_mode[0] = aom_read_symbol(r, xd->tile_ctx->ncobmc_mode_cdf[ao_block], |
| 362 | MAX_NCOBMC_MODES, ACCT_STR); |
Wei-Ting Lin | 85a8f70 | 2017-06-22 13:55:15 -0700 | [diff] [blame] | 363 | if (counts) ++counts->ncobmc_mode[ao_block][ncobmc_mode[0]]; |
| 364 | |
| 365 | if (mi_size_wide[mbmi->sb_type] != mi_size_high[mbmi->sb_type]) { |
Wei-Ting Lin | ca710d6 | 2017-07-13 11:41:02 -0700 | [diff] [blame] | 366 | ncobmc_mode[1] = aom_read_symbol(r, xd->tile_ctx->ncobmc_mode_cdf[ao_block], |
| 367 | MAX_NCOBMC_MODES, ACCT_STR); |
Wei-Ting Lin | 85a8f70 | 2017-06-22 13:55:15 -0700 | [diff] [blame] | 368 | if (counts) ++counts->ncobmc_mode[ao_block][ncobmc_mode[1]]; |
| 369 | } |
| 370 | } |
Wei-Ting Lin | 7daf042 | 2017-08-03 11:42:37 -0700 | [diff] [blame] | 371 | #endif // CONFIG_NCOBMC_ADAPT_WEIGHT |
Yaowu Xu | b24e115 | 2016-10-31 16:28:32 -0700 | [diff] [blame] | 372 | #endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION |
| 373 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 374 | #if CONFIG_EXT_INTER |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 375 | static PREDICTION_MODE read_inter_compound_mode(AV1_COMMON *cm, MACROBLOCKD *xd, |
| 376 | aom_reader *r, int16_t ctx) { |
Thomas Davies | 8c08a33 | 2017-06-26 17:30:34 +0100 | [diff] [blame] | 377 | (void)cm; |
| 378 | const int mode = |
| 379 | aom_read_symbol(r, xd->tile_ctx->inter_compound_mode_cdf[ctx], |
| 380 | INTER_COMPOUND_MODES, ACCT_STR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 381 | FRAME_COUNTS *counts = xd->counts; |
| 382 | |
| 383 | if (counts) ++counts->inter_compound_mode[ctx][mode]; |
| 384 | |
| 385 | assert(is_inter_compound_mode(NEAREST_NEARESTMV + mode)); |
| 386 | return NEAREST_NEARESTMV + mode; |
| 387 | } |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 388 | |
| 389 | #if CONFIG_COMPOUND_SINGLEREF |
Thomas Davies | b8b14a9 | 2017-07-12 15:11:49 +0100 | [diff] [blame] | 390 | static PREDICTION_MODE read_inter_singleref_comp_mode(MACROBLOCKD *xd, |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 391 | aom_reader *r, |
| 392 | int16_t ctx) { |
| 393 | const int mode = |
Thomas Davies | b8b14a9 | 2017-07-12 15:11:49 +0100 | [diff] [blame] | 394 | aom_read_symbol(r, xd->tile_ctx->inter_singleref_comp_mode_cdf[ctx], |
| 395 | INTER_SINGLEREF_COMP_MODES, ACCT_STR); |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 396 | FRAME_COUNTS *counts = xd->counts; |
| 397 | |
| 398 | if (counts) ++counts->inter_singleref_comp_mode[ctx][mode]; |
| 399 | |
| 400 | assert(is_inter_singleref_comp_mode(SR_NEAREST_NEARMV + mode)); |
| 401 | return SR_NEAREST_NEARMV + mode; |
| 402 | } |
| 403 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 404 | #endif // CONFIG_EXT_INTER |
| 405 | |
Thomas | 9ac5508 | 2016-09-23 18:04:17 +0100 | [diff] [blame] | 406 | static int read_segment_id(aom_reader *r, struct segmentation_probs *segp) { |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 407 | return aom_read_symbol(r, segp->tree_cdf, MAX_SEGMENTS, ACCT_STR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | #if CONFIG_VAR_TX |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 411 | static void read_tx_size_vartx(AV1_COMMON *cm, MACROBLOCKD *xd, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 412 | MB_MODE_INFO *mbmi, FRAME_COUNTS *counts, |
Jingning Han | 94d5bfc | 2016-10-21 10:14:36 -0700 | [diff] [blame] | 413 | TX_SIZE tx_size, int depth, int blk_row, |
| 414 | int blk_col, aom_reader *r) { |
Thomas Davies | 985bfc3 | 2017-06-27 16:51:26 +0100 | [diff] [blame] | 415 | #if CONFIG_NEW_MULTISYMBOL |
| 416 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
| 417 | (void)cm; |
| 418 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 419 | int is_split = 0; |
| 420 | const int tx_row = blk_row >> 1; |
| 421 | const int tx_col = blk_col >> 1; |
Jingning Han | f64062f | 2016-11-02 16:22:18 -0700 | [diff] [blame] | 422 | const int max_blocks_high = max_block_high(xd, mbmi->sb_type, 0); |
| 423 | const int max_blocks_wide = max_block_wide(xd, mbmi->sb_type, 0); |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 424 | int ctx = txfm_partition_context(xd->above_txfm_context + blk_col, |
| 425 | xd->left_txfm_context + blk_row, |
Jingning Han | c8b8936 | 2016-11-01 10:28:53 -0700 | [diff] [blame] | 426 | mbmi->sb_type, tx_size); |
clang-format | 67948d3 | 2016-09-07 22:40:40 -0700 | [diff] [blame] | 427 | TX_SIZE(*const inter_tx_size) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 428 | [MAX_MIB_SIZE] = |
| 429 | (TX_SIZE(*)[MAX_MIB_SIZE]) & mbmi->inter_tx_size[tx_row][tx_col]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 430 | if (blk_row >= max_blocks_high || blk_col >= max_blocks_wide) return; |
| 431 | |
Jingning Han | 571189c | 2016-10-24 10:38:43 -0700 | [diff] [blame] | 432 | if (depth == MAX_VARTX_DEPTH) { |
Jingning Han | 94d5bfc | 2016-10-21 10:14:36 -0700 | [diff] [blame] | 433 | int idx, idy; |
| 434 | inter_tx_size[0][0] = tx_size; |
Jingning Han | 65abc31 | 2016-10-27 13:04:21 -0700 | [diff] [blame] | 435 | for (idy = 0; idy < tx_size_high_unit[tx_size] / 2; ++idy) |
| 436 | for (idx = 0; idx < tx_size_wide_unit[tx_size] / 2; ++idx) |
Jingning Han | 94d5bfc | 2016-10-21 10:14:36 -0700 | [diff] [blame] | 437 | inter_tx_size[idy][idx] = tx_size; |
| 438 | mbmi->tx_size = tx_size; |
Jingning Han | e67b38a | 2016-11-04 10:30:00 -0700 | [diff] [blame] | 439 | mbmi->min_tx_size = AOMMIN(mbmi->min_tx_size, get_min_tx_size(tx_size)); |
Jingning Han | 94d5bfc | 2016-10-21 10:14:36 -0700 | [diff] [blame] | 440 | if (counts) ++counts->txfm_partition[ctx][0]; |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 441 | txfm_partition_update(xd->above_txfm_context + blk_col, |
| 442 | xd->left_txfm_context + blk_row, tx_size, tx_size); |
Jingning Han | 94d5bfc | 2016-10-21 10:14:36 -0700 | [diff] [blame] | 443 | return; |
| 444 | } |
| 445 | |
Thomas Davies | 985bfc3 | 2017-06-27 16:51:26 +0100 | [diff] [blame] | 446 | #if CONFIG_NEW_MULTISYMBOL |
| 447 | is_split = aom_read_symbol(r, ec_ctx->txfm_partition_cdf[ctx], 2, ACCT_STR); |
| 448 | #else |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 449 | is_split = aom_read(r, cm->fc->txfm_partition_prob[ctx], ACCT_STR); |
Thomas Davies | 985bfc3 | 2017-06-27 16:51:26 +0100 | [diff] [blame] | 450 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 451 | |
| 452 | if (is_split) { |
Jingning Han | f64062f | 2016-11-02 16:22:18 -0700 | [diff] [blame] | 453 | const TX_SIZE sub_txs = sub_tx_size_map[tx_size]; |
| 454 | const int bsl = tx_size_wide_unit[sub_txs]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 455 | int i; |
| 456 | |
| 457 | if (counts) ++counts->txfm_partition[ctx][1]; |
| 458 | |
| 459 | if (tx_size == TX_8X8) { |
Jingning Han | 9ca05b7 | 2017-01-03 14:41:36 -0800 | [diff] [blame] | 460 | int idx, idy; |
Jingning Han | ab9ecba | 2017-01-13 09:11:58 -0800 | [diff] [blame] | 461 | inter_tx_size[0][0] = sub_txs; |
Jingning Han | 9ca05b7 | 2017-01-03 14:41:36 -0800 | [diff] [blame] | 462 | for (idy = 0; idy < tx_size_high_unit[tx_size] / 2; ++idy) |
| 463 | for (idx = 0; idx < tx_size_wide_unit[tx_size] / 2; ++idx) |
Jingning Han | 581d169 | 2017-01-05 16:03:54 -0800 | [diff] [blame] | 464 | inter_tx_size[idy][idx] = inter_tx_size[0][0]; |
Jingning Han | ab9ecba | 2017-01-13 09:11:58 -0800 | [diff] [blame] | 465 | mbmi->tx_size = sub_txs; |
Jingning Han | e67b38a | 2016-11-04 10:30:00 -0700 | [diff] [blame] | 466 | mbmi->min_tx_size = get_min_tx_size(mbmi->tx_size); |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 467 | txfm_partition_update(xd->above_txfm_context + blk_col, |
| 468 | xd->left_txfm_context + blk_row, sub_txs, tx_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 469 | return; |
| 470 | } |
| 471 | |
| 472 | assert(bsl > 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 473 | for (i = 0; i < 4; ++i) { |
Jingning Han | f64062f | 2016-11-02 16:22:18 -0700 | [diff] [blame] | 474 | int offsetr = blk_row + (i >> 1) * bsl; |
| 475 | int offsetc = blk_col + (i & 0x01) * bsl; |
| 476 | read_tx_size_vartx(cm, xd, mbmi, counts, sub_txs, depth + 1, offsetr, |
Jingning Han | 94d5bfc | 2016-10-21 10:14:36 -0700 | [diff] [blame] | 477 | offsetc, r); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 478 | } |
| 479 | } else { |
| 480 | int idx, idy; |
| 481 | inter_tx_size[0][0] = tx_size; |
Jingning Han | 65abc31 | 2016-10-27 13:04:21 -0700 | [diff] [blame] | 482 | for (idy = 0; idy < tx_size_high_unit[tx_size] / 2; ++idy) |
| 483 | for (idx = 0; idx < tx_size_wide_unit[tx_size] / 2; ++idx) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 484 | inter_tx_size[idy][idx] = tx_size; |
| 485 | mbmi->tx_size = tx_size; |
Jingning Han | e67b38a | 2016-11-04 10:30:00 -0700 | [diff] [blame] | 486 | mbmi->min_tx_size = AOMMIN(mbmi->min_tx_size, get_min_tx_size(tx_size)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 487 | if (counts) ++counts->txfm_partition[ctx][0]; |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 488 | txfm_partition_update(xd->above_txfm_context + blk_col, |
| 489 | xd->left_txfm_context + blk_row, tx_size, tx_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 490 | } |
| 491 | } |
| 492 | #endif |
| 493 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 494 | static TX_SIZE read_selected_tx_size(AV1_COMMON *cm, MACROBLOCKD *xd, |
| 495 | int tx_size_cat, aom_reader *r) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 496 | FRAME_COUNTS *counts = xd->counts; |
| 497 | const int ctx = get_tx_size_context(xd); |
Thomas Davies | 15580c5 | 2017-03-09 13:53:42 +0000 | [diff] [blame] | 498 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
| 499 | (void)cm; |
Thomas Davies | 15580c5 | 2017-03-09 13:53:42 +0000 | [diff] [blame] | 500 | |
Nathan E. Egge | 476c63c | 2017-05-18 18:35:16 -0400 | [diff] [blame] | 501 | const int depth = aom_read_symbol(r, ec_ctx->tx_size_cdf[tx_size_cat][ctx], |
| 502 | tx_size_cat + 2, ACCT_STR); |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 503 | const TX_SIZE tx_size = depth_to_tx_size(depth); |
| 504 | #if CONFIG_RECT_TX |
| 505 | assert(!is_rect_tx(tx_size)); |
| 506 | #endif // CONFIG_RECT_TX |
Jingning Han | 906be07 | 2016-10-26 11:04:31 -0700 | [diff] [blame] | 507 | if (counts) ++counts->tx_size[tx_size_cat][ctx][depth]; |
Jingning Han | 4e1737a | 2016-10-25 16:05:02 -0700 | [diff] [blame] | 508 | return tx_size; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 509 | } |
| 510 | |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 511 | static TX_SIZE read_tx_size(AV1_COMMON *cm, MACROBLOCKD *xd, int is_inter, |
| 512 | int allow_select_inter, aom_reader *r) { |
| 513 | const TX_MODE tx_mode = cm->tx_mode; |
| 514 | const BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 515 | if (xd->lossless[xd->mi[0]->mbmi.segment_id]) return TX_4X4; |
Debargha Mukherjee | 428bbb2 | 2017-03-17 07:30:24 -0700 | [diff] [blame] | 516 | #if CONFIG_CB4X4 && (CONFIG_VAR_TX || CONFIG_EXT_TX) && CONFIG_RECT_TX |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 517 | if (bsize > BLOCK_4X4) |
Jingning Han | 4be1a4d | 2017-01-06 10:59:20 -0800 | [diff] [blame] | 518 | #else |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 519 | if (bsize >= BLOCK_8X8) |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 520 | #endif // CONFIG_CB4X4 && CONFIG_VAR_TX |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 521 | { |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 522 | if ((!is_inter || allow_select_inter) && tx_mode == TX_MODE_SELECT) { |
| 523 | const int32_t tx_size_cat = is_inter ? inter_tx_size_cat_lookup[bsize] |
| 524 | : intra_tx_size_cat_lookup[bsize]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 525 | const TX_SIZE coded_tx_size = |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 526 | read_selected_tx_size(cm, xd, tx_size_cat, r); |
Yue Chen | 3ca7dd9 | 2017-05-23 16:03:39 -0700 | [diff] [blame] | 527 | #if CONFIG_RECT_TX && (CONFIG_EXT_TX || CONFIG_VAR_TX) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 528 | if (coded_tx_size > max_txsize_lookup[bsize]) { |
| 529 | assert(coded_tx_size == max_txsize_lookup[bsize] + 1); |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 530 | #if CONFIG_RECT_TX_EXT |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 531 | if (is_quarter_tx_allowed(xd, &xd->mi[0]->mbmi, is_inter)) { |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 532 | int quarter_tx; |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 533 | |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 534 | if (quarter_txsize_lookup[bsize] != max_txsize_lookup[bsize]) { |
| 535 | quarter_tx = aom_read(r, cm->fc->quarter_tx_size_prob, ACCT_STR); |
| 536 | FRAME_COUNTS *counts = xd->counts; |
| 537 | |
| 538 | if (counts) ++counts->quarter_tx_size[quarter_tx]; |
| 539 | } else { |
| 540 | quarter_tx = 1; |
| 541 | } |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 542 | return quarter_tx ? quarter_txsize_lookup[bsize] |
| 543 | : max_txsize_rect_lookup[bsize]; |
| 544 | } |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 545 | #endif // CONFIG_RECT_TX_EXT |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 546 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 547 | return max_txsize_rect_lookup[bsize]; |
| 548 | } |
Peter de Rivaz | a7c8146 | 2016-09-26 14:20:13 +0100 | [diff] [blame] | 549 | #else |
| 550 | assert(coded_tx_size <= max_txsize_lookup[bsize]); |
Yue Chen | 3ca7dd9 | 2017-05-23 16:03:39 -0700 | [diff] [blame] | 551 | #endif // CONFIG_RECT_TX && (CONFIG_EXT_TX || CONFIG_VAR_TX) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 552 | return coded_tx_size; |
| 553 | } else { |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 554 | return tx_size_from_tx_mode(bsize, tx_mode, is_inter); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 555 | } |
| 556 | } else { |
| 557 | #if CONFIG_EXT_TX && CONFIG_RECT_TX |
| 558 | assert(IMPLIES(tx_mode == ONLY_4X4, bsize == BLOCK_4X4)); |
| 559 | return max_txsize_rect_lookup[bsize]; |
| 560 | #else |
| 561 | return TX_4X4; |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 562 | #endif // CONFIG_EXT_TX && CONFIG_RECT_TX |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 563 | } |
| 564 | } |
| 565 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 566 | static int dec_get_segment_id(const AV1_COMMON *cm, const uint8_t *segment_ids, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 567 | int mi_offset, int x_mis, int y_mis) { |
| 568 | int x, y, segment_id = INT_MAX; |
| 569 | |
| 570 | for (y = 0; y < y_mis; y++) |
| 571 | for (x = 0; x < x_mis; x++) |
| 572 | segment_id = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 573 | AOMMIN(segment_id, segment_ids[mi_offset + y * cm->mi_cols + x]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 574 | |
| 575 | assert(segment_id >= 0 && segment_id < MAX_SEGMENTS); |
| 576 | return segment_id; |
| 577 | } |
| 578 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 579 | static void set_segment_id(AV1_COMMON *cm, int mi_offset, int x_mis, int y_mis, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 580 | int segment_id) { |
| 581 | int x, y; |
| 582 | |
| 583 | assert(segment_id >= 0 && segment_id < MAX_SEGMENTS); |
| 584 | |
| 585 | for (y = 0; y < y_mis; y++) |
| 586 | for (x = 0; x < x_mis; x++) |
| 587 | cm->current_frame_seg_map[mi_offset + y * cm->mi_cols + x] = segment_id; |
| 588 | } |
| 589 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 590 | static int read_intra_segment_id(AV1_COMMON *const cm, MACROBLOCKD *const xd, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 591 | int mi_offset, int x_mis, int y_mis, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 592 | aom_reader *r) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 593 | struct segmentation *const seg = &cm->seg; |
| 594 | FRAME_COUNTS *counts = xd->counts; |
Thomas Davies | 9f5cedd | 2017-07-10 09:20:32 +0100 | [diff] [blame] | 595 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
Thomas Davies | 9f5cedd | 2017-07-10 09:20:32 +0100 | [diff] [blame] | 596 | struct segmentation_probs *const segp = &ec_ctx->seg; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 597 | int segment_id; |
| 598 | |
| 599 | if (!seg->enabled) return 0; // Default for disabled segmentation |
| 600 | |
| 601 | assert(seg->update_map && !seg->temporal_update); |
| 602 | |
| 603 | segment_id = read_segment_id(r, segp); |
| 604 | if (counts) ++counts->seg.tree_total[segment_id]; |
| 605 | set_segment_id(cm, mi_offset, x_mis, y_mis, segment_id); |
| 606 | return segment_id; |
| 607 | } |
| 608 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 609 | static void copy_segment_id(const AV1_COMMON *cm, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 610 | const uint8_t *last_segment_ids, |
| 611 | uint8_t *current_segment_ids, int mi_offset, |
| 612 | int x_mis, int y_mis) { |
| 613 | int x, y; |
| 614 | |
| 615 | for (y = 0; y < y_mis; y++) |
| 616 | for (x = 0; x < x_mis; x++) |
| 617 | current_segment_ids[mi_offset + y * cm->mi_cols + x] = |
| 618 | last_segment_ids ? last_segment_ids[mi_offset + y * cm->mi_cols + x] |
| 619 | : 0; |
| 620 | } |
| 621 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 622 | static int read_inter_segment_id(AV1_COMMON *const cm, MACROBLOCKD *const xd, |
| 623 | int mi_row, int mi_col, aom_reader *r) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 624 | struct segmentation *const seg = &cm->seg; |
| 625 | FRAME_COUNTS *counts = xd->counts; |
Thomas Davies | 9f5cedd | 2017-07-10 09:20:32 +0100 | [diff] [blame] | 626 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
Thomas Davies | 9f5cedd | 2017-07-10 09:20:32 +0100 | [diff] [blame] | 627 | struct segmentation_probs *const segp = &ec_ctx->seg; |
| 628 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 629 | MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
| 630 | int predicted_segment_id, segment_id; |
| 631 | const int mi_offset = mi_row * cm->mi_cols + mi_col; |
Jingning Han | c709e1f | 2016-12-06 14:48:09 -0800 | [diff] [blame] | 632 | const int bw = mi_size_wide[mbmi->sb_type]; |
| 633 | const int bh = mi_size_high[mbmi->sb_type]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 634 | |
| 635 | // TODO(slavarnway): move x_mis, y_mis into xd ????? |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 636 | const int x_mis = AOMMIN(cm->mi_cols - mi_col, bw); |
| 637 | const int y_mis = AOMMIN(cm->mi_rows - mi_row, bh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 638 | |
| 639 | if (!seg->enabled) return 0; // Default for disabled segmentation |
| 640 | |
| 641 | predicted_segment_id = cm->last_frame_seg_map |
| 642 | ? dec_get_segment_id(cm, cm->last_frame_seg_map, |
| 643 | mi_offset, x_mis, y_mis) |
| 644 | : 0; |
| 645 | |
| 646 | if (!seg->update_map) { |
| 647 | copy_segment_id(cm, cm->last_frame_seg_map, cm->current_frame_seg_map, |
| 648 | mi_offset, x_mis, y_mis); |
| 649 | return predicted_segment_id; |
| 650 | } |
| 651 | |
| 652 | if (seg->temporal_update) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 653 | const int ctx = av1_get_pred_context_seg_id(xd); |
Thomas Davies | 0002135 | 2017-07-11 16:07:55 +0100 | [diff] [blame] | 654 | #if CONFIG_NEW_MULTISYMBOL |
| 655 | aom_cdf_prob *pred_cdf = segp->pred_cdf[ctx]; |
| 656 | mbmi->seg_id_predicted = aom_read_symbol(r, pred_cdf, 2, ACCT_STR); |
| 657 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 658 | const aom_prob pred_prob = segp->pred_probs[ctx]; |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 659 | mbmi->seg_id_predicted = aom_read(r, pred_prob, ACCT_STR); |
Thomas Davies | 0002135 | 2017-07-11 16:07:55 +0100 | [diff] [blame] | 660 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 661 | if (counts) ++counts->seg.pred[ctx][mbmi->seg_id_predicted]; |
| 662 | if (mbmi->seg_id_predicted) { |
| 663 | segment_id = predicted_segment_id; |
| 664 | } else { |
| 665 | segment_id = read_segment_id(r, segp); |
| 666 | if (counts) ++counts->seg.tree_mispred[segment_id]; |
| 667 | } |
| 668 | } else { |
| 669 | segment_id = read_segment_id(r, segp); |
| 670 | if (counts) ++counts->seg.tree_total[segment_id]; |
| 671 | } |
| 672 | set_segment_id(cm, mi_offset, x_mis, y_mis, segment_id); |
| 673 | return segment_id; |
| 674 | } |
| 675 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 676 | static int read_skip(AV1_COMMON *cm, const MACROBLOCKD *xd, int segment_id, |
| 677 | aom_reader *r) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 678 | if (segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)) { |
| 679 | return 1; |
| 680 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 681 | const int ctx = av1_get_skip_context(xd); |
Thomas Davies | 61e3e37 | 2017-04-04 16:10:23 +0100 | [diff] [blame] | 682 | #if CONFIG_NEW_MULTISYMBOL |
| 683 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
| 684 | const int skip = aom_read_symbol(r, ec_ctx->skip_cdfs[ctx], 2, ACCT_STR); |
| 685 | #else |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 686 | const int skip = aom_read(r, cm->fc->skip_probs[ctx], ACCT_STR); |
Thomas Davies | 61e3e37 | 2017-04-04 16:10:23 +0100 | [diff] [blame] | 687 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 688 | FRAME_COUNTS *counts = xd->counts; |
| 689 | if (counts) ++counts->skip[ctx][skip]; |
| 690 | return skip; |
| 691 | } |
| 692 | } |
| 693 | |
hui su | 33567b2 | 2017-04-30 16:40:19 -0700 | [diff] [blame] | 694 | #if CONFIG_PALETTE_DELTA_ENCODING |
hui su | 33567b2 | 2017-04-30 16:40:19 -0700 | [diff] [blame] | 695 | static int uint16_compare(const void *a, const void *b) { |
Urvang Joshi | 0ba850e | 2017-05-12 17:05:45 -0700 | [diff] [blame] | 696 | const uint16_t va = *(const uint16_t *)a; |
| 697 | const uint16_t vb = *(const uint16_t *)b; |
hui su | 33567b2 | 2017-04-30 16:40:19 -0700 | [diff] [blame] | 698 | return va - vb; |
| 699 | } |
hui su | 33567b2 | 2017-04-30 16:40:19 -0700 | [diff] [blame] | 700 | |
| 701 | static void read_palette_colors_y(MACROBLOCKD *const xd, int bit_depth, |
| 702 | PALETTE_MODE_INFO *const pmi, aom_reader *r) { |
| 703 | uint16_t color_cache[2 * PALETTE_MAX_SIZE]; |
| 704 | const MODE_INFO *const above_mi = xd->above_mi; |
| 705 | const MODE_INFO *const left_mi = xd->left_mi; |
| 706 | const int n_cache = av1_get_palette_cache(above_mi, left_mi, 0, color_cache); |
| 707 | const int n = pmi->palette_size[0]; |
| 708 | int idx = 0; |
| 709 | for (int i = 0; i < n_cache && idx < n; ++i) |
| 710 | if (aom_read_bit(r, ACCT_STR)) pmi->palette_colors[idx++] = color_cache[i]; |
| 711 | if (idx < n) { |
| 712 | pmi->palette_colors[idx++] = aom_read_literal(r, bit_depth, ACCT_STR); |
| 713 | if (idx < n) { |
| 714 | const int min_bits = bit_depth - 3; |
| 715 | int bits = min_bits + aom_read_literal(r, 2, ACCT_STR); |
| 716 | int range = (1 << bit_depth) - pmi->palette_colors[idx - 1] - 1; |
| 717 | for (; idx < n; ++idx) { |
| 718 | const int delta = aom_read_literal(r, bits, ACCT_STR) + 1; |
| 719 | pmi->palette_colors[idx] = pmi->palette_colors[idx - 1] + delta; |
| 720 | range -= delta; |
| 721 | bits = AOMMIN(bits, av1_ceil_log2(range)); |
| 722 | } |
| 723 | } |
| 724 | } |
hui su | 33567b2 | 2017-04-30 16:40:19 -0700 | [diff] [blame] | 725 | qsort(pmi->palette_colors, n, sizeof(pmi->palette_colors[0]), uint16_compare); |
hui su | 33567b2 | 2017-04-30 16:40:19 -0700 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | static void read_palette_colors_uv(MACROBLOCKD *const xd, int bit_depth, |
| 729 | PALETTE_MODE_INFO *const pmi, |
| 730 | aom_reader *r) { |
| 731 | const int n = pmi->palette_size[1]; |
| 732 | // U channel colors. |
| 733 | uint16_t color_cache[2 * PALETTE_MAX_SIZE]; |
| 734 | const MODE_INFO *const above_mi = xd->above_mi; |
| 735 | const MODE_INFO *const left_mi = xd->left_mi; |
| 736 | const int n_cache = av1_get_palette_cache(above_mi, left_mi, 1, color_cache); |
| 737 | int idx = PALETTE_MAX_SIZE; |
| 738 | for (int i = 0; i < n_cache && idx < PALETTE_MAX_SIZE + n; ++i) |
| 739 | if (aom_read_bit(r, ACCT_STR)) pmi->palette_colors[idx++] = color_cache[i]; |
| 740 | if (idx < PALETTE_MAX_SIZE + n) { |
| 741 | pmi->palette_colors[idx++] = aom_read_literal(r, bit_depth, ACCT_STR); |
| 742 | if (idx < PALETTE_MAX_SIZE + n) { |
| 743 | const int min_bits = bit_depth - 3; |
| 744 | int bits = min_bits + aom_read_literal(r, 2, ACCT_STR); |
| 745 | int range = (1 << bit_depth) - pmi->palette_colors[idx - 1]; |
| 746 | for (; idx < PALETTE_MAX_SIZE + n; ++idx) { |
| 747 | const int delta = aom_read_literal(r, bits, ACCT_STR); |
| 748 | pmi->palette_colors[idx] = pmi->palette_colors[idx - 1] + delta; |
| 749 | range -= delta; |
| 750 | bits = AOMMIN(bits, av1_ceil_log2(range)); |
| 751 | } |
| 752 | } |
| 753 | } |
hui su | 33567b2 | 2017-04-30 16:40:19 -0700 | [diff] [blame] | 754 | qsort(pmi->palette_colors + PALETTE_MAX_SIZE, n, |
| 755 | sizeof(pmi->palette_colors[0]), uint16_compare); |
hui su | 33567b2 | 2017-04-30 16:40:19 -0700 | [diff] [blame] | 756 | |
| 757 | // V channel colors. |
| 758 | if (aom_read_bit(r, ACCT_STR)) { // Delta encoding. |
| 759 | const int min_bits_v = bit_depth - 4; |
| 760 | const int max_val = 1 << bit_depth; |
| 761 | int bits = min_bits_v + aom_read_literal(r, 2, ACCT_STR); |
| 762 | pmi->palette_colors[2 * PALETTE_MAX_SIZE] = |
| 763 | aom_read_literal(r, bit_depth, ACCT_STR); |
| 764 | for (int i = 1; i < n; ++i) { |
| 765 | int delta = aom_read_literal(r, bits, ACCT_STR); |
| 766 | if (delta && aom_read_bit(r, ACCT_STR)) delta = -delta; |
| 767 | int val = (int)pmi->palette_colors[2 * PALETTE_MAX_SIZE + i - 1] + delta; |
| 768 | if (val < 0) val += max_val; |
| 769 | if (val >= max_val) val -= max_val; |
| 770 | pmi->palette_colors[2 * PALETTE_MAX_SIZE + i] = val; |
| 771 | } |
| 772 | } else { |
| 773 | for (int i = 0; i < n; ++i) { |
| 774 | pmi->palette_colors[2 * PALETTE_MAX_SIZE + i] = |
| 775 | aom_read_literal(r, bit_depth, ACCT_STR); |
| 776 | } |
| 777 | } |
| 778 | } |
| 779 | #endif // CONFIG_PALETTE_DELTA_ENCODING |
| 780 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 781 | static void read_palette_mode_info(AV1_COMMON *const cm, MACROBLOCKD *const xd, |
| 782 | aom_reader *r) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 783 | MODE_INFO *const mi = xd->mi[0]; |
| 784 | MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 785 | const MODE_INFO *const above_mi = xd->above_mi; |
| 786 | const MODE_INFO *const left_mi = xd->left_mi; |
| 787 | const BLOCK_SIZE bsize = mbmi->sb_type; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 788 | PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info; |
| 789 | |
Rupert Swarbrick | 6f9cd94 | 2017-08-02 15:57:18 +0100 | [diff] [blame] | 790 | assert(bsize >= BLOCK_8X8 && bsize <= BLOCK_LARGEST); |
| 791 | const int block_palette_idx = bsize - BLOCK_8X8; |
| 792 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 793 | if (mbmi->mode == DC_PRED) { |
Urvang Joshi | 23a6111 | 2017-01-30 14:59:27 -0800 | [diff] [blame] | 794 | int palette_y_mode_ctx = 0; |
hui su | 40b9e7f | 2017-07-13 18:15:56 -0700 | [diff] [blame] | 795 | if (above_mi) { |
Urvang Joshi | 23a6111 | 2017-01-30 14:59:27 -0800 | [diff] [blame] | 796 | palette_y_mode_ctx += |
| 797 | (above_mi->mbmi.palette_mode_info.palette_size[0] > 0); |
hui su | 40b9e7f | 2017-07-13 18:15:56 -0700 | [diff] [blame] | 798 | } |
| 799 | if (left_mi) { |
Urvang Joshi | 23a6111 | 2017-01-30 14:59:27 -0800 | [diff] [blame] | 800 | palette_y_mode_ctx += |
| 801 | (left_mi->mbmi.palette_mode_info.palette_size[0] > 0); |
hui su | 40b9e7f | 2017-07-13 18:15:56 -0700 | [diff] [blame] | 802 | } |
Rupert Swarbrick | 6f9cd94 | 2017-08-02 15:57:18 +0100 | [diff] [blame] | 803 | if (aom_read(r, av1_default_palette_y_mode_prob[block_palette_idx] |
Urvang Joshi | 23a6111 | 2017-01-30 14:59:27 -0800 | [diff] [blame] | 804 | [palette_y_mode_ctx], |
| 805 | ACCT_STR)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 806 | pmi->palette_size[0] = |
Thomas Davies | ce7272d | 2017-07-04 16:11:08 +0100 | [diff] [blame] | 807 | aom_read_symbol(r, |
Rupert Swarbrick | 6f9cd94 | 2017-08-02 15:57:18 +0100 | [diff] [blame] | 808 | xd->tile_ctx->palette_y_size_cdf[block_palette_idx], |
Thomas Davies | ce7272d | 2017-07-04 16:11:08 +0100 | [diff] [blame] | 809 | PALETTE_SIZES, ACCT_STR) + |
| 810 | 2; |
hui su | d13c24a | 2017-04-07 16:13:07 -0700 | [diff] [blame] | 811 | #if CONFIG_PALETTE_DELTA_ENCODING |
hui su | 33567b2 | 2017-04-30 16:40:19 -0700 | [diff] [blame] | 812 | read_palette_colors_y(xd, cm->bit_depth, pmi, r); |
hui su | d13c24a | 2017-04-07 16:13:07 -0700 | [diff] [blame] | 813 | #else |
hui su | 40b9e7f | 2017-07-13 18:15:56 -0700 | [diff] [blame] | 814 | for (int i = 0; i < pmi->palette_size[0]; ++i) |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 815 | pmi->palette_colors[i] = aom_read_literal(r, cm->bit_depth, ACCT_STR); |
hui su | d13c24a | 2017-04-07 16:13:07 -0700 | [diff] [blame] | 816 | #endif // CONFIG_PALETTE_DELTA_ENCODING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 817 | } |
| 818 | } |
| 819 | |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 820 | if (mbmi->uv_mode == UV_DC_PRED) { |
Urvang Joshi | 23a6111 | 2017-01-30 14:59:27 -0800 | [diff] [blame] | 821 | const int palette_uv_mode_ctx = (pmi->palette_size[0] > 0); |
| 822 | if (aom_read(r, av1_default_palette_uv_mode_prob[palette_uv_mode_ctx], |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 823 | ACCT_STR)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 824 | pmi->palette_size[1] = |
Thomas Davies | ce7272d | 2017-07-04 16:11:08 +0100 | [diff] [blame] | 825 | aom_read_symbol(r, |
Rupert Swarbrick | 6f9cd94 | 2017-08-02 15:57:18 +0100 | [diff] [blame] | 826 | xd->tile_ctx->palette_uv_size_cdf[block_palette_idx], |
Thomas Davies | ce7272d | 2017-07-04 16:11:08 +0100 | [diff] [blame] | 827 | PALETTE_SIZES, ACCT_STR) + |
| 828 | 2; |
hui su | d13c24a | 2017-04-07 16:13:07 -0700 | [diff] [blame] | 829 | #if CONFIG_PALETTE_DELTA_ENCODING |
hui su | 33567b2 | 2017-04-30 16:40:19 -0700 | [diff] [blame] | 830 | read_palette_colors_uv(xd, cm->bit_depth, pmi, r); |
hui su | d13c24a | 2017-04-07 16:13:07 -0700 | [diff] [blame] | 831 | #else |
hui su | 40b9e7f | 2017-07-13 18:15:56 -0700 | [diff] [blame] | 832 | for (int i = 0; i < pmi->palette_size[1]; ++i) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 833 | pmi->palette_colors[PALETTE_MAX_SIZE + i] = |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 834 | aom_read_literal(r, cm->bit_depth, ACCT_STR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 835 | pmi->palette_colors[2 * PALETTE_MAX_SIZE + i] = |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 836 | aom_read_literal(r, cm->bit_depth, ACCT_STR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 837 | } |
hui su | d13c24a | 2017-04-07 16:13:07 -0700 | [diff] [blame] | 838 | #endif // CONFIG_PALETTE_DELTA_ENCODING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 839 | } |
| 840 | } |
| 841 | } |
| 842 | |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 843 | #if CONFIG_FILTER_INTRA |
| 844 | static void read_filter_intra_mode_info(AV1_COMMON *const cm, |
Jingning Han | 62946d1 | 2017-05-26 11:29:30 -0700 | [diff] [blame] | 845 | MACROBLOCKD *const xd, int mi_row, |
| 846 | int mi_col, aom_reader *r) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 847 | MODE_INFO *const mi = xd->mi[0]; |
| 848 | MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 849 | FRAME_COUNTS *counts = xd->counts; |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 850 | FILTER_INTRA_MODE_INFO *filter_intra_mode_info = |
| 851 | &mbmi->filter_intra_mode_info; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 852 | |
Urvang Joshi | c6300aa | 2017-06-01 14:46:23 -0700 | [diff] [blame] | 853 | if (mbmi->mode == DC_PRED && mbmi->palette_mode_info.palette_size[0] == 0) { |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 854 | filter_intra_mode_info->use_filter_intra_mode[0] = |
| 855 | aom_read(r, cm->fc->filter_intra_probs[0], ACCT_STR); |
| 856 | if (filter_intra_mode_info->use_filter_intra_mode[0]) { |
| 857 | filter_intra_mode_info->filter_intra_mode[0] = |
hui su | 40b9e7f | 2017-07-13 18:15:56 -0700 | [diff] [blame] | 858 | av1_read_uniform(r, FILTER_INTRA_MODES); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 859 | } |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 860 | if (counts) { |
clang-format | 55ce9e0 | 2017-02-15 22:27:12 -0800 | [diff] [blame] | 861 | ++counts |
| 862 | ->filter_intra[0][filter_intra_mode_info->use_filter_intra_mode[0]]; |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 863 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 864 | } |
Jingning Han | 62946d1 | 2017-05-26 11:29:30 -0700 | [diff] [blame] | 865 | |
| 866 | #if CONFIG_CB4X4 |
| 867 | if (!is_chroma_reference(mi_row, mi_col, mbmi->sb_type, |
| 868 | xd->plane[1].subsampling_x, |
| 869 | xd->plane[1].subsampling_y)) |
| 870 | return; |
hui su | b4ed149 | 2017-05-31 17:25:42 -0700 | [diff] [blame] | 871 | #else |
| 872 | (void)mi_row; |
| 873 | (void)mi_col; |
| 874 | #endif // CONFIG_CB4X4 |
Jingning Han | 62946d1 | 2017-05-26 11:29:30 -0700 | [diff] [blame] | 875 | |
Urvang Joshi | c6300aa | 2017-06-01 14:46:23 -0700 | [diff] [blame] | 876 | if (mbmi->uv_mode == UV_DC_PRED && |
| 877 | mbmi->palette_mode_info.palette_size[1] == 0) { |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 878 | filter_intra_mode_info->use_filter_intra_mode[1] = |
| 879 | aom_read(r, cm->fc->filter_intra_probs[1], ACCT_STR); |
| 880 | if (filter_intra_mode_info->use_filter_intra_mode[1]) { |
| 881 | filter_intra_mode_info->filter_intra_mode[1] = |
hui su | 40b9e7f | 2017-07-13 18:15:56 -0700 | [diff] [blame] | 882 | av1_read_uniform(r, FILTER_INTRA_MODES); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 883 | } |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 884 | if (counts) { |
clang-format | 55ce9e0 | 2017-02-15 22:27:12 -0800 | [diff] [blame] | 885 | ++counts |
| 886 | ->filter_intra[1][filter_intra_mode_info->use_filter_intra_mode[1]]; |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 887 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 888 | } |
| 889 | } |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 890 | #endif // CONFIG_FILTER_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 891 | |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 892 | #if CONFIG_EXT_INTRA |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 893 | static void read_intra_angle_info(AV1_COMMON *const cm, MACROBLOCKD *const xd, |
| 894 | aom_reader *r) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 895 | MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
| 896 | const BLOCK_SIZE bsize = mbmi->sb_type; |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 897 | #if CONFIG_INTRA_INTERP |
hui su | b4e25d2 | 2017-03-09 15:32:30 -0800 | [diff] [blame] | 898 | FRAME_CONTEXT *const ec_ctx = xd->tile_ctx; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 899 | const int ctx = av1_get_pred_context_intra_interp(xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 900 | int p_angle; |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 901 | #endif // CONFIG_INTRA_INTERP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 902 | |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 903 | (void)cm; |
Joe Young | 830d4ce | 2017-05-30 17:48:13 -0700 | [diff] [blame] | 904 | |
| 905 | mbmi->angle_delta[0] = 0; |
| 906 | mbmi->angle_delta[1] = 0; |
| 907 | |
| 908 | if (!av1_use_angle_delta(bsize)) return; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 909 | |
hui su | 45dc597 | 2016-12-08 17:42:50 -0800 | [diff] [blame] | 910 | if (av1_is_directional_mode(mbmi->mode, bsize)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 911 | mbmi->angle_delta[0] = |
hui su | 40b9e7f | 2017-07-13 18:15:56 -0700 | [diff] [blame] | 912 | av1_read_uniform(r, 2 * MAX_ANGLE_DELTA + 1) - MAX_ANGLE_DELTA; |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 913 | #if CONFIG_INTRA_INTERP |
hui su | 0a6731f | 2017-04-26 15:23:47 -0700 | [diff] [blame] | 914 | p_angle = mode_to_angle_map[mbmi->mode] + mbmi->angle_delta[0] * ANGLE_STEP; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 915 | if (av1_is_intra_filter_switchable(p_angle)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 916 | FRAME_COUNTS *counts = xd->counts; |
hui su | b4e25d2 | 2017-03-09 15:32:30 -0800 | [diff] [blame] | 917 | mbmi->intra_filter = aom_read_symbol(r, ec_ctx->intra_filter_cdf[ctx], |
| 918 | INTRA_FILTERS, ACCT_STR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 919 | if (counts) ++counts->intra_filter[ctx][mbmi->intra_filter]; |
| 920 | } else { |
| 921 | mbmi->intra_filter = INTRA_FILTER_LINEAR; |
| 922 | } |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 923 | #endif // CONFIG_INTRA_INTERP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 924 | } |
| 925 | |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 926 | if (av1_is_directional_mode(get_uv_mode(mbmi->uv_mode), bsize)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 927 | mbmi->angle_delta[1] = |
hui su | 40b9e7f | 2017-07-13 18:15:56 -0700 | [diff] [blame] | 928 | av1_read_uniform(r, 2 * MAX_ANGLE_DELTA + 1) - MAX_ANGLE_DELTA; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 929 | } |
| 930 | } |
| 931 | #endif // CONFIG_EXT_INTRA |
| 932 | |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 933 | void av1_read_tx_type(const AV1_COMMON *const cm, MACROBLOCKD *xd, |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 934 | #if CONFIG_SUPERTX |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 935 | int supertx_enabled, |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 936 | #endif |
Angie Chiang | cd9b03f | 2017-04-16 13:37:13 -0700 | [diff] [blame] | 937 | #if CONFIG_TXK_SEL |
Jingning Han | 19b5c8f | 2017-07-06 15:10:12 -0700 | [diff] [blame] | 938 | int blk_row, int blk_col, int block, int plane, |
| 939 | TX_SIZE tx_size, |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 940 | #endif |
| 941 | aom_reader *r) { |
| 942 | MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 943 | const int inter_block = is_inter_block(mbmi); |
Jingning Han | 243b66b | 2017-06-23 12:11:47 -0700 | [diff] [blame] | 944 | #if !CONFIG_TXK_SEL |
Jingning Han | e67b38a | 2016-11-04 10:30:00 -0700 | [diff] [blame] | 945 | #if CONFIG_VAR_TX |
| 946 | const TX_SIZE tx_size = inter_block ? mbmi->min_tx_size : mbmi->tx_size; |
| 947 | #else |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 948 | const TX_SIZE tx_size = mbmi->tx_size; |
Jingning Han | e67b38a | 2016-11-04 10:30:00 -0700 | [diff] [blame] | 949 | #endif |
Jingning Han | 243b66b | 2017-06-23 12:11:47 -0700 | [diff] [blame] | 950 | #endif // !CONFIG_TXK_SEL |
Thomas Davies | cef0962 | 2017-01-11 17:27:12 +0000 | [diff] [blame] | 951 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
Thomas Davies | cef0962 | 2017-01-11 17:27:12 +0000 | [diff] [blame] | 952 | |
Angie Chiang | cd9b03f | 2017-04-16 13:37:13 -0700 | [diff] [blame] | 953 | #if !CONFIG_TXK_SEL |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 954 | TX_TYPE *tx_type = &mbmi->tx_type; |
| 955 | #else |
Angie Chiang | 39b06eb | 2017-04-14 09:52:29 -0700 | [diff] [blame] | 956 | // only y plane's tx_type is transmitted |
| 957 | if (plane > 0) return; |
Jingning Han | 19b5c8f | 2017-07-06 15:10:12 -0700 | [diff] [blame] | 958 | (void)block; |
| 959 | TX_TYPE *tx_type = &mbmi->txk_type[(blk_row << 4) + blk_col]; |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 960 | #endif |
| 961 | |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 962 | if (!FIXED_TX_TYPE) { |
| 963 | #if CONFIG_EXT_TX |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 964 | const TX_SIZE square_tx_size = txsize_sqr_map[tx_size]; |
Sarah Parker | e68a3e4 | 2017-02-16 14:03:24 -0800 | [diff] [blame] | 965 | if (get_ext_tx_types(tx_size, mbmi->sb_type, inter_block, |
| 966 | cm->reduced_tx_set_used) > 1 && |
Yue Chen | eeacc4c | 2017-01-17 17:29:17 -0800 | [diff] [blame] | 967 | ((!cm->seg.enabled && cm->base_qindex > 0) || |
| 968 | (cm->seg.enabled && xd->qindex[mbmi->segment_id] > 0)) && |
| 969 | !mbmi->skip && |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 970 | #if CONFIG_SUPERTX |
| 971 | !supertx_enabled && |
| 972 | #endif // CONFIG_SUPERTX |
| 973 | !segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { |
Sarah Parker | e68a3e4 | 2017-02-16 14:03:24 -0800 | [diff] [blame] | 974 | const int eset = get_ext_tx_set(tx_size, mbmi->sb_type, inter_block, |
| 975 | cm->reduced_tx_set_used); |
Sarah Parker | 784596d | 2017-06-23 08:41:26 -0700 | [diff] [blame] | 976 | // eset == 0 should correspond to a set with only DCT_DCT and |
| 977 | // there is no need to read the tx_type |
| 978 | assert(eset != 0); |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 979 | FRAME_COUNTS *counts = xd->counts; |
| 980 | |
| 981 | if (inter_block) { |
Sarah Parker | 784596d | 2017-06-23 08:41:26 -0700 | [diff] [blame] | 982 | *tx_type = av1_ext_tx_inter_inv[eset][aom_read_symbol( |
| 983 | r, ec_ctx->inter_ext_tx_cdf[eset][square_tx_size], |
| 984 | ext_tx_cnt_inter[eset], ACCT_STR)]; |
| 985 | if (counts) ++counts->inter_ext_tx[eset][square_tx_size][*tx_type]; |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 986 | } else if (ALLOW_INTRA_EXT_TX) { |
Sarah Parker | 784596d | 2017-06-23 08:41:26 -0700 | [diff] [blame] | 987 | *tx_type = av1_ext_tx_intra_inv[eset][aom_read_symbol( |
| 988 | r, ec_ctx->intra_ext_tx_cdf[eset][square_tx_size][mbmi->mode], |
| 989 | ext_tx_cnt_intra[eset], ACCT_STR)]; |
| 990 | if (counts) |
| 991 | ++counts->intra_ext_tx[eset][square_tx_size][mbmi->mode][*tx_type]; |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 992 | } |
| 993 | } else { |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 994 | *tx_type = DCT_DCT; |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 995 | } |
| 996 | #else |
Yue Chen | eeacc4c | 2017-01-17 17:29:17 -0800 | [diff] [blame] | 997 | |
| 998 | if (tx_size < TX_32X32 && |
| 999 | ((!cm->seg.enabled && cm->base_qindex > 0) || |
| 1000 | (cm->seg.enabled && xd->qindex[mbmi->segment_id] > 0)) && |
| 1001 | !mbmi->skip && |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 1002 | #if CONFIG_SUPERTX |
| 1003 | !supertx_enabled && |
| 1004 | #endif // CONFIG_SUPERTX |
| 1005 | !segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { |
| 1006 | FRAME_COUNTS *counts = xd->counts; |
Yue Chen | eeacc4c | 2017-01-17 17:29:17 -0800 | [diff] [blame] | 1007 | |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 1008 | if (inter_block) { |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 1009 | *tx_type = av1_ext_tx_inv[aom_read_symbol( |
Thomas Davies | cef0962 | 2017-01-11 17:27:12 +0000 | [diff] [blame] | 1010 | r, ec_ctx->inter_ext_tx_cdf[tx_size], TX_TYPES, ACCT_STR)]; |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 1011 | if (counts) ++counts->inter_ext_tx[tx_size][*tx_type]; |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 1012 | } else { |
| 1013 | const TX_TYPE tx_type_nom = intra_mode_to_tx_type_context[mbmi->mode]; |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 1014 | *tx_type = av1_ext_tx_inv[aom_read_symbol( |
Thomas Davies | cef0962 | 2017-01-11 17:27:12 +0000 | [diff] [blame] | 1015 | r, ec_ctx->intra_ext_tx_cdf[tx_size][tx_type_nom], TX_TYPES, |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 1016 | ACCT_STR)]; |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 1017 | if (counts) ++counts->intra_ext_tx[tx_size][tx_type_nom][*tx_type]; |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 1018 | } |
| 1019 | } else { |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 1020 | *tx_type = DCT_DCT; |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 1021 | } |
| 1022 | #endif // CONFIG_EXT_TX |
| 1023 | } |
Nathan E. Egge | ebced37 | 2017-02-17 20:57:21 -0500 | [diff] [blame] | 1024 | #if FIXED_TX_TYPE |
| 1025 | assert(mbmi->tx_type == DCT_DCT); |
| 1026 | #endif |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 1027 | } |
| 1028 | |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 1029 | #if CONFIG_INTRABC |
| 1030 | static INLINE void read_mv(aom_reader *r, MV *mv, const MV *ref, |
| 1031 | nmv_context *ctx, nmv_context_counts *counts, |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1032 | MvSubpelPrecision precision); |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 1033 | |
| 1034 | static INLINE int is_mv_valid(const MV *mv); |
| 1035 | |
| 1036 | static INLINE int assign_dv(AV1_COMMON *cm, MACROBLOCKD *xd, int_mv *mv, |
| 1037 | const int_mv *ref_mv, int mi_row, int mi_col, |
| 1038 | BLOCK_SIZE bsize, aom_reader *r) { |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 1039 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
| 1040 | (void)cm; |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 1041 | FRAME_COUNTS *counts = xd->counts; |
| 1042 | nmv_context_counts *const dv_counts = counts ? &counts->dv : NULL; |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1043 | read_mv(r, &mv->as_mv, &ref_mv->as_mv, &ec_ctx->ndvc, dv_counts, |
| 1044 | MV_SUBPEL_NONE); |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 1045 | int valid = is_mv_valid(&mv->as_mv) && |
| 1046 | is_dv_valid(mv->as_mv, &xd->tile, mi_row, mi_col, bsize); |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 1047 | return valid; |
| 1048 | } |
| 1049 | #endif // CONFIG_INTRABC |
| 1050 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1051 | static void read_intra_frame_mode_info(AV1_COMMON *const cm, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1052 | MACROBLOCKD *const xd, int mi_row, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1053 | int mi_col, aom_reader *r) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1054 | MODE_INFO *const mi = xd->mi[0]; |
| 1055 | MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 1056 | const MODE_INFO *above_mi = xd->above_mi; |
| 1057 | const MODE_INFO *left_mi = xd->left_mi; |
| 1058 | const BLOCK_SIZE bsize = mbmi->sb_type; |
| 1059 | int i; |
| 1060 | const int mi_offset = mi_row * cm->mi_cols + mi_col; |
Jingning Han | 85dc03f | 2016-12-06 16:03:10 -0800 | [diff] [blame] | 1061 | const int bw = mi_size_wide[bsize]; |
| 1062 | const int bh = mi_size_high[bsize]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1063 | |
| 1064 | // TODO(slavarnway): move x_mis, y_mis into xd ????? |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1065 | const int x_mis = AOMMIN(cm->mi_cols - mi_col, bw); |
| 1066 | const int y_mis = AOMMIN(cm->mi_rows - mi_row, bh); |
Thomas Davies | 1bfb5ed | 2017-01-11 15:28:11 +0000 | [diff] [blame] | 1067 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1068 | |
| 1069 | mbmi->segment_id = read_intra_segment_id(cm, xd, mi_offset, x_mis, y_mis, r); |
| 1070 | mbmi->skip = read_skip(cm, xd, mbmi->segment_id, r); |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 1071 | |
| 1072 | #if CONFIG_DELTA_Q |
| 1073 | if (cm->delta_q_present_flag) { |
Thomas Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 1074 | xd->current_qindex = |
| 1075 | xd->prev_qindex + |
| 1076 | read_delta_qindex(cm, xd, r, mbmi, mi_col, mi_row) * cm->delta_q_res; |
Arild Fuldseth (arilfuld) | 54de7d6 | 2017-03-20 13:07:11 +0100 | [diff] [blame] | 1077 | /* Normative: Clamp to [1,MAXQ] to not interfere with lossless mode */ |
| 1078 | xd->current_qindex = clamp(xd->current_qindex, 1, MAXQ); |
Thomas Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 1079 | xd->prev_qindex = xd->current_qindex; |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 1080 | #if CONFIG_EXT_DELTA_Q |
| 1081 | if (cm->delta_lf_present_flag) { |
| 1082 | mbmi->current_delta_lf_from_base = xd->current_delta_lf_from_base = |
| 1083 | xd->prev_delta_lf_from_base + |
| 1084 | read_delta_lflevel(cm, xd, r, mbmi, mi_col, mi_row) * |
| 1085 | cm->delta_lf_res; |
| 1086 | xd->prev_delta_lf_from_base = xd->current_delta_lf_from_base; |
| 1087 | } |
| 1088 | #endif |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 1089 | } |
| 1090 | #endif |
| 1091 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1092 | mbmi->ref_frame[0] = INTRA_FRAME; |
Emil Keyder | 01770b3 | 2017-01-20 18:03:11 -0500 | [diff] [blame] | 1093 | mbmi->ref_frame[1] = NONE_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1094 | |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 1095 | #if CONFIG_INTRABC |
| 1096 | if (bsize >= BLOCK_8X8 && cm->allow_screen_content_tools) { |
Alex Converse | 7c412ea | 2017-06-01 15:16:22 -0700 | [diff] [blame] | 1097 | mbmi->use_intrabc = aom_read(r, ec_ctx->intrabc_prob, ACCT_STR); |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 1098 | if (mbmi->use_intrabc) { |
Alex Converse | f71808c | 2017-06-06 12:21:17 -0700 | [diff] [blame] | 1099 | mbmi->tx_size = read_tx_size(cm, xd, 1, !mbmi->skip, r); |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 1100 | mbmi->mode = mbmi->uv_mode = UV_DC_PRED; |
Jingning Han | d6c17d9 | 2017-04-24 16:33:12 -0700 | [diff] [blame] | 1101 | #if CONFIG_DUAL_FILTER |
| 1102 | for (int idx = 0; idx < 4; ++idx) mbmi->interp_filter[idx] = BILINEAR; |
| 1103 | #else |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 1104 | mbmi->interp_filter = BILINEAR; |
Jingning Han | d6c17d9 | 2017-04-24 16:33:12 -0700 | [diff] [blame] | 1105 | #endif |
Alex Converse | 44c2bad | 2017-05-11 09:36:10 -0700 | [diff] [blame] | 1106 | |
| 1107 | int16_t inter_mode_ctx[MODE_CTX_REF_FRAMES]; |
| 1108 | int_mv ref_mvs[MAX_MV_REF_CANDIDATES] = {}; |
| 1109 | |
| 1110 | av1_find_mv_refs(cm, xd, mi, INTRA_FRAME, &xd->ref_mv_count[INTRA_FRAME], |
| 1111 | xd->ref_mv_stack[INTRA_FRAME], |
| 1112 | #if CONFIG_EXT_INTER |
Yue Chen | f03907a | 2017-05-31 12:04:04 -0700 | [diff] [blame] | 1113 | NULL, |
Alex Converse | 44c2bad | 2017-05-11 09:36:10 -0700 | [diff] [blame] | 1114 | #endif // CONFIG_EXT_INTER |
| 1115 | ref_mvs, mi_row, mi_col, NULL, NULL, inter_mode_ctx); |
| 1116 | |
| 1117 | int_mv nearestmv, nearmv; |
| 1118 | av1_find_best_ref_mvs(0, ref_mvs, &nearestmv, &nearmv); |
| 1119 | |
| 1120 | int_mv dv_ref = nearestmv.as_int == 0 ? nearmv : nearestmv; |
| 1121 | if (dv_ref.as_int == 0) av1_find_ref_dv(&dv_ref, mi_row, mi_col); |
| 1122 | |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 1123 | xd->corrupted |= |
| 1124 | !assign_dv(cm, xd, &mbmi->mv[0], &dv_ref, mi_row, mi_col, bsize, r); |
Alex Converse | e16b266 | 2017-05-24 14:00:00 -0700 | [diff] [blame] | 1125 | #if CONFIG_VAR_TX |
| 1126 | // TODO(aconverse@google.com): Evaluate allowing VAR TX on intrabc blocks |
| 1127 | const int width = block_size_wide[bsize] >> tx_size_wide_log2[0]; |
| 1128 | const int height = block_size_high[bsize] >> tx_size_high_log2[0]; |
| 1129 | int idx, idy; |
| 1130 | for (idy = 0; idy < height; ++idy) |
| 1131 | for (idx = 0; idx < width; ++idx) |
| 1132 | mbmi->inter_tx_size[idy >> 1][idx >> 1] = mbmi->tx_size; |
| 1133 | mbmi->min_tx_size = get_min_tx_size(mbmi->tx_size); |
| 1134 | #endif // CONFIG_VAR_TX |
Alex Converse | daa15e4 | 2017-05-02 14:27:16 -0700 | [diff] [blame] | 1135 | #if CONFIG_EXT_TX && !CONFIG_TXK_SEL |
| 1136 | av1_read_tx_type(cm, xd, |
| 1137 | #if CONFIG_SUPERTX |
| 1138 | 0, |
| 1139 | #endif |
| 1140 | r); |
| 1141 | #endif // CONFIG_EXT_TX && !CONFIG_TXK_SEL |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 1142 | return; |
| 1143 | } |
| 1144 | } |
| 1145 | #endif // CONFIG_INTRABC |
| 1146 | |
Alex Converse | f71808c | 2017-06-06 12:21:17 -0700 | [diff] [blame] | 1147 | mbmi->tx_size = read_tx_size(cm, xd, 0, 1, r); |
| 1148 | |
Jingning Han | 5226184 | 2016-12-14 12:17:49 -0800 | [diff] [blame] | 1149 | #if CONFIG_CB4X4 |
| 1150 | (void)i; |
| 1151 | mbmi->mode = |
Thomas Davies | 1bfb5ed | 2017-01-11 15:28:11 +0000 | [diff] [blame] | 1152 | read_intra_mode(r, get_y_mode_cdf(ec_ctx, mi, above_mi, left_mi, 0)); |
Jingning Han | 5226184 | 2016-12-14 12:17:49 -0800 | [diff] [blame] | 1153 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1154 | switch (bsize) { |
| 1155 | case BLOCK_4X4: |
| 1156 | for (i = 0; i < 4; ++i) |
Nathan E. Egge | 476c63c | 2017-05-18 18:35:16 -0400 | [diff] [blame] | 1157 | mi->bmi[i].as_mode = read_intra_mode( |
| 1158 | r, get_y_mode_cdf(ec_ctx, mi, above_mi, left_mi, i)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1159 | mbmi->mode = mi->bmi[3].as_mode; |
| 1160 | break; |
| 1161 | case BLOCK_4X8: |
| 1162 | mi->bmi[0].as_mode = mi->bmi[2].as_mode = |
Thomas Davies | 1bfb5ed | 2017-01-11 15:28:11 +0000 | [diff] [blame] | 1163 | read_intra_mode(r, get_y_mode_cdf(ec_ctx, mi, above_mi, left_mi, 0)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1164 | mi->bmi[1].as_mode = mi->bmi[3].as_mode = mbmi->mode = |
Thomas Davies | 1bfb5ed | 2017-01-11 15:28:11 +0000 | [diff] [blame] | 1165 | read_intra_mode(r, get_y_mode_cdf(ec_ctx, mi, above_mi, left_mi, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1166 | break; |
| 1167 | case BLOCK_8X4: |
| 1168 | mi->bmi[0].as_mode = mi->bmi[1].as_mode = |
Thomas Davies | 1bfb5ed | 2017-01-11 15:28:11 +0000 | [diff] [blame] | 1169 | read_intra_mode(r, get_y_mode_cdf(ec_ctx, mi, above_mi, left_mi, 0)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1170 | mi->bmi[2].as_mode = mi->bmi[3].as_mode = mbmi->mode = |
Thomas Davies | 1bfb5ed | 2017-01-11 15:28:11 +0000 | [diff] [blame] | 1171 | read_intra_mode(r, get_y_mode_cdf(ec_ctx, mi, above_mi, left_mi, 2)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1172 | break; |
| 1173 | default: |
| 1174 | mbmi->mode = |
Thomas Davies | 1bfb5ed | 2017-01-11 15:28:11 +0000 | [diff] [blame] | 1175 | read_intra_mode(r, get_y_mode_cdf(ec_ctx, mi, above_mi, left_mi, 0)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1176 | } |
Jingning Han | 5226184 | 2016-12-14 12:17:49 -0800 | [diff] [blame] | 1177 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1178 | |
Jingning Han | 36fe320 | 2017-02-20 22:31:49 -0800 | [diff] [blame] | 1179 | #if CONFIG_CB4X4 |
Jingning Han | d3a6443 | 2017-04-06 17:04:17 -0700 | [diff] [blame] | 1180 | if (is_chroma_reference(mi_row, mi_col, bsize, xd->plane[1].subsampling_x, |
Luc Trudeau | 2c31790 | 2017-04-28 11:06:50 -0400 | [diff] [blame] | 1181 | xd->plane[1].subsampling_y)) { |
Nathan E. Egge | a1f80e3 | 2017-05-23 11:52:32 -0400 | [diff] [blame] | 1182 | mbmi->uv_mode = read_intra_mode_uv(ec_ctx, xd, r, mbmi->mode); |
Jingning Han | 36fe320 | 2017-02-20 22:31:49 -0800 | [diff] [blame] | 1183 | #else |
Nathan E. Egge | a1f80e3 | 2017-05-23 11:52:32 -0400 | [diff] [blame] | 1184 | mbmi->uv_mode = read_intra_mode_uv(ec_ctx, xd, r, mbmi->mode); |
Jingning Han | 36fe320 | 2017-02-20 22:31:49 -0800 | [diff] [blame] | 1185 | #endif |
| 1186 | |
Luc Trudeau | f533400 | 2017-04-25 12:21:26 -0400 | [diff] [blame] | 1187 | #if CONFIG_CFL |
Luc Trudeau | 2c31790 | 2017-04-28 11:06:50 -0400 | [diff] [blame] | 1188 | // TODO(ltrudeau) support PALETTE |
Luc Trudeau | 6e1cd78 | 2017-06-21 13:52:36 -0400 | [diff] [blame] | 1189 | if (mbmi->uv_mode == UV_CFL_PRED) { |
David Michael Barr | f6eaa15 | 2017-07-19 19:42:28 +0900 | [diff] [blame] | 1190 | mbmi->cfl_alpha_idx = read_cfl_alphas(ec_ctx, r, &mbmi->cfl_alpha_signs); |
Luc Trudeau | f533400 | 2017-04-25 12:21:26 -0400 | [diff] [blame] | 1191 | } |
Luc Trudeau | 2c31790 | 2017-04-28 11:06:50 -0400 | [diff] [blame] | 1192 | #endif // CONFIG_CFL |
| 1193 | |
| 1194 | #if CONFIG_CB4X4 |
Joe Young | 830d4ce | 2017-05-30 17:48:13 -0700 | [diff] [blame] | 1195 | } else { |
| 1196 | // Avoid decoding angle_info if there is is no chroma prediction |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 1197 | mbmi->uv_mode = UV_DC_PRED; |
Luc Trudeau | f533400 | 2017-04-25 12:21:26 -0400 | [diff] [blame] | 1198 | } |
| 1199 | #endif |
| 1200 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1201 | #if CONFIG_EXT_INTRA |
| 1202 | read_intra_angle_info(cm, xd, r); |
| 1203 | #endif // CONFIG_EXT_INTRA |
| 1204 | mbmi->palette_mode_info.palette_size[0] = 0; |
| 1205 | mbmi->palette_mode_info.palette_size[1] = 0; |
Rupert Swarbrick | 6f9cd94 | 2017-08-02 15:57:18 +0100 | [diff] [blame] | 1206 | if (bsize >= BLOCK_8X8 && bsize <= BLOCK_LARGEST && |
| 1207 | cm->allow_screen_content_tools) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1208 | read_palette_mode_info(cm, xd, r); |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 1209 | #if CONFIG_FILTER_INTRA |
| 1210 | mbmi->filter_intra_mode_info.use_filter_intra_mode[0] = 0; |
| 1211 | mbmi->filter_intra_mode_info.use_filter_intra_mode[1] = 0; |
Jingning Han | 48b1cb3 | 2017-01-23 10:26:14 -0800 | [diff] [blame] | 1212 | if (bsize >= BLOCK_8X8 || CONFIG_CB4X4) |
Jingning Han | 62946d1 | 2017-05-26 11:29:30 -0700 | [diff] [blame] | 1213 | read_filter_intra_mode_info(cm, xd, mi_row, mi_col, r); |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 1214 | #endif // CONFIG_FILTER_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1215 | |
Angie Chiang | cd9b03f | 2017-04-16 13:37:13 -0700 | [diff] [blame] | 1216 | #if !CONFIG_TXK_SEL |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 1217 | av1_read_tx_type(cm, xd, |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 1218 | #if CONFIG_SUPERTX |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 1219 | 0, |
Nathan E. Egge | 72762a2 | 2016-09-07 17:12:07 -0400 | [diff] [blame] | 1220 | #endif |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 1221 | r); |
Angie Chiang | cd9b03f | 2017-04-16 13:37:13 -0700 | [diff] [blame] | 1222 | #endif // !CONFIG_TXK_SEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1223 | } |
| 1224 | |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1225 | static int read_mv_component(aom_reader *r, nmv_component *mvcomp, |
| 1226 | #if CONFIG_INTRABC |
| 1227 | int use_subpel, |
| 1228 | #endif // CONFIG_INTRABC |
| 1229 | int usehp) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1230 | int mag, d, fr, hp; |
Thomas Davies | 599395e | 2017-07-21 18:02:48 +0100 | [diff] [blame] | 1231 | #if CONFIG_NEW_MULTISYMBOL |
| 1232 | const int sign = aom_read_bit(r, ACCT_STR); |
| 1233 | #else |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 1234 | const int sign = aom_read(r, mvcomp->sign, ACCT_STR); |
Thomas Davies | 599395e | 2017-07-21 18:02:48 +0100 | [diff] [blame] | 1235 | #endif |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 1236 | const int mv_class = |
Nathan E. Egge | d7b893c | 2016-09-08 15:08:48 -0400 | [diff] [blame] | 1237 | aom_read_symbol(r, mvcomp->class_cdf, MV_CLASSES, ACCT_STR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1238 | const int class0 = mv_class == MV_CLASS_0; |
| 1239 | |
| 1240 | // Integer part |
| 1241 | if (class0) { |
Thomas Davies | 599395e | 2017-07-21 18:02:48 +0100 | [diff] [blame] | 1242 | #if CONFIG_NEW_MULTISYMBOL |
| 1243 | d = aom_read_symbol(r, mvcomp->class0_cdf, CLASS0_SIZE, ACCT_STR); |
| 1244 | #else |
Nathan E. Egge | 45ea963 | 2016-09-08 17:25:49 -0400 | [diff] [blame] | 1245 | d = aom_read(r, mvcomp->class0[0], ACCT_STR); |
Thomas Davies | 599395e | 2017-07-21 18:02:48 +0100 | [diff] [blame] | 1246 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1247 | mag = 0; |
| 1248 | } else { |
| 1249 | int i; |
| 1250 | const int n = mv_class + CLASS0_BITS - 1; // number of bits |
| 1251 | |
| 1252 | d = 0; |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 1253 | for (i = 0; i < n; ++i) d |= aom_read(r, mvcomp->bits[i], ACCT_STR) << i; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1254 | mag = CLASS0_SIZE << (mv_class + 2); |
| 1255 | } |
| 1256 | |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1257 | #if CONFIG_INTRABC |
| 1258 | if (use_subpel) { |
| 1259 | #endif // CONFIG_INTRABC |
| 1260 | // Fractional part |
| 1261 | fr = aom_read_symbol(r, class0 ? mvcomp->class0_fp_cdf[d] : mvcomp->fp_cdf, |
| 1262 | MV_FP_SIZE, ACCT_STR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1263 | |
Thomas Davies | 599395e | 2017-07-21 18:02:48 +0100 | [diff] [blame] | 1264 | // High precision part (if hp is not used, the default value of the hp is 1) |
| 1265 | #if CONFIG_NEW_MULTISYMBOL |
| 1266 | hp = usehp ? aom_read_symbol( |
| 1267 | r, class0 ? mvcomp->class0_hp_cdf : mvcomp->hp_cdf, 2, |
| 1268 | ACCT_STR) |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1269 | : 1; |
Thomas Davies | 599395e | 2017-07-21 18:02:48 +0100 | [diff] [blame] | 1270 | #else |
| 1271 | hp = usehp ? aom_read(r, class0 ? mvcomp->class0_hp : mvcomp->hp, ACCT_STR) |
| 1272 | : 1; |
| 1273 | #endif |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1274 | #if CONFIG_INTRABC |
| 1275 | } else { |
| 1276 | fr = 3; |
| 1277 | hp = 1; |
| 1278 | } |
| 1279 | #endif // CONFIG_INTRABC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1280 | |
| 1281 | // Result |
| 1282 | mag += ((d << 3) | (fr << 1) | hp) + 1; |
| 1283 | return sign ? -mag : mag; |
| 1284 | } |
| 1285 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1286 | static INLINE void read_mv(aom_reader *r, MV *mv, const MV *ref, |
Thomas | 9ac5508 | 2016-09-23 18:04:17 +0100 | [diff] [blame] | 1287 | nmv_context *ctx, nmv_context_counts *counts, |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1288 | MvSubpelPrecision precision) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1289 | MV_JOINT_TYPE joint_type; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1290 | MV diff = { 0, 0 }; |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 1291 | joint_type = |
Nathan E. Egge | 5f7fd7a | 2016-09-08 11:22:03 -0400 | [diff] [blame] | 1292 | (MV_JOINT_TYPE)aom_read_symbol(r, ctx->joint_cdf, MV_JOINTS, ACCT_STR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1293 | |
| 1294 | if (mv_joint_vertical(joint_type)) |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1295 | diff.row = read_mv_component(r, &ctx->comps[0], |
| 1296 | #if CONFIG_INTRABC |
| 1297 | precision > MV_SUBPEL_NONE, |
| 1298 | #endif // CONFIG_INTRABC |
| 1299 | precision > MV_SUBPEL_LOW_PRECISION); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1300 | |
| 1301 | if (mv_joint_horizontal(joint_type)) |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1302 | diff.col = read_mv_component(r, &ctx->comps[1], |
| 1303 | #if CONFIG_INTRABC |
| 1304 | precision > MV_SUBPEL_NONE, |
| 1305 | #endif // CONFIG_INTRABC |
| 1306 | precision > MV_SUBPEL_LOW_PRECISION); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1307 | |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1308 | av1_inc_mv(&diff, counts, precision); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1309 | |
| 1310 | mv->row = ref->row + diff.row; |
| 1311 | mv->col = ref->col + diff.col; |
| 1312 | } |
| 1313 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1314 | static REFERENCE_MODE read_block_reference_mode(AV1_COMMON *cm, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1315 | const MACROBLOCKD *xd, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1316 | aom_reader *r) { |
Jingning Han | 6b06472 | 2017-05-01 09:48:18 -0700 | [diff] [blame] | 1317 | #if !SUB8X8_COMP_REF |
Jingning Han | 69d2101 | 2017-05-14 16:51:27 -0700 | [diff] [blame] | 1318 | if (xd->mi[0]->mbmi.sb_type == BLOCK_4X4) return SINGLE_REFERENCE; |
Jingning Han | 6b06472 | 2017-05-01 09:48:18 -0700 | [diff] [blame] | 1319 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1320 | if (cm->reference_mode == REFERENCE_MODE_SELECT) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1321 | const int ctx = av1_get_reference_mode_context(cm, xd); |
Thomas Davies | 8c9bcdf | 2017-06-21 10:12:48 +0100 | [diff] [blame] | 1322 | #if CONFIG_NEW_MULTISYMBOL |
| 1323 | const REFERENCE_MODE mode = (REFERENCE_MODE)aom_read_symbol( |
| 1324 | r, xd->tile_ctx->comp_inter_cdf[ctx], 2, ACCT_STR); |
| 1325 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1326 | const REFERENCE_MODE mode = |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 1327 | (REFERENCE_MODE)aom_read(r, cm->fc->comp_inter_prob[ctx], ACCT_STR); |
Thomas Davies | 8c9bcdf | 2017-06-21 10:12:48 +0100 | [diff] [blame] | 1328 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1329 | FRAME_COUNTS *counts = xd->counts; |
| 1330 | if (counts) ++counts->comp_inter[ctx][mode]; |
| 1331 | return mode; // SINGLE_REFERENCE or COMPOUND_REFERENCE |
| 1332 | } else { |
| 1333 | return cm->reference_mode; |
| 1334 | } |
| 1335 | } |
| 1336 | |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1337 | #if CONFIG_NEW_MULTISYMBOL |
| 1338 | #define READ_REF_BIT(pname) \ |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 1339 | aom_read_symbol(r, av1_get_pred_cdf_##pname(cm, xd), 2, ACCT_STR) |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1340 | #else |
| 1341 | #define READ_REF_BIT(pname) \ |
| 1342 | aom_read(r, av1_get_pred_prob_##pname(cm, xd), ACCT_STR) |
| 1343 | #endif |
| 1344 | |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1345 | #if CONFIG_EXT_COMP_REFS |
| 1346 | static REFERENCE_MODE read_comp_reference_type(AV1_COMMON *cm, |
| 1347 | const MACROBLOCKD *xd, |
| 1348 | aom_reader *r) { |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 1349 | const int ctx = av1_get_comp_reference_type_context(xd); |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1350 | #if USE_UNI_COMP_REFS |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 1351 | COMP_REFERENCE_TYPE comp_ref_type; |
| 1352 | #if CONFIG_VAR_REFS |
| 1353 | if ((L_OR_L2(cm) || L3_OR_G(cm)) && BWD_OR_ALT(cm)) |
| 1354 | if (L_AND_L2(cm) || L_AND_L3(cm) || L_AND_G(cm) || BWD_AND_ALT(cm)) |
| 1355 | #endif // CONFIG_VAR_REFS |
| 1356 | comp_ref_type = (COMP_REFERENCE_TYPE)aom_read( |
| 1357 | r, cm->fc->comp_ref_type_prob[ctx], ACCT_STR); |
| 1358 | #if CONFIG_VAR_REFS |
| 1359 | else |
| 1360 | comp_ref_type = BIDIR_COMP_REFERENCE; |
| 1361 | else |
| 1362 | comp_ref_type = UNIDIR_COMP_REFERENCE; |
| 1363 | #endif // CONFIG_VAR_REFS |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1364 | #else // !USE_UNI_COMP_REFS |
| 1365 | // TODO(zoeliu): Temporarily turn off uni-directional comp refs |
| 1366 | const COMP_REFERENCE_TYPE comp_ref_type = BIDIR_COMP_REFERENCE; |
| 1367 | #endif // USE_UNI_COMP_REFS |
| 1368 | FRAME_COUNTS *counts = xd->counts; |
| 1369 | if (counts) ++counts->comp_ref_type[ctx][comp_ref_type]; |
| 1370 | return comp_ref_type; // UNIDIR_COMP_REFERENCE or BIDIR_COMP_REFERENCE |
| 1371 | } |
| 1372 | #endif // CONFIG_EXT_COMP_REFS |
| 1373 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1374 | // Read the referncence frame |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1375 | static void read_ref_frames(AV1_COMMON *const cm, MACROBLOCKD *const xd, |
| 1376 | aom_reader *r, int segment_id, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1377 | MV_REFERENCE_FRAME ref_frame[2]) { |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 1378 | #if CONFIG_EXT_COMP_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1379 | FRAME_CONTEXT *const fc = cm->fc; |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 1380 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1381 | FRAME_COUNTS *counts = xd->counts; |
| 1382 | |
| 1383 | if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) { |
| 1384 | ref_frame[0] = (MV_REFERENCE_FRAME)get_segdata(&cm->seg, segment_id, |
| 1385 | SEG_LVL_REF_FRAME); |
Emil Keyder | 01770b3 | 2017-01-20 18:03:11 -0500 | [diff] [blame] | 1386 | ref_frame[1] = NONE_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1387 | } else { |
| 1388 | const REFERENCE_MODE mode = read_block_reference_mode(cm, xd, r); |
| 1389 | // FIXME(rbultje) I'm pretty sure this breaks segmentation ref frame coding |
| 1390 | if (mode == COMPOUND_REFERENCE) { |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1391 | #if CONFIG_EXT_COMP_REFS |
| 1392 | const COMP_REFERENCE_TYPE comp_ref_type = |
| 1393 | read_comp_reference_type(cm, xd, r); |
| 1394 | |
| 1395 | #if !USE_UNI_COMP_REFS |
| 1396 | // TODO(zoeliu): Temporarily turn off uni-directional comp refs |
| 1397 | assert(comp_ref_type == BIDIR_COMP_REFERENCE); |
| 1398 | #endif // !USE_UNI_COMP_REFS |
| 1399 | |
| 1400 | if (comp_ref_type == UNIDIR_COMP_REFERENCE) { |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 1401 | const int ctx = av1_get_pred_context_uni_comp_ref_p(xd); |
| 1402 | int bit; |
| 1403 | #if CONFIG_VAR_REFS |
| 1404 | if ((L_AND_L2(cm) || L_AND_L3(cm) || L_AND_G(cm)) && BWD_AND_ALT(cm)) |
| 1405 | #endif // CONFIG_VAR_REFS |
| 1406 | bit = aom_read(r, fc->uni_comp_ref_prob[ctx][0], ACCT_STR); |
| 1407 | #if CONFIG_VAR_REFS |
| 1408 | else |
| 1409 | bit = BWD_AND_ALT(cm); |
| 1410 | #endif // CONFIG_VAR_REFS |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1411 | if (counts) ++counts->uni_comp_ref[ctx][0][bit]; |
| 1412 | |
| 1413 | if (bit) { |
| 1414 | ref_frame[0] = BWDREF_FRAME; |
| 1415 | ref_frame[1] = ALTREF_FRAME; |
| 1416 | } else { |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 1417 | const int ctx1 = av1_get_pred_context_uni_comp_ref_p1(xd); |
| 1418 | int bit1; |
| 1419 | #if CONFIG_VAR_REFS |
| 1420 | if (L_AND_L2(cm) && (L_AND_L3(cm) || L_AND_G(cm))) |
| 1421 | #endif // CONFIG_VAR_REFS |
| 1422 | bit1 = aom_read(r, fc->uni_comp_ref_prob[ctx1][1], ACCT_STR); |
| 1423 | #if CONFIG_VAR_REFS |
| 1424 | else |
| 1425 | bit1 = L_AND_L3(cm) || L_AND_G(cm); |
| 1426 | #endif // CONFIG_VAR_REFS |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1427 | if (counts) ++counts->uni_comp_ref[ctx1][1][bit1]; |
| 1428 | |
| 1429 | if (bit1) { |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 1430 | const int ctx2 = av1_get_pred_context_uni_comp_ref_p2(xd); |
| 1431 | int bit2; |
| 1432 | #if CONFIG_VAR_REFS |
| 1433 | if (L_AND_L3(cm) && L_AND_G(cm)) |
| 1434 | #endif // CONFIG_VAR_REFS |
| 1435 | bit2 = aom_read(r, fc->uni_comp_ref_prob[ctx2][2], ACCT_STR); |
| 1436 | #if CONFIG_VAR_REFS |
| 1437 | else |
| 1438 | bit2 = L_AND_G(cm); |
| 1439 | #endif // CONFIG_VAR_REFS |
| 1440 | if (counts) ++counts->uni_comp_ref[ctx2][2][bit2]; |
| 1441 | |
| 1442 | if (bit2) { |
| 1443 | ref_frame[0] = LAST_FRAME; |
| 1444 | ref_frame[1] = GOLDEN_FRAME; |
| 1445 | } else { |
| 1446 | ref_frame[0] = LAST_FRAME; |
| 1447 | ref_frame[1] = LAST3_FRAME; |
| 1448 | } |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1449 | } else { |
| 1450 | ref_frame[0] = LAST_FRAME; |
| 1451 | ref_frame[1] = LAST2_FRAME; |
| 1452 | } |
| 1453 | } |
| 1454 | |
| 1455 | return; |
| 1456 | } |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 1457 | |
| 1458 | assert(comp_ref_type == BIDIR_COMP_REFERENCE); |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1459 | #endif // CONFIG_EXT_COMP_REFS |
| 1460 | |
| 1461 | // Normative in decoder (for low delay) |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 1462 | #if CONFIG_ONE_SIDED_COMPOUND |
Arild Fuldseth (arilfuld) | 3889730 | 2017-04-27 20:03:03 +0200 | [diff] [blame] | 1463 | const int idx = 1; |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 1464 | #else // !CONFIG_ONE_SIDED_COMPOUND |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1465 | #if CONFIG_EXT_REFS |
| 1466 | const int idx = cm->ref_frame_sign_bias[cm->comp_bwd_ref[0]]; |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1467 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1468 | const int idx = cm->ref_frame_sign_bias[cm->comp_fixed_ref]; |
| 1469 | #endif // CONFIG_EXT_REFS |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 1470 | #endif // CONFIG_ONE_SIDED_COMPOUND |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1471 | |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1472 | const int ctx = av1_get_pred_context_comp_ref_p(cm, xd); |
| 1473 | #if CONFIG_VAR_REFS |
| 1474 | int bit; |
| 1475 | // Test need to explicitly code (L,L2) vs (L3,G) branch node in tree |
| 1476 | if (L_OR_L2(cm) && L3_OR_G(cm)) |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 1477 | bit = READ_REF_BIT(comp_ref_p); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1478 | else |
| 1479 | bit = L3_OR_G(cm); |
| 1480 | #else // !CONFIG_VAR_REFS |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 1481 | const int bit = READ_REF_BIT(comp_ref_p); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1482 | #endif // CONFIG_VAR_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1483 | if (counts) ++counts->comp_ref[ctx][0][bit]; |
| 1484 | |
| 1485 | #if CONFIG_EXT_REFS |
| 1486 | // Decode forward references. |
| 1487 | if (!bit) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1488 | const int ctx1 = av1_get_pred_context_comp_ref_p1(cm, xd); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1489 | #if CONFIG_VAR_REFS |
| 1490 | int bit1; |
| 1491 | // Test need to explicitly code (L) vs (L2) branch node in tree |
| 1492 | if (L_AND_L2(cm)) |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 1493 | bit1 = READ_REF_BIT(comp_ref_p1); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1494 | else |
| 1495 | bit1 = LAST_IS_VALID(cm); |
| 1496 | #else // !CONFIG_VAR_REFS |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 1497 | const int bit1 = READ_REF_BIT(comp_ref_p1); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1498 | #endif // CONFIG_VAR_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1499 | if (counts) ++counts->comp_ref[ctx1][1][bit1]; |
| 1500 | ref_frame[!idx] = cm->comp_fwd_ref[bit1 ? 0 : 1]; |
| 1501 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1502 | const int ctx2 = av1_get_pred_context_comp_ref_p2(cm, xd); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1503 | #if CONFIG_VAR_REFS |
| 1504 | int bit2; |
| 1505 | // Test need to explicitly code (L3) vs (G) branch node in tree |
| 1506 | if (L3_AND_G(cm)) |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 1507 | bit2 = READ_REF_BIT(comp_ref_p2); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1508 | else |
| 1509 | bit2 = GOLDEN_IS_VALID(cm); |
| 1510 | #else // !CONFIG_VAR_REFS |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 1511 | const int bit2 = READ_REF_BIT(comp_ref_p2); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1512 | #endif // CONFIG_VAR_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1513 | if (counts) ++counts->comp_ref[ctx2][2][bit2]; |
| 1514 | ref_frame[!idx] = cm->comp_fwd_ref[bit2 ? 3 : 2]; |
| 1515 | } |
| 1516 | |
| 1517 | // Decode backward references. |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1518 | const int ctx_bwd = av1_get_pred_context_comp_bwdref_p(cm, xd); |
| 1519 | #if CONFIG_VAR_REFS |
| 1520 | int bit_bwd; |
Zoe Liu | 043c227 | 2017-07-19 12:40:29 -0700 | [diff] [blame] | 1521 | // Test need to explicitly code (BWD/ALT2) vs (ALT) branch node in tree |
| 1522 | #if CONFIG_ALTREF2 |
| 1523 | const int bit_bwd_uncertain = BWD_OR_ALT2(cm) && ALTREF_IS_VALID(cm); |
| 1524 | #else // !CONFIG_ALTREF2 |
| 1525 | const int bit_bwd_uncertain = BWD_AND_ALT(cm); |
| 1526 | #endif // CONFIG_ALTREF2 |
| 1527 | if (bit_bwd_uncertain) |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 1528 | bit_bwd = READ_REF_BIT(comp_bwdref_p); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1529 | else |
| 1530 | bit_bwd = ALTREF_IS_VALID(cm); |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 1531 | #else // !CONFIG_VAR_REFS |
| 1532 | const int bit_bwd = READ_REF_BIT(comp_bwdref_p); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1533 | #endif // CONFIG_VAR_REFS |
| 1534 | if (counts) ++counts->comp_bwdref[ctx_bwd][0][bit_bwd]; |
Zoe Liu | 043c227 | 2017-07-19 12:40:29 -0700 | [diff] [blame] | 1535 | #if CONFIG_ALTREF2 |
| 1536 | if (!bit_bwd) { |
| 1537 | const int ctx1_bwd = av1_get_pred_context_comp_bwdref_p1(cm, xd); |
| 1538 | #if CONFIG_VAR_REFS |
| 1539 | int bit1_bwd; |
| 1540 | if (BWD_AND_ALT2(cm)) |
| 1541 | bit1_bwd = READ_REF_BIT(comp_bwdref_p1); |
| 1542 | else |
| 1543 | bit1_bwd = ALTREF2_IS_VALID(cm); |
| 1544 | #else // !CONFIG_VAR_REFS |
| 1545 | const int bit1_bwd = READ_REF_BIT(comp_bwdref_p1); |
| 1546 | #endif // CONFIG_VAR_REFS |
| 1547 | if (counts) ++counts->comp_bwdref[ctx1_bwd][1][bit1_bwd]; |
| 1548 | ref_frame[idx] = cm->comp_bwd_ref[bit1_bwd]; |
| 1549 | } else { |
| 1550 | ref_frame[idx] = cm->comp_bwd_ref[2]; |
| 1551 | } |
| 1552 | #else // !CONFIG_ALTREF2 |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1553 | ref_frame[idx] = cm->comp_bwd_ref[bit_bwd]; |
Zoe Liu | 043c227 | 2017-07-19 12:40:29 -0700 | [diff] [blame] | 1554 | #endif // CONFIG_ALTREF2 |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1555 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1556 | ref_frame[!idx] = cm->comp_var_ref[bit]; |
| 1557 | ref_frame[idx] = cm->comp_fixed_ref; |
| 1558 | #endif // CONFIG_EXT_REFS |
| 1559 | } else if (mode == SINGLE_REFERENCE) { |
| 1560 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1561 | const int ctx0 = av1_get_pred_context_single_ref_p1(xd); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1562 | #if CONFIG_VAR_REFS |
| 1563 | int bit0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 1564 | #if CONFIG_ALTREF2 |
| 1565 | // Test need to explicitly code (L,L2,L3,G) vs (BWD,ALT2,ALT) branch node |
| 1566 | // in tree |
| 1567 | if ((L_OR_L2(cm) || L3_OR_G(cm)) && |
| 1568 | (BWD_OR_ALT2(cm) || ALTREF_IS_VALID(cm))) |
| 1569 | bit0 = READ_REF_BIT(single_ref_p1); |
| 1570 | else |
| 1571 | bit0 = (BWD_OR_ALT2(cm) || ALTREF_IS_VALID(cm)); |
| 1572 | #else // !CONFIG_ALTREF2 |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1573 | // Test need to explicitly code (L,L2,L3,G) vs (BWD,ALT) branch node in |
| 1574 | // tree |
| 1575 | if ((L_OR_L2(cm) || L3_OR_G(cm)) && BWD_OR_ALT(cm)) |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1576 | bit0 = READ_REF_BIT(single_ref_p1); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1577 | else |
| 1578 | bit0 = BWD_OR_ALT(cm); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 1579 | #endif // CONFIG_ALTREF2 |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1580 | #else // !CONFIG_VAR_REFS |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1581 | const int bit0 = READ_REF_BIT(single_ref_p1); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1582 | #endif // CONFIG_VAR_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1583 | if (counts) ++counts->single_ref[ctx0][0][bit0]; |
| 1584 | |
| 1585 | if (bit0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1586 | const int ctx1 = av1_get_pred_context_single_ref_p2(xd); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1587 | #if CONFIG_VAR_REFS |
| 1588 | int bit1; |
Zoe Liu | 043c227 | 2017-07-19 12:40:29 -0700 | [diff] [blame] | 1589 | #if CONFIG_ALTREF2 |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 1590 | // Test need to explicitly code (BWD/ALT2) vs (ALT) branch node in tree |
Zoe Liu | 043c227 | 2017-07-19 12:40:29 -0700 | [diff] [blame] | 1591 | const int bit1_uncertain = BWD_OR_ALT2(cm) && ALTREF_IS_VALID(cm); |
| 1592 | #else // !CONFIG_ALTREF2 |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 1593 | // Test need to explicitly code (BWD) vs (ALT) branch node in tree |
Zoe Liu | 043c227 | 2017-07-19 12:40:29 -0700 | [diff] [blame] | 1594 | const int bit1_uncertain = BWD_AND_ALT(cm); |
| 1595 | #endif // CONFIG_ALTREF2 |
| 1596 | if (bit1_uncertain) |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1597 | bit1 = READ_REF_BIT(single_ref_p2); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1598 | else |
| 1599 | bit1 = ALTREF_IS_VALID(cm); |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1600 | #else // !CONFIG_VAR_REFS |
| 1601 | const int bit1 = READ_REF_BIT(single_ref_p2); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1602 | #endif // CONFIG_VAR_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1603 | if (counts) ++counts->single_ref[ctx1][1][bit1]; |
Zoe Liu | 043c227 | 2017-07-19 12:40:29 -0700 | [diff] [blame] | 1604 | #if CONFIG_ALTREF2 |
| 1605 | if (!bit1) { |
| 1606 | const int ctx5 = av1_get_pred_context_single_ref_p6(xd); |
| 1607 | #if CONFIG_VAR_REFS |
| 1608 | int bit5; |
| 1609 | if (BWD_AND_ALT2(cm)) |
| 1610 | bit5 = READ_REF_BIT(single_ref_p6); |
| 1611 | else |
| 1612 | bit5 = ALTREF2_IS_VALID(cm); |
| 1613 | #else // !CONFIG_VAR_REFS |
| 1614 | const int bit5 = READ_REF_BIT(single_ref_p6); |
| 1615 | #endif // CONFIG_VAR_REFS |
| 1616 | if (counts) ++counts->single_ref[ctx5][5][bit5]; |
| 1617 | ref_frame[0] = bit5 ? ALTREF2_FRAME : BWDREF_FRAME; |
| 1618 | } else { |
| 1619 | ref_frame[0] = ALTREF_FRAME; |
| 1620 | } |
| 1621 | #else // !CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1622 | ref_frame[0] = bit1 ? ALTREF_FRAME : BWDREF_FRAME; |
Zoe Liu | 043c227 | 2017-07-19 12:40:29 -0700 | [diff] [blame] | 1623 | #endif // CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1624 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1625 | const int ctx2 = av1_get_pred_context_single_ref_p3(xd); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1626 | #if CONFIG_VAR_REFS |
| 1627 | int bit2; |
| 1628 | // Test need to explicitly code (L,L2) vs (L3,G) branch node in tree |
| 1629 | if (L_OR_L2(cm) && L3_OR_G(cm)) |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1630 | bit2 = READ_REF_BIT(single_ref_p3); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1631 | else |
| 1632 | bit2 = L3_OR_G(cm); |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1633 | #else // !CONFIG_VAR_REFS |
| 1634 | const int bit2 = READ_REF_BIT(single_ref_p3); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1635 | #endif // CONFIG_VAR_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1636 | if (counts) ++counts->single_ref[ctx2][2][bit2]; |
| 1637 | if (bit2) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1638 | const int ctx4 = av1_get_pred_context_single_ref_p5(xd); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1639 | #if CONFIG_VAR_REFS |
| 1640 | int bit4; |
| 1641 | // Test need to explicitly code (L3) vs (G) branch node in tree |
| 1642 | if (L3_AND_G(cm)) |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1643 | bit4 = READ_REF_BIT(single_ref_p5); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1644 | else |
| 1645 | bit4 = GOLDEN_IS_VALID(cm); |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1646 | #else // !CONFIG_VAR_REFS |
| 1647 | const int bit4 = READ_REF_BIT(single_ref_p5); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1648 | #endif // CONFIG_VAR_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1649 | if (counts) ++counts->single_ref[ctx4][4][bit4]; |
| 1650 | ref_frame[0] = bit4 ? GOLDEN_FRAME : LAST3_FRAME; |
| 1651 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1652 | const int ctx3 = av1_get_pred_context_single_ref_p4(xd); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1653 | #if CONFIG_VAR_REFS |
| 1654 | int bit3; |
| 1655 | // Test need to explicitly code (L) vs (L2) branch node in tree |
| 1656 | if (L_AND_L2(cm)) |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1657 | bit3 = READ_REF_BIT(single_ref_p4); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1658 | else |
| 1659 | bit3 = LAST2_IS_VALID(cm); |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1660 | #else // !CONFIG_VAR_REFS |
| 1661 | const int bit3 = READ_REF_BIT(single_ref_p4); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1662 | #endif // CONFIG_VAR_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1663 | if (counts) ++counts->single_ref[ctx3][3][bit3]; |
| 1664 | ref_frame[0] = bit3 ? LAST2_FRAME : LAST_FRAME; |
| 1665 | } |
| 1666 | } |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1667 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1668 | const int ctx0 = av1_get_pred_context_single_ref_p1(xd); |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1669 | const int bit0 = READ_REF_BIT(single_ref_p1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1670 | if (counts) ++counts->single_ref[ctx0][0][bit0]; |
| 1671 | |
| 1672 | if (bit0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1673 | const int ctx1 = av1_get_pred_context_single_ref_p2(xd); |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1674 | const int bit1 = READ_REF_BIT(single_ref_p2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1675 | if (counts) ++counts->single_ref[ctx1][1][bit1]; |
| 1676 | ref_frame[0] = bit1 ? ALTREF_FRAME : GOLDEN_FRAME; |
| 1677 | } else { |
| 1678 | ref_frame[0] = LAST_FRAME; |
| 1679 | } |
| 1680 | #endif // CONFIG_EXT_REFS |
| 1681 | |
Emil Keyder | 01770b3 | 2017-01-20 18:03:11 -0500 | [diff] [blame] | 1682 | ref_frame[1] = NONE_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1683 | } else { |
| 1684 | assert(0 && "Invalid prediction mode."); |
| 1685 | } |
| 1686 | } |
| 1687 | } |
| 1688 | |
Angie Chiang | 9c4f895 | 2016-11-21 11:13:19 -0800 | [diff] [blame] | 1689 | static INLINE void read_mb_interp_filter(AV1_COMMON *const cm, |
| 1690 | MACROBLOCKD *const xd, |
| 1691 | MB_MODE_INFO *const mbmi, |
| 1692 | aom_reader *r) { |
| 1693 | FRAME_COUNTS *counts = xd->counts; |
Thomas Davies | 77c7c40 | 2017-01-11 17:58:54 +0000 | [diff] [blame] | 1694 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
Thomas Davies | 77c7c40 | 2017-01-11 17:58:54 +0000 | [diff] [blame] | 1695 | |
Debargha Mukherjee | 0df711f | 2017-05-02 16:00:20 -0700 | [diff] [blame] | 1696 | if (!av1_is_interp_needed(xd)) { |
| 1697 | set_default_interp_filters(mbmi, cm->interp_filter); |
Yue Chen | 19e7aa8 | 2016-11-30 14:05:39 -0800 | [diff] [blame] | 1698 | return; |
| 1699 | } |
Yue Chen | 19e7aa8 | 2016-11-30 14:05:39 -0800 | [diff] [blame] | 1700 | |
| 1701 | #if CONFIG_DUAL_FILTER |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1702 | if (cm->interp_filter != SWITCHABLE) { |
Yue Chen | 19e7aa8 | 2016-11-30 14:05:39 -0800 | [diff] [blame] | 1703 | int dir; |
| 1704 | |
Angie Chiang | 9c4f895 | 2016-11-21 11:13:19 -0800 | [diff] [blame] | 1705 | for (dir = 0; dir < 4; ++dir) mbmi->interp_filter[dir] = cm->interp_filter; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1706 | } else { |
Yue Chen | 19e7aa8 | 2016-11-30 14:05:39 -0800 | [diff] [blame] | 1707 | int dir; |
| 1708 | |
Angie Chiang | 9c4f895 | 2016-11-21 11:13:19 -0800 | [diff] [blame] | 1709 | for (dir = 0; dir < 2; ++dir) { |
| 1710 | const int ctx = av1_get_pred_context_switchable_interp(xd, dir); |
| 1711 | mbmi->interp_filter[dir] = EIGHTTAP_REGULAR; |
| 1712 | |
| 1713 | if (has_subpel_mv_component(xd->mi[0], xd, dir) || |
| 1714 | (mbmi->ref_frame[1] > INTRA_FRAME && |
| 1715 | has_subpel_mv_component(xd->mi[0], xd, dir + 2))) { |
Angie Chiang | 9c4f895 | 2016-11-21 11:13:19 -0800 | [diff] [blame] | 1716 | mbmi->interp_filter[dir] = |
| 1717 | (InterpFilter)av1_switchable_interp_inv[aom_read_symbol( |
Thomas Davies | 77c7c40 | 2017-01-11 17:58:54 +0000 | [diff] [blame] | 1718 | r, ec_ctx->switchable_interp_cdf[ctx], SWITCHABLE_FILTERS, |
Angie Chiang | 9c4f895 | 2016-11-21 11:13:19 -0800 | [diff] [blame] | 1719 | ACCT_STR)]; |
Angie Chiang | 9c4f895 | 2016-11-21 11:13:19 -0800 | [diff] [blame] | 1720 | if (counts) ++counts->switchable_interp[ctx][mbmi->interp_filter[dir]]; |
| 1721 | } |
| 1722 | } |
| 1723 | // The index system works as: |
| 1724 | // (0, 1) -> (vertical, horizontal) filter types for the first ref frame. |
| 1725 | // (2, 3) -> (vertical, horizontal) filter types for the second ref frame. |
| 1726 | mbmi->interp_filter[2] = mbmi->interp_filter[0]; |
| 1727 | mbmi->interp_filter[3] = mbmi->interp_filter[1]; |
| 1728 | } |
Nathan E. Egge | 476c63c | 2017-05-18 18:35:16 -0400 | [diff] [blame] | 1729 | #else // CONFIG_DUAL_FILTER |
Angie Chiang | 9c4f895 | 2016-11-21 11:13:19 -0800 | [diff] [blame] | 1730 | if (cm->interp_filter != SWITCHABLE) { |
| 1731 | mbmi->interp_filter = cm->interp_filter; |
| 1732 | } else { |
| 1733 | const int ctx = av1_get_pred_context_switchable_interp(xd); |
Angie Chiang | 9c4f895 | 2016-11-21 11:13:19 -0800 | [diff] [blame] | 1734 | mbmi->interp_filter = |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 1735 | (InterpFilter)av1_switchable_interp_inv[aom_read_symbol( |
Thomas Davies | 77c7c40 | 2017-01-11 17:58:54 +0000 | [diff] [blame] | 1736 | r, ec_ctx->switchable_interp_cdf[ctx], SWITCHABLE_FILTERS, |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 1737 | ACCT_STR)]; |
Angie Chiang | 9c4f895 | 2016-11-21 11:13:19 -0800 | [diff] [blame] | 1738 | if (counts) ++counts->switchable_interp[ctx][mbmi->interp_filter]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1739 | } |
Angie Chiang | 9c4f895 | 2016-11-21 11:13:19 -0800 | [diff] [blame] | 1740 | #endif // CONFIG_DUAL_FILTER |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1741 | } |
| 1742 | |
Jingning Han | 36fe320 | 2017-02-20 22:31:49 -0800 | [diff] [blame] | 1743 | static void read_intra_block_mode_info(AV1_COMMON *const cm, const int mi_row, |
| 1744 | const int mi_col, MACROBLOCKD *const xd, |
| 1745 | MODE_INFO *mi, aom_reader *r) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1746 | MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 1747 | const BLOCK_SIZE bsize = mi->mbmi.sb_type; |
| 1748 | int i; |
| 1749 | |
| 1750 | mbmi->ref_frame[0] = INTRA_FRAME; |
Emil Keyder | 01770b3 | 2017-01-20 18:03:11 -0500 | [diff] [blame] | 1751 | mbmi->ref_frame[1] = NONE_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1752 | |
Nathan E. Egge | a1f80e3 | 2017-05-23 11:52:32 -0400 | [diff] [blame] | 1753 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
Nathan E. Egge | a1f80e3 | 2017-05-23 11:52:32 -0400 | [diff] [blame] | 1754 | |
Jingning Han | 5226184 | 2016-12-14 12:17:49 -0800 | [diff] [blame] | 1755 | #if CONFIG_CB4X4 |
| 1756 | (void)i; |
Nathan E. Egge | a1f80e3 | 2017-05-23 11:52:32 -0400 | [diff] [blame] | 1757 | mbmi->mode = read_intra_mode_y(ec_ctx, xd, r, size_group_lookup[bsize]); |
Jingning Han | 5226184 | 2016-12-14 12:17:49 -0800 | [diff] [blame] | 1758 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1759 | switch (bsize) { |
| 1760 | case BLOCK_4X4: |
| 1761 | for (i = 0; i < 4; ++i) |
Nathan E. Egge | a1f80e3 | 2017-05-23 11:52:32 -0400 | [diff] [blame] | 1762 | mi->bmi[i].as_mode = read_intra_mode_y(ec_ctx, xd, r, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1763 | mbmi->mode = mi->bmi[3].as_mode; |
| 1764 | break; |
| 1765 | case BLOCK_4X8: |
Nathan E. Egge | a1f80e3 | 2017-05-23 11:52:32 -0400 | [diff] [blame] | 1766 | mi->bmi[0].as_mode = mi->bmi[2].as_mode = |
| 1767 | read_intra_mode_y(ec_ctx, xd, r, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1768 | mi->bmi[1].as_mode = mi->bmi[3].as_mode = mbmi->mode = |
Nathan E. Egge | a1f80e3 | 2017-05-23 11:52:32 -0400 | [diff] [blame] | 1769 | read_intra_mode_y(ec_ctx, xd, r, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1770 | break; |
| 1771 | case BLOCK_8X4: |
Nathan E. Egge | a1f80e3 | 2017-05-23 11:52:32 -0400 | [diff] [blame] | 1772 | mi->bmi[0].as_mode = mi->bmi[1].as_mode = |
| 1773 | read_intra_mode_y(ec_ctx, xd, r, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1774 | mi->bmi[2].as_mode = mi->bmi[3].as_mode = mbmi->mode = |
Nathan E. Egge | a1f80e3 | 2017-05-23 11:52:32 -0400 | [diff] [blame] | 1775 | read_intra_mode_y(ec_ctx, xd, r, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1776 | break; |
| 1777 | default: |
Nathan E. Egge | a1f80e3 | 2017-05-23 11:52:32 -0400 | [diff] [blame] | 1778 | mbmi->mode = read_intra_mode_y(ec_ctx, xd, r, size_group_lookup[bsize]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1779 | } |
Jingning Han | 5226184 | 2016-12-14 12:17:49 -0800 | [diff] [blame] | 1780 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1781 | |
Jingning Han | 36fe320 | 2017-02-20 22:31:49 -0800 | [diff] [blame] | 1782 | #if CONFIG_CB4X4 |
Jingning Han | d3a6443 | 2017-04-06 17:04:17 -0700 | [diff] [blame] | 1783 | if (is_chroma_reference(mi_row, mi_col, bsize, xd->plane[1].subsampling_x, |
Luc Trudeau | b09b55d | 2017-04-26 10:06:35 -0400 | [diff] [blame] | 1784 | xd->plane[1].subsampling_y)) { |
Nathan E. Egge | a1f80e3 | 2017-05-23 11:52:32 -0400 | [diff] [blame] | 1785 | mbmi->uv_mode = read_intra_mode_uv(ec_ctx, xd, r, mbmi->mode); |
Jingning Han | 36fe320 | 2017-02-20 22:31:49 -0800 | [diff] [blame] | 1786 | #else |
Nathan E. Egge | a1f80e3 | 2017-05-23 11:52:32 -0400 | [diff] [blame] | 1787 | mbmi->uv_mode = read_intra_mode_uv(ec_ctx, xd, r, mbmi->mode); |
Jingning Han | 36fe320 | 2017-02-20 22:31:49 -0800 | [diff] [blame] | 1788 | (void)mi_row; |
| 1789 | (void)mi_col; |
| 1790 | #endif |
| 1791 | |
Luc Trudeau | b09b55d | 2017-04-26 10:06:35 -0400 | [diff] [blame] | 1792 | #if CONFIG_CFL |
Luc Trudeau | 6e1cd78 | 2017-06-21 13:52:36 -0400 | [diff] [blame] | 1793 | if (mbmi->uv_mode == UV_CFL_PRED) { |
Nathan E. Egge | 6bdc40f | 2017-06-18 19:02:23 -0400 | [diff] [blame] | 1794 | mbmi->cfl_alpha_idx = |
David Michael Barr | f6eaa15 | 2017-07-19 19:42:28 +0900 | [diff] [blame] | 1795 | read_cfl_alphas(xd->tile_ctx, r, &mbmi->cfl_alpha_signs); |
Luc Trudeau | b09b55d | 2017-04-26 10:06:35 -0400 | [diff] [blame] | 1796 | } |
| 1797 | #endif // CONFIG_CFL |
| 1798 | |
| 1799 | #if CONFIG_CB4X4 |
| 1800 | } |
| 1801 | #endif |
| 1802 | |
Rupert Swarbrick | 766c9d5 | 2017-07-31 11:30:53 +0100 | [diff] [blame] | 1803 | // Explicitly ignore cm here to avoid a compile warning if none of |
| 1804 | // ext-intra, palette and filter-intra are enabled. |
| 1805 | (void)cm; |
| 1806 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1807 | #if CONFIG_EXT_INTRA |
| 1808 | read_intra_angle_info(cm, xd, r); |
| 1809 | #endif // CONFIG_EXT_INTRA |
| 1810 | mbmi->palette_mode_info.palette_size[0] = 0; |
| 1811 | mbmi->palette_mode_info.palette_size[1] = 0; |
| 1812 | if (bsize >= BLOCK_8X8 && cm->allow_screen_content_tools) |
| 1813 | read_palette_mode_info(cm, xd, r); |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 1814 | #if CONFIG_FILTER_INTRA |
| 1815 | mbmi->filter_intra_mode_info.use_filter_intra_mode[0] = 0; |
| 1816 | mbmi->filter_intra_mode_info.use_filter_intra_mode[1] = 0; |
Jingning Han | 48b1cb3 | 2017-01-23 10:26:14 -0800 | [diff] [blame] | 1817 | if (bsize >= BLOCK_8X8 || CONFIG_CB4X4) |
Jingning Han | 62946d1 | 2017-05-26 11:29:30 -0700 | [diff] [blame] | 1818 | read_filter_intra_mode_info(cm, xd, mi_row, mi_col, r); |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 1819 | #endif // CONFIG_FILTER_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | static INLINE int is_mv_valid(const MV *mv) { |
| 1823 | return mv->row > MV_LOW && mv->row < MV_UPP && mv->col > MV_LOW && |
| 1824 | mv->col < MV_UPP; |
| 1825 | } |
| 1826 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1827 | static INLINE int assign_mv(AV1_COMMON *cm, MACROBLOCKD *xd, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1828 | PREDICTION_MODE mode, |
Jingning Han | 5c60cdf | 2016-09-30 09:37:46 -0700 | [diff] [blame] | 1829 | MV_REFERENCE_FRAME ref_frame[2], int block, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1830 | int_mv mv[2], int_mv ref_mv[2], |
David Barker | 45390c1 | 2017-02-20 14:44:40 +0000 | [diff] [blame] | 1831 | int_mv nearest_mv[2], int_mv near_mv[2], int mi_row, |
| 1832 | int mi_col, int is_compound, int allow_hp, |
| 1833 | aom_reader *r) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1834 | int i; |
| 1835 | int ret = 1; |
Thomas Davies | 2452329 | 2017-01-11 16:56:47 +0000 | [diff] [blame] | 1836 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
Debargha Mukherjee | f6dd3c6 | 2017-02-23 13:21:23 -0800 | [diff] [blame] | 1837 | BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1838 | MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; |
Jingning Han | 5cfa671 | 2016-12-14 09:53:38 -0800 | [diff] [blame] | 1839 | #if CONFIG_CB4X4 |
| 1840 | int_mv *pred_mv = mbmi->pred_mv; |
| 1841 | (void)block; |
| 1842 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1843 | int_mv *pred_mv = |
Yaowu Xu | f5bbbfa | 2016-09-26 09:13:38 -0700 | [diff] [blame] | 1844 | (bsize >= BLOCK_8X8) ? mbmi->pred_mv : xd->mi[0]->bmi[block].pred_mv; |
Jingning Han | 5cfa671 | 2016-12-14 09:53:38 -0800 | [diff] [blame] | 1845 | #endif // CONFIG_CB4X4 |
Sarah Parker | e529986 | 2016-08-16 14:57:37 -0700 | [diff] [blame] | 1846 | (void)ref_frame; |
Thomas Davies | 2452329 | 2017-01-11 16:56:47 +0000 | [diff] [blame] | 1847 | (void)cm; |
David Barker | 45390c1 | 2017-02-20 14:44:40 +0000 | [diff] [blame] | 1848 | (void)mi_row; |
| 1849 | (void)mi_col; |
Debargha Mukherjee | f6dd3c6 | 2017-02-23 13:21:23 -0800 | [diff] [blame] | 1850 | (void)bsize; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1851 | |
| 1852 | switch (mode) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1853 | case NEWMV: { |
| 1854 | FRAME_COUNTS *counts = xd->counts; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1855 | for (i = 0; i < 1 + is_compound; ++i) { |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 1856 | int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); |
| 1857 | int nmv_ctx = |
| 1858 | av1_nmv_ctx(xd->ref_mv_count[rf_type], xd->ref_mv_stack[rf_type], i, |
| 1859 | mbmi->ref_mv_idx); |
Alex Converse | 3d0bdc1 | 2017-05-01 15:19:58 -0700 | [diff] [blame] | 1860 | nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1861 | nmv_context_counts *const mv_counts = |
| 1862 | counts ? &counts->mv[nmv_ctx] : NULL; |
Alex Converse | 3d0bdc1 | 2017-05-01 15:19:58 -0700 | [diff] [blame] | 1863 | read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, nmvc, mv_counts, allow_hp); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1864 | ret = ret && is_mv_valid(&mv[i].as_mv); |
| 1865 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1866 | pred_mv[i].as_int = ref_mv[i].as_int; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1867 | } |
| 1868 | break; |
| 1869 | } |
| 1870 | case NEARESTMV: { |
| 1871 | mv[0].as_int = nearest_mv[0].as_int; |
| 1872 | if (is_compound) mv[1].as_int = nearest_mv[1].as_int; |
| 1873 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1874 | pred_mv[0].as_int = nearest_mv[0].as_int; |
| 1875 | if (is_compound) pred_mv[1].as_int = nearest_mv[1].as_int; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1876 | break; |
| 1877 | } |
| 1878 | case NEARMV: { |
| 1879 | mv[0].as_int = near_mv[0].as_int; |
| 1880 | if (is_compound) mv[1].as_int = near_mv[1].as_int; |
| 1881 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1882 | pred_mv[0].as_int = near_mv[0].as_int; |
| 1883 | if (is_compound) pred_mv[1].as_int = near_mv[1].as_int; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1884 | break; |
| 1885 | } |
| 1886 | case ZEROMV: { |
Sarah Parker | e529986 | 2016-08-16 14:57:37 -0700 | [diff] [blame] | 1887 | #if CONFIG_GLOBAL_MOTION |
David Barker | cdcac6d | 2016-12-01 17:04:16 +0000 | [diff] [blame] | 1888 | mv[0].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[0]], |
Sarah Parker | ae7c458 | 2017-02-28 16:30:30 -0800 | [diff] [blame] | 1889 | cm->allow_high_precision_mv, bsize, |
Debargha Mukherjee | febb59c | 2017-03-02 12:23:45 -0800 | [diff] [blame] | 1890 | mi_col, mi_row, block) |
David Barker | cdcac6d | 2016-12-01 17:04:16 +0000 | [diff] [blame] | 1891 | .as_int; |
Sarah Parker | e529986 | 2016-08-16 14:57:37 -0700 | [diff] [blame] | 1892 | if (is_compound) |
David Barker | cdcac6d | 2016-12-01 17:04:16 +0000 | [diff] [blame] | 1893 | mv[1].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[1]], |
Sarah Parker | ae7c458 | 2017-02-28 16:30:30 -0800 | [diff] [blame] | 1894 | cm->allow_high_precision_mv, bsize, |
Debargha Mukherjee | febb59c | 2017-03-02 12:23:45 -0800 | [diff] [blame] | 1895 | mi_col, mi_row, block) |
David Barker | cdcac6d | 2016-12-01 17:04:16 +0000 | [diff] [blame] | 1896 | .as_int; |
Sarah Parker | e529986 | 2016-08-16 14:57:37 -0700 | [diff] [blame] | 1897 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1898 | mv[0].as_int = 0; |
| 1899 | if (is_compound) mv[1].as_int = 0; |
Sarah Parker | e529986 | 2016-08-16 14:57:37 -0700 | [diff] [blame] | 1900 | #endif // CONFIG_GLOBAL_MOTION |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1901 | |
Debargha Mukherjee | febb59c | 2017-03-02 12:23:45 -0800 | [diff] [blame] | 1902 | pred_mv[0].as_int = mv[0].as_int; |
| 1903 | if (is_compound) pred_mv[1].as_int = mv[1].as_int; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1904 | break; |
| 1905 | } |
| 1906 | #if CONFIG_EXT_INTER |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 1907 | #if CONFIG_COMPOUND_SINGLEREF |
| 1908 | case SR_NEAREST_NEARMV: { |
| 1909 | assert(!is_compound); |
| 1910 | mv[0].as_int = nearest_mv[0].as_int; |
| 1911 | mv[1].as_int = near_mv[0].as_int; |
| 1912 | break; |
| 1913 | } |
| 1914 | /* |
| 1915 | case SR_NEAREST_NEWMV: { |
| 1916 | assert(!is_compound); |
| 1917 | mv[0].as_int = nearest_mv[0].as_int; |
| 1918 | |
| 1919 | FRAME_COUNTS *counts = xd->counts; |
| 1920 | int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); |
| 1921 | int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type], |
| 1922 | xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx); |
| 1923 | nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx]; |
| 1924 | nmv_context_counts *const mv_counts = |
| 1925 | counts ? &counts->mv[nmv_ctx] : NULL; |
| 1926 | read_mv(r, &mv[1].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp); |
| 1927 | ret = ret && is_mv_valid(&mv[1].as_mv); |
| 1928 | break; |
| 1929 | }*/ |
| 1930 | case SR_NEAR_NEWMV: { |
| 1931 | assert(!is_compound); |
| 1932 | mv[0].as_int = near_mv[0].as_int; |
| 1933 | |
| 1934 | FRAME_COUNTS *counts = xd->counts; |
| 1935 | int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); |
| 1936 | int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type], |
| 1937 | xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx); |
| 1938 | nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx]; |
| 1939 | nmv_context_counts *const mv_counts = |
| 1940 | counts ? &counts->mv[nmv_ctx] : NULL; |
| 1941 | read_mv(r, &mv[1].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp); |
| 1942 | ret = ret && is_mv_valid(&mv[1].as_mv); |
| 1943 | break; |
| 1944 | } |
| 1945 | case SR_ZERO_NEWMV: { |
| 1946 | assert(!is_compound); |
| 1947 | #if CONFIG_GLOBAL_MOTION |
| 1948 | mv[0].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[0]], |
| 1949 | cm->allow_high_precision_mv, bsize, |
| 1950 | mi_col, mi_row, block) |
| 1951 | .as_int; |
| 1952 | #else |
| 1953 | mv[0].as_int = 0; |
| 1954 | #endif // CONFIG_GLOBAL_MOTION |
| 1955 | |
| 1956 | FRAME_COUNTS *counts = xd->counts; |
| 1957 | int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); |
| 1958 | int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type], |
| 1959 | xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx); |
| 1960 | nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx]; |
| 1961 | nmv_context_counts *const mv_counts = |
| 1962 | counts ? &counts->mv[nmv_ctx] : NULL; |
| 1963 | read_mv(r, &mv[1].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp); |
| 1964 | ret = ret && is_mv_valid(&mv[1].as_mv); |
| 1965 | break; |
| 1966 | } |
| 1967 | case SR_NEW_NEWMV: { |
| 1968 | assert(!is_compound); |
| 1969 | |
| 1970 | FRAME_COUNTS *counts = xd->counts; |
| 1971 | for (i = 0; i < 2; ++i) { |
| 1972 | int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); |
| 1973 | int nmv_ctx = |
| 1974 | av1_nmv_ctx(xd->ref_mv_count[rf_type], xd->ref_mv_stack[rf_type], 0, |
| 1975 | mbmi->ref_mv_idx); |
| 1976 | nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx]; |
| 1977 | nmv_context_counts *const mv_counts = |
| 1978 | counts ? &counts->mv[nmv_ctx] : NULL; |
| 1979 | read_mv(r, &mv[i].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp); |
| 1980 | ret = ret && is_mv_valid(&mv[i].as_mv); |
| 1981 | } |
| 1982 | break; |
| 1983 | } |
| 1984 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1985 | case NEW_NEWMV: { |
| 1986 | FRAME_COUNTS *counts = xd->counts; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1987 | assert(is_compound); |
| 1988 | for (i = 0; i < 2; ++i) { |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 1989 | int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); |
| 1990 | int nmv_ctx = |
| 1991 | av1_nmv_ctx(xd->ref_mv_count[rf_type], xd->ref_mv_stack[rf_type], i, |
| 1992 | mbmi->ref_mv_idx); |
Alex Converse | 3d0bdc1 | 2017-05-01 15:19:58 -0700 | [diff] [blame] | 1993 | nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1994 | nmv_context_counts *const mv_counts = |
| 1995 | counts ? &counts->mv[nmv_ctx] : NULL; |
Alex Converse | 3d0bdc1 | 2017-05-01 15:19:58 -0700 | [diff] [blame] | 1996 | read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, nmvc, mv_counts, allow_hp); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1997 | ret = ret && is_mv_valid(&mv[i].as_mv); |
| 1998 | } |
| 1999 | break; |
| 2000 | } |
| 2001 | case NEAREST_NEARESTMV: { |
| 2002 | assert(is_compound); |
| 2003 | mv[0].as_int = nearest_mv[0].as_int; |
| 2004 | mv[1].as_int = nearest_mv[1].as_int; |
| 2005 | break; |
| 2006 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2007 | case NEAR_NEARMV: { |
| 2008 | assert(is_compound); |
| 2009 | mv[0].as_int = near_mv[0].as_int; |
| 2010 | mv[1].as_int = near_mv[1].as_int; |
| 2011 | break; |
| 2012 | } |
| 2013 | case NEW_NEARESTMV: { |
| 2014 | FRAME_COUNTS *counts = xd->counts; |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 2015 | int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); |
| 2016 | int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type], |
| 2017 | xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx); |
Alex Converse | 3d0bdc1 | 2017-05-01 15:19:58 -0700 | [diff] [blame] | 2018 | nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2019 | nmv_context_counts *const mv_counts = |
| 2020 | counts ? &counts->mv[nmv_ctx] : NULL; |
Alex Converse | 3d0bdc1 | 2017-05-01 15:19:58 -0700 | [diff] [blame] | 2021 | read_mv(r, &mv[0].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2022 | assert(is_compound); |
| 2023 | ret = ret && is_mv_valid(&mv[0].as_mv); |
| 2024 | mv[1].as_int = nearest_mv[1].as_int; |
| 2025 | break; |
| 2026 | } |
| 2027 | case NEAREST_NEWMV: { |
| 2028 | FRAME_COUNTS *counts = xd->counts; |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 2029 | int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); |
| 2030 | int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type], |
| 2031 | xd->ref_mv_stack[rf_type], 1, mbmi->ref_mv_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2032 | nmv_context_counts *const mv_counts = |
| 2033 | counts ? &counts->mv[nmv_ctx] : NULL; |
Alex Converse | 3d0bdc1 | 2017-05-01 15:19:58 -0700 | [diff] [blame] | 2034 | nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx]; |
Alex Converse | 3d0bdc1 | 2017-05-01 15:19:58 -0700 | [diff] [blame] | 2035 | mv[0].as_int = nearest_mv[0].as_int; |
| 2036 | read_mv(r, &mv[1].as_mv, &ref_mv[1].as_mv, nmvc, mv_counts, allow_hp); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2037 | assert(is_compound); |
| 2038 | ret = ret && is_mv_valid(&mv[1].as_mv); |
| 2039 | break; |
| 2040 | } |
| 2041 | case NEAR_NEWMV: { |
| 2042 | FRAME_COUNTS *counts = xd->counts; |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 2043 | int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); |
| 2044 | int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type], |
| 2045 | xd->ref_mv_stack[rf_type], 1, mbmi->ref_mv_idx); |
Alex Converse | 3d0bdc1 | 2017-05-01 15:19:58 -0700 | [diff] [blame] | 2046 | nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2047 | nmv_context_counts *const mv_counts = |
| 2048 | counts ? &counts->mv[nmv_ctx] : NULL; |
Alex Converse | 3d0bdc1 | 2017-05-01 15:19:58 -0700 | [diff] [blame] | 2049 | mv[0].as_int = near_mv[0].as_int; |
| 2050 | read_mv(r, &mv[1].as_mv, &ref_mv[1].as_mv, nmvc, mv_counts, allow_hp); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2051 | assert(is_compound); |
| 2052 | |
| 2053 | ret = ret && is_mv_valid(&mv[1].as_mv); |
| 2054 | break; |
| 2055 | } |
| 2056 | case NEW_NEARMV: { |
| 2057 | FRAME_COUNTS *counts = xd->counts; |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 2058 | int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); |
| 2059 | int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type], |
| 2060 | xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx); |
Alex Converse | 3d0bdc1 | 2017-05-01 15:19:58 -0700 | [diff] [blame] | 2061 | nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2062 | nmv_context_counts *const mv_counts = |
| 2063 | counts ? &counts->mv[nmv_ctx] : NULL; |
Alex Converse | 3d0bdc1 | 2017-05-01 15:19:58 -0700 | [diff] [blame] | 2064 | read_mv(r, &mv[0].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2065 | assert(is_compound); |
| 2066 | ret = ret && is_mv_valid(&mv[0].as_mv); |
| 2067 | mv[1].as_int = near_mv[1].as_int; |
| 2068 | break; |
| 2069 | } |
| 2070 | case ZERO_ZEROMV: { |
| 2071 | assert(is_compound); |
Sarah Parker | c2d3871 | 2017-01-24 15:15:41 -0800 | [diff] [blame] | 2072 | #if CONFIG_GLOBAL_MOTION |
| 2073 | mv[0].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[0]], |
Sarah Parker | ae7c458 | 2017-02-28 16:30:30 -0800 | [diff] [blame] | 2074 | cm->allow_high_precision_mv, bsize, |
Debargha Mukherjee | febb59c | 2017-03-02 12:23:45 -0800 | [diff] [blame] | 2075 | mi_col, mi_row, block) |
Sarah Parker | c2d3871 | 2017-01-24 15:15:41 -0800 | [diff] [blame] | 2076 | .as_int; |
| 2077 | mv[1].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[1]], |
Sarah Parker | ae7c458 | 2017-02-28 16:30:30 -0800 | [diff] [blame] | 2078 | cm->allow_high_precision_mv, bsize, |
Debargha Mukherjee | febb59c | 2017-03-02 12:23:45 -0800 | [diff] [blame] | 2079 | mi_col, mi_row, block) |
Sarah Parker | c2d3871 | 2017-01-24 15:15:41 -0800 | [diff] [blame] | 2080 | .as_int; |
| 2081 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2082 | mv[0].as_int = 0; |
| 2083 | mv[1].as_int = 0; |
Sarah Parker | c2d3871 | 2017-01-24 15:15:41 -0800 | [diff] [blame] | 2084 | #endif // CONFIG_GLOBAL_MOTION |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2085 | break; |
| 2086 | } |
| 2087 | #endif // CONFIG_EXT_INTER |
| 2088 | default: { return 0; } |
| 2089 | } |
| 2090 | return ret; |
| 2091 | } |
| 2092 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2093 | static int read_is_inter_block(AV1_COMMON *const cm, MACROBLOCKD *const xd, |
| 2094 | int segment_id, aom_reader *r) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2095 | if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) { |
| 2096 | return get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME) != INTRA_FRAME; |
| 2097 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2098 | const int ctx = av1_get_intra_inter_context(xd); |
Thomas Davies | f6ad935 | 2017-04-19 11:38:06 +0100 | [diff] [blame] | 2099 | #if CONFIG_NEW_MULTISYMBOL |
Thomas Davies | f6ad935 | 2017-04-19 11:38:06 +0100 | [diff] [blame] | 2100 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
Thomas Davies | f6ad935 | 2017-04-19 11:38:06 +0100 | [diff] [blame] | 2101 | const int is_inter = |
| 2102 | aom_read_symbol(r, ec_ctx->intra_inter_cdf[ctx], 2, ACCT_STR); |
| 2103 | #else |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 2104 | const int is_inter = aom_read(r, cm->fc->intra_inter_prob[ctx], ACCT_STR); |
Thomas Davies | f6ad935 | 2017-04-19 11:38:06 +0100 | [diff] [blame] | 2105 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2106 | FRAME_COUNTS *counts = xd->counts; |
| 2107 | if (counts) ++counts->intra_inter[ctx][is_inter]; |
| 2108 | return is_inter; |
| 2109 | } |
| 2110 | } |
| 2111 | |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2112 | #if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF |
| 2113 | static int read_is_inter_singleref_comp_mode(AV1_COMMON *const cm, |
| 2114 | MACROBLOCKD *const xd, |
| 2115 | int segment_id, aom_reader *r) { |
| 2116 | if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) return 0; |
| 2117 | |
| 2118 | const int ctx = av1_get_inter_mode_context(xd); |
| 2119 | const int is_singleref_comp_mode = |
| 2120 | aom_read(r, cm->fc->comp_inter_mode_prob[ctx], ACCT_STR); |
| 2121 | FRAME_COUNTS *counts = xd->counts; |
| 2122 | |
| 2123 | if (counts) ++counts->comp_inter_mode[ctx][is_singleref_comp_mode]; |
| 2124 | return is_singleref_comp_mode; |
| 2125 | } |
| 2126 | #endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF |
| 2127 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2128 | static void fpm_sync(void *const data, int mi_row) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2129 | AV1Decoder *const pbi = (AV1Decoder *)data; |
| 2130 | av1_frameworker_wait(pbi->frame_worker_owner, pbi->common.prev_frame, |
| 2131 | mi_row << pbi->common.mib_size_log2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2132 | } |
| 2133 | |
Di Chen | 5658662 | 2017-06-09 13:49:44 -0700 | [diff] [blame] | 2134 | #if DEC_MISMATCH_DEBUG |
| 2135 | static void dec_dump_logs(AV1_COMMON *cm, MODE_INFO *const mi, |
Zoe Liu | f9333f5 | 2017-07-03 10:52:01 -0700 | [diff] [blame] | 2136 | MACROBLOCKD *const xd, int mi_row, int mi_col, |
| 2137 | int16_t inter_mode_ctx[MODE_CTX_REF_FRAMES], |
| 2138 | int16_t mode_ctx) { |
Di Chen | 5658662 | 2017-06-09 13:49:44 -0700 | [diff] [blame] | 2139 | int_mv mv[2] = { { 0 } }; |
| 2140 | int ref; |
| 2141 | MB_MODE_INFO *const mbmi = &mi->mbmi; |
Di Chen | 5658662 | 2017-06-09 13:49:44 -0700 | [diff] [blame] | 2142 | for (ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) |
| 2143 | mv[ref].as_mv = mbmi->mv[ref].as_mv; |
| 2144 | |
| 2145 | int interp_ctx[2] = { -1 }; |
| 2146 | int interp_filter[2] = { cm->interp_filter }; |
| 2147 | if (cm->interp_filter == SWITCHABLE) { |
| 2148 | int dir; |
| 2149 | for (dir = 0; dir < 2; ++dir) { |
| 2150 | if (has_subpel_mv_component(xd->mi[0], xd, dir) || |
| 2151 | (mbmi->ref_frame[1] > INTRA_FRAME && |
| 2152 | has_subpel_mv_component(xd->mi[0], xd, dir + 2))) { |
| 2153 | interp_ctx[dir] = av1_get_pred_context_switchable_interp(xd, dir); |
| 2154 | interp_filter[dir] = mbmi->interp_filter[dir]; |
| 2155 | } else { |
| 2156 | interp_filter[dir] = EIGHTTAP_REGULAR; |
| 2157 | } |
| 2158 | } |
| 2159 | } |
| 2160 | |
| 2161 | const int16_t newmv_ctx = mode_ctx & NEWMV_CTX_MASK; |
| 2162 | int16_t zeromv_ctx = -1; |
| 2163 | int16_t refmv_ctx = -1; |
| 2164 | if (mbmi->mode != NEWMV) { |
| 2165 | if (mode_ctx & (1 << ALL_ZERO_FLAG_OFFSET)) assert(mbmi->mode == ZEROMV); |
| 2166 | zeromv_ctx = (mode_ctx >> ZEROMV_OFFSET) & ZEROMV_CTX_MASK; |
| 2167 | if (mbmi->mode != ZEROMV) { |
| 2168 | refmv_ctx = (mode_ctx >> REFMV_OFFSET) & REFMV_CTX_MASK; |
| 2169 | if (mode_ctx & (1 << SKIP_NEARESTMV_OFFSET)) refmv_ctx = 6; |
| 2170 | if (mode_ctx & (1 << SKIP_NEARMV_OFFSET)) refmv_ctx = 7; |
| 2171 | if (mode_ctx & (1 << SKIP_NEARESTMV_SUB8X8_OFFSET)) refmv_ctx = 8; |
| 2172 | } |
| 2173 | } |
| 2174 | |
| 2175 | int8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame); |
Zoe Liu | f9333f5 | 2017-07-03 10:52:01 -0700 | [diff] [blame] | 2176 | #define FRAME_TO_CHECK 1 |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 2177 | if (cm->current_video_frame == FRAME_TO_CHECK /*&& cm->show_frame == 0*/) { |
Zoe Liu | f9333f5 | 2017-07-03 10:52:01 -0700 | [diff] [blame] | 2178 | printf( |
| 2179 | "=== DECODER ===: " |
| 2180 | "Frame=%d, (mi_row,mi_col)=(%d,%d), mode=%d, bsize=%d, " |
| 2181 | "show_frame=%d, mv[0]=(%d,%d), mv[1]=(%d,%d), ref[0]=%d, " |
| 2182 | "ref[1]=%d, motion_mode=%d, inter_mode_ctx=%d, mode_ctx=%d, " |
| 2183 | "interp_ctx=(%d,%d), interp_filter=(%d,%d), newmv_ctx=%d, " |
| 2184 | "zeromv_ctx=%d, refmv_ctx=%d\n", |
| 2185 | cm->current_video_frame, mi_row, mi_col, mbmi->mode, mbmi->sb_type, |
| 2186 | cm->show_frame, mv[0].as_mv.row, mv[0].as_mv.col, mv[1].as_mv.row, |
| 2187 | mv[1].as_mv.col, mbmi->ref_frame[0], mbmi->ref_frame[1], |
| 2188 | mbmi->motion_mode, inter_mode_ctx[ref_frame_type], mode_ctx, |
| 2189 | interp_ctx[0], interp_ctx[1], interp_filter[0], interp_filter[1], |
| 2190 | newmv_ctx, zeromv_ctx, refmv_ctx); |
| 2191 | } |
Di Chen | 5658662 | 2017-06-09 13:49:44 -0700 | [diff] [blame] | 2192 | } |
| 2193 | #endif // DEC_MISMATCH_DEBUG |
| 2194 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2195 | static void read_inter_block_mode_info(AV1Decoder *const pbi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2196 | MACROBLOCKD *const xd, |
| 2197 | MODE_INFO *const mi, |
David Barker | 491983d | 2016-11-10 13:22:17 +0000 | [diff] [blame] | 2198 | #if (CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION || CONFIG_EXT_INTER) && \ |
| 2199 | CONFIG_SUPERTX |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2200 | int mi_row, int mi_col, aom_reader *r, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2201 | int supertx_enabled) { |
| 2202 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2203 | int mi_row, int mi_col, aom_reader *r) { |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2204 | #endif // CONFIG_MOTION_VAR && CONFIG_SUPERTX |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2205 | AV1_COMMON *const cm = &pbi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2206 | MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 2207 | const BLOCK_SIZE bsize = mbmi->sb_type; |
| 2208 | const int allow_hp = cm->allow_high_precision_mv; |
Jingning Han | 5cfa671 | 2016-12-14 09:53:38 -0800 | [diff] [blame] | 2209 | const int unify_bsize = CONFIG_CB4X4; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2210 | int_mv nearestmv[2], nearmv[2]; |
| 2211 | int_mv ref_mvs[MODE_CTX_REF_FRAMES][MAX_MV_REF_CANDIDATES]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2212 | int ref, is_compound; |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2213 | #if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF |
| 2214 | int is_singleref_comp_mode = 0; |
| 2215 | #endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2216 | int16_t inter_mode_ctx[MODE_CTX_REF_FRAMES]; |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 2217 | #if CONFIG_EXT_INTER |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2218 | int16_t compound_inter_mode_ctx[MODE_CTX_REF_FRAMES]; |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 2219 | #endif // CONFIG_EXT_INTER |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2220 | int16_t mode_ctx = 0; |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 2221 | #if CONFIG_WARPED_MOTION |
Debargha Mukherjee | e6eb3b5 | 2017-02-26 08:50:56 -0800 | [diff] [blame] | 2222 | int pts[SAMPLES_ARRAY_SIZE], pts_inref[SAMPLES_ARRAY_SIZE]; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 2223 | #if WARPED_MOTION_SORT_SAMPLES |
| 2224 | int pts_mv[SAMPLES_ARRAY_SIZE]; |
| 2225 | #endif // WARPED_MOTION_SORT_SAMPLES |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 2226 | #endif // CONFIG_WARPED_MOTION |
Thomas Davies | 1de6c88 | 2017-01-11 17:47:49 +0000 | [diff] [blame] | 2227 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2228 | |
Urvang Joshi | 5a9ea00 | 2017-05-22 15:25:18 -0700 | [diff] [blame] | 2229 | assert(NELEMENTS(mode_2_counter) == MB_MODE_COUNT); |
| 2230 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2231 | mbmi->palette_mode_info.palette_size[0] = 0; |
| 2232 | mbmi->palette_mode_info.palette_size[1] = 0; |
| 2233 | |
Frederic Barbier | 7a84fd8 | 2017-03-02 18:08:15 +0100 | [diff] [blame] | 2234 | memset(ref_mvs, 0, sizeof(ref_mvs)); |
| 2235 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2236 | read_ref_frames(cm, xd, r, mbmi->segment_id, mbmi->ref_frame); |
| 2237 | is_compound = has_second_ref(mbmi); |
| 2238 | |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 2239 | #if CONFIG_EXT_COMP_REFS |
| 2240 | #if !USE_UNI_COMP_REFS |
| 2241 | // NOTE: uni-directional comp refs disabled |
| 2242 | if (is_compound) |
| 2243 | assert(mbmi->ref_frame[0] < BWDREF_FRAME && |
| 2244 | mbmi->ref_frame[1] >= BWDREF_FRAME); |
| 2245 | #endif // !USE_UNI_COMP_REFS |
| 2246 | #endif // CONFIG_EXT_COMP_REFS |
| 2247 | |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2248 | #if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF |
| 2249 | if (!is_compound) |
| 2250 | is_singleref_comp_mode = |
| 2251 | read_is_inter_singleref_comp_mode(cm, xd, mbmi->segment_id, r); |
| 2252 | #endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF |
| 2253 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2254 | for (ref = 0; ref < 1 + is_compound; ++ref) { |
| 2255 | MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2256 | |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 2257 | av1_find_mv_refs( |
| 2258 | cm, xd, mi, frame, &xd->ref_mv_count[frame], xd->ref_mv_stack[frame], |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2259 | #if CONFIG_EXT_INTER |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 2260 | compound_inter_mode_ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2261 | #endif // CONFIG_EXT_INTER |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 2262 | ref_mvs[frame], mi_row, mi_col, fpm_sync, (void *)pbi, inter_mode_ctx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2263 | } |
| 2264 | |
Jingning Han | acddc03 | 2016-11-17 15:26:20 -0800 | [diff] [blame] | 2265 | if (is_compound) { |
| 2266 | MV_REFERENCE_FRAME ref_frame = av1_ref_frame_type(mbmi->ref_frame); |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 2267 | av1_find_mv_refs(cm, xd, mi, ref_frame, &xd->ref_mv_count[ref_frame], |
| 2268 | xd->ref_mv_stack[ref_frame], |
| 2269 | #if CONFIG_EXT_INTER |
| 2270 | compound_inter_mode_ctx, |
| 2271 | #endif // CONFIG_EXT_INTER |
| 2272 | ref_mvs[ref_frame], mi_row, mi_col, fpm_sync, (void *)pbi, |
| 2273 | inter_mode_ctx); |
| 2274 | |
| 2275 | if (xd->ref_mv_count[ref_frame] < 2) { |
| 2276 | MV_REFERENCE_FRAME rf[2]; |
David Barker | cdcac6d | 2016-12-01 17:04:16 +0000 | [diff] [blame] | 2277 | int_mv zeromv[2]; |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 2278 | av1_set_ref_frame(rf, ref_frame); |
David Barker | cdcac6d | 2016-12-01 17:04:16 +0000 | [diff] [blame] | 2279 | #if CONFIG_GLOBAL_MOTION |
| 2280 | zeromv[0].as_int = gm_get_motion_vector(&cm->global_motion[rf[0]], |
David Barker | 45390c1 | 2017-02-20 14:44:40 +0000 | [diff] [blame] | 2281 | cm->allow_high_precision_mv, |
Debargha Mukherjee | febb59c | 2017-03-02 12:23:45 -0800 | [diff] [blame] | 2282 | bsize, mi_col, mi_row, 0) |
David Barker | cdcac6d | 2016-12-01 17:04:16 +0000 | [diff] [blame] | 2283 | .as_int; |
Sarah Parker | ae7c458 | 2017-02-28 16:30:30 -0800 | [diff] [blame] | 2284 | zeromv[1].as_int = (rf[1] != NONE_FRAME) |
| 2285 | ? gm_get_motion_vector(&cm->global_motion[rf[1]], |
| 2286 | cm->allow_high_precision_mv, |
Debargha Mukherjee | febb59c | 2017-03-02 12:23:45 -0800 | [diff] [blame] | 2287 | bsize, mi_col, mi_row, 0) |
Sarah Parker | ae7c458 | 2017-02-28 16:30:30 -0800 | [diff] [blame] | 2288 | .as_int |
| 2289 | : 0; |
David Barker | cdcac6d | 2016-12-01 17:04:16 +0000 | [diff] [blame] | 2290 | #else |
| 2291 | zeromv[0].as_int = zeromv[1].as_int = 0; |
| 2292 | #endif |
Sarah Parker | 9923d1b | 2017-04-10 11:56:40 -0700 | [diff] [blame] | 2293 | for (ref = 0; ref < 2; ++ref) { |
| 2294 | if (rf[ref] == NONE_FRAME) continue; |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 2295 | lower_mv_precision(&ref_mvs[rf[ref]][0].as_mv, allow_hp); |
| 2296 | lower_mv_precision(&ref_mvs[rf[ref]][1].as_mv, allow_hp); |
Sarah Parker | 9923d1b | 2017-04-10 11:56:40 -0700 | [diff] [blame] | 2297 | if (ref_mvs[rf[ref]][0].as_int != zeromv[ref].as_int || |
| 2298 | ref_mvs[rf[ref]][1].as_int != zeromv[ref].as_int) |
| 2299 | inter_mode_ctx[ref_frame] &= ~(1 << ALL_ZERO_FLAG_OFFSET); |
Frederic Barbier | 72e2e98 | 2017-03-03 10:01:04 +0100 | [diff] [blame] | 2300 | } |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 2301 | } |
| 2302 | } |
| 2303 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2304 | #if CONFIG_EXT_INTER |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2305 | #if CONFIG_COMPOUND_SINGLEREF |
| 2306 | if (is_compound || is_singleref_comp_mode) |
| 2307 | #else // !CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2308 | if (is_compound) |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2309 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2310 | mode_ctx = compound_inter_mode_ctx[mbmi->ref_frame[0]]; |
| 2311 | else |
| 2312 | #endif // CONFIG_EXT_INTER |
| 2313 | mode_ctx = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2314 | av1_mode_context_analyzer(inter_mode_ctx, mbmi->ref_frame, bsize, -1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2315 | mbmi->ref_mv_idx = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2316 | |
| 2317 | if (segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { |
| 2318 | mbmi->mode = ZEROMV; |
Debargha Mukherjee | c76f9dc | 2017-05-01 13:18:09 -0700 | [diff] [blame] | 2319 | if (bsize < BLOCK_8X8 && !unify_bsize) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2320 | aom_internal_error(xd->error_info, AOM_CODEC_UNSUP_BITSTREAM, |
David Barker | 3409c0d | 2017-06-30 17:33:13 +0100 | [diff] [blame] | 2321 | "Invalid usage of segment feature on small blocks"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2322 | return; |
| 2323 | } |
| 2324 | } else { |
Jingning Han | 5cfa671 | 2016-12-14 09:53:38 -0800 | [diff] [blame] | 2325 | if (bsize >= BLOCK_8X8 || unify_bsize) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2326 | #if CONFIG_EXT_INTER |
| 2327 | if (is_compound) |
| 2328 | mbmi->mode = read_inter_compound_mode(cm, xd, r, mode_ctx); |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2329 | #if CONFIG_COMPOUND_SINGLEREF |
| 2330 | else if (is_singleref_comp_mode) |
Thomas Davies | b8b14a9 | 2017-07-12 15:11:49 +0100 | [diff] [blame] | 2331 | mbmi->mode = read_inter_singleref_comp_mode(xd, r, mode_ctx); |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2332 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2333 | else |
| 2334 | #endif // CONFIG_EXT_INTER |
Zoe Liu | 7f24e1b | 2017-03-17 17:42:05 -0700 | [diff] [blame] | 2335 | mbmi->mode = read_inter_mode(ec_ctx, xd, r, mode_ctx); |
David Barker | 404b2e8 | 2017-03-27 13:07:47 +0100 | [diff] [blame] | 2336 | #if CONFIG_EXT_INTER |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2337 | if (mbmi->mode == NEWMV || mbmi->mode == NEW_NEWMV || |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2338 | #if CONFIG_COMPOUND_SINGLEREF |
| 2339 | mbmi->mode == SR_NEW_NEWMV || |
| 2340 | #endif // CONFIG_COMPOUND_SINGLEREF |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2341 | have_nearmv_in_inter_mode(mbmi->mode)) |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2342 | #else // !CONFIG_EXT_INTER |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2343 | if (mbmi->mode == NEARMV || mbmi->mode == NEWMV) |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2344 | #endif // CONFIG_EXT_INTER |
Thomas Davies | 149eda5 | 2017-06-12 18:11:55 +0100 | [diff] [blame] | 2345 | read_drl_idx(ec_ctx, xd, mbmi, r); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2346 | } |
| 2347 | } |
| 2348 | |
| 2349 | #if CONFIG_EXT_INTER |
David Barker | 9b75e21 | 2017-07-28 15:31:41 +0100 | [diff] [blame] | 2350 | if ((bsize < BLOCK_8X8 && !unify_bsize) || |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 2351 | (mbmi->mode != ZEROMV && mbmi->mode != ZERO_ZEROMV)) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2352 | #else |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 2353 | if ((bsize < BLOCK_8X8 && !unify_bsize) || mbmi->mode != ZEROMV) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2354 | #endif // CONFIG_EXT_INTER |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 2355 | { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2356 | for (ref = 0; ref < 1 + is_compound; ++ref) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2357 | av1_find_best_ref_mvs(allow_hp, ref_mvs[mbmi->ref_frame[ref]], |
| 2358 | &nearestmv[ref], &nearmv[ref]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2359 | } |
| 2360 | } |
| 2361 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2362 | #if CONFIG_EXT_INTER |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2363 | #if CONFIG_COMPOUND_SINGLEREF |
| 2364 | if ((is_compound || is_singleref_comp_mode) && |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 2365 | (bsize >= BLOCK_8X8 || unify_bsize) && mbmi->mode != ZERO_ZEROMV) |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2366 | #else // !CONFIG_COMPOUND_SINGLEREF |
Jingning Han | 61418bb | 2017-01-23 17:12:48 -0800 | [diff] [blame] | 2367 | if (is_compound && (bsize >= BLOCK_8X8 || unify_bsize) && |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 2368 | mbmi->mode != ZERO_ZEROMV) |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2369 | #endif // CONFIG_COMPOUND_SINGLEREF |
| 2370 | #else // !CONFIG_EXT_INTER |
Jingning Han | 5cfa671 | 2016-12-14 09:53:38 -0800 | [diff] [blame] | 2371 | if (is_compound && (bsize >= BLOCK_8X8 || unify_bsize) && |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 2372 | mbmi->mode != NEWMV && mbmi->mode != ZEROMV) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2373 | #endif // CONFIG_EXT_INTER |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 2374 | { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2375 | uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2376 | |
| 2377 | #if CONFIG_EXT_INTER |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 2378 | if (xd->ref_mv_count[ref_frame_type] > 0) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2379 | #else |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 2380 | if (xd->ref_mv_count[ref_frame_type] == 1 && mbmi->mode == NEARESTMV) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2381 | #endif // CONFIG_EXT_INTER |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 2382 | { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2383 | #if CONFIG_EXT_INTER |
| 2384 | if (mbmi->mode == NEAREST_NEARESTMV) { |
| 2385 | #endif // CONFIG_EXT_INTER |
| 2386 | nearestmv[0] = xd->ref_mv_stack[ref_frame_type][0].this_mv; |
| 2387 | nearestmv[1] = xd->ref_mv_stack[ref_frame_type][0].comp_mv; |
| 2388 | lower_mv_precision(&nearestmv[0].as_mv, allow_hp); |
| 2389 | lower_mv_precision(&nearestmv[1].as_mv, allow_hp); |
| 2390 | #if CONFIG_EXT_INTER |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2391 | } else if (mbmi->mode == NEAREST_NEWMV |
| 2392 | #if CONFIG_COMPOUND_SINGLEREF |
| 2393 | || mbmi->mode == SR_NEAREST_NEARMV |
| 2394 | // || mbmi->mode == SR_NEAREST_NEWMV |
| 2395 | #endif // CONFIG_COMPOUND_SINGLEREF |
| 2396 | ) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2397 | nearestmv[0] = xd->ref_mv_stack[ref_frame_type][0].this_mv; |
| 2398 | lower_mv_precision(&nearestmv[0].as_mv, allow_hp); |
Debargha Mukherjee | bb6e134 | 2017-04-17 16:05:04 -0700 | [diff] [blame] | 2399 | } else if (mbmi->mode == NEW_NEARESTMV) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2400 | nearestmv[1] = xd->ref_mv_stack[ref_frame_type][0].comp_mv; |
| 2401 | lower_mv_precision(&nearestmv[1].as_mv, allow_hp); |
| 2402 | } |
| 2403 | #endif // CONFIG_EXT_INTER |
| 2404 | } |
| 2405 | |
| 2406 | #if CONFIG_EXT_INTER |
| 2407 | if (xd->ref_mv_count[ref_frame_type] > 1) { |
David Barker | 404b2e8 | 2017-03-27 13:07:47 +0100 | [diff] [blame] | 2408 | int ref_mv_idx = 1 + mbmi->ref_mv_idx; |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2409 | #if CONFIG_COMPOUND_SINGLEREF |
| 2410 | if (is_compound) { |
| 2411 | #endif // CONFIG_COMPOUND_SINGLEREF |
| 2412 | if (compound_ref0_mode(mbmi->mode) == NEARMV) { |
| 2413 | nearmv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv; |
| 2414 | lower_mv_precision(&nearmv[0].as_mv, allow_hp); |
| 2415 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2416 | |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2417 | if (compound_ref1_mode(mbmi->mode) == NEARMV) { |
| 2418 | nearmv[1] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].comp_mv; |
| 2419 | lower_mv_precision(&nearmv[1].as_mv, allow_hp); |
| 2420 | } |
| 2421 | #if CONFIG_COMPOUND_SINGLEREF |
| 2422 | } else { |
| 2423 | assert(is_singleref_comp_mode); |
| 2424 | if (compound_ref0_mode(mbmi->mode) == NEARMV || |
| 2425 | compound_ref1_mode(mbmi->mode) == NEARMV) { |
| 2426 | nearmv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv; |
| 2427 | lower_mv_precision(&nearmv[0].as_mv, allow_hp); |
| 2428 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2429 | } |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2430 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2431 | } |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2432 | #else // !CONFIG_EXT_INTER |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2433 | if (xd->ref_mv_count[ref_frame_type] > 1) { |
| 2434 | int ref_mv_idx = 1 + mbmi->ref_mv_idx; |
| 2435 | nearestmv[0] = xd->ref_mv_stack[ref_frame_type][0].this_mv; |
| 2436 | nearestmv[1] = xd->ref_mv_stack[ref_frame_type][0].comp_mv; |
| 2437 | nearmv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv; |
| 2438 | nearmv[1] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].comp_mv; |
| 2439 | } |
| 2440 | #endif // CONFIG_EXT_INTER |
David Barker | 0d7c4b0 | 2017-07-25 14:55:48 +0100 | [diff] [blame] | 2441 | } else if (mbmi->ref_mv_idx > 0 && mbmi->mode == NEARMV) { |
| 2442 | int_mv cur_mv = |
| 2443 | xd->ref_mv_stack[mbmi->ref_frame[0]][1 + mbmi->ref_mv_idx].this_mv; |
| 2444 | nearmv[0] = cur_mv; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2445 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2446 | |
Yue Chen | 19e7aa8 | 2016-11-30 14:05:39 -0800 | [diff] [blame] | 2447 | #if !CONFIG_DUAL_FILTER && !CONFIG_WARPED_MOTION && !CONFIG_GLOBAL_MOTION |
Angie Chiang | 9c4f895 | 2016-11-21 11:13:19 -0800 | [diff] [blame] | 2448 | read_mb_interp_filter(cm, xd, mbmi, r); |
Angie Chiang | 1733f6b | 2017-01-05 09:52:20 -0800 | [diff] [blame] | 2449 | #endif // !CONFIG_DUAL_FILTER && !CONFIG_WARPED_MOTION |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2450 | |
Jingning Han | 5cfa671 | 2016-12-14 09:53:38 -0800 | [diff] [blame] | 2451 | if (bsize < BLOCK_8X8 && !unify_bsize) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2452 | const int num_4x4_w = 1 << xd->bmode_blocks_wl; |
| 2453 | const int num_4x4_h = 1 << xd->bmode_blocks_hl; |
| 2454 | int idx, idy; |
| 2455 | PREDICTION_MODE b_mode; |
| 2456 | int_mv nearest_sub8x8[2], near_sub8x8[2]; |
| 2457 | #if CONFIG_EXT_INTER |
| 2458 | int_mv ref_mv[2][2]; |
| 2459 | #endif // CONFIG_EXT_INTER |
| 2460 | for (idy = 0; idy < 2; idy += num_4x4_h) { |
| 2461 | for (idx = 0; idx < 2; idx += num_4x4_w) { |
| 2462 | int_mv block[2]; |
| 2463 | const int j = idy * 2 + idx; |
| 2464 | int_mv ref_mv_s8[2]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2465 | #if CONFIG_EXT_INTER |
| 2466 | if (!is_compound) |
| 2467 | #endif // CONFIG_EXT_INTER |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2468 | mode_ctx = av1_mode_context_analyzer(inter_mode_ctx, mbmi->ref_frame, |
| 2469 | bsize, j); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2470 | #if CONFIG_EXT_INTER |
| 2471 | if (is_compound) |
| 2472 | b_mode = read_inter_compound_mode(cm, xd, r, mode_ctx); |
| 2473 | else |
| 2474 | #endif // CONFIG_EXT_INTER |
Zoe Liu | 7f24e1b | 2017-03-17 17:42:05 -0700 | [diff] [blame] | 2475 | b_mode = read_inter_mode(ec_ctx, xd, r, mode_ctx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2476 | |
| 2477 | #if CONFIG_EXT_INTER |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 2478 | if (b_mode != ZEROMV && b_mode != ZERO_ZEROMV) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2479 | #else |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 2480 | if (b_mode != ZEROMV) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2481 | #endif // CONFIG_EXT_INTER |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 2482 | { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2483 | CANDIDATE_MV ref_mv_stack[2][MAX_REF_MV_STACK_SIZE]; |
| 2484 | uint8_t ref_mv_count[2]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2485 | for (ref = 0; ref < 1 + is_compound; ++ref) |
| 2486 | #if CONFIG_EXT_INTER |
| 2487 | { |
| 2488 | int_mv mv_ref_list[MAX_MV_REF_CANDIDATES]; |
Yaowu Xu | 531d6af | 2017-03-07 17:48:52 -0800 | [diff] [blame] | 2489 | av1_update_mv_context(cm, xd, mi, mbmi->ref_frame[ref], mv_ref_list, |
| 2490 | j, mi_row, mi_col, NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2491 | #endif // CONFIG_EXT_INTER |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2492 | av1_append_sub8x8_mvs_for_idx(cm, xd, j, ref, mi_row, mi_col, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2493 | ref_mv_stack[ref], &ref_mv_count[ref], |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2494 | #if CONFIG_EXT_INTER |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2495 | mv_ref_list, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2496 | #endif // CONFIG_EXT_INTER |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2497 | &nearest_sub8x8[ref], |
| 2498 | &near_sub8x8[ref]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2499 | #if CONFIG_EXT_INTER |
| 2500 | if (have_newmv_in_inter_mode(b_mode)) { |
| 2501 | mv_ref_list[0].as_int = nearest_sub8x8[ref].as_int; |
| 2502 | mv_ref_list[1].as_int = near_sub8x8[ref].as_int; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2503 | av1_find_best_ref_mvs(allow_hp, mv_ref_list, &ref_mv[0][ref], |
| 2504 | &ref_mv[1][ref]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2505 | } |
| 2506 | } |
| 2507 | #endif // CONFIG_EXT_INTER |
| 2508 | } |
| 2509 | |
| 2510 | for (ref = 0; ref < 1 + is_compound && b_mode != ZEROMV; ++ref) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2511 | ref_mv_s8[ref] = nearest_sub8x8[ref]; |
| 2512 | lower_mv_precision(&ref_mv_s8[ref].as_mv, allow_hp); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2513 | } |
| 2514 | #if CONFIG_EXT_INTER |
| 2515 | (void)ref_mv_s8; |
| 2516 | #endif |
| 2517 | |
Jingning Han | 5c60cdf | 2016-09-30 09:37:46 -0700 | [diff] [blame] | 2518 | if (!assign_mv(cm, xd, b_mode, mbmi->ref_frame, j, block, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2519 | #if CONFIG_EXT_INTER |
Zoe Liu | 7f24e1b | 2017-03-17 17:42:05 -0700 | [diff] [blame] | 2520 | ref_mv[0], |
| 2521 | #else // !CONFIG_EXT_INTER |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2522 | ref_mv_s8, |
| 2523 | #endif // CONFIG_EXT_INTER |
David Barker | 45390c1 | 2017-02-20 14:44:40 +0000 | [diff] [blame] | 2524 | nearest_sub8x8, near_sub8x8, mi_row, mi_col, is_compound, |
| 2525 | allow_hp, r)) { |
Angie Chiang | d0916d9 | 2017-03-10 17:54:18 -0800 | [diff] [blame] | 2526 | aom_merge_corrupted_flag(&xd->corrupted, 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2527 | break; |
| 2528 | }; |
| 2529 | |
| 2530 | mi->bmi[j].as_mv[0].as_int = block[0].as_int; |
Sarah Parker | d7fa854 | 2016-10-11 11:51:59 -0700 | [diff] [blame] | 2531 | mi->bmi[j].as_mode = b_mode; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2532 | if (is_compound) mi->bmi[j].as_mv[1].as_int = block[1].as_int; |
| 2533 | |
| 2534 | if (num_4x4_h == 2) mi->bmi[j + 2] = mi->bmi[j]; |
| 2535 | if (num_4x4_w == 2) mi->bmi[j + 1] = mi->bmi[j]; |
| 2536 | } |
| 2537 | } |
| 2538 | |
Yaowu Xu | f5bbbfa | 2016-09-26 09:13:38 -0700 | [diff] [blame] | 2539 | mbmi->pred_mv[0].as_int = mi->bmi[3].pred_mv[0].as_int; |
| 2540 | mbmi->pred_mv[1].as_int = mi->bmi[3].pred_mv[1].as_int; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2541 | mi->mbmi.mode = b_mode; |
| 2542 | |
| 2543 | mbmi->mv[0].as_int = mi->bmi[3].as_mv[0].as_int; |
| 2544 | mbmi->mv[1].as_int = mi->bmi[3].as_mv[1].as_int; |
| 2545 | } else { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2546 | int_mv ref_mv[2]; |
| 2547 | ref_mv[0] = nearestmv[0]; |
| 2548 | ref_mv[1] = nearestmv[1]; |
| 2549 | |
David Barker | 404b2e8 | 2017-03-27 13:07:47 +0100 | [diff] [blame] | 2550 | #if CONFIG_EXT_INTER |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2551 | if (is_compound) { |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2552 | int ref_mv_idx = mbmi->ref_mv_idx; |
| 2553 | // Special case: NEAR_NEWMV and NEW_NEARMV modes use |
| 2554 | // 1 + mbmi->ref_mv_idx (like NEARMV) instead of |
| 2555 | // mbmi->ref_mv_idx (like NEWMV) |
| 2556 | if (mbmi->mode == NEAR_NEWMV || mbmi->mode == NEW_NEARMV) |
| 2557 | ref_mv_idx = 1 + mbmi->ref_mv_idx; |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2558 | |
| 2559 | if (compound_ref0_mode(mbmi->mode) == NEWMV) { |
David Barker | 404b2e8 | 2017-03-27 13:07:47 +0100 | [diff] [blame] | 2560 | uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame); |
| 2561 | if (xd->ref_mv_count[ref_frame_type] > 1) { |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2562 | ref_mv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv; |
Jingning Han | 1b5bd00 | 2017-04-20 08:48:30 -0700 | [diff] [blame] | 2563 | clamp_mv_ref(&ref_mv[0].as_mv, xd->n8_w << MI_SIZE_LOG2, |
David Barker | 404b2e8 | 2017-03-27 13:07:47 +0100 | [diff] [blame] | 2564 | xd->n8_h << MI_SIZE_LOG2, xd); |
| 2565 | } |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2566 | nearestmv[0] = ref_mv[0]; |
David Barker | 404b2e8 | 2017-03-27 13:07:47 +0100 | [diff] [blame] | 2567 | } |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2568 | if (compound_ref1_mode(mbmi->mode) == NEWMV) { |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2569 | uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame); |
| 2570 | if (xd->ref_mv_count[ref_frame_type] > 1) { |
| 2571 | ref_mv[1] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].comp_mv; |
Jingning Han | 1b5bd00 | 2017-04-20 08:48:30 -0700 | [diff] [blame] | 2572 | clamp_mv_ref(&ref_mv[1].as_mv, xd->n8_w << MI_SIZE_LOG2, |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2573 | xd->n8_h << MI_SIZE_LOG2, xd); |
| 2574 | } |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2575 | nearestmv[1] = ref_mv[1]; |
| 2576 | } |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2577 | #if CONFIG_COMPOUND_SINGLEREF |
| 2578 | } else if (is_singleref_comp_mode) { |
| 2579 | int ref_mv_idx = mbmi->ref_mv_idx; |
| 2580 | // Special case: SR_NEAR_NEWMV use 1 + mbmi->ref_mv_idx (like NEARMV) |
| 2581 | // instead of mbmi->ref_mv_idx (like NEWMV) |
| 2582 | if (mbmi->mode == SR_NEAR_NEWMV) ref_mv_idx = 1 + mbmi->ref_mv_idx; |
| 2583 | |
| 2584 | if (compound_ref0_mode(mbmi->mode) == NEWMV || |
| 2585 | compound_ref1_mode(mbmi->mode) == NEWMV) { |
| 2586 | uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame); |
| 2587 | if (xd->ref_mv_count[ref_frame_type] > 1) { |
| 2588 | ref_mv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv; |
| 2589 | clamp_mv_ref(&ref_mv[0].as_mv, xd->n8_w << MI_SIZE_LOG2, |
| 2590 | xd->n8_h << MI_SIZE_LOG2, xd); |
| 2591 | } |
| 2592 | // TODO(zoeliu): To further investigate why this would not cause a |
| 2593 | // mismatch for the mode of SR_NEAREST_NEWMV. |
| 2594 | nearestmv[0] = ref_mv[0]; |
| 2595 | } |
| 2596 | #endif // CONFIG_COMPOUND_SINGLEREF |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2597 | } else { |
| 2598 | #endif // CONFIG_EXT_INTER |
| 2599 | if (mbmi->mode == NEWMV) { |
| 2600 | for (ref = 0; ref < 1 + is_compound; ++ref) { |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2601 | uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame); |
| 2602 | if (xd->ref_mv_count[ref_frame_type] > 1) { |
| 2603 | ref_mv[ref] = |
| 2604 | (ref == 0) |
| 2605 | ? xd->ref_mv_stack[ref_frame_type][mbmi->ref_mv_idx].this_mv |
| 2606 | : xd->ref_mv_stack[ref_frame_type][mbmi->ref_mv_idx] |
| 2607 | .comp_mv; |
| 2608 | clamp_mv_ref(&ref_mv[ref].as_mv, xd->n8_w << MI_SIZE_LOG2, |
| 2609 | xd->n8_h << MI_SIZE_LOG2, xd); |
| 2610 | } |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2611 | nearestmv[ref] = ref_mv[ref]; |
| 2612 | } |
| 2613 | } |
| 2614 | #if CONFIG_EXT_INTER |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2615 | } |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2616 | #endif // CONFIG_EXT_INTER |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2617 | |
Angie Chiang | d0916d9 | 2017-03-10 17:54:18 -0800 | [diff] [blame] | 2618 | int mv_corrupted_flag = |
Zoe Liu | 7f24e1b | 2017-03-17 17:42:05 -0700 | [diff] [blame] | 2619 | !assign_mv(cm, xd, mbmi->mode, mbmi->ref_frame, 0, mbmi->mv, ref_mv, |
David Barker | 45390c1 | 2017-02-20 14:44:40 +0000 | [diff] [blame] | 2620 | nearestmv, nearmv, mi_row, mi_col, is_compound, allow_hp, r); |
Angie Chiang | d0916d9 | 2017-03-10 17:54:18 -0800 | [diff] [blame] | 2621 | aom_merge_corrupted_flag(&xd->corrupted, mv_corrupted_flag); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2622 | } |
| 2623 | |
Yue Chen | 4d26acb | 2017-05-01 12:28:34 -0700 | [diff] [blame] | 2624 | #if CONFIG_EXT_INTER && CONFIG_INTERINTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2625 | mbmi->use_wedge_interintra = 0; |
| 2626 | if (cm->reference_mode != COMPOUND_REFERENCE && |
| 2627 | #if CONFIG_SUPERTX |
| 2628 | !supertx_enabled && |
| 2629 | #endif |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2630 | cm->allow_interintra_compound && is_interintra_allowed(mbmi)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2631 | const int bsize_group = size_group_lookup[bsize]; |
Thomas Davies | cff9171 | 2017-07-07 11:49:55 +0100 | [diff] [blame] | 2632 | #if CONFIG_NEW_MULTISYMBOL |
| 2633 | const int interintra = |
| 2634 | aom_read_symbol(r, ec_ctx->interintra_cdf[bsize_group], 2, ACCT_STR); |
| 2635 | #else |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 2636 | const int interintra = |
| 2637 | aom_read(r, cm->fc->interintra_prob[bsize_group], ACCT_STR); |
Thomas Davies | cff9171 | 2017-07-07 11:49:55 +0100 | [diff] [blame] | 2638 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2639 | if (xd->counts) xd->counts->interintra[bsize_group][interintra]++; |
Emil Keyder | 01770b3 | 2017-01-20 18:03:11 -0500 | [diff] [blame] | 2640 | assert(mbmi->ref_frame[1] == NONE_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2641 | if (interintra) { |
| 2642 | const INTERINTRA_MODE interintra_mode = |
| 2643 | read_interintra_mode(cm, xd, r, bsize_group); |
| 2644 | mbmi->ref_frame[1] = INTRA_FRAME; |
| 2645 | mbmi->interintra_mode = interintra_mode; |
| 2646 | #if CONFIG_EXT_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2647 | mbmi->angle_delta[0] = 0; |
| 2648 | mbmi->angle_delta[1] = 0; |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 2649 | #if CONFIG_INTRA_INTERP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2650 | mbmi->intra_filter = INTRA_FILTER_LINEAR; |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 2651 | #endif // CONFIG_INTRA_INTERP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2652 | #endif // CONFIG_EXT_INTRA |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 2653 | #if CONFIG_FILTER_INTRA |
| 2654 | mbmi->filter_intra_mode_info.use_filter_intra_mode[0] = 0; |
| 2655 | mbmi->filter_intra_mode_info.use_filter_intra_mode[1] = 0; |
| 2656 | #endif // CONFIG_FILTER_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2657 | if (is_interintra_wedge_used(bsize)) { |
Thomas Davies | cff9171 | 2017-07-07 11:49:55 +0100 | [diff] [blame] | 2658 | #if CONFIG_NEW_MULTISYMBOL |
| 2659 | mbmi->use_wedge_interintra = aom_read_symbol( |
| 2660 | r, ec_ctx->wedge_interintra_cdf[bsize], 2, ACCT_STR); |
| 2661 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2662 | mbmi->use_wedge_interintra = |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 2663 | aom_read(r, cm->fc->wedge_interintra_prob[bsize], ACCT_STR); |
Thomas Davies | cff9171 | 2017-07-07 11:49:55 +0100 | [diff] [blame] | 2664 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2665 | if (xd->counts) |
| 2666 | xd->counts->wedge_interintra[bsize][mbmi->use_wedge_interintra]++; |
| 2667 | if (mbmi->use_wedge_interintra) { |
| 2668 | mbmi->interintra_wedge_index = |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 2669 | aom_read_literal(r, get_wedge_bits_lookup(bsize), ACCT_STR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2670 | mbmi->interintra_wedge_sign = 0; |
| 2671 | } |
| 2672 | } |
| 2673 | } |
| 2674 | } |
Yue Chen | 4d26acb | 2017-05-01 12:28:34 -0700 | [diff] [blame] | 2675 | #endif // CONFIG_EXT_INTER && CONFIG_INTERINTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2676 | |
Yue Chen | 52c5173 | 2017-07-11 15:08:30 -0700 | [diff] [blame] | 2677 | #if CONFIG_WARPED_MOTION |
| 2678 | for (ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) { |
| 2679 | const MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref]; |
| 2680 | RefBuffer *ref_buf = &cm->frame_refs[frame - LAST_FRAME]; |
| 2681 | |
| 2682 | xd->block_refs[ref] = ref_buf; |
| 2683 | } |
| 2684 | #endif |
| 2685 | |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2686 | #if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION |
| 2687 | mbmi->motion_mode = SIMPLE_TRANSLATION; |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 2688 | #if CONFIG_WARPED_MOTION |
| 2689 | if (mbmi->sb_type >= BLOCK_8X8 && !has_second_ref(mbmi)) |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 2690 | #if WARPED_MOTION_SORT_SAMPLES |
| 2691 | mbmi->num_proj_ref[0] = |
| 2692 | findSamples(cm, xd, mi_row, mi_col, pts, pts_inref, pts_mv); |
| 2693 | #else |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 2694 | mbmi->num_proj_ref[0] = findSamples(cm, xd, mi_row, mi_col, pts, pts_inref); |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 2695 | #endif // WARPED_MOTION_SORT_SAMPLES |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 2696 | #endif // CONFIG_WARPED_MOTION |
Yue Chen | 5329a2b | 2017-02-28 17:33:00 +0800 | [diff] [blame] | 2697 | #if CONFIG_MOTION_VAR |
| 2698 | av1_count_overlappable_neighbors(cm, xd, mi_row, mi_col); |
| 2699 | #endif |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 2700 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2701 | #if CONFIG_SUPERTX |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 2702 | if (!supertx_enabled) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2703 | #endif // CONFIG_SUPERTX |
| 2704 | #if CONFIG_EXT_INTER |
| 2705 | if (mbmi->ref_frame[1] != INTRA_FRAME) |
| 2706 | #endif // CONFIG_EXT_INTER |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 2707 | mbmi->motion_mode = read_motion_mode(cm, xd, mi, r); |
Wei-Ting Lin | 85a8f70 | 2017-06-22 13:55:15 -0700 | [diff] [blame] | 2708 | |
| 2709 | #if CONFIG_NCOBMC_ADAPT_WEIGHT |
Wei-Ting Lin | ca710d6 | 2017-07-13 11:41:02 -0700 | [diff] [blame] | 2710 | read_ncobmc_mode(xd, mi, mbmi->ncobmc_mode, r); |
Wei-Ting Lin | 85a8f70 | 2017-06-22 13:55:15 -0700 | [diff] [blame] | 2711 | #endif |
| 2712 | |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2713 | #if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF |
| 2714 | if (is_singleref_comp_mode) assert(mbmi->motion_mode == SIMPLE_TRANSLATION); |
| 2715 | #endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 2716 | #if CONFIG_WARPED_MOTION |
| 2717 | if (mbmi->motion_mode == WARPED_CAUSAL) { |
| 2718 | mbmi->wm_params[0].wmtype = DEFAULT_WMTYPE; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 2719 | |
| 2720 | #if WARPED_MOTION_SORT_SAMPLES |
| 2721 | if (mbmi->num_proj_ref[0] > 1) |
| 2722 | mbmi->num_proj_ref[0] = sortSamples(pts_mv, &mbmi->mv[0].as_mv, pts, |
| 2723 | pts_inref, mbmi->num_proj_ref[0]); |
| 2724 | #endif // WARPED_MOTION_SORT_SAMPLES |
| 2725 | |
Debargha Mukherjee | 0df711f | 2017-05-02 16:00:20 -0700 | [diff] [blame] | 2726 | if (find_projection(mbmi->num_proj_ref[0], pts, pts_inref, bsize, |
| 2727 | mbmi->mv[0].as_mv.row, mbmi->mv[0].as_mv.col, |
| 2728 | &mbmi->wm_params[0], mi_row, mi_col)) { |
Yunqing Wang | 8657ad7 | 2017-06-20 14:46:08 -0700 | [diff] [blame] | 2729 | aom_internal_error(&cm->error, AOM_CODEC_ERROR, "Invalid Warped Model"); |
Debargha Mukherjee | 0df711f | 2017-05-02 16:00:20 -0700 | [diff] [blame] | 2730 | } |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 2731 | } |
| 2732 | #endif // CONFIG_WARPED_MOTION |
| 2733 | #if CONFIG_SUPERTX |
| 2734 | } |
| 2735 | #endif // CONFIG_SUPERTX |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2736 | #endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2737 | |
| 2738 | #if CONFIG_EXT_INTER |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 2739 | mbmi->interinter_compound_type = COMPOUND_AVERAGE; |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2740 | if ( |
| 2741 | #if CONFIG_COMPOUND_SINGLEREF |
Zoe Liu | 0c634c7 | 2017-06-19 07:06:28 -0700 | [diff] [blame] | 2742 | is_inter_anyref_comp_mode(mbmi->mode) |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2743 | #else // !CONFIG_COMPOUND_SINGLEREF |
| 2744 | cm->reference_mode != SINGLE_REFERENCE && |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 2745 | is_inter_compound_mode(mbmi->mode) |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2746 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2747 | #if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 2748 | && mbmi->motion_mode == SIMPLE_TRANSLATION |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2749 | #endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 2750 | ) { |
Sarah Parker | 42d9610 | 2017-01-31 21:05:27 -0800 | [diff] [blame] | 2751 | if (is_any_masked_compound_used(bsize)) { |
Debargha Mukherjee | c5f735f | 2017-04-26 03:25:28 +0000 | [diff] [blame] | 2752 | #if CONFIG_COMPOUND_SEGMENT || CONFIG_WEDGE |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2753 | if (cm->allow_masked_compound) { |
Sarah Parker | 680b9b1 | 2017-08-16 18:55:34 -0700 | [diff] [blame^] | 2754 | #if CONFIG_WEDGE && CONFIG_COMPOUND_SEGMENT |
| 2755 | if (!is_interinter_compound_used(COMPOUND_WEDGE, bsize)) |
| 2756 | mbmi->interinter_compound_type = |
| 2757 | aom_read_bit(r, ACCT_STR) ? COMPOUND_AVERAGE : COMPOUND_SEG; |
| 2758 | else |
| 2759 | #endif // CONFIG_WEDGE && CONFIG_COMPOUND_SEGMENT |
| 2760 | mbmi->interinter_compound_type = aom_read_symbol( |
| 2761 | r, ec_ctx->compound_type_cdf[bsize], COMPOUND_TYPES, ACCT_STR); |
Debargha Mukherjee | c5f735f | 2017-04-26 03:25:28 +0000 | [diff] [blame] | 2762 | #if CONFIG_WEDGE |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2763 | if (mbmi->interinter_compound_type == COMPOUND_WEDGE) { |
Sarah Parker | 680b9b1 | 2017-08-16 18:55:34 -0700 | [diff] [blame^] | 2764 | assert(is_interinter_compound_used(COMPOUND_WEDGE, bsize)); |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2765 | mbmi->wedge_index = |
| 2766 | aom_read_literal(r, get_wedge_bits_lookup(bsize), ACCT_STR); |
| 2767 | mbmi->wedge_sign = aom_read_bit(r, ACCT_STR); |
| 2768 | } |
Debargha Mukherjee | c5f735f | 2017-04-26 03:25:28 +0000 | [diff] [blame] | 2769 | #endif // CONFIG_WEDGE |
Sarah Parker | 42d9610 | 2017-01-31 21:05:27 -0800 | [diff] [blame] | 2770 | #if CONFIG_COMPOUND_SEGMENT |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2771 | if (mbmi->interinter_compound_type == COMPOUND_SEG) { |
| 2772 | mbmi->mask_type = aom_read_literal(r, MAX_SEG_MASK_BITS, ACCT_STR); |
| 2773 | } |
Sarah Parker | 42d9610 | 2017-01-31 21:05:27 -0800 | [diff] [blame] | 2774 | #endif // CONFIG_COMPOUND_SEGMENT |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2775 | } |
| 2776 | #endif // CONFIG_COMPOUND_SEGMENT || CONFIG_WEDGE |
Sarah Parker | 42d9610 | 2017-01-31 21:05:27 -0800 | [diff] [blame] | 2777 | } else { |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 2778 | mbmi->interinter_compound_type = COMPOUND_AVERAGE; |
Sarah Parker | 42d9610 | 2017-01-31 21:05:27 -0800 | [diff] [blame] | 2779 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2780 | if (xd->counts) |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 2781 | xd->counts->compound_interinter[bsize][mbmi->interinter_compound_type]++; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2782 | } |
| 2783 | #endif // CONFIG_EXT_INTER |
| 2784 | |
Yue Chen | 19e7aa8 | 2016-11-30 14:05:39 -0800 | [diff] [blame] | 2785 | #if CONFIG_DUAL_FILTER || CONFIG_WARPED_MOTION || CONFIG_GLOBAL_MOTION |
Debargha Mukherjee | 0df711f | 2017-05-02 16:00:20 -0700 | [diff] [blame] | 2786 | read_mb_interp_filter(cm, xd, mbmi, r); |
Angie Chiang | 1733f6b | 2017-01-05 09:52:20 -0800 | [diff] [blame] | 2787 | #endif // CONFIG_DUAL_FILTER || CONFIG_WARPED_MOTION |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2788 | |
Di Chen | 5658662 | 2017-06-09 13:49:44 -0700 | [diff] [blame] | 2789 | #if DEC_MISMATCH_DEBUG |
| 2790 | // NOTE(zoeliu): For debug |
Zoe Liu | f9333f5 | 2017-07-03 10:52:01 -0700 | [diff] [blame] | 2791 | dec_dump_logs(cm, mi, xd, mi_row, mi_col, inter_mode_ctx, mode_ctx); |
Di Chen | 5658662 | 2017-06-09 13:49:44 -0700 | [diff] [blame] | 2792 | #endif // DEC_MISMATCH_DEBUG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2793 | } |
| 2794 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2795 | static void read_inter_frame_mode_info(AV1Decoder *const pbi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2796 | MACROBLOCKD *const xd, |
| 2797 | #if CONFIG_SUPERTX |
| 2798 | int supertx_enabled, |
| 2799 | #endif // CONFIG_SUPERTX |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2800 | int mi_row, int mi_col, aom_reader *r) { |
| 2801 | AV1_COMMON *const cm = &pbi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2802 | MODE_INFO *const mi = xd->mi[0]; |
| 2803 | MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 2804 | int inter_block = 1; |
| 2805 | #if CONFIG_VAR_TX |
| 2806 | BLOCK_SIZE bsize = mbmi->sb_type; |
| 2807 | #endif // CONFIG_VAR_TX |
| 2808 | |
| 2809 | mbmi->mv[0].as_int = 0; |
| 2810 | mbmi->mv[1].as_int = 0; |
| 2811 | mbmi->segment_id = read_inter_segment_id(cm, xd, mi_row, mi_col, r); |
| 2812 | #if CONFIG_SUPERTX |
David Barker | 3aec8d6 | 2017-01-31 14:55:32 +0000 | [diff] [blame] | 2813 | if (!supertx_enabled) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2814 | #endif // CONFIG_SUPERTX |
| 2815 | mbmi->skip = read_skip(cm, xd, mbmi->segment_id, r); |
David Barker | 3aec8d6 | 2017-01-31 14:55:32 +0000 | [diff] [blame] | 2816 | |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 2817 | #if CONFIG_DELTA_Q |
David Barker | 3aec8d6 | 2017-01-31 14:55:32 +0000 | [diff] [blame] | 2818 | if (cm->delta_q_present_flag) { |
| 2819 | xd->current_qindex = |
| 2820 | xd->prev_qindex + |
| 2821 | read_delta_qindex(cm, xd, r, mbmi, mi_col, mi_row) * cm->delta_q_res; |
Arild Fuldseth (arilfuld) | 54de7d6 | 2017-03-20 13:07:11 +0100 | [diff] [blame] | 2822 | /* Normative: Clamp to [1,MAXQ] to not interfere with lossless mode */ |
| 2823 | xd->current_qindex = clamp(xd->current_qindex, 1, MAXQ); |
David Barker | 3aec8d6 | 2017-01-31 14:55:32 +0000 | [diff] [blame] | 2824 | xd->prev_qindex = xd->current_qindex; |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 2825 | #if CONFIG_EXT_DELTA_Q |
| 2826 | if (cm->delta_lf_present_flag) { |
| 2827 | mbmi->current_delta_lf_from_base = xd->current_delta_lf_from_base = |
| 2828 | xd->prev_delta_lf_from_base + |
| 2829 | read_delta_lflevel(cm, xd, r, mbmi, mi_col, mi_row) * |
| 2830 | cm->delta_lf_res; |
| 2831 | xd->prev_delta_lf_from_base = xd->current_delta_lf_from_base; |
| 2832 | } |
| 2833 | #endif |
David Barker | 3aec8d6 | 2017-01-31 14:55:32 +0000 | [diff] [blame] | 2834 | } |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 2835 | #endif |
David Barker | 3aec8d6 | 2017-01-31 14:55:32 +0000 | [diff] [blame] | 2836 | |
| 2837 | #if CONFIG_SUPERTX |
| 2838 | if (!supertx_enabled) { |
| 2839 | #endif // CONFIG_SUPERTX |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2840 | inter_block = read_is_inter_block(cm, xd, mbmi->segment_id, r); |
| 2841 | |
| 2842 | #if CONFIG_VAR_TX |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 2843 | xd->above_txfm_context = |
| 2844 | cm->above_txfm_context + (mi_col << TX_UNIT_WIDE_LOG2); |
| 2845 | xd->left_txfm_context = xd->left_txfm_context_buffer + |
| 2846 | ((mi_row & MAX_MIB_MASK) << TX_UNIT_HIGH_LOG2); |
Jingning Han | 581d169 | 2017-01-05 16:03:54 -0800 | [diff] [blame] | 2847 | |
| 2848 | if (cm->tx_mode == TX_MODE_SELECT && |
| 2849 | #if CONFIG_CB4X4 |
Jingning Han | 3daa4fd | 2017-01-20 10:33:50 -0800 | [diff] [blame] | 2850 | bsize > BLOCK_4X4 && |
Jingning Han | 581d169 | 2017-01-05 16:03:54 -0800 | [diff] [blame] | 2851 | #else |
| 2852 | bsize >= BLOCK_8X8 && |
| 2853 | #endif |
| 2854 | !mbmi->skip && inter_block) { |
Jingning Han | 70e5f3f | 2016-11-09 17:03:07 -0800 | [diff] [blame] | 2855 | const TX_SIZE max_tx_size = max_txsize_rect_lookup[bsize]; |
Jingning Han | f64062f | 2016-11-02 16:22:18 -0700 | [diff] [blame] | 2856 | const int bh = tx_size_high_unit[max_tx_size]; |
| 2857 | const int bw = tx_size_wide_unit[max_tx_size]; |
Jingning Han | 65abc31 | 2016-10-27 13:04:21 -0700 | [diff] [blame] | 2858 | const int width = block_size_wide[bsize] >> tx_size_wide_log2[0]; |
| 2859 | const int height = block_size_high[bsize] >> tx_size_wide_log2[0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2860 | int idx, idy; |
Yue Chen | a1e48dc | 2016-08-29 17:29:33 -0700 | [diff] [blame] | 2861 | |
Jingning Han | fe45b21 | 2016-11-22 10:30:23 -0800 | [diff] [blame] | 2862 | mbmi->min_tx_size = TX_SIZES_ALL; |
| 2863 | for (idy = 0; idy < height; idy += bh) |
| 2864 | for (idx = 0; idx < width; idx += bw) |
| 2865 | read_tx_size_vartx(cm, xd, mbmi, xd->counts, max_tx_size, |
| 2866 | height != width, idy, idx, r); |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 2867 | #if CONFIG_RECT_TX_EXT |
| 2868 | if (is_quarter_tx_allowed(xd, mbmi, inter_block) && |
| 2869 | mbmi->tx_size == max_tx_size) { |
| 2870 | int quarter_tx; |
| 2871 | |
| 2872 | if (quarter_txsize_lookup[bsize] != max_tx_size) { |
| 2873 | quarter_tx = aom_read(r, cm->fc->quarter_tx_size_prob, ACCT_STR); |
| 2874 | if (xd->counts) ++xd->counts->quarter_tx_size[quarter_tx]; |
| 2875 | } else { |
| 2876 | quarter_tx = 1; |
| 2877 | } |
| 2878 | if (quarter_tx) { |
| 2879 | mbmi->tx_size = quarter_txsize_lookup[bsize]; |
| 2880 | for (idy = 0; idy < tx_size_high_unit[max_tx_size] / 2; ++idy) |
| 2881 | for (idx = 0; idx < tx_size_wide_unit[max_tx_size] / 2; ++idx) |
| 2882 | mbmi->inter_tx_size[idy][idx] = mbmi->tx_size; |
| 2883 | mbmi->min_tx_size = get_min_tx_size(mbmi->tx_size); |
| 2884 | } |
| 2885 | } |
| 2886 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2887 | } else { |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 2888 | mbmi->tx_size = read_tx_size(cm, xd, inter_block, !mbmi->skip, r); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2889 | |
| 2890 | if (inter_block) { |
Jingning Han | 9ca05b7 | 2017-01-03 14:41:36 -0800 | [diff] [blame] | 2891 | const int width = block_size_wide[bsize] >> tx_size_wide_log2[0]; |
| 2892 | const int height = block_size_high[bsize] >> tx_size_high_log2[0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2893 | int idx, idy; |
| 2894 | for (idy = 0; idy < height; ++idy) |
| 2895 | for (idx = 0; idx < width; ++idx) |
| 2896 | mbmi->inter_tx_size[idy >> 1][idx >> 1] = mbmi->tx_size; |
| 2897 | } |
Jingning Han | e67b38a | 2016-11-04 10:30:00 -0700 | [diff] [blame] | 2898 | mbmi->min_tx_size = get_min_tx_size(mbmi->tx_size); |
Jingning Han | 1b1dc93 | 2016-11-09 10:55:30 -0800 | [diff] [blame] | 2899 | set_txfm_ctxs(mbmi->tx_size, xd->n8_w, xd->n8_h, mbmi->skip, xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2900 | } |
| 2901 | #else |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 2902 | mbmi->tx_size = read_tx_size(cm, xd, inter_block, !mbmi->skip, r); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2903 | #endif // CONFIG_VAR_TX |
| 2904 | #if CONFIG_SUPERTX |
| 2905 | } |
| 2906 | #if CONFIG_VAR_TX |
| 2907 | else if (inter_block) { |
| 2908 | const int width = num_4x4_blocks_wide_lookup[bsize]; |
| 2909 | const int height = num_4x4_blocks_high_lookup[bsize]; |
| 2910 | int idx, idy; |
| 2911 | xd->mi[0]->mbmi.tx_size = xd->supertx_size; |
| 2912 | for (idy = 0; idy < height; ++idy) |
| 2913 | for (idx = 0; idx < width; ++idx) |
| 2914 | xd->mi[0]->mbmi.inter_tx_size[idy >> 1][idx >> 1] = xd->supertx_size; |
| 2915 | } |
| 2916 | #endif // CONFIG_VAR_TX |
| 2917 | #endif // CONFIG_SUPERTX |
| 2918 | |
| 2919 | if (inter_block) |
| 2920 | read_inter_block_mode_info(pbi, xd, |
David Barker | 491983d | 2016-11-10 13:22:17 +0000 | [diff] [blame] | 2921 | #if (CONFIG_MOTION_VAR || CONFIG_EXT_INTER || CONFIG_WARPED_MOTION) && \ |
| 2922 | CONFIG_SUPERTX |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2923 | |
| 2924 | mi, mi_row, mi_col, r, supertx_enabled); |
| 2925 | #else |
| 2926 | mi, mi_row, mi_col, r); |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2927 | #endif // CONFIG_MOTION_VAR && CONFIG_SUPERTX |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2928 | else |
Jingning Han | 36fe320 | 2017-02-20 22:31:49 -0800 | [diff] [blame] | 2929 | read_intra_block_mode_info(cm, mi_row, mi_col, xd, mi, r); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2930 | |
Angie Chiang | cd9b03f | 2017-04-16 13:37:13 -0700 | [diff] [blame] | 2931 | #if !CONFIG_TXK_SEL |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 2932 | av1_read_tx_type(cm, xd, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2933 | #if CONFIG_SUPERTX |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 2934 | supertx_enabled, |
Nathan E. Egge | 93878c4 | 2016-05-03 10:01:32 -0400 | [diff] [blame] | 2935 | #endif |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 2936 | r); |
Angie Chiang | cd9b03f | 2017-04-16 13:37:13 -0700 | [diff] [blame] | 2937 | #endif // !CONFIG_TXK_SEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2938 | } |
| 2939 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2940 | void av1_read_mode_info(AV1Decoder *const pbi, MACROBLOCKD *xd, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2941 | #if CONFIG_SUPERTX |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2942 | int supertx_enabled, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2943 | #endif // CONFIG_SUPERTX |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2944 | int mi_row, int mi_col, aom_reader *r, int x_mis, |
| 2945 | int y_mis) { |
| 2946 | AV1_COMMON *const cm = &pbi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2947 | MODE_INFO *const mi = xd->mi[0]; |
| 2948 | MV_REF *frame_mvs = cm->cur_frame->mvs + mi_row * cm->mi_cols + mi_col; |
| 2949 | int w, h; |
| 2950 | |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 2951 | #if CONFIG_INTRABC |
| 2952 | mi->mbmi.use_intrabc = 0; |
| 2953 | #endif // CONFIG_INTRABC |
| 2954 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2955 | if (frame_is_intra_only(cm)) { |
| 2956 | read_intra_frame_mode_info(cm, xd, mi_row, mi_col, r); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2957 | for (h = 0; h < y_mis; ++h) { |
| 2958 | MV_REF *const frame_mv = frame_mvs + h * cm->mi_cols; |
| 2959 | for (w = 0; w < x_mis; ++w) { |
| 2960 | MV_REF *const mv = frame_mv + w; |
Emil Keyder | 01770b3 | 2017-01-20 18:03:11 -0500 | [diff] [blame] | 2961 | mv->ref_frame[0] = NONE_FRAME; |
| 2962 | mv->ref_frame[1] = NONE_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2963 | } |
| 2964 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2965 | } else { |
| 2966 | read_inter_frame_mode_info(pbi, xd, |
| 2967 | #if CONFIG_SUPERTX |
| 2968 | supertx_enabled, |
| 2969 | #endif // CONFIG_SUPERTX |
| 2970 | mi_row, mi_col, r); |
| 2971 | for (h = 0; h < y_mis; ++h) { |
| 2972 | MV_REF *const frame_mv = frame_mvs + h * cm->mi_cols; |
| 2973 | for (w = 0; w < x_mis; ++w) { |
| 2974 | MV_REF *const mv = frame_mv + w; |
| 2975 | mv->ref_frame[0] = mi->mbmi.ref_frame[0]; |
| 2976 | mv->ref_frame[1] = mi->mbmi.ref_frame[1]; |
| 2977 | mv->mv[0].as_int = mi->mbmi.mv[0].as_int; |
| 2978 | mv->mv[1].as_int = mi->mbmi.mv[1].as_int; |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 2979 | mv->pred_mv[0].as_int = mi->mbmi.pred_mv[0].as_int; |
| 2980 | mv->pred_mv[1].as_int = mi->mbmi.pred_mv[1].as_int; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2981 | } |
| 2982 | } |
| 2983 | } |
| 2984 | } |