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

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

Issue 1169543007: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: Created 5 years, 6 months 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
« no previous file with comments | « source/libvpx/vp9/decoder/vp9_decodemv.h ('k') | source/libvpx/vp9/decoder/vp9_detokenize.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <assert.h> 11 #include <assert.h>
12 12
13 #include "vp9/common/vp9_common.h" 13 #include "vp9/common/vp9_common.h"
14 #include "vp9/common/vp9_entropy.h" 14 #include "vp9/common/vp9_entropy.h"
15 #include "vp9/common/vp9_entropymode.h" 15 #include "vp9/common/vp9_entropymode.h"
16 #include "vp9/common/vp9_entropymv.h" 16 #include "vp9/common/vp9_entropymv.h"
17 #include "vp9/common/vp9_mvref_common.h" 17 #include "vp9/common/vp9_mvref_common.h"
18 #include "vp9/common/vp9_pred_common.h" 18 #include "vp9/common/vp9_pred_common.h"
19 #include "vp9/common/vp9_reconinter.h" 19 #include "vp9/common/vp9_reconinter.h"
20 #include "vp9/common/vp9_seg_common.h" 20 #include "vp9/common/vp9_seg_common.h"
21 21
22 #include "vp9/decoder/vp9_decodemv.h" 22 #include "vp9/decoder/vp9_decodemv.h"
23 #include "vp9/decoder/vp9_decodeframe.h" 23 #include "vp9/decoder/vp9_decodeframe.h"
24 #include "vp9/decoder/vp9_reader.h" 24 #include "vp9/decoder/vp9_reader.h"
25 25
26 static PREDICTION_MODE read_intra_mode(vp9_reader *r, const vp9_prob *p) { 26 static PREDICTION_MODE read_intra_mode(vp9_reader *r, const vp9_prob *p) {
27 return (PREDICTION_MODE)vp9_read_tree(r, vp9_intra_mode_tree, p); 27 return (PREDICTION_MODE)vp9_read_tree(r, vp9_intra_mode_tree, p);
28 } 28 }
29 29
30 static PREDICTION_MODE read_intra_mode_y(VP9_COMMON *cm, FRAME_COUNTS *counts, 30 static PREDICTION_MODE read_intra_mode_y(VP9_COMMON *cm, MACROBLOCKD *xd,
31 vp9_reader *r, int size_group) { 31 vp9_reader *r, int size_group) {
32 const PREDICTION_MODE y_mode = 32 const PREDICTION_MODE y_mode =
33 read_intra_mode(r, cm->fc->y_mode_prob[size_group]); 33 read_intra_mode(r, cm->fc->y_mode_prob[size_group]);
34 if (!cm->frame_parallel_decoding_mode) 34 FRAME_COUNTS *counts = xd->counts;
35 if (counts)
35 ++counts->y_mode[size_group][y_mode]; 36 ++counts->y_mode[size_group][y_mode];
36 return y_mode; 37 return y_mode;
37 } 38 }
38 39
39 static PREDICTION_MODE read_intra_mode_uv(VP9_COMMON *cm, FRAME_COUNTS *counts, 40 static PREDICTION_MODE read_intra_mode_uv(VP9_COMMON *cm, MACROBLOCKD *xd,
40 vp9_reader *r, 41 vp9_reader *r,
41 PREDICTION_MODE y_mode) { 42 PREDICTION_MODE y_mode) {
42 const PREDICTION_MODE uv_mode = read_intra_mode(r, 43 const PREDICTION_MODE uv_mode = read_intra_mode(r,
43 cm->fc->uv_mode_prob[y_mode]); 44 cm->fc->uv_mode_prob[y_mode]);
44 if (!cm->frame_parallel_decoding_mode) 45 FRAME_COUNTS *counts = xd->counts;
46 if (counts)
45 ++counts->uv_mode[y_mode][uv_mode]; 47 ++counts->uv_mode[y_mode][uv_mode];
46 return uv_mode; 48 return uv_mode;
47 } 49 }
48 50
49 static PREDICTION_MODE read_inter_mode(VP9_COMMON *cm, FRAME_COUNTS *counts, 51 static PREDICTION_MODE read_inter_mode(VP9_COMMON *cm, MACROBLOCKD *xd,
50 vp9_reader *r, int ctx) { 52 vp9_reader *r, int ctx) {
51 const int mode = vp9_read_tree(r, vp9_inter_mode_tree, 53 const int mode = vp9_read_tree(r, vp9_inter_mode_tree,
52 cm->fc->inter_mode_probs[ctx]); 54 cm->fc->inter_mode_probs[ctx]);
53 if (!cm->frame_parallel_decoding_mode) 55 FRAME_COUNTS *counts = xd->counts;
56 if (counts)
54 ++counts->inter_mode[ctx][mode]; 57 ++counts->inter_mode[ctx][mode];
55 58
56 return NEARESTMV + mode; 59 return NEARESTMV + mode;
57 } 60 }
58 61
59 static int read_segment_id(vp9_reader *r, const struct segmentation *seg) { 62 static int read_segment_id(vp9_reader *r, const struct segmentation *seg) {
60 return vp9_read_tree(r, vp9_segment_tree, seg->tree_probs); 63 return vp9_read_tree(r, vp9_segment_tree, seg->tree_probs);
61 } 64 }
62 65
63 static TX_SIZE read_selected_tx_size(VP9_COMMON *cm, MACROBLOCKD *xd, 66 static TX_SIZE read_selected_tx_size(VP9_COMMON *cm, MACROBLOCKD *xd,
64 FRAME_COUNTS *counts,
65 TX_SIZE max_tx_size, vp9_reader *r) { 67 TX_SIZE max_tx_size, vp9_reader *r) {
68 FRAME_COUNTS *counts = xd->counts;
66 const int ctx = vp9_get_tx_size_context(xd); 69 const int ctx = vp9_get_tx_size_context(xd);
67 const vp9_prob *tx_probs = get_tx_probs(max_tx_size, ctx, &cm->fc->tx_probs); 70 const vp9_prob *tx_probs = get_tx_probs(max_tx_size, ctx, &cm->fc->tx_probs);
68 int tx_size = vp9_read(r, tx_probs[0]); 71 int tx_size = vp9_read(r, tx_probs[0]);
69 if (tx_size != TX_4X4 && max_tx_size >= TX_16X16) { 72 if (tx_size != TX_4X4 && max_tx_size >= TX_16X16) {
70 tx_size += vp9_read(r, tx_probs[1]); 73 tx_size += vp9_read(r, tx_probs[1]);
71 if (tx_size != TX_8X8 && max_tx_size >= TX_32X32) 74 if (tx_size != TX_8X8 && max_tx_size >= TX_32X32)
72 tx_size += vp9_read(r, tx_probs[2]); 75 tx_size += vp9_read(r, tx_probs[2]);
73 } 76 }
74 77
75 if (!cm->frame_parallel_decoding_mode) 78 if (counts)
76 ++get_tx_counts(max_tx_size, ctx, &counts->tx)[tx_size]; 79 ++get_tx_counts(max_tx_size, ctx, &counts->tx)[tx_size];
77 return (TX_SIZE)tx_size; 80 return (TX_SIZE)tx_size;
78 } 81 }
79 82
80 static TX_SIZE read_tx_size(VP9_COMMON *cm, MACROBLOCKD *xd, 83 static TX_SIZE read_tx_size(VP9_COMMON *cm, MACROBLOCKD *xd,
81 FRAME_COUNTS *counts,
82 int allow_select, vp9_reader *r) { 84 int allow_select, vp9_reader *r) {
83 TX_MODE tx_mode = cm->tx_mode; 85 TX_MODE tx_mode = cm->tx_mode;
84 BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type; 86 BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type;
85 const TX_SIZE max_tx_size = max_txsize_lookup[bsize]; 87 const TX_SIZE max_tx_size = max_txsize_lookup[bsize];
86 if (allow_select && tx_mode == TX_MODE_SELECT && bsize >= BLOCK_8X8) 88 if (allow_select && tx_mode == TX_MODE_SELECT && bsize >= BLOCK_8X8)
87 return read_selected_tx_size(cm, xd, counts, max_tx_size, r); 89 return read_selected_tx_size(cm, xd, max_tx_size, r);
88 else 90 else
89 return MIN(max_tx_size, tx_mode_to_biggest_tx_size[tx_mode]); 91 return MIN(max_tx_size, tx_mode_to_biggest_tx_size[tx_mode]);
90 } 92 }
91 93
92 static void set_segment_id(VP9_COMMON *cm, BLOCK_SIZE bsize, 94 static void set_segment_id(VP9_COMMON *cm, BLOCK_SIZE bsize,
93 int mi_row, int mi_col, int segment_id) { 95 int mi_row, int mi_col, int segment_id) {
94 const int mi_offset = mi_row * cm->mi_cols + mi_col; 96 const int mi_offset = mi_row * cm->mi_cols + mi_col;
95 const int bw = num_8x8_blocks_wide_lookup[bsize]; 97 const int bw = num_8x8_blocks_wide_lookup[bsize];
96 const int bh = num_8x8_blocks_high_lookup[bsize]; 98 const int bh = num_8x8_blocks_high_lookup[bsize];
97 const int xmis = MIN(cm->mi_cols - mi_col, bw); 99 const int xmis = MIN(cm->mi_cols - mi_col, bw);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 segment_id = mbmi->seg_id_predicted ? predicted_segment_id 169 segment_id = mbmi->seg_id_predicted ? predicted_segment_id
168 : read_segment_id(r, seg); 170 : read_segment_id(r, seg);
169 } else { 171 } else {
170 segment_id = read_segment_id(r, seg); 172 segment_id = read_segment_id(r, seg);
171 } 173 }
172 set_segment_id(cm, bsize, mi_row, mi_col, segment_id); 174 set_segment_id(cm, bsize, mi_row, mi_col, segment_id);
173 return segment_id; 175 return segment_id;
174 } 176 }
175 177
176 static int read_skip(VP9_COMMON *cm, const MACROBLOCKD *xd, 178 static int read_skip(VP9_COMMON *cm, const MACROBLOCKD *xd,
177 FRAME_COUNTS *counts,
178 int segment_id, vp9_reader *r) { 179 int segment_id, vp9_reader *r) {
179 if (vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)) { 180 if (vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)) {
180 return 1; 181 return 1;
181 } else { 182 } else {
182 const int ctx = vp9_get_skip_context(xd); 183 const int ctx = vp9_get_skip_context(xd);
183 const int skip = vp9_read(r, cm->fc->skip_probs[ctx]); 184 const int skip = vp9_read(r, cm->fc->skip_probs[ctx]);
184 if (!cm->frame_parallel_decoding_mode) 185 FRAME_COUNTS *counts = xd->counts;
186 if (counts)
185 ++counts->skip[ctx][skip]; 187 ++counts->skip[ctx][skip];
186 return skip; 188 return skip;
187 } 189 }
188 } 190 }
189 191
190 static void read_intra_frame_mode_info(VP9_COMMON *const cm, 192 static void read_intra_frame_mode_info(VP9_COMMON *const cm,
191 MACROBLOCKD *const xd, 193 MACROBLOCKD *const xd,
192 FRAME_COUNTS *counts,
193 int mi_row, int mi_col, vp9_reader *r) { 194 int mi_row, int mi_col, vp9_reader *r) {
194 MODE_INFO *const mi = xd->mi[0]; 195 MODE_INFO *const mi = xd->mi[0];
195 MB_MODE_INFO *const mbmi = &mi->mbmi; 196 MB_MODE_INFO *const mbmi = &mi->mbmi;
196 const MODE_INFO *above_mi = xd->above_mi; 197 const MODE_INFO *above_mi = xd->above_mi;
197 const MODE_INFO *left_mi = xd->left_mi; 198 const MODE_INFO *left_mi = xd->left_mi;
198 const BLOCK_SIZE bsize = mbmi->sb_type; 199 const BLOCK_SIZE bsize = mbmi->sb_type;
199 int i; 200 int i;
200 201
201 mbmi->segment_id = read_intra_segment_id(cm, bsize, mi_row, mi_col, r); 202 mbmi->segment_id = read_intra_segment_id(cm, bsize, mi_row, mi_col, r);
202 mbmi->skip = read_skip(cm, xd, counts, mbmi->segment_id, r); 203 mbmi->skip = read_skip(cm, xd, mbmi->segment_id, r);
203 mbmi->tx_size = read_tx_size(cm, xd, counts, 1, r); 204 mbmi->tx_size = read_tx_size(cm, xd, 1, r);
204 mbmi->ref_frame[0] = INTRA_FRAME; 205 mbmi->ref_frame[0] = INTRA_FRAME;
205 mbmi->ref_frame[1] = NONE; 206 mbmi->ref_frame[1] = NONE;
206 207
207 switch (bsize) { 208 switch (bsize) {
208 case BLOCK_4X4: 209 case BLOCK_4X4:
209 for (i = 0; i < 4; ++i) 210 for (i = 0; i < 4; ++i)
210 mi->bmi[i].as_mode = 211 mi->bmi[i].as_mode =
211 read_intra_mode(r, get_y_mode_probs(mi, above_mi, left_mi, i)); 212 read_intra_mode(r, get_y_mode_probs(mi, above_mi, left_mi, i));
212 mbmi->mode = mi->bmi[3].as_mode; 213 mbmi->mode = mi->bmi[3].as_mode;
213 break; 214 break;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 diff.col = read_mv_component(r, &ctx->comps[1], use_hp); 279 diff.col = read_mv_component(r, &ctx->comps[1], use_hp);
279 280
280 vp9_inc_mv(&diff, counts); 281 vp9_inc_mv(&diff, counts);
281 282
282 mv->row = ref->row + diff.row; 283 mv->row = ref->row + diff.row;
283 mv->col = ref->col + diff.col; 284 mv->col = ref->col + diff.col;
284 } 285 }
285 286
286 static REFERENCE_MODE read_block_reference_mode(VP9_COMMON *cm, 287 static REFERENCE_MODE read_block_reference_mode(VP9_COMMON *cm,
287 const MACROBLOCKD *xd, 288 const MACROBLOCKD *xd,
288 FRAME_COUNTS *counts,
289 vp9_reader *r) { 289 vp9_reader *r) {
290 if (cm->reference_mode == REFERENCE_MODE_SELECT) { 290 if (cm->reference_mode == REFERENCE_MODE_SELECT) {
291 const int ctx = vp9_get_reference_mode_context(cm, xd); 291 const int ctx = vp9_get_reference_mode_context(cm, xd);
292 const REFERENCE_MODE mode = 292 const REFERENCE_MODE mode =
293 (REFERENCE_MODE)vp9_read(r, cm->fc->comp_inter_prob[ctx]); 293 (REFERENCE_MODE)vp9_read(r, cm->fc->comp_inter_prob[ctx]);
294 if (!cm->frame_parallel_decoding_mode) 294 FRAME_COUNTS *counts = xd->counts;
295 if (counts)
295 ++counts->comp_inter[ctx][mode]; 296 ++counts->comp_inter[ctx][mode];
296 return mode; // SINGLE_REFERENCE or COMPOUND_REFERENCE 297 return mode; // SINGLE_REFERENCE or COMPOUND_REFERENCE
297 } else { 298 } else {
298 return cm->reference_mode; 299 return cm->reference_mode;
299 } 300 }
300 } 301 }
301 302
302 // Read the referncence frame 303 // Read the referncence frame
303 static void read_ref_frames(VP9_COMMON *const cm, MACROBLOCKD *const xd, 304 static void read_ref_frames(VP9_COMMON *const cm, MACROBLOCKD *const xd,
304 FRAME_COUNTS *counts, vp9_reader *r, 305 vp9_reader *r,
305 int segment_id, MV_REFERENCE_FRAME ref_frame[2]) { 306 int segment_id, MV_REFERENCE_FRAME ref_frame[2]) {
306 FRAME_CONTEXT *const fc = cm->fc; 307 FRAME_CONTEXT *const fc = cm->fc;
308 FRAME_COUNTS *counts = xd->counts;
307 309
308 if (vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) { 310 if (vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) {
309 ref_frame[0] = (MV_REFERENCE_FRAME)vp9_get_segdata(&cm->seg, segment_id, 311 ref_frame[0] = (MV_REFERENCE_FRAME)vp9_get_segdata(&cm->seg, segment_id,
310 SEG_LVL_REF_FRAME); 312 SEG_LVL_REF_FRAME);
311 ref_frame[1] = NONE; 313 ref_frame[1] = NONE;
312 } else { 314 } else {
313 const REFERENCE_MODE mode = read_block_reference_mode(cm, xd, counts, r); 315 const REFERENCE_MODE mode = read_block_reference_mode(cm, xd, r);
314 // FIXME(rbultje) I'm pretty sure this breaks segmentation ref frame coding 316 // FIXME(rbultje) I'm pretty sure this breaks segmentation ref frame coding
315 if (mode == COMPOUND_REFERENCE) { 317 if (mode == COMPOUND_REFERENCE) {
316 const int idx = cm->ref_frame_sign_bias[cm->comp_fixed_ref]; 318 const int idx = cm->ref_frame_sign_bias[cm->comp_fixed_ref];
317 const int ctx = vp9_get_pred_context_comp_ref_p(cm, xd); 319 const int ctx = vp9_get_pred_context_comp_ref_p(cm, xd);
318 const int bit = vp9_read(r, fc->comp_ref_prob[ctx]); 320 const int bit = vp9_read(r, fc->comp_ref_prob[ctx]);
319 if (!cm->frame_parallel_decoding_mode) 321 if (counts)
320 ++counts->comp_ref[ctx][bit]; 322 ++counts->comp_ref[ctx][bit];
321 ref_frame[idx] = cm->comp_fixed_ref; 323 ref_frame[idx] = cm->comp_fixed_ref;
322 ref_frame[!idx] = cm->comp_var_ref[bit]; 324 ref_frame[!idx] = cm->comp_var_ref[bit];
323 } else if (mode == SINGLE_REFERENCE) { 325 } else if (mode == SINGLE_REFERENCE) {
324 const int ctx0 = vp9_get_pred_context_single_ref_p1(xd); 326 const int ctx0 = vp9_get_pred_context_single_ref_p1(xd);
325 const int bit0 = vp9_read(r, fc->single_ref_prob[ctx0][0]); 327 const int bit0 = vp9_read(r, fc->single_ref_prob[ctx0][0]);
326 if (!cm->frame_parallel_decoding_mode) 328 if (counts)
327 ++counts->single_ref[ctx0][0][bit0]; 329 ++counts->single_ref[ctx0][0][bit0];
328 if (bit0) { 330 if (bit0) {
329 const int ctx1 = vp9_get_pred_context_single_ref_p2(xd); 331 const int ctx1 = vp9_get_pred_context_single_ref_p2(xd);
330 const int bit1 = vp9_read(r, fc->single_ref_prob[ctx1][1]); 332 const int bit1 = vp9_read(r, fc->single_ref_prob[ctx1][1]);
331 if (!cm->frame_parallel_decoding_mode) 333 if (counts)
332 ++counts->single_ref[ctx1][1][bit1]; 334 ++counts->single_ref[ctx1][1][bit1];
333 ref_frame[0] = bit1 ? ALTREF_FRAME : GOLDEN_FRAME; 335 ref_frame[0] = bit1 ? ALTREF_FRAME : GOLDEN_FRAME;
334 } else { 336 } else {
335 ref_frame[0] = LAST_FRAME; 337 ref_frame[0] = LAST_FRAME;
336 } 338 }
337 339
338 ref_frame[1] = NONE; 340 ref_frame[1] = NONE;
339 } else { 341 } else {
340 assert(0 && "Invalid prediction mode."); 342 assert(0 && "Invalid prediction mode.");
341 } 343 }
342 } 344 }
343 } 345 }
344 346
345 347
346 static INLINE INTERP_FILTER read_switchable_interp_filter( 348 static INLINE INTERP_FILTER read_switchable_interp_filter(
347 VP9_COMMON *const cm, MACROBLOCKD *const xd, 349 VP9_COMMON *const cm, MACROBLOCKD *const xd,
348 FRAME_COUNTS *counts, vp9_reader *r) { 350 vp9_reader *r) {
349 const int ctx = vp9_get_pred_context_switchable_interp(xd); 351 const int ctx = vp9_get_pred_context_switchable_interp(xd);
350 const INTERP_FILTER type = 352 const INTERP_FILTER type =
351 (INTERP_FILTER)vp9_read_tree(r, vp9_switchable_interp_tree, 353 (INTERP_FILTER)vp9_read_tree(r, vp9_switchable_interp_tree,
352 cm->fc->switchable_interp_prob[ctx]); 354 cm->fc->switchable_interp_prob[ctx]);
353 if (!cm->frame_parallel_decoding_mode) 355 FRAME_COUNTS *counts = xd->counts;
356 if (counts)
354 ++counts->switchable_interp[ctx][type]; 357 ++counts->switchable_interp[ctx][type];
355 return type; 358 return type;
356 } 359 }
357 360
358 static void read_intra_block_mode_info(VP9_COMMON *const cm, 361 static void read_intra_block_mode_info(VP9_COMMON *const cm,
359 FRAME_COUNTS *counts, MODE_INFO *mi, 362 MACROBLOCKD *const xd, MODE_INFO *mi,
360 vp9_reader *r) { 363 vp9_reader *r) {
361 MB_MODE_INFO *const mbmi = &mi->mbmi; 364 MB_MODE_INFO *const mbmi = &mi->mbmi;
362 const BLOCK_SIZE bsize = mi->mbmi.sb_type; 365 const BLOCK_SIZE bsize = mi->mbmi.sb_type;
363 int i; 366 int i;
364 367
365 mbmi->ref_frame[0] = INTRA_FRAME; 368 mbmi->ref_frame[0] = INTRA_FRAME;
366 mbmi->ref_frame[1] = NONE; 369 mbmi->ref_frame[1] = NONE;
367 370
368 switch (bsize) { 371 switch (bsize) {
369 case BLOCK_4X4: 372 case BLOCK_4X4:
370 for (i = 0; i < 4; ++i) 373 for (i = 0; i < 4; ++i)
371 mi->bmi[i].as_mode = read_intra_mode_y(cm, counts, r, 0); 374 mi->bmi[i].as_mode = read_intra_mode_y(cm, xd, r, 0);
372 mbmi->mode = mi->bmi[3].as_mode; 375 mbmi->mode = mi->bmi[3].as_mode;
373 break; 376 break;
374 case BLOCK_4X8: 377 case BLOCK_4X8:
375 mi->bmi[0].as_mode = mi->bmi[2].as_mode = read_intra_mode_y(cm, counts, 378 mi->bmi[0].as_mode = mi->bmi[2].as_mode = read_intra_mode_y(cm, xd,
376 r, 0); 379 r, 0);
377 mi->bmi[1].as_mode = mi->bmi[3].as_mode = mbmi->mode = 380 mi->bmi[1].as_mode = mi->bmi[3].as_mode = mbmi->mode =
378 read_intra_mode_y(cm, counts, r, 0); 381 read_intra_mode_y(cm, xd, r, 0);
379 break; 382 break;
380 case BLOCK_8X4: 383 case BLOCK_8X4:
381 mi->bmi[0].as_mode = mi->bmi[1].as_mode = read_intra_mode_y(cm, counts, 384 mi->bmi[0].as_mode = mi->bmi[1].as_mode = read_intra_mode_y(cm, xd,
382 r, 0); 385 r, 0);
383 mi->bmi[2].as_mode = mi->bmi[3].as_mode = mbmi->mode = 386 mi->bmi[2].as_mode = mi->bmi[3].as_mode = mbmi->mode =
384 read_intra_mode_y(cm, counts, r, 0); 387 read_intra_mode_y(cm, xd, r, 0);
385 break; 388 break;
386 default: 389 default:
387 mbmi->mode = read_intra_mode_y(cm, counts, r, size_group_lookup[bsize]); 390 mbmi->mode = read_intra_mode_y(cm, xd, r, size_group_lookup[bsize]);
388 } 391 }
389 392
390 mbmi->uv_mode = read_intra_mode_uv(cm, counts, r, mbmi->mode); 393 mbmi->uv_mode = read_intra_mode_uv(cm, xd, r, mbmi->mode);
391 } 394 }
392 395
393 static INLINE int is_mv_valid(const MV *mv) { 396 static INLINE int is_mv_valid(const MV *mv) {
394 return mv->row > MV_LOW && mv->row < MV_UPP && 397 return mv->row > MV_LOW && mv->row < MV_UPP &&
395 mv->col > MV_LOW && mv->col < MV_UPP; 398 mv->col > MV_LOW && mv->col < MV_UPP;
396 } 399 }
397 400
398 static INLINE int assign_mv(VP9_COMMON *cm, FRAME_COUNTS *counts, 401 static INLINE int assign_mv(VP9_COMMON *cm, MACROBLOCKD *xd,
399 PREDICTION_MODE mode, 402 PREDICTION_MODE mode,
400 int_mv mv[2], int_mv ref_mv[2], 403 int_mv mv[2], int_mv ref_mv[2],
401 int_mv nearest_mv[2], int_mv near_mv[2], 404 int_mv nearest_mv[2], int_mv near_mv[2],
402 int is_compound, int allow_hp, vp9_reader *r) { 405 int is_compound, int allow_hp, vp9_reader *r) {
403 int i; 406 int i;
404 int ret = 1; 407 int ret = 1;
405 408
406 switch (mode) { 409 switch (mode) {
407 case NEWMV: { 410 case NEWMV: {
408 nmv_context_counts *const mv_counts = cm->frame_parallel_decoding_mode ? 411 FRAME_COUNTS *counts = xd->counts;
409 NULL : &counts->mv; 412 nmv_context_counts *const mv_counts = counts ? &counts->mv : NULL;
410 for (i = 0; i < 1 + is_compound; ++i) { 413 for (i = 0; i < 1 + is_compound; ++i) {
411 read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, &cm->fc->nmvc, mv_counts, 414 read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, &cm->fc->nmvc, mv_counts,
412 allow_hp); 415 allow_hp);
413 ret = ret && is_mv_valid(&mv[i].as_mv); 416 ret = ret && is_mv_valid(&mv[i].as_mv);
414 } 417 }
415 break; 418 break;
416 } 419 }
417 case NEARESTMV: { 420 case NEARESTMV: {
418 mv[0].as_int = nearest_mv[0].as_int; 421 mv[0].as_int = nearest_mv[0].as_int;
419 if (is_compound) 422 if (is_compound)
(...skipping 13 matching lines...) Expand all
433 break; 436 break;
434 } 437 }
435 default: { 438 default: {
436 return 0; 439 return 0;
437 } 440 }
438 } 441 }
439 return ret; 442 return ret;
440 } 443 }
441 444
442 static int read_is_inter_block(VP9_COMMON *const cm, MACROBLOCKD *const xd, 445 static int read_is_inter_block(VP9_COMMON *const cm, MACROBLOCKD *const xd,
443 FRAME_COUNTS *counts,
444 int segment_id, vp9_reader *r) { 446 int segment_id, vp9_reader *r) {
445 if (vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) { 447 if (vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) {
446 return vp9_get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME) != 448 return vp9_get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME) !=
447 INTRA_FRAME; 449 INTRA_FRAME;
448 } else { 450 } else {
449 const int ctx = vp9_get_intra_inter_context(xd); 451 const int ctx = vp9_get_intra_inter_context(xd);
450 const int is_inter = vp9_read(r, cm->fc->intra_inter_prob[ctx]); 452 const int is_inter = vp9_read(r, cm->fc->intra_inter_prob[ctx]);
451 if (!cm->frame_parallel_decoding_mode) 453 FRAME_COUNTS *counts = xd->counts;
454 if (counts)
452 ++counts->intra_inter[ctx][is_inter]; 455 ++counts->intra_inter[ctx][is_inter];
453 return is_inter; 456 return is_inter;
454 } 457 }
455 } 458 }
456 459
457 static void fpm_sync(void *const data, int mi_row) { 460 static void fpm_sync(void *const data, int mi_row) {
458 VP9Decoder *const pbi = (VP9Decoder *)data; 461 VP9Decoder *const pbi = (VP9Decoder *)data;
459 vp9_frameworker_wait(pbi->frame_worker_owner, pbi->common.prev_frame, 462 vp9_frameworker_wait(pbi->frame_worker_owner, pbi->common.prev_frame,
460 mi_row << MI_BLOCK_SIZE_LOG2); 463 mi_row << MI_BLOCK_SIZE_LOG2);
461 } 464 }
462 465
463 static void read_inter_block_mode_info(VP9Decoder *const pbi, 466 static void read_inter_block_mode_info(VP9Decoder *const pbi,
464 MACROBLOCKD *const xd, 467 MACROBLOCKD *const xd,
465 FRAME_COUNTS *counts,
466 const TileInfo *const tile, 468 const TileInfo *const tile,
467 MODE_INFO *const mi, 469 MODE_INFO *const mi,
468 int mi_row, int mi_col, vp9_reader *r) { 470 int mi_row, int mi_col, vp9_reader *r) {
469 VP9_COMMON *const cm = &pbi->common; 471 VP9_COMMON *const cm = &pbi->common;
470 MB_MODE_INFO *const mbmi = &mi->mbmi; 472 MB_MODE_INFO *const mbmi = &mi->mbmi;
471 const BLOCK_SIZE bsize = mbmi->sb_type; 473 const BLOCK_SIZE bsize = mbmi->sb_type;
472 const int allow_hp = cm->allow_high_precision_mv; 474 const int allow_hp = cm->allow_high_precision_mv;
473 int_mv nearestmv[2], nearmv[2]; 475 int_mv nearestmv[2], nearmv[2];
474 int inter_mode_ctx, ref, is_compound; 476 int inter_mode_ctx, ref, is_compound;
475 477
476 read_ref_frames(cm, xd, counts, r, mbmi->segment_id, mbmi->ref_frame); 478 read_ref_frames(cm, xd, r, mbmi->segment_id, mbmi->ref_frame);
477 is_compound = has_second_ref(mbmi); 479 is_compound = has_second_ref(mbmi);
478 480
479 for (ref = 0; ref < 1 + is_compound; ++ref) { 481 for (ref = 0; ref < 1 + is_compound; ++ref) {
480 const MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref]; 482 const MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref];
481 RefBuffer *ref_buf = &cm->frame_refs[frame - LAST_FRAME]; 483 RefBuffer *ref_buf = &cm->frame_refs[frame - LAST_FRAME];
482 xd->block_refs[ref] = ref_buf; 484 xd->block_refs[ref] = ref_buf;
483 if ((!vp9_is_valid_scale(&ref_buf->sf))) 485 if ((!vp9_is_valid_scale(&ref_buf->sf)))
484 vpx_internal_error(xd->error_info, VPX_CODEC_UNSUP_BITSTREAM, 486 vpx_internal_error(xd->error_info, VPX_CODEC_UNSUP_BITSTREAM,
485 "Reference frame has invalid dimensions"); 487 "Reference frame has invalid dimensions");
486 vp9_setup_pre_planes(xd, ref, ref_buf->buf, mi_row, mi_col, 488 vp9_setup_pre_planes(xd, ref, ref_buf->buf, mi_row, mi_col,
487 &ref_buf->sf); 489 &ref_buf->sf);
488 vp9_find_mv_refs(cm, xd, tile, mi, frame, mbmi->ref_mvs[frame], 490 vp9_find_mv_refs(cm, xd, tile, mi, frame, mbmi->ref_mvs[frame],
489 mi_row, mi_col, fpm_sync, (void *)pbi); 491 mi_row, mi_col, fpm_sync, (void *)pbi);
490 } 492 }
491 493
492 inter_mode_ctx = mbmi->mode_context[mbmi->ref_frame[0]]; 494 inter_mode_ctx = mbmi->mode_context[mbmi->ref_frame[0]];
493 495
494 if (vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { 496 if (vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) {
495 mbmi->mode = ZEROMV; 497 mbmi->mode = ZEROMV;
496 if (bsize < BLOCK_8X8) { 498 if (bsize < BLOCK_8X8) {
497 vpx_internal_error(xd->error_info, VPX_CODEC_UNSUP_BITSTREAM, 499 vpx_internal_error(xd->error_info, VPX_CODEC_UNSUP_BITSTREAM,
498 "Invalid usage of segement feature on small blocks"); 500 "Invalid usage of segement feature on small blocks");
499 return; 501 return;
500 } 502 }
501 } else { 503 } else {
502 if (bsize >= BLOCK_8X8) 504 if (bsize >= BLOCK_8X8)
503 mbmi->mode = read_inter_mode(cm, counts, r, inter_mode_ctx); 505 mbmi->mode = read_inter_mode(cm, xd, r, inter_mode_ctx);
504 } 506 }
505 507
506 if (bsize < BLOCK_8X8 || mbmi->mode != ZEROMV) { 508 if (bsize < BLOCK_8X8 || mbmi->mode != ZEROMV) {
507 for (ref = 0; ref < 1 + is_compound; ++ref) { 509 for (ref = 0; ref < 1 + is_compound; ++ref) {
508 vp9_find_best_ref_mvs(xd, allow_hp, mbmi->ref_mvs[mbmi->ref_frame[ref]], 510 vp9_find_best_ref_mvs(xd, allow_hp, mbmi->ref_mvs[mbmi->ref_frame[ref]],
509 &nearestmv[ref], &nearmv[ref]); 511 &nearestmv[ref], &nearmv[ref]);
510 } 512 }
511 } 513 }
512 514
513 mbmi->interp_filter = (cm->interp_filter == SWITCHABLE) 515 mbmi->interp_filter = (cm->interp_filter == SWITCHABLE)
514 ? read_switchable_interp_filter(cm, xd, counts, r) 516 ? read_switchable_interp_filter(cm, xd, r)
515 : cm->interp_filter; 517 : cm->interp_filter;
516 518
517 if (bsize < BLOCK_8X8) { 519 if (bsize < BLOCK_8X8) {
518 const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize]; // 1 or 2 520 const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize]; // 1 or 2
519 const int num_4x4_h = num_4x4_blocks_high_lookup[bsize]; // 1 or 2 521 const int num_4x4_h = num_4x4_blocks_high_lookup[bsize]; // 1 or 2
520 int idx, idy; 522 int idx, idy;
521 PREDICTION_MODE b_mode; 523 PREDICTION_MODE b_mode;
522 int_mv nearest_sub8x8[2], near_sub8x8[2]; 524 int_mv nearest_sub8x8[2], near_sub8x8[2];
523 for (idy = 0; idy < 2; idy += num_4x4_h) { 525 for (idy = 0; idy < 2; idy += num_4x4_h) {
524 for (idx = 0; idx < 2; idx += num_4x4_w) { 526 for (idx = 0; idx < 2; idx += num_4x4_w) {
525 int_mv block[2]; 527 int_mv block[2];
526 const int j = idy * 2 + idx; 528 const int j = idy * 2 + idx;
527 b_mode = read_inter_mode(cm, counts, r, inter_mode_ctx); 529 b_mode = read_inter_mode(cm, xd, r, inter_mode_ctx);
528 530
529 if (b_mode == NEARESTMV || b_mode == NEARMV) 531 if (b_mode == NEARESTMV || b_mode == NEARMV)
530 for (ref = 0; ref < 1 + is_compound; ++ref) 532 for (ref = 0; ref < 1 + is_compound; ++ref)
531 vp9_append_sub8x8_mvs_for_idx(cm, xd, tile, j, ref, mi_row, mi_col, 533 vp9_append_sub8x8_mvs_for_idx(cm, xd, tile, j, ref, mi_row, mi_col,
532 &nearest_sub8x8[ref], 534 &nearest_sub8x8[ref],
533 &near_sub8x8[ref]); 535 &near_sub8x8[ref]);
534 536
535 if (!assign_mv(cm, counts, b_mode, block, nearestmv, 537 if (!assign_mv(cm, xd, b_mode, block, nearestmv,
536 nearest_sub8x8, near_sub8x8, 538 nearest_sub8x8, near_sub8x8,
537 is_compound, allow_hp, r)) { 539 is_compound, allow_hp, r)) {
538 xd->corrupted |= 1; 540 xd->corrupted |= 1;
539 break; 541 break;
540 }; 542 };
541 543
542 mi->bmi[j].as_mv[0].as_int = block[0].as_int; 544 mi->bmi[j].as_mv[0].as_int = block[0].as_int;
543 if (is_compound) 545 if (is_compound)
544 mi->bmi[j].as_mv[1].as_int = block[1].as_int; 546 mi->bmi[j].as_mv[1].as_int = block[1].as_int;
545 547
546 if (num_4x4_h == 2) 548 if (num_4x4_h == 2)
547 mi->bmi[j + 2] = mi->bmi[j]; 549 mi->bmi[j + 2] = mi->bmi[j];
548 if (num_4x4_w == 2) 550 if (num_4x4_w == 2)
549 mi->bmi[j + 1] = mi->bmi[j]; 551 mi->bmi[j + 1] = mi->bmi[j];
550 } 552 }
551 } 553 }
552 554
553 mi->mbmi.mode = b_mode; 555 mi->mbmi.mode = b_mode;
554 556
555 mbmi->mv[0].as_int = mi->bmi[3].as_mv[0].as_int; 557 mbmi->mv[0].as_int = mi->bmi[3].as_mv[0].as_int;
556 mbmi->mv[1].as_int = mi->bmi[3].as_mv[1].as_int; 558 mbmi->mv[1].as_int = mi->bmi[3].as_mv[1].as_int;
557 } else { 559 } else {
558 xd->corrupted |= !assign_mv(cm, counts, mbmi->mode, mbmi->mv, nearestmv, 560 xd->corrupted |= !assign_mv(cm, xd, mbmi->mode, mbmi->mv, nearestmv,
559 nearestmv, nearmv, is_compound, allow_hp, r); 561 nearestmv, nearmv, is_compound, allow_hp, r);
560 } 562 }
561 } 563 }
562 564
563 static void read_inter_frame_mode_info(VP9Decoder *const pbi, 565 static void read_inter_frame_mode_info(VP9Decoder *const pbi,
564 MACROBLOCKD *const xd, 566 MACROBLOCKD *const xd,
565 FRAME_COUNTS *counts,
566 const TileInfo *const tile, 567 const TileInfo *const tile,
567 int mi_row, int mi_col, vp9_reader *r) { 568 int mi_row, int mi_col, vp9_reader *r) {
568 VP9_COMMON *const cm = &pbi->common; 569 VP9_COMMON *const cm = &pbi->common;
569 MODE_INFO *const mi = xd->mi[0]; 570 MODE_INFO *const mi = xd->mi[0];
570 MB_MODE_INFO *const mbmi = &mi->mbmi; 571 MB_MODE_INFO *const mbmi = &mi->mbmi;
571 int inter_block; 572 int inter_block;
572 573
573 mbmi->mv[0].as_int = 0; 574 mbmi->mv[0].as_int = 0;
574 mbmi->mv[1].as_int = 0; 575 mbmi->mv[1].as_int = 0;
575 mbmi->segment_id = read_inter_segment_id(cm, xd, mi_row, mi_col, r); 576 mbmi->segment_id = read_inter_segment_id(cm, xd, mi_row, mi_col, r);
576 mbmi->skip = read_skip(cm, xd, counts, mbmi->segment_id, r); 577 mbmi->skip = read_skip(cm, xd, mbmi->segment_id, r);
577 inter_block = read_is_inter_block(cm, xd, counts, mbmi->segment_id, r); 578 inter_block = read_is_inter_block(cm, xd, mbmi->segment_id, r);
578 mbmi->tx_size = read_tx_size(cm, xd, counts, !mbmi->skip || !inter_block, r); 579 mbmi->tx_size = read_tx_size(cm, xd, !mbmi->skip || !inter_block, r);
579 580
580 if (inter_block) 581 if (inter_block)
581 read_inter_block_mode_info(pbi, xd, counts, tile, mi, mi_row, mi_col, r); 582 read_inter_block_mode_info(pbi, xd, tile, mi, mi_row, mi_col, r);
582 else 583 else
583 read_intra_block_mode_info(cm, counts, mi, r); 584 read_intra_block_mode_info(cm, xd, mi, r);
584 } 585 }
585 586
586 void vp9_read_mode_info(VP9Decoder *const pbi, MACROBLOCKD *xd, 587 void vp9_read_mode_info(VP9Decoder *const pbi, MACROBLOCKD *xd,
587 FRAME_COUNTS *counts,
588 const TileInfo *const tile, 588 const TileInfo *const tile,
589 int mi_row, int mi_col, vp9_reader *r) { 589 int mi_row, int mi_col, vp9_reader *r) {
590 VP9_COMMON *const cm = &pbi->common; 590 VP9_COMMON *const cm = &pbi->common;
591 MODE_INFO *const mi = xd->mi[0]; 591 MODE_INFO *const mi = xd->mi[0];
592 const int bw = num_8x8_blocks_wide_lookup[mi->mbmi.sb_type]; 592 const int bw = num_8x8_blocks_wide_lookup[mi->mbmi.sb_type];
593 const int bh = num_8x8_blocks_high_lookup[mi->mbmi.sb_type]; 593 const int bh = num_8x8_blocks_high_lookup[mi->mbmi.sb_type];
594 const int x_mis = MIN(bw, cm->mi_cols - mi_col); 594 const int x_mis = MIN(bw, cm->mi_cols - mi_col);
595 const int y_mis = MIN(bh, cm->mi_rows - mi_row); 595 const int y_mis = MIN(bh, cm->mi_rows - mi_row);
596 MV_REF* frame_mvs = cm->cur_frame->mvs + mi_row * cm->mi_cols + mi_col; 596 MV_REF* frame_mvs = cm->cur_frame->mvs + mi_row * cm->mi_cols + mi_col;
597 int w, h; 597 int w, h;
598 598
599 if (frame_is_intra_only(cm)) 599 if (frame_is_intra_only(cm))
600 read_intra_frame_mode_info(cm, xd, counts, mi_row, mi_col, r); 600 read_intra_frame_mode_info(cm, xd, mi_row, mi_col, r);
601 else 601 else
602 read_inter_frame_mode_info(pbi, xd, counts, tile, mi_row, mi_col, r); 602 read_inter_frame_mode_info(pbi, xd, tile, mi_row, mi_col, r);
603 603
604 for (h = 0; h < y_mis; ++h) { 604 for (h = 0; h < y_mis; ++h) {
605 MV_REF *const frame_mv = frame_mvs + h * cm->mi_cols; 605 MV_REF *const frame_mv = frame_mvs + h * cm->mi_cols;
606 for (w = 0; w < x_mis; ++w) { 606 for (w = 0; w < x_mis; ++w) {
607 MV_REF *const mv = frame_mv + w; 607 MV_REF *const mv = frame_mv + w;
608 mv->ref_frame[0] = mi->mbmi.ref_frame[0]; 608 mv->ref_frame[0] = mi->mbmi.ref_frame[0];
609 mv->ref_frame[1] = mi->mbmi.ref_frame[1]; 609 mv->ref_frame[1] = mi->mbmi.ref_frame[1];
610 mv->mv[0].as_int = mi->mbmi.mv[0].as_int; 610 mv->mv[0].as_int = mi->mbmi.mv[0].as_int;
611 mv->mv[1].as_int = mi->mbmi.mv[1].as_int; 611 mv->mv[1].as_int = mi->mbmi.mv[1].as_int;
612 } 612 }
613 } 613 }
614 } 614 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/decoder/vp9_decodemv.h ('k') | source/libvpx/vp9/decoder/vp9_detokenize.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698