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