| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // The following are defined in various DDK headers, and we (re)define them | 27 // The following are defined in various DDK headers, and we (re)define them |
| 28 // here to avoid adding the DDK as a chrome dependency. | 28 // here to avoid adding the DDK as a chrome dependency. |
| 29 #define DRV_QUERYDEVICEINTERFACE 0x80c | 29 #define DRV_QUERYDEVICEINTERFACE 0x80c |
| 30 #define DRVM_MAPPER_PREFERRED_GET 0x2015 | 30 #define DRVM_MAPPER_PREFERRED_GET 0x2015 |
| 31 #define DRV_QUERYDEVICEINTERFACESIZE 0x80d | 31 #define DRV_QUERYDEVICEINTERFACESIZE 0x80d |
| 32 DEFINE_GUID(AM_KSCATEGORY_AUDIO, 0x6994ad04, 0x93ef, 0x11d0, | 32 DEFINE_GUID(AM_KSCATEGORY_AUDIO, 0x6994ad04, 0x93ef, 0x11d0, |
| 33 0xa3, 0xcc, 0x00, 0xa0, 0xc9, 0x22, 0x31, 0x96); | 33 0xa3, 0xcc, 0x00, 0xa0, 0xc9, 0x22, 0x31, 0x96); |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 // Maximum number of output streams that can be open simultaneously. |
| 38 const size_t kMaxOutputStreams = 50; |
| 39 |
| 37 // Up to 8 channels can be passed to the driver. | 40 // Up to 8 channels can be passed to the driver. |
| 38 // This should work, given the right drivers, but graceful error handling is | 41 // This should work, given the right drivers, but graceful error handling is |
| 39 // needed. | 42 // needed. |
| 40 const int kWinMaxChannels = 8; | 43 const int kWinMaxChannels = 8; |
| 41 | 44 |
| 42 const int kWinMaxInputChannels = 2; | 45 const int kWinMaxInputChannels = 2; |
| 43 // We use 3 buffers for recording audio so that if a recording callback takes | 46 // We use 3 buffers for recording audio so that if a recording callback takes |
| 44 // some time to return we won't lose audio. More buffers while recording are | 47 // some time to return we won't lose audio. More buffers while recording are |
| 45 // ok because they don't introduce any delay in recording, unlike in playback | 48 // ok because they don't introduce any delay in recording, unlike in playback |
| 46 // where you first need to fill in that number of buffers before starting to | 49 // where you first need to fill in that number of buffers before starting to |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 } | 87 } |
| 85 | 88 |
| 86 SetupDiSetDeviceInstallParams(device_info, device_data, | 89 SetupDiSetDeviceInstallParams(device_info, device_data, |
| 87 &old_device_install_params); | 90 &old_device_install_params); |
| 88 | 91 |
| 89 return device_and_driver_info; | 92 return device_and_driver_info; |
| 90 } | 93 } |
| 91 | 94 |
| 92 } // namespace | 95 } // namespace |
| 93 | 96 |
| 97 AudioManagerWin::AudioManagerWin() |
| 98 : num_output_streams_(0) { |
| 99 } |
| 100 |
| 94 bool AudioManagerWin::HasAudioOutputDevices() { | 101 bool AudioManagerWin::HasAudioOutputDevices() { |
| 95 return (::waveOutGetNumDevs() != 0); | 102 return (::waveOutGetNumDevs() != 0); |
| 96 } | 103 } |
| 97 | 104 |
| 98 bool AudioManagerWin::HasAudioInputDevices() { | 105 bool AudioManagerWin::HasAudioInputDevices() { |
| 99 return (::waveInGetNumDevs() != 0); | 106 return (::waveInGetNumDevs() != 0); |
| 100 } | 107 } |
| 101 | 108 |
| 102 // Factory for the implementations of AudioOutputStream. Two implementations | 109 // Factory for the implementations of AudioOutputStream. Two implementations |
| 103 // should suffice most windows user's needs. | 110 // should suffice most windows user's needs. |
| 104 // - PCMWaveOutAudioOutputStream: Based on the waveOutWrite API (in progress) | 111 // - PCMWaveOutAudioOutputStream: Based on the waveOutWrite API (in progress) |
| 105 // - PCMDXSoundAudioOutputStream: Based on DirectSound or XAudio (future work). | 112 // - PCMDXSoundAudioOutputStream: Based on DirectSound or XAudio (future work). |
| 106 AudioOutputStream* AudioManagerWin::MakeAudioOutputStream( | 113 AudioOutputStream* AudioManagerWin::MakeAudioOutputStream( |
| 107 AudioParameters params) { | 114 AudioParameters params) { |
| 108 if (!params.IsValid() || (params.channels > kWinMaxChannels)) | 115 if (!params.IsValid() || (params.channels > kWinMaxChannels)) |
| 109 return NULL; | 116 return NULL; |
| 110 | 117 |
| 118 // Limit the number of audio streams opened. |
| 119 if (num_output_streams_ >= kMaxOutputStreams) { |
| 120 return NULL; |
| 121 } |
| 122 |
| 111 if (params.format == AudioParameters::AUDIO_MOCK) { | 123 if (params.format == AudioParameters::AUDIO_MOCK) { |
| 112 return FakeAudioOutputStream::MakeFakeStream(params); | 124 return FakeAudioOutputStream::MakeFakeStream(params); |
| 113 } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) { | 125 } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) { |
| 126 num_output_streams_++; |
| 114 return new PCMWaveOutAudioOutputStream(this, params, 3, WAVE_MAPPER); | 127 return new PCMWaveOutAudioOutputStream(this, params, 3, WAVE_MAPPER); |
| 115 } else if (params.format == AudioParameters::AUDIO_PCM_LOW_LATENCY) { | 128 } else if (params.format == AudioParameters::AUDIO_PCM_LOW_LATENCY) { |
| 129 num_output_streams_++; |
| 116 // TODO(cpu): waveout cannot hit 20ms latency. Use other method. | 130 // TODO(cpu): waveout cannot hit 20ms latency. Use other method. |
| 117 return new PCMWaveOutAudioOutputStream(this, params, 2, WAVE_MAPPER); | 131 return new PCMWaveOutAudioOutputStream(this, params, 2, WAVE_MAPPER); |
| 118 } | 132 } |
| 119 return NULL; | 133 return NULL; |
| 120 } | 134 } |
| 121 | 135 |
| 122 // Factory for the implementations of AudioInputStream. | 136 // Factory for the implementations of AudioInputStream. |
| 123 AudioInputStream* AudioManagerWin::MakeAudioInputStream( | 137 AudioInputStream* AudioManagerWin::MakeAudioInputStream( |
| 124 AudioParameters params) { | 138 AudioParameters params) { |
| 125 if (!params.IsValid() || (params.channels > kWinMaxInputChannels)) | 139 if (!params.IsValid() || (params.channels > kWinMaxInputChannels)) |
| 126 return NULL; | 140 return NULL; |
| 127 | 141 |
| 128 if (params.format == AudioParameters::AUDIO_MOCK) { | 142 if (params.format == AudioParameters::AUDIO_MOCK) { |
| 129 return FakeAudioInputStream::MakeFakeStream(params); | 143 return FakeAudioInputStream::MakeFakeStream(params); |
| 130 } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) { | 144 } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) { |
| 131 return new PCMWaveInAudioInputStream(this, params, kNumInputBuffers, | 145 return new PCMWaveInAudioInputStream(this, params, kNumInputBuffers, |
| 132 WAVE_MAPPER); | 146 WAVE_MAPPER); |
| 133 } | 147 } |
| 134 return NULL; | 148 return NULL; |
| 135 } | 149 } |
| 136 | 150 |
| 137 void AudioManagerWin::ReleaseOutputStream(PCMWaveOutAudioOutputStream* stream) { | 151 void AudioManagerWin::ReleaseOutputStream(PCMWaveOutAudioOutputStream* stream) { |
| 138 if (stream) | 152 DCHECK(stream); |
| 139 delete stream; | 153 num_output_streams_--; |
| 154 delete stream; |
| 140 } | 155 } |
| 141 | 156 |
| 142 void AudioManagerWin::ReleaseInputStream(PCMWaveInAudioInputStream* stream) { | 157 void AudioManagerWin::ReleaseInputStream(PCMWaveInAudioInputStream* stream) { |
| 143 if (stream) | 158 delete stream; |
| 144 delete stream; | |
| 145 } | 159 } |
| 146 | 160 |
| 147 void AudioManagerWin::MuteAll() { | 161 void AudioManagerWin::MuteAll() { |
| 148 } | 162 } |
| 149 | 163 |
| 150 void AudioManagerWin::UnMuteAll() { | 164 void AudioManagerWin::UnMuteAll() { |
| 151 } | 165 } |
| 152 | 166 |
| 153 AudioManagerWin::~AudioManagerWin() { | 167 AudioManagerWin::~AudioManagerWin() { |
| 154 } | 168 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 return GetDeviceAndDriverInfo(device_info, &device_data); | 223 return GetDeviceAndDriverInfo(device_info, &device_data); |
| 210 } | 224 } |
| 211 | 225 |
| 212 return string16(); | 226 return string16(); |
| 213 } | 227 } |
| 214 | 228 |
| 215 // static | 229 // static |
| 216 AudioManager* AudioManager::CreateAudioManager() { | 230 AudioManager* AudioManager::CreateAudioManager() { |
| 217 return new AudioManagerWin(); | 231 return new AudioManagerWin(); |
| 218 } | 232 } |
| OLD | NEW |