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

Side by Side Diff: media/audio/audio_manager_unittest.cc

Issue 2563653002: Replace AudioManager::GetAudio*DeviceNames with AudioManager::GetAudio*DeviceDescriptions (Closed)
Patch Set: nit fixes Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/audio/audio_manager_base.cc ('k') | media/audio/mock_audio_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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->unique_id.empty());
319 EXPECT_FALSE(it->group_id.empty());
314 DVLOG(2) << "Device ID(" << it->unique_id 320 DVLOG(2) << "Device ID(" << it->unique_id
315 << "), label: " << it->device_name; 321 << "), label: " << it->device_name
322 << "group: " << it->group_id;
316 uint64_t key; 323 uint64_t key;
317 EXPECT_TRUE(base::StringToUint64(it->unique_id, &key)); 324 EXPECT_TRUE(base::StringToUint64(it->unique_id, &key));
318 EXPECT_TRUE(expectation.find(key) != expectation.end()); 325 EXPECT_TRUE(expectation.find(key) != expectation.end());
319 EXPECT_EQ(expectation.find(key)->second, it->device_name); 326 EXPECT_EQ(expectation.find(key)->second, it->device_name);
320 ++it; 327 ++it;
321 } 328 }
322 } else { 329 } else {
323 // Log a warning so we can see the status on the build bots. No need to 330 // 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 331 // break the test though since this does successfully test the code and
325 // some failure cases. 332 // some failure cases.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 std::map<uint64_t, std::string> expectation; 389 std::map<uint64_t, std::string> expectation;
383 expectation[kJabraMic1.id] = 390 expectation[kJabraMic1.id] =
384 cras_audio_handler_->GetDeviceFromId(kJabraMic1.id)->display_name; 391 cras_audio_handler_->GetDeviceFromId(kJabraMic1.id)->display_name;
385 expectation[kJabraMic2.id] = 392 expectation[kJabraMic2.id] =
386 cras_audio_handler_->GetDeviceFromId(kJabraMic2.id)->display_name; 393 cras_audio_handler_->GetDeviceFromId(kJabraMic2.id)->display_name;
387 expectation[kUSBCameraMic.id] = 394 expectation[kUSBCameraMic.id] =
388 cras_audio_handler_->GetDeviceFromId(kUSBCameraMic.id)->display_name; 395 cras_audio_handler_->GetDeviceFromId(kUSBCameraMic.id)->display_name;
389 396
390 DVLOG(2) << "Testing AudioManagerCras."; 397 DVLOG(2) << "Testing AudioManagerCras.";
391 CreateAudioManagerForTesting<AudioManagerCras>(); 398 CreateAudioManagerForTesting<AudioManagerCras>();
392 AudioDeviceNames device_names; 399 AudioDeviceDescriptions device_descriptions;
393 audio_manager_->GetAudioInputDeviceNames(&device_names); 400 audio_manager_->GetAudioInputDeviceDescriptions(&device_descriptions);
394 CheckDeviceNamesCras(device_names, expectation); 401 CheckDeviceDescriptionsCras(device_descriptions, expectation);
395 } 402 }
396 403
397 // TODO(warx): enable the test once crbug.com/554168 is fixed. 404 // TODO(warx): enable the test once crbug.com/554168 is fixed.
398 TEST_F(AudioManagerTest, DISABLED_EnumerateOutputDevicesCras) { 405 TEST_F(AudioManagerTest, DISABLED_EnumerateOutputDevicesCras) {
399 // Setup the devices without internal mic, so that it doesn't exist 406 // Setup the devices without internal mic, so that it doesn't exist
400 // beamforming capable mic. 407 // beamforming capable mic.
401 AudioNodeList audio_nodes; 408 AudioNodeList audio_nodes;
402 audio_nodes.push_back(kJabraMic1); 409 audio_nodes.push_back(kJabraMic1);
403 audio_nodes.push_back(kJabraMic2); 410 audio_nodes.push_back(kJabraMic2);
404 audio_nodes.push_back(kUSBCameraMic); 411 audio_nodes.push_back(kUSBCameraMic);
405 audio_nodes.push_back(kHDMIOutput); 412 audio_nodes.push_back(kHDMIOutput);
406 audio_nodes.push_back(kJabraSpeaker1); 413 audio_nodes.push_back(kJabraSpeaker1);
407 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes); 414 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes);
408 415
409 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); 416 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable());
410 417
411 // Setup expectation with physical devices. 418 // Setup expectation with physical devices.
412 std::map<uint64_t, std::string> expectation; 419 std::map<uint64_t, std::string> expectation;
413 expectation[kHDMIOutput.id] = 420 expectation[kHDMIOutput.id] =
414 cras_audio_handler_->GetDeviceFromId(kHDMIOutput.id)->display_name; 421 cras_audio_handler_->GetDeviceFromId(kHDMIOutput.id)->display_name;
415 expectation[kJabraSpeaker1.id] = 422 expectation[kJabraSpeaker1.id] =
416 cras_audio_handler_->GetDeviceFromId(kJabraSpeaker1.id)->display_name; 423 cras_audio_handler_->GetDeviceFromId(kJabraSpeaker1.id)->display_name;
417 424
418 DVLOG(2) << "Testing AudioManagerCras."; 425 DVLOG(2) << "Testing AudioManagerCras.";
419 CreateAudioManagerForTesting<AudioManagerCras>(); 426 CreateAudioManagerForTesting<AudioManagerCras>();
420 AudioDeviceNames device_names; 427 AudioDeviceDescriptions device_descriptions;
421 audio_manager_->GetAudioOutputDeviceNames(&device_names); 428 audio_manager_->GetAudioOutputDeviceDescriptions(&device_descriptions);
422 CheckDeviceNamesCras(device_names, expectation); 429 CheckDeviceDescriptionsCras(device_descriptions, expectation);
423 } 430 }
424 #else // !defined(USE_CRAS) 431 #else // !defined(USE_CRAS)
425 432
426 TEST_F(AudioManagerTest, HandleDefaultDeviceIDs) { 433 TEST_F(AudioManagerTest, HandleDefaultDeviceIDs) {
427 // Use a fake manager so we can makeup device ids, this will still use the 434 // Use a fake manager so we can makeup device ids, this will still use the
428 // AudioManagerBase code. 435 // AudioManagerBase code.
429 CreateAudioManagerForTesting<FakeAudioManager>(); 436 CreateAudioManagerForTesting<FakeAudioManager>();
430 HandleDefaultDeviceIDsTest(); 437 HandleDefaultDeviceIDsTest();
431 base::RunLoop().RunUntilIdle(); 438 base::RunLoop().RunUntilIdle();
432 } 439 }
433 440
434 // Test that devices can be enumerated. 441 // Test that devices can be enumerated.
435 TEST_F(AudioManagerTest, EnumerateInputDevices) { 442 TEST_F(AudioManagerTest, EnumerateInputDevices) {
436 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); 443 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable());
437 444
438 AudioDeviceNames device_names; 445 AudioDeviceDescriptions device_descriptions;
439 audio_manager_->GetAudioInputDeviceNames(&device_names); 446 audio_manager_->GetAudioInputDeviceDescriptions(&device_descriptions);
440 CheckDeviceNames(device_names); 447 CheckDeviceDescriptions(device_descriptions);
441 } 448 }
442 449
443 // Test that devices can be enumerated. 450 // Test that devices can be enumerated.
444 TEST_F(AudioManagerTest, EnumerateOutputDevices) { 451 TEST_F(AudioManagerTest, EnumerateOutputDevices) {
445 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); 452 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable());
446 453
447 AudioDeviceNames device_names; 454 AudioDeviceDescriptions device_descriptions;
448 audio_manager_->GetAudioOutputDeviceNames(&device_names); 455 audio_manager_->GetAudioOutputDeviceDescriptions(&device_descriptions);
449 CheckDeviceNames(device_names); 456 CheckDeviceDescriptions(device_descriptions);
450 } 457 }
451 458
452 // Run additional tests for Windows since enumeration can be done using 459 // Run additional tests for Windows since enumeration can be done using
453 // two different APIs. MMDevice is default for Vista and higher and Wave 460 // two different APIs. MMDevice is default for Vista and higher and Wave
454 // is default for XP and lower. 461 // is default for XP and lower.
455 #if defined(OS_WIN) 462 #if defined(OS_WIN)
456 463
457 // Override default enumeration API and force usage of Windows MMDevice. 464 // Override default enumeration API and force usage of Windows MMDevice.
458 // This test will only run on Windows Vista and higher. 465 // This test will only run on Windows Vista and higher.
459 TEST_F(AudioManagerTest, EnumerateInputDevicesWinMMDevice) { 466 TEST_F(AudioManagerTest, EnumerateInputDevicesWinMMDevice) {
460 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); 467 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable());
461 468
462 AudioDeviceNames device_names; 469 AudioDeviceDescriptions device_descriptions;
463 if (!SetMMDeviceEnumeration()) { 470 if (!SetMMDeviceEnumeration()) {
464 // Usage of MMDevice will fail on XP and lower. 471 // Usage of MMDevice will fail on XP and lower.
465 LOG(WARNING) << "MM device enumeration is not supported."; 472 LOG(WARNING) << "MM device enumeration is not supported.";
466 return; 473 return;
467 } 474 }
468 audio_manager_->GetAudioInputDeviceNames(&device_names); 475 audio_manager_->GetAudioInputDeviceDescriptions(&device_descriptions);
469 CheckDeviceNames(device_names); 476 CheckDeviceDescriptions(device_descriptions);
470 } 477 }
471 478
472 TEST_F(AudioManagerTest, EnumerateOutputDevicesWinMMDevice) { 479 TEST_F(AudioManagerTest, EnumerateOutputDevicesWinMMDevice) {
473 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); 480 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable());
474 481
475 AudioDeviceNames device_names; 482 AudioDeviceDescriptions device_descriptions;
476 if (!SetMMDeviceEnumeration()) { 483 if (!SetMMDeviceEnumeration()) {
477 // Usage of MMDevice will fail on XP and lower. 484 // Usage of MMDevice will fail on XP and lower.
478 LOG(WARNING) << "MM device enumeration is not supported."; 485 LOG(WARNING) << "MM device enumeration is not supported.";
479 return; 486 return;
480 } 487 }
481 audio_manager_->GetAudioOutputDeviceNames(&device_names); 488 audio_manager_->GetAudioOutputDeviceDescriptions(&device_descriptions);
482 CheckDeviceNames(device_names); 489 CheckDeviceDescriptions(device_descriptions);
483 } 490 }
484 491
485 // Override default enumeration API and force usage of Windows Wave. 492 // Override default enumeration API and force usage of Windows Wave.
486 // This test will run on Windows XP, Windows Vista and Windows 7. 493 // This test will run on Windows XP, Windows Vista and Windows 7.
487 TEST_F(AudioManagerTest, EnumerateInputDevicesWinWave) { 494 TEST_F(AudioManagerTest, EnumerateInputDevicesWinWave) {
488 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); 495 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable());
489 496
490 AudioDeviceNames device_names; 497 AudioDeviceDescriptions device_descriptions;
491 SetWaveEnumeration(); 498 SetWaveEnumeration();
492 audio_manager_->GetAudioInputDeviceNames(&device_names); 499 audio_manager_->GetAudioInputDeviceDescriptions(&device_descriptions);
493 CheckDeviceNames(device_names); 500 CheckDeviceDescriptions(device_descriptions);
494 } 501 }
495 502
496 TEST_F(AudioManagerTest, EnumerateOutputDevicesWinWave) { 503 TEST_F(AudioManagerTest, EnumerateOutputDevicesWinWave) {
497 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); 504 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable());
498 505
499 AudioDeviceNames device_names; 506 AudioDeviceDescriptions device_descriptions;
500 SetWaveEnumeration(); 507 SetWaveEnumeration();
501 audio_manager_->GetAudioOutputDeviceNames(&device_names); 508 audio_manager_->GetAudioOutputDeviceDescriptions(&device_descriptions);
502 CheckDeviceNames(device_names); 509 CheckDeviceDescriptions(device_descriptions);
503 } 510 }
504 511
505 TEST_F(AudioManagerTest, WinXPDeviceIdUnchanged) { 512 TEST_F(AudioManagerTest, WinXPDeviceIdUnchanged) {
506 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); 513 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable());
507 514
508 AudioDeviceNames xp_device_names; 515 AudioDeviceDescriptions xp_device_descriptions;
509 SetWaveEnumeration(); 516 SetWaveEnumeration();
510 audio_manager_->GetAudioInputDeviceNames(&xp_device_names); 517 audio_manager_->GetAudioInputDeviceDescriptions(&xp_device_descriptions);
511 CheckDeviceNames(xp_device_names); 518 CheckDeviceDescriptions(xp_device_descriptions);
512 519
513 // Device ID should remain unchanged, including the default device ID. 520 // Device ID should remain unchanged, including the default device ID.
514 for (AudioDeviceNames::iterator i = xp_device_names.begin(); 521 for (const auto& description : xp_device_descriptions) {
515 i != xp_device_names.end(); ++i) { 522 EXPECT_EQ(description.unique_id,
516 EXPECT_EQ(i->unique_id, 523 GetDeviceIdFromPCMWaveInAudioInputStream(description.unique_id));
517 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(&params); 621 GetDefaultOutputStreamParameters(&params);
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 (const auto& description : device_descriptions) {
628 it != device_names.end(); 634 EXPECT_FALSE(description.unique_id.empty());
629 ++it) { 635 EXPECT_FALSE(description.device_name.empty());
630 EXPECT_FALSE(it->unique_id.empty()); 636 EXPECT_FALSE(description.group_id.empty());
631 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(description.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) << description.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 inputs;
694 group.push_back(audio_manager_->GetGroupIDInput("input2")); 701 audio_manager_->GetAudioInputDeviceDescriptions(&inputs);
695 group.push_back(audio_manager_->GetGroupIDInput("input3")); 702 AudioDeviceDescriptions outputs;
696 group.push_back(audio_manager_->GetGroupIDOutput("output4")); 703 audio_manager_->GetAudioOutputDeviceDescriptions(&outputs);
697 for (size_t i = 0; i < group.size(); ++i) { 704 EXPECT_EQ(inputs[0].group_id, outputs[1].group_id);
698 for (size_t j = i + 1; j < group.size(); ++j) { 705 EXPECT_EQ(inputs[1].group_id, outputs[1].group_id);
699 EXPECT_NE(group[i], group[j]); 706 EXPECT_EQ(inputs[2].group_id, outputs[2].group_id);
700 } 707 EXPECT_NE(inputs[3].group_id, outputs[3].group_id);
701 } 708 EXPECT_EQ(outputs[4].group_id, outputs[0].group_id);
702 EXPECT_EQ(group[0], audio_manager_->GetGroupIDOutput("output1")); 709 EXPECT_NE(inputs[0].group_id, outputs[0].group_id);
703 EXPECT_EQ(group[0], audio_manager_->GetGroupIDInput("default")); 710 EXPECT_NE(inputs[1].group_id, outputs[2].group_id);
704 EXPECT_EQ(group[1], audio_manager_->GetGroupIDOutput("output2")); 711 EXPECT_NE(inputs[2].group_id, outputs[3].group_id);
705 EXPECT_EQ(group[3], audio_manager_->GetGroupIDOutput("default")); 712 EXPECT_NE(inputs[1].group_id, outputs[3].group_id);
706 } 713 }
707 714
708 } // namespace media 715 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_manager_base.cc ('k') | media/audio/mock_audio_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698