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

Side by Side Diff: webrtc/voice_engine/test/auto_test/standard/volume_test.cc

Issue 2727063004: Remove VoEVolumeControl interface. (Closed)
Patch Set: fix Created 3 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
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2012 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 "webrtc/voice_engine/test/auto_test/fixtures/after_streaming_fixture.h"
12
13 namespace {
14
15 void ExpectVolumeNear(int expected, int actual) {
16 // The hardware volume may be more coarsely quantized than [0, 255], so
17 // it is not always reasonable to expect to get exactly what we set. This
18 // allows for some error.
19 const int kMaxVolumeError = 10;
20 EXPECT_NEAR(expected, actual, kMaxVolumeError);
21 EXPECT_GE(actual, 0);
22 EXPECT_LE(actual, 255);
23 }
24
25 } // namespace
26
27 class VolumeTest : public AfterStreamingFixture {
28 public:
29 void SetAndVerifyMicVolume(unsigned int volume) {
30 bool success = voe_volume_control_->SetMicVolume(volume) == 0;
31 #if !defined(WEBRTC_LINUX)
32 EXPECT_TRUE(success);
33 #endif
34 if (!success) {
35 TEST_LOG("Failed to set microphone volume to %u.\n", volume);
36 return;
37 }
38
39 unsigned int test_volume = 1000;
40 success = voe_volume_control_->GetMicVolume(test_volume) == 0;
41 #if !defined(WEBRTC_LINUX)
42 EXPECT_TRUE(success);
43 #endif
44 if (success) {
45 EXPECT_EQ(volume, test_volume);
46 } else {
47 TEST_LOG("Failed to get the microphone volume.");
48 EXPECT_EQ(1000u, test_volume);
49 }
50 }
51
52 void SetAndVerifyInputMute(bool enable) {
53 bool success = voe_volume_control_->SetInputMute(channel_, enable) == 0;
54 #if !defined(WEBRTC_LINUX)
55 EXPECT_TRUE(success);
56 #endif
57 if (!success) {
58 TEST_LOG("Failed to %smute input.\n", enable ? "" : "un");
59 return;
60 }
61
62 bool is_muted = !enable;
63 success = voe_volume_control_->GetInputMute(channel_, is_muted) == 0;
64 #if !defined(WEBRTC_LINUX)
65 EXPECT_TRUE(success);
66 #endif
67 if (success) {
68 EXPECT_EQ(enable, is_muted);
69 } else {
70 TEST_LOG("Failed to mute the input.");
71 EXPECT_NE(enable, is_muted);
72 }
73 }
74 };
75
76 // Some tests are flaky on Linux (Pulse Audio), which boils down to some system
77 // values not being acquired in time. In Pulse Audio we make one retry if
78 // needed, but if we fail then, a -1 is returned propagating up through VoE.
79 // To avoid possible bugs slipping through on other platforms we make adequate
80 // changes on Linux only.
81 TEST_F(VolumeTest, VerifyCorrectErrorReturns) {
82 // All tests run on correct initialization which eliminates one possible error
83 // return. In addition, we assume the audio_device returning values without
84 // error, which eliminates another potential error.
85 // Left to verify are sanity checks of set parameters.
86
87 // Valid volume range: [0, 255]
88 EXPECT_EQ(-1, voe_volume_control_->SetSpeakerVolume(256));
89 EXPECT_EQ(-1, voe_volume_control_->SetMicVolume(256));
90
91 // Valid panning rage: [0, 1]
92 EXPECT_EQ(-1, voe_volume_control_->SetOutputVolumePan(channel_, -0.1f, 0.5f));
93 EXPECT_EQ(-1, voe_volume_control_->SetOutputVolumePan(channel_, 1.1f, 0.5f));
94 EXPECT_EQ(-1, voe_volume_control_->SetOutputVolumePan(channel_, 0.5f, -0.1f));
95 EXPECT_EQ(-1, voe_volume_control_->SetOutputVolumePan(channel_, 0.5f, 1.1f));
96 }
97
98 TEST_F(VolumeTest, DefaultSpeakerVolumeIsAtMost255) {
99 unsigned int volume = 1000;
100 EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(volume));
101 EXPECT_LE(volume, 255u);
102 }
103
104 TEST_F(VolumeTest, SetVolumeBeforePlayoutWorks) {
105 // This is a rather specialized test, intended to exercise some PulseAudio
106 // code. However, these conditions should be satisfied on any platform.
107 unsigned int original_volume = 0;
108 EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(original_volume));
109 Sleep(1000);
110
111 EXPECT_EQ(0, voe_volume_control_->SetSpeakerVolume(200));
112 unsigned int volume;
113 EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(volume));
114 ExpectVolumeNear(200u, volume);
115
116 PausePlaying();
117 ResumePlaying();
118 EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(volume));
119 // Ensure the volume has not changed after resuming playout.
120 ExpectVolumeNear(200u, volume);
121
122 PausePlaying();
123 EXPECT_EQ(0, voe_volume_control_->SetSpeakerVolume(100));
124 ResumePlaying();
125 // Ensure the volume set while paused is retained.
126 EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(volume));
127 ExpectVolumeNear(100u, volume);
128
129 EXPECT_EQ(0, voe_volume_control_->SetSpeakerVolume(original_volume));
130 }
131
132 TEST_F(VolumeTest, ManualSetVolumeWorks) {
133 unsigned int original_volume = 0;
134 EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(original_volume));
135 Sleep(1000);
136
137 TEST_LOG("Setting speaker volume to 0 out of 255.\n");
138 EXPECT_EQ(0, voe_volume_control_->SetSpeakerVolume(0));
139 unsigned int volume;
140 EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(volume));
141 ExpectVolumeNear(0u, volume);
142 Sleep(1000);
143
144 TEST_LOG("Setting speaker volume to 100 out of 255.\n");
145 EXPECT_EQ(0, voe_volume_control_->SetSpeakerVolume(100));
146 EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(volume));
147 ExpectVolumeNear(100u, volume);
148 Sleep(1000);
149
150 // Set the volume to 255 very briefly so we don't blast the poor user
151 // listening to this. This is just to test the call succeeds.
152 EXPECT_EQ(0, voe_volume_control_->SetSpeakerVolume(255));
153 EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(volume));
154 ExpectVolumeNear(255u, volume);
155
156 TEST_LOG("Setting speaker volume to the original %d out of 255.\n",
157 original_volume);
158 EXPECT_EQ(0, voe_volume_control_->SetSpeakerVolume(original_volume));
159 Sleep(1000);
160 }
161
162 TEST_F(VolumeTest, DefaultMicrophoneVolumeIsAtMost255) {
163 unsigned int volume = 1000;
164 bool could_get_mic_volume = voe_volume_control_->GetMicVolume(volume) == 0;
165 #if !defined(WEBRTC_LINUX)
166 EXPECT_TRUE(could_get_mic_volume);
167 #endif
168 if (could_get_mic_volume) {
169 EXPECT_LE(volume, 255u);
170 } else {
171 TEST_LOG("Failed to get the microphone volume.");
172 EXPECT_EQ(1000u, volume);
173 }
174 }
175
176 // The test below is disabled due to issue webrtc:6206.
177 TEST_F(VolumeTest, DISABLED_ManualRequiresMicrophoneCanSetMicrophoneVolumeWithAg cOff) {
178 SwitchToManualMicrophone();
179 EXPECT_EQ(0, voe_apm_->SetAgcStatus(false));
180
181 unsigned int original_volume = 0;
182 bool could_get_mic_volume =
183 (voe_volume_control_->GetMicVolume(original_volume) == 0);
184 #if !defined(WEBRTC_LINUX)
185 EXPECT_TRUE(could_get_mic_volume);
186 #endif
187 if (could_get_mic_volume)
188 TEST_LOG("Current microphone volume is %u.\n", original_volume);
189 else
190 TEST_LOG("Failed to fetch current microphone volume.\n");
191
192 TEST_LOG("Setting microphone volume to 0.\n");
193 SetAndVerifyMicVolume(0);
194 Sleep(1000);
195 TEST_LOG("Setting microphone volume to 255.\n");
196 SetAndVerifyMicVolume(255);
197 Sleep(1000);
198 if (could_get_mic_volume) {
199 TEST_LOG("Setting microphone volume back to %u.\n", original_volume);
200 SetAndVerifyMicVolume(original_volume);
201 Sleep(1000);
202 }
203 }
204
205 TEST_F(VolumeTest, ChannelScalingIsOneByDefault) {
206 float scaling = -1.0f;
207
208 EXPECT_EQ(0, voe_volume_control_->GetChannelOutputVolumeScaling(
209 channel_, scaling));
210 EXPECT_FLOAT_EQ(1.0f, scaling);
211 }
212
213 TEST_F(VolumeTest, ManualCanSetChannelScaling) {
214 EXPECT_EQ(0, voe_volume_control_->SetChannelOutputVolumeScaling(
215 channel_, 0.1f));
216
217 float scaling = 1.0f;
218 EXPECT_EQ(0, voe_volume_control_->GetChannelOutputVolumeScaling(
219 channel_, scaling));
220
221 EXPECT_FLOAT_EQ(0.1f, scaling);
222
223 TEST_LOG("Channel scaling set to 0.1: audio should be barely audible.\n");
224 Sleep(2000);
225 }
226
227 TEST_F(VolumeTest, InputMutingIsNotEnabledByDefault) {
228 bool is_muted = true;
229 EXPECT_EQ(0, voe_volume_control_->GetInputMute(channel_, is_muted));
230 EXPECT_FALSE(is_muted);
231 }
232
233 TEST_F(VolumeTest, ManualInputMutingMutesMicrophone) {
234 SwitchToManualMicrophone();
235 // Enable muting.
236 SetAndVerifyInputMute(true);
237 TEST_LOG("Muted: talk into microphone and verify you can't hear yourself.\n");
238 Sleep(2000);
239
240 // Test that we can disable muting.
241 SetAndVerifyInputMute(false);
242 TEST_LOG("Unmuted: talk into microphone and verify you can hear yourself.\n");
243 Sleep(2000);
244 }
245
246 TEST_F(VolumeTest, ManualTestInputAndOutputLevels) {
247 SwitchToManualMicrophone();
248
249 TEST_LOG("Speak and verify that the following levels look right:\n");
250 for (int i = 0; i < 5; i++) {
251 Sleep(1000);
252 unsigned int input_level = 0;
253 unsigned int output_level = 0;
254 unsigned int input_level_full_range = 0;
255 unsigned int output_level_full_range = 0;
256
257 EXPECT_EQ(0, voe_volume_control_->GetSpeechInputLevel(
258 input_level));
259 EXPECT_EQ(0, voe_volume_control_->GetSpeechOutputLevel(
260 channel_, output_level));
261 EXPECT_EQ(0, voe_volume_control_->GetSpeechInputLevelFullRange(
262 input_level_full_range));
263 EXPECT_EQ(0, voe_volume_control_->GetSpeechOutputLevelFullRange(
264 channel_, output_level_full_range));
265
266 TEST_LOG(" warped levels (0-9) : in=%5d, out=%5d\n",
267 input_level, output_level);
268 TEST_LOG(" linear levels (0-32768): in=%5d, out=%5d\n",
269 input_level_full_range, output_level_full_range);
270 }
271 }
272
273 TEST_F(VolumeTest, ChannelsAreNotPannedByDefault) {
274 float left = -1.0;
275 float right = -1.0;
276
277 EXPECT_EQ(0, voe_volume_control_->GetOutputVolumePan(channel_, left, right));
278 EXPECT_FLOAT_EQ(1.0, left);
279 EXPECT_FLOAT_EQ(1.0, right);
280 }
281
282 TEST_F(VolumeTest, ManualTestChannelPanning) {
283 TEST_LOG("Panning left.\n");
284 EXPECT_EQ(0, voe_volume_control_->SetOutputVolumePan(channel_, 0.8f, 0.1f));
285 Sleep(1000);
286
287 TEST_LOG("Back to center.\n");
288 EXPECT_EQ(0, voe_volume_control_->SetOutputVolumePan(channel_, 1.0f, 1.0f));
289 Sleep(1000);
290
291 TEST_LOG("Panning right.\n");
292 EXPECT_EQ(0, voe_volume_control_->SetOutputVolumePan(channel_, 0.1f, 0.8f));
293 Sleep(1000);
294
295 // To finish, verify that the getter works.
296 float left = 0.0f;
297 float right = 0.0f;
298
299 EXPECT_EQ(0, voe_volume_control_->GetOutputVolumePan(channel_, left, right));
300 EXPECT_FLOAT_EQ(0.1f, left);
301 EXPECT_FLOAT_EQ(0.8f, right);
302 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698