OLD | NEW |
| (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 <math.h> | |
12 #include <stdio.h> | |
13 #include <string.h> | |
14 | |
15 #include <memory> | |
16 | |
17 #include "webrtc/modules/audio_device/audio_device_config.h" | |
18 #include "webrtc/modules/audio_device/audio_device_impl.h" | |
19 #include "webrtc/modules/audio_device/test/audio_device_test_defines.h" | |
20 #include "webrtc/modules/utility/include/process_thread.h" | |
21 #include "webrtc/rtc_base/location.h" | |
22 #include "webrtc/system_wrappers/include/sleep.h" | |
23 #include "webrtc/test/gtest.h" | |
24 #include "webrtc/test/testsupport/fileutils.h" | |
25 | |
26 // Helper functions | |
27 #if defined(ANDROID) | |
28 char filenameStr[2][256] = | |
29 { {0}, | |
30 {0}, | |
31 }; // Allow two buffers for those API calls taking two filenames | |
32 int currentStr = 0; | |
33 | |
34 const char* GetFilename(const char* filename) | |
35 { | |
36 currentStr = !currentStr; | |
37 sprintf(filenameStr[currentStr], "/sdcard/admtest/%s", filename); | |
38 return filenameStr[currentStr]; | |
39 } | |
40 #elif !defined(WEBRTC_IOS) | |
41 const char* GetFilename(const char* filename) { | |
42 std::string full_path_filename = webrtc::test::OutputPath() + filename; | |
43 return full_path_filename.c_str(); | |
44 } | |
45 #endif | |
46 | |
47 using namespace webrtc; | |
48 | |
49 class AudioEventObserverAPI: public AudioDeviceObserver { | |
50 public: | |
51 AudioEventObserverAPI( | |
52 const rtc::scoped_refptr<AudioDeviceModule>& audioDevice) | |
53 : error_(kRecordingError), | |
54 warning_(kRecordingWarning), | |
55 audio_device_(audioDevice) {} | |
56 | |
57 ~AudioEventObserverAPI() override {} | |
58 | |
59 void OnErrorIsReported(const ErrorCode error) override { | |
60 TEST_LOG("\n[*** ERROR ***] => OnErrorIsReported(%d)\n\n", error); | |
61 error_ = error; | |
62 } | |
63 | |
64 void OnWarningIsReported(const WarningCode warning) override { | |
65 TEST_LOG("\n[*** WARNING ***] => OnWarningIsReported(%d)\n\n", warning); | |
66 warning_ = warning; | |
67 EXPECT_EQ(0, audio_device_->StopRecording()); | |
68 EXPECT_EQ(0, audio_device_->StopPlayout()); | |
69 } | |
70 | |
71 public: | |
72 ErrorCode error_; | |
73 WarningCode warning_; | |
74 private: | |
75 rtc::scoped_refptr<AudioDeviceModule> audio_device_; | |
76 }; | |
77 | |
78 class AudioTransportAPI: public AudioTransport { | |
79 public: | |
80 AudioTransportAPI(const rtc::scoped_refptr<AudioDeviceModule>& audioDevice) | |
81 : rec_count_(0), | |
82 play_count_(0) { | |
83 } | |
84 | |
85 ~AudioTransportAPI() override {} | |
86 | |
87 int32_t RecordedDataIsAvailable(const void* audioSamples, | |
88 const size_t nSamples, | |
89 const size_t nBytesPerSample, | |
90 const size_t nChannels, | |
91 const uint32_t sampleRate, | |
92 const uint32_t totalDelay, | |
93 const int32_t clockSkew, | |
94 const uint32_t currentMicLevel, | |
95 const bool keyPressed, | |
96 uint32_t& newMicLevel) override { | |
97 rec_count_++; | |
98 if (rec_count_ % 100 == 0) { | |
99 if (nChannels == 1) { | |
100 // mono | |
101 TEST_LOG("-"); | |
102 } else if ((nChannels == 2) && (nBytesPerSample == 2)) { | |
103 // stereo but only using one channel | |
104 TEST_LOG("-|"); | |
105 } else { | |
106 // stereo | |
107 TEST_LOG("--"); | |
108 } | |
109 } | |
110 return 0; | |
111 } | |
112 | |
113 int32_t NeedMorePlayData(const size_t nSamples, | |
114 const size_t nBytesPerSample, | |
115 const size_t nChannels, | |
116 const uint32_t sampleRate, | |
117 void* audioSamples, | |
118 size_t& nSamplesOut, | |
119 int64_t* elapsed_time_ms, | |
120 int64_t* ntp_time_ms) override { | |
121 play_count_++; | |
122 if (play_count_ % 100 == 0) { | |
123 if (nChannels == 1) { | |
124 TEST_LOG("+"); | |
125 } else { | |
126 TEST_LOG("++"); | |
127 } | |
128 } | |
129 nSamplesOut = 480; | |
130 return 0; | |
131 } | |
132 | |
133 void PushCaptureData(int voe_channel, | |
134 const void* audio_data, | |
135 int bits_per_sample, | |
136 int sample_rate, | |
137 size_t number_of_channels, | |
138 size_t number_of_frames) override {} | |
139 | |
140 void PullRenderData(int bits_per_sample, | |
141 int sample_rate, | |
142 size_t number_of_channels, | |
143 size_t number_of_frames, | |
144 void* audio_data, | |
145 int64_t* elapsed_time_ms, | |
146 int64_t* ntp_time_ms) override {} | |
147 | |
148 private: | |
149 uint32_t rec_count_; | |
150 uint32_t play_count_; | |
151 }; | |
152 | |
153 class AudioDeviceAPITest: public testing::Test { | |
154 protected: | |
155 AudioDeviceAPITest() {} | |
156 | |
157 ~AudioDeviceAPITest() override {} | |
158 | |
159 static void SetUpTestCase() { | |
160 process_thread_ = ProcessThread::Create("ProcessThread"); | |
161 process_thread_->Start(); | |
162 | |
163 // Windows: | |
164 // if (WEBRTC_WINDOWS_CORE_AUDIO_BUILD) | |
165 // user can select only the default (Core) | |
166 const int32_t kId = 444; | |
167 | |
168 #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) | |
169 TEST_LOG("WEBRTC_WINDOWS_CORE_AUDIO_BUILD is defined!\n\n"); | |
170 // create default implementation (=Core Audio) instance | |
171 EXPECT_TRUE((audio_device_ = AudioDeviceModule::Create( | |
172 kId, AudioDeviceModule::kPlatformDefaultAudio)) != NULL); | |
173 EXPECT_EQ(0, audio_device_.release()->Release()); | |
174 // explicitly specify usage of Core Audio (same as default) | |
175 EXPECT_TRUE((audio_device_ = AudioDeviceModule::Create( | |
176 kId, AudioDeviceModule::kWindowsCoreAudio)) != NULL); | |
177 #endif | |
178 | |
179 #if defined(ANDROID) | |
180 // Fails tests | |
181 EXPECT_TRUE((audio_device_ = AudioDeviceModule::Create( | |
182 kId, AudioDeviceModule::kWindowsCoreAudio)) == NULL); | |
183 EXPECT_TRUE((audio_device_ = AudioDeviceModule::Create( | |
184 kId, AudioDeviceModule::kLinuxAlsaAudio)) == NULL); | |
185 EXPECT_TRUE((audio_device_ = AudioDeviceModule::Create( | |
186 kId, AudioDeviceModule::kLinuxPulseAudio)) == NULL); | |
187 // Create default implementation instance | |
188 EXPECT_TRUE((audio_device_ = AudioDeviceModule::Create( | |
189 kId, AudioDeviceModule::kPlatformDefaultAudio)) != NULL); | |
190 #elif defined(WEBRTC_LINUX) | |
191 EXPECT_TRUE((audio_device_ = AudioDeviceModule::Create( | |
192 kId, AudioDeviceModule::kWindowsCoreAudio)) == NULL); | |
193 // create default implementation instance | |
194 EXPECT_TRUE((audio_device_ = AudioDeviceModule::Create( | |
195 kId, AudioDeviceModule::kPlatformDefaultAudio)) != NULL); | |
196 EXPECT_EQ(0, audio_device_->Terminate()); | |
197 EXPECT_EQ(0, audio_device_.release()->Release()); | |
198 // explicitly specify usage of Pulse Audio (same as default) | |
199 EXPECT_TRUE((audio_device_ = AudioDeviceModule::Create( | |
200 kId, AudioDeviceModule::kLinuxPulseAudio)) != NULL); | |
201 #endif | |
202 | |
203 #if defined(WEBRTC_MAC) | |
204 // Fails tests | |
205 EXPECT_TRUE((audio_device_ = AudioDeviceModule::Create( | |
206 kId, AudioDeviceModule::kWindowsCoreAudio)) == NULL); | |
207 EXPECT_TRUE((audio_device_ = AudioDeviceModule::Create( | |
208 kId, AudioDeviceModule::kLinuxAlsaAudio)) == NULL); | |
209 EXPECT_TRUE((audio_device_ = AudioDeviceModule::Create( | |
210 kId, AudioDeviceModule::kLinuxPulseAudio)) == NULL); | |
211 // Create default implementation instance | |
212 EXPECT_TRUE((audio_device_ = AudioDeviceModule::Create( | |
213 kId, AudioDeviceModule::kPlatformDefaultAudio)) != NULL); | |
214 #endif | |
215 | |
216 if (audio_device_ == NULL) { | |
217 FAIL() << "Failed creating audio device object!"; | |
218 } | |
219 | |
220 process_thread_->RegisterModule(audio_device_, RTC_FROM_HERE); | |
221 | |
222 AudioDeviceModule::AudioLayer audio_layer = | |
223 AudioDeviceModule::kPlatformDefaultAudio; | |
224 EXPECT_EQ(0, audio_device_->ActiveAudioLayer(&audio_layer)); | |
225 if (audio_layer == AudioDeviceModule::kLinuxAlsaAudio) { | |
226 linux_alsa_ = true; | |
227 } | |
228 } | |
229 | |
230 static void TearDownTestCase() { | |
231 if (process_thread_) { | |
232 process_thread_->DeRegisterModule(audio_device_); | |
233 process_thread_->Stop(); | |
234 process_thread_.reset(); | |
235 } | |
236 if (event_observer_) { | |
237 delete event_observer_; | |
238 event_observer_ = NULL; | |
239 } | |
240 if (audio_transport_) { | |
241 delete audio_transport_; | |
242 audio_transport_ = NULL; | |
243 } | |
244 if (audio_device_) | |
245 EXPECT_EQ(0, audio_device_.release()->Release()); | |
246 PRINT_TEST_RESULTS; | |
247 } | |
248 | |
249 void SetUp() override { | |
250 if (linux_alsa_) { | |
251 FAIL() << "API Test is not available on ALSA on Linux!"; | |
252 } | |
253 EXPECT_EQ(0, audio_device_->Init()); | |
254 EXPECT_TRUE(audio_device_->Initialized()); | |
255 } | |
256 | |
257 void TearDown() override { EXPECT_EQ(0, audio_device_->Terminate()); } | |
258 | |
259 void CheckVolume(uint32_t expected, uint32_t actual) { | |
260 // Mac and Windows have lower resolution on the volume settings. | |
261 #if defined(WEBRTC_MAC) || defined(_WIN32) | |
262 int diff = abs(static_cast<int>(expected - actual)); | |
263 EXPECT_LE(diff, 5); | |
264 #else | |
265 EXPECT_TRUE((actual == expected) || (actual == expected-1)); | |
266 #endif | |
267 } | |
268 | |
269 void CheckInitialPlayoutStates() { | |
270 EXPECT_FALSE(audio_device_->PlayoutIsInitialized()); | |
271 EXPECT_FALSE(audio_device_->Playing()); | |
272 EXPECT_FALSE(audio_device_->SpeakerIsInitialized()); | |
273 } | |
274 | |
275 void CheckInitialRecordingStates() { | |
276 EXPECT_FALSE(audio_device_->RecordingIsInitialized()); | |
277 EXPECT_FALSE(audio_device_->Recording()); | |
278 EXPECT_FALSE(audio_device_->MicrophoneIsInitialized()); | |
279 } | |
280 | |
281 // TODO(henrika): Get rid of globals. | |
282 static bool linux_alsa_; | |
283 static std::unique_ptr<ProcessThread> process_thread_; | |
284 static rtc::scoped_refptr<AudioDeviceModule> audio_device_; | |
285 static AudioTransportAPI* audio_transport_; | |
286 static AudioEventObserverAPI* event_observer_; | |
287 }; | |
288 | |
289 // Must be initialized like this to handle static SetUpTestCase() above. | |
290 bool AudioDeviceAPITest::linux_alsa_ = false; | |
291 std::unique_ptr<ProcessThread> AudioDeviceAPITest::process_thread_; | |
292 rtc::scoped_refptr<AudioDeviceModule> AudioDeviceAPITest::audio_device_; | |
293 AudioTransportAPI* AudioDeviceAPITest::audio_transport_ = NULL; | |
294 AudioEventObserverAPI* AudioDeviceAPITest::event_observer_ = NULL; | |
295 | |
296 TEST_F(AudioDeviceAPITest, RegisterEventObserver) { | |
297 event_observer_ = new AudioEventObserverAPI(audio_device_); | |
298 EXPECT_EQ(0, audio_device_->RegisterEventObserver(NULL)); | |
299 EXPECT_EQ(0, audio_device_->RegisterEventObserver(event_observer_)); | |
300 EXPECT_EQ(0, audio_device_->RegisterEventObserver(NULL)); | |
301 } | |
302 | |
303 TEST_F(AudioDeviceAPITest, RegisterAudioCallback) { | |
304 audio_transport_ = new AudioTransportAPI(audio_device_); | |
305 EXPECT_EQ(0, audio_device_->RegisterAudioCallback(NULL)); | |
306 EXPECT_EQ(0, audio_device_->RegisterAudioCallback(audio_transport_)); | |
307 EXPECT_EQ(0, audio_device_->RegisterAudioCallback(NULL)); | |
308 } | |
309 | |
310 TEST_F(AudioDeviceAPITest, Init) { | |
311 EXPECT_TRUE(audio_device_->Initialized()); | |
312 EXPECT_EQ(0, audio_device_->Init()); | |
313 EXPECT_TRUE(audio_device_->Initialized()); | |
314 EXPECT_EQ(0, audio_device_->Terminate()); | |
315 EXPECT_FALSE(audio_device_->Initialized()); | |
316 EXPECT_EQ(0, audio_device_->Init()); | |
317 EXPECT_TRUE(audio_device_->Initialized()); | |
318 EXPECT_EQ(0, audio_device_->Terminate()); | |
319 EXPECT_FALSE(audio_device_->Initialized()); | |
320 } | |
321 | |
322 TEST_F(AudioDeviceAPITest, Terminate) { | |
323 EXPECT_TRUE(audio_device_->Initialized()); | |
324 EXPECT_EQ(0, audio_device_->Terminate()); | |
325 EXPECT_FALSE(audio_device_->Initialized()); | |
326 EXPECT_EQ(0, audio_device_->Terminate()); | |
327 EXPECT_FALSE(audio_device_->Initialized()); | |
328 EXPECT_EQ(0, audio_device_->Init()); | |
329 EXPECT_TRUE(audio_device_->Initialized()); | |
330 EXPECT_EQ(0, audio_device_->Terminate()); | |
331 EXPECT_FALSE(audio_device_->Initialized()); | |
332 } | |
333 | |
334 TEST_F(AudioDeviceAPITest, PlayoutDevices) { | |
335 EXPECT_GT(audio_device_->PlayoutDevices(), 0); | |
336 EXPECT_GT(audio_device_->PlayoutDevices(), 0); | |
337 } | |
338 | |
339 TEST_F(AudioDeviceAPITest, RecordingDevices) { | |
340 EXPECT_GT(audio_device_->RecordingDevices(), 0); | |
341 EXPECT_GT(audio_device_->RecordingDevices(), 0); | |
342 } | |
343 | |
344 // TODO(henrika): uncomment when you have decided what to do with issue 3675. | |
345 #if 0 | |
346 TEST_F(AudioDeviceAPITest, PlayoutDeviceName) { | |
347 char name[kAdmMaxDeviceNameSize]; | |
348 char guid[kAdmMaxGuidSize]; | |
349 int16_t no_devices = audio_device_->PlayoutDevices(); | |
350 | |
351 // fail tests | |
352 EXPECT_EQ(-1, audio_device_->PlayoutDeviceName(-2, name, guid)); | |
353 EXPECT_EQ(-1, audio_device_->PlayoutDeviceName(no_devices, name, guid)); | |
354 EXPECT_EQ(-1, audio_device_->PlayoutDeviceName(0, NULL, guid)); | |
355 | |
356 // bulk tests | |
357 EXPECT_EQ(0, audio_device_->PlayoutDeviceName(0, name, NULL)); | |
358 #ifdef _WIN32 | |
359 // shall be mapped to 0. | |
360 EXPECT_EQ(0, audio_device_->PlayoutDeviceName(-1, name, NULL)); | |
361 #else | |
362 EXPECT_EQ(-1, audio_device_->PlayoutDeviceName(-1, name, NULL)); | |
363 #endif | |
364 for (int i = 0; i < no_devices; i++) { | |
365 EXPECT_EQ(0, audio_device_->PlayoutDeviceName(i, name, guid)); | |
366 EXPECT_EQ(0, audio_device_->PlayoutDeviceName(i, name, NULL)); | |
367 } | |
368 } | |
369 | |
370 TEST_F(AudioDeviceAPITest, RecordingDeviceName) { | |
371 char name[kAdmMaxDeviceNameSize]; | |
372 char guid[kAdmMaxGuidSize]; | |
373 int16_t no_devices = audio_device_->RecordingDevices(); | |
374 | |
375 // fail tests | |
376 EXPECT_EQ(-1, audio_device_->RecordingDeviceName(-2, name, guid)); | |
377 EXPECT_EQ(-1, audio_device_->RecordingDeviceName(no_devices, name, guid)); | |
378 EXPECT_EQ(-1, audio_device_->RecordingDeviceName(0, NULL, guid)); | |
379 | |
380 // bulk tests | |
381 EXPECT_EQ(0, audio_device_->RecordingDeviceName(0, name, NULL)); | |
382 #ifdef _WIN32 | |
383 // shall me mapped to 0 | |
384 EXPECT_EQ(0, audio_device_->RecordingDeviceName(-1, name, NULL)); | |
385 #else | |
386 EXPECT_EQ(-1, audio_device_->RecordingDeviceName(-1, name, NULL)); | |
387 #endif | |
388 for (int i = 0; i < no_devices; i++) { | |
389 EXPECT_EQ(0, audio_device_->RecordingDeviceName(i, name, guid)); | |
390 EXPECT_EQ(0, audio_device_->RecordingDeviceName(i, name, NULL)); | |
391 } | |
392 } | |
393 | |
394 TEST_F(AudioDeviceAPITest, SetPlayoutDevice) { | |
395 int16_t no_devices = audio_device_->PlayoutDevices(); | |
396 | |
397 // fail tests | |
398 EXPECT_EQ(-1, audio_device_->SetPlayoutDevice(-1)); | |
399 EXPECT_EQ(-1, audio_device_->SetPlayoutDevice(no_devices)); | |
400 | |
401 // bulk tests | |
402 #ifdef _WIN32 | |
403 EXPECT_EQ(0, audio_device_->SetPlayoutDevice( | |
404 AudioDeviceModule::kDefaultCommunicationDevice)); | |
405 EXPECT_EQ(0, audio_device_->SetPlayoutDevice( | |
406 AudioDeviceModule::kDefaultDevice)); | |
407 #else | |
408 EXPECT_EQ(-1, audio_device_->SetPlayoutDevice( | |
409 AudioDeviceModule::kDefaultCommunicationDevice)); | |
410 EXPECT_EQ(-1, audio_device_->SetPlayoutDevice( | |
411 AudioDeviceModule::kDefaultDevice)); | |
412 #endif | |
413 for (int i = 0; i < no_devices; i++) { | |
414 EXPECT_EQ(0, audio_device_->SetPlayoutDevice(i)); | |
415 } | |
416 } | |
417 | |
418 TEST_F(AudioDeviceAPITest, SetRecordingDevice) { | |
419 EXPECT_EQ(0, audio_device_->Init()); | |
420 int16_t no_devices = audio_device_->RecordingDevices(); | |
421 | |
422 // fail tests | |
423 EXPECT_EQ(-1, audio_device_->SetRecordingDevice(-1)); | |
424 EXPECT_EQ(-1, audio_device_->SetRecordingDevice(no_devices)); | |
425 | |
426 // bulk tests | |
427 #ifdef _WIN32 | |
428 EXPECT_TRUE(audio_device_->SetRecordingDevice( | |
429 AudioDeviceModule::kDefaultCommunicationDevice) == 0); | |
430 EXPECT_EQ(0, audio_device_->SetRecordingDevice( | |
431 AudioDeviceModule::kDefaultDevice)); | |
432 #else | |
433 EXPECT_TRUE(audio_device_->SetRecordingDevice( | |
434 AudioDeviceModule::kDefaultCommunicationDevice) == -1); | |
435 EXPECT_TRUE(audio_device_->SetRecordingDevice( | |
436 AudioDeviceModule::kDefaultDevice) == -1); | |
437 #endif | |
438 for (int i = 0; i < no_devices; i++) { | |
439 EXPECT_EQ(0, audio_device_->SetRecordingDevice(i)); | |
440 } | |
441 } | |
442 #endif // 0 | |
443 | |
444 TEST_F(AudioDeviceAPITest, PlayoutIsAvailable) { | |
445 bool available; | |
446 #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) | |
447 EXPECT_TRUE(audio_device_->SetPlayoutDevice( | |
448 AudioDeviceModule::kDefaultCommunicationDevice) == 0); | |
449 EXPECT_EQ(0, audio_device_->PlayoutIsAvailable(&available)); | |
450 // Availability check should not initialize. | |
451 EXPECT_FALSE(audio_device_->PlayoutIsInitialized()); | |
452 | |
453 EXPECT_EQ(0, | |
454 audio_device_->SetPlayoutDevice(AudioDeviceModule::kDefaultDevice)); | |
455 EXPECT_EQ(0, audio_device_->PlayoutIsAvailable(&available)); | |
456 EXPECT_FALSE(audio_device_->PlayoutIsInitialized()); | |
457 #endif | |
458 | |
459 int16_t no_devices = audio_device_->PlayoutDevices(); | |
460 for (int i = 0; i < no_devices; i++) { | |
461 EXPECT_EQ(0, audio_device_->SetPlayoutDevice(i)); | |
462 EXPECT_EQ(0, audio_device_->PlayoutIsAvailable(&available)); | |
463 EXPECT_FALSE(audio_device_->PlayoutIsInitialized()); | |
464 } | |
465 } | |
466 | |
467 TEST_F(AudioDeviceAPITest, RecordingIsAvailable) { | |
468 bool available; | |
469 #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) | |
470 EXPECT_EQ(0, audio_device_->SetRecordingDevice( | |
471 AudioDeviceModule::kDefaultCommunicationDevice)); | |
472 EXPECT_EQ(0, audio_device_->RecordingIsAvailable(&available)); | |
473 EXPECT_FALSE(audio_device_->RecordingIsInitialized()); | |
474 | |
475 EXPECT_EQ(0, audio_device_->SetRecordingDevice( | |
476 AudioDeviceModule::kDefaultDevice)); | |
477 EXPECT_EQ(0, audio_device_->RecordingIsAvailable(&available)); | |
478 EXPECT_FALSE(audio_device_->RecordingIsInitialized()); | |
479 #endif | |
480 | |
481 int16_t no_devices = audio_device_->RecordingDevices(); | |
482 for (int i = 0; i < no_devices; i++) { | |
483 EXPECT_EQ(0, audio_device_->SetRecordingDevice(i)); | |
484 EXPECT_EQ(0, audio_device_->RecordingIsAvailable(&available)); | |
485 EXPECT_FALSE(audio_device_->RecordingIsInitialized()); | |
486 } | |
487 } | |
488 | |
489 TEST_F(AudioDeviceAPITest, InitPlayout) { | |
490 // check initial state | |
491 EXPECT_FALSE(audio_device_->PlayoutIsInitialized()); | |
492 | |
493 // ensure that device must be set before we can initialize | |
494 EXPECT_EQ(-1, audio_device_->InitPlayout()); | |
495 EXPECT_EQ(0, audio_device_->SetPlayoutDevice(MACRO_DEFAULT_DEVICE)); | |
496 EXPECT_EQ(0, audio_device_->InitPlayout()); | |
497 EXPECT_TRUE(audio_device_->PlayoutIsInitialized()); | |
498 | |
499 // bulk tests | |
500 bool available; | |
501 EXPECT_EQ(0, audio_device_->PlayoutIsAvailable(&available)); | |
502 if (available) { | |
503 EXPECT_EQ(0, audio_device_->InitPlayout()); | |
504 EXPECT_TRUE(audio_device_->PlayoutIsInitialized()); | |
505 EXPECT_EQ(0, audio_device_->InitPlayout()); | |
506 EXPECT_EQ(-1, audio_device_->SetPlayoutDevice( | |
507 MACRO_DEFAULT_COMMUNICATION_DEVICE)); | |
508 EXPECT_EQ(0, audio_device_->StopPlayout()); | |
509 EXPECT_FALSE(audio_device_->PlayoutIsInitialized()); | |
510 } | |
511 | |
512 EXPECT_EQ(0, audio_device_->SetPlayoutDevice( | |
513 MACRO_DEFAULT_COMMUNICATION_DEVICE)); | |
514 EXPECT_EQ(0, audio_device_->PlayoutIsAvailable(&available)); | |
515 if (available) { | |
516 EXPECT_EQ(0, audio_device_->InitPlayout()); | |
517 // Sleep is needed for e.g. iPhone since we after stopping then starting may | |
518 // have a hangover time of a couple of ms before initialized. | |
519 SleepMs(50); | |
520 EXPECT_TRUE(audio_device_->PlayoutIsInitialized()); | |
521 } | |
522 | |
523 int16_t no_devices = audio_device_->PlayoutDevices(); | |
524 for (int i = 0; i < no_devices; i++) { | |
525 EXPECT_EQ(0, audio_device_->PlayoutIsAvailable(&available)); | |
526 if (available) { | |
527 EXPECT_EQ(0, audio_device_->StopPlayout()); | |
528 EXPECT_FALSE(audio_device_->PlayoutIsInitialized()); | |
529 EXPECT_EQ(0, audio_device_->SetPlayoutDevice(i)); | |
530 EXPECT_EQ(0, audio_device_->PlayoutIsAvailable(&available)); | |
531 if (available) { | |
532 EXPECT_EQ(0, audio_device_->InitPlayout()); | |
533 EXPECT_TRUE(audio_device_->PlayoutIsInitialized()); | |
534 } | |
535 } | |
536 } | |
537 EXPECT_EQ(0, audio_device_->StopPlayout()); | |
538 } | |
539 | |
540 TEST_F(AudioDeviceAPITest, InitRecording) { | |
541 // check initial state | |
542 EXPECT_FALSE(audio_device_->RecordingIsInitialized()); | |
543 | |
544 // ensure that device must be set before we can initialize | |
545 EXPECT_EQ(-1, audio_device_->InitRecording()); | |
546 EXPECT_EQ(0, audio_device_->SetRecordingDevice(MACRO_DEFAULT_DEVICE)); | |
547 EXPECT_EQ(0, audio_device_->InitRecording()); | |
548 EXPECT_TRUE(audio_device_->RecordingIsInitialized()); | |
549 | |
550 // bulk tests | |
551 bool available; | |
552 EXPECT_EQ(0, audio_device_->RecordingIsAvailable(&available)); | |
553 if (available) { | |
554 EXPECT_EQ(0, audio_device_->InitRecording()); | |
555 EXPECT_TRUE(audio_device_->RecordingIsInitialized()); | |
556 EXPECT_EQ(0, audio_device_->InitRecording()); | |
557 EXPECT_EQ(-1, | |
558 audio_device_->SetRecordingDevice(MACRO_DEFAULT_COMMUNICATION_DEVICE)); | |
559 EXPECT_EQ(0, audio_device_->StopRecording()); | |
560 EXPECT_FALSE(audio_device_->RecordingIsInitialized()); | |
561 } | |
562 | |
563 EXPECT_EQ(0, | |
564 audio_device_->SetRecordingDevice(MACRO_DEFAULT_COMMUNICATION_DEVICE)); | |
565 EXPECT_EQ(0, audio_device_->RecordingIsAvailable(&available)); | |
566 if (available) { | |
567 EXPECT_EQ(0, audio_device_->InitRecording()); | |
568 SleepMs(50); | |
569 EXPECT_TRUE(audio_device_->RecordingIsInitialized()); | |
570 } | |
571 | |
572 int16_t no_devices = audio_device_->RecordingDevices(); | |
573 for (int i = 0; i < no_devices; i++) { | |
574 EXPECT_EQ(0, audio_device_->RecordingIsAvailable(&available)); | |
575 if (available) { | |
576 EXPECT_EQ(0, audio_device_->StopRecording()); | |
577 EXPECT_FALSE(audio_device_->RecordingIsInitialized()); | |
578 EXPECT_EQ(0, audio_device_->SetRecordingDevice(i)); | |
579 EXPECT_EQ(0, audio_device_->RecordingIsAvailable(&available)); | |
580 if (available) { | |
581 EXPECT_EQ(0, audio_device_->InitRecording()); | |
582 EXPECT_TRUE(audio_device_->RecordingIsInitialized()); | |
583 } | |
584 } | |
585 } | |
586 EXPECT_EQ(0, audio_device_->StopRecording()); | |
587 } | |
588 | |
589 TEST_F(AudioDeviceAPITest, StartAndStopPlayout) { | |
590 bool available; | |
591 EXPECT_EQ(0, audio_device_->RegisterAudioCallback(NULL)); | |
592 | |
593 CheckInitialPlayoutStates(); | |
594 | |
595 EXPECT_EQ(-1, audio_device_->StartPlayout()); | |
596 EXPECT_EQ(0, audio_device_->StopPlayout()); | |
597 | |
598 #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) | |
599 // kDefaultCommunicationDevice | |
600 EXPECT_TRUE(audio_device_->SetPlayoutDevice( | |
601 AudioDeviceModule::kDefaultCommunicationDevice) == 0); | |
602 EXPECT_EQ(0, audio_device_->PlayoutIsAvailable(&available)); | |
603 if (available) | |
604 { | |
605 EXPECT_FALSE(audio_device_->PlayoutIsInitialized()); | |
606 EXPECT_EQ(0, audio_device_->InitPlayout()); | |
607 EXPECT_EQ(0, audio_device_->StartPlayout()); | |
608 EXPECT_TRUE(audio_device_->Playing()); | |
609 EXPECT_EQ(-1, audio_device_->RegisterAudioCallback(audio_transport_)); | |
610 EXPECT_EQ(0, audio_device_->StopPlayout()); | |
611 EXPECT_FALSE(audio_device_->Playing()); | |
612 EXPECT_EQ(0, audio_device_->RegisterAudioCallback(NULL)); | |
613 } | |
614 #endif | |
615 | |
616 // repeat test but for kDefaultDevice | |
617 EXPECT_EQ(0, audio_device_->SetPlayoutDevice(MACRO_DEFAULT_DEVICE)); | |
618 EXPECT_EQ(0, audio_device_->PlayoutIsAvailable(&available)); | |
619 if (available) { | |
620 EXPECT_FALSE(audio_device_->PlayoutIsInitialized()); | |
621 EXPECT_EQ(0, audio_device_->InitPlayout()); | |
622 EXPECT_EQ(0, audio_device_->StartPlayout()); | |
623 EXPECT_TRUE(audio_device_->Playing()); | |
624 EXPECT_EQ(-1, audio_device_->RegisterAudioCallback(audio_transport_)); | |
625 EXPECT_EQ(0, audio_device_->StopPlayout()); | |
626 EXPECT_FALSE(audio_device_->Playing()); | |
627 EXPECT_EQ(0, audio_device_->RegisterAudioCallback(NULL)); | |
628 } | |
629 | |
630 // repeat test for all devices | |
631 int16_t no_devices = audio_device_->PlayoutDevices(); | |
632 for (int i = 0; i < no_devices; i++) { | |
633 EXPECT_EQ(0, audio_device_->SetPlayoutDevice(i)); | |
634 EXPECT_EQ(0, audio_device_->PlayoutIsAvailable(&available)); | |
635 if (available) { | |
636 EXPECT_FALSE(audio_device_->PlayoutIsInitialized()); | |
637 EXPECT_EQ(0, audio_device_->InitPlayout()); | |
638 EXPECT_EQ(0, audio_device_->StartPlayout()); | |
639 EXPECT_TRUE(audio_device_->Playing()); | |
640 EXPECT_EQ(-1, audio_device_->RegisterAudioCallback(audio_transport_)); | |
641 EXPECT_EQ(0, audio_device_->StopPlayout()); | |
642 EXPECT_FALSE(audio_device_->Playing()); | |
643 EXPECT_EQ(0, audio_device_->RegisterAudioCallback(NULL)); | |
644 } | |
645 } | |
646 } | |
647 | |
648 TEST_F(AudioDeviceAPITest, StartAndStopRecording) { | |
649 bool available; | |
650 EXPECT_EQ(0, audio_device_->RegisterAudioCallback(NULL)); | |
651 | |
652 CheckInitialRecordingStates(); | |
653 | |
654 EXPECT_EQ(-1, audio_device_->StartRecording()); | |
655 EXPECT_EQ(0, audio_device_->StopRecording()); | |
656 | |
657 #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) | |
658 // kDefaultCommunicationDevice | |
659 EXPECT_TRUE(audio_device_->SetRecordingDevice( | |
660 AudioDeviceModule::kDefaultCommunicationDevice) == 0); | |
661 EXPECT_EQ(0, audio_device_->RecordingIsAvailable(&available)); | |
662 if (available) | |
663 { | |
664 EXPECT_FALSE(audio_device_->RecordingIsInitialized()); | |
665 EXPECT_EQ(0, audio_device_->InitRecording()); | |
666 EXPECT_EQ(0, audio_device_->StartRecording()); | |
667 EXPECT_TRUE(audio_device_->Recording()); | |
668 EXPECT_EQ(-1, audio_device_->RegisterAudioCallback(audio_transport_)); | |
669 EXPECT_EQ(0, audio_device_->StopRecording()); | |
670 EXPECT_FALSE(audio_device_->Recording()); | |
671 EXPECT_EQ(0, audio_device_->RegisterAudioCallback(NULL)); | |
672 } | |
673 #endif | |
674 | |
675 // repeat test but for kDefaultDevice | |
676 EXPECT_EQ(0, audio_device_->SetRecordingDevice(MACRO_DEFAULT_DEVICE)); | |
677 EXPECT_EQ(0, audio_device_->RecordingIsAvailable(&available)); | |
678 if (available) { | |
679 EXPECT_FALSE(audio_device_->RecordingIsInitialized()); | |
680 EXPECT_EQ(0, audio_device_->InitRecording()); | |
681 EXPECT_EQ(0, audio_device_->StartRecording()); | |
682 EXPECT_TRUE(audio_device_->Recording()); | |
683 EXPECT_EQ(-1, audio_device_->RegisterAudioCallback(audio_transport_)); | |
684 EXPECT_EQ(0, audio_device_->StopRecording()); | |
685 EXPECT_FALSE(audio_device_->Recording()); | |
686 EXPECT_EQ(0, audio_device_->RegisterAudioCallback(NULL)); | |
687 } | |
688 | |
689 // repeat test for all devices | |
690 int16_t no_devices = audio_device_->RecordingDevices(); | |
691 for (int i = 0; i < no_devices; i++) { | |
692 EXPECT_EQ(0, audio_device_->SetRecordingDevice(i)); | |
693 EXPECT_EQ(0, audio_device_->RecordingIsAvailable(&available)); | |
694 if (available) { | |
695 EXPECT_FALSE(audio_device_->RecordingIsInitialized()); | |
696 EXPECT_EQ(0, audio_device_->InitRecording()); | |
697 EXPECT_EQ(0, audio_device_->StartRecording()); | |
698 EXPECT_TRUE(audio_device_->Recording()); | |
699 EXPECT_EQ(-1, audio_device_->RegisterAudioCallback(audio_transport_)); | |
700 EXPECT_EQ(0, audio_device_->StopRecording()); | |
701 EXPECT_FALSE(audio_device_->Recording()); | |
702 EXPECT_EQ(0, audio_device_->RegisterAudioCallback(NULL)); | |
703 } | |
704 } | |
705 } | |
706 | |
707 | |
708 TEST_F(AudioDeviceAPITest, InitSpeaker) { | |
709 // NOTE: By calling Terminate (in TearDown) followed by Init (in SetUp) we | |
710 // ensure that any existing output mixer handle is set to NULL. | |
711 // The mixer handle is closed and reopened again for each call to | |
712 // SetPlayoutDevice. | |
713 CheckInitialPlayoutStates(); | |
714 | |
715 // kDefaultCommunicationDevice | |
716 EXPECT_EQ(0, audio_device_->SetPlayoutDevice( | |
717 MACRO_DEFAULT_COMMUNICATION_DEVICE)); | |
718 EXPECT_EQ(0, audio_device_->InitSpeaker()); | |
719 | |
720 // fail tests | |
721 bool available; | |
722 EXPECT_EQ(0, audio_device_->PlayoutIsAvailable(&available)); | |
723 if (available) { | |
724 EXPECT_EQ(0, audio_device_->InitPlayout()); | |
725 EXPECT_EQ(0, audio_device_->StartPlayout()); | |
726 EXPECT_EQ(-1, audio_device_->InitSpeaker()); | |
727 EXPECT_EQ(0, audio_device_->StopPlayout()); | |
728 } | |
729 | |
730 // kDefaultDevice | |
731 EXPECT_EQ(0, audio_device_->SetPlayoutDevice(MACRO_DEFAULT_DEVICE)); | |
732 EXPECT_EQ(0, audio_device_->InitSpeaker()); | |
733 | |
734 // repeat test for all devices | |
735 int16_t no_devices = audio_device_->PlayoutDevices(); | |
736 for (int i = 0; i < no_devices; i++) { | |
737 EXPECT_EQ(0, audio_device_->SetPlayoutDevice(i)); | |
738 EXPECT_EQ(0, audio_device_->InitSpeaker()); | |
739 } | |
740 } | |
741 | |
742 TEST_F(AudioDeviceAPITest, InitMicrophone) { | |
743 // NOTE: By calling Terminate (in TearDown) followed by Init (in SetUp) we | |
744 // ensure that any existing output mixer handle is set to NULL. | |
745 // The mixer handle is closed and reopened again for each call to | |
746 // SetRecordingDevice. | |
747 CheckInitialRecordingStates(); | |
748 | |
749 // kDefaultCommunicationDevice | |
750 EXPECT_EQ(0, | |
751 audio_device_->SetRecordingDevice(MACRO_DEFAULT_COMMUNICATION_DEVICE)); | |
752 EXPECT_EQ(0, audio_device_->InitMicrophone()); | |
753 | |
754 // fail tests | |
755 bool available; | |
756 EXPECT_EQ(0, audio_device_->RecordingIsAvailable(&available)); | |
757 if (available) { | |
758 EXPECT_EQ(0, audio_device_->InitRecording()); | |
759 EXPECT_EQ(0, audio_device_->StartRecording()); | |
760 EXPECT_EQ(-1, audio_device_->InitMicrophone()); | |
761 EXPECT_EQ(0, audio_device_->StopRecording()); | |
762 } | |
763 | |
764 // kDefaultDevice | |
765 EXPECT_EQ(0, audio_device_->SetRecordingDevice(MACRO_DEFAULT_DEVICE)); | |
766 EXPECT_EQ(0, audio_device_->InitMicrophone()); | |
767 | |
768 // repeat test for all devices | |
769 int16_t no_devices = audio_device_->RecordingDevices(); | |
770 for (int i = 0; i < no_devices; i++) { | |
771 EXPECT_EQ(0, audio_device_->SetRecordingDevice(i)); | |
772 EXPECT_EQ(0, audio_device_->InitMicrophone()); | |
773 } | |
774 } | |
775 | |
776 TEST_F(AudioDeviceAPITest, SpeakerVolumeIsAvailable) { | |
777 CheckInitialPlayoutStates(); | |
778 bool available; | |
779 | |
780 #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) | |
781 // check the kDefaultCommunicationDevice | |
782 EXPECT_TRUE(audio_device_->SetPlayoutDevice( | |
783 AudioDeviceModule::kDefaultCommunicationDevice) == 0); | |
784 EXPECT_EQ(0, audio_device_->SpeakerVolumeIsAvailable(&available)); | |
785 // check for availability should not lead to initialization | |
786 EXPECT_FALSE(audio_device_->SpeakerIsInitialized()); | |
787 #endif | |
788 | |
789 // check the kDefaultDevice | |
790 EXPECT_EQ(0, audio_device_->SetPlayoutDevice(MACRO_DEFAULT_DEVICE)); | |
791 EXPECT_EQ(0, audio_device_->SpeakerVolumeIsAvailable(&available)); | |
792 EXPECT_FALSE(audio_device_->SpeakerIsInitialized()); | |
793 | |
794 // check all availiable devices | |
795 int16_t no_devices = audio_device_->PlayoutDevices(); | |
796 for (int i = 0; i < no_devices; i++) { | |
797 EXPECT_EQ(0, audio_device_->SetPlayoutDevice(i)); | |
798 EXPECT_EQ(0, audio_device_->SpeakerVolumeIsAvailable(&available)); | |
799 EXPECT_FALSE(audio_device_->SpeakerIsInitialized()); | |
800 } | |
801 } | |
802 | |
803 // Tests the following methods: | |
804 // SetSpeakerVolume | |
805 // SpeakerVolume | |
806 // MaxSpeakerVolume | |
807 // MinSpeakerVolume | |
808 // NOTE: Disabled on mac due to issue 257. | |
809 #ifndef WEBRTC_MAC | |
810 TEST_F(AudioDeviceAPITest, SpeakerVolumeTests) { | |
811 uint32_t vol(0); | |
812 uint32_t volume(0); | |
813 uint32_t maxVolume(0); | |
814 uint32_t minVolume(0); | |
815 uint16_t stepSize(0); | |
816 bool available; | |
817 CheckInitialPlayoutStates(); | |
818 | |
819 // fail tests | |
820 EXPECT_EQ(-1, audio_device_->SetSpeakerVolume(0)); | |
821 // speaker must be initialized first | |
822 EXPECT_EQ(-1, audio_device_->SpeakerVolume(&volume)); | |
823 EXPECT_EQ(-1, audio_device_->MaxSpeakerVolume(&maxVolume)); | |
824 EXPECT_EQ(-1, audio_device_->MinSpeakerVolume(&minVolume)); | |
825 EXPECT_EQ(-1, audio_device_->SpeakerVolumeStepSize(&stepSize)); | |
826 | |
827 #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) | |
828 // use kDefaultCommunicationDevice and modify/retrieve the volume | |
829 EXPECT_TRUE(audio_device_->SetPlayoutDevice( | |
830 AudioDeviceModule::kDefaultCommunicationDevice) == 0); | |
831 EXPECT_EQ(0, audio_device_->SpeakerVolumeIsAvailable(&available)); | |
832 if (available) { | |
833 EXPECT_EQ(0, audio_device_->InitSpeaker()); | |
834 EXPECT_EQ(0, audio_device_->MaxSpeakerVolume(&maxVolume)); | |
835 EXPECT_EQ(0, audio_device_->MinSpeakerVolume(&minVolume)); | |
836 EXPECT_EQ(0, audio_device_->SpeakerVolumeStepSize(&stepSize)); | |
837 for (vol = minVolume; vol < (unsigned int)maxVolume; vol += 20*stepSize) { | |
838 EXPECT_EQ(0, audio_device_->SetSpeakerVolume(vol)); | |
839 EXPECT_EQ(0, audio_device_->SpeakerVolume(&volume)); | |
840 CheckVolume(volume, vol); | |
841 } | |
842 } | |
843 #endif | |
844 | |
845 // use kDefaultDevice and modify/retrieve the volume | |
846 EXPECT_EQ(0, audio_device_->SetPlayoutDevice(MACRO_DEFAULT_DEVICE)); | |
847 EXPECT_EQ(0, audio_device_->SpeakerVolumeIsAvailable(&available)); | |
848 if (available) { | |
849 EXPECT_EQ(0, audio_device_->InitSpeaker()); | |
850 EXPECT_EQ(0, audio_device_->MaxSpeakerVolume(&maxVolume)); | |
851 EXPECT_EQ(0, audio_device_->MinSpeakerVolume(&minVolume)); | |
852 EXPECT_EQ(0, audio_device_->SpeakerVolumeStepSize(&stepSize)); | |
853 uint32_t step = (maxVolume - minVolume) / 10; | |
854 step = (step < stepSize ? stepSize : step); | |
855 for (vol = minVolume; vol <= maxVolume; vol += step) { | |
856 EXPECT_EQ(0, audio_device_->SetSpeakerVolume(vol)); | |
857 EXPECT_EQ(0, audio_device_->SpeakerVolume(&volume)); | |
858 CheckVolume(volume, vol); | |
859 } | |
860 } | |
861 | |
862 // use all (indexed) devices and modify/retrieve the volume | |
863 int16_t no_devices = audio_device_->PlayoutDevices(); | |
864 for (int i = 0; i < no_devices; i++) { | |
865 EXPECT_EQ(0, audio_device_->SetPlayoutDevice(i)); | |
866 EXPECT_EQ(0, audio_device_->SpeakerVolumeIsAvailable(&available)); | |
867 if (available) { | |
868 EXPECT_EQ(0, audio_device_->InitSpeaker()); | |
869 EXPECT_EQ(0, audio_device_->MaxSpeakerVolume(&maxVolume)); | |
870 EXPECT_EQ(0, audio_device_->MinSpeakerVolume(&minVolume)); | |
871 EXPECT_EQ(0, audio_device_->SpeakerVolumeStepSize(&stepSize)); | |
872 uint32_t step = (maxVolume - minVolume) / 10; | |
873 step = (step < stepSize ? stepSize : step); | |
874 for (vol = minVolume; vol <= maxVolume; vol += step) { | |
875 EXPECT_EQ(0, audio_device_->SetSpeakerVolume(vol)); | |
876 EXPECT_EQ(0, audio_device_->SpeakerVolume(&volume)); | |
877 CheckVolume(volume, vol); | |
878 } | |
879 } | |
880 } | |
881 | |
882 // restore reasonable level | |
883 EXPECT_EQ(0, audio_device_->SetPlayoutDevice(MACRO_DEFAULT_DEVICE)); | |
884 EXPECT_EQ(0, audio_device_->SpeakerVolumeIsAvailable(&available)); | |
885 if (available) { | |
886 EXPECT_EQ(0, audio_device_->InitSpeaker()); | |
887 EXPECT_EQ(0, audio_device_->MaxSpeakerVolume(&maxVolume)); | |
888 EXPECT_TRUE(audio_device_->SetSpeakerVolume(maxVolume < 10 ? | |
889 maxVolume/3 : maxVolume/10) == 0); | |
890 } | |
891 } | |
892 #endif // !WEBRTC_MAC | |
893 | |
894 TEST_F(AudioDeviceAPITest, AGC) { | |
895 // NOTE: The AGC API only enables/disables the AGC. To ensure that it will | |
896 // have an effect, use it in combination with MicrophoneVolumeIsAvailable. | |
897 CheckInitialRecordingStates(); | |
898 EXPECT_FALSE(audio_device_->AGC()); | |
899 | |
900 // set/get tests | |
901 EXPECT_EQ(0, audio_device_->SetAGC(true)); | |
902 EXPECT_TRUE(audio_device_->AGC()); | |
903 EXPECT_EQ(0, audio_device_->SetAGC(false)); | |
904 EXPECT_FALSE(audio_device_->AGC()); | |
905 } | |
906 | |
907 TEST_F(AudioDeviceAPITest, MicrophoneVolumeIsAvailable) { | |
908 CheckInitialRecordingStates(); | |
909 bool available; | |
910 | |
911 #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) | |
912 // check the kDefaultCommunicationDevice | |
913 EXPECT_TRUE(audio_device_->SetRecordingDevice( | |
914 AudioDeviceModule::kDefaultCommunicationDevice) == 0); | |
915 EXPECT_EQ(0, audio_device_->MicrophoneVolumeIsAvailable(&available)); | |
916 // check for availability should not lead to initialization | |
917 EXPECT_FALSE(audio_device_->MicrophoneIsInitialized()); | |
918 #endif | |
919 | |
920 // check the kDefaultDevice | |
921 EXPECT_EQ(0, audio_device_->SetRecordingDevice(MACRO_DEFAULT_DEVICE)); | |
922 EXPECT_EQ(0, audio_device_->MicrophoneVolumeIsAvailable(&available)); | |
923 EXPECT_FALSE(audio_device_->MicrophoneIsInitialized()); | |
924 | |
925 // check all availiable devices | |
926 int16_t no_devices = audio_device_->RecordingDevices(); | |
927 for (int i = 0; i < no_devices; i++) { | |
928 EXPECT_EQ(0, audio_device_->SetRecordingDevice(i)); | |
929 EXPECT_EQ(0, audio_device_->MicrophoneVolumeIsAvailable(&available)); | |
930 EXPECT_FALSE(audio_device_->MicrophoneIsInitialized()); | |
931 } | |
932 } | |
933 | |
934 // Tests the methods: | |
935 // SetMicrophoneVolume | |
936 // MicrophoneVolume | |
937 // MaxMicrophoneVolume | |
938 // MinMicrophoneVolume | |
939 | |
940 // Disabled on Mac and Linux, | |
941 // see https://bugs.chromium.org/p/webrtc/issues/detail?id=5414 | |
942 #if defined(WEBRTC_MAC) || defined(WEBRTC_LINUX) | |
943 #define MAYBE_MicrophoneVolumeTests DISABLED_MicrophoneVolumeTests | |
944 #else | |
945 #define MAYBE_MicrophoneVolumeTests MicrophoneVolumeTests | |
946 #endif | |
947 TEST_F(AudioDeviceAPITest, MAYBE_MicrophoneVolumeTests) { | |
948 uint32_t vol(0); | |
949 uint32_t volume(0); | |
950 uint32_t maxVolume(0); | |
951 uint32_t minVolume(0); | |
952 uint16_t stepSize(0); | |
953 bool available; | |
954 CheckInitialRecordingStates(); | |
955 | |
956 // fail tests | |
957 EXPECT_EQ(-1, audio_device_->SetMicrophoneVolume(0)); | |
958 // must be initialized first | |
959 EXPECT_EQ(-1, audio_device_->MicrophoneVolume(&volume)); | |
960 EXPECT_EQ(-1, audio_device_->MaxMicrophoneVolume(&maxVolume)); | |
961 EXPECT_EQ(-1, audio_device_->MinMicrophoneVolume(&minVolume)); | |
962 EXPECT_EQ(-1, audio_device_->MicrophoneVolumeStepSize(&stepSize)); | |
963 | |
964 #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) | |
965 // initialize kDefaultCommunicationDevice and modify/retrieve the volume | |
966 EXPECT_TRUE(audio_device_->SetRecordingDevice( | |
967 AudioDeviceModule::kDefaultCommunicationDevice) == 0); | |
968 EXPECT_EQ(0, audio_device_->MicrophoneVolumeIsAvailable(&available)); | |
969 if (available) | |
970 { | |
971 EXPECT_EQ(0, audio_device_->InitMicrophone()); | |
972 EXPECT_EQ(0, audio_device_->MaxMicrophoneVolume(&maxVolume)); | |
973 EXPECT_EQ(0, audio_device_->MinMicrophoneVolume(&minVolume)); | |
974 EXPECT_EQ(0, audio_device_->MicrophoneVolumeStepSize(&stepSize)); | |
975 for (vol = minVolume; vol < (unsigned int)maxVolume; vol += 10*stepSize) | |
976 { | |
977 EXPECT_EQ(0, audio_device_->SetMicrophoneVolume(vol)); | |
978 EXPECT_EQ(0, audio_device_->MicrophoneVolume(&volume)); | |
979 CheckVolume(volume, vol); | |
980 } | |
981 } | |
982 #endif | |
983 | |
984 // reinitialize kDefaultDevice and modify/retrieve the volume | |
985 EXPECT_EQ(0, audio_device_->SetRecordingDevice(MACRO_DEFAULT_DEVICE)); | |
986 EXPECT_EQ(0, audio_device_->MicrophoneVolumeIsAvailable(&available)); | |
987 if (available) { | |
988 EXPECT_EQ(0, audio_device_->InitMicrophone()); | |
989 EXPECT_EQ(0, audio_device_->MaxMicrophoneVolume(&maxVolume)); | |
990 EXPECT_EQ(0, audio_device_->MinMicrophoneVolume(&minVolume)); | |
991 EXPECT_EQ(0, audio_device_->MicrophoneVolumeStepSize(&stepSize)); | |
992 for (vol = minVolume; vol < maxVolume; vol += 10 * stepSize) { | |
993 EXPECT_EQ(0, audio_device_->SetMicrophoneVolume(vol)); | |
994 EXPECT_EQ(0, audio_device_->MicrophoneVolume(&volume)); | |
995 CheckVolume(volume, vol); | |
996 } | |
997 } | |
998 | |
999 // use all (indexed) devices and modify/retrieve the volume | |
1000 int16_t no_devices = audio_device_->RecordingDevices(); | |
1001 for (int i = 0; i < no_devices; i++) { | |
1002 EXPECT_EQ(0, audio_device_->SetRecordingDevice(i)); | |
1003 EXPECT_EQ(0, audio_device_->MicrophoneVolumeIsAvailable(&available)); | |
1004 if (available) { | |
1005 EXPECT_EQ(0, audio_device_->InitMicrophone()); | |
1006 EXPECT_EQ(0, audio_device_->MaxMicrophoneVolume(&maxVolume)); | |
1007 EXPECT_EQ(0, audio_device_->MinMicrophoneVolume(&minVolume)); | |
1008 EXPECT_EQ(0, audio_device_->MicrophoneVolumeStepSize(&stepSize)); | |
1009 for (vol = minVolume; vol < maxVolume; vol += 20 * stepSize) { | |
1010 EXPECT_EQ(0, audio_device_->SetMicrophoneVolume(vol)); | |
1011 EXPECT_EQ(0, audio_device_->MicrophoneVolume(&volume)); | |
1012 CheckVolume(volume, vol); | |
1013 } | |
1014 } | |
1015 } | |
1016 | |
1017 // restore reasonable level | |
1018 EXPECT_EQ(0, audio_device_->SetRecordingDevice(MACRO_DEFAULT_DEVICE)); | |
1019 EXPECT_EQ(0, audio_device_->MicrophoneVolumeIsAvailable(&available)); | |
1020 if (available) { | |
1021 EXPECT_EQ(0, audio_device_->InitMicrophone()); | |
1022 EXPECT_EQ(0, audio_device_->MaxMicrophoneVolume(&maxVolume)); | |
1023 EXPECT_EQ(0, audio_device_->SetMicrophoneVolume(maxVolume/10)); | |
1024 } | |
1025 } | |
1026 | |
1027 TEST_F(AudioDeviceAPITest, SpeakerMuteIsAvailable) { | |
1028 bool available; | |
1029 CheckInitialPlayoutStates(); | |
1030 #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) | |
1031 // check the kDefaultCommunicationDevice | |
1032 EXPECT_TRUE(audio_device_->SetPlayoutDevice( | |
1033 AudioDeviceModule::kDefaultCommunicationDevice) == 0); | |
1034 EXPECT_EQ(0, audio_device_->SpeakerMuteIsAvailable(&available)); | |
1035 // check for availability should not lead to initialization | |
1036 EXPECT_FALSE(audio_device_->SpeakerIsInitialized()); | |
1037 #endif | |
1038 | |
1039 // check the kDefaultDevice | |
1040 EXPECT_EQ(0, audio_device_->SetPlayoutDevice(MACRO_DEFAULT_DEVICE)); | |
1041 EXPECT_EQ(0, audio_device_->SpeakerMuteIsAvailable(&available)); | |
1042 EXPECT_FALSE(audio_device_->SpeakerIsInitialized()); | |
1043 | |
1044 // check all availiable devices | |
1045 int16_t no_devices = audio_device_->PlayoutDevices(); | |
1046 for (int i = 0; i < no_devices; i++) { | |
1047 EXPECT_EQ(0, audio_device_->SetPlayoutDevice(i)); | |
1048 EXPECT_EQ(0, audio_device_->SpeakerMuteIsAvailable(&available)); | |
1049 EXPECT_FALSE(audio_device_->SpeakerIsInitialized()); | |
1050 } | |
1051 } | |
1052 | |
1053 TEST_F(AudioDeviceAPITest, MicrophoneMuteIsAvailable) { | |
1054 bool available; | |
1055 CheckInitialRecordingStates(); | |
1056 #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) | |
1057 // check the kDefaultCommunicationDevice | |
1058 EXPECT_TRUE(audio_device_->SetRecordingDevice( | |
1059 AudioDeviceModule::kDefaultCommunicationDevice) == 0); | |
1060 EXPECT_EQ(0, audio_device_->MicrophoneMuteIsAvailable(&available)); | |
1061 // check for availability should not lead to initialization | |
1062 #endif | |
1063 EXPECT_FALSE(audio_device_->MicrophoneIsInitialized()); | |
1064 | |
1065 // check the kDefaultDevice | |
1066 EXPECT_EQ(0, audio_device_->SetRecordingDevice(MACRO_DEFAULT_DEVICE)); | |
1067 EXPECT_EQ(0, audio_device_->MicrophoneMuteIsAvailable(&available)); | |
1068 EXPECT_FALSE(audio_device_->MicrophoneIsInitialized()); | |
1069 | |
1070 // check all availiable devices | |
1071 int16_t no_devices = audio_device_->RecordingDevices(); | |
1072 for (int i = 0; i < no_devices; i++) { | |
1073 EXPECT_EQ(0, audio_device_->SetRecordingDevice(i)); | |
1074 EXPECT_EQ(0, audio_device_->MicrophoneMuteIsAvailable(&available)); | |
1075 EXPECT_FALSE(audio_device_->MicrophoneIsInitialized()); | |
1076 } | |
1077 } | |
1078 | |
1079 TEST_F(AudioDeviceAPITest, MicrophoneBoostIsAvailable) { | |
1080 bool available; | |
1081 CheckInitialRecordingStates(); | |
1082 #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) | |
1083 // check the kDefaultCommunicationDevice | |
1084 EXPECT_TRUE(audio_device_->SetRecordingDevice( | |
1085 AudioDeviceModule::kDefaultCommunicationDevice) == 0); | |
1086 EXPECT_EQ(0, audio_device_->MicrophoneBoostIsAvailable(&available)); | |
1087 // check for availability should not lead to initialization | |
1088 EXPECT_FALSE(audio_device_->MicrophoneIsInitialized()); | |
1089 #endif | |
1090 | |
1091 // check the kDefaultDevice | |
1092 EXPECT_EQ(0, audio_device_->SetRecordingDevice(MACRO_DEFAULT_DEVICE)); | |
1093 EXPECT_EQ(0, audio_device_->MicrophoneBoostIsAvailable(&available)); | |
1094 EXPECT_FALSE(audio_device_->MicrophoneIsInitialized()); | |
1095 | |
1096 // check all availiable devices | |
1097 int16_t no_devices = audio_device_->RecordingDevices(); | |
1098 for (int i = 0; i < no_devices; i++) { | |
1099 EXPECT_EQ(0, audio_device_->SetRecordingDevice(i)); | |
1100 EXPECT_EQ(0, audio_device_->MicrophoneBoostIsAvailable(&available)); | |
1101 EXPECT_FALSE(audio_device_->MicrophoneIsInitialized()); | |
1102 } | |
1103 } | |
1104 | |
1105 TEST_F(AudioDeviceAPITest, SpeakerMuteTests) { | |
1106 bool available; | |
1107 bool enabled; | |
1108 CheckInitialPlayoutStates(); | |
1109 // fail tests | |
1110 EXPECT_EQ(-1, audio_device_->SetSpeakerMute(true)); | |
1111 // requires initialization | |
1112 EXPECT_EQ(-1, audio_device_->SpeakerMute(&enabled)); | |
1113 | |
1114 #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) | |
1115 // initialize kDefaultCommunicationDevice and modify/retrieve the mute state | |
1116 EXPECT_EQ(0, audio_device_->SetPlayoutDevice( | |
1117 AudioDeviceModule::kDefaultCommunicationDevice)); | |
1118 EXPECT_EQ(0, audio_device_->SpeakerMuteIsAvailable(&available)); | |
1119 if (available) | |
1120 { | |
1121 EXPECT_EQ(0, audio_device_->InitSpeaker()); | |
1122 EXPECT_EQ(0, audio_device_->SetSpeakerMute(true)); | |
1123 EXPECT_EQ(0, audio_device_->SpeakerMute(&enabled)); | |
1124 EXPECT_TRUE(enabled); | |
1125 EXPECT_EQ(0, audio_device_->SetSpeakerMute(false)); | |
1126 EXPECT_EQ(0, audio_device_->SpeakerMute(&enabled)); | |
1127 EXPECT_FALSE(enabled); | |
1128 } | |
1129 #endif | |
1130 | |
1131 // reinitialize kDefaultDevice and modify/retrieve the mute state | |
1132 EXPECT_EQ(0, audio_device_->SetPlayoutDevice(MACRO_DEFAULT_DEVICE)); | |
1133 EXPECT_EQ(0, audio_device_->SpeakerMuteIsAvailable(&available)); | |
1134 if (available) { | |
1135 EXPECT_EQ(0, audio_device_->InitSpeaker()); | |
1136 EXPECT_EQ(0, audio_device_->SetSpeakerMute(true)); | |
1137 EXPECT_EQ(0, audio_device_->SpeakerMute(&enabled)); | |
1138 EXPECT_TRUE(enabled); | |
1139 EXPECT_EQ(0, audio_device_->SetSpeakerMute(false)); | |
1140 EXPECT_EQ(0, audio_device_->SpeakerMute(&enabled)); | |
1141 EXPECT_FALSE(enabled); | |
1142 } | |
1143 | |
1144 // reinitialize the default device (0) and modify/retrieve the mute state | |
1145 EXPECT_EQ(0, audio_device_->SetPlayoutDevice(0)); | |
1146 EXPECT_EQ(0, audio_device_->SpeakerMuteIsAvailable(&available)); | |
1147 if (available) { | |
1148 EXPECT_EQ(0, audio_device_->InitSpeaker()); | |
1149 EXPECT_EQ(0, audio_device_->SetSpeakerMute(true)); | |
1150 EXPECT_EQ(0, audio_device_->SpeakerMute(&enabled)); | |
1151 EXPECT_TRUE(enabled); | |
1152 EXPECT_EQ(0, audio_device_->SetSpeakerMute(false)); | |
1153 EXPECT_EQ(0, audio_device_->SpeakerMute(&enabled)); | |
1154 EXPECT_FALSE(enabled); | |
1155 } | |
1156 } | |
1157 | |
1158 TEST_F(AudioDeviceAPITest, MicrophoneMuteTests) { | |
1159 CheckInitialRecordingStates(); | |
1160 | |
1161 // fail tests | |
1162 EXPECT_EQ(-1, audio_device_->SetMicrophoneMute(true)); | |
1163 // requires initialization | |
1164 bool available; | |
1165 bool enabled; | |
1166 EXPECT_EQ(-1, audio_device_->MicrophoneMute(&enabled)); | |
1167 | |
1168 #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) | |
1169 // initialize kDefaultCommunicationDevice and modify/retrieve the mute | |
1170 EXPECT_TRUE(audio_device_->SetRecordingDevice( | |
1171 AudioDeviceModule::kDefaultCommunicationDevice) == 0); | |
1172 EXPECT_EQ(0, audio_device_->MicrophoneMuteIsAvailable(&available)); | |
1173 if (available) | |
1174 { | |
1175 EXPECT_EQ(0, audio_device_->InitMicrophone()); | |
1176 EXPECT_EQ(0, audio_device_->SetMicrophoneMute(true)); | |
1177 EXPECT_EQ(0, audio_device_->MicrophoneMute(&enabled)); | |
1178 EXPECT_TRUE(enabled); | |
1179 EXPECT_EQ(0, audio_device_->SetMicrophoneMute(false)); | |
1180 EXPECT_EQ(0, audio_device_->MicrophoneMute(&enabled)); | |
1181 EXPECT_FALSE(enabled); | |
1182 } | |
1183 #endif | |
1184 | |
1185 // reinitialize kDefaultDevice and modify/retrieve the mute | |
1186 EXPECT_EQ(0, audio_device_->SetRecordingDevice(MACRO_DEFAULT_DEVICE)); | |
1187 EXPECT_EQ(0, audio_device_->MicrophoneMuteIsAvailable(&available)); | |
1188 if (available) { | |
1189 EXPECT_EQ(0, audio_device_->InitMicrophone()); | |
1190 EXPECT_EQ(0, audio_device_->SetMicrophoneMute(true)); | |
1191 EXPECT_EQ(0, audio_device_->MicrophoneMute(&enabled)); | |
1192 EXPECT_TRUE(enabled); | |
1193 EXPECT_EQ(0, audio_device_->SetMicrophoneMute(false)); | |
1194 EXPECT_EQ(0, audio_device_->MicrophoneMute(&enabled)); | |
1195 EXPECT_FALSE(enabled); | |
1196 } | |
1197 | |
1198 // reinitialize the default device (0) and modify/retrieve the Mute | |
1199 EXPECT_EQ(0, audio_device_->SetRecordingDevice(0)); | |
1200 EXPECT_EQ(0, audio_device_->MicrophoneMuteIsAvailable(&available)); | |
1201 if (available) { | |
1202 EXPECT_EQ(0, audio_device_->InitMicrophone()); | |
1203 EXPECT_EQ(0, audio_device_->SetMicrophoneMute(true)); | |
1204 EXPECT_EQ(0, audio_device_->MicrophoneMute(&enabled)); | |
1205 EXPECT_TRUE(enabled); | |
1206 EXPECT_EQ(0, audio_device_->SetMicrophoneMute(false)); | |
1207 EXPECT_EQ(0, audio_device_->MicrophoneMute(&enabled)); | |
1208 EXPECT_FALSE(enabled); | |
1209 } | |
1210 } | |
1211 | |
1212 TEST_F(AudioDeviceAPITest, MicrophoneBoostTests) { | |
1213 bool available; | |
1214 bool enabled; | |
1215 CheckInitialRecordingStates(); | |
1216 | |
1217 // fail tests | |
1218 EXPECT_EQ(-1, audio_device_->SetMicrophoneBoost(true)); | |
1219 // requires initialization | |
1220 EXPECT_EQ(-1, audio_device_->MicrophoneBoost(&enabled)); | |
1221 | |
1222 #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) | |
1223 // initialize kDefaultCommunicationDevice and modify/retrieve the boost | |
1224 EXPECT_TRUE(audio_device_->SetRecordingDevice( | |
1225 AudioDeviceModule::kDefaultCommunicationDevice) == 0); | |
1226 EXPECT_EQ(0, audio_device_->MicrophoneBoostIsAvailable(&available)); | |
1227 if (available) | |
1228 { | |
1229 EXPECT_EQ(0, audio_device_->InitMicrophone()); | |
1230 EXPECT_EQ(0, audio_device_->SetMicrophoneBoost(true)); | |
1231 EXPECT_EQ(0, audio_device_->MicrophoneBoost(&enabled)); | |
1232 EXPECT_TRUE(enabled); | |
1233 EXPECT_EQ(0, audio_device_->SetMicrophoneBoost(false)); | |
1234 EXPECT_EQ(0, audio_device_->MicrophoneBoost(&enabled)); | |
1235 EXPECT_FALSE(enabled); | |
1236 } | |
1237 #endif | |
1238 | |
1239 // reinitialize kDefaultDevice and modify/retrieve the boost | |
1240 EXPECT_EQ(0, audio_device_->SetRecordingDevice(MACRO_DEFAULT_DEVICE)); | |
1241 EXPECT_EQ(0, audio_device_->MicrophoneBoostIsAvailable(&available)); | |
1242 if (available) { | |
1243 EXPECT_EQ(0, audio_device_->InitMicrophone()); | |
1244 EXPECT_EQ(0, audio_device_->SetMicrophoneBoost(true)); | |
1245 EXPECT_EQ(0, audio_device_->MicrophoneBoost(&enabled)); | |
1246 EXPECT_TRUE(enabled); | |
1247 EXPECT_EQ(0, audio_device_->SetMicrophoneBoost(false)); | |
1248 EXPECT_EQ(0, audio_device_->MicrophoneBoost(&enabled)); | |
1249 EXPECT_FALSE(enabled); | |
1250 } | |
1251 | |
1252 // reinitialize the default device (0) and modify/retrieve the boost | |
1253 EXPECT_EQ(0, audio_device_->SetRecordingDevice(0)); | |
1254 EXPECT_EQ(0, audio_device_->MicrophoneBoostIsAvailable(&available)); | |
1255 if (available) { | |
1256 EXPECT_EQ(0, audio_device_->InitMicrophone()); | |
1257 EXPECT_EQ(0, audio_device_->SetMicrophoneBoost(true)); | |
1258 EXPECT_EQ(0, audio_device_->MicrophoneBoost(&enabled)); | |
1259 EXPECT_TRUE(enabled); | |
1260 EXPECT_EQ(0, audio_device_->SetMicrophoneBoost(false)); | |
1261 EXPECT_EQ(0, audio_device_->MicrophoneBoost(&enabled)); | |
1262 EXPECT_FALSE(enabled); | |
1263 } | |
1264 } | |
1265 | |
1266 TEST_F(AudioDeviceAPITest, StereoPlayoutTests) { | |
1267 CheckInitialPlayoutStates(); | |
1268 | |
1269 // fail tests | |
1270 EXPECT_EQ(-1, audio_device_->InitPlayout()); | |
1271 EXPECT_EQ(0, audio_device_->SetPlayoutDevice( | |
1272 MACRO_DEFAULT_COMMUNICATION_DEVICE)); | |
1273 | |
1274 // TODO(kjellander): Fix so these tests pass on Mac. | |
1275 #if !defined(WEBRTC_MAC) | |
1276 EXPECT_EQ(0, audio_device_->InitPlayout()); | |
1277 EXPECT_TRUE(audio_device_->PlayoutIsInitialized()); | |
1278 // must be performed before initialization | |
1279 EXPECT_EQ(-1, audio_device_->SetStereoPlayout(true)); | |
1280 #endif | |
1281 | |
1282 // ensure that we can set the stereo mode for playout | |
1283 EXPECT_EQ(0, audio_device_->StopPlayout()); | |
1284 EXPECT_FALSE(audio_device_->PlayoutIsInitialized()); | |
1285 | |
1286 // initialize kDefaultCommunicationDevice and modify/retrieve stereo support | |
1287 EXPECT_EQ(0, audio_device_->SetPlayoutDevice( | |
1288 MACRO_DEFAULT_COMMUNICATION_DEVICE)); | |
1289 bool available; | |
1290 bool enabled; | |
1291 EXPECT_EQ(0, audio_device_->StereoPlayoutIsAvailable(&available)); | |
1292 if (available) { | |
1293 EXPECT_EQ(0, audio_device_->SetStereoPlayout(true)); | |
1294 EXPECT_EQ(0, audio_device_->StereoPlayout(&enabled)); | |
1295 EXPECT_TRUE(enabled); | |
1296 EXPECT_EQ(0, audio_device_->SetStereoPlayout(false)); | |
1297 EXPECT_EQ(0, audio_device_->StereoPlayout(&enabled)); | |
1298 EXPECT_FALSE(enabled); | |
1299 EXPECT_EQ(0, audio_device_->SetStereoPlayout(true)); | |
1300 EXPECT_EQ(0, audio_device_->StereoPlayout(&enabled)); | |
1301 EXPECT_TRUE(enabled); | |
1302 } | |
1303 | |
1304 // initialize kDefaultDevice and modify/retrieve stereo support | |
1305 EXPECT_EQ(0, audio_device_->SetPlayoutDevice(MACRO_DEFAULT_DEVICE)); | |
1306 EXPECT_EQ(0, audio_device_->StereoPlayoutIsAvailable(&available)); | |
1307 if (available) { | |
1308 EXPECT_EQ(0, audio_device_->SetStereoPlayout(true)); | |
1309 EXPECT_EQ(0, audio_device_->StereoPlayout(&enabled)); | |
1310 EXPECT_TRUE(enabled); | |
1311 EXPECT_EQ(0, audio_device_->SetStereoPlayout(false)); | |
1312 EXPECT_EQ(0, audio_device_->StereoPlayout(&enabled)); | |
1313 EXPECT_FALSE(enabled); | |
1314 EXPECT_EQ(0, audio_device_->SetStereoPlayout(true)); | |
1315 EXPECT_EQ(0, audio_device_->StereoPlayout(&enabled)); | |
1316 EXPECT_TRUE(enabled); | |
1317 } | |
1318 | |
1319 // initialize default device (0) and modify/retrieve stereo support | |
1320 EXPECT_EQ(0, audio_device_->SetPlayoutDevice(0)); | |
1321 EXPECT_EQ(0, audio_device_->StereoPlayoutIsAvailable(&available)); | |
1322 if (available) { | |
1323 EXPECT_EQ(0, audio_device_->SetStereoPlayout(true)); | |
1324 EXPECT_EQ(0, audio_device_->StereoPlayout(&enabled)); | |
1325 EXPECT_TRUE(enabled); | |
1326 EXPECT_EQ(0, audio_device_->SetStereoPlayout(false)); | |
1327 EXPECT_EQ(0, audio_device_->StereoPlayout(&enabled)); | |
1328 EXPECT_FALSE(enabled); | |
1329 EXPECT_EQ(0, audio_device_->SetStereoPlayout(true)); | |
1330 EXPECT_EQ(0, audio_device_->StereoPlayout(&enabled)); | |
1331 EXPECT_TRUE(enabled); | |
1332 } | |
1333 } | |
1334 | |
1335 TEST_F(AudioDeviceAPITest, StereoRecordingTests) { | |
1336 CheckInitialRecordingStates(); | |
1337 EXPECT_FALSE(audio_device_->Playing()); | |
1338 | |
1339 // fail tests | |
1340 EXPECT_EQ(-1, audio_device_->InitRecording()); | |
1341 EXPECT_EQ(0, audio_device_->SetRecordingDevice( | |
1342 MACRO_DEFAULT_COMMUNICATION_DEVICE)); | |
1343 | |
1344 // TODO(kjellander): Fix so these tests pass on Mac. | |
1345 #if !defined(WEBRTC_MAC) | |
1346 EXPECT_EQ(0, audio_device_->InitRecording()); | |
1347 EXPECT_TRUE(audio_device_->RecordingIsInitialized()); | |
1348 // must be performed before initialization | |
1349 EXPECT_EQ(-1, audio_device_->SetStereoRecording(true)); | |
1350 #endif | |
1351 // ensures that we can set the stereo mode for recording | |
1352 EXPECT_EQ(0, audio_device_->StopRecording()); | |
1353 EXPECT_FALSE(audio_device_->RecordingIsInitialized()); | |
1354 | |
1355 // initialize kDefaultCommunicationDevice and modify/retrieve stereo support | |
1356 EXPECT_EQ(0, audio_device_->SetRecordingDevice( | |
1357 MACRO_DEFAULT_COMMUNICATION_DEVICE)); | |
1358 bool available; | |
1359 bool enabled; | |
1360 EXPECT_EQ(0, audio_device_->StereoRecordingIsAvailable(&available)); | |
1361 if (available) { | |
1362 EXPECT_EQ(0, audio_device_->SetStereoRecording(true)); | |
1363 EXPECT_EQ(0, audio_device_->StereoRecording(&enabled)); | |
1364 EXPECT_TRUE(enabled); | |
1365 EXPECT_EQ(0, audio_device_->SetStereoRecording(false)); | |
1366 EXPECT_EQ(0, audio_device_->StereoRecording(&enabled)); | |
1367 EXPECT_FALSE(enabled); | |
1368 } | |
1369 | |
1370 // initialize kDefaultDevice and modify/retrieve stereo support | |
1371 EXPECT_EQ(0, audio_device_->SetRecordingDevice(MACRO_DEFAULT_DEVICE)); | |
1372 EXPECT_EQ(0, audio_device_->StereoRecordingIsAvailable(&available)); | |
1373 if (available) { | |
1374 EXPECT_EQ(0, audio_device_->SetStereoRecording(true)); | |
1375 EXPECT_EQ(0, audio_device_->StereoRecording(&enabled)); | |
1376 EXPECT_TRUE(enabled); | |
1377 EXPECT_EQ(0, audio_device_->SetStereoRecording(false)); | |
1378 EXPECT_EQ(0, audio_device_->StereoRecording(&enabled)); | |
1379 EXPECT_FALSE(enabled); | |
1380 } | |
1381 | |
1382 // initialize default device (0) and modify/retrieve stereo support | |
1383 EXPECT_EQ(0, audio_device_->SetRecordingDevice(0)); | |
1384 EXPECT_EQ(0, audio_device_->StereoRecordingIsAvailable(&available)); | |
1385 if (available) { | |
1386 EXPECT_EQ(0, audio_device_->SetStereoRecording(true)); | |
1387 EXPECT_EQ(0, audio_device_->StereoRecording(&enabled)); | |
1388 EXPECT_TRUE(enabled); | |
1389 EXPECT_EQ(0, audio_device_->SetStereoRecording(false)); | |
1390 EXPECT_EQ(0, audio_device_->StereoRecording(&enabled)); | |
1391 EXPECT_FALSE(enabled); | |
1392 } | |
1393 } | |
1394 | |
1395 TEST_F(AudioDeviceAPITest, PlayoutBufferTests) { | |
1396 AudioDeviceModule::BufferType bufferType; | |
1397 uint16_t sizeMS(0); | |
1398 | |
1399 CheckInitialPlayoutStates(); | |
1400 EXPECT_EQ(0, audio_device_->PlayoutBuffer(&bufferType, &sizeMS)); | |
1401 #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) || defined(ANDROID) || \ | |
1402 defined(WEBRTC_IOS) | |
1403 EXPECT_EQ(AudioDeviceModule::kAdaptiveBufferSize, bufferType); | |
1404 #else | |
1405 EXPECT_EQ(AudioDeviceModule::kFixedBufferSize, bufferType); | |
1406 #endif | |
1407 | |
1408 // fail tests | |
1409 EXPECT_EQ(-1, audio_device_->InitPlayout()); | |
1410 // must set device first | |
1411 EXPECT_EQ(0, audio_device_->SetPlayoutDevice( | |
1412 MACRO_DEFAULT_COMMUNICATION_DEVICE)); | |
1413 | |
1414 // TODO(kjellander): Fix so these tests pass on Mac. | |
1415 #if !defined(WEBRTC_MAC) | |
1416 EXPECT_EQ(0, audio_device_->InitPlayout()); | |
1417 EXPECT_TRUE(audio_device_->PlayoutIsInitialized()); | |
1418 #endif | |
1419 EXPECT_TRUE(audio_device_->SetPlayoutBuffer( | |
1420 AudioDeviceModule::kAdaptiveBufferSize, 100) == -1); | |
1421 EXPECT_EQ(0, audio_device_->StopPlayout()); | |
1422 EXPECT_TRUE(audio_device_->SetPlayoutBuffer( | |
1423 AudioDeviceModule::kFixedBufferSize, kAdmMinPlayoutBufferSizeMs-1) == -1); | |
1424 EXPECT_TRUE(audio_device_->SetPlayoutBuffer( | |
1425 AudioDeviceModule::kFixedBufferSize, kAdmMaxPlayoutBufferSizeMs+1) == -1); | |
1426 | |
1427 // bulk tests (all should be successful) | |
1428 EXPECT_FALSE(audio_device_->PlayoutIsInitialized()); | |
1429 #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) | |
1430 EXPECT_EQ(0, audio_device_->SetPlayoutBuffer( | |
1431 AudioDeviceModule::kAdaptiveBufferSize, 0)); | |
1432 EXPECT_EQ(0, audio_device_->PlayoutBuffer(&bufferType, &sizeMS)); | |
1433 EXPECT_EQ(AudioDeviceModule::kAdaptiveBufferSize, bufferType); | |
1434 EXPECT_EQ(0, audio_device_->SetPlayoutBuffer( | |
1435 AudioDeviceModule::kAdaptiveBufferSize, 10000)); | |
1436 EXPECT_EQ(0, audio_device_->PlayoutBuffer(&bufferType, &sizeMS)); | |
1437 EXPECT_EQ(AudioDeviceModule::kAdaptiveBufferSize, bufferType); | |
1438 #endif | |
1439 #if defined(ANDROID) || defined(WEBRTC_IOS) | |
1440 EXPECT_EQ(-1, | |
1441 audio_device_->SetPlayoutBuffer(AudioDeviceModule::kFixedBufferSize, | |
1442 kAdmMinPlayoutBufferSizeMs)); | |
1443 #else | |
1444 EXPECT_EQ(0, audio_device_->SetPlayoutBuffer( | |
1445 AudioDeviceModule::kFixedBufferSize, kAdmMinPlayoutBufferSizeMs)); | |
1446 EXPECT_EQ(0, audio_device_->PlayoutBuffer(&bufferType, &sizeMS)); | |
1447 EXPECT_EQ(AudioDeviceModule::kFixedBufferSize, bufferType); | |
1448 EXPECT_EQ(kAdmMinPlayoutBufferSizeMs, sizeMS); | |
1449 EXPECT_EQ(0, audio_device_->SetPlayoutBuffer( | |
1450 AudioDeviceModule::kFixedBufferSize, kAdmMaxPlayoutBufferSizeMs)); | |
1451 EXPECT_EQ(0, audio_device_->PlayoutBuffer(&bufferType, &sizeMS)); | |
1452 EXPECT_EQ(AudioDeviceModule::kFixedBufferSize, bufferType); | |
1453 EXPECT_EQ(kAdmMaxPlayoutBufferSizeMs, sizeMS); | |
1454 EXPECT_EQ(0, audio_device_->SetPlayoutBuffer( | |
1455 AudioDeviceModule::kFixedBufferSize, 100)); | |
1456 EXPECT_EQ(0, audio_device_->PlayoutBuffer(&bufferType, &sizeMS)); | |
1457 EXPECT_EQ(AudioDeviceModule::kFixedBufferSize, bufferType); | |
1458 EXPECT_EQ(100, sizeMS); | |
1459 #endif | |
1460 | |
1461 #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) | |
1462 // restore default | |
1463 EXPECT_EQ(0, audio_device_->SetPlayoutBuffer( | |
1464 AudioDeviceModule::kAdaptiveBufferSize, 0)); | |
1465 EXPECT_EQ(0, audio_device_->PlayoutBuffer(&bufferType, &sizeMS)); | |
1466 #endif | |
1467 } | |
1468 | |
1469 TEST_F(AudioDeviceAPITest, PlayoutDelay) { | |
1470 // NOTE: this API is better tested in a functional test | |
1471 uint16_t sizeMS(0); | |
1472 CheckInitialPlayoutStates(); | |
1473 // bulk tests | |
1474 EXPECT_EQ(0, audio_device_->PlayoutDelay(&sizeMS)); | |
1475 EXPECT_EQ(0, audio_device_->PlayoutDelay(&sizeMS)); | |
1476 } | |
1477 | |
1478 TEST_F(AudioDeviceAPITest, RecordingDelay) { | |
1479 // NOTE: this API is better tested in a functional test | |
1480 uint16_t sizeMS(0); | |
1481 CheckInitialRecordingStates(); | |
1482 | |
1483 // bulk tests | |
1484 EXPECT_EQ(0, audio_device_->RecordingDelay(&sizeMS)); | |
1485 EXPECT_EQ(0, audio_device_->RecordingDelay(&sizeMS)); | |
1486 } | |
1487 | |
1488 TEST_F(AudioDeviceAPITest, CPULoad) { | |
1489 // NOTE: this API is better tested in a functional test | |
1490 uint16_t load(0); | |
1491 | |
1492 // bulk tests | |
1493 #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) | |
1494 EXPECT_EQ(0, audio_device_->CPULoad(&load)); | |
1495 EXPECT_EQ(0, load); | |
1496 #else | |
1497 EXPECT_EQ(-1, audio_device_->CPULoad(&load)); | |
1498 #endif | |
1499 } | |
1500 | |
1501 // TODO(kjellander): Fix flakiness causing failures on Windows. | |
1502 // TODO(phoglund): Fix flakiness causing failures on Linux. | |
1503 #if !defined(_WIN32) && !defined(WEBRTC_LINUX) | |
1504 TEST_F(AudioDeviceAPITest, StartAndStopRawOutputFileRecording) { | |
1505 // NOTE: this API is better tested in a functional test | |
1506 CheckInitialPlayoutStates(); | |
1507 | |
1508 // fail tests | |
1509 EXPECT_EQ(-1, audio_device_->StartRawOutputFileRecording(NULL)); | |
1510 | |
1511 // bulk tests | |
1512 EXPECT_EQ(0, audio_device_->StartRawOutputFileRecording( | |
1513 GetFilename("raw_output_not_playing.pcm"))); | |
1514 EXPECT_EQ(0, audio_device_->StopRawOutputFileRecording()); | |
1515 EXPECT_EQ(0, audio_device_->SetPlayoutDevice( | |
1516 MACRO_DEFAULT_COMMUNICATION_DEVICE)); | |
1517 | |
1518 // TODO(kjellander): Fix so these tests pass on Mac. | |
1519 #if !defined(WEBRTC_MAC) | |
1520 EXPECT_EQ(0, audio_device_->InitPlayout()); | |
1521 EXPECT_EQ(0, audio_device_->StartPlayout()); | |
1522 #endif | |
1523 | |
1524 EXPECT_EQ(0, audio_device_->StartRawOutputFileRecording( | |
1525 GetFilename("raw_output_playing.pcm"))); | |
1526 SleepMs(100); | |
1527 EXPECT_EQ(0, audio_device_->StopRawOutputFileRecording()); | |
1528 EXPECT_EQ(0, audio_device_->StopPlayout()); | |
1529 EXPECT_EQ(0, audio_device_->StartRawOutputFileRecording( | |
1530 GetFilename("raw_output_not_playing.pcm"))); | |
1531 EXPECT_EQ(0, audio_device_->StopRawOutputFileRecording()); | |
1532 | |
1533 // results after this test: | |
1534 // | |
1535 // - size of raw_output_not_playing.pcm shall be 0 | |
1536 // - size of raw_output_playing.pcm shall be > 0 | |
1537 } | |
1538 | |
1539 TEST_F(AudioDeviceAPITest, StartAndStopRawInputFileRecording) { | |
1540 // NOTE: this API is better tested in a functional test | |
1541 CheckInitialRecordingStates(); | |
1542 EXPECT_FALSE(audio_device_->Playing()); | |
1543 | |
1544 // fail tests | |
1545 EXPECT_EQ(-1, audio_device_->StartRawInputFileRecording(NULL)); | |
1546 | |
1547 // bulk tests | |
1548 EXPECT_EQ(0, audio_device_->StartRawInputFileRecording( | |
1549 GetFilename("raw_input_not_recording.pcm"))); | |
1550 EXPECT_EQ(0, audio_device_->StopRawInputFileRecording()); | |
1551 EXPECT_EQ(0, audio_device_->SetRecordingDevice(MACRO_DEFAULT_DEVICE)); | |
1552 | |
1553 // TODO(kjellander): Fix so these tests pass on Mac. | |
1554 #if !defined(WEBRTC_MAC) | |
1555 EXPECT_EQ(0, audio_device_->InitRecording()); | |
1556 EXPECT_EQ(0, audio_device_->StartRecording()); | |
1557 #endif | |
1558 EXPECT_EQ(0, audio_device_->StartRawInputFileRecording( | |
1559 GetFilename("raw_input_recording.pcm"))); | |
1560 SleepMs(100); | |
1561 EXPECT_EQ(0, audio_device_->StopRawInputFileRecording()); | |
1562 EXPECT_EQ(0, audio_device_->StopRecording()); | |
1563 EXPECT_EQ(0, audio_device_->StartRawInputFileRecording( | |
1564 GetFilename("raw_input_not_recording.pcm"))); | |
1565 EXPECT_EQ(0, audio_device_->StopRawInputFileRecording()); | |
1566 | |
1567 // results after this test: | |
1568 // | |
1569 // - size of raw_input_not_recording.pcm shall be 0 | |
1570 // - size of raw_input_not_recording.pcm shall be > 0 | |
1571 } | |
1572 #endif // !WIN32 && !WEBRTC_LINUX | |
1573 | |
1574 TEST_F(AudioDeviceAPITest, RecordingSampleRate) { | |
1575 uint32_t sampleRate(0); | |
1576 | |
1577 // bulk tests | |
1578 EXPECT_EQ(0, audio_device_->RecordingSampleRate(&sampleRate)); | |
1579 #if defined(_WIN32) && !defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) | |
1580 EXPECT_EQ(48000, sampleRate); | |
1581 #elif defined(ANDROID) | |
1582 TEST_LOG("Recording sample rate is %u\n\n", sampleRate); | |
1583 EXPECT_TRUE((sampleRate == 44000) || (sampleRate == 16000)); | |
1584 #elif defined(WEBRTC_IOS) | |
1585 TEST_LOG("Recording sample rate is %u\n\n", sampleRate); | |
1586 EXPECT_TRUE((sampleRate == 44000) || (sampleRate == 16000) || | |
1587 (sampleRate == 8000)); | |
1588 #endif | |
1589 | |
1590 // @TODO(xians) - add tests for all platforms here... | |
1591 } | |
1592 | |
1593 TEST_F(AudioDeviceAPITest, PlayoutSampleRate) { | |
1594 uint32_t sampleRate(0); | |
1595 | |
1596 // bulk tests | |
1597 EXPECT_EQ(0, audio_device_->PlayoutSampleRate(&sampleRate)); | |
1598 #if defined(_WIN32) && !defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) | |
1599 EXPECT_EQ(48000, sampleRate); | |
1600 #elif defined(ANDROID) | |
1601 TEST_LOG("Playout sample rate is %u\n\n", sampleRate); | |
1602 EXPECT_TRUE((sampleRate == 44000) || (sampleRate == 16000)); | |
1603 #elif defined(WEBRTC_IOS) | |
1604 TEST_LOG("Playout sample rate is %u\n\n", sampleRate); | |
1605 EXPECT_TRUE((sampleRate == 44000) || (sampleRate == 16000) || | |
1606 (sampleRate == 8000)); | |
1607 #endif | |
1608 } | |
OLD | NEW |