1 /*
2 Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <assert.h>
12
13 #include "vp9/common/vp9_common.h"
14 #include "vp9/common/vp9_entropy.h"
15 #include "vp9/common/vp9_entropymode.h"
16 #include "vp9/common/vp9_entropymv.h"
17 #include "vp9/common/vp9_mvref_common.h"
18 #include "vp9/common/vp9_pred_common.h"
19 #include "vp9/common/vp9_reconinter.h"
20 #include "vp9/common/vp9_seg_common.h"
21
22 #include "vp9/decoder/vp9_decodemv.h"
23 #include "vp9/decoder/vp9_decodeframe.h"
24 #include "vp9/decoder/vp9_reader.h"
25
read_intra_mode(vp9_reader * r,const vp9_prob * p)26 static MB_PREDICTION_MODE read_intra_mode(vp9_reader *r, const vp9_prob *p) {
27 return (MB_PREDICTION_MODE)vp9_read_tree(r, vp9_intra_mode_tree, p);
28 }
29
read_intra_mode_y(VP9_COMMON * cm,vp9_reader * r,int size_group)30 static MB_PREDICTION_MODE read_intra_mode_y(VP9_COMMON *cm, vp9_reader *r,
31 int size_group) {
32 const MB_PREDICTION_MODE y_mode = read_intra_mode(r,
33 cm->fc.y_mode_prob[size_group]);
34 if (!cm->frame_parallel_decoding_mode)
35 ++cm->counts.y_mode[size_group][y_mode];
36 return y_mode;
37 }
38
read_intra_mode_uv(VP9_COMMON * cm,vp9_reader * r,MB_PREDICTION_MODE y_mode)39 static MB_PREDICTION_MODE read_intra_mode_uv(VP9_COMMON *cm, vp9_reader *r,
40 MB_PREDICTION_MODE y_mode) {
41 const MB_PREDICTION_MODE uv_mode = read_intra_mode(r,
42 cm->fc.uv_mode_prob[y_mode]);
43 if (!cm->frame_parallel_decoding_mode)
44 ++cm->counts.uv_mode[y_mode][uv_mode];
45 return uv_mode;
46 }
47
read_inter_mode(VP9_COMMON * cm,vp9_reader * r,int ctx)48 static MB_PREDICTION_MODE read_inter_mode(VP9_COMMON *cm, vp9_reader *r,
49 int ctx) {
50 const int mode = vp9_read_tree(r, vp9_inter_mode_tree,
51 cm->fc.inter_mode_probs[ctx]);
52 if (!cm->frame_parallel_decoding_mode)
53 ++cm->counts.inter_mode[ctx][mode];
54
55 return NEARESTMV + mode;
56 }
57
read_segment_id(vp9_reader * r,const struct segmentation * seg)58 static int read_segment_id(vp9_reader *r, const struct segmentation *seg) {
59 return vp9_read_tree(r, vp9_segment_tree, seg->tree_probs);
60 }
61
read_selected_tx_size(VP9_COMMON * cm,MACROBLOCKD * xd,TX_SIZE max_tx_size,vp9_reader * r)62 static TX_SIZE read_selected_tx_size(VP9_COMMON *cm, MACROBLOCKD *xd,
63 TX_SIZE max_tx_size, vp9_reader *r) {
64 const int ctx = vp9_get_tx_size_context(xd);
65 const vp9_prob *tx_probs = get_tx_probs(max_tx_size, ctx, &cm->fc.tx_probs);
66 int tx_size = vp9_read(r, tx_probs[0]);
67 if (tx_size != TX_4X4 && max_tx_size >= TX_16X16) {
68 tx_size += vp9_read(r, tx_probs[1]);
69 if (tx_size != TX_8X8 && max_tx_size >= TX_32X32)
70 tx_size += vp9_read(r, tx_probs[2]);
71 }
72
73 if (!cm->frame_parallel_decoding_mode)
74 ++get_tx_counts(max_tx_size, ctx, &cm->counts.tx)[tx_size];
75 return (TX_SIZE)tx_size;
76 }
77
read_tx_size(VP9_COMMON * cm,MACROBLOCKD * xd,TX_MODE tx_mode,BLOCK_SIZE bsize,int allow_select,vp9_reader * r)78 static TX_SIZE read_tx_size(VP9_COMMON *cm, MACROBLOCKD *xd, TX_MODE tx_mode,
79 BLOCK_SIZE bsize, int allow_select, vp9_reader *r) {
80 const TX_SIZE max_tx_size = max_txsize_lookup[bsize];
81 if (allow_select && tx_mode == TX_MODE_SELECT && bsize >= BLOCK_8X8)
82 return read_selected_tx_size(cm, xd, max_tx_size, r);
83 else
84 return MIN(max_tx_size, tx_mode_to_biggest_tx_size[tx_mode]);
85 }
86
set_segment_id(VP9_COMMON * cm,BLOCK_SIZE bsize,int mi_row,int mi_col,int segment_id)87 static void set_segment_id(VP9_COMMON *cm, BLOCK_SIZE bsize,
88 int mi_row, int mi_col, int segment_id) {
89 const int mi_offset = mi_row * cm->mi_cols + mi_col;
90 const int bw = num_8x8_blocks_wide_lookup[bsize];
91 const int bh = num_8x8_blocks_high_lookup[bsize];
92 const int xmis = MIN(cm->mi_cols - mi_col, bw);
93 const int ymis = MIN(cm->mi_rows - mi_row, bh);
94 int x, y;
95
96 assert(segment_id >= 0 && segment_id < MAX_SEGMENTS);
97
98 for (y = 0; y < ymis; y++)
99 for (x = 0; x < xmis; x++)
100 cm->last_frame_seg_map[mi_offset + y * cm->mi_cols + x] = segment_id;
101 }
102
read_intra_segment_id(VP9_COMMON * const cm,MACROBLOCKD * const xd,int mi_row,int mi_col,vp9_reader * r)103 static int read_intra_segment_id(VP9_COMMON *const cm, MACROBLOCKD *const xd,
104 int mi_row, int mi_col,
105 vp9_reader *r) {
106 struct segmentation *const seg = &cm->seg;
107 const BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type;
108 int segment_id;
109
110 if (!seg->enabled)
111 return 0; // Default for disabled segmentation
112
113 if (!seg->update_map)
114 return 0;
115
116 segment_id = read_segment_id(r, seg);
117 set_segment_id(cm, bsize, mi_row, mi_col, segment_id);
118 return segment_id;
119 }
120
read_inter_segment_id(VP9_COMMON * const cm,MACROBLOCKD * const xd,int mi_row,int mi_col,vp9_reader * r)121 static int read_inter_segment_id(VP9_COMMON *const cm, MACROBLOCKD *const xd,
122 int mi_row, int mi_col, vp9_reader *r) {
123 struct segmentation *const seg = &cm->seg;
124 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
125 const BLOCK_SIZE bsize = mbmi->sb_type;
126 int predicted_segment_id, segment_id;
127
128 if (!seg->enabled)
129 return 0; // Default for disabled segmentation
130
131 predicted_segment_id = vp9_get_segment_id(cm, cm->last_frame_seg_map,
132 bsize, mi_row, mi_col);
133 if (!seg->update_map)
134 return predicted_segment_id;
135
136 if (seg->temporal_update) {
137 const vp9_prob pred_prob = vp9_get_pred_prob_seg_id(seg, xd);
138 mbmi->seg_id_predicted = vp9_read(r, pred_prob);
139 segment_id = mbmi->seg_id_predicted ? predicted_segment_id
140 : read_segment_id(r, seg);
141 } else {
142 segment_id = read_segment_id(r, seg);
143 }
144 set_segment_id(cm, bsize, mi_row, mi_col, segment_id);
145 return segment_id;
146 }
147
read_skip(VP9_COMMON * cm,const MACROBLOCKD * xd,int segment_id,vp9_reader * r)148 static int read_skip(VP9_COMMON *cm, const MACROBLOCKD *xd,
149 int segment_id, vp9_reader *r) {
150 if (vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)) {
151 return 1;
152 } else {
153 const int ctx = vp9_get_skip_context(xd);
154 const int skip = vp9_read(r, cm->fc.skip_probs[ctx]);
155 if (!cm->frame_parallel_decoding_mode)
156 ++cm->counts.skip[ctx][skip];
157 return skip;
158 }
159 }
160
read_intra_frame_mode_info(VP9_COMMON * const cm,MACROBLOCKD * const xd,int mi_row,int mi_col,vp9_reader * r)161 static void read_intra_frame_mode_info(VP9_COMMON *const cm,
162 MACROBLOCKD *const xd,
163 int mi_row, int mi_col, vp9_reader *r) {
164 MODE_INFO *const mi = xd->mi[0];
165 MB_MODE_INFO *const mbmi = &mi->mbmi;
166 const MODE_INFO *above_mi = xd->mi[-cm->mi_stride];
167 const MODE_INFO *left_mi = xd->left_available ? xd->mi[-1] : NULL;
168 const BLOCK_SIZE bsize = mbmi->sb_type;
169 int i;
170
171 mbmi->segment_id = read_intra_segment_id(cm, xd, mi_row, mi_col, r);
172 mbmi->skip = read_skip(cm, xd, mbmi->segment_id, r);
173 mbmi->tx_size = read_tx_size(cm, xd, cm->tx_mode, bsize, 1, r);
174 mbmi->ref_frame[0] = INTRA_FRAME;
175 mbmi->ref_frame[1] = NONE;
176
177 switch (bsize) {
178 case BLOCK_4X4:
179 for (i = 0; i < 4; ++i)
180 mi->bmi[i].as_mode =
181 read_intra_mode(r, get_y_mode_probs(mi, above_mi, left_mi, i));
182 mbmi->mode = mi->bmi[3].as_mode;
183 break;
184 case BLOCK_4X8:
185 mi->bmi[0].as_mode = mi->bmi[2].as_mode =
186 read_intra_mode(r, get_y_mode_probs(mi, above_mi, left_mi, 0));
187 mi->bmi[1].as_mode = mi->bmi[3].as_mode = mbmi->mode =
188 read_intra_mode(r, get_y_mode_probs(mi, above_mi, left_mi, 1));
189 break;
190 case BLOCK_8X4:
191 mi->bmi[0].as_mode = mi->bmi[1].as_mode =
192 read_intra_mode(r, get_y_mode_probs(mi, above_mi, left_mi, 0));
193 mi->bmi[2].as_mode = mi->bmi[3].as_mode = mbmi->mode =
194 read_intra_mode(r, get_y_mode_probs(mi, above_mi, left_mi, 2));
195 break;
196 default:
197 mbmi->mode = read_intra_mode(r,
198 get_y_mode_probs(mi, above_mi, left_mi, 0));
199 }
200
201 mbmi->uv_mode = read_intra_mode(r, vp9_kf_uv_mode_prob[mbmi->mode]);
202 }
203
read_mv_component(vp9_reader * r,const nmv_component * mvcomp,int usehp)204 static int read_mv_component(vp9_reader *r,
205 const nmv_component *mvcomp, int usehp) {
206 int mag, d, fr, hp;
207 const int sign = vp9_read(r, mvcomp->sign);
208 const int mv_class = vp9_read_tree(r, vp9_mv_class_tree, mvcomp->classes);
209 const int class0 = mv_class == MV_CLASS_0;
210
211 // Integer part
212 if (class0) {
213 d = vp9_read_tree(r, vp9_mv_class0_tree, mvcomp->class0);
214 } else {
215 int i;
216 const int n = mv_class + CLASS0_BITS - 1; // number of bits
217
218 d = 0;
219 for (i = 0; i < n; ++i)
220 d |= vp9_read(r, mvcomp->bits[i]) << i;
221 }
222
223 // Fractional part
224 fr = vp9_read_tree(r, vp9_mv_fp_tree, class0 ? mvcomp->class0_fp[d]
225 : mvcomp->fp);
226
227
228 // High precision part (if hp is not used, the default value of the hp is 1)
229 hp = usehp ? vp9_read(r, class0 ? mvcomp->class0_hp : mvcomp->hp)
230 : 1;
231
232 // Result
233 mag = vp9_get_mv_mag(mv_class, (d << 3) | (fr << 1) | hp) + 1;
234 return sign ? -mag : mag;
235 }
236
read_mv(vp9_reader * r,MV * mv,const MV * ref,const nmv_context * ctx,nmv_context_counts * counts,int allow_hp)237 static INLINE void read_mv(vp9_reader *r, MV *mv, const MV *ref,
238 const nmv_context *ctx,
239 nmv_context_counts *counts, int allow_hp) {
240 const MV_JOINT_TYPE joint_type =
241 (MV_JOINT_TYPE)vp9_read_tree(r, vp9_mv_joint_tree, ctx->joints);
242 const int use_hp = allow_hp && vp9_use_mv_hp(ref);
243 MV diff = {0, 0};
244
245 if (mv_joint_vertical(joint_type))
246 diff.row = read_mv_component(r, &ctx->comps[0], use_hp);
247
248 if (mv_joint_horizontal(joint_type))
249 diff.col = read_mv_component(r, &ctx->comps[1], use_hp);
250
251 vp9_inc_mv(&diff, counts);
252
253 mv->row = ref->row + diff.row;
254 mv->col = ref->col + diff.col;
255 }
256
read_block_reference_mode(VP9_COMMON * cm,const MACROBLOCKD * xd,vp9_reader * r)257 static REFERENCE_MODE read_block_reference_mode(VP9_COMMON *cm,
258 const MACROBLOCKD *xd,
259 vp9_reader *r) {
260 if (cm->reference_mode == REFERENCE_MODE_SELECT) {
261 const int ctx = vp9_get_reference_mode_context(cm, xd);
262 const REFERENCE_MODE mode =
263 (REFERENCE_MODE)vp9_read(r, cm->fc.comp_inter_prob[ctx]);
264 if (!cm->frame_parallel_decoding_mode)
265 ++cm->counts.comp_inter[ctx][mode];
266 return mode; // SINGLE_REFERENCE or COMPOUND_REFERENCE
267 } else {
268 return cm->reference_mode;
269 }
270 }
271
272 // Read the referncence frame
read_ref_frames(VP9_COMMON * const cm,MACROBLOCKD * const xd,vp9_reader * r,int segment_id,MV_REFERENCE_FRAME ref_frame[2])273 static void read_ref_frames(VP9_COMMON *const cm, MACROBLOCKD *const xd,
274 vp9_reader *r,
275 int segment_id, MV_REFERENCE_FRAME ref_frame[2]) {
276 FRAME_CONTEXT *const fc = &cm->fc;
277 FRAME_COUNTS *const counts = &cm->counts;
278
279 if (vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) {
280 ref_frame[0] = (MV_REFERENCE_FRAME)vp9_get_segdata(&cm->seg, segment_id,
281 SEG_LVL_REF_FRAME);
282 ref_frame[1] = NONE;
283 } else {
284 const REFERENCE_MODE mode = read_block_reference_mode(cm, xd, r);
285 // FIXME(rbultje) I'm pretty sure this breaks segmentation ref frame coding
286 if (mode == COMPOUND_REFERENCE) {
287 const int idx = cm->ref_frame_sign_bias[cm->comp_fixed_ref];
288 const int ctx = vp9_get_pred_context_comp_ref_p(cm, xd);
289 const int bit = vp9_read(r, fc->comp_ref_prob[ctx]);
290 if (!cm->frame_parallel_decoding_mode)
291 ++counts->comp_ref[ctx][bit];
292 ref_frame[idx] = cm->comp_fixed_ref;
293 ref_frame[!idx] = cm->comp_var_ref[bit];
294 } else if (mode == SINGLE_REFERENCE) {
295 const int ctx0 = vp9_get_pred_context_single_ref_p1(xd);
296 const int bit0 = vp9_read(r, fc->single_ref_prob[ctx0][0]);
297 if (!cm->frame_parallel_decoding_mode)
298 ++counts->single_ref[ctx0][0][bit0];
299 if (bit0) {
300 const int ctx1 = vp9_get_pred_context_single_ref_p2(xd);
301 const int bit1 = vp9_read(r, fc->single_ref_prob[ctx1][1]);
302 if (!cm->frame_parallel_decoding_mode)
303 ++counts->single_ref[ctx1][1][bit1];
304 ref_frame[0] = bit1 ? ALTREF_FRAME : GOLDEN_FRAME;
305 } else {
306 ref_frame[0] = LAST_FRAME;
307 }
308
309 ref_frame[1] = NONE;
310 } else {
311 assert(0 && "Invalid prediction mode.");
312 }
313 }
314 }
315
316
read_switchable_interp_filter(VP9_COMMON * const cm,MACROBLOCKD * const xd,vp9_reader * r)317 static INLINE INTERP_FILTER read_switchable_interp_filter(
318 VP9_COMMON *const cm, MACROBLOCKD *const xd, vp9_reader *r) {
319 const int ctx = vp9_get_pred_context_switchable_interp(xd);
320 const INTERP_FILTER type =
321 (INTERP_FILTER)vp9_read_tree(r, vp9_switchable_interp_tree,
322 cm->fc.switchable_interp_prob[ctx]);
323 if (!cm->frame_parallel_decoding_mode)
324 ++cm->counts.switchable_interp[ctx][type];
325 return type;
326 }
327
read_intra_block_mode_info(VP9_COMMON * const cm,MODE_INFO * mi,vp9_reader * r)328 static void read_intra_block_mode_info(VP9_COMMON *const cm, MODE_INFO *mi,
329 vp9_reader *r) {
330 MB_MODE_INFO *const mbmi = &mi->mbmi;
331 const BLOCK_SIZE bsize = mi->mbmi.sb_type;
332 int i;
333
334 mbmi->ref_frame[0] = INTRA_FRAME;
335 mbmi->ref_frame[1] = NONE;
336
337 switch (bsize) {
338 case BLOCK_4X4:
339 for (i = 0; i < 4; ++i)
340 mi->bmi[i].as_mode = read_intra_mode_y(cm, r, 0);
341 mbmi->mode = mi->bmi[3].as_mode;
342 break;
343 case BLOCK_4X8:
344 mi->bmi[0].as_mode = mi->bmi[2].as_mode = read_intra_mode_y(cm, r, 0);
345 mi->bmi[1].as_mode = mi->bmi[3].as_mode = mbmi->mode =
346 read_intra_mode_y(cm, r, 0);
347 break;
348 case BLOCK_8X4:
349 mi->bmi[0].as_mode = mi->bmi[1].as_mode = read_intra_mode_y(cm, r, 0);
350 mi->bmi[2].as_mode = mi->bmi[3].as_mode = mbmi->mode =
351 read_intra_mode_y(cm, r, 0);
352 break;
353 default:
354 mbmi->mode = read_intra_mode_y(cm, r, size_group_lookup[bsize]);
355 }
356
357 mbmi->uv_mode = read_intra_mode_uv(cm, r, mbmi->mode);
358 }
359
is_mv_valid(const MV * mv)360 static INLINE int is_mv_valid(const MV *mv) {
361 return mv->row > MV_LOW && mv->row < MV_UPP &&
362 mv->col > MV_LOW && mv->col < MV_UPP;
363 }
364
assign_mv(VP9_COMMON * cm,MB_PREDICTION_MODE mode,int_mv mv[2],int_mv ref_mv[2],int_mv nearest_mv[2],int_mv near_mv[2],int is_compound,int allow_hp,vp9_reader * r)365 static INLINE int assign_mv(VP9_COMMON *cm, MB_PREDICTION_MODE mode,
366 int_mv mv[2], int_mv ref_mv[2],
367 int_mv nearest_mv[2], int_mv near_mv[2],
368 int is_compound, int allow_hp, vp9_reader *r) {
369 int i;
370 int ret = 1;
371
372 switch (mode) {
373 case NEWMV: {
374 nmv_context_counts *const mv_counts = cm->frame_parallel_decoding_mode ?
375 NULL : &cm->counts.mv;
376 for (i = 0; i < 1 + is_compound; ++i) {
377 read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, &cm->fc.nmvc, mv_counts,
378 allow_hp);
379 ret = ret && is_mv_valid(&mv[i].as_mv);
380 }
381 break;
382 }
383 case NEARESTMV: {
384 mv[0].as_int = nearest_mv[0].as_int;
385 if (is_compound)
386 mv[1].as_int = nearest_mv[1].as_int;
387 break;
388 }
389 case NEARMV: {
390 mv[0].as_int = near_mv[0].as_int;
391 if (is_compound)
392 mv[1].as_int = near_mv[1].as_int;
393 break;
394 }
395 case ZEROMV: {
396 mv[0].as_int = 0;
397 if (is_compound)
398 mv[1].as_int = 0;
399 break;
400 }
401 default: {
402 return 0;
403 }
404 }
405 return ret;
406 }
407
read_is_inter_block(VP9_COMMON * const cm,MACROBLOCKD * const xd,int segment_id,vp9_reader * r)408 static int read_is_inter_block(VP9_COMMON *const cm, MACROBLOCKD *const xd,
409 int segment_id, vp9_reader *r) {
410 if (vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) {
411 return vp9_get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME) !=
412 INTRA_FRAME;
413 } else {
414 const int ctx = vp9_get_intra_inter_context(xd);
415 const int is_inter = vp9_read(r, cm->fc.intra_inter_prob[ctx]);
416 if (!cm->frame_parallel_decoding_mode)
417 ++cm->counts.intra_inter[ctx][is_inter];
418 return is_inter;
419 }
420 }
421
read_inter_block_mode_info(VP9_COMMON * const cm,MACROBLOCKD * const xd,const TileInfo * const tile,MODE_INFO * const mi,int mi_row,int mi_col,vp9_reader * r)422 static void read_inter_block_mode_info(VP9_COMMON *const cm,
423 MACROBLOCKD *const xd,
424 const TileInfo *const tile,
425 MODE_INFO *const mi,
426 int mi_row, int mi_col, vp9_reader *r) {
427 MB_MODE_INFO *const mbmi = &mi->mbmi;
428 const BLOCK_SIZE bsize = mbmi->sb_type;
429 const int allow_hp = cm->allow_high_precision_mv;
430
431 int_mv nearestmv[2], nearmv[2];
432 int inter_mode_ctx, ref, is_compound;
433
434 read_ref_frames(cm, xd, r, mbmi->segment_id, mbmi->ref_frame);
435 is_compound = has_second_ref(mbmi);
436
437 for (ref = 0; ref < 1 + is_compound; ++ref) {
438 const MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref];
439 vp9_find_mv_refs(cm, xd, tile, mi, frame, mbmi->ref_mvs[frame],
440 mi_row, mi_col);
441 }
442
443 inter_mode_ctx = mbmi->mode_context[mbmi->ref_frame[0]];
444
445 if (vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) {
446 mbmi->mode = ZEROMV;
447 if (bsize < BLOCK_8X8) {
448 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
449 "Invalid usage of segement feature on small blocks");
450 return;
451 }
452 } else {
453 if (bsize >= BLOCK_8X8)
454 mbmi->mode = read_inter_mode(cm, r, inter_mode_ctx);
455 }
456
457 if (bsize < BLOCK_8X8 || mbmi->mode != ZEROMV) {
458 for (ref = 0; ref < 1 + is_compound; ++ref) {
459 vp9_find_best_ref_mvs(xd, allow_hp, mbmi->ref_mvs[mbmi->ref_frame[ref]],
460 &nearestmv[ref], &nearmv[ref]);
461 }
462 }
463
464 mbmi->interp_filter = (cm->interp_filter == SWITCHABLE)
465 ? read_switchable_interp_filter(cm, xd, r)
466 : cm->interp_filter;
467
468 if (bsize < BLOCK_8X8) {
469 const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize]; // 1 or 2
470 const int num_4x4_h = num_4x4_blocks_high_lookup[bsize]; // 1 or 2
471 int idx, idy;
472 MB_PREDICTION_MODE b_mode;
473 int_mv nearest_sub8x8[2], near_sub8x8[2];
474 for (idy = 0; idy < 2; idy += num_4x4_h) {
475 for (idx = 0; idx < 2; idx += num_4x4_w) {
476 int_mv block[2];
477 const int j = idy * 2 + idx;
478 b_mode = read_inter_mode(cm, r, inter_mode_ctx);
479
480 if (b_mode == NEARESTMV || b_mode == NEARMV)
481 for (ref = 0; ref < 1 + is_compound; ++ref)
482 vp9_append_sub8x8_mvs_for_idx(cm, xd, tile, j, ref, mi_row, mi_col,
483 &nearest_sub8x8[ref],
484 &near_sub8x8[ref]);
485
486 if (!assign_mv(cm, b_mode, block, nearestmv,
487 nearest_sub8x8, near_sub8x8,
488 is_compound, allow_hp, r)) {
489 xd->corrupted |= 1;
490 break;
491 };
492
493 mi->bmi[j].as_mv[0].as_int = block[0].as_int;
494 if (is_compound)
495 mi->bmi[j].as_mv[1].as_int = block[1].as_int;
496
497 if (num_4x4_h == 2)
498 mi->bmi[j + 2] = mi->bmi[j];
499 if (num_4x4_w == 2)
500 mi->bmi[j + 1] = mi->bmi[j];
501 }
502 }
503
504 mi->mbmi.mode = b_mode;
505
506 mbmi->mv[0].as_int = mi->bmi[3].as_mv[0].as_int;
507 mbmi->mv[1].as_int = mi->bmi[3].as_mv[1].as_int;
508 } else {
509 xd->corrupted |= !assign_mv(cm, mbmi->mode, mbmi->mv, nearestmv,
510 nearestmv, nearmv, is_compound, allow_hp, r);
511 }
512 }
513
read_inter_frame_mode_info(VP9_COMMON * const cm,MACROBLOCKD * const xd,const TileInfo * const tile,int mi_row,int mi_col,vp9_reader * r)514 static void read_inter_frame_mode_info(VP9_COMMON *const cm,
515 MACROBLOCKD *const xd,
516 const TileInfo *const tile,
517 int mi_row, int mi_col, vp9_reader *r) {
518 MODE_INFO *const mi = xd->mi[0];
519 MB_MODE_INFO *const mbmi = &mi->mbmi;
520 int inter_block;
521
522 mbmi->mv[0].as_int = 0;
523 mbmi->mv[1].as_int = 0;
524 mbmi->segment_id = read_inter_segment_id(cm, xd, mi_row, mi_col, r);
525 mbmi->skip = read_skip(cm, xd, mbmi->segment_id, r);
526 inter_block = read_is_inter_block(cm, xd, mbmi->segment_id, r);
527 mbmi->tx_size = read_tx_size(cm, xd, cm->tx_mode, mbmi->sb_type,
528 !mbmi->skip || !inter_block, r);
529
530 if (inter_block)
531 read_inter_block_mode_info(cm, xd, tile, mi, mi_row, mi_col, r);
532 else
533 read_intra_block_mode_info(cm, mi, r);
534 }
535
vp9_read_mode_info(VP9_COMMON * cm,MACROBLOCKD * xd,const TileInfo * const tile,int mi_row,int mi_col,vp9_reader * r)536 void vp9_read_mode_info(VP9_COMMON *cm, MACROBLOCKD *xd,
537 const TileInfo *const tile,
538 int mi_row, int mi_col, vp9_reader *r) {
539 if (frame_is_intra_only(cm))
540 read_intra_frame_mode_info(cm, xd, mi_row, mi_col, r);
541 else
542 read_inter_frame_mode_info(cm, xd, tile, mi_row, mi_col, r);
543 }
544