| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 #define HIGH_PRECISION_MV_QTHRESH 200 // Q threshold for high precision | 58 #define HIGH_PRECISION_MV_QTHRESH 200 // Q threshold for high precision |
| 59 // mv. Choose a very high value for | 59 // mv. Choose a very high value for |
| 60 // now so that HIGH_PRECISION is always | 60 // now so that HIGH_PRECISION is always |
| 61 // chosen. | 61 // chosen. |
| 62 | 62 |
| 63 // #define OUTPUT_YUV_REC | 63 // #define OUTPUT_YUV_REC |
| 64 | 64 |
| 65 #ifdef OUTPUT_YUV_DENOISED | 65 #ifdef OUTPUT_YUV_DENOISED |
| 66 FILE *yuv_denoised_file = NULL; | 66 FILE *yuv_denoised_file = NULL; |
| 67 #endif | 67 #endif |
| 68 #ifdef OUTPUT_YUV_SRC | |
| 69 FILE *yuv_file; | |
| 70 #endif | |
| 71 #ifdef OUTPUT_YUV_REC | 68 #ifdef OUTPUT_YUV_REC |
| 72 FILE *yuv_rec_file; | 69 FILE *yuv_rec_file; |
| 73 #endif | 70 #endif |
| 74 | 71 |
| 75 #if 0 | 72 #if 0 |
| 76 FILE *framepsnr; | 73 FILE *framepsnr; |
| 77 FILE *kf_list; | 74 FILE *kf_list; |
| 78 FILE *keyfile; | 75 FILE *keyfile; |
| 79 #endif | 76 #endif |
| 80 | 77 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 // other inter-frames the encoder currently uses only two contexts; | 121 // other inter-frames the encoder currently uses only two contexts; |
| 125 // context 1 for ALTREF frames and context 0 for the others. | 122 // context 1 for ALTREF frames and context 0 for the others. |
| 126 if (frame_is_intra_only(cm) || cm->error_resilient_mode) { | 123 if (frame_is_intra_only(cm) || cm->error_resilient_mode) { |
| 127 vp9_setup_past_independence(cm); | 124 vp9_setup_past_independence(cm); |
| 128 } else { | 125 } else { |
| 129 if (!cpi->use_svc) | 126 if (!cpi->use_svc) |
| 130 cm->frame_context_idx = cpi->refresh_alt_ref_frame; | 127 cm->frame_context_idx = cpi->refresh_alt_ref_frame; |
| 131 } | 128 } |
| 132 | 129 |
| 133 if (cm->frame_type == KEY_FRAME) { | 130 if (cm->frame_type == KEY_FRAME) { |
| 134 cpi->refresh_golden_frame = 1; | 131 if (!is_spatial_svc(cpi)) |
| 132 cpi->refresh_golden_frame = 1; |
| 135 cpi->refresh_alt_ref_frame = 1; | 133 cpi->refresh_alt_ref_frame = 1; |
| 136 } else { | 134 } else { |
| 137 cm->fc = cm->frame_contexts[cm->frame_context_idx]; | 135 cm->fc = cm->frame_contexts[cm->frame_context_idx]; |
| 138 } | 136 } |
| 139 } | 137 } |
| 140 | 138 |
| 141 void vp9_initialize_enc() { | 139 void vp9_initialize_enc() { |
| 142 static int init_done = 0; | 140 static int init_done = 0; |
| 143 | 141 |
| 144 if (!init_done) { | 142 if (!init_done) { |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 } | 467 } |
| 470 | 468 |
| 471 static void update_frame_size(VP9_COMP *cpi) { | 469 static void update_frame_size(VP9_COMP *cpi) { |
| 472 VP9_COMMON *const cm = &cpi->common; | 470 VP9_COMMON *const cm = &cpi->common; |
| 473 MACROBLOCKD *const xd = &cpi->mb.e_mbd; | 471 MACROBLOCKD *const xd = &cpi->mb.e_mbd; |
| 474 | 472 |
| 475 vp9_set_mb_mi(cm, cm->width, cm->height); | 473 vp9_set_mb_mi(cm, cm->width, cm->height); |
| 476 vp9_init_context_buffers(cm); | 474 vp9_init_context_buffers(cm); |
| 477 init_macroblockd(cm, xd); | 475 init_macroblockd(cm, xd); |
| 478 | 476 |
| 479 if (cpi->use_svc && cpi->svc.number_temporal_layers == 1) { | 477 if (is_spatial_svc(cpi)) { |
| 480 if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer, | 478 if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer, |
| 481 cm->width, cm->height, | 479 cm->width, cm->height, |
| 482 cm->subsampling_x, cm->subsampling_y, | 480 cm->subsampling_x, cm->subsampling_y, |
| 483 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL)) | 481 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL)) |
| 484 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 482 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
| 485 "Failed to reallocate alt_ref_buffer"); | 483 "Failed to reallocate alt_ref_buffer"); |
| 486 } | 484 } |
| 487 } | 485 } |
| 488 | 486 |
| 489 void vp9_new_framerate(VP9_COMP *cpi, double framerate) { | 487 void vp9_new_framerate(VP9_COMP *cpi, double framerate) { |
| 490 cpi->oxcf.framerate = framerate < 0.1 ? 30 : framerate; | 488 cpi->framerate = framerate < 0.1 ? 30 : framerate; |
| 491 vp9_rc_update_framerate(cpi); | 489 vp9_rc_update_framerate(cpi); |
| 492 } | 490 } |
| 493 | 491 |
| 494 int64_t vp9_rescale(int64_t val, int64_t num, int denom) { | 492 int64_t vp9_rescale(int64_t val, int64_t num, int denom) { |
| 495 int64_t llnum = num; | 493 int64_t llnum = num; |
| 496 int64_t llden = denom; | 494 int64_t llden = denom; |
| 497 int64_t llval = val; | 495 int64_t llval = val; |
| 498 | 496 |
| 499 return (llval * llnum / llden); | 497 return (llval * llnum / llden); |
| 500 } | 498 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 513 static void init_buffer_indices(VP9_COMP *cpi) { | 511 static void init_buffer_indices(VP9_COMP *cpi) { |
| 514 cpi->lst_fb_idx = 0; | 512 cpi->lst_fb_idx = 0; |
| 515 cpi->gld_fb_idx = 1; | 513 cpi->gld_fb_idx = 1; |
| 516 cpi->alt_fb_idx = 2; | 514 cpi->alt_fb_idx = 2; |
| 517 } | 515 } |
| 518 | 516 |
| 519 static void init_config(struct VP9_COMP *cpi, VP9EncoderConfig *oxcf) { | 517 static void init_config(struct VP9_COMP *cpi, VP9EncoderConfig *oxcf) { |
| 520 VP9_COMMON *const cm = &cpi->common; | 518 VP9_COMMON *const cm = &cpi->common; |
| 521 | 519 |
| 522 cpi->oxcf = *oxcf; | 520 cpi->oxcf = *oxcf; |
| 521 cpi->framerate = oxcf->init_framerate; |
| 523 | 522 |
| 524 cm->profile = oxcf->profile; | 523 cm->profile = oxcf->profile; |
| 525 cm->bit_depth = oxcf->bit_depth; | 524 cm->bit_depth = oxcf->bit_depth; |
| 525 cm->color_space = UNKNOWN; |
| 526 | 526 |
| 527 cm->width = oxcf->width; | 527 cm->width = oxcf->width; |
| 528 cm->height = oxcf->height; | 528 cm->height = oxcf->height; |
| 529 vp9_alloc_compressor_data(cpi); | 529 vp9_alloc_compressor_data(cpi); |
| 530 | 530 |
| 531 // Spatial scalability. | 531 // Spatial scalability. |
| 532 cpi->svc.number_spatial_layers = oxcf->ss_number_layers; | 532 cpi->svc.number_spatial_layers = oxcf->ss_number_layers; |
| 533 // Temporal scalability. | 533 // Temporal scalability. |
| 534 cpi->svc.number_temporal_layers = oxcf->ts_number_layers; | 534 cpi->svc.number_temporal_layers = oxcf->ts_number_layers; |
| 535 | 535 |
| 536 if ((cpi->svc.number_temporal_layers > 1 && | 536 if ((cpi->svc.number_temporal_layers > 1 && |
| 537 cpi->oxcf.rc_mode == VPX_CBR) || | 537 cpi->oxcf.rc_mode == VPX_CBR) || |
| 538 (cpi->svc.number_spatial_layers > 1 && | 538 (cpi->svc.number_spatial_layers > 1 && |
| 539 cpi->oxcf.mode == TWO_PASS_SECOND_BEST)) { | 539 cpi->oxcf.mode == TWO_PASS_SECOND_BEST)) { |
| 540 vp9_init_layer_context(cpi); | 540 vp9_init_layer_context(cpi); |
| 541 } | 541 } |
| 542 | 542 |
| 543 // change includes all joint functionality | 543 // change includes all joint functionality |
| 544 vp9_change_config(cpi, oxcf); | 544 vp9_change_config(cpi, oxcf); |
| 545 | 545 |
| 546 cpi->static_mb_pct = 0; | 546 cpi->static_mb_pct = 0; |
| 547 cpi->ref_frame_flags = 0; | 547 cpi->ref_frame_flags = 0; |
| 548 | 548 |
| 549 init_buffer_indices(cpi); | 549 init_buffer_indices(cpi); |
| 550 | 550 |
| 551 set_tile_limits(cpi); | 551 set_tile_limits(cpi); |
| 552 } | 552 } |
| 553 | 553 |
| 554 static int get_pass(MODE mode) { | |
| 555 switch (mode) { | |
| 556 case REALTIME: | |
| 557 case ONE_PASS_GOOD: | |
| 558 case ONE_PASS_BEST: | |
| 559 return 0; | |
| 560 | |
| 561 case TWO_PASS_FIRST: | |
| 562 return 1; | |
| 563 | |
| 564 case TWO_PASS_SECOND_GOOD: | |
| 565 case TWO_PASS_SECOND_BEST: | |
| 566 return 2; | |
| 567 } | |
| 568 return -1; | |
| 569 } | |
| 570 | |
| 571 void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) { | 554 void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) { |
| 572 VP9_COMMON *const cm = &cpi->common; | 555 VP9_COMMON *const cm = &cpi->common; |
| 573 RATE_CONTROL *const rc = &cpi->rc; | 556 RATE_CONTROL *const rc = &cpi->rc; |
| 574 | 557 |
| 575 if (cm->profile != oxcf->profile) | 558 if (cm->profile != oxcf->profile) |
| 576 cm->profile = oxcf->profile; | 559 cm->profile = oxcf->profile; |
| 577 cm->bit_depth = oxcf->bit_depth; | 560 cm->bit_depth = oxcf->bit_depth; |
| 578 | 561 |
| 579 if (cm->profile <= PROFILE_1) | 562 if (cm->profile <= PROFILE_1) |
| 580 assert(cm->bit_depth == BITS_8); | 563 assert(cm->bit_depth == BITS_8); |
| 581 else | 564 else |
| 582 assert(cm->bit_depth > BITS_8); | 565 assert(cm->bit_depth > BITS_8); |
| 583 | 566 |
| 584 cpi->oxcf = *oxcf; | 567 cpi->oxcf = *oxcf; |
| 585 cpi->pass = get_pass(cpi->oxcf.mode); | |
| 586 | 568 |
| 587 rc->baseline_gf_interval = DEFAULT_GF_INTERVAL; | 569 rc->baseline_gf_interval = DEFAULT_GF_INTERVAL; |
| 588 | 570 |
| 589 cpi->refresh_golden_frame = 0; | 571 cpi->refresh_golden_frame = 0; |
| 590 cpi->refresh_last_frame = 1; | 572 cpi->refresh_last_frame = 1; |
| 591 cm->refresh_frame_context = 1; | 573 cm->refresh_frame_context = 1; |
| 592 cm->reset_frame_context = 0; | 574 cm->reset_frame_context = 0; |
| 593 | 575 |
| 594 vp9_reset_segment_features(&cm->seg); | 576 vp9_reset_segment_features(&cm->seg); |
| 595 vp9_set_high_precision_mv(cpi, 0); | 577 vp9_set_high_precision_mv(cpi, 0); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 623 rc->maximum_buffer_size = cpi->oxcf.target_bandwidth / 8; | 605 rc->maximum_buffer_size = cpi->oxcf.target_bandwidth / 8; |
| 624 else | 606 else |
| 625 rc->maximum_buffer_size = vp9_rescale(cpi->oxcf.maximum_buffer_size_ms, | 607 rc->maximum_buffer_size = vp9_rescale(cpi->oxcf.maximum_buffer_size_ms, |
| 626 cpi->oxcf.target_bandwidth, 1000); | 608 cpi->oxcf.target_bandwidth, 1000); |
| 627 // Under a configuration change, where maximum_buffer_size may change, | 609 // Under a configuration change, where maximum_buffer_size may change, |
| 628 // keep buffer level clipped to the maximum allowed buffer size. | 610 // keep buffer level clipped to the maximum allowed buffer size. |
| 629 rc->bits_off_target = MIN(rc->bits_off_target, rc->maximum_buffer_size); | 611 rc->bits_off_target = MIN(rc->bits_off_target, rc->maximum_buffer_size); |
| 630 rc->buffer_level = MIN(rc->buffer_level, rc->maximum_buffer_size); | 612 rc->buffer_level = MIN(rc->buffer_level, rc->maximum_buffer_size); |
| 631 | 613 |
| 632 // Set up frame rate and related parameters rate control values. | 614 // Set up frame rate and related parameters rate control values. |
| 633 vp9_new_framerate(cpi, cpi->oxcf.framerate); | 615 vp9_new_framerate(cpi, cpi->framerate); |
| 634 | 616 |
| 635 // Set absolute upper and lower quality limits | 617 // Set absolute upper and lower quality limits |
| 636 rc->worst_quality = cpi->oxcf.worst_allowed_q; | 618 rc->worst_quality = cpi->oxcf.worst_allowed_q; |
| 637 rc->best_quality = cpi->oxcf.best_allowed_q; | 619 rc->best_quality = cpi->oxcf.best_allowed_q; |
| 638 | 620 |
| 639 cm->interp_filter = cpi->sf.default_interp_filter; | 621 cm->interp_filter = cpi->sf.default_interp_filter; |
| 640 | 622 |
| 641 cm->display_width = cpi->oxcf.width; | 623 cm->display_width = cpi->oxcf.width; |
| 642 cm->display_height = cpi->oxcf.height; | 624 cm->display_height = cpi->oxcf.height; |
| 643 | 625 |
| 644 if (cpi->initial_width) { | 626 if (cpi->initial_width) { |
| 645 // Increasing the size of the frame beyond the first seen frame, or some | 627 // Increasing the size of the frame beyond the first seen frame, or some |
| 646 // otherwise signaled maximum size, is not supported. | 628 // otherwise signaled maximum size, is not supported. |
| 647 // TODO(jkoleszar): exit gracefully. | 629 // TODO(jkoleszar): exit gracefully. |
| 648 assert(cm->width <= cpi->initial_width); | 630 assert(cm->width <= cpi->initial_width); |
| 649 assert(cm->height <= cpi->initial_height); | 631 assert(cm->height <= cpi->initial_height); |
| 650 } | 632 } |
| 651 update_frame_size(cpi); | 633 update_frame_size(cpi); |
| 652 | 634 |
| 653 if ((cpi->svc.number_temporal_layers > 1 && | 635 if ((cpi->svc.number_temporal_layers > 1 && |
| 654 cpi->oxcf.rc_mode == VPX_CBR) || | 636 cpi->oxcf.rc_mode == VPX_CBR) || |
| 655 (cpi->svc.number_spatial_layers > 1 && cpi->pass == 2)) { | 637 (cpi->svc.number_spatial_layers > 1 && cpi->oxcf.pass == 2)) { |
| 656 vp9_update_layer_context_change_config(cpi, | 638 vp9_update_layer_context_change_config(cpi, |
| 657 (int)cpi->oxcf.target_bandwidth); | 639 (int)cpi->oxcf.target_bandwidth); |
| 658 } | 640 } |
| 659 | 641 |
| 660 cpi->alt_ref_source = NULL; | 642 cpi->alt_ref_source = NULL; |
| 661 rc->is_src_frame_alt_ref = 0; | 643 rc->is_src_frame_alt_ref = 0; |
| 662 | 644 |
| 663 #if 0 | 645 #if 0 |
| 664 // Experimental RD Code | 646 // Experimental RD Code |
| 665 cpi->frame_distortion = 0; | 647 cpi->frame_distortion = 0; |
| 666 cpi->last_frame_distortion = 0; | 648 cpi->last_frame_distortion = 0; |
| 667 #endif | 649 #endif |
| 668 | 650 |
| 669 set_tile_limits(cpi); | 651 set_tile_limits(cpi); |
| 670 | 652 |
| 671 cpi->ext_refresh_frame_flags_pending = 0; | 653 cpi->ext_refresh_frame_flags_pending = 0; |
| 672 cpi->ext_refresh_frame_context_pending = 0; | 654 cpi->ext_refresh_frame_context_pending = 0; |
| 673 | 655 |
| 674 #if CONFIG_DENOISING | 656 #if CONFIG_VP9_TEMPORAL_DENOISING |
| 675 if (cpi->oxcf.noise_sensitivity > 0) { | 657 if (cpi->oxcf.noise_sensitivity > 0) { |
| 676 vp9_denoiser_alloc(&(cpi->denoiser), cm->width, cm->height, | 658 vp9_denoiser_alloc(&(cpi->denoiser), cm->width, cm->height, |
| 677 cm->subsampling_x, cm->subsampling_y, | 659 cm->subsampling_x, cm->subsampling_y, |
| 678 VP9_ENC_BORDER_IN_PIXELS); | 660 VP9_ENC_BORDER_IN_PIXELS); |
| 679 } | 661 } |
| 680 #endif | 662 #endif |
| 681 } | 663 } |
| 682 | 664 |
| 683 #ifndef M_LOG2_E | 665 #ifndef M_LOG2_E |
| 684 #define M_LOG2_E 0.693147180559945309417 | 666 #define M_LOG2_E 0.693147180559945309417 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 return 0; | 721 return 0; |
| 740 } | 722 } |
| 741 | 723 |
| 742 cm->error.setjmp = 1; | 724 cm->error.setjmp = 1; |
| 743 | 725 |
| 744 vp9_rtcd(); | 726 vp9_rtcd(); |
| 745 | 727 |
| 746 cpi->use_svc = 0; | 728 cpi->use_svc = 0; |
| 747 | 729 |
| 748 init_config(cpi, oxcf); | 730 init_config(cpi, oxcf); |
| 749 vp9_rc_init(&cpi->oxcf, cpi->pass, &cpi->rc); | 731 vp9_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); |
| 750 | 732 |
| 751 cm->current_video_frame = 0; | 733 cm->current_video_frame = 0; |
| 752 | 734 |
| 753 cpi->gold_is_last = 0; | 735 cpi->gold_is_last = 0; |
| 754 cpi->alt_is_last = 0; | 736 cpi->alt_is_last = 0; |
| 755 cpi->gold_is_alt = 0; | 737 cpi->gold_is_alt = 0; |
| 756 | 738 |
| 757 cpi->skippable_frame = 0; | 739 cpi->skippable_frame = 0; |
| 758 | 740 |
| 759 // Create the encoder segmentation map and set all entries to 0 | 741 // Create the encoder segmentation map and set all entries to 0 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 } | 773 } |
| 792 #endif | 774 #endif |
| 793 | 775 |
| 794 cpi->refresh_alt_ref_frame = 0; | 776 cpi->refresh_alt_ref_frame = 0; |
| 795 | 777 |
| 796 // Note that at the moment multi_arf will not work with svc. | 778 // Note that at the moment multi_arf will not work with svc. |
| 797 // For the current check in all the execution paths are defaulted to 0 | 779 // For the current check in all the execution paths are defaulted to 0 |
| 798 // pending further tuning and testing. The code is left in place here | 780 // pending further tuning and testing. The code is left in place here |
| 799 // as a place holder in regard to the required paths. | 781 // as a place holder in regard to the required paths. |
| 800 cpi->multi_arf_last_grp_enabled = 0; | 782 cpi->multi_arf_last_grp_enabled = 0; |
| 801 if (cpi->pass == 2) { | 783 if (oxcf->pass == 2) { |
| 802 if (cpi->use_svc) { | 784 if (cpi->use_svc) { |
| 803 cpi->multi_arf_allowed = 0; | 785 cpi->multi_arf_allowed = 0; |
| 804 cpi->multi_arf_enabled = 0; | 786 cpi->multi_arf_enabled = 0; |
| 805 } else { | 787 } else { |
| 806 // Disable by default for now. | 788 // Disable by default for now. |
| 807 cpi->multi_arf_allowed = 0; | 789 cpi->multi_arf_allowed = 0; |
| 808 cpi->multi_arf_enabled = 0; | 790 cpi->multi_arf_enabled = 0; |
| 809 } | 791 } |
| 810 } else { | 792 } else { |
| 811 cpi->multi_arf_allowed = 0; | 793 cpi->multi_arf_allowed = 0; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 cpi->mb.nmvsadcost[0] = &cpi->mb.nmvsadcosts[0][MV_MAX]; | 840 cpi->mb.nmvsadcost[0] = &cpi->mb.nmvsadcosts[0][MV_MAX]; |
| 859 cpi->mb.nmvsadcost[1] = &cpi->mb.nmvsadcosts[1][MV_MAX]; | 841 cpi->mb.nmvsadcost[1] = &cpi->mb.nmvsadcosts[1][MV_MAX]; |
| 860 cal_nmvsadcosts(cpi->mb.nmvsadcost); | 842 cal_nmvsadcosts(cpi->mb.nmvsadcost); |
| 861 | 843 |
| 862 cpi->mb.nmvcost_hp[0] = &cpi->mb.nmvcosts_hp[0][MV_MAX]; | 844 cpi->mb.nmvcost_hp[0] = &cpi->mb.nmvcosts_hp[0][MV_MAX]; |
| 863 cpi->mb.nmvcost_hp[1] = &cpi->mb.nmvcosts_hp[1][MV_MAX]; | 845 cpi->mb.nmvcost_hp[1] = &cpi->mb.nmvcosts_hp[1][MV_MAX]; |
| 864 cpi->mb.nmvsadcost_hp[0] = &cpi->mb.nmvsadcosts_hp[0][MV_MAX]; | 846 cpi->mb.nmvsadcost_hp[0] = &cpi->mb.nmvsadcosts_hp[0][MV_MAX]; |
| 865 cpi->mb.nmvsadcost_hp[1] = &cpi->mb.nmvsadcosts_hp[1][MV_MAX]; | 847 cpi->mb.nmvsadcost_hp[1] = &cpi->mb.nmvsadcosts_hp[1][MV_MAX]; |
| 866 cal_nmvsadcosts_hp(cpi->mb.nmvsadcost_hp); | 848 cal_nmvsadcosts_hp(cpi->mb.nmvsadcost_hp); |
| 867 | 849 |
| 868 #if CONFIG_DENOISING | 850 #if CONFIG_VP9_TEMPORAL_DENOISING |
| 869 #ifdef OUTPUT_YUV_DENOISED | 851 #ifdef OUTPUT_YUV_DENOISED |
| 870 yuv_denoised_file = fopen("denoised.yuv", "ab"); | 852 yuv_denoised_file = fopen("denoised.yuv", "ab"); |
| 871 #endif | 853 #endif |
| 872 #endif | 854 #endif |
| 873 #ifdef OUTPUT_YUV_SRC | |
| 874 yuv_file = fopen("bd.yuv", "ab"); | |
| 875 #endif | |
| 876 #ifdef OUTPUT_YUV_REC | 855 #ifdef OUTPUT_YUV_REC |
| 877 yuv_rec_file = fopen("rec.yuv", "wb"); | 856 yuv_rec_file = fopen("rec.yuv", "wb"); |
| 878 #endif | 857 #endif |
| 879 | 858 |
| 880 #if 0 | 859 #if 0 |
| 881 framepsnr = fopen("framepsnr.stt", "a"); | 860 framepsnr = fopen("framepsnr.stt", "a"); |
| 882 kf_list = fopen("kf_list.stt", "w"); | 861 kf_list = fopen("kf_list.stt", "w"); |
| 883 #endif | 862 #endif |
| 884 | 863 |
| 885 cpi->output_pkt_list = oxcf->output_pkt_list; | 864 cpi->output_pkt_list = oxcf->output_pkt_list; |
| 886 | 865 |
| 887 cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED; | 866 cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED; |
| 888 | 867 |
| 889 if (cpi->pass == 1) { | 868 if (oxcf->pass == 1) { |
| 890 vp9_init_first_pass(cpi); | 869 vp9_init_first_pass(cpi); |
| 891 } else if (cpi->pass == 2) { | 870 } else if (oxcf->pass == 2) { |
| 892 const size_t packet_sz = sizeof(FIRSTPASS_STATS); | 871 const size_t packet_sz = sizeof(FIRSTPASS_STATS); |
| 893 const int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz); | 872 const int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz); |
| 894 | 873 |
| 895 if (cpi->svc.number_spatial_layers > 1 | 874 if (cpi->svc.number_spatial_layers > 1 |
| 896 && cpi->svc.number_temporal_layers == 1) { | 875 && cpi->svc.number_temporal_layers == 1) { |
| 897 FIRSTPASS_STATS *const stats = oxcf->two_pass_stats_in.buf; | 876 FIRSTPASS_STATS *const stats = oxcf->two_pass_stats_in.buf; |
| 898 FIRSTPASS_STATS *stats_copy[VPX_SS_MAX_LAYERS] = {0}; | 877 FIRSTPASS_STATS *stats_copy[VPX_SS_MAX_LAYERS] = {0}; |
| 899 int i; | 878 int i; |
| 900 | 879 |
| 901 for (i = 0; i < oxcf->ss_number_layers; ++i) { | 880 for (i = 0; i < oxcf->ss_number_layers; ++i) { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1027 | 1006 |
| 1028 BFP(BLOCK_4X8, vp9_sad4x8, vp9_sad4x8_avg, | 1007 BFP(BLOCK_4X8, vp9_sad4x8, vp9_sad4x8_avg, |
| 1029 vp9_variance4x8, vp9_sub_pixel_variance4x8, | 1008 vp9_variance4x8, vp9_sub_pixel_variance4x8, |
| 1030 vp9_sub_pixel_avg_variance4x8, NULL, vp9_sad4x8x8, vp9_sad4x8x4d) | 1009 vp9_sub_pixel_avg_variance4x8, NULL, vp9_sad4x8x8, vp9_sad4x8x4d) |
| 1031 | 1010 |
| 1032 BFP(BLOCK_4X4, vp9_sad4x4, vp9_sad4x4_avg, | 1011 BFP(BLOCK_4X4, vp9_sad4x4, vp9_sad4x4_avg, |
| 1033 vp9_variance4x4, vp9_sub_pixel_variance4x4, | 1012 vp9_variance4x4, vp9_sub_pixel_variance4x4, |
| 1034 vp9_sub_pixel_avg_variance4x4, | 1013 vp9_sub_pixel_avg_variance4x4, |
| 1035 vp9_sad4x4x3, vp9_sad4x4x8, vp9_sad4x4x4d) | 1014 vp9_sad4x4x3, vp9_sad4x4x8, vp9_sad4x4x4d) |
| 1036 | 1015 |
| 1037 cpi->full_search_sad = vp9_full_search_sad; | |
| 1038 cpi->diamond_search_sad = vp9_diamond_search_sad; | |
| 1039 cpi->refining_search_sad = vp9_refining_search_sad; | |
| 1040 | |
| 1041 /* vp9_init_quantizer() is first called here. Add check in | 1016 /* vp9_init_quantizer() is first called here. Add check in |
| 1042 * vp9_frame_init_quantizer() so that vp9_init_quantizer is only | 1017 * vp9_frame_init_quantizer() so that vp9_init_quantizer is only |
| 1043 * called later when needed. This will avoid unnecessary calls of | 1018 * called later when needed. This will avoid unnecessary calls of |
| 1044 * vp9_init_quantizer() for every frame. | 1019 * vp9_init_quantizer() for every frame. |
| 1045 */ | 1020 */ |
| 1046 vp9_init_quantizer(cpi); | 1021 vp9_init_quantizer(cpi); |
| 1047 | 1022 |
| 1048 vp9_loop_filter_init(cm); | 1023 vp9_loop_filter_init(cm); |
| 1049 | 1024 |
| 1050 cm->error.setjmp = 0; | 1025 cm->error.setjmp = 0; |
| 1051 | 1026 |
| 1052 return cpi; | 1027 return cpi; |
| 1053 } | 1028 } |
| 1054 | 1029 |
| 1055 void vp9_remove_compressor(VP9_COMP *cpi) { | 1030 void vp9_remove_compressor(VP9_COMP *cpi) { |
| 1056 unsigned int i; | 1031 unsigned int i; |
| 1057 | 1032 |
| 1058 if (!cpi) | 1033 if (!cpi) |
| 1059 return; | 1034 return; |
| 1060 | 1035 |
| 1061 if (cpi && (cpi->common.current_video_frame > 0)) { | 1036 if (cpi && (cpi->common.current_video_frame > 0)) { |
| 1062 #if CONFIG_INTERNAL_STATS | 1037 #if CONFIG_INTERNAL_STATS |
| 1063 | 1038 |
| 1064 vp9_clear_system_state(); | 1039 vp9_clear_system_state(); |
| 1065 | 1040 |
| 1066 // printf("\n8x8-4x4:%d-%d\n", cpi->t8x8_count, cpi->t4x4_count); | 1041 // printf("\n8x8-4x4:%d-%d\n", cpi->t8x8_count, cpi->t4x4_count); |
| 1067 if (cpi->pass != 1) { | 1042 if (cpi->oxcf.pass != 1) { |
| 1068 FILE *f = fopen("opsnr.stt", "a"); | 1043 FILE *f = fopen("opsnr.stt", "a"); |
| 1069 double time_encoded = (cpi->last_end_time_stamp_seen | 1044 double time_encoded = (cpi->last_end_time_stamp_seen |
| 1070 - cpi->first_time_stamp_ever) / 10000000.000; | 1045 - cpi->first_time_stamp_ever) / 10000000.000; |
| 1071 double total_encode_time = (cpi->time_receive_data + | 1046 double total_encode_time = (cpi->time_receive_data + |
| 1072 cpi->time_compress_data) / 1000.000; | 1047 cpi->time_compress_data) / 1000.000; |
| 1073 double dr = (double)cpi->bytes * (double) 8 / (double)1000 | 1048 double dr = (double)cpi->bytes * (double) 8 / (double)1000 |
| 1074 / time_encoded; | 1049 / time_encoded; |
| 1075 | 1050 |
| 1076 if (cpi->b_calculate_psnr) { | 1051 if (cpi->b_calculate_psnr) { |
| 1077 const double total_psnr = | 1052 const double total_psnr = |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1112 printf("\n_pick_loop_filter_level:%d\n", cpi->time_pick_lpf / 1000); | 1087 printf("\n_pick_loop_filter_level:%d\n", cpi->time_pick_lpf / 1000); |
| 1113 printf("\n_frames recive_data encod_mb_row compress_frame Total\n"); | 1088 printf("\n_frames recive_data encod_mb_row compress_frame Total\n"); |
| 1114 printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame, | 1089 printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame, |
| 1115 cpi->time_receive_data / 1000, cpi->time_encode_sb_row / 1000, | 1090 cpi->time_receive_data / 1000, cpi->time_encode_sb_row / 1000, |
| 1116 cpi->time_compress_data / 1000, | 1091 cpi->time_compress_data / 1000, |
| 1117 (cpi->time_receive_data + cpi->time_compress_data) / 1000); | 1092 (cpi->time_receive_data + cpi->time_compress_data) / 1000); |
| 1118 } | 1093 } |
| 1119 #endif | 1094 #endif |
| 1120 } | 1095 } |
| 1121 | 1096 |
| 1122 #if CONFIG_DENOISING | 1097 #if CONFIG_VP9_TEMPORAL_DENOISING |
| 1123 if (cpi->oxcf.noise_sensitivity > 0) { | 1098 if (cpi->oxcf.noise_sensitivity > 0) { |
| 1124 vp9_denoiser_free(&(cpi->denoiser)); | 1099 vp9_denoiser_free(&(cpi->denoiser)); |
| 1125 } | 1100 } |
| 1126 #endif | 1101 #endif |
| 1127 | 1102 |
| 1128 dealloc_compressor_data(cpi); | 1103 dealloc_compressor_data(cpi); |
| 1129 vpx_free(cpi->tok); | 1104 vpx_free(cpi->tok); |
| 1130 | 1105 |
| 1131 for (i = 0; i < sizeof(cpi->mbgraph_stats) / | 1106 for (i = 0; i < sizeof(cpi->mbgraph_stats) / |
| 1132 sizeof(cpi->mbgraph_stats[0]); ++i) { | 1107 sizeof(cpi->mbgraph_stats[0]); ++i) { |
| 1133 vpx_free(cpi->mbgraph_stats[i].mb_stats); | 1108 vpx_free(cpi->mbgraph_stats[i].mb_stats); |
| 1134 } | 1109 } |
| 1135 | 1110 |
| 1136 #if CONFIG_FP_MB_STATS | 1111 #if CONFIG_FP_MB_STATS |
| 1137 if (cpi->use_fp_mb_stats) { | 1112 if (cpi->use_fp_mb_stats) { |
| 1138 vpx_free(cpi->twopass.frame_mb_stats_buf); | 1113 vpx_free(cpi->twopass.frame_mb_stats_buf); |
| 1139 cpi->twopass.frame_mb_stats_buf = NULL; | 1114 cpi->twopass.frame_mb_stats_buf = NULL; |
| 1140 } | 1115 } |
| 1141 #endif | 1116 #endif |
| 1142 | 1117 |
| 1143 vp9_remove_common(&cpi->common); | 1118 vp9_remove_common(&cpi->common); |
| 1144 vpx_free(cpi); | 1119 vpx_free(cpi); |
| 1145 | 1120 |
| 1146 #if CONFIG_DENOISING | 1121 #if CONFIG_VP9_TEMPORAL_DENOISING |
| 1147 #ifdef OUTPUT_YUV_DENOISED | 1122 #ifdef OUTPUT_YUV_DENOISED |
| 1148 fclose(yuv_denoised_file); | 1123 fclose(yuv_denoised_file); |
| 1149 #endif | 1124 #endif |
| 1150 #endif | 1125 #endif |
| 1151 #ifdef OUTPUT_YUV_SRC | |
| 1152 fclose(yuv_file); | |
| 1153 #endif | |
| 1154 #ifdef OUTPUT_YUV_REC | 1126 #ifdef OUTPUT_YUV_REC |
| 1155 fclose(yuv_rec_file); | 1127 fclose(yuv_rec_file); |
| 1156 #endif | 1128 #endif |
| 1157 | 1129 |
| 1158 #if 0 | 1130 #if 0 |
| 1159 | 1131 |
| 1160 if (keyfile) | 1132 if (keyfile) |
| 1161 fclose(keyfile); | 1133 fclose(keyfile); |
| 1162 | 1134 |
| 1163 if (framepsnr) | 1135 if (framepsnr) |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1294 YV12_BUFFER_CONFIG *sd) { | 1266 YV12_BUFFER_CONFIG *sd) { |
| 1295 YV12_BUFFER_CONFIG *cfg = get_vp9_ref_frame_buffer(cpi, ref_frame_flag); | 1267 YV12_BUFFER_CONFIG *cfg = get_vp9_ref_frame_buffer(cpi, ref_frame_flag); |
| 1296 if (cfg) { | 1268 if (cfg) { |
| 1297 vp8_yv12_copy_frame(cfg, sd); | 1269 vp8_yv12_copy_frame(cfg, sd); |
| 1298 return 0; | 1270 return 0; |
| 1299 } else { | 1271 } else { |
| 1300 return -1; | 1272 return -1; |
| 1301 } | 1273 } |
| 1302 } | 1274 } |
| 1303 | 1275 |
| 1304 int vp9_get_reference_enc(VP9_COMP *cpi, int index, YV12_BUFFER_CONFIG **fb) { | |
| 1305 VP9_COMMON *cm = &cpi->common; | |
| 1306 | |
| 1307 if (index < 0 || index >= REF_FRAMES) | |
| 1308 return -1; | |
| 1309 | |
| 1310 *fb = &cm->frame_bufs[cm->ref_frame_map[index]].buf; | |
| 1311 return 0; | |
| 1312 } | |
| 1313 | |
| 1314 int vp9_set_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag, | 1276 int vp9_set_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag, |
| 1315 YV12_BUFFER_CONFIG *sd) { | 1277 YV12_BUFFER_CONFIG *sd) { |
| 1316 YV12_BUFFER_CONFIG *cfg = get_vp9_ref_frame_buffer(cpi, ref_frame_flag); | 1278 YV12_BUFFER_CONFIG *cfg = get_vp9_ref_frame_buffer(cpi, ref_frame_flag); |
| 1317 if (cfg) { | 1279 if (cfg) { |
| 1318 vp8_yv12_copy_frame(sd, cfg); | 1280 vp8_yv12_copy_frame(sd, cfg); |
| 1319 return 0; | 1281 return 0; |
| 1320 } else { | 1282 } else { |
| 1321 return -1; | 1283 return -1; |
| 1322 } | 1284 } |
| 1323 } | 1285 } |
| 1324 | 1286 |
| 1325 int vp9_update_entropy(VP9_COMP * cpi, int update) { | 1287 int vp9_update_entropy(VP9_COMP * cpi, int update) { |
| 1326 cpi->ext_refresh_frame_context = update; | 1288 cpi->ext_refresh_frame_context = update; |
| 1327 cpi->ext_refresh_frame_context_pending = 1; | 1289 cpi->ext_refresh_frame_context_pending = 1; |
| 1328 return 0; | 1290 return 0; |
| 1329 } | 1291 } |
| 1330 | 1292 |
| 1331 | 1293 #if CONFIG_VP9_TEMPORAL_DENOISING |
| 1332 #if defined(OUTPUT_YUV_SRC) | |
| 1333 void vp9_write_yuv_frame(YV12_BUFFER_CONFIG *s, FILE *f) { | |
| 1334 uint8_t *src = s->y_buffer; | |
| 1335 int h = s->y_height; | |
| 1336 | |
| 1337 do { | |
| 1338 fwrite(src, s->y_width, 1, f); | |
| 1339 src += s->y_stride; | |
| 1340 } while (--h); | |
| 1341 | |
| 1342 src = s->u_buffer; | |
| 1343 h = s->uv_height; | |
| 1344 | |
| 1345 do { | |
| 1346 fwrite(src, s->uv_width, 1, f); | |
| 1347 src += s->uv_stride; | |
| 1348 } while (--h); | |
| 1349 | |
| 1350 src = s->v_buffer; | |
| 1351 h = s->uv_height; | |
| 1352 | |
| 1353 do { | |
| 1354 fwrite(src, s->uv_width, 1, f); | |
| 1355 src += s->uv_stride; | |
| 1356 } while (--h); | |
| 1357 } | |
| 1358 #endif | |
| 1359 | |
| 1360 #if CONFIG_DENOISING | |
| 1361 #if defined(OUTPUT_YUV_DENOISED) | 1294 #if defined(OUTPUT_YUV_DENOISED) |
| 1362 // The denoiser buffer is allocated as a YUV 440 buffer. This function writes it | 1295 // The denoiser buffer is allocated as a YUV 440 buffer. This function writes it |
| 1363 // as YUV 420. We simply use the top-left pixels of the UV buffers, since we do | 1296 // as YUV 420. We simply use the top-left pixels of the UV buffers, since we do |
| 1364 // not denoise the UV channels at this time. If ever we implement UV channel | 1297 // not denoise the UV channels at this time. If ever we implement UV channel |
| 1365 // denoising we will have to modify this. | 1298 // denoising we will have to modify this. |
| 1366 void vp9_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) { | 1299 void vp9_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) { |
| 1367 uint8_t *src = s->y_buffer; | 1300 uint8_t *src = s->y_buffer; |
| 1368 int h = s->y_height; | 1301 int h = s->y_height; |
| 1369 | 1302 |
| 1370 do { | 1303 do { |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1556 void vp9_update_reference_frames(VP9_COMP *cpi) { | 1489 void vp9_update_reference_frames(VP9_COMP *cpi) { |
| 1557 VP9_COMMON * const cm = &cpi->common; | 1490 VP9_COMMON * const cm = &cpi->common; |
| 1558 | 1491 |
| 1559 // At this point the new frame has been encoded. | 1492 // At this point the new frame has been encoded. |
| 1560 // If any buffer copy / swapping is signaled it should be done here. | 1493 // If any buffer copy / swapping is signaled it should be done here. |
| 1561 if (cm->frame_type == KEY_FRAME) { | 1494 if (cm->frame_type == KEY_FRAME) { |
| 1562 ref_cnt_fb(cm->frame_bufs, | 1495 ref_cnt_fb(cm->frame_bufs, |
| 1563 &cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx); | 1496 &cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx); |
| 1564 ref_cnt_fb(cm->frame_bufs, | 1497 ref_cnt_fb(cm->frame_bufs, |
| 1565 &cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx); | 1498 &cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx); |
| 1566 } else if (!cpi->multi_arf_allowed && cpi->refresh_golden_frame && | 1499 } else if (vp9_preserve_existing_gf(cpi)) { |
| 1567 cpi->rc.is_src_frame_alt_ref && !cpi->use_svc) { | 1500 // We have decided to preserve the previously existing golden frame as our |
| 1568 /* Preserve the previously existing golden frame and update the frame in | 1501 // new ARF frame. However, in the short term in function |
| 1569 * the alt ref slot instead. This is highly specific to the current use of | 1502 // vp9_bitstream.c::get_refresh_mask() we left it in the GF slot and, if |
| 1570 * alt-ref as a forward reference, and this needs to be generalized as | 1503 // we're updating the GF with the current decoded frame, we save it to the |
| 1571 * other uses are implemented (like RTC/temporal scaling) | 1504 // ARF slot instead. |
| 1572 * | 1505 // We now have to update the ARF with the current frame and swap gld_fb_idx |
| 1573 * The update to the buffer in the alt ref slot was signaled in | 1506 // and alt_fb_idx so that, overall, we've stored the old GF in the new ARF |
| 1574 * vp9_pack_bitstream(), now swap the buffer pointers so that it's treated | 1507 // slot and, if we're updating the GF, the current frame becomes the new GF. |
| 1575 * as the golden frame next time. | |
| 1576 */ | |
| 1577 int tmp; | 1508 int tmp; |
| 1578 | 1509 |
| 1579 ref_cnt_fb(cm->frame_bufs, | 1510 ref_cnt_fb(cm->frame_bufs, |
| 1580 &cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx); | 1511 &cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx); |
| 1581 | 1512 |
| 1582 tmp = cpi->alt_fb_idx; | 1513 tmp = cpi->alt_fb_idx; |
| 1583 cpi->alt_fb_idx = cpi->gld_fb_idx; | 1514 cpi->alt_fb_idx = cpi->gld_fb_idx; |
| 1584 cpi->gld_fb_idx = tmp; | 1515 cpi->gld_fb_idx = tmp; |
| 1516 |
| 1517 if (is_spatial_svc(cpi)) { |
| 1518 cpi->svc.layer_context[0].gold_ref_idx = cpi->gld_fb_idx; |
| 1519 cpi->svc.layer_context[0].alt_ref_idx = cpi->alt_fb_idx; |
| 1520 } |
| 1585 } else { /* For non key/golden frames */ | 1521 } else { /* For non key/golden frames */ |
| 1586 if (cpi->refresh_alt_ref_frame) { | 1522 if (cpi->refresh_alt_ref_frame) { |
| 1587 int arf_idx = cpi->alt_fb_idx; | 1523 int arf_idx = cpi->alt_fb_idx; |
| 1588 if ((cpi->pass == 2) && cpi->multi_arf_allowed) { | 1524 if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) { |
| 1589 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; | 1525 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 1590 arf_idx = gf_group->arf_update_idx[gf_group->index]; | 1526 arf_idx = gf_group->arf_update_idx[gf_group->index]; |
| 1591 } | 1527 } |
| 1592 | 1528 |
| 1593 ref_cnt_fb(cm->frame_bufs, | 1529 ref_cnt_fb(cm->frame_bufs, |
| 1594 &cm->ref_frame_map[arf_idx], cm->new_fb_idx); | 1530 &cm->ref_frame_map[arf_idx], cm->new_fb_idx); |
| 1595 } | 1531 } |
| 1596 | 1532 |
| 1597 if (cpi->refresh_golden_frame) { | 1533 if (cpi->refresh_golden_frame) { |
| 1598 ref_cnt_fb(cm->frame_bufs, | 1534 ref_cnt_fb(cm->frame_bufs, |
| 1599 &cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx); | 1535 &cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx); |
| 1600 } | 1536 } |
| 1601 } | 1537 } |
| 1602 | 1538 |
| 1603 if (cpi->refresh_last_frame) { | 1539 if (cpi->refresh_last_frame) { |
| 1604 ref_cnt_fb(cm->frame_bufs, | 1540 ref_cnt_fb(cm->frame_bufs, |
| 1605 &cm->ref_frame_map[cpi->lst_fb_idx], cm->new_fb_idx); | 1541 &cm->ref_frame_map[cpi->lst_fb_idx], cm->new_fb_idx); |
| 1606 } | 1542 } |
| 1607 #if CONFIG_DENOISING | 1543 #if CONFIG_VP9_TEMPORAL_DENOISING |
| 1608 if (cpi->oxcf.noise_sensitivity > 0) { | 1544 if (cpi->oxcf.noise_sensitivity > 0) { |
| 1609 vp9_denoiser_update_frame_info(&cpi->denoiser, | 1545 vp9_denoiser_update_frame_info(&cpi->denoiser, |
| 1610 *cpi->Source, | 1546 *cpi->Source, |
| 1611 cpi->common.frame_type, | 1547 cpi->common.frame_type, |
| 1612 cpi->refresh_alt_ref_frame, | 1548 cpi->refresh_alt_ref_frame, |
| 1613 cpi->refresh_golden_frame, | 1549 cpi->refresh_golden_frame, |
| 1614 cpi->refresh_last_frame); | 1550 cpi->refresh_last_frame); |
| 1615 } | 1551 } |
| 1616 #endif | 1552 #endif |
| 1617 } | 1553 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1717 cpi->common.current_video_frame, cpi->rc.this_frame_target, | 1653 cpi->common.current_video_frame, cpi->rc.this_frame_target, |
| 1718 cpi->rc.projected_frame_size, | 1654 cpi->rc.projected_frame_size, |
| 1719 cpi->rc.projected_frame_size / cpi->common.MBs, | 1655 cpi->rc.projected_frame_size / cpi->common.MBs, |
| 1720 (cpi->rc.projected_frame_size - cpi->rc.this_frame_target), | 1656 (cpi->rc.projected_frame_size - cpi->rc.this_frame_target), |
| 1721 cpi->rc.vbr_bits_off_target, | 1657 cpi->rc.vbr_bits_off_target, |
| 1722 cpi->rc.total_target_vs_actual, | 1658 cpi->rc.total_target_vs_actual, |
| 1723 (cpi->rc.starting_buffer_level - cpi->rc.bits_off_target), | 1659 (cpi->rc.starting_buffer_level - cpi->rc.bits_off_target), |
| 1724 cpi->rc.total_actual_bits, cm->base_qindex, | 1660 cpi->rc.total_actual_bits, cm->base_qindex, |
| 1725 vp9_convert_qindex_to_q(cm->base_qindex), | 1661 vp9_convert_qindex_to_q(cm->base_qindex), |
| 1726 (double)vp9_dc_quant(cm->base_qindex, 0) / 4.0, | 1662 (double)vp9_dc_quant(cm->base_qindex, 0) / 4.0, |
| 1663 vp9_convert_qindex_to_q(cpi->twopass.active_worst_quality), |
| 1727 cpi->rc.avg_q, | 1664 cpi->rc.avg_q, |
| 1728 vp9_convert_qindex_to_q(cpi->rc.ni_av_qi), | |
| 1729 vp9_convert_qindex_to_q(cpi->oxcf.cq_level), | 1665 vp9_convert_qindex_to_q(cpi->oxcf.cq_level), |
| 1730 cpi->refresh_last_frame, cpi->refresh_golden_frame, | 1666 cpi->refresh_last_frame, cpi->refresh_golden_frame, |
| 1731 cpi->refresh_alt_ref_frame, cm->frame_type, cpi->rc.gfu_boost, | 1667 cpi->refresh_alt_ref_frame, cm->frame_type, cpi->rc.gfu_boost, |
| 1732 cpi->twopass.bits_left, | 1668 cpi->twopass.bits_left, |
| 1733 cpi->twopass.total_left_stats.coded_error, | 1669 cpi->twopass.total_left_stats.coded_error, |
| 1734 cpi->twopass.bits_left / | 1670 cpi->twopass.bits_left / |
| 1735 (1 + cpi->twopass.total_left_stats.coded_error), | 1671 (1 + cpi->twopass.total_left_stats.coded_error), |
| 1736 cpi->tot_recode_hits, recon_err, cpi->rc.kf_boost, | 1672 cpi->tot_recode_hits, recon_err, cpi->rc.kf_boost, |
| 1737 cpi->twopass.kf_zeromotion_pct); | 1673 cpi->twopass.kf_zeromotion_pct); |
| 1738 | 1674 |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1994 if (cpi->refresh_alt_ref_frame & cpi->refresh_golden_frame) | 1930 if (cpi->refresh_alt_ref_frame & cpi->refresh_golden_frame) |
| 1995 cpi->gold_is_alt = 1; | 1931 cpi->gold_is_alt = 1; |
| 1996 else if (cpi->refresh_alt_ref_frame ^ cpi->refresh_golden_frame) | 1932 else if (cpi->refresh_alt_ref_frame ^ cpi->refresh_golden_frame) |
| 1997 cpi->gold_is_alt = 0; | 1933 cpi->gold_is_alt = 0; |
| 1998 | 1934 |
| 1999 cpi->ref_frame_flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG; | 1935 cpi->ref_frame_flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG; |
| 2000 | 1936 |
| 2001 if (cpi->gold_is_last) | 1937 if (cpi->gold_is_last) |
| 2002 cpi->ref_frame_flags &= ~VP9_GOLD_FLAG; | 1938 cpi->ref_frame_flags &= ~VP9_GOLD_FLAG; |
| 2003 | 1939 |
| 2004 if (cpi->rc.frames_till_gf_update_due == INT_MAX) | 1940 if (cpi->rc.frames_till_gf_update_due == INT_MAX && |
| 1941 !is_spatial_svc(cpi)) |
| 2005 cpi->ref_frame_flags &= ~VP9_GOLD_FLAG; | 1942 cpi->ref_frame_flags &= ~VP9_GOLD_FLAG; |
| 2006 | 1943 |
| 2007 if (cpi->alt_is_last) | 1944 if (cpi->alt_is_last) |
| 2008 cpi->ref_frame_flags &= ~VP9_ALT_FLAG; | 1945 cpi->ref_frame_flags &= ~VP9_ALT_FLAG; |
| 2009 | 1946 |
| 2010 if (cpi->gold_is_alt) | 1947 if (cpi->gold_is_alt) |
| 2011 cpi->ref_frame_flags &= ~VP9_ALT_FLAG; | 1948 cpi->ref_frame_flags &= ~VP9_ALT_FLAG; |
| 2012 } | 1949 } |
| 2013 | 1950 |
| 2014 static void set_ext_overrides(VP9_COMP *cpi) { | 1951 static void set_ext_overrides(VP9_COMP *cpi) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2040 } | 1977 } |
| 2041 } | 1978 } |
| 2042 | 1979 |
| 2043 static void configure_skippable_frame(VP9_COMP *cpi) { | 1980 static void configure_skippable_frame(VP9_COMP *cpi) { |
| 2044 // If the current frame does not have non-zero motion vector detected in the | 1981 // If the current frame does not have non-zero motion vector detected in the |
| 2045 // first pass, and so do its previous and forward frames, then this frame | 1982 // first pass, and so do its previous and forward frames, then this frame |
| 2046 // can be skipped for partition check, and the partition size is assigned | 1983 // can be skipped for partition check, and the partition size is assigned |
| 2047 // according to the variance | 1984 // according to the variance |
| 2048 | 1985 |
| 2049 SVC *const svc = &cpi->svc; | 1986 SVC *const svc = &cpi->svc; |
| 2050 const int is_spatial_svc = (svc->number_spatial_layers > 1) && | 1987 TWO_PASS *const twopass = is_spatial_svc(cpi) ? |
| 2051 (svc->number_temporal_layers == 1); | |
| 2052 TWO_PASS *const twopass = is_spatial_svc ? | |
| 2053 &svc->layer_context[svc->spatial_layer_id].twopass | 1988 &svc->layer_context[svc->spatial_layer_id].twopass |
| 2054 : &cpi->twopass; | 1989 : &cpi->twopass; |
| 2055 | 1990 |
| 2056 cpi->skippable_frame = (!frame_is_intra_only(&cpi->common) && | 1991 cpi->skippable_frame = (!frame_is_intra_only(&cpi->common) && |
| 2057 twopass->stats_in - 2 > twopass->stats_in_start && | 1992 twopass->stats_in - 2 > twopass->stats_in_start && |
| 2058 twopass->stats_in < twopass->stats_in_end && | 1993 twopass->stats_in < twopass->stats_in_end && |
| 2059 (twopass->stats_in - 1)->pcnt_inter - (twopass->stats_in - 1)->pcnt_motion | 1994 (twopass->stats_in - 1)->pcnt_inter - (twopass->stats_in - 1)->pcnt_motion |
| 2060 == 1 && | 1995 == 1 && |
| 2061 (twopass->stats_in - 2)->pcnt_inter - (twopass->stats_in - 2)->pcnt_motion | 1996 (twopass->stats_in - 2)->pcnt_inter - (twopass->stats_in - 2)->pcnt_motion |
| 2062 == 1 && | 1997 == 1 && |
| 2063 twopass->stats_in->pcnt_inter - twopass->stats_in->pcnt_motion == 1); | 1998 twopass->stats_in->pcnt_inter - twopass->stats_in->pcnt_motion == 1); |
| 2064 } | 1999 } |
| 2065 | 2000 |
| 2066 static void set_arf_sign_bias(VP9_COMP *cpi) { | 2001 static void set_arf_sign_bias(VP9_COMP *cpi) { |
| 2067 VP9_COMMON *const cm = &cpi->common; | 2002 VP9_COMMON *const cm = &cpi->common; |
| 2068 int arf_sign_bias; | 2003 int arf_sign_bias; |
| 2069 | 2004 |
| 2070 if ((cpi->pass == 2) && cpi->multi_arf_allowed) { | 2005 if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) { |
| 2071 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; | 2006 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 2072 arf_sign_bias = cpi->rc.source_alt_ref_active && | 2007 arf_sign_bias = cpi->rc.source_alt_ref_active && |
| 2073 (!cpi->refresh_alt_ref_frame || | 2008 (!cpi->refresh_alt_ref_frame || |
| 2074 (gf_group->rf_level[gf_group->index] == GF_ARF_LOW)); | 2009 (gf_group->rf_level[gf_group->index] == GF_ARF_LOW)); |
| 2075 } else { | 2010 } else { |
| 2076 arf_sign_bias = | 2011 arf_sign_bias = |
| 2077 (cpi->rc.source_alt_ref_active && !cpi->refresh_alt_ref_frame); | 2012 (cpi->rc.source_alt_ref_active && !cpi->refresh_alt_ref_frame); |
| 2078 } | 2013 } |
| 2079 cm->ref_frame_sign_bias[ALTREF_FRAME] = arf_sign_bias; | 2014 cm->ref_frame_sign_bias[ALTREF_FRAME] = arf_sign_bias; |
| 2080 } | 2015 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2148 } | 2083 } |
| 2149 | 2084 |
| 2150 // The alternate reference frame cannot be active for a key frame. | 2085 // The alternate reference frame cannot be active for a key frame. |
| 2151 cpi->rc.source_alt_ref_active = 0; | 2086 cpi->rc.source_alt_ref_active = 0; |
| 2152 | 2087 |
| 2153 cm->error_resilient_mode = (cpi->oxcf.error_resilient_mode != 0); | 2088 cm->error_resilient_mode = (cpi->oxcf.error_resilient_mode != 0); |
| 2154 cm->frame_parallel_decoding_mode = | 2089 cm->frame_parallel_decoding_mode = |
| 2155 (cpi->oxcf.frame_parallel_decoding_mode != 0); | 2090 (cpi->oxcf.frame_parallel_decoding_mode != 0); |
| 2156 | 2091 |
| 2157 // By default, encoder assumes decoder can use prev_mi. | 2092 // By default, encoder assumes decoder can use prev_mi. |
| 2158 cm->coding_use_prev_mi = 1; | |
| 2159 if (cm->error_resilient_mode) { | 2093 if (cm->error_resilient_mode) { |
| 2160 cm->coding_use_prev_mi = 0; | |
| 2161 cm->frame_parallel_decoding_mode = 1; | 2094 cm->frame_parallel_decoding_mode = 1; |
| 2162 cm->reset_frame_context = 0; | 2095 cm->reset_frame_context = 0; |
| 2163 cm->refresh_frame_context = 0; | 2096 cm->refresh_frame_context = 0; |
| 2164 } else if (cm->intra_only) { | 2097 } else if (cm->intra_only) { |
| 2165 // Only reset the current context. | 2098 // Only reset the current context. |
| 2166 cm->reset_frame_context = 2; | 2099 cm->reset_frame_context = 2; |
| 2167 } | 2100 } |
| 2168 } | 2101 } |
| 2169 | 2102 |
| 2170 // Configure experimental use of segmentation for enhanced coding of | 2103 // Configure experimental use of segmentation for enhanced coding of |
| 2171 // static regions if indicated. | 2104 // static regions if indicated. |
| 2172 // Only allowed in second pass of two pass (as requires lagged coding) | 2105 // Only allowed in second pass of two pass (as requires lagged coding) |
| 2173 // and if the relevant speed feature flag is set. | 2106 // and if the relevant speed feature flag is set. |
| 2174 if (cpi->pass == 2 && cpi->sf.static_segmentation) | 2107 if (cpi->oxcf.pass == 2 && cpi->sf.static_segmentation) |
| 2175 configure_static_seg_features(cpi); | 2108 configure_static_seg_features(cpi); |
| 2176 | 2109 |
| 2177 // Check if the current frame is skippable for the partition search in the | 2110 // Check if the current frame is skippable for the partition search in the |
| 2178 // second pass according to the first pass stats | 2111 // second pass according to the first pass stats |
| 2179 if (cpi->pass == 2 && | 2112 if (cpi->oxcf.pass == 2 && |
| 2180 (!cpi->use_svc || cpi->svc.number_temporal_layers == 1)) { | 2113 (!cpi->use_svc || is_spatial_svc(cpi))) { |
| 2181 configure_skippable_frame(cpi); | 2114 configure_skippable_frame(cpi); |
| 2182 } | 2115 } |
| 2183 | 2116 |
| 2184 // For 1 pass CBR, check if we are dropping this frame. | 2117 // For 1 pass CBR, check if we are dropping this frame. |
| 2185 // Never drop on key frame. | 2118 // Never drop on key frame. |
| 2186 if (cpi->pass == 0 && | 2119 if (cpi->oxcf.pass == 0 && |
| 2187 cpi->oxcf.rc_mode == VPX_CBR && | 2120 cpi->oxcf.rc_mode == VPX_CBR && |
| 2188 cm->frame_type != KEY_FRAME) { | 2121 cm->frame_type != KEY_FRAME) { |
| 2189 if (vp9_rc_drop_frame(cpi)) { | 2122 if (vp9_rc_drop_frame(cpi)) { |
| 2190 vp9_rc_postencode_update_drop_frame(cpi); | 2123 vp9_rc_postencode_update_drop_frame(cpi); |
| 2191 ++cm->current_video_frame; | 2124 ++cm->current_video_frame; |
| 2192 return; | 2125 return; |
| 2193 } | 2126 } |
| 2194 } | 2127 } |
| 2195 | 2128 |
| 2196 vp9_clear_system_state(); | 2129 vp9_clear_system_state(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2213 l = 100; | 2146 l = 100; |
| 2214 break; | 2147 break; |
| 2215 case 6: | 2148 case 6: |
| 2216 l = 150; | 2149 l = 150; |
| 2217 break; | 2150 break; |
| 2218 } | 2151 } |
| 2219 vp9_denoise(cpi->Source, cpi->Source, l); | 2152 vp9_denoise(cpi->Source, cpi->Source, l); |
| 2220 } | 2153 } |
| 2221 #endif | 2154 #endif |
| 2222 | 2155 |
| 2223 #ifdef OUTPUT_YUV_SRC | |
| 2224 vp9_write_yuv_frame(cpi->Source, yuv_file); | |
| 2225 #endif | |
| 2226 | |
| 2227 set_speed_features(cpi); | 2156 set_speed_features(cpi); |
| 2228 | 2157 |
| 2229 // Decide q and q bounds. | 2158 // Decide q and q bounds. |
| 2230 q = vp9_rc_pick_q_and_bounds(cpi, &bottom_index, &top_index); | 2159 q = vp9_rc_pick_q_and_bounds(cpi, &bottom_index, &top_index); |
| 2231 | 2160 |
| 2232 if (!frame_is_intra_only(cm)) { | 2161 if (!frame_is_intra_only(cm)) { |
| 2233 cm->interp_filter = cpi->sf.default_interp_filter; | 2162 cm->interp_filter = cpi->sf.default_interp_filter; |
| 2234 /* TODO: Decide this more intelligently */ | 2163 /* TODO: Decide this more intelligently */ |
| 2235 vp9_set_high_precision_mv(cpi, q < HIGH_PRECISION_MV_QTHRESH); | 2164 vp9_set_high_precision_mv(cpi, q < HIGH_PRECISION_MV_QTHRESH); |
| 2236 } | 2165 } |
| 2237 | 2166 |
| 2238 if (cpi->sf.recode_loop == DISALLOW_RECODE) { | 2167 if (cpi->sf.recode_loop == DISALLOW_RECODE) { |
| 2239 encode_without_recode_loop(cpi, q); | 2168 encode_without_recode_loop(cpi, q); |
| 2240 } else { | 2169 } else { |
| 2241 encode_with_recode_loop(cpi, size, dest, q, bottom_index, top_index); | 2170 encode_with_recode_loop(cpi, size, dest, q, bottom_index, top_index); |
| 2242 } | 2171 } |
| 2243 | 2172 |
| 2244 #if CONFIG_DENOISING | 2173 #if CONFIG_VP9_TEMPORAL_DENOISING |
| 2245 #ifdef OUTPUT_YUV_DENOISED | 2174 #ifdef OUTPUT_YUV_DENOISED |
| 2246 if (cpi->oxcf.noise_sensitivity > 0) { | 2175 if (cpi->oxcf.noise_sensitivity > 0) { |
| 2247 vp9_write_yuv_frame_420(&cpi->denoiser.running_avg_y[INTRA_FRAME], | 2176 vp9_write_yuv_frame_420(&cpi->denoiser.running_avg_y[INTRA_FRAME], |
| 2248 yuv_denoised_file); | 2177 yuv_denoised_file); |
| 2249 } | 2178 } |
| 2250 #endif | 2179 #endif |
| 2251 #endif | 2180 #endif |
| 2252 | 2181 |
| 2253 | 2182 |
| 2254 // Special case code to reduce pulsing when key frames are forced at a | 2183 // Special case code to reduce pulsing when key frames are forced at a |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2422 struct vpx_usec_timer timer; | 2351 struct vpx_usec_timer timer; |
| 2423 int res = 0; | 2352 int res = 0; |
| 2424 const int subsampling_x = sd->uv_width < sd->y_width; | 2353 const int subsampling_x = sd->uv_width < sd->y_width; |
| 2425 const int subsampling_y = sd->uv_height < sd->y_height; | 2354 const int subsampling_y = sd->uv_height < sd->y_height; |
| 2426 | 2355 |
| 2427 check_initial_width(cpi, subsampling_x, subsampling_y); | 2356 check_initial_width(cpi, subsampling_x, subsampling_y); |
| 2428 | 2357 |
| 2429 vpx_usec_timer_start(&timer); | 2358 vpx_usec_timer_start(&timer); |
| 2430 | 2359 |
| 2431 #if CONFIG_SPATIAL_SVC | 2360 #if CONFIG_SPATIAL_SVC |
| 2432 if (cpi->use_svc && cpi->svc.number_temporal_layers == 1) | 2361 if (is_spatial_svc(cpi)) |
| 2433 res = vp9_svc_lookahead_push(cpi, cpi->lookahead, sd, time_stamp, end_time, | 2362 res = vp9_svc_lookahead_push(cpi, cpi->lookahead, sd, time_stamp, end_time, |
| 2434 frame_flags); | 2363 frame_flags); |
| 2435 else | 2364 else |
| 2436 #endif | 2365 #endif |
| 2437 res = vp9_lookahead_push(cpi->lookahead, | 2366 res = vp9_lookahead_push(cpi->lookahead, |
| 2438 sd, time_stamp, end_time, frame_flags); | 2367 sd, time_stamp, end_time, frame_flags); |
| 2439 if (res) | 2368 if (res) |
| 2440 res = -1; | 2369 res = -1; |
| 2441 vpx_usec_timer_mark(&timer); | 2370 vpx_usec_timer_mark(&timer); |
| 2442 cpi->time_receive_data += vpx_usec_timer_elapsed(&timer); | 2371 cpi->time_receive_data += vpx_usec_timer_elapsed(&timer); |
| 2443 | 2372 |
| 2444 if (cm->profile == PROFILE_0 && (subsampling_x != 1 || subsampling_y != 1)) { | 2373 if ((cm->profile == PROFILE_0 || cm->profile == PROFILE_2) && |
| 2374 (subsampling_x != 1 || subsampling_y != 1)) { |
| 2445 vpx_internal_error(&cm->error, VPX_CODEC_INVALID_PARAM, | 2375 vpx_internal_error(&cm->error, VPX_CODEC_INVALID_PARAM, |
| 2446 "Non-4:2:0 color space requires profile >= 1"); | 2376 "Non-4:2:0 color space requires profile 1 or 3"); |
| 2377 res = -1; |
| 2378 } |
| 2379 if ((cm->profile == PROFILE_1 || cm->profile == PROFILE_3) && |
| 2380 (subsampling_x == 1 && subsampling_y == 1)) { |
| 2381 vpx_internal_error(&cm->error, VPX_CODEC_INVALID_PARAM, |
| 2382 "4:2:0 color space requires profile 0 or 2"); |
| 2447 res = -1; | 2383 res = -1; |
| 2448 } | 2384 } |
| 2449 | 2385 |
| 2450 return res; | 2386 return res; |
| 2451 } | 2387 } |
| 2452 | 2388 |
| 2453 | 2389 |
| 2454 static int frame_is_reference(const VP9_COMP *cpi) { | 2390 static int frame_is_reference(const VP9_COMP *cpi) { |
| 2455 const VP9_COMMON *cm = &cpi->common; | 2391 const VP9_COMMON *cm = &cpi->common; |
| 2456 | 2392 |
| 2457 return cm->frame_type == KEY_FRAME || | 2393 return cm->frame_type == KEY_FRAME || |
| 2458 cpi->refresh_last_frame || | 2394 cpi->refresh_last_frame || |
| 2459 cpi->refresh_golden_frame || | 2395 cpi->refresh_golden_frame || |
| 2460 cpi->refresh_alt_ref_frame || | 2396 cpi->refresh_alt_ref_frame || |
| 2461 cm->refresh_frame_context || | 2397 cm->refresh_frame_context || |
| 2462 cm->lf.mode_ref_delta_update || | 2398 cm->lf.mode_ref_delta_update || |
| 2463 cm->seg.update_map || | 2399 cm->seg.update_map || |
| 2464 cm->seg.update_data; | 2400 cm->seg.update_data; |
| 2465 } | 2401 } |
| 2466 | 2402 |
| 2467 void adjust_frame_rate(VP9_COMP *cpi) { | 2403 void adjust_frame_rate(VP9_COMP *cpi) { |
| 2404 const struct lookahead_entry *const source = cpi->source; |
| 2468 int64_t this_duration; | 2405 int64_t this_duration; |
| 2469 int step = 0; | 2406 int step = 0; |
| 2470 | 2407 |
| 2471 if (cpi->source->ts_start == cpi->first_time_stamp_ever) { | 2408 if (source->ts_start == cpi->first_time_stamp_ever) { |
| 2472 this_duration = cpi->source->ts_end - cpi->source->ts_start; | 2409 this_duration = source->ts_end - source->ts_start; |
| 2473 step = 1; | 2410 step = 1; |
| 2474 } else { | 2411 } else { |
| 2475 int64_t last_duration = cpi->last_end_time_stamp_seen | 2412 int64_t last_duration = cpi->last_end_time_stamp_seen |
| 2476 - cpi->last_time_stamp_seen; | 2413 - cpi->last_time_stamp_seen; |
| 2477 | 2414 |
| 2478 this_duration = cpi->source->ts_end - cpi->last_end_time_stamp_seen; | 2415 this_duration = source->ts_end - cpi->last_end_time_stamp_seen; |
| 2479 | 2416 |
| 2480 // do a step update if the duration changes by 10% | 2417 // do a step update if the duration changes by 10% |
| 2481 if (last_duration) | 2418 if (last_duration) |
| 2482 step = (int)((this_duration - last_duration) * 10 / last_duration); | 2419 step = (int)((this_duration - last_duration) * 10 / last_duration); |
| 2483 } | 2420 } |
| 2484 | 2421 |
| 2485 if (this_duration) { | 2422 if (this_duration) { |
| 2486 if (step) { | 2423 if (step) { |
| 2487 vp9_new_framerate(cpi, 10000000.0 / this_duration); | 2424 vp9_new_framerate(cpi, 10000000.0 / this_duration); |
| 2488 } else { | 2425 } else { |
| 2489 // Average this frame's rate into the last second's average | 2426 // Average this frame's rate into the last second's average |
| 2490 // frame rate. If we haven't seen 1 second yet, then average | 2427 // frame rate. If we haven't seen 1 second yet, then average |
| 2491 // over the whole interval seen. | 2428 // over the whole interval seen. |
| 2492 const double interval = MIN((double)(cpi->source->ts_end | 2429 const double interval = MIN((double)(source->ts_end |
| 2493 - cpi->first_time_stamp_ever), 10000000.0); | 2430 - cpi->first_time_stamp_ever), 10000000.0); |
| 2494 double avg_duration = 10000000.0 / cpi->oxcf.framerate; | 2431 double avg_duration = 10000000.0 / cpi->framerate; |
| 2495 avg_duration *= (interval - avg_duration + this_duration); | 2432 avg_duration *= (interval - avg_duration + this_duration); |
| 2496 avg_duration /= interval; | 2433 avg_duration /= interval; |
| 2497 | 2434 |
| 2498 vp9_new_framerate(cpi, 10000000.0 / avg_duration); | 2435 vp9_new_framerate(cpi, 10000000.0 / avg_duration); |
| 2499 } | 2436 } |
| 2500 } | 2437 } |
| 2501 cpi->last_time_stamp_seen = cpi->source->ts_start; | 2438 cpi->last_time_stamp_seen = source->ts_start; |
| 2502 cpi->last_end_time_stamp_seen = cpi->source->ts_end; | 2439 cpi->last_end_time_stamp_seen = source->ts_end; |
| 2503 } | 2440 } |
| 2504 | 2441 |
| 2505 // Returns 0 if this is not an alt ref else the offset of the source frame | 2442 // Returns 0 if this is not an alt ref else the offset of the source frame |
| 2506 // used as the arf midpoint. | 2443 // used as the arf midpoint. |
| 2507 static int get_arf_src_index(VP9_COMP *cpi) { | 2444 static int get_arf_src_index(VP9_COMP *cpi) { |
| 2508 RATE_CONTROL *const rc = &cpi->rc; | 2445 RATE_CONTROL *const rc = &cpi->rc; |
| 2509 int arf_src_index = 0; | 2446 int arf_src_index = 0; |
| 2510 if (is_altref_enabled(cpi)) { | 2447 if (is_altref_enabled(cpi)) { |
| 2511 if (cpi->pass == 2) { | 2448 if (cpi->oxcf.pass == 2) { |
| 2512 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; | 2449 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 2513 if (gf_group->update_type[gf_group->index] == ARF_UPDATE) { | 2450 if (gf_group->update_type[gf_group->index] == ARF_UPDATE) { |
| 2514 arf_src_index = gf_group->arf_src_offset[gf_group->index]; | 2451 arf_src_index = gf_group->arf_src_offset[gf_group->index]; |
| 2515 } | 2452 } |
| 2516 } else if (rc->source_alt_ref_pending) { | 2453 } else if (rc->source_alt_ref_pending) { |
| 2517 arf_src_index = rc->frames_till_gf_update_due; | 2454 arf_src_index = rc->frames_till_gf_update_due; |
| 2518 } | 2455 } |
| 2519 } | 2456 } |
| 2520 return arf_src_index; | 2457 return arf_src_index; |
| 2521 } | 2458 } |
| 2522 | 2459 |
| 2523 static void check_src_altref(VP9_COMP *cpi) { | 2460 static void check_src_altref(VP9_COMP *cpi) { |
| 2524 RATE_CONTROL *const rc = &cpi->rc; | 2461 RATE_CONTROL *const rc = &cpi->rc; |
| 2525 | 2462 |
| 2526 if (cpi->pass == 2) { | 2463 if (cpi->oxcf.pass == 2) { |
| 2527 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; | 2464 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 2528 rc->is_src_frame_alt_ref = | 2465 rc->is_src_frame_alt_ref = |
| 2529 (gf_group->update_type[gf_group->index] == OVERLAY_UPDATE); | 2466 (gf_group->update_type[gf_group->index] == OVERLAY_UPDATE); |
| 2530 } else { | 2467 } else { |
| 2531 rc->is_src_frame_alt_ref = cpi->alt_ref_source && | 2468 rc->is_src_frame_alt_ref = cpi->alt_ref_source && |
| 2532 (cpi->source == cpi->alt_ref_source); | 2469 (cpi->source == cpi->alt_ref_source); |
| 2533 } | 2470 } |
| 2534 | 2471 |
| 2535 if (rc->is_src_frame_alt_ref) { | 2472 if (rc->is_src_frame_alt_ref) { |
| 2536 // Current frame is an ARF overlay frame. | 2473 // Current frame is an ARF overlay frame. |
| 2537 cpi->alt_ref_source = NULL; | 2474 cpi->alt_ref_source = NULL; |
| 2538 | 2475 |
| 2539 // Don't refresh the last buffer for an ARF overlay frame. It will | 2476 // Don't refresh the last buffer for an ARF overlay frame. It will |
| 2540 // become the GF so preserve last as an alternative prediction option. | 2477 // become the GF so preserve last as an alternative prediction option. |
| 2541 cpi->refresh_last_frame = 0; | 2478 cpi->refresh_last_frame = 0; |
| 2542 } | 2479 } |
| 2543 } | 2480 } |
| 2544 | 2481 |
| 2545 int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, | 2482 int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, |
| 2546 size_t *size, uint8_t *dest, | 2483 size_t *size, uint8_t *dest, |
| 2547 int64_t *time_stamp, int64_t *time_end, int flush) { | 2484 int64_t *time_stamp, int64_t *time_end, int flush) { |
| 2485 const VP9EncoderConfig *const oxcf = &cpi->oxcf; |
| 2548 VP9_COMMON *const cm = &cpi->common; | 2486 VP9_COMMON *const cm = &cpi->common; |
| 2549 MACROBLOCKD *const xd = &cpi->mb.e_mbd; | 2487 MACROBLOCKD *const xd = &cpi->mb.e_mbd; |
| 2550 RATE_CONTROL *const rc = &cpi->rc; | 2488 RATE_CONTROL *const rc = &cpi->rc; |
| 2551 struct vpx_usec_timer cmptimer; | 2489 struct vpx_usec_timer cmptimer; |
| 2552 YV12_BUFFER_CONFIG *force_src_buffer = NULL; | 2490 YV12_BUFFER_CONFIG *force_src_buffer = NULL; |
| 2553 MV_REFERENCE_FRAME ref_frame; | 2491 MV_REFERENCE_FRAME ref_frame; |
| 2554 int arf_src_index; | 2492 int arf_src_index; |
| 2555 const int is_spatial_svc = cpi->use_svc && | |
| 2556 (cpi->svc.number_temporal_layers == 1) && | |
| 2557 (cpi->svc.number_spatial_layers > 1); | |
| 2558 | 2493 |
| 2559 if (!cpi) | 2494 if (is_spatial_svc(cpi) && oxcf->pass == 2) { |
| 2560 return -1; | |
| 2561 | |
| 2562 if (is_spatial_svc && cpi->pass == 2) { | |
| 2563 #if CONFIG_SPATIAL_SVC | 2495 #if CONFIG_SPATIAL_SVC |
| 2564 vp9_svc_lookahead_peek(cpi, cpi->lookahead, 0, 1); | 2496 vp9_svc_lookahead_peek(cpi, cpi->lookahead, 0, 1); |
| 2565 #endif | 2497 #endif |
| 2566 vp9_restore_layer_context(cpi); | 2498 vp9_restore_layer_context(cpi); |
| 2567 } | 2499 } |
| 2568 | 2500 |
| 2569 vpx_usec_timer_start(&cmptimer); | 2501 vpx_usec_timer_start(&cmptimer); |
| 2570 | 2502 |
| 2571 cpi->source = NULL; | 2503 cpi->source = NULL; |
| 2572 cpi->last_source = NULL; | 2504 cpi->last_source = NULL; |
| 2573 | 2505 |
| 2574 vp9_set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV); | 2506 vp9_set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV); |
| 2575 | 2507 |
| 2576 // Normal defaults | 2508 // Normal defaults |
| 2577 cm->reset_frame_context = 0; | 2509 cm->reset_frame_context = 0; |
| 2578 cm->refresh_frame_context = 1; | 2510 cm->refresh_frame_context = 1; |
| 2579 cpi->refresh_last_frame = 1; | 2511 cpi->refresh_last_frame = 1; |
| 2580 cpi->refresh_golden_frame = 0; | 2512 cpi->refresh_golden_frame = 0; |
| 2581 cpi->refresh_alt_ref_frame = 0; | 2513 cpi->refresh_alt_ref_frame = 0; |
| 2582 | 2514 |
| 2583 // Should we encode an arf frame. | 2515 // Should we encode an arf frame. |
| 2584 arf_src_index = get_arf_src_index(cpi); | 2516 arf_src_index = get_arf_src_index(cpi); |
| 2585 if (arf_src_index) { | 2517 if (arf_src_index) { |
| 2586 assert(arf_src_index <= rc->frames_to_key); | 2518 assert(arf_src_index <= rc->frames_to_key); |
| 2587 | 2519 |
| 2588 #if CONFIG_SPATIAL_SVC | 2520 #if CONFIG_SPATIAL_SVC |
| 2589 if (is_spatial_svc) | 2521 if (is_spatial_svc(cpi)) |
| 2590 cpi->source = vp9_svc_lookahead_peek(cpi, cpi->lookahead, | 2522 cpi->source = vp9_svc_lookahead_peek(cpi, cpi->lookahead, |
| 2591 arf_src_index, 0); | 2523 arf_src_index, 0); |
| 2592 else | 2524 else |
| 2593 #endif | 2525 #endif |
| 2594 cpi->source = vp9_lookahead_peek(cpi->lookahead, arf_src_index); | 2526 cpi->source = vp9_lookahead_peek(cpi->lookahead, arf_src_index); |
| 2595 if (cpi->source != NULL) { | 2527 if (cpi->source != NULL) { |
| 2596 cpi->alt_ref_source = cpi->source; | 2528 cpi->alt_ref_source = cpi->source; |
| 2597 | 2529 |
| 2598 #if CONFIG_SPATIAL_SVC | 2530 #if CONFIG_SPATIAL_SVC |
| 2599 if (is_spatial_svc && cpi->svc.spatial_layer_id > 0) { | 2531 if (is_spatial_svc(cpi) && cpi->svc.spatial_layer_id > 0) { |
| 2600 int i; | 2532 int i; |
| 2601 // Reference a hidden frame from a lower layer | 2533 // Reference a hidden frame from a lower layer |
| 2602 for (i = cpi->svc.spatial_layer_id - 1; i >= 0; --i) { | 2534 for (i = cpi->svc.spatial_layer_id - 1; i >= 0; --i) { |
| 2603 if (cpi->oxcf.ss_play_alternate[i]) { | 2535 if (oxcf->ss_play_alternate[i]) { |
| 2604 cpi->gld_fb_idx = cpi->svc.layer_context[i].alt_ref_idx; | 2536 cpi->gld_fb_idx = cpi->svc.layer_context[i].alt_ref_idx; |
| 2605 break; | 2537 break; |
| 2606 } | 2538 } |
| 2607 } | 2539 } |
| 2608 } | 2540 } |
| 2609 cpi->svc.layer_context[cpi->svc.spatial_layer_id].has_alt_frame = 1; | 2541 cpi->svc.layer_context[cpi->svc.spatial_layer_id].has_alt_frame = 1; |
| 2610 #endif | 2542 #endif |
| 2611 | 2543 |
| 2612 if (cpi->oxcf.arnr_max_frames > 0) { | 2544 if (oxcf->arnr_max_frames > 0) { |
| 2613 // Produce the filtered ARF frame. | 2545 // Produce the filtered ARF frame. |
| 2614 vp9_temporal_filter(cpi, arf_src_index); | 2546 vp9_temporal_filter(cpi, arf_src_index); |
| 2615 vp9_extend_frame_borders(&cpi->alt_ref_buffer); | 2547 vp9_extend_frame_borders(&cpi->alt_ref_buffer); |
| 2616 force_src_buffer = &cpi->alt_ref_buffer; | 2548 force_src_buffer = &cpi->alt_ref_buffer; |
| 2617 } | 2549 } |
| 2618 | 2550 |
| 2619 cm->show_frame = 0; | 2551 cm->show_frame = 0; |
| 2620 cpi->refresh_alt_ref_frame = 1; | 2552 cpi->refresh_alt_ref_frame = 1; |
| 2621 cpi->refresh_golden_frame = 0; | 2553 cpi->refresh_golden_frame = 0; |
| 2622 cpi->refresh_last_frame = 0; | 2554 cpi->refresh_last_frame = 0; |
| 2623 rc->is_src_frame_alt_ref = 0; | 2555 rc->is_src_frame_alt_ref = 0; |
| 2624 rc->source_alt_ref_pending = 0; | 2556 rc->source_alt_ref_pending = 0; |
| 2625 } else { | 2557 } else { |
| 2626 rc->source_alt_ref_pending = 0; | 2558 rc->source_alt_ref_pending = 0; |
| 2627 } | 2559 } |
| 2628 } | 2560 } |
| 2629 | 2561 |
| 2630 if (!cpi->source) { | 2562 if (!cpi->source) { |
| 2631 // Get last frame source. | 2563 // Get last frame source. |
| 2632 if (cm->current_video_frame > 0) { | 2564 if (cm->current_video_frame > 0) { |
| 2633 #if CONFIG_SPATIAL_SVC | 2565 #if CONFIG_SPATIAL_SVC |
| 2634 if (is_spatial_svc) | 2566 if (is_spatial_svc(cpi)) |
| 2635 cpi->last_source = vp9_svc_lookahead_peek(cpi, cpi->lookahead, -1, 0); | 2567 cpi->last_source = vp9_svc_lookahead_peek(cpi, cpi->lookahead, -1, 0); |
| 2636 else | 2568 else |
| 2637 #endif | 2569 #endif |
| 2638 cpi->last_source = vp9_lookahead_peek(cpi->lookahead, -1); | 2570 cpi->last_source = vp9_lookahead_peek(cpi->lookahead, -1); |
| 2639 if (cpi->last_source == NULL) | 2571 if (cpi->last_source == NULL) |
| 2640 return -1; | 2572 return -1; |
| 2641 } | 2573 } |
| 2642 | 2574 |
| 2643 // Read in the source frame. | 2575 // Read in the source frame. |
| 2644 #if CONFIG_SPATIAL_SVC | 2576 #if CONFIG_SPATIAL_SVC |
| 2645 if (is_spatial_svc) | 2577 if (is_spatial_svc(cpi)) |
| 2646 cpi->source = vp9_svc_lookahead_pop(cpi, cpi->lookahead, flush); | 2578 cpi->source = vp9_svc_lookahead_pop(cpi, cpi->lookahead, flush); |
| 2647 else | 2579 else |
| 2648 #endif | 2580 #endif |
| 2649 cpi->source = vp9_lookahead_pop(cpi->lookahead, flush); | 2581 cpi->source = vp9_lookahead_pop(cpi->lookahead, flush); |
| 2650 if (cpi->source != NULL) { | 2582 if (cpi->source != NULL) { |
| 2651 cm->show_frame = 1; | 2583 cm->show_frame = 1; |
| 2652 cm->intra_only = 0; | 2584 cm->intra_only = 0; |
| 2653 | 2585 |
| 2654 // Check to see if the frame should be encoded as an arf overlay. | 2586 // Check to see if the frame should be encoded as an arf overlay. |
| 2655 check_src_altref(cpi); | 2587 check_src_altref(cpi); |
| 2656 } | 2588 } |
| 2657 } | 2589 } |
| 2658 | 2590 |
| 2659 if (cpi->source) { | 2591 if (cpi->source) { |
| 2660 cpi->un_scaled_source = cpi->Source = force_src_buffer ? force_src_buffer | 2592 cpi->un_scaled_source = cpi->Source = force_src_buffer ? force_src_buffer |
| 2661 : &cpi->source->img; | 2593 : &cpi->source->img; |
| 2662 | 2594 |
| 2663 if (cpi->last_source != NULL) { | 2595 cpi->unscaled_last_source = cpi->last_source != NULL ? |
| 2664 cpi->unscaled_last_source = &cpi->last_source->img; | 2596 &cpi->last_source->img : NULL; |
| 2665 } else { | |
| 2666 cpi->unscaled_last_source = NULL; | |
| 2667 } | |
| 2668 | 2597 |
| 2669 *time_stamp = cpi->source->ts_start; | 2598 *time_stamp = cpi->source->ts_start; |
| 2670 *time_end = cpi->source->ts_end; | 2599 *time_end = cpi->source->ts_end; |
| 2671 *frame_flags = | 2600 *frame_flags = |
| 2672 (cpi->source->flags & VPX_EFLAG_FORCE_KF) ? FRAMEFLAGS_KEY : 0; | 2601 (cpi->source->flags & VPX_EFLAG_FORCE_KF) ? FRAMEFLAGS_KEY : 0; |
| 2673 | 2602 |
| 2674 } else { | 2603 } else { |
| 2675 *size = 0; | 2604 *size = 0; |
| 2676 if (flush && cpi->pass == 1 && !cpi->twopass.first_pass_done) { | 2605 if (flush && oxcf->pass == 1 && !cpi->twopass.first_pass_done) { |
| 2677 vp9_end_first_pass(cpi); /* get last stats packet */ | 2606 vp9_end_first_pass(cpi); /* get last stats packet */ |
| 2678 cpi->twopass.first_pass_done = 1; | 2607 cpi->twopass.first_pass_done = 1; |
| 2679 } | 2608 } |
| 2680 return -1; | 2609 return -1; |
| 2681 } | 2610 } |
| 2682 | 2611 |
| 2683 if (cpi->source->ts_start < cpi->first_time_stamp_ever) { | 2612 if (cpi->source->ts_start < cpi->first_time_stamp_ever) { |
| 2684 cpi->first_time_stamp_ever = cpi->source->ts_start; | 2613 cpi->first_time_stamp_ever = cpi->source->ts_start; |
| 2685 cpi->last_end_time_stamp_seen = cpi->source->ts_start; | 2614 cpi->last_end_time_stamp_seen = cpi->source->ts_start; |
| 2686 } | 2615 } |
| 2687 | 2616 |
| 2688 // Clear down mmx registers | 2617 // Clear down mmx registers |
| 2689 vp9_clear_system_state(); | 2618 vp9_clear_system_state(); |
| 2690 | 2619 |
| 2691 // adjust frame rates based on timestamps given | 2620 // adjust frame rates based on timestamps given |
| 2692 if (cm->show_frame) { | 2621 if (cm->show_frame) { |
| 2693 adjust_frame_rate(cpi); | 2622 adjust_frame_rate(cpi); |
| 2694 } | 2623 } |
| 2695 | 2624 |
| 2696 if (cpi->svc.number_temporal_layers > 1 && | 2625 if (cpi->svc.number_temporal_layers > 1 && |
| 2697 cpi->oxcf.rc_mode == VPX_CBR) { | 2626 oxcf->rc_mode == VPX_CBR) { |
| 2698 vp9_update_temporal_layer_framerate(cpi); | 2627 vp9_update_temporal_layer_framerate(cpi); |
| 2699 vp9_restore_layer_context(cpi); | 2628 vp9_restore_layer_context(cpi); |
| 2700 } | 2629 } |
| 2701 | 2630 |
| 2702 // start with a 0 size frame | 2631 // start with a 0 size frame |
| 2703 *size = 0; | 2632 *size = 0; |
| 2704 | 2633 |
| 2705 /* find a free buffer for the new frame, releasing the reference previously | 2634 /* find a free buffer for the new frame, releasing the reference previously |
| 2706 * held. | 2635 * held. |
| 2707 */ | 2636 */ |
| 2708 cm->frame_bufs[cm->new_fb_idx].ref_count--; | 2637 cm->frame_bufs[cm->new_fb_idx].ref_count--; |
| 2709 cm->new_fb_idx = get_free_fb(cm); | 2638 cm->new_fb_idx = get_free_fb(cm); |
| 2710 | 2639 |
| 2711 if (!cpi->use_svc && cpi->multi_arf_allowed) { | 2640 if (!cpi->use_svc && cpi->multi_arf_allowed) { |
| 2712 if (cm->frame_type == KEY_FRAME) { | 2641 if (cm->frame_type == KEY_FRAME) { |
| 2713 init_buffer_indices(cpi); | 2642 init_buffer_indices(cpi); |
| 2714 } else if (cpi->pass == 2) { | 2643 } else if (oxcf->pass == 2) { |
| 2715 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; | 2644 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 2716 cpi->alt_fb_idx = gf_group->arf_ref_idx[gf_group->index]; | 2645 cpi->alt_fb_idx = gf_group->arf_ref_idx[gf_group->index]; |
| 2717 } | 2646 } |
| 2718 } | 2647 } |
| 2719 | 2648 |
| 2720 cpi->frame_flags = *frame_flags; | 2649 cpi->frame_flags = *frame_flags; |
| 2721 | 2650 |
| 2722 if (cpi->pass == 2 && | 2651 if (oxcf->pass == 2 && |
| 2723 cm->current_video_frame == 0 && | 2652 cm->current_video_frame == 0 && |
| 2724 cpi->oxcf.allow_spatial_resampling && | 2653 oxcf->allow_spatial_resampling && |
| 2725 cpi->oxcf.rc_mode == VPX_VBR) { | 2654 oxcf->rc_mode == VPX_VBR) { |
| 2726 // Internal scaling is triggered on the first frame. | 2655 // Internal scaling is triggered on the first frame. |
| 2727 vp9_set_size_literal(cpi, cpi->oxcf.scaled_frame_width, | 2656 vp9_set_size_literal(cpi, oxcf->scaled_frame_width, |
| 2728 cpi->oxcf.scaled_frame_height); | 2657 oxcf->scaled_frame_height); |
| 2729 } | 2658 } |
| 2730 | 2659 |
| 2731 // Reset the frame pointers to the current frame size | 2660 // Reset the frame pointers to the current frame size |
| 2732 vp9_realloc_frame_buffer(get_frame_new_buffer(cm), | 2661 vp9_realloc_frame_buffer(get_frame_new_buffer(cm), |
| 2733 cm->width, cm->height, | 2662 cm->width, cm->height, |
| 2734 cm->subsampling_x, cm->subsampling_y, | 2663 cm->subsampling_x, cm->subsampling_y, |
| 2735 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL); | 2664 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL); |
| 2736 | 2665 |
| 2737 alloc_util_frame_buffers(cpi); | 2666 alloc_util_frame_buffers(cpi); |
| 2738 init_motion_estimation(cpi); | 2667 init_motion_estimation(cpi); |
| 2739 | 2668 |
| 2740 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { | 2669 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 2741 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; | 2670 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; |
| 2742 YV12_BUFFER_CONFIG *const buf = &cm->frame_bufs[idx].buf; | 2671 YV12_BUFFER_CONFIG *const buf = &cm->frame_bufs[idx].buf; |
| 2743 RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - 1]; | 2672 RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - 1]; |
| 2744 ref_buf->buf = buf; | 2673 ref_buf->buf = buf; |
| 2745 ref_buf->idx = idx; | 2674 ref_buf->idx = idx; |
| 2746 vp9_setup_scale_factors_for_frame(&ref_buf->sf, | 2675 vp9_setup_scale_factors_for_frame(&ref_buf->sf, |
| 2747 buf->y_crop_width, buf->y_crop_height, | 2676 buf->y_crop_width, buf->y_crop_height, |
| 2748 cm->width, cm->height); | 2677 cm->width, cm->height); |
| 2749 | 2678 |
| 2750 if (vp9_is_scaled(&ref_buf->sf)) | 2679 if (vp9_is_scaled(&ref_buf->sf)) |
| 2751 vp9_extend_frame_borders(buf); | 2680 vp9_extend_frame_borders(buf); |
| 2752 } | 2681 } |
| 2753 | 2682 |
| 2754 set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); | 2683 set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); |
| 2755 | 2684 |
| 2756 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { | 2685 if (oxcf->aq_mode == VARIANCE_AQ) { |
| 2757 vp9_vaq_init(); | 2686 vp9_vaq_init(); |
| 2758 } | 2687 } |
| 2759 | 2688 |
| 2760 if (cpi->pass == 1 && | 2689 if (oxcf->pass == 1 && |
| 2761 (!cpi->use_svc || cpi->svc.number_temporal_layers == 1)) { | 2690 (!cpi->use_svc || is_spatial_svc(cpi))) { |
| 2762 const int lossless = is_lossless_requested(&cpi->oxcf); | 2691 const int lossless = is_lossless_requested(oxcf); |
| 2763 cpi->mb.fwd_txm4x4 = lossless ? vp9_fwht4x4 : vp9_fdct4x4; | 2692 cpi->mb.fwd_txm4x4 = lossless ? vp9_fwht4x4 : vp9_fdct4x4; |
| 2764 cpi->mb.itxm_add = lossless ? vp9_iwht4x4_add : vp9_idct4x4_add; | 2693 cpi->mb.itxm_add = lossless ? vp9_iwht4x4_add : vp9_idct4x4_add; |
| 2765 vp9_first_pass(cpi); | 2694 vp9_first_pass(cpi); |
| 2766 } else if (cpi->pass == 2 && | 2695 } else if (oxcf->pass == 2 && |
| 2767 (!cpi->use_svc || cpi->svc.number_temporal_layers == 1)) { | 2696 (!cpi->use_svc || is_spatial_svc(cpi))) { |
| 2768 Pass2Encode(cpi, size, dest, frame_flags); | 2697 Pass2Encode(cpi, size, dest, frame_flags); |
| 2769 } else if (cpi->use_svc) { | 2698 } else if (cpi->use_svc) { |
| 2770 SvcEncode(cpi, size, dest, frame_flags); | 2699 SvcEncode(cpi, size, dest, frame_flags); |
| 2771 } else { | 2700 } else { |
| 2772 // One pass encode | 2701 // One pass encode |
| 2773 Pass0Encode(cpi, size, dest, frame_flags); | 2702 Pass0Encode(cpi, size, dest, frame_flags); |
| 2774 } | 2703 } |
| 2775 | 2704 |
| 2776 if (cm->refresh_frame_context) | 2705 if (cm->refresh_frame_context) |
| 2777 cm->frame_contexts[cm->frame_context_idx] = cm->fc; | 2706 cm->frame_contexts[cm->frame_context_idx] = cm->fc; |
| 2778 | 2707 |
| 2779 // Frame was dropped, release scaled references. | 2708 // Frame was dropped, release scaled references. |
| 2780 if (*size == 0) { | 2709 if (*size == 0) { |
| 2781 release_scaled_references(cpi); | 2710 release_scaled_references(cpi); |
| 2782 } | 2711 } |
| 2783 | 2712 |
| 2784 if (*size > 0) { | 2713 if (*size > 0) { |
| 2785 cpi->droppable = !frame_is_reference(cpi); | 2714 cpi->droppable = !frame_is_reference(cpi); |
| 2786 } | 2715 } |
| 2787 | 2716 |
| 2788 // Save layer specific state. | 2717 // Save layer specific state. |
| 2789 if ((cpi->svc.number_temporal_layers > 1 && | 2718 if ((cpi->svc.number_temporal_layers > 1 && |
| 2790 cpi->oxcf.rc_mode == VPX_CBR) || | 2719 oxcf->rc_mode == VPX_CBR) || |
| 2791 (cpi->svc.number_spatial_layers > 1 && cpi->pass == 2)) { | 2720 (cpi->svc.number_spatial_layers > 1 && oxcf->pass == 2)) { |
| 2792 vp9_save_layer_context(cpi); | 2721 vp9_save_layer_context(cpi); |
| 2793 } | 2722 } |
| 2794 | 2723 |
| 2795 vpx_usec_timer_mark(&cmptimer); | 2724 vpx_usec_timer_mark(&cmptimer); |
| 2796 cpi->time_compress_data += vpx_usec_timer_elapsed(&cmptimer); | 2725 cpi->time_compress_data += vpx_usec_timer_elapsed(&cmptimer); |
| 2797 | 2726 |
| 2798 if (cpi->b_calculate_psnr && cpi->pass != 1 && cm->show_frame) | 2727 if (cpi->b_calculate_psnr && oxcf->pass != 1 && cm->show_frame) |
| 2799 generate_psnr_packet(cpi); | 2728 generate_psnr_packet(cpi); |
| 2800 | 2729 |
| 2801 #if CONFIG_INTERNAL_STATS | 2730 #if CONFIG_INTERNAL_STATS |
| 2802 | 2731 |
| 2803 if (cpi->pass != 1) { | 2732 if (oxcf->pass != 1) { |
| 2804 cpi->bytes += (int)(*size); | 2733 cpi->bytes += (int)(*size); |
| 2805 | 2734 |
| 2806 if (cm->show_frame) { | 2735 if (cm->show_frame) { |
| 2807 cpi->count++; | 2736 cpi->count++; |
| 2808 | 2737 |
| 2809 if (cpi->b_calculate_psnr) { | 2738 if (cpi->b_calculate_psnr) { |
| 2810 YV12_BUFFER_CONFIG *orig = cpi->Source; | 2739 YV12_BUFFER_CONFIG *orig = cpi->Source; |
| 2811 YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show; | 2740 YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show; |
| 2812 YV12_BUFFER_CONFIG *pp = &cm->post_proc_buffer; | 2741 YV12_BUFFER_CONFIG *pp = &cm->post_proc_buffer; |
| 2813 PSNR_STATS psnr; | 2742 PSNR_STATS psnr; |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3037 if (flags & VP8_EFLAG_NO_UPD_ARF) | 2966 if (flags & VP8_EFLAG_NO_UPD_ARF) |
| 3038 upd ^= VP9_ALT_FLAG; | 2967 upd ^= VP9_ALT_FLAG; |
| 3039 | 2968 |
| 3040 vp9_update_reference(cpi, upd); | 2969 vp9_update_reference(cpi, upd); |
| 3041 } | 2970 } |
| 3042 | 2971 |
| 3043 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) { | 2972 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) { |
| 3044 vp9_update_entropy(cpi, 0); | 2973 vp9_update_entropy(cpi, 0); |
| 3045 } | 2974 } |
| 3046 } | 2975 } |
| OLD | NEW |