| 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" |
| (...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 speed_setting_ = GET_PARAM(2); | 754 speed_setting_ = GET_PARAM(2); |
| 755 ResetModel(); | 755 ResetModel(); |
| 756 } | 756 } |
| 757 virtual void ResetModel() { | 757 virtual void ResetModel() { |
| 758 last_pts_ = 0; | 758 last_pts_ = 0; |
| 759 bits_in_buffer_model_ = cfg_.rc_target_bitrate * cfg_.rc_buf_initial_sz; | 759 bits_in_buffer_model_ = cfg_.rc_target_bitrate * cfg_.rc_buf_initial_sz; |
| 760 frame_number_ = 0; | 760 frame_number_ = 0; |
| 761 first_drop_ = 0; | 761 first_drop_ = 0; |
| 762 bits_total_ = 0; | 762 bits_total_ = 0; |
| 763 duration_ = 0.0; | 763 duration_ = 0.0; |
| 764 mismatch_psnr_ = 0.0; |
| 765 mismatch_nframes_ = 0; |
| 764 } | 766 } |
| 765 virtual void BeginPassHook(unsigned int /*pass*/) { | 767 virtual void BeginPassHook(unsigned int /*pass*/) { |
| 766 } | 768 } |
| 767 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, | 769 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, |
| 768 ::libvpx_test::Encoder *encoder) { | 770 ::libvpx_test::Encoder *encoder) { |
| 769 if (video->frame() == 0) { | 771 if (video->frame() == 0) { |
| 770 int i; | 772 int i; |
| 771 for (i = 0; i < 2; ++i) { | 773 for (i = 0; i < 2; ++i) { |
| 772 svc_params_.max_quantizers[i] = 63; | 774 svc_params_.max_quantizers[i] = 63; |
| 773 svc_params_.min_quantizers[i] = 0; | 775 svc_params_.min_quantizers[i] = 0; |
| 774 } | 776 } |
| 775 svc_params_.scaling_factor_num[0] = 144; | 777 svc_params_.scaling_factor_num[0] = 144; |
| 776 svc_params_.scaling_factor_den[0] = 288; | 778 svc_params_.scaling_factor_den[0] = 288; |
| 777 svc_params_.scaling_factor_num[1] = 288; | 779 svc_params_.scaling_factor_num[1] = 288; |
| 778 svc_params_.scaling_factor_den[1] = 288; | 780 svc_params_.scaling_factor_den[1] = 288; |
| 779 encoder->Control(VP9E_SET_SVC, 1); | 781 encoder->Control(VP9E_SET_SVC, 1); |
| 780 encoder->Control(VP9E_SET_SVC_PARAMETERS, &svc_params_); | 782 encoder->Control(VP9E_SET_SVC_PARAMETERS, &svc_params_); |
| 781 encoder->Control(VP8E_SET_CPUUSED, speed_setting_); | 783 encoder->Control(VP8E_SET_CPUUSED, speed_setting_); |
| 782 encoder->Control(VP9E_SET_TILE_COLUMNS, 0); | 784 encoder->Control(VP9E_SET_TILE_COLUMNS, 0); |
| 783 encoder->Control(VP8E_SET_MAX_INTRA_BITRATE_PCT, 300); | 785 encoder->Control(VP8E_SET_MAX_INTRA_BITRATE_PCT, 300); |
| 786 encoder->Control(VP9E_SET_TILE_COLUMNS, (cfg_.g_threads >> 1)); |
| 784 } | 787 } |
| 785 const vpx_rational_t tb = video->timebase(); | 788 const vpx_rational_t tb = video->timebase(); |
| 786 timebase_ = static_cast<double>(tb.num) / tb.den; | 789 timebase_ = static_cast<double>(tb.num) / tb.den; |
| 787 duration_ = 0; | 790 duration_ = 0; |
| 788 } | 791 } |
| 789 virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { | 792 virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { |
| 790 vpx_codec_pts_t duration = pkt->data.frame.pts - last_pts_; | 793 vpx_codec_pts_t duration = pkt->data.frame.pts - last_pts_; |
| 791 if (last_pts_ == 0) | 794 if (last_pts_ == 0) |
| 792 duration = 1; | 795 duration = 1; |
| 793 bits_in_buffer_model_ += static_cast<int64_t>( | 796 bits_in_buffer_model_ += static_cast<int64_t>( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 809 } | 812 } |
| 810 virtual void EndPassHook(void) { | 813 virtual void EndPassHook(void) { |
| 811 if (bits_total_) { | 814 if (bits_total_) { |
| 812 const double file_size_in_kb = bits_total_ / 1000.; // bits per kilobit | 815 const double file_size_in_kb = bits_total_ / 1000.; // bits per kilobit |
| 813 duration_ = (last_pts_ + 1) * timebase_; | 816 duration_ = (last_pts_ + 1) * timebase_; |
| 814 effective_datarate_ = (bits_total_ - bits_in_last_frame_) / 1000.0 | 817 effective_datarate_ = (bits_total_ - bits_in_last_frame_) / 1000.0 |
| 815 / (cfg_.rc_buf_initial_sz / 1000.0 + duration_); | 818 / (cfg_.rc_buf_initial_sz / 1000.0 + duration_); |
| 816 file_datarate_ = file_size_in_kb / duration_; | 819 file_datarate_ = file_size_in_kb / duration_; |
| 817 } | 820 } |
| 818 } | 821 } |
| 822 |
| 823 virtual void MismatchHook(const vpx_image_t *img1, |
| 824 const vpx_image_t *img2) { |
| 825 double mismatch_psnr = compute_psnr(img1, img2); |
| 826 mismatch_psnr_ += mismatch_psnr; |
| 827 ++mismatch_nframes_; |
| 828 } |
| 829 |
| 830 unsigned int GetMismatchFrames() { |
| 831 return mismatch_nframes_; |
| 832 } |
| 833 |
| 819 vpx_codec_pts_t last_pts_; | 834 vpx_codec_pts_t last_pts_; |
| 820 int64_t bits_in_buffer_model_; | 835 int64_t bits_in_buffer_model_; |
| 821 double timebase_; | 836 double timebase_; |
| 822 int frame_number_; | 837 int frame_number_; |
| 823 vpx_codec_pts_t first_drop_; | 838 vpx_codec_pts_t first_drop_; |
| 824 int64_t bits_total_; | 839 int64_t bits_total_; |
| 825 double duration_; | 840 double duration_; |
| 826 double file_datarate_; | 841 double file_datarate_; |
| 827 double effective_datarate_; | 842 double effective_datarate_; |
| 828 size_t bits_in_last_frame_; | 843 size_t bits_in_last_frame_; |
| 829 vpx_svc_extra_cfg_t svc_params_; | 844 vpx_svc_extra_cfg_t svc_params_; |
| 830 int speed_setting_; | 845 int speed_setting_; |
| 846 double mismatch_psnr_; |
| 847 int mismatch_nframes_; |
| 831 }; | 848 }; |
| 832 static void assign_layer_bitrates(vpx_codec_enc_cfg_t *const enc_cfg, | 849 static void assign_layer_bitrates(vpx_codec_enc_cfg_t *const enc_cfg, |
| 833 const vpx_svc_extra_cfg_t *svc_params, | 850 const vpx_svc_extra_cfg_t *svc_params, |
| 834 int spatial_layers, | 851 int spatial_layers, |
| 835 int temporal_layers, | 852 int temporal_layers, |
| 836 int temporal_layering_mode, | 853 int temporal_layering_mode, |
| 837 unsigned int total_rate) { | 854 unsigned int total_rate) { |
| 838 int sl, spatial_layer_target; | 855 int sl, spatial_layer_target; |
| 839 float total = 0; | 856 float total = 0; |
| 840 float alloc_ratio[VPX_MAX_LAYERS] = {0}; | 857 float alloc_ratio[VPX_MAX_LAYERS] = {0}; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 860 } else if (temporal_layering_mode == 2) { | 877 } else if (temporal_layering_mode == 2) { |
| 861 enc_cfg->layer_target_bitrate[index] = | 878 enc_cfg->layer_target_bitrate[index] = |
| 862 spatial_layer_target * 2 / 3; | 879 spatial_layer_target * 2 / 3; |
| 863 enc_cfg->layer_target_bitrate[index + 1] = | 880 enc_cfg->layer_target_bitrate[index + 1] = |
| 864 spatial_layer_target; | 881 spatial_layer_target; |
| 865 } | 882 } |
| 866 } | 883 } |
| 867 } | 884 } |
| 868 | 885 |
| 869 // Check basic rate targeting for 1 pass CBR SVC: 2 spatial layers and | 886 // Check basic rate targeting for 1 pass CBR SVC: 2 spatial layers and |
| 870 // 3 temporal layers. | 887 // 3 temporal layers. Run CIF clip with 1 thread. |
| 871 TEST_P(DatarateOnePassCbrSvc, OnePassCbrSvc) { | 888 TEST_P(DatarateOnePassCbrSvc, OnePassCbrSvc) { |
| 872 cfg_.rc_buf_initial_sz = 500; | 889 cfg_.rc_buf_initial_sz = 500; |
| 873 cfg_.rc_buf_optimal_sz = 500; | 890 cfg_.rc_buf_optimal_sz = 500; |
| 874 cfg_.rc_buf_sz = 1000; | 891 cfg_.rc_buf_sz = 1000; |
| 875 cfg_.rc_min_quantizer = 0; | 892 cfg_.rc_min_quantizer = 0; |
| 876 cfg_.rc_max_quantizer = 63; | 893 cfg_.rc_max_quantizer = 63; |
| 877 cfg_.rc_end_usage = VPX_CBR; | 894 cfg_.rc_end_usage = VPX_CBR; |
| 878 cfg_.g_lag_in_frames = 0; | 895 cfg_.g_lag_in_frames = 0; |
| 879 cfg_.ss_number_layers = 2; | 896 cfg_.ss_number_layers = 2; |
| 880 cfg_.ts_number_layers = 3; | 897 cfg_.ts_number_layers = 3; |
| 881 cfg_.ts_rate_decimator[0] = 4; | 898 cfg_.ts_rate_decimator[0] = 4; |
| 882 cfg_.ts_rate_decimator[1] = 2; | 899 cfg_.ts_rate_decimator[1] = 2; |
| 883 cfg_.ts_rate_decimator[2] = 1; | 900 cfg_.ts_rate_decimator[2] = 1; |
| 884 cfg_.g_error_resilient = 1; | 901 cfg_.g_error_resilient = 1; |
| 902 cfg_.g_threads = 1; |
| 885 cfg_.temporal_layering_mode = 3; | 903 cfg_.temporal_layering_mode = 3; |
| 886 svc_params_.scaling_factor_num[0] = 144; | 904 svc_params_.scaling_factor_num[0] = 144; |
| 887 svc_params_.scaling_factor_den[0] = 288; | 905 svc_params_.scaling_factor_den[0] = 288; |
| 888 svc_params_.scaling_factor_num[1] = 288; | 906 svc_params_.scaling_factor_num[1] = 288; |
| 889 svc_params_.scaling_factor_den[1] = 288; | 907 svc_params_.scaling_factor_den[1] = 288; |
| 890 // TODO(wonkap/marpan): No frame drop for now, we need to implement correct | 908 // TODO(wonkap/marpan): No frame drop for now, we need to implement correct |
| 891 // frame dropping for SVC. | 909 // frame dropping for SVC. |
| 892 cfg_.rc_dropframe_thresh = 0; | 910 cfg_.rc_dropframe_thresh = 0; |
| 893 ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, | 911 ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
| 894 30, 1, 0, 200); | 912 30, 1, 0, 200); |
| 895 // TODO(wonkap/marpan): Check that effective_datarate for each layer hits the | 913 // 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). | 914 // layer target_bitrate. Also check if test can pass at lower bitrate (~200k). |
| 897 for (int i = 400; i <= 800; i += 200) { | 915 for (int i = 400; i <= 800; i += 200) { |
| 898 cfg_.rc_target_bitrate = i; | 916 cfg_.rc_target_bitrate = i; |
| 899 ResetModel(); | 917 ResetModel(); |
| 900 assign_layer_bitrates(&cfg_, &svc_params_, cfg_.ss_number_layers, | 918 assign_layer_bitrates(&cfg_, &svc_params_, cfg_.ss_number_layers, |
| 901 cfg_.ts_number_layers, cfg_.temporal_layering_mode, | 919 cfg_.ts_number_layers, cfg_.temporal_layering_mode, |
| 902 cfg_.rc_target_bitrate); | 920 cfg_.rc_target_bitrate); |
| 903 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); | 921 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 904 ASSERT_GE(cfg_.rc_target_bitrate, effective_datarate_ * 0.85) | 922 ASSERT_GE(cfg_.rc_target_bitrate, effective_datarate_ * 0.85) |
| 905 << " The datarate for the file exceeds the target by too much!"; | 923 << " The datarate for the file exceeds the target by too much!"; |
| 906 ASSERT_LE(cfg_.rc_target_bitrate, file_datarate_ * 1.15) | 924 ASSERT_LE(cfg_.rc_target_bitrate, file_datarate_ * 1.15) |
| 907 << " The datarate for the file is lower than the target by too much!"; | 925 << " The datarate for the file is lower than the target by too much!"; |
| 926 EXPECT_EQ(GetMismatchFrames(), (unsigned int) 0); |
| 908 } | 927 } |
| 909 } | 928 } |
| 910 | 929 |
| 930 // Check basic rate targeting for 1 pass CBR SVC: 2 spatial layers and |
| 931 // 3 temporal layers. Run HD clip with 4 threads. |
| 932 TEST_P(DatarateOnePassCbrSvc, OnePassCbrSvc4threads) { |
| 933 cfg_.rc_buf_initial_sz = 500; |
| 934 cfg_.rc_buf_optimal_sz = 500; |
| 935 cfg_.rc_buf_sz = 1000; |
| 936 cfg_.rc_min_quantizer = 0; |
| 937 cfg_.rc_max_quantizer = 63; |
| 938 cfg_.rc_end_usage = VPX_CBR; |
| 939 cfg_.g_lag_in_frames = 0; |
| 940 cfg_.ss_number_layers = 2; |
| 941 cfg_.ts_number_layers = 3; |
| 942 cfg_.ts_rate_decimator[0] = 4; |
| 943 cfg_.ts_rate_decimator[1] = 2; |
| 944 cfg_.ts_rate_decimator[2] = 1; |
| 945 cfg_.g_error_resilient = 1; |
| 946 cfg_.g_threads = 4; |
| 947 cfg_.temporal_layering_mode = 3; |
| 948 svc_params_.scaling_factor_num[0] = 144; |
| 949 svc_params_.scaling_factor_den[0] = 288; |
| 950 svc_params_.scaling_factor_num[1] = 288; |
| 951 svc_params_.scaling_factor_den[1] = 288; |
| 952 // TODO(wonkap/marpan): No frame drop for now, we need to implement correct |
| 953 // frame dropping for SVC. |
| 954 cfg_.rc_dropframe_thresh = 0; |
| 955 ::libvpx_test::I420VideoSource video("niklas_1280_720_30.y4m", 1280, 720, |
| 956 30, 1, 0, 300); |
| 957 cfg_.rc_target_bitrate = 800; |
| 958 ResetModel(); |
| 959 assign_layer_bitrates(&cfg_, &svc_params_, cfg_.ss_number_layers, |
| 960 cfg_.ts_number_layers, cfg_.temporal_layering_mode, |
| 961 cfg_.rc_target_bitrate); |
| 962 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 963 ASSERT_GE(cfg_.rc_target_bitrate, effective_datarate_ * 0.85) |
| 964 << " The datarate for the file exceeds the target by too much!"; |
| 965 ASSERT_LE(cfg_.rc_target_bitrate, file_datarate_ * 1.15) |
| 966 << " The datarate for the file is lower than the target by too much!"; |
| 967 EXPECT_EQ(GetMismatchFrames(), (unsigned int) 0); |
| 968 } |
| 969 |
| 911 VP8_INSTANTIATE_TEST_CASE(DatarateTestLarge, ALL_TEST_MODES); | 970 VP8_INSTANTIATE_TEST_CASE(DatarateTestLarge, ALL_TEST_MODES); |
| 912 VP9_INSTANTIATE_TEST_CASE(DatarateTestVP9Large, | 971 VP9_INSTANTIATE_TEST_CASE(DatarateTestVP9Large, |
| 913 ::testing::Values(::libvpx_test::kOnePassGood, | 972 ::testing::Values(::libvpx_test::kOnePassGood, |
| 914 ::libvpx_test::kRealTime), | 973 ::libvpx_test::kRealTime), |
| 915 ::testing::Range(2, 7)); | 974 ::testing::Range(2, 7)); |
| 916 VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvc, | 975 VP9_INSTANTIATE_TEST_CASE(DatarateOnePassCbrSvc, |
| 917 ::testing::Values(::libvpx_test::kRealTime), | 976 ::testing::Values(::libvpx_test::kRealTime), |
| 918 ::testing::Range(5, 8)); | 977 ::testing::Range(5, 8)); |
| 919 } // namespace | 978 } // namespace |
| OLD | NEW |