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

Side by Side Diff: webrtc/modules/audio_device/test/audio_device_test_api.cc

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

Powered by Google App Engine
This is Rietveld 408576698