| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/environment.h" | 6 #include "base/environment.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "media/audio/audio_manager.h" | 10 #include "media/audio/audio_manager.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #if defined(USE_PULSEAUDIO) | 26 #if defined(USE_PULSEAUDIO) |
| 27 #include "media/audio/pulse/audio_manager_pulse.h" | 27 #include "media/audio/pulse/audio_manager_pulse.h" |
| 28 #endif // defined(USE_PULSEAUDIO) | 28 #endif // defined(USE_PULSEAUDIO) |
| 29 | 29 |
| 30 namespace media { | 30 namespace media { |
| 31 | 31 |
| 32 // Test fixture which allows us to override the default enumeration API on | 32 // Test fixture which allows us to override the default enumeration API on |
| 33 // Windows. | 33 // Windows. |
| 34 class AudioManagerTest : public ::testing::Test { | 34 class AudioManagerTest : public ::testing::Test { |
| 35 protected: | 35 protected: |
| 36 AudioManagerTest() : audio_manager_(AudioManager::CreateForTesting()) {} | 36 AudioManagerTest() |
| 37 : audio_manager_(AudioManager::CreateForTesting()) |
| 38 #if defined(OS_WIN) |
| 39 , com_init_(base::win::ScopedCOMInitializer::kMTA) |
| 40 #endif |
| 41 { |
| 42 // Wait for audio thread initialization to complete. Otherwise the |
| 43 // enumeration type may not have been set yet. |
| 44 base::WaitableEvent event(false, false); |
| 45 audio_manager_->GetTaskRunner()->PostTask(FROM_HERE, base::Bind( |
| 46 &base::WaitableEvent::Signal, base::Unretained(&event))); |
| 47 event.Wait(); |
| 48 } |
| 37 | 49 |
| 38 #if defined(OS_WIN) | 50 #if defined(OS_WIN) |
| 39 bool SetMMDeviceEnumeration() { | 51 bool SetMMDeviceEnumeration() { |
| 40 AudioManagerWin* amw = static_cast<AudioManagerWin*>(audio_manager_.get()); | 52 AudioManagerWin* amw = static_cast<AudioManagerWin*>(audio_manager_.get()); |
| 41 // Windows Wave is used as default if Windows XP was detected => | 53 // Windows Wave is used as default if Windows XP was detected => |
| 42 // return false since MMDevice is not supported on XP. | 54 // return false since MMDevice is not supported on XP. |
| 43 if (amw->enumeration_type() == AudioManagerWin::kWaveEnumeration) | 55 if (amw->enumeration_type() == AudioManagerWin::kWaveEnumeration) |
| 44 return false; | 56 return false; |
| 45 | 57 |
| 46 amw->set_enumeration_type(AudioManagerWin::kMMDeviceEnumeration); | 58 amw->SetEnumerationType(AudioManagerWin::kMMDeviceEnumeration); |
| 47 return true; | 59 return true; |
| 48 } | 60 } |
| 49 | 61 |
| 50 void SetWaveEnumeration() { | 62 void SetWaveEnumeration() { |
| 51 AudioManagerWin* amw = static_cast<AudioManagerWin*>(audio_manager_.get()); | 63 AudioManagerWin* amw = static_cast<AudioManagerWin*>(audio_manager_.get()); |
| 52 amw->set_enumeration_type(AudioManagerWin::kWaveEnumeration); | 64 amw->SetEnumerationType(AudioManagerWin::kWaveEnumeration); |
| 53 } | 65 } |
| 54 | 66 |
| 55 std::string GetDeviceIdFromPCMWaveInAudioInputStream( | 67 std::string GetDeviceIdFromPCMWaveInAudioInputStream( |
| 56 const std::string& device_id) { | 68 const std::string& device_id) { |
| 57 AudioManagerWin* amw = static_cast<AudioManagerWin*>(audio_manager_.get()); | 69 AudioManagerWin* amw = static_cast<AudioManagerWin*>(audio_manager_.get()); |
| 58 AudioParameters parameters( | 70 AudioParameters parameters( |
| 59 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, | 71 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, |
| 60 AudioParameters::kAudioCDSampleRate, 16, | 72 AudioParameters::kAudioCDSampleRate, 16, |
| 61 1024); | 73 1024); |
| 62 scoped_ptr<PCMWaveInAudioInputStream> stream( | 74 scoped_ptr<PCMWaveInAudioInputStream> stream( |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 DVLOG(2) << it->unique_id << " matches with " << output_device_id; | 371 DVLOG(2) << it->unique_id << " matches with " << output_device_id; |
| 360 found_an_associated_device = true; | 372 found_an_associated_device = true; |
| 361 } | 373 } |
| 362 } | 374 } |
| 363 | 375 |
| 364 EXPECT_TRUE(found_an_associated_device); | 376 EXPECT_TRUE(found_an_associated_device); |
| 365 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 377 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
| 366 } | 378 } |
| 367 | 379 |
| 368 } // namespace media | 380 } // namespace media |
| OLD | NEW |