OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | |
the sun
2015/11/09 12:41:01
Why do we need to test at this level? Shouldn't th
minyue-webrtc
2015/11/09 15:13:00
I see. There are two reasons that I wanted to chec
the sun
2015/11/09 15:29:56
Ah, I see, sorry I didn't notice it was a fuzzer t
| |
3 * | |
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 | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 #include "webrtc/base/scoped_ptr.h" | |
13 #include "webrtc/base/timeutils.h" | |
14 #include "webrtc/system_wrappers/include/sleep.h" | |
15 #include "webrtc/test/channel_transport/include/channel_transport.h" | |
16 #include "webrtc/test/random.h" | |
17 #include "webrtc/test/testsupport/fileutils.h" | |
18 #include "webrtc/voice_engine/test/auto_test/voe_standard_test.h" | |
19 | |
20 namespace { | |
21 | |
22 const char kIp[] = "127.0.0.1"; | |
23 const int kPort = 1234; | |
24 const webrtc::CodecInst kCodecInst = {120, "opus", 48000, 960, 2, 64000}; | |
25 | |
26 } // namespace | |
27 | |
28 namespace voetest { | |
29 | |
30 using webrtc::test::Random; | |
31 using webrtc::test::VoiceChannelTransport; | |
32 | |
33 // This test allows a check on the output signal in an end-to-end call. | |
34 class OutputTest { | |
35 public: | |
36 OutputTest(); | |
37 ~OutputTest(); | |
38 | |
39 void Start(); | |
40 | |
41 void EnableOutputCheck(); | |
42 void DisableOutputCheck(); | |
43 void SetOutputBound(int16_t lower_bound, int16_t upper_bound); | |
the sun
2015/11/09 12:41:01
Make this settable in c-tor instead - the bounds d
minyue-webrtc
2015/11/09 15:13:00
ok. I just wanted to make this class a bit more ge
| |
44 void Mute(); | |
45 void Unmute(); | |
46 void SetBitRate(int rate); | |
47 | |
48 private: | |
49 // This class checks all output values and count the number of samples that | |
50 // go out of a defined range. | |
51 class VoEOutputCheckMediaProcess : public VoEMediaProcess { | |
52 public: | |
53 VoEOutputCheckMediaProcess(); | |
54 void set_enabled(bool enabled) { enabled_ = enabled; } | |
55 void set_lower_bound(int16_t lower_bound) { lower_bound_ = lower_bound; } | |
the sun
2015/11/09 12:41:00
set in c-tor
minyue-webrtc
2015/11/09 15:13:00
Done.
| |
56 void set_upper_bound(int16_t upper_bound) { upper_bound_ = upper_bound; } | |
57 void Process(int channel, | |
58 ProcessingTypes type, | |
59 int16_t audio10ms[], | |
60 size_t length, | |
61 int samplingFreq, | |
62 bool isStereo) override; | |
63 | |
64 private: | |
65 bool enabled_; | |
66 int16_t lower_bound_; | |
67 int16_t upper_bound_; | |
68 }; | |
69 | |
70 VoETestManager manager_; | |
71 VoEOutputCheckMediaProcess output_checker_; | |
72 | |
73 int channel_; | |
74 }; | |
75 | |
76 OutputTest::OutputTest() { | |
77 EXPECT_TRUE(manager_.Init()); | |
78 manager_.GetInterfaces(); | |
79 | |
80 VoEBase* base = manager_.BasePtr(); | |
81 VoECodec* codec = manager_.CodecPtr(); | |
82 VoENetwork* network = manager_.NetworkPtr(); | |
83 | |
84 EXPECT_EQ(0, base->Init()); | |
85 | |
86 channel_ = base->CreateChannel(); | |
87 | |
88 // |network| will take care of the life time of |transport|. | |
89 VoiceChannelTransport* transport = | |
90 new VoiceChannelTransport(network, channel_); | |
91 | |
92 EXPECT_EQ(0, transport->SetSendDestination(kIp, kPort)); | |
93 EXPECT_EQ(0, transport->SetLocalReceiver(kPort)); | |
94 | |
95 EXPECT_EQ(0, codec->SetSendCodec(channel_, kCodecInst)); | |
96 EXPECT_EQ(0, codec->SetOpusDtx(channel_, true)); | |
97 | |
98 EXPECT_EQ(0, manager_.VolumeControlPtr()->SetSpeakerVolume(255)); | |
99 | |
100 manager_.ExternalMediaPtr()->RegisterExternalMediaProcessing( | |
101 channel_, ProcessingTypes::kPlaybackPerChannel, output_checker_); | |
102 } | |
103 | |
104 OutputTest::~OutputTest() { | |
105 EXPECT_EQ(0, manager_.NetworkPtr()->DeRegisterExternalTransport(channel_)); | |
106 EXPECT_EQ(0, manager_.ReleaseInterfaces()); | |
107 } | |
108 | |
109 void OutputTest::Start() { | |
110 const std::string file_name = | |
111 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"); | |
112 const webrtc::FileFormats kInputFormat = webrtc::kFileFormatPcm32kHzFile; | |
113 | |
114 ASSERT_EQ(0, | |
115 manager_.FilePtr()->StartPlayingFileAsMicrophone( | |
116 channel_, file_name.c_str(), true, false, kInputFormat, 1.0)); | |
the sun
2015/11/09 12:41:01
nit: formatting
minyue-webrtc
2015/11/09 15:13:00
Done.
| |
117 | |
118 VoEBase* base = manager_.BasePtr(); | |
119 ASSERT_EQ(0, base->StartPlayout(channel_)); | |
120 ASSERT_EQ(0, base->StartSend(channel_)); | |
121 } | |
122 | |
123 void OutputTest::EnableOutputCheck() { | |
124 output_checker_.set_enabled(true); | |
125 } | |
126 | |
127 void OutputTest::DisableOutputCheck() { | |
128 output_checker_.set_enabled(false); | |
129 } | |
130 | |
131 void OutputTest::SetOutputBound(int16_t lower_bound, int16_t upper_bound) { | |
132 output_checker_.set_lower_bound(lower_bound); | |
133 output_checker_.set_upper_bound(upper_bound); | |
134 } | |
135 | |
136 void OutputTest::Mute() { | |
137 manager_.VolumeControlPtr()->SetInputMute(channel_, true); | |
138 } | |
139 | |
140 void OutputTest::Unmute() { | |
141 manager_.VolumeControlPtr()->SetInputMute(channel_, false); | |
142 } | |
143 | |
144 void OutputTest::SetBitRate(int rate) { | |
145 manager_.CodecPtr()->SetBitRate(channel_, rate); | |
146 } | |
147 | |
148 OutputTest::VoEOutputCheckMediaProcess::VoEOutputCheckMediaProcess() | |
149 : enabled_(false), | |
150 lower_bound_(-32768), | |
151 upper_bound_(32767) {} | |
152 | |
153 void OutputTest::VoEOutputCheckMediaProcess::Process(int channel, | |
154 ProcessingTypes type, | |
155 int16_t* audio10ms, | |
156 size_t length, | |
157 int samplingFreq, | |
158 bool isStereo) { | |
159 if (!enabled_) | |
160 return; | |
161 const int num_channels = isStereo ? 2 : 1; | |
162 for (size_t i = 0; i < length; ++i) { | |
163 for (int c = 0; c < num_channels; ++c) { | |
164 ASSERT_GE(audio10ms[i * num_channels + c], lower_bound_); | |
165 ASSERT_LE(audio10ms[i * num_channels + c], upper_bound_); | |
166 } | |
167 } | |
168 } | |
169 | |
170 TEST(OutputTest, OpusDtxHasNoNoisePump) { | |
171 const int kRuntimeMs = 20000; | |
172 const uint32_t kUnmuteTimeMs = 1000; | |
173 const int kCheckAfterMute = 2000; | |
174 const uint32_t kCheckTimeMs = 2000; | |
175 const int kMinOpusRate = 6000; | |
176 const int kMaxOpusRate = 64000; | |
177 | |
178 #if defined(OPUS_FIXED_POINT) | |
179 const int16_t kDtxBoundForSilence = 20; | |
180 #else | |
181 const int16_t kDtxBoundForSilence = 2; | |
182 #endif | |
183 | |
184 OutputTest test; | |
185 Random random(1234ull); | |
186 | |
187 uint32_t start_time = rtc::Time(); | |
188 test.Start(); | |
189 test.SetOutputBound(-kDtxBoundForSilence, kDtxBoundForSilence); | |
190 while (rtc::TimeSince(start_time) < kRuntimeMs) { | |
191 webrtc::SleepMs(random.Rand(kUnmuteTimeMs - kUnmuteTimeMs / 10, | |
192 kUnmuteTimeMs + kUnmuteTimeMs / 10)); | |
193 test.Mute(); | |
194 webrtc::SleepMs(kCheckAfterMute); | |
195 test.EnableOutputCheck(); | |
196 webrtc::SleepMs(random.Rand(kCheckTimeMs - kCheckTimeMs / 10, | |
197 kCheckTimeMs + kCheckTimeMs / 10)); | |
198 test.DisableOutputCheck(); | |
199 test.SetBitRate(random.Rand(kMinOpusRate, kMaxOpusRate)); | |
200 test.Unmute(); | |
201 } | |
202 } | |
203 | |
204 } // namespace voetest | |
OLD | NEW |