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 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 11 | #ifndef AV1_COMMON_MVREF_COMMON_H_ |
| 12 | #define AV1_COMMON_MVREF_COMMON_H_ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 13 | |
| 14 | #include "av1/common/onyxc_int.h" |
| 15 | #include "av1/common/blockd.h" |
| 16 | |
| 17 | #ifdef __cplusplus |
| 18 | extern "C" { |
| 19 | #endif |
| 20 | |
Yaowu Xu | dd28be8 | 2016-11-21 10:15:30 -0800 | [diff] [blame] | 21 | #if CONFIG_REF_MV |
Deng | ca8d24d | 2016-10-17 14:06:35 +0800 | [diff] [blame] | 22 | #define MVREF_NEIGHBOURS 9 |
| 23 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 24 | #define MVREF_NEIGHBOURS 8 |
Deng | ca8d24d | 2016-10-17 14:06:35 +0800 | [diff] [blame] | 25 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 26 | |
| 27 | typedef struct position { |
| 28 | int row; |
| 29 | int col; |
| 30 | } POSITION; |
| 31 | |
| 32 | typedef enum { |
| 33 | BOTH_ZERO = 0, |
| 34 | ZERO_PLUS_PREDICTED = 1, |
| 35 | BOTH_PREDICTED = 2, |
| 36 | NEW_PLUS_NON_INTRA = 3, |
| 37 | BOTH_NEW = 4, |
| 38 | INTRA_PLUS_NON_INTRA = 5, |
| 39 | BOTH_INTRA = 6, |
| 40 | INVALID_CASE = 9 |
| 41 | } motion_vector_context; |
| 42 | |
| 43 | // This is used to figure out a context for the ref blocks. The code flattens |
| 44 | // an array that would have 3 possible counts (0, 1 & 2) for 3 choices by |
| 45 | // adding 9 for each intra block, 3 for each zero mv and 1 for each new |
| 46 | // motion vector. This single number is then converted into a context |
| 47 | // with a single lookup ( counter_to_context ). |
| 48 | static const int mode_2_counter[MB_MODE_COUNT] = { |
| 49 | 9, // DC_PRED |
| 50 | 9, // V_PRED |
| 51 | 9, // H_PRED |
| 52 | 9, // D45_PRED |
| 53 | 9, // D135_PRED |
| 54 | 9, // D117_PRED |
| 55 | 9, // D153_PRED |
| 56 | 9, // D207_PRED |
| 57 | 9, // D63_PRED |
Urvang Joshi | 102245d | 2016-11-28 13:05:36 -0800 | [diff] [blame] | 58 | #if CONFIG_ALT_INTRA |
| 59 | 9, // SMOOTH_PRED |
| 60 | #endif // CONFIG_ALT_INTRA |
| 61 | 9, // TM_PRED |
| 62 | 0, // NEARESTMV |
| 63 | 0, // NEARMV |
| 64 | 3, // ZEROMV |
| 65 | 1, // NEWMV |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 66 | #if CONFIG_EXT_INTER |
| 67 | 1, // NEWFROMNEARMV |
| 68 | 0, // NEAREST_NEARESTMV |
| 69 | 0, // NEAREST_NEARMV |
| 70 | 0, // NEAR_NEARESTMV |
| 71 | 0, // NEAR_NEARMV |
| 72 | 1, // NEAREST_NEWMV |
| 73 | 1, // NEW_NEARESTMV |
| 74 | 1, // NEAR_NEWMV |
| 75 | 1, // NEW_NEARMV |
| 76 | 3, // ZERO_ZEROMV |
| 77 | 1, // NEW_NEWMV |
| 78 | #endif // CONFIG_EXT_INTER |
| 79 | }; |
| 80 | |
| 81 | // There are 3^3 different combinations of 3 counts that can be either 0,1 or |
| 82 | // 2. However the actual count can never be greater than 2 so the highest |
| 83 | // counter we need is 18. 9 is an invalid counter that's never used. |
| 84 | static const int counter_to_context[19] = { |
| 85 | BOTH_PREDICTED, // 0 |
| 86 | NEW_PLUS_NON_INTRA, // 1 |
| 87 | BOTH_NEW, // 2 |
| 88 | ZERO_PLUS_PREDICTED, // 3 |
| 89 | NEW_PLUS_NON_INTRA, // 4 |
| 90 | INVALID_CASE, // 5 |
| 91 | BOTH_ZERO, // 6 |
| 92 | INVALID_CASE, // 7 |
| 93 | INVALID_CASE, // 8 |
| 94 | INTRA_PLUS_NON_INTRA, // 9 |
| 95 | INTRA_PLUS_NON_INTRA, // 10 |
| 96 | INVALID_CASE, // 11 |
| 97 | INTRA_PLUS_NON_INTRA, // 12 |
| 98 | INVALID_CASE, // 13 |
| 99 | INVALID_CASE, // 14 |
| 100 | INVALID_CASE, // 15 |
| 101 | INVALID_CASE, // 16 |
| 102 | INVALID_CASE, // 17 |
| 103 | BOTH_INTRA // 18 |
| 104 | }; |
| 105 | |
Yaowu Xu | dd28be8 | 2016-11-21 10:15:30 -0800 | [diff] [blame] | 106 | #if !CONFIG_REF_MV |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 107 | static const POSITION mv_ref_blocks[BLOCK_SIZES][MVREF_NEIGHBOURS] = { |
| 108 | // 4X4 |
| 109 | { { -1, 0 }, |
| 110 | { 0, -1 }, |
| 111 | { -1, -1 }, |
| 112 | { -2, 0 }, |
| 113 | { 0, -2 }, |
| 114 | { -2, -1 }, |
| 115 | { -1, -2 }, |
| 116 | { -2, -2 } }, |
| 117 | // 4X8 |
| 118 | { { -1, 0 }, |
| 119 | { 0, -1 }, |
| 120 | { -1, -1 }, |
| 121 | { -2, 0 }, |
| 122 | { 0, -2 }, |
| 123 | { -2, -1 }, |
| 124 | { -1, -2 }, |
| 125 | { -2, -2 } }, |
| 126 | // 8X4 |
| 127 | { { -1, 0 }, |
| 128 | { 0, -1 }, |
| 129 | { -1, -1 }, |
| 130 | { -2, 0 }, |
| 131 | { 0, -2 }, |
| 132 | { -2, -1 }, |
| 133 | { -1, -2 }, |
| 134 | { -2, -2 } }, |
| 135 | // 8X8 |
| 136 | { { -1, 0 }, |
| 137 | { 0, -1 }, |
| 138 | { -1, -1 }, |
| 139 | { -2, 0 }, |
| 140 | { 0, -2 }, |
| 141 | { -2, -1 }, |
| 142 | { -1, -2 }, |
| 143 | { -2, -2 } }, |
| 144 | // 8X16 |
| 145 | { { 0, -1 }, |
| 146 | { -1, 0 }, |
| 147 | { 1, -1 }, |
| 148 | { -1, -1 }, |
| 149 | { 0, -2 }, |
| 150 | { -2, 0 }, |
| 151 | { -2, -1 }, |
| 152 | { -1, -2 } }, |
| 153 | // 16X8 |
| 154 | { { -1, 0 }, |
| 155 | { 0, -1 }, |
| 156 | { -1, 1 }, |
| 157 | { -1, -1 }, |
| 158 | { -2, 0 }, |
| 159 | { 0, -2 }, |
| 160 | { -1, -2 }, |
| 161 | { -2, -1 } }, |
| 162 | // 16X16 |
| 163 | { { -1, 0 }, |
| 164 | { 0, -1 }, |
| 165 | { -1, 1 }, |
| 166 | { 1, -1 }, |
| 167 | { -1, -1 }, |
| 168 | { -3, 0 }, |
| 169 | { 0, -3 }, |
| 170 | { -3, -3 } }, |
| 171 | // 16X32 |
| 172 | { { 0, -1 }, |
| 173 | { -1, 0 }, |
| 174 | { 2, -1 }, |
| 175 | { -1, -1 }, |
| 176 | { -1, 1 }, |
| 177 | { 0, -3 }, |
| 178 | { -3, 0 }, |
| 179 | { -3, -3 } }, |
| 180 | // 32X16 |
| 181 | { { -1, 0 }, |
| 182 | { 0, -1 }, |
| 183 | { -1, 2 }, |
| 184 | { -1, -1 }, |
| 185 | { 1, -1 }, |
| 186 | { -3, 0 }, |
| 187 | { 0, -3 }, |
| 188 | { -3, -3 } }, |
| 189 | // 32X32 |
| 190 | { { -1, 1 }, |
| 191 | { 1, -1 }, |
| 192 | { -1, 2 }, |
| 193 | { 2, -1 }, |
| 194 | { -1, -1 }, |
| 195 | { -3, 0 }, |
| 196 | { 0, -3 }, |
| 197 | { -3, -3 } }, |
| 198 | // 32X64 |
| 199 | { { 0, -1 }, |
| 200 | { -1, 0 }, |
| 201 | { 4, -1 }, |
| 202 | { -1, 2 }, |
| 203 | { -1, -1 }, |
| 204 | { 0, -3 }, |
| 205 | { -3, 0 }, |
| 206 | { 2, -1 } }, |
| 207 | // 64X32 |
| 208 | { { -1, 0 }, |
| 209 | { 0, -1 }, |
| 210 | { -1, 4 }, |
| 211 | { 2, -1 }, |
| 212 | { -1, -1 }, |
| 213 | { -3, 0 }, |
| 214 | { 0, -3 }, |
| 215 | { -1, 2 } }, |
| 216 | // 64X64 |
| 217 | { { -1, 3 }, |
| 218 | { 3, -1 }, |
| 219 | { -1, 4 }, |
| 220 | { 4, -1 }, |
| 221 | { -1, -1 }, |
| 222 | { -1, 0 }, |
| 223 | { 0, -1 }, |
| 224 | { -1, 6 } }, |
| 225 | #if CONFIG_EXT_PARTITION |
| 226 | // TODO(debargha/jingning) Making them twice the 32x64, .. ones above |
| 227 | // 64x128 |
| 228 | { { 0, -2 }, |
| 229 | { -2, 0 }, |
| 230 | { 8, -2 }, |
| 231 | { -2, 4 }, |
| 232 | { -2, -2 }, |
| 233 | { 0, -6 }, |
| 234 | { -6, 0 }, |
| 235 | { 4, -2 } }, |
| 236 | // 128x64 |
| 237 | { { -2, 0 }, |
| 238 | { 0, -2 }, |
| 239 | { -2, 8 }, |
| 240 | { 4, -2 }, |
| 241 | { -2, -2 }, |
| 242 | { -6, 0 }, |
| 243 | { 0, -6 }, |
| 244 | { -2, 4 } }, |
| 245 | // 128x128 |
| 246 | { { -2, 6 }, |
| 247 | { 6, -2 }, |
| 248 | { -2, 8 }, |
| 249 | { 8, -2 }, |
| 250 | { -2, -2 }, |
| 251 | { -2, 0 }, |
| 252 | { 0, -2 }, |
| 253 | { -2, 12 } }, |
| 254 | #endif // CONFIG_EXT_PARTITION |
| 255 | }; |
Deng | ca8d24d | 2016-10-17 14:06:35 +0800 | [diff] [blame] | 256 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 257 | |
| 258 | static const int idx_n_column_to_subblock[4][2] = { |
| 259 | { 1, 2 }, { 1, 3 }, { 3, 2 }, { 3, 3 } |
| 260 | }; |
| 261 | |
| 262 | // clamp_mv_ref |
| 263 | #if CONFIG_EXT_PARTITION |
| 264 | #define MV_BORDER (16 << 3) // Allow 16 pels in 1/8th pel units |
| 265 | #else |
| 266 | #define MV_BORDER (8 << 3) // Allow 8 pels in 1/8th pel units |
| 267 | #endif // CONFIG_EXT_PARTITION |
| 268 | |
| 269 | static INLINE void clamp_mv_ref(MV *mv, int bw, int bh, const MACROBLOCKD *xd) { |
| 270 | clamp_mv(mv, xd->mb_to_left_edge - bw * 8 - MV_BORDER, |
| 271 | xd->mb_to_right_edge + bw * 8 + MV_BORDER, |
| 272 | xd->mb_to_top_edge - bh * 8 - MV_BORDER, |
| 273 | xd->mb_to_bottom_edge + bh * 8 + MV_BORDER); |
| 274 | } |
| 275 | |
| 276 | // This function returns either the appropriate sub block or block's mv |
| 277 | // on whether the block_size < 8x8 and we have check_sub_blocks set. |
| 278 | static INLINE int_mv get_sub_block_mv(const MODE_INFO *candidate, int which_mv, |
| 279 | int search_col, int block_idx) { |
Yaowu Xu | dd28be8 | 2016-11-21 10:15:30 -0800 | [diff] [blame] | 280 | #if CONFIG_REF_MV |
| 281 | (void)search_col; |
Yaowu Xu | 4ce287a | 2016-11-21 14:20:22 -0800 | [diff] [blame] | 282 | (void)block_idx; |
Deng | ca8d24d | 2016-10-17 14:06:35 +0800 | [diff] [blame] | 283 | return candidate->mbmi.mv[which_mv]; |
| 284 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 285 | return block_idx >= 0 && candidate->mbmi.sb_type < BLOCK_8X8 |
| 286 | ? candidate |
| 287 | ->bmi[idx_n_column_to_subblock[block_idx][search_col == 0]] |
| 288 | .as_mv[which_mv] |
| 289 | : candidate->mbmi.mv[which_mv]; |
Deng | ca8d24d | 2016-10-17 14:06:35 +0800 | [diff] [blame] | 290 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | #if CONFIG_REF_MV |
| 294 | static INLINE int_mv get_sub_block_pred_mv(const MODE_INFO *candidate, |
| 295 | int which_mv, int search_col, |
| 296 | int block_idx) { |
Jingning Han | 24e0a18 | 2016-11-20 22:34:12 -0800 | [diff] [blame] | 297 | (void)search_col; |
| 298 | (void)block_idx; |
Deng | ca8d24d | 2016-10-17 14:06:35 +0800 | [diff] [blame] | 299 | return candidate->mbmi.mv[which_mv]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 300 | } |
| 301 | #endif |
| 302 | |
| 303 | // Performs mv sign inversion if indicated by the reference frame combination. |
| 304 | static INLINE int_mv scale_mv(const MB_MODE_INFO *mbmi, int ref, |
| 305 | const MV_REFERENCE_FRAME this_ref_frame, |
| 306 | const int *ref_sign_bias) { |
| 307 | int_mv mv = mbmi->mv[ref]; |
| 308 | if (ref_sign_bias[mbmi->ref_frame[ref]] != ref_sign_bias[this_ref_frame]) { |
| 309 | mv.as_mv.row *= -1; |
| 310 | mv.as_mv.col *= -1; |
| 311 | } |
| 312 | return mv; |
| 313 | } |
| 314 | |
| 315 | #define CLIP_IN_ADD(mv, bw, bh, xd) clamp_mv_ref(mv, bw, bh, xd) |
| 316 | |
| 317 | // This macro is used to add a motion vector mv_ref list if it isn't |
| 318 | // already in the list. If it's the second motion vector it will also |
| 319 | // skip all additional processing and jump to done! |
| 320 | #define ADD_MV_REF_LIST(mv, refmv_count, mv_ref_list, bw, bh, xd, Done) \ |
| 321 | do { \ |
| 322 | (mv_ref_list)[(refmv_count)] = (mv); \ |
| 323 | CLIP_IN_ADD(&(mv_ref_list)[(refmv_count)].as_mv, (bw), (bh), (xd)); \ |
| 324 | if (refmv_count && (mv_ref_list)[1].as_int != (mv_ref_list)[0].as_int) { \ |
| 325 | (refmv_count) = 2; \ |
| 326 | goto Done; \ |
| 327 | } \ |
| 328 | (refmv_count) = 1; \ |
| 329 | } while (0) |
| 330 | |
| 331 | // If either reference frame is different, not INTRA, and they |
| 332 | // are different from each other scale and add the mv to our list. |
| 333 | #define IF_DIFF_REF_FRAME_ADD_MV(mbmi, ref_frame, ref_sign_bias, refmv_count, \ |
| 334 | mv_ref_list, bw, bh, xd, Done) \ |
| 335 | do { \ |
| 336 | if (is_inter_block(mbmi)) { \ |
| 337 | if ((mbmi)->ref_frame[0] != ref_frame) \ |
| 338 | ADD_MV_REF_LIST(scale_mv((mbmi), 0, ref_frame, ref_sign_bias), \ |
| 339 | refmv_count, mv_ref_list, bw, bh, xd, Done); \ |
| 340 | if (has_second_ref(mbmi) && (mbmi)->ref_frame[1] != ref_frame) \ |
| 341 | ADD_MV_REF_LIST(scale_mv((mbmi), 1, ref_frame, ref_sign_bias), \ |
| 342 | refmv_count, mv_ref_list, bw, bh, xd, Done); \ |
| 343 | } \ |
| 344 | } while (0) |
| 345 | |
| 346 | // Checks that the given mi_row, mi_col and search point |
| 347 | // are inside the borders of the tile. |
| 348 | static INLINE int is_inside(const TileInfo *const tile, int mi_col, int mi_row, |
| 349 | const POSITION *mi_pos) { |
| 350 | return !(mi_row + mi_pos->row < tile->mi_row_start || |
| 351 | mi_col + mi_pos->col < tile->mi_col_start || |
| 352 | mi_row + mi_pos->row >= tile->mi_row_end || |
| 353 | mi_col + mi_pos->col >= tile->mi_col_end); |
| 354 | } |
| 355 | |
| 356 | static INLINE void lower_mv_precision(MV *mv, int allow_hp) { |
Alex Converse | 6317c88 | 2016-09-29 14:21:37 -0700 | [diff] [blame] | 357 | if (!allow_hp) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 358 | if (mv->row & 1) mv->row += (mv->row > 0 ? -1 : 1); |
| 359 | if (mv->col & 1) mv->col += (mv->col > 0 ? -1 : 1); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | #if CONFIG_REF_MV |
Jingning Han | 3f33883 | 2016-11-18 11:01:48 -0800 | [diff] [blame] | 364 | static INLINE uint8_t av1_get_pred_diff_ctx(const int_mv pred_mv, |
| 365 | const int_mv this_mv) { |
| 366 | if (abs(this_mv.as_mv.row - pred_mv.as_mv.row) <= 4 && |
| 367 | abs(this_mv.as_mv.col - pred_mv.as_mv.col) <= 4) |
| 368 | return 2; |
| 369 | else |
| 370 | return 1; |
| 371 | } |
| 372 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 373 | static INLINE int av1_nmv_ctx(const uint8_t ref_mv_count, |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 374 | const CANDIDATE_MV *ref_mv_stack, int ref, |
| 375 | int ref_mv_idx) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 376 | #if CONFIG_EXT_INTER |
| 377 | return 0; |
| 378 | #endif |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 379 | |
Jingning Han | 3f33883 | 2016-11-18 11:01:48 -0800 | [diff] [blame] | 380 | if (ref_mv_stack[ref_mv_idx].weight >= REF_CAT_LEVEL && ref_mv_count > 0) |
| 381 | return ref_mv_stack[ref_mv_idx].pred_diff[ref]; |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 382 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 383 | return 0; |
| 384 | } |
| 385 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 386 | static INLINE int8_t av1_ref_frame_type(const MV_REFERENCE_FRAME *const rf) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 387 | if (rf[1] > INTRA_FRAME) { |
| 388 | return TOTAL_REFS_PER_FRAME + FWD_RF_OFFSET(rf[0]) + |
| 389 | BWD_RF_OFFSET(rf[1]) * FWD_REFS; |
| 390 | } |
| 391 | |
| 392 | return rf[0]; |
| 393 | } |
| 394 | |
| 395 | static MV_REFERENCE_FRAME ref_frame_map[COMP_REFS][2] = { |
| 396 | #if CONFIG_EXT_REFS |
| 397 | { LAST_FRAME, BWDREF_FRAME }, { LAST2_FRAME, BWDREF_FRAME }, |
| 398 | { LAST3_FRAME, BWDREF_FRAME }, { GOLDEN_FRAME, BWDREF_FRAME }, |
| 399 | |
| 400 | { LAST_FRAME, ALTREF_FRAME }, { LAST2_FRAME, ALTREF_FRAME }, |
| 401 | { LAST3_FRAME, ALTREF_FRAME }, { GOLDEN_FRAME, ALTREF_FRAME } |
| 402 | #else |
| 403 | { LAST_FRAME, ALTREF_FRAME }, { GOLDEN_FRAME, ALTREF_FRAME } |
| 404 | #endif |
| 405 | }; |
| 406 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 407 | static INLINE void av1_set_ref_frame(MV_REFERENCE_FRAME *rf, |
| 408 | int8_t ref_frame_type) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 409 | if (ref_frame_type >= TOTAL_REFS_PER_FRAME) { |
| 410 | rf[0] = ref_frame_map[ref_frame_type - TOTAL_REFS_PER_FRAME][0]; |
| 411 | rf[1] = ref_frame_map[ref_frame_type - TOTAL_REFS_PER_FRAME][1]; |
| 412 | } else { |
| 413 | rf[0] = ref_frame_type; |
| 414 | rf[1] = NONE; |
| 415 | assert(ref_frame_type > INTRA_FRAME && |
| 416 | ref_frame_type < TOTAL_REFS_PER_FRAME); |
| 417 | } |
| 418 | } |
| 419 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 420 | static INLINE int16_t av1_mode_context_analyzer( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 421 | const int16_t *const mode_context, const MV_REFERENCE_FRAME *const rf, |
| 422 | BLOCK_SIZE bsize, int block) { |
| 423 | int16_t mode_ctx = 0; |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 424 | int8_t ref_frame_type = av1_ref_frame_type(rf); |
| 425 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 426 | if (block >= 0) { |
| 427 | mode_ctx = mode_context[rf[0]] & 0x00ff; |
Jingning Han | 8570b35 | 2016-12-14 11:05:10 -0800 | [diff] [blame] | 428 | #if !CONFIG_CB4X4 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 429 | if (block > 0 && bsize < BLOCK_8X8 && bsize > BLOCK_4X4) |
| 430 | mode_ctx |= (1 << SKIP_NEARESTMV_SUB8X8_OFFSET); |
Jingning Han | 8570b35 | 2016-12-14 11:05:10 -0800 | [diff] [blame] | 431 | #else |
| 432 | (void)block; |
| 433 | (void)bsize; |
| 434 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 435 | |
| 436 | return mode_ctx; |
| 437 | } |
| 438 | |
Jingning Han | 731af49 | 2016-11-17 11:53:23 -0800 | [diff] [blame] | 439 | return mode_context[ref_frame_type]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 440 | } |
| 441 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 442 | static INLINE uint8_t av1_drl_ctx(const CANDIDATE_MV *ref_mv_stack, |
| 443 | int ref_idx) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 444 | if (ref_mv_stack[ref_idx].weight >= REF_CAT_LEVEL && |
Jingning Han | 8205b78 | 2016-10-05 09:08:44 -0700 | [diff] [blame] | 445 | ref_mv_stack[ref_idx + 1].weight >= REF_CAT_LEVEL) |
| 446 | return 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 447 | |
| 448 | if (ref_mv_stack[ref_idx].weight >= REF_CAT_LEVEL && |
| 449 | ref_mv_stack[ref_idx + 1].weight < REF_CAT_LEVEL) |
| 450 | return 2; |
| 451 | |
| 452 | if (ref_mv_stack[ref_idx].weight < REF_CAT_LEVEL && |
Jingning Han | 8205b78 | 2016-10-05 09:08:44 -0700 | [diff] [blame] | 453 | ref_mv_stack[ref_idx + 1].weight < REF_CAT_LEVEL) |
| 454 | return 3; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 455 | |
| 456 | return 0; |
| 457 | } |
| 458 | #endif |
| 459 | |
| 460 | typedef void (*find_mv_refs_sync)(void *const data, int mi_row); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 461 | void av1_find_mv_refs(const AV1_COMMON *cm, const MACROBLOCKD *xd, |
| 462 | MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 463 | #if CONFIG_REF_MV |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 464 | uint8_t *ref_mv_count, CANDIDATE_MV *ref_mv_stack, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 465 | #if CONFIG_EXT_INTER |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 466 | int16_t *compound_mode_context, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 467 | #endif // CONFIG_EXT_INTER |
| 468 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 469 | int_mv *mv_ref_list, int mi_row, int mi_col, |
| 470 | find_mv_refs_sync sync, void *const data, |
| 471 | int16_t *mode_context); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 472 | |
| 473 | // check a list of motion vectors by sad score using a number rows of pixels |
| 474 | // above and a number cols of pixels in the left to select the one with best |
| 475 | // score to use as ref motion vector |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 476 | void av1_find_best_ref_mvs(int allow_hp, int_mv *mvlist, int_mv *nearest_mv, |
| 477 | int_mv *near_mv); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 478 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 479 | void av1_append_sub8x8_mvs_for_idx(const AV1_COMMON *cm, MACROBLOCKD *xd, |
| 480 | int block, int ref, int mi_row, int mi_col, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 481 | #if CONFIG_REF_MV |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 482 | CANDIDATE_MV *ref_mv_stack, |
| 483 | uint8_t *ref_mv_count, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 484 | #endif |
| 485 | #if CONFIG_EXT_INTER |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 486 | int_mv *mv_list, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 487 | #endif // CONFIG_EXT_INTER |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 488 | int_mv *nearest_mv, int_mv *near_mv); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 489 | |
| 490 | #if CONFIG_EXT_INTER |
| 491 | // This function keeps a mode count for a given MB/SB |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 492 | void av1_update_mv_context(const MACROBLOCKD *xd, MODE_INFO *mi, |
| 493 | MV_REFERENCE_FRAME ref_frame, int_mv *mv_ref_list, |
| 494 | int block, int mi_row, int mi_col, |
| 495 | int16_t *mode_context); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 496 | #endif // CONFIG_EXT_INTER |
| 497 | |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 498 | #if CONFIG_WARPED_MOTION |
| 499 | int findSamples(const AV1_COMMON *cm, MACROBLOCKD *xd, int mi_row, int mi_col, |
| 500 | double *pts, double *pts_inref); |
| 501 | #endif // CONFIG_WARPED_MOTION |
| 502 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 503 | #ifdef __cplusplus |
| 504 | } // extern "C" |
| 505 | #endif |
| 506 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 507 | #endif // AV1_COMMON_MVREF_COMMON_H_ |