| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 #include "./vpx_config.h" | 10 #include "./vpx_config.h" |
| 11 #include "third_party/googletest/src/include/gtest/gtest.h" | 11 #include "third_party/googletest/src/include/gtest/gtest.h" |
| 12 #include "test/codec_factory.h" | 12 #include "test/codec_factory.h" |
| 13 #include "test/encode_test_driver.h" | 13 #include "test/encode_test_driver.h" |
| 14 #include "test/i420_video_source.h" | 14 #include "test/i420_video_source.h" |
| 15 #include "test/util.h" | 15 #include "test/util.h" |
| 16 #include "test/y4m_video_source.h" | 16 #include "test/y4m_video_source.h" |
| 17 #include "vpx/vpx_codec.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 class DatarateTestLarge : public ::libvpx_test::EncoderTest, | 21 class DatarateTestLarge : public ::libvpx_test::EncoderTest, |
| 21 public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> { | 22 public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> { |
| 22 public: | 23 public: |
| 23 DatarateTestLarge() : EncoderTest(GET_PARAM(0)) {} | 24 DatarateTestLarge() : EncoderTest(GET_PARAM(0)) {} |
| 24 | 25 |
| 25 virtual ~DatarateTestLarge() {} | 26 virtual ~DatarateTestLarge() {} |
| 26 | 27 |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 } | 365 } |
| 365 } | 366 } |
| 366 | 367 |
| 367 encoder->Control(VP9E_SET_NOISE_SENSITIVITY, denoiser_on_); | 368 encoder->Control(VP9E_SET_NOISE_SENSITIVITY, denoiser_on_); |
| 368 | 369 |
| 369 if (cfg_.ts_number_layers > 1) { | 370 if (cfg_.ts_number_layers > 1) { |
| 370 if (video->frame() == 0) { | 371 if (video->frame() == 0) { |
| 371 encoder->Control(VP9E_SET_SVC, 1); | 372 encoder->Control(VP9E_SET_SVC, 1); |
| 372 } | 373 } |
| 373 vpx_svc_layer_id_t layer_id; | 374 vpx_svc_layer_id_t layer_id; |
| 374 #if VPX_ENCODER_ABI_VERSION > (4 + VPX_CODEC_ABI_VERSION) | |
| 375 layer_id.spatial_layer_id = 0; | 375 layer_id.spatial_layer_id = 0; |
| 376 #endif | |
| 377 frame_flags_ = SetFrameFlags(video->frame(), cfg_.ts_number_layers); | 376 frame_flags_ = SetFrameFlags(video->frame(), cfg_.ts_number_layers); |
| 378 layer_id.temporal_layer_id = SetLayerId(video->frame(), | 377 layer_id.temporal_layer_id = SetLayerId(video->frame(), |
| 379 cfg_.ts_number_layers); | 378 cfg_.ts_number_layers); |
| 380 encoder->Control(VP9E_SET_SVC_LAYER_ID, &layer_id); | 379 encoder->Control(VP9E_SET_SVC_LAYER_ID, &layer_id); |
| 381 } | 380 } |
| 382 const vpx_rational_t tb = video->timebase(); | 381 const vpx_rational_t tb = video->timebase(); |
| 383 timebase_ = static_cast<double>(tb.num) / tb.den; | 382 timebase_ = static_cast<double>(tb.num) / tb.den; |
| 384 duration_ = 0; | 383 duration_ = 0; |
| 385 } | 384 } |
| 386 | 385 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 cfg_.rc_max_quantizer = 63; | 557 cfg_.rc_max_quantizer = 63; |
| 559 cfg_.rc_end_usage = VPX_CBR; | 558 cfg_.rc_end_usage = VPX_CBR; |
| 560 cfg_.g_lag_in_frames = 0; | 559 cfg_.g_lag_in_frames = 0; |
| 561 | 560 |
| 562 // 2 Temporal layers, no spatial layers: Framerate decimation (2, 1). | 561 // 2 Temporal layers, no spatial layers: Framerate decimation (2, 1). |
| 563 cfg_.ss_number_layers = 1; | 562 cfg_.ss_number_layers = 1; |
| 564 cfg_.ts_number_layers = 2; | 563 cfg_.ts_number_layers = 2; |
| 565 cfg_.ts_rate_decimator[0] = 2; | 564 cfg_.ts_rate_decimator[0] = 2; |
| 566 cfg_.ts_rate_decimator[1] = 1; | 565 cfg_.ts_rate_decimator[1] = 1; |
| 567 | 566 |
| 567 cfg_.temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_BYPASS; |
| 568 |
| 568 if (deadline_ == VPX_DL_REALTIME) | 569 if (deadline_ == VPX_DL_REALTIME) |
| 569 cfg_.g_error_resilient = 1; | 570 cfg_.g_error_resilient = 1; |
| 570 | 571 |
| 571 ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, | 572 ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
| 572 30, 1, 0, 200); | 573 30, 1, 0, 200); |
| 573 for (int i = 200; i <= 800; i += 200) { | 574 for (int i = 200; i <= 800; i += 200) { |
| 574 cfg_.rc_target_bitrate = i; | 575 cfg_.rc_target_bitrate = i; |
| 575 ResetModel(); | 576 ResetModel(); |
| 576 // 60-40 bitrate allocation for 2 temporal layers. | 577 // 60-40 bitrate allocation for 2 temporal layers. |
| 577 cfg_.ts_target_bitrate[0] = 60 * cfg_.rc_target_bitrate / 100; | 578 cfg_.layer_target_bitrate[0] = 60 * cfg_.rc_target_bitrate / 100; |
| 578 cfg_.ts_target_bitrate[1] = cfg_.rc_target_bitrate; | 579 cfg_.layer_target_bitrate[1] = cfg_.rc_target_bitrate; |
| 579 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); | 580 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 580 for (int j = 0; j < static_cast<int>(cfg_.ts_number_layers); ++j) { | 581 for (int j = 0; j < static_cast<int>(cfg_.ts_number_layers); ++j) { |
| 581 ASSERT_GE(effective_datarate_[j], cfg_.ts_target_bitrate[j] * 0.85) | 582 ASSERT_GE(effective_datarate_[j], cfg_.layer_target_bitrate[j] * 0.85) |
| 582 << " The datarate for the file is lower than target by too much, " | 583 << " The datarate for the file is lower than target by too much, " |
| 583 "for layer: " << j; | 584 "for layer: " << j; |
| 584 ASSERT_LE(effective_datarate_[j], cfg_.ts_target_bitrate[j] * 1.15) | 585 ASSERT_LE(effective_datarate_[j], cfg_.layer_target_bitrate[j] * 1.15) |
| 585 << " The datarate for the file is greater than target by too much, " | 586 << " The datarate for the file is greater than target by too much, " |
| 586 "for layer: " << j; | 587 "for layer: " << j; |
| 587 } | 588 } |
| 588 } | 589 } |
| 589 } | 590 } |
| 590 | 591 |
| 591 // Check basic rate targeting for 3 temporal layers. | 592 // Check basic rate targeting for 3 temporal layers. |
| 592 TEST_P(DatarateTestVP9Large, BasicRateTargeting3TemporalLayers) { | 593 TEST_P(DatarateTestVP9Large, BasicRateTargeting3TemporalLayers) { |
| 593 cfg_.rc_buf_initial_sz = 500; | 594 cfg_.rc_buf_initial_sz = 500; |
| 594 cfg_.rc_buf_optimal_sz = 500; | 595 cfg_.rc_buf_optimal_sz = 500; |
| 595 cfg_.rc_buf_sz = 1000; | 596 cfg_.rc_buf_sz = 1000; |
| 596 cfg_.rc_dropframe_thresh = 1; | 597 cfg_.rc_dropframe_thresh = 1; |
| 597 cfg_.rc_min_quantizer = 0; | 598 cfg_.rc_min_quantizer = 0; |
| 598 cfg_.rc_max_quantizer = 63; | 599 cfg_.rc_max_quantizer = 63; |
| 599 cfg_.rc_end_usage = VPX_CBR; | 600 cfg_.rc_end_usage = VPX_CBR; |
| 600 cfg_.g_lag_in_frames = 0; | 601 cfg_.g_lag_in_frames = 0; |
| 601 | 602 |
| 602 // 3 Temporal layers, no spatial layers: Framerate decimation (4, 2, 1). | 603 // 3 Temporal layers, no spatial layers: Framerate decimation (4, 2, 1). |
| 603 cfg_.ss_number_layers = 1; | 604 cfg_.ss_number_layers = 1; |
| 604 cfg_.ts_number_layers = 3; | 605 cfg_.ts_number_layers = 3; |
| 605 cfg_.ts_rate_decimator[0] = 4; | 606 cfg_.ts_rate_decimator[0] = 4; |
| 606 cfg_.ts_rate_decimator[1] = 2; | 607 cfg_.ts_rate_decimator[1] = 2; |
| 607 cfg_.ts_rate_decimator[2] = 1; | 608 cfg_.ts_rate_decimator[2] = 1; |
| 608 | 609 |
| 610 cfg_.temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_BYPASS; |
| 611 |
| 609 ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, | 612 ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
| 610 30, 1, 0, 200); | 613 30, 1, 0, 200); |
| 611 for (int i = 200; i <= 800; i += 200) { | 614 for (int i = 200; i <= 800; i += 200) { |
| 612 cfg_.rc_target_bitrate = i; | 615 cfg_.rc_target_bitrate = i; |
| 613 ResetModel(); | 616 ResetModel(); |
| 614 // 40-20-40 bitrate allocation for 3 temporal layers. | 617 // 40-20-40 bitrate allocation for 3 temporal layers. |
| 615 cfg_.ts_target_bitrate[0] = 40 * cfg_.rc_target_bitrate / 100; | 618 cfg_.layer_target_bitrate[0] = 40 * cfg_.rc_target_bitrate / 100; |
| 616 cfg_.ts_target_bitrate[1] = 60 * cfg_.rc_target_bitrate / 100; | 619 cfg_.layer_target_bitrate[1] = 60 * cfg_.rc_target_bitrate / 100; |
| 617 cfg_.ts_target_bitrate[2] = cfg_.rc_target_bitrate; | 620 cfg_.layer_target_bitrate[2] = cfg_.rc_target_bitrate; |
| 618 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); | 621 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 619 for (int j = 0; j < static_cast<int>(cfg_.ts_number_layers); ++j) { | 622 for (int j = 0; j < static_cast<int>(cfg_.ts_number_layers); ++j) { |
| 620 // TODO(yaowu): Work out more stable rc control strategy and | 623 // TODO(yaowu): Work out more stable rc control strategy and |
| 621 // Adjust the thresholds to be tighter than .75. | 624 // Adjust the thresholds to be tighter than .75. |
| 622 ASSERT_GE(effective_datarate_[j], cfg_.ts_target_bitrate[j] * 0.75) | 625 ASSERT_GE(effective_datarate_[j], cfg_.layer_target_bitrate[j] * 0.75) |
| 623 << " The datarate for the file is lower than target by too much, " | 626 << " The datarate for the file is lower than target by too much, " |
| 624 "for layer: " << j; | 627 "for layer: " << j; |
| 625 // TODO(yaowu): Work out more stable rc control strategy and | 628 // TODO(yaowu): Work out more stable rc control strategy and |
| 626 // Adjust the thresholds to be tighter than 1.25. | 629 // Adjust the thresholds to be tighter than 1.25. |
| 627 ASSERT_LE(effective_datarate_[j], cfg_.ts_target_bitrate[j] * 1.25) | 630 ASSERT_LE(effective_datarate_[j], cfg_.layer_target_bitrate[j] * 1.25) |
| 628 << " The datarate for the file is greater than target by too much, " | 631 << " The datarate for the file is greater than target by too much, " |
| 629 "for layer: " << j; | 632 "for layer: " << j; |
| 630 } | 633 } |
| 631 } | 634 } |
| 632 } | 635 } |
| 633 | 636 |
| 634 // Check basic rate targeting for 3 temporal layers, with frame dropping. | 637 // Check basic rate targeting for 3 temporal layers, with frame dropping. |
| 635 // Only for one (low) bitrate with lower max_quantizer, and somewhat higher | 638 // Only for one (low) bitrate with lower max_quantizer, and somewhat higher |
| 636 // frame drop threshold, to force frame dropping. | 639 // frame drop threshold, to force frame dropping. |
| 637 TEST_P(DatarateTestVP9Large, BasicRateTargeting3TemporalLayersFrameDropping) { | 640 TEST_P(DatarateTestVP9Large, BasicRateTargeting3TemporalLayersFrameDropping) { |
| 638 cfg_.rc_buf_initial_sz = 500; | 641 cfg_.rc_buf_initial_sz = 500; |
| 639 cfg_.rc_buf_optimal_sz = 500; | 642 cfg_.rc_buf_optimal_sz = 500; |
| 640 cfg_.rc_buf_sz = 1000; | 643 cfg_.rc_buf_sz = 1000; |
| 641 // Set frame drop threshold and rc_max_quantizer to force some frame drops. | 644 // Set frame drop threshold and rc_max_quantizer to force some frame drops. |
| 642 cfg_.rc_dropframe_thresh = 20; | 645 cfg_.rc_dropframe_thresh = 20; |
| 643 cfg_.rc_max_quantizer = 45; | 646 cfg_.rc_max_quantizer = 45; |
| 644 cfg_.rc_min_quantizer = 0; | 647 cfg_.rc_min_quantizer = 0; |
| 645 cfg_.rc_end_usage = VPX_CBR; | 648 cfg_.rc_end_usage = VPX_CBR; |
| 646 cfg_.g_lag_in_frames = 0; | 649 cfg_.g_lag_in_frames = 0; |
| 647 | 650 |
| 648 // 3 Temporal layers, no spatial layers: Framerate decimation (4, 2, 1). | 651 // 3 Temporal layers, no spatial layers: Framerate decimation (4, 2, 1). |
| 649 cfg_.ss_number_layers = 1; | 652 cfg_.ss_number_layers = 1; |
| 650 cfg_.ts_number_layers = 3; | 653 cfg_.ts_number_layers = 3; |
| 651 cfg_.ts_rate_decimator[0] = 4; | 654 cfg_.ts_rate_decimator[0] = 4; |
| 652 cfg_.ts_rate_decimator[1] = 2; | 655 cfg_.ts_rate_decimator[1] = 2; |
| 653 cfg_.ts_rate_decimator[2] = 1; | 656 cfg_.ts_rate_decimator[2] = 1; |
| 654 | 657 |
| 658 cfg_.temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_BYPASS; |
| 659 |
| 655 ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, | 660 ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
| 656 30, 1, 0, 200); | 661 30, 1, 0, 200); |
| 657 cfg_.rc_target_bitrate = 200; | 662 cfg_.rc_target_bitrate = 200; |
| 658 ResetModel(); | 663 ResetModel(); |
| 659 // 40-20-40 bitrate allocation for 3 temporal layers. | 664 // 40-20-40 bitrate allocation for 3 temporal layers. |
| 660 cfg_.ts_target_bitrate[0] = 40 * cfg_.rc_target_bitrate / 100; | 665 cfg_.layer_target_bitrate[0] = 40 * cfg_.rc_target_bitrate / 100; |
| 661 cfg_.ts_target_bitrate[1] = 60 * cfg_.rc_target_bitrate / 100; | 666 cfg_.layer_target_bitrate[1] = 60 * cfg_.rc_target_bitrate / 100; |
| 662 cfg_.ts_target_bitrate[2] = cfg_.rc_target_bitrate; | 667 cfg_.layer_target_bitrate[2] = cfg_.rc_target_bitrate; |
| 663 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); | 668 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 664 for (int j = 0; j < static_cast<int>(cfg_.ts_number_layers); ++j) { | 669 for (int j = 0; j < static_cast<int>(cfg_.ts_number_layers); ++j) { |
| 665 ASSERT_GE(effective_datarate_[j], cfg_.ts_target_bitrate[j] * 0.85) | 670 ASSERT_GE(effective_datarate_[j], cfg_.layer_target_bitrate[j] * 0.85) |
| 666 << " The datarate for the file is lower than target by too much, " | 671 << " The datarate for the file is lower than target by too much, " |
| 667 "for layer: " << j; | 672 "for layer: " << j; |
| 668 ASSERT_LE(effective_datarate_[j], cfg_.ts_target_bitrate[j] * 1.15) | 673 ASSERT_LE(effective_datarate_[j], cfg_.layer_target_bitrate[j] * 1.15) |
| 669 << " The datarate for the file is greater than target by too much, " | 674 << " The datarate for the file is greater than target by too much, " |
| 670 "for layer: " << j; | 675 "for layer: " << j; |
| 671 // Expect some frame drops in this test: for this 200 frames test, | 676 // Expect some frame drops in this test: for this 200 frames test, |
| 672 // expect at least 10% and not more than 60% drops. | 677 // expect at least 10% and not more than 60% drops. |
| 673 ASSERT_GE(num_drops_, 20); | 678 ASSERT_GE(num_drops_, 20); |
| 674 ASSERT_LE(num_drops_, 130); | 679 ASSERT_LE(num_drops_, 130); |
| 675 } | 680 } |
| 676 } | 681 } |
| 677 | 682 |
| 678 #if CONFIG_VP9_TEMPORAL_DENOISING | 683 #if CONFIG_VP9_TEMPORAL_DENOISING |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 denoiser_offon_test_ = 1; | 735 denoiser_offon_test_ = 1; |
| 731 denoiser_offon_period_ = 100; | 736 denoiser_offon_period_ = 100; |
| 732 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); | 737 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 733 ASSERT_GE(effective_datarate_[0], cfg_.rc_target_bitrate * 0.85) | 738 ASSERT_GE(effective_datarate_[0], cfg_.rc_target_bitrate * 0.85) |
| 734 << " The datarate for the file is lower than target by too much!"; | 739 << " The datarate for the file is lower than target by too much!"; |
| 735 ASSERT_LE(effective_datarate_[0], cfg_.rc_target_bitrate * 1.15) | 740 ASSERT_LE(effective_datarate_[0], cfg_.rc_target_bitrate * 1.15) |
| 736 << " The datarate for the file is greater than target by too much!"; | 741 << " The datarate for the file is greater than target by too much!"; |
| 737 } | 742 } |
| 738 #endif // CONFIG_VP9_TEMPORAL_DENOISING | 743 #endif // CONFIG_VP9_TEMPORAL_DENOISING |
| 739 | 744 |
| 745 class DatarateOnePassCbrSvc : public ::libvpx_test::EncoderTest, |
| 746 public ::libvpx_test::CodecTestWith2Params<libvpx_test::TestMode, int> { |
| 747 public: |
| 748 DatarateOnePassCbrSvc() : EncoderTest(GET_PARAM(0)) {} |
| 749 virtual ~DatarateOnePassCbrSvc() {} |
| 750 protected: |
| 751 virtual void SetUp() { |
| 752 InitializeConfig(); |
| 753 SetMode(GET_PARAM(1)); |
| 754 speed_setting_ = GET_PARAM(2); |
| 755 ResetModel(); |
| 756 } |
| 757 virtual void ResetModel() { |
| 758 last_pts_ = 0; |
| 759 bits_in_buffer_model_ = cfg_.rc_target_bitrate * cfg_.rc_buf_initial_sz; |
| 760 frame_number_ = 0; |
| 761 first_drop_ = 0; |
| 762 bits_total_ = 0; |
| 763 duration_ = 0.0; |
| 764 } |
| 765 virtual void BeginPassHook(unsigned int /*pass*/) { |
| 766 } |
| 767 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, |
| 768 ::libvpx_test::Encoder *encoder) { |
| 769 if (video->frame() == 0) { |
| 770 int i; |
| 771 for (i = 0; i < 2; ++i) { |
| 772 svc_params_.max_quantizers[i] = 63; |
| 773 svc_params_.min_quantizers[i] = 0; |
| 774 } |
| 775 svc_params_.scaling_factor_num[0] = 144; |
| 776 svc_params_.scaling_factor_den[0] = 288; |
| 777 svc_params_.scaling_factor_num[1] = 288; |
| 778 svc_params_.scaling_factor_den[1] = 288; |
| 779 encoder->Control(VP9E_SET_SVC, 1); |
| 780 encoder->Control(VP9E_SET_SVC_PARAMETERS, &svc_params_); |
| 781 encoder->Control(VP8E_SET_CPUUSED, speed_setting_); |
| 782 encoder->Control(VP9E_SET_TILE_COLUMNS, 0); |
| 783 encoder->Control(VP8E_SET_MAX_INTRA_BITRATE_PCT, 300); |
| 784 } |
| 785 const vpx_rational_t tb = video->timebase(); |
| 786 timebase_ = static_cast<double>(tb.num) / tb.den; |
| 787 duration_ = 0; |
| 788 } |
| 789 virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { |
| 790 vpx_codec_pts_t duration = pkt->data.frame.pts - last_pts_; |
| 791 if (last_pts_ == 0) |
| 792 duration = 1; |
| 793 bits_in_buffer_model_ += static_cast<int64_t>( |
| 794 duration * timebase_ * cfg_.rc_target_bitrate * 1000); |
| 795 const bool key_frame = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) |
| 796 ? true: false; |
| 797 if (!key_frame) { |
| 798 ASSERT_GE(bits_in_buffer_model_, 0) << "Buffer Underrun at frame " |
| 799 << pkt->data.frame.pts; |
| 800 } |
| 801 const size_t frame_size_in_bits = pkt->data.frame.sz * 8; |
| 802 bits_in_buffer_model_ -= frame_size_in_bits; |
| 803 bits_total_ += frame_size_in_bits; |
| 804 if (!first_drop_ && duration > 1) |
| 805 first_drop_ = last_pts_ + 1; |
| 806 last_pts_ = pkt->data.frame.pts; |
| 807 bits_in_last_frame_ = frame_size_in_bits; |
| 808 ++frame_number_; |
| 809 } |
| 810 virtual void EndPassHook(void) { |
| 811 if (bits_total_) { |
| 812 const double file_size_in_kb = bits_total_ / 1000.; // bits per kilobit |
| 813 duration_ = (last_pts_ + 1) * timebase_; |
| 814 effective_datarate_ = (bits_total_ - bits_in_last_frame_) / 1000.0 |
| 815 / (cfg_.rc_buf_initial_sz / 1000.0 + duration_); |
| 816 file_datarate_ = file_size_in_kb / duration_; |
| 817 } |
| 818 } |
| 819 vpx_codec_pts_t last_pts_; |
| 820 int64_t bits_in_buffer_model_; |
| 821 double timebase_; |
| 822 int frame_number_; |
| 823 vpx_codec_pts_t first_drop_; |
| 824 int64_t bits_total_; |
| 825 double duration_; |
| 826 double file_datarate_; |
| 827 double effective_datarate_; |
| 828 size_t bits_in_last_frame_; |
| 829 vpx_svc_extra_cfg_t svc_params_; |
| 830 int speed_setting_; |
| 831 }; |
| 832 static void assign_layer_bitrates(vpx_codec_enc_cfg_t *const enc_cfg, |
| 833 const vpx_svc_extra_cfg_t *svc_params, |
| 834 int spatial_layers, |
| 835 int temporal_layers, |
| 836 int temporal_layering_mode, |
| 837 unsigned int total_rate) { |
| 838 int sl, spatial_layer_target; |
| 839 float total = 0; |
| 840 float alloc_ratio[VPX_MAX_LAYERS] = {0}; |
| 841 for (sl = 0; sl < spatial_layers; ++sl) { |
| 842 if (svc_params->scaling_factor_den[sl] > 0) { |
| 843 alloc_ratio[sl] = (float)(svc_params->scaling_factor_num[sl] * |
| 844 1.0 / svc_params->scaling_factor_den[sl]); |
| 845 total += alloc_ratio[sl]; |
| 846 } |
| 847 } |
| 848 for (sl = 0; sl < spatial_layers; ++sl) { |
| 849 enc_cfg->ss_target_bitrate[sl] = spatial_layer_target = |
| 850 (unsigned int)(enc_cfg->rc_target_bitrate * |
| 851 alloc_ratio[sl] / total); |
| 852 const int index = sl * temporal_layers; |
| 853 if (temporal_layering_mode == 3) { |
| 854 enc_cfg->layer_target_bitrate[index] = |
| 855 spatial_layer_target >> 1; |
| 856 enc_cfg->layer_target_bitrate[index + 1] = |
| 857 (spatial_layer_target >> 1) + (spatial_layer_target >> 2); |
| 858 enc_cfg->layer_target_bitrate[index + 2] = |
| 859 spatial_layer_target; |
| 860 } else if (temporal_layering_mode == 2) { |
| 861 enc_cfg->layer_target_bitrate[index] = |
| 862 spatial_layer_target * 2 / 3; |
| 863 enc_cfg->layer_target_bitrate[index + 1] = |
| 864 spatial_layer_target; |
| 865 } |
| 866 } |
| 867 } |
| 868 |
| 869 // Check basic rate targeting for 1 pass CBR SVC: 2 spatial layers and |
| 870 // 3 temporal layers. |
| 871 TEST_P(DatarateOnePassCbrSvc, OnePassCbrSvc) { |
| 872 cfg_.rc_buf_initial_sz = 500; |
| 873 cfg_.rc_buf_optimal_sz = 500; |
| 874 cfg_.rc_buf_sz = 1000; |
| 875 cfg_.rc_min_quantizer = 0; |
| 876 cfg_.rc_max_quantizer = 63; |
| 877 cfg_.rc_end_usage = VPX_CBR; |
| 878 cfg_.g_lag_in_frames = 0; |
| 879 cfg_.ss_number_layers = 2; |
| 880 cfg_.ts_number_layers = 3; |
| 881 cfg_.ts_rate_decimator[0] = 4; |
| 882 cfg_.ts_rate_decimator[1] = 2; |
| 883 cfg_.ts_rate_decimator[2] = 1; |
| 884 cfg_.g_error_resilient = 1; |
| 885 cfg_.temporal_layering_mode = 3; |
| 886 svc_params_.scaling_factor_num[0] = 144; |
| 887 svc_params_.scaling_factor_den[0] = 288; |
| 888 svc_params_.scaling_factor_num[1] = 288; |
| 889 svc_params_.scaling_factor_den[1] = 288; |
| 890 // TODO(wonkap/marpan): No frame drop for now, we need to implement correct |
| 891 // frame dropping for SVC. |
| 892 cfg_.rc_dropframe_thresh = 0; |
| 893 ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
| 894 30, 1, 0, 200); |
| 895 // TODO(wonkap/marpan): Check that effective_datarate for each layer hits the |
| 896 // layer target_bitrate. Also check if test can pass at lower bitrate (~200k). |
| 897 for (int i = 400; i <= 800; i += 200) { |
| 898 cfg_.rc_target_bitrate = i; |
| 899 ResetModel(); |
| 900 assign_layer_bitrates(&cfg_, &svc_params_, cfg_.ss_number_layers, |
| 901 cfg_.ts_number_layers, cfg_.temporal_layering_mode, |
| 902 cfg_.rc_target_bitrate); |
| 903 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 904 ASSERT_GE(cfg_.rc_target_bitrate, effective_datarate_ * 0.85) |
| 905 << " The datarate for the file exceeds the target by too much!"; |
| 906 ASSERT_LE(cfg_.rc_target_bitrate, file_datarate_ * 1.15) |
| 907 << " The datarate for the file is lower than the target by too much!"; |
| 908 } |
| 909 } |
| 910 |
| 740 VP8_INSTANTIATE_TEST_CASE(DatarateTestLarge, ALL_TEST_MODES); | 911 VP8_INSTANTIATE_TEST_CASE(DatarateTestLarge, ALL_TEST_MODES); |
| 741 VP9_INSTANTIATE_TEST_CASE(DatarateTestVP9Large, | 912 VP9_INSTANTIATE_TEST_CASE(DatarateTestVP9Large, |
| 742 ::testing::Values(::libvpx_test::kOnePassGood, | 913 ::testing::Values(::libvpx_test::kOnePassGood, |
| 743 ::libvpx_test::kRealTime), | 914 ::libvpx_test::kRealTime), |
| 744 ::testing::Range(2, 7)); | 915 ::testing::Range(2, 7)); |
| 916 VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvc, |
| 917 ::testing::Values(::libvpx_test::kRealTime), |
| 918 ::testing::Range(5, 8)); |
| 745 } // namespace | 919 } // namespace |
| OLD | NEW |