Chromium Code Reviews| 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 "base/win/windows_version.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/wavein_input_win.h" | 28 #include "media/audio/win/wavein_input_win.h" |
| 28 #include "media/audio/win/waveout_output_win.h" | 29 #include "media/audio/win/waveout_output_win.h" |
| 29 #include "media/base/limits.h" | 30 #include "media/base/limits.h" |
| 30 | 31 |
| 31 // Libraries required for the SetupAPI and Wbem APIs used here. | 32 // Libraries required for the SetupAPI and Wbem APIs used here. |
| 32 #pragma comment(lib, "setupapi.lib") | 33 #pragma comment(lib, "setupapi.lib") |
| 33 | 34 |
| 34 // The following are defined in various DDK headers, and we (re)define them | 35 // The following are defined in various DDK headers, and we (re)define them |
| 35 // here to avoid adding the DDK as a chrome dependency. | 36 // here to avoid adding the DDK as a chrome dependency. |
| 36 #define DRV_QUERYDEVICEINTERFACE 0x80c | 37 #define DRV_QUERYDEVICEINTERFACE 0x80c |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 48 static const int kWinMaxChannels = 8; | 49 static const int kWinMaxChannels = 8; |
| 49 | 50 |
| 50 static const int kWinMaxInputChannels = 2; | 51 static const int kWinMaxInputChannels = 2; |
| 51 // We use 3 buffers for recording audio so that if a recording callback takes | 52 // We use 3 buffers for recording audio so that if a recording callback takes |
| 52 // some time to return we won't lose audio. More buffers while recording are | 53 // some time to return we won't lose audio. More buffers while recording are |
| 53 // ok because they don't introduce any delay in recording, unlike in playback | 54 // ok because they don't introduce any delay in recording, unlike in playback |
| 54 // where you first need to fill in that number of buffers before starting to | 55 // where you first need to fill in that number of buffers before starting to |
| 55 // play. | 56 // play. |
| 56 static const int kNumInputBuffers = 3; | 57 static const int kNumInputBuffers = 3; |
| 57 | 58 |
| 59 // TODO(henrika): add comment | |
| 60 AudioManagerWin::EnumerationType AudioManagerWin::enumeration_type_ = | |
|
tommi (sloooow) - chröme
2011/11/22 12:52:37
see comment elsewhere about this global variable.
henrika (OOO until Aug 14)
2011/11/23 09:19:19
Will use private member instead.
| |
| 61 AudioManagerWin::kUninitializedEnumeration; | |
| 62 | |
| 58 static int GetVersionPartAsInt(DWORDLONG num) { | 63 static int GetVersionPartAsInt(DWORDLONG num) { |
| 59 return static_cast<int>(num & 0xffff); | 64 return static_cast<int>(num & 0xffff); |
| 60 } | 65 } |
| 61 | 66 |
| 62 // Returns a string containing the given device's description and installed | 67 // Returns a string containing the given device's description and installed |
| 63 // driver version. | 68 // driver version. |
| 64 static string16 GetDeviceAndDriverInfo(HDEVINFO device_info, | 69 static string16 GetDeviceAndDriverInfo(HDEVINFO device_info, |
| 65 SP_DEVINFO_DATA* device_data) { | 70 SP_DEVINFO_DATA* device_data) { |
| 66 // Save the old install params setting and set a flag for the | 71 // Save the old install params setting and set a flag for the |
| 67 // SetupDiBuildDriverInfoList below to return only the installed drivers. | 72 // SetupDiBuildDriverInfoList below to return only the installed drivers. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 92 } | 97 } |
| 93 | 98 |
| 94 SetupDiSetDeviceInstallParams(device_info, device_data, | 99 SetupDiSetDeviceInstallParams(device_info, device_data, |
| 95 &old_device_install_params); | 100 &old_device_install_params); |
| 96 | 101 |
| 97 return device_and_driver_info; | 102 return device_and_driver_info; |
| 98 } | 103 } |
| 99 | 104 |
| 100 AudioManagerWin::AudioManagerWin() | 105 AudioManagerWin::AudioManagerWin() |
| 101 : num_output_streams_(0) { | 106 : num_output_streams_(0) { |
| 107 if (base::win::GetVersion() <= base::win::VERSION_XP) { | |
| 108 // Use the Wave API for device enumeration if XP or lower. | |
| 109 enumeration_type_ = kWaveEnumeration; | |
| 110 } else { | |
| 111 // Use the MMDevice API for device enumeration if Vista or higher. | |
| 112 enumeration_type_ = kMMDeviceEnumeration; | |
| 113 } | |
| 102 } | 114 } |
| 103 | 115 |
| 104 AudioManagerWin::~AudioManagerWin() { | 116 AudioManagerWin::~AudioManagerWin() { |
| 105 } | 117 } |
| 106 | 118 |
| 107 bool AudioManagerWin::HasAudioOutputDevices() { | 119 bool AudioManagerWin::HasAudioOutputDevices() { |
| 108 return (::waveOutGetNumDevs() != 0); | 120 return (::waveOutGetNumDevs() != 0); |
| 109 } | 121 } |
| 110 | 122 |
| 111 bool AudioManagerWin::HasAudioInputDevices() { | 123 bool AudioManagerWin::HasAudioInputDevices() { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 FilePath path; | 280 FilePath path; |
| 269 PathService::Get(base::DIR_SYSTEM, &path); | 281 PathService::Get(base::DIR_SYSTEM, &path); |
| 270 path = path.Append(program); | 282 path = path.Append(program); |
| 271 CommandLine command_line(path); | 283 CommandLine command_line(path); |
| 272 command_line.AppendArg(argument); | 284 command_line.AppendArg(argument); |
| 273 base::LaunchProcess(command_line, base::LaunchOptions(), NULL); | 285 base::LaunchProcess(command_line, base::LaunchOptions(), NULL); |
| 274 } | 286 } |
| 275 | 287 |
| 276 void AudioManagerWin::GetAudioInputDeviceNames( | 288 void AudioManagerWin::GetAudioInputDeviceNames( |
| 277 media::AudioDeviceNames* device_names) { | 289 media::AudioDeviceNames* device_names) { |
| 278 // TODO(xians): query a full list of valid devices. | 290 DCHECK(enumeration_type() != kUninitializedEnumeration); |
| 279 if (HasAudioInputDevices()) { | 291 // Enumerate all active audio-endpoint capture devices. |
| 280 // Add the default device to the list. | 292 if (enumeration_type() == kWaveEnumeration) { |
| 281 // We use index 0 to make up the unique_id to identify the | 293 // Utilize the Wave API for Windows XP. |
| 282 // default devices. | 294 GetInputDeviceNamesWinXP(device_names); |
| 295 } else { | |
| 296 // Utilize the MMDevice API (part of Core Audio) for Vista and higher. | |
| 297 GetInputDeviceNamesWin(device_names); | |
| 298 } | |
| 299 | |
| 300 // Always add default device parameters as first element. | |
| 301 if (!device_names->empty()) { | |
| 283 media::AudioDeviceName name; | 302 media::AudioDeviceName name; |
| 284 name.device_name = AudioManagerBase::kDefaultDeviceName; | 303 name.device_name = AudioManagerBase::kDefaultDeviceName; |
| 304 // TODO(henrika): modify to AudioManagerBase::kXXX when pending patch has | |
| 305 // landed. | |
| 285 name.unique_id = "0"; | 306 name.unique_id = "0"; |
| 286 device_names->push_back(name); | 307 device_names->push_front(name); |
| 287 } | 308 } |
| 288 } | 309 } |
| 289 | 310 |
| 290 // static | 311 // static |
| 291 AudioManager* AudioManager::CreateAudioManager() { | 312 AudioManager* AudioManager::CreateAudioManager() { |
| 292 return new AudioManagerWin(); | 313 return new AudioManagerWin(); |
| 293 } | 314 } |
| OLD | NEW |