OLD | NEW |
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_int(maxplaybackrate, 48000, "Maximum playback rate (Hz)."); |
51 RegisterFlagValidator(&FLAGS_complexity, &ValidateComplexity); | |
52 | 31 |
53 // Define switch for maxplaybackrate | 32 DEFINE_int(application, 0, "Application mode: 0 -- VOIP, 1 -- Audio."); |
54 DEFINE_int32(maxplaybackrate, 48000, "Maximum playback rate (Hz)."); | |
55 | 33 |
56 // Define switch for application mode. | 34 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 | 35 |
83 DEFINE_bool(fec, false, "Enable FEC for encoding (-nofec to disable)."); | 36 DEFINE_bool(fec, false, "Enable FEC for encoding (-nofec to disable)."); |
84 | 37 |
85 DEFINE_bool(dtx, false, "Enable DTX for encoding (-nodtx to disable)."); | 38 DEFINE_bool(dtx, false, "Enable DTX for encoding (-nodtx to disable)."); |
86 | 39 |
87 // Define switch for number of sub packets to repacketize. | 40 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 | 41 |
98 } // namepsace | 42 } // namespace |
99 | 43 |
100 class NetEqOpusQualityTest : public NetEqQualityTest { | 44 class NetEqOpusQualityTest : public NetEqQualityTest { |
101 protected: | 45 protected: |
102 NetEqOpusQualityTest(); | 46 NetEqOpusQualityTest(); |
103 void SetUp() override; | 47 void SetUp() override; |
104 void TearDown() override; | 48 void TearDown() override; |
105 int EncodeBlock(int16_t* in_data, size_t block_size_samples, | 49 int EncodeBlock(int16_t* in_data, size_t block_size_samples, |
106 rtc::Buffer* payload, size_t max_bytes) override; | 50 rtc::Buffer* payload, size_t max_bytes) override; |
107 private: | 51 private: |
108 WebRtcOpusEncInst* opus_encoder_; | 52 WebRtcOpusEncInst* opus_encoder_; |
109 OpusRepacketizer* repacketizer_; | 53 OpusRepacketizer* repacketizer_; |
110 size_t sub_block_size_samples_; | 54 size_t sub_block_size_samples_; |
111 int bit_rate_kbps_; | 55 int bit_rate_kbps_; |
112 bool fec_; | 56 bool fec_; |
113 bool dtx_; | 57 bool dtx_; |
114 int complexity_; | 58 int complexity_; |
115 int maxplaybackrate_; | 59 int maxplaybackrate_; |
116 int target_loss_rate_; | 60 int target_loss_rate_; |
117 int sub_packets_; | 61 int sub_packets_; |
118 int application_; | 62 int application_; |
119 }; | 63 }; |
120 | 64 |
121 NetEqOpusQualityTest::NetEqOpusQualityTest() | 65 NetEqOpusQualityTest::NetEqOpusQualityTest() |
122 : NetEqQualityTest(kOpusBlockDurationMs * FLAGS_sub_packets, | 66 : NetEqQualityTest(kOpusBlockDurationMs * FLAG_sub_packets, |
123 kOpusSamplingKhz, | 67 kOpusSamplingKhz, |
124 kOpusSamplingKhz, | 68 kOpusSamplingKhz, |
125 NetEqDecoder::kDecoderOpus), | 69 NetEqDecoder::kDecoderOpus), |
126 opus_encoder_(NULL), | 70 opus_encoder_(NULL), |
127 repacketizer_(NULL), | 71 repacketizer_(NULL), |
128 sub_block_size_samples_( | 72 sub_block_size_samples_( |
129 static_cast<size_t>(kOpusBlockDurationMs * kOpusSamplingKhz)), | 73 static_cast<size_t>(kOpusBlockDurationMs * kOpusSamplingKhz)), |
130 bit_rate_kbps_(FLAGS_bit_rate_kbps), | 74 bit_rate_kbps_(FLAG_bit_rate_kbps), |
131 fec_(FLAGS_fec), | 75 fec_(FLAG_fec), |
132 dtx_(FLAGS_dtx), | 76 dtx_(FLAG_dtx), |
133 complexity_(FLAGS_complexity), | 77 complexity_(FLAG_complexity), |
134 maxplaybackrate_(FLAGS_maxplaybackrate), | 78 maxplaybackrate_(FLAG_maxplaybackrate), |
135 target_loss_rate_(FLAGS_reported_loss_rate), | 79 target_loss_rate_(FLAG_reported_loss_rate), |
136 sub_packets_(FLAGS_sub_packets) { | 80 sub_packets_(FLAG_sub_packets) { |
| 81 // Flag validation |
| 82 RTC_CHECK(FLAG_bit_rate_kbps >= 6 && FLAG_bit_rate_kbps <= 510) |
| 83 << "Invalid bit rate, should be between 6 and 510 kbps."; |
| 84 |
| 85 RTC_CHECK(FLAG_complexity >= -1 && FLAG_complexity <= 10) |
| 86 << "Invalid complexity setting, should be between 0 and 10."; |
| 87 |
| 88 RTC_CHECK(FLAG_application == 0 || FLAG_application == 1) |
| 89 << "Invalid application mode, should be 0 or 1."; |
| 90 |
| 91 RTC_CHECK(FLAG_reported_loss_rate >= 0 && FLAG_reported_loss_rate <= 100) |
| 92 << "Invalid packet loss percentile, should be between 0 and 100."; |
| 93 |
| 94 RTC_CHECK(FLAG_sub_packets >= 1 && FLAG_sub_packets <= 3) |
| 95 << "Invalid number of sub packets, should be between 1 and 3."; |
| 96 |
137 // Redefine decoder type if input is stereo. | 97 // Redefine decoder type if input is stereo. |
138 if (channels_ > 1) { | 98 if (channels_ > 1) { |
139 decoder_type_ = NetEqDecoder::kDecoderOpus_2ch; | 99 decoder_type_ = NetEqDecoder::kDecoderOpus_2ch; |
140 } | 100 } |
141 application_ = FLAGS_application; | 101 application_ = FLAG_application; |
142 } | 102 } |
143 | 103 |
144 void NetEqOpusQualityTest::SetUp() { | 104 void NetEqOpusQualityTest::SetUp() { |
145 // Create encoder memory. | 105 // Create encoder memory. |
146 WebRtcOpus_EncoderCreate(&opus_encoder_, channels_, application_); | 106 WebRtcOpus_EncoderCreate(&opus_encoder_, channels_, application_); |
147 ASSERT_TRUE(opus_encoder_); | 107 ASSERT_TRUE(opus_encoder_); |
148 | 108 |
149 // Create repacketizer. | 109 // Create repacketizer. |
150 repacketizer_ = opus_repacketizer_create(); | 110 repacketizer_ = opus_repacketizer_create(); |
151 ASSERT_TRUE(repacketizer_); | 111 ASSERT_TRUE(repacketizer_); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 EXPECT_GE(value, 0); | 165 EXPECT_GE(value, 0); |
206 return value; | 166 return value; |
207 } | 167 } |
208 | 168 |
209 TEST_F(NetEqOpusQualityTest, Test) { | 169 TEST_F(NetEqOpusQualityTest, Test) { |
210 Simulate(); | 170 Simulate(); |
211 } | 171 } |
212 | 172 |
213 } // namespace test | 173 } // namespace test |
214 } // namespace webrtc | 174 } // namespace webrtc |
OLD | NEW |