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] = |
hui su | 40b9e7f | 2017-07-13 18:15:56 -0700 | [diff] [blame] | 893 | av1_read_uniform(r, FILTER_INTRA_MODES); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 894 | } |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 895 | if (counts) { |
clang-format | 55ce9e0 | 2017-02-15 22:27:12 -0800 | [diff] [blame] | 896 | ++counts |
| 897 | ->filter_intra[0][filter_intra_mode_info->use_filter_intra_mode[0]]; |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 898 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 899 | } |
Jingning Han | 62946d1 | 2017-05-26 11:29:30 -0700 | [diff] [blame] | 900 | |
| 901 | #if CONFIG_CB4X4 |
| 902 | if (!is_chroma_reference(mi_row, mi_col, mbmi->sb_type, |
| 903 | xd->plane[1].subsampling_x, |
| 904 | xd->plane[1].subsampling_y)) |
| 905 | return; |
hui su | b4ed149 | 2017-05-31 17:25:42 -0700 | [diff] [blame] | 906 | #else |
| 907 | (void)mi_row; |
| 908 | (void)mi_col; |
| 909 | #endif // CONFIG_CB4X4 |
Jingning Han | 62946d1 | 2017-05-26 11:29:30 -0700 | [diff] [blame] | 910 | |
Urvang Joshi | c6300aa | 2017-06-01 14:46:23 -0700 | [diff] [blame] | 911 | if (mbmi->uv_mode == UV_DC_PRED && |
| 912 | mbmi->palette_mode_info.palette_size[1] == 0) { |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 913 | filter_intra_mode_info->use_filter_intra_mode[1] = |
| 914 | aom_read(r, cm->fc->filter_intra_probs[1], ACCT_STR); |
| 915 | if (filter_intra_mode_info->use_filter_intra_mode[1]) { |
| 916 | filter_intra_mode_info->filter_intra_mode[1] = |
hui su | 40b9e7f | 2017-07-13 18:15:56 -0700 | [diff] [blame] | 917 | av1_read_uniform(r, FILTER_INTRA_MODES); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 918 | } |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 919 | if (counts) { |
clang-format | 55ce9e0 | 2017-02-15 22:27:12 -0800 | [diff] [blame] | 920 | ++counts |
| 921 | ->filter_intra[1][filter_intra_mode_info->use_filter_intra_mode[1]]; |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 922 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 923 | } |
| 924 | } |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 925 | #endif // CONFIG_FILTER_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 926 | |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 927 | #if CONFIG_EXT_INTRA |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 928 | static void read_intra_angle_info(AV1_COMMON *const cm, MACROBLOCKD *const xd, |
| 929 | aom_reader *r) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 930 | MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
| 931 | const BLOCK_SIZE bsize = mbmi->sb_type; |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 932 | #if CONFIG_INTRA_INTERP |
hui su | b4e25d2 | 2017-03-09 15:32:30 -0800 | [diff] [blame] | 933 | FRAME_CONTEXT *const ec_ctx = xd->tile_ctx; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 934 | const int ctx = av1_get_pred_context_intra_interp(xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 935 | int p_angle; |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 936 | #endif // CONFIG_INTRA_INTERP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 937 | |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 938 | (void)cm; |
Joe Young | 830d4ce | 2017-05-30 17:48:13 -0700 | [diff] [blame] | 939 | |
| 940 | mbmi->angle_delta[0] = 0; |
| 941 | mbmi->angle_delta[1] = 0; |
Jonathan Matthews | 67c9ab0 | 2017-09-27 13:38:50 +0100 | [diff] [blame] | 942 | #if CONFIG_INTRA_INTERP |
| 943 | mbmi->intra_filter = INTRA_FILTER_LINEAR; |
| 944 | #endif // CONFIG_INTRA_INTERP |
Joe Young | 830d4ce | 2017-05-30 17:48:13 -0700 | [diff] [blame] | 945 | |
| 946 | if (!av1_use_angle_delta(bsize)) return; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 947 | |
hui su | 45dc597 | 2016-12-08 17:42:50 -0800 | [diff] [blame] | 948 | if (av1_is_directional_mode(mbmi->mode, bsize)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 949 | mbmi->angle_delta[0] = |
hui su | 40b9e7f | 2017-07-13 18:15:56 -0700 | [diff] [blame] | 950 | av1_read_uniform(r, 2 * MAX_ANGLE_DELTA + 1) - MAX_ANGLE_DELTA; |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 951 | #if CONFIG_INTRA_INTERP |
hui su | 0a6731f | 2017-04-26 15:23:47 -0700 | [diff] [blame] | 952 | p_angle = mode_to_angle_map[mbmi->mode] + mbmi->angle_delta[0] * ANGLE_STEP; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 953 | if (av1_is_intra_filter_switchable(p_angle)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 954 | FRAME_COUNTS *counts = xd->counts; |
hui su | b4e25d2 | 2017-03-09 15:32:30 -0800 | [diff] [blame] | 955 | mbmi->intra_filter = aom_read_symbol(r, ec_ctx->intra_filter_cdf[ctx], |
| 956 | INTRA_FILTERS, ACCT_STR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 957 | if (counts) ++counts->intra_filter[ctx][mbmi->intra_filter]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 958 | } |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 959 | #endif // CONFIG_INTRA_INTERP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 960 | } |
| 961 | |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 962 | if (av1_is_directional_mode(get_uv_mode(mbmi->uv_mode), bsize)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 963 | mbmi->angle_delta[1] = |
hui su | 40b9e7f | 2017-07-13 18:15:56 -0700 | [diff] [blame] | 964 | av1_read_uniform(r, 2 * MAX_ANGLE_DELTA + 1) - MAX_ANGLE_DELTA; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 965 | } |
| 966 | } |
| 967 | #endif // CONFIG_EXT_INTRA |
| 968 | |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 969 | void av1_read_tx_type(const AV1_COMMON *const cm, MACROBLOCKD *xd, |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 970 | #if CONFIG_SUPERTX |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 971 | int supertx_enabled, |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 972 | #endif |
Angie Chiang | cd9b03f | 2017-04-16 13:37:13 -0700 | [diff] [blame] | 973 | #if CONFIG_TXK_SEL |
Jingning Han | 19b5c8f | 2017-07-06 15:10:12 -0700 | [diff] [blame] | 974 | int blk_row, int blk_col, int block, int plane, |
| 975 | TX_SIZE tx_size, |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 976 | #endif |
| 977 | aom_reader *r) { |
| 978 | MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 979 | const int inter_block = is_inter_block(mbmi); |
Jingning Han | 243b66b | 2017-06-23 12:11:47 -0700 | [diff] [blame] | 980 | #if !CONFIG_TXK_SEL |
Jingning Han | e67b38a | 2016-11-04 10:30:00 -0700 | [diff] [blame] | 981 | #if CONFIG_VAR_TX |
| 982 | const TX_SIZE tx_size = inter_block ? mbmi->min_tx_size : mbmi->tx_size; |
| 983 | #else |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 984 | const TX_SIZE tx_size = mbmi->tx_size; |
Jingning Han | e67b38a | 2016-11-04 10:30:00 -0700 | [diff] [blame] | 985 | #endif |
Jingning Han | 243b66b | 2017-06-23 12:11:47 -0700 | [diff] [blame] | 986 | #endif // !CONFIG_TXK_SEL |
Thomas Davies | cef0962 | 2017-01-11 17:27:12 +0000 | [diff] [blame] | 987 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
Thomas Davies | cef0962 | 2017-01-11 17:27:12 +0000 | [diff] [blame] | 988 | |
Angie Chiang | cd9b03f | 2017-04-16 13:37:13 -0700 | [diff] [blame] | 989 | #if !CONFIG_TXK_SEL |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 990 | TX_TYPE *tx_type = &mbmi->tx_type; |
| 991 | #else |
Angie Chiang | 39b06eb | 2017-04-14 09:52:29 -0700 | [diff] [blame] | 992 | // only y plane's tx_type is transmitted |
| 993 | if (plane > 0) return; |
Jingning Han | 19b5c8f | 2017-07-06 15:10:12 -0700 | [diff] [blame] | 994 | (void)block; |
| 995 | TX_TYPE *tx_type = &mbmi->txk_type[(blk_row << 4) + blk_col]; |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 996 | #endif |
| 997 | |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 998 | if (!FIXED_TX_TYPE) { |
| 999 | #if CONFIG_EXT_TX |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 1000 | const TX_SIZE square_tx_size = txsize_sqr_map[tx_size]; |
Sarah Parker | e68a3e4 | 2017-02-16 14:03:24 -0800 | [diff] [blame] | 1001 | if (get_ext_tx_types(tx_size, mbmi->sb_type, inter_block, |
| 1002 | cm->reduced_tx_set_used) > 1 && |
Yue Chen | eeacc4c | 2017-01-17 17:29:17 -0800 | [diff] [blame] | 1003 | ((!cm->seg.enabled && cm->base_qindex > 0) || |
| 1004 | (cm->seg.enabled && xd->qindex[mbmi->segment_id] > 0)) && |
| 1005 | !mbmi->skip && |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 1006 | #if CONFIG_SUPERTX |
| 1007 | !supertx_enabled && |
| 1008 | #endif // CONFIG_SUPERTX |
| 1009 | !segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 1010 | const TxSetType tx_set_type = get_ext_tx_set_type( |
| 1011 | tx_size, mbmi->sb_type, inter_block, cm->reduced_tx_set_used); |
Sarah Parker | e68a3e4 | 2017-02-16 14:03:24 -0800 | [diff] [blame] | 1012 | const int eset = get_ext_tx_set(tx_size, mbmi->sb_type, inter_block, |
| 1013 | cm->reduced_tx_set_used); |
Sarah Parker | 784596d | 2017-06-23 08:41:26 -0700 | [diff] [blame] | 1014 | // eset == 0 should correspond to a set with only DCT_DCT and |
| 1015 | // there is no need to read the tx_type |
| 1016 | assert(eset != 0); |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 1017 | if (inter_block) { |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 1018 | *tx_type = av1_ext_tx_inv[tx_set_type][aom_read_symbol( |
Sarah Parker | 784596d | 2017-06-23 08:41:26 -0700 | [diff] [blame] | 1019 | r, ec_ctx->inter_ext_tx_cdf[eset][square_tx_size], |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 1020 | av1_num_ext_tx_set[tx_set_type], ACCT_STR)]; |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 1021 | } else if (ALLOW_INTRA_EXT_TX) { |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 1022 | *tx_type = av1_ext_tx_inv[tx_set_type][aom_read_symbol( |
Sarah Parker | 784596d | 2017-06-23 08:41:26 -0700 | [diff] [blame] | 1023 | 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] | 1024 | av1_num_ext_tx_set[tx_set_type], ACCT_STR)]; |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 1025 | } |
| 1026 | } else { |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 1027 | *tx_type = DCT_DCT; |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 1028 | } |
| 1029 | #else |
Yue Chen | eeacc4c | 2017-01-17 17:29:17 -0800 | [diff] [blame] | 1030 | |
| 1031 | if (tx_size < TX_32X32 && |
| 1032 | ((!cm->seg.enabled && cm->base_qindex > 0) || |
| 1033 | (cm->seg.enabled && xd->qindex[mbmi->segment_id] > 0)) && |
| 1034 | !mbmi->skip && |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 1035 | #if CONFIG_SUPERTX |
| 1036 | !supertx_enabled && |
| 1037 | #endif // CONFIG_SUPERTX |
| 1038 | !segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { |
Hui Su | 98b0b3e | 2017-09-19 13:54:02 -0700 | [diff] [blame] | 1039 | #if CONFIG_ENTROPY_STATS |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 1040 | FRAME_COUNTS *counts = xd->counts; |
Hui Su | 98b0b3e | 2017-09-19 13:54:02 -0700 | [diff] [blame] | 1041 | #endif // CONFIG_ENTROPY_STATS |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 1042 | if (inter_block) { |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 1043 | *tx_type = av1_ext_tx_inv[aom_read_symbol( |
Thomas Davies | cef0962 | 2017-01-11 17:27:12 +0000 | [diff] [blame] | 1044 | 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] | 1045 | #if CONFIG_ENTROPY_STATS |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 1046 | if (counts) ++counts->inter_ext_tx[tx_size][*tx_type]; |
Hui Su | 98b0b3e | 2017-09-19 13:54:02 -0700 | [diff] [blame] | 1047 | #endif // CONFIG_ENTROPY_STATS |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 1048 | } else { |
| 1049 | 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] | 1050 | *tx_type = av1_ext_tx_inv[aom_read_symbol( |
Thomas Davies | cef0962 | 2017-01-11 17:27:12 +0000 | [diff] [blame] | 1051 | 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] | 1052 | ACCT_STR)]; |
Hui Su | 98b0b3e | 2017-09-19 13:54:02 -0700 | [diff] [blame] | 1053 | #if CONFIG_ENTROPY_STATS |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 1054 | 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] | 1055 | #endif // CONFIG_ENTROPY_STATS |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 1056 | } |
| 1057 | } else { |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 1058 | *tx_type = DCT_DCT; |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 1059 | } |
| 1060 | #endif // CONFIG_EXT_TX |
| 1061 | } |
Nathan E. Egge | ebced37 | 2017-02-17 20:57:21 -0500 | [diff] [blame] | 1062 | #if FIXED_TX_TYPE |
| 1063 | assert(mbmi->tx_type == DCT_DCT); |
| 1064 | #endif |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 1065 | } |
| 1066 | |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 1067 | #if CONFIG_INTRABC |
| 1068 | static INLINE void read_mv(aom_reader *r, MV *mv, const MV *ref, |
| 1069 | nmv_context *ctx, nmv_context_counts *counts, |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1070 | MvSubpelPrecision precision); |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 1071 | |
| 1072 | static INLINE int is_mv_valid(const MV *mv); |
| 1073 | |
| 1074 | static INLINE int assign_dv(AV1_COMMON *cm, MACROBLOCKD *xd, int_mv *mv, |
| 1075 | const int_mv *ref_mv, int mi_row, int mi_col, |
| 1076 | BLOCK_SIZE bsize, aom_reader *r) { |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 1077 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
| 1078 | (void)cm; |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 1079 | FRAME_COUNTS *counts = xd->counts; |
| 1080 | nmv_context_counts *const dv_counts = counts ? &counts->dv : NULL; |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1081 | read_mv(r, &mv->as_mv, &ref_mv->as_mv, &ec_ctx->ndvc, dv_counts, |
| 1082 | MV_SUBPEL_NONE); |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 1083 | int valid = is_mv_valid(&mv->as_mv) && |
| 1084 | 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] | 1085 | return valid; |
| 1086 | } |
| 1087 | #endif // CONFIG_INTRABC |
| 1088 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1089 | static void read_intra_frame_mode_info(AV1_COMMON *const cm, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1090 | MACROBLOCKD *const xd, int mi_row, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1091 | int mi_col, aom_reader *r) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1092 | MODE_INFO *const mi = xd->mi[0]; |
| 1093 | MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 1094 | const MODE_INFO *above_mi = xd->above_mi; |
| 1095 | const MODE_INFO *left_mi = xd->left_mi; |
| 1096 | const BLOCK_SIZE bsize = mbmi->sb_type; |
| 1097 | int i; |
| 1098 | const int mi_offset = mi_row * cm->mi_cols + mi_col; |
Jingning Han | 85dc03f | 2016-12-06 16:03:10 -0800 | [diff] [blame] | 1099 | const int bw = mi_size_wide[bsize]; |
| 1100 | const int bh = mi_size_high[bsize]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1101 | |
| 1102 | // TODO(slavarnway): move x_mis, y_mis into xd ????? |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1103 | const int x_mis = AOMMIN(cm->mi_cols - mi_col, bw); |
| 1104 | const int y_mis = AOMMIN(cm->mi_rows - mi_row, bh); |
Thomas Davies | 1bfb5ed | 2017-01-11 15:28:11 +0000 | [diff] [blame] | 1105 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1106 | |
| 1107 | mbmi->segment_id = read_intra_segment_id(cm, xd, mi_offset, x_mis, y_mis, r); |
| 1108 | mbmi->skip = read_skip(cm, xd, mbmi->segment_id, r); |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 1109 | |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 1110 | if (cm->delta_q_present_flag) { |
Thomas Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 1111 | xd->current_qindex = |
| 1112 | xd->prev_qindex + |
| 1113 | 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] | 1114 | /* Normative: Clamp to [1,MAXQ] to not interfere with lossless mode */ |
| 1115 | xd->current_qindex = clamp(xd->current_qindex, 1, MAXQ); |
Thomas Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 1116 | xd->prev_qindex = xd->current_qindex; |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 1117 | #if CONFIG_EXT_DELTA_Q |
| 1118 | if (cm->delta_lf_present_flag) { |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 1119 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 880166a | 2017-10-02 17:48:48 -0700 | [diff] [blame] | 1120 | if (cm->delta_lf_multi) { |
| 1121 | for (int lf_id = 0; lf_id < FRAME_LF_COUNT; ++lf_id) { |
| 1122 | mbmi->curr_delta_lf[lf_id] = xd->curr_delta_lf[lf_id] = |
| 1123 | xd->prev_delta_lf[lf_id] + |
| 1124 | read_delta_lflevel(cm, xd, r, lf_id, mbmi, mi_col, mi_row) * |
| 1125 | cm->delta_lf_res; |
| 1126 | xd->prev_delta_lf[lf_id] = xd->curr_delta_lf[lf_id]; |
| 1127 | } |
| 1128 | } else { |
| 1129 | mbmi->current_delta_lf_from_base = xd->current_delta_lf_from_base = |
| 1130 | xd->prev_delta_lf_from_base + |
| 1131 | read_delta_lflevel(cm, xd, r, -1, mbmi, mi_col, mi_row) * |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 1132 | cm->delta_lf_res; |
Cheng Chen | 880166a | 2017-10-02 17:48:48 -0700 | [diff] [blame] | 1133 | xd->prev_delta_lf_from_base = xd->current_delta_lf_from_base; |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 1134 | } |
| 1135 | #else |
Cheng Chen | 9dccdf2 | 2017-10-02 15:04:40 -0700 | [diff] [blame] | 1136 | const int current_delta_lf_from_base = |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 1137 | xd->prev_delta_lf_from_base + |
| 1138 | read_delta_lflevel(cm, xd, r, mbmi, mi_col, mi_row) * |
| 1139 | cm->delta_lf_res; |
Cheng Chen | 9dccdf2 | 2017-10-02 15:04:40 -0700 | [diff] [blame] | 1140 | mbmi->current_delta_lf_from_base = xd->current_delta_lf_from_base = |
| 1141 | clamp(current_delta_lf_from_base, 0, MAX_LOOP_FILTER); |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 1142 | xd->prev_delta_lf_from_base = xd->current_delta_lf_from_base; |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 1143 | #endif // CONFIG_LOOPFILTER_LEVEL |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 1144 | } |
| 1145 | #endif |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 1146 | } |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 1147 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1148 | mbmi->ref_frame[0] = INTRA_FRAME; |
Emil Keyder | 01770b3 | 2017-01-20 18:03:11 -0500 | [diff] [blame] | 1149 | mbmi->ref_frame[1] = NONE_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1150 | |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 1151 | #if CONFIG_INTRABC |
RogerZhou | ca86546 | 2017-10-05 15:06:27 -0700 | [diff] [blame] | 1152 | if (av1_allow_intrabc(bsize, cm)) { |
Hui Su | 6c8584f | 2017-09-14 15:37:02 -0700 | [diff] [blame] | 1153 | mbmi->use_intrabc = aom_read_symbol(r, ec_ctx->intrabc_cdf, 2, ACCT_STR); |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 1154 | if (mbmi->use_intrabc) { |
Alex Converse | f71808c | 2017-06-06 12:21:17 -0700 | [diff] [blame] | 1155 | mbmi->tx_size = read_tx_size(cm, xd, 1, !mbmi->skip, r); |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 1156 | mbmi->mode = mbmi->uv_mode = UV_DC_PRED; |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 1157 | mbmi->interp_filters = av1_broadcast_interp_filter(BILINEAR); |
Alex Converse | 44c2bad | 2017-05-11 09:36:10 -0700 | [diff] [blame] | 1158 | |
| 1159 | int16_t inter_mode_ctx[MODE_CTX_REF_FRAMES]; |
Ryan | 95acd06 | 2017-09-29 14:56:44 -0700 | [diff] [blame] | 1160 | int_mv ref_mvs[MAX_MV_REF_CANDIDATES]; |
Alex Converse | 44c2bad | 2017-05-11 09:36:10 -0700 | [diff] [blame] | 1161 | |
| 1162 | av1_find_mv_refs(cm, xd, mi, INTRA_FRAME, &xd->ref_mv_count[INTRA_FRAME], |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 1163 | xd->ref_mv_stack[INTRA_FRAME], NULL, ref_mvs, mi_row, |
| 1164 | mi_col, NULL, NULL, inter_mode_ctx); |
Alex Converse | 44c2bad | 2017-05-11 09:36:10 -0700 | [diff] [blame] | 1165 | |
| 1166 | int_mv nearestmv, nearmv; |
| 1167 | av1_find_best_ref_mvs(0, ref_mvs, &nearestmv, &nearmv); |
| 1168 | |
| 1169 | int_mv dv_ref = nearestmv.as_int == 0 ? nearmv : nearestmv; |
| 1170 | if (dv_ref.as_int == 0) av1_find_ref_dv(&dv_ref, mi_row, mi_col); |
| 1171 | |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 1172 | xd->corrupted |= |
| 1173 | !assign_dv(cm, xd, &mbmi->mv[0], &dv_ref, mi_row, mi_col, bsize, r); |
Alex Converse | e16b266 | 2017-05-24 14:00:00 -0700 | [diff] [blame] | 1174 | #if CONFIG_VAR_TX |
| 1175 | // TODO(aconverse@google.com): Evaluate allowing VAR TX on intrabc blocks |
| 1176 | const int width = block_size_wide[bsize] >> tx_size_wide_log2[0]; |
| 1177 | const int height = block_size_high[bsize] >> tx_size_high_log2[0]; |
| 1178 | int idx, idy; |
| 1179 | for (idy = 0; idy < height; ++idy) |
| 1180 | for (idx = 0; idx < width; ++idx) |
| 1181 | mbmi->inter_tx_size[idy >> 1][idx >> 1] = mbmi->tx_size; |
| 1182 | mbmi->min_tx_size = get_min_tx_size(mbmi->tx_size); |
| 1183 | #endif // CONFIG_VAR_TX |
Alex Converse | daa15e4 | 2017-05-02 14:27:16 -0700 | [diff] [blame] | 1184 | #if CONFIG_EXT_TX && !CONFIG_TXK_SEL |
| 1185 | av1_read_tx_type(cm, xd, |
| 1186 | #if CONFIG_SUPERTX |
| 1187 | 0, |
| 1188 | #endif |
| 1189 | r); |
| 1190 | #endif // CONFIG_EXT_TX && !CONFIG_TXK_SEL |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 1191 | return; |
| 1192 | } |
| 1193 | } |
| 1194 | #endif // CONFIG_INTRABC |
| 1195 | |
Alex Converse | f71808c | 2017-06-06 12:21:17 -0700 | [diff] [blame] | 1196 | mbmi->tx_size = read_tx_size(cm, xd, 0, 1, r); |
| 1197 | |
Jingning Han | 5226184 | 2016-12-14 12:17:49 -0800 | [diff] [blame] | 1198 | #if CONFIG_CB4X4 |
| 1199 | (void)i; |
| 1200 | mbmi->mode = |
Thomas Davies | 1bfb5ed | 2017-01-11 15:28:11 +0000 | [diff] [blame] | 1201 | 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] | 1202 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1203 | switch (bsize) { |
| 1204 | case BLOCK_4X4: |
| 1205 | for (i = 0; i < 4; ++i) |
Nathan E. Egge | 476c63c | 2017-05-18 18:35:16 -0400 | [diff] [blame] | 1206 | mi->bmi[i].as_mode = read_intra_mode( |
| 1207 | 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] | 1208 | mbmi->mode = mi->bmi[3].as_mode; |
| 1209 | break; |
| 1210 | case BLOCK_4X8: |
| 1211 | mi->bmi[0].as_mode = mi->bmi[2].as_mode = |
Thomas Davies | 1bfb5ed | 2017-01-11 15:28:11 +0000 | [diff] [blame] | 1212 | 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] | 1213 | mi->bmi[1].as_mode = mi->bmi[3].as_mode = mbmi->mode = |
Thomas Davies | 1bfb5ed | 2017-01-11 15:28:11 +0000 | [diff] [blame] | 1214 | 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] | 1215 | break; |
| 1216 | case BLOCK_8X4: |
| 1217 | mi->bmi[0].as_mode = mi->bmi[1].as_mode = |
Thomas Davies | 1bfb5ed | 2017-01-11 15:28:11 +0000 | [diff] [blame] | 1218 | 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] | 1219 | mi->bmi[2].as_mode = mi->bmi[3].as_mode = mbmi->mode = |
Thomas Davies | 1bfb5ed | 2017-01-11 15:28:11 +0000 | [diff] [blame] | 1220 | 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] | 1221 | break; |
| 1222 | default: |
| 1223 | mbmi->mode = |
Thomas Davies | 1bfb5ed | 2017-01-11 15:28:11 +0000 | [diff] [blame] | 1224 | 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] | 1225 | } |
Jingning Han | 5226184 | 2016-12-14 12:17:49 -0800 | [diff] [blame] | 1226 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1227 | |
Jingning Han | 36fe320 | 2017-02-20 22:31:49 -0800 | [diff] [blame] | 1228 | #if CONFIG_CB4X4 |
Jingning Han | d3a6443 | 2017-04-06 17:04:17 -0700 | [diff] [blame] | 1229 | 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] | 1230 | xd->plane[1].subsampling_y)) { |
Luc Trudeau | c84c21c | 2017-07-25 19:40:34 -0400 | [diff] [blame] | 1231 | #if CONFIG_CFL |
| 1232 | xd->cfl->is_chroma_reference = 1; |
| 1233 | #endif // CONFIG_CFL |
| 1234 | #endif // CONFIG_CB4X4 |
Hui Su | aa2965e | 2017-10-05 15:59:12 -0700 | [diff] [blame] | 1235 | mbmi->uv_mode = read_intra_mode_uv(ec_ctx, r, mbmi->mode); |
Jingning Han | 36fe320 | 2017-02-20 22:31:49 -0800 | [diff] [blame] | 1236 | |
Luc Trudeau | f533400 | 2017-04-25 12:21:26 -0400 | [diff] [blame] | 1237 | #if CONFIG_CFL |
Luc Trudeau | 6e1cd78 | 2017-06-21 13:52:36 -0400 | [diff] [blame] | 1238 | if (mbmi->uv_mode == UV_CFL_PRED) { |
David Michael Barr | f6eaa15 | 2017-07-19 19:42:28 +0900 | [diff] [blame] | 1239 | 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] | 1240 | xd->cfl->store_y = 1; |
Luc Trudeau | e784b3f | 2017-08-14 15:25:28 -0400 | [diff] [blame] | 1241 | } else { |
| 1242 | xd->cfl->store_y = 0; |
Luc Trudeau | f533400 | 2017-04-25 12:21:26 -0400 | [diff] [blame] | 1243 | } |
Luc Trudeau | 2c31790 | 2017-04-28 11:06:50 -0400 | [diff] [blame] | 1244 | #endif // CONFIG_CFL |
| 1245 | |
| 1246 | #if CONFIG_CB4X4 |
Joe Young | 830d4ce | 2017-05-30 17:48:13 -0700 | [diff] [blame] | 1247 | } else { |
| 1248 | // Avoid decoding angle_info if there is is no chroma prediction |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 1249 | mbmi->uv_mode = UV_DC_PRED; |
Luc Trudeau | c84c21c | 2017-07-25 19:40:34 -0400 | [diff] [blame] | 1250 | #if CONFIG_CFL |
| 1251 | xd->cfl->is_chroma_reference = 0; |
Luc Trudeau | b05eeae | 2017-08-18 15:14:30 -0400 | [diff] [blame] | 1252 | xd->cfl->store_y = 1; |
Luc Trudeau | c84c21c | 2017-07-25 19:40:34 -0400 | [diff] [blame] | 1253 | #endif |
Luc Trudeau | f533400 | 2017-04-25 12:21:26 -0400 | [diff] [blame] | 1254 | } |
| 1255 | #endif |
| 1256 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1257 | #if CONFIG_EXT_INTRA |
| 1258 | read_intra_angle_info(cm, xd, r); |
| 1259 | #endif // CONFIG_EXT_INTRA |
| 1260 | mbmi->palette_mode_info.palette_size[0] = 0; |
| 1261 | mbmi->palette_mode_info.palette_size[1] = 0; |
Rupert Swarbrick | 6f9cd94 | 2017-08-02 15:57:18 +0100 | [diff] [blame] | 1262 | if (bsize >= BLOCK_8X8 && bsize <= BLOCK_LARGEST && |
| 1263 | cm->allow_screen_content_tools) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1264 | read_palette_mode_info(cm, xd, r); |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 1265 | #if CONFIG_FILTER_INTRA |
| 1266 | mbmi->filter_intra_mode_info.use_filter_intra_mode[0] = 0; |
| 1267 | mbmi->filter_intra_mode_info.use_filter_intra_mode[1] = 0; |
Jingning Han | 48b1cb3 | 2017-01-23 10:26:14 -0800 | [diff] [blame] | 1268 | if (bsize >= BLOCK_8X8 || CONFIG_CB4X4) |
Jingning Han | 62946d1 | 2017-05-26 11:29:30 -0700 | [diff] [blame] | 1269 | read_filter_intra_mode_info(cm, xd, mi_row, mi_col, r); |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 1270 | #endif // CONFIG_FILTER_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1271 | |
Angie Chiang | cd9b03f | 2017-04-16 13:37:13 -0700 | [diff] [blame] | 1272 | #if !CONFIG_TXK_SEL |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 1273 | av1_read_tx_type(cm, xd, |
Jingning Han | ab7163d | 2016-11-04 09:46:35 -0700 | [diff] [blame] | 1274 | #if CONFIG_SUPERTX |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 1275 | 0, |
Nathan E. Egge | 72762a2 | 2016-09-07 17:12:07 -0400 | [diff] [blame] | 1276 | #endif |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 1277 | r); |
Angie Chiang | cd9b03f | 2017-04-16 13:37:13 -0700 | [diff] [blame] | 1278 | #endif // !CONFIG_TXK_SEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1279 | } |
| 1280 | |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1281 | static int read_mv_component(aom_reader *r, nmv_component *mvcomp, |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1282 | #if CONFIG_INTRABC || CONFIG_AMVR |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1283 | int use_subpel, |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1284 | #endif // CONFIG_INTRABC || CONFIG_AMVR |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1285 | int usehp) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1286 | int mag, d, fr, hp; |
Thomas Davies | 599395e | 2017-07-21 18:02:48 +0100 | [diff] [blame] | 1287 | #if CONFIG_NEW_MULTISYMBOL |
| 1288 | const int sign = aom_read_bit(r, ACCT_STR); |
| 1289 | #else |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 1290 | const int sign = aom_read(r, mvcomp->sign, ACCT_STR); |
Thomas Davies | 599395e | 2017-07-21 18:02:48 +0100 | [diff] [blame] | 1291 | #endif |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 1292 | const int mv_class = |
Nathan E. Egge | d7b893c | 2016-09-08 15:08:48 -0400 | [diff] [blame] | 1293 | aom_read_symbol(r, mvcomp->class_cdf, MV_CLASSES, ACCT_STR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1294 | const int class0 = mv_class == MV_CLASS_0; |
| 1295 | |
| 1296 | // Integer part |
| 1297 | if (class0) { |
Thomas Davies | 599395e | 2017-07-21 18:02:48 +0100 | [diff] [blame] | 1298 | #if CONFIG_NEW_MULTISYMBOL |
| 1299 | d = aom_read_symbol(r, mvcomp->class0_cdf, CLASS0_SIZE, ACCT_STR); |
| 1300 | #else |
Nathan E. Egge | 45ea963 | 2016-09-08 17:25:49 -0400 | [diff] [blame] | 1301 | d = aom_read(r, mvcomp->class0[0], ACCT_STR); |
Thomas Davies | 599395e | 2017-07-21 18:02:48 +0100 | [diff] [blame] | 1302 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1303 | mag = 0; |
| 1304 | } else { |
| 1305 | int i; |
| 1306 | const int n = mv_class + CLASS0_BITS - 1; // number of bits |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1307 | d = 0; |
Thomas Davies | 0e7b1d7 | 2017-10-02 10:54:24 +0100 | [diff] [blame] | 1308 | #if CONFIG_NEW_MULTISYMBOL |
| 1309 | for (i = 0; i < n; ++i) |
| 1310 | d |= aom_read_symbol(r, mvcomp->bits_cdf[(i + 1) / 2], 2, ACCT_STR) << i; |
| 1311 | #else |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 1312 | 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] | 1313 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1314 | mag = CLASS0_SIZE << (mv_class + 2); |
| 1315 | } |
| 1316 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1317 | #if CONFIG_INTRABC || CONFIG_AMVR |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1318 | if (use_subpel) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1319 | #endif // CONFIG_INTRABC || CONFIG_AMVR |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1320 | // Fractional part |
| 1321 | fr = aom_read_symbol(r, class0 ? mvcomp->class0_fp_cdf[d] : mvcomp->fp_cdf, |
| 1322 | MV_FP_SIZE, ACCT_STR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1323 | |
Thomas Davies | 599395e | 2017-07-21 18:02:48 +0100 | [diff] [blame] | 1324 | // High precision part (if hp is not used, the default value of the hp is 1) |
| 1325 | #if CONFIG_NEW_MULTISYMBOL |
| 1326 | hp = usehp ? aom_read_symbol( |
| 1327 | r, class0 ? mvcomp->class0_hp_cdf : mvcomp->hp_cdf, 2, |
| 1328 | ACCT_STR) |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1329 | : 1; |
Thomas Davies | 599395e | 2017-07-21 18:02:48 +0100 | [diff] [blame] | 1330 | #else |
| 1331 | hp = usehp ? aom_read(r, class0 ? mvcomp->class0_hp : mvcomp->hp, ACCT_STR) |
| 1332 | : 1; |
| 1333 | #endif |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1334 | #if CONFIG_INTRABC || CONFIG_AMVR |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1335 | } else { |
| 1336 | fr = 3; |
| 1337 | hp = 1; |
| 1338 | } |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1339 | #endif // CONFIG_INTRABC || CONFIG_AMVR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1340 | |
| 1341 | // Result |
| 1342 | mag += ((d << 3) | (fr << 1) | hp) + 1; |
| 1343 | return sign ? -mag : mag; |
| 1344 | } |
| 1345 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1346 | static INLINE void read_mv(aom_reader *r, MV *mv, const MV *ref, |
Thomas | 9ac5508 | 2016-09-23 18:04:17 +0100 | [diff] [blame] | 1347 | nmv_context *ctx, nmv_context_counts *counts, |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1348 | MvSubpelPrecision precision) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1349 | MV_JOINT_TYPE joint_type; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1350 | MV diff = { 0, 0 }; |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 1351 | joint_type = |
Nathan E. Egge | 5f7fd7a | 2016-09-08 11:22:03 -0400 | [diff] [blame] | 1352 | (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] | 1353 | |
| 1354 | if (mv_joint_vertical(joint_type)) |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1355 | diff.row = read_mv_component(r, &ctx->comps[0], |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1356 | #if CONFIG_INTRABC || CONFIG_AMVR |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1357 | precision > MV_SUBPEL_NONE, |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1358 | #endif // CONFIG_INTRABC || CONFIG_AMVR |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1359 | precision > MV_SUBPEL_LOW_PRECISION); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1360 | |
| 1361 | if (mv_joint_horizontal(joint_type)) |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1362 | diff.col = read_mv_component(r, &ctx->comps[1], |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1363 | #if CONFIG_INTRABC || CONFIG_AMVR |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1364 | precision > MV_SUBPEL_NONE, |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1365 | #endif // CONFIG_INTRABC || CONFIG_AMVR |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1366 | precision > MV_SUBPEL_LOW_PRECISION); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1367 | |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 1368 | av1_inc_mv(&diff, counts, precision); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1369 | |
| 1370 | mv->row = ref->row + diff.row; |
| 1371 | mv->col = ref->col + diff.col; |
| 1372 | } |
| 1373 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1374 | static REFERENCE_MODE read_block_reference_mode(AV1_COMMON *cm, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1375 | const MACROBLOCKD *xd, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1376 | aom_reader *r) { |
Debargha Mukherjee | 0f248c4 | 2017-09-07 12:40:18 -0700 | [diff] [blame] | 1377 | 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] | 1378 | if (cm->reference_mode == REFERENCE_MODE_SELECT) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1379 | const int ctx = av1_get_reference_mode_context(cm, xd); |
Thomas Davies | 8c9bcdf | 2017-06-21 10:12:48 +0100 | [diff] [blame] | 1380 | #if CONFIG_NEW_MULTISYMBOL |
| 1381 | const REFERENCE_MODE mode = (REFERENCE_MODE)aom_read_symbol( |
| 1382 | r, xd->tile_ctx->comp_inter_cdf[ctx], 2, ACCT_STR); |
| 1383 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1384 | const REFERENCE_MODE mode = |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 1385 | (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] | 1386 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1387 | FRAME_COUNTS *counts = xd->counts; |
| 1388 | if (counts) ++counts->comp_inter[ctx][mode]; |
| 1389 | return mode; // SINGLE_REFERENCE or COMPOUND_REFERENCE |
| 1390 | } else { |
| 1391 | return cm->reference_mode; |
| 1392 | } |
| 1393 | } |
| 1394 | |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1395 | #if CONFIG_NEW_MULTISYMBOL |
| 1396 | #define READ_REF_BIT(pname) \ |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 1397 | 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] | 1398 | #define READ_REF_BIT2(pname) \ |
| 1399 | 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] | 1400 | #else |
| 1401 | #define READ_REF_BIT(pname) \ |
| 1402 | aom_read(r, av1_get_pred_prob_##pname(cm, xd), ACCT_STR) |
Thomas Davies | 0fbd2b7 | 2017-09-12 10:49:45 +0100 | [diff] [blame] | 1403 | #define READ_REF_BIT2(pname) \ |
| 1404 | aom_read(r, av1_get_pred_prob_##pname(cm, xd), ACCT_STR) |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1405 | #endif |
| 1406 | |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1407 | #if CONFIG_EXT_COMP_REFS |
Zoe Liu | ec50d6b | 2017-08-23 16:02:59 -0700 | [diff] [blame] | 1408 | static COMP_REFERENCE_TYPE read_comp_reference_type(AV1_COMMON *cm, |
| 1409 | const MACROBLOCKD *xd, |
| 1410 | aom_reader *r) { |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 1411 | const int ctx = av1_get_comp_reference_type_context(xd); |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1412 | #if USE_UNI_COMP_REFS |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 1413 | COMP_REFERENCE_TYPE comp_ref_type; |
| 1414 | #if CONFIG_VAR_REFS |
Thomas Davies | 0fbd2b7 | 2017-09-12 10:49:45 +0100 | [diff] [blame] | 1415 | if ((L_OR_L2(cm) || L3_OR_G(cm)) && BWD_OR_ALT(cm)) { |
| 1416 | 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] | 1417 | #endif // CONFIG_VAR_REFS |
Thomas Davies | 0fbd2b7 | 2017-09-12 10:49:45 +0100 | [diff] [blame] | 1418 | #if CONFIG_NEW_MULTISYMBOL |
| 1419 | (void)cm; |
| 1420 | comp_ref_type = (COMP_REFERENCE_TYPE)aom_read_symbol( |
| 1421 | r, xd->tile_ctx->comp_ref_type_cdf[ctx], 2, ACCT_STR); |
| 1422 | #else |
| 1423 | comp_ref_type = (COMP_REFERENCE_TYPE)aom_read( |
| 1424 | r, cm->fc->comp_ref_type_prob[ctx], ACCT_STR); |
| 1425 | #endif |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 1426 | #if CONFIG_VAR_REFS |
Thomas Davies | 0fbd2b7 | 2017-09-12 10:49:45 +0100 | [diff] [blame] | 1427 | } else { |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 1428 | comp_ref_type = BIDIR_COMP_REFERENCE; |
Thomas Davies | 0fbd2b7 | 2017-09-12 10:49:45 +0100 | [diff] [blame] | 1429 | } |
| 1430 | } else { |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 1431 | comp_ref_type = UNIDIR_COMP_REFERENCE; |
Thomas Davies | 0fbd2b7 | 2017-09-12 10:49:45 +0100 | [diff] [blame] | 1432 | } |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 1433 | #endif // CONFIG_VAR_REFS |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1434 | #else // !USE_UNI_COMP_REFS |
| 1435 | // TODO(zoeliu): Temporarily turn off uni-directional comp refs |
| 1436 | const COMP_REFERENCE_TYPE comp_ref_type = BIDIR_COMP_REFERENCE; |
| 1437 | #endif // USE_UNI_COMP_REFS |
| 1438 | FRAME_COUNTS *counts = xd->counts; |
| 1439 | if (counts) ++counts->comp_ref_type[ctx][comp_ref_type]; |
| 1440 | return comp_ref_type; // UNIDIR_COMP_REFERENCE or BIDIR_COMP_REFERENCE |
| 1441 | } |
| 1442 | #endif // CONFIG_EXT_COMP_REFS |
| 1443 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1444 | // Read the referncence frame |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1445 | static void read_ref_frames(AV1_COMMON *const cm, MACROBLOCKD *const xd, |
| 1446 | aom_reader *r, int segment_id, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1447 | MV_REFERENCE_FRAME ref_frame[2]) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1448 | FRAME_COUNTS *counts = xd->counts; |
| 1449 | |
| 1450 | if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) { |
| 1451 | ref_frame[0] = (MV_REFERENCE_FRAME)get_segdata(&cm->seg, segment_id, |
| 1452 | SEG_LVL_REF_FRAME); |
Emil Keyder | 01770b3 | 2017-01-20 18:03:11 -0500 | [diff] [blame] | 1453 | ref_frame[1] = NONE_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1454 | } else { |
| 1455 | const REFERENCE_MODE mode = read_block_reference_mode(cm, xd, r); |
| 1456 | // FIXME(rbultje) I'm pretty sure this breaks segmentation ref frame coding |
| 1457 | if (mode == COMPOUND_REFERENCE) { |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1458 | #if CONFIG_EXT_COMP_REFS |
| 1459 | const COMP_REFERENCE_TYPE comp_ref_type = |
| 1460 | read_comp_reference_type(cm, xd, r); |
| 1461 | |
| 1462 | #if !USE_UNI_COMP_REFS |
| 1463 | // TODO(zoeliu): Temporarily turn off uni-directional comp refs |
| 1464 | assert(comp_ref_type == BIDIR_COMP_REFERENCE); |
| 1465 | #endif // !USE_UNI_COMP_REFS |
| 1466 | |
| 1467 | if (comp_ref_type == UNIDIR_COMP_REFERENCE) { |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 1468 | const int ctx = av1_get_pred_context_uni_comp_ref_p(xd); |
| 1469 | int bit; |
| 1470 | #if CONFIG_VAR_REFS |
| 1471 | if ((L_AND_L2(cm) || L_AND_L3(cm) || L_AND_G(cm)) && BWD_AND_ALT(cm)) |
| 1472 | #endif // CONFIG_VAR_REFS |
Thomas Davies | 0fbd2b7 | 2017-09-12 10:49:45 +0100 | [diff] [blame] | 1473 | bit = READ_REF_BIT2(uni_comp_ref_p); |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 1474 | #if CONFIG_VAR_REFS |
| 1475 | else |
| 1476 | bit = BWD_AND_ALT(cm); |
| 1477 | #endif // CONFIG_VAR_REFS |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1478 | if (counts) ++counts->uni_comp_ref[ctx][0][bit]; |
| 1479 | |
| 1480 | if (bit) { |
| 1481 | ref_frame[0] = BWDREF_FRAME; |
| 1482 | ref_frame[1] = ALTREF_FRAME; |
| 1483 | } else { |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 1484 | const int ctx1 = av1_get_pred_context_uni_comp_ref_p1(xd); |
| 1485 | int bit1; |
| 1486 | #if CONFIG_VAR_REFS |
| 1487 | if (L_AND_L2(cm) && (L_AND_L3(cm) || L_AND_G(cm))) |
| 1488 | #endif // CONFIG_VAR_REFS |
Thomas Davies | 0fbd2b7 | 2017-09-12 10:49:45 +0100 | [diff] [blame] | 1489 | bit1 = READ_REF_BIT2(uni_comp_ref_p1); |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 1490 | #if CONFIG_VAR_REFS |
| 1491 | else |
| 1492 | bit1 = L_AND_L3(cm) || L_AND_G(cm); |
| 1493 | #endif // CONFIG_VAR_REFS |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1494 | if (counts) ++counts->uni_comp_ref[ctx1][1][bit1]; |
| 1495 | |
| 1496 | if (bit1) { |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 1497 | const int ctx2 = av1_get_pred_context_uni_comp_ref_p2(xd); |
| 1498 | int bit2; |
| 1499 | #if CONFIG_VAR_REFS |
| 1500 | if (L_AND_L3(cm) && L_AND_G(cm)) |
| 1501 | #endif // CONFIG_VAR_REFS |
Thomas Davies | 0fbd2b7 | 2017-09-12 10:49:45 +0100 | [diff] [blame] | 1502 | bit2 = READ_REF_BIT2(uni_comp_ref_p2); |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 1503 | #if CONFIG_VAR_REFS |
| 1504 | else |
| 1505 | bit2 = L_AND_G(cm); |
| 1506 | #endif // CONFIG_VAR_REFS |
| 1507 | if (counts) ++counts->uni_comp_ref[ctx2][2][bit2]; |
| 1508 | |
| 1509 | if (bit2) { |
| 1510 | ref_frame[0] = LAST_FRAME; |
| 1511 | ref_frame[1] = GOLDEN_FRAME; |
| 1512 | } else { |
| 1513 | ref_frame[0] = LAST_FRAME; |
| 1514 | ref_frame[1] = LAST3_FRAME; |
| 1515 | } |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1516 | } else { |
| 1517 | ref_frame[0] = LAST_FRAME; |
| 1518 | ref_frame[1] = LAST2_FRAME; |
| 1519 | } |
| 1520 | } |
| 1521 | |
| 1522 | return; |
| 1523 | } |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 1524 | |
| 1525 | assert(comp_ref_type == BIDIR_COMP_REFERENCE); |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1526 | #endif // CONFIG_EXT_COMP_REFS |
| 1527 | |
| 1528 | // Normative in decoder (for low delay) |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 1529 | #if CONFIG_ONE_SIDED_COMPOUND || CONFIG_FRAME_SIGN_BIAS |
Arild Fuldseth (arilfuld) | 3889730 | 2017-04-27 20:03:03 +0200 | [diff] [blame] | 1530 | const int idx = 1; |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 1531 | #else // !(CONFIG_ONE_SIDED_COMPOUND || CONFIG_FRAME_SIGN_BIAS) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1532 | #if CONFIG_EXT_REFS |
| 1533 | 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] | 1534 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1535 | const int idx = cm->ref_frame_sign_bias[cm->comp_fixed_ref]; |
| 1536 | #endif // CONFIG_EXT_REFS |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 1537 | #endif // CONFIG_ONE_SIDED_COMPOUND || CONFIG_FRAME_SIGN_BIAS) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1538 | |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1539 | const int ctx = av1_get_pred_context_comp_ref_p(cm, xd); |
| 1540 | #if CONFIG_VAR_REFS |
| 1541 | int bit; |
| 1542 | // Test need to explicitly code (L,L2) vs (L3,G) branch node in tree |
| 1543 | if (L_OR_L2(cm) && L3_OR_G(cm)) |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 1544 | bit = READ_REF_BIT(comp_ref_p); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1545 | else |
| 1546 | bit = L3_OR_G(cm); |
| 1547 | #else // !CONFIG_VAR_REFS |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 1548 | const int bit = READ_REF_BIT(comp_ref_p); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1549 | #endif // CONFIG_VAR_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1550 | if (counts) ++counts->comp_ref[ctx][0][bit]; |
| 1551 | |
| 1552 | #if CONFIG_EXT_REFS |
| 1553 | // Decode forward references. |
| 1554 | if (!bit) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1555 | const int ctx1 = av1_get_pred_context_comp_ref_p1(cm, xd); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1556 | #if CONFIG_VAR_REFS |
| 1557 | int bit1; |
| 1558 | // Test need to explicitly code (L) vs (L2) branch node in tree |
| 1559 | if (L_AND_L2(cm)) |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 1560 | bit1 = READ_REF_BIT(comp_ref_p1); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1561 | else |
| 1562 | bit1 = LAST_IS_VALID(cm); |
| 1563 | #else // !CONFIG_VAR_REFS |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 1564 | const int bit1 = READ_REF_BIT(comp_ref_p1); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1565 | #endif // CONFIG_VAR_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1566 | if (counts) ++counts->comp_ref[ctx1][1][bit1]; |
| 1567 | ref_frame[!idx] = cm->comp_fwd_ref[bit1 ? 0 : 1]; |
| 1568 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1569 | const int ctx2 = av1_get_pred_context_comp_ref_p2(cm, xd); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1570 | #if CONFIG_VAR_REFS |
| 1571 | int bit2; |
| 1572 | // Test need to explicitly code (L3) vs (G) branch node in tree |
| 1573 | if (L3_AND_G(cm)) |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 1574 | bit2 = READ_REF_BIT(comp_ref_p2); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1575 | else |
| 1576 | bit2 = GOLDEN_IS_VALID(cm); |
| 1577 | #else // !CONFIG_VAR_REFS |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 1578 | const int bit2 = READ_REF_BIT(comp_ref_p2); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1579 | #endif // CONFIG_VAR_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1580 | if (counts) ++counts->comp_ref[ctx2][2][bit2]; |
| 1581 | ref_frame[!idx] = cm->comp_fwd_ref[bit2 ? 3 : 2]; |
| 1582 | } |
| 1583 | |
| 1584 | // Decode backward references. |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1585 | const int ctx_bwd = av1_get_pred_context_comp_bwdref_p(cm, xd); |
| 1586 | #if CONFIG_VAR_REFS |
| 1587 | int bit_bwd; |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 1588 | // 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] | 1589 | 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] | 1590 | if (bit_bwd_uncertain) |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 1591 | bit_bwd = READ_REF_BIT(comp_bwdref_p); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1592 | else |
| 1593 | bit_bwd = ALTREF_IS_VALID(cm); |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 1594 | #else // !CONFIG_VAR_REFS |
| 1595 | const int bit_bwd = READ_REF_BIT(comp_bwdref_p); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1596 | #endif // CONFIG_VAR_REFS |
| 1597 | if (counts) ++counts->comp_bwdref[ctx_bwd][0][bit_bwd]; |
Zoe Liu | 043c227 | 2017-07-19 12:40:29 -0700 | [diff] [blame] | 1598 | if (!bit_bwd) { |
| 1599 | const int ctx1_bwd = av1_get_pred_context_comp_bwdref_p1(cm, xd); |
| 1600 | #if CONFIG_VAR_REFS |
| 1601 | int bit1_bwd; |
| 1602 | if (BWD_AND_ALT2(cm)) |
| 1603 | bit1_bwd = READ_REF_BIT(comp_bwdref_p1); |
| 1604 | else |
| 1605 | bit1_bwd = ALTREF2_IS_VALID(cm); |
| 1606 | #else // !CONFIG_VAR_REFS |
| 1607 | const int bit1_bwd = READ_REF_BIT(comp_bwdref_p1); |
| 1608 | #endif // CONFIG_VAR_REFS |
| 1609 | if (counts) ++counts->comp_bwdref[ctx1_bwd][1][bit1_bwd]; |
| 1610 | ref_frame[idx] = cm->comp_bwd_ref[bit1_bwd]; |
| 1611 | } else { |
| 1612 | ref_frame[idx] = cm->comp_bwd_ref[2]; |
| 1613 | } |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1614 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1615 | ref_frame[!idx] = cm->comp_var_ref[bit]; |
| 1616 | ref_frame[idx] = cm->comp_fixed_ref; |
| 1617 | #endif // CONFIG_EXT_REFS |
| 1618 | } else if (mode == SINGLE_REFERENCE) { |
| 1619 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1620 | const int ctx0 = av1_get_pred_context_single_ref_p1(xd); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1621 | #if CONFIG_VAR_REFS |
| 1622 | int bit0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 1623 | // Test need to explicitly code (L,L2,L3,G) vs (BWD,ALT2,ALT) branch node |
| 1624 | // in tree |
| 1625 | if ((L_OR_L2(cm) || L3_OR_G(cm)) && |
| 1626 | (BWD_OR_ALT2(cm) || ALTREF_IS_VALID(cm))) |
| 1627 | bit0 = READ_REF_BIT(single_ref_p1); |
| 1628 | else |
| 1629 | bit0 = (BWD_OR_ALT2(cm) || ALTREF_IS_VALID(cm)); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1630 | #else // !CONFIG_VAR_REFS |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1631 | const int bit0 = READ_REF_BIT(single_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->single_ref[ctx0][0][bit0]; |
| 1634 | |
| 1635 | if (bit0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1636 | const int ctx1 = av1_get_pred_context_single_ref_p2(xd); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1637 | #if CONFIG_VAR_REFS |
| 1638 | int bit1; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 1639 | // 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] | 1640 | const int bit1_uncertain = BWD_OR_ALT2(cm) && ALTREF_IS_VALID(cm); |
Zoe Liu | 043c227 | 2017-07-19 12:40:29 -0700 | [diff] [blame] | 1641 | if (bit1_uncertain) |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1642 | bit1 = READ_REF_BIT(single_ref_p2); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1643 | else |
| 1644 | bit1 = ALTREF_IS_VALID(cm); |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1645 | #else // !CONFIG_VAR_REFS |
| 1646 | const int bit1 = READ_REF_BIT(single_ref_p2); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1647 | #endif // CONFIG_VAR_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1648 | if (counts) ++counts->single_ref[ctx1][1][bit1]; |
Zoe Liu | 043c227 | 2017-07-19 12:40:29 -0700 | [diff] [blame] | 1649 | if (!bit1) { |
| 1650 | const int ctx5 = av1_get_pred_context_single_ref_p6(xd); |
| 1651 | #if CONFIG_VAR_REFS |
| 1652 | int bit5; |
| 1653 | if (BWD_AND_ALT2(cm)) |
| 1654 | bit5 = READ_REF_BIT(single_ref_p6); |
| 1655 | else |
| 1656 | bit5 = ALTREF2_IS_VALID(cm); |
| 1657 | #else // !CONFIG_VAR_REFS |
| 1658 | const int bit5 = READ_REF_BIT(single_ref_p6); |
| 1659 | #endif // CONFIG_VAR_REFS |
| 1660 | if (counts) ++counts->single_ref[ctx5][5][bit5]; |
| 1661 | ref_frame[0] = bit5 ? ALTREF2_FRAME : BWDREF_FRAME; |
| 1662 | } else { |
| 1663 | ref_frame[0] = ALTREF_FRAME; |
| 1664 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1665 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1666 | const int ctx2 = av1_get_pred_context_single_ref_p3(xd); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1667 | #if CONFIG_VAR_REFS |
| 1668 | int bit2; |
| 1669 | // Test need to explicitly code (L,L2) vs (L3,G) branch node in tree |
| 1670 | if (L_OR_L2(cm) && L3_OR_G(cm)) |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1671 | bit2 = READ_REF_BIT(single_ref_p3); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1672 | else |
| 1673 | bit2 = L3_OR_G(cm); |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1674 | #else // !CONFIG_VAR_REFS |
| 1675 | const int bit2 = READ_REF_BIT(single_ref_p3); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1676 | #endif // CONFIG_VAR_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1677 | if (counts) ++counts->single_ref[ctx2][2][bit2]; |
| 1678 | if (bit2) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1679 | const int ctx4 = av1_get_pred_context_single_ref_p5(xd); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1680 | #if CONFIG_VAR_REFS |
| 1681 | int bit4; |
| 1682 | // Test need to explicitly code (L3) vs (G) branch node in tree |
| 1683 | if (L3_AND_G(cm)) |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1684 | bit4 = READ_REF_BIT(single_ref_p5); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1685 | else |
| 1686 | bit4 = GOLDEN_IS_VALID(cm); |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1687 | #else // !CONFIG_VAR_REFS |
| 1688 | const int bit4 = READ_REF_BIT(single_ref_p5); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1689 | #endif // CONFIG_VAR_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1690 | if (counts) ++counts->single_ref[ctx4][4][bit4]; |
| 1691 | ref_frame[0] = bit4 ? GOLDEN_FRAME : LAST3_FRAME; |
| 1692 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1693 | const int ctx3 = av1_get_pred_context_single_ref_p4(xd); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1694 | #if CONFIG_VAR_REFS |
| 1695 | int bit3; |
| 1696 | // Test need to explicitly code (L) vs (L2) branch node in tree |
| 1697 | if (L_AND_L2(cm)) |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1698 | bit3 = READ_REF_BIT(single_ref_p4); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1699 | else |
| 1700 | bit3 = LAST2_IS_VALID(cm); |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1701 | #else // !CONFIG_VAR_REFS |
| 1702 | const int bit3 = READ_REF_BIT(single_ref_p4); |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1703 | #endif // CONFIG_VAR_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1704 | if (counts) ++counts->single_ref[ctx3][3][bit3]; |
| 1705 | ref_frame[0] = bit3 ? LAST2_FRAME : LAST_FRAME; |
| 1706 | } |
| 1707 | } |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 1708 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1709 | const int ctx0 = av1_get_pred_context_single_ref_p1(xd); |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1710 | const int bit0 = READ_REF_BIT(single_ref_p1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1711 | if (counts) ++counts->single_ref[ctx0][0][bit0]; |
| 1712 | |
| 1713 | if (bit0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1714 | const int ctx1 = av1_get_pred_context_single_ref_p2(xd); |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 1715 | const int bit1 = READ_REF_BIT(single_ref_p2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1716 | if (counts) ++counts->single_ref[ctx1][1][bit1]; |
| 1717 | ref_frame[0] = bit1 ? ALTREF_FRAME : GOLDEN_FRAME; |
| 1718 | } else { |
| 1719 | ref_frame[0] = LAST_FRAME; |
| 1720 | } |
| 1721 | #endif // CONFIG_EXT_REFS |
| 1722 | |
Emil Keyder | 01770b3 | 2017-01-20 18:03:11 -0500 | [diff] [blame] | 1723 | ref_frame[1] = NONE_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1724 | } else { |
| 1725 | assert(0 && "Invalid prediction mode."); |
| 1726 | } |
| 1727 | } |
| 1728 | } |
| 1729 | |
Angie Chiang | 9c4f895 | 2016-11-21 11:13:19 -0800 | [diff] [blame] | 1730 | static INLINE void read_mb_interp_filter(AV1_COMMON *const cm, |
| 1731 | MACROBLOCKD *const xd, |
| 1732 | MB_MODE_INFO *const mbmi, |
| 1733 | aom_reader *r) { |
| 1734 | FRAME_COUNTS *counts = xd->counts; |
Thomas Davies | 77c7c40 | 2017-01-11 17:58:54 +0000 | [diff] [blame] | 1735 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
Thomas Davies | 77c7c40 | 2017-01-11 17:58:54 +0000 | [diff] [blame] | 1736 | |
Debargha Mukherjee | 0df711f | 2017-05-02 16:00:20 -0700 | [diff] [blame] | 1737 | if (!av1_is_interp_needed(xd)) { |
| 1738 | set_default_interp_filters(mbmi, cm->interp_filter); |
Yue Chen | 19e7aa8 | 2016-11-30 14:05:39 -0800 | [diff] [blame] | 1739 | return; |
| 1740 | } |
Yue Chen | 19e7aa8 | 2016-11-30 14:05:39 -0800 | [diff] [blame] | 1741 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1742 | if (cm->interp_filter != SWITCHABLE) { |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 1743 | mbmi->interp_filters = av1_broadcast_interp_filter(cm->interp_filter); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1744 | } else { |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 1745 | #if CONFIG_DUAL_FILTER |
| 1746 | InterpFilter ref0_filter[2] = { EIGHTTAP_REGULAR, EIGHTTAP_REGULAR }; |
| 1747 | for (int dir = 0; dir < 2; ++dir) { |
Angie Chiang | 9c4f895 | 2016-11-21 11:13:19 -0800 | [diff] [blame] | 1748 | if (has_subpel_mv_component(xd->mi[0], xd, dir) || |
| 1749 | (mbmi->ref_frame[1] > INTRA_FRAME && |
| 1750 | has_subpel_mv_component(xd->mi[0], xd, dir + 2))) { |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 1751 | const int ctx = av1_get_pred_context_switchable_interp(xd, dir); |
| 1752 | ref0_filter[dir] = |
Thomas Davies | ec92c11 | 2017-09-25 11:03:58 +0100 | [diff] [blame] | 1753 | (InterpFilter)aom_read_symbol(r, ec_ctx->switchable_interp_cdf[ctx], |
| 1754 | SWITCHABLE_FILTERS, ACCT_STR); |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 1755 | if (counts) ++counts->switchable_interp[ctx][ref0_filter[dir]]; |
Angie Chiang | 9c4f895 | 2016-11-21 11:13:19 -0800 | [diff] [blame] | 1756 | } |
| 1757 | } |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 1758 | // The index system works as: (0, 1) -> (vertical, horizontal) filter types |
| 1759 | mbmi->interp_filters = |
| 1760 | av1_make_interp_filters(ref0_filter[0], ref0_filter[1]); |
Nathan E. Egge | 476c63c | 2017-05-18 18:35:16 -0400 | [diff] [blame] | 1761 | #else // CONFIG_DUAL_FILTER |
Angie Chiang | 9c4f895 | 2016-11-21 11:13:19 -0800 | [diff] [blame] | 1762 | const int ctx = av1_get_pred_context_switchable_interp(xd); |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 1763 | InterpFilter filter = (InterpFilter)aom_read_symbol( |
Thomas Davies | ec92c11 | 2017-09-25 11:03:58 +0100 | [diff] [blame] | 1764 | r, ec_ctx->switchable_interp_cdf[ctx], SWITCHABLE_FILTERS, ACCT_STR); |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 1765 | mbmi->interp_filters = av1_broadcast_interp_filter(filter); |
| 1766 | if (counts) ++counts->switchable_interp[ctx][filter]; |
Angie Chiang | 9c4f895 | 2016-11-21 11:13:19 -0800 | [diff] [blame] | 1767 | #endif // CONFIG_DUAL_FILTER |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 1768 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1769 | } |
| 1770 | |
Jingning Han | 36fe320 | 2017-02-20 22:31:49 -0800 | [diff] [blame] | 1771 | static void read_intra_block_mode_info(AV1_COMMON *const cm, const int mi_row, |
| 1772 | const int mi_col, MACROBLOCKD *const xd, |
| 1773 | MODE_INFO *mi, aom_reader *r) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1774 | MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 1775 | const BLOCK_SIZE bsize = mi->mbmi.sb_type; |
| 1776 | int i; |
| 1777 | |
| 1778 | mbmi->ref_frame[0] = INTRA_FRAME; |
Emil Keyder | 01770b3 | 2017-01-20 18:03:11 -0500 | [diff] [blame] | 1779 | mbmi->ref_frame[1] = NONE_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1780 | |
Nathan E. Egge | a1f80e3 | 2017-05-23 11:52:32 -0400 | [diff] [blame] | 1781 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
Nathan E. Egge | a1f80e3 | 2017-05-23 11:52:32 -0400 | [diff] [blame] | 1782 | |
Jingning Han | 5226184 | 2016-12-14 12:17:49 -0800 | [diff] [blame] | 1783 | #if CONFIG_CB4X4 |
| 1784 | (void)i; |
Hui Su | aa2965e | 2017-10-05 15:59:12 -0700 | [diff] [blame] | 1785 | 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] | 1786 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1787 | switch (bsize) { |
| 1788 | case BLOCK_4X4: |
| 1789 | for (i = 0; i < 4; ++i) |
Hui Su | aa2965e | 2017-10-05 15:59:12 -0700 | [diff] [blame] | 1790 | 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] | 1791 | mbmi->mode = mi->bmi[3].as_mode; |
| 1792 | break; |
| 1793 | case BLOCK_4X8: |
Nathan E. Egge | a1f80e3 | 2017-05-23 11:52:32 -0400 | [diff] [blame] | 1794 | mi->bmi[0].as_mode = mi->bmi[2].as_mode = |
Hui Su | aa2965e | 2017-10-05 15:59:12 -0700 | [diff] [blame] | 1795 | read_intra_mode(r, ec_ctx->y_mode_cdf[0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1796 | mi->bmi[1].as_mode = mi->bmi[3].as_mode = mbmi->mode = |
Hui Su | aa2965e | 2017-10-05 15:59:12 -0700 | [diff] [blame] | 1797 | read_intra_mode(r, ec_ctx->y_mode_cdf[0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1798 | break; |
| 1799 | case BLOCK_8X4: |
Nathan E. Egge | a1f80e3 | 2017-05-23 11:52:32 -0400 | [diff] [blame] | 1800 | mi->bmi[0].as_mode = mi->bmi[1].as_mode = |
Hui Su | aa2965e | 2017-10-05 15:59:12 -0700 | [diff] [blame] | 1801 | read_intra_mode(r, ec_ctx->y_mode_cdf[0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1802 | mi->bmi[2].as_mode = mi->bmi[3].as_mode = mbmi->mode = |
Hui Su | aa2965e | 2017-10-05 15:59:12 -0700 | [diff] [blame] | 1803 | read_intra_mode(r, ec_ctx->y_mode_cdf[0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1804 | break; |
| 1805 | default: |
Hui Su | aa2965e | 2017-10-05 15:59:12 -0700 | [diff] [blame] | 1806 | mbmi->mode = |
| 1807 | 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] | 1808 | } |
Jingning Han | 5226184 | 2016-12-14 12:17:49 -0800 | [diff] [blame] | 1809 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1810 | |
Jingning Han | 36fe320 | 2017-02-20 22:31:49 -0800 | [diff] [blame] | 1811 | #if CONFIG_CB4X4 |
Jingning Han | d3a6443 | 2017-04-06 17:04:17 -0700 | [diff] [blame] | 1812 | 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] | 1813 | xd->plane[1].subsampling_y)) { |
Hui Su | aa2965e | 2017-10-05 15:59:12 -0700 | [diff] [blame] | 1814 | mbmi->uv_mode = read_intra_mode_uv(ec_ctx, r, mbmi->mode); |
Jingning Han | 36fe320 | 2017-02-20 22:31:49 -0800 | [diff] [blame] | 1815 | #else |
Hui Su | aa2965e | 2017-10-05 15:59:12 -0700 | [diff] [blame] | 1816 | mbmi->uv_mode = read_intra_mode_uv(ec_ctx, r, mbmi->mode); |
Jingning Han | 36fe320 | 2017-02-20 22:31:49 -0800 | [diff] [blame] | 1817 | (void)mi_row; |
| 1818 | (void)mi_col; |
| 1819 | #endif |
| 1820 | |
Luc Trudeau | b09b55d | 2017-04-26 10:06:35 -0400 | [diff] [blame] | 1821 | #if CONFIG_CFL |
Luc Trudeau | 6e1cd78 | 2017-06-21 13:52:36 -0400 | [diff] [blame] | 1822 | if (mbmi->uv_mode == UV_CFL_PRED) { |
Nathan E. Egge | 6bdc40f | 2017-06-18 19:02:23 -0400 | [diff] [blame] | 1823 | mbmi->cfl_alpha_idx = |
David Michael Barr | f6eaa15 | 2017-07-19 19:42:28 +0900 | [diff] [blame] | 1824 | read_cfl_alphas(xd->tile_ctx, r, &mbmi->cfl_alpha_signs); |
Luc Trudeau | b05eeae | 2017-08-18 15:14:30 -0400 | [diff] [blame] | 1825 | xd->cfl->store_y = 1; |
Luc Trudeau | e784b3f | 2017-08-14 15:25:28 -0400 | [diff] [blame] | 1826 | } else { |
| 1827 | xd->cfl->store_y = 0; |
Luc Trudeau | b09b55d | 2017-04-26 10:06:35 -0400 | [diff] [blame] | 1828 | } |
| 1829 | #endif // CONFIG_CFL |
| 1830 | |
| 1831 | #if CONFIG_CB4X4 |
Luc Trudeau | b05eeae | 2017-08-18 15:14:30 -0400 | [diff] [blame] | 1832 | } else { |
| 1833 | // Avoid decoding angle_info if there is is no chroma prediction |
| 1834 | mbmi->uv_mode = UV_DC_PRED; |
| 1835 | #if CONFIG_CFL |
| 1836 | xd->cfl->is_chroma_reference = 0; |
| 1837 | xd->cfl->store_y = 1; |
| 1838 | #endif |
Luc Trudeau | b09b55d | 2017-04-26 10:06:35 -0400 | [diff] [blame] | 1839 | } |
| 1840 | #endif |
| 1841 | |
Rupert Swarbrick | 766c9d5 | 2017-07-31 11:30:53 +0100 | [diff] [blame] | 1842 | // Explicitly ignore cm here to avoid a compile warning if none of |
| 1843 | // ext-intra, palette and filter-intra are enabled. |
| 1844 | (void)cm; |
| 1845 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1846 | #if CONFIG_EXT_INTRA |
| 1847 | read_intra_angle_info(cm, xd, r); |
| 1848 | #endif // CONFIG_EXT_INTRA |
| 1849 | mbmi->palette_mode_info.palette_size[0] = 0; |
| 1850 | mbmi->palette_mode_info.palette_size[1] = 0; |
| 1851 | if (bsize >= BLOCK_8X8 && cm->allow_screen_content_tools) |
| 1852 | read_palette_mode_info(cm, xd, r); |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 1853 | #if CONFIG_FILTER_INTRA |
| 1854 | mbmi->filter_intra_mode_info.use_filter_intra_mode[0] = 0; |
| 1855 | mbmi->filter_intra_mode_info.use_filter_intra_mode[1] = 0; |
Jingning Han | 48b1cb3 | 2017-01-23 10:26:14 -0800 | [diff] [blame] | 1856 | if (bsize >= BLOCK_8X8 || CONFIG_CB4X4) |
Jingning Han | 62946d1 | 2017-05-26 11:29:30 -0700 | [diff] [blame] | 1857 | read_filter_intra_mode_info(cm, xd, mi_row, mi_col, r); |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 1858 | #endif // CONFIG_FILTER_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | static INLINE int is_mv_valid(const MV *mv) { |
| 1862 | return mv->row > MV_LOW && mv->row < MV_UPP && mv->col > MV_LOW && |
| 1863 | mv->col < MV_UPP; |
| 1864 | } |
| 1865 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1866 | static INLINE int assign_mv(AV1_COMMON *cm, MACROBLOCKD *xd, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1867 | PREDICTION_MODE mode, |
Jingning Han | 5c60cdf | 2016-09-30 09:37:46 -0700 | [diff] [blame] | 1868 | MV_REFERENCE_FRAME ref_frame[2], int block, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1869 | int_mv mv[2], int_mv ref_mv[2], |
David Barker | 45390c1 | 2017-02-20 14:44:40 +0000 | [diff] [blame] | 1870 | int_mv nearest_mv[2], int_mv near_mv[2], int mi_row, |
| 1871 | int mi_col, int is_compound, int allow_hp, |
| 1872 | aom_reader *r) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1873 | int i; |
| 1874 | int ret = 1; |
Thomas Davies | 2452329 | 2017-01-11 16:56:47 +0000 | [diff] [blame] | 1875 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
Debargha Mukherjee | f6dd3c6 | 2017-02-23 13:21:23 -0800 | [diff] [blame] | 1876 | BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1877 | MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; |
Jingning Han | 5cfa671 | 2016-12-14 09:53:38 -0800 | [diff] [blame] | 1878 | #if CONFIG_CB4X4 |
| 1879 | int_mv *pred_mv = mbmi->pred_mv; |
| 1880 | (void)block; |
| 1881 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1882 | int_mv *pred_mv = |
Yaowu Xu | f5bbbfa | 2016-09-26 09:13:38 -0700 | [diff] [blame] | 1883 | (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] | 1884 | #endif // CONFIG_CB4X4 |
Sarah Parker | e529986 | 2016-08-16 14:57:37 -0700 | [diff] [blame] | 1885 | (void)ref_frame; |
Thomas Davies | 2452329 | 2017-01-11 16:56:47 +0000 | [diff] [blame] | 1886 | (void)cm; |
David Barker | 45390c1 | 2017-02-20 14:44:40 +0000 | [diff] [blame] | 1887 | (void)mi_row; |
| 1888 | (void)mi_col; |
Debargha Mukherjee | f6dd3c6 | 2017-02-23 13:21:23 -0800 | [diff] [blame] | 1889 | (void)bsize; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1890 | #if CONFIG_AMVR |
| 1891 | if (cm->cur_frame_mv_precision_level) { |
| 1892 | allow_hp = MV_SUBPEL_NONE; |
| 1893 | } |
| 1894 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1895 | switch (mode) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1896 | case NEWMV: { |
| 1897 | FRAME_COUNTS *counts = xd->counts; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1898 | for (i = 0; i < 1 + is_compound; ++i) { |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 1899 | int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); |
| 1900 | int nmv_ctx = |
| 1901 | av1_nmv_ctx(xd->ref_mv_count[rf_type], xd->ref_mv_stack[rf_type], i, |
| 1902 | mbmi->ref_mv_idx); |
Alex Converse | 3d0bdc1 | 2017-05-01 15:19:58 -0700 | [diff] [blame] | 1903 | nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1904 | nmv_context_counts *const mv_counts = |
| 1905 | counts ? &counts->mv[nmv_ctx] : NULL; |
Alex Converse | 3d0bdc1 | 2017-05-01 15:19:58 -0700 | [diff] [blame] | 1906 | 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] | 1907 | ret = ret && is_mv_valid(&mv[i].as_mv); |
| 1908 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1909 | pred_mv[i].as_int = ref_mv[i].as_int; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1910 | } |
| 1911 | break; |
| 1912 | } |
| 1913 | case NEARESTMV: { |
| 1914 | mv[0].as_int = nearest_mv[0].as_int; |
| 1915 | if (is_compound) mv[1].as_int = nearest_mv[1].as_int; |
| 1916 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1917 | pred_mv[0].as_int = nearest_mv[0].as_int; |
| 1918 | 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] | 1919 | break; |
| 1920 | } |
| 1921 | case NEARMV: { |
| 1922 | mv[0].as_int = near_mv[0].as_int; |
| 1923 | if (is_compound) mv[1].as_int = near_mv[1].as_int; |
| 1924 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1925 | pred_mv[0].as_int = near_mv[0].as_int; |
| 1926 | 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] | 1927 | break; |
| 1928 | } |
| 1929 | case ZEROMV: { |
Sarah Parker | e529986 | 2016-08-16 14:57:37 -0700 | [diff] [blame] | 1930 | #if CONFIG_GLOBAL_MOTION |
David Barker | cdcac6d | 2016-12-01 17:04:16 +0000 | [diff] [blame] | 1931 | 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] | 1932 | cm->allow_high_precision_mv, bsize, |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1933 | mi_col, mi_row, block |
| 1934 | #if CONFIG_AMVR |
| 1935 | , |
| 1936 | cm->cur_frame_mv_precision_level |
| 1937 | #endif |
| 1938 | ) |
David Barker | cdcac6d | 2016-12-01 17:04:16 +0000 | [diff] [blame] | 1939 | .as_int; |
Sarah Parker | e529986 | 2016-08-16 14:57:37 -0700 | [diff] [blame] | 1940 | if (is_compound) |
David Barker | cdcac6d | 2016-12-01 17:04:16 +0000 | [diff] [blame] | 1941 | 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] | 1942 | cm->allow_high_precision_mv, bsize, |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1943 | mi_col, mi_row, block |
| 1944 | #if CONFIG_AMVR |
| 1945 | , |
| 1946 | cm->cur_frame_mv_precision_level |
| 1947 | #endif |
| 1948 | ) |
David Barker | cdcac6d | 2016-12-01 17:04:16 +0000 | [diff] [blame] | 1949 | .as_int; |
Sarah Parker | e529986 | 2016-08-16 14:57:37 -0700 | [diff] [blame] | 1950 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1951 | mv[0].as_int = 0; |
| 1952 | if (is_compound) mv[1].as_int = 0; |
Sarah Parker | e529986 | 2016-08-16 14:57:37 -0700 | [diff] [blame] | 1953 | #endif // CONFIG_GLOBAL_MOTION |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1954 | |
Debargha Mukherjee | febb59c | 2017-03-02 12:23:45 -0800 | [diff] [blame] | 1955 | pred_mv[0].as_int = mv[0].as_int; |
| 1956 | if (is_compound) pred_mv[1].as_int = mv[1].as_int; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1957 | break; |
| 1958 | } |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 1959 | #if CONFIG_COMPOUND_SINGLEREF |
| 1960 | case SR_NEAREST_NEARMV: { |
| 1961 | assert(!is_compound); |
| 1962 | mv[0].as_int = nearest_mv[0].as_int; |
| 1963 | mv[1].as_int = near_mv[0].as_int; |
| 1964 | break; |
| 1965 | } |
| 1966 | /* |
| 1967 | case SR_NEAREST_NEWMV: { |
| 1968 | assert(!is_compound); |
| 1969 | mv[0].as_int = nearest_mv[0].as_int; |
| 1970 | |
| 1971 | FRAME_COUNTS *counts = xd->counts; |
| 1972 | int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); |
| 1973 | int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type], |
| 1974 | xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx); |
| 1975 | nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx]; |
| 1976 | nmv_context_counts *const mv_counts = |
| 1977 | counts ? &counts->mv[nmv_ctx] : NULL; |
| 1978 | read_mv(r, &mv[1].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp); |
| 1979 | ret = ret && is_mv_valid(&mv[1].as_mv); |
| 1980 | break; |
| 1981 | }*/ |
| 1982 | case SR_NEAR_NEWMV: { |
| 1983 | assert(!is_compound); |
| 1984 | mv[0].as_int = near_mv[0].as_int; |
| 1985 | |
| 1986 | FRAME_COUNTS *counts = xd->counts; |
| 1987 | int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); |
| 1988 | int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type], |
| 1989 | xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx); |
| 1990 | nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx]; |
| 1991 | nmv_context_counts *const mv_counts = |
| 1992 | counts ? &counts->mv[nmv_ctx] : NULL; |
| 1993 | read_mv(r, &mv[1].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp); |
| 1994 | ret = ret && is_mv_valid(&mv[1].as_mv); |
| 1995 | break; |
| 1996 | } |
| 1997 | case SR_ZERO_NEWMV: { |
| 1998 | assert(!is_compound); |
| 1999 | #if CONFIG_GLOBAL_MOTION |
| 2000 | mv[0].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[0]], |
| 2001 | cm->allow_high_precision_mv, bsize, |
| 2002 | mi_col, mi_row, block) |
| 2003 | .as_int; |
| 2004 | #else |
| 2005 | mv[0].as_int = 0; |
| 2006 | #endif // CONFIG_GLOBAL_MOTION |
| 2007 | |
| 2008 | FRAME_COUNTS *counts = xd->counts; |
| 2009 | int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); |
| 2010 | int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type], |
| 2011 | xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx); |
| 2012 | nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx]; |
| 2013 | nmv_context_counts *const mv_counts = |
| 2014 | counts ? &counts->mv[nmv_ctx] : NULL; |
| 2015 | read_mv(r, &mv[1].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp); |
| 2016 | ret = ret && is_mv_valid(&mv[1].as_mv); |
| 2017 | break; |
| 2018 | } |
| 2019 | case SR_NEW_NEWMV: { |
| 2020 | assert(!is_compound); |
| 2021 | |
| 2022 | FRAME_COUNTS *counts = xd->counts; |
| 2023 | for (i = 0; i < 2; ++i) { |
| 2024 | int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); |
| 2025 | int nmv_ctx = |
| 2026 | av1_nmv_ctx(xd->ref_mv_count[rf_type], xd->ref_mv_stack[rf_type], 0, |
| 2027 | mbmi->ref_mv_idx); |
| 2028 | nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx]; |
| 2029 | nmv_context_counts *const mv_counts = |
| 2030 | counts ? &counts->mv[nmv_ctx] : NULL; |
| 2031 | read_mv(r, &mv[i].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp); |
| 2032 | ret = ret && is_mv_valid(&mv[i].as_mv); |
| 2033 | } |
| 2034 | break; |
| 2035 | } |
| 2036 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2037 | case NEW_NEWMV: { |
| 2038 | FRAME_COUNTS *counts = xd->counts; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2039 | assert(is_compound); |
| 2040 | for (i = 0; i < 2; ++i) { |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 2041 | int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); |
| 2042 | int nmv_ctx = |
| 2043 | av1_nmv_ctx(xd->ref_mv_count[rf_type], xd->ref_mv_stack[rf_type], i, |
| 2044 | mbmi->ref_mv_idx); |
Alex Converse | 3d0bdc1 | 2017-05-01 15:19:58 -0700 | [diff] [blame] | 2045 | nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2046 | nmv_context_counts *const mv_counts = |
| 2047 | counts ? &counts->mv[nmv_ctx] : NULL; |
Alex Converse | 3d0bdc1 | 2017-05-01 15:19:58 -0700 | [diff] [blame] | 2048 | 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] | 2049 | ret = ret && is_mv_valid(&mv[i].as_mv); |
| 2050 | } |
| 2051 | break; |
| 2052 | } |
| 2053 | case NEAREST_NEARESTMV: { |
| 2054 | assert(is_compound); |
| 2055 | mv[0].as_int = nearest_mv[0].as_int; |
| 2056 | mv[1].as_int = nearest_mv[1].as_int; |
| 2057 | break; |
| 2058 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2059 | case NEAR_NEARMV: { |
| 2060 | assert(is_compound); |
| 2061 | mv[0].as_int = near_mv[0].as_int; |
| 2062 | mv[1].as_int = near_mv[1].as_int; |
| 2063 | break; |
| 2064 | } |
| 2065 | case NEW_NEARESTMV: { |
| 2066 | FRAME_COUNTS *counts = xd->counts; |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 2067 | int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); |
| 2068 | int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type], |
| 2069 | xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx); |
Alex Converse | 3d0bdc1 | 2017-05-01 15:19:58 -0700 | [diff] [blame] | 2070 | nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2071 | nmv_context_counts *const mv_counts = |
| 2072 | counts ? &counts->mv[nmv_ctx] : NULL; |
Alex Converse | 3d0bdc1 | 2017-05-01 15:19:58 -0700 | [diff] [blame] | 2073 | 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] | 2074 | assert(is_compound); |
| 2075 | ret = ret && is_mv_valid(&mv[0].as_mv); |
| 2076 | mv[1].as_int = nearest_mv[1].as_int; |
| 2077 | break; |
| 2078 | } |
| 2079 | case NEAREST_NEWMV: { |
| 2080 | FRAME_COUNTS *counts = xd->counts; |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 2081 | int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); |
| 2082 | int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type], |
| 2083 | xd->ref_mv_stack[rf_type], 1, mbmi->ref_mv_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2084 | nmv_context_counts *const mv_counts = |
| 2085 | counts ? &counts->mv[nmv_ctx] : NULL; |
Alex Converse | 3d0bdc1 | 2017-05-01 15:19:58 -0700 | [diff] [blame] | 2086 | nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx]; |
Alex Converse | 3d0bdc1 | 2017-05-01 15:19:58 -0700 | [diff] [blame] | 2087 | mv[0].as_int = nearest_mv[0].as_int; |
| 2088 | 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] | 2089 | assert(is_compound); |
| 2090 | ret = ret && is_mv_valid(&mv[1].as_mv); |
| 2091 | break; |
| 2092 | } |
| 2093 | case NEAR_NEWMV: { |
| 2094 | FRAME_COUNTS *counts = xd->counts; |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 2095 | int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); |
| 2096 | int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type], |
| 2097 | xd->ref_mv_stack[rf_type], 1, mbmi->ref_mv_idx); |
Alex Converse | 3d0bdc1 | 2017-05-01 15:19:58 -0700 | [diff] [blame] | 2098 | nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2099 | nmv_context_counts *const mv_counts = |
| 2100 | counts ? &counts->mv[nmv_ctx] : NULL; |
Alex Converse | 3d0bdc1 | 2017-05-01 15:19:58 -0700 | [diff] [blame] | 2101 | mv[0].as_int = near_mv[0].as_int; |
| 2102 | 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] | 2103 | assert(is_compound); |
| 2104 | |
| 2105 | ret = ret && is_mv_valid(&mv[1].as_mv); |
| 2106 | break; |
| 2107 | } |
| 2108 | case NEW_NEARMV: { |
| 2109 | FRAME_COUNTS *counts = xd->counts; |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 2110 | int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); |
| 2111 | int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type], |
| 2112 | xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx); |
Alex Converse | 3d0bdc1 | 2017-05-01 15:19:58 -0700 | [diff] [blame] | 2113 | nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2114 | nmv_context_counts *const mv_counts = |
| 2115 | counts ? &counts->mv[nmv_ctx] : NULL; |
Alex Converse | 3d0bdc1 | 2017-05-01 15:19:58 -0700 | [diff] [blame] | 2116 | 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] | 2117 | assert(is_compound); |
| 2118 | ret = ret && is_mv_valid(&mv[0].as_mv); |
| 2119 | mv[1].as_int = near_mv[1].as_int; |
| 2120 | break; |
| 2121 | } |
| 2122 | case ZERO_ZEROMV: { |
| 2123 | assert(is_compound); |
Sarah Parker | c2d3871 | 2017-01-24 15:15:41 -0800 | [diff] [blame] | 2124 | #if CONFIG_GLOBAL_MOTION |
| 2125 | 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] | 2126 | cm->allow_high_precision_mv, bsize, |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2127 | mi_col, mi_row, block |
| 2128 | #if CONFIG_AMVR |
| 2129 | , |
| 2130 | cm->cur_frame_mv_precision_level |
| 2131 | #endif |
| 2132 | ) |
Sarah Parker | c2d3871 | 2017-01-24 15:15:41 -0800 | [diff] [blame] | 2133 | .as_int; |
| 2134 | 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] | 2135 | cm->allow_high_precision_mv, bsize, |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2136 | mi_col, mi_row, block |
| 2137 | #if CONFIG_AMVR |
| 2138 | , |
| 2139 | cm->cur_frame_mv_precision_level |
| 2140 | #endif |
| 2141 | ) |
Sarah Parker | c2d3871 | 2017-01-24 15:15:41 -0800 | [diff] [blame] | 2142 | .as_int; |
| 2143 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2144 | mv[0].as_int = 0; |
| 2145 | mv[1].as_int = 0; |
Sarah Parker | c2d3871 | 2017-01-24 15:15:41 -0800 | [diff] [blame] | 2146 | #endif // CONFIG_GLOBAL_MOTION |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2147 | break; |
| 2148 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2149 | default: { return 0; } |
| 2150 | } |
| 2151 | return ret; |
| 2152 | } |
| 2153 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2154 | static int read_is_inter_block(AV1_COMMON *const cm, MACROBLOCKD *const xd, |
| 2155 | int segment_id, aom_reader *r) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2156 | if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) { |
| 2157 | return get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME) != INTRA_FRAME; |
| 2158 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2159 | const int ctx = av1_get_intra_inter_context(xd); |
Thomas Davies | f6ad935 | 2017-04-19 11:38:06 +0100 | [diff] [blame] | 2160 | #if CONFIG_NEW_MULTISYMBOL |
Thomas Davies | f6ad935 | 2017-04-19 11:38:06 +0100 | [diff] [blame] | 2161 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
Thomas Davies | f6ad935 | 2017-04-19 11:38:06 +0100 | [diff] [blame] | 2162 | const int is_inter = |
| 2163 | aom_read_symbol(r, ec_ctx->intra_inter_cdf[ctx], 2, ACCT_STR); |
| 2164 | #else |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 2165 | 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] | 2166 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2167 | FRAME_COUNTS *counts = xd->counts; |
| 2168 | if (counts) ++counts->intra_inter[ctx][is_inter]; |
| 2169 | return is_inter; |
| 2170 | } |
| 2171 | } |
| 2172 | |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 2173 | #if CONFIG_COMPOUND_SINGLEREF |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2174 | static int read_is_inter_singleref_comp_mode(AV1_COMMON *const cm, |
| 2175 | MACROBLOCKD *const xd, |
| 2176 | int segment_id, aom_reader *r) { |
| 2177 | if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) return 0; |
| 2178 | |
| 2179 | const int ctx = av1_get_inter_mode_context(xd); |
| 2180 | const int is_singleref_comp_mode = |
| 2181 | aom_read(r, cm->fc->comp_inter_mode_prob[ctx], ACCT_STR); |
| 2182 | FRAME_COUNTS *counts = xd->counts; |
| 2183 | |
| 2184 | if (counts) ++counts->comp_inter_mode[ctx][is_singleref_comp_mode]; |
| 2185 | return is_singleref_comp_mode; |
| 2186 | } |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 2187 | #endif // CONFIG_COMPOUND_SINGLEREF |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2188 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2189 | static void fpm_sync(void *const data, int mi_row) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2190 | AV1Decoder *const pbi = (AV1Decoder *)data; |
| 2191 | av1_frameworker_wait(pbi->frame_worker_owner, pbi->common.prev_frame, |
| 2192 | mi_row << pbi->common.mib_size_log2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2193 | } |
| 2194 | |
Di Chen | 5658662 | 2017-06-09 13:49:44 -0700 | [diff] [blame] | 2195 | #if DEC_MISMATCH_DEBUG |
Zoe Liu | 0b3ef73 | 2017-10-06 18:37:24 -0700 | [diff] [blame] | 2196 | static void dec_dump_logs(AV1_COMMON *cm, MODE_INFO *const mi, int mi_row, |
| 2197 | int mi_col, |
Zoe Liu | f9333f5 | 2017-07-03 10:52:01 -0700 | [diff] [blame] | 2198 | int16_t inter_mode_ctx[MODE_CTX_REF_FRAMES], |
| 2199 | int16_t mode_ctx) { |
Di Chen | 5658662 | 2017-06-09 13:49:44 -0700 | [diff] [blame] | 2200 | int_mv mv[2] = { { 0 } }; |
| 2201 | int ref; |
| 2202 | MB_MODE_INFO *const mbmi = &mi->mbmi; |
Di Chen | 5658662 | 2017-06-09 13:49:44 -0700 | [diff] [blame] | 2203 | for (ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) |
| 2204 | mv[ref].as_mv = mbmi->mv[ref].as_mv; |
| 2205 | |
Di Chen | 5658662 | 2017-06-09 13:49:44 -0700 | [diff] [blame] | 2206 | const int16_t newmv_ctx = mode_ctx & NEWMV_CTX_MASK; |
| 2207 | int16_t zeromv_ctx = -1; |
| 2208 | int16_t refmv_ctx = -1; |
| 2209 | if (mbmi->mode != NEWMV) { |
| 2210 | if (mode_ctx & (1 << ALL_ZERO_FLAG_OFFSET)) assert(mbmi->mode == ZEROMV); |
| 2211 | zeromv_ctx = (mode_ctx >> ZEROMV_OFFSET) & ZEROMV_CTX_MASK; |
| 2212 | if (mbmi->mode != ZEROMV) { |
| 2213 | refmv_ctx = (mode_ctx >> REFMV_OFFSET) & REFMV_CTX_MASK; |
| 2214 | if (mode_ctx & (1 << SKIP_NEARESTMV_OFFSET)) refmv_ctx = 6; |
| 2215 | if (mode_ctx & (1 << SKIP_NEARMV_OFFSET)) refmv_ctx = 7; |
| 2216 | if (mode_ctx & (1 << SKIP_NEARESTMV_SUB8X8_OFFSET)) refmv_ctx = 8; |
| 2217 | } |
| 2218 | } |
| 2219 | |
| 2220 | int8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame); |
Zoe Liu | f9333f5 | 2017-07-03 10:52:01 -0700 | [diff] [blame] | 2221 | #define FRAME_TO_CHECK 1 |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 2222 | if (cm->current_video_frame == FRAME_TO_CHECK && cm->show_frame == 1) { |
Zoe Liu | f9333f5 | 2017-07-03 10:52:01 -0700 | [diff] [blame] | 2223 | printf( |
| 2224 | "=== DECODER ===: " |
| 2225 | "Frame=%d, (mi_row,mi_col)=(%d,%d), mode=%d, bsize=%d, " |
| 2226 | "show_frame=%d, mv[0]=(%d,%d), mv[1]=(%d,%d), ref[0]=%d, " |
| 2227 | "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] | 2228 | "newmv_ctx=%d, zeromv_ctx=%d, refmv_ctx=%d\n", |
Zoe Liu | f9333f5 | 2017-07-03 10:52:01 -0700 | [diff] [blame] | 2229 | cm->current_video_frame, mi_row, mi_col, mbmi->mode, mbmi->sb_type, |
| 2230 | cm->show_frame, mv[0].as_mv.row, mv[0].as_mv.col, mv[1].as_mv.row, |
| 2231 | 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] | 2232 | mbmi->motion_mode, inter_mode_ctx[ref_frame_type], mode_ctx, newmv_ctx, |
| 2233 | zeromv_ctx, refmv_ctx); |
Zoe Liu | f9333f5 | 2017-07-03 10:52:01 -0700 | [diff] [blame] | 2234 | } |
Di Chen | 5658662 | 2017-06-09 13:49:44 -0700 | [diff] [blame] | 2235 | } |
| 2236 | #endif // DEC_MISMATCH_DEBUG |
| 2237 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2238 | static void read_inter_block_mode_info(AV1Decoder *const pbi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2239 | MACROBLOCKD *const xd, |
| 2240 | MODE_INFO *const mi, |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 2241 | #if CONFIG_SUPERTX |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2242 | int mi_row, int mi_col, aom_reader *r, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2243 | int supertx_enabled) { |
| 2244 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2245 | int mi_row, int mi_col, aom_reader *r) { |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2246 | #endif // CONFIG_MOTION_VAR && CONFIG_SUPERTX |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2247 | AV1_COMMON *const cm = &pbi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2248 | MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 2249 | const BLOCK_SIZE bsize = mbmi->sb_type; |
| 2250 | const int allow_hp = cm->allow_high_precision_mv; |
Jingning Han | 5cfa671 | 2016-12-14 09:53:38 -0800 | [diff] [blame] | 2251 | const int unify_bsize = CONFIG_CB4X4; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2252 | int_mv nearestmv[2], nearmv[2]; |
| 2253 | int_mv ref_mvs[MODE_CTX_REF_FRAMES][MAX_MV_REF_CANDIDATES]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2254 | int ref, is_compound; |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 2255 | #if CONFIG_COMPOUND_SINGLEREF |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2256 | int is_singleref_comp_mode = 0; |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 2257 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2258 | int16_t inter_mode_ctx[MODE_CTX_REF_FRAMES]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2259 | int16_t compound_inter_mode_ctx[MODE_CTX_REF_FRAMES]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2260 | int16_t mode_ctx = 0; |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 2261 | #if CONFIG_WARPED_MOTION |
Debargha Mukherjee | e6eb3b5 | 2017-02-26 08:50:56 -0800 | [diff] [blame] | 2262 | int pts[SAMPLES_ARRAY_SIZE], pts_inref[SAMPLES_ARRAY_SIZE]; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 2263 | #if WARPED_MOTION_SORT_SAMPLES |
| 2264 | int pts_mv[SAMPLES_ARRAY_SIZE]; |
| 2265 | #endif // WARPED_MOTION_SORT_SAMPLES |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 2266 | #endif // CONFIG_WARPED_MOTION |
Thomas Davies | 1de6c88 | 2017-01-11 17:47:49 +0000 | [diff] [blame] | 2267 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2268 | |
Urvang Joshi | 5a9ea00 | 2017-05-22 15:25:18 -0700 | [diff] [blame] | 2269 | assert(NELEMENTS(mode_2_counter) == MB_MODE_COUNT); |
| 2270 | |
Luc Trudeau | b05eeae | 2017-08-18 15:14:30 -0400 | [diff] [blame] | 2271 | mbmi->uv_mode = UV_DC_PRED; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2272 | mbmi->palette_mode_info.palette_size[0] = 0; |
| 2273 | mbmi->palette_mode_info.palette_size[1] = 0; |
| 2274 | |
Frederic Barbier | 7a84fd8 | 2017-03-02 18:08:15 +0100 | [diff] [blame] | 2275 | memset(ref_mvs, 0, sizeof(ref_mvs)); |
| 2276 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2277 | read_ref_frames(cm, xd, r, mbmi->segment_id, mbmi->ref_frame); |
| 2278 | is_compound = has_second_ref(mbmi); |
| 2279 | |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 2280 | #if CONFIG_EXT_COMP_REFS |
| 2281 | #if !USE_UNI_COMP_REFS |
| 2282 | // NOTE: uni-directional comp refs disabled |
| 2283 | if (is_compound) |
| 2284 | assert(mbmi->ref_frame[0] < BWDREF_FRAME && |
| 2285 | mbmi->ref_frame[1] >= BWDREF_FRAME); |
| 2286 | #endif // !USE_UNI_COMP_REFS |
| 2287 | #endif // CONFIG_EXT_COMP_REFS |
| 2288 | |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 2289 | #if CONFIG_COMPOUND_SINGLEREF |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2290 | if (!is_compound) |
| 2291 | is_singleref_comp_mode = |
| 2292 | read_is_inter_singleref_comp_mode(cm, xd, mbmi->segment_id, r); |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 2293 | #endif // CONFIG_COMPOUND_SINGLEREF |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2294 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2295 | for (ref = 0; ref < 1 + is_compound; ++ref) { |
| 2296 | MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2297 | |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 2298 | av1_find_mv_refs(cm, xd, mi, frame, &xd->ref_mv_count[frame], |
| 2299 | xd->ref_mv_stack[frame], compound_inter_mode_ctx, |
| 2300 | ref_mvs[frame], mi_row, mi_col, fpm_sync, (void *)pbi, |
| 2301 | inter_mode_ctx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2302 | } |
| 2303 | |
Jingning Han | acddc03 | 2016-11-17 15:26:20 -0800 | [diff] [blame] | 2304 | if (is_compound) { |
| 2305 | MV_REFERENCE_FRAME ref_frame = av1_ref_frame_type(mbmi->ref_frame); |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 2306 | 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] | 2307 | xd->ref_mv_stack[ref_frame], compound_inter_mode_ctx, |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 2308 | ref_mvs[ref_frame], mi_row, mi_col, fpm_sync, (void *)pbi, |
| 2309 | inter_mode_ctx); |
| 2310 | |
| 2311 | if (xd->ref_mv_count[ref_frame] < 2) { |
| 2312 | MV_REFERENCE_FRAME rf[2]; |
David Barker | cdcac6d | 2016-12-01 17:04:16 +0000 | [diff] [blame] | 2313 | int_mv zeromv[2]; |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 2314 | av1_set_ref_frame(rf, ref_frame); |
David Barker | cdcac6d | 2016-12-01 17:04:16 +0000 | [diff] [blame] | 2315 | #if CONFIG_GLOBAL_MOTION |
| 2316 | 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] | 2317 | cm->allow_high_precision_mv, |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2318 | bsize, mi_col, mi_row, 0 |
| 2319 | #if CONFIG_AMVR |
| 2320 | , |
| 2321 | cm->cur_frame_mv_precision_level |
| 2322 | #endif |
| 2323 | ) |
David Barker | cdcac6d | 2016-12-01 17:04:16 +0000 | [diff] [blame] | 2324 | .as_int; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2325 | zeromv[1].as_int = |
| 2326 | (rf[1] != NONE_FRAME) |
| 2327 | ? gm_get_motion_vector(&cm->global_motion[rf[1]], |
| 2328 | cm->allow_high_precision_mv, bsize, mi_col, |
| 2329 | mi_row, 0 |
| 2330 | #if CONFIG_AMVR |
| 2331 | , |
| 2332 | cm->cur_frame_mv_precision_level |
| 2333 | #endif |
| 2334 | ) |
| 2335 | .as_int |
| 2336 | : 0; |
David Barker | cdcac6d | 2016-12-01 17:04:16 +0000 | [diff] [blame] | 2337 | #else |
| 2338 | zeromv[0].as_int = zeromv[1].as_int = 0; |
| 2339 | #endif |
Sarah Parker | 9923d1b | 2017-04-10 11:56:40 -0700 | [diff] [blame] | 2340 | for (ref = 0; ref < 2; ++ref) { |
| 2341 | if (rf[ref] == NONE_FRAME) continue; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2342 | #if CONFIG_AMVR |
| 2343 | lower_mv_precision(&ref_mvs[rf[ref]][0].as_mv, allow_hp, |
| 2344 | cm->cur_frame_mv_precision_level); |
| 2345 | lower_mv_precision(&ref_mvs[rf[ref]][1].as_mv, allow_hp, |
| 2346 | cm->cur_frame_mv_precision_level); |
| 2347 | #else |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 2348 | lower_mv_precision(&ref_mvs[rf[ref]][0].as_mv, allow_hp); |
| 2349 | lower_mv_precision(&ref_mvs[rf[ref]][1].as_mv, allow_hp); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2350 | #endif |
Sarah Parker | 9923d1b | 2017-04-10 11:56:40 -0700 | [diff] [blame] | 2351 | if (ref_mvs[rf[ref]][0].as_int != zeromv[ref].as_int || |
| 2352 | ref_mvs[rf[ref]][1].as_int != zeromv[ref].as_int) |
| 2353 | inter_mode_ctx[ref_frame] &= ~(1 << ALL_ZERO_FLAG_OFFSET); |
Frederic Barbier | 72e2e98 | 2017-03-03 10:01:04 +0100 | [diff] [blame] | 2354 | } |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 2355 | } |
| 2356 | } |
| 2357 | |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2358 | #if CONFIG_COMPOUND_SINGLEREF |
| 2359 | if (is_compound || is_singleref_comp_mode) |
| 2360 | #else // !CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2361 | if (is_compound) |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2362 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2363 | mode_ctx = compound_inter_mode_ctx[mbmi->ref_frame[0]]; |
| 2364 | else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2365 | mode_ctx = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2366 | av1_mode_context_analyzer(inter_mode_ctx, mbmi->ref_frame, bsize, -1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2367 | mbmi->ref_mv_idx = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2368 | |
Soo-Chul Han | a752d1d | 2017-09-08 11:21:25 -0400 | [diff] [blame] | 2369 | #if CONFIG_SEGMENT_ZEROMV |
| 2370 | if (segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP) || |
| 2371 | segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_ZEROMV)) { |
| 2372 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2373 | if (segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { |
Soo-Chul Han | a752d1d | 2017-09-08 11:21:25 -0400 | [diff] [blame] | 2374 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2375 | mbmi->mode = ZEROMV; |
Debargha Mukherjee | c76f9dc | 2017-05-01 13:18:09 -0700 | [diff] [blame] | 2376 | if (bsize < BLOCK_8X8 && !unify_bsize) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2377 | aom_internal_error(xd->error_info, AOM_CODEC_UNSUP_BITSTREAM, |
David Barker | 3409c0d | 2017-06-30 17:33:13 +0100 | [diff] [blame] | 2378 | "Invalid usage of segment feature on small blocks"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2379 | return; |
| 2380 | } |
| 2381 | } else { |
Jingning Han | 5cfa671 | 2016-12-14 09:53:38 -0800 | [diff] [blame] | 2382 | if (bsize >= BLOCK_8X8 || unify_bsize) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2383 | if (is_compound) |
| 2384 | mbmi->mode = read_inter_compound_mode(cm, xd, r, mode_ctx); |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2385 | #if CONFIG_COMPOUND_SINGLEREF |
| 2386 | else if (is_singleref_comp_mode) |
Thomas Davies | b8b14a9 | 2017-07-12 15:11:49 +0100 | [diff] [blame] | 2387 | mbmi->mode = read_inter_singleref_comp_mode(xd, r, mode_ctx); |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2388 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2389 | else |
Zoe Liu | 7f24e1b | 2017-03-17 17:42:05 -0700 | [diff] [blame] | 2390 | mbmi->mode = read_inter_mode(ec_ctx, xd, r, mode_ctx); |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2391 | if (mbmi->mode == NEWMV || mbmi->mode == NEW_NEWMV || |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2392 | #if CONFIG_COMPOUND_SINGLEREF |
| 2393 | mbmi->mode == SR_NEW_NEWMV || |
| 2394 | #endif // CONFIG_COMPOUND_SINGLEREF |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2395 | have_nearmv_in_inter_mode(mbmi->mode)) |
Thomas Davies | 149eda5 | 2017-06-12 18:11:55 +0100 | [diff] [blame] | 2396 | read_drl_idx(ec_ctx, xd, mbmi, r); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2397 | } |
| 2398 | } |
| 2399 | |
David Barker | 9b75e21 | 2017-07-28 15:31:41 +0100 | [diff] [blame] | 2400 | if ((bsize < BLOCK_8X8 && !unify_bsize) || |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 2401 | (mbmi->mode != ZEROMV && mbmi->mode != ZERO_ZEROMV)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2402 | for (ref = 0; ref < 1 + is_compound; ++ref) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2403 | #if CONFIG_AMVR |
| 2404 | av1_find_best_ref_mvs(allow_hp, ref_mvs[mbmi->ref_frame[ref]], |
| 2405 | &nearestmv[ref], &nearmv[ref], |
| 2406 | cm->cur_frame_mv_precision_level); |
| 2407 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2408 | av1_find_best_ref_mvs(allow_hp, ref_mvs[mbmi->ref_frame[ref]], |
| 2409 | &nearestmv[ref], &nearmv[ref]); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2410 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2411 | } |
| 2412 | } |
| 2413 | |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2414 | #if CONFIG_COMPOUND_SINGLEREF |
| 2415 | if ((is_compound || is_singleref_comp_mode) && |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 2416 | (bsize >= BLOCK_8X8 || unify_bsize) && mbmi->mode != ZERO_ZEROMV) |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2417 | #else // !CONFIG_COMPOUND_SINGLEREF |
Jingning Han | 61418bb | 2017-01-23 17:12:48 -0800 | [diff] [blame] | 2418 | if (is_compound && (bsize >= BLOCK_8X8 || unify_bsize) && |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 2419 | mbmi->mode != ZERO_ZEROMV) |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2420 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 2421 | { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2422 | uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2423 | |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 2424 | if (xd->ref_mv_count[ref_frame_type] > 0) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2425 | if (mbmi->mode == NEAREST_NEARESTMV) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2426 | nearestmv[0] = xd->ref_mv_stack[ref_frame_type][0].this_mv; |
| 2427 | nearestmv[1] = xd->ref_mv_stack[ref_frame_type][0].comp_mv; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2428 | #if CONFIG_AMVR |
| 2429 | lower_mv_precision(&nearestmv[0].as_mv, allow_hp, |
| 2430 | cm->cur_frame_mv_precision_level); |
| 2431 | lower_mv_precision(&nearestmv[1].as_mv, allow_hp, |
| 2432 | cm->cur_frame_mv_precision_level); |
| 2433 | #else |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 2434 | lower_mv_precision(&nearestmv[0].as_mv, allow_hp); |
| 2435 | lower_mv_precision(&nearestmv[1].as_mv, allow_hp); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2436 | #endif |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2437 | } else if (mbmi->mode == NEAREST_NEWMV |
| 2438 | #if CONFIG_COMPOUND_SINGLEREF |
| 2439 | || mbmi->mode == SR_NEAREST_NEARMV |
| 2440 | // || mbmi->mode == SR_NEAREST_NEWMV |
| 2441 | #endif // CONFIG_COMPOUND_SINGLEREF |
| 2442 | ) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2443 | nearestmv[0] = xd->ref_mv_stack[ref_frame_type][0].this_mv; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2444 | |
| 2445 | #if CONFIG_AMVR |
| 2446 | lower_mv_precision(&nearestmv[0].as_mv, allow_hp, |
| 2447 | cm->cur_frame_mv_precision_level); |
| 2448 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2449 | lower_mv_precision(&nearestmv[0].as_mv, allow_hp); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2450 | #endif |
Debargha Mukherjee | bb6e134 | 2017-04-17 16:05:04 -0700 | [diff] [blame] | 2451 | } else if (mbmi->mode == NEW_NEARESTMV) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2452 | nearestmv[1] = xd->ref_mv_stack[ref_frame_type][0].comp_mv; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2453 | #if CONFIG_AMVR |
| 2454 | lower_mv_precision(&nearestmv[1].as_mv, allow_hp, |
| 2455 | cm->cur_frame_mv_precision_level); |
| 2456 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2457 | lower_mv_precision(&nearestmv[1].as_mv, allow_hp); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2458 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2459 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2460 | } |
| 2461 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2462 | if (xd->ref_mv_count[ref_frame_type] > 1) { |
David Barker | 404b2e8 | 2017-03-27 13:07:47 +0100 | [diff] [blame] | 2463 | int ref_mv_idx = 1 + mbmi->ref_mv_idx; |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2464 | #if CONFIG_COMPOUND_SINGLEREF |
| 2465 | if (is_compound) { |
| 2466 | #endif // CONFIG_COMPOUND_SINGLEREF |
| 2467 | if (compound_ref0_mode(mbmi->mode) == NEARMV) { |
| 2468 | 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] | 2469 | #if CONFIG_AMVR |
| 2470 | lower_mv_precision(&nearmv[0].as_mv, allow_hp, |
| 2471 | cm->cur_frame_mv_precision_level); |
| 2472 | #else |
| 2473 | lower_mv_precision(&nearmv[0].as_mv, allow_hp); |
| 2474 | #endif |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2475 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2476 | |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2477 | if (compound_ref1_mode(mbmi->mode) == NEARMV) { |
| 2478 | 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] | 2479 | #if CONFIG_AMVR |
| 2480 | lower_mv_precision(&nearmv[1].as_mv, allow_hp, |
| 2481 | cm->cur_frame_mv_precision_level); |
| 2482 | #else |
| 2483 | lower_mv_precision(&nearmv[1].as_mv, allow_hp); |
| 2484 | #endif |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2485 | } |
| 2486 | #if CONFIG_COMPOUND_SINGLEREF |
| 2487 | } else { |
| 2488 | assert(is_singleref_comp_mode); |
| 2489 | if (compound_ref0_mode(mbmi->mode) == NEARMV || |
| 2490 | compound_ref1_mode(mbmi->mode) == NEARMV) { |
| 2491 | nearmv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv; |
| 2492 | lower_mv_precision(&nearmv[0].as_mv, allow_hp); |
| 2493 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2494 | } |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2495 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2496 | } |
David Barker | 0d7c4b0 | 2017-07-25 14:55:48 +0100 | [diff] [blame] | 2497 | } else if (mbmi->ref_mv_idx > 0 && mbmi->mode == NEARMV) { |
| 2498 | int_mv cur_mv = |
| 2499 | xd->ref_mv_stack[mbmi->ref_frame[0]][1 + mbmi->ref_mv_idx].this_mv; |
| 2500 | nearmv[0] = cur_mv; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2501 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2502 | |
Yue Chen | 19e7aa8 | 2016-11-30 14:05:39 -0800 | [diff] [blame] | 2503 | #if !CONFIG_DUAL_FILTER && !CONFIG_WARPED_MOTION && !CONFIG_GLOBAL_MOTION |
Angie Chiang | 9c4f895 | 2016-11-21 11:13:19 -0800 | [diff] [blame] | 2504 | read_mb_interp_filter(cm, xd, mbmi, r); |
Angie Chiang | 1733f6b | 2017-01-05 09:52:20 -0800 | [diff] [blame] | 2505 | #endif // !CONFIG_DUAL_FILTER && !CONFIG_WARPED_MOTION |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2506 | |
Jingning Han | 5cfa671 | 2016-12-14 09:53:38 -0800 | [diff] [blame] | 2507 | if (bsize < BLOCK_8X8 && !unify_bsize) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2508 | const int num_4x4_w = 1 << xd->bmode_blocks_wl; |
| 2509 | const int num_4x4_h = 1 << xd->bmode_blocks_hl; |
| 2510 | int idx, idy; |
| 2511 | PREDICTION_MODE b_mode; |
| 2512 | int_mv nearest_sub8x8[2], near_sub8x8[2]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2513 | int_mv ref_mv[2][2]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2514 | for (idy = 0; idy < 2; idy += num_4x4_h) { |
| 2515 | for (idx = 0; idx < 2; idx += num_4x4_w) { |
| 2516 | int_mv block[2]; |
| 2517 | const int j = idy * 2 + idx; |
| 2518 | int_mv ref_mv_s8[2]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2519 | if (!is_compound) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2520 | mode_ctx = av1_mode_context_analyzer(inter_mode_ctx, mbmi->ref_frame, |
| 2521 | bsize, j); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2522 | if (is_compound) |
| 2523 | b_mode = read_inter_compound_mode(cm, xd, r, mode_ctx); |
| 2524 | else |
Zoe Liu | 7f24e1b | 2017-03-17 17:42:05 -0700 | [diff] [blame] | 2525 | b_mode = read_inter_mode(ec_ctx, xd, r, mode_ctx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2526 | |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 2527 | if (b_mode != ZEROMV && b_mode != ZERO_ZEROMV) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2528 | CANDIDATE_MV ref_mv_stack[2][MAX_REF_MV_STACK_SIZE]; |
| 2529 | uint8_t ref_mv_count[2]; |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 2530 | for (ref = 0; ref < 1 + is_compound; ++ref) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2531 | int_mv mv_ref_list[MAX_MV_REF_CANDIDATES]; |
Yaowu Xu | 531d6af | 2017-03-07 17:48:52 -0800 | [diff] [blame] | 2532 | av1_update_mv_context(cm, xd, mi, mbmi->ref_frame[ref], mv_ref_list, |
| 2533 | j, mi_row, mi_col, NULL); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2534 | 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] | 2535 | ref_mv_stack[ref], &ref_mv_count[ref], |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 2536 | mv_ref_list, &nearest_sub8x8[ref], |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2537 | &near_sub8x8[ref]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2538 | if (have_newmv_in_inter_mode(b_mode)) { |
| 2539 | mv_ref_list[0].as_int = nearest_sub8x8[ref].as_int; |
| 2540 | mv_ref_list[1].as_int = near_sub8x8[ref].as_int; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2541 | #if CONFIG_AMVR |
| 2542 | av1_find_best_ref_mvs(allow_hp, mv_ref_list, &ref_mv[0][ref], |
| 2543 | &ref_mv[1][ref], |
| 2544 | cm->cur_frame_mv_precision_level); |
| 2545 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2546 | av1_find_best_ref_mvs(allow_hp, mv_ref_list, &ref_mv[0][ref], |
| 2547 | &ref_mv[1][ref]); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2548 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2549 | } |
| 2550 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2551 | } |
| 2552 | |
| 2553 | for (ref = 0; ref < 1 + is_compound && b_mode != ZEROMV; ++ref) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2554 | ref_mv_s8[ref] = nearest_sub8x8[ref]; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2555 | #if CONFIG_AMVR |
| 2556 | lower_mv_precision(&ref_mv_s8[ref].as_mv, allow_hp, |
| 2557 | cm->cur_frame_mv_precision_level); |
| 2558 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2559 | lower_mv_precision(&ref_mv_s8[ref].as_mv, allow_hp); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2560 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2561 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2562 | (void)ref_mv_s8; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2563 | |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 2564 | 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] | 2565 | nearest_sub8x8, near_sub8x8, mi_row, mi_col, is_compound, |
| 2566 | allow_hp, r)) { |
Angie Chiang | d0916d9 | 2017-03-10 17:54:18 -0800 | [diff] [blame] | 2567 | aom_merge_corrupted_flag(&xd->corrupted, 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2568 | break; |
| 2569 | }; |
| 2570 | |
| 2571 | mi->bmi[j].as_mv[0].as_int = block[0].as_int; |
Sarah Parker | d7fa854 | 2016-10-11 11:51:59 -0700 | [diff] [blame] | 2572 | mi->bmi[j].as_mode = b_mode; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2573 | if (is_compound) mi->bmi[j].as_mv[1].as_int = block[1].as_int; |
| 2574 | |
| 2575 | if (num_4x4_h == 2) mi->bmi[j + 2] = mi->bmi[j]; |
| 2576 | if (num_4x4_w == 2) mi->bmi[j + 1] = mi->bmi[j]; |
| 2577 | } |
| 2578 | } |
| 2579 | |
Yaowu Xu | f5bbbfa | 2016-09-26 09:13:38 -0700 | [diff] [blame] | 2580 | mbmi->pred_mv[0].as_int = mi->bmi[3].pred_mv[0].as_int; |
| 2581 | 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] | 2582 | mi->mbmi.mode = b_mode; |
| 2583 | |
| 2584 | mbmi->mv[0].as_int = mi->bmi[3].as_mv[0].as_int; |
| 2585 | mbmi->mv[1].as_int = mi->bmi[3].as_mv[1].as_int; |
| 2586 | } else { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2587 | int_mv ref_mv[2]; |
| 2588 | ref_mv[0] = nearestmv[0]; |
| 2589 | ref_mv[1] = nearestmv[1]; |
| 2590 | |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2591 | if (is_compound) { |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2592 | int ref_mv_idx = mbmi->ref_mv_idx; |
| 2593 | // Special case: NEAR_NEWMV and NEW_NEARMV modes use |
| 2594 | // 1 + mbmi->ref_mv_idx (like NEARMV) instead of |
| 2595 | // mbmi->ref_mv_idx (like NEWMV) |
| 2596 | if (mbmi->mode == NEAR_NEWMV || mbmi->mode == NEW_NEARMV) |
| 2597 | ref_mv_idx = 1 + mbmi->ref_mv_idx; |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2598 | |
| 2599 | if (compound_ref0_mode(mbmi->mode) == NEWMV) { |
David Barker | 404b2e8 | 2017-03-27 13:07:47 +0100 | [diff] [blame] | 2600 | uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame); |
| 2601 | if (xd->ref_mv_count[ref_frame_type] > 1) { |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2602 | 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] | 2603 | 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] | 2604 | xd->n8_h << MI_SIZE_LOG2, xd); |
| 2605 | } |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2606 | nearestmv[0] = ref_mv[0]; |
David Barker | 404b2e8 | 2017-03-27 13:07:47 +0100 | [diff] [blame] | 2607 | } |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2608 | if (compound_ref1_mode(mbmi->mode) == NEWMV) { |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2609 | uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame); |
| 2610 | if (xd->ref_mv_count[ref_frame_type] > 1) { |
| 2611 | 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] | 2612 | 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] | 2613 | xd->n8_h << MI_SIZE_LOG2, xd); |
| 2614 | } |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2615 | nearestmv[1] = ref_mv[1]; |
| 2616 | } |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2617 | #if CONFIG_COMPOUND_SINGLEREF |
| 2618 | } else if (is_singleref_comp_mode) { |
| 2619 | int ref_mv_idx = mbmi->ref_mv_idx; |
| 2620 | // Special case: SR_NEAR_NEWMV use 1 + mbmi->ref_mv_idx (like NEARMV) |
| 2621 | // instead of mbmi->ref_mv_idx (like NEWMV) |
| 2622 | if (mbmi->mode == SR_NEAR_NEWMV) ref_mv_idx = 1 + mbmi->ref_mv_idx; |
| 2623 | |
| 2624 | if (compound_ref0_mode(mbmi->mode) == NEWMV || |
| 2625 | compound_ref1_mode(mbmi->mode) == NEWMV) { |
| 2626 | uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame); |
| 2627 | if (xd->ref_mv_count[ref_frame_type] > 1) { |
| 2628 | ref_mv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv; |
| 2629 | clamp_mv_ref(&ref_mv[0].as_mv, xd->n8_w << MI_SIZE_LOG2, |
| 2630 | xd->n8_h << MI_SIZE_LOG2, xd); |
| 2631 | } |
| 2632 | // TODO(zoeliu): To further investigate why this would not cause a |
| 2633 | // mismatch for the mode of SR_NEAREST_NEWMV. |
| 2634 | nearestmv[0] = ref_mv[0]; |
| 2635 | } |
| 2636 | #endif // CONFIG_COMPOUND_SINGLEREF |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2637 | } else { |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2638 | if (mbmi->mode == NEWMV) { |
| 2639 | for (ref = 0; ref < 1 + is_compound; ++ref) { |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2640 | uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame); |
| 2641 | if (xd->ref_mv_count[ref_frame_type] > 1) { |
| 2642 | ref_mv[ref] = |
| 2643 | (ref == 0) |
| 2644 | ? xd->ref_mv_stack[ref_frame_type][mbmi->ref_mv_idx].this_mv |
| 2645 | : xd->ref_mv_stack[ref_frame_type][mbmi->ref_mv_idx] |
| 2646 | .comp_mv; |
| 2647 | clamp_mv_ref(&ref_mv[ref].as_mv, xd->n8_w << MI_SIZE_LOG2, |
| 2648 | xd->n8_h << MI_SIZE_LOG2, xd); |
| 2649 | } |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 2650 | nearestmv[ref] = ref_mv[ref]; |
| 2651 | } |
| 2652 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2653 | } |
| 2654 | |
Angie Chiang | d0916d9 | 2017-03-10 17:54:18 -0800 | [diff] [blame] | 2655 | int mv_corrupted_flag = |
Zoe Liu | 7f24e1b | 2017-03-17 17:42:05 -0700 | [diff] [blame] | 2656 | !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] | 2657 | nearestmv, nearmv, mi_row, mi_col, is_compound, allow_hp, r); |
Angie Chiang | d0916d9 | 2017-03-10 17:54:18 -0800 | [diff] [blame] | 2658 | aom_merge_corrupted_flag(&xd->corrupted, mv_corrupted_flag); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2659 | } |
| 2660 | |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 2661 | #if CONFIG_INTERINTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2662 | mbmi->use_wedge_interintra = 0; |
| 2663 | if (cm->reference_mode != COMPOUND_REFERENCE && |
| 2664 | #if CONFIG_SUPERTX |
| 2665 | !supertx_enabled && |
| 2666 | #endif |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2667 | cm->allow_interintra_compound && is_interintra_allowed(mbmi)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2668 | const int bsize_group = size_group_lookup[bsize]; |
Thomas Davies | cff9171 | 2017-07-07 11:49:55 +0100 | [diff] [blame] | 2669 | #if CONFIG_NEW_MULTISYMBOL |
| 2670 | const int interintra = |
| 2671 | aom_read_symbol(r, ec_ctx->interintra_cdf[bsize_group], 2, ACCT_STR); |
| 2672 | #else |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 2673 | const int interintra = |
| 2674 | aom_read(r, cm->fc->interintra_prob[bsize_group], ACCT_STR); |
Thomas Davies | cff9171 | 2017-07-07 11:49:55 +0100 | [diff] [blame] | 2675 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2676 | if (xd->counts) xd->counts->interintra[bsize_group][interintra]++; |
Emil Keyder | 01770b3 | 2017-01-20 18:03:11 -0500 | [diff] [blame] | 2677 | assert(mbmi->ref_frame[1] == NONE_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2678 | if (interintra) { |
| 2679 | const INTERINTRA_MODE interintra_mode = |
| 2680 | read_interintra_mode(cm, xd, r, bsize_group); |
| 2681 | mbmi->ref_frame[1] = INTRA_FRAME; |
| 2682 | mbmi->interintra_mode = interintra_mode; |
| 2683 | #if CONFIG_EXT_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2684 | mbmi->angle_delta[0] = 0; |
| 2685 | mbmi->angle_delta[1] = 0; |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 2686 | #if CONFIG_INTRA_INTERP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2687 | mbmi->intra_filter = INTRA_FILTER_LINEAR; |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 2688 | #endif // CONFIG_INTRA_INTERP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2689 | #endif // CONFIG_EXT_INTRA |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 2690 | #if CONFIG_FILTER_INTRA |
| 2691 | mbmi->filter_intra_mode_info.use_filter_intra_mode[0] = 0; |
| 2692 | mbmi->filter_intra_mode_info.use_filter_intra_mode[1] = 0; |
| 2693 | #endif // CONFIG_FILTER_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2694 | if (is_interintra_wedge_used(bsize)) { |
Thomas Davies | cff9171 | 2017-07-07 11:49:55 +0100 | [diff] [blame] | 2695 | #if CONFIG_NEW_MULTISYMBOL |
| 2696 | mbmi->use_wedge_interintra = aom_read_symbol( |
| 2697 | r, ec_ctx->wedge_interintra_cdf[bsize], 2, ACCT_STR); |
| 2698 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2699 | mbmi->use_wedge_interintra = |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 2700 | aom_read(r, cm->fc->wedge_interintra_prob[bsize], ACCT_STR); |
Thomas Davies | cff9171 | 2017-07-07 11:49:55 +0100 | [diff] [blame] | 2701 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2702 | if (xd->counts) |
| 2703 | xd->counts->wedge_interintra[bsize][mbmi->use_wedge_interintra]++; |
| 2704 | if (mbmi->use_wedge_interintra) { |
| 2705 | mbmi->interintra_wedge_index = |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 2706 | aom_read_literal(r, get_wedge_bits_lookup(bsize), ACCT_STR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2707 | mbmi->interintra_wedge_sign = 0; |
| 2708 | } |
| 2709 | } |
| 2710 | } |
| 2711 | } |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 2712 | #endif // CONFIG_INTERINTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2713 | |
Yue Chen | 52c5173 | 2017-07-11 15:08:30 -0700 | [diff] [blame] | 2714 | #if CONFIG_WARPED_MOTION |
| 2715 | for (ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) { |
| 2716 | const MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref]; |
| 2717 | RefBuffer *ref_buf = &cm->frame_refs[frame - LAST_FRAME]; |
| 2718 | |
| 2719 | xd->block_refs[ref] = ref_buf; |
| 2720 | } |
| 2721 | #endif |
| 2722 | |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2723 | #if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION |
| 2724 | mbmi->motion_mode = SIMPLE_TRANSLATION; |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 2725 | #if CONFIG_WARPED_MOTION |
| 2726 | if (mbmi->sb_type >= BLOCK_8X8 && !has_second_ref(mbmi)) |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 2727 | #if WARPED_MOTION_SORT_SAMPLES |
| 2728 | mbmi->num_proj_ref[0] = |
| 2729 | findSamples(cm, xd, mi_row, mi_col, pts, pts_inref, pts_mv); |
| 2730 | #else |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 2731 | mbmi->num_proj_ref[0] = findSamples(cm, xd, mi_row, mi_col, pts, pts_inref); |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 2732 | #endif // WARPED_MOTION_SORT_SAMPLES |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 2733 | #endif // CONFIG_WARPED_MOTION |
Yue Chen | 5329a2b | 2017-02-28 17:33:00 +0800 | [diff] [blame] | 2734 | #if CONFIG_MOTION_VAR |
| 2735 | av1_count_overlappable_neighbors(cm, xd, mi_row, mi_col); |
| 2736 | #endif |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 2737 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2738 | #if CONFIG_SUPERTX |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 2739 | if (!supertx_enabled) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2740 | #endif // CONFIG_SUPERTX |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2741 | if (mbmi->ref_frame[1] != INTRA_FRAME) |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 2742 | mbmi->motion_mode = read_motion_mode(cm, xd, mi, r); |
Wei-Ting Lin | 85a8f70 | 2017-06-22 13:55:15 -0700 | [diff] [blame] | 2743 | |
| 2744 | #if CONFIG_NCOBMC_ADAPT_WEIGHT |
Wei-Ting Lin | ca710d6 | 2017-07-13 11:41:02 -0700 | [diff] [blame] | 2745 | read_ncobmc_mode(xd, mi, mbmi->ncobmc_mode, r); |
Wei-Ting Lin | 85a8f70 | 2017-06-22 13:55:15 -0700 | [diff] [blame] | 2746 | #endif |
| 2747 | |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 2748 | #if CONFIG_COMPOUND_SINGLEREF |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2749 | if (is_singleref_comp_mode) assert(mbmi->motion_mode == SIMPLE_TRANSLATION); |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 2750 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 2751 | #if CONFIG_WARPED_MOTION |
| 2752 | if (mbmi->motion_mode == WARPED_CAUSAL) { |
| 2753 | mbmi->wm_params[0].wmtype = DEFAULT_WMTYPE; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 2754 | |
| 2755 | #if WARPED_MOTION_SORT_SAMPLES |
| 2756 | if (mbmi->num_proj_ref[0] > 1) |
| 2757 | mbmi->num_proj_ref[0] = sortSamples(pts_mv, &mbmi->mv[0].as_mv, pts, |
| 2758 | pts_inref, mbmi->num_proj_ref[0]); |
| 2759 | #endif // WARPED_MOTION_SORT_SAMPLES |
| 2760 | |
Debargha Mukherjee | 0df711f | 2017-05-02 16:00:20 -0700 | [diff] [blame] | 2761 | if (find_projection(mbmi->num_proj_ref[0], pts, pts_inref, bsize, |
| 2762 | mbmi->mv[0].as_mv.row, mbmi->mv[0].as_mv.col, |
| 2763 | &mbmi->wm_params[0], mi_row, mi_col)) { |
Yunqing Wang | 8657ad7 | 2017-06-20 14:46:08 -0700 | [diff] [blame] | 2764 | aom_internal_error(&cm->error, AOM_CODEC_ERROR, "Invalid Warped Model"); |
Debargha Mukherjee | 0df711f | 2017-05-02 16:00:20 -0700 | [diff] [blame] | 2765 | } |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 2766 | } |
| 2767 | #endif // CONFIG_WARPED_MOTION |
| 2768 | #if CONFIG_SUPERTX |
| 2769 | } |
| 2770 | #endif // CONFIG_SUPERTX |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2771 | #endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2772 | |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 2773 | mbmi->interinter_compound_type = COMPOUND_AVERAGE; |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2774 | if ( |
| 2775 | #if CONFIG_COMPOUND_SINGLEREF |
Zoe Liu | 0c634c7 | 2017-06-19 07:06:28 -0700 | [diff] [blame] | 2776 | is_inter_anyref_comp_mode(mbmi->mode) |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2777 | #else // !CONFIG_COMPOUND_SINGLEREF |
| 2778 | cm->reference_mode != SINGLE_REFERENCE && |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 2779 | is_inter_compound_mode(mbmi->mode) |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2780 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2781 | #if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 2782 | && mbmi->motion_mode == SIMPLE_TRANSLATION |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2783 | #endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 2784 | ) { |
Sarah Parker | 42d9610 | 2017-01-31 21:05:27 -0800 | [diff] [blame] | 2785 | if (is_any_masked_compound_used(bsize)) { |
Debargha Mukherjee | c5f735f | 2017-04-26 03:25:28 +0000 | [diff] [blame] | 2786 | #if CONFIG_COMPOUND_SEGMENT || CONFIG_WEDGE |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2787 | if (cm->allow_masked_compound) { |
Sarah Parker | 680b9b1 | 2017-08-16 18:55:34 -0700 | [diff] [blame] | 2788 | #if CONFIG_WEDGE && CONFIG_COMPOUND_SEGMENT |
| 2789 | if (!is_interinter_compound_used(COMPOUND_WEDGE, bsize)) |
| 2790 | mbmi->interinter_compound_type = |
| 2791 | aom_read_bit(r, ACCT_STR) ? COMPOUND_AVERAGE : COMPOUND_SEG; |
| 2792 | else |
| 2793 | #endif // CONFIG_WEDGE && CONFIG_COMPOUND_SEGMENT |
| 2794 | mbmi->interinter_compound_type = aom_read_symbol( |
| 2795 | r, ec_ctx->compound_type_cdf[bsize], COMPOUND_TYPES, ACCT_STR); |
Debargha Mukherjee | c5f735f | 2017-04-26 03:25:28 +0000 | [diff] [blame] | 2796 | #if CONFIG_WEDGE |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2797 | if (mbmi->interinter_compound_type == COMPOUND_WEDGE) { |
Sarah Parker | 680b9b1 | 2017-08-16 18:55:34 -0700 | [diff] [blame] | 2798 | assert(is_interinter_compound_used(COMPOUND_WEDGE, bsize)); |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2799 | mbmi->wedge_index = |
| 2800 | aom_read_literal(r, get_wedge_bits_lookup(bsize), ACCT_STR); |
| 2801 | mbmi->wedge_sign = aom_read_bit(r, ACCT_STR); |
| 2802 | } |
Debargha Mukherjee | c5f735f | 2017-04-26 03:25:28 +0000 | [diff] [blame] | 2803 | #endif // CONFIG_WEDGE |
Sarah Parker | 42d9610 | 2017-01-31 21:05:27 -0800 | [diff] [blame] | 2804 | #if CONFIG_COMPOUND_SEGMENT |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2805 | if (mbmi->interinter_compound_type == COMPOUND_SEG) { |
| 2806 | mbmi->mask_type = aom_read_literal(r, MAX_SEG_MASK_BITS, ACCT_STR); |
| 2807 | } |
Sarah Parker | 42d9610 | 2017-01-31 21:05:27 -0800 | [diff] [blame] | 2808 | #endif // CONFIG_COMPOUND_SEGMENT |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2809 | } |
| 2810 | #endif // CONFIG_COMPOUND_SEGMENT || CONFIG_WEDGE |
Sarah Parker | 42d9610 | 2017-01-31 21:05:27 -0800 | [diff] [blame] | 2811 | } else { |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 2812 | mbmi->interinter_compound_type = COMPOUND_AVERAGE; |
Sarah Parker | 42d9610 | 2017-01-31 21:05:27 -0800 | [diff] [blame] | 2813 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2814 | if (xd->counts) |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 2815 | xd->counts->compound_interinter[bsize][mbmi->interinter_compound_type]++; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2816 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2817 | |
Yue Chen | 19e7aa8 | 2016-11-30 14:05:39 -0800 | [diff] [blame] | 2818 | #if CONFIG_DUAL_FILTER || CONFIG_WARPED_MOTION || CONFIG_GLOBAL_MOTION |
Debargha Mukherjee | 0df711f | 2017-05-02 16:00:20 -0700 | [diff] [blame] | 2819 | read_mb_interp_filter(cm, xd, mbmi, r); |
Angie Chiang | 1733f6b | 2017-01-05 09:52:20 -0800 | [diff] [blame] | 2820 | #endif // CONFIG_DUAL_FILTER || CONFIG_WARPED_MOTION |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2821 | |
Di Chen | 5658662 | 2017-06-09 13:49:44 -0700 | [diff] [blame] | 2822 | #if DEC_MISMATCH_DEBUG |
Zoe Liu | 0b3ef73 | 2017-10-06 18:37:24 -0700 | [diff] [blame] | 2823 | 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] | 2824 | #endif // DEC_MISMATCH_DEBUG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2825 | } |
| 2826 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2827 | static void read_inter_frame_mode_info(AV1Decoder *const pbi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2828 | MACROBLOCKD *const xd, |
| 2829 | #if CONFIG_SUPERTX |
| 2830 | int supertx_enabled, |
| 2831 | #endif // CONFIG_SUPERTX |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2832 | int mi_row, int mi_col, aom_reader *r) { |
| 2833 | AV1_COMMON *const cm = &pbi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2834 | MODE_INFO *const mi = xd->mi[0]; |
| 2835 | MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 2836 | int inter_block = 1; |
| 2837 | #if CONFIG_VAR_TX |
| 2838 | BLOCK_SIZE bsize = mbmi->sb_type; |
| 2839 | #endif // CONFIG_VAR_TX |
| 2840 | |
| 2841 | mbmi->mv[0].as_int = 0; |
| 2842 | mbmi->mv[1].as_int = 0; |
| 2843 | mbmi->segment_id = read_inter_segment_id(cm, xd, mi_row, mi_col, r); |
| 2844 | #if CONFIG_SUPERTX |
David Barker | 3aec8d6 | 2017-01-31 14:55:32 +0000 | [diff] [blame] | 2845 | if (!supertx_enabled) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2846 | #endif // CONFIG_SUPERTX |
| 2847 | mbmi->skip = read_skip(cm, xd, mbmi->segment_id, r); |
David Barker | 3aec8d6 | 2017-01-31 14:55:32 +0000 | [diff] [blame] | 2848 | |
David Barker | 3aec8d6 | 2017-01-31 14:55:32 +0000 | [diff] [blame] | 2849 | if (cm->delta_q_present_flag) { |
| 2850 | xd->current_qindex = |
| 2851 | xd->prev_qindex + |
| 2852 | 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] | 2853 | /* Normative: Clamp to [1,MAXQ] to not interfere with lossless mode */ |
| 2854 | xd->current_qindex = clamp(xd->current_qindex, 1, MAXQ); |
David Barker | 3aec8d6 | 2017-01-31 14:55:32 +0000 | [diff] [blame] | 2855 | xd->prev_qindex = xd->current_qindex; |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 2856 | #if CONFIG_EXT_DELTA_Q |
| 2857 | if (cm->delta_lf_present_flag) { |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 2858 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 880166a | 2017-10-02 17:48:48 -0700 | [diff] [blame] | 2859 | if (cm->delta_lf_multi) { |
| 2860 | for (int lf_id = 0; lf_id < FRAME_LF_COUNT; ++lf_id) { |
| 2861 | mbmi->curr_delta_lf[lf_id] = xd->curr_delta_lf[lf_id] = |
| 2862 | xd->prev_delta_lf[lf_id] + |
| 2863 | read_delta_lflevel(cm, xd, r, lf_id, mbmi, mi_col, mi_row) * |
| 2864 | cm->delta_lf_res; |
| 2865 | xd->prev_delta_lf[lf_id] = xd->curr_delta_lf[lf_id]; |
| 2866 | } |
| 2867 | } else { |
| 2868 | mbmi->current_delta_lf_from_base = xd->current_delta_lf_from_base = |
| 2869 | xd->prev_delta_lf_from_base + |
| 2870 | read_delta_lflevel(cm, xd, r, -1, mbmi, mi_col, mi_row) * |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 2871 | cm->delta_lf_res; |
Cheng Chen | 880166a | 2017-10-02 17:48:48 -0700 | [diff] [blame] | 2872 | xd->prev_delta_lf_from_base = xd->current_delta_lf_from_base; |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 2873 | } |
| 2874 | #else |
Cheng Chen | 9dccdf2 | 2017-10-02 15:04:40 -0700 | [diff] [blame] | 2875 | const int current_delta_lf_from_base = |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 2876 | xd->prev_delta_lf_from_base + |
| 2877 | read_delta_lflevel(cm, xd, r, mbmi, mi_col, mi_row) * |
| 2878 | cm->delta_lf_res; |
Cheng Chen | 9dccdf2 | 2017-10-02 15:04:40 -0700 | [diff] [blame] | 2879 | mbmi->current_delta_lf_from_base = xd->current_delta_lf_from_base = |
| 2880 | clamp(current_delta_lf_from_base, 0, MAX_LOOP_FILTER); |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 2881 | xd->prev_delta_lf_from_base = xd->current_delta_lf_from_base; |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 2882 | #endif // CONFIG_LOOPFILTER_LEVEL |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 2883 | } |
| 2884 | #endif |
David Barker | 3aec8d6 | 2017-01-31 14:55:32 +0000 | [diff] [blame] | 2885 | } |
David Barker | 3aec8d6 | 2017-01-31 14:55:32 +0000 | [diff] [blame] | 2886 | |
| 2887 | #if CONFIG_SUPERTX |
| 2888 | if (!supertx_enabled) { |
| 2889 | #endif // CONFIG_SUPERTX |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2890 | inter_block = read_is_inter_block(cm, xd, mbmi->segment_id, r); |
| 2891 | |
| 2892 | #if CONFIG_VAR_TX |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 2893 | xd->above_txfm_context = |
| 2894 | cm->above_txfm_context + (mi_col << TX_UNIT_WIDE_LOG2); |
| 2895 | xd->left_txfm_context = xd->left_txfm_context_buffer + |
| 2896 | ((mi_row & MAX_MIB_MASK) << TX_UNIT_HIGH_LOG2); |
Jingning Han | 581d169 | 2017-01-05 16:03:54 -0800 | [diff] [blame] | 2897 | |
| 2898 | if (cm->tx_mode == TX_MODE_SELECT && |
| 2899 | #if CONFIG_CB4X4 |
Jingning Han | 3daa4fd | 2017-01-20 10:33:50 -0800 | [diff] [blame] | 2900 | bsize > BLOCK_4X4 && |
Jingning Han | 581d169 | 2017-01-05 16:03:54 -0800 | [diff] [blame] | 2901 | #else |
| 2902 | bsize >= BLOCK_8X8 && |
| 2903 | #endif |
David Barker | 16c64e3 | 2017-08-23 16:54:59 +0100 | [diff] [blame] | 2904 | !mbmi->skip && inter_block && !xd->lossless[mbmi->segment_id]) { |
Jingning Han | 70e5f3f | 2016-11-09 17:03:07 -0800 | [diff] [blame] | 2905 | const TX_SIZE max_tx_size = max_txsize_rect_lookup[bsize]; |
Jingning Han | f64062f | 2016-11-02 16:22:18 -0700 | [diff] [blame] | 2906 | const int bh = tx_size_high_unit[max_tx_size]; |
| 2907 | const int bw = tx_size_wide_unit[max_tx_size]; |
Jingning Han | 65abc31 | 2016-10-27 13:04:21 -0700 | [diff] [blame] | 2908 | const int width = block_size_wide[bsize] >> tx_size_wide_log2[0]; |
| 2909 | const int height = block_size_high[bsize] >> tx_size_wide_log2[0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2910 | int idx, idy; |
Sarah Parker | d25ef8c | 2017-10-06 12:17:30 -0700 | [diff] [blame] | 2911 | int init_depth = |
| 2912 | (height != width) ? RECT_VARTX_DEPTH_INIT : SQR_VARTX_DEPTH_INIT; |
Yue Chen | a1e48dc | 2016-08-29 17:29:33 -0700 | [diff] [blame] | 2913 | |
Jingning Han | fe45b21 | 2016-11-22 10:30:23 -0800 | [diff] [blame] | 2914 | mbmi->min_tx_size = TX_SIZES_ALL; |
| 2915 | for (idy = 0; idy < height; idy += bh) |
| 2916 | for (idx = 0; idx < width; idx += bw) |
Sarah Parker | d25ef8c | 2017-10-06 12:17:30 -0700 | [diff] [blame] | 2917 | read_tx_size_vartx(cm, xd, mbmi, xd->counts, max_tx_size, init_depth, |
| 2918 | idy, idx, r); |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 2919 | #if CONFIG_RECT_TX_EXT |
| 2920 | if (is_quarter_tx_allowed(xd, mbmi, inter_block) && |
| 2921 | mbmi->tx_size == max_tx_size) { |
| 2922 | int quarter_tx; |
| 2923 | |
| 2924 | if (quarter_txsize_lookup[bsize] != max_tx_size) { |
Thomas Davies | e3f6978 | 2017-10-03 10:43:17 +0100 | [diff] [blame] | 2925 | #if CONFIG_NEW_MULTISYMBOL |
| 2926 | quarter_tx = |
| 2927 | aom_read_symbol(r, cm->fc->quarter_tx_size_cdf, 2, ACCT_STR); |
| 2928 | #else |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 2929 | quarter_tx = aom_read(r, cm->fc->quarter_tx_size_prob, ACCT_STR); |
| 2930 | if (xd->counts) ++xd->counts->quarter_tx_size[quarter_tx]; |
Thomas Davies | e3f6978 | 2017-10-03 10:43:17 +0100 | [diff] [blame] | 2931 | #endif |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 2932 | } else { |
| 2933 | quarter_tx = 1; |
| 2934 | } |
| 2935 | if (quarter_tx) { |
| 2936 | mbmi->tx_size = quarter_txsize_lookup[bsize]; |
| 2937 | for (idy = 0; idy < tx_size_high_unit[max_tx_size] / 2; ++idy) |
| 2938 | for (idx = 0; idx < tx_size_wide_unit[max_tx_size] / 2; ++idx) |
| 2939 | mbmi->inter_tx_size[idy][idx] = mbmi->tx_size; |
| 2940 | mbmi->min_tx_size = get_min_tx_size(mbmi->tx_size); |
| 2941 | } |
| 2942 | } |
| 2943 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2944 | } else { |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 2945 | 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] | 2946 | |
| 2947 | if (inter_block) { |
Jingning Han | 9ca05b7 | 2017-01-03 14:41:36 -0800 | [diff] [blame] | 2948 | const int width = block_size_wide[bsize] >> tx_size_wide_log2[0]; |
| 2949 | const int height = block_size_high[bsize] >> tx_size_high_log2[0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2950 | int idx, idy; |
| 2951 | for (idy = 0; idy < height; ++idy) |
| 2952 | for (idx = 0; idx < width; ++idx) |
| 2953 | mbmi->inter_tx_size[idy >> 1][idx >> 1] = mbmi->tx_size; |
| 2954 | } |
Jingning Han | e67b38a | 2016-11-04 10:30:00 -0700 | [diff] [blame] | 2955 | mbmi->min_tx_size = get_min_tx_size(mbmi->tx_size); |
Jingning Han | 1b1dc93 | 2016-11-09 10:55:30 -0800 | [diff] [blame] | 2956 | 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] | 2957 | } |
| 2958 | #else |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 2959 | 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] | 2960 | #endif // CONFIG_VAR_TX |
| 2961 | #if CONFIG_SUPERTX |
| 2962 | } |
| 2963 | #if CONFIG_VAR_TX |
| 2964 | else if (inter_block) { |
| 2965 | const int width = num_4x4_blocks_wide_lookup[bsize]; |
| 2966 | const int height = num_4x4_blocks_high_lookup[bsize]; |
| 2967 | int idx, idy; |
| 2968 | xd->mi[0]->mbmi.tx_size = xd->supertx_size; |
| 2969 | for (idy = 0; idy < height; ++idy) |
| 2970 | for (idx = 0; idx < width; ++idx) |
| 2971 | xd->mi[0]->mbmi.inter_tx_size[idy >> 1][idx >> 1] = xd->supertx_size; |
| 2972 | } |
| 2973 | #endif // CONFIG_VAR_TX |
| 2974 | #endif // CONFIG_SUPERTX |
| 2975 | |
| 2976 | if (inter_block) |
| 2977 | read_inter_block_mode_info(pbi, xd, |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 2978 | #if CONFIG_SUPERTX |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2979 | mi, mi_row, mi_col, r, supertx_enabled); |
| 2980 | #else |
| 2981 | mi, mi_row, mi_col, r); |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2982 | #endif // CONFIG_MOTION_VAR && CONFIG_SUPERTX |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2983 | else |
Jingning Han | 36fe320 | 2017-02-20 22:31:49 -0800 | [diff] [blame] | 2984 | 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] | 2985 | |
Angie Chiang | cd9b03f | 2017-04-16 13:37:13 -0700 | [diff] [blame] | 2986 | #if !CONFIG_TXK_SEL |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 2987 | av1_read_tx_type(cm, xd, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2988 | #if CONFIG_SUPERTX |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 2989 | supertx_enabled, |
Nathan E. Egge | 93878c4 | 2016-05-03 10:01:32 -0400 | [diff] [blame] | 2990 | #endif |
Angie Chiang | a9f9a31 | 2017-04-13 16:40:43 -0700 | [diff] [blame] | 2991 | r); |
Angie Chiang | cd9b03f | 2017-04-16 13:37:13 -0700 | [diff] [blame] | 2992 | #endif // !CONFIG_TXK_SEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2993 | } |
| 2994 | |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 2995 | static void av1_intra_copy_frame_mvs(AV1_COMMON *const cm, int mi_row, |
| 2996 | int mi_col, int x_mis, int y_mis) { |
| 2997 | #if CONFIG_TMV |
| 2998 | const int frame_mvs_stride = ROUND_POWER_OF_TWO(cm->mi_cols, 1); |
| 2999 | MV_REF *frame_mvs = cm->cur_frame->mvs + |
| 3000 | ((mi_row & 0xfffe) >> 1) * frame_mvs_stride + |
| 3001 | ((mi_col & 0xfffe) >> 1); |
| 3002 | x_mis = ROUND_POWER_OF_TWO(x_mis, 1); |
| 3003 | y_mis = ROUND_POWER_OF_TWO(y_mis, 1); |
| 3004 | #else |
| 3005 | const int frame_mvs_stride = cm->mi_cols; |
| 3006 | MV_REF *frame_mvs = cm->cur_frame->mvs + |
| 3007 | (mi_row & 0xfffe) * frame_mvs_stride + (mi_col & 0xfffe); |
| 3008 | x_mis = AOMMAX(x_mis, 2); |
| 3009 | y_mis = AOMMAX(y_mis, 2); |
| 3010 | #endif // CONFIG_TMV |
| 3011 | int w, h; |
| 3012 | |
| 3013 | for (h = 0; h < y_mis; h++) { |
| 3014 | MV_REF *const frame_mv = frame_mvs + h * frame_mvs_stride; |
| 3015 | for (w = 0; w < x_mis; w++) { |
| 3016 | MV_REF *const mv = frame_mv + w; |
| 3017 | mv->ref_frame[0] = NONE_FRAME; |
| 3018 | mv->ref_frame[1] = NONE_FRAME; |
| 3019 | } |
| 3020 | } |
| 3021 | } |
| 3022 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3023 | void av1_read_mode_info(AV1Decoder *const pbi, MACROBLOCKD *xd, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3024 | #if CONFIG_SUPERTX |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3025 | int supertx_enabled, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3026 | #endif // CONFIG_SUPERTX |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3027 | int mi_row, int mi_col, aom_reader *r, int x_mis, |
| 3028 | int y_mis) { |
| 3029 | AV1_COMMON *const cm = &pbi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3030 | MODE_INFO *const mi = xd->mi[0]; |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 3031 | #if CONFIG_INTRABC |
| 3032 | mi->mbmi.use_intrabc = 0; |
| 3033 | #endif // CONFIG_INTRABC |
| 3034 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3035 | if (frame_is_intra_only(cm)) { |
| 3036 | read_intra_frame_mode_info(cm, xd, mi_row, mi_col, r); |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 3037 | 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] | 3038 | } else { |
| 3039 | read_inter_frame_mode_info(pbi, xd, |
| 3040 | #if CONFIG_SUPERTX |
| 3041 | supertx_enabled, |
| 3042 | #endif // CONFIG_SUPERTX |
| 3043 | mi_row, mi_col, r); |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 3044 | 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] | 3045 | } |
| 3046 | } |