OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/environment.h" | 5 #include "base/environment.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/win/scoped_com_initializer.h" | 7 #include "base/win/scoped_com_initializer.h" |
8 #include "media/audio/audio_manager.h" | 8 #include "media/audio/audio_manager.h" |
9 #include "media/audio/audio_manager_base.h" | 9 #include "media/audio/audio_manager_base.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
10 #if defined(OS_WIN) | 12 #if defined(OS_WIN) |
11 #include "media/audio/win/audio_manager_win.h" | 13 #include "media/audio/win/audio_manager_win.h" |
| 14 #include "media/audio/win/wavein_input_win.h" |
12 #endif | 15 #endif |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 | 16 |
15 using base::win::ScopedCOMInitializer; | 17 using base::win::ScopedCOMInitializer; |
16 using media::AudioDeviceNames; | 18 using media::AudioDeviceNames; |
17 | 19 |
18 // Test fixture which allows us to override the default enumeration API on | 20 // Test fixture which allows us to override the default enumeration API on |
19 // Windows. | 21 // Windows. |
20 class AudioInputDeviceTest | 22 class AudioInputDeviceTest |
21 : public ::testing::Test { | 23 : public ::testing::Test { |
22 protected: | 24 protected: |
23 AudioInputDeviceTest() | 25 AudioInputDeviceTest() |
(...skipping 10 matching lines...) Expand all Loading... |
34 return false; | 36 return false; |
35 | 37 |
36 amw->SetEnumerationType(AudioManagerWin::kMMDeviceEnumeration); | 38 amw->SetEnumerationType(AudioManagerWin::kMMDeviceEnumeration); |
37 return true; | 39 return true; |
38 } | 40 } |
39 | 41 |
40 void SetWaveEnumeration() { | 42 void SetWaveEnumeration() { |
41 AudioManagerWin* amw = static_cast<AudioManagerWin*>(audio_manager_.get()); | 43 AudioManagerWin* amw = static_cast<AudioManagerWin*>(audio_manager_.get()); |
42 amw->SetEnumerationType(AudioManagerWin::kWaveEnumeration); | 44 amw->SetEnumerationType(AudioManagerWin::kWaveEnumeration); |
43 } | 45 } |
| 46 |
| 47 std::string GetDeviceIdFromPCMWaveInAudioInputStream( |
| 48 const std::string& device_id) { |
| 49 AudioManagerWin* amw = static_cast<AudioManagerWin*>(audio_manager_.get()); |
| 50 AudioParameters parameters( |
| 51 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, |
| 52 AudioParameters::kAudioCDSampleRate, 16, |
| 53 1024); |
| 54 scoped_ptr<PCMWaveInAudioInputStream> stream( |
| 55 static_cast<PCMWaveInAudioInputStream*>( |
| 56 amw->CreatePCMWaveInAudioInputStream(parameters, device_id))); |
| 57 return stream.get() ? stream->device_id_ : std::string(); |
| 58 } |
44 #endif | 59 #endif |
45 | 60 |
46 // Helper method which verifies that the device list starts with a valid | 61 // Helper method which verifies that the device list starts with a valid |
47 // default record followed by non-default device names. | 62 // default record followed by non-default device names. |
48 static void CheckDeviceNames(const AudioDeviceNames& device_names) { | 63 static void CheckDeviceNames(const AudioDeviceNames& device_names) { |
49 if (!device_names.empty()) { | 64 if (!device_names.empty()) { |
50 AudioDeviceNames::const_iterator it = device_names.begin(); | 65 AudioDeviceNames::const_iterator it = device_names.begin(); |
51 | 66 |
52 // The first device in the list should always be the default device. | 67 // The first device in the list should always be the default device. |
53 EXPECT_EQ(std::string(AudioManagerBase::kDefaultDeviceName), | 68 EXPECT_EQ(std::string(AudioManagerBase::kDefaultDeviceName), |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 122 |
108 // Override default enumeration API and force usage of Windows Wave. | 123 // Override default enumeration API and force usage of Windows Wave. |
109 // This test will run on Windows XP, Windows Vista and Windows 7. | 124 // This test will run on Windows XP, Windows Vista and Windows 7. |
110 TEST_F(AudioInputDeviceTest, EnumerateDevicesWinWave) { | 125 TEST_F(AudioInputDeviceTest, EnumerateDevicesWinWave) { |
111 AudioDeviceNames device_names; | 126 AudioDeviceNames device_names; |
112 SetWaveEnumeration(); | 127 SetWaveEnumeration(); |
113 audio_manager_->GetAudioInputDeviceNames(&device_names); | 128 audio_manager_->GetAudioInputDeviceNames(&device_names); |
114 CheckDeviceNames(device_names); | 129 CheckDeviceNames(device_names); |
115 } | 130 } |
116 | 131 |
| 132 TEST_F(AudioInputDeviceTest, WinXPDeviceIdUnchanged) { |
| 133 AudioDeviceNames xp_device_names; |
| 134 SetWaveEnumeration(); |
| 135 audio_manager_->GetAudioInputDeviceNames(&xp_device_names); |
| 136 CheckDeviceNames(xp_device_names); |
| 137 |
| 138 // Device ID should remain unchanged, including the default device ID. |
| 139 for (AudioDeviceNames::iterator i = xp_device_names.begin(); |
| 140 i != xp_device_names.end(); ++i) { |
| 141 EXPECT_EQ(i->unique_id, |
| 142 GetDeviceIdFromPCMWaveInAudioInputStream(i->unique_id)); |
| 143 } |
| 144 } |
| 145 |
| 146 TEST_F(AudioInputDeviceTest, ConvertToWinXPDeviceId) { |
| 147 if (!SetMMDeviceEnumeration()) { |
| 148 // Usage of MMDevice will fail on XP and lower. |
| 149 LOG(WARNING) << "MM device enumeration is not supported."; |
| 150 return; |
| 151 } |
| 152 |
| 153 AudioDeviceNames device_names; |
| 154 audio_manager_->GetAudioInputDeviceNames(&device_names); |
| 155 CheckDeviceNames(device_names); |
| 156 |
| 157 for (AudioDeviceNames::iterator i = device_names.begin(); |
| 158 i != device_names.end(); ++i) { |
| 159 std::string converted_id = |
| 160 GetDeviceIdFromPCMWaveInAudioInputStream(i->unique_id); |
| 161 if (i == device_names.begin()) { |
| 162 // The first in the list is the default device ID, which should not be |
| 163 // changed when passed to PCMWaveInAudioInputStream. |
| 164 EXPECT_EQ(i->unique_id, converted_id); |
| 165 } else { |
| 166 // MMDevice-style device IDs should be converted to WaveIn-style device |
| 167 // IDs. |
| 168 EXPECT_NE(i->unique_id, converted_id); |
| 169 } |
| 170 } |
| 171 } |
| 172 |
117 #endif | 173 #endif |
OLD | NEW |