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 "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/bind.h" | |
henrika (OOO until Aug 14)
2012/10/25 18:12:56
Fix order.
DaleCurtis
2012/10/25 20:27:37
Done. Removed a bunch of unused imports too.
| |
14 #include "base/bind_helpers.h" | |
13 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
14 #include "base/command_line.h" | 16 #include "base/command_line.h" |
15 #include "base/file_path.h" | 17 #include "base/file_path.h" |
16 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
19 #include "base/message_loop.h" | |
17 #include "base/path_service.h" | 20 #include "base/path_service.h" |
18 #include "base/process_util.h" | 21 #include "base/process_util.h" |
19 #include "base/string_number_conversions.h" | 22 #include "base/string_number_conversions.h" |
20 #include "base/string_util.h" | 23 #include "base/string_util.h" |
21 #include "media/audio/audio_util.h" | 24 #include "media/audio/audio_util.h" |
22 #include "media/audio/win/audio_low_latency_input_win.h" | 25 #include "media/audio/win/audio_low_latency_input_win.h" |
23 #include "media/audio/win/audio_low_latency_output_win.h" | 26 #include "media/audio/win/audio_low_latency_output_win.h" |
24 #include "media/audio/win/audio_manager_win.h" | 27 #include "media/audio/win/audio_manager_win.h" |
25 #include "media/audio/win/audio_unified_win.h" | 28 #include "media/audio/win/audio_unified_win.h" |
26 #include "media/audio/win/device_enumeration_win.h" | 29 #include "media/audio/win/device_enumeration_win.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 enumeration_type_ = kWaveEnumeration; | 108 enumeration_type_ = kWaveEnumeration; |
106 } else { | 109 } else { |
107 // Use the MMDevice API for device enumeration if Vista or higher. | 110 // Use the MMDevice API for device enumeration if Vista or higher. |
108 enumeration_type_ = kMMDeviceEnumeration; | 111 enumeration_type_ = kMMDeviceEnumeration; |
109 } | 112 } |
110 | 113 |
111 SetMaxOutputStreamsAllowed(kMaxOutputStreams); | 114 SetMaxOutputStreamsAllowed(kMaxOutputStreams); |
112 } | 115 } |
113 | 116 |
114 AudioManagerWin::~AudioManagerWin() { | 117 AudioManagerWin::~AudioManagerWin() { |
118 output_device_listener_.reset(); | |
115 Shutdown(); | 119 Shutdown(); |
116 } | 120 } |
117 | 121 |
118 bool AudioManagerWin::HasAudioOutputDevices() { | 122 bool AudioManagerWin::HasAudioOutputDevices() { |
119 return (::waveOutGetNumDevs() != 0); | 123 return (::waveOutGetNumDevs() != 0); |
120 } | 124 } |
121 | 125 |
122 bool AudioManagerWin::HasAudioInputDevices() { | 126 bool AudioManagerWin::HasAudioInputDevices() { |
123 return (::waveInGetNumDevs() != 0); | 127 return (::waveInGetNumDevs() != 0); |
124 } | 128 } |
125 | 129 |
130 void AudioManagerWin::InitializeOnAudioThread() { | |
131 // AudioDeviceListenerWin must be initialized on a COM thread. | |
132 if (media::IsWASAPISupported()) { | |
133 output_device_listener_.reset(new AudioDeviceListenerWin(base::Bind( | |
134 &AudioManagerWin::OnDeviceChange, base::Unretained(this)))); | |
135 } | |
136 } | |
137 | |
126 string16 AudioManagerWin::GetAudioInputDeviceModel() { | 138 string16 AudioManagerWin::GetAudioInputDeviceModel() { |
127 // Get the default audio capture device and its device interface name. | 139 // Get the default audio capture device and its device interface name. |
128 DWORD device_id = 0; | 140 DWORD device_id = 0; |
129 waveInMessage(reinterpret_cast<HWAVEIN>(WAVE_MAPPER), | 141 waveInMessage(reinterpret_cast<HWAVEIN>(WAVE_MAPPER), |
130 DRVM_MAPPER_PREFERRED_GET, | 142 DRVM_MAPPER_PREFERRED_GET, |
131 reinterpret_cast<DWORD_PTR>(&device_id), NULL); | 143 reinterpret_cast<DWORD_PTR>(&device_id), NULL); |
132 ULONG device_interface_name_size = 0; | 144 ULONG device_interface_name_size = 0; |
133 waveInMessage(reinterpret_cast<HWAVEIN>(device_id), | 145 waveInMessage(reinterpret_cast<HWAVEIN>(device_id), |
134 DRV_QUERYDEVICEINTERFACESIZE, | 146 DRV_QUERYDEVICEINTERFACESIZE, |
135 reinterpret_cast<DWORD_PTR>(&device_interface_name_size), 0); | 147 reinterpret_cast<DWORD_PTR>(&device_interface_name_size), 0); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
338 bits_per_sample = 16; | 350 bits_per_sample = 16; |
339 channel_layout = WASAPIAudioOutputStream::HardwareChannelLayout(); | 351 channel_layout = WASAPIAudioOutputStream::HardwareChannelLayout(); |
340 } | 352 } |
341 | 353 |
342 // TODO(dalecurtis): This should include hardware bits per channel eventually. | 354 // TODO(dalecurtis): This should include hardware bits per channel eventually. |
343 return AudioParameters( | 355 return AudioParameters( |
344 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, | 356 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, |
345 sample_rate, bits_per_sample, GetAudioHardwareBufferSize()); | 357 sample_rate, bits_per_sample, GetAudioHardwareBufferSize()); |
346 } | 358 } |
347 | 359 |
360 void AudioManagerWin::OnDeviceChange() { | |
361 // We should only fire device changes when we're creating low latency streams. | |
362 DCHECK(media::IsWASAPISupported()); | |
363 GetMessageLoop()->PostTask(FROM_HERE, base::Bind( | |
364 &AudioManagerWin::NotifyAllOutputDeviceChangeListeners, | |
365 base::Unretained(this))); | |
366 } | |
367 | |
348 } // namespace media | 368 } // namespace media |
OLD | NEW |