decodemv.c 31.1 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jingning Han's avatar
Jingning Han committed
3
 *
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 13
 */

#include <assert.h>

Yaowu Xu's avatar
Yaowu Xu committed
14 15 16 17 18 19 20 21
#include "av1/common/common.h"
#include "av1/common/entropy.h"
#include "av1/common/entropymode.h"
#include "av1/common/entropymv.h"
#include "av1/common/mvref_common.h"
#include "av1/common/pred_common.h"
#include "av1/common/reconinter.h"
#include "av1/common/seg_common.h"
Jingning Han's avatar
Jingning Han committed
22

Yaowu Xu's avatar
Yaowu Xu committed
23
#include "av1/decoder/decodeframe.h"
Jingning Han's avatar
Jingning Han committed
24
#include "av1/decoder/decodemv.h"
Jingning Han's avatar
Jingning Han committed
25

Adrian Grange's avatar
Adrian Grange committed
26
#include "aom_dsp/aom_dsp_common.h"
27

Adrian Grange's avatar
Adrian Grange committed
28
static PREDICTION_MODE read_intra_mode(aom_reader *r, const aom_prob *p) {
29
  return (PREDICTION_MODE)aom_read_tree(r, av1_intra_mode_tree, p);
Jingning Han's avatar
Jingning Han committed
30 31
}

32
static PREDICTION_MODE read_intra_mode_y(AV1_COMMON *cm, MACROBLOCKD *xd,
Adrian Grange's avatar
Adrian Grange committed
33
                                         aom_reader *r, int size_group) {
Jingning Han's avatar
Jingning Han committed
34 35 36
  const PREDICTION_MODE y_mode =
      read_intra_mode(r, cm->fc->y_mode_prob[size_group]);
  FRAME_COUNTS *counts = xd->counts;
clang-format's avatar
clang-format committed
37
  if (counts) ++counts->y_mode[size_group][y_mode];
Jingning Han's avatar
Jingning Han committed
38 39 40
  return y_mode;
}

41
static PREDICTION_MODE read_intra_mode_uv(AV1_COMMON *cm, MACROBLOCKD *xd,
Adrian Grange's avatar
Adrian Grange committed
42
                                          aom_reader *r,
Jingning Han's avatar
Jingning Han committed
43
                                          PREDICTION_MODE y_mode) {
clang-format's avatar
clang-format committed
44 45
  const PREDICTION_MODE uv_mode =
      read_intra_mode(r, cm->fc->uv_mode_prob[y_mode]);
Jingning Han's avatar
Jingning Han committed
46
  FRAME_COUNTS *counts = xd->counts;
clang-format's avatar
clang-format committed
47
  if (counts) ++counts->uv_mode[y_mode][uv_mode];
Jingning Han's avatar
Jingning Han committed
48 49 50
  return uv_mode;
}

51
static PREDICTION_MODE read_inter_mode(AV1_COMMON *cm, MACROBLOCKD *xd,
52
                                       aom_reader *r, int16_t ctx) {
53 54
#if CONFIG_REF_MV
  FRAME_COUNTS *counts = xd->counts;
55
  int16_t mode_ctx = ctx & NEWMV_CTX_MASK;
56 57 58
  aom_prob mode_prob = cm->fc->newmv_prob[mode_ctx];

  if (aom_read(r, mode_prob) == 0) {
clang-format's avatar
clang-format committed
59
    if (counts) ++counts->newmv_mode[mode_ctx][0];
60 61
    return NEWMV;
  }
clang-format's avatar
clang-format committed
62
  if (counts) ++counts->newmv_mode[mode_ctx][1];
63

clang-format's avatar
clang-format committed
64
  if (ctx & (1 << ALL_ZERO_FLAG_OFFSET)) return ZEROMV;
65

66
  mode_ctx = (ctx >> ZEROMV_OFFSET) & ZEROMV_CTX_MASK;
67 68 69

  mode_prob = cm->fc->zeromv_prob[mode_ctx];
  if (aom_read(r, mode_prob) == 0) {
clang-format's avatar
clang-format committed
70
    if (counts) ++counts->zeromv_mode[mode_ctx][0];
71 72
    return ZEROMV;
  }
clang-format's avatar
clang-format committed
73
  if (counts) ++counts->zeromv_mode[mode_ctx][1];
74

75
  mode_ctx = (ctx >> REFMV_OFFSET) & REFMV_CTX_MASK;
76

clang-format's avatar
clang-format committed
77 78 79
  if (ctx & (1 << SKIP_NEARESTMV_OFFSET)) mode_ctx = 6;
  if (ctx & (1 << SKIP_NEARMV_OFFSET)) mode_ctx = 7;
  if (ctx & (1 << SKIP_NEARESTMV_SUB8X8_OFFSET)) mode_ctx = 8;
80

81 82
  mode_prob = cm->fc->refmv_prob[mode_ctx];
  if (aom_read(r, mode_prob) == 0) {
clang-format's avatar
clang-format committed
83
    if (counts) ++counts->refmv_mode[mode_ctx][0];
84 85
    return NEARESTMV;
  } else {
clang-format's avatar
clang-format committed
86
    if (counts) ++counts->refmv_mode[mode_ctx][1];
87 88 89 90 91 92
    return NEARMV;
  }

  // Invalid prediction mode.
  assert(0);
#else
clang-format's avatar
clang-format committed
93
  const int mode =
94
      aom_read_tree(r, av1_inter_mode_tree, cm->fc->inter_mode_probs[ctx]);
Jingning Han's avatar
Jingning Han committed
95
  FRAME_COUNTS *counts = xd->counts;
clang-format's avatar
clang-format committed
96
  if (counts) ++counts->inter_mode[ctx][mode];
Jingning Han's avatar
Jingning Han committed
97 98

  return NEARESTMV + mode;
99
#endif
Jingning Han's avatar
Jingning Han committed
100 101
}

102
#if CONFIG_REF_MV
clang-format's avatar
clang-format committed
103 104
static void read_drl_idx(const AV1_COMMON *cm, MACROBLOCKD *xd,
                         MB_MODE_INFO *mbmi, aom_reader *r) {
105 106 107
  uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
  mbmi->ref_mv_idx = 0;

108 109 110 111 112 113 114 115
  if (mbmi->mode == NEWMV) {
    int idx;
    for (idx = 0; idx < 2; ++idx) {
      if (xd->ref_mv_count[ref_frame_type] > idx + 1) {
        uint8_t drl_ctx = av1_drl_ctx(xd->ref_mv_stack[ref_frame_type], idx);
        aom_prob drl_prob = cm->fc->drl_prob[drl_ctx];
        if (!aom_read(r, drl_prob)) {
          mbmi->ref_mv_idx = idx;
clang-format's avatar
clang-format committed
116
          if (xd->counts) ++xd->counts->drl_mode[drl_ctx][0];
117 118 119
          return;
        }
        mbmi->ref_mv_idx = idx + 1;
clang-format's avatar
clang-format committed
120
        if (xd->counts) ++xd->counts->drl_mode[drl_ctx][1];
121 122 123 124
      }
    }
  }

125 126 127 128 129 130 131 132 133 134 135
  if (mbmi->mode == NEARMV) {
    int idx;
    // Offset the NEARESTMV mode.
    // TODO(jingning): Unify the two syntax decoding loops after the NEARESTMV
    // mode is factored in.
    for (idx = 1; idx < 3; ++idx) {
      if (xd->ref_mv_count[ref_frame_type] > idx + 1) {
        uint8_t drl_ctx = av1_drl_ctx(xd->ref_mv_stack[ref_frame_type], idx);
        aom_prob drl_prob = cm->fc->drl_prob[drl_ctx];
        if (!aom_read(r, drl_prob)) {
          mbmi->ref_mv_idx = idx - 1;
clang-format's avatar
clang-format committed
136
          if (xd->counts) ++xd->counts->drl_mode[drl_ctx][0];
137 138
          return;
        }
139
        mbmi->ref_mv_idx = idx;
clang-format's avatar
clang-format committed
140
        if (xd->counts) ++xd->counts->drl_mode[drl_ctx][1];
141 142 143 144 145 146
      }
    }
  }
}
#endif

Adrian Grange's avatar
Adrian Grange committed
147
static int read_segment_id(aom_reader *r,
clang-format's avatar
clang-format committed
148
                           const struct segmentation_probs *segp) {
149
  return aom_read_tree(r, av1_segment_tree, segp->tree_probs);
Jingning Han's avatar
Jingning Han committed
150 151
}

152
static TX_SIZE read_selected_tx_size(AV1_COMMON *cm, MACROBLOCKD *xd,
Adrian Grange's avatar
Adrian Grange committed
153
                                     TX_SIZE max_tx_size, aom_reader *r) {
Jingning Han's avatar
Jingning Han committed
154 155
  FRAME_COUNTS *counts = xd->counts;
  const int ctx = get_tx_size_context(xd);
Adrian Grange's avatar
Adrian Grange committed
156 157
  const aom_prob *tx_probs = get_tx_probs(max_tx_size, ctx, &cm->fc->tx_probs);
  int tx_size = aom_read(r, tx_probs[0]);
Jingning Han's avatar
Jingning Han committed
158
  if (tx_size != TX_4X4 && max_tx_size >= TX_16X16) {
Adrian Grange's avatar
Adrian Grange committed
159
    tx_size += aom_read(r, tx_probs[1]);
Jingning Han's avatar
Jingning Han committed
160
    if (tx_size != TX_8X8 && max_tx_size >= TX_32X32)
Adrian Grange's avatar
Adrian Grange committed
161
      tx_size += aom_read(r, tx_probs[2]);
Jingning Han's avatar
Jingning Han committed
162 163
  }

clang-format's avatar
clang-format committed
164
  if (counts) ++get_tx_counts(max_tx_size, ctx, &counts->tx)[tx_size];
Jingning Han's avatar
Jingning Han committed
165 166 167
  return (TX_SIZE)tx_size;
}

168
static TX_SIZE read_tx_size(AV1_COMMON *cm, MACROBLOCKD *xd, int allow_select,
Adrian Grange's avatar
Adrian Grange committed
169
                            aom_reader *r) {
Jingning Han's avatar
Jingning Han committed
170 171 172
  TX_MODE tx_mode = cm->tx_mode;
  BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type;
  const TX_SIZE max_tx_size = max_txsize_lookup[bsize];
clang-format's avatar
clang-format committed
173
  if (xd->lossless[xd->mi[0]->mbmi.segment_id]) return TX_4X4;
Jingning Han's avatar
Jingning Han committed
174 175 176
  if (allow_select && tx_mode == TX_MODE_SELECT && bsize >= BLOCK_8X8)
    return read_selected_tx_size(cm, xd, max_tx_size, r);
  else
Adrian Grange's avatar
Adrian Grange committed
177
    return AOMMIN(max_tx_size, tx_mode_to_biggest_tx_size[tx_mode]);
Jingning Han's avatar
Jingning Han committed
178 179
}

180
static int dec_get_segment_id(const AV1_COMMON *cm, const uint8_t *segment_ids,
Jingning Han's avatar
Jingning Han committed
181 182 183 184 185
                              int mi_offset, int x_mis, int y_mis) {
  int x, y, segment_id = INT_MAX;

  for (y = 0; y < y_mis; y++)
    for (x = 0; x < x_mis; x++)
186
      segment_id =
Adrian Grange's avatar
Adrian Grange committed
187
          AOMMIN(segment_id, segment_ids[mi_offset + y * cm->mi_cols + x]);
Jingning Han's avatar
Jingning Han committed
188 189 190 191 192

  assert(segment_id >= 0 && segment_id < MAX_SEGMENTS);
  return segment_id;
}

193
static void set_segment_id(AV1_COMMON *cm, int mi_offset, int x_mis, int y_mis,
clang-format's avatar
clang-format committed
194
                           int segment_id) {
Jingning Han's avatar
Jingning Han committed
195 196 197 198 199 200 201 202 203
  int x, y;

  assert(segment_id >= 0 && segment_id < MAX_SEGMENTS);

  for (y = 0; y < y_mis; y++)
    for (x = 0; x < x_mis; x++)
      cm->current_frame_seg_map[mi_offset + y * cm->mi_cols + x] = segment_id;
}

204
static int read_intra_segment_id(AV1_COMMON *const cm, MACROBLOCKD *const xd,
205
                                 int mi_offset, int x_mis, int y_mis,
Adrian Grange's avatar
Adrian Grange committed
206
                                 aom_reader *r) {
Jingning Han's avatar
Jingning Han committed
207
  struct segmentation *const seg = &cm->seg;
208 209 210 211 212 213
#if CONFIG_MISC_FIXES
  FRAME_COUNTS *counts = xd->counts;
  struct segmentation_probs *const segp = &cm->fc->seg;
#else
  struct segmentation_probs *const segp = &cm->segp;
#endif
Jingning Han's avatar
Jingning Han committed
214 215
  int segment_id;

216
#if !CONFIG_MISC_FIXES
clang-format's avatar
clang-format committed
217
  (void)xd;
218 219
#endif

clang-format's avatar
clang-format committed
220
  if (!seg->enabled) return 0;  // Default for disabled segmentation
Jingning Han's avatar
Jingning Han committed
221

222
  assert(seg->update_map && !seg->temporal_update);
Jingning Han's avatar
Jingning Han committed
223

224 225
  segment_id = read_segment_id(r, segp);
#if CONFIG_MISC_FIXES
clang-format's avatar
clang-format committed
226
  if (counts) ++counts->seg.tree_total[segment_id];
227
#endif
Jingning Han's avatar
Jingning Han committed
228 229 230 231
  set_segment_id(cm, mi_offset, x_mis, y_mis, segment_id);
  return segment_id;
}

232
static void copy_segment_id(const AV1_COMMON *cm,
clang-format's avatar
clang-format committed
233 234 235
                            const uint8_t *last_segment_ids,
                            uint8_t *current_segment_ids, int mi_offset,
                            int x_mis, int y_mis) {
236 237 238 239
  int x, y;

  for (y = 0; y < y_mis; y++)
    for (x = 0; x < x_mis; x++)
clang-format's avatar
clang-format committed
240 241 242
      current_segment_ids[mi_offset + y * cm->mi_cols + x] =
          last_segment_ids ? last_segment_ids[mi_offset + y * cm->mi_cols + x]
                           : 0;
243 244
}

245
static int read_inter_segment_id(AV1_COMMON *const cm, MACROBLOCKD *const xd,
Adrian Grange's avatar
Adrian Grange committed
246
                                 int mi_row, int mi_col, aom_reader *r) {
Jingning Han's avatar
Jingning Han committed
247
  struct segmentation *const seg = &cm->seg;
248 249 250 251 252 253
#if CONFIG_MISC_FIXES
  FRAME_COUNTS *counts = xd->counts;
  struct segmentation_probs *const segp = &cm->fc->seg;
#else
  struct segmentation_probs *const segp = &cm->segp;
#endif
Jingning Han's avatar
Jingning Han committed
254 255 256 257 258 259 260
  MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
  int predicted_segment_id, segment_id;
  const int mi_offset = mi_row * cm->mi_cols + mi_col;
  const int bw = xd->plane[0].n4_w >> 1;
  const int bh = xd->plane[0].n4_h >> 1;

  // TODO(slavarnway): move x_mis, y_mis into xd ?????
Adrian Grange's avatar
Adrian Grange committed
261 262
  const int x_mis = AOMMIN(cm->mi_cols - mi_col, bw);
  const int y_mis = AOMMIN(cm->mi_rows - mi_row, bh);
Jingning Han's avatar
Jingning Han committed
263

clang-format's avatar
clang-format committed
264
  if (!seg->enabled) return 0;  // Default for disabled segmentation
Jingning Han's avatar
Jingning Han committed
265

clang-format's avatar
clang-format committed
266 267 268 269
  predicted_segment_id = cm->last_frame_seg_map
                             ? dec_get_segment_id(cm, cm->last_frame_seg_map,
                                                  mi_offset, x_mis, y_mis)
                             : 0;
Jingning Han's avatar
Jingning Han committed
270 271 272 273 274 275 276 277

  if (!seg->update_map) {
    copy_segment_id(cm, cm->last_frame_seg_map, cm->current_frame_seg_map,
                    mi_offset, x_mis, y_mis);
    return predicted_segment_id;
  }

  if (seg->temporal_update) {
278
    const int ctx = av1_get_pred_context_seg_id(xd);
Adrian Grange's avatar
Adrian Grange committed
279 280
    const aom_prob pred_prob = segp->pred_probs[ctx];
    mbmi->seg_id_predicted = aom_read(r, pred_prob);
281
#if CONFIG_MISC_FIXES
clang-format's avatar
clang-format committed
282
    if (counts) ++counts->seg.pred[ctx][mbmi->seg_id_predicted];
283 284 285 286 287 288
#endif
    if (mbmi->seg_id_predicted) {
      segment_id = predicted_segment_id;
    } else {
      segment_id = read_segment_id(r, segp);
#if CONFIG_MISC_FIXES
clang-format's avatar
clang-format committed
289
      if (counts) ++counts->seg.tree_mispred[segment_id];
290 291
#endif
    }
Jingning Han's avatar
Jingning Han committed
292
  } else {
293 294
    segment_id = read_segment_id(r, segp);
#if CONFIG_MISC_FIXES
clang-format's avatar
clang-format committed
295
    if (counts) ++counts->seg.tree_total[segment_id];
296
#endif
Jingning Han's avatar
Jingning Han committed
297 298 299 300 301
  }
  set_segment_id(cm, mi_offset, x_mis, y_mis, segment_id);
  return segment_id;
}

302
static int read_skip(AV1_COMMON *cm, const MACROBLOCKD *xd, int segment_id,
Adrian Grange's avatar
Adrian Grange committed
303
                     aom_reader *r) {
Jingning Han's avatar
Jingning Han committed
304 305 306
  if (segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)) {
    return 1;
  } else {
307
    const int ctx = av1_get_skip_context(xd);
Adrian Grange's avatar
Adrian Grange committed
308
    const int skip = aom_read(r, cm->fc->skip_probs[ctx]);
Jingning Han's avatar
Jingning Han committed
309
    FRAME_COUNTS *counts = xd->counts;
clang-format's avatar
clang-format committed
310
    if (counts) ++counts->skip[ctx][skip];
Jingning Han's avatar
Jingning Han committed
311 312 313 314
    return skip;
  }
}

315
static void read_intra_frame_mode_info(AV1_COMMON *const cm,
clang-format's avatar
clang-format committed
316
                                       MACROBLOCKD *const xd, int mi_row,
Adrian Grange's avatar
Adrian Grange committed
317
                                       int mi_col, aom_reader *r) {
Jingning Han's avatar
Jingning Han committed
318 319 320
  MODE_INFO *const mi = xd->mi[0];
  MB_MODE_INFO *const mbmi = &mi->mbmi;
  const MODE_INFO *above_mi = xd->above_mi;
clang-format's avatar
clang-format committed
321
  const MODE_INFO *left_mi = xd->left_mi;
Jingning Han's avatar
Jingning Han committed
322 323 324 325 326 327 328
  const BLOCK_SIZE bsize = mbmi->sb_type;
  int i;
  const int mi_offset = mi_row * cm->mi_cols + mi_col;
  const int bw = xd->plane[0].n4_w >> 1;
  const int bh = xd->plane[0].n4_h >> 1;

  // TODO(slavarnway): move x_mis, y_mis into xd ?????
Adrian Grange's avatar
Adrian Grange committed
329 330
  const int x_mis = AOMMIN(cm->mi_cols - mi_col, bw);
  const int y_mis = AOMMIN(cm->mi_rows - mi_row, bh);
Jingning Han's avatar
Jingning Han committed
331

332
  mbmi->segment_id = read_intra_segment_id(cm, xd, mi_offset, x_mis, y_mis, r);
Jingning Han's avatar
Jingning Han committed
333 334 335 336 337 338 339 340 341
  mbmi->skip = read_skip(cm, xd, mbmi->segment_id, r);
  mbmi->tx_size = read_tx_size(cm, xd, 1, r);
  mbmi->ref_frame[0] = INTRA_FRAME;
  mbmi->ref_frame[1] = NONE;

  switch (bsize) {
    case BLOCK_4X4:
      for (i = 0; i < 4; ++i)
        mi->bmi[i].as_mode =
342
            read_intra_mode(r, get_y_mode_probs(cm, mi, above_mi, left_mi, i));
Jingning Han's avatar
Jingning Han committed
343 344 345 346
      mbmi->mode = mi->bmi[3].as_mode;
      break;
    case BLOCK_4X8:
      mi->bmi[0].as_mode = mi->bmi[2].as_mode =
347
          read_intra_mode(r, get_y_mode_probs(cm, mi, above_mi, left_mi, 0));
Jingning Han's avatar
Jingning Han committed
348
      mi->bmi[1].as_mode = mi->bmi[3].as_mode = mbmi->mode =
349
          read_intra_mode(r, get_y_mode_probs(cm, mi, above_mi, left_mi, 1));
Jingning Han's avatar
Jingning Han committed
350 351 352
      break;
    case BLOCK_8X4:
      mi->bmi[0].as_mode = mi->bmi[1].as_mode =
353
          read_intra_mode(r, get_y_mode_probs(cm, mi, above_mi, left_mi, 0));
Jingning Han's avatar
Jingning Han committed
354
      mi->bmi[2].as_mode = mi->bmi[3].as_mode = mbmi->mode =
355
          read_intra_mode(r, get_y_mode_probs(cm, mi, above_mi, left_mi, 2));
Jingning Han's avatar
Jingning Han committed
356 357
      break;
    default:
clang-format's avatar
clang-format committed
358 359
      mbmi->mode =
          read_intra_mode(r, get_y_mode_probs(cm, mi, above_mi, left_mi, 0));
Jingning Han's avatar
Jingning Han committed
360 361
  }

362
  mbmi->uv_mode = read_intra_mode_uv(cm, xd, r, mbmi->mode);
363

clang-format's avatar
clang-format committed
364
  if (mbmi->tx_size < TX_32X32 && cm->base_qindex > 0 && !mbmi->skip &&
365 366 367
      !segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) {
    FRAME_COUNTS *counts = xd->counts;
    TX_TYPE tx_type_nom = intra_mode_to_tx_type_context[mbmi->mode];
clang-format's avatar
clang-format committed
368
    mbmi->tx_type =
369
        aom_read_tree(r, av1_ext_tx_tree,
clang-format's avatar
clang-format committed
370
                      cm->fc->intra_ext_tx_prob[mbmi->tx_size][tx_type_nom]);
371 372 373 374 375
    if (counts)
      ++counts->intra_ext_tx[mbmi->tx_size][tx_type_nom][mbmi->tx_type];
  } else {
    mbmi->tx_type = DCT_DCT;
  }
Jingning Han's avatar
Jingning Han committed
376 377
}

Adrian Grange's avatar
Adrian Grange committed
378
static int read_mv_component(aom_reader *r, const nmv_component *mvcomp,
clang-format's avatar
clang-format committed
379
                             int usehp) {
Jingning Han's avatar
Jingning Han committed
380
  int mag, d, fr, hp;
Adrian Grange's avatar
Adrian Grange committed
381
  const int sign = aom_read(r, mvcomp->sign);
382
  const int mv_class = aom_read_tree(r, av1_mv_class_tree, mvcomp->classes);
Jingning Han's avatar
Jingning Han committed
383 384 385 386
  const int class0 = mv_class == MV_CLASS_0;

  // Integer part
  if (class0) {
387
    d = aom_read_tree(r, av1_mv_class0_tree, mvcomp->class0);
Jingning Han's avatar
Jingning Han committed
388 389 390 391 392 393
    mag = 0;
  } else {
    int i;
    const int n = mv_class + CLASS0_BITS - 1;  // number of bits

    d = 0;
Adrian Grange's avatar
Adrian Grange committed
394
    for (i = 0; i < n; ++i) d |= aom_read(r, mvcomp->bits[i]) << i;
Jingning Han's avatar
Jingning Han committed
395 396 397 398
    mag = CLASS0_SIZE << (mv_class + 2);
  }

  // Fractional part
399
  fr = aom_read_tree(r, av1_mv_fp_tree,
clang-format's avatar
clang-format committed
400
                     class0 ? mvcomp->class0_fp[d] : mvcomp->fp);
Jingning Han's avatar
Jingning Han committed
401 402

  // High precision part (if hp is not used, the default value of the hp is 1)
Adrian Grange's avatar
Adrian Grange committed
403
  hp = usehp ? aom_read(r, class0 ? mvcomp->class0_hp : mvcomp->hp) : 1;
Jingning Han's avatar
Jingning Han committed
404 405 406 407 408 409

  // Result
  mag += ((d << 3) | (fr << 1) | hp) + 1;
  return sign ? -mag : mag;
}

Adrian Grange's avatar
Adrian Grange committed
410
static INLINE void read_mv(aom_reader *r, MV *mv, const MV *ref,
clang-format's avatar
clang-format committed
411 412
                           const nmv_context *ctx, nmv_context_counts *counts,
                           int allow_hp) {
Jingning Han's avatar
Jingning Han committed
413
  const MV_JOINT_TYPE joint_type =
414 415
      (MV_JOINT_TYPE)aom_read_tree(r, av1_mv_joint_tree, ctx->joints);
  const int use_hp = allow_hp && av1_use_mv_hp(ref);
clang-format's avatar
clang-format committed
416
  MV diff = { 0, 0 };
Jingning Han's avatar
Jingning Han committed
417 418 419 420 421 422 423

  if (mv_joint_vertical(joint_type))
    diff.row = read_mv_component(r, &ctx->comps[0], use_hp);

  if (mv_joint_horizontal(joint_type))
    diff.col = read_mv_component(r, &ctx->comps[1], use_hp);

424
  av1_inc_mv(&diff, counts, use_hp);
Jingning Han's avatar
Jingning Han committed
425 426 427 428 429

  mv->row = ref->row + diff.row;
  mv->col = ref->col + diff.col;
}

430
static REFERENCE_MODE read_block_reference_mode(AV1_COMMON *cm,
Jingning Han's avatar
Jingning Han committed
431
                                                const MACROBLOCKD *xd,
Adrian Grange's avatar
Adrian Grange committed
432
                                                aom_reader *r) {
Jingning Han's avatar
Jingning Han committed
433
  if (cm->reference_mode == REFERENCE_MODE_SELECT) {
434
    const int ctx = av1_get_reference_mode_context(cm, xd);
Jingning Han's avatar
Jingning Han committed
435
    const REFERENCE_MODE mode =
Adrian Grange's avatar
Adrian Grange committed
436
        (REFERENCE_MODE)aom_read(r, cm->fc->comp_inter_prob[ctx]);
Jingning Han's avatar
Jingning Han committed
437
    FRAME_COUNTS *counts = xd->counts;
clang-format's avatar
clang-format committed
438
    if (counts) ++counts->comp_inter[ctx][mode];
Jingning Han's avatar
Jingning Han committed
439 440 441 442 443 444 445
    return mode;  // SINGLE_REFERENCE or COMPOUND_REFERENCE
  } else {
    return cm->reference_mode;
  }
}

// Read the referncence frame
446
static void read_ref_frames(AV1_COMMON *const cm, MACROBLOCKD *const xd,
Adrian Grange's avatar
Adrian Grange committed
447
                            aom_reader *r, int segment_id,
clang-format's avatar
clang-format committed
448
                            MV_REFERENCE_FRAME ref_frame[2]) {
Jingning Han's avatar
Jingning Han committed
449 450 451 452 453 454 455 456 457 458 459 460
  FRAME_CONTEXT *const fc = cm->fc;
  FRAME_COUNTS *counts = xd->counts;

  if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) {
    ref_frame[0] = (MV_REFERENCE_FRAME)get_segdata(&cm->seg, segment_id,
                                                   SEG_LVL_REF_FRAME);
    ref_frame[1] = NONE;
  } else {
    const REFERENCE_MODE mode = read_block_reference_mode(cm, xd, r);
    // FIXME(rbultje) I'm pretty sure this breaks segmentation ref frame coding
    if (mode == COMPOUND_REFERENCE) {
      const int idx = cm->ref_frame_sign_bias[cm->comp_fixed_ref];
461
      const int ctx = av1_get_pred_context_comp_ref_p(cm, xd);
Adrian Grange's avatar
Adrian Grange committed
462
      const int bit = aom_read(r, fc->comp_ref_prob[ctx]);
clang-format's avatar
clang-format committed
463
      if (counts) ++counts->comp_ref[ctx][bit];
Jingning Han's avatar
Jingning Han committed
464 465 466
      ref_frame[idx] = cm->comp_fixed_ref;
      ref_frame[!idx] = cm->comp_var_ref[bit];
    } else if (mode == SINGLE_REFERENCE) {
467
      const int ctx0 = av1_get_pred_context_single_ref_p1(xd);
Adrian Grange's avatar
Adrian Grange committed
468
      const int bit0 = aom_read(r, fc->single_ref_prob[ctx0][0]);
clang-format's avatar
clang-format committed
469
      if (counts) ++counts->single_ref[ctx0][0][bit0];
Jingning Han's avatar
Jingning Han committed
470
      if (bit0) {
471
        const int ctx1 = av1_get_pred_context_single_ref_p2(xd);
Adrian Grange's avatar
Adrian Grange committed
472
        const int bit1 = aom_read(r, fc->single_ref_prob[ctx1][1]);
clang-format's avatar
clang-format committed
473
        if (counts) ++counts->single_ref[ctx1][1][bit1];
Jingning Han's avatar
Jingning Han committed
474 475 476 477 478 479 480 481 482 483 484 485
        ref_frame[0] = bit1 ? ALTREF_FRAME : GOLDEN_FRAME;
      } else {
        ref_frame[0] = LAST_FRAME;
      }

      ref_frame[1] = NONE;
    } else {
      assert(0 && "Invalid prediction mode.");
    }
  }
}

James Zern's avatar
James Zern committed
486 487 488
static INLINE InterpFilter read_switchable_interp_filter(AV1_COMMON *const cm,
                                                         MACROBLOCKD *const xd,
                                                         aom_reader *r) {
489
  const int ctx = av1_get_pred_context_switchable_interp(xd);
James Zern's avatar
James Zern committed
490
  const InterpFilter type = (InterpFilter)aom_read_tree(
491
      r, av1_switchable_interp_tree, cm->fc->switchable_interp_prob[ctx]);
Jingning Han's avatar
Jingning Han committed
492
  FRAME_COUNTS *counts = xd->counts;
clang-format's avatar
clang-format committed
493
  if (counts) ++counts->switchable_interp[ctx][type];
Jingning Han's avatar
Jingning Han committed
494 495 496
  return type;
}

497
static void read_intra_block_mode_info(AV1_COMMON *const cm,
Jingning Han's avatar
Jingning Han committed
498
                                       MACROBLOCKD *const xd, MODE_INFO *mi,
Adrian Grange's avatar
Adrian Grange committed
499
                                       aom_reader *r) {
Jingning Han's avatar
Jingning Han committed
500 501 502 503 504 505 506 507 508 509 510 511 512 513
  MB_MODE_INFO *const mbmi = &mi->mbmi;
  const BLOCK_SIZE bsize = mi->mbmi.sb_type;
  int i;

  mbmi->ref_frame[0] = INTRA_FRAME;
  mbmi->ref_frame[1] = NONE;

  switch (bsize) {
    case BLOCK_4X4:
      for (i = 0; i < 4; ++i)
        mi->bmi[i].as_mode = read_intra_mode_y(cm, xd, r, 0);
      mbmi->mode = mi->bmi[3].as_mode;
      break;
    case BLOCK_4X8:
clang-format's avatar
clang-format committed
514
      mi->bmi[0].as_mode = mi->bmi[2].as_mode = read_intra_mode_y(cm, xd, r, 0);
Jingning Han's avatar
Jingning Han committed
515 516 517 518
      mi->bmi[1].as_mode = mi->bmi[3].as_mode = mbmi->mode =
          read_intra_mode_y(cm, xd, r, 0);
      break;
    case BLOCK_8X4:
clang-format's avatar
clang-format committed
519
      mi->bmi[0].as_mode = mi->bmi[1].as_mode = read_intra_mode_y(cm, xd, r, 0);
Jingning Han's avatar
Jingning Han committed
520 521 522 523 524 525 526 527 528 529 530
      mi->bmi[2].as_mode = mi->bmi[3].as_mode = mbmi->mode =
          read_intra_mode_y(cm, xd, r, 0);
      break;
    default:
      mbmi->mode = read_intra_mode_y(cm, xd, r, size_group_lookup[bsize]);
  }

  mbmi->uv_mode = read_intra_mode_uv(cm, xd, r, mbmi->mode);
}

static INLINE int is_mv_valid(const MV *mv) {
clang-format's avatar
clang-format committed
531 532
  return mv->row > MV_LOW && mv->row < MV_UPP && mv->col > MV_LOW &&
         mv->col < MV_UPP;
Jingning Han's avatar
Jingning Han committed
533 534
}

535
static INLINE int assign_mv(AV1_COMMON *cm, MACROBLOCKD *xd,
536
                            PREDICTION_MODE mode, int block, int_mv mv[2],
clang-format's avatar
clang-format committed
537 538
                            int_mv ref_mv[2], int_mv nearest_mv[2],
                            int_mv near_mv[2], int is_compound, int allow_hp,
Adrian Grange's avatar
Adrian Grange committed
539
                            aom_reader *r) {
Jingning Han's avatar
Jingning Han committed
540 541 542
  int i;
  int ret = 1;

543 544 545
#if CONFIG_REF_MV
  MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
  BLOCK_SIZE bsize = mbmi->sb_type;
clang-format's avatar
clang-format committed
546 547
  int_mv *pred_mv =
      (bsize >= BLOCK_8X8) ? mbmi->pred_mv : xd->mi[0]->bmi[block].pred_mv;
548 549 550 551
#else
  (void)block;
#endif

Jingning Han's avatar
Jingning Han committed
552 553 554
  switch (mode) {
    case NEWMV: {
      FRAME_COUNTS *counts = xd->counts;
555
#if !CONFIG_REF_MV
Jingning Han's avatar
Jingning Han committed
556
      nmv_context_counts *const mv_counts = counts ? &counts->mv : NULL;
557
#endif
Jingning Han's avatar
Jingning Han committed
558
      for (i = 0; i < 1 + is_compound; ++i) {
559
#if CONFIG_REF_MV
560 561 562 563
        int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
        int nmv_ctx =
            av1_nmv_ctx(xd->ref_mv_count[rf_type], xd->ref_mv_stack[rf_type], i,
                        mbmi->ref_mv_idx);
564 565 566 567 568
        nmv_context_counts *const mv_counts =
            counts ? &counts->mv[nmv_ctx] : NULL;
        read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, &cm->fc->nmvc[nmv_ctx],
                mv_counts, allow_hp);
#else
Jingning Han's avatar
Jingning Han committed
569 570
        read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, &cm->fc->nmvc, mv_counts,
                allow_hp);
571
#endif
Jingning Han's avatar
Jingning Han committed
572
        ret = ret && is_mv_valid(&mv[i].as_mv);
573 574 575
#if CONFIG_REF_MV
        pred_mv[i].as_int = ref_mv[i].as_int;
#endif
Jingning Han's avatar
Jingning Han committed
576 577 578 579 580
      }
      break;
    }
    case NEARESTMV: {
      mv[0].as_int = nearest_mv[0].as_int;
clang-format's avatar
clang-format committed
581
      if (is_compound) mv[1].as_int = nearest_mv[1].as_int;
582 583
#if CONFIG_REF_MV
      pred_mv[0].as_int = nearest_mv[0].as_int;
clang-format's avatar
clang-format committed
584
      if (is_compound) pred_mv[1].as_int = nearest_mv[1].as_int;
585
#endif
Jingning Han's avatar
Jingning Han committed
586 587 588 589
      break;
    }
    case NEARMV: {
      mv[0].as_int = near_mv[0].as_int;
clang-format's avatar
clang-format committed
590
      if (is_compound) mv[1].as_int = near_mv[1].as_int;
591 592
#if CONFIG_REF_MV
      pred_mv[0].as_int = near_mv[0].as_int;
clang-format's avatar
clang-format committed
593
      if (is_compound) pred_mv[1].as_int = near_mv[1].as_int;
594
#endif
Jingning Han's avatar
Jingning Han committed
595 596 597 598
      break;
    }
    case ZEROMV: {
      mv[0].as_int = 0;
clang-format's avatar
clang-format committed
599
      if (is_compound) mv[1].as_int = 0;
600 601
#if CONFIG_REF_MV
      pred_mv[0].as_int = 0;
clang-format's avatar
clang-format committed
602
      if (is_compound) pred_mv[1].as_int = 0;
603
#endif
Jingning Han's avatar
Jingning Han committed
604 605
      break;
    }
clang-format's avatar
clang-format committed
606
    default: { return 0; }
Jingning Han's avatar
Jingning Han committed
607 608 609 610
  }
  return ret;
}

611
static int read_is_inter_block(AV1_COMMON *const cm, MACROBLOCKD *const xd,
Adrian Grange's avatar
Adrian Grange committed
612
                               int segment_id, aom_reader *r) {
Jingning Han's avatar
Jingning Han committed
613 614 615
  if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) {
    return get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME) != INTRA_FRAME;
  } else {
616
    const int ctx = av1_get_intra_inter_context(xd);
Adrian Grange's avatar
Adrian Grange committed
617
    const int is_inter = aom_read(r, cm->fc->intra_inter_prob[ctx]);
Jingning Han's avatar
Jingning Han committed
618
    FRAME_COUNTS *counts = xd->counts;
clang-format's avatar
clang-format committed
619
    if (counts) ++counts->intra_inter[ctx][is_inter];
Jingning Han's avatar
Jingning Han committed
620 621 622 623 624
    return is_inter;
  }
}

static void fpm_sync(void *const data, int mi_row) {
625 626
  AV1Decoder *const pbi = (AV1Decoder *)data;
  av1_frameworker_wait(pbi->frame_worker_owner, pbi->common.prev_frame,
clang-format's avatar
clang-format committed
627
                       mi_row << MI_BLOCK_SIZE_LOG2);
Jingning Han's avatar
Jingning Han committed
628 629
}

630
static void read_inter_block_mode_info(AV1Decoder *const pbi,
Jingning Han's avatar
Jingning Han committed
631
                                       MACROBLOCKD *const xd,
clang-format's avatar
clang-format committed
632
                                       MODE_INFO *const mi, int mi_row,
Adrian Grange's avatar
Adrian Grange committed
633
                                       int mi_col, aom_reader *r) {
634
  AV1_COMMON *const cm = &pbi->common;
Jingning Han's avatar
Jingning Han committed
635 636 637 638
  MB_MODE_INFO *const mbmi = &mi->mbmi;
  const BLOCK_SIZE bsize = mbmi->sb_type;
  const int allow_hp = cm->allow_high_precision_mv;
  int_mv nearestmv[2], nearmv[2];
639
  int_mv ref_mvs[MODE_CTX_REF_FRAMES][MAX_MV_REF_CANDIDATES];
Jingning Han's avatar
Jingning Han committed
640
  int ref, is_compound;
641
  int16_t inter_mode_ctx[MODE_CTX_REF_FRAMES];
642
  int16_t mode_ctx = 0;
643
  MV_REFERENCE_FRAME ref_frame;
Jingning Han's avatar
Jingning Han committed
644 645 646 647 648 649 650 651 652

  read_ref_frames(cm, xd, r, mbmi->segment_id, mbmi->ref_frame);
  is_compound = has_second_ref(mbmi);

  for (ref = 0; ref < 1 + is_compound; ++ref) {
    const MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref];
    RefBuffer *ref_buf = &cm->frame_refs[frame - LAST_FRAME];

    xd->block_refs[ref] = ref_buf;
653
    if ((!av1_is_valid_scale(&ref_buf->sf)))
Adrian Grange's avatar
Adrian Grange committed
654
      aom_internal_error(xd->error_info, AOM_CODEC_UNSUP_BITSTREAM,
Jingning Han's avatar
Jingning Han committed
655
                         "Reference frame has invalid dimensions");
656
    av1_setup_pre_planes(xd, ref, ref_buf->buf, mi_row, mi_col, &ref_buf->sf);
657 658
  }

659
  for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
660
    av1_find_mv_refs(cm, xd, mi, ref_frame,
661
#if CONFIG_REF_MV
clang-format's avatar
clang-format committed
662
                     &xd->ref_mv_count[ref_frame], xd->ref_mv_stack[ref_frame],
663
#endif
clang-format's avatar
clang-format committed
664 665
                     ref_mvs[ref_frame], mi_row, mi_col, fpm_sync, (void *)pbi,
                     inter_mode_ctx);
Jingning Han's avatar
Jingning Han committed
666 667
  }

668
#if CONFIG_REF_MV
669
  for (; ref_frame < MODE_CTX_REF_FRAMES; ++ref_frame) {
clang-format's avatar
clang-format committed
670 671 672
    av1_find_mv_refs(cm, xd, mi, ref_frame, &xd->ref_mv_count[ref_frame],
                     xd->ref_mv_stack[ref_frame], ref_mvs[ref_frame], mi_row,
                     mi_col, fpm_sync, (void *)pbi, inter_mode_ctx);
673 674 675 676 677 678 679 680 681 682 683 684 685 686

    if (xd->ref_mv_count[ref_frame] < 2) {
      MV_REFERENCE_FRAME rf[2];
      av1_set_ref_frame(rf, ref_frame);
      for (ref = 0; ref < 2; ++ref) {
        lower_mv_precision(&ref_mvs[rf[ref]][0].as_mv, allow_hp);
        lower_mv_precision(&ref_mvs[rf[ref]][1].as_mv, allow_hp);
      }

      if (ref_mvs[rf[0]][0].as_int != 0 || ref_mvs[rf[0]][1].as_int != 0 ||
          ref_mvs[rf[1]][0].as_int != 0 || ref_mvs[rf[1]][1].as_int != 0)
        inter_mode_ctx[ref_frame] &= ~(1 << ALL_ZERO_FLAG_OFFSET);
    }
  }
clang-format's avatar
clang-format committed
687 688
  mode_ctx =
      av1_mode_context_analyzer(inter_mode_ctx, mbmi->ref_frame, bsize, -1);
689
  mbmi->ref_mv_idx = 0;
690 691
#else
  mode_ctx = inter_mode_ctx[mbmi->ref_frame[0]];
692 693
#endif

Jingning Han's avatar
Jingning Han committed
694 695 696
  if (segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) {
    mbmi->mode = ZEROMV;
    if (bsize < BLOCK_8X8) {
Adrian Grange's avatar
Adrian Grange committed
697
      aom_internal_error(xd->error_info, AOM_CODEC_UNSUP_BITSTREAM,
clang-format's avatar
clang-format committed
698 699
                         "Invalid usage of segement feature on small blocks");
      return;
Jingning Han's avatar
Jingning Han committed
700 701
    }
  } else {
702 703 704
    if (bsize >= BLOCK_8X8) {
      mbmi->mode = read_inter_mode(cm, xd, r, mode_ctx);
#if CONFIG_REF_MV
705
      if (mbmi->mode == NEARMV || mbmi->mode == NEWMV)
706
        read_drl_idx(cm, xd, mbmi, r);
707 708
#endif
    }
Jingning Han's avatar
Jingning Han committed
709 710 711 712
  }

  if (bsize < BLOCK_8X8 || mbmi->mode != ZEROMV) {
    for (ref = 0; ref < 1 + is_compound; ++ref) {
713
      av1_find_best_ref_mvs(allow_hp, ref_mvs[mbmi->ref_frame[ref]],
clang-format's avatar
clang-format committed
714
                            &nearestmv[ref], &nearmv[ref]);
Jingning Han's avatar
Jingning Han committed
715 716 717
    }
  }

718
#if CONFIG_REF_MV
719 720 721
  if (mbmi->ref_mv_idx > 0) {
    int_mv cur_mv =
        xd->ref_mv_stack[mbmi->ref_frame[0]][1 + mbmi->ref_mv_idx].this_mv;
722 723 724 725
    lower_mv_precision(&cur_mv.as_mv, cm->allow_high_precision_mv);
    nearmv[0] = cur_mv;
  }

726 727 728 729 730 731 732 733 734
  if (is_compound && bsize >= BLOCK_8X8 && mbmi->mode != NEWMV &&
      mbmi->mode != ZEROMV) {
    uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);

    if (xd->ref_mv_count[ref_frame_type] == 1 && mbmi->mode == NEARESTMV) {
      int i;
      nearestmv[0] = xd->ref_mv_stack[ref_frame_type][0].this_mv;
      nearestmv[1] = xd->ref_mv_stack[ref_frame_type][0].comp_mv;

clang-format's avatar
clang-format committed
735
      for (i = 0; i < 2; ++i) lower_mv_precision(&nearestmv[i].as_mv, allow_hp);
736 737 738 739
    }

    if (xd->ref_mv_count[ref_frame_type] > 1) {
      int i;
740
      const int ref_mv_idx = 1 + mbmi->ref_mv_idx;
741 742
      nearestmv[0] = xd->ref_mv_stack[ref_frame_type][0].this_mv;
      nearestmv[1] = xd->ref_mv_stack[ref_frame_type][0].comp_mv;
743 744
      nearmv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv;
      nearmv[1] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].comp_mv;
745

746
      for (i = 0; i < 2; ++i) {
747 748 749 750 751 752 753
        lower_mv_precision(&nearestmv[i].as_mv, allow_hp);
        lower_mv_precision(&nearmv[i].as_mv, allow_hp);
      }
    }
  }
#endif

Jingning Han's avatar
Jingning Han committed
754
  mbmi->interp_filter = (cm->interp_filter == SWITCHABLE)
clang-format's avatar
clang-format committed
755 756
                            ? read_switchable_interp_filter(cm, xd, r)
                            : cm->interp_filter;
Jingning Han's avatar
Jingning Han committed
757 758 759 760 761 762 763 764 765 766 767

  if (bsize < BLOCK_8X8) {
    const int num_4x4_w = 1 << xd->bmode_blocks_wl;
    const int num_4x4_h = 1 << xd->bmode_blocks_hl;
    int idx, idy;
    PREDICTION_MODE b_mode;
    int_mv nearest_sub8x8[2], near_sub8x8[2];
    for (idy = 0; idy < 2; idy += num_4x4_h) {
      for (idx = 0; idx < 2; idx += num_4x4_w) {
        int_mv block[2];
        const int j = idy * 2 + idx;
768
#if CONFIG_REF_MV
clang-format's avatar
clang-format committed
769
        mode_ctx = av1_mode_context_analyzer(inter_mode_ctx, mbmi->ref_frame,
770 771
                                             bsize, j);
#endif
772
        b_mode = read_inter_mode(cm, xd, r, mode_ctx);
Jingning Han's avatar
Jingning Han committed
773 774 775

        if (b_mode == NEARESTMV || b_mode == NEARMV) {
          for (ref = 0; ref < 1 + is_compound; ++ref)
776
            av1_append_sub8x8_mvs_for_idx(cm, xd, j, ref, mi_row, mi_col,
clang-format's avatar
clang-format committed
777 778
                                          &nearest_sub8x8[ref],
                                          &near_sub8x8[ref]);
Jingning Han's avatar
Jingning Han committed
779 780
        }

781
        if (!assign_mv(cm, xd, b_mode, j, block, nearestmv, nearest_sub8x8,
clang-format's avatar
clang-format committed
782
                       near_sub8x8, is_compound, allow_hp, r)) {
Jingning Han's avatar
Jingning Han committed
783 784 785 786 787
          xd->corrupted |= 1;
          break;
        };

        mi->bmi[j].as_mv[0].as_int = block[0].as_int;
clang-format's avatar
clang-format committed
788
        if (is_compound) mi->bmi[j].as_mv[1].as_int = block[1].as_int;
Jingning Han's avatar
Jingning Han committed
789

clang-format's avatar
clang-format committed
790 791
        if (num_4x4_h == 2) mi->bmi[j + 2] = mi->bmi[j];
        if (num_4x4_w == 2) mi->bmi[j + 1] = mi->bmi[j];
Jingning Han's avatar
Jingning Han committed
792 793 794 795
      }
    }

    mi->mbmi.mode = b_mode;
796 797 798 799
#if CONFIG_REF_MV
    mbmi->pred_mv[0].as_int = mi->bmi[3].pred_mv[