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 <assert.h> 12 #include <ctype.h> 13 #include <stdio.h> 14 #include <string.h> 15 16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "webrtc/modules/audio_device/test/func_test_manager.h" 18 #include "webrtc/system_wrappers/interface/sleep.h" 19 #include "webrtc/test/testsupport/fileutils.h" 20 21 #include "webrtc/modules/audio_device/audio_device_config.h" 22 #include "webrtc/modules/audio_device/audio_device_impl.h" 23 24 #ifndef __GNUC__ 25 // Disable warning message ('sprintf': name was marked as #pragma deprecated) 26 #pragma warning( disable : 4995 ) 27 // Disable warning message 4996 ('scanf': This function or variable may be unsafe) 28 #pragma warning( disable : 4996 ) 29 #endif 30 31 const char* RecordedMicrophoneFile = "recorded_microphone_mono_48.pcm"; 32 const char* RecordedMicrophoneVolumeFile = 33 "recorded_microphone_volume_mono_48.pcm"; 34 const char* RecordedMicrophoneMuteFile = "recorded_microphone_mute_mono_48.pcm"; 35 const char* RecordedMicrophoneBoostFile = 36 "recorded_microphone_boost_mono_48.pcm"; 37 const char* RecordedMicrophoneAGCFile = "recorded_microphone_AGC_mono_48.pcm"; 38 const char* RecordedSpeakerFile = "recorded_speaker_48.pcm"; 39 40 // Helper functions 41 #if !defined(WEBRTC_IOS) 42 char* GetFilename(char* filename) 43 { 44 return filename; 45 } 46 const char* GetFilename(const char* filename) 47 { 48 return filename; 49 } 50 char* GetResource(char* resource) 51 { 52 return resource; 53 } 54 const char* GetResource(const char* resource) 55 { 56 return resource; 57 } 58 #endif 59 60 namespace webrtc 61 { 62 63 AudioEventObserver::AudioEventObserver(AudioDeviceModule* audioDevice) 64 { 65 } 66 67 AudioEventObserver::~AudioEventObserver() 68 { 69 } 70 71 void AudioEventObserver::OnErrorIsReported(const ErrorCode error) 72 { 73 TEST_LOG("\n[*** ERROR ***] => OnErrorIsReported(%d)\n \n", error); 74 _error = error; 75 } 76 77 78 void AudioEventObserver::OnWarningIsReported(const WarningCode warning) 79 { 80 TEST_LOG("\n[*** WARNING ***] => OnWarningIsReported(%d)\n \n", warning); 81 _warning = warning; 82 } 83 84 AudioTransportImpl::AudioTransportImpl(AudioDeviceModule* audioDevice) : 85 _audioDevice(audioDevice), 86 _playFromFile(false), 87 _fullDuplex(false), 88 _speakerVolume(false), 89 _speakerMute(false), 90 _microphoneVolume(false), 91 _microphoneMute(false), 92 _microphoneBoost(false), 93 _microphoneAGC(false), 94 _loopBackMeasurements(false), 95 _playFile(*FileWrapper::Create()), 96 _recCount(0), 97 _playCount(0) 98 { 99 _resampler.Reset(48000, 48000, kResamplerSynchronousStereo); 100 } 101 102 AudioTransportImpl::~AudioTransportImpl() 103 { 104 _playFile.Flush(); 105 _playFile.CloseFile(); 106 delete &_playFile; 107 108 for (AudioPacketList::iterator iter = _audioList.begin(); 109 iter != _audioList.end(); ++iter) { 110 delete *iter; 111 } 112 } 113 114 // ---------------------------------------------------------------------------- 115 // AudioTransportImpl::SetFilePlayout 116 // ---------------------------------------------------------------------------- 117 118 int32_t AudioTransportImpl::SetFilePlayout(bool enable, const char* fileName) 119 { 120 _playFromFile = enable; 121 if (enable) 122 { 123 return (_playFile.OpenFile(fileName, true, true, false)); 124 } else 125 { 126 _playFile.Flush(); 127 return (_playFile.CloseFile()); 128 } 129 } 130 ; 131 132 void AudioTransportImpl::SetFullDuplex(bool enable) 133 { 134 _fullDuplex = enable; 135 136 for (AudioPacketList::iterator iter = _audioList.begin(); 137 iter != _audioList.end(); ++iter) { 138 delete *iter; 139 } 140 _audioList.clear(); 141 } 142 143 int32_t AudioTransportImpl::RecordedDataIsAvailable( 144 const void* audioSamples, 145 const uint32_t nSamples, 146 const uint8_t nBytesPerSample, 147 const uint8_t nChannels, 148 const uint32_t samplesPerSec, 149 const uint32_t totalDelayMS, 150 const int32_t clockDrift, 151 const uint32_t currentMicLevel, 152 const bool keyPressed, 153 uint32_t& newMicLevel) 154 { 155 if (_fullDuplex && _audioList.size() < 15) 156 { 157 AudioPacket* packet = new AudioPacket(); 158 memcpy(packet->dataBuffer, audioSamples, nSamples * nBytesPerSample); 159 packet->nSamples = (uint16_t) nSamples; 160 packet->nBytesPerSample = nBytesPerSample; 161 packet->nChannels = nChannels; 162 packet->samplesPerSec = samplesPerSec; 163 _audioList.push_back(packet); 164 } 165 166 _recCount++; 167 if (_recCount % 100 == 0) 168 { 169 bool addMarker(true); 170 171 if (_loopBackMeasurements) 172 { 173 addMarker = false; 174 } 175 176 if (_microphoneVolume) 177 { 178 uint32_t maxVolume(0); 179 uint32_t minVolume(0); 180 uint32_t volume(0); 181 uint16_t stepSize(0); 182 EXPECT_EQ(0, _audioDevice->MaxMicrophoneVolume(&maxVolume)); 183 EXPECT_EQ(0, _audioDevice->MinMicrophoneVolume(&minVolume)); 184 EXPECT_EQ(0, _audioDevice->MicrophoneVolumeStepSize(&stepSize)); 185 EXPECT_EQ(0, _audioDevice->MicrophoneVolume(&volume)); 186 if (volume == 0) 187 { 188 TEST_LOG("[0]"); 189 addMarker = false; 190 } 191 int stepScale = (int) ((maxVolume - minVolume) / (stepSize * 10)); 192 volume += (stepScale * stepSize); 193 if (volume > maxVolume) 194 { 195 TEST_LOG("[MAX]"); 196 volume = 0; 197 addMarker = false; 198 } 199 EXPECT_EQ(0, _audioDevice->SetMicrophoneVolume(volume)); 200 } 201 202 if (_microphoneAGC) 203 { 204 uint32_t maxVolume(0); 205 uint32_t minVolume(0); 206 uint16_t stepSize(0); 207 EXPECT_EQ(0, _audioDevice->MaxMicrophoneVolume(&maxVolume)); 208 EXPECT_EQ(0, _audioDevice->MinMicrophoneVolume(&minVolume)); 209 EXPECT_EQ(0, _audioDevice->MicrophoneVolumeStepSize(&stepSize)); 210 // emulate real AGC (min->max->min->max etc.) 211 if (currentMicLevel <= 1) 212 { 213 TEST_LOG("[MIN]"); 214 addMarker = false; 215 } 216 int stepScale = (int) ((maxVolume - minVolume) / (stepSize * 10)); 217 newMicLevel = currentMicLevel + (stepScale * stepSize); 218 if (newMicLevel > maxVolume) 219 { 220 TEST_LOG("[MAX]"); 221 newMicLevel = 1; // set lowest (non-zero) AGC level 222 addMarker = false; 223 } 224 } 225 226 if (_microphoneMute && (_recCount % 500 == 0)) 227 { 228 bool muted(false); 229 EXPECT_EQ(0, _audioDevice->MicrophoneMute(&muted)); 230 muted = !muted; 231 EXPECT_EQ(0, _audioDevice->SetMicrophoneMute(muted)); 232 if (muted) 233 { 234 TEST_LOG("[MUTE ON]"); 235 addMarker = false; 236 } else 237 { 238 TEST_LOG("[MUTE OFF]"); 239 addMarker = false; 240 } 241 } 242 243 if (_microphoneBoost && (_recCount % 500 == 0)) 244 { 245 bool boosted(false); 246 EXPECT_EQ(0, _audioDevice->MicrophoneBoost(&boosted)); 247 boosted = !boosted; 248 EXPECT_EQ(0, _audioDevice->SetMicrophoneBoost(boosted)); 249 if (boosted) 250 { 251 TEST_LOG("[BOOST ON]"); 252 addMarker = false; 253 } else 254 { 255 TEST_LOG("[BOOST OFF]"); 256 addMarker = false; 257 } 258 } 259 260 if ((nChannels == 1) && addMarker) 261 { 262 // mono 263 TEST_LOG("-"); 264 } else if ((nChannels == 2) && (nBytesPerSample == 2) && addMarker) 265 { 266 AudioDeviceModule::ChannelType 267 chType(AudioDeviceModule::kChannelLeft); 268 EXPECT_EQ(0, _audioDevice->RecordingChannel(&chType)); 269 if (chType == AudioDeviceModule::kChannelLeft) 270 TEST_LOG("-|"); 271 else 272 TEST_LOG("|-"); 273 } else if (addMarker) 274 { 275 // stereo 276 TEST_LOG("--"); 277 } 278 279 if (nChannels == 2 && nBytesPerSample == 2) 280 { 281 // TEST_LOG("=> emulated mono (one channel exctracted from stereo input)\n"); 282 } 283 } 284 285 return 0; 286 } 287 288 289 int32_t AudioTransportImpl::NeedMorePlayData( 290 const uint32_t nSamples, 291 const uint8_t nBytesPerSample, 292 const uint8_t nChannels, 293 const uint32_t samplesPerSec, 294 void* audioSamples, 295 uint32_t& nSamplesOut, 296 int64_t* elapsed_time_ms, 297 int64_t* ntp_time_ms) 298 { 299 if (_fullDuplex) 300 { 301 if (_audioList.empty()) 302 { 303 // use zero stuffing when not enough data 304 memset(audioSamples, 0, nBytesPerSample * nSamples); 305 } else 306 { 307 AudioPacket* packet = _audioList.front(); 308 _audioList.pop_front(); 309 if (packet) 310 { 311 int ret(0); 312 int lenOut(0); 313 int16_t tmpBuf_96kHz[80 * 12]; 314 int16_t* ptr16In = NULL; 315 int16_t* ptr16Out = NULL; 316 317 const uint16_t nSamplesIn = packet->nSamples; 318 const uint8_t nChannelsIn = packet->nChannels; 319 const uint32_t samplesPerSecIn = packet->samplesPerSec; 320 const uint16_t nBytesPerSampleIn = 321 packet->nBytesPerSample; 322 323 int32_t fsInHz(samplesPerSecIn); 324 int32_t fsOutHz(samplesPerSec); 325 326 if (fsInHz == 44100) 327 fsInHz = 44000; 328 329 if (fsOutHz == 44100) 330 fsOutHz = 44000; 331 332 if (nChannelsIn == 2 && nBytesPerSampleIn == 4) 333 { 334 // input is stereo => we will resample in stereo 335 ret = _resampler.ResetIfNeeded(fsInHz, fsOutHz, 336 kResamplerSynchronousStereo); 337 if (ret == 0) 338 { 339 if (nChannels == 2) 340 { 341 _resampler.Push( 342 (const int16_t*) packet->dataBuffer, 343 2 * nSamplesIn, 344 (int16_t*) audioSamples, 2 345 * nSamples, lenOut); 346 } else 347 { 348 _resampler.Push( 349 (const int16_t*) packet->dataBuffer, 350 2 * nSamplesIn, tmpBuf_96kHz, 2 351 * nSamples, lenOut); 352 353 ptr16In = &tmpBuf_96kHz[0]; 354 ptr16Out = (int16_t*) audioSamples; 355 356 // do stereo -> mono 357 for (unsigned int i = 0; i < nSamples; i++) 358 { 359 *ptr16Out = *ptr16In; // use left channel 360 ptr16Out++; 361 ptr16In++; 362 ptr16In++; 363 } 364 } 365 assert(2*nSamples == (uint32_t)lenOut); 366 } else 367 { 368 if (_playCount % 100 == 0) 369 TEST_LOG( 370 "ERROR: unable to resample from %d to %d\n", 371 samplesPerSecIn, samplesPerSec); 372 } 373 } else 374 { 375 // input is mono (can be "reduced from stereo" as well) => 376 // we will resample in mono 377 ret = _resampler.ResetIfNeeded(fsInHz, fsOutHz, 378 kResamplerSynchronous); 379 if (ret == 0) 380 { 381 if (nChannels == 1) 382 { 383 _resampler.Push( 384 (const int16_t*) packet->dataBuffer, 385 nSamplesIn, 386 (int16_t*) audioSamples, 387 nSamples, lenOut); 388 } else 389 { 390 _resampler.Push( 391 (const int16_t*) packet->dataBuffer, 392 nSamplesIn, tmpBuf_96kHz, nSamples, 393 lenOut); 394 395 ptr16In = &tmpBuf_96kHz[0]; 396 ptr16Out = (int16_t*) audioSamples; 397 398 // do mono -> stereo 399 for (unsigned int i = 0; i < nSamples; i++) 400 { 401 *ptr16Out = *ptr16In; // left 402 ptr16Out++; 403 *ptr16Out = *ptr16In; // right (same as left sample) 404 ptr16Out++; 405 ptr16In++; 406 } 407 } 408 assert(nSamples == (uint32_t)lenOut); 409 } else 410 { 411 if (_playCount % 100 == 0) 412 TEST_LOG("ERROR: unable to resample from %d to %d\n", 413 samplesPerSecIn, samplesPerSec); 414 } 415 } 416 nSamplesOut = nSamples; 417 delete packet; 418 } 419 } 420 } // if (_fullDuplex) 421 422 if (_playFromFile && _playFile.Open()) 423 { 424 int16_t fileBuf[480]; 425 426 // read mono-file 427 int32_t len = _playFile.Read((int8_t*) fileBuf, 2 428 * nSamples); 429 if (len != 2 * (int32_t) nSamples) 430 { 431 _playFile.Rewind(); 432 _playFile.Read((int8_t*) fileBuf, 2 * nSamples); 433 } 434 435 // convert to stero if required 436 if (nChannels == 1) 437 { 438 memcpy(audioSamples, fileBuf, 2 * nSamples); 439 } else 440 { 441 // mono sample from file is duplicated and sent to left and right 442 // channels 443 int16_t* audio16 = (int16_t*) audioSamples; 444 for (unsigned int i = 0; i < nSamples; i++) 445 { 446 (*audio16) = fileBuf[i]; // left 447 audio16++; 448 (*audio16) = fileBuf[i]; // right 449 audio16++; 450 } 451 } 452 } // if (_playFromFile && _playFile.Open()) 453 454 _playCount++; 455 456 if (_playCount % 100 == 0) 457 { 458 bool addMarker(true); 459 460 if (_speakerVolume) 461 { 462 uint32_t maxVolume(0); 463 uint32_t minVolume(0); 464 uint32_t volume(0); 465 uint16_t stepSize(0); 466 EXPECT_EQ(0, _audioDevice->MaxSpeakerVolume(&maxVolume)); 467 EXPECT_EQ(0, _audioDevice->MinSpeakerVolume(&minVolume)); 468 EXPECT_EQ(0, _audioDevice->SpeakerVolumeStepSize(&stepSize)); 469 EXPECT_EQ(0, _audioDevice->SpeakerVolume(&volume)); 470 if (volume == 0) 471 { 472 TEST_LOG("[0]"); 473 addMarker = false; 474 } 475 uint32_t step = (maxVolume - minVolume) / 10; 476 step = (step < stepSize ? stepSize : step); 477 volume += step; 478 if (volume > maxVolume) 479 { 480 TEST_LOG("[MAX]"); 481 volume = 0; 482 addMarker = false; 483 } 484 EXPECT_EQ(0, _audioDevice->SetSpeakerVolume(volume)); 485 } 486 487 if (_speakerMute && (_playCount % 500 == 0)) 488 { 489 bool muted(false); 490 EXPECT_EQ(0, _audioDevice->SpeakerMute(&muted)); 491 muted = !muted; 492 EXPECT_EQ(0, _audioDevice->SetSpeakerMute(muted)); 493 if (muted) 494 { 495 TEST_LOG("[MUTE ON]"); 496 addMarker = false; 497 } else 498 { 499 TEST_LOG("[MUTE OFF]"); 500 addMarker = false; 501 } 502 } 503 504 if (_loopBackMeasurements) 505 { 506 uint16_t recDelayMS(0); 507 uint16_t playDelayMS(0); 508 size_t nItemsInList(0); 509 510 nItemsInList = _audioList.size(); 511 EXPECT_EQ(0, _audioDevice->RecordingDelay(&recDelayMS)); 512 EXPECT_EQ(0, _audioDevice->PlayoutDelay(&playDelayMS)); 513 TEST_LOG("Delay (rec+play)+buf: %3zu (%3u+%3u)+%3zu [ms]\n", 514 recDelayMS + playDelayMS + 10 * (nItemsInList + 1), 515 recDelayMS, playDelayMS, 10 * (nItemsInList + 1)); 516 517 addMarker = false; 518 } 519 520 if ((nChannels == 1) && addMarker) 521 { 522 TEST_LOG("+"); 523 } else if ((nChannels == 2) && addMarker) 524 { 525 TEST_LOG("++"); 526 } 527 } // if (_playCount % 100 == 0) 528 529 nSamplesOut = nSamples; 530 531 return 0; 532 } 533 534 int AudioTransportImpl::OnDataAvailable(const int voe_channels[], 535 int number_of_voe_channels, 536 const int16_t* audio_data, 537 int sample_rate, 538 int number_of_channels, 539 int number_of_frames, 540 int audio_delay_milliseconds, 541 int current_volume, 542 bool key_pressed, 543 bool need_audio_processing) { 544 return 0; 545 } 546 547 void AudioTransportImpl::PushCaptureData(int voe_channel, 548 const void* audio_data, 549 int bits_per_sample, int sample_rate, 550 int number_of_channels, 551 int number_of_frames) {} 552 553 void AudioTransportImpl::PullRenderData(int bits_per_sample, int sample_rate, 554 int number_of_channels, 555 int number_of_frames, 556 void* audio_data, 557 int64_t* elapsed_time_ms, 558 int64_t* ntp_time_ms) {} 559 560 FuncTestManager::FuncTestManager() : 561 _processThread(NULL), 562 _audioDevice(NULL), 563 _audioEventObserver(NULL), 564 _audioTransport(NULL) 565 { 566 _playoutFile48 = webrtc::test::ResourcePath("audio_device\\audio_short48", 567 "pcm"); 568 _playoutFile44 = webrtc::test::ResourcePath("audio_device\\audio_short44", 569 "pcm"); 570 _playoutFile16 = webrtc::test::ResourcePath("audio_device\\audio_short16", 571 "pcm"); 572 _playoutFile8 = webrtc::test::ResourcePath("audio_device\\audio_short8", 573 "pcm"); 574 } 575 576 FuncTestManager::~FuncTestManager() 577 { 578 } 579 580 int32_t FuncTestManager::Init() 581 { 582 EXPECT_TRUE((_processThread = ProcessThread::CreateProcessThread()) != NULL); 583 if (_processThread == NULL) 584 { 585 return -1; 586 } 587 _processThread->Start(); 588 589 // create the Audio Device module 590 EXPECT_TRUE((_audioDevice = AudioDeviceModuleImpl::Create( 591 555, ADM_AUDIO_LAYER)) != NULL); 592 if (_audioDevice == NULL) 593 { 594 return -1; 595 } 596 EXPECT_EQ(1, _audioDevice->AddRef()); 597 598 // register the Audio Device module 599 _processThread->RegisterModule(_audioDevice); 600 601 // register event observer 602 _audioEventObserver = new AudioEventObserver(_audioDevice); 603 EXPECT_EQ(0, _audioDevice->RegisterEventObserver(_audioEventObserver)); 604 605 // register audio transport 606 _audioTransport = new AudioTransportImpl(_audioDevice); 607 EXPECT_EQ(0, _audioDevice->RegisterAudioCallback(_audioTransport)); 608 609 return 0; 610 } 611 612 int32_t FuncTestManager::Close() 613 { 614 EXPECT_EQ(0, _audioDevice->RegisterEventObserver(NULL)); 615 EXPECT_EQ(0, _audioDevice->RegisterAudioCallback(NULL)); 616 EXPECT_EQ(0, _audioDevice->Terminate()); 617 618 // release the ProcessThread object 619 if (_processThread) 620 { 621 _processThread->DeRegisterModule(_audioDevice); 622 _processThread->Stop(); 623 ProcessThread::DestroyProcessThread(_processThread); 624 } 625 626 // delete the audio observer 627 if (_audioEventObserver) 628 { 629 delete _audioEventObserver; 630 _audioEventObserver = NULL; 631 } 632 633 // delete the audio transport 634 if (_audioTransport) 635 { 636 delete _audioTransport; 637 _audioTransport = NULL; 638 } 639 640 // release the AudioDeviceModule object 641 if (_audioDevice) 642 { 643 EXPECT_EQ(0, _audioDevice->Release()); 644 _audioDevice = NULL; 645 } 646 647 // return the ThreadWrapper (singleton) 648 Trace::ReturnTrace(); 649 650 // PRINT_TEST_RESULTS; 651 652 return 0; 653 } 654 655 int32_t FuncTestManager::DoTest(const TestType testType) 656 { 657 switch (testType) 658 { 659 case TTAll: 660 TestAudioLayerSelection(); 661 TestDeviceEnumeration(); 662 TestDeviceSelection(); 663 TestAudioTransport(); 664 TestSpeakerVolume(); 665 TestMicrophoneVolume(); 666 TestLoopback(); 667 case TTAudioLayerSelection: 668 TestAudioLayerSelection(); 669 break; 670 case TTDeviceEnumeration: 671 TestDeviceEnumeration(); 672 break; 673 case TTDeviceSelection: 674 TestDeviceSelection(); 675 break; 676 case TTAudioTransport: 677 TestAudioTransport(); 678 break; 679 case TTSpeakerVolume: 680 TestSpeakerVolume(); 681 break; 682 case TTMicrophoneVolume: 683 TestMicrophoneVolume(); 684 break; 685 case TTSpeakerMute: 686 TestSpeakerMute(); 687 break; 688 case TTMicrophoneMute: 689 TestMicrophoneMute(); 690 break; 691 case TTMicrophoneBoost: 692 TestMicrophoneBoost(); 693 break; 694 case TTMicrophoneAGC: 695 TestMicrophoneAGC(); 696 break; 697 case TTLoopback: 698 TestLoopback(); 699 break; 700 case TTDeviceRemoval: 701 TestDeviceRemoval(); 702 break; 703 case TTMobileAPI: 704 TestAdvancedMBAPI(); 705 case TTTest: 706 TestExtra(); 707 break; 708 default: 709 break; 710 } 711 712 return 0; 713 } 714 715 int32_t FuncTestManager::TestAudioLayerSelection() 716 { 717 TEST_LOG("\n=======================================\n"); 718 TEST_LOG(" Audio Layer test:\n"); 719 TEST_LOG("=======================================\n"); 720 721 if (_audioDevice == NULL) 722 { 723 return -1; 724 } 725 726 RESET_TEST; 727 728 AudioDeviceModule* audioDevice = _audioDevice; 729 730 AudioDeviceModule::AudioLayer audioLayer; 731 EXPECT_EQ(0, audioDevice->ActiveAudioLayer(&audioLayer)); 732 733 if (audioLayer == AudioDeviceModule::kWindowsWaveAudio) 734 { 735 TEST_LOG("\nActiveAudioLayer: kWindowsWaveAudio\n \n"); 736 } else if (audioLayer == AudioDeviceModule::kWindowsCoreAudio) 737 { 738 TEST_LOG("\nActiveAudioLayer: kWindowsCoreAudio\n \n"); 739 } else if (audioLayer == AudioDeviceModule::kLinuxAlsaAudio) 740 { 741 TEST_LOG("\nActiveAudioLayer: kLinuxAlsaAudio\n \n"); 742 } else if (audioLayer == AudioDeviceModule::kLinuxPulseAudio) 743 { 744 TEST_LOG("\nActiveAudioLayer: kLinuxPulseAudio\n \n"); 745 } else 746 { 747 TEST_LOG("\nActiveAudioLayer: INVALID\n \n"); 748 } 749 750 char ch; 751 bool tryWinWave(false); 752 bool tryWinCore(false); 753 754 if (audioLayer == AudioDeviceModule::kWindowsWaveAudio) 755 { 756 TEST_LOG("Would you like to try kWindowsCoreAudio instead " 757 "[requires Win Vista or Win 7] (Y/N)?\n: "); 758 EXPECT_TRUE(scanf(" %c", &ch) > 0); 759 ch = toupper(ch); 760 if (ch == 'Y') 761 { 762 tryWinCore = true; 763 } 764 } else if (audioLayer == AudioDeviceModule::kWindowsCoreAudio) 765 { 766 TEST_LOG("Would you like to try kWindowsWaveAudio instead (Y/N)?\n: "); 767 EXPECT_TRUE(scanf(" %c", &ch) > 0); 768 ch = toupper(ch); 769 if (ch == 'Y') 770 { 771 tryWinWave = true; 772 } 773 } 774 775 if (tryWinWave || tryWinCore) 776 { 777 // ======================================= 778 // First, close down what we have started 779 780 // terminate 781 EXPECT_EQ(0, _audioDevice->RegisterEventObserver(NULL)); 782 EXPECT_EQ(0, _audioDevice->RegisterAudioCallback(NULL)); 783 EXPECT_EQ(0, _audioDevice->Terminate()); 784 785 // release the ProcessThread object 786 if (_processThread) 787 { 788 _processThread->DeRegisterModule(_audioDevice); 789 _processThread->Stop(); 790 ProcessThread::DestroyProcessThread(_processThread); 791 } 792 793 // delete the audio observer 794 if (_audioEventObserver) 795 { 796 delete _audioEventObserver; 797 _audioEventObserver = NULL; 798 } 799 800 // delete the audio transport 801 if (_audioTransport) 802 { 803 delete _audioTransport; 804 _audioTransport = NULL; 805 } 806 807 // release the AudioDeviceModule object 808 if (_audioDevice) 809 { 810 EXPECT_EQ(0, _audioDevice->Release()); 811 _audioDevice = NULL; 812 } 813 814 // ================================================== 815 // Next, try to make fresh start with new audio layer 816 817 EXPECT_TRUE((_processThread = ProcessThread::CreateProcessThread()) != NULL); 818 if (_processThread == NULL) 819 { 820 return -1; 821 } 822 _processThread->Start(); 823 824 // create the Audio Device module based on selected audio layer 825 if (tryWinWave) 826 { 827 _audioDevice = AudioDeviceModuleImpl::Create( 828 555, 829 AudioDeviceModule::kWindowsWaveAudio); 830 } else if (tryWinCore) 831 { 832 _audioDevice = AudioDeviceModuleImpl::Create( 833 555, 834 AudioDeviceModule::kWindowsCoreAudio); 835 } 836 837 if (_audioDevice == NULL) 838 { 839 TEST_LOG("\nERROR: Switch of audio layer failed!\n"); 840 // restore default audio layer instead 841 EXPECT_TRUE((_audioDevice = AudioDeviceModuleImpl::Create( 842 555, AudioDeviceModule::kPlatformDefaultAudio)) != NULL); 843 } 844 845 if (_audioDevice == NULL) 846 { 847 TEST_LOG("\nERROR: Failed to revert back to default audio layer!\n"); 848 return -1; 849 } 850 851 EXPECT_EQ(1, _audioDevice->AddRef()); 852 853 // register the Audio Device module 854 _processThread->RegisterModule(_audioDevice); 855 856 // register event observer 857 _audioEventObserver = new AudioEventObserver(_audioDevice); 858 EXPECT_EQ(0, _audioDevice->RegisterEventObserver(_audioEventObserver)); 859 860 // register audio transport 861 _audioTransport = new AudioTransportImpl(_audioDevice); 862 EXPECT_EQ(0, _audioDevice->RegisterAudioCallback(_audioTransport)); 863 864 EXPECT_EQ(0, _audioDevice->ActiveAudioLayer(&audioLayer)); 865 866 if (audioLayer == AudioDeviceModule::kWindowsWaveAudio) 867 { 868 if (tryWinCore) 869 TEST_LOG("\nActiveAudioLayer: kWindowsWaveAudio <=> " 870 "switch was *not* possible\n \n"); 871 else 872 TEST_LOG("\nActiveAudioLayer: kWindowsWaveAudio <=> " 873 "switch was possible\n \n"); 874 } else if (audioLayer == AudioDeviceModule::kWindowsCoreAudio) 875 { 876 if (tryWinWave) 877 TEST_LOG("\nActiveAudioLayer: kWindowsCoreAudio <=> " 878 "switch was *not* possible\n \n"); 879 else 880 TEST_LOG("\nActiveAudioLayer: kWindowsCoreAudio <=> " 881 "switch was possible\n \n"); 882 } 883 } // if (tryWinWave || tryWinCore) 884 885 PRINT_TEST_RESULTS; 886 887 return 0; 888 } 889 890 int32_t FuncTestManager::TestDeviceEnumeration() 891 { 892 TEST_LOG("\n=======================================\n"); 893 TEST_LOG(" Device Enumeration test:\n"); 894 TEST_LOG("=======================================\n"); 895 896 if (_audioDevice == NULL) 897 { 898 return -1; 899 } 900 901 RESET_TEST; 902 903 AudioDeviceModule* audioDevice = _audioDevice; 904 905 EXPECT_EQ(0, audioDevice->Init()); 906 EXPECT_TRUE(audioDevice->Initialized()); 907 908 char name[kAdmMaxDeviceNameSize]; 909 char guid[kAdmMaxGuidSize]; 910 911 const int16_t nPlayoutDevices(audioDevice->PlayoutDevices()); 912 EXPECT_TRUE(nPlayoutDevices >= 0); 913 TEST_LOG("\nPlayoutDevices: %u\n \n", nPlayoutDevices); 914 for (int n = 0; n < nPlayoutDevices; n++) 915 { 916 EXPECT_EQ(0, audioDevice->PlayoutDeviceName(n, name, guid)); 917 TEST_LOG( 918 "PlayoutDeviceName(%d) : name=%s \n \ 919 guid=%s\n", 920 n, name, guid); 921 } 922 923 #ifdef _WIN32 924 // default (-1) 925 EXPECT_EQ(0, audioDevice->PlayoutDeviceName(-1, name, guid)); 926 TEST_LOG("PlayoutDeviceName(%d): default name=%s \n \ 927 default guid=%s\n", -1, name, guid); 928 #else 929 // should fail 930 EXPECT_EQ(-1, audioDevice->PlayoutDeviceName(-1, name, guid)); 931 #endif 932 933 const int16_t nRecordingDevices(audioDevice->RecordingDevices()); 934 EXPECT_TRUE(nRecordingDevices >= 0); 935 TEST_LOG("\nRecordingDevices: %u\n \n", nRecordingDevices); 936 for (int n = 0; n < nRecordingDevices; n++) 937 { 938 EXPECT_EQ(0, audioDevice->RecordingDeviceName(n, name, guid)); 939 TEST_LOG( 940 "RecordingDeviceName(%d) : name=%s \n \ 941 guid=%s\n", 942 n, name, guid); 943 } 944 945 #ifdef _WIN32 946 // default (-1) 947 EXPECT_EQ(0, audioDevice->RecordingDeviceName(-1, name, guid)); 948 TEST_LOG("RecordingDeviceName(%d): default name=%s \n \ 949 default guid=%s\n", -1, name, guid); 950 #else 951 // should fail 952 EXPECT_EQ(-1, audioDevice->PlayoutDeviceName(-1, name, guid)); 953 #endif 954 955 EXPECT_EQ(0, audioDevice->Terminate()); 956 EXPECT_FALSE(audioDevice->Initialized()); 957 958 PRINT_TEST_RESULTS; 959 960 return 0; 961 } 962 963 int32_t FuncTestManager::TestDeviceSelection() 964 { 965 TEST_LOG("\n=======================================\n"); 966 TEST_LOG(" Device Selection test:\n"); 967 TEST_LOG("=======================================\n"); 968 969 if (_audioDevice == NULL) 970 { 971 return -1; 972 } 973 974 RESET_TEST; 975 976 #define PRINT_HEADING(a, b) \ 977 { \ 978 TEST_LOG("Set" #a "Device(" #b ") => \n"); \ 979 } \ 980 981 #define PRINT_HEADING_IDX(a, b,c ) \ 982 { \ 983 TEST_LOG("Set" #a "Device(%d) (%s) => \n", b, c); \ 984 } \ 985 986 #define PRINT_STR(a, b) \ 987 { \ 988 char str[128]; \ 989 (b == true) ? (sprintf(str, " %-17s: available\n", #a)) : (sprintf(str, " %-17s: NA\n", #a)); \ 990 TEST_LOG("%s", str); \ 991 } \ 992 993 AudioDeviceModule* audioDevice = _audioDevice; 994 995 EXPECT_EQ(0, audioDevice->Init()); 996 EXPECT_TRUE(audioDevice->Initialized()); 997 998 bool available(false); 999 int16_t nDevices(-1); 1000 char name[kAdmMaxDeviceNameSize]; 1001 char guid[kAdmMaxGuidSize]; 1002 1003 // ======= 1004 // Playout 1005 1006 nDevices = audioDevice->PlayoutDevices(); 1007 EXPECT_TRUE(nDevices >= 0); 1008 1009 TEST_LOG("\n"); 1010 #ifdef _WIN32 1011 EXPECT_TRUE(audioDevice->SetPlayoutDevice( 1012 AudioDeviceModule::kDefaultCommunicationDevice) == 0); 1013 PRINT_HEADING(Playout, kDefaultCommunicationDevice); 1014 EXPECT_EQ(0, audioDevice->PlayoutIsAvailable(&available)); 1015 PRINT_STR(Playout, available); 1016 if (available) 1017 { 1018 EXPECT_EQ(0, audioDevice->StereoPlayoutIsAvailable(&available)); 1019 PRINT_STR(Stereo Playout, available); 1020 } 1021 else 1022 { 1023 PRINT_STR(Stereo Playout, false); 1024 } 1025 EXPECT_EQ(0, audioDevice->SpeakerVolumeIsAvailable(&available)); 1026 PRINT_STR(Speaker Volume, available); 1027 EXPECT_EQ(0, audioDevice->SpeakerMuteIsAvailable(&available)); 1028 PRINT_STR(Speaker Mute, available); 1029 1030 EXPECT_EQ(0, audioDevice->SetPlayoutDevice(AudioDeviceModule::kDefaultDevice)); 1031 PRINT_HEADING(Playout, kDefaultDevice); 1032 EXPECT_EQ(0, audioDevice->PlayoutIsAvailable(&available)); 1033 PRINT_STR(Playout, available); 1034 if (available) 1035 { 1036 EXPECT_EQ(0, audioDevice->StereoPlayoutIsAvailable(&available)); 1037 PRINT_STR(Stereo Playout, available); 1038 } 1039 else 1040 { 1041 PRINT_STR(Stereo Playout, false); 1042 } 1043 EXPECT_EQ(0, audioDevice->SpeakerVolumeIsAvailable(&available)); 1044 PRINT_STR(Speaker Volume, available); 1045 EXPECT_EQ(0, audioDevice->SpeakerMuteIsAvailable(&available)); 1046 PRINT_STR(Speaker Mute, available); 1047 #else 1048 EXPECT_TRUE(audioDevice->SetPlayoutDevice( 1049 AudioDeviceModule::kDefaultCommunicationDevice) == -1); 1050 EXPECT_EQ(-1, audioDevice->SetPlayoutDevice(AudioDeviceModule::kDefaultDevice)); 1051 #endif 1052 1053 for (int i = 0; i < nDevices; i++) 1054 { 1055 EXPECT_EQ(0, audioDevice->SetPlayoutDevice(i)); 1056 EXPECT_EQ(0, audioDevice->PlayoutDeviceName(i, name, guid)); 1057 PRINT_HEADING_IDX(Playout, i, name); 1058 EXPECT_EQ(0, audioDevice->PlayoutIsAvailable(&available)); 1059 PRINT_STR(Playout, available); 1060 if (available) 1061 { 1062 EXPECT_EQ(0, audioDevice->StereoPlayoutIsAvailable(&available)); 1063 PRINT_STR(Stereo Playout, available); 1064 } else 1065 { 1066 PRINT_STR(Stereo Playout, false); 1067 } 1068 EXPECT_EQ(0, audioDevice->SpeakerVolumeIsAvailable(&available)); 1069 PRINT_STR(Speaker Volume, available); 1070 EXPECT_EQ(0, audioDevice->SpeakerMuteIsAvailable(&available)); 1071 PRINT_STR(Speaker Mute, available); 1072 } 1073 1074 // ========= 1075 // Recording 1076 1077 nDevices = audioDevice->RecordingDevices(); 1078 EXPECT_TRUE(nDevices >= 0); 1079 1080 TEST_LOG("\n"); 1081 #ifdef _WIN32 1082 EXPECT_TRUE(audioDevice->SetRecordingDevice( 1083 AudioDeviceModule::kDefaultCommunicationDevice) == 0); 1084 PRINT_HEADING(Recording, kDefaultCommunicationDevice); 1085 EXPECT_EQ(0, audioDevice->RecordingIsAvailable(&available)); 1086 PRINT_STR(Recording, available); 1087 if (available) 1088 { 1089 EXPECT_EQ(0, audioDevice->StereoRecordingIsAvailable(&available)); 1090 PRINT_STR(Stereo Recording, available); 1091 } 1092 else 1093 { 1094 // special fix to ensure that we don't log 'available' when recording is not OK 1095 PRINT_STR(Stereo Recording, false); 1096 } 1097 EXPECT_EQ(0, audioDevice->MicrophoneVolumeIsAvailable(&available)); 1098 PRINT_STR(Microphone Volume, available); 1099 EXPECT_EQ(0, audioDevice->MicrophoneMuteIsAvailable(&available)); 1100 PRINT_STR(Microphone Mute, available); 1101 EXPECT_EQ(0, audioDevice->MicrophoneBoostIsAvailable(&available)); 1102 PRINT_STR(Microphone Boost, available); 1103 1104 EXPECT_EQ(0, audioDevice->SetRecordingDevice(AudioDeviceModule::kDefaultDevice)); 1105 PRINT_HEADING(Recording, kDefaultDevice); 1106 EXPECT_EQ(0, audioDevice->RecordingIsAvailable(&available)); 1107 PRINT_STR(Recording, available); 1108 if (available) 1109 { 1110 EXPECT_EQ(0, audioDevice->StereoRecordingIsAvailable(&available)); 1111 PRINT_STR(Stereo Recording, available); 1112 } 1113 else 1114 { 1115 // special fix to ensure that we don't log 'available' when recording is not OK 1116 PRINT_STR(Stereo Recording, false); 1117 } 1118 EXPECT_EQ(0, audioDevice->MicrophoneVolumeIsAvailable(&available)); 1119 PRINT_STR(Microphone Volume, available); 1120 EXPECT_EQ(0, audioDevice->MicrophoneMuteIsAvailable(&available)); 1121 PRINT_STR(Microphone Mute, available); 1122 EXPECT_EQ(0, audioDevice->MicrophoneBoostIsAvailable(&available)); 1123 PRINT_STR(Microphone Boost, available); 1124 #else 1125 EXPECT_TRUE(audioDevice->SetRecordingDevice( 1126 AudioDeviceModule::kDefaultCommunicationDevice) == -1); 1127 EXPECT_EQ(-1, audioDevice->SetRecordingDevice(AudioDeviceModule::kDefaultDevice)); 1128 #endif 1129 1130 for (int i = 0; i < nDevices; i++) 1131 { 1132 EXPECT_EQ(0, audioDevice->SetRecordingDevice(i)); 1133 EXPECT_EQ(0, audioDevice->RecordingDeviceName(i, name, guid)); 1134 PRINT_HEADING_IDX(Recording, i, name); 1135 EXPECT_EQ(0, audioDevice->RecordingIsAvailable(&available)); 1136 PRINT_STR(Recording, available); 1137 if (available) 1138 { 1139 EXPECT_EQ(0, audioDevice->StereoRecordingIsAvailable(&available)); 1140 PRINT_STR(Stereo Recording, available); 1141 } else 1142 { 1143 // special fix to ensure that we don't log 'available' when recording 1144 // is not OK 1145 PRINT_STR(Stereo Recording, false); 1146 } 1147 EXPECT_EQ(0, audioDevice->MicrophoneVolumeIsAvailable(&available)); 1148 PRINT_STR(Microphone Volume, available); 1149 EXPECT_EQ(0, audioDevice->MicrophoneMuteIsAvailable(&available)); 1150 PRINT_STR(Microphone Mute, available); 1151 EXPECT_EQ(0, audioDevice->MicrophoneBoostIsAvailable(&available)); 1152 PRINT_STR(Microphone Boost, available); 1153 } 1154 1155 EXPECT_EQ(0, audioDevice->Terminate()); 1156 EXPECT_FALSE(audioDevice->Initialized()); 1157 1158 PRINT_TEST_RESULTS; 1159 1160 return 0; 1161 } 1162 1163 int32_t FuncTestManager::TestAudioTransport() 1164 { 1165 TEST_LOG("\n=======================================\n"); 1166 TEST_LOG(" Audio Transport test:\n"); 1167 TEST_LOG("=======================================\n"); 1168 1169 if (_audioDevice == NULL) 1170 { 1171 return -1; 1172 } 1173 1174 RESET_TEST; 1175 1176 AudioDeviceModule* audioDevice = _audioDevice; 1177 1178 EXPECT_EQ(0, audioDevice->Init()); 1179 EXPECT_TRUE(audioDevice->Initialized()); 1180 1181 bool recIsAvailable(false); 1182 bool playIsAvailable(false); 1183 1184 if (SelectRecordingDevice() == -1) 1185 { 1186 TEST_LOG("\nERROR: Device selection failed!\n \n"); 1187 return -1; 1188 } 1189 1190 EXPECT_EQ(0, audioDevice->RecordingIsAvailable(&recIsAvailable)); 1191 if (!recIsAvailable) 1192 { 1193 TEST_LOG( 1194 "\nWARNING: Recording is not available for the selected device!\n \n"); 1195 } 1196 1197 if (SelectPlayoutDevice() == -1) 1198 { 1199 TEST_LOG("\nERROR: Device selection failed!\n \n"); 1200 return -1; 1201 } 1202 1203 EXPECT_EQ(0, audioDevice->PlayoutIsAvailable(&playIsAvailable)); 1204 if (recIsAvailable && playIsAvailable) 1205 { 1206 _audioTransport->SetFullDuplex(true); 1207 } else if (!playIsAvailable) 1208 { 1209 TEST_LOG( 1210 "\nWARNING: Playout is not available for the selected device!\n \n"); 1211 } 1212 1213 bool available(false); 1214 uint32_t samplesPerSec(0); 1215 1216 if (playIsAvailable) 1217 { 1218 // ========================================= 1219 // Start by playing out an existing PCM file 1220 1221 EXPECT_EQ(0, audioDevice->SpeakerVolumeIsAvailable(&available)); 1222 if (available) 1223 { 1224 uint32_t maxVolume(0); 1225 EXPECT_EQ(0, audioDevice->MaxSpeakerVolume(&maxVolume)); 1226 EXPECT_EQ(0, audioDevice->SetSpeakerVolume(maxVolume/2)); 1227 } 1228 1229 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(_audioTransport)); 1230 1231 EXPECT_EQ(0, audioDevice->InitPlayout()); 1232 EXPECT_EQ(0, audioDevice->PlayoutSampleRate(&samplesPerSec)); 1233 if (samplesPerSec == 48000) { 1234 _audioTransport->SetFilePlayout( 1235 true, GetResource(_playoutFile48.c_str())); 1236 } else if (samplesPerSec == 44100 || samplesPerSec == 44000) { 1237 _audioTransport->SetFilePlayout( 1238 true, GetResource(_playoutFile44.c_str())); 1239 } else if (samplesPerSec == 16000) { 1240 _audioTransport->SetFilePlayout( 1241 true, GetResource(_playoutFile16.c_str())); 1242 } else if (samplesPerSec == 8000) { 1243 _audioTransport->SetFilePlayout( 1244 true, GetResource(_playoutFile8.c_str())); 1245 } else { 1246 TEST_LOG("\nERROR: Sample rate (%u) is not supported!\n \n", 1247 samplesPerSec); 1248 return -1; 1249 } 1250 EXPECT_EQ(0, audioDevice->StartPlayout()); 1251 1252 if (audioDevice->Playing()) 1253 { 1254 TEST_LOG("\n> Listen to the file being played (fs=%d) out " 1255 "and verify that the audio quality is OK.\n" 1256 "> Press any key to stop playing...\n \n", 1257 samplesPerSec); 1258 PAUSE(DEFAULT_PAUSE_TIME); 1259 } 1260 1261 EXPECT_EQ(0, audioDevice->StopPlayout()); 1262 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(NULL)); 1263 1264 _audioTransport->SetFilePlayout(false); 1265 } 1266 1267 bool enabled(false); 1268 if (recIsAvailable) 1269 { 1270 // ==================================== 1271 // Next, record from microphone to file 1272 1273 EXPECT_EQ(0, audioDevice->MicrophoneVolumeIsAvailable(&available)); 1274 if (available) 1275 { 1276 uint32_t maxVolume(0); 1277 EXPECT_EQ(0, audioDevice->MaxMicrophoneVolume(&maxVolume)); 1278 EXPECT_EQ(0, audioDevice->SetMicrophoneVolume(maxVolume)); 1279 } 1280 1281 EXPECT_TRUE(audioDevice->StartRawInputFileRecording( 1282 GetFilename(RecordedMicrophoneFile)) == 0); 1283 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(_audioTransport)); 1284 1285 EXPECT_EQ(0, audioDevice->InitRecording()); 1286 EXPECT_EQ(0, audioDevice->StereoRecording(&enabled)); 1287 if (enabled) 1288 { 1289 // ensure file recording in mono 1290 EXPECT_EQ(0, audioDevice->SetRecordingChannel(AudioDeviceModule::kChannelLeft)); 1291 } 1292 EXPECT_EQ(0, audioDevice->StartRecording()); 1293 SleepMs(100); 1294 1295 EXPECT_TRUE(audioDevice->Recording()); 1296 if (audioDevice->Recording()) 1297 { 1298 TEST_LOG("\n \n> The microphone input signal is now being recorded " 1299 "to a PCM file.\n" 1300 "> Speak into the microphone to ensure that your voice is" 1301 " recorded.\n> Press any key to stop recording...\n \n"); 1302 PAUSE(DEFAULT_PAUSE_TIME); 1303 } 1304 1305 EXPECT_EQ(0, audioDevice->StereoRecording(&enabled)); 1306 if (enabled) 1307 { 1308 EXPECT_EQ(0, audioDevice->SetRecordingChannel(AudioDeviceModule::kChannelBoth)); 1309 } 1310 EXPECT_EQ(0, audioDevice->StopRecording()); 1311 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(NULL)); 1312 EXPECT_EQ(0, audioDevice->StopRawInputFileRecording()); 1313 } 1314 1315 if (recIsAvailable && playIsAvailable) 1316 { 1317 // ========================== 1318 // Play out the recorded file 1319 1320 _audioTransport->SetFilePlayout(true, 1321 GetFilename(RecordedMicrophoneFile)); 1322 1323 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(_audioTransport)); 1324 EXPECT_EQ(0, audioDevice->PlayoutIsAvailable(&available)); 1325 if (available) 1326 { 1327 EXPECT_EQ(0, audioDevice->InitPlayout()); 1328 EXPECT_EQ(0, audioDevice->StartPlayout()); 1329 SleepMs(100); 1330 } 1331 1332 EXPECT_TRUE(audioDevice->Playing()); 1333 if (audioDevice->Playing()) 1334 { 1335 TEST_LOG("\n \n> Listen to the recorded file and verify that the " 1336 "audio quality is OK.\n" 1337 "> Press any key to stop listening...\n \n"); 1338 PAUSE(DEFAULT_PAUSE_TIME); 1339 } 1340 1341 EXPECT_EQ(0, audioDevice->StopPlayout()); 1342 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(NULL)); 1343 1344 _audioTransport->SetFilePlayout(false); 1345 } 1346 1347 if (recIsAvailable && playIsAvailable) 1348 { 1349 // ============================== 1350 // Finally, make full duplex test 1351 1352 uint32_t playSamplesPerSec(0); 1353 uint32_t recSamplesPerSecRec(0); 1354 1355 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(_audioTransport)); 1356 1357 _audioTransport->SetFullDuplex(true); 1358 1359 EXPECT_EQ(0, audioDevice->MicrophoneVolumeIsAvailable(&available)); 1360 if (available) 1361 { 1362 uint32_t maxVolume(0); 1363 EXPECT_EQ(0, audioDevice->MaxMicrophoneVolume(&maxVolume)); 1364 EXPECT_EQ(0, audioDevice->SetMicrophoneVolume(maxVolume)); 1365 } 1366 1367 EXPECT_EQ(0, audioDevice->InitRecording()); 1368 EXPECT_EQ(0, audioDevice->InitPlayout()); 1369 EXPECT_EQ(0, audioDevice->PlayoutSampleRate(&playSamplesPerSec)); 1370 EXPECT_EQ(0, audioDevice->RecordingSampleRate(&recSamplesPerSecRec)); 1371 if (playSamplesPerSec != recSamplesPerSecRec) 1372 { 1373 TEST_LOG("\nERROR: sample rates does not match (fs_play=%u, fs_rec=%u)", 1374 playSamplesPerSec, recSamplesPerSecRec); 1375 EXPECT_EQ(0, audioDevice->StopRecording()); 1376 EXPECT_EQ(0, audioDevice->StopPlayout()); 1377 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(NULL)); 1378 _audioTransport->SetFullDuplex(false); 1379 return -1; 1380 } 1381 1382 EXPECT_EQ(0, audioDevice->StartRecording()); 1383 EXPECT_EQ(0, audioDevice->StartPlayout()); 1384 SleepMs(100); 1385 1386 if (audioDevice->Playing() && audioDevice->Recording()) 1387 { 1388 TEST_LOG("\n \n> Full duplex audio (fs=%u) is now active.\n" 1389 "> Speak into the microphone and verify that your voice is " 1390 "played out in loopback.\n> Press any key to stop...\n \n", 1391 playSamplesPerSec); 1392 PAUSE(DEFAULT_PAUSE_TIME); 1393 } 1394 1395 EXPECT_EQ(0, audioDevice->StopRecording()); 1396 EXPECT_EQ(0, audioDevice->StopPlayout()); 1397 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(NULL)); 1398 1399 _audioTransport->SetFullDuplex(false); 1400 } 1401 1402 EXPECT_EQ(0, audioDevice->Terminate()); 1403 EXPECT_FALSE(audioDevice->Initialized()); 1404 1405 TEST_LOG("\n"); 1406 PRINT_TEST_RESULTS; 1407 1408 return 0; 1409 } 1410 1411 int32_t FuncTestManager::TestSpeakerVolume() 1412 { 1413 TEST_LOG("\n=======================================\n"); 1414 TEST_LOG(" Speaker Volume test:\n"); 1415 TEST_LOG("=======================================\n"); 1416 1417 if (_audioDevice == NULL) 1418 { 1419 return -1; 1420 } 1421 1422 RESET_TEST; 1423 1424 AudioDeviceModule* audioDevice = _audioDevice; 1425 1426 EXPECT_EQ(0, audioDevice->Init()); 1427 EXPECT_TRUE(audioDevice->Initialized()); 1428 1429 if (SelectPlayoutDevice() == -1) 1430 { 1431 TEST_LOG("\nERROR: Device selection failed!\n \n"); 1432 return -1; 1433 } 1434 1435 bool available(false); 1436 uint32_t startVolume(0); 1437 uint32_t samplesPerSec(0); 1438 1439 EXPECT_EQ(0, audioDevice->SpeakerVolumeIsAvailable(&available)); 1440 if (available) 1441 { 1442 _audioTransport->SetSpeakerVolume(true); 1443 } else 1444 { 1445 TEST_LOG("\nERROR: Volume control is not available for the selected " 1446 "device!\n \n"); 1447 return -1; 1448 } 1449 1450 // store initial volume setting 1451 EXPECT_EQ(0, audioDevice->InitSpeaker()); 1452 EXPECT_EQ(0, audioDevice->SpeakerVolume(&startVolume)); 1453 1454 // start at volume 0 1455 EXPECT_EQ(0, audioDevice->SetSpeakerVolume(0)); 1456 1457 // ====================================== 1458 // Start playing out an existing PCM file 1459 1460 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(_audioTransport)); 1461 EXPECT_EQ(0, audioDevice->PlayoutIsAvailable(&available)); 1462 if (available) 1463 { 1464 EXPECT_EQ(0, audioDevice->InitPlayout()); 1465 EXPECT_EQ(0, audioDevice->PlayoutSampleRate(&samplesPerSec)); 1466 if (48000 == samplesPerSec) { 1467 _audioTransport->SetFilePlayout( 1468 true, GetResource(_playoutFile48.c_str())); 1469 } else if (44100 == samplesPerSec || samplesPerSec == 44000) { 1470 _audioTransport->SetFilePlayout( 1471 true, GetResource(_playoutFile44.c_str())); 1472 } else if (samplesPerSec == 16000) { 1473 _audioTransport->SetFilePlayout( 1474 true, GetResource(_playoutFile16.c_str())); 1475 } else if (samplesPerSec == 8000) { 1476 _audioTransport->SetFilePlayout( 1477 true, GetResource(_playoutFile8.c_str())); 1478 } else { 1479 TEST_LOG("\nERROR: Sample rate (%d) is not supported!\n \n", 1480 samplesPerSec); 1481 return -1; 1482 } 1483 EXPECT_EQ(0, audioDevice->StartPlayout()); 1484 } 1485 1486 EXPECT_TRUE(audioDevice->Playing()); 1487 if (audioDevice->Playing()) 1488 { 1489 TEST_LOG("\n> Listen to the file being played out and verify that the " 1490 "selected speaker volume is varied between [~0] and [~MAX].\n" 1491 "> The file shall be played out with an increasing volume level " 1492 "correlated to the speaker volume.\n" 1493 "> Press any key to stop playing...\n \n"); 1494 PAUSE(10000); 1495 } 1496 1497 EXPECT_EQ(0, audioDevice->StopPlayout()); 1498 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(NULL)); 1499 1500 _audioTransport->SetSpeakerVolume(false); 1501 _audioTransport->SetFilePlayout(false); 1502 1503 // restore volume setting 1504 EXPECT_EQ(0, audioDevice->SetSpeakerVolume(startVolume)); 1505 1506 TEST_LOG("\n"); 1507 PRINT_TEST_RESULTS; 1508 1509 return 0; 1510 } 1511 1512 int32_t FuncTestManager::TestSpeakerMute() 1513 { 1514 TEST_LOG("\n=======================================\n"); 1515 TEST_LOG(" Speaker Mute test:\n"); 1516 TEST_LOG("=======================================\n"); 1517 1518 if (_audioDevice == NULL) 1519 { 1520 return -1; 1521 } 1522 1523 RESET_TEST; 1524 1525 AudioDeviceModule* audioDevice = _audioDevice; 1526 1527 EXPECT_EQ(0, audioDevice->Init()); 1528 EXPECT_TRUE(audioDevice->Initialized()); 1529 1530 if (SelectPlayoutDevice() == -1) 1531 { 1532 TEST_LOG("\nERROR: Device selection failed!\n \n"); 1533 return -1; 1534 } 1535 1536 bool available(false); 1537 bool startMute(false); 1538 uint32_t samplesPerSec(0); 1539 1540 EXPECT_EQ(0, audioDevice->SpeakerMuteIsAvailable(&available)); 1541 if (available) 1542 { 1543 _audioTransport->SetSpeakerMute(true); 1544 } else 1545 { 1546 TEST_LOG( 1547 "\nERROR: Mute control is not available for the selected" 1548 " device!\n \n"); 1549 return -1; 1550 } 1551 1552 // store initial mute setting 1553 EXPECT_EQ(0, audioDevice->InitSpeaker()); 1554 EXPECT_EQ(0, audioDevice->SpeakerMute(&startMute)); 1555 1556 // start with no mute 1557 EXPECT_EQ(0, audioDevice->SetSpeakerMute(false)); 1558 1559 // ====================================== 1560 // Start playing out an existing PCM file 1561 1562 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(_audioTransport)); 1563 EXPECT_EQ(0, audioDevice->PlayoutIsAvailable(&available)); 1564 if (available) 1565 { 1566 EXPECT_EQ(0, audioDevice->InitPlayout()); 1567 EXPECT_EQ(0, audioDevice->PlayoutSampleRate(&samplesPerSec)); 1568 if (48000 == samplesPerSec) 1569 _audioTransport->SetFilePlayout(true, _playoutFile48.c_str()); 1570 else if (44100 == samplesPerSec || 44000 == samplesPerSec) 1571 _audioTransport->SetFilePlayout(true, _playoutFile44.c_str()); 1572 else 1573 { 1574 TEST_LOG("\nERROR: Sample rate (%d) is not supported!\n \n", 1575 samplesPerSec); 1576 return -1; 1577 } 1578 EXPECT_EQ(0, audioDevice->StartPlayout()); 1579 } 1580 1581 EXPECT_TRUE(audioDevice->Playing()); 1582 if (audioDevice->Playing()) 1583 { 1584 TEST_LOG("\n> Listen to the file being played out and verify that the" 1585 " selected speaker mute control is toggled between [MUTE ON] and" 1586 " [MUTE OFF].\n> You should only hear the file during the" 1587 " 'MUTE OFF' periods.\n" 1588 "> Press any key to stop playing...\n \n"); 1589 PAUSE(DEFAULT_PAUSE_TIME); 1590 } 1591 1592 EXPECT_EQ(0, audioDevice->StopPlayout()); 1593 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(NULL)); 1594 1595 _audioTransport->SetSpeakerMute(false); 1596 _audioTransport->SetFilePlayout(false); 1597 1598 // restore mute setting 1599 EXPECT_EQ(0, audioDevice->SetSpeakerMute(startMute)); 1600 1601 TEST_LOG("\n"); 1602 PRINT_TEST_RESULTS; 1603 1604 return 0; 1605 } 1606 1607 int32_t FuncTestManager::TestMicrophoneVolume() 1608 { 1609 TEST_LOG("\n=======================================\n"); 1610 TEST_LOG(" Microphone Volume test:\n"); 1611 TEST_LOG("=======================================\n"); 1612 1613 if (_audioDevice == NULL) 1614 { 1615 return -1; 1616 } 1617 1618 RESET_TEST; 1619 1620 AudioDeviceModule* audioDevice = _audioDevice; 1621 1622 EXPECT_EQ(0, audioDevice->Init()); 1623 EXPECT_TRUE(audioDevice->Initialized()); 1624 1625 if (SelectRecordingDevice() == -1) 1626 { 1627 TEST_LOG("\nERROR: Device selection failed!\n \n"); 1628 return -1; 1629 } 1630 1631 bool available(false); 1632 EXPECT_EQ(0, audioDevice->MicrophoneVolumeIsAvailable(&available)); 1633 if (available) 1634 { 1635 _audioTransport->SetMicrophoneVolume(true); 1636 } else 1637 { 1638 TEST_LOG("\nERROR: Volume control is not available for the selected " 1639 "device!\n \n"); 1640 return -1; 1641 } 1642 1643 if (SelectPlayoutDevice() == -1) 1644 { 1645 TEST_LOG("\nERROR: Device selection failed!\n \n"); 1646 return -1; 1647 } 1648 1649 EXPECT_EQ(0, audioDevice->PlayoutIsAvailable(&available)); 1650 if (available) 1651 { 1652 _audioTransport->SetFullDuplex(true); 1653 } else 1654 { 1655 TEST_LOG("\nERROR: Playout is not available for the selected " 1656 "device!\n \n"); 1657 return -1; 1658 } 1659 1660 TEST_LOG("\nEnable recording of microphone input to file (%s) during this" 1661 " test (Y/N)?\n: ", 1662 RecordedMicrophoneVolumeFile); 1663 char ch; 1664 bool fileRecording(false); 1665 EXPECT_TRUE(scanf(" %c", &ch) > 0); 1666 ch = toupper(ch); 1667 if (ch == 'Y') 1668 { 1669 fileRecording = true; 1670 } 1671 1672 uint32_t startVolume(0); 1673 bool enabled(false); 1674 1675 // store initial volume setting 1676 EXPECT_EQ(0, audioDevice->InitMicrophone()); 1677 EXPECT_EQ(0, audioDevice->MicrophoneVolume(&startVolume)); 1678 1679 // start at volume 0 1680 EXPECT_EQ(0, audioDevice->SetMicrophoneVolume(0)); 1681 1682 // ====================================================================== 1683 // Start recording from the microphone while the mic volume is changed 1684 // continuously. 1685 // Also, start playing out the input to enable real-time verification. 1686 1687 if (fileRecording) 1688 { 1689 EXPECT_EQ(0, audioDevice->StartRawInputFileRecording(RecordedMicrophoneVolumeFile)); 1690 } 1691 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(_audioTransport)); 1692 EXPECT_EQ(0, audioDevice->RecordingIsAvailable(&available)); 1693 if (available) 1694 { 1695 EXPECT_EQ(0, audioDevice->InitRecording()); 1696 EXPECT_EQ(0, audioDevice->StereoRecording(&enabled)); 1697 if (enabled) 1698 { 1699 // ensures a mono file 1700 EXPECT_EQ(0, audioDevice->SetRecordingChannel(AudioDeviceModule::kChannelRight)); 1701 } 1702 EXPECT_EQ(0, audioDevice->StartRecording()); 1703 } 1704 EXPECT_EQ(0, audioDevice->PlayoutIsAvailable(&available)); 1705 if (available) 1706 { 1707 EXPECT_EQ(0, audioDevice->InitPlayout()); 1708 EXPECT_EQ(0, audioDevice->StartPlayout()); 1709 } 1710 1711 EXPECT_TRUE(audioDevice->Recording()); 1712 EXPECT_TRUE(audioDevice->Playing()); 1713 if (audioDevice->Recording() && audioDevice->Playing()) 1714 { 1715 TEST_LOG("\n> Speak into the microphone and verify that the selected " 1716 "microphone volume is varied between [~0] and [~MAX].\n" 1717 "> You should hear your own voice with an increasing volume level" 1718 " correlated to the microphone volume.\n" 1719 "> After a finalized test (and if file recording was enabled) " 1720 "verify the recorded result off line.\n" 1721 "> Press any key to stop...\n \n"); 1722 PAUSE(DEFAULT_PAUSE_TIME); 1723 } 1724 1725 if (fileRecording) 1726 { 1727 EXPECT_EQ(0, audioDevice->StopRawInputFileRecording()); 1728 } 1729 EXPECT_EQ(0, audioDevice->StopRecording()); 1730 EXPECT_EQ(0, audioDevice->StopPlayout()); 1731 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(NULL)); 1732 EXPECT_EQ(0, audioDevice->StereoRecordingIsAvailable(&available)); 1733 1734 _audioTransport->SetMicrophoneVolume(false); 1735 _audioTransport->SetFullDuplex(false); 1736 1737 // restore volume setting 1738 EXPECT_EQ(0, audioDevice->SetMicrophoneVolume(startVolume)); 1739 1740 TEST_LOG("\n"); 1741 PRINT_TEST_RESULTS; 1742 1743 return 0; 1744 } 1745 1746 int32_t FuncTestManager::TestMicrophoneMute() 1747 { 1748 TEST_LOG("\n=======================================\n"); 1749 TEST_LOG(" Microphone Mute test:\n"); 1750 TEST_LOG("=======================================\n"); 1751 1752 if (_audioDevice == NULL) 1753 { 1754 return -1; 1755 } 1756 1757 RESET_TEST; 1758 1759 AudioDeviceModule* audioDevice = _audioDevice; 1760 1761 EXPECT_EQ(0, audioDevice->Init()); 1762 EXPECT_TRUE(audioDevice->Initialized()); 1763 1764 if (SelectRecordingDevice() == -1) 1765 { 1766 TEST_LOG("\nERROR: Device selection failed!\n \n"); 1767 return -1; 1768 } 1769 1770 bool available(false); 1771 EXPECT_EQ(0, audioDevice->MicrophoneMuteIsAvailable(&available)); 1772 if (available) 1773 { 1774 _audioTransport->SetMicrophoneMute(true); 1775 } else 1776 { 1777 TEST_LOG("\nERROR: Mute control is not available for the selected" 1778 " device!\n \n"); 1779 return -1; 1780 } 1781 1782 if (SelectPlayoutDevice() == -1) 1783 { 1784 TEST_LOG("\nERROR: Device selection failed!\n \n"); 1785 return -1; 1786 } 1787 1788 EXPECT_EQ(0, audioDevice->PlayoutIsAvailable(&available)); 1789 if (available) 1790 { 1791 _audioTransport->SetFullDuplex(true); 1792 } else 1793 { 1794 TEST_LOG("\nERROR: Playout is not available for the selected " 1795 "device!\n \n"); 1796 return -1; 1797 } 1798 1799 TEST_LOG("\nEnable recording of microphone input to file (%s) during this " 1800 "test (Y/N)?\n: ", 1801 RecordedMicrophoneMuteFile); 1802 char ch; 1803 bool fileRecording(false); 1804 EXPECT_TRUE(scanf(" %c", &ch) > 0); 1805 ch = toupper(ch); 1806 if (ch == 'Y') 1807 { 1808 fileRecording = true; 1809 } 1810 1811 bool startMute(false); 1812 bool enabled(false); 1813 1814 // store initial volume setting 1815 EXPECT_EQ(0, audioDevice->InitMicrophone()); 1816 EXPECT_EQ(0, audioDevice->MicrophoneMute(&startMute)); 1817 1818 // start at no mute 1819 EXPECT_EQ(0, audioDevice->SetMicrophoneMute(false)); 1820 1821 // ================================================================== 1822 // Start recording from the microphone while the mic mute is toggled 1823 // continuously. 1824 // Also, start playing out the input to enable real-time verification. 1825 1826 if (fileRecording) 1827 { 1828 EXPECT_EQ(0, audioDevice->StartRawInputFileRecording(RecordedMicrophoneMuteFile)); 1829 } 1830 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(_audioTransport)); 1831 EXPECT_EQ(0, audioDevice->RecordingIsAvailable(&available)); 1832 if (available) 1833 { 1834 EXPECT_EQ(0, audioDevice->InitRecording()); 1835 EXPECT_EQ(0, audioDevice->StereoRecording(&enabled)); 1836 if (enabled) 1837 { 1838 // ensure file recording in mono 1839 EXPECT_EQ(0, audioDevice->SetRecordingChannel(AudioDeviceModule::kChannelLeft)); 1840 } 1841 EXPECT_EQ(0, audioDevice->StartRecording()); 1842 } 1843 EXPECT_EQ(0, audioDevice->PlayoutIsAvailable(&available)); 1844 if (available) 1845 { 1846 EXPECT_EQ(0, audioDevice->InitPlayout()); 1847 EXPECT_EQ(0, audioDevice->StartPlayout()); 1848 } 1849 1850 EXPECT_TRUE(audioDevice->Recording()); 1851 EXPECT_TRUE(audioDevice->Playing()); 1852 if (audioDevice->Recording() && audioDevice->Playing()) 1853 { 1854 TEST_LOG("\n> Speak into the microphone and verify that the selected " 1855 "microphone mute control is toggled between [MUTE ON] and [MUTE OFF]." 1856 "\n> You should only hear your own voice in loopback during the" 1857 " 'MUTE OFF' periods.\n> After a finalized test (and if file " 1858 "recording was enabled) verify the recorded result off line.\n" 1859 "> Press any key to stop...\n \n"); 1860 PAUSE(DEFAULT_PAUSE_TIME); 1861 } 1862 1863 if (fileRecording) 1864 { 1865 EXPECT_EQ(0, audioDevice->StopRawInputFileRecording()); 1866 } 1867 EXPECT_EQ(0, audioDevice->StopRecording()); 1868 EXPECT_EQ(0, audioDevice->StopPlayout()); 1869 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(NULL)); 1870 1871 _audioTransport->SetMicrophoneMute(false); 1872 _audioTransport->SetFullDuplex(false); 1873 1874 // restore volume setting 1875 EXPECT_EQ(0, audioDevice->SetMicrophoneMute(startMute)); 1876 1877 TEST_LOG("\n"); 1878 PRINT_TEST_RESULTS; 1879 1880 return 0; 1881 } 1882 1883 int32_t FuncTestManager::TestMicrophoneBoost() 1884 { 1885 TEST_LOG("\n=======================================\n"); 1886 TEST_LOG(" Microphone Boost test:\n"); 1887 TEST_LOG("=======================================\n"); 1888 1889 if (_audioDevice == NULL) 1890 { 1891 return -1; 1892 } 1893 1894 RESET_TEST; 1895 1896 AudioDeviceModule* audioDevice = _audioDevice; 1897 1898 EXPECT_EQ(0, audioDevice->Init()); 1899 EXPECT_TRUE(audioDevice->Initialized()); 1900 1901 if (SelectRecordingDevice() == -1) 1902 { 1903 TEST_LOG("\nERROR: Device selection failed!\n \n"); 1904 return -1; 1905 } 1906 1907 bool available(false); 1908 EXPECT_EQ(0, audioDevice->MicrophoneBoostIsAvailable(&available)); 1909 if (available) 1910 { 1911 _audioTransport->SetMicrophoneBoost(true); 1912 } else 1913 { 1914 TEST_LOG( 1915 "\nERROR: Boost control is not available for the selected device!\n \n"); 1916 return -1; 1917 } 1918 1919 if (SelectPlayoutDevice() == -1) 1920 { 1921 TEST_LOG("\nERROR: Device selection failed!\n \n"); 1922 return -1; 1923 } 1924 1925 EXPECT_EQ(0, audioDevice->PlayoutIsAvailable(&available)); 1926 if (available) 1927 { 1928 _audioTransport->SetFullDuplex(true); 1929 } else 1930 { 1931 TEST_LOG("\nERROR: Playout is not available for the selected device!\n \n"); 1932 return -1; 1933 } 1934 1935 TEST_LOG("\nEnable recording of microphone input to file (%s) during this " 1936 "test (Y/N)?\n: ", 1937 RecordedMicrophoneBoostFile); 1938 char ch; 1939 bool fileRecording(false); 1940 EXPECT_TRUE(scanf(" %c", &ch) > 0); 1941 ch = toupper(ch); 1942 if (ch == 'Y') 1943 { 1944 fileRecording = true; 1945 } 1946 1947 bool startBoost(false); 1948 bool enabled(false); 1949 1950 // store initial volume setting 1951 EXPECT_EQ(0, audioDevice->InitMicrophone()); 1952 EXPECT_EQ(0, audioDevice->MicrophoneBoost(&startBoost)); 1953 1954 // start at no boost 1955 EXPECT_EQ(0, audioDevice->SetMicrophoneBoost(false)); 1956 1957 // ================================================================== 1958 // Start recording from the microphone while the mic boost is toggled 1959 // continuously. 1960 // Also, start playing out the input to enable real-time verification. 1961 1962 if (fileRecording) 1963 { 1964 EXPECT_EQ(0, audioDevice->StartRawInputFileRecording(RecordedMicrophoneBoostFile)); 1965 } 1966 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(_audioTransport)); 1967 EXPECT_EQ(0, audioDevice->RecordingIsAvailable(&available)); 1968 if (available) 1969 { 1970 EXPECT_EQ(0, audioDevice->InitRecording()); 1971 EXPECT_EQ(0, audioDevice->StereoRecording(&enabled)); 1972 if (enabled) 1973 { 1974 // ensure file recording in mono 1975 EXPECT_EQ(0, audioDevice->SetRecordingChannel(AudioDeviceModule::kChannelLeft)); 1976 } 1977 EXPECT_EQ(0, audioDevice->StartRecording()); 1978 } 1979 EXPECT_EQ(0, audioDevice->PlayoutIsAvailable(&available)); 1980 if (available) 1981 { 1982 EXPECT_EQ(0, audioDevice->InitPlayout()); 1983 EXPECT_EQ(0, audioDevice->StartPlayout()); 1984 } 1985 1986 EXPECT_TRUE(audioDevice->Recording()); 1987 EXPECT_TRUE(audioDevice->Playing()); 1988 if (audioDevice->Recording() && audioDevice->Playing()) 1989 { 1990 TEST_LOG("\n> Speak into the microphone and verify that the selected " 1991 "microphone boost control is toggled between [BOOST ON] and [BOOST OFF].\n" 1992 "> You should hear your own voice with an increased volume level " 1993 "during the 'BOOST ON' periods.\n \n" 1994 "> After a finalized test (and if file recording was enabled) verify" 1995 " the recorded result off line.\n" 1996 "> Press any key to stop...\n \n"); 1997 PAUSE(DEFAULT_PAUSE_TIME); 1998 } 1999 2000 if (fileRecording) 2001 { 2002 EXPECT_EQ(0, audioDevice->StopRawInputFileRecording()); 2003 } 2004 EXPECT_EQ(0, audioDevice->StopRecording()); 2005 EXPECT_EQ(0, audioDevice->StopPlayout()); 2006 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(NULL)); 2007 2008 _audioTransport->SetMicrophoneBoost(false); 2009 _audioTransport->SetFullDuplex(false); 2010 2011 // restore boost setting 2012 EXPECT_EQ(0, audioDevice->SetMicrophoneBoost(startBoost)); 2013 2014 TEST_LOG("\n"); 2015 PRINT_TEST_RESULTS; 2016 2017 return 0; 2018 } 2019 2020 int32_t FuncTestManager::TestMicrophoneAGC() 2021 { 2022 TEST_LOG("\n=======================================\n"); 2023 TEST_LOG(" Microphone AGC test:\n"); 2024 TEST_LOG("=======================================\n"); 2025 2026 if (_audioDevice == NULL) 2027 { 2028 return -1; 2029 } 2030 2031 RESET_TEST; 2032 2033 AudioDeviceModule* audioDevice = _audioDevice; 2034 2035 EXPECT_EQ(0, audioDevice->Init()); 2036 EXPECT_TRUE(audioDevice->Initialized()); 2037 2038 if (SelectRecordingDevice() == -1) 2039 { 2040 TEST_LOG("\nERROR: Device selection failed!\n \n"); 2041 return -1; 2042 } 2043 2044 bool available(false); 2045 EXPECT_EQ(0, audioDevice->MicrophoneVolumeIsAvailable(&available)); 2046 if (available) 2047 { 2048 _audioTransport->SetMicrophoneAGC(true); 2049 } else 2050 { 2051 TEST_LOG("\nERROR: It is not possible to control the microphone volume" 2052 " for the selected device!\n \n"); 2053 return -1; 2054 } 2055 2056 if (SelectPlayoutDevice() == -1) 2057 { 2058 TEST_LOG("\nERROR: Device selection failed!\n \n"); 2059 return -1; 2060 } 2061 2062 EXPECT_EQ(0, audioDevice->PlayoutIsAvailable(&available)); 2063 if (available) 2064 { 2065 _audioTransport->SetFullDuplex(true); 2066 } else 2067 { 2068 TEST_LOG("\nERROR: Playout is not available for the selected device!\n \n"); 2069 return -1; 2070 } 2071 2072 TEST_LOG("\nEnable recording of microphone input to file (%s) during " 2073 "this test (Y/N)?\n: ", 2074 RecordedMicrophoneAGCFile); 2075 char ch; 2076 bool fileRecording(false); 2077 EXPECT_TRUE(scanf(" %c", &ch) > 0); 2078 ch = toupper(ch); 2079 if (ch == 'Y') 2080 { 2081 fileRecording = true; 2082 } 2083 2084 uint32_t startVolume(0); 2085 bool enabled(false); 2086 2087 // store initial volume setting 2088 EXPECT_EQ(0, audioDevice->InitMicrophone()); 2089 EXPECT_EQ(0, audioDevice->MicrophoneVolume(&startVolume)); 2090 2091 // ==================================================================== 2092 // Start recording from the microphone while the mic volume is changed 2093 // continuously 2094 // by the emulated AGC (implemented by our audio transport). 2095 // Also, start playing out the input to enable real-time verification. 2096 2097 if (fileRecording) 2098 { 2099 EXPECT_EQ(0, audioDevice->StartRawInputFileRecording(RecordedMicrophoneAGCFile)); 2100 } 2101 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(_audioTransport)); 2102 EXPECT_EQ(0, audioDevice->RecordingIsAvailable(&available)); 2103 if (available) 2104 { 2105 EXPECT_EQ(0, audioDevice->SetAGC(true)); 2106 EXPECT_EQ(0, audioDevice->InitRecording()); 2107 EXPECT_EQ(0, audioDevice->StereoRecording(&enabled)); 2108 if (enabled) 2109 { 2110 // ensures a mono file 2111 EXPECT_EQ(0, audioDevice->SetRecordingChannel(AudioDeviceModule::kChannelRight)); 2112 } 2113 EXPECT_EQ(0, audioDevice->StartRecording()); 2114 } 2115 EXPECT_EQ(0, audioDevice->PlayoutIsAvailable(&available)); 2116 if (available) 2117 { 2118 EXPECT_EQ(0, audioDevice->InitPlayout()); 2119 EXPECT_EQ(0, audioDevice->StartPlayout()); 2120 } 2121 2122 EXPECT_TRUE(audioDevice->AGC()); 2123 EXPECT_TRUE(audioDevice->Recording()); 2124 EXPECT_TRUE(audioDevice->Playing()); 2125 if (audioDevice->Recording() && audioDevice->Playing()) 2126 { 2127 TEST_LOG("\n> Speak into the microphone and verify that the volume of" 2128 " the selected microphone is varied between [~0] and [~MAX].\n" 2129 "> You should hear your own voice with an increasing volume level" 2130 " correlated to an emulated AGC setting.\n" 2131 "> After a finalized test (and if file recording was enabled) verify" 2132 " the recorded result off line.\n" 2133 "> Press any key to stop...\n \n"); 2134 PAUSE(DEFAULT_PAUSE_TIME); 2135 } 2136 2137 if (fileRecording) 2138 { 2139 EXPECT_EQ(0, audioDevice->StopRawInputFileRecording()); 2140 } 2141 EXPECT_EQ(0, audioDevice->SetAGC(false)); 2142 EXPECT_EQ(0, audioDevice->StopRecording()); 2143 EXPECT_EQ(0, audioDevice->StopPlayout()); 2144 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(NULL)); 2145 EXPECT_EQ(0, audioDevice->StereoRecordingIsAvailable(&available)); 2146 2147 _audioTransport->SetMicrophoneAGC(false); 2148 _audioTransport->SetFullDuplex(false); 2149 2150 // restore volume setting 2151 EXPECT_EQ(0, audioDevice->SetMicrophoneVolume(startVolume)); 2152 2153 TEST_LOG("\n"); 2154 PRINT_TEST_RESULTS; 2155 2156 return 0; 2157 } 2158 2159 int32_t FuncTestManager::TestLoopback() 2160 { 2161 TEST_LOG("\n=======================================\n"); 2162 TEST_LOG(" Loopback measurement test:\n"); 2163 TEST_LOG("=======================================\n"); 2164 2165 if (_audioDevice == NULL) 2166 { 2167 return -1; 2168 } 2169 2170 RESET_TEST; 2171 2172 AudioDeviceModule* audioDevice = _audioDevice; 2173 2174 EXPECT_EQ(0, audioDevice->Init()); 2175 EXPECT_TRUE(audioDevice->Initialized()); 2176 2177 bool recIsAvailable(false); 2178 bool playIsAvailable(false); 2179 uint8_t nPlayChannels(0); 2180 uint8_t nRecChannels(0); 2181 2182 if (SelectRecordingDevice() == -1) 2183 { 2184 TEST_LOG("\nERROR: Device selection failed!\n \n"); 2185 return -1; 2186 } 2187 2188 EXPECT_EQ(0, audioDevice->RecordingIsAvailable(&recIsAvailable)); 2189 if (!recIsAvailable) 2190 { 2191 TEST_LOG("\nERROR: Recording is not available for the selected device!\n \n"); 2192 return -1; 2193 } 2194 2195 if (SelectPlayoutDevice() == -1) 2196 { 2197 TEST_LOG("\nERROR: Device selection failed!\n \n"); 2198 return -1; 2199 } 2200 2201 EXPECT_EQ(0, audioDevice->PlayoutIsAvailable(&playIsAvailable)); 2202 if (recIsAvailable && playIsAvailable) 2203 { 2204 _audioTransport->SetFullDuplex(true); 2205 _audioTransport->SetLoopbackMeasurements(true); 2206 } else if (!playIsAvailable) 2207 { 2208 TEST_LOG("\nERROR: Playout is not available for the selected device!\n \n"); 2209 return -1; 2210 } 2211 2212 bool enabled(false); 2213 bool available(false); 2214 2215 if (recIsAvailable && playIsAvailable) 2216 { 2217 uint32_t playSamplesPerSec(0); 2218 uint32_t recSamplesPerSecRec(0); 2219 2220 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(_audioTransport)); 2221 2222 _audioTransport->SetFullDuplex(true); 2223 2224 EXPECT_EQ(0, audioDevice->StereoRecordingIsAvailable(&available)); 2225 if (available) 2226 { 2227 EXPECT_EQ(0, audioDevice->SetStereoRecording(true)); 2228 } 2229 2230 EXPECT_EQ(0, audioDevice->StereoPlayoutIsAvailable(&available)); 2231 if (available) 2232 { 2233 EXPECT_EQ(0, audioDevice->SetStereoPlayout(true)); 2234 } 2235 2236 EXPECT_EQ(0, audioDevice->MicrophoneVolumeIsAvailable(&available)); 2237 if (available) 2238 { 2239 uint32_t maxVolume(0); 2240 EXPECT_EQ(0, audioDevice->MaxMicrophoneVolume(&maxVolume)); 2241 EXPECT_EQ(0, audioDevice->SetMicrophoneVolume(maxVolume)); 2242 } 2243 2244 EXPECT_EQ(0, audioDevice->InitRecording()); 2245 EXPECT_EQ(0, audioDevice->InitPlayout()); 2246 EXPECT_EQ(0, audioDevice->PlayoutSampleRate(&playSamplesPerSec)); 2247 EXPECT_EQ(0, audioDevice->RecordingSampleRate(&recSamplesPerSecRec)); 2248 EXPECT_EQ(0, audioDevice->StereoPlayout(&enabled)); 2249 enabled ? nPlayChannels = 2 : nPlayChannels = 1; 2250 EXPECT_EQ(0, audioDevice->StereoRecording(&enabled)); 2251 enabled ? nRecChannels = 2 : nRecChannels = 1; 2252 EXPECT_EQ(0, audioDevice->StartRecording()); 2253 EXPECT_EQ(0, audioDevice->StartPlayout()); 2254 2255 if (audioDevice->Playing() && audioDevice->Recording()) 2256 { 2257 TEST_LOG("\n \n> Loopback audio is now active.\n" 2258 "> Rec : fs=%u, #channels=%u.\n" 2259 "> Play: fs=%u, #channels=%u.\n" 2260 "> Speak into the microphone and verify that your voice is" 2261 " played out in loopback.\n" 2262 "> Press any key to stop...\n \n", 2263 recSamplesPerSecRec, nRecChannels, playSamplesPerSec, 2264 nPlayChannels); 2265 PAUSE(30000); 2266 } 2267 2268 EXPECT_EQ(0, audioDevice->StopRecording()); 2269 EXPECT_EQ(0, audioDevice->StopPlayout()); 2270 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(NULL)); 2271 2272 _audioTransport->SetFullDuplex(false); 2273 _audioTransport->SetLoopbackMeasurements(false); 2274 } 2275 2276 EXPECT_EQ(0, audioDevice->Terminate()); 2277 EXPECT_FALSE(audioDevice->Initialized()); 2278 2279 TEST_LOG("\n"); 2280 PRINT_TEST_RESULTS; 2281 2282 return 0; 2283 } 2284 2285 int32_t FuncTestManager::TestDeviceRemoval() 2286 { 2287 TEST_LOG("\n=======================================\n"); 2288 TEST_LOG(" Device removal test:\n"); 2289 TEST_LOG("=======================================\n"); 2290 2291 if (_audioDevice == NULL) 2292 { 2293 return -1; 2294 } 2295 2296 RESET_TEST; 2297 2298 AudioDeviceModule* audioDevice = _audioDevice; 2299 2300 EXPECT_EQ(0, audioDevice->Init()); 2301 EXPECT_TRUE(audioDevice->Initialized()); 2302 2303 bool recIsAvailable(false); 2304 bool playIsAvailable(false); 2305 uint8_t nPlayChannels(0); 2306 uint8_t nRecChannels(0); 2307 uint8_t loopCount(0); 2308 2309 while (loopCount < 2) 2310 { 2311 if (SelectRecordingDevice() == -1) 2312 { 2313 TEST_LOG("\nERROR: Device selection failed!\n \n"); 2314 return -1; 2315 } 2316 2317 EXPECT_EQ(0, audioDevice->RecordingIsAvailable(&recIsAvailable)); 2318 if (!recIsAvailable) 2319 { 2320 TEST_LOG("\nERROR: Recording is not available for the selected device!\n \n"); 2321 return -1; 2322 } 2323 2324 if (SelectPlayoutDevice() == -1) 2325 { 2326 TEST_LOG("\nERROR: Device selection failed!\n \n"); 2327 return -1; 2328 } 2329 2330 EXPECT_EQ(0, audioDevice->PlayoutIsAvailable(&playIsAvailable)); 2331 if (recIsAvailable && playIsAvailable) 2332 { 2333 _audioTransport->SetFullDuplex(true); 2334 } else if (!playIsAvailable) 2335 { 2336 TEST_LOG("\nERROR: Playout is not available for the selected device!\n \n"); 2337 return -1; 2338 } 2339 2340 bool available(false); 2341 bool enabled(false); 2342 2343 if (recIsAvailable && playIsAvailable) 2344 { 2345 uint32_t playSamplesPerSec(0); 2346 uint32_t recSamplesPerSecRec(0); 2347 2348 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(_audioTransport)); 2349 2350 _audioTransport->SetFullDuplex(true); 2351 2352 EXPECT_EQ(0, audioDevice->StereoRecordingIsAvailable(&available)); 2353 if (available) 2354 { 2355 EXPECT_EQ(0, audioDevice->SetStereoRecording(true)); 2356 } 2357 2358 EXPECT_EQ(0, audioDevice->StereoPlayoutIsAvailable(&available)); 2359 if (available) 2360 { 2361 EXPECT_EQ(0, audioDevice->SetStereoPlayout(true)); 2362 } 2363 2364 EXPECT_EQ(0, audioDevice->MicrophoneVolumeIsAvailable(&available)); 2365 if (available) 2366 { 2367 uint32_t maxVolume(0); 2368 EXPECT_EQ(0, audioDevice->MaxMicrophoneVolume(&maxVolume)); 2369 EXPECT_EQ(0, audioDevice->SetMicrophoneVolume(maxVolume)); 2370 } 2371 2372 EXPECT_EQ(0, audioDevice->InitRecording()); 2373 EXPECT_EQ(0, audioDevice->InitPlayout()); 2374 EXPECT_EQ(0, audioDevice->PlayoutSampleRate(&playSamplesPerSec)); 2375 EXPECT_EQ(0, audioDevice->RecordingSampleRate(&recSamplesPerSecRec)); 2376 EXPECT_EQ(0, audioDevice->StereoPlayout(&enabled)); 2377 enabled ? nPlayChannels = 2 : nPlayChannels = 1; 2378 EXPECT_EQ(0, audioDevice->StereoRecording(&enabled)); 2379 enabled ? nRecChannels = 2 : nRecChannels = 1; 2380 EXPECT_EQ(0, audioDevice->StartRecording()); 2381 EXPECT_EQ(0, audioDevice->StartPlayout()); 2382 2383 AudioDeviceModule::AudioLayer audioLayer; 2384 EXPECT_EQ(0, audioDevice->ActiveAudioLayer(&audioLayer)); 2385 2386 if (audioLayer == AudioDeviceModule::kLinuxPulseAudio) 2387 { 2388 TEST_LOG("\n \n> PulseAudio loopback audio is now active.\n" 2389 "> Rec : fs=%u, #channels=%u.\n" 2390 "> Play: fs=%u, #channels=%u.\n" 2391 "> Speak into the microphone and verify that your voice is" 2392 " played out in loopback.\n" 2393 "> Unplug the device and make sure that your voice is played" 2394 " out in loop back on the built-in soundcard.\n" 2395 "> Then press any key...\n", 2396 recSamplesPerSecRec, nRecChannels, playSamplesPerSec, 2397 nPlayChannels); 2398 2399 PAUSE(DEFAULT_PAUSE_TIME); 2400 } else if (audioDevice->Playing() && audioDevice->Recording()) 2401 { 2402 if (loopCount < 1) 2403 { 2404 TEST_LOG("\n \n> Loopback audio is now active.\n" 2405 "> Rec : fs=%u, #channels=%u.\n" 2406 "> Play: fs=%u, #channels=%u.\n" 2407 "> Speak into the microphone and verify that your voice" 2408 " is played out in loopback.\n" 2409 "> Unplug the device and wait for the error message...\n", 2410 recSamplesPerSecRec, nRecChannels, 2411 playSamplesPerSec, nPlayChannels); 2412 2413 _audioEventObserver->_error 2414 = (AudioDeviceObserver::ErrorCode) (-1); 2415 while (_audioEventObserver->_error 2416 == (AudioDeviceObserver::ErrorCode) (-1)) 2417 { 2418 SleepMs(500); 2419 } 2420 } else 2421 { 2422 TEST_LOG("\n \n> Loopback audio is now active.\n" 2423 "> Rec : fs=%u, #channels=%u.\n" 2424 "> Play: fs=%u, #channels=%u.\n" 2425 "> Speak into the microphone and verify that your voice" 2426 " is played out in loopback.\n" 2427 "> Press any key to stop...\n", 2428 recSamplesPerSecRec, nRecChannels, 2429 playSamplesPerSec, nPlayChannels); 2430 2431 PAUSE(DEFAULT_PAUSE_TIME); 2432 } 2433 } 2434 2435 EXPECT_EQ(0, audioDevice->StopRecording()); 2436 EXPECT_EQ(0, audioDevice->StopPlayout()); 2437 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(NULL)); 2438 2439 _audioTransport->SetFullDuplex(false); 2440 2441 if (loopCount < 1) 2442 { 2443 TEST_LOG("\n \n> Stopped!\n"); 2444 TEST_LOG("> Now reinsert device if you want to enumerate it.\n"); 2445 TEST_LOG("> Press any key when done.\n"); 2446 PAUSE(DEFAULT_PAUSE_TIME); 2447 } 2448 2449 loopCount++; 2450 } 2451 } // loopCount 2452 2453 EXPECT_EQ(0, audioDevice->Terminate()); 2454 EXPECT_FALSE(audioDevice->Initialized()); 2455 2456 TEST_LOG("\n"); 2457 PRINT_TEST_RESULTS; 2458 2459 return 0; 2460 } 2461 2462 int32_t FuncTestManager::TestExtra() 2463 { 2464 TEST_LOG("\n=======================================\n"); 2465 TEST_LOG(" Extra test:\n"); 2466 TEST_LOG("=======================================\n"); 2467 2468 if (_audioDevice == NULL) 2469 { 2470 return -1; 2471 } 2472 2473 RESET_TEST; 2474 2475 AudioDeviceModule* audioDevice = _audioDevice; 2476 2477 EXPECT_EQ(0, audioDevice->Init()); 2478 EXPECT_TRUE(audioDevice->Initialized()); 2479 2480 EXPECT_EQ(0, audioDevice->Terminate()); 2481 EXPECT_FALSE(audioDevice->Initialized()); 2482 2483 TEST_LOG("\n"); 2484 PRINT_TEST_RESULTS; 2485 2486 return 0; 2487 } 2488 2489 int32_t FuncTestManager::SelectRecordingDevice() 2490 { 2491 int16_t nDevices = _audioDevice->RecordingDevices(); 2492 char name[kAdmMaxDeviceNameSize]; 2493 char guid[kAdmMaxGuidSize]; 2494 int32_t ret(-1); 2495 2496 #ifdef _WIN32 2497 TEST_LOG("\nSelect Recording Device\n \n"); 2498 TEST_LOG(" (%d) Default\n", 0); 2499 TEST_LOG(" (%d) Default Communication [Win 7]\n", 1); 2500 TEST_LOG("- - - - - - - - - - - - - - - - - - - -\n"); 2501 for (int i = 0; i < nDevices; i++) 2502 { 2503 EXPECT_EQ(0, _audioDevice->RecordingDeviceName(i, name, guid)); 2504 TEST_LOG(" (%d) Device %d (%s)\n", i+10, i, name); 2505 } 2506 TEST_LOG("\n: "); 2507 2508 int sel(0); 2509 2510 scanf("%u", &sel); 2511 2512 if (sel == 0) 2513 { 2514 EXPECT_EQ(0, (ret = _audioDevice->SetRecordingDevice(AudioDeviceModule::kDefaultDevice))); 2515 } 2516 else if (sel == 1) 2517 { 2518 EXPECT_TRUE((ret = _audioDevice->SetRecordingDevice( 2519 AudioDeviceModule::kDefaultCommunicationDevice)) == 0); 2520 } 2521 else if (sel < (nDevices+10)) 2522 { 2523 EXPECT_EQ(0, (ret = _audioDevice->SetRecordingDevice(sel-10))); 2524 } 2525 else 2526 { 2527 return -1; 2528 } 2529 #else 2530 TEST_LOG("\nSelect Recording Device\n \n"); 2531 for (int i = 0; i < nDevices; i++) 2532 { 2533 EXPECT_EQ(0, _audioDevice->RecordingDeviceName(i, name, guid)); 2534 TEST_LOG(" (%d) Device %d (%s)\n", i, i, name); 2535 } 2536 TEST_LOG("\n: "); 2537 int sel(0); 2538 EXPECT_TRUE(scanf("%u", &sel) > 0); 2539 if (sel < (nDevices)) 2540 { 2541 EXPECT_EQ(0, (ret = _audioDevice->SetRecordingDevice(sel))); 2542 } else 2543 { 2544 return -1; 2545 } 2546 #endif 2547 2548 return ret; 2549 } 2550 2551 int32_t FuncTestManager::SelectPlayoutDevice() 2552 { 2553 int16_t nDevices = _audioDevice->PlayoutDevices(); 2554 char name[kAdmMaxDeviceNameSize]; 2555 char guid[kAdmMaxGuidSize]; 2556 2557 #ifdef _WIN32 2558 TEST_LOG("\nSelect Playout Device\n \n"); 2559 TEST_LOG(" (%d) Default\n", 0); 2560 TEST_LOG(" (%d) Default Communication [Win 7]\n", 1); 2561 TEST_LOG("- - - - - - - - - - - - - - - - - - - -\n"); 2562 for (int i = 0; i < nDevices; i++) 2563 { 2564 EXPECT_EQ(0, _audioDevice->PlayoutDeviceName(i, name, guid)); 2565 TEST_LOG(" (%d) Device %d (%s)\n", i+10, i, name); 2566 } 2567 TEST_LOG("\n: "); 2568 2569 int sel(0); 2570 2571 scanf("%u", &sel); 2572 2573 int32_t ret(0); 2574 2575 if (sel == 0) 2576 { 2577 EXPECT_TRUE((ret = _audioDevice->SetPlayoutDevice( 2578 AudioDeviceModule::kDefaultDevice)) == 0); 2579 } 2580 else if (sel == 1) 2581 { 2582 EXPECT_TRUE((ret = _audioDevice->SetPlayoutDevice( 2583 AudioDeviceModule::kDefaultCommunicationDevice)) == 0); 2584 } 2585 else if (sel < (nDevices+10)) 2586 { 2587 EXPECT_EQ(0, (ret = _audioDevice->SetPlayoutDevice(sel-10))); 2588 } 2589 else 2590 { 2591 return -1; 2592 } 2593 #else 2594 TEST_LOG("\nSelect Playout Device\n \n"); 2595 for (int i = 0; i < nDevices; i++) 2596 { 2597 EXPECT_EQ(0, _audioDevice->PlayoutDeviceName(i, name, guid)); 2598 TEST_LOG(" (%d) Device %d (%s)\n", i, i, name); 2599 } 2600 TEST_LOG("\n: "); 2601 int sel(0); 2602 EXPECT_TRUE(scanf("%u", &sel) > 0); 2603 int32_t ret(0); 2604 if (sel < (nDevices)) 2605 { 2606 EXPECT_EQ(0, (ret = _audioDevice->SetPlayoutDevice(sel))); 2607 } else 2608 { 2609 return -1; 2610 } 2611 #endif 2612 2613 return ret; 2614 } 2615 2616 int32_t FuncTestManager::TestAdvancedMBAPI() 2617 { 2618 TEST_LOG("\n=======================================\n"); 2619 TEST_LOG(" Advanced mobile device API test:\n"); 2620 TEST_LOG("=======================================\n"); 2621 2622 if (_audioDevice == NULL) 2623 { 2624 return -1; 2625 } 2626 2627 RESET_TEST; 2628 2629 AudioDeviceModule* audioDevice = _audioDevice; 2630 2631 EXPECT_EQ(0, audioDevice->Init()); 2632 EXPECT_TRUE(audioDevice->Initialized()); 2633 2634 if (SelectRecordingDevice() == -1) 2635 { 2636 TEST_LOG("\nERROR: Device selection failed!\n \n"); 2637 return -1; 2638 } 2639 if (SelectPlayoutDevice() == -1) 2640 { 2641 TEST_LOG("\nERROR: Device selection failed!\n \n"); 2642 return -1; 2643 } 2644 _audioTransport->SetFullDuplex(true); 2645 _audioTransport->SetLoopbackMeasurements(true); 2646 2647 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(_audioTransport)); 2648 // Start recording 2649 EXPECT_EQ(0, audioDevice->InitRecording()); 2650 EXPECT_EQ(0, audioDevice->StartRecording()); 2651 // Start playout 2652 EXPECT_EQ(0, audioDevice->InitPlayout()); 2653 EXPECT_EQ(0, audioDevice->StartPlayout()); 2654 2655 EXPECT_TRUE(audioDevice->Recording()); 2656 EXPECT_TRUE(audioDevice->Playing()); 2657 2658 #if defined(_WIN32_WCE) || defined(WEBRTC_IOS) 2659 TEST_LOG("\nResetAudioDevice\n \n"); 2660 if (audioDevice->Recording() && audioDevice->Playing()) 2661 { 2662 TEST_LOG("\n> Speak into the microphone and verify that the audio is good.\n\ 2663 > Press any key to stop...\n \n"); 2664 PAUSE(DEFAULT_PAUSE_TIME); 2665 } 2666 for (int p=0; p<=60; p+=20) 2667 { 2668 TEST_LOG("Resetting sound device several time with pause %d ms\n", p); 2669 for (int l=0; l<20; ++l) 2670 { 2671 EXPECT_EQ(0, audioDevice->ResetAudioDevice()); 2672 SleepMs(p); 2673 } 2674 TEST_LOG("\n> Speak into the microphone and verify that the audio is good.\n"); 2675 SleepMs(2000); 2676 } 2677 #endif 2678 2679 #if defined(WEBRTC_IOS) 2680 bool loudspeakerOn(false); 2681 TEST_LOG("\nSet playout spaker\n \n"); 2682 if (audioDevice->Recording() && audioDevice->Playing()) 2683 { 2684 TEST_LOG("\n> Speak into the microphone and verify that the audio is good.\n\ 2685 > Press any key to stop...\n \n"); 2686 PAUSE(DEFAULT_PAUSE_TIME); 2687 } 2688 2689 TEST_LOG("Set to use speaker\n"); 2690 EXPECT_EQ(0, audioDevice->SetLoudspeakerStatus(true)); 2691 TEST_LOG("\n> Speak into the microphone and verify that the audio is" 2692 " from the loudspeaker.\n\ 2693 > Press any key to stop...\n \n"); 2694 PAUSE(DEFAULT_PAUSE_TIME); 2695 EXPECT_EQ(0, audioDevice->GetLoudspeakerStatus(&loudspeakerOn)); 2696 EXPECT_TRUE(loudspeakerOn); 2697 2698 TEST_LOG("Set to not use speaker\n"); 2699 EXPECT_EQ(0, audioDevice->SetLoudspeakerStatus(false)); 2700 TEST_LOG("\n> Speak into the microphone and verify that the audio is not" 2701 " from the loudspeaker.\n\ 2702 > Press any key to stop...\n \n"); 2703 PAUSE(DEFAULT_PAUSE_TIME); 2704 EXPECT_EQ(0, audioDevice->GetLoudspeakerStatus(&loudspeakerOn)); 2705 EXPECT_FALSE(loudspeakerOn); 2706 #endif 2707 2708 EXPECT_EQ(0, audioDevice->StopRecording()); 2709 EXPECT_EQ(0, audioDevice->StopPlayout()); 2710 EXPECT_EQ(0, audioDevice->RegisterAudioCallback(NULL)); 2711 2712 _audioTransport->SetFullDuplex(false); 2713 2714 TEST_LOG("\n"); 2715 PRINT_TEST_RESULTS; 2716 2717 return 0; 2718 } 2719 2720 } // namespace webrtc 2721 2722 // EOF 2723