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