Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: source/libvpx/vp9/decoder/vp9_decodemv.c

Issue 11555023: libvpx: Add VP9 decoder. (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
12 #include "vp9/decoder/vp9_treereader.h"
13 #include "vp9/common/vp9_entropymv.h"
14 #include "vp9/common/vp9_entropymode.h"
15 #include "vp9/decoder/vp9_onyxd_int.h"
16 #include "vp9/common/vp9_findnearmv.h"
17
18 #include "vp9/common/vp9_seg_common.h"
19 #include "vp9/common/vp9_pred_common.h"
20 #include "vp9/common/vp9_entropy.h"
21 #include "vp9/decoder/vp9_decodemv.h"
22 #include "vp9/common/vp9_mvref_common.h"
23 #if CONFIG_DEBUG
24 #include <assert.h>
25 #endif
26
27 // #define DEBUG_DEC_MV
28 #ifdef DEBUG_DEC_MV
29 int dec_mvcount = 0;
30 #endif
31 // #define DEC_DEBUG
32 #ifdef DEC_DEBUG
33 extern int dec_debug;
34 #endif
35
36 static int read_bmode(vp9_reader *bc, const vp9_prob *p) {
37 B_PREDICTION_MODE m = treed_read(bc, vp9_bmode_tree, p);
38 #if CONFIG_NEWBINTRAMODES
39 if (m == B_CONTEXT_PRED - CONTEXT_PRED_REPLACEMENTS)
40 m = B_CONTEXT_PRED;
41 assert(m < B_CONTEXT_PRED - CONTEXT_PRED_REPLACEMENTS || m == B_CONTEXT_PRED);
42 #endif
43 return m;
44 }
45
46 static int read_kf_bmode(vp9_reader *bc, const vp9_prob *p) {
47 return treed_read(bc, vp9_kf_bmode_tree, p);
48 }
49
50 static int read_ymode(vp9_reader *bc, const vp9_prob *p) {
51 return treed_read(bc, vp9_ymode_tree, p);
52 }
53
54 #if CONFIG_SUPERBLOCKS
55 static int read_sb_ymode(vp9_reader *bc, const vp9_prob *p) {
56 return treed_read(bc, vp9_sb_ymode_tree, p);
57 }
58
59 static int read_kf_sb_ymode(vp9_reader *bc, const vp9_prob *p) {
60 return treed_read(bc, vp9_uv_mode_tree, p);
61 }
62 #endif
63
64 static int read_kf_mb_ymode(vp9_reader *bc, const vp9_prob *p) {
65 return treed_read(bc, vp9_kf_ymode_tree, p);
66 }
67
68 static int read_i8x8_mode(vp9_reader *bc, const vp9_prob *p) {
69 return treed_read(bc, vp9_i8x8_mode_tree, p);
70 }
71
72 static int read_uv_mode(vp9_reader *bc, const vp9_prob *p) {
73 return treed_read(bc, vp9_uv_mode_tree, p);
74 }
75
76 // This function reads the current macro block's segnent id from the bitstream
77 // It should only be called if a segment map update is indicated.
78 static void read_mb_segid(vp9_reader *r, MB_MODE_INFO *mi,
79 MACROBLOCKD *xd) {
80 /* Is segmentation enabled */
81 if (xd->segmentation_enabled && xd->update_mb_segmentation_map) {
82 /* If so then read the segment id. */
83 if (vp9_read(r, xd->mb_segment_tree_probs[0]))
84 mi->segment_id =
85 (unsigned char)(2 + vp9_read(r, xd->mb_segment_tree_probs[2]));
86 else
87 mi->segment_id =
88 (unsigned char)(vp9_read(r, xd->mb_segment_tree_probs[1]));
89 }
90 }
91
92 #if CONFIG_NEW_MVREF
93 int vp9_read_mv_ref_id(vp9_reader *r,
94 vp9_prob * ref_id_probs) {
95 int ref_index = 0;
96
97 if (vp9_read(r, ref_id_probs[0])) {
98 ref_index++;
99 if (vp9_read(r, ref_id_probs[1])) {
100 ref_index++;
101 if (vp9_read(r, ref_id_probs[2]))
102 ref_index++;
103 }
104 }
105 return ref_index;
106 }
107 #endif
108
109 extern const int vp9_i8x8_block[4];
110 static void kfread_modes(VP9D_COMP *pbi,
111 MODE_INFO *m,
112 int mb_row,
113 int mb_col,
114 BOOL_DECODER* const bc) {
115 VP9_COMMON *const cm = &pbi->common;
116 const int mis = pbi->common.mode_info_stride;
117 int map_index = mb_row * pbi->common.mb_cols + mb_col;
118 MB_PREDICTION_MODE y_mode;
119
120 // Read the Macroblock segmentation map if it is being updated explicitly
121 // this frame (reset to 0 by default).
122 m->mbmi.segment_id = 0;
123 if (pbi->mb.update_mb_segmentation_map) {
124 read_mb_segid(bc, &m->mbmi, &pbi->mb);
125 pbi->common.last_frame_seg_map[map_index] = m->mbmi.segment_id;
126 }
127
128 m->mbmi.mb_skip_coeff = 0;
129 if (pbi->common.mb_no_coeff_skip &&
130 (!vp9_segfeature_active(&pbi->mb,
131 m->mbmi.segment_id, SEG_LVL_EOB) ||
132 (vp9_get_segdata(&pbi->mb,
133 m->mbmi.segment_id, SEG_LVL_EOB) != 0))) {
134 MACROBLOCKD *const xd = &pbi->mb;
135 m->mbmi.mb_skip_coeff =
136 vp9_read(bc, vp9_get_pred_prob(cm, xd, PRED_MBSKIP));
137 } else {
138 if (vp9_segfeature_active(&pbi->mb,
139 m->mbmi.segment_id, SEG_LVL_EOB) &&
140 (vp9_get_segdata(&pbi->mb,
141 m->mbmi.segment_id, SEG_LVL_EOB) == 0)) {
142 m->mbmi.mb_skip_coeff = 1;
143 } else
144 m->mbmi.mb_skip_coeff = 0;
145 }
146
147 #if CONFIG_SUPERBLOCKS
148 if (m->mbmi.encoded_as_sb) {
149 y_mode = (MB_PREDICTION_MODE) read_kf_sb_ymode(bc,
150 pbi->common.sb_kf_ymode_prob[pbi->common.kf_ymode_probs_index]);
151 } else
152 #endif
153 y_mode = (MB_PREDICTION_MODE) read_kf_mb_ymode(bc,
154 pbi->common.kf_ymode_prob[pbi->common.kf_ymode_probs_index]);
155 #if CONFIG_COMP_INTRA_PRED
156 m->mbmi.second_mode = (MB_PREDICTION_MODE)(DC_PRED - 1);
157 #endif
158
159 m->mbmi.ref_frame = INTRA_FRAME;
160
161 if ((m->mbmi.mode = y_mode) == B_PRED) {
162 int i = 0;
163 #if CONFIG_COMP_INTRA_PRED
164 int use_comp_pred = vp9_read(bc, DEFAULT_COMP_INTRA_PROB);
165 #endif
166 do {
167 const B_PREDICTION_MODE A = above_block_mode(m, i, mis);
168 const B_PREDICTION_MODE L = left_block_mode(m, i);
169
170 m->bmi[i].as_mode.first =
171 (B_PREDICTION_MODE) read_kf_bmode(
172 bc, pbi->common.kf_bmode_prob [A] [L]);
173 #if CONFIG_COMP_INTRA_PRED
174 if (use_comp_pred) {
175 m->bmi[i].as_mode.second =
176 (B_PREDICTION_MODE) read_kf_bmode(
177 bc, pbi->common.kf_bmode_prob [A] [L]);
178 } else {
179 m->bmi[i].as_mode.second = (B_PREDICTION_MODE)(B_DC_PRED - 1);
180 }
181 #endif
182 } while (++i < 16);
183 }
184 if ((m->mbmi.mode = y_mode) == I8X8_PRED) {
185 int i;
186 int mode8x8;
187 for (i = 0; i < 4; i++) {
188 int ib = vp9_i8x8_block[i];
189 mode8x8 = read_i8x8_mode(bc, pbi->common.fc.i8x8_mode_prob);
190 m->bmi[ib + 0].as_mode.first = mode8x8;
191 m->bmi[ib + 1].as_mode.first = mode8x8;
192 m->bmi[ib + 4].as_mode.first = mode8x8;
193 m->bmi[ib + 5].as_mode.first = mode8x8;
194 #if CONFIG_COMP_INTRA_PRED
195 m->bmi[ib + 0].as_mode.second = (MB_PREDICTION_MODE)(DC_PRED - 1);
196 m->bmi[ib + 1].as_mode.second = (MB_PREDICTION_MODE)(DC_PRED - 1);
197 m->bmi[ib + 4].as_mode.second = (MB_PREDICTION_MODE)(DC_PRED - 1);
198 m->bmi[ib + 5].as_mode.second = (MB_PREDICTION_MODE)(DC_PRED - 1);
199 #endif
200 }
201 } else
202 m->mbmi.uv_mode = (MB_PREDICTION_MODE)read_uv_mode(bc,
203 pbi->common.kf_uv_mode_pr ob[m->mbmi.mode]);
204 #if CONFIG_COMP_INTRA_PRED
205 m->mbmi.second_uv_mode = (MB_PREDICTION_MODE)(DC_PRED - 1);
206 #endif
207
208 if (cm->txfm_mode == TX_MODE_SELECT && m->mbmi.mb_skip_coeff == 0 &&
209 m->mbmi.mode <= I8X8_PRED) {
210 // FIXME(rbultje) code ternary symbol once all experiments are merged
211 m->mbmi.txfm_size = vp9_read(bc, cm->prob_tx[0]);
212 if (m->mbmi.txfm_size != TX_4X4 && m->mbmi.mode != I8X8_PRED)
213 m->mbmi.txfm_size += vp9_read(bc, cm->prob_tx[1]);
214 } else if (cm->txfm_mode >= ALLOW_16X16 && m->mbmi.mode <= TM_PRED) {
215 m->mbmi.txfm_size = TX_16X16;
216 } else if (cm->txfm_mode >= ALLOW_8X8 && m->mbmi.mode != B_PRED) {
217 m->mbmi.txfm_size = TX_8X8;
218 } else {
219 m->mbmi.txfm_size = TX_4X4;
220 }
221 }
222
223 static int read_nmv_component(vp9_reader *r,
224 int rv,
225 const nmv_component *mvcomp) {
226 int v, s, z, c, o, d;
227 s = vp9_read(r, mvcomp->sign);
228 c = treed_read(r, vp9_mv_class_tree, mvcomp->classes);
229 if (c == MV_CLASS_0) {
230 d = treed_read(r, vp9_mv_class0_tree, mvcomp->class0);
231 } else {
232 int i, b;
233 d = 0;
234 b = c + CLASS0_BITS - 1; /* number of bits */
235 for (i = 0; i < b; ++i)
236 d |= (vp9_read(r, mvcomp->bits[i]) << i);
237 }
238 o = d << 3;
239
240 z = vp9_get_mv_mag(c, o);
241 v = (s ? -(z + 8) : (z + 8));
242 return v;
243 }
244
245 static int read_nmv_component_fp(vp9_reader *r,
246 int v,
247 int rv,
248 const nmv_component *mvcomp,
249 int usehp) {
250 int s, z, c, o, d, e, f;
251 s = v < 0;
252 z = (s ? -v : v) - 1; /* magnitude - 1 */
253 z &= ~7;
254
255 c = vp9_get_mv_class(z, &o);
256 d = o >> 3;
257
258 if (c == MV_CLASS_0) {
259 f = treed_read(r, vp9_mv_fp_tree, mvcomp->class0_fp[d]);
260 } else {
261 f = treed_read(r, vp9_mv_fp_tree, mvcomp->fp);
262 }
263 o += (f << 1);
264
265 if (usehp) {
266 if (c == MV_CLASS_0) {
267 e = vp9_read(r, mvcomp->class0_hp);
268 } else {
269 e = vp9_read(r, mvcomp->hp);
270 }
271 o += e;
272 } else {
273 ++o; /* Note if hp is not used, the default value of the hp bit is 1 */
274 }
275 z = vp9_get_mv_mag(c, o);
276 v = (s ? -(z + 1) : (z + 1));
277 return v;
278 }
279
280 static void read_nmv(vp9_reader *r, MV *mv, const MV *ref,
281 const nmv_context *mvctx) {
282 MV_JOINT_TYPE j = treed_read(r, vp9_mv_joint_tree, mvctx->joints);
283 mv->row = mv-> col = 0;
284 if (j == MV_JOINT_HZVNZ || j == MV_JOINT_HNZVNZ) {
285 mv->row = read_nmv_component(r, ref->row, &mvctx->comps[0]);
286 }
287 if (j == MV_JOINT_HNZVZ || j == MV_JOINT_HNZVNZ) {
288 mv->col = read_nmv_component(r, ref->col, &mvctx->comps[1]);
289 }
290 }
291
292 static void read_nmv_fp(vp9_reader *r, MV *mv, const MV *ref,
293 const nmv_context *mvctx, int usehp) {
294 MV_JOINT_TYPE j = vp9_get_mv_joint(*mv);
295 usehp = usehp && vp9_use_nmv_hp(ref);
296 if (j == MV_JOINT_HZVNZ || j == MV_JOINT_HNZVNZ) {
297 mv->row = read_nmv_component_fp(r, mv->row, ref->row, &mvctx->comps[0],
298 usehp);
299 }
300 if (j == MV_JOINT_HNZVZ || j == MV_JOINT_HNZVNZ) {
301 mv->col = read_nmv_component_fp(r, mv->col, ref->col, &mvctx->comps[1],
302 usehp);
303 }
304 //printf(" %d: %d %d ref: %d %d\n", usehp, mv->row, mv-> col, ref->row, ref-> col);
305 }
306
307 static void update_nmv(vp9_reader *bc, vp9_prob *const p,
308 const vp9_prob upd_p) {
309 if (vp9_read(bc, upd_p)) {
310 #ifdef LOW_PRECISION_MV_UPDATE
311 *p = (vp9_read_literal(bc, 7) << 1) | 1;
312 #else
313 *p = (vp9_read_literal(bc, 8));
314 #endif
315 }
316 }
317
318 static void read_nmvprobs(vp9_reader *bc, nmv_context *mvctx,
319 int usehp) {
320 int i, j, k;
321 #ifdef MV_GROUP_UPDATE
322 if (!vp9_read_bit(bc)) return;
323 #endif
324 for (j = 0; j < MV_JOINTS - 1; ++j) {
325 update_nmv(bc, &mvctx->joints[j],
326 VP9_NMV_UPDATE_PROB);
327 }
328 for (i = 0; i < 2; ++i) {
329 update_nmv(bc, &mvctx->comps[i].sign,
330 VP9_NMV_UPDATE_PROB);
331 for (j = 0; j < MV_CLASSES - 1; ++j) {
332 update_nmv(bc, &mvctx->comps[i].classes[j],
333 VP9_NMV_UPDATE_PROB);
334 }
335 for (j = 0; j < CLASS0_SIZE - 1; ++j) {
336 update_nmv(bc, &mvctx->comps[i].class0[j],
337 VP9_NMV_UPDATE_PROB);
338 }
339 for (j = 0; j < MV_OFFSET_BITS; ++j) {
340 update_nmv(bc, &mvctx->comps[i].bits[j],
341 VP9_NMV_UPDATE_PROB);
342 }
343 }
344
345 for (i = 0; i < 2; ++i) {
346 for (j = 0; j < CLASS0_SIZE; ++j) {
347 for (k = 0; k < 3; ++k)
348 update_nmv(bc, &mvctx->comps[i].class0_fp[j][k],
349 VP9_NMV_UPDATE_PROB);
350 }
351 for (j = 0; j < 3; ++j) {
352 update_nmv(bc, &mvctx->comps[i].fp[j],
353 VP9_NMV_UPDATE_PROB);
354 }
355 }
356
357 if (usehp) {
358 for (i = 0; i < 2; ++i) {
359 update_nmv(bc, &mvctx->comps[i].class0_hp,
360 VP9_NMV_UPDATE_PROB);
361 update_nmv(bc, &mvctx->comps[i].hp,
362 VP9_NMV_UPDATE_PROB);
363 }
364 }
365 }
366
367 // Read the referncence frame
368 static MV_REFERENCE_FRAME read_ref_frame(VP9D_COMP *pbi,
369 vp9_reader *const bc,
370 unsigned char segment_id) {
371 MV_REFERENCE_FRAME ref_frame;
372 int seg_ref_active;
373 int seg_ref_count = 0;
374
375 VP9_COMMON *const cm = &pbi->common;
376 MACROBLOCKD *const xd = &pbi->mb;
377
378 seg_ref_active = vp9_segfeature_active(xd,
379 segment_id,
380 SEG_LVL_REF_FRAME);
381
382 // If segment coding enabled does the segment allow for more than one
383 // possible reference frame
384 if (seg_ref_active) {
385 seg_ref_count = vp9_check_segref(xd, segment_id, INTRA_FRAME) +
386 vp9_check_segref(xd, segment_id, LAST_FRAME) +
387 vp9_check_segref(xd, segment_id, GOLDEN_FRAME) +
388 vp9_check_segref(xd, segment_id, ALTREF_FRAME);
389 }
390
391 // Segment reference frame features not available or allows for
392 // multiple reference frame options
393 if (!seg_ref_active || (seg_ref_count > 1)) {
394 // Values used in prediction model coding
395 unsigned char prediction_flag;
396 vp9_prob pred_prob;
397 MV_REFERENCE_FRAME pred_ref;
398
399 // Get the context probability the prediction flag
400 pred_prob = vp9_get_pred_prob(cm, xd, PRED_REF);
401
402 // Read the prediction status flag
403 prediction_flag = (unsigned char)vp9_read(bc, pred_prob);
404
405 // Store the prediction flag.
406 vp9_set_pred_flag(xd, PRED_REF, prediction_flag);
407
408 // Get the predicted reference frame.
409 pred_ref = vp9_get_pred_ref(cm, xd);
410
411 // If correctly predicted then use the predicted value
412 if (prediction_flag) {
413 ref_frame = pred_ref;
414 }
415 // else decode the explicitly coded value
416 else {
417 vp9_prob mod_refprobs[PREDICTION_PROBS];
418 vpx_memcpy(mod_refprobs,
419 cm->mod_refprobs[pred_ref], sizeof(mod_refprobs));
420
421 // If segment coding enabled blank out options that cant occur by
422 // setting the branch probability to 0.
423 if (seg_ref_active) {
424 mod_refprobs[INTRA_FRAME] *=
425 vp9_check_segref(xd, segment_id, INTRA_FRAME);
426 mod_refprobs[LAST_FRAME] *=
427 vp9_check_segref(xd, segment_id, LAST_FRAME);
428 mod_refprobs[GOLDEN_FRAME] *=
429 (vp9_check_segref(xd, segment_id, GOLDEN_FRAME) *
430 vp9_check_segref(xd, segment_id, ALTREF_FRAME));
431 }
432
433 // Default to INTRA_FRAME (value 0)
434 ref_frame = INTRA_FRAME;
435
436 // Do we need to decode the Intra/Inter branch
437 if (mod_refprobs[0])
438 ref_frame = (MV_REFERENCE_FRAME) vp9_read(bc, mod_refprobs[0]);
439 else
440 ref_frame++;
441
442 if (ref_frame) {
443 // Do we need to decode the Last/Gf_Arf branch
444 if (mod_refprobs[1])
445 ref_frame += vp9_read(bc, mod_refprobs[1]);
446 else
447 ref_frame++;
448
449 if (ref_frame > 1) {
450 // Do we need to decode the GF/Arf branch
451 if (mod_refprobs[2])
452 ref_frame += vp9_read(bc, mod_refprobs[2]);
453 else {
454 if (seg_ref_active) {
455 if ((pred_ref == GOLDEN_FRAME) ||
456 !vp9_check_segref(xd, segment_id, GOLDEN_FRAME)) {
457 ref_frame = ALTREF_FRAME;
458 } else
459 ref_frame = GOLDEN_FRAME;
460 } else
461 ref_frame = (pred_ref == GOLDEN_FRAME)
462 ? ALTREF_FRAME : GOLDEN_FRAME;
463 }
464 }
465 }
466 }
467 }
468
469 // Segment reference frame features are enabled
470 else {
471 // The reference frame for the mb is considered as correclty predicted
472 // if it is signaled at the segment level for the purposes of the
473 // common prediction model
474 vp9_set_pred_flag(xd, PRED_REF, 1);
475 ref_frame = vp9_get_pred_ref(cm, xd);
476 }
477
478 return (MV_REFERENCE_FRAME)ref_frame;
479 }
480
481 #if CONFIG_SUPERBLOCKS
482 static MB_PREDICTION_MODE read_sb_mv_ref(vp9_reader *bc, const vp9_prob *p) {
483 return (MB_PREDICTION_MODE) treed_read(bc, vp9_sb_mv_ref_tree, p);
484 }
485 #endif
486
487 static MB_PREDICTION_MODE read_mv_ref(vp9_reader *bc, const vp9_prob *p) {
488 return (MB_PREDICTION_MODE) treed_read(bc, vp9_mv_ref_tree, p);
489 }
490
491 static B_PREDICTION_MODE sub_mv_ref(vp9_reader *bc, const vp9_prob *p) {
492 return (B_PREDICTION_MODE) treed_read(bc, vp9_sub_mv_ref_tree, p);
493 }
494
495 #ifdef VPX_MODE_COUNT
496 unsigned int vp9_mv_cont_count[5][4] = {
497 { 0, 0, 0, 0 },
498 { 0, 0, 0, 0 },
499 { 0, 0, 0, 0 },
500 { 0, 0, 0, 0 },
501 { 0, 0, 0, 0 }
502 };
503 #endif
504
505 static const unsigned char mbsplit_fill_count[4] = {8, 8, 4, 1};
506 static const unsigned char mbsplit_fill_offset[4][16] = {
507 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
508 { 0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15},
509 { 0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15},
510 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
511 };
512
513 static void read_switchable_interp_probs(VP9D_COMP* const pbi,
514 BOOL_DECODER* const bc) {
515 VP9_COMMON *const cm = &pbi->common;
516 int i, j;
517 for (j = 0; j <= VP9_SWITCHABLE_FILTERS; ++j) {
518 for (i = 0; i < VP9_SWITCHABLE_FILTERS - 1; ++i) {
519 cm->fc.switchable_interp_prob[j][i] = vp9_read_literal(bc, 8);
520 }
521 }
522 //printf("DECODER: %d %d\n", cm->fc.switchable_interp_prob[0],
523 //cm->fc.switchable_interp_prob[1]);
524 }
525
526 static void mb_mode_mv_init(VP9D_COMP *pbi, vp9_reader *bc) {
527 VP9_COMMON *const cm = &pbi->common;
528 nmv_context *const nmvc = &pbi->common.fc.nmvc;
529 MACROBLOCKD *const xd = &pbi->mb;
530
531 if (cm->frame_type == KEY_FRAME) {
532 if (!cm->kf_ymode_probs_update)
533 cm->kf_ymode_probs_index = vp9_read_literal(bc, 3);
534 } else {
535 #if CONFIG_PRED_FILTER
536 cm->pred_filter_mode = (vp9_prob)vp9_read_literal(bc, 2);
537
538 if (cm->pred_filter_mode == 2)
539 cm->prob_pred_filter_off = (vp9_prob)vp9_read_literal(bc, 8);
540 #endif
541 if (cm->mcomp_filter_type == SWITCHABLE)
542 read_switchable_interp_probs(pbi, bc);
543 #if CONFIG_COMP_INTERINTRA_PRED
544 if (cm->use_interintra) {
545 if (vp9_read(bc, VP9_UPD_INTERINTRA_PROB))
546 cm->fc.interintra_prob = (vp9_prob)vp9_read_literal(bc, 8);
547 }
548 #endif
549 // Decode the baseline probabilities for decoding reference frame
550 cm->prob_intra_coded = (vp9_prob)vp9_read_literal(bc, 8);
551 cm->prob_last_coded = (vp9_prob)vp9_read_literal(bc, 8);
552 cm->prob_gf_coded = (vp9_prob)vp9_read_literal(bc, 8);
553
554 // Computes a modified set of probabilities for use when reference
555 // frame prediction fails.
556 vp9_compute_mod_refprobs(cm);
557
558 pbi->common.comp_pred_mode = vp9_read(bc, 128);
559 if (cm->comp_pred_mode)
560 cm->comp_pred_mode += vp9_read(bc, 128);
561 if (cm->comp_pred_mode == HYBRID_PREDICTION) {
562 int i;
563 for (i = 0; i < COMP_PRED_CONTEXTS; i++)
564 cm->prob_comppred[i] = (vp9_prob)vp9_read_literal(bc, 8);
565 }
566
567 if (vp9_read_bit(bc)) {
568 int i = 0;
569
570 do {
571 cm->fc.ymode_prob[i] = (vp9_prob) vp9_read_literal(bc, 8);
572 } while (++i < VP9_YMODES - 1);
573 }
574
575 #if CONFIG_SUPERBLOCKS
576 if (vp9_read_bit(bc)) {
577 int i = 0;
578
579 do {
580 cm->fc.sb_ymode_prob[i] = (vp9_prob) vp9_read_literal(bc, 8);
581 } while (++i < VP9_I32X32_MODES - 1);
582 }
583 #endif
584
585 #if CONFIG_NEW_MVREF
586 // Temp defaults probabilities for ecnoding the MV ref id signal
587 vpx_memset(xd->mb_mv_ref_id_probs, 192, sizeof(xd->mb_mv_ref_id_probs));
588 #endif
589
590 read_nmvprobs(bc, nmvc, xd->allow_high_precision_mv);
591 }
592 }
593
594 // This function either reads the segment id for the current macroblock from
595 // the bitstream or if the value is temporally predicted asserts the predicted
596 // value
597 static void read_mb_segment_id(VP9D_COMP *pbi,
598 int mb_row, int mb_col,
599 BOOL_DECODER* const bc) {
600 VP9_COMMON *const cm = &pbi->common;
601 MACROBLOCKD *const xd = &pbi->mb;
602 MODE_INFO *mi = xd->mode_info_context;
603 MB_MODE_INFO *mbmi = &mi->mbmi;
604 int index = mb_row * pbi->common.mb_cols + mb_col;
605
606 if (xd->segmentation_enabled) {
607 if (xd->update_mb_segmentation_map) {
608 // Is temporal coding of the segment id for this mb enabled.
609 if (cm->temporal_update) {
610 // Get the context based probability for reading the
611 // prediction status flag
612 vp9_prob pred_prob =
613 vp9_get_pred_prob(cm, xd, PRED_SEG_ID);
614
615 // Read the prediction status flag
616 unsigned char seg_pred_flag =
617 (unsigned char)vp9_read(bc, pred_prob);
618
619 // Store the prediction flag.
620 vp9_set_pred_flag(xd, PRED_SEG_ID, seg_pred_flag);
621
622 // If the value is flagged as correctly predicted
623 // then use the predicted value
624 if (seg_pred_flag) {
625 mbmi->segment_id = vp9_get_pred_mb_segid(cm, xd, index);
626 }
627 // Else .... decode it explicitly
628 else {
629 read_mb_segid(bc, mbmi, xd);
630 }
631 }
632 // Normal unpredicted coding mode
633 else {
634 read_mb_segid(bc, mbmi, xd);
635 }
636 #if CONFIG_SUPERBLOCKS
637 if (mbmi->encoded_as_sb) {
638 cm->last_frame_seg_map[index] = mbmi->segment_id;
639 if (mb_col + 1 < cm->mb_cols)
640 cm->last_frame_seg_map[index + 1] = mbmi->segment_id;
641 if (mb_row + 1 < cm->mb_rows) {
642 cm->last_frame_seg_map[index + cm->mb_cols] = mbmi->segment_id;
643 if (mb_col + 1 < cm->mb_cols)
644 cm->last_frame_seg_map[index + cm->mb_cols + 1] = mbmi->segment_id;
645 }
646 } else
647 #endif
648 {
649 cm->last_frame_seg_map[index] = mbmi->segment_id;
650 }
651 } else {
652 #if CONFIG_SUPERBLOCKS
653 if (mbmi->encoded_as_sb) {
654 mbmi->segment_id = cm->last_frame_seg_map[index];
655 if (mb_col < cm->mb_cols - 1)
656 mbmi->segment_id = mbmi->segment_id &&
657 cm->last_frame_seg_map[index + 1];
658 if (mb_row < cm->mb_rows - 1) {
659 mbmi->segment_id = mbmi->segment_id &&
660 cm->last_frame_seg_map[index + cm->mb_cols];
661 if (mb_col < cm->mb_cols - 1)
662 mbmi->segment_id = mbmi->segment_id &&
663 cm->last_frame_seg_map[index + cm->mb_cols + 1];
664 }
665 } else
666 #endif
667 {
668 mbmi->segment_id = cm->last_frame_seg_map[index];
669 }
670 }
671 } else {
672 // The encoder explicitly sets the segment_id to 0
673 // when segmentation is disabled
674 mbmi->segment_id = 0;
675 }
676 }
677
678 static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
679 MODE_INFO *prev_mi,
680 int mb_row, int mb_col,
681 BOOL_DECODER* const bc) {
682 VP9_COMMON *const cm = &pbi->common;
683 nmv_context *const nmvc = &pbi->common.fc.nmvc;
684 const int mis = pbi->common.mode_info_stride;
685 MACROBLOCKD *const xd = &pbi->mb;
686
687 int_mv *const mv = &mbmi->mv[0];
688 int mb_to_left_edge;
689 int mb_to_right_edge;
690 int mb_to_top_edge;
691 int mb_to_bottom_edge;
692
693 mb_to_top_edge = xd->mb_to_top_edge;
694 mb_to_bottom_edge = xd->mb_to_bottom_edge;
695 mb_to_top_edge -= LEFT_TOP_MARGIN;
696 mb_to_bottom_edge += RIGHT_BOTTOM_MARGIN;
697 mbmi->need_to_clamp_mvs = 0;
698 mbmi->need_to_clamp_secondmv = 0;
699 mbmi->second_ref_frame = NONE;
700 /* Distance of Mb to the various image edges.
701 * These specified to 8th pel as they are always compared to MV values that ar e in 1/8th pel units
702 */
703 xd->mb_to_left_edge =
704 mb_to_left_edge = -((mb_col * 16) << 3);
705 mb_to_left_edge -= LEFT_TOP_MARGIN;
706
707 #if CONFIG_SUPERBLOCKS
708 if (mi->mbmi.encoded_as_sb) {
709 xd->mb_to_right_edge =
710 mb_to_right_edge = ((pbi->common.mb_cols - 2 - mb_col) * 16) << 3;
711 } else {
712 #endif
713 xd->mb_to_right_edge =
714 mb_to_right_edge = ((pbi->common.mb_cols - 1 - mb_col) * 16) << 3;
715 #if CONFIG_SUPERBLOCKS
716 }
717 #endif
718 mb_to_right_edge += RIGHT_BOTTOM_MARGIN;
719
720 // Make sure the MACROBLOCKD mode info pointer is pointed at the
721 // correct entry for the current macroblock.
722 xd->mode_info_context = mi;
723 xd->prev_mode_info_context = prev_mi;
724
725 // Read the macroblock segment id.
726 read_mb_segment_id(pbi, mb_row, mb_col, bc);
727
728 if (pbi->common.mb_no_coeff_skip &&
729 (!vp9_segfeature_active(xd,
730 mbmi->segment_id, SEG_LVL_EOB) ||
731 (vp9_get_segdata(xd, mbmi->segment_id, SEG_LVL_EOB) != 0))) {
732 // Read the macroblock coeff skip flag if this feature is in use,
733 // else default to 0
734 mbmi->mb_skip_coeff = vp9_read(bc, vp9_get_pred_prob(cm, xd, PRED_MBSKIP));
735 } else {
736 if (vp9_segfeature_active(xd,
737 mbmi->segment_id, SEG_LVL_EOB) &&
738 (vp9_get_segdata(xd, mbmi->segment_id, SEG_LVL_EOB) == 0)) {
739 mbmi->mb_skip_coeff = 1;
740 } else
741 mbmi->mb_skip_coeff = 0;
742 }
743
744 // Read the reference frame
745 if (vp9_segfeature_active(xd, mbmi->segment_id, SEG_LVL_MODE)
746 && vp9_get_segdata(xd, mbmi->segment_id, SEG_LVL_MODE) < NEARESTMV)
747 mbmi->ref_frame = INTRA_FRAME;
748 else
749 mbmi->ref_frame = read_ref_frame(pbi, bc, mbmi->segment_id);
750
751 // If reference frame is an Inter frame
752 if (mbmi->ref_frame) {
753 int_mv nearest, nearby, best_mv;
754 int_mv nearest_second, nearby_second, best_mv_second;
755 vp9_prob mv_ref_p [VP9_MVREFS - 1];
756
757 int recon_y_stride, recon_yoffset;
758 int recon_uv_stride, recon_uvoffset;
759
760 {
761 int ref_fb_idx;
762 MV_REFERENCE_FRAME ref_frame = mbmi->ref_frame;
763
764 /* Select the appropriate reference frame for this MB */
765 if (ref_frame == LAST_FRAME)
766 ref_fb_idx = cm->lst_fb_idx;
767 else if (ref_frame == GOLDEN_FRAME)
768 ref_fb_idx = cm->gld_fb_idx;
769 else
770 ref_fb_idx = cm->alt_fb_idx;
771
772 recon_y_stride = cm->yv12_fb[ref_fb_idx].y_stride ;
773 recon_uv_stride = cm->yv12_fb[ref_fb_idx].uv_stride;
774
775 recon_yoffset = (mb_row * recon_y_stride * 16) + (mb_col * 16);
776 recon_uvoffset = (mb_row * recon_uv_stride * 8) + (mb_col * 8);
777
778 xd->pre.y_buffer = cm->yv12_fb[ref_fb_idx].y_buffer + recon_yoffset;
779 xd->pre.u_buffer = cm->yv12_fb[ref_fb_idx].u_buffer + recon_uvoffset;
780 xd->pre.v_buffer = cm->yv12_fb[ref_fb_idx].v_buffer + recon_uvoffset;
781
782 #ifdef DEC_DEBUG
783 if (dec_debug)
784 printf("%d %d\n", xd->mode_info_context->mbmi.mv[0].as_mv.row,
785 xd->mode_info_context->mbmi.mv[0].as_mv.col);
786 #endif
787 vp9_find_mv_refs(xd, mi, prev_mi,
788 ref_frame, mbmi->ref_mvs[ref_frame],
789 cm->ref_frame_sign_bias);
790
791 vp9_find_best_ref_mvs(xd,
792 xd->pre.y_buffer,
793 recon_y_stride,
794 mbmi->ref_mvs[ref_frame],
795 &best_mv, &nearest, &nearby);
796
797 vp9_mv_ref_probs(&pbi->common, mv_ref_p,
798 mbmi->mb_mode_context[ref_frame]);
799 #ifdef DEC_DEBUG
800 if (dec_debug)
801 printf("[D %d %d] %d %d %d %d\n", ref_frame,
802 mbmi->mb_mode_context[ref_frame],
803 mv_ref_p[0], mv_ref_p[1], mv_ref_p[2], mv_ref_p[3]);
804 #endif
805 }
806
807 // Is the segment level mode feature enabled for this segment
808 if (vp9_segfeature_active(xd, mbmi->segment_id, SEG_LVL_MODE)) {
809 mbmi->mode =
810 vp9_get_segdata(xd, mbmi->segment_id, SEG_LVL_MODE);
811 } else {
812 #if CONFIG_SUPERBLOCKS
813 if (mbmi->encoded_as_sb) {
814 mbmi->mode = read_sb_mv_ref(bc, mv_ref_p);
815 } else
816 #endif
817 mbmi->mode = read_mv_ref(bc, mv_ref_p);
818
819 vp9_accum_mv_refs(&pbi->common, mbmi->mode,
820 mbmi->mb_mode_context[mbmi->ref_frame]);
821 }
822
823 #if CONFIG_PRED_FILTER
824 if (mbmi->mode >= NEARESTMV && mbmi->mode < SPLITMV) {
825 // Is the prediction filter enabled
826 if (cm->pred_filter_mode == 2)
827 mbmi->pred_filter_enabled =
828 vp9_read(bc, cm->prob_pred_filter_off);
829 else
830 mbmi->pred_filter_enabled = cm->pred_filter_mode;
831 }
832 #endif
833 if (mbmi->mode >= NEARESTMV && mbmi->mode <= SPLITMV)
834 {
835 if (cm->mcomp_filter_type == SWITCHABLE) {
836 mbmi->interp_filter = vp9_switchable_interp[
837 treed_read(bc, vp9_switchable_interp_tree,
838 vp9_get_pred_probs(cm, xd, PRED_SWITCHABLE_INTERP))];
839 } else {
840 mbmi->interp_filter = cm->mcomp_filter_type;
841 }
842 }
843
844 if (cm->comp_pred_mode == COMP_PREDICTION_ONLY ||
845 (cm->comp_pred_mode == HYBRID_PREDICTION &&
846 vp9_read(bc, vp9_get_pred_prob(cm, xd, PRED_COMP)))) {
847 /* Since we have 3 reference frames, we can only have 3 unique
848 * combinations of combinations of 2 different reference frames
849 * (A-G, G-L or A-L). In the bitstream, we use this to simply
850 * derive the second reference frame from the first reference
851 * frame, by saying it's the next one in the enumerator, and
852 * if that's > n_refs, then the second reference frame is the
853 * first one in the enumerator. */
854 mbmi->second_ref_frame = mbmi->ref_frame + 1;
855 if (mbmi->second_ref_frame == 4)
856 mbmi->second_ref_frame = 1;
857 if (mbmi->second_ref_frame > 0) {
858 int second_ref_fb_idx;
859 /* Select the appropriate reference frame for this MB */
860 if (mbmi->second_ref_frame == LAST_FRAME)
861 second_ref_fb_idx = cm->lst_fb_idx;
862 else if (mbmi->second_ref_frame ==
863 GOLDEN_FRAME)
864 second_ref_fb_idx = cm->gld_fb_idx;
865 else
866 second_ref_fb_idx = cm->alt_fb_idx;
867
868 xd->second_pre.y_buffer =
869 cm->yv12_fb[second_ref_fb_idx].y_buffer + recon_yoffset;
870 xd->second_pre.u_buffer =
871 cm->yv12_fb[second_ref_fb_idx].u_buffer + recon_uvoffset;
872 xd->second_pre.v_buffer =
873 cm->yv12_fb[second_ref_fb_idx].v_buffer + recon_uvoffset;
874
875 vp9_find_mv_refs(xd, mi, prev_mi,
876 mbmi->second_ref_frame,
877 mbmi->ref_mvs[mbmi->second_ref_frame],
878 cm->ref_frame_sign_bias);
879
880 vp9_find_best_ref_mvs(xd,
881 xd->second_pre.y_buffer,
882 recon_y_stride,
883 mbmi->ref_mvs[mbmi->second_ref_frame],
884 &best_mv_second,
885 &nearest_second,
886 &nearby_second);
887 }
888
889 } else {
890 #if CONFIG_COMP_INTERINTRA_PRED
891 if (pbi->common.use_interintra &&
892 mbmi->mode >= NEARESTMV && mbmi->mode < SPLITMV &&
893 mbmi->second_ref_frame == NONE) {
894 mbmi->second_ref_frame = (vp9_read(bc, pbi->common.fc.interintra_prob) ?
895 INTRA_FRAME : NONE);
896 // printf("-- %d (%d)\n", mbmi->second_ref_frame == INTRA_FRAME,
897 // pbi->common.fc.interintra_prob);
898 pbi->common.fc.interintra_counts[
899 mbmi->second_ref_frame == INTRA_FRAME]++;
900 if (mbmi->second_ref_frame == INTRA_FRAME) {
901 mbmi->interintra_mode = (MB_PREDICTION_MODE)read_ymode(
902 bc, pbi->common.fc.ymode_prob);
903 pbi->common.fc.ymode_counts[mbmi->interintra_mode]++;
904 #if SEPARATE_INTERINTRA_UV
905 mbmi->interintra_uv_mode = (MB_PREDICTION_MODE)read_uv_mode(
906 bc, pbi->common.fc.uv_mode_prob[mbmi->interintra_mode]);
907 pbi->common.fc.uv_mode_counts[mbmi->interintra_mode]
908 [mbmi->interintra_uv_mode]++;
909 #else
910 mbmi->interintra_uv_mode = mbmi->interintra_mode;
911 #endif
912 // printf("** %d %d\n",
913 // mbmi->interintra_mode, mbmi->interintra_uv_mode);
914 }
915 }
916 #endif
917 }
918
919 mbmi->uv_mode = DC_PRED;
920 switch (mbmi->mode) {
921 case SPLITMV: {
922 const int s = mbmi->partitioning =
923 treed_read(bc, vp9_mbsplit_tree, cm->fc.mbsplit_prob);
924 const int num_p = vp9_mbsplit_count [s];
925 int j = 0;
926 cm->fc.mbsplit_counts[s]++;
927
928 mbmi->need_to_clamp_mvs = 0;
929 do { /* for each subset j */
930 int_mv leftmv, abovemv, second_leftmv, second_abovemv;
931 int_mv blockmv, secondmv;
932 int k; /* first block in subset j */
933 int mv_contz;
934 int blockmode;
935
936 k = vp9_mbsplit_offset[s][j];
937
938 leftmv.as_int = left_block_mv(mi, k);
939 abovemv.as_int = above_block_mv(mi, k, mis);
940 second_leftmv.as_int = 0;
941 second_abovemv.as_int = 0;
942 if (mbmi->second_ref_frame > 0) {
943 second_leftmv.as_int = left_block_second_mv(mi, k);
944 second_abovemv.as_int = above_block_second_mv(mi, k, mis);
945 }
946 mv_contz = vp9_mv_cont(&leftmv, &abovemv);
947 blockmode = sub_mv_ref(bc, cm->fc.sub_mv_ref_prob [mv_contz]);
948 cm->fc.sub_mv_ref_counts[mv_contz][blockmode - LEFT4X4]++;
949
950 switch (blockmode) {
951 case NEW4X4:
952 read_nmv(bc, &blockmv.as_mv, &best_mv.as_mv, nmvc);
953 read_nmv_fp(bc, &blockmv.as_mv, &best_mv.as_mv, nmvc,
954 xd->allow_high_precision_mv);
955 vp9_increment_nmv(&blockmv.as_mv, &best_mv.as_mv,
956 &cm->fc.NMVcount, xd->allow_high_precision_mv);
957 blockmv.as_mv.row += best_mv.as_mv.row;
958 blockmv.as_mv.col += best_mv.as_mv.col;
959
960 if (mbmi->second_ref_frame > 0) {
961 read_nmv(bc, &secondmv.as_mv, &best_mv_second.as_mv, nmvc);
962 read_nmv_fp(bc, &secondmv.as_mv, &best_mv_second.as_mv, nmvc,
963 xd->allow_high_precision_mv);
964 vp9_increment_nmv(&secondmv.as_mv, &best_mv_second.as_mv,
965 &cm->fc.NMVcount, xd->allow_high_precision_mv) ;
966 secondmv.as_mv.row += best_mv_second.as_mv.row;
967 secondmv.as_mv.col += best_mv_second.as_mv.col;
968 }
969 #ifdef VPX_MODE_COUNT
970 vp9_mv_cont_count[mv_contz][3]++;
971 #endif
972 break;
973 case LEFT4X4:
974 blockmv.as_int = leftmv.as_int;
975 if (mbmi->second_ref_frame > 0)
976 secondmv.as_int = second_leftmv.as_int;
977 #ifdef VPX_MODE_COUNT
978 vp9_mv_cont_count[mv_contz][0]++;
979 #endif
980 break;
981 case ABOVE4X4:
982 blockmv.as_int = abovemv.as_int;
983 if (mbmi->second_ref_frame > 0)
984 secondmv.as_int = second_abovemv.as_int;
985 #ifdef VPX_MODE_COUNT
986 vp9_mv_cont_count[mv_contz][1]++;
987 #endif
988 break;
989 case ZERO4X4:
990 blockmv.as_int = 0;
991 if (mbmi->second_ref_frame > 0)
992 secondmv.as_int = 0;
993 #ifdef VPX_MODE_COUNT
994 vp9_mv_cont_count[mv_contz][2]++;
995 #endif
996 break;
997 default:
998 break;
999 }
1000
1001 /* Commenting this section out, not sure why this was needed, and
1002 * there are mismatches with this section in rare cases since it is
1003 * not done in the encoder at all.
1004 mbmi->need_to_clamp_mvs |= check_mv_bounds(&blockmv,
1005 mb_to_left_edge,
1006 mb_to_right_edge,
1007 mb_to_top_edge,
1008 mb_to_bottom_edge);
1009 if (mbmi->second_ref_frame > 0) {
1010 mbmi->need_to_clamp_mvs |= check_mv_bounds(&secondmv,
1011 mb_to_left_edge,
1012 mb_to_right_edge,
1013 mb_to_top_edge,
1014 mb_to_bottom_edge);
1015 }
1016 */
1017
1018 {
1019 /* Fill (uniform) modes, mvs of jth subset.
1020 Must do it here because ensuing subsets can
1021 refer back to us via "left" or "above". */
1022 const unsigned char *fill_offset;
1023 unsigned int fill_count = mbsplit_fill_count[s];
1024
1025 fill_offset = &mbsplit_fill_offset[s][(unsigned char)j * mbsplit_fil l_count[s]];
1026
1027 do {
1028 mi->bmi[ *fill_offset].as_mv.first.as_int = blockmv.as_int;
1029 if (mbmi->second_ref_frame > 0)
1030 mi->bmi[ *fill_offset].as_mv.second.as_int = secondmv.as_int;
1031 fill_offset++;
1032 } while (--fill_count);
1033 }
1034
1035 } while (++j < num_p);
1036 }
1037
1038 mv->as_int = mi->bmi[15].as_mv.first.as_int;
1039 mbmi->mv[1].as_int = mi->bmi[15].as_mv.second.as_int;
1040
1041 break; /* done with SPLITMV */
1042
1043 case NEARMV:
1044 mv->as_int = nearby.as_int;
1045 /* Clip "next_nearest" so that it does not extend to far out of image */
1046 clamp_mv(mv, mb_to_left_edge, mb_to_right_edge,
1047 mb_to_top_edge, mb_to_bottom_edge);
1048 if (mbmi->second_ref_frame > 0) {
1049 mbmi->mv[1].as_int = nearby_second.as_int;
1050 clamp_mv(&mbmi->mv[1], mb_to_left_edge, mb_to_right_edge,
1051 mb_to_top_edge, mb_to_bottom_edge);
1052 }
1053 break;
1054
1055 case NEARESTMV:
1056 mv->as_int = nearest.as_int;
1057 /* Clip "next_nearest" so that it does not extend to far out of image */
1058 clamp_mv(mv, mb_to_left_edge, mb_to_right_edge,
1059 mb_to_top_edge, mb_to_bottom_edge);
1060 if (mbmi->second_ref_frame > 0) {
1061 mbmi->mv[1].as_int = nearest_second.as_int;
1062 clamp_mv(&mbmi->mv[1], mb_to_left_edge, mb_to_right_edge,
1063 mb_to_top_edge, mb_to_bottom_edge);
1064 }
1065 break;
1066
1067 case ZEROMV:
1068 mv->as_int = 0;
1069 if (mbmi->second_ref_frame > 0)
1070 mbmi->mv[1].as_int = 0;
1071 break;
1072
1073 case NEWMV:
1074
1075 #if CONFIG_NEW_MVREF
1076 {
1077 int best_index;
1078 MV_REFERENCE_FRAME ref_frame = mbmi->ref_frame;
1079
1080 // Encode the index of the choice.
1081 best_index =
1082 vp9_read_mv_ref_id(bc, xd->mb_mv_ref_id_probs[ref_frame]);
1083
1084 best_mv.as_int = mbmi->ref_mvs[ref_frame][best_index].as_int;
1085 }
1086 #endif
1087
1088 read_nmv(bc, &mv->as_mv, &best_mv.as_mv, nmvc);
1089 read_nmv_fp(bc, &mv->as_mv, &best_mv.as_mv, nmvc,
1090 xd->allow_high_precision_mv);
1091 vp9_increment_nmv(&mv->as_mv, &best_mv.as_mv, &cm->fc.NMVcount,
1092 xd->allow_high_precision_mv);
1093
1094 mv->as_mv.row += best_mv.as_mv.row;
1095 mv->as_mv.col += best_mv.as_mv.col;
1096
1097 /* Don't need to check this on NEARMV and NEARESTMV modes
1098 * since those modes clamp the MV. The NEWMV mode does not,
1099 * so signal to the prediction stage whether special
1100 * handling may be required.
1101 */
1102 mbmi->need_to_clamp_mvs = check_mv_bounds(mv,
1103 mb_to_left_edge,
1104 mb_to_right_edge,
1105 mb_to_top_edge,
1106 mb_to_bottom_edge);
1107
1108 if (mbmi->second_ref_frame > 0) {
1109 #if CONFIG_NEW_MVREF
1110 {
1111 int best_index;
1112 MV_REFERENCE_FRAME ref_frame = mbmi->second_ref_frame;
1113
1114 // Encode the index of the choice.
1115 best_index =
1116 vp9_read_mv_ref_id(bc, xd->mb_mv_ref_id_probs[ref_frame]);
1117 best_mv_second.as_int = mbmi->ref_mvs[ref_frame][best_index].as_int;
1118 }
1119 #endif
1120
1121 read_nmv(bc, &mbmi->mv[1].as_mv, &best_mv_second.as_mv, nmvc);
1122 read_nmv_fp(bc, &mbmi->mv[1].as_mv, &best_mv_second.as_mv, nmvc,
1123 xd->allow_high_precision_mv);
1124 vp9_increment_nmv(&mbmi->mv[1].as_mv, &best_mv_second.as_mv,
1125 &cm->fc.NMVcount, xd->allow_high_precision_mv);
1126 mbmi->mv[1].as_mv.row += best_mv_second.as_mv.row;
1127 mbmi->mv[1].as_mv.col += best_mv_second.as_mv.col;
1128 mbmi->need_to_clamp_secondmv |=
1129 check_mv_bounds(&mbmi->mv[1],
1130 mb_to_left_edge, mb_to_right_edge,
1131 mb_to_top_edge, mb_to_bottom_edge);
1132 }
1133 break;
1134 default:
1135 ;
1136 #if CONFIG_DEBUG
1137 assert(0);
1138 #endif
1139 }
1140 } else {
1141 /* required for left and above block mv */
1142 mbmi->mv[0].as_int = 0;
1143
1144 if (vp9_segfeature_active(xd, mbmi->segment_id, SEG_LVL_MODE)) {
1145 mbmi->mode = (MB_PREDICTION_MODE)
1146 vp9_get_segdata(xd, mbmi->segment_id, SEG_LVL_MODE);
1147 #if CONFIG_SUPERBLOCKS
1148 } else if (mbmi->encoded_as_sb) {
1149 mbmi->mode = (MB_PREDICTION_MODE)
1150 read_sb_ymode(bc, pbi->common.fc.sb_ymode_prob);
1151 pbi->common.fc.sb_ymode_counts[mbmi->mode]++;
1152 #endif
1153 } else {
1154 mbmi->mode = (MB_PREDICTION_MODE)
1155 read_ymode(bc, pbi->common.fc.ymode_prob);
1156 pbi->common.fc.ymode_counts[mbmi->mode]++;
1157 }
1158 #if CONFIG_COMP_INTRA_PRED
1159 mbmi->second_mode = (MB_PREDICTION_MODE)(DC_PRED - 1);
1160 #endif
1161
1162 // If MB mode is BPRED read the block modes
1163 if (mbmi->mode == B_PRED) {
1164 int j = 0;
1165 #if CONFIG_COMP_INTRA_PRED
1166 int use_comp_pred = vp9_read(bc, DEFAULT_COMP_INTRA_PROB);
1167 #endif
1168 do {
1169 int m;
1170 m = mi->bmi[j].as_mode.first = (B_PREDICTION_MODE)
1171 read_bmode(bc, pbi->common.fc.bmode_prob);
1172 #if CONFIG_NEWBINTRAMODES
1173 if (m == B_CONTEXT_PRED) m -= CONTEXT_PRED_REPLACEMENTS;
1174 #endif
1175 pbi->common.fc.bmode_counts[m]++;
1176 #if CONFIG_COMP_INTRA_PRED
1177 if (use_comp_pred) {
1178 mi->bmi[j].as_mode.second = (B_PREDICTION_MODE)read_bmode(bc, pbi->com mon.fc.bmode_prob);
1179 } else {
1180 mi->bmi[j].as_mode.second = (B_PREDICTION_MODE)(B_DC_PRED - 1);
1181 }
1182 #endif
1183 } while (++j < 16);
1184 }
1185
1186 if (mbmi->mode == I8X8_PRED) {
1187 int i;
1188 int mode8x8;
1189 for (i = 0; i < 4; i++) {
1190 int ib = vp9_i8x8_block[i];
1191 mode8x8 = read_i8x8_mode(bc, pbi->common.fc.i8x8_mode_prob);
1192 mi->bmi[ib + 0].as_mode.first = mode8x8;
1193 mi->bmi[ib + 1].as_mode.first = mode8x8;
1194 mi->bmi[ib + 4].as_mode.first = mode8x8;
1195 mi->bmi[ib + 5].as_mode.first = mode8x8;
1196 pbi->common.fc.i8x8_mode_counts[mode8x8]++;
1197 #if CONFIG_COMP_INTRA_PRED
1198 mi->bmi[ib + 0].as_mode.second = (MB_PREDICTION_MODE)(DC_PRED - 1);
1199 mi->bmi[ib + 1].as_mode.second = (MB_PREDICTION_MODE)(DC_PRED - 1);
1200 mi->bmi[ib + 4].as_mode.second = (MB_PREDICTION_MODE)(DC_PRED - 1);
1201 mi->bmi[ib + 5].as_mode.second = (MB_PREDICTION_MODE)(DC_PRED - 1);
1202 #endif
1203 }
1204 } else {
1205 mbmi->uv_mode = (MB_PREDICTION_MODE)read_uv_mode(
1206 bc, pbi->common.fc.uv_mode_prob[mbmi->mode]);
1207 pbi->common.fc.uv_mode_counts[mbmi->mode][mbmi->uv_mode]++;
1208 }
1209
1210 #if CONFIG_COMP_INTRA_PRED
1211 mbmi->second_uv_mode = (MB_PREDICTION_MODE)(DC_PRED - 1);
1212 #endif
1213 }
1214
1215 if (cm->txfm_mode == TX_MODE_SELECT && mbmi->mb_skip_coeff == 0 &&
1216 ((mbmi->ref_frame == INTRA_FRAME && mbmi->mode <= I8X8_PRED) ||
1217 (mbmi->ref_frame != INTRA_FRAME && !(mbmi->mode == SPLITMV &&
1218 mbmi->partitioning == PARTITIONING_4X4)))) {
1219 // FIXME(rbultje) code ternary symbol once all experiments are merged
1220 mbmi->txfm_size = vp9_read(bc, cm->prob_tx[0]);
1221 if (mbmi->txfm_size != TX_4X4 && mbmi->mode != I8X8_PRED &&
1222 mbmi->mode != SPLITMV)
1223 mbmi->txfm_size += vp9_read(bc, cm->prob_tx[1]);
1224 } else if (cm->txfm_mode >= ALLOW_16X16 &&
1225 ((mbmi->ref_frame == INTRA_FRAME && mbmi->mode <= TM_PRED) ||
1226 (mbmi->ref_frame != INTRA_FRAME && mbmi->mode != SPLITMV))) {
1227 mbmi->txfm_size = TX_16X16;
1228 } else if (cm->txfm_mode >= ALLOW_8X8 &&
1229 (!(mbmi->ref_frame == INTRA_FRAME && mbmi->mode == B_PRED) &&
1230 !(mbmi->ref_frame != INTRA_FRAME && mbmi->mode == SPLITMV &&
1231 mbmi->partitioning == PARTITIONING_4X4))) {
1232 mbmi->txfm_size = TX_8X8;
1233 } else {
1234 mbmi->txfm_size = TX_4X4;
1235 }
1236 }
1237
1238 void vp9_decode_mode_mvs_init(VP9D_COMP* const pbi, BOOL_DECODER* const bc) {
1239 VP9_COMMON *cm = &pbi->common;
1240
1241 vpx_memset(cm->mbskip_pred_probs, 0, sizeof(cm->mbskip_pred_probs));
1242 if (pbi->common.mb_no_coeff_skip) {
1243 int k;
1244 for (k = 0; k < MBSKIP_CONTEXTS; ++k)
1245 cm->mbskip_pred_probs[k] = (vp9_prob)vp9_read_literal(bc, 8);
1246 }
1247
1248 mb_mode_mv_init(pbi, bc);
1249 }
1250 void vp9_decode_mb_mode_mv(VP9D_COMP* const pbi,
1251 MACROBLOCKD* const xd,
1252 int mb_row,
1253 int mb_col,
1254 BOOL_DECODER* const bc) {
1255 MODE_INFO *mi = xd->mode_info_context;
1256 MODE_INFO *prev_mi = xd->prev_mode_info_context;
1257
1258 if (pbi->common.frame_type == KEY_FRAME)
1259 kfread_modes(pbi, mi, mb_row, mb_col, bc);
1260 else
1261 read_mb_modes_mv(pbi, mi, &mi->mbmi, prev_mi, mb_row, mb_col, bc);
1262 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698