| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_io.h" | 5 #include "media/audio/audio_io.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <objbase.h> // This has to be before initguid.h | 8 #include <objbase.h> // This has to be before initguid.h |
| 9 #include <initguid.h> | 9 #include <initguid.h> |
| 10 #include <mmsystem.h> | 10 #include <mmsystem.h> |
| 11 #include <setupapi.h> | 11 #include <setupapi.h> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/file_path.h" | 15 #include "base/file_path.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 18 #include "base/process_util.h" | 18 #include "base/process_util.h" |
| 19 #include "base/string_number_conversions.h" | 19 #include "base/string_number_conversions.h" |
| 20 #include "base/string_util.h" | 20 #include "base/string_util.h" |
| 21 #include "base/win/windows_version.h" | 21 #include "media/audio/audio_util.h" |
| 22 #include "media/audio/fake_audio_input_stream.h" | 22 #include "media/audio/fake_audio_input_stream.h" |
| 23 #include "media/audio/fake_audio_output_stream.h" | 23 #include "media/audio/fake_audio_output_stream.h" |
| 24 #include "media/audio/win/audio_low_latency_input_win.h" | 24 #include "media/audio/win/audio_low_latency_input_win.h" |
| 25 #include "media/audio/win/audio_low_latency_output_win.h" | 25 #include "media/audio/win/audio_low_latency_output_win.h" |
| 26 #include "media/audio/win/audio_manager_win.h" | 26 #include "media/audio/win/audio_manager_win.h" |
| 27 #include "media/audio/win/device_enumeration_win.h" | 27 #include "media/audio/win/device_enumeration_win.h" |
| 28 #include "media/audio/win/wavein_input_win.h" | 28 #include "media/audio/win/wavein_input_win.h" |
| 29 #include "media/audio/win/waveout_output_win.h" | 29 #include "media/audio/win/waveout_output_win.h" |
| 30 #include "media/base/limits.h" | 30 #include "media/base/limits.h" |
| 31 | 31 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 93 } |
| 94 | 94 |
| 95 SetupDiSetDeviceInstallParams(device_info, device_data, | 95 SetupDiSetDeviceInstallParams(device_info, device_data, |
| 96 &old_device_install_params); | 96 &old_device_install_params); |
| 97 | 97 |
| 98 return device_and_driver_info; | 98 return device_and_driver_info; |
| 99 } | 99 } |
| 100 | 100 |
| 101 AudioManagerWin::AudioManagerWin() | 101 AudioManagerWin::AudioManagerWin() |
| 102 : num_output_streams_(0) { | 102 : num_output_streams_(0) { |
| 103 if (base::win::GetVersion() <= base::win::VERSION_XP) { | 103 if (!media::WindowsSupportWASAPI()) { |
| 104 // Use the Wave API for device enumeration if XP or lower. | 104 // Use the Wave API for device enumeration if XP or lower. |
| 105 enumeration_type_ = kWaveEnumeration; | 105 enumeration_type_ = kWaveEnumeration; |
| 106 } else { | 106 } else { |
| 107 // Use the MMDevice API for device enumeration if Vista or higher. | 107 // Use the MMDevice API for device enumeration if Vista or higher. |
| 108 enumeration_type_ = kMMDeviceEnumeration; | 108 enumeration_type_ = kMMDeviceEnumeration; |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 | 111 |
| 112 AudioManagerWin::~AudioManagerWin() { | 112 AudioManagerWin::~AudioManagerWin() { |
| 113 } | 113 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 134 return NULL; | 134 return NULL; |
| 135 } | 135 } |
| 136 | 136 |
| 137 if (params.format == AudioParameters::AUDIO_MOCK) { | 137 if (params.format == AudioParameters::AUDIO_MOCK) { |
| 138 return FakeAudioOutputStream::MakeFakeStream(params); | 138 return FakeAudioOutputStream::MakeFakeStream(params); |
| 139 } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) { | 139 } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) { |
| 140 num_output_streams_++; | 140 num_output_streams_++; |
| 141 return new PCMWaveOutAudioOutputStream(this, params, 3, WAVE_MAPPER); | 141 return new PCMWaveOutAudioOutputStream(this, params, 3, WAVE_MAPPER); |
| 142 } else if (params.format == AudioParameters::AUDIO_PCM_LOW_LATENCY) { | 142 } else if (params.format == AudioParameters::AUDIO_PCM_LOW_LATENCY) { |
| 143 num_output_streams_++; | 143 num_output_streams_++; |
| 144 if (base::win::GetVersion() <= base::win::VERSION_XP) { | 144 if (!media::WindowsSupportWASAPI()) { |
| 145 // Fall back to Windows Wave implementation on Windows XP or lower. | 145 // Fall back to Windows Wave implementation on Windows XP or lower. |
| 146 DLOG(INFO) << "Using WaveOut since WASAPI requires at least Vista."; | 146 DLOG(INFO) << "Using WaveOut since WASAPI requires at least Vista."; |
| 147 return new PCMWaveOutAudioOutputStream(this, params, 2, WAVE_MAPPER); | 147 return new PCMWaveOutAudioOutputStream(this, params, 2, WAVE_MAPPER); |
| 148 } else { | 148 } else { |
| 149 // TODO(henrika): improve possibility to specify audio endpoint. | 149 // TODO(henrika): improve possibility to specify audio endpoint. |
| 150 // Use the default device (same as for Wave) for now to be compatible. | 150 // Use the default device (same as for Wave) for now to be compatible. |
| 151 return new WASAPIAudioOutputStream(this, params, eConsole); | 151 return new WASAPIAudioOutputStream(this, params, eConsole); |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 return NULL; | 154 return NULL; |
| 155 } | 155 } |
| 156 | 156 |
| 157 // Factory for the implementations of AudioInputStream. | 157 // Factory for the implementations of AudioInputStream. |
| 158 AudioInputStream* AudioManagerWin::MakeAudioInputStream( | 158 AudioInputStream* AudioManagerWin::MakeAudioInputStream( |
| 159 const AudioParameters& params, const std::string& device_id) { | 159 const AudioParameters& params, const std::string& device_id) { |
| 160 if (!params.IsValid() || (params.channels > kWinMaxInputChannels) || | 160 if (!params.IsValid() || (params.channels > kWinMaxInputChannels) || |
| 161 device_id.empty()) | 161 device_id.empty()) |
| 162 return NULL; | 162 return NULL; |
| 163 | 163 |
| 164 if (params.format == AudioParameters::AUDIO_MOCK) { | 164 if (params.format == AudioParameters::AUDIO_MOCK) { |
| 165 return FakeAudioInputStream::MakeFakeStream(params); | 165 return FakeAudioInputStream::MakeFakeStream(params); |
| 166 } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) { | 166 } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) { |
| 167 return new PCMWaveInAudioInputStream(this, params, kNumInputBuffers, | 167 return new PCMWaveInAudioInputStream(this, params, kNumInputBuffers, |
| 168 WAVE_MAPPER); | 168 WAVE_MAPPER); |
| 169 } else if (params.format == AudioParameters::AUDIO_PCM_LOW_LATENCY) { | 169 } else if (params.format == AudioParameters::AUDIO_PCM_LOW_LATENCY) { |
| 170 if (base::win::GetVersion() <= base::win::VERSION_XP) { | 170 if (!media::WindowsSupportWASAPI()) { |
| 171 // Fall back to Windows Wave implementation on Windows XP or lower. | 171 // Fall back to Windows Wave implementation on Windows XP or lower. |
| 172 DLOG(INFO) << "Using WaveIn since WASAPI requires at least Vista."; | 172 DLOG(INFO) << "Using WaveIn since WASAPI requires at least Vista."; |
| 173 // TODO(xians): Handle the non-default device. | 173 // TODO(xians): Handle the non-default device. |
| 174 if (device_id == AudioManagerBase::kDefaultDeviceId) | 174 if (device_id == AudioManagerBase::kDefaultDeviceId) |
| 175 return new PCMWaveInAudioInputStream(this, params, kNumInputBuffers, | 175 return new PCMWaveInAudioInputStream(this, params, kNumInputBuffers, |
| 176 WAVE_MAPPER); | 176 WAVE_MAPPER); |
| 177 } else { | 177 } else { |
| 178 // TODO(henrika): improve possibility to specify audio endpoint. | 178 // TODO(henrika): improve possibility to specify audio endpoint. |
| 179 // Use the default device (same as for Wave) for now to be compatible. | 179 // Use the default device (same as for Wave) for now to be compatible. |
| 180 // TODO(xians): Handle the non-default device. | 180 // TODO(xians): Handle the non-default device. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 return string16(); | 265 return string16(); |
| 266 } | 266 } |
| 267 | 267 |
| 268 bool AudioManagerWin::CanShowAudioInputSettings() { | 268 bool AudioManagerWin::CanShowAudioInputSettings() { |
| 269 return true; | 269 return true; |
| 270 } | 270 } |
| 271 | 271 |
| 272 void AudioManagerWin::ShowAudioInputSettings() { | 272 void AudioManagerWin::ShowAudioInputSettings() { |
| 273 std::wstring program; | 273 std::wstring program; |
| 274 std::string argument; | 274 std::string argument; |
| 275 if (base::win::GetVersion() <= base::win::VERSION_XP) { | 275 if (!media::WindowsSupportWASAPI()) { |
| 276 program = L"sndvol32.exe"; | 276 program = L"sndvol32.exe"; |
| 277 argument = "-R"; | 277 argument = "-R"; |
| 278 } else { | 278 } else { |
| 279 program = L"control.exe"; | 279 program = L"control.exe"; |
| 280 argument = "mmsys.cpl,,1"; | 280 argument = "mmsys.cpl,,1"; |
| 281 } | 281 } |
| 282 | 282 |
| 283 FilePath path; | 283 FilePath path; |
| 284 PathService::Get(base::DIR_SYSTEM, &path); | 284 PathService::Get(base::DIR_SYSTEM, &path); |
| 285 path = path.Append(program); | 285 path = path.Append(program); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 306 name.device_name = AudioManagerBase::kDefaultDeviceName; | 306 name.device_name = AudioManagerBase::kDefaultDeviceName; |
| 307 name.unique_id = AudioManagerBase::kDefaultDeviceId; | 307 name.unique_id = AudioManagerBase::kDefaultDeviceId; |
| 308 device_names->push_front(name); | 308 device_names->push_front(name); |
| 309 } | 309 } |
| 310 } | 310 } |
| 311 | 311 |
| 312 /// static | 312 /// static |
| 313 AudioManager* AudioManager::CreateAudioManager() { | 313 AudioManager* AudioManager::CreateAudioManager() { |
| 314 return new AudioManagerWin(); | 314 return new AudioManagerWin(); |
| 315 } | 315 } |
| OLD | NEW |