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 <cmath> | 10 #include <cmath> |
| 11 #include <map> |
11 #include "third_party/googletest/src/include/gtest/gtest.h" | 12 #include "third_party/googletest/src/include/gtest/gtest.h" |
12 #include "test/codec_factory.h" | 13 #include "test/codec_factory.h" |
13 #include "test/encode_test_driver.h" | 14 #include "test/encode_test_driver.h" |
14 #include "test/i420_video_source.h" | 15 #include "test/i420_video_source.h" |
15 #include "test/util.h" | 16 #include "test/util.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // CQ level range: [kCQLevelMin, kCQLevelMax). | 20 // CQ level range: [kCQLevelMin, kCQLevelMax). |
20 const int kCQLevelMin = 4; | 21 const int kCQLevelMin = 4; |
21 const int kCQLevelMax = 63; | 22 const int kCQLevelMax = 63; |
22 const int kCQLevelStep = 8; | 23 const int kCQLevelStep = 8; |
23 const unsigned int kCQTargetBitrate = 2000; | 24 const unsigned int kCQTargetBitrate = 2000; |
24 | 25 |
25 class CQTest : public ::libvpx_test::EncoderTest, | 26 class CQTest : public ::libvpx_test::EncoderTest, |
26 public ::libvpx_test::CodecTestWithParam<int> { | 27 public ::libvpx_test::CodecTestWithParam<int> { |
| 28 public: |
| 29 // maps the cqlevel to the bitrate produced. |
| 30 typedef std::map<int, uint32_t> BitrateMap; |
| 31 |
| 32 static void SetUpTestCase() { |
| 33 bitrates_.clear(); |
| 34 } |
| 35 |
| 36 static void TearDownTestCase() { |
| 37 ASSERT_TRUE(!HasFailure()) |
| 38 << "skipping bitrate validation due to earlier failure."; |
| 39 uint32_t prev_actual_bitrate = kCQTargetBitrate; |
| 40 for (BitrateMap::const_iterator iter = bitrates_.begin(); |
| 41 iter != bitrates_.end(); ++iter) { |
| 42 const uint32_t cq_actual_bitrate = iter->second; |
| 43 EXPECT_LE(cq_actual_bitrate, prev_actual_bitrate) |
| 44 << "cq_level: " << iter->first |
| 45 << ", bitrate should decrease with increase in CQ level."; |
| 46 prev_actual_bitrate = cq_actual_bitrate; |
| 47 } |
| 48 } |
| 49 |
27 protected: | 50 protected: |
28 CQTest() : EncoderTest(GET_PARAM(0)), cq_level_(GET_PARAM(1)) { | 51 CQTest() : EncoderTest(GET_PARAM(0)), cq_level_(GET_PARAM(1)) { |
29 init_flags_ = VPX_CODEC_USE_PSNR; | 52 init_flags_ = VPX_CODEC_USE_PSNR; |
30 } | 53 } |
31 | 54 |
32 virtual ~CQTest() {} | 55 virtual ~CQTest() {} |
33 | 56 |
34 virtual void SetUp() { | 57 virtual void SetUp() { |
35 InitializeConfig(); | 58 InitializeConfig(); |
36 SetMode(libvpx_test::kTwoPassGood); | 59 SetMode(libvpx_test::kTwoPassGood); |
(...skipping 22 matching lines...) Expand all Loading... |
59 | 82 |
60 virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { | 83 virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { |
61 file_size_ += pkt->data.frame.sz; | 84 file_size_ += pkt->data.frame.sz; |
62 } | 85 } |
63 | 86 |
64 double GetLinearPSNROverBitrate() const { | 87 double GetLinearPSNROverBitrate() const { |
65 double avg_psnr = log10(psnr_ / n_frames_) * 10.0; | 88 double avg_psnr = log10(psnr_ / n_frames_) * 10.0; |
66 return pow(10.0, avg_psnr / 10.0) / file_size_; | 89 return pow(10.0, avg_psnr / 10.0) / file_size_; |
67 } | 90 } |
68 | 91 |
| 92 int cq_level() const { return cq_level_; } |
69 size_t file_size() const { return file_size_; } | 93 size_t file_size() const { return file_size_; } |
70 int n_frames() const { return n_frames_; } | 94 int n_frames() const { return n_frames_; } |
71 | 95 |
| 96 static BitrateMap bitrates_; |
| 97 |
72 private: | 98 private: |
73 int cq_level_; | 99 int cq_level_; |
74 size_t file_size_; | 100 size_t file_size_; |
75 double psnr_; | 101 double psnr_; |
76 int n_frames_; | 102 int n_frames_; |
77 }; | 103 }; |
78 | 104 |
79 unsigned int prev_actual_bitrate = kCQTargetBitrate; | 105 CQTest::BitrateMap CQTest::bitrates_; |
| 106 |
80 TEST_P(CQTest, LinearPSNRIsHigherForCQLevel) { | 107 TEST_P(CQTest, LinearPSNRIsHigherForCQLevel) { |
81 const vpx_rational timebase = { 33333333, 1000000000 }; | 108 const vpx_rational timebase = { 33333333, 1000000000 }; |
82 cfg_.g_timebase = timebase; | 109 cfg_.g_timebase = timebase; |
83 cfg_.rc_target_bitrate = kCQTargetBitrate; | 110 cfg_.rc_target_bitrate = kCQTargetBitrate; |
84 cfg_.g_lag_in_frames = 25; | 111 cfg_.g_lag_in_frames = 25; |
85 | 112 |
86 cfg_.rc_end_usage = VPX_CQ; | 113 cfg_.rc_end_usage = VPX_CQ; |
87 libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, | 114 libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, |
88 timebase.den, timebase.num, 0, 30); | 115 timebase.den, timebase.num, 0, 30); |
89 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); | 116 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
90 const double cq_psnr_lin = GetLinearPSNROverBitrate(); | 117 const double cq_psnr_lin = GetLinearPSNROverBitrate(); |
91 const unsigned int cq_actual_bitrate = | 118 const unsigned int cq_actual_bitrate = |
92 static_cast<unsigned int>(file_size()) * 8 * 30 / (n_frames() * 1000); | 119 static_cast<unsigned int>(file_size()) * 8 * 30 / (n_frames() * 1000); |
93 EXPECT_LE(cq_actual_bitrate, kCQTargetBitrate); | 120 EXPECT_LE(cq_actual_bitrate, kCQTargetBitrate); |
94 EXPECT_LE(cq_actual_bitrate, prev_actual_bitrate); | 121 bitrates_[cq_level()] = cq_actual_bitrate; |
95 prev_actual_bitrate = cq_actual_bitrate; | |
96 | 122 |
97 // try targeting the approximate same bitrate with VBR mode | 123 // try targeting the approximate same bitrate with VBR mode |
98 cfg_.rc_end_usage = VPX_VBR; | 124 cfg_.rc_end_usage = VPX_VBR; |
99 cfg_.rc_target_bitrate = cq_actual_bitrate; | 125 cfg_.rc_target_bitrate = cq_actual_bitrate; |
100 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); | 126 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
101 const double vbr_psnr_lin = GetLinearPSNROverBitrate(); | 127 const double vbr_psnr_lin = GetLinearPSNROverBitrate(); |
102 EXPECT_GE(cq_psnr_lin, vbr_psnr_lin); | 128 EXPECT_GE(cq_psnr_lin, vbr_psnr_lin); |
103 } | 129 } |
104 | 130 |
105 VP8_INSTANTIATE_TEST_CASE(CQTest, | 131 VP8_INSTANTIATE_TEST_CASE(CQTest, |
106 ::testing::Range(kCQLevelMin, kCQLevelMax, | 132 ::testing::Range(kCQLevelMin, kCQLevelMax, |
107 kCQLevelStep)); | 133 kCQLevelStep)); |
108 } // namespace | 134 } // namespace |
OLD | NEW |