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 "av1/common/mvref_common.h" |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 13 | #include "av1/common/warped_motion.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | |
Sarah Parker | 0a5cc5f | 2017-10-03 17:53:53 -0700 | [diff] [blame] | 15 | #define USE_CUR_GM_REFMV 1 |
Sarah Parker | 0a5cc5f | 2017-10-03 17:53:53 -0700 | [diff] [blame] | 16 | |
Frank Bossen | 7b6bb94 | 2018-01-25 07:49:52 -0500 | [diff] [blame] | 17 | #if CONFIG_MFMV |
| 18 | // Although we assign 32 bit integers, all the values are strictly under 14 |
| 19 | // bits. |
| 20 | static int div_mult[64] = { |
| 21 | 0, 16384, 8192, 5461, 4096, 3276, 2730, 2340, 2048, 1820, 1638, 1489, 1365, |
| 22 | 1260, 1170, 1092, 1024, 963, 910, 862, 819, 780, 744, 712, 682, 655, |
| 23 | 630, 606, 585, 564, 546, 528, 512, 496, 481, 468, 455, 442, 431, |
| 24 | 420, 409, 399, 390, 381, 372, 364, 356, 348, 341, 334, 327, 321, |
| 25 | 315, 309, 303, 297, 292, 287, 282, 277, 273, 268, 264, 260, |
| 26 | }; |
| 27 | |
| 28 | // TODO(jingning): Consider the use of lookup table for (num / den) |
| 29 | // altogether. |
| 30 | static void get_mv_projection(MV *output, MV ref, int num, int den) { |
| 31 | output->row = |
| 32 | (int16_t)(ROUND_POWER_OF_TWO_SIGNED(ref.row * num * div_mult[den], 14)); |
| 33 | output->col = |
| 34 | (int16_t)(ROUND_POWER_OF_TWO_SIGNED(ref.col * num * div_mult[den], 14)); |
| 35 | } |
| 36 | #endif // CONFIG_MFMV |
| 37 | |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 38 | void av1_copy_frame_mvs(const AV1_COMMON *const cm, MODE_INFO *mi, int mi_row, |
| 39 | int mi_col, int x_mis, int y_mis) { |
Jingning Han | c7d198e | 2017-10-12 16:11:06 -0700 | [diff] [blame] | 40 | #if CONFIG_TMV || CONFIG_MFMV |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 41 | const int frame_mvs_stride = ROUND_POWER_OF_TWO(cm->mi_cols, 1); |
Jingning Han | 17dc4c7 | 2017-10-10 09:37:43 -0700 | [diff] [blame] | 42 | MV_REF *frame_mvs = |
| 43 | 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] | 44 | x_mis = ROUND_POWER_OF_TWO(x_mis, 1); |
| 45 | y_mis = ROUND_POWER_OF_TWO(y_mis, 1); |
| 46 | #else |
| 47 | const int frame_mvs_stride = cm->mi_cols; |
| 48 | MV_REF *frame_mvs = cm->cur_frame->mvs + |
| 49 | (mi_row & 0xfffe) * frame_mvs_stride + (mi_col & 0xfffe); |
| 50 | x_mis = AOMMAX(x_mis, 2); |
| 51 | y_mis = AOMMAX(y_mis, 2); |
| 52 | #endif // CONFIG_TMV |
| 53 | int w, h; |
| 54 | |
| 55 | for (h = 0; h < y_mis; h++) { |
Yunqing Wang | b90a97a | 2017-10-24 11:50:15 -0700 | [diff] [blame] | 56 | MV_REF *mv = frame_mvs; |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 57 | for (w = 0; w < x_mis; w++) { |
Jingning Han | 707f832 | 2017-12-02 09:25:01 -0800 | [diff] [blame] | 58 | #if CONFIG_MFMV |
| 59 | mv->ref_frame[0] = NONE_FRAME; |
| 60 | mv->ref_frame[1] = NONE_FRAME; |
| 61 | mv->mv[0].as_int = 0; |
| 62 | mv->mv[1].as_int = 0; |
| 63 | |
| 64 | for (int idx = 0; idx < 2; ++idx) { |
| 65 | MV_REFERENCE_FRAME ref_frame = mi->mbmi.ref_frame[idx]; |
| 66 | if (ref_frame > INTRA_FRAME) { |
| 67 | int8_t ref_idx = cm->ref_frame_side[ref_frame]; |
| 68 | if (ref_idx < 0) continue; |
Jingning Han | 05102b5 | 2017-12-22 08:59:11 -0800 | [diff] [blame] | 69 | if ((abs(mi->mbmi.mv[idx].as_mv.row) > REFMVS_LIMIT) || |
| 70 | (abs(mi->mbmi.mv[idx].as_mv.col) > REFMVS_LIMIT)) |
| 71 | continue; |
Jingning Han | 707f832 | 2017-12-02 09:25:01 -0800 | [diff] [blame] | 72 | mv->ref_frame[ref_idx] = ref_frame; |
| 73 | mv->mv[ref_idx].as_int = mi->mbmi.mv[idx].as_int; |
| 74 | } |
| 75 | } |
| 76 | #else |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 77 | mv->ref_frame[0] = mi->mbmi.ref_frame[0]; |
| 78 | mv->ref_frame[1] = mi->mbmi.ref_frame[1]; |
| 79 | mv->mv[0].as_int = mi->mbmi.mv[0].as_int; |
| 80 | mv->mv[1].as_int = mi->mbmi.mv[1].as_int; |
Jingning Han | 707f832 | 2017-12-02 09:25:01 -0800 | [diff] [blame] | 81 | #endif |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 82 | // (TODO:yunqing) The following 2 lines won't be used and can be removed. |
| 83 | mv->pred_mv[0].as_int = mi->mbmi.pred_mv[0].as_int; |
| 84 | mv->pred_mv[1].as_int = mi->mbmi.pred_mv[1].as_int; |
Yunqing Wang | b90a97a | 2017-10-24 11:50:15 -0700 | [diff] [blame] | 85 | mv++; |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 86 | } |
Yunqing Wang | b90a97a | 2017-10-24 11:50:15 -0700 | [diff] [blame] | 87 | frame_mvs += frame_mvs_stride; |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | |
Sarah Parker | 0a5cc5f | 2017-10-03 17:53:53 -0700 | [diff] [blame] | 91 | static uint8_t add_ref_mv_candidate( |
| 92 | const MODE_INFO *const candidate_mi, const MB_MODE_INFO *const candidate, |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 93 | const MV_REFERENCE_FRAME rf[2], uint8_t refmv_counts[MODE_CTX_REF_FRAMES], |
| 94 | uint8_t ref_match_counts[MODE_CTX_REF_FRAMES], |
| 95 | CANDIDATE_MV ref_mv_stacks[][MAX_REF_MV_STACK_SIZE], const int use_hp, |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 96 | int len, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 97 | #if USE_CUR_GM_REFMV |
Sarah Parker | 0a5cc5f | 2017-10-03 17:53:53 -0700 | [diff] [blame] | 98 | int_mv *gm_mv_candidates, const WarpedMotionParams *gm_params, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 99 | #endif // USE_CUR_GM_REFMV |
Yunqing Wang | 62fe78e | 2017-12-22 16:03:43 -0800 | [diff] [blame] | 100 | int col, int weight |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 101 | #if CONFIG_AMVR |
Yunqing Wang | 62fe78e | 2017-12-22 16:03:43 -0800 | [diff] [blame] | 102 | , |
| 103 | int is_integer |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 104 | #endif |
Johann | 6b41d4d | 2018-02-08 14:32:53 -0800 | [diff] [blame] | 105 | ) { |
Hui Su | 1e68d5d | 2017-11-02 12:31:52 -0700 | [diff] [blame] | 106 | #if CONFIG_INTRABC |
| 107 | if (!is_inter_block(candidate)) return 0; |
| 108 | #endif // CONFIG_INTRABC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 109 | int index = 0, ref; |
| 110 | int newmv_count = 0; |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 111 | assert(weight % 2 == 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 112 | |
Emil Keyder | 01770b3 | 2017-01-20 18:03:11 -0500 | [diff] [blame] | 113 | if (rf[1] == NONE_FRAME) { |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 114 | uint8_t *refmv_count = &refmv_counts[rf[0]]; |
| 115 | uint8_t *ref_match_count = &ref_match_counts[rf[0]]; |
| 116 | CANDIDATE_MV *ref_mv_stack = ref_mv_stacks[rf[0]]; |
| 117 | (void)ref_match_count; |
| 118 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 119 | // single reference frame |
| 120 | for (ref = 0; ref < 2; ++ref) { |
| 121 | if (candidate->ref_frame[ref] == rf[0]) { |
Sarah Parker | 0a5cc5f | 2017-10-03 17:53:53 -0700 | [diff] [blame] | 122 | int_mv this_refmv; |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 123 | #if USE_CUR_GM_REFMV |
Yunqing Wang | 62fe78e | 2017-12-22 16:03:43 -0800 | [diff] [blame] | 124 | if (is_global_mv_block(candidate_mi, gm_params[rf[0]].wmtype)) |
| 125 | this_refmv = gm_mv_candidates[0]; |
| 126 | else |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 127 | #endif // USE_CUR_GM_REFMV |
Yunqing Wang | 62fe78e | 2017-12-22 16:03:43 -0800 | [diff] [blame] | 128 | this_refmv = get_sub_block_mv(candidate_mi, ref, col); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 129 | #if CONFIG_AMVR |
Yunqing Wang | 62fe78e | 2017-12-22 16:03:43 -0800 | [diff] [blame] | 130 | lower_mv_precision(&this_refmv.as_mv, use_hp, is_integer); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 131 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 132 | lower_mv_precision(&this_refmv.as_mv, use_hp); |
Sarah Parker | 0a5cc5f | 2017-10-03 17:53:53 -0700 | [diff] [blame] | 133 | #endif // CONFIG_AMVR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 134 | |
| 135 | for (index = 0; index < *refmv_count; ++index) |
| 136 | if (ref_mv_stack[index].this_mv.as_int == this_refmv.as_int) break; |
| 137 | |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 138 | if (index < *refmv_count) ref_mv_stack[index].weight += weight * len; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 139 | |
| 140 | // Add a new item to the list. |
Jonathan Matthews | ca9132d | 2017-10-31 10:32:38 +0000 | [diff] [blame] | 141 | if (index == *refmv_count && *refmv_count < MAX_REF_MV_STACK_SIZE) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 142 | ref_mv_stack[index].this_mv = this_refmv; |
Jingning Han | 3f33883 | 2016-11-18 11:01:48 -0800 | [diff] [blame] | 143 | ref_mv_stack[index].pred_diff[0] = av1_get_pred_diff_ctx( |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 144 | get_sub_block_pred_mv(candidate_mi, ref, col), this_refmv); |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 145 | ref_mv_stack[index].weight = weight * len; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 146 | ++(*refmv_count); |
| 147 | |
Jingning Han | 835a49e | 2017-12-01 15:55:34 -0800 | [diff] [blame] | 148 | #if !CONFIG_OPT_REF_MV |
Zoe Liu | 7f24e1b | 2017-03-17 17:42:05 -0700 | [diff] [blame] | 149 | if (candidate->mode == NEWMV) ++newmv_count; |
Jingning Han | 835a49e | 2017-12-01 15:55:34 -0800 | [diff] [blame] | 150 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 151 | } |
Jingning Han | 835a49e | 2017-12-01 15:55:34 -0800 | [diff] [blame] | 152 | #if CONFIG_OPT_REF_MV |
Jingning Han | 2d17ec6 | 2018-02-08 20:59:49 -0800 | [diff] [blame] | 153 | if (have_newmv_in_inter_mode(candidate->mode)) ++newmv_count; |
Jingning Han | 835a49e | 2017-12-01 15:55:34 -0800 | [diff] [blame] | 154 | ++*ref_match_count; |
| 155 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 156 | } |
| 157 | } |
| 158 | } else { |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 159 | MV_REFERENCE_FRAME ref_frame = av1_ref_frame_type(rf); |
| 160 | uint8_t *refmv_count = &refmv_counts[ref_frame]; |
| 161 | uint8_t *ref_match_count = &ref_match_counts[ref_frame]; |
| 162 | CANDIDATE_MV *ref_mv_stack = ref_mv_stacks[ref_frame]; |
| 163 | (void)ref_match_count; |
| 164 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 165 | // compound reference frame |
| 166 | if (candidate->ref_frame[0] == rf[0] && candidate->ref_frame[1] == rf[1]) { |
| 167 | int_mv this_refmv[2]; |
| 168 | |
| 169 | for (ref = 0; ref < 2; ++ref) { |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 170 | #if USE_CUR_GM_REFMV |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 171 | if (is_global_mv_block(candidate_mi, gm_params[rf[ref]].wmtype)) |
Sarah Parker | 0a5cc5f | 2017-10-03 17:53:53 -0700 | [diff] [blame] | 172 | this_refmv[ref] = gm_mv_candidates[ref]; |
| 173 | else |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 174 | #endif // USE_CUR_GM_REFMV |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 175 | this_refmv[ref] = get_sub_block_mv(candidate_mi, ref, col); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 176 | #if CONFIG_AMVR |
| 177 | lower_mv_precision(&this_refmv[ref].as_mv, use_hp, is_integer); |
| 178 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 179 | lower_mv_precision(&this_refmv[ref].as_mv, use_hp); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 180 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | for (index = 0; index < *refmv_count; ++index) |
| 184 | if ((ref_mv_stack[index].this_mv.as_int == this_refmv[0].as_int) && |
| 185 | (ref_mv_stack[index].comp_mv.as_int == this_refmv[1].as_int)) |
| 186 | break; |
| 187 | |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 188 | if (index < *refmv_count) ref_mv_stack[index].weight += weight * len; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 189 | |
| 190 | // Add a new item to the list. |
Jonathan Matthews | ca9132d | 2017-10-31 10:32:38 +0000 | [diff] [blame] | 191 | if (index == *refmv_count && *refmv_count < MAX_REF_MV_STACK_SIZE) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 192 | ref_mv_stack[index].this_mv = this_refmv[0]; |
| 193 | ref_mv_stack[index].comp_mv = this_refmv[1]; |
Jingning Han | 3f33883 | 2016-11-18 11:01:48 -0800 | [diff] [blame] | 194 | ref_mv_stack[index].pred_diff[0] = av1_get_pred_diff_ctx( |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 195 | get_sub_block_pred_mv(candidate_mi, 0, col), this_refmv[0]); |
Jingning Han | 3f33883 | 2016-11-18 11:01:48 -0800 | [diff] [blame] | 196 | ref_mv_stack[index].pred_diff[1] = av1_get_pred_diff_ctx( |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 197 | get_sub_block_pred_mv(candidate_mi, 1, col), this_refmv[1]); |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 198 | ref_mv_stack[index].weight = weight * len; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 199 | ++(*refmv_count); |
| 200 | |
Jingning Han | 835a49e | 2017-12-01 15:55:34 -0800 | [diff] [blame] | 201 | #if !CONFIG_OPT_REF_MV |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 202 | if (candidate->mode == NEW_NEWMV) ++newmv_count; |
Jingning Han | 835a49e | 2017-12-01 15:55:34 -0800 | [diff] [blame] | 203 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 204 | } |
Jingning Han | 835a49e | 2017-12-01 15:55:34 -0800 | [diff] [blame] | 205 | #if CONFIG_OPT_REF_MV |
Jingning Han | 2d17ec6 | 2018-02-08 20:59:49 -0800 | [diff] [blame] | 206 | if (have_newmv_in_inter_mode(candidate->mode)) ++newmv_count; |
Jingning Han | 835a49e | 2017-12-01 15:55:34 -0800 | [diff] [blame] | 207 | ++*ref_match_count; |
| 208 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | return newmv_count; |
| 212 | } |
| 213 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 214 | static uint8_t scan_row_mbmi(const AV1_COMMON *cm, const MACROBLOCKD *xd, |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 215 | int mi_row, int mi_col, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 216 | const MV_REFERENCE_FRAME rf[2], int row_offset, |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 217 | CANDIDATE_MV ref_mv_stack[][MAX_REF_MV_STACK_SIZE], |
| 218 | uint8_t refmv_count[MODE_CTX_REF_FRAMES], |
| 219 | uint8_t ref_match_count[MODE_CTX_REF_FRAMES], |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 220 | #if USE_CUR_GM_REFMV |
Sarah Parker | 0a5cc5f | 2017-10-03 17:53:53 -0700 | [diff] [blame] | 221 | int_mv *gm_mv_candidates, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 222 | #endif // USE_CUR_GM_REFMV |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 223 | int max_row_offset, int *processed_rows) { |
Jingning Han | 5e19c9d | 2018-02-09 12:16:56 -0800 | [diff] [blame] | 224 | int end_mi = AOMMIN(xd->n8_w, cm->mi_cols - mi_col); |
| 225 | end_mi = AOMMIN(end_mi, mi_size_wide[BLOCK_64X64]); |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 226 | const int n8_w_8 = mi_size_wide[BLOCK_8X8]; |
| 227 | const int n8_w_16 = mi_size_wide[BLOCK_16X16]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 228 | int i; |
| 229 | uint8_t newmv_count = 0; |
Jingning Han | 7f99477 | 2017-07-27 08:02:16 -0700 | [diff] [blame] | 230 | int col_offset = 0; |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 231 | const int shift = 0; |
Jingning Han | c016df8 | 2016-12-09 12:37:28 -0800 | [diff] [blame] | 232 | // TODO(jingning): Revisit this part after cb4x4 is stable. |
Jingning Han | 74978fc | 2017-07-27 15:27:55 -0700 | [diff] [blame] | 233 | if (abs(row_offset) > 1) { |
Jingning Han | 74978fc | 2017-07-27 15:27:55 -0700 | [diff] [blame] | 234 | col_offset = 1; |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 235 | if (mi_col & 0x01 && xd->n8_w < n8_w_8) --col_offset; |
Jingning Han | 7f99477 | 2017-07-27 08:02:16 -0700 | [diff] [blame] | 236 | } |
Yunqing Wang | d797ea9 | 2017-08-27 18:05:55 -0700 | [diff] [blame] | 237 | const int use_step_16 = (xd->n8_w >= 16); |
Yunqing Wang | d797ea9 | 2017-08-27 18:05:55 -0700 | [diff] [blame] | 238 | MODE_INFO **const candidate_mi0 = xd->mi + row_offset * xd->mi_stride; |
Yunqing Wang | 62fe78e | 2017-12-22 16:03:43 -0800 | [diff] [blame] | 239 | (void)mi_row; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 240 | |
Jonathan Matthews | ca9132d | 2017-10-31 10:32:38 +0000 | [diff] [blame] | 241 | for (i = 0; i < end_mi;) { |
Yunqing Wang | d797ea9 | 2017-08-27 18:05:55 -0700 | [diff] [blame] | 242 | const MODE_INFO *const candidate_mi = candidate_mi0[col_offset + i]; |
| 243 | const MB_MODE_INFO *const candidate = &candidate_mi->mbmi; |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 244 | const int candidate_bsize = candidate->sb_type; |
| 245 | const int n8_w = mi_size_wide[candidate_bsize]; |
| 246 | int len = AOMMIN(xd->n8_w, n8_w); |
Yunqing Wang | d797ea9 | 2017-08-27 18:05:55 -0700 | [diff] [blame] | 247 | if (use_step_16) |
| 248 | len = AOMMAX(n8_w_16, len); |
| 249 | else if (abs(row_offset) > 1) |
| 250 | len = AOMMAX(len, n8_w_8); |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 251 | |
| 252 | int weight = 2; |
| 253 | if (xd->n8_w >= n8_w_8 && xd->n8_w <= n8_w) { |
| 254 | int inc = AOMMIN(-max_row_offset + row_offset + 1, |
| 255 | mi_size_high[candidate_bsize]); |
| 256 | // Obtain range used in weight calculation. |
| 257 | weight = AOMMAX(weight, (inc << shift)); |
| 258 | // Update processed rows. |
| 259 | *processed_rows = inc - row_offset - 1; |
| 260 | } |
| 261 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 262 | #if CONFIG_AMVR |
| 263 | newmv_count += add_ref_mv_candidate( |
Jingning Han | 835a49e | 2017-12-01 15:55:34 -0800 | [diff] [blame] | 264 | candidate_mi, candidate, rf, refmv_count, ref_match_count, ref_mv_stack, |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 265 | cm->allow_high_precision_mv, len, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 266 | #if USE_CUR_GM_REFMV |
Sarah Parker | 0a5cc5f | 2017-10-03 17:53:53 -0700 | [diff] [blame] | 267 | gm_mv_candidates, cm->global_motion, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 268 | #endif // USE_CUR_GM_REFMV |
Yunqing Wang | 62fe78e | 2017-12-22 16:03:43 -0800 | [diff] [blame] | 269 | col_offset + i, weight, cm->cur_frame_force_integer_mv); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 270 | #else |
Yunqing Wang | 97d6a37 | 2017-10-09 14:15:15 -0700 | [diff] [blame] | 271 | newmv_count += add_ref_mv_candidate( |
Jingning Han | 835a49e | 2017-12-01 15:55:34 -0800 | [diff] [blame] | 272 | candidate_mi, candidate, rf, refmv_count, ref_match_count, ref_mv_stack, |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 273 | cm->allow_high_precision_mv, len, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 274 | #if USE_CUR_GM_REFMV |
Yunqing Wang | 97d6a37 | 2017-10-09 14:15:15 -0700 | [diff] [blame] | 275 | gm_mv_candidates, cm->global_motion, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 276 | #endif // USE_CUR_GM_REFMV |
Yunqing Wang | 62fe78e | 2017-12-22 16:03:43 -0800 | [diff] [blame] | 277 | col_offset + i, weight); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 278 | #endif |
Sarah Parker | 0a5cc5f | 2017-10-03 17:53:53 -0700 | [diff] [blame] | 279 | |
Yunqing Wang | d797ea9 | 2017-08-27 18:05:55 -0700 | [diff] [blame] | 280 | i += len; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | return newmv_count; |
| 284 | } |
| 285 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 286 | static uint8_t scan_col_mbmi(const AV1_COMMON *cm, const MACROBLOCKD *xd, |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 287 | int mi_row, int mi_col, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 288 | const MV_REFERENCE_FRAME rf[2], int col_offset, |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 289 | CANDIDATE_MV ref_mv_stack[][MAX_REF_MV_STACK_SIZE], |
| 290 | uint8_t refmv_count[MODE_CTX_REF_FRAMES], |
| 291 | uint8_t ref_match_count[MODE_CTX_REF_FRAMES], |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 292 | #if USE_CUR_GM_REFMV |
Sarah Parker | 0a5cc5f | 2017-10-03 17:53:53 -0700 | [diff] [blame] | 293 | int_mv *gm_mv_candidates, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 294 | #endif // USE_CUR_GM_REFMV |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 295 | int max_col_offset, int *processed_cols) { |
Jingning Han | 5e19c9d | 2018-02-09 12:16:56 -0800 | [diff] [blame] | 296 | int end_mi = AOMMIN(xd->n8_h, cm->mi_rows - mi_row); |
| 297 | end_mi = AOMMIN(end_mi, mi_size_high[BLOCK_64X64]); |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 298 | const int n8_h_8 = mi_size_high[BLOCK_8X8]; |
| 299 | const int n8_h_16 = mi_size_high[BLOCK_16X16]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 300 | int i; |
| 301 | uint8_t newmv_count = 0; |
Jingning Han | 7f99477 | 2017-07-27 08:02:16 -0700 | [diff] [blame] | 302 | int row_offset = 0; |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 303 | const int shift = 0; |
Jingning Han | 74978fc | 2017-07-27 15:27:55 -0700 | [diff] [blame] | 304 | if (abs(col_offset) > 1) { |
Jingning Han | 74978fc | 2017-07-27 15:27:55 -0700 | [diff] [blame] | 305 | row_offset = 1; |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 306 | if (mi_row & 0x01 && xd->n8_h < n8_h_8) --row_offset; |
Jingning Han | 7f99477 | 2017-07-27 08:02:16 -0700 | [diff] [blame] | 307 | } |
Yunqing Wang | d797ea9 | 2017-08-27 18:05:55 -0700 | [diff] [blame] | 308 | const int use_step_16 = (xd->n8_h >= 16); |
Yunqing Wang | 62fe78e | 2017-12-22 16:03:43 -0800 | [diff] [blame] | 309 | (void)mi_col; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 310 | |
Jonathan Matthews | ca9132d | 2017-10-31 10:32:38 +0000 | [diff] [blame] | 311 | for (i = 0; i < end_mi;) { |
Yunqing Wang | d797ea9 | 2017-08-27 18:05:55 -0700 | [diff] [blame] | 312 | const MODE_INFO *const candidate_mi = |
| 313 | xd->mi[(row_offset + i) * xd->mi_stride + col_offset]; |
| 314 | const MB_MODE_INFO *const candidate = &candidate_mi->mbmi; |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 315 | const int candidate_bsize = candidate->sb_type; |
| 316 | const int n8_h = mi_size_high[candidate_bsize]; |
| 317 | int len = AOMMIN(xd->n8_h, n8_h); |
Yunqing Wang | d797ea9 | 2017-08-27 18:05:55 -0700 | [diff] [blame] | 318 | if (use_step_16) |
| 319 | len = AOMMAX(n8_h_16, len); |
| 320 | else if (abs(col_offset) > 1) |
| 321 | len = AOMMAX(len, n8_h_8); |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 322 | |
| 323 | int weight = 2; |
| 324 | if (xd->n8_h >= n8_h_8 && xd->n8_h <= n8_h) { |
| 325 | int inc = AOMMIN(-max_col_offset + col_offset + 1, |
| 326 | mi_size_wide[candidate_bsize]); |
| 327 | // Obtain range used in weight calculation. |
| 328 | weight = AOMMAX(weight, (inc << shift)); |
| 329 | // Update processed cols. |
| 330 | *processed_cols = inc - col_offset - 1; |
| 331 | } |
| 332 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 333 | #if CONFIG_AMVR |
| 334 | newmv_count += add_ref_mv_candidate( |
Jingning Han | 835a49e | 2017-12-01 15:55:34 -0800 | [diff] [blame] | 335 | candidate_mi, candidate, rf, refmv_count, ref_match_count, ref_mv_stack, |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 336 | cm->allow_high_precision_mv, len, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 337 | #if USE_CUR_GM_REFMV |
Sarah Parker | 0a5cc5f | 2017-10-03 17:53:53 -0700 | [diff] [blame] | 338 | gm_mv_candidates, cm->global_motion, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 339 | #endif // USE_CUR_GM_REFMV |
Yunqing Wang | 62fe78e | 2017-12-22 16:03:43 -0800 | [diff] [blame] | 340 | col_offset, weight, cm->cur_frame_force_integer_mv); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 341 | #else |
Yunqing Wang | 97d6a37 | 2017-10-09 14:15:15 -0700 | [diff] [blame] | 342 | newmv_count += add_ref_mv_candidate( |
Jingning Han | 835a49e | 2017-12-01 15:55:34 -0800 | [diff] [blame] | 343 | candidate_mi, candidate, rf, refmv_count, ref_match_count, ref_mv_stack, |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 344 | cm->allow_high_precision_mv, len, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 345 | #if USE_CUR_GM_REFMV |
Yunqing Wang | 97d6a37 | 2017-10-09 14:15:15 -0700 | [diff] [blame] | 346 | gm_mv_candidates, cm->global_motion, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 347 | #endif // USE_CUR_GM_REFMV |
Yunqing Wang | 62fe78e | 2017-12-22 16:03:43 -0800 | [diff] [blame] | 348 | col_offset, weight); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 349 | #endif |
Yunqing Wang | d797ea9 | 2017-08-27 18:05:55 -0700 | [diff] [blame] | 350 | i += len; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | return newmv_count; |
| 354 | } |
| 355 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 356 | static uint8_t scan_blk_mbmi(const AV1_COMMON *cm, const MACROBLOCKD *xd, |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 357 | const int mi_row, const int mi_col, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 358 | const MV_REFERENCE_FRAME rf[2], int row_offset, |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 359 | int col_offset, |
| 360 | CANDIDATE_MV ref_mv_stack[][MAX_REF_MV_STACK_SIZE], |
| 361 | uint8_t ref_match_count[MODE_CTX_REF_FRAMES], |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 362 | #if USE_CUR_GM_REFMV |
Sarah Parker | 0a5cc5f | 2017-10-03 17:53:53 -0700 | [diff] [blame] | 363 | int_mv *gm_mv_candidates, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 364 | #endif // USE_CUR_GM_REFMV |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 365 | uint8_t refmv_count[MODE_CTX_REF_FRAMES]) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 366 | const TileInfo *const tile = &xd->tile; |
| 367 | POSITION mi_pos; |
| 368 | uint8_t newmv_count = 0; |
| 369 | |
| 370 | mi_pos.row = row_offset; |
| 371 | mi_pos.col = col_offset; |
| 372 | |
Jonathan Matthews | ca9132d | 2017-10-31 10:32:38 +0000 | [diff] [blame] | 373 | if (is_inside(tile, mi_col, mi_row, cm->mi_rows, cm, &mi_pos)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 374 | const MODE_INFO *const candidate_mi = |
| 375 | xd->mi[mi_pos.row * xd->mi_stride + mi_pos.col]; |
| 376 | const MB_MODE_INFO *const candidate = &candidate_mi->mbmi; |
Jingning Han | c016df8 | 2016-12-09 12:37:28 -0800 | [diff] [blame] | 377 | const int len = mi_size_wide[BLOCK_8X8]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 378 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 379 | #if CONFIG_AMVR |
| 380 | newmv_count += add_ref_mv_candidate( |
Jingning Han | 835a49e | 2017-12-01 15:55:34 -0800 | [diff] [blame] | 381 | candidate_mi, candidate, rf, refmv_count, ref_match_count, ref_mv_stack, |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 382 | cm->allow_high_precision_mv, len, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 383 | #if USE_CUR_GM_REFMV |
Sarah Parker | 0a5cc5f | 2017-10-03 17:53:53 -0700 | [diff] [blame] | 384 | gm_mv_candidates, cm->global_motion, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 385 | #endif // USE_CUR_GM_REFMV |
Yunqing Wang | 62fe78e | 2017-12-22 16:03:43 -0800 | [diff] [blame] | 386 | mi_pos.col, 2, cm->cur_frame_force_integer_mv); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 387 | #else |
Yunqing Wang | 97d6a37 | 2017-10-09 14:15:15 -0700 | [diff] [blame] | 388 | newmv_count += add_ref_mv_candidate( |
Jingning Han | 835a49e | 2017-12-01 15:55:34 -0800 | [diff] [blame] | 389 | candidate_mi, candidate, rf, refmv_count, ref_match_count, ref_mv_stack, |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 390 | cm->allow_high_precision_mv, len, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 391 | #if USE_CUR_GM_REFMV |
Yunqing Wang | 97d6a37 | 2017-10-09 14:15:15 -0700 | [diff] [blame] | 392 | gm_mv_candidates, cm->global_motion, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 393 | #endif // USE_CUR_GM_REFMV |
Yunqing Wang | 62fe78e | 2017-12-22 16:03:43 -0800 | [diff] [blame] | 394 | mi_pos.col, 2); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 395 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 396 | } // Analyze a single 8x8 block motion information. |
Yaowu Xu | 4306b6e | 2016-09-27 12:55:32 -0700 | [diff] [blame] | 397 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 398 | return newmv_count; |
| 399 | } |
| 400 | |
David Barker | 761b1ac | 2017-09-25 11:23:03 +0100 | [diff] [blame] | 401 | static int has_top_right(const AV1_COMMON *cm, const MACROBLOCKD *xd, |
| 402 | int mi_row, int mi_col, int bs) { |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 403 | const int sb_mi_size = mi_size_wide[cm->seq_params.sb_size]; |
David Barker | 761b1ac | 2017-09-25 11:23:03 +0100 | [diff] [blame] | 404 | const int mask_row = mi_row & (sb_mi_size - 1); |
| 405 | const int mask_col = mi_col & (sb_mi_size - 1); |
Jingning Han | 3eb1f07 | 2016-11-17 15:17:25 -0800 | [diff] [blame] | 406 | |
Jingning Han | 5e19c9d | 2018-02-09 12:16:56 -0800 | [diff] [blame] | 407 | if (bs > mi_size_wide[BLOCK_64X64]) return 0; |
| 408 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 409 | // In a split partition all apart from the bottom right has a top right |
Jingning Han | 3eb1f07 | 2016-11-17 15:17:25 -0800 | [diff] [blame] | 410 | int has_tr = !((mask_row & bs) && (mask_col & bs)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 411 | |
| 412 | // bs > 0 and bs is a power of 2 |
| 413 | assert(bs > 0 && !(bs & (bs - 1))); |
| 414 | |
| 415 | // For each 4x4 group of blocks, when the bottom right is decoded the blocks |
| 416 | // to the right have not been decoded therefore the bottom right does |
| 417 | // not have a top right |
David Barker | 761b1ac | 2017-09-25 11:23:03 +0100 | [diff] [blame] | 418 | while (bs < sb_mi_size) { |
Jingning Han | 3eb1f07 | 2016-11-17 15:17:25 -0800 | [diff] [blame] | 419 | if (mask_col & bs) { |
| 420 | if ((mask_col & (2 * bs)) && (mask_row & (2 * bs))) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 421 | has_tr = 0; |
| 422 | break; |
| 423 | } |
| 424 | } else { |
| 425 | break; |
| 426 | } |
| 427 | bs <<= 1; |
| 428 | } |
| 429 | |
| 430 | // The left hand of two vertical rectangles always has a top right (as the |
| 431 | // block above will have been decoded) |
| 432 | if (xd->n8_w < xd->n8_h) |
| 433 | if (!xd->is_sec_rect) has_tr = 1; |
| 434 | |
| 435 | // The bottom of two horizontal rectangles never has a top right (as the block |
| 436 | // to the right won't have been decoded) |
| 437 | if (xd->n8_w > xd->n8_h) |
| 438 | if (xd->is_sec_rect) has_tr = 0; |
| 439 | |
Frederic Barbier | 3f53da7 | 2017-12-18 15:24:46 +0100 | [diff] [blame] | 440 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 441 | // The bottom left square of a Vertical A (in the old format) does |
| 442 | // not have a top right as it is decoded before the right hand |
| 443 | // rectangle of the partition |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 444 | if (xd->mi[0]->mbmi.partition == PARTITION_VERT_A) |
Jingning Han | 3eb1f07 | 2016-11-17 15:17:25 -0800 | [diff] [blame] | 445 | if ((mask_row & bs) && !(mask_col & bs)) has_tr = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 446 | #endif // CONFIG_EXT_PARTITION_TYPES |
| 447 | |
| 448 | return has_tr; |
| 449 | } |
| 450 | |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 451 | #if CONFIG_MFMV |
Jingning Han | d41869a | 2018-02-09 10:44:30 -0800 | [diff] [blame] | 452 | static int check_sb_border(const int mi_row, const int mi_col, |
| 453 | const int row_offset, const int col_offset) { |
| 454 | const int sb_mi_size = mi_size_wide[BLOCK_64X64]; |
David Barker | 761b1ac | 2017-09-25 11:23:03 +0100 | [diff] [blame] | 455 | const int row = mi_row & (sb_mi_size - 1); |
| 456 | const int col = mi_col & (sb_mi_size - 1); |
Jingning Han | 83c27ec | 2017-09-20 08:05:17 -0700 | [diff] [blame] | 457 | |
David Barker | 761b1ac | 2017-09-25 11:23:03 +0100 | [diff] [blame] | 458 | if (row + row_offset < 0 || row + row_offset >= sb_mi_size || |
| 459 | col + col_offset < 0 || col + col_offset >= sb_mi_size) |
Jingning Han | 83c27ec | 2017-09-20 08:05:17 -0700 | [diff] [blame] | 460 | return 0; |
| 461 | |
| 462 | return 1; |
| 463 | } |
| 464 | |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 465 | static int add_tpl_ref_mv(const AV1_COMMON *cm, |
| 466 | const MV_REF *prev_frame_mvs_base, |
| 467 | const MACROBLOCKD *xd, int mi_row, int mi_col, |
| 468 | MV_REFERENCE_FRAME ref_frame, int blk_row, |
Jingning Han | a07a3b2 | 2018-02-05 14:32:28 -0800 | [diff] [blame] | 469 | int blk_col, int_mv *gm_mv_candidates, |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 470 | uint8_t refmv_count[MODE_CTX_REF_FRAMES], |
| 471 | CANDIDATE_MV ref_mv_stacks[][MAX_REF_MV_STACK_SIZE], |
Jingning Han | a07a3b2 | 2018-02-05 14:32:28 -0800 | [diff] [blame] | 472 | int16_t *mode_context) { |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 473 | (void)prev_frame_mvs_base; |
| 474 | POSITION mi_pos; |
| 475 | int idx; |
| 476 | int coll_blk_count = 0; |
| 477 | const int weight_unit = 1; // mi_size_wide[BLOCK_8X8]; |
| 478 | |
Jingning Han | a07a3b2 | 2018-02-05 14:32:28 -0800 | [diff] [blame] | 479 | (void)gm_mv_candidates; |
| 480 | |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 481 | mi_pos.row = (mi_row & 0x01) ? blk_row : blk_row + 1; |
| 482 | mi_pos.col = (mi_col & 0x01) ? blk_col : blk_col + 1; |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 483 | |
| 484 | if (!is_inside(&xd->tile, mi_col, mi_row, cm->mi_rows, cm, &mi_pos)) |
| 485 | return coll_blk_count; |
| 486 | |
Jingning Han | c7d198e | 2017-10-12 16:11:06 -0700 | [diff] [blame] | 487 | const TPL_MV_REF *prev_frame_mvs = |
Jingning Han | 6cc1fd3 | 2017-10-13 09:05:36 -0700 | [diff] [blame] | 488 | cm->tpl_mvs + ((mi_row + mi_pos.row) >> 1) * (cm->mi_stride >> 1) + |
Jingning Han | c7d198e | 2017-10-12 16:11:06 -0700 | [diff] [blame] | 489 | ((mi_col + mi_pos.col) >> 1); |
Jingning Han | 5946d36 | 2017-09-18 12:56:00 -0700 | [diff] [blame] | 490 | |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 491 | MV_REFERENCE_FRAME rf[2]; |
| 492 | av1_set_ref_frame(rf, ref_frame); |
| 493 | |
| 494 | if (rf[1] == NONE_FRAME) { |
Frank Bossen | 7b6bb94 | 2018-01-25 07:49:52 -0500 | [diff] [blame] | 495 | int cur_frame_index = cm->cur_frame->cur_frame_offset; |
| 496 | int buf_idx_0 = cm->frame_refs[FWD_RF_OFFSET(rf[0])].idx; |
Yaowu Xu | 30bf871 | 2018-01-26 07:56:45 -0800 | [diff] [blame] | 497 | int frame0_index = cm->buffer_pool->frame_bufs[buf_idx_0].cur_frame_offset; |
| 498 | int cur_offset_0 = cur_frame_index - frame0_index; |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 499 | CANDIDATE_MV *ref_mv_stack = ref_mv_stacks[rf[0]]; |
Frank Bossen | 7b6bb94 | 2018-01-25 07:49:52 -0500 | [diff] [blame] | 500 | |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 501 | for (int i = 0; i < MFMV_STACK_SIZE; ++i) { |
Frank Bossen | 7b6bb94 | 2018-01-25 07:49:52 -0500 | [diff] [blame] | 502 | if (prev_frame_mvs->mfmv0[i].as_int != INVALID_MV) { |
| 503 | int_mv this_refmv; |
| 504 | |
| 505 | get_mv_projection(&this_refmv.as_mv, prev_frame_mvs->mfmv0[i].as_mv, |
| 506 | cur_offset_0, prev_frame_mvs->ref_frame_offset[i]); |
RogerZhou | 088251e | 2017-11-14 10:52:12 -0800 | [diff] [blame] | 507 | #if CONFIG_AMVR |
| 508 | lower_mv_precision(&this_refmv.as_mv, cm->allow_high_precision_mv, |
| 509 | cm->cur_frame_force_integer_mv); |
| 510 | #else |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 511 | lower_mv_precision(&this_refmv.as_mv, cm->allow_high_precision_mv); |
RogerZhou | 088251e | 2017-11-14 10:52:12 -0800 | [diff] [blame] | 512 | #endif |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 513 | |
Jingning Han | a07a3b2 | 2018-02-05 14:32:28 -0800 | [diff] [blame] | 514 | #if CONFIG_OPT_REF_MV |
| 515 | if (blk_row == 0 && blk_col == 0) |
| 516 | if (abs(this_refmv.as_mv.row - gm_mv_candidates[0].as_mv.row) >= 16 || |
| 517 | abs(this_refmv.as_mv.col - gm_mv_candidates[0].as_mv.col) >= 16) |
| 518 | mode_context[ref_frame] |= (1 << GLOBALMV_OFFSET); |
| 519 | #else |
Jingning Han | 0e4c806 | 2017-10-03 20:27:22 -0700 | [diff] [blame] | 520 | if (blk_row == 0 && blk_col == 0) |
| 521 | if (abs(this_refmv.as_mv.row) >= 16 || |
| 522 | abs(this_refmv.as_mv.col) >= 16) |
Sarah Parker | 2b9ec2e | 2017-10-30 17:34:08 -0700 | [diff] [blame] | 523 | mode_context[ref_frame] |= (1 << GLOBALMV_OFFSET); |
Jingning Han | a07a3b2 | 2018-02-05 14:32:28 -0800 | [diff] [blame] | 524 | #endif |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 525 | |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 526 | for (idx = 0; idx < refmv_count[rf[0]]; ++idx) |
Jingning Han | c9c8189 | 2018-02-07 20:12:26 -0800 | [diff] [blame] | 527 | if (this_refmv.as_int == ref_mv_stack[idx].this_mv.as_int) break; |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 528 | |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 529 | if (idx < refmv_count[rf[0]]) |
| 530 | ref_mv_stack[idx].weight += 2 * weight_unit; |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 531 | |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 532 | if (idx == refmv_count[rf[0]] && |
| 533 | refmv_count[rf[0]] < MAX_REF_MV_STACK_SIZE) { |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 534 | ref_mv_stack[idx].this_mv.as_int = this_refmv.as_int; |
| 535 | // TODO(jingning): Hard coded context number. Need to make it better |
| 536 | // sense. |
| 537 | ref_mv_stack[idx].pred_diff[0] = 1; |
| 538 | ref_mv_stack[idx].weight = 2 * weight_unit; |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 539 | ++(refmv_count[rf[0]]); |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | ++coll_blk_count; |
Jingning Han | 2049c01 | 2018-02-07 20:24:48 -0800 | [diff] [blame] | 543 | return coll_blk_count; |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 544 | } |
| 545 | } |
| 546 | } else { |
| 547 | // Process compound inter mode |
Frank Bossen | 7b6bb94 | 2018-01-25 07:49:52 -0500 | [diff] [blame] | 548 | int cur_frame_index = cm->cur_frame->cur_frame_offset; |
| 549 | int buf_idx_0 = cm->frame_refs[FWD_RF_OFFSET(rf[0])].idx; |
Yaowu Xu | 30bf871 | 2018-01-26 07:56:45 -0800 | [diff] [blame] | 550 | int frame0_index = cm->buffer_pool->frame_bufs[buf_idx_0].cur_frame_offset; |
| 551 | |
| 552 | int cur_offset_0 = cur_frame_index - frame0_index; |
Frank Bossen | 7b6bb94 | 2018-01-25 07:49:52 -0500 | [diff] [blame] | 553 | int buf_idx_1 = cm->frame_refs[FWD_RF_OFFSET(rf[1])].idx; |
Yaowu Xu | 30bf871 | 2018-01-26 07:56:45 -0800 | [diff] [blame] | 554 | int frame1_index = cm->buffer_pool->frame_bufs[buf_idx_1].cur_frame_offset; |
| 555 | int cur_offset_1 = cur_frame_index - frame1_index; |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 556 | CANDIDATE_MV *ref_mv_stack = ref_mv_stacks[ref_frame]; |
Frank Bossen | 7b6bb94 | 2018-01-25 07:49:52 -0500 | [diff] [blame] | 557 | |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 558 | for (int i = 0; i < MFMV_STACK_SIZE; ++i) { |
Frank Bossen | 7b6bb94 | 2018-01-25 07:49:52 -0500 | [diff] [blame] | 559 | if (prev_frame_mvs->mfmv0[i].as_int != INVALID_MV) { |
| 560 | int_mv this_refmv; |
| 561 | int_mv comp_refmv; |
| 562 | get_mv_projection(&this_refmv.as_mv, prev_frame_mvs->mfmv0[i].as_mv, |
| 563 | cur_offset_0, prev_frame_mvs->ref_frame_offset[i]); |
| 564 | get_mv_projection(&comp_refmv.as_mv, prev_frame_mvs->mfmv0[i].as_mv, |
| 565 | cur_offset_1, prev_frame_mvs->ref_frame_offset[i]); |
| 566 | |
RogerZhou | 088251e | 2017-11-14 10:52:12 -0800 | [diff] [blame] | 567 | #if CONFIG_AMVR |
| 568 | lower_mv_precision(&this_refmv.as_mv, cm->allow_high_precision_mv, |
| 569 | cm->cur_frame_force_integer_mv); |
| 570 | lower_mv_precision(&comp_refmv.as_mv, cm->allow_high_precision_mv, |
| 571 | cm->cur_frame_force_integer_mv); |
| 572 | #else |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 573 | lower_mv_precision(&this_refmv.as_mv, cm->allow_high_precision_mv); |
| 574 | lower_mv_precision(&comp_refmv.as_mv, cm->allow_high_precision_mv); |
RogerZhou | 088251e | 2017-11-14 10:52:12 -0800 | [diff] [blame] | 575 | #endif |
Jingning Han | a07a3b2 | 2018-02-05 14:32:28 -0800 | [diff] [blame] | 576 | |
| 577 | #if CONFIG_OPT_REF_MV |
| 578 | if (blk_row == 0 && blk_col == 0) |
| 579 | if (abs(this_refmv.as_mv.row - gm_mv_candidates[0].as_mv.row) >= 16 || |
| 580 | abs(this_refmv.as_mv.col - gm_mv_candidates[0].as_mv.col) >= 16 || |
| 581 | abs(comp_refmv.as_mv.row - gm_mv_candidates[1].as_mv.row) >= 16 || |
| 582 | abs(comp_refmv.as_mv.col - gm_mv_candidates[1].as_mv.col) >= 16) |
| 583 | mode_context[ref_frame] |= (1 << GLOBALMV_OFFSET); |
| 584 | #else |
Jingning Han | 0e4c806 | 2017-10-03 20:27:22 -0700 | [diff] [blame] | 585 | if (blk_row == 0 && blk_col == 0) |
| 586 | if (abs(this_refmv.as_mv.row) >= 16 || |
| 587 | abs(this_refmv.as_mv.col) >= 16 || |
| 588 | abs(comp_refmv.as_mv.row) >= 16 || |
| 589 | abs(comp_refmv.as_mv.col) >= 16) |
Sarah Parker | 2b9ec2e | 2017-10-30 17:34:08 -0700 | [diff] [blame] | 590 | mode_context[ref_frame] |= (1 << GLOBALMV_OFFSET); |
Jingning Han | a07a3b2 | 2018-02-05 14:32:28 -0800 | [diff] [blame] | 591 | #endif |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 592 | |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 593 | for (idx = 0; idx < refmv_count[ref_frame]; ++idx) |
Jingning Han | c9c8189 | 2018-02-07 20:12:26 -0800 | [diff] [blame] | 594 | if (this_refmv.as_int == ref_mv_stack[idx].this_mv.as_int && |
| 595 | comp_refmv.as_int == ref_mv_stack[idx].comp_mv.as_int) |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 596 | break; |
| 597 | |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 598 | if (idx < refmv_count[ref_frame]) |
| 599 | ref_mv_stack[idx].weight += 2 * weight_unit; |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 600 | |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 601 | if (idx == refmv_count[ref_frame] && |
| 602 | refmv_count[ref_frame] < MAX_REF_MV_STACK_SIZE) { |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 603 | ref_mv_stack[idx].this_mv.as_int = this_refmv.as_int; |
| 604 | ref_mv_stack[idx].comp_mv.as_int = comp_refmv.as_int; |
| 605 | // TODO(jingning): Hard coded context number. Need to make it better |
| 606 | // sense. |
| 607 | ref_mv_stack[idx].pred_diff[0] = 1; |
| 608 | ref_mv_stack[idx].pred_diff[1] = 1; |
| 609 | ref_mv_stack[idx].weight = 2 * weight_unit; |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 610 | ++(refmv_count[ref_frame]); |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | ++coll_blk_count; |
Jingning Han | 2049c01 | 2018-02-07 20:24:48 -0800 | [diff] [blame] | 614 | return coll_blk_count; |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 615 | } |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | return coll_blk_count; |
| 620 | } |
| 621 | #else |
Yaowu Xu | dc035da | 2016-09-27 10:29:34 -0700 | [diff] [blame] | 622 | static int add_col_ref_mv(const AV1_COMMON *cm, |
| 623 | const MV_REF *prev_frame_mvs_base, |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 624 | int prev_frame_mvs_stride, const MACROBLOCKD *xd, |
| 625 | int mi_row, int mi_col, MV_REFERENCE_FRAME ref_frame, |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 626 | int blk_row, int blk_col, |
| 627 | uint8_t refmv_count[MODE_CTX_REF_FRAMES], |
| 628 | CANDIDATE_MV ref_mv_stacks[][MAX_REF_MV_STACK_SIZE], |
| 629 | int16_t *mode_context) { |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 630 | #if CONFIG_TMV |
| 631 | const MV_REF *prev_frame_mvs = prev_frame_mvs_base + |
Yunqing Wang | c99a564 | 2017-10-11 13:48:22 -0700 | [diff] [blame] | 632 | (blk_row >> 1) * prev_frame_mvs_stride + |
| 633 | (blk_col >> 1); |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 634 | #else |
Yaowu Xu | dc035da | 2016-09-27 10:29:34 -0700 | [diff] [blame] | 635 | const MV_REF *prev_frame_mvs = |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 636 | prev_frame_mvs_base + blk_row * prev_frame_mvs_stride + blk_col; |
| 637 | #endif |
Yaowu Xu | dc035da | 2016-09-27 10:29:34 -0700 | [diff] [blame] | 638 | POSITION mi_pos; |
| 639 | int ref, idx; |
| 640 | int coll_blk_count = 0; |
Jingning Han | c016df8 | 2016-12-09 12:37:28 -0800 | [diff] [blame] | 641 | const int weight_unit = mi_size_wide[BLOCK_8X8]; |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 642 | CANDIDATE_MV *ref_mv_stack = ref_mv_stacks[ref_frame]; |
Yaowu Xu | dc035da | 2016-09-27 10:29:34 -0700 | [diff] [blame] | 643 | |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 644 | #if CONFIG_TMV |
| 645 | mi_pos.row = blk_row; |
| 646 | mi_pos.col = blk_col; |
| 647 | #else |
zhipin deng | eb019b8 | 2017-02-17 17:49:03 +0800 | [diff] [blame] | 648 | mi_pos.row = (mi_row & 0x01) ? blk_row : blk_row + 1; |
| 649 | mi_pos.col = (mi_col & 0x01) ? blk_col : blk_col + 1; |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 650 | #endif // CONFIG_TMV |
Yaowu Xu | dc035da | 2016-09-27 10:29:34 -0700 | [diff] [blame] | 651 | |
Yaowu Xu | 531d6af | 2017-03-07 17:48:52 -0800 | [diff] [blame] | 652 | if (!is_inside(&xd->tile, mi_col, mi_row, cm->mi_rows, cm, &mi_pos)) |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 653 | return coll_blk_count; |
Yaowu Xu | dc035da | 2016-09-27 10:29:34 -0700 | [diff] [blame] | 654 | for (ref = 0; ref < 2; ++ref) { |
| 655 | if (prev_frame_mvs->ref_frame[ref] == ref_frame) { |
| 656 | int_mv this_refmv = prev_frame_mvs->mv[ref]; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 657 | #if CONFIG_AMVR |
| 658 | lower_mv_precision(&this_refmv.as_mv, cm->allow_high_precision_mv, |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 659 | cm->cur_frame_force_integer_mv); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 660 | #else |
Yaowu Xu | dc035da | 2016-09-27 10:29:34 -0700 | [diff] [blame] | 661 | lower_mv_precision(&this_refmv.as_mv, cm->allow_high_precision_mv); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 662 | #endif |
Jingning Han | 0e4c806 | 2017-10-03 20:27:22 -0700 | [diff] [blame] | 663 | |
| 664 | #if CONFIG_OPT_REF_MV |
| 665 | if (blk_row == 0 && blk_col == 0) |
| 666 | #endif |
| 667 | { |
| 668 | if (abs(this_refmv.as_mv.row) >= 16 || abs(this_refmv.as_mv.col) >= 16) |
Sarah Parker | 2b9ec2e | 2017-10-30 17:34:08 -0700 | [diff] [blame] | 669 | mode_context[ref_frame] |= (1 << GLOBALMV_OFFSET); |
Jingning Han | 0e4c806 | 2017-10-03 20:27:22 -0700 | [diff] [blame] | 670 | } |
Yaowu Xu | dc035da | 2016-09-27 10:29:34 -0700 | [diff] [blame] | 671 | |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 672 | for (idx = 0; idx < refmv_count[ref_frame]; ++idx) |
Yaowu Xu | dc035da | 2016-09-27 10:29:34 -0700 | [diff] [blame] | 673 | if (this_refmv.as_int == ref_mv_stack[idx].this_mv.as_int) break; |
| 674 | |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 675 | if (idx < refmv_count[ref_frame]) |
| 676 | ref_mv_stack[idx].weight += 2 * weight_unit; |
Yaowu Xu | dc035da | 2016-09-27 10:29:34 -0700 | [diff] [blame] | 677 | |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 678 | if (idx == refmv_count[ref_frame] && |
| 679 | refmv_count[ref_frame] < MAX_REF_MV_STACK_SIZE) { |
Yaowu Xu | dc035da | 2016-09-27 10:29:34 -0700 | [diff] [blame] | 680 | ref_mv_stack[idx].this_mv.as_int = this_refmv.as_int; |
Jingning Han | 3f33883 | 2016-11-18 11:01:48 -0800 | [diff] [blame] | 681 | ref_mv_stack[idx].pred_diff[0] = |
| 682 | av1_get_pred_diff_ctx(prev_frame_mvs->pred_mv[ref], this_refmv); |
Jingning Han | c016df8 | 2016-12-09 12:37:28 -0800 | [diff] [blame] | 683 | ref_mv_stack[idx].weight = 2 * weight_unit; |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 684 | ++(refmv_count[ref_frame]); |
Yaowu Xu | dc035da | 2016-09-27 10:29:34 -0700 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | ++coll_blk_count; |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | return coll_blk_count; |
| 692 | } |
Zoe Liu | 294f59d | 2017-10-31 23:02:04 -0700 | [diff] [blame] | 693 | #endif // CONFIG_MFMV |
Yaowu Xu | dc035da | 2016-09-27 10:29:34 -0700 | [diff] [blame] | 694 | |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 695 | static void setup_ref_mv_list( |
| 696 | const AV1_COMMON *cm, const MACROBLOCKD *xd, MV_REFERENCE_FRAME ref_frame, |
| 697 | uint8_t refmv_count[MODE_CTX_REF_FRAMES], |
| 698 | CANDIDATE_MV ref_mv_stack[][MAX_REF_MV_STACK_SIZE], |
| 699 | int_mv mv_ref_list[][MAX_MV_REF_CANDIDATES], |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 700 | #if USE_CUR_GM_REFMV |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 701 | int_mv *gm_mv_candidates, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 702 | #endif // USE_CUR_GM_REFMV |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 703 | int mi_row, int mi_col, int16_t *mode_context, int compound_search) { |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 704 | #if CONFIG_TMV |
| 705 | const int prev_frame_mvs_stride = ROUND_POWER_OF_TWO(cm->mi_cols, 1); |
| 706 | const int tmi_row = mi_row & 0xfffe; |
| 707 | const int tmi_col = mi_col & 0xfffe; |
| 708 | const MV_REF *const prev_frame_mvs_base = |
| 709 | cm->use_prev_frame_mvs |
| 710 | ? cm->prev_frame->mvs + (tmi_row >> 1) * prev_frame_mvs_stride + |
| 711 | (tmi_col >> 1) |
| 712 | : NULL; |
| 713 | #else |
| 714 | const int prev_frame_mvs_stride = cm->mi_cols; |
zhipin deng | eb019b8 | 2017-02-17 17:49:03 +0800 | [diff] [blame] | 715 | const MV_REF *const prev_frame_mvs_base = |
| 716 | cm->use_prev_frame_mvs |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 717 | ? cm->prev_frame->mvs + |
| 718 | (((mi_row >> 1) << 1) + 1) * prev_frame_mvs_stride + |
zhipin deng | eb019b8 | 2017-02-17 17:49:03 +0800 | [diff] [blame] | 719 | ((mi_col >> 1) << 1) + 1 |
| 720 | : NULL; |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 721 | #endif // CONFIG_TMV |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 722 | |
Yaowu Xu | dc035da | 2016-09-27 10:29:34 -0700 | [diff] [blame] | 723 | const int bs = AOMMAX(xd->n8_w, xd->n8_h); |
David Barker | 761b1ac | 2017-09-25 11:23:03 +0100 | [diff] [blame] | 724 | const int has_tr = has_top_right(cm, xd, mi_row, mi_col, bs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 725 | MV_REFERENCE_FRAME rf[2]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 726 | |
Yunqing Wang | d797ea9 | 2017-08-27 18:05:55 -0700 | [diff] [blame] | 727 | const TileInfo *const tile = &xd->tile; |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 728 | int max_row_offset = 0, max_col_offset = 0; |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 729 | const int row_adj = (xd->n8_h < mi_size_high[BLOCK_8X8]) && (mi_row & 0x01); |
| 730 | const int col_adj = (xd->n8_w < mi_size_wide[BLOCK_8X8]) && (mi_col & 0x01); |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 731 | int processed_rows = 0; |
| 732 | int processed_cols = 0; |
Yunqing Wang | d797ea9 | 2017-08-27 18:05:55 -0700 | [diff] [blame] | 733 | |
Yaowu Xu | dc035da | 2016-09-27 10:29:34 -0700 | [diff] [blame] | 734 | av1_set_ref_frame(rf, ref_frame); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 735 | mode_context[ref_frame] = 0; |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 736 | refmv_count[ref_frame] = 0; |
| 737 | (void)compound_search; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 738 | |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 739 | // Find valid maximum row/col offset. |
| 740 | if (xd->up_available) { |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 741 | max_row_offset = -(MVREF_ROWS << 1) + row_adj; |
Jingning Han | 818b006 | 2017-12-21 15:21:32 -0800 | [diff] [blame] | 742 | #if CONFIG_OPT_REF_MV |
| 743 | if (xd->n8_h < mi_size_high[BLOCK_8X8]) |
| 744 | max_row_offset = -(2 << 1) + row_adj; |
| 745 | #endif |
Yunqing Wang | d797ea9 | 2017-08-27 18:05:55 -0700 | [diff] [blame] | 746 | max_row_offset = |
| 747 | find_valid_row_offset(tile, mi_row, cm->mi_rows, cm, max_row_offset); |
Yunqing Wang | d797ea9 | 2017-08-27 18:05:55 -0700 | [diff] [blame] | 748 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 749 | |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 750 | if (xd->left_available) { |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 751 | max_col_offset = -(MVREF_COLS << 1) + col_adj; |
Jingning Han | 818b006 | 2017-12-21 15:21:32 -0800 | [diff] [blame] | 752 | #if CONFIG_OPT_REF_MV |
| 753 | if (xd->n8_w < mi_size_wide[BLOCK_8X8]) |
| 754 | max_col_offset = -(2 << 1) + col_adj; |
| 755 | #endif |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 756 | max_col_offset = find_valid_col_offset(tile, mi_col, max_col_offset); |
| 757 | } |
| 758 | |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 759 | uint8_t ref_match_count[MODE_CTX_REF_FRAMES] = { 0 }; |
Sebastien Alaiwan | 62cc585 | 2017-12-05 10:19:04 +0100 | [diff] [blame] | 760 | uint8_t newmv_count = 0; |
| 761 | |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 762 | // Scan the first above row mode info. row_offset = -1; |
| 763 | if (abs(max_row_offset) >= 1) |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 764 | newmv_count += scan_row_mbmi(cm, xd, mi_row, mi_col, rf, -1, ref_mv_stack, |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 765 | refmv_count, ref_match_count, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 766 | #if USE_CUR_GM_REFMV |
Yunqing Wang | 97d6a37 | 2017-10-09 14:15:15 -0700 | [diff] [blame] | 767 | gm_mv_candidates, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 768 | #endif // USE_CUR_GM_REFMV |
Yunqing Wang | 97d6a37 | 2017-10-09 14:15:15 -0700 | [diff] [blame] | 769 | max_row_offset, &processed_rows); |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 770 | // Scan the first left column mode info. col_offset = -1; |
| 771 | if (abs(max_col_offset) >= 1) |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 772 | newmv_count += scan_col_mbmi(cm, xd, mi_row, mi_col, rf, -1, ref_mv_stack, |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 773 | refmv_count, ref_match_count, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 774 | #if USE_CUR_GM_REFMV |
Yunqing Wang | 97d6a37 | 2017-10-09 14:15:15 -0700 | [diff] [blame] | 775 | gm_mv_candidates, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 776 | #endif // USE_CUR_GM_REFMV |
Yunqing Wang | 97d6a37 | 2017-10-09 14:15:15 -0700 | [diff] [blame] | 777 | max_col_offset, &processed_cols); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 778 | // Check top-right boundary |
| 779 | if (has_tr) |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 780 | newmv_count += scan_blk_mbmi(cm, xd, mi_row, mi_col, rf, -1, xd->n8_w, |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 781 | ref_mv_stack, ref_match_count, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 782 | #if USE_CUR_GM_REFMV |
Sarah Parker | 0a5cc5f | 2017-10-03 17:53:53 -0700 | [diff] [blame] | 783 | gm_mv_candidates, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 784 | #endif // USE_CUR_GM_REFMV |
Sarah Parker | 0a5cc5f | 2017-10-03 17:53:53 -0700 | [diff] [blame] | 785 | refmv_count); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 786 | |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 787 | uint8_t nearest_match[MODE_CTX_REF_FRAMES]; |
| 788 | uint8_t nearest_refmv_count[MODE_CTX_REF_FRAMES]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 789 | |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 790 | nearest_match[ref_frame] = ref_match_count[ref_frame]; |
| 791 | nearest_refmv_count[ref_frame] = refmv_count[ref_frame]; |
| 792 | |
| 793 | // TODO(yunqing): for comp_search, do it for all 3 cases. |
| 794 | for (int idx = 0; idx < nearest_refmv_count[ref_frame]; ++idx) |
| 795 | ref_mv_stack[ref_frame][idx].weight += REF_CAT_LEVEL; |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 796 | |
| 797 | #if CONFIG_MFMV |
Jingning Han | e17ebe9 | 2017-11-03 15:25:42 -0700 | [diff] [blame] | 798 | if (cm->use_ref_frame_mvs) { |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 799 | int coll_blk_count[MODE_CTX_REF_FRAMES] = { 0 }; |
Sebastien Alaiwan | 62cc585 | 2017-12-05 10:19:04 +0100 | [diff] [blame] | 800 | const int voffset = AOMMAX(mi_size_high[BLOCK_8X8], xd->n8_h); |
| 801 | const int hoffset = AOMMAX(mi_size_wide[BLOCK_8X8], xd->n8_w); |
Jingning Han | 5e19c9d | 2018-02-09 12:16:56 -0800 | [diff] [blame] | 802 | const int blk_row_end = AOMMIN(xd->n8_h, mi_size_high[BLOCK_64X64]); |
| 803 | const int blk_col_end = AOMMIN(xd->n8_w, mi_size_wide[BLOCK_64X64]); |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 804 | |
Jingning Han | 4c864e0 | 2017-12-22 10:03:03 -0800 | [diff] [blame] | 805 | const int tpl_sample_pos[3][2] = { |
Johann | 6b41d4d | 2018-02-08 14:32:53 -0800 | [diff] [blame] | 806 | { voffset, -2 }, |
| 807 | { voffset, hoffset }, |
| 808 | { voffset - 2, hoffset }, |
Jingning Han | d4e8716 | 2017-10-31 09:22:58 -0700 | [diff] [blame] | 809 | }; |
Jingning Han | 4c864e0 | 2017-12-22 10:03:03 -0800 | [diff] [blame] | 810 | const int allow_extension = (xd->n8_h >= mi_size_high[BLOCK_8X8]) && |
Jingning Han | 5e19c9d | 2018-02-09 12:16:56 -0800 | [diff] [blame] | 811 | (xd->n8_h < mi_size_high[BLOCK_64X64]) && |
| 812 | (xd->n8_w >= mi_size_wide[BLOCK_8X8]) && |
| 813 | (xd->n8_w < mi_size_wide[BLOCK_64X64]); |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 814 | |
Jingning Han | 5e19c9d | 2018-02-09 12:16:56 -0800 | [diff] [blame] | 815 | for (int blk_row = 0; blk_row < blk_row_end; |
Sebastien Alaiwan | 62cc585 | 2017-12-05 10:19:04 +0100 | [diff] [blame] | 816 | blk_row += mi_size_high[BLOCK_8X8]) { |
Jingning Han | 5e19c9d | 2018-02-09 12:16:56 -0800 | [diff] [blame] | 817 | for (int blk_col = 0; blk_col < blk_col_end; |
Jingning Han | d4e8716 | 2017-10-31 09:22:58 -0700 | [diff] [blame] | 818 | blk_col += mi_size_wide[BLOCK_8X8]) { |
| 819 | // (TODO: yunqing) prev_frame_mvs_base is not used here, tpl_mvs is |
| 820 | // used. |
| 821 | // Can be modified the same way. |
| 822 | int is_available = add_tpl_ref_mv( |
| 823 | cm, prev_frame_mvs_base, xd, mi_row, mi_col, ref_frame, blk_row, |
Jingning Han | a07a3b2 | 2018-02-05 14:32:28 -0800 | [diff] [blame] | 824 | blk_col, gm_mv_candidates, refmv_count, ref_mv_stack, mode_context); |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 825 | if (blk_row == 0 && blk_col == 0) |
| 826 | coll_blk_count[ref_frame] = is_available; |
Jingning Han | d4e8716 | 2017-10-31 09:22:58 -0700 | [diff] [blame] | 827 | } |
| 828 | } |
| 829 | |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 830 | if (coll_blk_count[ref_frame] == 0) |
| 831 | mode_context[ref_frame] |= (1 << GLOBALMV_OFFSET); |
Jingning Han | d4e8716 | 2017-10-31 09:22:58 -0700 | [diff] [blame] | 832 | |
Jingning Han | 4c864e0 | 2017-12-22 10:03:03 -0800 | [diff] [blame] | 833 | for (int i = 0; i < 3 && allow_extension; ++i) { |
Sebastien Alaiwan | 62cc585 | 2017-12-05 10:19:04 +0100 | [diff] [blame] | 834 | const int blk_row = tpl_sample_pos[i][0]; |
| 835 | const int blk_col = tpl_sample_pos[i][1]; |
Jingning Han | d4e8716 | 2017-10-31 09:22:58 -0700 | [diff] [blame] | 836 | |
Jingning Han | d41869a | 2018-02-09 10:44:30 -0800 | [diff] [blame] | 837 | if (!check_sb_border(mi_row, mi_col, blk_row, blk_col)) continue; |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 838 | // (TODO: yunqing) prev_frame_mvs_base is not used here, tpl_mvs is used. |
| 839 | // Can be modified the same way. |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 840 | coll_blk_count[ref_frame] += add_tpl_ref_mv( |
Jingning Han | a07a3b2 | 2018-02-05 14:32:28 -0800 | [diff] [blame] | 841 | cm, prev_frame_mvs_base, xd, mi_row, mi_col, ref_frame, blk_row, |
| 842 | blk_col, gm_mv_candidates, refmv_count, ref_mv_stack, mode_context); |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 843 | } |
| 844 | } |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 845 | #else |
Frederic Barbier | 98c16fa | 2018-02-07 10:22:51 +0100 | [diff] [blame] | 846 | if (cm->use_prev_frame_mvs && rf[1] == NONE_FRAME) { |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 847 | int coll_blk_count[MODE_CTX_REF_FRAMES] = { 0 }; |
Jingning Han | fab1603 | 2016-12-16 14:52:45 -0800 | [diff] [blame] | 848 | const int mi_step = (xd->n8_w == 1 || xd->n8_h == 1) |
| 849 | ? mi_size_wide[BLOCK_8X8] |
| 850 | : mi_size_wide[BLOCK_16X16]; |
Jingning Han | 8cf8364 | 2017-01-30 14:39:28 -0800 | [diff] [blame] | 851 | |
Sebastien Alaiwan | 62cc585 | 2017-12-05 10:19:04 +0100 | [diff] [blame] | 852 | for (int blk_row = 0; blk_row < xd->n8_h; blk_row += mi_step) { |
| 853 | for (int blk_col = 0; blk_col < xd->n8_w; blk_col += mi_step) { |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 854 | #if CONFIG_TMV |
| 855 | int is_available = |
| 856 | add_col_ref_mv(cm, prev_frame_mvs_base, prev_frame_mvs_stride, xd, |
| 857 | tmi_row, tmi_col, ref_frame, blk_row, blk_col, |
| 858 | refmv_count, ref_mv_stack, mode_context); |
| 859 | #else |
| 860 | int is_available = |
| 861 | add_col_ref_mv(cm, prev_frame_mvs_base, prev_frame_mvs_stride, xd, |
| 862 | mi_row, mi_col, ref_frame, blk_row, blk_col, |
| 863 | refmv_count, ref_mv_stack, mode_context); |
| 864 | #endif // CONFIG_TMV |
Jingning Han | 0e4c806 | 2017-10-03 20:27:22 -0700 | [diff] [blame] | 865 | #if CONFIG_OPT_REF_MV |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 866 | if (blk_row == 0 && blk_col == 0) |
| 867 | coll_blk_count[ref_frame] = is_available; |
Jingning Han | 0e4c806 | 2017-10-03 20:27:22 -0700 | [diff] [blame] | 868 | #else |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 869 | coll_blk_count[ref_frame] += is_available; |
Jingning Han | 0e4c806 | 2017-10-03 20:27:22 -0700 | [diff] [blame] | 870 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 871 | } |
| 872 | } |
Jingning Han | 8cf8364 | 2017-01-30 14:39:28 -0800 | [diff] [blame] | 873 | |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 874 | if (coll_blk_count[ref_frame] == 0) |
| 875 | mode_context[ref_frame] |= (1 << GLOBALMV_OFFSET); |
Yaowu Xu | dc035da | 2016-09-27 10:29:34 -0700 | [diff] [blame] | 876 | } else { |
Sarah Parker | 2b9ec2e | 2017-10-30 17:34:08 -0700 | [diff] [blame] | 877 | mode_context[ref_frame] |= (1 << GLOBALMV_OFFSET); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 878 | } |
Zoe Liu | 294f59d | 2017-10-31 23:02:04 -0700 | [diff] [blame] | 879 | #endif // CONFIG_MFMV |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 880 | |
Jingning Han | 24e0a18 | 2016-11-20 22:34:12 -0800 | [diff] [blame] | 881 | // Scan the second outer area. |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 882 | scan_blk_mbmi(cm, xd, mi_row, mi_col, rf, -1, -1, ref_mv_stack, |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 883 | ref_match_count, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 884 | #if USE_CUR_GM_REFMV |
Sarah Parker | 0a5cc5f | 2017-10-03 17:53:53 -0700 | [diff] [blame] | 885 | gm_mv_candidates, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 886 | #endif // USE_CUR_GM_REFMV |
Deng | ca8d24d | 2016-10-17 14:06:35 +0800 | [diff] [blame] | 887 | refmv_count); |
Jingning Han | 818b006 | 2017-12-21 15:21:32 -0800 | [diff] [blame] | 888 | |
Sebastien Alaiwan | 62cc585 | 2017-12-05 10:19:04 +0100 | [diff] [blame] | 889 | for (int idx = 2; idx <= MVREF_ROWS; ++idx) { |
| 890 | const int row_offset = -(idx << 1) + 1 + row_adj; |
| 891 | const int col_offset = -(idx << 1) + 1 + col_adj; |
Yunqing Wang | d797ea9 | 2017-08-27 18:05:55 -0700 | [diff] [blame] | 892 | |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 893 | if (abs(row_offset) <= abs(max_row_offset) && |
| 894 | abs(row_offset) > processed_rows) |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 895 | scan_row_mbmi(cm, xd, mi_row, mi_col, rf, row_offset, ref_mv_stack, |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 896 | refmv_count, ref_match_count, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 897 | #if USE_CUR_GM_REFMV |
Sarah Parker | 0a5cc5f | 2017-10-03 17:53:53 -0700 | [diff] [blame] | 898 | gm_mv_candidates, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 899 | #endif // USE_CUR_GM_REFMV |
Sarah Parker | 0a5cc5f | 2017-10-03 17:53:53 -0700 | [diff] [blame] | 900 | max_row_offset, &processed_rows); |
Yunqing Wang | d797ea9 | 2017-08-27 18:05:55 -0700 | [diff] [blame] | 901 | |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 902 | if (abs(col_offset) <= abs(max_col_offset) && |
| 903 | abs(col_offset) > processed_cols) |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 904 | scan_col_mbmi(cm, xd, mi_row, mi_col, rf, col_offset, ref_mv_stack, |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 905 | refmv_count, ref_match_count, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 906 | #if USE_CUR_GM_REFMV |
Sarah Parker | 0a5cc5f | 2017-10-03 17:53:53 -0700 | [diff] [blame] | 907 | gm_mv_candidates, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 908 | #endif // USE_CUR_GM_REFMV |
Sarah Parker | 0a5cc5f | 2017-10-03 17:53:53 -0700 | [diff] [blame] | 909 | max_col_offset, &processed_cols); |
Yunqing Wang | d797ea9 | 2017-08-27 18:05:55 -0700 | [diff] [blame] | 910 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 911 | |
Sebastien Alaiwan | 62cc585 | 2017-12-05 10:19:04 +0100 | [diff] [blame] | 912 | const int col_offset = -(MVREF_COLS << 1) + 1 + col_adj; |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 913 | if (abs(col_offset) <= abs(max_col_offset) && |
| 914 | abs(col_offset) > processed_cols) |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 915 | scan_col_mbmi(cm, xd, mi_row, mi_col, rf, col_offset, ref_mv_stack, |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 916 | refmv_count, ref_match_count, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 917 | #if USE_CUR_GM_REFMV |
Sarah Parker | 0a5cc5f | 2017-10-03 17:53:53 -0700 | [diff] [blame] | 918 | gm_mv_candidates, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 919 | #endif // USE_CUR_GM_REFMV |
Sarah Parker | 0a5cc5f | 2017-10-03 17:53:53 -0700 | [diff] [blame] | 920 | max_col_offset, &processed_cols); |
Yunqing Wang | d1121fa | 2017-09-13 14:34:45 -0700 | [diff] [blame] | 921 | |
Jingning Han | 835a49e | 2017-12-01 15:55:34 -0800 | [diff] [blame] | 922 | #if CONFIG_OPT_REF_MV |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 923 | switch (nearest_match[ref_frame]) |
Jingning Han | 835a49e | 2017-12-01 15:55:34 -0800 | [diff] [blame] | 924 | #else |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 925 | switch (nearest_refmv_count[ref_frame]) |
Jingning Han | 835a49e | 2017-12-01 15:55:34 -0800 | [diff] [blame] | 926 | #endif |
| 927 | { |
Jingning Han | 8a8c50a | 2017-10-08 11:25:41 -0700 | [diff] [blame] | 928 | case 0: mode_context[ref_frame] |= 0; |
Jingning Han | 835a49e | 2017-12-01 15:55:34 -0800 | [diff] [blame] | 929 | #if CONFIG_OPT_REF_MV |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 930 | if (ref_match_count[ref_frame] >= 1) mode_context[ref_frame] |= 1; |
| 931 | if (ref_match_count[ref_frame] == 1) |
Jingning Han | 835a49e | 2017-12-01 15:55:34 -0800 | [diff] [blame] | 932 | mode_context[ref_frame] |= (1 << REFMV_OFFSET); |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 933 | else if (ref_match_count[ref_frame] >= 2) |
Jingning Han | 835a49e | 2017-12-01 15:55:34 -0800 | [diff] [blame] | 934 | mode_context[ref_frame] |= (2 << REFMV_OFFSET); |
| 935 | #else |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 936 | if (refmv_count[ref_frame] >= 1) mode_context[ref_frame] |= 1; |
| 937 | if (refmv_count[ref_frame] == 1) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 938 | mode_context[ref_frame] |= (1 << REFMV_OFFSET); |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 939 | else if (refmv_count[ref_frame] >= 2) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 940 | mode_context[ref_frame] |= (2 << REFMV_OFFSET); |
Jingning Han | abf6f28 | 2017-10-09 13:18:59 -0700 | [diff] [blame] | 941 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 942 | break; |
Jingning Han | abf6f28 | 2017-10-09 13:18:59 -0700 | [diff] [blame] | 943 | case 1: mode_context[ref_frame] |= (newmv_count > 0) ? 2 : 3; |
| 944 | #if CONFIG_OPT_REF_MV |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 945 | if (ref_match_count[ref_frame] == 1) |
Jingning Han | 835a49e | 2017-12-01 15:55:34 -0800 | [diff] [blame] | 946 | mode_context[ref_frame] |= (3 << REFMV_OFFSET); |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 947 | else if (ref_match_count[ref_frame] >= 2) |
Jingning Han | 835a49e | 2017-12-01 15:55:34 -0800 | [diff] [blame] | 948 | mode_context[ref_frame] |= (4 << REFMV_OFFSET); |
Jingning Han | abf6f28 | 2017-10-09 13:18:59 -0700 | [diff] [blame] | 949 | #else |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 950 | if (refmv_count[ref_frame] == 1) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 951 | mode_context[ref_frame] |= (3 << REFMV_OFFSET); |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 952 | else if (refmv_count[ref_frame] >= 2) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 953 | mode_context[ref_frame] |= (4 << REFMV_OFFSET); |
Jingning Han | abf6f28 | 2017-10-09 13:18:59 -0700 | [diff] [blame] | 954 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 955 | break; |
| 956 | |
| 957 | case 2: |
| 958 | default: |
| 959 | if (newmv_count >= 2) |
| 960 | mode_context[ref_frame] |= 4; |
| 961 | else if (newmv_count == 1) |
| 962 | mode_context[ref_frame] |= 5; |
| 963 | else |
| 964 | mode_context[ref_frame] |= 6; |
| 965 | |
| 966 | mode_context[ref_frame] |= (5 << REFMV_OFFSET); |
| 967 | break; |
| 968 | } |
| 969 | |
| 970 | // Rank the likelihood and assign nearest and near mvs. |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 971 | int len = nearest_refmv_count[ref_frame]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 972 | while (len > 0) { |
Sebastien Alaiwan | 62cc585 | 2017-12-05 10:19:04 +0100 | [diff] [blame] | 973 | int nr_len = 0; |
| 974 | for (int idx = 1; idx < len; ++idx) { |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 975 | if (ref_mv_stack[ref_frame][idx - 1].weight < |
| 976 | ref_mv_stack[ref_frame][idx].weight) { |
| 977 | CANDIDATE_MV tmp_mv = ref_mv_stack[ref_frame][idx - 1]; |
| 978 | ref_mv_stack[ref_frame][idx - 1] = ref_mv_stack[ref_frame][idx]; |
| 979 | ref_mv_stack[ref_frame][idx] = tmp_mv; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 980 | nr_len = idx; |
| 981 | } |
| 982 | } |
| 983 | len = nr_len; |
| 984 | } |
| 985 | |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 986 | len = refmv_count[ref_frame]; |
| 987 | while (len > nearest_refmv_count[ref_frame]) { |
| 988 | int nr_len = nearest_refmv_count[ref_frame]; |
| 989 | for (int idx = nearest_refmv_count[ref_frame] + 1; idx < len; ++idx) { |
| 990 | if (ref_mv_stack[ref_frame][idx - 1].weight < |
| 991 | ref_mv_stack[ref_frame][idx].weight) { |
| 992 | CANDIDATE_MV tmp_mv = ref_mv_stack[ref_frame][idx - 1]; |
| 993 | ref_mv_stack[ref_frame][idx - 1] = ref_mv_stack[ref_frame][idx]; |
| 994 | ref_mv_stack[ref_frame][idx] = tmp_mv; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 995 | nr_len = idx; |
| 996 | } |
| 997 | } |
| 998 | len = nr_len; |
| 999 | } |
| 1000 | |
Emil Keyder | 01770b3 | 2017-01-20 18:03:11 -0500 | [diff] [blame] | 1001 | if (rf[1] > NONE_FRAME) { |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 1002 | for (int idx = 0; idx < refmv_count[ref_frame]; ++idx) { |
| 1003 | clamp_mv_ref(&ref_mv_stack[ref_frame][idx].this_mv.as_mv, |
| 1004 | xd->n8_w << MI_SIZE_LOG2, xd->n8_h << MI_SIZE_LOG2, xd); |
| 1005 | clamp_mv_ref(&ref_mv_stack[ref_frame][idx].comp_mv.as_mv, |
| 1006 | xd->n8_w << MI_SIZE_LOG2, xd->n8_h << MI_SIZE_LOG2, xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1007 | } |
| 1008 | } else { |
Jingning Han | ff1a35b | 2018-02-09 20:17:50 -0800 | [diff] [blame^] | 1009 | #if CONFIG_OPT_REF_MV |
| 1010 | // Handle single reference frame extension |
| 1011 | int mi_width = AOMMIN(mi_size_wide[BLOCK_64X64], xd->n8_w); |
| 1012 | mi_width = AOMMIN(mi_width, cm->mi_cols - mi_col); |
| 1013 | int mi_height = AOMMIN(mi_size_high[BLOCK_64X64], xd->n8_h); |
| 1014 | mi_height = AOMMIN(mi_height, cm->mi_rows - mi_row); |
| 1015 | int mi_size = AOMMIN(mi_width, mi_height); |
| 1016 | |
| 1017 | for (int idx = 0; abs(max_row_offset) >= 1 && idx < mi_size && |
| 1018 | refmv_count[ref_frame] < MAX_MV_REF_CANDIDATES;) { |
| 1019 | const MODE_INFO *const candidate_mi = xd->mi[-xd->mi_stride + idx]; |
| 1020 | const MB_MODE_INFO *const candidate = &candidate_mi->mbmi; |
| 1021 | const int candidate_bsize = candidate->sb_type; |
| 1022 | |
| 1023 | // TODO(jingning): Refactor the following code. |
| 1024 | for (int rf_idx = 0; rf_idx < 2; ++rf_idx) { |
| 1025 | if (candidate->ref_frame[rf_idx] > INTRA_FRAME) { |
| 1026 | int_mv this_mv = candidate->mv[rf_idx]; |
| 1027 | if (cm->ref_frame_sign_bias[candidate->ref_frame[rf_idx]] != |
| 1028 | cm->ref_frame_sign_bias[ref_frame]) { |
| 1029 | this_mv.as_mv.row = -this_mv.as_mv.row; |
| 1030 | this_mv.as_mv.col = -this_mv.as_mv.col; |
| 1031 | } |
| 1032 | int stack_idx; |
| 1033 | for (stack_idx = 0; stack_idx < refmv_count[ref_frame]; ++stack_idx) { |
| 1034 | int_mv stack_mv = ref_mv_stack[ref_frame][stack_idx].this_mv; |
| 1035 | if (this_mv.as_int == stack_mv.as_int) break; |
| 1036 | } |
| 1037 | |
| 1038 | if (stack_idx == refmv_count[ref_frame]) { |
| 1039 | ref_mv_stack[ref_frame][stack_idx].this_mv = this_mv; |
| 1040 | |
| 1041 | // TODO(jingning): Set an arbitrary small number here. The weight |
| 1042 | // doesn't matter as long as it is properly initialized. |
| 1043 | ref_mv_stack[ref_frame][stack_idx].weight = 2; |
| 1044 | ++refmv_count[ref_frame]; |
| 1045 | } |
| 1046 | } |
| 1047 | } |
| 1048 | idx += mi_size_wide[candidate_bsize]; |
| 1049 | } |
| 1050 | |
| 1051 | for (int idx = 0; abs(max_col_offset) >= 1 && idx < mi_size && |
| 1052 | refmv_count[ref_frame] < MAX_MV_REF_CANDIDATES;) { |
| 1053 | const MODE_INFO *const candidate_mi = xd->mi[idx * xd->mi_stride - 1]; |
| 1054 | const MB_MODE_INFO *const candidate = &candidate_mi->mbmi; |
| 1055 | const int candidate_bsize = candidate->sb_type; |
| 1056 | |
| 1057 | // TODO(jingning): Refactor the following code. |
| 1058 | for (int rf_idx = 0; rf_idx < 2; ++rf_idx) { |
| 1059 | if (candidate->ref_frame[rf_idx] > INTRA_FRAME) { |
| 1060 | int_mv this_mv = candidate->mv[rf_idx]; |
| 1061 | if (cm->ref_frame_sign_bias[candidate->ref_frame[rf_idx]] != |
| 1062 | cm->ref_frame_sign_bias[ref_frame]) { |
| 1063 | this_mv.as_mv.row = -this_mv.as_mv.row; |
| 1064 | this_mv.as_mv.col = -this_mv.as_mv.col; |
| 1065 | } |
| 1066 | int stack_idx; |
| 1067 | for (stack_idx = 0; stack_idx < refmv_count[ref_frame]; ++stack_idx) { |
| 1068 | int_mv stack_mv = ref_mv_stack[ref_frame][stack_idx].this_mv; |
| 1069 | if (this_mv.as_int == stack_mv.as_int) break; |
| 1070 | } |
| 1071 | |
| 1072 | if (stack_idx == refmv_count[ref_frame]) { |
| 1073 | ref_mv_stack[ref_frame][stack_idx].this_mv = this_mv; |
| 1074 | |
| 1075 | // TODO(jingning): Set an arbitrary small number here. The weight |
| 1076 | // doesn't matter as long as it is properly initialized. |
| 1077 | ref_mv_stack[ref_frame][stack_idx].weight = 2; |
| 1078 | ++refmv_count[ref_frame]; |
| 1079 | } |
| 1080 | } |
| 1081 | } |
| 1082 | idx += mi_size_high[candidate_bsize]; |
| 1083 | } |
| 1084 | |
| 1085 | for (int idx = refmv_count[ref_frame]; idx < MAX_MV_REF_CANDIDATES; ++idx) |
| 1086 | mv_ref_list[rf[0]][idx].as_int = gm_mv_candidates[0].as_int; |
| 1087 | #endif |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 1088 | for (int idx = 0; |
| 1089 | idx < AOMMIN(MAX_MV_REF_CANDIDATES, refmv_count[ref_frame]); ++idx) { |
| 1090 | mv_ref_list[rf[0]][idx].as_int = |
| 1091 | ref_mv_stack[ref_frame][idx].this_mv.as_int; |
| 1092 | clamp_mv_ref(&mv_ref_list[rf[0]][idx].as_mv, xd->n8_w << MI_SIZE_LOG2, |
Jingning Han | ff6ee6a | 2016-12-07 09:55:21 -0800 | [diff] [blame] | 1093 | xd->n8_h << MI_SIZE_LOG2, xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1094 | } |
| 1095 | } |
Jingning Han | 835a49e | 2017-12-01 15:55:34 -0800 | [diff] [blame] | 1096 | (void)nearest_match; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1097 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1098 | |
| 1099 | // This function searches the neighbourhood of a given MB/SB |
| 1100 | // to try and find candidate reference vectors. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1101 | static void find_mv_refs_idx(const AV1_COMMON *cm, const MACROBLOCKD *xd, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1102 | MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame, |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 1103 | int_mv *mv_ref_list, int mi_row, int mi_col, |
| 1104 | find_mv_refs_sync sync, void *const data, |
Yunqing Wang | 880ab1c | 2018-02-02 15:24:06 -0800 | [diff] [blame] | 1105 | int16_t *mode_context, int_mv zeromv, |
| 1106 | uint8_t refmv_count) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1107 | const int *ref_sign_bias = cm->ref_frame_sign_bias; |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 1108 | const int sb_mi_size = mi_size_wide[cm->seq_params.sb_size]; |
Yunqing Wang | 880ab1c | 2018-02-02 15:24:06 -0800 | [diff] [blame] | 1109 | int i; |
Yunqing Wang | b41ffb9 | 2018-01-25 15:58:02 -0800 | [diff] [blame] | 1110 | int context_counter = 0; |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 1111 | |
Zoe Liu | 294f59d | 2017-10-31 23:02:04 -0700 | [diff] [blame] | 1112 | #if CONFIG_MFMV |
| 1113 | (void)sync; |
| 1114 | (void)data; |
| 1115 | #else |
| 1116 | #if CONFIG_TMV |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 1117 | int tmi_row = mi_row & 0xfffe; |
| 1118 | int tmi_col = mi_col & 0xfffe; |
| 1119 | POSITION mi_pos = { 0, 0 }; |
| 1120 | int inside = is_inside(&xd->tile, tmi_col, tmi_row, cm->mi_rows, cm, &mi_pos); |
| 1121 | const MV_REF *const prev_frame_mvs = |
| 1122 | cm->use_prev_frame_mvs && inside |
| 1123 | ? cm->prev_frame->mvs + (tmi_row >> 1) * ((cm->mi_cols + 1) >> 1) + |
| 1124 | (tmi_col >> 1) |
| 1125 | : NULL; |
| 1126 | #else |
zhipin deng | eb019b8 | 2017-02-17 17:49:03 +0800 | [diff] [blame] | 1127 | const TileInfo *const tile_ = &xd->tile; |
| 1128 | int mi_row_end = tile_->mi_row_end; |
| 1129 | int mi_col_end = tile_->mi_col_end; |
| 1130 | const MV_REF *const prev_frame_mvs = |
| 1131 | cm->use_prev_frame_mvs |
| 1132 | ? cm->prev_frame->mvs + |
| 1133 | AOMMIN(((mi_row >> 1) << 1) + 1 + (((xd->n8_h - 1) >> 1) << 1), |
| 1134 | mi_row_end - 1) * |
| 1135 | cm->mi_cols + |
| 1136 | AOMMIN(((mi_col >> 1) << 1) + 1 + (((xd->n8_w - 1) >> 1) << 1), |
| 1137 | mi_col_end - 1) |
| 1138 | : NULL; |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 1139 | #endif // CONFIG_TMV |
Zoe Liu | 294f59d | 2017-10-31 23:02:04 -0700 | [diff] [blame] | 1140 | #endif // CONFIG_MFMV |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 1141 | |
Alex Converse | 44c2bad | 2017-05-11 09:36:10 -0700 | [diff] [blame] | 1142 | #if CONFIG_INTRABC |
| 1143 | assert(IMPLIES(ref_frame == INTRA_FRAME, cm->use_prev_frame_mvs == 0)); |
| 1144 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1145 | const TileInfo *const tile = &xd->tile; |
Jingning Han | c016df8 | 2016-12-09 12:37:28 -0800 | [diff] [blame] | 1146 | const BLOCK_SIZE bsize = mi->mbmi.sb_type; |
| 1147 | const int bw = block_size_wide[AOMMAX(bsize, BLOCK_8X8)]; |
| 1148 | const int bh = block_size_high[AOMMAX(bsize, BLOCK_8X8)]; |
Deng | ca8d24d | 2016-10-17 14:06:35 +0800 | [diff] [blame] | 1149 | POSITION mv_ref_search[MVREF_NEIGHBOURS]; |
Jingning Han | c016df8 | 2016-12-09 12:37:28 -0800 | [diff] [blame] | 1150 | const int num_8x8_blocks_wide = num_8x8_blocks_wide_lookup[bsize]; |
| 1151 | const int num_8x8_blocks_high = num_8x8_blocks_high_lookup[bsize]; |
Deng | ca8d24d | 2016-10-17 14:06:35 +0800 | [diff] [blame] | 1152 | mv_ref_search[0].row = num_8x8_blocks_high - 1; |
| 1153 | mv_ref_search[0].col = -1; |
| 1154 | mv_ref_search[1].row = -1; |
| 1155 | mv_ref_search[1].col = num_8x8_blocks_wide - 1; |
| 1156 | mv_ref_search[2].row = -1; |
| 1157 | mv_ref_search[2].col = (num_8x8_blocks_wide - 1) >> 1; |
| 1158 | mv_ref_search[3].row = (num_8x8_blocks_high - 1) >> 1; |
| 1159 | mv_ref_search[3].col = -1; |
| 1160 | mv_ref_search[4].row = -1; |
| 1161 | mv_ref_search[4].col = -1; |
Debargha Mukherjee | ff59b6a | 2017-01-26 08:50:48 -0800 | [diff] [blame] | 1162 | #if CONFIG_EXT_PARTITION_TYPES |
| 1163 | if (num_8x8_blocks_wide == num_8x8_blocks_high) { |
| 1164 | mv_ref_search[5].row = -1; |
| 1165 | mv_ref_search[5].col = 0; |
| 1166 | mv_ref_search[6].row = 0; |
| 1167 | mv_ref_search[6].col = -1; |
| 1168 | } else { |
| 1169 | mv_ref_search[5].row = -1; |
| 1170 | mv_ref_search[5].col = num_8x8_blocks_wide; |
| 1171 | mv_ref_search[6].row = num_8x8_blocks_high; |
| 1172 | mv_ref_search[6].col = -1; |
| 1173 | } |
| 1174 | #else |
Deng | ca8d24d | 2016-10-17 14:06:35 +0800 | [diff] [blame] | 1175 | mv_ref_search[5].row = -1; |
| 1176 | mv_ref_search[5].col = num_8x8_blocks_wide; |
| 1177 | mv_ref_search[6].row = num_8x8_blocks_high; |
| 1178 | mv_ref_search[6].col = -1; |
Debargha Mukherjee | ff59b6a | 2017-01-26 08:50:48 -0800 | [diff] [blame] | 1179 | #endif // CONFIG_EXT_PARTITION_TYPES |
Deng | ca8d24d | 2016-10-17 14:06:35 +0800 | [diff] [blame] | 1180 | mv_ref_search[7].row = -1; |
| 1181 | mv_ref_search[7].col = -3; |
| 1182 | mv_ref_search[8].row = num_8x8_blocks_high - 1; |
| 1183 | mv_ref_search[8].col = -3; |
Jingning Han | c016df8 | 2016-12-09 12:37:28 -0800 | [diff] [blame] | 1184 | |
Jingning Han | c016df8 | 2016-12-09 12:37:28 -0800 | [diff] [blame] | 1185 | for (i = 0; i < MVREF_NEIGHBOURS; ++i) { |
| 1186 | mv_ref_search[i].row *= 2; |
| 1187 | mv_ref_search[i].col *= 2; |
| 1188 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1189 | |
| 1190 | // The nearest 2 blocks are treated differently |
| 1191 | // if the size < 8x8 we get the mv from the bmi substructure, |
| 1192 | // and we also need to keep a mode count. |
| 1193 | for (i = 0; i < 2; ++i) { |
| 1194 | const POSITION *const mv_ref = &mv_ref_search[i]; |
Yaowu Xu | 531d6af | 2017-03-07 17:48:52 -0800 | [diff] [blame] | 1195 | if (is_inside(tile, mi_col, mi_row, cm->mi_rows, cm, mv_ref)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1196 | const MODE_INFO *const candidate_mi = |
| 1197 | xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride]; |
| 1198 | const MB_MODE_INFO *const candidate = &candidate_mi->mbmi; |
Hui Su | 1e68d5d | 2017-11-02 12:31:52 -0700 | [diff] [blame] | 1199 | #if CONFIG_INTRABC |
| 1200 | if (ref_frame == INTRA_FRAME && !is_intrabc_block(candidate)) continue; |
| 1201 | #endif // CONFIG_INTRABC |
Yunqing Wang | b41ffb9 | 2018-01-25 15:58:02 -0800 | [diff] [blame] | 1202 | // Keep counts for entropy encoding. |
| 1203 | context_counter += mode_2_counter[candidate->mode]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1204 | } |
| 1205 | } |
| 1206 | |
Yunqing Wang | 880ab1c | 2018-02-02 15:24:06 -0800 | [diff] [blame] | 1207 | if (refmv_count >= MAX_MV_REF_CANDIDATES) goto Done; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1208 | |
| 1209 | // TODO(hkuang): Remove this sync after fixing pthread_cond_broadcast |
| 1210 | // on windows platform. The sync here is unncessary if use_perv_frame_mvs |
| 1211 | // is 0. But after removing it, there will be hang in the unit test on windows |
| 1212 | // due to several threads waiting for a thread's signal. |
| 1213 | #if defined(_WIN32) && !HAVE_PTHREAD_H |
| 1214 | if (cm->frame_parallel_decode && sync != NULL) { |
| 1215 | sync(data, mi_row); |
| 1216 | } |
| 1217 | #endif |
| 1218 | |
Zoe Liu | 294f59d | 2017-10-31 23:02:04 -0700 | [diff] [blame] | 1219 | #if !CONFIG_MFMV |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1220 | // Check the last frame's mode and mv info. |
| 1221 | if (cm->use_prev_frame_mvs) { |
| 1222 | // Synchronize here for frame parallel decode if sync function is provided. |
| 1223 | if (cm->frame_parallel_decode && sync != NULL) { |
| 1224 | sync(data, mi_row); |
| 1225 | } |
| 1226 | |
| 1227 | if (prev_frame_mvs->ref_frame[0] == ref_frame) { |
| 1228 | ADD_MV_REF_LIST(prev_frame_mvs->mv[0], refmv_count, mv_ref_list, bw, bh, |
| 1229 | xd, Done); |
| 1230 | } else if (prev_frame_mvs->ref_frame[1] == ref_frame) { |
| 1231 | ADD_MV_REF_LIST(prev_frame_mvs->mv[1], refmv_count, mv_ref_list, bw, bh, |
| 1232 | xd, Done); |
| 1233 | } |
| 1234 | } |
Zoe Liu | 294f59d | 2017-10-31 23:02:04 -0700 | [diff] [blame] | 1235 | #endif // !CONFIG_MFMV |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1236 | |
Jonathan Matthews | dca1925 | 2018-02-05 14:34:32 +0000 | [diff] [blame] | 1237 | // Since we couldn't find 2 mvs from the same reference frame |
| 1238 | // go back through the neighbors and find motion vectors from |
| 1239 | // different reference frames. |
Hui Su | 1e68d5d | 2017-11-02 12:31:52 -0700 | [diff] [blame] | 1240 | #if CONFIG_INTRABC |
Jonathan Matthews | dca1925 | 2018-02-05 14:34:32 +0000 | [diff] [blame] | 1241 | if (ref_frame != INTRA_FRAME) { |
Hui Su | 1e68d5d | 2017-11-02 12:31:52 -0700 | [diff] [blame] | 1242 | #endif // CONFIG_INTRABC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1243 | for (i = 0; i < MVREF_NEIGHBOURS; ++i) { |
| 1244 | const POSITION *mv_ref = &mv_ref_search[i]; |
Yaowu Xu | 531d6af | 2017-03-07 17:48:52 -0800 | [diff] [blame] | 1245 | if (is_inside(tile, mi_col, mi_row, cm->mi_rows, cm, mv_ref)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1246 | const MB_MODE_INFO *const candidate = |
Yaowu Xu | f0602bb | 2016-12-14 09:30:03 -0800 | [diff] [blame] | 1247 | !xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride] |
| 1248 | ? NULL |
| 1249 | : &xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride]->mbmi; |
Yaowu Xu | 750955b | 2016-10-31 08:55:27 -0700 | [diff] [blame] | 1250 | if (candidate == NULL) continue; |
David Barker | 761b1ac | 2017-09-25 11:23:03 +0100 | [diff] [blame] | 1251 | if ((mi_row & (sb_mi_size - 1)) + mv_ref->row >= sb_mi_size || |
| 1252 | (mi_col & (sb_mi_size - 1)) + mv_ref->col >= sb_mi_size) |
Deng | ca8d24d | 2016-10-17 14:06:35 +0800 | [diff] [blame] | 1253 | continue; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1254 | |
| 1255 | // If the candidate is INTRA we don't want to consider its mv. |
| 1256 | IF_DIFF_REF_FRAME_ADD_MV(candidate, ref_frame, ref_sign_bias, |
| 1257 | refmv_count, mv_ref_list, bw, bh, xd, Done); |
| 1258 | } |
| 1259 | } |
Jonathan Matthews | dca1925 | 2018-02-05 14:34:32 +0000 | [diff] [blame] | 1260 | #if CONFIG_INTRABC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1261 | } |
Jonathan Matthews | dca1925 | 2018-02-05 14:34:32 +0000 | [diff] [blame] | 1262 | #endif // CONFIG_INTRABC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1263 | |
Zoe Liu | 294f59d | 2017-10-31 23:02:04 -0700 | [diff] [blame] | 1264 | #if !CONFIG_MFMV |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1265 | // Since we still don't have a candidate we'll try the last frame. |
| 1266 | if (cm->use_prev_frame_mvs) { |
| 1267 | if (prev_frame_mvs->ref_frame[0] != ref_frame && |
| 1268 | prev_frame_mvs->ref_frame[0] > INTRA_FRAME) { |
| 1269 | int_mv mv = prev_frame_mvs->mv[0]; |
| 1270 | if (ref_sign_bias[prev_frame_mvs->ref_frame[0]] != |
| 1271 | ref_sign_bias[ref_frame]) { |
| 1272 | mv.as_mv.row *= -1; |
| 1273 | mv.as_mv.col *= -1; |
| 1274 | } |
| 1275 | ADD_MV_REF_LIST(mv, refmv_count, mv_ref_list, bw, bh, xd, Done); |
| 1276 | } |
| 1277 | |
| 1278 | if (prev_frame_mvs->ref_frame[1] > INTRA_FRAME && |
| 1279 | prev_frame_mvs->ref_frame[1] != ref_frame) { |
| 1280 | int_mv mv = prev_frame_mvs->mv[1]; |
| 1281 | if (ref_sign_bias[prev_frame_mvs->ref_frame[1]] != |
| 1282 | ref_sign_bias[ref_frame]) { |
| 1283 | mv.as_mv.row *= -1; |
| 1284 | mv.as_mv.col *= -1; |
| 1285 | } |
| 1286 | ADD_MV_REF_LIST(mv, refmv_count, mv_ref_list, bw, bh, xd, Done); |
| 1287 | } |
| 1288 | } |
Zoe Liu | 294f59d | 2017-10-31 23:02:04 -0700 | [diff] [blame] | 1289 | #endif // !CONFIG_MFMV |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1290 | |
| 1291 | Done: |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1292 | if (mode_context) |
| 1293 | mode_context[ref_frame] = counter_to_context[context_counter]; |
Yunqing Wang | b41ffb9 | 2018-01-25 15:58:02 -0800 | [diff] [blame] | 1294 | for (i = refmv_count; i < MAX_MV_REF_CANDIDATES; ++i) |
| 1295 | mv_ref_list[i].as_int = zeromv.as_int; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1296 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1297 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1298 | void av1_find_mv_refs(const AV1_COMMON *cm, const MACROBLOCKD *xd, |
| 1299 | MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame, |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 1300 | uint8_t ref_mv_count[MODE_CTX_REF_FRAMES], |
| 1301 | CANDIDATE_MV ref_mv_stack[][MAX_REF_MV_STACK_SIZE], |
| 1302 | int16_t *compound_mode_context, |
| 1303 | int_mv mv_ref_list[][MAX_MV_REF_CANDIDATES], int mi_row, |
| 1304 | int mi_col, find_mv_refs_sync sync, void *const data, |
| 1305 | int16_t *mode_context, int compound_search) { |
David Barker | cdcac6d | 2016-12-01 17:04:16 +0000 | [diff] [blame] | 1306 | int_mv zeromv[2]; |
Debargha Mukherjee | 0bae624 | 2017-05-02 21:54:41 -0700 | [diff] [blame] | 1307 | BLOCK_SIZE bsize = mi->mbmi.sb_type; |
David Barker | cdcac6d | 2016-12-01 17:04:16 +0000 | [diff] [blame] | 1308 | MV_REFERENCE_FRAME rf[2]; |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 1309 | av1_set_ref_frame(rf, ref_frame); |
Alex Converse | 7d5559c | 2017-06-14 12:32:35 -0700 | [diff] [blame] | 1310 | if (!CONFIG_INTRABC || ref_frame != INTRA_FRAME) { |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 1311 | zeromv[0].as_int = |
| 1312 | gm_get_motion_vector(&cm->global_motion[rf[0]], |
| 1313 | cm->allow_high_precision_mv, bsize, mi_col, mi_row |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1314 | #if CONFIG_AMVR |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 1315 | , |
| 1316 | cm->cur_frame_force_integer_mv |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1317 | #endif |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 1318 | ) |
| 1319 | .as_int; |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 1320 | zeromv[1].as_int = (rf[1] != NONE_FRAME) |
| 1321 | ? gm_get_motion_vector(&cm->global_motion[rf[1]], |
| 1322 | cm->allow_high_precision_mv, |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 1323 | bsize, mi_col, mi_row |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1324 | #if CONFIG_AMVR |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 1325 | , |
| 1326 | cm->cur_frame_force_integer_mv |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1327 | #endif |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 1328 | ) |
| 1329 | .as_int |
| 1330 | : 0; |
Alex Converse | 7d5559c | 2017-06-14 12:32:35 -0700 | [diff] [blame] | 1331 | } else { |
| 1332 | zeromv[0].as_int = zeromv[1].as_int = 0; |
| 1333 | } |
David Barker | cdcac6d | 2016-12-01 17:04:16 +0000 | [diff] [blame] | 1334 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1335 | setup_ref_mv_list(cm, xd, ref_frame, ref_mv_count, ref_mv_stack, mv_ref_list, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 1336 | #if USE_CUR_GM_REFMV |
Sarah Parker | 0a5cc5f | 2017-10-03 17:53:53 -0700 | [diff] [blame] | 1337 | zeromv, |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 1338 | #endif // USE_CUR_GM_REFMV |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 1339 | mi_row, mi_col, mode_context, compound_search); |
Yunqing Wang | 880ab1c | 2018-02-02 15:24:06 -0800 | [diff] [blame] | 1340 | |
Jingning Han | ff1a35b | 2018-02-09 20:17:50 -0800 | [diff] [blame^] | 1341 | #if !CONFIG_OPT_REF_MV |
Yunqing Wang | 880ab1c | 2018-02-02 15:24:06 -0800 | [diff] [blame] | 1342 | if (ref_frame <= ALTREF_FRAME) |
Yunqing Wang | 02efe6a | 2018-02-07 15:12:38 -0800 | [diff] [blame] | 1343 | find_mv_refs_idx(cm, xd, mi, ref_frame, mv_ref_list[rf[0]], mi_row, mi_col, |
| 1344 | sync, data, compound_mode_context, zeromv[0], |
| 1345 | ref_mv_count[ref_frame]); |
Jingning Han | ff1a35b | 2018-02-09 20:17:50 -0800 | [diff] [blame^] | 1346 | #else |
| 1347 | (void)compound_mode_context; |
| 1348 | (void)data; |
| 1349 | (void)sync; |
| 1350 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1351 | } |
| 1352 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1353 | void av1_find_best_ref_mvs(int allow_hp, int_mv *mvlist, int_mv *nearest_mv, |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1354 | int_mv *near_mv |
| 1355 | #if CONFIG_AMVR |
| 1356 | , |
| 1357 | int is_integer |
| 1358 | #endif |
Johann | 6b41d4d | 2018-02-08 14:32:53 -0800 | [diff] [blame] | 1359 | ) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1360 | int i; |
| 1361 | // Make sure all the candidates are properly clamped etc |
| 1362 | for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1363 | #if CONFIG_AMVR |
| 1364 | lower_mv_precision(&mvlist[i].as_mv, allow_hp, is_integer); |
| 1365 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1366 | lower_mv_precision(&mvlist[i].as_mv, allow_hp); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1367 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1368 | } |
| 1369 | *nearest_mv = mvlist[0]; |
| 1370 | *near_mv = mvlist[1]; |
| 1371 | } |
| 1372 | |
Jingning Han | c723b34 | 2017-08-24 11:19:46 -0700 | [diff] [blame] | 1373 | void av1_setup_frame_buf_refs(AV1_COMMON *cm) { |
| 1374 | cm->cur_frame->cur_frame_offset = cm->frame_offset; |
| 1375 | int alt_buf_idx = cm->frame_refs[ALTREF_FRAME - LAST_FRAME].idx; |
| 1376 | int lst_buf_idx = cm->frame_refs[LAST_FRAME - LAST_FRAME].idx; |
| 1377 | int gld_buf_idx = cm->frame_refs[GOLDEN_FRAME - LAST_FRAME].idx; |
| 1378 | |
Jingning Han | c723b34 | 2017-08-24 11:19:46 -0700 | [diff] [blame] | 1379 | int lst2_buf_idx = cm->frame_refs[LAST2_FRAME - LAST_FRAME].idx; |
| 1380 | int lst3_buf_idx = cm->frame_refs[LAST3_FRAME - LAST_FRAME].idx; |
| 1381 | int bwd_buf_idx = cm->frame_refs[BWDREF_FRAME - LAST_FRAME].idx; |
Jingning Han | 94a504a | 2017-09-18 16:17:02 -0700 | [diff] [blame] | 1382 | int alt2_buf_idx = cm->frame_refs[ALTREF2_FRAME - LAST_FRAME].idx; |
Jingning Han | c723b34 | 2017-08-24 11:19:46 -0700 | [diff] [blame] | 1383 | |
| 1384 | if (alt_buf_idx >= 0) |
| 1385 | cm->cur_frame->alt_frame_offset = |
| 1386 | cm->buffer_pool->frame_bufs[alt_buf_idx].cur_frame_offset; |
| 1387 | |
| 1388 | if (lst_buf_idx >= 0) |
| 1389 | cm->cur_frame->lst_frame_offset = |
| 1390 | cm->buffer_pool->frame_bufs[lst_buf_idx].cur_frame_offset; |
| 1391 | |
| 1392 | if (gld_buf_idx >= 0) |
| 1393 | cm->cur_frame->gld_frame_offset = |
| 1394 | cm->buffer_pool->frame_bufs[gld_buf_idx].cur_frame_offset; |
| 1395 | |
Jingning Han | c723b34 | 2017-08-24 11:19:46 -0700 | [diff] [blame] | 1396 | if (lst2_buf_idx >= 0) |
| 1397 | cm->cur_frame->lst2_frame_offset = |
| 1398 | cm->buffer_pool->frame_bufs[lst2_buf_idx].cur_frame_offset; |
| 1399 | |
| 1400 | if (lst3_buf_idx >= 0) |
| 1401 | cm->cur_frame->lst3_frame_offset = |
| 1402 | cm->buffer_pool->frame_bufs[lst3_buf_idx].cur_frame_offset; |
| 1403 | |
| 1404 | if (bwd_buf_idx >= 0) |
| 1405 | cm->cur_frame->bwd_frame_offset = |
| 1406 | cm->buffer_pool->frame_bufs[bwd_buf_idx].cur_frame_offset; |
Jingning Han | 94a504a | 2017-09-18 16:17:02 -0700 | [diff] [blame] | 1407 | |
| 1408 | if (alt2_buf_idx >= 0) |
| 1409 | cm->cur_frame->alt2_frame_offset = |
| 1410 | cm->buffer_pool->frame_bufs[alt2_buf_idx].cur_frame_offset; |
Jingning Han | c723b34 | 2017-08-24 11:19:46 -0700 | [diff] [blame] | 1411 | } |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 1412 | |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 1413 | void av1_setup_frame_sign_bias(AV1_COMMON *cm) { |
| 1414 | MV_REFERENCE_FRAME ref_frame; |
| 1415 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 1416 | const int buf_idx = cm->frame_refs[ref_frame - LAST_FRAME].idx; |
| 1417 | if (buf_idx != INVALID_IDX) { |
| 1418 | const int ref_frame_offset = |
| 1419 | cm->buffer_pool->frame_bufs[buf_idx].cur_frame_offset; |
| 1420 | cm->ref_frame_sign_bias[ref_frame] = |
| 1421 | (ref_frame_offset <= (int)cm->frame_offset) ? 0 : 1; |
| 1422 | } else { |
| 1423 | cm->ref_frame_sign_bias[ref_frame] = 0; |
| 1424 | } |
| 1425 | } |
| 1426 | } |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 1427 | |
Zoe Liu | feb1ebe | 2017-12-19 13:57:28 -0800 | [diff] [blame] | 1428 | #if CONFIG_MFMV |
Jingning Han | b74a72b | 2017-09-02 08:55:51 -0700 | [diff] [blame] | 1429 | #define MAX_OFFSET_WIDTH 64 |
Jingning Han | f1639a1 | 2017-10-21 17:21:18 -0700 | [diff] [blame] | 1430 | #define MAX_OFFSET_HEIGHT 0 |
Jingning Han | b74a72b | 2017-09-02 08:55:51 -0700 | [diff] [blame] | 1431 | |
Jingning Han | 5c70091 | 2017-09-03 16:06:51 -0700 | [diff] [blame] | 1432 | static int get_block_position(AV1_COMMON *cm, int *mi_r, int *mi_c, int blk_row, |
Jingning Han | e84eec5 | 2017-09-01 16:49:29 -0700 | [diff] [blame] | 1433 | int blk_col, MV mv, int sign_bias) { |
Jingning Han | 7f537b8 | 2017-10-16 08:47:27 -0700 | [diff] [blame] | 1434 | const int base_blk_row = (blk_row >> 3) << 3; |
| 1435 | const int base_blk_col = (blk_col >> 3) << 3; |
Jingning Han | b74a72b | 2017-09-02 08:55:51 -0700 | [diff] [blame] | 1436 | |
Jingning Han | f5b8068 | 2017-10-23 09:30:01 -0700 | [diff] [blame] | 1437 | const int row_offset = (mv.row >= 0) ? (mv.row >> (4 + MI_SIZE_LOG2)) |
| 1438 | : -((-mv.row) >> (4 + MI_SIZE_LOG2)); |
| 1439 | |
| 1440 | const int col_offset = (mv.col >= 0) ? (mv.col >> (4 + MI_SIZE_LOG2)) |
| 1441 | : -((-mv.col) >> (4 + MI_SIZE_LOG2)); |
| 1442 | |
| 1443 | int row = (sign_bias == 1) ? blk_row - row_offset : blk_row + row_offset; |
| 1444 | int col = (sign_bias == 1) ? blk_col - col_offset : blk_col + col_offset; |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 1445 | |
Jingning Han | c7d198e | 2017-10-12 16:11:06 -0700 | [diff] [blame] | 1446 | if (row < 0 || row >= (cm->mi_rows >> 1) || col < 0 || |
| 1447 | col >= (cm->mi_cols >> 1)) |
| 1448 | return 0; |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 1449 | |
Jingning Han | f1639a1 | 2017-10-21 17:21:18 -0700 | [diff] [blame] | 1450 | if (row <= base_blk_row - (MAX_OFFSET_HEIGHT >> 3) || |
| 1451 | row >= base_blk_row + 8 + (MAX_OFFSET_HEIGHT >> 3) || |
Jingning Han | 7f537b8 | 2017-10-16 08:47:27 -0700 | [diff] [blame] | 1452 | col <= base_blk_col - (MAX_OFFSET_WIDTH >> 3) || |
Jingning Han | f1639a1 | 2017-10-21 17:21:18 -0700 | [diff] [blame] | 1453 | col >= base_blk_col + 8 + (MAX_OFFSET_WIDTH >> 3)) |
Jingning Han | 7f537b8 | 2017-10-16 08:47:27 -0700 | [diff] [blame] | 1454 | return 0; |
| 1455 | |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 1456 | *mi_r = row; |
| 1457 | *mi_c = col; |
Jingning Han | e84eec5 | 2017-09-01 16:49:29 -0700 | [diff] [blame] | 1458 | |
| 1459 | return 1; |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 1460 | } |
| 1461 | |
Jingning Han | fbfe880 | 2017-12-05 11:14:42 -0800 | [diff] [blame] | 1462 | static int motion_field_projection(AV1_COMMON *cm, MV_REFERENCE_FRAME ref_frame, |
| 1463 | int ref_stamp, int dir) { |
Jingning Han | 3bd1bc2 | 2017-10-18 16:51:23 -0700 | [diff] [blame] | 1464 | TPL_MV_REF *tpl_mvs_base = cm->tpl_mvs; |
Jingning Han | c2c3c87 | 2017-12-04 15:30:56 -0800 | [diff] [blame] | 1465 | int cur_rf_index[TOTAL_REFS_PER_FRAME] = { 0 }; |
| 1466 | int ref_rf_idx[TOTAL_REFS_PER_FRAME] = { 0 }; |
| 1467 | int cur_offset[TOTAL_REFS_PER_FRAME] = { 0 }; |
| 1468 | int ref_offset[TOTAL_REFS_PER_FRAME] = { 0 }; |
Jingning Han | 3bd1bc2 | 2017-10-18 16:51:23 -0700 | [diff] [blame] | 1469 | |
Jingning Han | c2c3c87 | 2017-12-04 15:30:56 -0800 | [diff] [blame] | 1470 | (void)dir; |
Jingning Han | 3bd1bc2 | 2017-10-18 16:51:23 -0700 | [diff] [blame] | 1471 | |
| 1472 | int ref_frame_idx = cm->frame_refs[FWD_RF_OFFSET(ref_frame)].idx; |
Jingning Han | fbfe880 | 2017-12-05 11:14:42 -0800 | [diff] [blame] | 1473 | if (ref_frame_idx < 0) return 0; |
| 1474 | |
Jingning Han | a06e059 | 2018-01-09 10:01:40 -0800 | [diff] [blame] | 1475 | if (cm->buffer_pool->frame_bufs[ref_frame_idx].mi_rows != cm->mi_rows || |
| 1476 | cm->buffer_pool->frame_bufs[ref_frame_idx].mi_cols != cm->mi_cols) |
| 1477 | return 0; |
| 1478 | |
Jingning Han | 3bd1bc2 | 2017-10-18 16:51:23 -0700 | [diff] [blame] | 1479 | int ref_frame_index = |
| 1480 | cm->buffer_pool->frame_bufs[ref_frame_idx].cur_frame_offset; |
Jingning Han | c2c3c87 | 2017-12-04 15:30:56 -0800 | [diff] [blame] | 1481 | int cur_frame_index = cm->cur_frame->cur_frame_offset; |
| 1482 | int ref_to_cur = ref_frame_index - cur_frame_index; |
Jingning Han | 3bd1bc2 | 2017-10-18 16:51:23 -0700 | [diff] [blame] | 1483 | |
Jingning Han | c2c3c87 | 2017-12-04 15:30:56 -0800 | [diff] [blame] | 1484 | ref_rf_idx[LAST_FRAME] = |
| 1485 | cm->buffer_pool->frame_bufs[ref_frame_idx].lst_frame_offset; |
| 1486 | ref_rf_idx[GOLDEN_FRAME] = |
| 1487 | cm->buffer_pool->frame_bufs[ref_frame_idx].gld_frame_offset; |
| 1488 | ref_rf_idx[LAST2_FRAME] = |
| 1489 | cm->buffer_pool->frame_bufs[ref_frame_idx].lst2_frame_offset; |
| 1490 | ref_rf_idx[LAST3_FRAME] = |
| 1491 | cm->buffer_pool->frame_bufs[ref_frame_idx].lst3_frame_offset; |
| 1492 | ref_rf_idx[BWDREF_FRAME] = |
| 1493 | cm->buffer_pool->frame_bufs[ref_frame_idx].bwd_frame_offset; |
| 1494 | ref_rf_idx[ALTREF2_FRAME] = |
| 1495 | cm->buffer_pool->frame_bufs[ref_frame_idx].alt2_frame_offset; |
| 1496 | ref_rf_idx[ALTREF_FRAME] = |
| 1497 | cm->buffer_pool->frame_bufs[ref_frame_idx].alt_frame_offset; |
Jingning Han | 3bd1bc2 | 2017-10-18 16:51:23 -0700 | [diff] [blame] | 1498 | |
Jingning Han | c2c3c87 | 2017-12-04 15:30:56 -0800 | [diff] [blame] | 1499 | for (MV_REFERENCE_FRAME rf = LAST_FRAME; rf <= INTER_REFS_PER_FRAME; ++rf) { |
| 1500 | int buf_idx = cm->frame_refs[FWD_RF_OFFSET(rf)].idx; |
| 1501 | if (buf_idx >= 0) |
| 1502 | cur_rf_index[rf] = cm->buffer_pool->frame_bufs[buf_idx].cur_frame_offset; |
| 1503 | cur_offset[rf] = cur_frame_index - cur_rf_index[rf]; |
| 1504 | ref_offset[rf] = ref_frame_index - ref_rf_idx[rf]; |
| 1505 | } |
Jingning Han | 3bd1bc2 | 2017-10-18 16:51:23 -0700 | [diff] [blame] | 1506 | |
Jingning Han | fbfe880 | 2017-12-05 11:14:42 -0800 | [diff] [blame] | 1507 | if (dir == 1) { |
| 1508 | ref_to_cur = -ref_to_cur; |
| 1509 | for (MV_REFERENCE_FRAME rf = LAST_FRAME; rf <= INTER_REFS_PER_FRAME; ++rf) { |
| 1510 | cur_offset[rf] = -cur_offset[rf]; |
| 1511 | ref_offset[rf] = -ref_offset[rf]; |
| 1512 | } |
| 1513 | } |
| 1514 | |
| 1515 | if (dir == 2) ref_to_cur = -ref_to_cur; |
| 1516 | |
Jingning Han | 3bd1bc2 | 2017-10-18 16:51:23 -0700 | [diff] [blame] | 1517 | MV_REF *mv_ref_base = cm->buffer_pool->frame_bufs[ref_frame_idx].mvs; |
Jingning Han | 3bd1bc2 | 2017-10-18 16:51:23 -0700 | [diff] [blame] | 1518 | const int mvs_rows = (cm->mi_rows + 1) >> 1; |
| 1519 | const int mvs_cols = (cm->mi_cols + 1) >> 1; |
| 1520 | |
| 1521 | for (int blk_row = 0; blk_row < mvs_rows; ++blk_row) { |
| 1522 | for (int blk_col = 0; blk_col < mvs_cols; ++blk_col) { |
| 1523 | MV_REF *mv_ref = &mv_ref_base[blk_row * mvs_cols + blk_col]; |
Jingning Han | fbfe880 | 2017-12-05 11:14:42 -0800 | [diff] [blame] | 1524 | MV fwd_mv = mv_ref->mv[dir & 0x01].as_mv; |
Jingning Han | 3bd1bc2 | 2017-10-18 16:51:23 -0700 | [diff] [blame] | 1525 | |
Jingning Han | fbfe880 | 2017-12-05 11:14:42 -0800 | [diff] [blame] | 1526 | if (mv_ref->ref_frame[dir & 0x01] > INTRA_FRAME) { |
Jingning Han | 3bd1bc2 | 2017-10-18 16:51:23 -0700 | [diff] [blame] | 1527 | int_mv this_mv; |
| 1528 | int mi_r, mi_c; |
Jingning Han | 74f839b | 2018-01-09 11:54:30 -0800 | [diff] [blame] | 1529 | const int ref_frame_offset = ref_offset[mv_ref->ref_frame[dir & 0x01]]; |
Jingning Han | 3bd1bc2 | 2017-10-18 16:51:23 -0700 | [diff] [blame] | 1530 | |
Jingning Han | c2c3c87 | 2017-12-04 15:30:56 -0800 | [diff] [blame] | 1531 | get_mv_projection(&this_mv.as_mv, fwd_mv, ref_to_cur, ref_frame_offset); |
Jingning Han | 3bd1bc2 | 2017-10-18 16:51:23 -0700 | [diff] [blame] | 1532 | int pos_valid = get_block_position(cm, &mi_r, &mi_c, blk_row, blk_col, |
Jingning Han | fbfe880 | 2017-12-05 11:14:42 -0800 | [diff] [blame] | 1533 | this_mv.as_mv, dir >> 1); |
Jingning Han | 3bd1bc2 | 2017-10-18 16:51:23 -0700 | [diff] [blame] | 1534 | if (pos_valid) { |
| 1535 | int mi_offset = mi_r * (cm->mi_stride >> 1) + mi_c; |
| 1536 | |
Frank Bossen | 7b6bb94 | 2018-01-25 07:49:52 -0500 | [diff] [blame] | 1537 | tpl_mvs_base[mi_offset].mfmv0[ref_stamp].as_mv.row = |
| 1538 | (dir == 1) ? -fwd_mv.row : fwd_mv.row; |
| 1539 | tpl_mvs_base[mi_offset].mfmv0[ref_stamp].as_mv.col = |
| 1540 | (dir == 1) ? -fwd_mv.col : fwd_mv.col; |
| 1541 | tpl_mvs_base[mi_offset].ref_frame_offset[ref_stamp] = |
| 1542 | ref_frame_offset; |
Jingning Han | 3bd1bc2 | 2017-10-18 16:51:23 -0700 | [diff] [blame] | 1543 | } |
| 1544 | } |
| 1545 | } |
| 1546 | } |
Jingning Han | fbfe880 | 2017-12-05 11:14:42 -0800 | [diff] [blame] | 1547 | |
| 1548 | return 1; |
Jingning Han | 3bd1bc2 | 2017-10-18 16:51:23 -0700 | [diff] [blame] | 1549 | } |
| 1550 | |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 1551 | void av1_setup_motion_field(AV1_COMMON *cm) { |
| 1552 | int cur_frame_index = cm->cur_frame->cur_frame_offset; |
Jingning Han | fbfe880 | 2017-12-05 11:14:42 -0800 | [diff] [blame] | 1553 | int alt_frame_index = 0, gld_frame_index = 0; |
Jingning Han | 94a504a | 2017-09-18 16:17:02 -0700 | [diff] [blame] | 1554 | int bwd_frame_index = 0, alt2_frame_index = 0; |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 1555 | |
Jingning Han | fbfe880 | 2017-12-05 11:14:42 -0800 | [diff] [blame] | 1556 | TPL_MV_REF *tpl_mvs_base = cm->tpl_mvs; |
Frank Bossen | 7b6bb94 | 2018-01-25 07:49:52 -0500 | [diff] [blame] | 1557 | int size = ((cm->mi_rows + MAX_MIB_SIZE) >> 1) * (cm->mi_stride >> 1); |
| 1558 | for (int idx = 0; idx < size; ++idx) { |
| 1559 | for (int i = 0; i < MFMV_STACK_SIZE; ++i) { |
| 1560 | tpl_mvs_base[idx].mfmv0[i].as_int = INVALID_MV; |
| 1561 | tpl_mvs_base[idx].ref_frame_offset[i] = 0; |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 1562 | } |
| 1563 | } |
| 1564 | |
Jingning Han | fbfe880 | 2017-12-05 11:14:42 -0800 | [diff] [blame] | 1565 | int gld_buf_idx = cm->frame_refs[GOLDEN_FRAME - LAST_FRAME].idx; |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 1566 | int alt_buf_idx = cm->frame_refs[ALTREF_FRAME - LAST_FRAME].idx; |
| 1567 | int lst_buf_idx = cm->frame_refs[LAST_FRAME - LAST_FRAME].idx; |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 1568 | int bwd_buf_idx = cm->frame_refs[BWDREF_FRAME - LAST_FRAME].idx; |
Jingning Han | 94a504a | 2017-09-18 16:17:02 -0700 | [diff] [blame] | 1569 | int alt2_buf_idx = cm->frame_refs[ALTREF2_FRAME - LAST_FRAME].idx; |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 1570 | |
| 1571 | if (alt_buf_idx >= 0) |
| 1572 | alt_frame_index = cm->buffer_pool->frame_bufs[alt_buf_idx].cur_frame_offset; |
| 1573 | |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 1574 | if (gld_buf_idx >= 0) |
| 1575 | gld_frame_index = cm->buffer_pool->frame_bufs[gld_buf_idx].cur_frame_offset; |
| 1576 | |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 1577 | if (bwd_buf_idx >= 0) |
| 1578 | bwd_frame_index = cm->buffer_pool->frame_bufs[bwd_buf_idx].cur_frame_offset; |
Jingning Han | 94a504a | 2017-09-18 16:17:02 -0700 | [diff] [blame] | 1579 | |
| 1580 | if (alt2_buf_idx >= 0) |
| 1581 | alt2_frame_index = |
| 1582 | cm->buffer_pool->frame_bufs[alt2_buf_idx].cur_frame_offset; |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 1583 | |
Jingning Han | 707f832 | 2017-12-02 09:25:01 -0800 | [diff] [blame] | 1584 | memset(cm->ref_frame_side, 0, sizeof(cm->ref_frame_side)); |
Jingning Han | c2c3c87 | 2017-12-04 15:30:56 -0800 | [diff] [blame] | 1585 | for (int ref_frame = LAST_FRAME; ref_frame <= INTER_REFS_PER_FRAME; |
Jingning Han | 707f832 | 2017-12-02 09:25:01 -0800 | [diff] [blame] | 1586 | ++ref_frame) { |
| 1587 | int buf_idx = cm->frame_refs[ref_frame - LAST_FRAME].idx; |
| 1588 | int frame_index = -1; |
| 1589 | if (buf_idx >= 0) |
| 1590 | frame_index = cm->buffer_pool->frame_bufs[buf_idx].cur_frame_offset; |
| 1591 | if (frame_index > cur_frame_index) |
| 1592 | cm->ref_frame_side[ref_frame] = 1; |
| 1593 | else if (frame_index == cur_frame_index) |
| 1594 | cm->ref_frame_side[ref_frame] = -1; |
| 1595 | } |
| 1596 | |
Jingning Han | 380e37c | 2017-10-24 20:35:02 -0700 | [diff] [blame] | 1597 | int ref_stamp = MFMV_STACK_SIZE - 1; |
Jingning Han | 406591c | 2017-10-24 12:49:15 -0700 | [diff] [blame] | 1598 | |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 1599 | if (lst_buf_idx >= 0) { |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 1600 | const int alt_frame_idx = |
| 1601 | cm->buffer_pool->frame_bufs[lst_buf_idx].alt_frame_offset; |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 1602 | |
| 1603 | const int is_lst_overlay = (alt_frame_idx == gld_frame_index); |
Jingning Han | fbfe880 | 2017-12-05 11:14:42 -0800 | [diff] [blame] | 1604 | if (!is_lst_overlay) motion_field_projection(cm, LAST_FRAME, ref_stamp, 1); |
Jingning Han | 406591c | 2017-10-24 12:49:15 -0700 | [diff] [blame] | 1605 | |
Jingning Han | 71da481 | 2017-10-24 14:16:08 -0700 | [diff] [blame] | 1606 | --ref_stamp; |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 1607 | } |
| 1608 | |
Jingning Han | 406591c | 2017-10-24 12:49:15 -0700 | [diff] [blame] | 1609 | if (bwd_frame_index > cur_frame_index) { |
Jingning Han | fbfe880 | 2017-12-05 11:14:42 -0800 | [diff] [blame] | 1610 | if (motion_field_projection(cm, BWDREF_FRAME, ref_stamp, 0)) --ref_stamp; |
Jingning Han | 406591c | 2017-10-24 12:49:15 -0700 | [diff] [blame] | 1611 | } |
| 1612 | |
| 1613 | if (alt2_frame_index > cur_frame_index) { |
Jingning Han | fbfe880 | 2017-12-05 11:14:42 -0800 | [diff] [blame] | 1614 | if (motion_field_projection(cm, ALTREF2_FRAME, ref_stamp, 0)) --ref_stamp; |
Jingning Han | 406591c | 2017-10-24 12:49:15 -0700 | [diff] [blame] | 1615 | } |
| 1616 | |
Jingning Han | 71da481 | 2017-10-24 14:16:08 -0700 | [diff] [blame] | 1617 | if (alt_frame_index > cur_frame_index && ref_stamp >= 0) |
Jingning Han | fbfe880 | 2017-12-05 11:14:42 -0800 | [diff] [blame] | 1618 | if (motion_field_projection(cm, ALTREF_FRAME, ref_stamp, 0)) --ref_stamp; |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 1619 | } |
| 1620 | #endif // CONFIG_MFMV |
Jingning Han | c723b34 | 2017-08-24 11:19:46 -0700 | [diff] [blame] | 1621 | |
Yunqing Wang | 97d6a37 | 2017-10-09 14:15:15 -0700 | [diff] [blame] | 1622 | #if CONFIG_EXT_WARPED_MOTION |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1623 | static INLINE void record_samples(MB_MODE_INFO *mbmi, int *pts, int *pts_inref, |
Yunqing Wang | d3c13e8 | 2018-01-02 17:52:56 -0800 | [diff] [blame] | 1624 | int row_offset, int sign_r, int col_offset, |
| 1625 | int sign_c) { |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1626 | int bw = block_size_wide[mbmi->sb_type]; |
| 1627 | int bh = block_size_high[mbmi->sb_type]; |
Yunqing Wang | c7d4cd3 | 2018-01-02 20:08:45 -0800 | [diff] [blame] | 1628 | int x = col_offset * MI_SIZE + sign_c * AOMMAX(bw, MI_SIZE) / 2 - 1; |
| 1629 | int y = row_offset * MI_SIZE + sign_r * AOMMAX(bh, MI_SIZE) / 2 - 1; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1630 | |
| 1631 | pts[0] = (x * 8); |
| 1632 | pts[1] = (y * 8); |
| 1633 | pts_inref[0] = (x * 8) + mbmi->mv[0].as_mv.col; |
| 1634 | pts_inref[1] = (y * 8) + mbmi->mv[0].as_mv.row; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1635 | } |
| 1636 | |
Yunqing Wang | d3c13e8 | 2018-01-02 17:52:56 -0800 | [diff] [blame] | 1637 | // Select samples according to the motion vector difference. |
| 1638 | int selectSamples(MV *mv, int *pts, int *pts_inref, int len, BLOCK_SIZE bsize) { |
| 1639 | const int bw = block_size_wide[bsize]; |
| 1640 | const int bh = block_size_high[bsize]; |
| 1641 | const int thresh = clamp(AOMMAX(bw, bh), 16, 112); |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1642 | int pts_mvd[SAMPLES_ARRAY_SIZE] = { 0 }; |
Yunqing Wang | d3c13e8 | 2018-01-02 17:52:56 -0800 | [diff] [blame] | 1643 | int i, j, k, l = len; |
| 1644 | int ret = 0; |
| 1645 | assert(len <= LEAST_SQUARES_SAMPLES_MAX); |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1646 | |
Yunqing Wang | d3c13e8 | 2018-01-02 17:52:56 -0800 | [diff] [blame] | 1647 | // Obtain the motion vector difference. |
| 1648 | for (i = 0; i < len; ++i) { |
| 1649 | pts_mvd[i] = abs(pts_inref[2 * i] - pts[2 * i] - mv->col) + |
| 1650 | abs(pts_inref[2 * i + 1] - pts[2 * i + 1] - mv->row); |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1651 | |
Yunqing Wang | d3c13e8 | 2018-01-02 17:52:56 -0800 | [diff] [blame] | 1652 | if (pts_mvd[i] > thresh) |
| 1653 | pts_mvd[i] = -1; |
| 1654 | else |
| 1655 | ret++; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1656 | } |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1657 | |
Yunqing Wang | d3c13e8 | 2018-01-02 17:52:56 -0800 | [diff] [blame] | 1658 | // Keep at least 1 sample. |
| 1659 | if (!ret) return 1; |
| 1660 | |
| 1661 | i = 0; |
| 1662 | j = l - 1; |
| 1663 | for (k = 0; k < l - ret; k++) { |
| 1664 | while (pts_mvd[i] != -1) i++; |
| 1665 | while (pts_mvd[j] == -1) j--; |
| 1666 | assert(i != j); |
| 1667 | if (i > j) break; |
| 1668 | |
| 1669 | // Replace the discarded samples; |
| 1670 | pts_mvd[i] = pts_mvd[j]; |
| 1671 | pts[2 * i] = pts[2 * j]; |
| 1672 | pts[2 * i + 1] = pts[2 * j + 1]; |
| 1673 | pts_inref[2 * i] = pts_inref[2 * j]; |
| 1674 | pts_inref[2 * i + 1] = pts_inref[2 * j + 1]; |
| 1675 | i++; |
| 1676 | j--; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1677 | } |
| 1678 | |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1679 | return ret; |
| 1680 | } |
| 1681 | |
| 1682 | // Note: Samples returned are at 1/8-pel precision |
Yunqing Wang | c7d4cd3 | 2018-01-02 20:08:45 -0800 | [diff] [blame] | 1683 | // Sample are the neighbor block center point's coordinates relative to the |
| 1684 | // left-top pixel of current block. |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1685 | int findSamples(const AV1_COMMON *cm, MACROBLOCKD *xd, int mi_row, int mi_col, |
Yunqing Wang | d3c13e8 | 2018-01-02 17:52:56 -0800 | [diff] [blame] | 1686 | int *pts, int *pts_inref) { |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1687 | MB_MODE_INFO *const mbmi0 = &(xd->mi[0]->mbmi); |
| 1688 | int ref_frame = mbmi0->ref_frame[0]; |
| 1689 | int up_available = xd->up_available; |
| 1690 | int left_available = xd->left_available; |
Yunqing Wang | 9a7c660 | 2017-08-08 14:04:06 -0700 | [diff] [blame] | 1691 | int i, mi_step = 1, np = 0; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1692 | |
| 1693 | const TileInfo *const tile = &xd->tile; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1694 | int do_tl = 1; |
| 1695 | int do_tr = 1; |
| 1696 | |
Yunqing Wang | 9a7c660 | 2017-08-08 14:04:06 -0700 | [diff] [blame] | 1697 | // scan the nearest above rows |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1698 | if (up_available) { |
Yunqing Wang | 9a7c660 | 2017-08-08 14:04:06 -0700 | [diff] [blame] | 1699 | int mi_row_offset = -1; |
| 1700 | MODE_INFO *mi = xd->mi[mi_row_offset * xd->mi_stride]; |
| 1701 | MB_MODE_INFO *mbmi = &mi->mbmi; |
| 1702 | uint8_t n8_w = mi_size_wide[mbmi->sb_type]; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1703 | |
Yunqing Wang | 9a7c660 | 2017-08-08 14:04:06 -0700 | [diff] [blame] | 1704 | if (xd->n8_w <= n8_w) { |
| 1705 | // Handle "current block width <= above block width" case. |
| 1706 | int col_offset = -mi_col % n8_w; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1707 | |
Yunqing Wang | 9a7c660 | 2017-08-08 14:04:06 -0700 | [diff] [blame] | 1708 | if (col_offset < 0) do_tl = 0; |
| 1709 | if (col_offset + n8_w > xd->n8_w) do_tr = 0; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1710 | |
Yunqing Wang | 9a7c660 | 2017-08-08 14:04:06 -0700 | [diff] [blame] | 1711 | if (mbmi->ref_frame[0] == ref_frame && mbmi->ref_frame[1] == NONE_FRAME) { |
Yunqing Wang | c7d4cd3 | 2018-01-02 20:08:45 -0800 | [diff] [blame] | 1712 | record_samples(mbmi, pts, pts_inref, 0, -1, col_offset, 1); |
Yunqing Wang | 9a7c660 | 2017-08-08 14:04:06 -0700 | [diff] [blame] | 1713 | pts += 2; |
| 1714 | pts_inref += 2; |
Yunqing Wang | 9a7c660 | 2017-08-08 14:04:06 -0700 | [diff] [blame] | 1715 | np++; |
Yunqing Wang | d3c13e8 | 2018-01-02 17:52:56 -0800 | [diff] [blame] | 1716 | if (np >= LEAST_SQUARES_SAMPLES_MAX) return LEAST_SQUARES_SAMPLES_MAX; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1717 | } |
Yunqing Wang | 9a7c660 | 2017-08-08 14:04:06 -0700 | [diff] [blame] | 1718 | } else { |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1719 | // Handle "current block width > above block width" case. |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1720 | for (i = 0; i < AOMMIN(xd->n8_w, cm->mi_cols - mi_col); i += mi_step) { |
| 1721 | int mi_col_offset = i; |
Yunqing Wang | 9a7c660 | 2017-08-08 14:04:06 -0700 | [diff] [blame] | 1722 | mi = xd->mi[mi_col_offset + mi_row_offset * xd->mi_stride]; |
| 1723 | mbmi = &mi->mbmi; |
| 1724 | n8_w = mi_size_wide[mbmi->sb_type]; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1725 | mi_step = AOMMIN(xd->n8_w, n8_w); |
| 1726 | |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1727 | if (mbmi->ref_frame[0] == ref_frame && |
| 1728 | mbmi->ref_frame[1] == NONE_FRAME) { |
Yunqing Wang | c7d4cd3 | 2018-01-02 20:08:45 -0800 | [diff] [blame] | 1729 | record_samples(mbmi, pts, pts_inref, 0, -1, i, 1); |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1730 | pts += 2; |
| 1731 | pts_inref += 2; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1732 | np++; |
Yunqing Wang | d3c13e8 | 2018-01-02 17:52:56 -0800 | [diff] [blame] | 1733 | if (np >= LEAST_SQUARES_SAMPLES_MAX) return LEAST_SQUARES_SAMPLES_MAX; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1734 | } |
| 1735 | } |
| 1736 | } |
| 1737 | } |
Yunqing Wang | d3c13e8 | 2018-01-02 17:52:56 -0800 | [diff] [blame] | 1738 | assert(np <= LEAST_SQUARES_SAMPLES_MAX); |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1739 | |
Yunqing Wang | 9a7c660 | 2017-08-08 14:04:06 -0700 | [diff] [blame] | 1740 | // scan the nearest left columns |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1741 | if (left_available) { |
Yunqing Wang | 9a7c660 | 2017-08-08 14:04:06 -0700 | [diff] [blame] | 1742 | int mi_col_offset = -1; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1743 | |
Yunqing Wang | 9a7c660 | 2017-08-08 14:04:06 -0700 | [diff] [blame] | 1744 | MODE_INFO *mi = xd->mi[mi_col_offset]; |
| 1745 | MB_MODE_INFO *mbmi = &mi->mbmi; |
| 1746 | uint8_t n8_h = mi_size_high[mbmi->sb_type]; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1747 | |
Yunqing Wang | 9a7c660 | 2017-08-08 14:04:06 -0700 | [diff] [blame] | 1748 | if (xd->n8_h <= n8_h) { |
| 1749 | // Handle "current block height <= above block height" case. |
| 1750 | int row_offset = -mi_row % n8_h; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1751 | |
Yunqing Wang | 9a7c660 | 2017-08-08 14:04:06 -0700 | [diff] [blame] | 1752 | if (row_offset < 0) do_tl = 0; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1753 | |
Yunqing Wang | 9a7c660 | 2017-08-08 14:04:06 -0700 | [diff] [blame] | 1754 | if (mbmi->ref_frame[0] == ref_frame && mbmi->ref_frame[1] == NONE_FRAME) { |
Yunqing Wang | c7d4cd3 | 2018-01-02 20:08:45 -0800 | [diff] [blame] | 1755 | record_samples(mbmi, pts, pts_inref, row_offset, 1, 0, -1); |
Yunqing Wang | 9a7c660 | 2017-08-08 14:04:06 -0700 | [diff] [blame] | 1756 | pts += 2; |
| 1757 | pts_inref += 2; |
Yunqing Wang | 9a7c660 | 2017-08-08 14:04:06 -0700 | [diff] [blame] | 1758 | np++; |
Yunqing Wang | d3c13e8 | 2018-01-02 17:52:56 -0800 | [diff] [blame] | 1759 | if (np >= LEAST_SQUARES_SAMPLES_MAX) return LEAST_SQUARES_SAMPLES_MAX; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1760 | } |
Yunqing Wang | 9a7c660 | 2017-08-08 14:04:06 -0700 | [diff] [blame] | 1761 | } else { |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1762 | // Handle "current block height > above block height" case. |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1763 | for (i = 0; i < AOMMIN(xd->n8_h, cm->mi_rows - mi_row); i += mi_step) { |
| 1764 | int mi_row_offset = i; |
Yunqing Wang | 9a7c660 | 2017-08-08 14:04:06 -0700 | [diff] [blame] | 1765 | mi = xd->mi[mi_col_offset + mi_row_offset * xd->mi_stride]; |
| 1766 | mbmi = &mi->mbmi; |
| 1767 | n8_h = mi_size_high[mbmi->sb_type]; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1768 | mi_step = AOMMIN(xd->n8_h, n8_h); |
| 1769 | |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1770 | if (mbmi->ref_frame[0] == ref_frame && |
| 1771 | mbmi->ref_frame[1] == NONE_FRAME) { |
Yunqing Wang | c7d4cd3 | 2018-01-02 20:08:45 -0800 | [diff] [blame] | 1772 | record_samples(mbmi, pts, pts_inref, i, 1, 0, -1); |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1773 | pts += 2; |
| 1774 | pts_inref += 2; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1775 | np++; |
Yunqing Wang | d3c13e8 | 2018-01-02 17:52:56 -0800 | [diff] [blame] | 1776 | if (np >= LEAST_SQUARES_SAMPLES_MAX) return LEAST_SQUARES_SAMPLES_MAX; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1777 | } |
| 1778 | } |
| 1779 | } |
| 1780 | } |
Yunqing Wang | d3c13e8 | 2018-01-02 17:52:56 -0800 | [diff] [blame] | 1781 | assert(np <= LEAST_SQUARES_SAMPLES_MAX); |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1782 | |
| 1783 | // Top-left block |
| 1784 | if (do_tl && left_available && up_available) { |
| 1785 | int mi_row_offset = -1; |
| 1786 | int mi_col_offset = -1; |
| 1787 | |
| 1788 | MODE_INFO *mi = xd->mi[mi_col_offset + mi_row_offset * xd->mi_stride]; |
| 1789 | MB_MODE_INFO *mbmi = &mi->mbmi; |
| 1790 | |
| 1791 | if (mbmi->ref_frame[0] == ref_frame && mbmi->ref_frame[1] == NONE_FRAME) { |
Yunqing Wang | c7d4cd3 | 2018-01-02 20:08:45 -0800 | [diff] [blame] | 1792 | record_samples(mbmi, pts, pts_inref, 0, -1, 0, -1); |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1793 | pts += 2; |
| 1794 | pts_inref += 2; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1795 | np++; |
Yunqing Wang | d3c13e8 | 2018-01-02 17:52:56 -0800 | [diff] [blame] | 1796 | if (np >= LEAST_SQUARES_SAMPLES_MAX) return LEAST_SQUARES_SAMPLES_MAX; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1797 | } |
| 1798 | } |
Yunqing Wang | d3c13e8 | 2018-01-02 17:52:56 -0800 | [diff] [blame] | 1799 | assert(np <= LEAST_SQUARES_SAMPLES_MAX); |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1800 | |
| 1801 | // Top-right block |
David Barker | 761b1ac | 2017-09-25 11:23:03 +0100 | [diff] [blame] | 1802 | if (do_tr && |
| 1803 | has_top_right(cm, xd, mi_row, mi_col, AOMMAX(xd->n8_w, xd->n8_h))) { |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1804 | POSITION trb_pos = { -1, xd->n8_w }; |
| 1805 | |
| 1806 | if (is_inside(tile, mi_col, mi_row, cm->mi_rows, cm, &trb_pos)) { |
| 1807 | int mi_row_offset = -1; |
| 1808 | int mi_col_offset = xd->n8_w; |
| 1809 | |
| 1810 | MODE_INFO *mi = xd->mi[mi_col_offset + mi_row_offset * xd->mi_stride]; |
| 1811 | MB_MODE_INFO *mbmi = &mi->mbmi; |
| 1812 | |
| 1813 | if (mbmi->ref_frame[0] == ref_frame && mbmi->ref_frame[1] == NONE_FRAME) { |
Yunqing Wang | c7d4cd3 | 2018-01-02 20:08:45 -0800 | [diff] [blame] | 1814 | record_samples(mbmi, pts, pts_inref, 0, -1, xd->n8_w, 1); |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1815 | np++; |
Yunqing Wang | d3c13e8 | 2018-01-02 17:52:56 -0800 | [diff] [blame] | 1816 | if (np >= LEAST_SQUARES_SAMPLES_MAX) return LEAST_SQUARES_SAMPLES_MAX; |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1817 | } |
| 1818 | } |
| 1819 | } |
Yunqing Wang | d3c13e8 | 2018-01-02 17:52:56 -0800 | [diff] [blame] | 1820 | assert(np <= LEAST_SQUARES_SAMPLES_MAX); |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 1821 | |
| 1822 | return np; |
| 1823 | } |
| 1824 | #else |
Yue Chen | ff61610 | 2017-04-04 15:50:12 -0700 | [diff] [blame] | 1825 | void calc_projection_samples(MB_MODE_INFO *const mbmi, int x, int y, |
| 1826 | int *pts_inref) { |
| 1827 | pts_inref[0] = (x * 8) + mbmi->mv[0].as_mv.col; |
| 1828 | pts_inref[1] = (y * 8) + mbmi->mv[0].as_mv.row; |
Yue Chen | d193cdc | 2017-01-13 00:52:23 -0800 | [diff] [blame] | 1829 | } |
| 1830 | |
Debargha Mukherjee | e6eb3b5 | 2017-02-26 08:50:56 -0800 | [diff] [blame] | 1831 | // Note: Samples returned are at 1/8-pel precision |
Yunqing Wang | c7d4cd3 | 2018-01-02 20:08:45 -0800 | [diff] [blame] | 1832 | // Sample are the neighbor block center point's coordinates relative to the |
| 1833 | // left-top pixel of current block. |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1834 | int findSamples(const AV1_COMMON *cm, MACROBLOCKD *xd, int mi_row, int mi_col, |
Debargha Mukherjee | e6eb3b5 | 2017-02-26 08:50:56 -0800 | [diff] [blame] | 1835 | int *pts, int *pts_inref) { |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1836 | MB_MODE_INFO *const mbmi0 = &(xd->mi[0]->mbmi); |
| 1837 | int ref_frame = mbmi0->ref_frame[0]; |
| 1838 | int up_available = xd->up_available; |
| 1839 | int left_available = xd->left_available; |
| 1840 | int i, mi_step, np = 0; |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1841 | |
| 1842 | // scan the above row |
| 1843 | if (up_available) { |
| 1844 | for (i = 0; i < AOMMIN(xd->n8_w, cm->mi_cols - mi_col); i += mi_step) { |
| 1845 | int mi_row_offset = -1; |
| 1846 | int mi_col_offset = i; |
| 1847 | |
| 1848 | MODE_INFO *mi = xd->mi[mi_col_offset + mi_row_offset * xd->mi_stride]; |
| 1849 | MB_MODE_INFO *mbmi = &mi->mbmi; |
| 1850 | |
Yue Chen | d0d3bcc | 2017-01-30 11:22:32 -0800 | [diff] [blame] | 1851 | mi_step = AOMMIN(xd->n8_w, mi_size_wide[mbmi->sb_type]); |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1852 | |
Emil Keyder | 01770b3 | 2017-01-20 18:03:11 -0500 | [diff] [blame] | 1853 | if (mbmi->ref_frame[0] == ref_frame && mbmi->ref_frame[1] == NONE_FRAME) { |
David Barker | cdcac6d | 2016-12-01 17:04:16 +0000 | [diff] [blame] | 1854 | int bw = block_size_wide[mbmi->sb_type]; |
| 1855 | int bh = block_size_high[mbmi->sb_type]; |
Yunqing Wang | c7d4cd3 | 2018-01-02 20:08:45 -0800 | [diff] [blame] | 1856 | int x = i * MI_SIZE + AOMMAX(bw, MI_SIZE) / 2 - 1; |
| 1857 | int y = -AOMMAX(bh, MI_SIZE) / 2 - 1; |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1858 | |
Yue Chen | 5558e5d | 2017-03-31 12:24:42 -0700 | [diff] [blame] | 1859 | pts[0] = (x * 8); |
| 1860 | pts[1] = (y * 8); |
Yue Chen | ff61610 | 2017-04-04 15:50:12 -0700 | [diff] [blame] | 1861 | calc_projection_samples(mbmi, x, y, pts_inref); |
Yue Chen | 5558e5d | 2017-03-31 12:24:42 -0700 | [diff] [blame] | 1862 | pts += 2; |
| 1863 | pts_inref += 2; |
| 1864 | np++; |
| 1865 | if (np >= LEAST_SQUARES_SAMPLES_MAX) return LEAST_SQUARES_SAMPLES_MAX; |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1866 | } |
| 1867 | } |
| 1868 | } |
Debargha Mukherjee | 9868c74 | 2017-01-26 15:23:35 -0800 | [diff] [blame] | 1869 | assert(2 * np <= SAMPLES_ARRAY_SIZE); |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1870 | |
| 1871 | // scan the left column |
| 1872 | if (left_available) { |
| 1873 | for (i = 0; i < AOMMIN(xd->n8_h, cm->mi_rows - mi_row); i += mi_step) { |
| 1874 | int mi_row_offset = i; |
| 1875 | int mi_col_offset = -1; |
| 1876 | |
| 1877 | MODE_INFO *mi = xd->mi[mi_col_offset + mi_row_offset * xd->mi_stride]; |
| 1878 | MB_MODE_INFO *mbmi = &mi->mbmi; |
| 1879 | |
Yue Chen | d0d3bcc | 2017-01-30 11:22:32 -0800 | [diff] [blame] | 1880 | mi_step = AOMMIN(xd->n8_h, mi_size_high[mbmi->sb_type]); |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1881 | |
Emil Keyder | 01770b3 | 2017-01-20 18:03:11 -0500 | [diff] [blame] | 1882 | if (mbmi->ref_frame[0] == ref_frame && mbmi->ref_frame[1] == NONE_FRAME) { |
David Barker | cdcac6d | 2016-12-01 17:04:16 +0000 | [diff] [blame] | 1883 | int bw = block_size_wide[mbmi->sb_type]; |
| 1884 | int bh = block_size_high[mbmi->sb_type]; |
Yunqing Wang | c7d4cd3 | 2018-01-02 20:08:45 -0800 | [diff] [blame] | 1885 | int x = -AOMMAX(bw, MI_SIZE) / 2 - 1; |
| 1886 | int y = i * MI_SIZE + AOMMAX(bh, MI_SIZE) / 2 - 1; |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1887 | |
Yue Chen | 5558e5d | 2017-03-31 12:24:42 -0700 | [diff] [blame] | 1888 | pts[0] = (x * 8); |
| 1889 | pts[1] = (y * 8); |
Yue Chen | ff61610 | 2017-04-04 15:50:12 -0700 | [diff] [blame] | 1890 | calc_projection_samples(mbmi, x, y, pts_inref); |
Yue Chen | 5558e5d | 2017-03-31 12:24:42 -0700 | [diff] [blame] | 1891 | pts += 2; |
| 1892 | pts_inref += 2; |
| 1893 | np++; |
| 1894 | if (np >= LEAST_SQUARES_SAMPLES_MAX) return LEAST_SQUARES_SAMPLES_MAX; |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1895 | } |
| 1896 | } |
| 1897 | } |
Debargha Mukherjee | 9868c74 | 2017-01-26 15:23:35 -0800 | [diff] [blame] | 1898 | assert(2 * np <= SAMPLES_ARRAY_SIZE); |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1899 | |
| 1900 | if (left_available && up_available) { |
| 1901 | int mi_row_offset = -1; |
| 1902 | int mi_col_offset = -1; |
| 1903 | |
| 1904 | MODE_INFO *mi = xd->mi[mi_col_offset + mi_row_offset * xd->mi_stride]; |
| 1905 | MB_MODE_INFO *mbmi = &mi->mbmi; |
| 1906 | |
Emil Keyder | 01770b3 | 2017-01-20 18:03:11 -0500 | [diff] [blame] | 1907 | if (mbmi->ref_frame[0] == ref_frame && mbmi->ref_frame[1] == NONE_FRAME) { |
David Barker | cdcac6d | 2016-12-01 17:04:16 +0000 | [diff] [blame] | 1908 | int bw = block_size_wide[mbmi->sb_type]; |
| 1909 | int bh = block_size_high[mbmi->sb_type]; |
Yunqing Wang | c7d4cd3 | 2018-01-02 20:08:45 -0800 | [diff] [blame] | 1910 | int x = -AOMMAX(bw, MI_SIZE) / 2 - 1; |
| 1911 | int y = -AOMMAX(bh, MI_SIZE) / 2 - 1; |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1912 | |
Yue Chen | 5558e5d | 2017-03-31 12:24:42 -0700 | [diff] [blame] | 1913 | pts[0] = (x * 8); |
| 1914 | pts[1] = (y * 8); |
Yue Chen | ff61610 | 2017-04-04 15:50:12 -0700 | [diff] [blame] | 1915 | calc_projection_samples(mbmi, x, y, pts_inref); |
Yue Chen | 5558e5d | 2017-03-31 12:24:42 -0700 | [diff] [blame] | 1916 | np++; |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1917 | } |
| 1918 | } |
Debargha Mukherjee | 9868c74 | 2017-01-26 15:23:35 -0800 | [diff] [blame] | 1919 | assert(2 * np <= SAMPLES_ARRAY_SIZE); |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1920 | |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1921 | return np; |
| 1922 | } |
Yunqing Wang | 97d6a37 | 2017-10-09 14:15:15 -0700 | [diff] [blame] | 1923 | #endif // CONFIG_EXT_WARPED_MOTION |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 1924 | |
| 1925 | #if CONFIG_EXT_SKIP |
Yaowu Xu | 96fa757 | 2017-12-26 20:51:41 -0800 | [diff] [blame] | 1926 | void av1_setup_skip_mode_allowed(AV1_COMMON *cm) { |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 1927 | cm->is_skip_mode_allowed = 0; |
| 1928 | cm->ref_frame_idx_0 = cm->ref_frame_idx_1 = INVALID_IDX; |
| 1929 | |
Zoe Liu | 4b847e1 | 2017-12-07 12:44:45 -0800 | [diff] [blame] | 1930 | if (frame_is_intra_only(cm) || cm->reference_mode == SINGLE_REFERENCE) return; |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 1931 | |
| 1932 | RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs; |
| 1933 | const int cur_frame_offset = cm->frame_offset; |
| 1934 | int ref_frame_offset[2] = { -1, INT_MAX }; |
| 1935 | int ref_idx[2] = { INVALID_IDX, INVALID_IDX }; |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 1936 | |
Zoe Liu | 4b847e1 | 2017-12-07 12:44:45 -0800 | [diff] [blame] | 1937 | // Identify the nearest forward and backward references. |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 1938 | for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) { |
| 1939 | const int buf_idx = cm->frame_refs[i].idx; |
| 1940 | if (buf_idx == INVALID_IDX) continue; |
| 1941 | |
| 1942 | const int ref_offset = frame_bufs[buf_idx].cur_frame_offset; |
| 1943 | if (ref_offset < cur_frame_offset) { |
| 1944 | // Forward reference |
| 1945 | if (ref_offset > ref_frame_offset[0]) { |
| 1946 | ref_frame_offset[0] = ref_offset; |
| 1947 | ref_idx[0] = i; |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 1948 | } |
| 1949 | } else if (ref_offset > cur_frame_offset) { |
| 1950 | // Backward reference |
| 1951 | if (ref_offset < ref_frame_offset[1]) { |
| 1952 | ref_frame_offset[1] = ref_offset; |
| 1953 | ref_idx[1] = i; |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 1954 | } |
| 1955 | } |
| 1956 | } |
| 1957 | |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 1958 | if (ref_idx[0] != INVALID_IDX && ref_idx[1] != INVALID_IDX) { |
Zoe Liu | 4b847e1 | 2017-12-07 12:44:45 -0800 | [diff] [blame] | 1959 | // == Bi-directional prediction == |
| 1960 | cm->is_skip_mode_allowed = 1; |
David Barker | 1efc5bd | 2018-02-07 14:38:44 +0000 | [diff] [blame] | 1961 | cm->ref_frame_idx_0 = AOMMIN(ref_idx[0], ref_idx[1]); |
| 1962 | cm->ref_frame_idx_1 = AOMMAX(ref_idx[0], ref_idx[1]); |
Zoe Liu | 4b847e1 | 2017-12-07 12:44:45 -0800 | [diff] [blame] | 1963 | } else if (ref_idx[0] != INVALID_IDX && ref_idx[1] == INVALID_IDX) { |
| 1964 | // == Forward prediction only == |
| 1965 | // Identify the second nearest forward reference. |
Zoe Liu | 104d62e | 2017-12-07 12:44:45 -0800 | [diff] [blame] | 1966 | ref_frame_offset[1] = -1; |
Zoe Liu | 104d62e | 2017-12-07 12:44:45 -0800 | [diff] [blame] | 1967 | for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) { |
| 1968 | const int buf_idx = cm->frame_refs[i].idx; |
| 1969 | if (buf_idx == INVALID_IDX) continue; |
| 1970 | |
| 1971 | const int ref_offset = frame_bufs[buf_idx].cur_frame_offset; |
| 1972 | if (ref_offset < ref_frame_offset[0] && |
| 1973 | ref_offset > ref_frame_offset[1]) { |
| 1974 | // Second closest forward reference |
| 1975 | ref_frame_offset[1] = ref_offset; |
| 1976 | ref_idx[1] = i; |
Zoe Liu | 104d62e | 2017-12-07 12:44:45 -0800 | [diff] [blame] | 1977 | } |
| 1978 | } |
| 1979 | if (ref_frame_offset[1] >= 0) { |
Zoe Liu | 4b847e1 | 2017-12-07 12:44:45 -0800 | [diff] [blame] | 1980 | cm->is_skip_mode_allowed = 1; |
| 1981 | cm->ref_frame_idx_0 = AOMMIN(ref_idx[0], ref_idx[1]); |
| 1982 | cm->ref_frame_idx_1 = AOMMAX(ref_idx[0], ref_idx[1]); |
Zoe Liu | 104d62e | 2017-12-07 12:44:45 -0800 | [diff] [blame] | 1983 | } |
| 1984 | } |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 1985 | } |
| 1986 | #endif // CONFIG_EXT_SKIP |