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

Side by Side Diff: webrtc/modules/audio_coding/neteq/test/neteq_opus_quality_test.cc

Issue 2995363002: Replace gflags usages with rtc_base/flags in all targets based on test_main (Closed)
Patch Set: Improve error messages Created 3 years, 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 The WebRTC 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
11 #include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h" 11 #include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h"
12 #include "webrtc/modules/audio_coding/codecs/opus/opus_inst.h" 12 #include "webrtc/modules/audio_coding/codecs/opus/opus_inst.h"
13 #include "webrtc/modules/audio_coding/neteq/tools/neteq_quality_test.h" 13 #include "webrtc/modules/audio_coding/neteq/tools/neteq_quality_test.h"
14 #include "webrtc/rtc_base/flags.h"
14 15
15 using google::RegisterFlagValidator;
16 using google::ParseCommandLineFlags;
17 using testing::InitGoogleTest; 16 using testing::InitGoogleTest;
18 17
19 namespace webrtc { 18 namespace webrtc {
20 namespace test { 19 namespace test {
21 namespace { 20 namespace {
22 21
23 static const int kOpusBlockDurationMs = 20; 22 static const int kOpusBlockDurationMs = 20;
24 static const int kOpusSamplingKhz = 48; 23 static const int kOpusSamplingKhz = 48;
25 24
26 // Define switch for bit rate. 25 DEFINE_int(bit_rate_kbps, 32, "Target bit rate (kbps).");
27 static bool ValidateBitRate(const char* flagname, int32_t value) {
28 if (value >= 6 && value <= 510)
29 return true;
30 printf("Invalid bit rate, should be between 6 and 510 kbps.");
31 return false;
32 }
33 26
34 DEFINE_int32(bit_rate_kbps, 32, "Target bit rate (kbps)."); 27 DEFINE_int(complexity, 10, "Complexity: 0 ~ 10 -- defined as in Opus"
35
36 static const bool bit_rate_dummy =
37 RegisterFlagValidator(&FLAGS_bit_rate_kbps, &ValidateBitRate);
38
39 // Define switch for complexity.
40 static bool ValidateComplexity(const char* flagname, int32_t value) {
41 if (value >= -1 && value <= 10)
42 return true;
43 printf("Invalid complexity setting, should be between 0 and 10.");
44 return false;
45 }
46
47 DEFINE_int32(complexity, 10, "Complexity: 0 ~ 10 -- defined as in Opus"
48 "specification."); 28 "specification.");
49 29
50 static const bool complexity_dummy = 30 // Define switch for maxplaybackrate
51 RegisterFlagValidator(&FLAGS_complexity, &ValidateComplexity); 31 DEFINE_int(maxplaybackrate, 48000, "Maximum playback rate (Hz).");
52 32
53 // Define switch for maxplaybackrate 33 DEFINE_int(application, 0, "Application mode: 0 -- VOIP, 1 -- Audio.");
54 DEFINE_int32(maxplaybackrate, 48000, "Maximum playback rate (Hz).");
55 34
56 // Define switch for application mode. 35 DEFINE_int(reported_loss_rate, 10, "Reported percentile of packet loss.");
57 static bool ValidateApplication(const char* flagname, int32_t value) {
58 if (value != 0 && value != 1) {
59 printf("Invalid application mode, should be 0 or 1.");
60 return false;
61 }
62 return true;
63 }
64
65 DEFINE_int32(application, 0, "Application mode: 0 -- VOIP, 1 -- Audio.");
66
67 static const bool application_dummy =
68 RegisterFlagValidator(&FLAGS_application, &ValidateApplication);
69
70 // Define switch for reported packet loss rate.
71 static bool ValidatePacketLossRate(const char* flagname, int32_t value) {
72 if (value >= 0 && value <= 100)
73 return true;
74 printf("Invalid packet loss percentile, should be between 0 and 100.");
75 return false;
76 }
77
78 DEFINE_int32(reported_loss_rate, 10, "Reported percentile of packet loss.");
79
80 static const bool reported_loss_rate_dummy =
81 RegisterFlagValidator(&FLAGS_reported_loss_rate, &ValidatePacketLossRate);
82 36
83 DEFINE_bool(fec, false, "Enable FEC for encoding (-nofec to disable)."); 37 DEFINE_bool(fec, false, "Enable FEC for encoding (-nofec to disable).");
84 38
85 DEFINE_bool(dtx, false, "Enable DTX for encoding (-nodtx to disable)."); 39 DEFINE_bool(dtx, false, "Enable DTX for encoding (-nodtx to disable).");
86 40
87 // Define switch for number of sub packets to repacketize. 41 DEFINE_int(sub_packets, 1, "Number of sub packets to repacketize.");
88 static bool ValidateSubPackets(const char* flagname, int32_t value) {
89 if (value >= 1 && value <= 3)
90 return true;
91 printf("Invalid number of sub packets, should be between 1 and 3.");
92 return false;
93 }
94 DEFINE_int32(sub_packets, 1, "Number of sub packets to repacketize.");
95 static const bool sub_packets_dummy =
96 RegisterFlagValidator(&FLAGS_sub_packets, &ValidateSubPackets);
97 42
98 } // namepsace 43 } // namepsace
99 44
100 class NetEqOpusQualityTest : public NetEqQualityTest { 45 class NetEqOpusQualityTest : public NetEqQualityTest {
101 protected: 46 protected:
102 NetEqOpusQualityTest(); 47 NetEqOpusQualityTest();
103 void SetUp() override; 48 void SetUp() override;
104 void TearDown() override; 49 void TearDown() override;
105 int EncodeBlock(int16_t* in_data, size_t block_size_samples, 50 int EncodeBlock(int16_t* in_data, size_t block_size_samples,
106 rtc::Buffer* payload, size_t max_bytes) override; 51 rtc::Buffer* payload, size_t max_bytes) override;
107 private: 52 private:
108 WebRtcOpusEncInst* opus_encoder_; 53 WebRtcOpusEncInst* opus_encoder_;
109 OpusRepacketizer* repacketizer_; 54 OpusRepacketizer* repacketizer_;
110 size_t sub_block_size_samples_; 55 size_t sub_block_size_samples_;
111 int bit_rate_kbps_; 56 int bit_rate_kbps_;
112 bool fec_; 57 bool fec_;
113 bool dtx_; 58 bool dtx_;
114 int complexity_; 59 int complexity_;
115 int maxplaybackrate_; 60 int maxplaybackrate_;
116 int target_loss_rate_; 61 int target_loss_rate_;
117 int sub_packets_; 62 int sub_packets_;
118 int application_; 63 int application_;
119 }; 64 };
120 65
121 NetEqOpusQualityTest::NetEqOpusQualityTest() 66 NetEqOpusQualityTest::NetEqOpusQualityTest()
122 : NetEqQualityTest(kOpusBlockDurationMs * FLAGS_sub_packets, 67 : NetEqQualityTest(kOpusBlockDurationMs * FLAG_sub_packets,
123 kOpusSamplingKhz, 68 kOpusSamplingKhz,
124 kOpusSamplingKhz, 69 kOpusSamplingKhz,
125 NetEqDecoder::kDecoderOpus), 70 NetEqDecoder::kDecoderOpus),
126 opus_encoder_(NULL), 71 opus_encoder_(NULL),
127 repacketizer_(NULL), 72 repacketizer_(NULL),
128 sub_block_size_samples_( 73 sub_block_size_samples_(
129 static_cast<size_t>(kOpusBlockDurationMs * kOpusSamplingKhz)), 74 static_cast<size_t>(kOpusBlockDurationMs * kOpusSamplingKhz)),
130 bit_rate_kbps_(FLAGS_bit_rate_kbps), 75 bit_rate_kbps_(FLAG_bit_rate_kbps),
131 fec_(FLAGS_fec), 76 fec_(FLAG_fec),
132 dtx_(FLAGS_dtx), 77 dtx_(FLAG_dtx),
133 complexity_(FLAGS_complexity), 78 complexity_(FLAG_complexity),
134 maxplaybackrate_(FLAGS_maxplaybackrate), 79 maxplaybackrate_(FLAG_maxplaybackrate),
135 target_loss_rate_(FLAGS_reported_loss_rate), 80 target_loss_rate_(FLAG_reported_loss_rate),
136 sub_packets_(FLAGS_sub_packets) { 81 sub_packets_(FLAG_sub_packets) {
82 // Flag validation
83 RTC_CHECK(FLAG_bit_rate_kbps >= 6 && FLAG_bit_rate_kbps <= 510)
84 << "Invalid bit rate, should be between 6 and 510 kbps.";
85
86 RTC_CHECK(FLAG_complexity >= -1 && FLAG_complexity <= 10)
87 << "Invalid complexity setting, should be between 0 and 10.";
88
89 RTC_CHECK(FLAG_application == 0 || FLAG_application == 1)
90 << "Invalid application mode, should be 0 or 1.";
91
92 RTC_CHECK(FLAG_reported_loss_rate >= 0 && FLAG_reported_loss_rate <= 100)
93 << "Invalid packet loss percentile, should be between 0 and 100.";
94
95 RTC_CHECK(FLAG_sub_packets >= 1 && FLAG_sub_packets <= 3)
96 << "Invalid number of sub packets, should be between 1 and 3.";
97
137 // Redefine decoder type if input is stereo. 98 // Redefine decoder type if input is stereo.
138 if (channels_ > 1) { 99 if (channels_ > 1) {
139 decoder_type_ = NetEqDecoder::kDecoderOpus_2ch; 100 decoder_type_ = NetEqDecoder::kDecoderOpus_2ch;
140 } 101 }
141 application_ = FLAGS_application; 102 application_ = FLAG_application;
142 } 103 }
143 104
144 void NetEqOpusQualityTest::SetUp() { 105 void NetEqOpusQualityTest::SetUp() {
145 // Create encoder memory. 106 // Create encoder memory.
146 WebRtcOpus_EncoderCreate(&opus_encoder_, channels_, application_); 107 WebRtcOpus_EncoderCreate(&opus_encoder_, channels_, application_);
147 ASSERT_TRUE(opus_encoder_); 108 ASSERT_TRUE(opus_encoder_);
148 109
149 // Create repacketizer. 110 // Create repacketizer.
150 repacketizer_ = opus_repacketizer_create(); 111 repacketizer_ = opus_repacketizer_create();
151 ASSERT_TRUE(repacketizer_); 112 ASSERT_TRUE(repacketizer_);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 EXPECT_GE(value, 0); 166 EXPECT_GE(value, 0);
206 return value; 167 return value;
207 } 168 }
208 169
209 TEST_F(NetEqOpusQualityTest, Test) { 170 TEST_F(NetEqOpusQualityTest, Test) {
210 Simulate(); 171 Simulate();
211 } 172 }
212 173
213 } // namespace test 174 } // namespace test
214 } // namespace webrtc 175 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698