| OLD | NEW |
| 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 |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 int x, y, eob; | 339 int x, y, eob; |
| 340 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x, &y); | 340 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x, &y); |
| 341 eob = vp9_decode_block_tokens(xd, plane, block, plane_bsize, | 341 eob = vp9_decode_block_tokens(xd, plane, block, plane_bsize, |
| 342 x, y, tx_size, args->r, args->seg_id); | 342 x, y, tx_size, args->r, args->seg_id); |
| 343 inverse_transform_block(xd, plane, block, tx_size, | 343 inverse_transform_block(xd, plane, block, tx_size, |
| 344 &pd->dst.buf[4 * y * pd->dst.stride + 4 * x], | 344 &pd->dst.buf[4 * y * pd->dst.stride + 4 * x], |
| 345 pd->dst.stride, eob); | 345 pd->dst.stride, eob); |
| 346 *args->eobtotal += eob; | 346 *args->eobtotal += eob; |
| 347 } | 347 } |
| 348 | 348 |
| 349 static void build_mc_border(const uint8_t *src, int src_stride, |
| 350 uint8_t *dst, int dst_stride, |
| 351 int x, int y, int b_w, int b_h, int w, int h) { |
| 352 // Get a pointer to the start of the real data for this row. |
| 353 const uint8_t *ref_row = src - x - y * src_stride; |
| 354 |
| 355 if (y >= h) |
| 356 ref_row += (h - 1) * src_stride; |
| 357 else if (y > 0) |
| 358 ref_row += y * src_stride; |
| 359 |
| 360 do { |
| 361 int right = 0, copy; |
| 362 int left = x < 0 ? -x : 0; |
| 363 |
| 364 if (left > b_w) |
| 365 left = b_w; |
| 366 |
| 367 if (x + b_w > w) |
| 368 right = x + b_w - w; |
| 369 |
| 370 if (right > b_w) |
| 371 right = b_w; |
| 372 |
| 373 copy = b_w - left - right; |
| 374 |
| 375 if (left) |
| 376 memset(dst, ref_row[0], left); |
| 377 |
| 378 if (copy) |
| 379 memcpy(dst + left, ref_row + x + left, copy); |
| 380 |
| 381 if (right) |
| 382 memset(dst + left + copy, ref_row[w - 1], right); |
| 383 |
| 384 dst += dst_stride; |
| 385 ++y; |
| 386 |
| 387 if (y > 0 && y < h) |
| 388 ref_row += src_stride; |
| 389 } while (--b_h); |
| 390 } |
| 391 |
| 392 #if CONFIG_VP9_HIGHBITDEPTH |
| 393 static void high_build_mc_border(const uint8_t *src8, int src_stride, |
| 394 uint16_t *dst, int dst_stride, |
| 395 int x, int y, int b_w, int b_h, |
| 396 int w, int h) { |
| 397 // Get a pointer to the start of the real data for this row. |
| 398 const uint16_t *src = CONVERT_TO_SHORTPTR(src8); |
| 399 const uint16_t *ref_row = src - x - y * src_stride; |
| 400 |
| 401 if (y >= h) |
| 402 ref_row += (h - 1) * src_stride; |
| 403 else if (y > 0) |
| 404 ref_row += y * src_stride; |
| 405 |
| 406 do { |
| 407 int right = 0, copy; |
| 408 int left = x < 0 ? -x : 0; |
| 409 |
| 410 if (left > b_w) |
| 411 left = b_w; |
| 412 |
| 413 if (x + b_w > w) |
| 414 right = x + b_w - w; |
| 415 |
| 416 if (right > b_w) |
| 417 right = b_w; |
| 418 |
| 419 copy = b_w - left - right; |
| 420 |
| 421 if (left) |
| 422 vpx_memset16(dst, ref_row[0], left); |
| 423 |
| 424 if (copy) |
| 425 memcpy(dst + left, ref_row + x + left, copy * sizeof(uint16_t)); |
| 426 |
| 427 if (right) |
| 428 vpx_memset16(dst + left + copy, ref_row[w - 1], right); |
| 429 |
| 430 dst += dst_stride; |
| 431 ++y; |
| 432 |
| 433 if (y > 0 && y < h) |
| 434 ref_row += src_stride; |
| 435 } while (--b_h); |
| 436 } |
| 437 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 438 |
| 439 #if CONFIG_VP9_HIGHBITDEPTH |
| 440 static void extend_and_predict(const uint8_t *buf_ptr1, int pre_buf_stride, |
| 441 int x0, int y0, int b_w, int b_h, |
| 442 int frame_width, int frame_height, |
| 443 int border_offset, |
| 444 uint8_t *const dst, int dst_buf_stride, |
| 445 int subpel_x, int subpel_y, |
| 446 const InterpKernel *kernel, |
| 447 const struct scale_factors *sf, |
| 448 MACROBLOCKD *xd, |
| 449 int w, int h, int ref, int xs, int ys) { |
| 450 DECLARE_ALIGNED(16, uint16_t, mc_buf_high[80 * 2 * 80 * 2]); |
| 451 const uint8_t *buf_ptr; |
| 452 |
| 453 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 454 high_build_mc_border(buf_ptr1, pre_buf_stride, mc_buf_high, b_w, |
| 455 x0, y0, b_w, b_h, frame_width, frame_height); |
| 456 buf_ptr = CONVERT_TO_BYTEPTR(mc_buf_high) + border_offset; |
| 457 } else { |
| 458 build_mc_border(buf_ptr1, pre_buf_stride, (uint8_t *)mc_buf_high, b_w, |
| 459 x0, y0, b_w, b_h, frame_width, frame_height); |
| 460 buf_ptr = ((uint8_t *)mc_buf_high) + border_offset; |
| 461 } |
| 462 |
| 463 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 464 high_inter_predictor(buf_ptr, b_w, dst, dst_buf_stride, subpel_x, |
| 465 subpel_y, sf, w, h, ref, kernel, xs, ys, xd->bd); |
| 466 } else { |
| 467 inter_predictor(buf_ptr, b_w, dst, dst_buf_stride, subpel_x, |
| 468 subpel_y, sf, w, h, ref, kernel, xs, ys); |
| 469 } |
| 470 } |
| 471 #else |
| 472 static void extend_and_predict(const uint8_t *buf_ptr1, int pre_buf_stride, |
| 473 int x0, int y0, int b_w, int b_h, |
| 474 int frame_width, int frame_height, |
| 475 int border_offset, |
| 476 uint8_t *const dst, int dst_buf_stride, |
| 477 int subpel_x, int subpel_y, |
| 478 const InterpKernel *kernel, |
| 479 const struct scale_factors *sf, |
| 480 int w, int h, int ref, int xs, int ys) { |
| 481 DECLARE_ALIGNED(16, uint8_t, mc_buf[80 * 2 * 80 * 2]); |
| 482 const uint8_t *buf_ptr; |
| 483 |
| 484 build_mc_border(buf_ptr1, pre_buf_stride, mc_buf, b_w, |
| 485 x0, y0, b_w, b_h, frame_width, frame_height); |
| 486 buf_ptr = mc_buf + border_offset; |
| 487 |
| 488 inter_predictor(buf_ptr, b_w, dst, dst_buf_stride, subpel_x, |
| 489 subpel_y, sf, w, h, ref, kernel, xs, ys); |
| 490 } |
| 491 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 492 |
| 493 static void dec_build_inter_predictors(VP9Decoder *const pbi, MACROBLOCKD *xd, |
| 494 int plane, int bw, int bh, int x, |
| 495 int y, int w, int h, int mi_x, int mi_y, |
| 496 const InterpKernel *kernel, |
| 497 const struct scale_factors *sf, |
| 498 struct buf_2d *pre_buf, |
| 499 struct buf_2d *dst_buf, const MV* mv, |
| 500 RefCntBuffer *ref_frame_buf, |
| 501 int is_scaled, int ref) { |
| 502 struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 503 uint8_t *const dst = dst_buf->buf + dst_buf->stride * y + x; |
| 504 MV32 scaled_mv; |
| 505 int xs, ys, x0, y0, x0_16, y0_16, frame_width, frame_height, |
| 506 buf_stride, subpel_x, subpel_y; |
| 507 uint8_t *ref_frame, *buf_ptr; |
| 508 |
| 509 // Get reference frame pointer, width and height. |
| 510 if (plane == 0) { |
| 511 frame_width = ref_frame_buf->buf.y_crop_width; |
| 512 frame_height = ref_frame_buf->buf.y_crop_height; |
| 513 ref_frame = ref_frame_buf->buf.y_buffer; |
| 514 } else { |
| 515 frame_width = ref_frame_buf->buf.uv_crop_width; |
| 516 frame_height = ref_frame_buf->buf.uv_crop_height; |
| 517 ref_frame = plane == 1 ? ref_frame_buf->buf.u_buffer |
| 518 : ref_frame_buf->buf.v_buffer; |
| 519 } |
| 520 |
| 521 if (is_scaled) { |
| 522 const MV mv_q4 = clamp_mv_to_umv_border_sb(xd, mv, bw, bh, |
| 523 pd->subsampling_x, |
| 524 pd->subsampling_y); |
| 525 // Co-ordinate of containing block to pixel precision. |
| 526 int x_start = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x)); |
| 527 int y_start = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y)); |
| 528 |
| 529 // Co-ordinate of the block to 1/16th pixel precision. |
| 530 x0_16 = (x_start + x) << SUBPEL_BITS; |
| 531 y0_16 = (y_start + y) << SUBPEL_BITS; |
| 532 |
| 533 // Co-ordinate of current block in reference frame |
| 534 // to 1/16th pixel precision. |
| 535 x0_16 = sf->scale_value_x(x0_16, sf); |
| 536 y0_16 = sf->scale_value_y(y0_16, sf); |
| 537 |
| 538 // Map the top left corner of the block into the reference frame. |
| 539 x0 = sf->scale_value_x(x_start + x, sf); |
| 540 y0 = sf->scale_value_y(y_start + y, sf); |
| 541 |
| 542 // Scale the MV and incorporate the sub-pixel offset of the block |
| 543 // in the reference frame. |
| 544 scaled_mv = vp9_scale_mv(&mv_q4, mi_x + x, mi_y + y, sf); |
| 545 xs = sf->x_step_q4; |
| 546 ys = sf->y_step_q4; |
| 547 } else { |
| 548 // Co-ordinate of containing block to pixel precision. |
| 549 x0 = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x)) + x; |
| 550 y0 = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y)) + y; |
| 551 |
| 552 // Co-ordinate of the block to 1/16th pixel precision. |
| 553 x0_16 = x0 << SUBPEL_BITS; |
| 554 y0_16 = y0 << SUBPEL_BITS; |
| 555 |
| 556 scaled_mv.row = mv->row * (1 << (1 - pd->subsampling_y)); |
| 557 scaled_mv.col = mv->col * (1 << (1 - pd->subsampling_x)); |
| 558 xs = ys = 16; |
| 559 } |
| 560 subpel_x = scaled_mv.col & SUBPEL_MASK; |
| 561 subpel_y = scaled_mv.row & SUBPEL_MASK; |
| 562 |
| 563 // Calculate the top left corner of the best matching block in the |
| 564 // reference frame. |
| 565 x0 += scaled_mv.col >> SUBPEL_BITS; |
| 566 y0 += scaled_mv.row >> SUBPEL_BITS; |
| 567 x0_16 += scaled_mv.col; |
| 568 y0_16 += scaled_mv.row; |
| 569 |
| 570 // Get reference block pointer. |
| 571 buf_ptr = ref_frame + y0 * pre_buf->stride + x0; |
| 572 buf_stride = pre_buf->stride; |
| 573 |
| 574 // Do border extension if there is motion or the |
| 575 // width/height is not a multiple of 8 pixels. |
| 576 if (is_scaled || scaled_mv.col || scaled_mv.row || |
| 577 (frame_width & 0x7) || (frame_height & 0x7)) { |
| 578 int y1 = (y0_16 + (h - 1) * ys) >> SUBPEL_BITS; |
| 579 |
| 580 // Get reference block bottom right horizontal coordinate. |
| 581 int x1 = (x0_16 + (w - 1) * xs) >> SUBPEL_BITS; |
| 582 int x_pad = 0, y_pad = 0; |
| 583 |
| 584 if (subpel_x || (sf->x_step_q4 != SUBPEL_SHIFTS)) { |
| 585 x0 -= VP9_INTERP_EXTEND - 1; |
| 586 x1 += VP9_INTERP_EXTEND; |
| 587 x_pad = 1; |
| 588 } |
| 589 |
| 590 if (subpel_y || (sf->y_step_q4 != SUBPEL_SHIFTS)) { |
| 591 y0 -= VP9_INTERP_EXTEND - 1; |
| 592 y1 += VP9_INTERP_EXTEND; |
| 593 y_pad = 1; |
| 594 } |
| 595 |
| 596 // Wait until reference block is ready. Pad 7 more pixels as last 7 |
| 597 // pixels of each superblock row can be changed by next superblock row. |
| 598 if (pbi->frame_parallel_decode) |
| 599 vp9_frameworker_wait(pbi->frame_worker_owner, ref_frame_buf, |
| 600 MAX(0, (y1 + 7)) << (plane == 0 ? 0 : 1)); |
| 601 |
| 602 // Skip border extension if block is inside the frame. |
| 603 if (x0 < 0 || x0 > frame_width - 1 || x1 < 0 || x1 > frame_width - 1 || |
| 604 y0 < 0 || y0 > frame_height - 1 || y1 < 0 || y1 > frame_height - 1) { |
| 605 // Extend the border. |
| 606 const uint8_t *const buf_ptr1 = ref_frame + y0 * buf_stride + x0; |
| 607 const int b_w = x1 - x0 + 1; |
| 608 const int b_h = y1 - y0 + 1; |
| 609 const int border_offset = y_pad * 3 * b_w + x_pad * 3; |
| 610 |
| 611 extend_and_predict(buf_ptr1, buf_stride, x0, y0, b_w, b_h, |
| 612 frame_width, frame_height, border_offset, |
| 613 dst, dst_buf->stride, |
| 614 subpel_x, subpel_y, |
| 615 kernel, sf, |
| 616 #if CONFIG_VP9_HIGHBITDEPTH |
| 617 xd, |
| 618 #endif |
| 619 w, h, ref, xs, ys); |
| 620 return; |
| 621 } |
| 622 } else { |
| 623 // Wait until reference block is ready. Pad 7 more pixels as last 7 |
| 624 // pixels of each superblock row can be changed by next superblock row. |
| 625 if (pbi->frame_parallel_decode) { |
| 626 const int y1 = (y0_16 + (h - 1) * ys) >> SUBPEL_BITS; |
| 627 vp9_frameworker_wait(pbi->frame_worker_owner, ref_frame_buf, |
| 628 MAX(0, (y1 + 7)) << (plane == 0 ? 0 : 1)); |
| 629 } |
| 630 } |
| 631 #if CONFIG_VP9_HIGHBITDEPTH |
| 632 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 633 high_inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x, |
| 634 subpel_y, sf, w, h, ref, kernel, xs, ys, xd->bd); |
| 635 } else { |
| 636 inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x, |
| 637 subpel_y, sf, w, h, ref, kernel, xs, ys); |
| 638 } |
| 639 #else |
| 640 inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x, |
| 641 subpel_y, sf, w, h, ref, kernel, xs, ys); |
| 642 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 643 } |
| 644 |
| 645 static void dec_build_inter_predictors_sb(VP9Decoder *const pbi, |
| 646 MACROBLOCKD *xd, |
| 647 int mi_row, int mi_col, |
| 648 BLOCK_SIZE bsize) { |
| 649 int plane; |
| 650 const int mi_x = mi_col * MI_SIZE; |
| 651 const int mi_y = mi_row * MI_SIZE; |
| 652 const MODE_INFO *mi = xd->mi[0]; |
| 653 const InterpKernel *kernel = vp9_get_interp_kernel(mi->mbmi.interp_filter); |
| 654 const BLOCK_SIZE sb_type = mi->mbmi.sb_type; |
| 655 const int is_compound = has_second_ref(&mi->mbmi); |
| 656 |
| 657 for (plane = 0; plane < MAX_MB_PLANE; ++plane) { |
| 658 const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, |
| 659 &xd->plane[plane]); |
| 660 struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 661 struct buf_2d *const dst_buf = &pd->dst; |
| 662 const int num_4x4_w = num_4x4_blocks_wide_lookup[plane_bsize]; |
| 663 const int num_4x4_h = num_4x4_blocks_high_lookup[plane_bsize]; |
| 664 |
| 665 const int bw = 4 * num_4x4_w; |
| 666 const int bh = 4 * num_4x4_h; |
| 667 int ref; |
| 668 |
| 669 for (ref = 0; ref < 1 + is_compound; ++ref) { |
| 670 const struct scale_factors *const sf = &xd->block_refs[ref]->sf; |
| 671 struct buf_2d *const pre_buf = &pd->pre[ref]; |
| 672 const int idx = xd->block_refs[ref]->idx; |
| 673 BufferPool *const pool = pbi->common.buffer_pool; |
| 674 RefCntBuffer *const ref_frame_buf = &pool->frame_bufs[idx]; |
| 675 const int is_scaled = vp9_is_scaled(sf); |
| 676 |
| 677 if (sb_type < BLOCK_8X8) { |
| 678 int i = 0, x, y; |
| 679 assert(bsize == BLOCK_8X8); |
| 680 for (y = 0; y < num_4x4_h; ++y) { |
| 681 for (x = 0; x < num_4x4_w; ++x) { |
| 682 const MV mv = average_split_mvs(pd, mi, ref, i++); |
| 683 dec_build_inter_predictors(pbi, xd, plane, bw, bh, |
| 684 4 * x, 4 * y, 4, 4, mi_x, mi_y, kernel, |
| 685 sf, pre_buf, dst_buf, &mv, |
| 686 ref_frame_buf, is_scaled, ref); |
| 687 } |
| 688 } |
| 689 } else { |
| 690 const MV mv = mi->mbmi.mv[ref].as_mv; |
| 691 dec_build_inter_predictors(pbi, xd, plane, bw, bh, |
| 692 0, 0, bw, bh, mi_x, mi_y, kernel, |
| 693 sf, pre_buf, dst_buf, &mv, ref_frame_buf, |
| 694 is_scaled, ref); |
| 695 } |
| 696 } |
| 697 } |
| 698 } |
| 699 |
| 349 static MB_MODE_INFO *set_offsets(VP9_COMMON *const cm, MACROBLOCKD *const xd, | 700 static MB_MODE_INFO *set_offsets(VP9_COMMON *const cm, MACROBLOCKD *const xd, |
| 350 const TileInfo *const tile, | 701 const TileInfo *const tile, |
| 351 BLOCK_SIZE bsize, int mi_row, int mi_col) { | 702 BLOCK_SIZE bsize, int mi_row, int mi_col) { |
| 352 const int bw = num_8x8_blocks_wide_lookup[bsize]; | 703 const int bw = num_8x8_blocks_wide_lookup[bsize]; |
| 353 const int bh = num_8x8_blocks_high_lookup[bsize]; | 704 const int bh = num_8x8_blocks_high_lookup[bsize]; |
| 354 const int x_mis = MIN(bw, cm->mi_cols - mi_col); | 705 const int x_mis = MIN(bw, cm->mi_cols - mi_col); |
| 355 const int y_mis = MIN(bh, cm->mi_rows - mi_row); | 706 const int y_mis = MIN(bh, cm->mi_rows - mi_row); |
| 356 const int offset = mi_row * cm->mi_stride + mi_col; | 707 const int offset = mi_row * cm->mi_stride + mi_col; |
| 357 int x, y; | 708 int x, y; |
| 358 | 709 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 if (mbmi->skip) { | 749 if (mbmi->skip) { |
| 399 reset_skip_context(xd, bsize); | 750 reset_skip_context(xd, bsize); |
| 400 } | 751 } |
| 401 | 752 |
| 402 if (!is_inter_block(mbmi)) { | 753 if (!is_inter_block(mbmi)) { |
| 403 struct intra_args arg = {xd, r, mbmi->segment_id}; | 754 struct intra_args arg = {xd, r, mbmi->segment_id}; |
| 404 vp9_foreach_transformed_block(xd, bsize, | 755 vp9_foreach_transformed_block(xd, bsize, |
| 405 predict_and_reconstruct_intra_block, &arg); | 756 predict_and_reconstruct_intra_block, &arg); |
| 406 } else { | 757 } else { |
| 407 // Prediction | 758 // Prediction |
| 408 vp9_dec_build_inter_predictors_sb(pbi, xd, mi_row, mi_col, bsize); | 759 dec_build_inter_predictors_sb(pbi, xd, mi_row, mi_col, bsize); |
| 409 | 760 |
| 410 // Reconstruction | 761 // Reconstruction |
| 411 if (!mbmi->skip) { | 762 if (!mbmi->skip) { |
| 412 int eobtotal = 0; | 763 int eobtotal = 0; |
| 413 struct inter_args arg = {xd, r, &eobtotal, mbmi->segment_id}; | 764 struct inter_args arg = {xd, r, &eobtotal, mbmi->segment_id}; |
| 414 vp9_foreach_transformed_block(xd, bsize, reconstruct_inter_block, &arg); | 765 vp9_foreach_transformed_block(xd, bsize, reconstruct_inter_block, &arg); |
| 415 if (!less8x8 && eobtotal == 0) | 766 if (!less8x8 && eobtotal == 0) |
| 416 mbmi->skip = 1; // skip loopfilter | 767 mbmi->skip = 1; // skip loopfilter |
| 417 } | 768 } |
| 418 } | 769 } |
| 419 | 770 |
| 420 xd->corrupted |= vp9_reader_has_error(r); | 771 xd->corrupted |= vp9_reader_has_error(r); |
| 421 } | 772 } |
| 422 | 773 |
| 423 static PARTITION_TYPE read_partition(VP9_COMMON *cm, MACROBLOCKD *xd, | 774 static PARTITION_TYPE read_partition(MACROBLOCKD *xd, int mi_row, int mi_col, |
| 424 int hbs, | 775 BLOCK_SIZE bsize, vp9_reader *r, |
| 425 int mi_row, int mi_col, BLOCK_SIZE bsize, | 776 int has_rows, int has_cols) { |
| 426 vp9_reader *r) { | |
| 427 const int ctx = partition_plane_context(xd, mi_row, mi_col, bsize); | 777 const int ctx = partition_plane_context(xd, mi_row, mi_col, bsize); |
| 428 const vp9_prob *const probs = get_partition_probs(cm, ctx); | 778 const vp9_prob *const probs = get_partition_probs(xd, ctx); |
| 429 const int has_rows = (mi_row + hbs) < cm->mi_rows; | |
| 430 const int has_cols = (mi_col + hbs) < cm->mi_cols; | |
| 431 FRAME_COUNTS *counts = xd->counts; | 779 FRAME_COUNTS *counts = xd->counts; |
| 432 PARTITION_TYPE p; | 780 PARTITION_TYPE p; |
| 433 | 781 |
| 434 if (has_rows && has_cols) | 782 if (has_rows && has_cols) |
| 435 p = (PARTITION_TYPE)vp9_read_tree(r, vp9_partition_tree, probs); | 783 p = (PARTITION_TYPE)vp9_read_tree(r, vp9_partition_tree, probs); |
| 436 else if (!has_rows && has_cols) | 784 else if (!has_rows && has_cols) |
| 437 p = vp9_read(r, probs[1]) ? PARTITION_SPLIT : PARTITION_HORZ; | 785 p = vp9_read(r, probs[1]) ? PARTITION_SPLIT : PARTITION_HORZ; |
| 438 else if (has_rows && !has_cols) | 786 else if (has_rows && !has_cols) |
| 439 p = vp9_read(r, probs[2]) ? PARTITION_SPLIT : PARTITION_VERT; | 787 p = vp9_read(r, probs[2]) ? PARTITION_SPLIT : PARTITION_VERT; |
| 440 else | 788 else |
| 441 p = PARTITION_SPLIT; | 789 p = PARTITION_SPLIT; |
| 442 | 790 |
| 443 if (counts) | 791 if (counts) |
| 444 ++counts->partition[ctx][p]; | 792 ++counts->partition[ctx][p]; |
| 445 | 793 |
| 446 return p; | 794 return p; |
| 447 } | 795 } |
| 448 | 796 |
| 449 static void decode_partition(VP9Decoder *const pbi, MACROBLOCKD *const xd, | 797 static void decode_partition(VP9Decoder *const pbi, MACROBLOCKD *const xd, |
| 450 const TileInfo *const tile, | 798 const TileInfo *const tile, |
| 451 int mi_row, int mi_col, | 799 int mi_row, int mi_col, |
| 452 vp9_reader* r, BLOCK_SIZE bsize) { | 800 vp9_reader* r, BLOCK_SIZE bsize) { |
| 453 VP9_COMMON *const cm = &pbi->common; | 801 VP9_COMMON *const cm = &pbi->common; |
| 454 const int hbs = num_8x8_blocks_wide_lookup[bsize] / 2; | 802 const int hbs = num_8x8_blocks_wide_lookup[bsize] / 2; |
| 455 PARTITION_TYPE partition; | 803 PARTITION_TYPE partition; |
| 456 BLOCK_SIZE subsize; | 804 BLOCK_SIZE subsize; |
| 805 const int has_rows = (mi_row + hbs) < cm->mi_rows; |
| 806 const int has_cols = (mi_col + hbs) < cm->mi_cols; |
| 457 | 807 |
| 458 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 808 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
| 459 return; | 809 return; |
| 460 | 810 |
| 461 partition = read_partition(cm, xd, hbs, mi_row, mi_col, bsize, r); | 811 partition = read_partition(xd, mi_row, mi_col, bsize, r, has_rows, has_cols); |
| 462 subsize = get_subsize(bsize, partition); | 812 subsize = get_subsize(bsize, partition); |
| 463 if (bsize == BLOCK_8X8) { | 813 if (bsize == BLOCK_8X8) { |
| 464 decode_block(pbi, xd, tile, mi_row, mi_col, r, subsize); | 814 decode_block(pbi, xd, tile, mi_row, mi_col, r, subsize); |
| 465 } else { | 815 } else { |
| 466 switch (partition) { | 816 switch (partition) { |
| 467 case PARTITION_NONE: | 817 case PARTITION_NONE: |
| 468 decode_block(pbi, xd, tile, mi_row, mi_col, r, subsize); | 818 decode_block(pbi, xd, tile, mi_row, mi_col, r, subsize); |
| 469 break; | 819 break; |
| 470 case PARTITION_HORZ: | 820 case PARTITION_HORZ: |
| 471 decode_block(pbi, xd, tile, mi_row, mi_col, r, subsize); | 821 decode_block(pbi, xd, tile, mi_row, mi_col, r, subsize); |
| 472 if (mi_row + hbs < cm->mi_rows) | 822 if (has_rows) |
| 473 decode_block(pbi, xd, tile, mi_row + hbs, mi_col, r, subsize); | 823 decode_block(pbi, xd, tile, mi_row + hbs, mi_col, r, subsize); |
| 474 break; | 824 break; |
| 475 case PARTITION_VERT: | 825 case PARTITION_VERT: |
| 476 decode_block(pbi, xd, tile, mi_row, mi_col, r, subsize); | 826 decode_block(pbi, xd, tile, mi_row, mi_col, r, subsize); |
| 477 if (mi_col + hbs < cm->mi_cols) | 827 if (has_cols) |
| 478 decode_block(pbi, xd, tile, mi_row, mi_col + hbs, r, subsize); | 828 decode_block(pbi, xd, tile, mi_row, mi_col + hbs, r, subsize); |
| 479 break; | 829 break; |
| 480 case PARTITION_SPLIT: | 830 case PARTITION_SPLIT: |
| 481 decode_partition(pbi, xd, tile, mi_row, mi_col, r, subsize); | 831 decode_partition(pbi, xd, tile, mi_row, mi_col, r, subsize); |
| 482 decode_partition(pbi, xd, tile, mi_row, mi_col + hbs, r, subsize); | 832 decode_partition(pbi, xd, tile, mi_row, mi_col + hbs, r, subsize); |
| 483 decode_partition(pbi, xd, tile, mi_row + hbs, mi_col, r, subsize); | 833 decode_partition(pbi, xd, tile, mi_row + hbs, mi_col, r, subsize); |
| 484 decode_partition(pbi, xd, tile, mi_row + hbs, mi_col + hbs, r, subsize); | 834 decode_partition(pbi, xd, tile, mi_row + hbs, mi_col + hbs, r, subsize); |
| 485 break; | 835 break; |
| 486 default: | 836 default: |
| 487 assert(0 && "Invalid partition type"); | 837 assert(0 && "Invalid partition type"); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 | 1012 |
| 663 static INTERP_FILTER read_interp_filter(struct vp9_read_bit_buffer *rb) { | 1013 static INTERP_FILTER read_interp_filter(struct vp9_read_bit_buffer *rb) { |
| 664 const INTERP_FILTER literal_to_filter[] = { EIGHTTAP_SMOOTH, | 1014 const INTERP_FILTER literal_to_filter[] = { EIGHTTAP_SMOOTH, |
| 665 EIGHTTAP, | 1015 EIGHTTAP, |
| 666 EIGHTTAP_SHARP, | 1016 EIGHTTAP_SHARP, |
| 667 BILINEAR }; | 1017 BILINEAR }; |
| 668 return vp9_rb_read_bit(rb) ? SWITCHABLE | 1018 return vp9_rb_read_bit(rb) ? SWITCHABLE |
| 669 : literal_to_filter[vp9_rb_read_literal(rb, 2)]; | 1019 : literal_to_filter[vp9_rb_read_literal(rb, 2)]; |
| 670 } | 1020 } |
| 671 | 1021 |
| 672 void vp9_read_frame_size(struct vp9_read_bit_buffer *rb, | |
| 673 int *width, int *height) { | |
| 674 *width = vp9_rb_read_literal(rb, 16) + 1; | |
| 675 *height = vp9_rb_read_literal(rb, 16) + 1; | |
| 676 } | |
| 677 | |
| 678 static void setup_display_size(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) { | 1022 static void setup_display_size(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) { |
| 679 cm->display_width = cm->width; | 1023 cm->display_width = cm->width; |
| 680 cm->display_height = cm->height; | 1024 cm->display_height = cm->height; |
| 681 if (vp9_rb_read_bit(rb)) | 1025 if (vp9_rb_read_bit(rb)) |
| 682 vp9_read_frame_size(rb, &cm->display_width, &cm->display_height); | 1026 vp9_read_frame_size(rb, &cm->display_width, &cm->display_height); |
| 683 } | 1027 } |
| 684 | 1028 |
| 685 static void resize_mv_buffer(VP9_COMMON *cm) { | 1029 static void resize_mv_buffer(VP9_COMMON *cm) { |
| 686 vpx_free(cm->cur_frame->mvs); | 1030 vpx_free(cm->cur_frame->mvs); |
| 687 cm->cur_frame->mi_rows = cm->mi_rows; | 1031 cm->cur_frame->mi_rows = cm->mi_rows; |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1105 | 1449 |
| 1106 assert(tile_cols <= (1 << 6)); | 1450 assert(tile_cols <= (1 << 6)); |
| 1107 assert(tile_rows == 1); | 1451 assert(tile_rows == 1); |
| 1108 (void)tile_rows; | 1452 (void)tile_rows; |
| 1109 | 1453 |
| 1110 // TODO(jzern): See if we can remove the restriction of passing in max | 1454 // TODO(jzern): See if we can remove the restriction of passing in max |
| 1111 // threads to the decoder. | 1455 // threads to the decoder. |
| 1112 if (pbi->num_tile_workers == 0) { | 1456 if (pbi->num_tile_workers == 0) { |
| 1113 const int num_threads = pbi->max_threads & ~1; | 1457 const int num_threads = pbi->max_threads & ~1; |
| 1114 int i; | 1458 int i; |
| 1115 // TODO(jzern): Allocate one less worker, as in the current code we only | |
| 1116 // use num_threads - 1 workers. | |
| 1117 CHECK_MEM_ERROR(cm, pbi->tile_workers, | 1459 CHECK_MEM_ERROR(cm, pbi->tile_workers, |
| 1118 vpx_malloc(num_threads * sizeof(*pbi->tile_workers))); | 1460 vpx_malloc(num_threads * sizeof(*pbi->tile_workers))); |
| 1119 // Ensure tile data offsets will be properly aligned. This may fail on | 1461 // Ensure tile data offsets will be properly aligned. This may fail on |
| 1120 // platforms without DECLARE_ALIGNED(). | 1462 // platforms without DECLARE_ALIGNED(). |
| 1121 assert((sizeof(*pbi->tile_worker_data) % 16) == 0); | 1463 assert((sizeof(*pbi->tile_worker_data) % 16) == 0); |
| 1122 CHECK_MEM_ERROR(cm, pbi->tile_worker_data, | 1464 CHECK_MEM_ERROR(cm, pbi->tile_worker_data, |
| 1123 vpx_memalign(32, num_threads * | 1465 vpx_memalign(32, num_threads * |
| 1124 sizeof(*pbi->tile_worker_data))); | 1466 sizeof(*pbi->tile_worker_data))); |
| 1125 CHECK_MEM_ERROR(cm, pbi->tile_worker_info, | 1467 CHECK_MEM_ERROR(cm, pbi->tile_worker_info, |
| 1126 vpx_malloc(num_threads * sizeof(*pbi->tile_worker_info))); | 1468 vpx_malloc(num_threads * sizeof(*pbi->tile_worker_info))); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1246 } | 1588 } |
| 1247 | 1589 |
| 1248 return bit_reader_end; | 1590 return bit_reader_end; |
| 1249 } | 1591 } |
| 1250 | 1592 |
| 1251 static void error_handler(void *data) { | 1593 static void error_handler(void *data) { |
| 1252 VP9_COMMON *const cm = (VP9_COMMON *)data; | 1594 VP9_COMMON *const cm = (VP9_COMMON *)data; |
| 1253 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, "Truncated packet"); | 1595 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, "Truncated packet"); |
| 1254 } | 1596 } |
| 1255 | 1597 |
| 1256 int vp9_read_sync_code(struct vp9_read_bit_buffer *const rb) { | |
| 1257 return vp9_rb_read_literal(rb, 8) == VP9_SYNC_CODE_0 && | |
| 1258 vp9_rb_read_literal(rb, 8) == VP9_SYNC_CODE_1 && | |
| 1259 vp9_rb_read_literal(rb, 8) == VP9_SYNC_CODE_2; | |
| 1260 } | |
| 1261 | |
| 1262 BITSTREAM_PROFILE vp9_read_profile(struct vp9_read_bit_buffer *rb) { | |
| 1263 int profile = vp9_rb_read_bit(rb); | |
| 1264 profile |= vp9_rb_read_bit(rb) << 1; | |
| 1265 if (profile > 2) | |
| 1266 profile += vp9_rb_read_bit(rb); | |
| 1267 return (BITSTREAM_PROFILE) profile; | |
| 1268 } | |
| 1269 | |
| 1270 static void read_bitdepth_colorspace_sampling( | 1598 static void read_bitdepth_colorspace_sampling( |
| 1271 VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) { | 1599 VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) { |
| 1272 if (cm->profile >= PROFILE_2) { | 1600 if (cm->profile >= PROFILE_2) { |
| 1273 cm->bit_depth = vp9_rb_read_bit(rb) ? VPX_BITS_12 : VPX_BITS_10; | 1601 cm->bit_depth = vp9_rb_read_bit(rb) ? VPX_BITS_12 : VPX_BITS_10; |
| 1274 #if CONFIG_VP9_HIGHBITDEPTH | 1602 #if CONFIG_VP9_HIGHBITDEPTH |
| 1275 cm->use_highbitdepth = 1; | 1603 cm->use_highbitdepth = 1; |
| 1276 #endif | 1604 #endif |
| 1277 } else { | 1605 } else { |
| 1278 cm->bit_depth = VPX_BITS_8; | 1606 cm->bit_depth = VPX_BITS_8; |
| 1279 #if CONFIG_VP9_HIGHBITDEPTH | 1607 #if CONFIG_VP9_HIGHBITDEPTH |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1312 | 1640 |
| 1313 static size_t read_uncompressed_header(VP9Decoder *pbi, | 1641 static size_t read_uncompressed_header(VP9Decoder *pbi, |
| 1314 struct vp9_read_bit_buffer *rb) { | 1642 struct vp9_read_bit_buffer *rb) { |
| 1315 VP9_COMMON *const cm = &pbi->common; | 1643 VP9_COMMON *const cm = &pbi->common; |
| 1316 BufferPool *const pool = cm->buffer_pool; | 1644 BufferPool *const pool = cm->buffer_pool; |
| 1317 RefCntBuffer *const frame_bufs = pool->frame_bufs; | 1645 RefCntBuffer *const frame_bufs = pool->frame_bufs; |
| 1318 int i, mask, ref_index = 0; | 1646 int i, mask, ref_index = 0; |
| 1319 size_t sz; | 1647 size_t sz; |
| 1320 | 1648 |
| 1321 cm->last_frame_type = cm->frame_type; | 1649 cm->last_frame_type = cm->frame_type; |
| 1650 cm->last_intra_only = cm->intra_only; |
| 1322 | 1651 |
| 1323 if (vp9_rb_read_literal(rb, 2) != VP9_FRAME_MARKER) | 1652 if (vp9_rb_read_literal(rb, 2) != VP9_FRAME_MARKER) |
| 1324 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, | 1653 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, |
| 1325 "Invalid frame marker"); | 1654 "Invalid frame marker"); |
| 1326 | 1655 |
| 1327 cm->profile = vp9_read_profile(rb); | 1656 cm->profile = vp9_read_profile(rb); |
| 1328 | 1657 |
| 1329 if (cm->profile >= MAX_PROFILES) | 1658 if (cm->profile >= MAX_PROFILES) |
| 1330 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, | 1659 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, |
| 1331 "Unsupported bitstream profile"); | 1660 "Unsupported bitstream profile"); |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1588 assert(!memcmp(cm->counts.single_ref, zero_counts.single_ref, | 1917 assert(!memcmp(cm->counts.single_ref, zero_counts.single_ref, |
| 1589 sizeof(cm->counts.single_ref))); | 1918 sizeof(cm->counts.single_ref))); |
| 1590 assert(!memcmp(cm->counts.comp_ref, zero_counts.comp_ref, | 1919 assert(!memcmp(cm->counts.comp_ref, zero_counts.comp_ref, |
| 1591 sizeof(cm->counts.comp_ref))); | 1920 sizeof(cm->counts.comp_ref))); |
| 1592 assert(!memcmp(&cm->counts.tx, &zero_counts.tx, sizeof(cm->counts.tx))); | 1921 assert(!memcmp(&cm->counts.tx, &zero_counts.tx, sizeof(cm->counts.tx))); |
| 1593 assert(!memcmp(cm->counts.skip, zero_counts.skip, sizeof(cm->counts.skip))); | 1922 assert(!memcmp(cm->counts.skip, zero_counts.skip, sizeof(cm->counts.skip))); |
| 1594 assert(!memcmp(&cm->counts.mv, &zero_counts.mv, sizeof(cm->counts.mv))); | 1923 assert(!memcmp(&cm->counts.mv, &zero_counts.mv, sizeof(cm->counts.mv))); |
| 1595 } | 1924 } |
| 1596 #endif // NDEBUG | 1925 #endif // NDEBUG |
| 1597 | 1926 |
| 1598 static struct vp9_read_bit_buffer* init_read_bit_buffer( | 1927 static struct vp9_read_bit_buffer *init_read_bit_buffer( |
| 1599 VP9Decoder *pbi, | 1928 VP9Decoder *pbi, |
| 1600 struct vp9_read_bit_buffer *rb, | 1929 struct vp9_read_bit_buffer *rb, |
| 1601 const uint8_t *data, | 1930 const uint8_t *data, |
| 1602 const uint8_t *data_end, | 1931 const uint8_t *data_end, |
| 1603 uint8_t *clear_data /* buffer size MAX_VP9_HEADER_SIZE */) { | 1932 uint8_t clear_data[MAX_VP9_HEADER_SIZE]) { |
| 1604 rb->bit_offset = 0; | 1933 rb->bit_offset = 0; |
| 1605 rb->error_handler = error_handler; | 1934 rb->error_handler = error_handler; |
| 1606 rb->error_handler_data = &pbi->common; | 1935 rb->error_handler_data = &pbi->common; |
| 1607 if (pbi->decrypt_cb) { | 1936 if (pbi->decrypt_cb) { |
| 1608 const int n = (int)MIN(MAX_VP9_HEADER_SIZE, data_end - data); | 1937 const int n = (int)MIN(MAX_VP9_HEADER_SIZE, data_end - data); |
| 1609 pbi->decrypt_cb(pbi->decrypt_state, data, clear_data, n); | 1938 pbi->decrypt_cb(pbi->decrypt_state, data, clear_data, n); |
| 1610 rb->bit_buffer = clear_data; | 1939 rb->bit_buffer = clear_data; |
| 1611 rb->bit_buffer_end = clear_data + n; | 1940 rb->bit_buffer_end = clear_data + n; |
| 1612 } else { | 1941 } else { |
| 1613 rb->bit_buffer = data; | 1942 rb->bit_buffer = data; |
| 1614 rb->bit_buffer_end = data_end; | 1943 rb->bit_buffer_end = data_end; |
| 1615 } | 1944 } |
| 1616 return rb; | 1945 return rb; |
| 1617 } | 1946 } |
| 1618 | 1947 |
| 1948 //------------------------------------------------------------------------------ |
| 1949 |
| 1950 int vp9_read_sync_code(struct vp9_read_bit_buffer *const rb) { |
| 1951 return vp9_rb_read_literal(rb, 8) == VP9_SYNC_CODE_0 && |
| 1952 vp9_rb_read_literal(rb, 8) == VP9_SYNC_CODE_1 && |
| 1953 vp9_rb_read_literal(rb, 8) == VP9_SYNC_CODE_2; |
| 1954 } |
| 1955 |
| 1956 void vp9_read_frame_size(struct vp9_read_bit_buffer *rb, |
| 1957 int *width, int *height) { |
| 1958 *width = vp9_rb_read_literal(rb, 16) + 1; |
| 1959 *height = vp9_rb_read_literal(rb, 16) + 1; |
| 1960 } |
| 1961 |
| 1962 BITSTREAM_PROFILE vp9_read_profile(struct vp9_read_bit_buffer *rb) { |
| 1963 int profile = vp9_rb_read_bit(rb); |
| 1964 profile |= vp9_rb_read_bit(rb) << 1; |
| 1965 if (profile > 2) |
| 1966 profile += vp9_rb_read_bit(rb); |
| 1967 return (BITSTREAM_PROFILE) profile; |
| 1968 } |
| 1969 |
| 1619 void vp9_decode_frame(VP9Decoder *pbi, | 1970 void vp9_decode_frame(VP9Decoder *pbi, |
| 1620 const uint8_t *data, const uint8_t *data_end, | 1971 const uint8_t *data, const uint8_t *data_end, |
| 1621 const uint8_t **p_data_end) { | 1972 const uint8_t **p_data_end) { |
| 1622 VP9_COMMON *const cm = &pbi->common; | 1973 VP9_COMMON *const cm = &pbi->common; |
| 1623 MACROBLOCKD *const xd = &pbi->mb; | 1974 MACROBLOCKD *const xd = &pbi->mb; |
| 1624 struct vp9_read_bit_buffer rb = { NULL, NULL, 0, NULL, 0}; | 1975 struct vp9_read_bit_buffer rb; |
| 1625 int context_updated = 0; | 1976 int context_updated = 0; |
| 1626 uint8_t clear_data[MAX_VP9_HEADER_SIZE]; | 1977 uint8_t clear_data[MAX_VP9_HEADER_SIZE]; |
| 1627 const size_t first_partition_size = read_uncompressed_header(pbi, | 1978 const size_t first_partition_size = read_uncompressed_header(pbi, |
| 1628 init_read_bit_buffer(pbi, &rb, data, data_end, clear_data)); | 1979 init_read_bit_buffer(pbi, &rb, data, data_end, clear_data)); |
| 1629 const int tile_rows = 1 << cm->log2_tile_rows; | 1980 const int tile_rows = 1 << cm->log2_tile_rows; |
| 1630 const int tile_cols = 1 << cm->log2_tile_cols; | 1981 const int tile_cols = 1 << cm->log2_tile_cols; |
| 1631 YV12_BUFFER_CONFIG *const new_fb = get_frame_new_buffer(cm); | 1982 YV12_BUFFER_CONFIG *const new_fb = get_frame_new_buffer(cm); |
| 1632 xd->cur_buf = new_fb; | 1983 xd->cur_buf = new_fb; |
| 1633 | 1984 |
| 1634 if (!first_partition_size) { | 1985 if (!first_partition_size) { |
| 1635 // showing a frame directly | 1986 // showing a frame directly |
| 1636 *p_data_end = data + (cm->profile <= PROFILE_2 ? 1 : 2); | 1987 *p_data_end = data + (cm->profile <= PROFILE_2 ? 1 : 2); |
| 1637 return; | 1988 return; |
| 1638 } | 1989 } |
| 1639 | 1990 |
| 1640 data += vp9_rb_bytes_read(&rb); | 1991 data += vp9_rb_bytes_read(&rb); |
| 1641 if (!read_is_valid(data, first_partition_size, data_end)) | 1992 if (!read_is_valid(data, first_partition_size, data_end)) |
| 1642 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, | 1993 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, |
| 1643 "Truncated packet or corrupt header length"); | 1994 "Truncated packet or corrupt header length"); |
| 1644 | 1995 |
| 1645 cm->use_prev_frame_mvs = !cm->error_resilient_mode && | 1996 cm->use_prev_frame_mvs = !cm->error_resilient_mode && |
| 1646 cm->width == cm->last_width && | 1997 cm->width == cm->last_width && |
| 1647 cm->height == cm->last_height && | 1998 cm->height == cm->last_height && |
| 1648 !cm->intra_only && | 1999 !cm->last_intra_only && |
| 1649 cm->last_show_frame; | 2000 cm->last_show_frame && |
| 2001 (cm->last_frame_type != KEY_FRAME); |
| 1650 | 2002 |
| 1651 vp9_setup_block_planes(xd, cm->subsampling_x, cm->subsampling_y); | 2003 vp9_setup_block_planes(xd, cm->subsampling_x, cm->subsampling_y); |
| 1652 | 2004 |
| 1653 *cm->fc = cm->frame_contexts[cm->frame_context_idx]; | 2005 *cm->fc = cm->frame_contexts[cm->frame_context_idx]; |
| 1654 if (!cm->fc->initialized) | 2006 if (!cm->fc->initialized) |
| 1655 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, | 2007 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, |
| 1656 "Uninitialized entropy context."); | 2008 "Uninitialized entropy context."); |
| 1657 | 2009 |
| 1658 vp9_zero(cm->counts); | 2010 vp9_zero(cm->counts); |
| 1659 | 2011 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1718 } | 2070 } |
| 1719 } else { | 2071 } else { |
| 1720 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, | 2072 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, |
| 1721 "Decode failed. Frame data is corrupted."); | 2073 "Decode failed. Frame data is corrupted."); |
| 1722 } | 2074 } |
| 1723 | 2075 |
| 1724 // Non frame parallel update frame context here. | 2076 // Non frame parallel update frame context here. |
| 1725 if (cm->refresh_frame_context && !context_updated) | 2077 if (cm->refresh_frame_context && !context_updated) |
| 1726 cm->frame_contexts[cm->frame_context_idx] = *cm->fc; | 2078 cm->frame_contexts[cm->frame_context_idx] = *cm->fc; |
| 1727 } | 2079 } |
| 1728 | |
| 1729 static void build_mc_border(const uint8_t *src, int src_stride, | |
| 1730 uint8_t *dst, int dst_stride, | |
| 1731 int x, int y, int b_w, int b_h, int w, int h) { | |
| 1732 // Get a pointer to the start of the real data for this row. | |
| 1733 const uint8_t *ref_row = src - x - y * src_stride; | |
| 1734 | |
| 1735 if (y >= h) | |
| 1736 ref_row += (h - 1) * src_stride; | |
| 1737 else if (y > 0) | |
| 1738 ref_row += y * src_stride; | |
| 1739 | |
| 1740 do { | |
| 1741 int right = 0, copy; | |
| 1742 int left = x < 0 ? -x : 0; | |
| 1743 | |
| 1744 if (left > b_w) | |
| 1745 left = b_w; | |
| 1746 | |
| 1747 if (x + b_w > w) | |
| 1748 right = x + b_w - w; | |
| 1749 | |
| 1750 if (right > b_w) | |
| 1751 right = b_w; | |
| 1752 | |
| 1753 copy = b_w - left - right; | |
| 1754 | |
| 1755 if (left) | |
| 1756 memset(dst, ref_row[0], left); | |
| 1757 | |
| 1758 if (copy) | |
| 1759 memcpy(dst + left, ref_row + x + left, copy); | |
| 1760 | |
| 1761 if (right) | |
| 1762 memset(dst + left + copy, ref_row[w - 1], right); | |
| 1763 | |
| 1764 dst += dst_stride; | |
| 1765 ++y; | |
| 1766 | |
| 1767 if (y > 0 && y < h) | |
| 1768 ref_row += src_stride; | |
| 1769 } while (--b_h); | |
| 1770 } | |
| 1771 | |
| 1772 #if CONFIG_VP9_HIGHBITDEPTH | |
| 1773 static void high_build_mc_border(const uint8_t *src8, int src_stride, | |
| 1774 uint16_t *dst, int dst_stride, | |
| 1775 int x, int y, int b_w, int b_h, | |
| 1776 int w, int h) { | |
| 1777 // Get a pointer to the start of the real data for this row. | |
| 1778 const uint16_t *src = CONVERT_TO_SHORTPTR(src8); | |
| 1779 const uint16_t *ref_row = src - x - y * src_stride; | |
| 1780 | |
| 1781 if (y >= h) | |
| 1782 ref_row += (h - 1) * src_stride; | |
| 1783 else if (y > 0) | |
| 1784 ref_row += y * src_stride; | |
| 1785 | |
| 1786 do { | |
| 1787 int right = 0, copy; | |
| 1788 int left = x < 0 ? -x : 0; | |
| 1789 | |
| 1790 if (left > b_w) | |
| 1791 left = b_w; | |
| 1792 | |
| 1793 if (x + b_w > w) | |
| 1794 right = x + b_w - w; | |
| 1795 | |
| 1796 if (right > b_w) | |
| 1797 right = b_w; | |
| 1798 | |
| 1799 copy = b_w - left - right; | |
| 1800 | |
| 1801 if (left) | |
| 1802 vpx_memset16(dst, ref_row[0], left); | |
| 1803 | |
| 1804 if (copy) | |
| 1805 memcpy(dst + left, ref_row + x + left, copy * sizeof(uint16_t)); | |
| 1806 | |
| 1807 if (right) | |
| 1808 vpx_memset16(dst + left + copy, ref_row[w - 1], right); | |
| 1809 | |
| 1810 dst += dst_stride; | |
| 1811 ++y; | |
| 1812 | |
| 1813 if (y > 0 && y < h) | |
| 1814 ref_row += src_stride; | |
| 1815 } while (--b_h); | |
| 1816 } | |
| 1817 #endif // CONFIG_VP9_HIGHBITDEPTH | |
| 1818 | |
| 1819 #if CONFIG_VP9_HIGHBITDEPTH | |
| 1820 static void extend_and_predict(const uint8_t *buf_ptr1, int pre_buf_stride, | |
| 1821 int x0, int y0, int b_w, int b_h, | |
| 1822 int frame_width, int frame_height, | |
| 1823 int border_offset, | |
| 1824 uint8_t *const dst, int dst_buf_stride, | |
| 1825 int subpel_x, int subpel_y, | |
| 1826 const InterpKernel *kernel, | |
| 1827 const struct scale_factors *sf, | |
| 1828 MACROBLOCKD *xd, | |
| 1829 int w, int h, int ref, int xs, int ys) { | |
| 1830 DECLARE_ALIGNED(16, uint16_t, mc_buf_high[80 * 2 * 80 * 2]); | |
| 1831 const uint8_t *buf_ptr; | |
| 1832 | |
| 1833 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { | |
| 1834 high_build_mc_border(buf_ptr1, pre_buf_stride, mc_buf_high, b_w, | |
| 1835 x0, y0, b_w, b_h, frame_width, frame_height); | |
| 1836 buf_ptr = CONVERT_TO_BYTEPTR(mc_buf_high) + border_offset; | |
| 1837 } else { | |
| 1838 build_mc_border(buf_ptr1, pre_buf_stride, (uint8_t *)mc_buf_high, b_w, | |
| 1839 x0, y0, b_w, b_h, frame_width, frame_height); | |
| 1840 buf_ptr = ((uint8_t *)mc_buf_high) + border_offset; | |
| 1841 } | |
| 1842 | |
| 1843 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { | |
| 1844 high_inter_predictor(buf_ptr, b_w, dst, dst_buf_stride, subpel_x, | |
| 1845 subpel_y, sf, w, h, ref, kernel, xs, ys, xd->bd); | |
| 1846 } else { | |
| 1847 inter_predictor(buf_ptr, b_w, dst, dst_buf_stride, subpel_x, | |
| 1848 subpel_y, sf, w, h, ref, kernel, xs, ys); | |
| 1849 } | |
| 1850 } | |
| 1851 #else | |
| 1852 static void extend_and_predict(const uint8_t *buf_ptr1, int pre_buf_stride, | |
| 1853 int x0, int y0, int b_w, int b_h, | |
| 1854 int frame_width, int frame_height, | |
| 1855 int border_offset, | |
| 1856 uint8_t *const dst, int dst_buf_stride, | |
| 1857 int subpel_x, int subpel_y, | |
| 1858 const InterpKernel *kernel, | |
| 1859 const struct scale_factors *sf, | |
| 1860 int w, int h, int ref, int xs, int ys) { | |
| 1861 DECLARE_ALIGNED(16, uint8_t, mc_buf[80 * 2 * 80 * 2]); | |
| 1862 const uint8_t *buf_ptr; | |
| 1863 | |
| 1864 build_mc_border(buf_ptr1, pre_buf_stride, mc_buf, b_w, | |
| 1865 x0, y0, b_w, b_h, frame_width, frame_height); | |
| 1866 buf_ptr = mc_buf + border_offset; | |
| 1867 | |
| 1868 inter_predictor(buf_ptr, b_w, dst, dst_buf_stride, subpel_x, | |
| 1869 subpel_y, sf, w, h, ref, kernel, xs, ys); | |
| 1870 } | |
| 1871 #endif // CONFIG_VP9_HIGHBITDEPTH | |
| 1872 | |
| 1873 static void dec_build_inter_predictors(VP9Decoder *const pbi, MACROBLOCKD *xd, | |
| 1874 int plane, int bw, int bh, int x, | |
| 1875 int y, int w, int h, int mi_x, int mi_y, | |
| 1876 const InterpKernel *kernel, | |
| 1877 const struct scale_factors *sf, | |
| 1878 struct buf_2d *pre_buf, | |
| 1879 struct buf_2d *dst_buf, const MV* mv, | |
| 1880 RefCntBuffer *ref_frame_buf, | |
| 1881 int is_scaled, int ref) { | |
| 1882 struct macroblockd_plane *const pd = &xd->plane[plane]; | |
| 1883 uint8_t *const dst = dst_buf->buf + dst_buf->stride * y + x; | |
| 1884 MV32 scaled_mv; | |
| 1885 int xs, ys, x0, y0, x0_16, y0_16, frame_width, frame_height, | |
| 1886 buf_stride, subpel_x, subpel_y; | |
| 1887 uint8_t *ref_frame, *buf_ptr; | |
| 1888 | |
| 1889 // Get reference frame pointer, width and height. | |
| 1890 if (plane == 0) { | |
| 1891 frame_width = ref_frame_buf->buf.y_crop_width; | |
| 1892 frame_height = ref_frame_buf->buf.y_crop_height; | |
| 1893 ref_frame = ref_frame_buf->buf.y_buffer; | |
| 1894 } else { | |
| 1895 frame_width = ref_frame_buf->buf.uv_crop_width; | |
| 1896 frame_height = ref_frame_buf->buf.uv_crop_height; | |
| 1897 ref_frame = plane == 1 ? ref_frame_buf->buf.u_buffer | |
| 1898 : ref_frame_buf->buf.v_buffer; | |
| 1899 } | |
| 1900 | |
| 1901 if (is_scaled) { | |
| 1902 const MV mv_q4 = clamp_mv_to_umv_border_sb(xd, mv, bw, bh, | |
| 1903 pd->subsampling_x, | |
| 1904 pd->subsampling_y); | |
| 1905 // Co-ordinate of containing block to pixel precision. | |
| 1906 int x_start = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x)); | |
| 1907 int y_start = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y)); | |
| 1908 | |
| 1909 // Co-ordinate of the block to 1/16th pixel precision. | |
| 1910 x0_16 = (x_start + x) << SUBPEL_BITS; | |
| 1911 y0_16 = (y_start + y) << SUBPEL_BITS; | |
| 1912 | |
| 1913 // Co-ordinate of current block in reference frame | |
| 1914 // to 1/16th pixel precision. | |
| 1915 x0_16 = sf->scale_value_x(x0_16, sf); | |
| 1916 y0_16 = sf->scale_value_y(y0_16, sf); | |
| 1917 | |
| 1918 // Map the top left corner of the block into the reference frame. | |
| 1919 x0 = sf->scale_value_x(x_start + x, sf); | |
| 1920 y0 = sf->scale_value_y(y_start + y, sf); | |
| 1921 | |
| 1922 // Scale the MV and incorporate the sub-pixel offset of the block | |
| 1923 // in the reference frame. | |
| 1924 scaled_mv = vp9_scale_mv(&mv_q4, mi_x + x, mi_y + y, sf); | |
| 1925 xs = sf->x_step_q4; | |
| 1926 ys = sf->y_step_q4; | |
| 1927 } else { | |
| 1928 // Co-ordinate of containing block to pixel precision. | |
| 1929 x0 = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x)) + x; | |
| 1930 y0 = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y)) + y; | |
| 1931 | |
| 1932 // Co-ordinate of the block to 1/16th pixel precision. | |
| 1933 x0_16 = x0 << SUBPEL_BITS; | |
| 1934 y0_16 = y0 << SUBPEL_BITS; | |
| 1935 | |
| 1936 scaled_mv.row = mv->row * (1 << (1 - pd->subsampling_y)); | |
| 1937 scaled_mv.col = mv->col * (1 << (1 - pd->subsampling_x)); | |
| 1938 xs = ys = 16; | |
| 1939 } | |
| 1940 subpel_x = scaled_mv.col & SUBPEL_MASK; | |
| 1941 subpel_y = scaled_mv.row & SUBPEL_MASK; | |
| 1942 | |
| 1943 // Calculate the top left corner of the best matching block in the | |
| 1944 // reference frame. | |
| 1945 x0 += scaled_mv.col >> SUBPEL_BITS; | |
| 1946 y0 += scaled_mv.row >> SUBPEL_BITS; | |
| 1947 x0_16 += scaled_mv.col; | |
| 1948 y0_16 += scaled_mv.row; | |
| 1949 | |
| 1950 // Get reference block pointer. | |
| 1951 buf_ptr = ref_frame + y0 * pre_buf->stride + x0; | |
| 1952 buf_stride = pre_buf->stride; | |
| 1953 | |
| 1954 // Do border extension if there is motion or the | |
| 1955 // width/height is not a multiple of 8 pixels. | |
| 1956 if (is_scaled || scaled_mv.col || scaled_mv.row || | |
| 1957 (frame_width & 0x7) || (frame_height & 0x7)) { | |
| 1958 int y1 = (y0_16 + (h - 1) * ys) >> SUBPEL_BITS; | |
| 1959 | |
| 1960 // Get reference block bottom right horizontal coordinate. | |
| 1961 int x1 = (x0_16 + (w - 1) * xs) >> SUBPEL_BITS; | |
| 1962 int x_pad = 0, y_pad = 0; | |
| 1963 | |
| 1964 if (subpel_x || (sf->x_step_q4 != SUBPEL_SHIFTS)) { | |
| 1965 x0 -= VP9_INTERP_EXTEND - 1; | |
| 1966 x1 += VP9_INTERP_EXTEND; | |
| 1967 x_pad = 1; | |
| 1968 } | |
| 1969 | |
| 1970 if (subpel_y || (sf->y_step_q4 != SUBPEL_SHIFTS)) { | |
| 1971 y0 -= VP9_INTERP_EXTEND - 1; | |
| 1972 y1 += VP9_INTERP_EXTEND; | |
| 1973 y_pad = 1; | |
| 1974 } | |
| 1975 | |
| 1976 // Wait until reference block is ready. Pad 7 more pixels as last 7 | |
| 1977 // pixels of each superblock row can be changed by next superblock row. | |
| 1978 if (pbi->frame_parallel_decode) | |
| 1979 vp9_frameworker_wait(pbi->frame_worker_owner, ref_frame_buf, | |
| 1980 MAX(0, (y1 + 7)) << (plane == 0 ? 0 : 1)); | |
| 1981 | |
| 1982 // Skip border extension if block is inside the frame. | |
| 1983 if (x0 < 0 || x0 > frame_width - 1 || x1 < 0 || x1 > frame_width - 1 || | |
| 1984 y0 < 0 || y0 > frame_height - 1 || y1 < 0 || y1 > frame_height - 1) { | |
| 1985 // Extend the border. | |
| 1986 const uint8_t *const buf_ptr1 = ref_frame + y0 * buf_stride + x0; | |
| 1987 const int b_w = x1 - x0 + 1; | |
| 1988 const int b_h = y1 - y0 + 1; | |
| 1989 const int border_offset = y_pad * 3 * b_w + x_pad * 3; | |
| 1990 | |
| 1991 extend_and_predict(buf_ptr1, buf_stride, x0, y0, b_w, b_h, | |
| 1992 frame_width, frame_height, border_offset, | |
| 1993 dst, dst_buf->stride, | |
| 1994 subpel_x, subpel_y, | |
| 1995 kernel, sf, | |
| 1996 #if CONFIG_VP9_HIGHBITDEPTH | |
| 1997 xd, | |
| 1998 #endif | |
| 1999 w, h, ref, xs, ys); | |
| 2000 return; | |
| 2001 } | |
| 2002 } else { | |
| 2003 // Wait until reference block is ready. Pad 7 more pixels as last 7 | |
| 2004 // pixels of each superblock row can be changed by next superblock row. | |
| 2005 if (pbi->frame_parallel_decode) { | |
| 2006 const int y1 = (y0_16 + (h - 1) * ys) >> SUBPEL_BITS; | |
| 2007 vp9_frameworker_wait(pbi->frame_worker_owner, ref_frame_buf, | |
| 2008 MAX(0, (y1 + 7)) << (plane == 0 ? 0 : 1)); | |
| 2009 } | |
| 2010 } | |
| 2011 #if CONFIG_VP9_HIGHBITDEPTH | |
| 2012 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { | |
| 2013 high_inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x, | |
| 2014 subpel_y, sf, w, h, ref, kernel, xs, ys, xd->bd); | |
| 2015 } else { | |
| 2016 inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x, | |
| 2017 subpel_y, sf, w, h, ref, kernel, xs, ys); | |
| 2018 } | |
| 2019 #else | |
| 2020 inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x, | |
| 2021 subpel_y, sf, w, h, ref, kernel, xs, ys); | |
| 2022 #endif // CONFIG_VP9_HIGHBITDEPTH | |
| 2023 } | |
| 2024 | |
| 2025 void vp9_dec_build_inter_predictors_sb(VP9Decoder *const pbi, MACROBLOCKD *xd, | |
| 2026 int mi_row, int mi_col, | |
| 2027 BLOCK_SIZE bsize) { | |
| 2028 int plane; | |
| 2029 const int mi_x = mi_col * MI_SIZE; | |
| 2030 const int mi_y = mi_row * MI_SIZE; | |
| 2031 const MODE_INFO *mi = xd->mi[0]; | |
| 2032 const InterpKernel *kernel = vp9_get_interp_kernel(mi->mbmi.interp_filter); | |
| 2033 const BLOCK_SIZE sb_type = mi->mbmi.sb_type; | |
| 2034 const int is_compound = has_second_ref(&mi->mbmi); | |
| 2035 | |
| 2036 for (plane = 0; plane < MAX_MB_PLANE; ++plane) { | |
| 2037 const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, | |
| 2038 &xd->plane[plane]); | |
| 2039 struct macroblockd_plane *const pd = &xd->plane[plane]; | |
| 2040 struct buf_2d *const dst_buf = &pd->dst; | |
| 2041 const int num_4x4_w = num_4x4_blocks_wide_lookup[plane_bsize]; | |
| 2042 const int num_4x4_h = num_4x4_blocks_high_lookup[plane_bsize]; | |
| 2043 | |
| 2044 const int bw = 4 * num_4x4_w; | |
| 2045 const int bh = 4 * num_4x4_h; | |
| 2046 int ref; | |
| 2047 | |
| 2048 for (ref = 0; ref < 1 + is_compound; ++ref) { | |
| 2049 const struct scale_factors *const sf = &xd->block_refs[ref]->sf; | |
| 2050 struct buf_2d *const pre_buf = &pd->pre[ref]; | |
| 2051 const int idx = xd->block_refs[ref]->idx; | |
| 2052 BufferPool *const pool = pbi->common.buffer_pool; | |
| 2053 RefCntBuffer *const ref_frame_buf = &pool->frame_bufs[idx]; | |
| 2054 const int is_scaled = vp9_is_scaled(sf); | |
| 2055 | |
| 2056 if (sb_type < BLOCK_8X8) { | |
| 2057 int i = 0, x, y; | |
| 2058 assert(bsize == BLOCK_8X8); | |
| 2059 for (y = 0; y < num_4x4_h; ++y) { | |
| 2060 for (x = 0; x < num_4x4_w; ++x) { | |
| 2061 const MV mv = average_split_mvs(pd, mi, ref, i++); | |
| 2062 dec_build_inter_predictors(pbi, xd, plane, bw, bh, | |
| 2063 4 * x, 4 * y, 4, 4, mi_x, mi_y, kernel, | |
| 2064 sf, pre_buf, dst_buf, &mv, | |
| 2065 ref_frame_buf, is_scaled, ref); | |
| 2066 } | |
| 2067 } | |
| 2068 } else { | |
| 2069 const MV mv = mi->mbmi.mv[ref].as_mv; | |
| 2070 dec_build_inter_predictors(pbi, xd, plane, bw, bh, | |
| 2071 0, 0, bw, bh, mi_x, mi_y, kernel, | |
| 2072 sf, pre_buf, dst_buf, &mv, ref_frame_buf, | |
| 2073 is_scaled, ref); | |
| 2074 } | |
| 2075 } | |
| 2076 } | |
| 2077 } | |
| OLD | NEW |