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

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

Issue 2646423005: Remove the wave based audio capture implementation for Windows (Closed)
Patch Set: Minor cleanup + documentation Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/audio/BUILD.gn ('k') | media/audio/win/audio_device_listener_win.cc » ('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"
(...skipping 13 matching lines...) Expand all
24 #include "media/audio/fake_audio_manager.h" 24 #include "media/audio/fake_audio_manager.h"
25 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
26 26
27 #if defined(USE_ALSA) 27 #if defined(USE_ALSA)
28 #include "media/audio/alsa/audio_manager_alsa.h" 28 #include "media/audio/alsa/audio_manager_alsa.h"
29 #endif // defined(USE_ALSA) 29 #endif // defined(USE_ALSA)
30 30
31 #if defined(OS_WIN) 31 #if defined(OS_WIN)
32 #include "base/win/scoped_com_initializer.h" 32 #include "base/win/scoped_com_initializer.h"
33 #include "media/audio/win/audio_manager_win.h" 33 #include "media/audio/win/audio_manager_win.h"
34 #include "media/audio/win/wavein_input_win.h"
35 #endif 34 #endif
36 35
37 #if defined(USE_PULSEAUDIO) 36 #if defined(USE_PULSEAUDIO)
38 #include "media/audio/pulse/audio_manager_pulse.h" 37 #include "media/audio/pulse/audio_manager_pulse.h"
39 #endif // defined(USE_PULSEAUDIO) 38 #endif // defined(USE_PULSEAUDIO)
40 39
41 #if defined(USE_CRAS) 40 #if defined(USE_CRAS)
42 #include "chromeos/audio/audio_devices_pref_handler_stub.h" 41 #include "chromeos/audio/audio_devices_pref_handler_stub.h"
43 #include "chromeos/audio/cras_audio_handler.h" 42 #include "chromeos/audio/cras_audio_handler.h"
44 #include "chromeos/dbus/dbus_thread_manager.h" 43 #include "chromeos/dbus/dbus_thread_manager.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 chromeos::CrasAudioHandler::Initialize(audio_pref_handler_); 225 chromeos::CrasAudioHandler::Initialize(audio_pref_handler_);
227 cras_audio_handler_ = chromeos::CrasAudioHandler::Get(); 226 cras_audio_handler_ = chromeos::CrasAudioHandler::Get();
228 base::RunLoop().RunUntilIdle(); 227 base::RunLoop().RunUntilIdle();
229 } 228 }
230 #endif // defined(USE_CRAS) 229 #endif // defined(USE_CRAS)
231 230
232 protected: 231 protected:
233 AudioManagerTest() { CreateAudioManagerForTesting(); } 232 AudioManagerTest() { CreateAudioManagerForTesting(); }
234 ~AudioManagerTest() override {} 233 ~AudioManagerTest() override {}
235 234
236 #if defined(OS_WIN)
237 bool SetMMDeviceEnumeration() {
238 AudioManagerWin* amw = static_cast<AudioManagerWin*>(audio_manager_.get());
239 // Windows Wave is used as default if Windows XP was detected =>
240 // return false since MMDevice is not supported on XP.
241 if (amw->enumeration_type() == AudioManagerWin::kWaveEnumeration)
242 return false;
243
244 amw->SetEnumerationType(AudioManagerWin::kMMDeviceEnumeration);
245 return true;
246 }
247
248 void SetWaveEnumeration() {
249 AudioManagerWin* amw = static_cast<AudioManagerWin*>(audio_manager_.get());
250 amw->SetEnumerationType(AudioManagerWin::kWaveEnumeration);
251 }
252
253 std::string GetDeviceIdFromPCMWaveInAudioInputStream(
254 const std::string& device_id) {
255 AudioManagerWin* amw = static_cast<AudioManagerWin*>(audio_manager_.get());
256 AudioParameters parameters(
257 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
258 AudioParameters::kAudioCDSampleRate, 16,
259 1024);
260 std::unique_ptr<PCMWaveInAudioInputStream> stream(
261 static_cast<PCMWaveInAudioInputStream*>(
262 amw->CreatePCMWaveInAudioInputStream(parameters, device_id)));
263 return stream.get() ? stream->device_id_ : std::string();
264 }
265 #endif
266
267 // Helper method which verifies that the device list starts with a valid 235 // Helper method which verifies that the device list starts with a valid
268 // default record followed by non-default device names. 236 // default record followed by non-default device names.
269 static void CheckDeviceDescriptions( 237 static void CheckDeviceDescriptions(
270 const AudioDeviceDescriptions& device_descriptions) { 238 const AudioDeviceDescriptions& device_descriptions) {
271 DVLOG(2) << "Got " << device_descriptions.size() << " audio devices."; 239 DVLOG(2) << "Got " << device_descriptions.size() << " audio devices.";
272 if (!device_descriptions.empty()) { 240 if (!device_descriptions.empty()) {
273 AudioDeviceDescriptions::const_iterator it = device_descriptions.begin(); 241 AudioDeviceDescriptions::const_iterator it = device_descriptions.begin();
274 242
275 // The first device in the list should always be the default device. 243 // The first device in the list should always be the default device.
276 EXPECT_EQ(AudioDeviceDescription::GetDefaultDeviceName(), 244 EXPECT_EQ(AudioDeviceDescription::GetDefaultDeviceName(),
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 // two different APIs. MMDevice is default for Vista and higher and Wave 440 // two different APIs. MMDevice is default for Vista and higher and Wave
473 // is default for XP and lower. 441 // is default for XP and lower.
474 #if defined(OS_WIN) 442 #if defined(OS_WIN)
475 443
476 // Override default enumeration API and force usage of Windows MMDevice. 444 // Override default enumeration API and force usage of Windows MMDevice.
477 // This test will only run on Windows Vista and higher. 445 // This test will only run on Windows Vista and higher.
478 TEST_F(AudioManagerTest, EnumerateInputDevicesWinMMDevice) { 446 TEST_F(AudioManagerTest, EnumerateInputDevicesWinMMDevice) {
479 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); 447 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable());
480 448
481 AudioDeviceDescriptions device_descriptions; 449 AudioDeviceDescriptions device_descriptions;
482 if (!SetMMDeviceEnumeration()) {
483 // Usage of MMDevice will fail on XP and lower.
484 LOG(WARNING) << "MM device enumeration is not supported.";
485 return;
486 }
487 audio_manager_->GetAudioInputDeviceDescriptions(&device_descriptions); 450 audio_manager_->GetAudioInputDeviceDescriptions(&device_descriptions);
488 CheckDeviceDescriptions(device_descriptions); 451 CheckDeviceDescriptions(device_descriptions);
489 } 452 }
490 453
491 TEST_F(AudioManagerTest, EnumerateOutputDevicesWinMMDevice) { 454 TEST_F(AudioManagerTest, EnumerateOutputDevicesWinMMDevice) {
492 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); 455 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable());
493 456
494 AudioDeviceDescriptions device_descriptions; 457 AudioDeviceDescriptions device_descriptions;
495 if (!SetMMDeviceEnumeration()) {
496 // Usage of MMDevice will fail on XP and lower.
497 LOG(WARNING) << "MM device enumeration is not supported.";
498 return;
499 }
500 audio_manager_->GetAudioOutputDeviceDescriptions(&device_descriptions); 458 audio_manager_->GetAudioOutputDeviceDescriptions(&device_descriptions);
501 CheckDeviceDescriptions(device_descriptions); 459 CheckDeviceDescriptions(device_descriptions);
502 } 460 }
503
504 // Override default enumeration API and force usage of Windows Wave.
505 // This test will run on Windows XP, Windows Vista and Windows 7.
506 TEST_F(AudioManagerTest, EnumerateInputDevicesWinWave) {
507 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable());
508
509 AudioDeviceDescriptions device_descriptions;
510 SetWaveEnumeration();
511 audio_manager_->GetAudioInputDeviceDescriptions(&device_descriptions);
512 CheckDeviceDescriptions(device_descriptions);
513 }
514
515 TEST_F(AudioManagerTest, EnumerateOutputDevicesWinWave) {
516 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable());
517
518 AudioDeviceDescriptions device_descriptions;
519 SetWaveEnumeration();
520 audio_manager_->GetAudioOutputDeviceDescriptions(&device_descriptions);
521 CheckDeviceDescriptions(device_descriptions);
522 }
523
524 TEST_F(AudioManagerTest, WinXPDeviceIdUnchanged) {
525 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable());
526
527 AudioDeviceDescriptions xp_device_descriptions;
528 SetWaveEnumeration();
529 audio_manager_->GetAudioInputDeviceDescriptions(&xp_device_descriptions);
530 CheckDeviceDescriptions(xp_device_descriptions);
531
532 // Device ID should remain unchanged, including the default device ID.
533 for (const auto& description : xp_device_descriptions) {
534 EXPECT_EQ(description.unique_id,
535 GetDeviceIdFromPCMWaveInAudioInputStream(description.unique_id));
536 }
537 }
538
539 TEST_F(AudioManagerTest, ConvertToWinXPInputDeviceId) {
540 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable());
541
542 if (!SetMMDeviceEnumeration()) {
543 // Usage of MMDevice will fail on XP and lower.
544 LOG(WARNING) << "MM device enumeration is not supported.";
545 return;
546 }
547
548 AudioDeviceDescriptions device_descriptions;
549 audio_manager_->GetAudioInputDeviceDescriptions(&device_descriptions);
550 CheckDeviceDescriptions(device_descriptions);
551
552 for (AudioDeviceDescriptions::iterator i = device_descriptions.begin();
553 i != device_descriptions.end(); ++i) {
554 std::string converted_id =
555 GetDeviceIdFromPCMWaveInAudioInputStream(i->unique_id);
556 if (i == device_descriptions.begin()) {
557 // The first in the list is the default device ID, which should not be
558 // changed when passed to PCMWaveInAudioInputStream.
559 EXPECT_EQ(i->unique_id, converted_id);
560 } else {
561 // MMDevice-style device IDs should be converted to WaveIn-style device
562 // IDs.
563 EXPECT_NE(i->unique_id, converted_id);
564 }
565 }
566 }
567
568 #endif // defined(OS_WIN) 461 #endif // defined(OS_WIN)
569 462
570 #if defined(USE_PULSEAUDIO) 463 #if defined(USE_PULSEAUDIO)
571 // On Linux, there are two implementations available and both can 464 // On Linux, there are two implementations available and both can
572 // sometimes be tested on a single system. These tests specifically 465 // sometimes be tested on a single system. These tests specifically
573 // test Pulseaudio. 466 // test Pulseaudio.
574 467
575 TEST_F(AudioManagerTest, EnumerateInputDevicesPulseaudio) { 468 TEST_F(AudioManagerTest, EnumerateInputDevicesPulseaudio) {
576 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); 469 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable());
577 470
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 EXPECT_EQ(inputs[2].group_id, outputs[2].group_id); 611 EXPECT_EQ(inputs[2].group_id, outputs[2].group_id);
719 EXPECT_NE(inputs[3].group_id, outputs[3].group_id); 612 EXPECT_NE(inputs[3].group_id, outputs[3].group_id);
720 EXPECT_EQ(outputs[4].group_id, outputs[0].group_id); 613 EXPECT_EQ(outputs[4].group_id, outputs[0].group_id);
721 EXPECT_NE(inputs[0].group_id, outputs[0].group_id); 614 EXPECT_NE(inputs[0].group_id, outputs[0].group_id);
722 EXPECT_NE(inputs[1].group_id, outputs[2].group_id); 615 EXPECT_NE(inputs[1].group_id, outputs[2].group_id);
723 EXPECT_NE(inputs[2].group_id, outputs[3].group_id); 616 EXPECT_NE(inputs[2].group_id, outputs[3].group_id);
724 EXPECT_NE(inputs[1].group_id, outputs[3].group_id); 617 EXPECT_NE(inputs[1].group_id, outputs[3].group_id);
725 } 618 }
726 619
727 } // namespace media 620 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/BUILD.gn ('k') | media/audio/win/audio_device_listener_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698