Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(489)

Side by Side Diff: source/libvpx/test/cq_test.cc

Issue 181493009: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/libs.mk ('k') | source/libvpx/test/datarate_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "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 16
17 namespace { 17 namespace {
18 18
19 // CQ level range: [kCQLevelMin, kCQLevelMax). 19 // CQ level range: [kCQLevelMin, kCQLevelMax).
20 const int kCQLevelMin = 4; 20 const int kCQLevelMin = 4;
21 const int kCQLevelMax = 63; 21 const int kCQLevelMax = 63;
22 const int kCQLevelStep = 8; 22 const int kCQLevelStep = 8;
23 const int kCQTargetBitrate = 2000; 23 const unsigned int kCQTargetBitrate = 2000;
24 24
25 class CQTest : public ::libvpx_test::EncoderTest, 25 class CQTest : public ::libvpx_test::EncoderTest,
26 public ::libvpx_test::CodecTestWithParam<int> { 26 public ::libvpx_test::CodecTestWithParam<int> {
27 protected: 27 protected:
28 CQTest() : EncoderTest(GET_PARAM(0)), cq_level_(GET_PARAM(1)) { 28 CQTest() : EncoderTest(GET_PARAM(0)), cq_level_(GET_PARAM(1)) {
29 init_flags_ = VPX_CODEC_USE_PSNR; 29 init_flags_ = VPX_CODEC_USE_PSNR;
30 } 30 }
31 31
32 virtual ~CQTest() {} 32 virtual ~CQTest() {}
33 33
(...skipping 25 matching lines...) Expand all
59 59
60 virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { 60 virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
61 file_size_ += pkt->data.frame.sz; 61 file_size_ += pkt->data.frame.sz;
62 } 62 }
63 63
64 double GetLinearPSNROverBitrate() const { 64 double GetLinearPSNROverBitrate() const {
65 double avg_psnr = log10(psnr_ / n_frames_) * 10.0; 65 double avg_psnr = log10(psnr_ / n_frames_) * 10.0;
66 return pow(10.0, avg_psnr / 10.0) / file_size_; 66 return pow(10.0, avg_psnr / 10.0) / file_size_;
67 } 67 }
68 68
69 int file_size() const { return file_size_; } 69 size_t file_size() const { return file_size_; }
70 int n_frames() const { return n_frames_; } 70 int n_frames() const { return n_frames_; }
71 71
72 private: 72 private:
73 int cq_level_; 73 int cq_level_;
74 int file_size_; 74 size_t file_size_;
75 double psnr_; 75 double psnr_;
76 int n_frames_; 76 int n_frames_;
77 }; 77 };
78 78
79 int prev_actual_bitrate = kCQTargetBitrate; 79 unsigned int prev_actual_bitrate = kCQTargetBitrate;
80 TEST_P(CQTest, LinearPSNRIsHigherForCQLevel) { 80 TEST_P(CQTest, LinearPSNRIsHigherForCQLevel) {
81 const vpx_rational timebase = { 33333333, 1000000000 }; 81 const vpx_rational timebase = { 33333333, 1000000000 };
82 cfg_.g_timebase = timebase; 82 cfg_.g_timebase = timebase;
83 cfg_.rc_target_bitrate = kCQTargetBitrate; 83 cfg_.rc_target_bitrate = kCQTargetBitrate;
84 cfg_.g_lag_in_frames = 25; 84 cfg_.g_lag_in_frames = 25;
85 85
86 cfg_.rc_end_usage = VPX_CQ; 86 cfg_.rc_end_usage = VPX_CQ;
87 libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, 87 libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
88 timebase.den, timebase.num, 0, 30); 88 timebase.den, timebase.num, 0, 30);
89 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 89 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
90 const double cq_psnr_lin = GetLinearPSNROverBitrate(); 90 const double cq_psnr_lin = GetLinearPSNROverBitrate();
91 const int cq_actual_bitrate = file_size() * 8 * 30 / (n_frames() * 1000); 91 const unsigned int cq_actual_bitrate =
92 static_cast<unsigned int>(file_size()) * 8 * 30 / (n_frames() * 1000);
92 EXPECT_LE(cq_actual_bitrate, kCQTargetBitrate); 93 EXPECT_LE(cq_actual_bitrate, kCQTargetBitrate);
93 EXPECT_LE(cq_actual_bitrate, prev_actual_bitrate); 94 EXPECT_LE(cq_actual_bitrate, prev_actual_bitrate);
94 prev_actual_bitrate = cq_actual_bitrate; 95 prev_actual_bitrate = cq_actual_bitrate;
95 96
96 // try targeting the approximate same bitrate with VBR mode 97 // try targeting the approximate same bitrate with VBR mode
97 cfg_.rc_end_usage = VPX_VBR; 98 cfg_.rc_end_usage = VPX_VBR;
98 cfg_.rc_target_bitrate = cq_actual_bitrate; 99 cfg_.rc_target_bitrate = cq_actual_bitrate;
99 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 100 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
100 const double vbr_psnr_lin = GetLinearPSNROverBitrate(); 101 const double vbr_psnr_lin = GetLinearPSNROverBitrate();
101 EXPECT_GE(cq_psnr_lin, vbr_psnr_lin); 102 EXPECT_GE(cq_psnr_lin, vbr_psnr_lin);
102 } 103 }
103 104
104 VP8_INSTANTIATE_TEST_CASE(CQTest, 105 VP8_INSTANTIATE_TEST_CASE(CQTest,
105 ::testing::Range(kCQLevelMin, kCQLevelMax, 106 ::testing::Range(kCQLevelMin, kCQLevelMax,
106 kCQLevelStep)); 107 kCQLevelStep));
107 } // namespace 108 } // namespace
OLDNEW
« no previous file with comments | « source/libvpx/libs.mk ('k') | source/libvpx/test/datarate_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698