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

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

Issue 958693004: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: Created 5 years, 9 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_decodeframe.h ('k') | source/libvpx/vp9/decoder/vp9_decodemv.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 #include <stdlib.h> // qsort() 12 #include <stdlib.h> // qsort()
13 13
14 #include "./vp9_rtcd.h" 14 #include "./vp9_rtcd.h"
15 #include "./vpx_scale_rtcd.h" 15 #include "./vpx_scale_rtcd.h"
16 16
17 #include "vpx_mem/vpx_mem.h" 17 #include "vpx_mem/vpx_mem.h"
18 #include "vpx_ports/mem_ops.h" 18 #include "vpx_ports/mem_ops.h"
19 #include "vpx_scale/vpx_scale.h" 19 #include "vpx_scale/vpx_scale.h"
20 20
21 #include "vp9/common/vp9_alloccommon.h" 21 #include "vp9/common/vp9_alloccommon.h"
22 #include "vp9/common/vp9_common.h" 22 #include "vp9/common/vp9_common.h"
23 #include "vp9/common/vp9_entropy.h" 23 #include "vp9/common/vp9_entropy.h"
24 #include "vp9/common/vp9_entropymode.h" 24 #include "vp9/common/vp9_entropymode.h"
25 #include "vp9/common/vp9_idct.h" 25 #include "vp9/common/vp9_idct.h"
26 #include "vp9/common/vp9_thread_common.h"
26 #include "vp9/common/vp9_pred_common.h" 27 #include "vp9/common/vp9_pred_common.h"
27 #include "vp9/common/vp9_quant_common.h" 28 #include "vp9/common/vp9_quant_common.h"
28 #include "vp9/common/vp9_reconintra.h" 29 #include "vp9/common/vp9_reconintra.h"
29 #include "vp9/common/vp9_reconinter.h" 30 #include "vp9/common/vp9_reconinter.h"
30 #include "vp9/common/vp9_seg_common.h" 31 #include "vp9/common/vp9_seg_common.h"
31 #include "vp9/common/vp9_thread.h" 32 #include "vp9/common/vp9_thread.h"
32 #include "vp9/common/vp9_tile_common.h" 33 #include "vp9/common/vp9_tile_common.h"
33 34
34 #include "vp9/decoder/vp9_decodeframe.h" 35 #include "vp9/decoder/vp9_decodeframe.h"
35 #include "vp9/decoder/vp9_detokenize.h" 36 #include "vp9/decoder/vp9_detokenize.h"
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 174
174 if (allow_hp) { 175 if (allow_hp) {
175 for (i = 0; i < 2; ++i) { 176 for (i = 0; i < 2; ++i) {
176 nmv_component *const comp_ctx = &ctx->comps[i]; 177 nmv_component *const comp_ctx = &ctx->comps[i];
177 update_mv_probs(&comp_ctx->class0_hp, 1, r); 178 update_mv_probs(&comp_ctx->class0_hp, 1, r);
178 update_mv_probs(&comp_ctx->hp, 1, r); 179 update_mv_probs(&comp_ctx->hp, 1, r);
179 } 180 }
180 } 181 }
181 } 182 }
182 183
183 static void setup_plane_dequants(VP9_COMMON *cm, MACROBLOCKD *xd, int q_index) {
184 int i;
185 xd->plane[0].dequant = cm->y_dequant[q_index];
186
187 for (i = 1; i < MAX_MB_PLANE; i++)
188 xd->plane[i].dequant = cm->uv_dequant[q_index];
189 }
190
191 static void inverse_transform_block(MACROBLOCKD* xd, int plane, int block, 184 static void inverse_transform_block(MACROBLOCKD* xd, int plane, int block,
192 TX_SIZE tx_size, uint8_t *dst, int stride, 185 TX_SIZE tx_size, uint8_t *dst, int stride,
193 int eob) { 186 int eob) {
194 struct macroblockd_plane *const pd = &xd->plane[plane]; 187 struct macroblockd_plane *const pd = &xd->plane[plane];
195 if (eob > 0) { 188 if (eob > 0) {
196 TX_TYPE tx_type = DCT_DCT; 189 TX_TYPE tx_type = DCT_DCT;
197 tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); 190 tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
198 #if CONFIG_VP9_HIGHBITDEPTH 191 #if CONFIG_VP9_HIGHBITDEPTH
199 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { 192 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
200 if (xd->lossless) { 193 if (xd->lossless) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 vpx_memset(dqcoeff, 0, 256 * sizeof(dqcoeff[0])); 284 vpx_memset(dqcoeff, 0, 256 * sizeof(dqcoeff[0]));
292 else 285 else
293 vpx_memset(dqcoeff, 0, (16 << (tx_size << 1)) * sizeof(dqcoeff[0])); 286 vpx_memset(dqcoeff, 0, (16 << (tx_size << 1)) * sizeof(dqcoeff[0]));
294 } 287 }
295 } 288 }
296 } 289 }
297 290
298 struct intra_args { 291 struct intra_args {
299 VP9_COMMON *cm; 292 VP9_COMMON *cm;
300 MACROBLOCKD *xd; 293 MACROBLOCKD *xd;
294 FRAME_COUNTS *counts;
301 vp9_reader *r; 295 vp9_reader *r;
296 const int16_t *const y_dequant;
297 const int16_t *const uv_dequant;
302 }; 298 };
303 299
304 static void predict_and_reconstruct_intra_block(int plane, int block, 300 static void predict_and_reconstruct_intra_block(int plane, int block,
305 BLOCK_SIZE plane_bsize, 301 BLOCK_SIZE plane_bsize,
306 TX_SIZE tx_size, void *arg) { 302 TX_SIZE tx_size, void *arg) {
307 struct intra_args *const args = (struct intra_args *)arg; 303 struct intra_args *const args = (struct intra_args *)arg;
308 VP9_COMMON *const cm = args->cm; 304 VP9_COMMON *const cm = args->cm;
309 MACROBLOCKD *const xd = args->xd; 305 MACROBLOCKD *const xd = args->xd;
310 struct macroblockd_plane *const pd = &xd->plane[plane]; 306 struct macroblockd_plane *const pd = &xd->plane[plane];
311 MODE_INFO *const mi = xd->mi[0].src_mi; 307 MODE_INFO *const mi = xd->mi[0].src_mi;
312 const PREDICTION_MODE mode = (plane == 0) ? get_y_mode(mi, block) 308 const PREDICTION_MODE mode = (plane == 0) ? get_y_mode(mi, block)
313 : mi->mbmi.uv_mode; 309 : mi->mbmi.uv_mode;
310 const int16_t *const dequant = (plane == 0) ? args->y_dequant
311 : args->uv_dequant;
314 int x, y; 312 int x, y;
315 uint8_t *dst; 313 uint8_t *dst;
316 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x, &y); 314 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x, &y);
317 dst = &pd->dst.buf[4 * y * pd->dst.stride + 4 * x]; 315 dst = &pd->dst.buf[4 * y * pd->dst.stride + 4 * x];
318 316
319 vp9_predict_intra_block(xd, block >> (tx_size << 1), 317 vp9_predict_intra_block(xd, block >> (tx_size << 1),
320 b_width_log2_lookup[plane_bsize], tx_size, mode, 318 b_width_log2_lookup[plane_bsize], tx_size, mode,
321 dst, pd->dst.stride, dst, pd->dst.stride, 319 dst, pd->dst.stride, dst, pd->dst.stride,
322 x, y, plane); 320 x, y, plane);
323 321
324 if (!mi->mbmi.skip) { 322 if (!mi->mbmi.skip) {
325 const int eob = vp9_decode_block_tokens(cm, xd, plane, block, 323 const int eob = vp9_decode_block_tokens(cm, xd, args->counts, plane, block,
326 plane_bsize, x, y, tx_size, 324 plane_bsize, x, y, tx_size,
327 args->r); 325 args->r, dequant);
328 inverse_transform_block(xd, plane, block, tx_size, dst, pd->dst.stride, 326 inverse_transform_block(xd, plane, block, tx_size, dst, pd->dst.stride,
329 eob); 327 eob);
330 } 328 }
331 } 329 }
332 330
333 struct inter_args { 331 struct inter_args {
334 VP9_COMMON *cm; 332 VP9_COMMON *cm;
335 MACROBLOCKD *xd; 333 MACROBLOCKD *xd;
336 vp9_reader *r; 334 vp9_reader *r;
335 FRAME_COUNTS *counts;
337 int *eobtotal; 336 int *eobtotal;
337 const int16_t *const y_dequant;
338 const int16_t *const uv_dequant;
338 }; 339 };
339 340
340 static void reconstruct_inter_block(int plane, int block, 341 static void reconstruct_inter_block(int plane, int block,
341 BLOCK_SIZE plane_bsize, 342 BLOCK_SIZE plane_bsize,
342 TX_SIZE tx_size, void *arg) { 343 TX_SIZE tx_size, void *arg) {
343 struct inter_args *args = (struct inter_args *)arg; 344 struct inter_args *args = (struct inter_args *)arg;
344 VP9_COMMON *const cm = args->cm; 345 VP9_COMMON *const cm = args->cm;
345 MACROBLOCKD *const xd = args->xd; 346 MACROBLOCKD *const xd = args->xd;
346 struct macroblockd_plane *const pd = &xd->plane[plane]; 347 struct macroblockd_plane *const pd = &xd->plane[plane];
348 const int16_t *const dequant = (plane == 0) ? args->y_dequant
349 : args->uv_dequant;
347 int x, y, eob; 350 int x, y, eob;
348 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x, &y); 351 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x, &y);
349 eob = vp9_decode_block_tokens(cm, xd, plane, block, plane_bsize, x, y, 352 eob = vp9_decode_block_tokens(cm, xd, args->counts, plane, block, plane_bsize,
350 tx_size, args->r); 353 x, y, tx_size, args->r, dequant);
351 inverse_transform_block(xd, plane, block, tx_size, 354 inverse_transform_block(xd, plane, block, tx_size,
352 &pd->dst.buf[4 * y * pd->dst.stride + 4 * x], 355 &pd->dst.buf[4 * y * pd->dst.stride + 4 * x],
353 pd->dst.stride, eob); 356 pd->dst.stride, eob);
354 *args->eobtotal += eob; 357 *args->eobtotal += eob;
355 } 358 }
356 359
357 static MB_MODE_INFO *set_offsets(VP9_COMMON *const cm, MACROBLOCKD *const xd, 360 static MB_MODE_INFO *set_offsets(VP9_COMMON *const cm, MACROBLOCKD *const xd,
358 const TileInfo *const tile, 361 const TileInfo *const tile,
359 BLOCK_SIZE bsize, int mi_row, int mi_col) { 362 BLOCK_SIZE bsize, int mi_row, int mi_col) {
360 const int bw = num_8x8_blocks_wide_lookup[bsize]; 363 const int bw = num_8x8_blocks_wide_lookup[bsize];
(...skipping 15 matching lines...) Expand all
376 set_skip_context(xd, mi_row, mi_col); 379 set_skip_context(xd, mi_row, mi_col);
377 380
378 // Distance of Mb to the various image edges. These are specified to 8th pel 381 // Distance of Mb to the various image edges. These are specified to 8th pel
379 // as they are always compared to values that are in 1/8th pel units 382 // as they are always compared to values that are in 1/8th pel units
380 set_mi_row_col(xd, tile, mi_row, bh, mi_col, bw, cm->mi_rows, cm->mi_cols); 383 set_mi_row_col(xd, tile, mi_row, bh, mi_col, bw, cm->mi_rows, cm->mi_cols);
381 384
382 vp9_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col); 385 vp9_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col);
383 return &xd->mi[0].mbmi; 386 return &xd->mi[0].mbmi;
384 } 387 }
385 388
386 static void decode_block(VP9_COMMON *const cm, MACROBLOCKD *const xd, 389 static void decode_block(VP9Decoder *const pbi, MACROBLOCKD *const xd,
390 FRAME_COUNTS *counts,
387 const TileInfo *const tile, 391 const TileInfo *const tile,
388 int mi_row, int mi_col, 392 int mi_row, int mi_col,
389 vp9_reader *r, BLOCK_SIZE bsize) { 393 vp9_reader *r, BLOCK_SIZE bsize) {
394 VP9_COMMON *const cm = &pbi->common;
390 const int less8x8 = bsize < BLOCK_8X8; 395 const int less8x8 = bsize < BLOCK_8X8;
396 int16_t y_dequant[2], uv_dequant[2];
397 int qindex = cm->base_qindex;
391 MB_MODE_INFO *mbmi = set_offsets(cm, xd, tile, bsize, mi_row, mi_col); 398 MB_MODE_INFO *mbmi = set_offsets(cm, xd, tile, bsize, mi_row, mi_col);
392 vp9_read_mode_info(cm, xd, tile, mi_row, mi_col, r); 399 vp9_read_mode_info(pbi, xd, counts, tile, mi_row, mi_col, r);
393 400
394 if (less8x8) 401 if (less8x8)
395 bsize = BLOCK_8X8; 402 bsize = BLOCK_8X8;
396 403
397 if (mbmi->skip) { 404 if (mbmi->skip) {
398 reset_skip_context(xd, bsize); 405 reset_skip_context(xd, bsize);
399 } else { 406 } else if (cm->seg.enabled) {
400 if (cm->seg.enabled) 407 qindex = vp9_get_qindex(&cm->seg, mbmi->segment_id, cm->base_qindex);
401 setup_plane_dequants(cm, xd, vp9_get_qindex(&cm->seg, mbmi->segment_id,
402 cm->base_qindex));
403 } 408 }
404 409
410 y_dequant[0] = vp9_dc_quant(qindex, cm->y_dc_delta_q, cm->bit_depth);
411 y_dequant[1] = vp9_ac_quant(qindex, 0, cm->bit_depth);
412 uv_dequant[0] = vp9_dc_quant(qindex, cm->uv_dc_delta_q, cm->bit_depth);
413 uv_dequant[1] = vp9_ac_quant(qindex, cm->uv_ac_delta_q, cm->bit_depth);
414
405 if (!is_inter_block(mbmi)) { 415 if (!is_inter_block(mbmi)) {
406 struct intra_args arg = { cm, xd, r }; 416 struct intra_args arg = {cm, xd, counts, r , y_dequant, uv_dequant};
407 vp9_foreach_transformed_block(xd, bsize, 417 vp9_foreach_transformed_block(xd, bsize,
408 predict_and_reconstruct_intra_block, &arg); 418 predict_and_reconstruct_intra_block, &arg);
409 } else { 419 } else {
410 // Prediction 420 // Prediction
411 vp9_dec_build_inter_predictors_sb(xd, mi_row, mi_col, bsize); 421 vp9_dec_build_inter_predictors_sb(pbi, xd, mi_row, mi_col, bsize);
412 422
413 // Reconstruction 423 // Reconstruction
414 if (!mbmi->skip) { 424 if (!mbmi->skip) {
415 int eobtotal = 0; 425 int eobtotal = 0;
416 struct inter_args arg = { cm, xd, r, &eobtotal }; 426 struct inter_args arg = {cm, xd, r, counts, &eobtotal, y_dequant,
427 uv_dequant};
417 vp9_foreach_transformed_block(xd, bsize, reconstruct_inter_block, &arg); 428 vp9_foreach_transformed_block(xd, bsize, reconstruct_inter_block, &arg);
418 if (!less8x8 && eobtotal == 0) 429 if (!less8x8 && eobtotal == 0)
419 mbmi->skip = 1; // skip loopfilter 430 mbmi->skip = 1; // skip loopfilter
420 } 431 }
421 } 432 }
422 433
423 xd->corrupted |= vp9_reader_has_error(r); 434 xd->corrupted |= vp9_reader_has_error(r);
424 } 435 }
425 436
426 static PARTITION_TYPE read_partition(VP9_COMMON *cm, MACROBLOCKD *xd, int hbs, 437 static PARTITION_TYPE read_partition(VP9_COMMON *cm, MACROBLOCKD *xd,
438 FRAME_COUNTS *counts, int hbs,
427 int mi_row, int mi_col, BLOCK_SIZE bsize, 439 int mi_row, int mi_col, BLOCK_SIZE bsize,
428 vp9_reader *r) { 440 vp9_reader *r) {
429 const int ctx = partition_plane_context(xd, mi_row, mi_col, bsize); 441 const int ctx = partition_plane_context(xd, mi_row, mi_col, bsize);
430 const vp9_prob *const probs = get_partition_probs(cm, ctx); 442 const vp9_prob *const probs = get_partition_probs(cm, ctx);
431 const int has_rows = (mi_row + hbs) < cm->mi_rows; 443 const int has_rows = (mi_row + hbs) < cm->mi_rows;
432 const int has_cols = (mi_col + hbs) < cm->mi_cols; 444 const int has_cols = (mi_col + hbs) < cm->mi_cols;
433 PARTITION_TYPE p; 445 PARTITION_TYPE p;
434 446
435 if (has_rows && has_cols) 447 if (has_rows && has_cols)
436 p = (PARTITION_TYPE)vp9_read_tree(r, vp9_partition_tree, probs); 448 p = (PARTITION_TYPE)vp9_read_tree(r, vp9_partition_tree, probs);
437 else if (!has_rows && has_cols) 449 else if (!has_rows && has_cols)
438 p = vp9_read(r, probs[1]) ? PARTITION_SPLIT : PARTITION_HORZ; 450 p = vp9_read(r, probs[1]) ? PARTITION_SPLIT : PARTITION_HORZ;
439 else if (has_rows && !has_cols) 451 else if (has_rows && !has_cols)
440 p = vp9_read(r, probs[2]) ? PARTITION_SPLIT : PARTITION_VERT; 452 p = vp9_read(r, probs[2]) ? PARTITION_SPLIT : PARTITION_VERT;
441 else 453 else
442 p = PARTITION_SPLIT; 454 p = PARTITION_SPLIT;
443 455
444 if (!cm->frame_parallel_decoding_mode) 456 if (!cm->frame_parallel_decoding_mode)
445 ++cm->counts.partition[ctx][p]; 457 ++counts->partition[ctx][p];
446 458
447 return p; 459 return p;
448 } 460 }
449 461
450 static void decode_partition(VP9_COMMON *const cm, MACROBLOCKD *const xd, 462 static void decode_partition(VP9Decoder *const pbi, MACROBLOCKD *const xd,
463 FRAME_COUNTS *counts,
451 const TileInfo *const tile, 464 const TileInfo *const tile,
452 int mi_row, int mi_col, 465 int mi_row, int mi_col,
453 vp9_reader* r, BLOCK_SIZE bsize) { 466 vp9_reader* r, BLOCK_SIZE bsize) {
467 VP9_COMMON *const cm = &pbi->common;
454 const int hbs = num_8x8_blocks_wide_lookup[bsize] / 2; 468 const int hbs = num_8x8_blocks_wide_lookup[bsize] / 2;
455 PARTITION_TYPE partition; 469 PARTITION_TYPE partition;
456 BLOCK_SIZE subsize, uv_subsize; 470 BLOCK_SIZE subsize, uv_subsize;
457 471
458 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) 472 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
459 return; 473 return;
460 474
461 partition = read_partition(cm, xd, hbs, mi_row, mi_col, bsize, r); 475 partition = read_partition(cm, xd, counts, hbs, mi_row, mi_col, bsize, r);
462 subsize = get_subsize(bsize, partition); 476 subsize = get_subsize(bsize, partition);
463 uv_subsize = ss_size_lookup[subsize][cm->subsampling_x][cm->subsampling_y]; 477 uv_subsize = ss_size_lookup[subsize][cm->subsampling_x][cm->subsampling_y];
464 if (subsize >= BLOCK_8X8 && uv_subsize == BLOCK_INVALID) 478 if (subsize >= BLOCK_8X8 && uv_subsize == BLOCK_INVALID)
465 vpx_internal_error(xd->error_info, 479 vpx_internal_error(xd->error_info,
466 VPX_CODEC_CORRUPT_FRAME, "Invalid block size."); 480 VPX_CODEC_CORRUPT_FRAME, "Invalid block size.");
467 if (subsize < BLOCK_8X8) { 481 if (subsize < BLOCK_8X8) {
468 decode_block(cm, xd, tile, mi_row, mi_col, r, subsize); 482 decode_block(pbi, xd, counts, tile, mi_row, mi_col, r, subsize);
469 } else { 483 } else {
470 switch (partition) { 484 switch (partition) {
471 case PARTITION_NONE: 485 case PARTITION_NONE:
472 decode_block(cm, xd, tile, mi_row, mi_col, r, subsize); 486 decode_block(pbi, xd, counts, tile, mi_row, mi_col, r, subsize);
473 break; 487 break;
474 case PARTITION_HORZ: 488 case PARTITION_HORZ:
475 decode_block(cm, xd, tile, mi_row, mi_col, r, subsize); 489 decode_block(pbi, xd, counts, tile, mi_row, mi_col, r, subsize);
476 if (mi_row + hbs < cm->mi_rows) 490 if (mi_row + hbs < cm->mi_rows)
477 decode_block(cm, xd, tile, mi_row + hbs, mi_col, r, subsize); 491 decode_block(pbi, xd, counts, tile, mi_row + hbs, mi_col, r, subsize);
478 break; 492 break;
479 case PARTITION_VERT: 493 case PARTITION_VERT:
480 decode_block(cm, xd, tile, mi_row, mi_col, r, subsize); 494 decode_block(pbi, xd, counts, tile, mi_row, mi_col, r, subsize);
481 if (mi_col + hbs < cm->mi_cols) 495 if (mi_col + hbs < cm->mi_cols)
482 decode_block(cm, xd, tile, mi_row, mi_col + hbs, r, subsize); 496 decode_block(pbi, xd, counts, tile, mi_row, mi_col + hbs, r, subsize);
483 break; 497 break;
484 case PARTITION_SPLIT: 498 case PARTITION_SPLIT:
485 decode_partition(cm, xd, tile, mi_row, mi_col, r, subsize); 499 decode_partition(pbi, xd, counts, tile, mi_row, mi_col, r, subsize);
486 decode_partition(cm, xd, tile, mi_row, mi_col + hbs, r, subsize); 500 decode_partition(pbi, xd, counts, tile, mi_row, mi_col + hbs, r,
487 decode_partition(cm, xd, tile, mi_row + hbs, mi_col, r, subsize); 501 subsize);
488 decode_partition(cm, xd, tile, mi_row + hbs, mi_col + hbs, r, subsize); 502 decode_partition(pbi, xd, counts, tile, mi_row + hbs, mi_col, r,
503 subsize);
504 decode_partition(pbi, xd, counts, tile, mi_row + hbs, mi_col + hbs, r,
505 subsize);
489 break; 506 break;
490 default: 507 default:
491 assert(0 && "Invalid partition type"); 508 assert(0 && "Invalid partition type");
492 } 509 }
493 } 510 }
494 511
495 // update partition context 512 // update partition context
496 if (bsize >= BLOCK_8X8 && 513 if (bsize >= BLOCK_8X8 &&
497 (bsize == BLOCK_8X8 || partition != PARTITION_SPLIT)) 514 (bsize == BLOCK_8X8 || partition != PARTITION_SPLIT))
498 update_partition_context(xd, mi_row, mi_col, subsize, bsize); 515 update_partition_context(xd, mi_row, mi_col, subsize, bsize);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 if (vp9_rb_read_bit(rb)) 626 if (vp9_rb_read_bit(rb))
610 lf->ref_deltas[i] = vp9_rb_read_signed_literal(rb, 6); 627 lf->ref_deltas[i] = vp9_rb_read_signed_literal(rb, 6);
611 628
612 for (i = 0; i < MAX_MODE_LF_DELTAS; i++) 629 for (i = 0; i < MAX_MODE_LF_DELTAS; i++)
613 if (vp9_rb_read_bit(rb)) 630 if (vp9_rb_read_bit(rb))
614 lf->mode_deltas[i] = vp9_rb_read_signed_literal(rb, 6); 631 lf->mode_deltas[i] = vp9_rb_read_signed_literal(rb, 6);
615 } 632 }
616 } 633 }
617 } 634 }
618 635
619 static int read_delta_q(struct vp9_read_bit_buffer *rb, int *delta_q) { 636 static INLINE int read_delta_q(struct vp9_read_bit_buffer *rb) {
620 const int old = *delta_q; 637 return vp9_rb_read_bit(rb) ? vp9_rb_read_signed_literal(rb, 4) : 0;
621 *delta_q = vp9_rb_read_bit(rb) ? vp9_rb_read_signed_literal(rb, 4) : 0;
622 return old != *delta_q;
623 } 638 }
624 639
625 static void setup_quantization(VP9_COMMON *const cm, MACROBLOCKD *const xd, 640 static void setup_quantization(VP9_COMMON *const cm, MACROBLOCKD *const xd,
626 struct vp9_read_bit_buffer *rb) { 641 struct vp9_read_bit_buffer *rb) {
627 int update = 0;
628
629 cm->base_qindex = vp9_rb_read_literal(rb, QINDEX_BITS); 642 cm->base_qindex = vp9_rb_read_literal(rb, QINDEX_BITS);
630 update |= read_delta_q(rb, &cm->y_dc_delta_q); 643 cm->y_dc_delta_q = read_delta_q(rb);
631 update |= read_delta_q(rb, &cm->uv_dc_delta_q); 644 cm->uv_dc_delta_q = read_delta_q(rb);
632 update |= read_delta_q(rb, &cm->uv_ac_delta_q); 645 cm->uv_ac_delta_q = read_delta_q(rb);
633 if (update || cm->bit_depth != cm->dequant_bit_depth) { 646 cm->dequant_bit_depth = cm->bit_depth;
634 vp9_init_dequantizer(cm);
635 cm->dequant_bit_depth = cm->bit_depth;
636 }
637
638 xd->lossless = cm->base_qindex == 0 && 647 xd->lossless = cm->base_qindex == 0 &&
639 cm->y_dc_delta_q == 0 && 648 cm->y_dc_delta_q == 0 &&
640 cm->uv_dc_delta_q == 0 && 649 cm->uv_dc_delta_q == 0 &&
641 cm->uv_ac_delta_q == 0; 650 cm->uv_ac_delta_q == 0;
642 #if CONFIG_VP9_HIGHBITDEPTH 651 #if CONFIG_VP9_HIGHBITDEPTH
643 xd->bd = (int)cm->bit_depth; 652 xd->bd = (int)cm->bit_depth;
644 #endif 653 #endif
645 } 654 }
646 655
647 static INTERP_FILTER read_interp_filter(struct vp9_read_bit_buffer *rb) { 656 static INTERP_FILTER read_interp_filter(struct vp9_read_bit_buffer *rb) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 cm->height = height; 709 cm->height = height;
701 } 710 }
702 if (cm->cur_frame->mvs == NULL || cm->mi_rows > cm->cur_frame->mi_rows || 711 if (cm->cur_frame->mvs == NULL || cm->mi_rows > cm->cur_frame->mi_rows ||
703 cm->mi_cols > cm->cur_frame->mi_cols) { 712 cm->mi_cols > cm->cur_frame->mi_cols) {
704 resize_mv_buffer(cm); 713 resize_mv_buffer(cm);
705 } 714 }
706 } 715 }
707 716
708 static void setup_frame_size(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) { 717 static void setup_frame_size(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) {
709 int width, height; 718 int width, height;
719 BufferPool *const pool = cm->buffer_pool;
710 vp9_read_frame_size(rb, &width, &height); 720 vp9_read_frame_size(rb, &width, &height);
711 resize_context_buffers(cm, width, height); 721 resize_context_buffers(cm, width, height);
712 setup_display_size(cm, rb); 722 setup_display_size(cm, rb);
713 723
724 lock_buffer_pool(pool);
714 if (vp9_realloc_frame_buffer( 725 if (vp9_realloc_frame_buffer(
715 get_frame_new_buffer(cm), cm->width, cm->height, 726 get_frame_new_buffer(cm), cm->width, cm->height,
716 cm->subsampling_x, cm->subsampling_y, 727 cm->subsampling_x, cm->subsampling_y,
717 #if CONFIG_VP9_HIGHBITDEPTH 728 #if CONFIG_VP9_HIGHBITDEPTH
718 cm->use_highbitdepth, 729 cm->use_highbitdepth,
719 #endif 730 #endif
720 VP9_DEC_BORDER_IN_PIXELS, 731 VP9_DEC_BORDER_IN_PIXELS,
721 cm->byte_alignment, 732 cm->byte_alignment,
722 &cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer, cm->get_fb_cb, 733 &pool->frame_bufs[cm->new_fb_idx].raw_frame_buffer, pool->get_fb_cb,
723 cm->cb_priv)) { 734 pool->cb_priv)) {
735 unlock_buffer_pool(pool);
724 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, 736 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
725 "Failed to allocate frame buffer"); 737 "Failed to allocate frame buffer");
726 } 738 }
727 cm->frame_bufs[cm->new_fb_idx].buf.subsampling_x = cm->subsampling_x; 739 unlock_buffer_pool(pool);
728 cm->frame_bufs[cm->new_fb_idx].buf.subsampling_y = cm->subsampling_y; 740
729 cm->frame_bufs[cm->new_fb_idx].buf.color_space = 741 pool->frame_bufs[cm->new_fb_idx].buf.subsampling_x = cm->subsampling_x;
730 (vpx_color_space_t)cm->color_space; 742 pool->frame_bufs[cm->new_fb_idx].buf.subsampling_y = cm->subsampling_y;
731 cm->frame_bufs[cm->new_fb_idx].buf.bit_depth = (unsigned int)cm->bit_depth; 743 pool->frame_bufs[cm->new_fb_idx].buf.bit_depth = (unsigned int)cm->bit_depth;
744 pool->frame_bufs[cm->new_fb_idx].buf.color_space = cm->color_space;
732 } 745 }
733 746
734 static INLINE int valid_ref_frame_img_fmt(vpx_bit_depth_t ref_bit_depth, 747 static INLINE int valid_ref_frame_img_fmt(vpx_bit_depth_t ref_bit_depth,
735 int ref_xss, int ref_yss, 748 int ref_xss, int ref_yss,
736 vpx_bit_depth_t this_bit_depth, 749 vpx_bit_depth_t this_bit_depth,
737 int this_xss, int this_yss) { 750 int this_xss, int this_yss) {
738 return ref_bit_depth == this_bit_depth && ref_xss == this_xss && 751 return ref_bit_depth == this_bit_depth && ref_xss == this_xss &&
739 ref_yss == this_yss; 752 ref_yss == this_yss;
740 } 753 }
741 754
742 static void setup_frame_size_with_refs(VP9_COMMON *cm, 755 static void setup_frame_size_with_refs(VP9_COMMON *cm,
743 struct vp9_read_bit_buffer *rb) { 756 struct vp9_read_bit_buffer *rb) {
744 int width, height; 757 int width, height;
745 int found = 0, i; 758 int found = 0, i;
746 int has_valid_ref_frame = 0; 759 int has_valid_ref_frame = 0;
760 BufferPool *const pool = cm->buffer_pool;
747 for (i = 0; i < REFS_PER_FRAME; ++i) { 761 for (i = 0; i < REFS_PER_FRAME; ++i) {
748 if (vp9_rb_read_bit(rb)) { 762 if (vp9_rb_read_bit(rb)) {
749 YV12_BUFFER_CONFIG *const buf = cm->frame_refs[i].buf; 763 YV12_BUFFER_CONFIG *const buf = cm->frame_refs[i].buf;
750 width = buf->y_crop_width; 764 width = buf->y_crop_width;
751 height = buf->y_crop_height; 765 height = buf->y_crop_height;
752 found = 1; 766 found = 1;
753 break; 767 break;
754 } 768 }
755 } 769 }
756 770
(...skipping 24 matching lines...) Expand all
781 cm->bit_depth, 795 cm->bit_depth,
782 cm->subsampling_x, 796 cm->subsampling_x,
783 cm->subsampling_y)) 797 cm->subsampling_y))
784 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, 798 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
785 "Referenced frame has incompatible color format"); 799 "Referenced frame has incompatible color format");
786 } 800 }
787 801
788 resize_context_buffers(cm, width, height); 802 resize_context_buffers(cm, width, height);
789 setup_display_size(cm, rb); 803 setup_display_size(cm, rb);
790 804
805 lock_buffer_pool(pool);
791 if (vp9_realloc_frame_buffer( 806 if (vp9_realloc_frame_buffer(
792 get_frame_new_buffer(cm), cm->width, cm->height, 807 get_frame_new_buffer(cm), cm->width, cm->height,
793 cm->subsampling_x, cm->subsampling_y, 808 cm->subsampling_x, cm->subsampling_y,
794 #if CONFIG_VP9_HIGHBITDEPTH 809 #if CONFIG_VP9_HIGHBITDEPTH
795 cm->use_highbitdepth, 810 cm->use_highbitdepth,
796 #endif 811 #endif
797 VP9_DEC_BORDER_IN_PIXELS, 812 VP9_DEC_BORDER_IN_PIXELS,
798 cm->byte_alignment, 813 cm->byte_alignment,
799 &cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer, cm->get_fb_cb, 814 &pool->frame_bufs[cm->new_fb_idx].raw_frame_buffer, pool->get_fb_cb,
800 cm->cb_priv)) { 815 pool->cb_priv)) {
816 unlock_buffer_pool(pool);
801 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, 817 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
802 "Failed to allocate frame buffer"); 818 "Failed to allocate frame buffer");
803 } 819 }
804 cm->frame_bufs[cm->new_fb_idx].buf.subsampling_x = cm->subsampling_x; 820 unlock_buffer_pool(pool);
805 cm->frame_bufs[cm->new_fb_idx].buf.subsampling_y = cm->subsampling_y; 821
806 cm->frame_bufs[cm->new_fb_idx].buf.bit_depth = (unsigned int)cm->bit_depth; 822 pool->frame_bufs[cm->new_fb_idx].buf.subsampling_x = cm->subsampling_x;
823 pool->frame_bufs[cm->new_fb_idx].buf.subsampling_y = cm->subsampling_y;
824 pool->frame_bufs[cm->new_fb_idx].buf.bit_depth = (unsigned int)cm->bit_depth;
825 pool->frame_bufs[cm->new_fb_idx].buf.color_space = cm->color_space;
807 } 826 }
808 827
809 static void setup_tile_info(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) { 828 static void setup_tile_info(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) {
810 int min_log2_tile_cols, max_log2_tile_cols, max_ones; 829 int min_log2_tile_cols, max_log2_tile_cols, max_ones;
811 vp9_get_tile_n_bits(cm->mi_cols, &min_log2_tile_cols, &max_log2_tile_cols); 830 vp9_get_tile_n_bits(cm->mi_cols, &min_log2_tile_cols, &max_log2_tile_cols);
812 831
813 // columns 832 // columns
814 max_ones = max_log2_tile_cols - min_log2_tile_cols; 833 max_ones = max_log2_tile_cols - min_log2_tile_cols;
815 cm->log2_tile_cols = min_log2_tile_cols; 834 cm->log2_tile_cols = min_log2_tile_cols;
816 while (max_ones-- && vp9_rb_read_bit(rb)) 835 while (max_ones-- && vp9_rb_read_bit(rb))
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 mi_row += MI_BLOCK_SIZE) { 984 mi_row += MI_BLOCK_SIZE) {
966 for (tile_col = 0; tile_col < tile_cols; ++tile_col) { 985 for (tile_col = 0; tile_col < tile_cols; ++tile_col) {
967 const int col = pbi->inv_tile_order ? 986 const int col = pbi->inv_tile_order ?
968 tile_cols - tile_col - 1 : tile_col; 987 tile_cols - tile_col - 1 : tile_col;
969 tile_data = pbi->tile_data + tile_cols * tile_row + col; 988 tile_data = pbi->tile_data + tile_cols * tile_row + col;
970 vp9_tile_set_col(&tile, tile_data->cm, col); 989 vp9_tile_set_col(&tile, tile_data->cm, col);
971 vp9_zero(tile_data->xd.left_context); 990 vp9_zero(tile_data->xd.left_context);
972 vp9_zero(tile_data->xd.left_seg_context); 991 vp9_zero(tile_data->xd.left_seg_context);
973 for (mi_col = tile.mi_col_start; mi_col < tile.mi_col_end; 992 for (mi_col = tile.mi_col_start; mi_col < tile.mi_col_end;
974 mi_col += MI_BLOCK_SIZE) { 993 mi_col += MI_BLOCK_SIZE) {
975 decode_partition(tile_data->cm, &tile_data->xd, &tile, mi_row, mi_col, 994 decode_partition(pbi, &tile_data->xd, &cm->counts, &tile, mi_row,
976 &tile_data->bit_reader, BLOCK_64X64); 995 mi_col, &tile_data->bit_reader, BLOCK_64X64);
977 } 996 }
978 pbi->mb.corrupted |= tile_data->xd.corrupted; 997 pbi->mb.corrupted |= tile_data->xd.corrupted;
979 if (pbi->mb.corrupted) 998 if (pbi->mb.corrupted)
980 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, 999 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
981 "Failed to decode tile data"); 1000 "Failed to decode tile data");
982 } 1001 }
983 // Loopfilter one row. 1002 // Loopfilter one row.
984 if (cm->lf.filter_level) { 1003 if (cm->lf.filter_level) {
985 const int lf_start = mi_row - MI_BLOCK_SIZE; 1004 const int lf_start = mi_row - MI_BLOCK_SIZE;
986 LFWorkerData *const lf_data = (LFWorkerData*)pbi->lf_worker.data1; 1005 LFWorkerData *const lf_data = (LFWorkerData*)pbi->lf_worker.data1;
987 1006
988 // delay the loopfilter by 1 macroblock row. 1007 // delay the loopfilter by 1 macroblock row.
989 if (lf_start < 0) continue; 1008 if (lf_start < 0) continue;
990 1009
991 // decoding has completed: finish up the loop filter in this thread. 1010 // decoding has completed: finish up the loop filter in this thread.
992 if (mi_row + MI_BLOCK_SIZE >= cm->mi_rows) continue; 1011 if (mi_row + MI_BLOCK_SIZE >= cm->mi_rows) continue;
993 1012
994 winterface->sync(&pbi->lf_worker); 1013 winterface->sync(&pbi->lf_worker);
995 lf_data->start = lf_start; 1014 lf_data->start = lf_start;
996 lf_data->stop = mi_row; 1015 lf_data->stop = mi_row;
997 if (pbi->max_threads > 1) { 1016 if (pbi->max_threads > 1) {
998 winterface->launch(&pbi->lf_worker); 1017 winterface->launch(&pbi->lf_worker);
999 } else { 1018 } else {
1000 winterface->execute(&pbi->lf_worker); 1019 winterface->execute(&pbi->lf_worker);
1001 } 1020 }
1002 } 1021 }
1022 // After loopfiltering, the last 7 row pixels in each superblock row may
1023 // still be changed by the longest loopfilter of the next superblock
1024 // row.
1025 if (pbi->frame_parallel_decode)
1026 vp9_frameworker_broadcast(pbi->cur_buf,
1027 mi_row << MI_BLOCK_SIZE_LOG2);
1003 } 1028 }
1004 } 1029 }
1005 1030
1006 // Loopfilter remaining rows in the frame. 1031 // Loopfilter remaining rows in the frame.
1007 if (cm->lf.filter_level) { 1032 if (cm->lf.filter_level) {
1008 LFWorkerData *const lf_data = (LFWorkerData*)pbi->lf_worker.data1; 1033 LFWorkerData *const lf_data = (LFWorkerData*)pbi->lf_worker.data1;
1009 winterface->sync(&pbi->lf_worker); 1034 winterface->sync(&pbi->lf_worker);
1010 lf_data->start = lf_data->stop; 1035 lf_data->start = lf_data->stop;
1011 lf_data->stop = cm->mi_rows; 1036 lf_data->stop = cm->mi_rows;
1012 winterface->execute(&pbi->lf_worker); 1037 winterface->execute(&pbi->lf_worker);
1013 } 1038 }
1014 1039
1015 // Get last tile data. 1040 // Get last tile data.
1016 tile_data = pbi->tile_data + tile_cols * tile_rows - 1; 1041 tile_data = pbi->tile_data + tile_cols * tile_rows - 1;
1017 1042
1043 if (pbi->frame_parallel_decode)
1044 vp9_frameworker_broadcast(pbi->cur_buf, INT_MAX);
1018 return vp9_reader_find_end(&tile_data->bit_reader); 1045 return vp9_reader_find_end(&tile_data->bit_reader);
1019 } 1046 }
1020 1047
1021 static int tile_worker_hook(TileWorkerData *const tile_data, 1048 static int tile_worker_hook(TileWorkerData *const tile_data,
1022 const TileInfo *const tile) { 1049 const TileInfo *const tile) {
1023 int mi_row, mi_col; 1050 int mi_row, mi_col;
1024 1051
1025 if (setjmp(tile_data->error_info.jmp)) { 1052 if (setjmp(tile_data->error_info.jmp)) {
1026 tile_data->error_info.setjmp = 0; 1053 tile_data->error_info.setjmp = 0;
1027 tile_data->xd.corrupted = 1; 1054 tile_data->xd.corrupted = 1;
1028 return 0; 1055 return 0;
1029 } 1056 }
1030 1057
1031 tile_data->error_info.setjmp = 1; 1058 tile_data->error_info.setjmp = 1;
1032 tile_data->xd.error_info = &tile_data->error_info; 1059 tile_data->xd.error_info = &tile_data->error_info;
1033 1060
1034 for (mi_row = tile->mi_row_start; mi_row < tile->mi_row_end; 1061 for (mi_row = tile->mi_row_start; mi_row < tile->mi_row_end;
1035 mi_row += MI_BLOCK_SIZE) { 1062 mi_row += MI_BLOCK_SIZE) {
1036 vp9_zero(tile_data->xd.left_context); 1063 vp9_zero(tile_data->xd.left_context);
1037 vp9_zero(tile_data->xd.left_seg_context); 1064 vp9_zero(tile_data->xd.left_seg_context);
1038 for (mi_col = tile->mi_col_start; mi_col < tile->mi_col_end; 1065 for (mi_col = tile->mi_col_start; mi_col < tile->mi_col_end;
1039 mi_col += MI_BLOCK_SIZE) { 1066 mi_col += MI_BLOCK_SIZE) {
1040 decode_partition(tile_data->cm, &tile_data->xd, tile, 1067 decode_partition(tile_data->pbi, &tile_data->xd, &tile_data->counts,
1041 mi_row, mi_col, &tile_data->bit_reader, BLOCK_64X64); 1068 tile, mi_row, mi_col, &tile_data->bit_reader,
1069 BLOCK_64X64);
1042 } 1070 }
1043 } 1071 }
1044 return !tile_data->xd.corrupted; 1072 return !tile_data->xd.corrupted;
1045 } 1073 }
1046 1074
1047 // sorts in descending order 1075 // sorts in descending order
1048 static int compare_tile_buffers(const void *a, const void *b) { 1076 static int compare_tile_buffers(const void *a, const void *b) {
1049 const TileBuffer *const buf1 = (const TileBuffer*)a; 1077 const TileBuffer *const buf1 = (const TileBuffer*)a;
1050 const TileBuffer *const buf2 = (const TileBuffer*)b; 1078 const TileBuffer *const buf2 = (const TileBuffer*)b;
1051 if (buf1->size < buf2->size) { 1079 if (buf1->size < buf2->size) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 while (group_start < tile_cols) { 1164 while (group_start < tile_cols) {
1137 const TileBuffer largest = tile_buffers[0][group_start]; 1165 const TileBuffer largest = tile_buffers[0][group_start];
1138 const int group_end = MIN(group_start + num_workers, tile_cols) - 1; 1166 const int group_end = MIN(group_start + num_workers, tile_cols) - 1;
1139 memmove(tile_buffers[0] + group_start, tile_buffers[0] + group_start + 1, 1167 memmove(tile_buffers[0] + group_start, tile_buffers[0] + group_start + 1,
1140 (group_end - group_start) * sizeof(tile_buffers[0][0])); 1168 (group_end - group_start) * sizeof(tile_buffers[0][0]));
1141 tile_buffers[0][group_end] = largest; 1169 tile_buffers[0][group_end] = largest;
1142 group_start = group_end + 1; 1170 group_start = group_end + 1;
1143 } 1171 }
1144 } 1172 }
1145 1173
1174 // Initialize thread frame counts.
1175 if (!cm->frame_parallel_decoding_mode) {
1176 int i;
1177
1178 for (i = 0; i < num_workers; ++i) {
1179 TileWorkerData *const tile_data =
1180 (TileWorkerData*)pbi->tile_workers[i].data1;
1181 vp9_zero(tile_data->counts);
1182 }
1183 }
1184
1146 n = 0; 1185 n = 0;
1147 while (n < tile_cols) { 1186 while (n < tile_cols) {
1148 int i; 1187 int i;
1149 for (i = 0; i < num_workers && n < tile_cols; ++i) { 1188 for (i = 0; i < num_workers && n < tile_cols; ++i) {
1150 VP9Worker *const worker = &pbi->tile_workers[i]; 1189 VP9Worker *const worker = &pbi->tile_workers[i];
1151 TileWorkerData *const tile_data = (TileWorkerData*)worker->data1; 1190 TileWorkerData *const tile_data = (TileWorkerData*)worker->data1;
1152 TileInfo *const tile = (TileInfo*)worker->data2; 1191 TileInfo *const tile = (TileInfo*)worker->data2;
1153 TileBuffer *const buf = &tile_buffers[0][n]; 1192 TileBuffer *const buf = &tile_buffers[0][n];
1154 1193
1155 tile_data->cm = cm; 1194 tile_data->pbi = pbi;
1156 tile_data->xd = pbi->mb; 1195 tile_data->xd = pbi->mb;
1157 tile_data->xd.corrupted = 0; 1196 tile_data->xd.corrupted = 0;
1158 vp9_tile_init(tile, tile_data->cm, 0, buf->col); 1197 vp9_tile_init(tile, cm, 0, buf->col);
1159 setup_token_decoder(buf->data, data_end, buf->size, &cm->error, 1198 setup_token_decoder(buf->data, data_end, buf->size, &cm->error,
1160 &tile_data->bit_reader, pbi->decrypt_cb, 1199 &tile_data->bit_reader, pbi->decrypt_cb,
1161 pbi->decrypt_state); 1200 pbi->decrypt_state);
1162 init_macroblockd(cm, &tile_data->xd); 1201 init_macroblockd(cm, &tile_data->xd);
1163 1202
1164 worker->had_error = 0; 1203 worker->had_error = 0;
1165 if (i == num_workers - 1 || n == tile_cols - 1) { 1204 if (i == num_workers - 1 || n == tile_cols - 1) {
1166 winterface->execute(worker); 1205 winterface->execute(worker);
1167 } else { 1206 } else {
1168 winterface->launch(worker); 1207 winterface->launch(worker);
(...skipping 13 matching lines...) Expand all
1182 // in cm. Additionally once the threads have been synced and an error is 1221 // in cm. Additionally once the threads have been synced and an error is
1183 // detected, there's no point in continuing to decode tiles. 1222 // detected, there's no point in continuing to decode tiles.
1184 pbi->mb.corrupted |= !winterface->sync(worker); 1223 pbi->mb.corrupted |= !winterface->sync(worker);
1185 } 1224 }
1186 if (final_worker > -1) { 1225 if (final_worker > -1) {
1187 TileWorkerData *const tile_data = 1226 TileWorkerData *const tile_data =
1188 (TileWorkerData*)pbi->tile_workers[final_worker].data1; 1227 (TileWorkerData*)pbi->tile_workers[final_worker].data1;
1189 bit_reader_end = vp9_reader_find_end(&tile_data->bit_reader); 1228 bit_reader_end = vp9_reader_find_end(&tile_data->bit_reader);
1190 final_worker = -1; 1229 final_worker = -1;
1191 } 1230 }
1231
1232 // Accumulate thread frame counts.
1233 if (n >= tile_cols && !cm->frame_parallel_decoding_mode) {
1234 for (i = 0; i < num_workers; ++i) {
1235 TileWorkerData *const tile_data =
1236 (TileWorkerData*)pbi->tile_workers[i].data1;
1237 vp9_accumulate_frame_counts(cm, &tile_data->counts, 1);
1238 }
1239 }
1192 } 1240 }
1193 1241
1194 return bit_reader_end; 1242 return bit_reader_end;
1195 } 1243 }
1196 1244
1197 static void error_handler(void *data) { 1245 static void error_handler(void *data) {
1198 VP9_COMMON *const cm = (VP9_COMMON *)data; 1246 VP9_COMMON *const cm = (VP9_COMMON *)data;
1199 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, "Truncated packet"); 1247 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, "Truncated packet");
1200 } 1248 }
1201 1249
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 } else { 1300 } else {
1253 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, 1301 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
1254 "4:4:4 color not supported in profile 0 or 2"); 1302 "4:4:4 color not supported in profile 0 or 2");
1255 } 1303 }
1256 } 1304 }
1257 } 1305 }
1258 1306
1259 static size_t read_uncompressed_header(VP9Decoder *pbi, 1307 static size_t read_uncompressed_header(VP9Decoder *pbi,
1260 struct vp9_read_bit_buffer *rb) { 1308 struct vp9_read_bit_buffer *rb) {
1261 VP9_COMMON *const cm = &pbi->common; 1309 VP9_COMMON *const cm = &pbi->common;
1310 RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs;
1311 BufferPool *const pool = pbi->common.buffer_pool;
1312 int i, mask, ref_index = 0;
1262 size_t sz; 1313 size_t sz;
1263 int i;
1264 1314
1265 cm->last_frame_type = cm->frame_type; 1315 cm->last_frame_type = cm->frame_type;
1266 1316
1267 if (vp9_rb_read_literal(rb, 2) != VP9_FRAME_MARKER) 1317 if (vp9_rb_read_literal(rb, 2) != VP9_FRAME_MARKER)
1268 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, 1318 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
1269 "Invalid frame marker"); 1319 "Invalid frame marker");
1270 1320
1271 cm->profile = vp9_read_profile(rb); 1321 cm->profile = vp9_read_profile(rb);
1272 1322
1273 if (cm->profile >= MAX_PROFILES) 1323 if (cm->profile >= MAX_PROFILES)
1274 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, 1324 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
1275 "Unsupported bitstream profile"); 1325 "Unsupported bitstream profile");
1276 1326
1277 cm->show_existing_frame = vp9_rb_read_bit(rb); 1327 cm->show_existing_frame = vp9_rb_read_bit(rb);
1278 if (cm->show_existing_frame) { 1328 if (cm->show_existing_frame) {
1279 // Show an existing frame directly. 1329 // Show an existing frame directly.
1280 const int frame_to_show = cm->ref_frame_map[vp9_rb_read_literal(rb, 3)]; 1330 const int frame_to_show = cm->ref_frame_map[vp9_rb_read_literal(rb, 3)];
1281 1331 lock_buffer_pool(pool);
1282 if (frame_to_show < 0 || cm->frame_bufs[frame_to_show].ref_count < 1) 1332 if (frame_to_show < 0 || frame_bufs[frame_to_show].ref_count < 1) {
1333 unlock_buffer_pool(pool);
1283 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, 1334 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
1284 "Buffer %d does not contain a decoded frame", 1335 "Buffer %d does not contain a decoded frame",
1285 frame_to_show); 1336 frame_to_show);
1337 }
1286 1338
1287 ref_cnt_fb(cm->frame_bufs, &cm->new_fb_idx, frame_to_show); 1339 ref_cnt_fb(frame_bufs, &cm->new_fb_idx, frame_to_show);
1340 unlock_buffer_pool(pool);
1288 pbi->refresh_frame_flags = 0; 1341 pbi->refresh_frame_flags = 0;
1289 cm->lf.filter_level = 0; 1342 cm->lf.filter_level = 0;
1290 cm->show_frame = 1; 1343 cm->show_frame = 1;
1344
1345 if (pbi->frame_parallel_decode) {
1346 for (i = 0; i < REF_FRAMES; ++i)
1347 cm->next_ref_frame_map[i] = cm->ref_frame_map[i];
1348 }
1291 return 0; 1349 return 0;
1292 } 1350 }
1293 1351
1294 cm->frame_type = (FRAME_TYPE) vp9_rb_read_bit(rb); 1352 cm->frame_type = (FRAME_TYPE) vp9_rb_read_bit(rb);
1295 cm->show_frame = vp9_rb_read_bit(rb); 1353 cm->show_frame = vp9_rb_read_bit(rb);
1296 cm->error_resilient_mode = vp9_rb_read_bit(rb); 1354 cm->error_resilient_mode = vp9_rb_read_bit(rb);
1297 1355
1298 if (cm->frame_type == KEY_FRAME) { 1356 if (cm->frame_type == KEY_FRAME) {
1299 if (!vp9_read_sync_code(rb)) 1357 if (!vp9_read_sync_code(rb))
1300 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, 1358 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
1301 "Invalid frame sync code"); 1359 "Invalid frame sync code");
1302 1360
1303 read_bitdepth_colorspace_sampling(cm, rb); 1361 read_bitdepth_colorspace_sampling(cm, rb);
1304 pbi->refresh_frame_flags = (1 << REF_FRAMES) - 1; 1362 pbi->refresh_frame_flags = (1 << REF_FRAMES) - 1;
1305 1363
1306 for (i = 0; i < REFS_PER_FRAME; ++i) { 1364 for (i = 0; i < REFS_PER_FRAME; ++i) {
1307 cm->frame_refs[i].idx = -1; 1365 cm->frame_refs[i].idx = -1;
1308 cm->frame_refs[i].buf = NULL; 1366 cm->frame_refs[i].buf = NULL;
1309 } 1367 }
1310 1368
1311 setup_frame_size(cm, rb); 1369 setup_frame_size(cm, rb);
1312 pbi->need_resync = 0; 1370 if (pbi->need_resync) {
1371 vpx_memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map));
1372 pbi->need_resync = 0;
1373 }
1313 } else { 1374 } else {
1314 cm->intra_only = cm->show_frame ? 0 : vp9_rb_read_bit(rb); 1375 cm->intra_only = cm->show_frame ? 0 : vp9_rb_read_bit(rb);
1315 1376
1316 cm->reset_frame_context = cm->error_resilient_mode ? 1377 cm->reset_frame_context = cm->error_resilient_mode ?
1317 0 : vp9_rb_read_literal(rb, 2); 1378 0 : vp9_rb_read_literal(rb, 2);
1318 1379
1319 if (cm->intra_only) { 1380 if (cm->intra_only) {
1320 if (!vp9_read_sync_code(rb)) 1381 if (!vp9_read_sync_code(rb))
1321 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, 1382 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
1322 "Invalid frame sync code"); 1383 "Invalid frame sync code");
1323 if (cm->profile > PROFILE_0) { 1384 if (cm->profile > PROFILE_0) {
1324 read_bitdepth_colorspace_sampling(cm, rb); 1385 read_bitdepth_colorspace_sampling(cm, rb);
1325 } else { 1386 } else {
1326 // NOTE: The intra-only frame header does not include the specification 1387 // NOTE: The intra-only frame header does not include the specification
1327 // of either the color format or color sub-sampling in profile 0. VP9 1388 // of either the color format or color sub-sampling in profile 0. VP9
1328 // specifies that the default color format should be YUV 4:2:0 in this 1389 // specifies that the default color format should be YUV 4:2:0 in this
1329 // case (normative). 1390 // case (normative).
1330 cm->color_space = VPX_CS_BT_601; 1391 cm->color_space = VPX_CS_BT_601;
1331 cm->subsampling_y = cm->subsampling_x = 1; 1392 cm->subsampling_y = cm->subsampling_x = 1;
1332 cm->bit_depth = VPX_BITS_8; 1393 cm->bit_depth = VPX_BITS_8;
1333 #if CONFIG_VP9_HIGHBITDEPTH 1394 #if CONFIG_VP9_HIGHBITDEPTH
1334 cm->use_highbitdepth = 0; 1395 cm->use_highbitdepth = 0;
1335 #endif 1396 #endif
1336 } 1397 }
1337 1398
1338 pbi->refresh_frame_flags = vp9_rb_read_literal(rb, REF_FRAMES); 1399 pbi->refresh_frame_flags = vp9_rb_read_literal(rb, REF_FRAMES);
1339 setup_frame_size(cm, rb); 1400 setup_frame_size(cm, rb);
1340 pbi->need_resync = 0; 1401 if (pbi->need_resync) {
1341 } else { 1402 vpx_memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map));
1403 pbi->need_resync = 0;
1404 }
1405 } else if (pbi->need_resync != 1) { /* Skip if need resync */
1342 pbi->refresh_frame_flags = vp9_rb_read_literal(rb, REF_FRAMES); 1406 pbi->refresh_frame_flags = vp9_rb_read_literal(rb, REF_FRAMES);
1343 for (i = 0; i < REFS_PER_FRAME; ++i) { 1407 for (i = 0; i < REFS_PER_FRAME; ++i) {
1344 const int ref = vp9_rb_read_literal(rb, REF_FRAMES_LOG2); 1408 const int ref = vp9_rb_read_literal(rb, REF_FRAMES_LOG2);
1345 const int idx = cm->ref_frame_map[ref]; 1409 const int idx = cm->ref_frame_map[ref];
1346 RefBuffer *const ref_frame = &cm->frame_refs[i]; 1410 RefBuffer *const ref_frame = &cm->frame_refs[i];
1347 ref_frame->idx = idx; 1411 ref_frame->idx = idx;
1348 ref_frame->buf = &cm->frame_bufs[idx].buf; 1412 ref_frame->buf = &frame_bufs[idx].buf;
1349 cm->ref_frame_sign_bias[LAST_FRAME + i] = vp9_rb_read_bit(rb); 1413 cm->ref_frame_sign_bias[LAST_FRAME + i] = vp9_rb_read_bit(rb);
1350 } 1414 }
1351 1415
1352 setup_frame_size_with_refs(cm, rb); 1416 setup_frame_size_with_refs(cm, rb);
1353 1417
1354 cm->allow_high_precision_mv = vp9_rb_read_bit(rb); 1418 cm->allow_high_precision_mv = vp9_rb_read_bit(rb);
1355 cm->interp_filter = read_interp_filter(rb); 1419 cm->interp_filter = read_interp_filter(rb);
1356 1420
1357 for (i = 0; i < REFS_PER_FRAME; ++i) { 1421 for (i = 0; i < REFS_PER_FRAME; ++i) {
1358 RefBuffer *const ref_buf = &cm->frame_refs[i]; 1422 RefBuffer *const ref_buf = &cm->frame_refs[i];
1359 #if CONFIG_VP9_HIGHBITDEPTH 1423 #if CONFIG_VP9_HIGHBITDEPTH
1360 vp9_setup_scale_factors_for_frame(&ref_buf->sf, 1424 vp9_setup_scale_factors_for_frame(&ref_buf->sf,
1361 ref_buf->buf->y_crop_width, 1425 ref_buf->buf->y_crop_width,
1362 ref_buf->buf->y_crop_height, 1426 ref_buf->buf->y_crop_height,
1363 cm->width, cm->height, 1427 cm->width, cm->height,
1364 cm->use_highbitdepth); 1428 cm->use_highbitdepth);
1365 #else 1429 #else
1366 vp9_setup_scale_factors_for_frame(&ref_buf->sf, 1430 vp9_setup_scale_factors_for_frame(&ref_buf->sf,
1367 ref_buf->buf->y_crop_width, 1431 ref_buf->buf->y_crop_width,
1368 ref_buf->buf->y_crop_height, 1432 ref_buf->buf->y_crop_height,
1369 cm->width, cm->height); 1433 cm->width, cm->height);
1370 #endif 1434 #endif
1371 if (vp9_is_scaled(&ref_buf->sf))
1372 vp9_extend_frame_borders(ref_buf->buf);
1373 } 1435 }
1374 } 1436 }
1375 } 1437 }
1376 #if CONFIG_VP9_HIGHBITDEPTH 1438 #if CONFIG_VP9_HIGHBITDEPTH
1377 get_frame_new_buffer(cm)->bit_depth = cm->bit_depth; 1439 get_frame_new_buffer(cm)->bit_depth = cm->bit_depth;
1378 #endif 1440 #endif
1441 get_frame_new_buffer(cm)->color_space = cm->color_space;
1379 1442
1380 if (pbi->need_resync) { 1443 if (pbi->need_resync) {
1381 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, 1444 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
1382 "Keyframe / intra-only frame required to reset decoder" 1445 "Keyframe / intra-only frame required to reset decoder"
1383 " state"); 1446 " state");
1384 } 1447 }
1385 1448
1386 if (!cm->error_resilient_mode) { 1449 if (!cm->error_resilient_mode) {
1387 cm->refresh_frame_context = vp9_rb_read_bit(rb); 1450 cm->refresh_frame_context = vp9_rb_read_bit(rb);
1388 cm->frame_parallel_decoding_mode = vp9_rb_read_bit(rb); 1451 cm->frame_parallel_decoding_mode = vp9_rb_read_bit(rb);
1389 } else { 1452 } else {
1390 cm->refresh_frame_context = 0; 1453 cm->refresh_frame_context = 0;
1391 cm->frame_parallel_decoding_mode = 1; 1454 cm->frame_parallel_decoding_mode = 1;
1392 } 1455 }
1393 1456
1394 // This flag will be overridden by the call to vp9_setup_past_independence 1457 // This flag will be overridden by the call to vp9_setup_past_independence
1395 // below, forcing the use of context 0 for those frame types. 1458 // below, forcing the use of context 0 for those frame types.
1396 cm->frame_context_idx = vp9_rb_read_literal(rb, FRAME_CONTEXTS_LOG2); 1459 cm->frame_context_idx = vp9_rb_read_literal(rb, FRAME_CONTEXTS_LOG2);
1397 1460
1461 // Generate next_ref_frame_map.
1462 lock_buffer_pool(pool);
1463 for (mask = pbi->refresh_frame_flags; mask; mask >>= 1) {
1464 if (mask & 1) {
1465 cm->next_ref_frame_map[ref_index] = cm->new_fb_idx;
1466 ++frame_bufs[cm->new_fb_idx].ref_count;
1467 } else {
1468 cm->next_ref_frame_map[ref_index] = cm->ref_frame_map[ref_index];
1469 }
1470 // Current thread holds the reference frame.
1471 if (cm->ref_frame_map[ref_index] >= 0)
1472 ++frame_bufs[cm->ref_frame_map[ref_index]].ref_count;
1473 ++ref_index;
1474 }
1475
1476 for (; ref_index < REF_FRAMES; ++ref_index) {
1477 cm->next_ref_frame_map[ref_index] = cm->ref_frame_map[ref_index];
1478 // Current thread holds the reference frame.
1479 if (cm->ref_frame_map[ref_index] >= 0)
1480 ++frame_bufs[cm->ref_frame_map[ref_index]].ref_count;
1481 }
1482 unlock_buffer_pool(pool);
1483 pbi->hold_ref_buf = 1;
1484
1398 if (frame_is_intra_only(cm) || cm->error_resilient_mode) 1485 if (frame_is_intra_only(cm) || cm->error_resilient_mode)
1399 vp9_setup_past_independence(cm); 1486 vp9_setup_past_independence(cm);
1400 1487
1401 setup_loopfilter(&cm->lf, rb); 1488 setup_loopfilter(&cm->lf, rb);
1402 setup_quantization(cm, &pbi->mb, rb); 1489 setup_quantization(cm, &pbi->mb, rb);
1403 setup_segmentation(&cm->seg, rb); 1490 setup_segmentation(&cm->seg, rb);
1404 1491
1405 setup_tile_info(cm, rb); 1492 setup_tile_info(cm, rb);
1406 sz = vp9_rb_read_literal(rb, 16); 1493 sz = vp9_rb_read_literal(rb, 16);
1407 1494
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1457 for (j = 0; j < PARTITION_CONTEXTS; ++j) 1544 for (j = 0; j < PARTITION_CONTEXTS; ++j)
1458 for (i = 0; i < PARTITION_TYPES - 1; ++i) 1545 for (i = 0; i < PARTITION_TYPES - 1; ++i)
1459 vp9_diff_update_prob(&r, &fc->partition_prob[j][i]); 1546 vp9_diff_update_prob(&r, &fc->partition_prob[j][i]);
1460 1547
1461 read_mv_probs(nmvc, cm->allow_high_precision_mv, &r); 1548 read_mv_probs(nmvc, cm->allow_high_precision_mv, &r);
1462 } 1549 }
1463 1550
1464 return vp9_reader_has_error(&r); 1551 return vp9_reader_has_error(&r);
1465 } 1552 }
1466 1553
1467 void vp9_init_dequantizer(VP9_COMMON *cm) {
1468 int q;
1469
1470 for (q = 0; q < QINDEX_RANGE; q++) {
1471 cm->y_dequant[q][0] = vp9_dc_quant(q, cm->y_dc_delta_q, cm->bit_depth);
1472 cm->y_dequant[q][1] = vp9_ac_quant(q, 0, cm->bit_depth);
1473
1474 cm->uv_dequant[q][0] = vp9_dc_quant(q, cm->uv_dc_delta_q, cm->bit_depth);
1475 cm->uv_dequant[q][1] = vp9_ac_quant(q, cm->uv_ac_delta_q, cm->bit_depth);
1476 }
1477 }
1478
1479 #ifdef NDEBUG 1554 #ifdef NDEBUG
1480 #define debug_check_frame_counts(cm) (void)0 1555 #define debug_check_frame_counts(cm) (void)0
1481 #else // !NDEBUG 1556 #else // !NDEBUG
1482 // Counts should only be incremented when frame_parallel_decoding_mode and 1557 // Counts should only be incremented when frame_parallel_decoding_mode and
1483 // error_resilient_mode are disabled. 1558 // error_resilient_mode are disabled.
1484 static void debug_check_frame_counts(const VP9_COMMON *const cm) { 1559 static void debug_check_frame_counts(const VP9_COMMON *const cm) {
1485 FRAME_COUNTS zero_counts; 1560 FRAME_COUNTS zero_counts;
1486 vp9_zero(zero_counts); 1561 vp9_zero(zero_counts);
1487 assert(cm->frame_parallel_decoding_mode || cm->error_resilient_mode); 1562 assert(cm->frame_parallel_decoding_mode || cm->error_resilient_mode);
1488 assert(!memcmp(cm->counts.y_mode, zero_counts.y_mode, 1563 assert(!memcmp(cm->counts.y_mode, zero_counts.y_mode,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1533 } 1608 }
1534 return rb; 1609 return rb;
1535 } 1610 }
1536 1611
1537 void vp9_decode_frame(VP9Decoder *pbi, 1612 void vp9_decode_frame(VP9Decoder *pbi,
1538 const uint8_t *data, const uint8_t *data_end, 1613 const uint8_t *data, const uint8_t *data_end,
1539 const uint8_t **p_data_end) { 1614 const uint8_t **p_data_end) {
1540 VP9_COMMON *const cm = &pbi->common; 1615 VP9_COMMON *const cm = &pbi->common;
1541 MACROBLOCKD *const xd = &pbi->mb; 1616 MACROBLOCKD *const xd = &pbi->mb;
1542 struct vp9_read_bit_buffer rb = { NULL, NULL, 0, NULL, 0}; 1617 struct vp9_read_bit_buffer rb = { NULL, NULL, 0, NULL, 0};
1543 1618 int context_updated = 0;
1544 uint8_t clear_data[MAX_VP9_HEADER_SIZE]; 1619 uint8_t clear_data[MAX_VP9_HEADER_SIZE];
1545 const size_t first_partition_size = read_uncompressed_header(pbi, 1620 const size_t first_partition_size = read_uncompressed_header(pbi,
1546 init_read_bit_buffer(pbi, &rb, data, data_end, clear_data)); 1621 init_read_bit_buffer(pbi, &rb, data, data_end, clear_data));
1547 const int tile_rows = 1 << cm->log2_tile_rows; 1622 const int tile_rows = 1 << cm->log2_tile_rows;
1548 const int tile_cols = 1 << cm->log2_tile_cols; 1623 const int tile_cols = 1 << cm->log2_tile_cols;
1549 YV12_BUFFER_CONFIG *const new_fb = get_frame_new_buffer(cm); 1624 YV12_BUFFER_CONFIG *const new_fb = get_frame_new_buffer(cm);
1550 xd->cur_buf = new_fb; 1625 xd->cur_buf = new_fb;
1551 1626
1552 if (!first_partition_size) { 1627 if (!first_partition_size) {
1553 // showing a frame directly 1628 // showing a frame directly
1554 *p_data_end = data + (cm->profile <= PROFILE_2 ? 1 : 2); 1629 *p_data_end = data + (cm->profile <= PROFILE_2 ? 1 : 2);
1555 return; 1630 return;
1556 } 1631 }
1557 1632
1558 data += vp9_rb_bytes_read(&rb); 1633 data += vp9_rb_bytes_read(&rb);
1559 if (!read_is_valid(data, first_partition_size, data_end)) 1634 if (!read_is_valid(data, first_partition_size, data_end))
1560 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, 1635 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
1561 "Truncated packet or corrupt header length"); 1636 "Truncated packet or corrupt header length");
1562 1637
1563 cm->use_prev_frame_mvs = !cm->error_resilient_mode && 1638 cm->use_prev_frame_mvs = !cm->error_resilient_mode &&
1564 cm->width == cm->last_width && 1639 cm->width == cm->last_width &&
1565 cm->height == cm->last_height && 1640 cm->height == cm->last_height &&
1566 !cm->intra_only && 1641 !cm->intra_only &&
1567 cm->last_show_frame; 1642 cm->last_show_frame;
1568 1643
1569 setup_plane_dequants(cm, xd, cm->base_qindex);
1570 vp9_setup_block_planes(xd, cm->subsampling_x, cm->subsampling_y); 1644 vp9_setup_block_planes(xd, cm->subsampling_x, cm->subsampling_y);
1571 1645
1572 *cm->fc = cm->frame_contexts[cm->frame_context_idx]; 1646 *cm->fc = cm->frame_contexts[cm->frame_context_idx];
1573 if (!cm->fc->initialized) 1647 if (!cm->fc->initialized)
1574 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, 1648 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
1575 "Uninitialized entropy context."); 1649 "Uninitialized entropy context.");
1576 1650
1577 vp9_zero(cm->counts); 1651 vp9_zero(cm->counts);
1578 1652
1579 xd->corrupted = 0; 1653 xd->corrupted = 0;
1580 new_fb->corrupted = read_compressed_header(pbi, data, first_partition_size); 1654 new_fb->corrupted = read_compressed_header(pbi, data, first_partition_size);
1581 if (new_fb->corrupted) 1655 if (new_fb->corrupted)
1582 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, 1656 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
1583 "Decode failed. Frame data header is corrupted."); 1657 "Decode failed. Frame data header is corrupted.");
1584 1658
1585 // TODO(jzern): remove frame_parallel_decoding_mode restriction for 1659 if (cm->lf.filter_level) {
1586 // single-frame tile decoding. 1660 vp9_loop_filter_frame_init(cm, cm->lf.filter_level);
1587 if (pbi->max_threads > 1 && tile_rows == 1 && tile_cols > 1 && 1661 }
1588 cm->frame_parallel_decoding_mode) { 1662
1663 // If encoded in frame parallel mode, frame context is ready after decoding
1664 // the frame header.
1665 if (pbi->frame_parallel_decode && cm->frame_parallel_decoding_mode) {
1666 VP9Worker *const worker = pbi->frame_worker_owner;
1667 FrameWorkerData *const frame_worker_data = worker->data1;
1668 if (cm->refresh_frame_context) {
1669 context_updated = 1;
1670 cm->frame_contexts[cm->frame_context_idx] = *cm->fc;
1671 }
1672 vp9_frameworker_lock_stats(worker);
1673 pbi->cur_buf->row = -1;
1674 pbi->cur_buf->col = -1;
1675 frame_worker_data->frame_context_ready = 1;
1676 // Signal the main thread that context is ready.
1677 vp9_frameworker_signal_stats(worker);
1678 vp9_frameworker_unlock_stats(worker);
1679 }
1680
1681 if (pbi->max_threads > 1 && tile_rows == 1 && tile_cols > 1) {
1682 // Multi-threaded tile decoder
1589 *p_data_end = decode_tiles_mt(pbi, data + first_partition_size, data_end); 1683 *p_data_end = decode_tiles_mt(pbi, data + first_partition_size, data_end);
1590 if (!xd->corrupted) { 1684 if (!xd->corrupted) {
1591 // If multiple threads are used to decode tiles, then we use those threads 1685 // If multiple threads are used to decode tiles, then we use those threads
1592 // to do parallel loopfiltering. 1686 // to do parallel loopfiltering.
1593 vp9_loop_filter_frame_mt(new_fb, cm, pbi->mb.plane, cm->lf.filter_level, 1687 vp9_loop_filter_frame_mt(new_fb, cm, pbi->mb.plane, cm->lf.filter_level,
1594 0, 0, pbi->tile_workers, pbi->num_tile_workers, 1688 0, 0, pbi->tile_workers, pbi->num_tile_workers,
1595 &pbi->lf_row_sync); 1689 &pbi->lf_row_sync);
1596 } else { 1690 } else {
1597 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, 1691 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
1598 "Decode failed. Frame data is corrupted."); 1692 "Decode failed. Frame data is corrupted.");
1599 1693
1600 } 1694 }
1601 } else { 1695 } else {
1602 *p_data_end = decode_tiles(pbi, data + first_partition_size, data_end); 1696 *p_data_end = decode_tiles(pbi, data + first_partition_size, data_end);
1603 } 1697 }
1604 1698
1605 new_fb->corrupted |= xd->corrupted; 1699 if (!xd->corrupted) {
1606
1607 if (!new_fb->corrupted) {
1608 if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) { 1700 if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) {
1609 vp9_adapt_coef_probs(cm); 1701 vp9_adapt_coef_probs(cm);
1610 1702
1611 if (!frame_is_intra_only(cm)) { 1703 if (!frame_is_intra_only(cm)) {
1612 vp9_adapt_mode_probs(cm); 1704 vp9_adapt_mode_probs(cm);
1613 vp9_adapt_mv_probs(cm, cm->allow_high_precision_mv); 1705 vp9_adapt_mv_probs(cm, cm->allow_high_precision_mv);
1614 } 1706 }
1615 } else { 1707 } else {
1616 debug_check_frame_counts(cm); 1708 debug_check_frame_counts(cm);
1617 } 1709 }
1618 } else { 1710 } else {
1619 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, 1711 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
1620 "Decode failed. Frame data is corrupted."); 1712 "Decode failed. Frame data is corrupted.");
1621 } 1713 }
1622 1714
1623 if (cm->refresh_frame_context) 1715 // Non frame parallel update frame context here.
1716 if (cm->refresh_frame_context && !context_updated)
1624 cm->frame_contexts[cm->frame_context_idx] = *cm->fc; 1717 cm->frame_contexts[cm->frame_context_idx] = *cm->fc;
1625 } 1718 }
1719
1720 static void build_mc_border(const uint8_t *src, int src_stride,
1721 uint8_t *dst, int dst_stride,
1722 int x, int y, int b_w, int b_h, int w, int h) {
1723 // Get a pointer to the start of the real data for this row.
1724 const uint8_t *ref_row = src - x - y * src_stride;
1725
1726 if (y >= h)
1727 ref_row += (h - 1) * src_stride;
1728 else if (y > 0)
1729 ref_row += y * src_stride;
1730
1731 do {
1732 int right = 0, copy;
1733 int left = x < 0 ? -x : 0;
1734
1735 if (left > b_w)
1736 left = b_w;
1737
1738 if (x + b_w > w)
1739 right = x + b_w - w;
1740
1741 if (right > b_w)
1742 right = b_w;
1743
1744 copy = b_w - left - right;
1745
1746 if (left)
1747 memset(dst, ref_row[0], left);
1748
1749 if (copy)
1750 memcpy(dst + left, ref_row + x + left, copy);
1751
1752 if (right)
1753 memset(dst + left + copy, ref_row[w - 1], right);
1754
1755 dst += dst_stride;
1756 ++y;
1757
1758 if (y > 0 && y < h)
1759 ref_row += src_stride;
1760 } while (--b_h);
1761 }
1762
1763 #if CONFIG_VP9_HIGHBITDEPTH
1764 static void high_build_mc_border(const uint8_t *src8, int src_stride,
1765 uint16_t *dst, int dst_stride,
1766 int x, int y, int b_w, int b_h,
1767 int w, int h) {
1768 // Get a pointer to the start of the real data for this row.
1769 const uint16_t *src = CONVERT_TO_SHORTPTR(src8);
1770 const uint16_t *ref_row = src - x - y * src_stride;
1771
1772 if (y >= h)
1773 ref_row += (h - 1) * src_stride;
1774 else if (y > 0)
1775 ref_row += y * src_stride;
1776
1777 do {
1778 int right = 0, copy;
1779 int left = x < 0 ? -x : 0;
1780
1781 if (left > b_w)
1782 left = b_w;
1783
1784 if (x + b_w > w)
1785 right = x + b_w - w;
1786
1787 if (right > b_w)
1788 right = b_w;
1789
1790 copy = b_w - left - right;
1791
1792 if (left)
1793 vpx_memset16(dst, ref_row[0], left);
1794
1795 if (copy)
1796 memcpy(dst + left, ref_row + x + left, copy * sizeof(uint16_t));
1797
1798 if (right)
1799 vpx_memset16(dst + left + copy, ref_row[w - 1], right);
1800
1801 dst += dst_stride;
1802 ++y;
1803
1804 if (y > 0 && y < h)
1805 ref_row += src_stride;
1806 } while (--b_h);
1807 }
1808 #endif // CONFIG_VP9_HIGHBITDEPTH
1809
1810 void dec_build_inter_predictors(VP9Decoder *const pbi, MACROBLOCKD *xd,
1811 int plane, int block, int bw, int bh, int x,
1812 int y, int w, int h, int mi_x, int mi_y) {
1813 struct macroblockd_plane *const pd = &xd->plane[plane];
1814 const MODE_INFO *mi = xd->mi[0].src_mi;
1815 const int is_compound = has_second_ref(&mi->mbmi);
1816 const InterpKernel *kernel = vp9_get_interp_kernel(mi->mbmi.interp_filter);
1817 int ref;
1818
1819 for (ref = 0; ref < 1 + is_compound; ++ref) {
1820 const struct scale_factors *const sf = &xd->block_refs[ref]->sf;
1821 struct buf_2d *const pre_buf = &pd->pre[ref];
1822 struct buf_2d *const dst_buf = &pd->dst;
1823 uint8_t *const dst = dst_buf->buf + dst_buf->stride * y + x;
1824 const MV mv = mi->mbmi.sb_type < BLOCK_8X8
1825 ? average_split_mvs(pd, mi, ref, block)
1826 : mi->mbmi.mv[ref].as_mv;
1827
1828 const MV mv_q4 = clamp_mv_to_umv_border_sb(xd, &mv, bw, bh,
1829 pd->subsampling_x,
1830 pd->subsampling_y);
1831
1832 MV32 scaled_mv;
1833 int xs, ys, x0, y0, x0_16, y0_16, y1, frame_width, frame_height,
1834 buf_stride, subpel_x, subpel_y;
1835 uint8_t *ref_frame, *buf_ptr;
1836 const int idx = xd->block_refs[ref]->idx;
1837 BufferPool *const pool = pbi->common.buffer_pool;
1838 RefCntBuffer *const ref_frame_buf = &pool->frame_bufs[idx];
1839 const int is_scaled = vp9_is_scaled(sf);
1840
1841 // Get reference frame pointer, width and height.
1842 if (plane == 0) {
1843 frame_width = ref_frame_buf->buf.y_crop_width;
1844 frame_height = ref_frame_buf->buf.y_crop_height;
1845 ref_frame = ref_frame_buf->buf.y_buffer;
1846 } else {
1847 frame_width = ref_frame_buf->buf.uv_crop_width;
1848 frame_height = ref_frame_buf->buf.uv_crop_height;
1849 ref_frame = plane == 1 ? ref_frame_buf->buf.u_buffer
1850 : ref_frame_buf->buf.v_buffer;
1851 }
1852
1853 if (is_scaled) {
1854 // Co-ordinate of containing block to pixel precision.
1855 int x_start = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x));
1856 int y_start = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y));
1857
1858 // Co-ordinate of the block to 1/16th pixel precision.
1859 x0_16 = (x_start + x) << SUBPEL_BITS;
1860 y0_16 = (y_start + y) << SUBPEL_BITS;
1861
1862 // Co-ordinate of current block in reference frame
1863 // to 1/16th pixel precision.
1864 x0_16 = sf->scale_value_x(x0_16, sf);
1865 y0_16 = sf->scale_value_y(y0_16, sf);
1866
1867 // Map the top left corner of the block into the reference frame.
1868 x0 = sf->scale_value_x(x_start + x, sf);
1869 y0 = sf->scale_value_y(y_start + y, sf);
1870
1871 // Scale the MV and incorporate the sub-pixel offset of the block
1872 // in the reference frame.
1873 scaled_mv = vp9_scale_mv(&mv_q4, mi_x + x, mi_y + y, sf);
1874 xs = sf->x_step_q4;
1875 ys = sf->y_step_q4;
1876 } else {
1877 // Co-ordinate of containing block to pixel precision.
1878 x0 = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x)) + x;
1879 y0 = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y)) + y;
1880
1881 // Co-ordinate of the block to 1/16th pixel precision.
1882 x0_16 = x0 << SUBPEL_BITS;
1883 y0_16 = y0 << SUBPEL_BITS;
1884
1885 scaled_mv.row = mv_q4.row;
1886 scaled_mv.col = mv_q4.col;
1887 xs = ys = 16;
1888 }
1889 subpel_x = scaled_mv.col & SUBPEL_MASK;
1890 subpel_y = scaled_mv.row & SUBPEL_MASK;
1891
1892 // Calculate the top left corner of the best matching block in the
1893 // reference frame.
1894 x0 += scaled_mv.col >> SUBPEL_BITS;
1895 y0 += scaled_mv.row >> SUBPEL_BITS;
1896 x0_16 += scaled_mv.col;
1897 y0_16 += scaled_mv.row;
1898
1899 // Get reference block pointer.
1900 buf_ptr = ref_frame + y0 * pre_buf->stride + x0;
1901 buf_stride = pre_buf->stride;
1902
1903 // Get reference block bottom right vertical coordinate.
1904 y1 = ((y0_16 + (h - 1) * ys) >> SUBPEL_BITS) + 1;
1905
1906 // Do border extension if there is motion or the
1907 // width/height is not a multiple of 8 pixels.
1908 if (is_scaled || scaled_mv.col || scaled_mv.row ||
1909 (frame_width & 0x7) || (frame_height & 0x7)) {
1910 // Get reference block bottom right horizontal coordinate.
1911 int x1 = ((x0_16 + (w - 1) * xs) >> SUBPEL_BITS) + 1;
1912 int x_pad = 0, y_pad = 0;
1913
1914 if (subpel_x || (sf->x_step_q4 != SUBPEL_SHIFTS)) {
1915 x0 -= VP9_INTERP_EXTEND - 1;
1916 x1 += VP9_INTERP_EXTEND;
1917 x_pad = 1;
1918 }
1919
1920 if (subpel_y || (sf->y_step_q4 != SUBPEL_SHIFTS)) {
1921 y0 -= VP9_INTERP_EXTEND - 1;
1922 y1 += VP9_INTERP_EXTEND;
1923 y_pad = 1;
1924 }
1925
1926 // Wait until reference block is ready. Pad 7 more pixels as last 7
1927 // pixels of each superblock row can be changed by next superblock row.
1928 if (pbi->frame_parallel_decode)
1929 vp9_frameworker_wait(pbi->frame_worker_owner, ref_frame_buf,
1930 (y1 + 7) << (plane == 0 ? 0 : 1));
1931
1932 // Skip border extension if block is inside the frame.
1933 if (x0 < 0 || x0 > frame_width - 1 || x1 < 0 || x1 > frame_width - 1 ||
1934 y0 < 0 || y0 > frame_height - 1 || y1 < 0 || y1 > frame_height - 1) {
1935 uint8_t *buf_ptr1 = ref_frame + y0 * pre_buf->stride + x0;
1936 // Extend the border.
1937 #if CONFIG_VP9_HIGHBITDEPTH
1938 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
1939 high_build_mc_border(buf_ptr1,
1940 pre_buf->stride,
1941 xd->mc_buf_high,
1942 x1 - x0 + 1,
1943 x0,
1944 y0,
1945 x1 - x0 + 1,
1946 y1 - y0 + 1,
1947 frame_width,
1948 frame_height);
1949 buf_stride = x1 - x0 + 1;
1950 buf_ptr = CONVERT_TO_BYTEPTR(xd->mc_buf_high) +
1951 y_pad * 3 * buf_stride + x_pad * 3;
1952 } else {
1953 build_mc_border(buf_ptr1,
1954 pre_buf->stride,
1955 xd->mc_buf,
1956 x1 - x0 + 1,
1957 x0,
1958 y0,
1959 x1 - x0 + 1,
1960 y1 - y0 + 1,
1961 frame_width,
1962 frame_height);
1963 buf_stride = x1 - x0 + 1;
1964 buf_ptr = xd->mc_buf + y_pad * 3 * buf_stride + x_pad * 3;
1965 }
1966 #else
1967 build_mc_border(buf_ptr1,
1968 pre_buf->stride,
1969 xd->mc_buf,
1970 x1 - x0 + 1,
1971 x0,
1972 y0,
1973 x1 - x0 + 1,
1974 y1 - y0 + 1,
1975 frame_width,
1976 frame_height);
1977 buf_stride = x1 - x0 + 1;
1978 buf_ptr = xd->mc_buf + y_pad * 3 * buf_stride + x_pad * 3;
1979 #endif // CONFIG_VP9_HIGHBITDEPTH
1980 }
1981 } else {
1982 // Wait until reference block is ready. Pad 7 more pixels as last 7
1983 // pixels of each superblock row can be changed by next superblock row.
1984 if (pbi->frame_parallel_decode)
1985 vp9_frameworker_wait(pbi->frame_worker_owner, ref_frame_buf,
1986 (y1 + 7) << (plane == 0 ? 0 : 1));
1987 }
1988 #if CONFIG_VP9_HIGHBITDEPTH
1989 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
1990 high_inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x,
1991 subpel_y, sf, w, h, ref, kernel, xs, ys, xd->bd);
1992 } else {
1993 inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x,
1994 subpel_y, sf, w, h, ref, kernel, xs, ys);
1995 }
1996 #else
1997 inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x,
1998 subpel_y, sf, w, h, ref, kernel, xs, ys);
1999 #endif // CONFIG_VP9_HIGHBITDEPTH
2000 }
2001 }
2002
2003 void vp9_dec_build_inter_predictors_sb(VP9Decoder *const pbi, MACROBLOCKD *xd,
2004 int mi_row, int mi_col,
2005 BLOCK_SIZE bsize) {
2006 int plane;
2007 const int mi_x = mi_col * MI_SIZE;
2008 const int mi_y = mi_row * MI_SIZE;
2009 for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
2010 const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize,
2011 &xd->plane[plane]);
2012 const int num_4x4_w = num_4x4_blocks_wide_lookup[plane_bsize];
2013 const int num_4x4_h = num_4x4_blocks_high_lookup[plane_bsize];
2014 const int bw = 4 * num_4x4_w;
2015 const int bh = 4 * num_4x4_h;
2016
2017 if (xd->mi[0].src_mi->mbmi.sb_type < BLOCK_8X8) {
2018 int i = 0, x, y;
2019 assert(bsize == BLOCK_8X8);
2020 for (y = 0; y < num_4x4_h; ++y)
2021 for (x = 0; x < num_4x4_w; ++x)
2022 dec_build_inter_predictors(pbi, xd, plane, i++, bw, bh,
2023 4 * x, 4 * y, 4, 4, mi_x, mi_y);
2024 } else {
2025 dec_build_inter_predictors(pbi, xd, plane, 0, bw, bh,
2026 0, 0, bw, bh, mi_x, mi_y);
2027 }
2028 }
2029 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/decoder/vp9_decodeframe.h ('k') | source/libvpx/vp9/decoder/vp9_decodemv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698