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