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