audio_manager_win.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
11d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert// Copyright (c) 2012 The Chromium Authors. All rights reserved.
21d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert// Use of this source code is governed by a BSD-style license that can be
31d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert// found in the LICENSE file.
41d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
51d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "media/audio/audio_io.h"
61d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
71d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include <windows.h>
81d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include <objbase.h>  // This has to be before initguid.h
91d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include <initguid.h>
101d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include <mmsystem.h>
111d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include <setupapi.h>
121d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
131d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "base/bind.h"
141d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "base/bind_helpers.h"
151d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "base/command_line.h"
161d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "base/files/file_path.h"
171d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "base/memory/scoped_ptr.h"
181d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "base/message_loop.h"
191d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "base/path_service.h"
201d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "base/process_util.h"
211d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "base/string_number_conversions.h"
221d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "base/string_util.h"
231d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "media/audio/audio_parameters.h"
241d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "media/audio/audio_util.h"
251d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "media/audio/win/audio_device_listener_win.h"
261d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "media/audio/win/audio_low_latency_input_win.h"
271d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "media/audio/win/audio_low_latency_output_win.h"
281d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "media/audio/win/audio_manager_win.h"
291d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "media/audio/win/audio_unified_win.h"
301d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "media/audio/win/core_audio_util_win.h"
311d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "media/audio/win/device_enumeration_win.h"
321d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "media/audio/win/wavein_input_win.h"
331d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "media/audio/win/waveout_output_win.h"
341d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "media/base/bind_to_loop.h"
351d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "media/base/channel_layout.h"
361d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "media/base/limits.h"
371d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#include "media/base/media_switches.h"
381d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
391d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert// Libraries required for the SetupAPI and Wbem APIs used here.
401d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#pragma comment(lib, "setupapi.lib")
411d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
421d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert// The following are defined in various DDK headers, and we (re)define them here
431d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert// to avoid adding the DDK as a chrome dependency.
441d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#define DRV_QUERYDEVICEINTERFACE 0x80c
451d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#define DRVM_MAPPER_PREFERRED_GET 0x2015
461d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert#define DRV_QUERYDEVICEINTERFACESIZE 0x80d
471d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn BringertDEFINE_GUID(AM_KSCATEGORY_AUDIO, 0x6994ad04, 0x93ef, 0x11d0,
481d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert            0xa3, 0xcc, 0x00, 0xa0, 0xc9, 0x22, 0x31, 0x96);
491d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
501d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertnamespace media {
511d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
521d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert// Maximum number of output streams that can be open simultaneously.
531d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertstatic const int kMaxOutputStreams = 50;
541d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
551d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert// Up to 8 channels can be passed to the driver.  This should work, given the
561d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert// right drivers, but graceful error handling is needed.
571d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertstatic const int kWinMaxChannels = 8;
581d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
591d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert// We use 3 buffers for recording audio so that if a recording callback takes
601d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert// some time to return we won't lose audio. More buffers while recording are
611d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert// ok because they don't introduce any delay in recording, unlike in playback
621d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert// where you first need to fill in that number of buffers before starting to
631d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert// play.
641d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertstatic const int kNumInputBuffers = 3;
651d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
661d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert// Buffer size to use for input and output stream when a proper size can't be
671d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert// determined from the system
681d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertstatic const int kFallbackBufferSize = 2048;
691d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
701d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertstatic int GetVersionPartAsInt(DWORDLONG num) {
71  return static_cast<int>(num & 0xffff);
72}
73
74// Returns a string containing the given device's description and installed
75// driver version.
76static string16 GetDeviceAndDriverInfo(HDEVINFO device_info,
77                                       SP_DEVINFO_DATA* device_data) {
78  // Save the old install params setting and set a flag for the
79  // SetupDiBuildDriverInfoList below to return only the installed drivers.
80  SP_DEVINSTALL_PARAMS old_device_install_params;
81  old_device_install_params.cbSize = sizeof(old_device_install_params);
82  SetupDiGetDeviceInstallParams(device_info, device_data,
83                                &old_device_install_params);
84  SP_DEVINSTALL_PARAMS device_install_params = old_device_install_params;
85  device_install_params.FlagsEx |= DI_FLAGSEX_INSTALLEDDRIVER;
86  SetupDiSetDeviceInstallParams(device_info, device_data,
87                                &device_install_params);
88
89  SP_DRVINFO_DATA driver_data;
90  driver_data.cbSize = sizeof(driver_data);
91  string16 device_and_driver_info;
92  if (SetupDiBuildDriverInfoList(device_info, device_data,
93                                 SPDIT_COMPATDRIVER)) {
94    if (SetupDiEnumDriverInfo(device_info, device_data, SPDIT_COMPATDRIVER, 0,
95                              &driver_data)) {
96      DWORDLONG version = driver_data.DriverVersion;
97      device_and_driver_info = string16(driver_data.Description) + L" v" +
98          base::IntToString16(GetVersionPartAsInt((version >> 48))) + L"." +
99          base::IntToString16(GetVersionPartAsInt((version >> 32))) + L"." +
100          base::IntToString16(GetVersionPartAsInt((version >> 16))) + L"." +
101          base::IntToString16(GetVersionPartAsInt(version));
102    }
103    SetupDiDestroyDriverInfoList(device_info, device_data, SPDIT_COMPATDRIVER);
104  }
105
106  SetupDiSetDeviceInstallParams(device_info, device_data,
107                                &old_device_install_params);
108
109  return device_and_driver_info;
110}
111
112AudioManagerWin::AudioManagerWin() {
113  if (!CoreAudioUtil::IsSupported()) {
114    // Use the Wave API for device enumeration if XP or lower.
115    enumeration_type_ = kWaveEnumeration;
116  } else {
117    // Use the MMDevice API for device enumeration if Vista or higher.
118    enumeration_type_ = kMMDeviceEnumeration;
119  }
120
121  SetMaxOutputStreamsAllowed(kMaxOutputStreams);
122
123  // Task must be posted last to avoid races from handing out "this" to the
124  // audio thread.
125  GetMessageLoop()->PostTask(FROM_HERE, base::Bind(
126      &AudioManagerWin::CreateDeviceListener, base::Unretained(this)));
127}
128
129AudioManagerWin::~AudioManagerWin() {
130  // It's safe to post a task here since Shutdown() will wait for all tasks to
131  // complete before returning.
132  GetMessageLoop()->PostTask(FROM_HERE, base::Bind(
133      &AudioManagerWin::DestroyDeviceListener, base::Unretained(this)));
134  Shutdown();
135}
136
137bool AudioManagerWin::HasAudioOutputDevices() {
138  return (::waveOutGetNumDevs() != 0);
139}
140
141bool AudioManagerWin::HasAudioInputDevices() {
142  return (::waveInGetNumDevs() != 0);
143}
144
145void AudioManagerWin::CreateDeviceListener() {
146  // AudioDeviceListenerWin must be initialized on a COM thread and should only
147  // be used if WASAPI / Core Audio is supported.
148  if (CoreAudioUtil::IsSupported()) {
149    output_device_listener_.reset(new AudioDeviceListenerWin(BindToLoop(
150        GetMessageLoop(), base::Bind(
151            &AudioManagerWin::NotifyAllOutputDeviceChangeListeners,
152            base::Unretained(this)))));
153  }
154}
155
156void AudioManagerWin::DestroyDeviceListener() {
157  output_device_listener_.reset();
158}
159
160string16 AudioManagerWin::GetAudioInputDeviceModel() {
161  // Get the default audio capture device and its device interface name.
162  DWORD device_id = 0;
163  waveInMessage(reinterpret_cast<HWAVEIN>(WAVE_MAPPER),
164                DRVM_MAPPER_PREFERRED_GET,
165                reinterpret_cast<DWORD_PTR>(&device_id), NULL);
166  ULONG device_interface_name_size = 0;
167  waveInMessage(reinterpret_cast<HWAVEIN>(device_id),
168                DRV_QUERYDEVICEINTERFACESIZE,
169                reinterpret_cast<DWORD_PTR>(&device_interface_name_size), 0);
170  size_t bytes_in_char16 = sizeof(string16::value_type);
171  DCHECK_EQ(0u, device_interface_name_size % bytes_in_char16);
172  if (device_interface_name_size <= bytes_in_char16)
173    return string16();  // No audio capture device.
174
175  string16 device_interface_name;
176  string16::value_type* name_ptr = WriteInto(&device_interface_name,
177      device_interface_name_size / bytes_in_char16);
178  waveInMessage(reinterpret_cast<HWAVEIN>(device_id),
179                DRV_QUERYDEVICEINTERFACE,
180                reinterpret_cast<DWORD_PTR>(name_ptr),
181                static_cast<DWORD_PTR>(device_interface_name_size));
182
183  // Enumerate all audio devices and find the one matching the above device
184  // interface name.
185  HDEVINFO device_info = SetupDiGetClassDevs(
186      &AM_KSCATEGORY_AUDIO, 0, 0, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
187  if (device_info == INVALID_HANDLE_VALUE)
188    return string16();
189
190  DWORD interface_index = 0;
191  SP_DEVICE_INTERFACE_DATA interface_data;
192  interface_data.cbSize = sizeof(interface_data);
193  while (SetupDiEnumDeviceInterfaces(device_info, 0, &AM_KSCATEGORY_AUDIO,
194                                     interface_index++, &interface_data)) {
195    // Query the size of the struct, allocate it and then query the data.
196    SP_DEVINFO_DATA device_data;
197    device_data.cbSize = sizeof(device_data);
198    DWORD interface_detail_size = 0;
199    SetupDiGetDeviceInterfaceDetail(device_info, &interface_data, 0, 0,
200                                    &interface_detail_size, &device_data);
201    if (!interface_detail_size)
202      continue;
203
204    scoped_array<char> interface_detail_buffer(new char[interface_detail_size]);
205    SP_DEVICE_INTERFACE_DETAIL_DATA* interface_detail =
206        reinterpret_cast<SP_DEVICE_INTERFACE_DETAIL_DATA*>(
207            interface_detail_buffer.get());
208    interface_detail->cbSize = interface_detail_size;
209    if (!SetupDiGetDeviceInterfaceDetail(device_info, &interface_data,
210                                         interface_detail,
211                                         interface_detail_size, NULL,
212                                         &device_data))
213      return string16();
214
215    bool device_found = (device_interface_name == interface_detail->DevicePath);
216
217    if (device_found)
218      return GetDeviceAndDriverInfo(device_info, &device_data);
219  }
220
221  return string16();
222}
223
224void AudioManagerWin::ShowAudioInputSettings() {
225  std::wstring program;
226  std::string argument;
227  if (!CoreAudioUtil::IsSupported()) {
228    program = L"sndvol32.exe";
229    argument = "-R";
230  } else {
231    program = L"control.exe";
232    argument = "mmsys.cpl,,1";
233  }
234
235  base::FilePath path;
236  PathService::Get(base::DIR_SYSTEM, &path);
237  path = path.Append(program);
238  CommandLine command_line(path);
239  command_line.AppendArg(argument);
240  base::LaunchProcess(command_line, base::LaunchOptions(), NULL);
241}
242
243void AudioManagerWin::GetAudioInputDeviceNames(
244    media::AudioDeviceNames* device_names) {
245  DCHECK(enumeration_type() !=  kUninitializedEnumeration);
246  // Enumerate all active audio-endpoint capture devices.
247  if (enumeration_type() == kWaveEnumeration) {
248    // Utilize the Wave API for Windows XP.
249    media::GetInputDeviceNamesWinXP(device_names);
250  } else {
251    // Utilize the MMDevice API (part of Core Audio) for Vista and higher.
252    media::GetInputDeviceNamesWin(device_names);
253  }
254
255  // Always add default device parameters as first element.
256  if (!device_names->empty()) {
257    media::AudioDeviceName name;
258    name.device_name = AudioManagerBase::kDefaultDeviceName;
259    name.unique_id = AudioManagerBase::kDefaultDeviceId;
260    device_names->push_front(name);
261  }
262}
263
264AudioParameters AudioManagerWin::GetInputStreamParameters(
265    const std::string& device_id) {
266  int sample_rate = 0;
267  ChannelLayout channel_layout = CHANNEL_LAYOUT_NONE;
268  if (!CoreAudioUtil::IsSupported()) {
269    sample_rate = 48000;
270    channel_layout = CHANNEL_LAYOUT_STEREO;
271  } else {
272    sample_rate = WASAPIAudioInputStream::HardwareSampleRate(device_id);
273    channel_layout =
274        WASAPIAudioInputStream::HardwareChannelCount(device_id) == 1 ?
275            CHANNEL_LAYOUT_MONO : CHANNEL_LAYOUT_STEREO;
276  }
277
278  // TODO(Henrika): improve the default buffer size value for input stream.
279  return AudioParameters(
280      AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout,
281      sample_rate, 16, kFallbackBufferSize);
282}
283
284// Factory for the implementations of AudioOutputStream for AUDIO_PCM_LINEAR
285// mode.
286// - PCMWaveOutAudioOutputStream: Based on the waveOut API.
287AudioOutputStream* AudioManagerWin::MakeLinearOutputStream(
288    const AudioParameters& params) {
289  DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format());
290  if (params.channels() > kWinMaxChannels)
291    return NULL;
292
293  return new PCMWaveOutAudioOutputStream(this,
294                                         params,
295                                         media::NumberOfWaveOutBuffers(),
296                                         WAVE_MAPPER);
297}
298
299// Factory for the implementations of AudioOutputStream for
300// AUDIO_PCM_LOW_LATENCY mode. Two implementations should suffice most
301// windows user's needs.
302// - PCMWaveOutAudioOutputStream: Based on the waveOut API.
303// - WASAPIAudioOutputStream: Based on Core Audio (WASAPI) API.
304AudioOutputStream* AudioManagerWin::MakeLowLatencyOutputStream(
305    const AudioParameters& params) {
306  DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format());
307  if (params.channels() > kWinMaxChannels)
308    return NULL;
309
310  if (!CoreAudioUtil::IsSupported()) {
311    // Fall back to Windows Wave implementation on Windows XP or lower.
312    DVLOG(1) << "Using WaveOut since WASAPI requires at least Vista.";
313    return new PCMWaveOutAudioOutputStream(
314        this, params, media::NumberOfWaveOutBuffers(), WAVE_MAPPER);
315  }
316
317  // TODO(crogers): support more than stereo input.
318  if (params.input_channels() == 2) {
319    if (WASAPIUnifiedStream::HasUnifiedDefaultIO()) {
320      DVLOG(1) << "WASAPIUnifiedStream is created.";
321      return new WASAPIUnifiedStream(this, params);
322    }
323    LOG(WARNING) << "Unified audio I/O is not supported.";
324  }
325
326  return new WASAPIAudioOutputStream(this, params, eConsole);
327}
328
329// Factory for the implementations of AudioInputStream for AUDIO_PCM_LINEAR
330// mode.
331AudioInputStream* AudioManagerWin::MakeLinearInputStream(
332    const AudioParameters& params, const std::string& device_id) {
333  DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format());
334  return CreatePCMWaveInAudioInputStream(params, device_id);
335}
336
337// Factory for the implementations of AudioInputStream for
338// AUDIO_PCM_LOW_LATENCY mode.
339AudioInputStream* AudioManagerWin::MakeLowLatencyInputStream(
340    const AudioParameters& params, const std::string& device_id) {
341  DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format());
342  AudioInputStream* stream = NULL;
343  if (!CoreAudioUtil::IsSupported()) {
344    // Fall back to Windows Wave implementation on Windows XP or lower.
345    DVLOG(1) << "Using WaveIn since WASAPI requires at least Vista.";
346    stream = CreatePCMWaveInAudioInputStream(params, device_id);
347  } else {
348    stream = new WASAPIAudioInputStream(this, params, device_id);
349  }
350
351  return stream;
352}
353
354AudioParameters AudioManagerWin::GetPreferredOutputStreamParameters(
355    const AudioParameters& input_params) {
356  const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
357  ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
358  int sample_rate = 0;
359  int buffer_size = 0;
360  int bits_per_sample = 16;
361  int input_channels = 0;
362  if (!CoreAudioUtil::IsSupported()) {
363    // Fall back to Windows Wave implementation on Windows XP or lower.
364    // Use 48kHz as default input sample rate, kFallbackBufferSize as
365    // default buffer size.
366    sample_rate = 48000;
367    buffer_size = kFallbackBufferSize;
368  } else if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) {
369    // TODO(crogers): tune these values for best possible WebAudio performance.
370    // WebRTC works well at 48kHz and a buffer size of 480 samples will be used
371    // for this case. Note that exclusive mode is experimental.
372    // This sample rate will be combined with a buffer size of 256 samples,
373    // which corresponds to an output delay of ~5.33ms.
374    sample_rate = 48000;
375    buffer_size = 256;
376  } else {
377    // Hardware sample-rate on Windows can be configured, so we must query.
378    // TODO(henrika): improve possibility to specify an audio endpoint.
379    // Use the default device (same as for Wave) for now to be compatible.
380    sample_rate = WASAPIAudioOutputStream::HardwareSampleRate();
381
382    AudioParameters params;
383    HRESULT hr = CoreAudioUtil::GetPreferredAudioParameters(eRender, eConsole,
384                                                            &params);
385    buffer_size = FAILED(hr) ? kFallbackBufferSize : params.frames_per_buffer();
386    channel_layout = WASAPIAudioOutputStream::HardwareChannelLayout();
387  }
388
389  if (input_params.IsValid()) {
390    input_channels = input_params.input_channels();
391    if (!CoreAudioUtil::IsSupported()) {
392      // If WASAPI isn't supported we'll fallback to WaveOut, which will take
393      // care of resampling and bits per sample changes.  By setting these
394      // equal to the input values, AudioOutputResampler will skip resampling
395      // and bit per sample differences (since the input parameters will match
396      // the output parameters).
397      sample_rate = input_params.sample_rate();
398      bits_per_sample = input_params.bits_per_sample();
399      channel_layout = input_params.channel_layout();
400    }
401  }
402
403  int user_buffer_size = GetUserBufferSize();
404  if (user_buffer_size)
405    buffer_size = user_buffer_size;
406
407  return AudioParameters(
408      AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, input_channels,
409      sample_rate, bits_per_sample, buffer_size);
410}
411
412AudioInputStream* AudioManagerWin::CreatePCMWaveInAudioInputStream(
413    const AudioParameters& params,
414    const std::string& device_id) {
415  std::string xp_device_id = device_id;
416  if (device_id != AudioManagerBase::kDefaultDeviceId &&
417      enumeration_type_ == kMMDeviceEnumeration) {
418    xp_device_id = media::ConvertToWinXPDeviceId(device_id);
419    if (xp_device_id.empty()) {
420      DLOG(ERROR) << "Cannot find a waveIn device which matches the device ID "
421                  << device_id;
422      return NULL;
423    }
424  }
425
426  return new PCMWaveInAudioInputStream(this, params, kNumInputBuffers,
427                                       xp_device_id);
428}
429
430/// static
431AudioManager* CreateAudioManager() {
432  return new AudioManagerWin();
433}
434
435}  // namespace media
436