OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/audio/audio_manager.h" | 5 #include "media/audio/audio_manager.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/environment.h" | 11 #include "base/environment.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
16 #include "base/test/test_message_loop.h" | 16 #include "base/test/test_message_loop.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
19 #include "media/audio/audio_device_description.h" | 19 #include "media/audio/audio_device_description.h" |
20 #include "media/audio/audio_device_name.h" | |
20 #include "media/audio/audio_output_proxy.h" | 21 #include "media/audio/audio_output_proxy.h" |
21 #include "media/audio/audio_unittest_util.h" | 22 #include "media/audio/audio_unittest_util.h" |
22 #include "media/audio/fake_audio_log_factory.h" | 23 #include "media/audio/fake_audio_log_factory.h" |
23 #include "media/audio/fake_audio_manager.h" | 24 #include "media/audio/fake_audio_manager.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 | 26 |
26 #if defined(USE_ALSA) | 27 #if defined(USE_ALSA) |
27 #include "media/audio/alsa/audio_manager_alsa.h" | 28 #include "media/audio/alsa/audio_manager_alsa.h" |
28 #endif // defined(USE_ALSA) | 29 #endif // defined(USE_ALSA) |
29 | 30 |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 1024); | 247 1024); |
247 std::unique_ptr<PCMWaveInAudioInputStream> stream( | 248 std::unique_ptr<PCMWaveInAudioInputStream> stream( |
248 static_cast<PCMWaveInAudioInputStream*>( | 249 static_cast<PCMWaveInAudioInputStream*>( |
249 amw->CreatePCMWaveInAudioInputStream(parameters, device_id))); | 250 amw->CreatePCMWaveInAudioInputStream(parameters, device_id))); |
250 return stream.get() ? stream->device_id_ : std::string(); | 251 return stream.get() ? stream->device_id_ : std::string(); |
251 } | 252 } |
252 #endif | 253 #endif |
253 | 254 |
254 // Helper method which verifies that the device list starts with a valid | 255 // Helper method which verifies that the device list starts with a valid |
255 // default record followed by non-default device names. | 256 // default record followed by non-default device names. |
256 static void CheckDeviceNames(const AudioDeviceNames& device_names) { | 257 static void CheckDeviceDescriptions( |
257 DVLOG(2) << "Got " << device_names.size() << " audio devices."; | 258 const AudioDeviceDescriptions& device_descriptions) { |
258 if (!device_names.empty()) { | 259 DVLOG(2) << "Got " << device_descriptions.size() << " audio devices."; |
259 AudioDeviceNames::const_iterator it = device_names.begin(); | 260 if (!device_descriptions.empty()) { |
261 AudioDeviceDescriptions::const_iterator it = device_descriptions.begin(); | |
260 | 262 |
261 // The first device in the list should always be the default device. | 263 // The first device in the list should always be the default device. |
262 EXPECT_EQ(AudioDeviceDescription::GetDefaultDeviceName(), | 264 EXPECT_EQ(AudioDeviceDescription::GetDefaultDeviceName(), |
263 it->device_name); | 265 it->device_name); |
264 EXPECT_EQ(std::string(AudioDeviceDescription::kDefaultDeviceId), | 266 EXPECT_EQ(std::string(AudioDeviceDescription::kDefaultDeviceId), |
265 it->unique_id); | 267 it->unique_id); |
266 ++it; | 268 ++it; |
267 | 269 |
268 // Other devices should have non-empty name and id and should not contain | 270 // Other devices should have non-empty name and id and should not contain |
269 // default name or id. | 271 // default name or id. |
270 while (it != device_names.end()) { | 272 while (it != device_descriptions.end()) { |
271 EXPECT_FALSE(it->device_name.empty()); | 273 EXPECT_FALSE(it->device_name.empty()); |
272 EXPECT_FALSE(it->unique_id.empty()); | 274 EXPECT_FALSE(it->unique_id.empty()); |
275 EXPECT_FALSE(it->group_id.empty()); | |
273 DVLOG(2) << "Device ID(" << it->unique_id | 276 DVLOG(2) << "Device ID(" << it->unique_id |
274 << "), label: " << it->device_name; | 277 << "), label: " << it->device_name |
278 << "group: " << it->group_id; | |
275 EXPECT_NE(AudioDeviceDescription::GetDefaultDeviceName(), | 279 EXPECT_NE(AudioDeviceDescription::GetDefaultDeviceName(), |
276 it->device_name); | 280 it->device_name); |
277 EXPECT_NE(std::string(AudioDeviceDescription::kDefaultDeviceId), | 281 EXPECT_NE(std::string(AudioDeviceDescription::kDefaultDeviceId), |
278 it->unique_id); | 282 it->unique_id); |
279 ++it; | 283 ++it; |
280 } | 284 } |
281 } else { | 285 } else { |
282 // Log a warning so we can see the status on the build bots. No need to | 286 // Log a warning so we can see the status on the build bots. No need to |
283 // break the test though since this does successfully test the code and | 287 // break the test though since this does successfully test the code and |
284 // some failure cases. | 288 // some failure cases. |
285 LOG(WARNING) << "No input devices detected"; | 289 LOG(WARNING) << "No input devices detected"; |
286 } | 290 } |
287 } | 291 } |
288 | 292 |
289 #if defined(USE_CRAS) | 293 #if defined(USE_CRAS) |
290 // Helper method for (USE_CRAS) which verifies that the device list starts | 294 // Helper method for (USE_CRAS) which verifies that the device list starts |
291 // with a valid default record followed by physical device names. | 295 // with a valid default record followed by physical device names. |
292 static void CheckDeviceNamesCras( | 296 static void CheckDeviceDescriptionsCras( |
293 const AudioDeviceNames& device_names, | 297 const AudioDeviceDescriptions& device_descriptions, |
294 const std::map<uint64_t, std::string>& expectation) { | 298 const std::map<uint64_t, std::string>& expectation) { |
295 DVLOG(2) << "Got " << device_names.size() << " audio devices."; | 299 DVLOG(2) << "Got " << device_descriptions.size() << " audio devices."; |
296 if (!device_names.empty()) { | 300 if (!device_descriptions.empty()) { |
297 AudioDeviceNames::const_iterator it = device_names.begin(); | 301 AudioDeviceDescriptions::const_iterator it = device_descriptions.begin(); |
298 | 302 |
299 // The first device in the list should always be the default device. | 303 // The first device in the list should always be the default device. |
300 EXPECT_EQ(AudioDeviceDescription::GetDefaultDeviceName(), | 304 EXPECT_EQ(AudioDeviceDescription::GetDefaultDeviceName(), |
301 it->device_name); | 305 it->device_name); |
302 EXPECT_EQ(std::string(AudioDeviceDescription::kDefaultDeviceId), | 306 EXPECT_EQ(std::string(AudioDeviceDescription::kDefaultDeviceId), |
303 it->unique_id); | 307 it->unique_id); |
304 | 308 |
305 // |device_names|'size should be |expectation|'s size plus one because of | 309 // |device_descriptions|'size should be |expectation|'s size plus one |
310 // because of | |
306 // default device. | 311 // default device. |
307 EXPECT_EQ(device_names.size(), expectation.size() + 1); | 312 EXPECT_EQ(device_descriptions.size(), expectation.size() + 1); |
308 ++it; | 313 ++it; |
309 // Check other devices that should have non-empty name and id, and should | 314 // Check other devices that should have non-empty name and id, and should |
310 // be contained in expectation. | 315 // be contained in expectation. |
311 while (it != device_names.end()) { | 316 while (it != device_descriptions.end()) { |
312 EXPECT_FALSE(it->device_name.empty()); | 317 EXPECT_FALSE(it->device_name.empty()); |
313 EXPECT_FALSE(it->unique_id.empty()); | 318 EXPECT_FALSE(it->group_id.empty()); |
Guido Urdaneta
2016/12/08 15:53:37
It looks like unique_id got renamed to group_id he
o1ka
2016/12/09 14:56:30
Done.
| |
314 DVLOG(2) << "Device ID(" << it->unique_id | 319 DVLOG(2) << "Device ID(" << it->unique_id |
315 << "), label: " << it->device_name; | 320 << "), label: " << it->device_name |
321 << "group: " << it->group_id; | |
316 uint64_t key; | 322 uint64_t key; |
317 EXPECT_TRUE(base::StringToUint64(it->unique_id, &key)); | 323 EXPECT_TRUE(base::StringToUint64(it->unique_id, &key)); |
318 EXPECT_TRUE(expectation.find(key) != expectation.end()); | 324 EXPECT_TRUE(expectation.find(key) != expectation.end()); |
319 EXPECT_EQ(expectation.find(key)->second, it->device_name); | 325 EXPECT_EQ(expectation.find(key)->second, it->device_name); |
320 ++it; | 326 ++it; |
321 } | 327 } |
322 } else { | 328 } else { |
323 // Log a warning so we can see the status on the build bots. No need to | 329 // Log a warning so we can see the status on the build bots. No need to |
324 // break the test though since this does successfully test the code and | 330 // break the test though since this does successfully test the code and |
325 // some failure cases. | 331 // some failure cases. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 std::map<uint64_t, std::string> expectation; | 388 std::map<uint64_t, std::string> expectation; |
383 expectation[kJabraMic1.id] = | 389 expectation[kJabraMic1.id] = |
384 cras_audio_handler_->GetDeviceFromId(kJabraMic1.id)->display_name; | 390 cras_audio_handler_->GetDeviceFromId(kJabraMic1.id)->display_name; |
385 expectation[kJabraMic2.id] = | 391 expectation[kJabraMic2.id] = |
386 cras_audio_handler_->GetDeviceFromId(kJabraMic2.id)->display_name; | 392 cras_audio_handler_->GetDeviceFromId(kJabraMic2.id)->display_name; |
387 expectation[kUSBCameraMic.id] = | 393 expectation[kUSBCameraMic.id] = |
388 cras_audio_handler_->GetDeviceFromId(kUSBCameraMic.id)->display_name; | 394 cras_audio_handler_->GetDeviceFromId(kUSBCameraMic.id)->display_name; |
389 | 395 |
390 DVLOG(2) << "Testing AudioManagerCras."; | 396 DVLOG(2) << "Testing AudioManagerCras."; |
391 CreateAudioManagerForTesting<AudioManagerCras>(); | 397 CreateAudioManagerForTesting<AudioManagerCras>(); |
392 AudioDeviceNames device_names; | 398 AudioDeviceDescriptions device_descriptions; |
393 audio_manager_->GetAudioInputDeviceNames(&device_names); | 399 audio_manager_->GetAudioInputDeviceDescriptions(&device_descriptions); |
394 CheckDeviceNamesCras(device_names, expectation); | 400 CheckDeviceDescriptionsCras(device_descriptions, expectation); |
395 } | 401 } |
396 | 402 |
397 // TODO(warx): enable the test once crbug.com/554168 is fixed. | 403 // TODO(warx): enable the test once crbug.com/554168 is fixed. |
398 TEST_F(AudioManagerTest, DISABLED_EnumerateOutputDevicesCras) { | 404 TEST_F(AudioManagerTest, DISABLED_EnumerateOutputDevicesCras) { |
399 // Setup the devices without internal mic, so that it doesn't exist | 405 // Setup the devices without internal mic, so that it doesn't exist |
400 // beamforming capable mic. | 406 // beamforming capable mic. |
401 AudioNodeList audio_nodes; | 407 AudioNodeList audio_nodes; |
402 audio_nodes.push_back(kJabraMic1); | 408 audio_nodes.push_back(kJabraMic1); |
403 audio_nodes.push_back(kJabraMic2); | 409 audio_nodes.push_back(kJabraMic2); |
404 audio_nodes.push_back(kUSBCameraMic); | 410 audio_nodes.push_back(kUSBCameraMic); |
405 audio_nodes.push_back(kHDMIOutput); | 411 audio_nodes.push_back(kHDMIOutput); |
406 audio_nodes.push_back(kJabraSpeaker1); | 412 audio_nodes.push_back(kJabraSpeaker1); |
407 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes); | 413 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes); |
408 | 414 |
409 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); | 415 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); |
410 | 416 |
411 // Setup expectation with physical devices. | 417 // Setup expectation with physical devices. |
412 std::map<uint64_t, std::string> expectation; | 418 std::map<uint64_t, std::string> expectation; |
413 expectation[kHDMIOutput.id] = | 419 expectation[kHDMIOutput.id] = |
414 cras_audio_handler_->GetDeviceFromId(kHDMIOutput.id)->display_name; | 420 cras_audio_handler_->GetDeviceFromId(kHDMIOutput.id)->display_name; |
415 expectation[kJabraSpeaker1.id] = | 421 expectation[kJabraSpeaker1.id] = |
416 cras_audio_handler_->GetDeviceFromId(kJabraSpeaker1.id)->display_name; | 422 cras_audio_handler_->GetDeviceFromId(kJabraSpeaker1.id)->display_name; |
417 | 423 |
418 DVLOG(2) << "Testing AudioManagerCras."; | 424 DVLOG(2) << "Testing AudioManagerCras."; |
419 CreateAudioManagerForTesting<AudioManagerCras>(); | 425 CreateAudioManagerForTesting<AudioManagerCras>(); |
420 AudioDeviceNames device_names; | 426 AudioDeviceDescriptions device_descriptions; |
421 audio_manager_->GetAudioOutputDeviceNames(&device_names); | 427 audio_manager_->GetAudioOutputDeviceDescriptions(&device_descriptions); |
422 CheckDeviceNamesCras(device_names, expectation); | 428 CheckDeviceDescriptionsCras(device_descriptions, expectation); |
423 } | 429 } |
424 #else // !defined(USE_CRAS) | 430 #else // !defined(USE_CRAS) |
425 | 431 |
426 TEST_F(AudioManagerTest, HandleDefaultDeviceIDs) { | 432 TEST_F(AudioManagerTest, HandleDefaultDeviceIDs) { |
427 // Use a fake manager so we can makeup device ids, this will still use the | 433 // Use a fake manager so we can makeup device ids, this will still use the |
428 // AudioManagerBase code. | 434 // AudioManagerBase code. |
429 CreateAudioManagerForTesting<FakeAudioManager>(); | 435 CreateAudioManagerForTesting<FakeAudioManager>(); |
430 HandleDefaultDeviceIDsTest(); | 436 HandleDefaultDeviceIDsTest(); |
431 base::RunLoop().RunUntilIdle(); | 437 base::RunLoop().RunUntilIdle(); |
432 } | 438 } |
433 | 439 |
434 // Test that devices can be enumerated. | 440 // Test that devices can be enumerated. |
435 TEST_F(AudioManagerTest, EnumerateInputDevices) { | 441 TEST_F(AudioManagerTest, EnumerateInputDevices) { |
436 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 442 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); |
437 | 443 |
438 AudioDeviceNames device_names; | 444 AudioDeviceDescriptions device_descriptions; |
439 audio_manager_->GetAudioInputDeviceNames(&device_names); | 445 audio_manager_->GetAudioInputDeviceDescriptions(&device_descriptions); |
440 CheckDeviceNames(device_names); | 446 CheckDeviceDescriptions(device_descriptions); |
441 } | 447 } |
442 | 448 |
443 // Test that devices can be enumerated. | 449 // Test that devices can be enumerated. |
444 TEST_F(AudioManagerTest, EnumerateOutputDevices) { | 450 TEST_F(AudioManagerTest, EnumerateOutputDevices) { |
445 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); | 451 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); |
446 | 452 |
447 AudioDeviceNames device_names; | 453 AudioDeviceDescriptions device_descriptions; |
448 audio_manager_->GetAudioOutputDeviceNames(&device_names); | 454 audio_manager_->GetAudioOutputDeviceDescriptions(&device_descriptions); |
449 CheckDeviceNames(device_names); | 455 CheckDeviceDescriptions(device_descriptions); |
450 } | 456 } |
451 | 457 |
452 // Run additional tests for Windows since enumeration can be done using | 458 // Run additional tests for Windows since enumeration can be done using |
453 // two different APIs. MMDevice is default for Vista and higher and Wave | 459 // two different APIs. MMDevice is default for Vista and higher and Wave |
454 // is default for XP and lower. | 460 // is default for XP and lower. |
455 #if defined(OS_WIN) | 461 #if defined(OS_WIN) |
456 | 462 |
457 // Override default enumeration API and force usage of Windows MMDevice. | 463 // Override default enumeration API and force usage of Windows MMDevice. |
458 // This test will only run on Windows Vista and higher. | 464 // This test will only run on Windows Vista and higher. |
459 TEST_F(AudioManagerTest, EnumerateInputDevicesWinMMDevice) { | 465 TEST_F(AudioManagerTest, EnumerateInputDevicesWinMMDevice) { |
460 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 466 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); |
461 | 467 |
462 AudioDeviceNames device_names; | 468 AudioDeviceDescriptions device_descriptions; |
463 if (!SetMMDeviceEnumeration()) { | 469 if (!SetMMDeviceEnumeration()) { |
464 // Usage of MMDevice will fail on XP and lower. | 470 // Usage of MMDevice will fail on XP and lower. |
465 LOG(WARNING) << "MM device enumeration is not supported."; | 471 LOG(WARNING) << "MM device enumeration is not supported."; |
466 return; | 472 return; |
467 } | 473 } |
468 audio_manager_->GetAudioInputDeviceNames(&device_names); | 474 audio_manager_->GetAudioInputDeviceDescriptions(&device_descriptions); |
469 CheckDeviceNames(device_names); | 475 CheckDeviceDescriptions(device_descriptions); |
470 } | 476 } |
471 | 477 |
472 TEST_F(AudioManagerTest, EnumerateOutputDevicesWinMMDevice) { | 478 TEST_F(AudioManagerTest, EnumerateOutputDevicesWinMMDevice) { |
473 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); | 479 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); |
474 | 480 |
475 AudioDeviceNames device_names; | 481 AudioDeviceDescriptions device_descriptions; |
476 if (!SetMMDeviceEnumeration()) { | 482 if (!SetMMDeviceEnumeration()) { |
477 // Usage of MMDevice will fail on XP and lower. | 483 // Usage of MMDevice will fail on XP and lower. |
478 LOG(WARNING) << "MM device enumeration is not supported."; | 484 LOG(WARNING) << "MM device enumeration is not supported."; |
479 return; | 485 return; |
480 } | 486 } |
481 audio_manager_->GetAudioOutputDeviceNames(&device_names); | 487 audio_manager_->GetAudioOutputDeviceDescriptions(&device_descriptions); |
482 CheckDeviceNames(device_names); | 488 CheckDeviceDescriptions(device_descriptions); |
483 } | 489 } |
484 | 490 |
485 // Override default enumeration API and force usage of Windows Wave. | 491 // Override default enumeration API and force usage of Windows Wave. |
486 // This test will run on Windows XP, Windows Vista and Windows 7. | 492 // This test will run on Windows XP, Windows Vista and Windows 7. |
487 TEST_F(AudioManagerTest, EnumerateInputDevicesWinWave) { | 493 TEST_F(AudioManagerTest, EnumerateInputDevicesWinWave) { |
488 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 494 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); |
489 | 495 |
490 AudioDeviceNames device_names; | 496 AudioDeviceDescriptions device_descriptions; |
491 SetWaveEnumeration(); | 497 SetWaveEnumeration(); |
492 audio_manager_->GetAudioInputDeviceNames(&device_names); | 498 audio_manager_->GetAudioInputDeviceDescriptions(&device_descriptions); |
493 CheckDeviceNames(device_names); | 499 CheckDeviceDescriptions(device_descriptions); |
494 } | 500 } |
495 | 501 |
496 TEST_F(AudioManagerTest, EnumerateOutputDevicesWinWave) { | 502 TEST_F(AudioManagerTest, EnumerateOutputDevicesWinWave) { |
497 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); | 503 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); |
498 | 504 |
499 AudioDeviceNames device_names; | 505 AudioDeviceDescriptions device_descriptions; |
500 SetWaveEnumeration(); | 506 SetWaveEnumeration(); |
501 audio_manager_->GetAudioOutputDeviceNames(&device_names); | 507 audio_manager_->GetAudioOutputDeviceDescriptions(&device_descriptions); |
502 CheckDeviceNames(device_names); | 508 CheckDeviceDescriptions(device_descriptions); |
503 } | 509 } |
504 | 510 |
505 TEST_F(AudioManagerTest, WinXPDeviceIdUnchanged) { | 511 TEST_F(AudioManagerTest, WinXPDeviceIdUnchanged) { |
506 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 512 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); |
507 | 513 |
508 AudioDeviceNames xp_device_names; | 514 AudioDeviceDescriptions xp_device_descriptions; |
509 SetWaveEnumeration(); | 515 SetWaveEnumeration(); |
510 audio_manager_->GetAudioInputDeviceNames(&xp_device_names); | 516 audio_manager_->GetAudioInputDeviceDescriptions(&xp_device_descriptions); |
511 CheckDeviceNames(xp_device_names); | 517 CheckDeviceDescriptions(xp_device_descriptions); |
512 | 518 |
513 // Device ID should remain unchanged, including the default device ID. | 519 // Device ID should remain unchanged, including the default device ID. |
514 for (AudioDeviceNames::iterator i = xp_device_names.begin(); | 520 for (AudioDeviceDescriptions::iterator i = xp_device_descriptions.begin(); |
Guido Urdaneta
2016/12/08 15:53:37
nit: consider switching to range for.
o1ka
2016/12/09 14:56:30
Done.
| |
515 i != xp_device_names.end(); ++i) { | 521 i != xp_device_descriptions.end(); ++i) { |
516 EXPECT_EQ(i->unique_id, | 522 EXPECT_EQ(i->unique_id, |
517 GetDeviceIdFromPCMWaveInAudioInputStream(i->unique_id)); | 523 GetDeviceIdFromPCMWaveInAudioInputStream(i->unique_id)); |
518 } | 524 } |
519 } | 525 } |
520 | 526 |
521 TEST_F(AudioManagerTest, ConvertToWinXPInputDeviceId) { | 527 TEST_F(AudioManagerTest, ConvertToWinXPInputDeviceId) { |
522 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 528 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); |
523 | 529 |
524 if (!SetMMDeviceEnumeration()) { | 530 if (!SetMMDeviceEnumeration()) { |
525 // Usage of MMDevice will fail on XP and lower. | 531 // Usage of MMDevice will fail on XP and lower. |
526 LOG(WARNING) << "MM device enumeration is not supported."; | 532 LOG(WARNING) << "MM device enumeration is not supported."; |
527 return; | 533 return; |
528 } | 534 } |
529 | 535 |
530 AudioDeviceNames device_names; | 536 AudioDeviceDescriptions device_descriptions; |
531 audio_manager_->GetAudioInputDeviceNames(&device_names); | 537 audio_manager_->GetAudioInputDeviceDescriptions(&device_descriptions); |
532 CheckDeviceNames(device_names); | 538 CheckDeviceDescriptions(device_descriptions); |
533 | 539 |
534 for (AudioDeviceNames::iterator i = device_names.begin(); | 540 for (AudioDeviceDescriptions::iterator i = device_descriptions.begin(); |
535 i != device_names.end(); ++i) { | 541 i != device_descriptions.end(); ++i) { |
536 std::string converted_id = | 542 std::string converted_id = |
537 GetDeviceIdFromPCMWaveInAudioInputStream(i->unique_id); | 543 GetDeviceIdFromPCMWaveInAudioInputStream(i->unique_id); |
538 if (i == device_names.begin()) { | 544 if (i == device_descriptions.begin()) { |
539 // The first in the list is the default device ID, which should not be | 545 // The first in the list is the default device ID, which should not be |
540 // changed when passed to PCMWaveInAudioInputStream. | 546 // changed when passed to PCMWaveInAudioInputStream. |
541 EXPECT_EQ(i->unique_id, converted_id); | 547 EXPECT_EQ(i->unique_id, converted_id); |
542 } else { | 548 } else { |
543 // MMDevice-style device IDs should be converted to WaveIn-style device | 549 // MMDevice-style device IDs should be converted to WaveIn-style device |
544 // IDs. | 550 // IDs. |
545 EXPECT_NE(i->unique_id, converted_id); | 551 EXPECT_NE(i->unique_id, converted_id); |
546 } | 552 } |
547 } | 553 } |
548 } | 554 } |
549 | 555 |
550 #endif // defined(OS_WIN) | 556 #endif // defined(OS_WIN) |
551 | 557 |
552 #if defined(USE_PULSEAUDIO) | 558 #if defined(USE_PULSEAUDIO) |
553 // On Linux, there are two implementations available and both can | 559 // On Linux, there are two implementations available and both can |
554 // sometimes be tested on a single system. These tests specifically | 560 // sometimes be tested on a single system. These tests specifically |
555 // test Pulseaudio. | 561 // test Pulseaudio. |
556 | 562 |
557 TEST_F(AudioManagerTest, EnumerateInputDevicesPulseaudio) { | 563 TEST_F(AudioManagerTest, EnumerateInputDevicesPulseaudio) { |
558 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 564 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); |
559 | 565 |
560 CreateAudioManagerForTesting<AudioManagerPulse>(); | 566 CreateAudioManagerForTesting<AudioManagerPulse>(); |
561 if (audio_manager_.get()) { | 567 if (audio_manager_.get()) { |
562 AudioDeviceNames device_names; | 568 AudioDeviceDescriptions device_descriptions; |
563 audio_manager_->GetAudioInputDeviceNames(&device_names); | 569 audio_manager_->GetAudioInputDeviceDescriptions(&device_descriptions); |
564 CheckDeviceNames(device_names); | 570 CheckDeviceDescriptions(device_descriptions); |
565 } else { | 571 } else { |
566 LOG(WARNING) << "No pulseaudio on this system."; | 572 LOG(WARNING) << "No pulseaudio on this system."; |
567 } | 573 } |
568 } | 574 } |
569 | 575 |
570 TEST_F(AudioManagerTest, EnumerateOutputDevicesPulseaudio) { | 576 TEST_F(AudioManagerTest, EnumerateOutputDevicesPulseaudio) { |
571 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); | 577 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); |
572 | 578 |
573 CreateAudioManagerForTesting<AudioManagerPulse>(); | 579 CreateAudioManagerForTesting<AudioManagerPulse>(); |
574 if (audio_manager_.get()) { | 580 if (audio_manager_.get()) { |
575 AudioDeviceNames device_names; | 581 AudioDeviceDescriptions device_descriptions; |
576 audio_manager_->GetAudioOutputDeviceNames(&device_names); | 582 audio_manager_->GetAudioOutputDeviceDescriptions(&device_descriptions); |
577 CheckDeviceNames(device_names); | 583 CheckDeviceDescriptions(device_descriptions); |
578 } else { | 584 } else { |
579 LOG(WARNING) << "No pulseaudio on this system."; | 585 LOG(WARNING) << "No pulseaudio on this system."; |
580 } | 586 } |
581 } | 587 } |
582 #endif // defined(USE_PULSEAUDIO) | 588 #endif // defined(USE_PULSEAUDIO) |
583 | 589 |
584 #if defined(USE_ALSA) | 590 #if defined(USE_ALSA) |
585 // On Linux, there are two implementations available and both can | 591 // On Linux, there are two implementations available and both can |
586 // sometimes be tested on a single system. These tests specifically | 592 // sometimes be tested on a single system. These tests specifically |
587 // test Alsa. | 593 // test Alsa. |
588 | 594 |
589 TEST_F(AudioManagerTest, EnumerateInputDevicesAlsa) { | 595 TEST_F(AudioManagerTest, EnumerateInputDevicesAlsa) { |
590 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 596 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); |
591 | 597 |
592 DVLOG(2) << "Testing AudioManagerAlsa."; | 598 DVLOG(2) << "Testing AudioManagerAlsa."; |
593 CreateAudioManagerForTesting<AudioManagerAlsa>(); | 599 CreateAudioManagerForTesting<AudioManagerAlsa>(); |
594 AudioDeviceNames device_names; | 600 AudioDeviceDescriptions device_descriptions; |
595 audio_manager_->GetAudioInputDeviceNames(&device_names); | 601 audio_manager_->GetAudioInputDeviceDescriptions(&device_descriptions); |
596 CheckDeviceNames(device_names); | 602 CheckDeviceDescriptions(device_descriptions); |
597 } | 603 } |
598 | 604 |
599 TEST_F(AudioManagerTest, EnumerateOutputDevicesAlsa) { | 605 TEST_F(AudioManagerTest, EnumerateOutputDevicesAlsa) { |
600 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); | 606 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); |
601 | 607 |
602 DVLOG(2) << "Testing AudioManagerAlsa."; | 608 DVLOG(2) << "Testing AudioManagerAlsa."; |
603 CreateAudioManagerForTesting<AudioManagerAlsa>(); | 609 CreateAudioManagerForTesting<AudioManagerAlsa>(); |
604 AudioDeviceNames device_names; | 610 AudioDeviceDescriptions device_descriptions; |
605 audio_manager_->GetAudioOutputDeviceNames(&device_names); | 611 audio_manager_->GetAudioOutputDeviceDescriptions(&device_descriptions); |
606 CheckDeviceNames(device_names); | 612 CheckDeviceDescriptions(device_descriptions); |
607 } | 613 } |
608 #endif // defined(USE_ALSA) | 614 #endif // defined(USE_ALSA) |
609 | 615 |
610 TEST_F(AudioManagerTest, GetDefaultOutputStreamParameters) { | 616 TEST_F(AudioManagerTest, GetDefaultOutputStreamParameters) { |
611 #if defined(OS_WIN) || defined(OS_MACOSX) | 617 #if defined(OS_WIN) || defined(OS_MACOSX) |
612 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 618 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); |
613 | 619 |
614 AudioParameters params; | 620 AudioParameters params; |
615 GetDefaultOutputStreamParameters(¶ms); | 621 GetDefaultOutputStreamParameters(¶ms); |
616 EXPECT_TRUE(params.IsValid()); | 622 EXPECT_TRUE(params.IsValid()); |
617 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 623 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
618 } | 624 } |
619 | 625 |
620 TEST_F(AudioManagerTest, GetAssociatedOutputDeviceID) { | 626 TEST_F(AudioManagerTest, GetAssociatedOutputDeviceID) { |
621 #if defined(OS_WIN) || defined(OS_MACOSX) | 627 #if defined(OS_WIN) || defined(OS_MACOSX) |
622 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable() && OutputDevicesAvailable()); | 628 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable() && OutputDevicesAvailable()); |
623 | 629 |
624 AudioDeviceNames device_names; | 630 AudioDeviceDescriptions device_descriptions; |
625 audio_manager_->GetAudioInputDeviceNames(&device_names); | 631 audio_manager_->GetAudioInputDeviceDescriptions(&device_descriptions); |
626 bool found_an_associated_device = false; | 632 bool found_an_associated_device = false; |
627 for (AudioDeviceNames::iterator it = device_names.begin(); | 633 for (AudioDeviceDescriptions::iterator it = device_descriptions.begin(); |
Guido Urdaneta
2016/12/08 15:53:37
nit: consider switching to range for
o1ka
2016/12/09 14:56:30
Done.
| |
628 it != device_names.end(); | 634 it != device_descriptions.end(); ++it) { |
629 ++it) { | |
630 EXPECT_FALSE(it->unique_id.empty()); | 635 EXPECT_FALSE(it->unique_id.empty()); |
631 EXPECT_FALSE(it->device_name.empty()); | 636 EXPECT_FALSE(it->device_name.empty()); |
632 std::string output_device_id; | 637 std::string output_device_id; |
633 GetAssociatedOutputDeviceID(it->unique_id, &output_device_id); | 638 GetAssociatedOutputDeviceID(it->unique_id, &output_device_id); |
634 if (!output_device_id.empty()) { | 639 if (!output_device_id.empty()) { |
635 DVLOG(2) << it->unique_id << " matches with " << output_device_id; | 640 DVLOG(2) << it->unique_id << " matches with " << output_device_id; |
636 found_an_associated_device = true; | 641 found_an_associated_device = true; |
637 } | 642 } |
638 } | 643 } |
639 | 644 |
640 EXPECT_TRUE(found_an_associated_device); | 645 EXPECT_TRUE(found_an_associated_device); |
641 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 646 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
642 } | 647 } |
643 #endif // defined(USE_CRAS) | 648 #endif // defined(USE_CRAS) |
644 | 649 |
645 class TestAudioManager : public FakeAudioManager { | 650 class TestAudioManager : public FakeAudioManager { |
646 // For testing the default implementation of GetGroupId(Input|Output) | 651 // For testing the default implementation of GetGroupId(Input|Output) |
647 // input$i is associated to output$i, if both exist. | 652 // input$i is associated to output$i, if both exist. |
648 // Default input is input1. | 653 // Default input is input1. |
649 // Default output is output2. | 654 // Default output is output2. |
650 public: | 655 public: |
651 TestAudioManager( | 656 TestAudioManager( |
652 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 657 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
653 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | 658 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, |
654 AudioLogFactory* audio_log_factory) | 659 AudioLogFactory* audio_log_factory) |
655 : FakeAudioManager(task_runner, worker_task_runner, audio_log_factory) {} | 660 : FakeAudioManager(task_runner, worker_task_runner, audio_log_factory) {} |
656 | 661 |
662 std::string GetDefaultOutputDeviceID() override { return "output4"; } | |
663 | |
664 std::string GetAssociatedOutputDeviceID( | |
665 const std::string& input_id) override { | |
666 if (input_id == "input1") | |
667 return "output1"; | |
668 if (input_id == "input2") | |
669 return "output2"; | |
670 if (input_id == "default") | |
671 return "output1"; | |
672 return ""; | |
673 } | |
674 | |
675 private: | |
657 void GetAudioInputDeviceNames(AudioDeviceNames* device_names) override { | 676 void GetAudioInputDeviceNames(AudioDeviceNames* device_names) override { |
658 device_names->emplace_back("Input 1", "input1"); | 677 device_names->emplace_back("Input 1", "input1"); |
659 device_names->emplace_back("Input 2", "input2"); | 678 device_names->emplace_back("Input 2", "input2"); |
660 device_names->emplace_back("Input 3", "input3"); | 679 device_names->emplace_back("Input 3", "input3"); |
661 device_names->push_front(AudioDeviceName::CreateDefault()); | 680 device_names->push_front(AudioDeviceName::CreateDefault()); |
662 } | 681 } |
663 | 682 |
664 void GetAudioOutputDeviceNames(AudioDeviceNames* device_names) override { | 683 void GetAudioOutputDeviceNames(AudioDeviceNames* device_names) override { |
665 device_names->emplace_back("Output 1", "output1"); | 684 device_names->emplace_back("Output 1", "output1"); |
666 device_names->emplace_back("Output 2", "output2"); | 685 device_names->emplace_back("Output 2", "output2"); |
686 device_names->emplace_back("Output 3", "output3"); | |
667 device_names->emplace_back("Output 4", "output4"); | 687 device_names->emplace_back("Output 4", "output4"); |
668 device_names->push_front(AudioDeviceName::CreateDefault()); | 688 device_names->push_front(AudioDeviceName::CreateDefault()); |
669 } | 689 } |
670 | |
671 std::string GetDefaultOutputDeviceID() override { return "output4"; } | |
672 | |
673 std::string GetAssociatedOutputDeviceID( | |
674 const std::string& input_id) override { | |
675 if (input_id == "input1") | |
676 return "output1"; | |
677 if (input_id == "input2") | |
678 return "output2"; | |
679 if (input_id == "default") | |
680 return "output1"; | |
681 return ""; | |
682 } | |
683 }; | 690 }; |
684 | 691 |
685 TEST_F(AudioManagerTest, GetGroupId) { | 692 TEST_F(AudioManagerTest, GroupId) { |
686 CreateAudioManagerForTesting<TestAudioManager>(); | 693 CreateAudioManagerForTesting<TestAudioManager>(); |
687 // Groups: | 694 // Groups: |
688 // 0: input1, output1, default input | 695 // input1, output1, default input |
689 // 1: input2, output2 | 696 // input2, output2 |
690 // 2: input3, | 697 // input3, |
691 // 3: output4, default output | 698 // output3 |
692 std::vector<std::string> group; | 699 // output4, default output |
693 group.push_back(audio_manager_->GetGroupIDInput("input1")); | 700 AudioDeviceDescriptions input_descriptions; |
694 group.push_back(audio_manager_->GetGroupIDInput("input2")); | 701 audio_manager_->GetAudioInputDeviceDescriptions(&input_descriptions); |
695 group.push_back(audio_manager_->GetGroupIDInput("input3")); | 702 std::vector<AudioDeviceDescription> inputs(input_descriptions.begin(), |
696 group.push_back(audio_manager_->GetGroupIDOutput("output4")); | 703 input_descriptions.end()); |
697 for (size_t i = 0; i < group.size(); ++i) { | 704 AudioDeviceDescriptions output_descriptions; |
698 for (size_t j = i + 1; j < group.size(); ++j) { | 705 audio_manager_->GetAudioOutputDeviceDescriptions(&output_descriptions); |
699 EXPECT_NE(group[i], group[j]); | 706 std::vector<AudioDeviceDescription> outputs(output_descriptions.begin(), |
700 } | 707 output_descriptions.end()); |
701 } | 708 |
702 EXPECT_EQ(group[0], audio_manager_->GetGroupIDOutput("output1")); | 709 EXPECT_EQ(inputs[0].group_id, outputs[1].group_id); |
703 EXPECT_EQ(group[0], audio_manager_->GetGroupIDInput("default")); | 710 EXPECT_EQ(inputs[1].group_id, outputs[1].group_id); |
704 EXPECT_EQ(group[1], audio_manager_->GetGroupIDOutput("output2")); | 711 EXPECT_EQ(inputs[2].group_id, outputs[2].group_id); |
705 EXPECT_EQ(group[3], audio_manager_->GetGroupIDOutput("default")); | 712 EXPECT_NE(inputs[3].group_id, outputs[3].group_id); |
713 EXPECT_EQ(outputs[4].group_id, outputs[0].group_id); | |
714 EXPECT_NE(inputs[0].group_id, outputs[0].group_id); | |
715 EXPECT_NE(inputs[1].group_id, outputs[2].group_id); | |
716 EXPECT_NE(inputs[2].group_id, outputs[3].group_id); | |
717 EXPECT_NE(inputs[1].group_id, outputs[3].group_id); | |
706 } | 718 } |
707 | 719 |
708 } // namespace media | 720 } // namespace media |
OLD | NEW |