mvref_common.c 74.4 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1
/*
Yaowu Xu's avatar
Yaowu Xu committed
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jingning Han's avatar
Jingning Han committed
3
 *
Yaowu Xu's avatar
Yaowu Xu committed
4
5
6
7
8
9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Jingning Han's avatar
Jingning Han committed
10
11
 */

12
#include "av1/common/mvref_common.h"
Yue Chen's avatar
Yue Chen committed
13
#include "av1/common/warped_motion.h"
Jingning Han's avatar
Jingning Han committed
14

15
16
#define USE_CUR_GM_REFMV 1

17
18
void av1_copy_frame_mvs(const AV1_COMMON *const cm, MODE_INFO *mi, int mi_row,
                        int mi_col, int x_mis, int y_mis) {
19
#if CONFIG_TMV || CONFIG_MFMV
20
  const int frame_mvs_stride = ROUND_POWER_OF_TWO(cm->mi_cols, 1);
21
22
  MV_REF *frame_mvs =
      cm->cur_frame->mvs + (mi_row >> 1) * frame_mvs_stride + (mi_col >> 1);
23
24
25
26
27
28
29
30
31
32
33
34
  x_mis = ROUND_POWER_OF_TWO(x_mis, 1);
  y_mis = ROUND_POWER_OF_TWO(y_mis, 1);
#else
  const int frame_mvs_stride = cm->mi_cols;
  MV_REF *frame_mvs = cm->cur_frame->mvs +
                      (mi_row & 0xfffe) * frame_mvs_stride + (mi_col & 0xfffe);
  x_mis = AOMMAX(x_mis, 2);
  y_mis = AOMMAX(y_mis, 2);
#endif  // CONFIG_TMV
  int w, h;

  for (h = 0; h < y_mis; h++) {
35
    MV_REF *mv = frame_mvs;
36
    for (w = 0; w < x_mis; w++) {
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#if CONFIG_MFMV
      mv->ref_frame[0] = NONE_FRAME;
      mv->ref_frame[1] = NONE_FRAME;
      mv->mv[0].as_int = 0;
      mv->mv[1].as_int = 0;

      for (int idx = 0; idx < 2; ++idx) {
        MV_REFERENCE_FRAME ref_frame = mi->mbmi.ref_frame[idx];
        if (ref_frame > INTRA_FRAME) {
          int8_t ref_idx = cm->ref_frame_side[ref_frame];
          if (ref_idx < 0) continue;
          mv->ref_frame[ref_idx] = ref_frame;
          mv->mv[ref_idx].as_int = mi->mbmi.mv[idx].as_int;
        }
      }
#else
53
54
55
56
      mv->ref_frame[0] = mi->mbmi.ref_frame[0];
      mv->ref_frame[1] = mi->mbmi.ref_frame[1];
      mv->mv[0].as_int = mi->mbmi.mv[0].as_int;
      mv->mv[1].as_int = mi->mbmi.mv[1].as_int;
57
#endif
58
59
60
      // (TODO:yunqing) The following 2 lines won't be used and can be removed.
      mv->pred_mv[0].as_int = mi->mbmi.pred_mv[0].as_int;
      mv->pred_mv[1].as_int = mi->mbmi.pred_mv[1].as_int;
61
      mv++;
62
    }
63
    frame_mvs += frame_mvs_stride;
64
65
66
  }
}

67
68
69
static uint8_t add_ref_mv_candidate(
    const MODE_INFO *const candidate_mi, const MB_MODE_INFO *const candidate,
    const MV_REFERENCE_FRAME rf[2], uint8_t *refmv_count,
70
    uint8_t *ref_match_count, CANDIDATE_MV *ref_mv_stack, const int use_hp,
Luc Trudeau's avatar
Luc Trudeau committed
71
    int len,
72
#if USE_CUR_GM_REFMV
73
    int_mv *gm_mv_candidates, const WarpedMotionParams *gm_params,
74
#endif  // USE_CUR_GM_REFMV
Yunqing Wang's avatar
Yunqing Wang committed
75
    int col, int weight,
RogerZhou's avatar
RogerZhou committed
76
#if CONFIG_AMVR
Yunqing Wang's avatar
Yunqing Wang committed
77
    int is_integer,
RogerZhou's avatar
RogerZhou committed
78
#endif
Yunqing Wang's avatar
Yunqing Wang committed
79
    BLOCK_SIZE bsize, int mi_row, int mi_col, int subsampling_x,
80
    int subsampling_y, int do_warping) {
81
82
83
#if CONFIG_INTRABC
  if (!is_inter_block(candidate)) return 0;
#endif  // CONFIG_INTRABC
Jingning Han's avatar
Jingning Han committed
84
85
  int index = 0, ref;
  int newmv_count = 0;
86
  assert(weight % 2 == 0);
87
  (void)ref_match_count;
Yunqing Wang's avatar
Yunqing Wang committed
88
89
90
91
92
93
#if !CONFIG_EXT_WARPED_MOTION
  (void)bsize;
  (void)mi_row;
  (void)mi_col;
  (void)subsampling_x;
  (void)subsampling_y;
94
  (void)do_warping;
Yunqing Wang's avatar
Yunqing Wang committed
95
#endif  // CONFIG_EXT_WARPED_MOTION
Jingning Han's avatar
Jingning Han committed
96

Emil Keyder's avatar
Emil Keyder committed
97
  if (rf[1] == NONE_FRAME) {
Jingning Han's avatar
Jingning Han committed
98
99
100
    // single reference frame
    for (ref = 0; ref < 2; ++ref) {
      if (candidate->ref_frame[ref] == rf[0]) {
101
        int_mv this_refmv;
Yunqing Wang's avatar
Yunqing Wang committed
102
#if CONFIG_EXT_WARPED_MOTION
103
        if (candidate->motion_mode == WARPED_CAUSAL && do_warping) {
104
          const WarpedMotionParams wm = candidate->wm_params[0];
Yunqing Wang's avatar
Yunqing Wang committed
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
          const int bw = block_size_wide[bsize];
          const int bh = block_size_high[bsize];
          int global_offset_c = mi_col * MI_SIZE;
          int global_offset_r = mi_row * MI_SIZE;
          int cc_offset = bw / 2 - 1;
          int cr_offset = bh / 2 - 1;
          int xc0 = cc_offset + global_offset_c;
          int yc0 = cr_offset + global_offset_r;
          int xc1 = xc0 + 1;
          int yc1 = yc0 + 1;
          int in[4] = { xc0, yc0, xc1, yc1 };
          int out[4] = { 0, 0, 0, 0 };

          assert(ref == 0);
          // For WARPED_CAUSAL, wmtype is always AFFINE.
          assert(wm.wmtype == AFFINE);
          project_points_affine(wm.wmmat, in, out, 2, 2, 2, subsampling_x,
                                subsampling_y);

          // assert(x_scale == 1024 && y_scale == 1024);
          // out[]'s precision is 1/64, adjust xc, yc accordingly.
          out[0] -= (xc0 << (3 + SCALING_FCT));
          out[1] -= (yc0 << (3 + SCALING_FCT));
          out[2] -= (xc1 << (3 + SCALING_FCT));
          out[3] -= (yc1 << (3 + SCALING_FCT));

          this_refmv.as_mv.col =
              ROUND_POWER_OF_TWO_SIGNED(out[0] + out[2], SCALING_FCT + 1);
          this_refmv.as_mv.row =
              ROUND_POWER_OF_TWO_SIGNED(out[1] + out[3], SCALING_FCT + 1);
RogerZhou's avatar
RogerZhou committed
135
136
137
#if CONFIG_AMVR
          lower_mv_precision(&this_refmv.as_mv, use_hp, is_integer);
#else
Yunqing Wang's avatar
Yunqing Wang committed
138
          lower_mv_precision(&this_refmv.as_mv, use_hp);
RogerZhou's avatar
RogerZhou committed
139
#endif
Yunqing Wang's avatar
Yunqing Wang committed
140
141
        } else {
#endif  // CONFIG_EXT_WARPED_MOTION
142
#if USE_CUR_GM_REFMV
Luc Trudeau's avatar
Luc Trudeau committed
143
          if (is_global_mv_block(candidate_mi, gm_params[rf[0]].wmtype))
Yunqing Wang's avatar
Yunqing Wang committed
144
145
            this_refmv = gm_mv_candidates[0];
          else
146
#endif  // USE_CUR_GM_REFMV
Luc Trudeau's avatar
Luc Trudeau committed
147
            this_refmv = get_sub_block_mv(candidate_mi, ref, col);
RogerZhou's avatar
RogerZhou committed
148
#if CONFIG_AMVR
Yunqing Wang's avatar
Yunqing Wang committed
149
          lower_mv_precision(&this_refmv.as_mv, use_hp, is_integer);
RogerZhou's avatar
RogerZhou committed
150
#else
151
        lower_mv_precision(&this_refmv.as_mv, use_hp);
152
#endif  // CONFIG_AMVR
Yunqing Wang's avatar
Yunqing Wang committed
153
154
155
#if CONFIG_EXT_WARPED_MOTION
        }
#endif  // CONFIG_EXT_WARPED_MOTION
156

Jingning Han's avatar
Jingning Han committed
157
        for (index = 0; index < *refmv_count; ++index)
clang-format's avatar
clang-format committed
158
          if (ref_mv_stack[index].this_mv.as_int == this_refmv.as_int) break;
159

160
        if (index < *refmv_count) ref_mv_stack[index].weight += weight * len;
161

Jingning Han's avatar
Jingning Han committed
162
        // Add a new item to the list.
163
        if (index == *refmv_count && *refmv_count < MAX_REF_MV_STACK_SIZE) {
Jingning Han's avatar
Jingning Han committed
164
          ref_mv_stack[index].this_mv = this_refmv;
165
          ref_mv_stack[index].pred_diff[0] = av1_get_pred_diff_ctx(
Luc Trudeau's avatar
Luc Trudeau committed
166
              get_sub_block_pred_mv(candidate_mi, ref, col), this_refmv);
167
          ref_mv_stack[index].weight = weight * len;
Jingning Han's avatar
Jingning Han committed
168
          ++(*refmv_count);
169

170
#if !CONFIG_OPT_REF_MV
171
          if (candidate->mode == NEWMV) ++newmv_count;
172
#endif
Jingning Han's avatar
Jingning Han committed
173
        }
174
175
176
177
#if CONFIG_OPT_REF_MV
        if (candidate->mode == NEWMV) ++newmv_count;
        ++*ref_match_count;
#endif
178
      }
Jingning Han's avatar
Jingning Han committed
179
180
181
    }
  } else {
    // compound reference frame
clang-format's avatar
clang-format committed
182
    if (candidate->ref_frame[0] == rf[0] && candidate->ref_frame[1] == rf[1]) {
183
      int_mv this_refmv[2];
Jingning Han's avatar
Jingning Han committed
184

185
      for (ref = 0; ref < 2; ++ref) {
186
#if USE_CUR_GM_REFMV
Luc Trudeau's avatar
Luc Trudeau committed
187
        if (is_global_mv_block(candidate_mi, gm_params[rf[ref]].wmtype))
188
189
          this_refmv[ref] = gm_mv_candidates[ref];
        else
190
#endif  // USE_CUR_GM_REFMV
Luc Trudeau's avatar
Luc Trudeau committed
191
          this_refmv[ref] = get_sub_block_mv(candidate_mi, ref, col);
RogerZhou's avatar
RogerZhou committed
192
193
194
#if CONFIG_AMVR
        lower_mv_precision(&this_refmv[ref].as_mv, use_hp, is_integer);
#else
195
        lower_mv_precision(&this_refmv[ref].as_mv, use_hp);
RogerZhou's avatar
RogerZhou committed
196
#endif
197
      }
198

Jingning Han's avatar
Jingning Han committed
199
200
201
202
203
      for (index = 0; index < *refmv_count; ++index)
        if ((ref_mv_stack[index].this_mv.as_int == this_refmv[0].as_int) &&
            (ref_mv_stack[index].comp_mv.as_int == this_refmv[1].as_int))
          break;

204
      if (index < *refmv_count) ref_mv_stack[index].weight += weight * len;
Jingning Han's avatar
Jingning Han committed
205
206

      // Add a new item to the list.
207
      if (index == *refmv_count && *refmv_count < MAX_REF_MV_STACK_SIZE) {
Jingning Han's avatar
Jingning Han committed
208
209
        ref_mv_stack[index].this_mv = this_refmv[0];
        ref_mv_stack[index].comp_mv = this_refmv[1];
210
        ref_mv_stack[index].pred_diff[0] = av1_get_pred_diff_ctx(
Luc Trudeau's avatar
Luc Trudeau committed
211
            get_sub_block_pred_mv(candidate_mi, 0, col), this_refmv[0]);
212
        ref_mv_stack[index].pred_diff[1] = av1_get_pred_diff_ctx(
Luc Trudeau's avatar
Luc Trudeau committed
213
            get_sub_block_pred_mv(candidate_mi, 1, col), this_refmv[1]);
214
        ref_mv_stack[index].weight = weight * len;
Jingning Han's avatar
Jingning Han committed
215
216
        ++(*refmv_count);

217
#if !CONFIG_OPT_REF_MV
218
        if (candidate->mode == NEW_NEWMV) ++newmv_count;
219
#endif
Jingning Han's avatar
Jingning Han committed
220
      }
221
222
223
224
#if CONFIG_OPT_REF_MV
      if (candidate->mode == NEW_NEWMV) ++newmv_count;
      ++*ref_match_count;
#endif
Jingning Han's avatar
Jingning Han committed
225
226
227
228
229
    }
  }
  return newmv_count;
}

Yaowu Xu's avatar
Yaowu Xu committed
230
static uint8_t scan_row_mbmi(const AV1_COMMON *cm, const MACROBLOCKD *xd,
Luc Trudeau's avatar
Luc Trudeau committed
231
                             int mi_row, int mi_col,
clang-format's avatar
clang-format committed
232
                             const MV_REFERENCE_FRAME rf[2], int row_offset,
233
                             CANDIDATE_MV *ref_mv_stack, uint8_t *refmv_count,
234
                             uint8_t *ref_match_count,
235
#if USE_CUR_GM_REFMV
236
                             int_mv *gm_mv_candidates,
237
#endif  // USE_CUR_GM_REFMV
238
                             int max_row_offset, int *processed_rows) {
Yunqing Wang's avatar
Yunqing Wang committed
239
  const int end_mi = AOMMIN(xd->n8_w, cm->mi_cols - mi_col);
240
241
  const int n8_w_8 = mi_size_wide[BLOCK_8X8];
  const int n8_w_16 = mi_size_wide[BLOCK_16X16];
Jingning Han's avatar
Jingning Han committed
242
243
  int i;
  uint8_t newmv_count = 0;
244
  int col_offset = 0;
245
  const int shift = 0;
246
  // TODO(jingning): Revisit this part after cb4x4 is stable.
247
248
  if (abs(row_offset) > 1) {
    col_offset = 1;
249
    if (mi_col & 0x01 && xd->n8_w < n8_w_8) --col_offset;
250
  }
Yunqing Wang's avatar
Yunqing Wang committed
251
252
  const int use_step_16 = (xd->n8_w >= 16);
  MODE_INFO **const candidate_mi0 = xd->mi + row_offset * xd->mi_stride;
253
  const int do_warping = (row_offset == -1);
Jingning Han's avatar
Jingning Han committed
254

255
  for (i = 0; i < end_mi;) {
Yunqing Wang's avatar
Yunqing Wang committed
256
257
    const MODE_INFO *const candidate_mi = candidate_mi0[col_offset + i];
    const MB_MODE_INFO *const candidate = &candidate_mi->mbmi;
258
259
260
    const int candidate_bsize = candidate->sb_type;
    const int n8_w = mi_size_wide[candidate_bsize];
    int len = AOMMIN(xd->n8_w, n8_w);
Yunqing Wang's avatar
Yunqing Wang committed
261
262
263
264
    if (use_step_16)
      len = AOMMAX(n8_w_16, len);
    else if (abs(row_offset) > 1)
      len = AOMMAX(len, n8_w_8);
265
266
267
268
269
270
271
272
273
274
275

    int weight = 2;
    if (xd->n8_w >= n8_w_8 && xd->n8_w <= n8_w) {
      int inc = AOMMIN(-max_row_offset + row_offset + 1,
                       mi_size_high[candidate_bsize]);
      // Obtain range used in weight calculation.
      weight = AOMMAX(weight, (inc << shift));
      // Update processed rows.
      *processed_rows = inc - row_offset - 1;
    }

RogerZhou's avatar
RogerZhou committed
276
277
#if CONFIG_AMVR
    newmv_count += add_ref_mv_candidate(
278
        candidate_mi, candidate, rf, refmv_count, ref_match_count, ref_mv_stack,
Luc Trudeau's avatar
Luc Trudeau committed
279
        cm->allow_high_precision_mv, len,
280
#if USE_CUR_GM_REFMV
281
        gm_mv_candidates, cm->global_motion,
282
#endif  // USE_CUR_GM_REFMV
283
        col_offset + i, weight, cm->cur_frame_force_integer_mv,
Yunqing Wang's avatar
Yunqing Wang committed
284
        xd->mi[0]->mbmi.sb_type, mi_row, mi_col, xd->plane[0].subsampling_x,
285
        xd->plane[0].subsampling_y, do_warping);
RogerZhou's avatar
RogerZhou committed
286
#else
Yunqing Wang's avatar
Yunqing Wang committed
287
    newmv_count += add_ref_mv_candidate(
288
        candidate_mi, candidate, rf, refmv_count, ref_match_count, ref_mv_stack,
Luc Trudeau's avatar
Luc Trudeau committed
289
        cm->allow_high_precision_mv, len,
290
#if USE_CUR_GM_REFMV
Yunqing Wang's avatar
Yunqing Wang committed
291
        gm_mv_candidates, cm->global_motion,
292
#endif  // USE_CUR_GM_REFMV
Yunqing Wang's avatar
Yunqing Wang committed
293
        col_offset + i, weight, xd->mi[0]->mbmi.sb_type, mi_row, mi_col,
294
        xd->plane[0].subsampling_x, xd->plane[0].subsampling_y, do_warping);
RogerZhou's avatar
RogerZhou committed
295
#endif
296

Yunqing Wang's avatar
Yunqing Wang committed
297
    i += len;
298
  }
299
300

  return newmv_count;
301
302
}

Yaowu Xu's avatar
Yaowu Xu committed
303
static uint8_t scan_col_mbmi(const AV1_COMMON *cm, const MACROBLOCKD *xd,
Luc Trudeau's avatar
Luc Trudeau committed
304
                             int mi_row, int mi_col,
clang-format's avatar
clang-format committed
305
                             const MV_REFERENCE_FRAME rf[2], int col_offset,
306
                             CANDIDATE_MV *ref_mv_stack, uint8_t *refmv_count,
307
                             uint8_t *ref_match_count,
308
#if USE_CUR_GM_REFMV
309
                             int_mv *gm_mv_candidates,
310
#endif  // USE_CUR_GM_REFMV
311
                             int max_col_offset, int *processed_cols) {
Yunqing Wang's avatar
Yunqing Wang committed
312
  const int end_mi = AOMMIN(xd->n8_h, cm->mi_rows - mi_row);
313
314
  const int n8_h_8 = mi_size_high[BLOCK_8X8];
  const int n8_h_16 = mi_size_high[BLOCK_16X16];
315
  int i;
316
  uint8_t newmv_count = 0;
317
  int row_offset = 0;
318
  const int shift = 0;
319
320
  if (abs(col_offset) > 1) {
    row_offset = 1;
321
    if (mi_row & 0x01 && xd->n8_h < n8_h_8) --row_offset;
322
  }
Yunqing Wang's avatar
Yunqing Wang committed
323
  const int use_step_16 = (xd->n8_h >= 16);
324
  const int do_warping = (col_offset == -1);
325

326
  for (i = 0; i < end_mi;) {
Yunqing Wang's avatar
Yunqing Wang committed
327
328
329
    const MODE_INFO *const candidate_mi =
        xd->mi[(row_offset + i) * xd->mi_stride + col_offset];
    const MB_MODE_INFO *const candidate = &candidate_mi->mbmi;
330
331
332
    const int candidate_bsize = candidate->sb_type;
    const int n8_h = mi_size_high[candidate_bsize];
    int len = AOMMIN(xd->n8_h, n8_h);
Yunqing Wang's avatar
Yunqing Wang committed
333
334
335
336
    if (use_step_16)
      len = AOMMAX(n8_h_16, len);
    else if (abs(col_offset) > 1)
      len = AOMMAX(len, n8_h_8);
337
338
339
340
341
342
343
344
345
346
347

    int weight = 2;
    if (xd->n8_h >= n8_h_8 && xd->n8_h <= n8_h) {
      int inc = AOMMIN(-max_col_offset + col_offset + 1,
                       mi_size_wide[candidate_bsize]);
      // Obtain range used in weight calculation.
      weight = AOMMAX(weight, (inc << shift));
      // Update processed cols.
      *processed_cols = inc - col_offset - 1;
    }

RogerZhou's avatar
RogerZhou committed
348
349
#if CONFIG_AMVR
    newmv_count += add_ref_mv_candidate(
350
        candidate_mi, candidate, rf, refmv_count, ref_match_count, ref_mv_stack,
Luc Trudeau's avatar
Luc Trudeau committed
351
        cm->allow_high_precision_mv, len,
352
#if USE_CUR_GM_REFMV
353
        gm_mv_candidates, cm->global_motion,
354
#endif  // USE_CUR_GM_REFMV
355
        col_offset, weight, cm->cur_frame_force_integer_mv,
Yunqing Wang's avatar
Yunqing Wang committed
356
        xd->mi[0]->mbmi.sb_type, mi_row, mi_col, xd->plane[0].subsampling_x,
357
        xd->plane[0].subsampling_y, do_warping);
RogerZhou's avatar
RogerZhou committed
358
#else
Yunqing Wang's avatar
Yunqing Wang committed
359
    newmv_count += add_ref_mv_candidate(
360
        candidate_mi, candidate, rf, refmv_count, ref_match_count, ref_mv_stack,
Luc Trudeau's avatar
Luc Trudeau committed
361
        cm->allow_high_precision_mv, len,
362
#if USE_CUR_GM_REFMV
Yunqing Wang's avatar
Yunqing Wang committed
363
        gm_mv_candidates, cm->global_motion,
364
#endif  // USE_CUR_GM_REFMV
Yunqing Wang's avatar
Yunqing Wang committed
365
        col_offset, weight, xd->mi[0]->mbmi.sb_type, mi_row, mi_col,
366
        xd->plane[0].subsampling_x, xd->plane[0].subsampling_y, do_warping);
RogerZhou's avatar
RogerZhou committed
367
#endif
Yunqing Wang's avatar
Yunqing Wang committed
368
    i += len;
369
  }
370
371

  return newmv_count;
372
373
}

Yaowu Xu's avatar
Yaowu Xu committed
374
static uint8_t scan_blk_mbmi(const AV1_COMMON *cm, const MACROBLOCKD *xd,
Luc Trudeau's avatar
Luc Trudeau committed
375
                             const int mi_row, const int mi_col,
clang-format's avatar
clang-format committed
376
377
                             const MV_REFERENCE_FRAME rf[2], int row_offset,
                             int col_offset, CANDIDATE_MV *ref_mv_stack,
378
                             uint8_t *ref_match_count,
379
#if USE_CUR_GM_REFMV
380
                             int_mv *gm_mv_candidates,
381
#endif  // USE_CUR_GM_REFMV
382
                             uint8_t *refmv_count) {
383
384
  const TileInfo *const tile = &xd->tile;
  POSITION mi_pos;
385
  uint8_t newmv_count = 0;
386
  const int do_warping = 1;
387
388
389
390

  mi_pos.row = row_offset;
  mi_pos.col = col_offset;

391
  if (is_inside(tile, mi_col, mi_row, cm->mi_rows, cm, &mi_pos)) {
392
393
394
    const MODE_INFO *const candidate_mi =
        xd->mi[mi_pos.row * xd->mi_stride + mi_pos.col];
    const MB_MODE_INFO *const candidate = &candidate_mi->mbmi;
395
    const int len = mi_size_wide[BLOCK_8X8];
396

RogerZhou's avatar
RogerZhou committed
397
398
#if CONFIG_AMVR
    newmv_count += add_ref_mv_candidate(
399
        candidate_mi, candidate, rf, refmv_count, ref_match_count, ref_mv_stack,
Luc Trudeau's avatar
Luc Trudeau committed
400
        cm->allow_high_precision_mv, len,
401
#if USE_CUR_GM_REFMV
402
        gm_mv_candidates, cm->global_motion,
403
#endif  // USE_CUR_GM_REFMV
404
        mi_pos.col, 2, cm->cur_frame_force_integer_mv, xd->mi[0]->mbmi.sb_type,
405
406
        mi_row, mi_col, xd->plane[0].subsampling_x, xd->plane[0].subsampling_y,
        do_warping);
RogerZhou's avatar
RogerZhou committed
407
#else
Yunqing Wang's avatar
Yunqing Wang committed
408
    newmv_count += add_ref_mv_candidate(
409
        candidate_mi, candidate, rf, refmv_count, ref_match_count, ref_mv_stack,
Luc Trudeau's avatar
Luc Trudeau committed
410
        cm->allow_high_precision_mv, len,
411
#if USE_CUR_GM_REFMV
Yunqing Wang's avatar
Yunqing Wang committed
412
        gm_mv_candidates, cm->global_motion,
413
#endif  // USE_CUR_GM_REFMV
Yunqing Wang's avatar
Yunqing Wang committed
414
        mi_pos.col, 2, xd->mi[0]->mbmi.sb_type, mi_row, mi_col,
415
        xd->plane[0].subsampling_x, xd->plane[0].subsampling_y, do_warping);
RogerZhou's avatar
RogerZhou committed
416
#endif
417
  }  // Analyze a single 8x8 block motion information.
Yaowu Xu's avatar
Yaowu Xu committed
418

419
  return newmv_count;
420
421
}

422
423
424
425
426
static int has_top_right(const AV1_COMMON *cm, const MACROBLOCKD *xd,
                         int mi_row, int mi_col, int bs) {
  const int sb_mi_size = mi_size_wide[cm->sb_size];
  const int mask_row = mi_row & (sb_mi_size - 1);
  const int mask_col = mi_col & (sb_mi_size - 1);
427

428
  // In a split partition all apart from the bottom right has a top right
429
  int has_tr = !((mask_row & bs) && (mask_col & bs));
430

431
432
  // bs > 0 and bs is a power of 2
  assert(bs > 0 && !(bs & (bs - 1)));
433

434
435
436
  // For each 4x4 group of blocks, when the bottom right is decoded the blocks
  // to the right have not been decoded therefore the bottom right does
  // not have a top right
437
  while (bs < sb_mi_size) {
438
439
    if (mask_col & bs) {
      if ((mask_col & (2 * bs)) && (mask_row & (2 * bs))) {
440
        has_tr = 0;
441
442
443
444
445
446
447
        break;
      }
    } else {
      break;
    }
    bs <<= 1;
  }
448

449
  // The left hand of two vertical rectangles always has a top right (as the
450
  // block above will have been decoded)
451
  if (xd->n8_w < xd->n8_h)
clang-format's avatar
clang-format committed
452
    if (!xd->is_sec_rect) has_tr = 1;
453

454
455
  // The bottom of two horizontal rectangles never has a top right (as the block
  // to the right won't have been decoded)
456
  if (xd->n8_w > xd->n8_h)
clang-format's avatar
clang-format committed
457
    if (xd->is_sec_rect) has_tr = 0;
458

459
#if CONFIG_EXT_PARTITION_TYPES
460
461
462
  // The bottom left square of a Vertical A (in the old format) does
  // not have a top right as it is decoded before the right hand
  // rectangle of the partition
463
  if (xd->mi[0]->mbmi.partition == PARTITION_VERT_A)
464
    if ((mask_row & bs) && !(mask_col & bs)) has_tr = 0;
465
466
#endif  // CONFIG_EXT_PARTITION_TYPES

467
468
469
  return has_tr;
}

470
#if CONFIG_MFMV
471
472
473
474
475
476
477
478
479
static int check_sb_border(const AV1_COMMON *cm, const int mi_row,
                           const int mi_col, const int row_offset,
                           const int col_offset) {
  const int sb_mi_size = mi_size_wide[cm->sb_size];
  const int row = mi_row & (sb_mi_size - 1);
  const int col = mi_col & (sb_mi_size - 1);

  if (row + row_offset < 0 || row + row_offset >= sb_mi_size ||
      col + col_offset < 0 || col + col_offset >= sb_mi_size)
480
481
482
483
484
    return 0;

  return 1;
}

485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
static int add_tpl_ref_mv(const AV1_COMMON *cm,
                          const MV_REF *prev_frame_mvs_base,
                          const MACROBLOCKD *xd, int mi_row, int mi_col,
                          MV_REFERENCE_FRAME ref_frame, int blk_row,
                          int blk_col, uint8_t *refmv_count,
                          CANDIDATE_MV *ref_mv_stack, int16_t *mode_context) {
  (void)prev_frame_mvs_base;
  POSITION mi_pos;
  int idx;
  int coll_blk_count = 0;
  const int weight_unit = 1;  // mi_size_wide[BLOCK_8X8];

#if CONFIG_MV_COMPRESS
  mi_pos.row = (mi_row & 0x01) ? blk_row : blk_row + 1;
  mi_pos.col = (mi_col & 0x01) ? blk_col : blk_col + 1;
#else
  mi_pos.row = blk_row;
  mi_pos.col = blk_col;
#endif

  if (!is_inside(&xd->tile, mi_col, mi_row, cm->mi_rows, cm, &mi_pos))
    return coll_blk_count;

508
  const TPL_MV_REF *prev_frame_mvs =
Jingning Han's avatar
Jingning Han committed
509
      cm->tpl_mvs + ((mi_row + mi_pos.row) >> 1) * (cm->mi_stride >> 1) +
510
      ((mi_col + mi_pos.col) >> 1);
Jingning Han's avatar
Jingning Han committed
511

512
513
514
515
516
517
518
519
  MV_REFERENCE_FRAME rf[2];
  av1_set_ref_frame(rf, ref_frame);

  if (rf[1] == NONE_FRAME) {
    for (int i = 0; i < MFMV_STACK_SIZE; ++i) {
      if (prev_frame_mvs->mfmv[ref_frame - LAST_FRAME][i].as_int !=
          INVALID_MV) {
        int_mv this_refmv = prev_frame_mvs->mfmv[ref_frame - LAST_FRAME][i];
RogerZhou's avatar
RogerZhou committed
520
521
522
523
#if CONFIG_AMVR
        lower_mv_precision(&this_refmv.as_mv, cm->allow_high_precision_mv,
                           cm->cur_frame_force_integer_mv);
#else
524
        lower_mv_precision(&this_refmv.as_mv, cm->allow_high_precision_mv);
RogerZhou's avatar
RogerZhou committed
525
#endif
526

527
528
529
        if (blk_row == 0 && blk_col == 0)
          if (abs(this_refmv.as_mv.row) >= 16 ||
              abs(this_refmv.as_mv.col) >= 16)
Sarah Parker's avatar
Sarah Parker committed
530
            mode_context[ref_frame] |= (1 << GLOBALMV_OFFSET);
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559

        for (idx = 0; idx < *refmv_count; ++idx)
          if (abs(this_refmv.as_mv.row - ref_mv_stack[idx].this_mv.as_mv.row) <
                  4 &&
              abs(this_refmv.as_mv.col - ref_mv_stack[idx].this_mv.as_mv.col) <
                  4)
            break;

        if (idx < *refmv_count) ref_mv_stack[idx].weight += 2 * weight_unit;

        if (idx == *refmv_count && *refmv_count < MAX_REF_MV_STACK_SIZE) {
          ref_mv_stack[idx].this_mv.as_int = this_refmv.as_int;
          // TODO(jingning): Hard coded context number. Need to make it better
          // sense.
          ref_mv_stack[idx].pred_diff[0] = 1;
          ref_mv_stack[idx].weight = 2 * weight_unit;
          ++(*refmv_count);
        }

        ++coll_blk_count;
      }
    }
  } else {
    // Process compound inter mode
    for (int i = 0; i < MFMV_STACK_SIZE; ++i) {
      if (prev_frame_mvs->mfmv[rf[0] - LAST_FRAME][i].as_int != INVALID_MV &&
          prev_frame_mvs->mfmv[rf[1] - LAST_FRAME][i].as_int != INVALID_MV) {
        int_mv this_refmv = prev_frame_mvs->mfmv[rf[0] - LAST_FRAME][i];
        int_mv comp_refmv = prev_frame_mvs->mfmv[rf[1] - LAST_FRAME][i];
RogerZhou's avatar
RogerZhou committed
560
561
562
563
564
565
#if CONFIG_AMVR
        lower_mv_precision(&this_refmv.as_mv, cm->allow_high_precision_mv,
                           cm->cur_frame_force_integer_mv);
        lower_mv_precision(&comp_refmv.as_mv, cm->allow_high_precision_mv,
                           cm->cur_frame_force_integer_mv);
#else
566
567
        lower_mv_precision(&this_refmv.as_mv, cm->allow_high_precision_mv);
        lower_mv_precision(&comp_refmv.as_mv, cm->allow_high_precision_mv);
RogerZhou's avatar
RogerZhou committed
568
#endif
569
570
571
572
573
        if (blk_row == 0 && blk_col == 0)
          if (abs(this_refmv.as_mv.row) >= 16 ||
              abs(this_refmv.as_mv.col) >= 16 ||
              abs(comp_refmv.as_mv.row) >= 16 ||
              abs(comp_refmv.as_mv.col) >= 16)
Sarah Parker's avatar
Sarah Parker committed
574
            mode_context[ref_frame] |= (1 << GLOBALMV_OFFSET);
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607

        for (idx = 0; idx < *refmv_count; ++idx)
          if (abs(this_refmv.as_mv.row - ref_mv_stack[idx].this_mv.as_mv.row) <
                  4 &&
              abs(this_refmv.as_mv.col - ref_mv_stack[idx].this_mv.as_mv.col) <
                  4 &&
              abs(comp_refmv.as_mv.row - ref_mv_stack[idx].comp_mv.as_mv.row) <
                  4 &&
              abs(comp_refmv.as_mv.col - ref_mv_stack[idx].comp_mv.as_mv.col) <
                  4)
            break;

        if (idx < *refmv_count) ref_mv_stack[idx].weight += 2 * weight_unit;

        if (idx == *refmv_count && *refmv_count < MAX_REF_MV_STACK_SIZE) {
          ref_mv_stack[idx].this_mv.as_int = this_refmv.as_int;
          ref_mv_stack[idx].comp_mv.as_int = comp_refmv.as_int;
          // TODO(jingning): Hard coded context number. Need to make it better
          // sense.
          ref_mv_stack[idx].pred_diff[0] = 1;
          ref_mv_stack[idx].pred_diff[1] = 1;
          ref_mv_stack[idx].weight = 2 * weight_unit;
          ++(*refmv_count);
        }

        ++coll_blk_count;
      }
    }
  }

  return coll_blk_count;
}
#else
608
609
static int add_col_ref_mv(const AV1_COMMON *cm,
                          const MV_REF *prev_frame_mvs_base,
610
611
612
                          int prev_frame_mvs_stride, const MACROBLOCKD *xd,
                          int mi_row, int mi_col, MV_REFERENCE_FRAME ref_frame,
                          int blk_row, int blk_col, uint8_t *refmv_count,
613
                          CANDIDATE_MV *ref_mv_stack, int16_t *mode_context) {
614
615
#if CONFIG_TMV
  const MV_REF *prev_frame_mvs = prev_frame_mvs_base +
Yunqing Wang's avatar
Yunqing Wang committed
616
617
                                 (blk_row >> 1) * prev_frame_mvs_stride +
                                 (blk_col >> 1);
618
#else
619
  const MV_REF *prev_frame_mvs =
620
621
      prev_frame_mvs_base + blk_row * prev_frame_mvs_stride + blk_col;
#endif
622
623
624
  POSITION mi_pos;
  int ref, idx;
  int coll_blk_count = 0;
625
  const int weight_unit = mi_size_wide[BLOCK_8X8];
626

627
628
629
630
#if CONFIG_TMV
  mi_pos.row = blk_row;
  mi_pos.col = blk_col;
#else
631
632
633
634
#if CONFIG_MV_COMPRESS
  mi_pos.row = (mi_row & 0x01) ? blk_row : blk_row + 1;
  mi_pos.col = (mi_col & 0x01) ? blk_col : blk_col + 1;
#else
635
636
  mi_pos.row = blk_row;
  mi_pos.col = blk_col;
637
#endif
638
#endif  // CONFIG_TMV
639

640
  if (!is_inside(&xd->tile, mi_col, mi_row, cm->mi_rows, cm, &mi_pos))
641
    return coll_blk_count;
642
643
644
  for (ref = 0; ref < 2; ++ref) {
    if (prev_frame_mvs->ref_frame[ref] == ref_frame) {
      int_mv this_refmv = prev_frame_mvs->mv[ref];
RogerZhou's avatar
RogerZhou committed
645
646
#if CONFIG_AMVR
      lower_mv_precision(&this_refmv.as_mv, cm->allow_high_precision_mv,
647
                         cm->cur_frame_force_integer_mv);
RogerZhou's avatar
RogerZhou committed
648
#else
649
      lower_mv_precision(&this_refmv.as_mv, cm->allow_high_precision_mv);
RogerZhou's avatar
RogerZhou committed
650
#endif
651
652
653
654
655
656

#if CONFIG_OPT_REF_MV
      if (blk_row == 0 && blk_col == 0)
#endif
      {
        if (abs(this_refmv.as_mv.row) >= 16 || abs(this_refmv.as_mv.col) >= 16)
Sarah Parker's avatar
Sarah Parker committed
657
          mode_context[ref_frame] |= (1 << GLOBALMV_OFFSET);
658
      }
659
660
661
662

      for (idx = 0; idx < *refmv_count; ++idx)
        if (this_refmv.as_int == ref_mv_stack[idx].this_mv.as_int) break;

663
      if (idx < *refmv_count) ref_mv_stack[idx].weight += 2 * weight_unit;
664
665
666

      if (idx == *refmv_count && *refmv_count < MAX_REF_MV_STACK_SIZE) {
        ref_mv_stack[idx].this_mv.as_int = this_refmv.as_int;
667
668
        ref_mv_stack[idx].pred_diff[0] =
            av1_get_pred_diff_ctx(prev_frame_mvs->pred_mv[ref], this_refmv);
669
        ref_mv_stack[idx].weight = 2 * weight_unit;
670
671
672
673
674
675
676
677
678
        ++(*refmv_count);
      }

      ++coll_blk_count;
    }
  }

  return coll_blk_count;
}
679
#endif  // CONFIG_MFMV
680

Yaowu Xu's avatar
Yaowu Xu committed
681
static void setup_ref_mv_list(const AV1_COMMON *cm, const MACROBLOCKD *xd,
682
                              MV_REFERENCE_FRAME ref_frame,
clang-format's avatar
clang-format committed
683
                              uint8_t *refmv_count, CANDIDATE_MV *ref_mv_stack,
684
                              int_mv *mv_ref_list,
685
#if USE_CUR_GM_REFMV
686
                              int_mv *gm_mv_candidates,
687
#endif  // USE_CUR_GM_REFMV
Luc Trudeau's avatar
Luc Trudeau committed
688
                              int mi_row, int mi_col, int16_t *mode_context) {
689
690
691
692
693
694
695
696
697
698
699
#if CONFIG_TMV
  const int prev_frame_mvs_stride = ROUND_POWER_OF_TWO(cm->mi_cols, 1);
  const int tmi_row = mi_row & 0xfffe;
  const int tmi_col = mi_col & 0xfffe;
  const MV_REF *const prev_frame_mvs_base =
      cm->use_prev_frame_mvs
          ? cm->prev_frame->mvs + (tmi_row >> 1) * prev_frame_mvs_stride +
                (tmi_col >> 1)
          : NULL;
#else
  const int prev_frame_mvs_stride = cm->mi_cols;
700
701
702
#if CONFIG_MV_COMPRESS
  const MV_REF *const prev_frame_mvs_base =
      cm->use_prev_frame_mvs
703
704
          ? cm->prev_frame->mvs +
                (((mi_row >> 1) << 1) + 1) * prev_frame_mvs_stride +
705
706
707
                ((mi_col >> 1) << 1) + 1
          : NULL;
#else
clang-format's avatar
clang-format committed
708
709
  const MV_REF *const prev_frame_mvs_base =
      cm->use_prev_frame_mvs
710
          ? cm->prev_frame->mvs + mi_row * prev_frame_mvs_stride + mi_col
clang-format's avatar
clang-format committed
711
          : NULL;
712
#endif
713
#endif  // CONFIG_TMV
714

715
  const int bs = AOMMAX(xd->n8_w, xd->n8_h);
716
  const int has_tr = has_top_right(cm, xd, mi_row, mi_col, bs);
Jingning Han's avatar
Jingning Han committed
717
718
  MV_REFERENCE_FRAME rf[2];

Yunqing Wang's avatar
Yunqing Wang committed
719
  const TileInfo *const tile = &xd->tile;
720
721
722
723
724
  int max_row_offset = 0, max_col_offset = 0;
  const int row_adj = (xd->n8_h < mi_size_high[BLOCK_8X8]) && (mi_row & 0x01);
  const int col_adj = (xd->n8_w < mi_size_wide[BLOCK_8X8]) && (mi_col & 0x01);
  int processed_rows = 0;
  int processed_cols = 0;
Yunqing Wang's avatar
Yunqing Wang committed
725

726
  av1_set_ref_frame(rf, ref_frame);
727
  mode_context[ref_frame] = 0;
728
  *refmv_count = 0;
729

730
731
732
  // Find valid maximum row/col offset.
  if (xd->up_available) {
    max_row_offset = -(MVREF_ROWS << 1) + row_adj;
733
734
735
736
#if CONFIG_OPT_REF_MV
    if (xd->n8_h < mi_size_high[BLOCK_8X8])
      max_row_offset = -(2 << 1) + row_adj;
#endif
Yunqing Wang's avatar
Yunqing Wang committed
737
738
739
    max_row_offset =
        find_valid_row_offset(tile, mi_row, cm->mi_rows, cm, max_row_offset);
  }
740
741
742

  if (xd->left_available) {
    max_col_offset = -(MVREF_COLS << 1) + col_adj;
743
744
745
746
#if CONFIG_OPT_REF_MV
    if (xd->n8_w < mi_size_wide[BLOCK_8X8])
      max_col_offset = -(2 << 1) + col_adj;
#endif
Yunqing Wang's avatar
Yunqing Wang committed
747
748
    max_col_offset = find_valid_col_offset(tile, mi_col, max_col_offset);
  }
749

750
751
752
  uint8_t ref_match_count = 0;
  uint8_t newmv_count = 0;

753
754
  // Scan the first above row mode info. row_offset = -1;
  if (abs(max_row_offset) >= 1)
Luc Trudeau's avatar
Luc Trudeau committed
755
756
    newmv_count += scan_row_mbmi(cm, xd, mi_row, mi_col, rf, -1, ref_mv_stack,
                                 refmv_count, &ref_match_count,
757
#if USE_CUR_GM_REFMV
Yunqing Wang's avatar
Yunqing Wang committed
758
                                 gm_mv_candidates,
759
#endif  // USE_CUR_GM_REFMV
Yunqing Wang's avatar
Yunqing Wang committed
760
                                 max_row_offset, &processed_rows);
761
762
  // Scan the first left column mode info. col_offset = -1;
  if (abs(max_col_offset) >= 1)
Luc Trudeau's avatar
Luc Trudeau committed
763
764
    newmv_count += scan_col_mbmi(cm, xd, mi_row, mi_col, rf, -1, ref_mv_stack,
                                 refmv_count, &ref_match_count,
765
#if USE_CUR_GM_REFMV
Yunqing Wang's avatar
Yunqing Wang committed
766
                                 gm_mv_candidates,
767
#endif  // USE_CUR_GM_REFMV
Yunqing Wang's avatar
Yunqing Wang committed
768
                                 max_col_offset, &processed_cols);
769
770
  // Check top-right boundary
  if (has_tr)
Luc Trudeau's avatar
Luc Trudeau committed
771
772
    newmv_count += scan_blk_mbmi(cm, xd, mi_row, mi_col, rf, -1, xd->n8_w,
                                 ref_mv_stack, &ref_match_count,
773
#if USE_CUR_GM_REFMV
774
                                 gm_mv_candidates,
775
#endif  // USE_CUR_GM_REFMV
776
                                 refmv_count);
777

778
779
  const int nearest_match = ref_match_count;
  const int nearest_refmv_count = *refmv_count;
780

781
  for (int idx = 0; idx < nearest_refmv_count; ++idx)
782
    ref_mv_stack[idx].weight += REF_CAT_LEVEL;
783
784

#if CONFIG_MFMV
785
  if (cm->use_ref_frame_mvs) {
786
    int coll_blk_count = 0;
787
788
    const int voffset = AOMMAX(mi_size_high[BLOCK_8X8], xd->n8_h);
    const int hoffset = AOMMAX(mi_size_wide[BLOCK_8X8], xd->n8_w);
789

790
    const int tpl_sample_pos[9][2] = {
791
792
793
794
795
      { -2, hoffset }, { 0, hoffset },  { voffset, hoffset },
      { voffset, 0 },  { voffset, -2 }, { voffset, -4 },
      { -4, hoffset }, { voffset, 4 },  { 2, hoffset + 4 },
    };

796
797
798
    for (int blk_row = 0; blk_row < xd->n8_h;
         blk_row += mi_size_high[BLOCK_8X8]) {
      for (int blk_col = 0; blk_col < xd->n8_w;
799
800
801
802
803
804
805
806
807
           blk_col += mi_size_wide[BLOCK_8X8]) {
        // (TODO: yunqing) prev_frame_mvs_base is not used here, tpl_mvs is
        // used.
        // Can be modified the same way.
        int is_available = add_tpl_ref_mv(
            cm, prev_frame_mvs_base, xd, mi_row, mi_col, ref_frame, blk_row,
            blk_col, refmv_count, ref_mv_stack, mode_context);
        if (blk_row == 0 && blk_col == 0) coll_blk_count = is_available;
      }
808
809
    }

Sarah Parker's avatar
Sarah Parker committed
810
    if (coll_blk_count == 0) mode_context[ref_frame] |= (1 << GLOBALMV_OFFSET);
811

812
813
814
    for (int i = 0; i < 9; ++i) {
      const int blk_row = tpl_sample_pos[i][0];
      const int blk_col = tpl_sample_pos[i][1];
815

816
817
818
819
820
821
822
      if (!check_sb_border(cm, mi_row, mi_col, blk_row, blk_col)) continue;
      // (TODO: yunqing) prev_frame_mvs_base is not used here, tpl_mvs is used.
      // Can be modified the same way.
      coll_blk_count += add_tpl_ref_mv(cm, prev_frame_mvs_base, xd, mi_row,
                                       mi_col, ref_frame, blk_row, blk_col,
                                       refmv_count, ref_mv_stack, mode_context);
    }
823
824
  }
#else
825
#if CONFIG_TEMPMV_SIGNALING
826
  if (cm->use_prev_frame_mvs && rf[1] == NONE_FRAME)
827
#else
clang-format's avatar
clang-format committed
828
  if (prev_frame_mvs_base && cm->show_frame && cm->last_show_frame &&
829
      rf[1] == NONE_FRAME)
830
#endif
831
  {
832
    int coll_blk_count = 0;
833
834
835
    const int mi_step = (xd->n8_w == 1 || xd->n8_h == 1)
                            ? mi_size_wide[BLOCK_8X8]
                            : mi_size_wide[BLOCK_16X16];
836

837
838
    for (int blk_row = 0; blk_row < xd->n8_h; blk_row += mi_step) {
      for (int blk_col = 0; blk_col < xd->n8_w; blk_col += mi_step) {
839
840
841
842
843
844
845
846
847
848
849
#if CONFIG_TMV
        int is_available =
            add_col_ref_mv(cm, prev_frame_mvs_base, prev_frame_mvs_stride, xd,
                           tmi_row, tmi_col, ref_frame, blk_row, blk_col,
                           refmv_count, ref_mv_stack, mode_context);
#else
        int is_available =
            add_col_ref_mv(cm, prev_frame_mvs_base, prev_frame_mvs_stride, xd,
                           mi_row, mi_col, ref_frame, blk_row, blk_col,
                           refmv_count, ref_mv_stack, mode_context);
#endif  // CONFIG_TMV
850
851
852
853
854
#if CONFIG_OPT_REF_MV
        if (blk_row == 0 && blk_col == 0) coll_blk_count = is_available;
#else
        coll_blk_count += is_available;
#endif
855
856
      }
    }
857

Sarah Parker's avatar
Sarah Parker committed
858
    if (coll_blk_count == 0) mode_context[ref_frame] |= (1 << GLOBALMV_OFFSET);
859
  } else {