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