Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: media/audio/win/audio_manager_win.cc

Issue 8440002: Low-latency AudioOutputStream implementation based on WASAPI for Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: rebased Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/audio/win/audio_manager_win.h ('k') | media/media.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_manager_win.h" 26 #include "media/audio/win/audio_manager_win.h"
26 #include "media/audio/win/wavein_input_win.h" 27 #include "media/audio/win/wavein_input_win.h"
27 #include "media/audio/win/waveout_output_win.h" 28 #include "media/audio/win/waveout_output_win.h"
28 #include "media/base/limits.h" 29 #include "media/base/limits.h"
29 30
30 // Libraries required for the SetupAPI and Wbem APIs used here. 31 // Libraries required for the SetupAPI and Wbem APIs used here.
31 #pragma comment(lib, "setupapi.lib") 32 #pragma comment(lib, "setupapi.lib")
32 33
33 // The following are defined in various DDK headers, and we (re)define them 34 // The following are defined in various DDK headers, and we (re)define them
34 // here to avoid adding the DDK as a chrome dependency. 35 // here to avoid adding the DDK as a chrome dependency.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 bool AudioManagerWin::HasAudioOutputDevices() { 107 bool AudioManagerWin::HasAudioOutputDevices() {
107 return (::waveOutGetNumDevs() != 0); 108 return (::waveOutGetNumDevs() != 0);
108 } 109 }
109 110
110 bool AudioManagerWin::HasAudioInputDevices() { 111 bool AudioManagerWin::HasAudioInputDevices() {
111 return (::waveInGetNumDevs() != 0); 112 return (::waveInGetNumDevs() != 0);
112 } 113 }
113 114
114 // Factory for the implementations of AudioOutputStream. Two implementations 115 // Factory for the implementations of AudioOutputStream. Two implementations
115 // should suffice most windows user's needs. 116 // should suffice most windows user's needs.
116 // - PCMWaveOutAudioOutputStream: Based on the waveOutWrite API (in progress) 117 // - PCMWaveOutAudioOutputStream: Based on the waveOut API.
117 // - PCMDXSoundAudioOutputStream: Based on DirectSound or XAudio (future work). 118 // - WASAPIAudioOutputStream: Based on Core Audio (WASAPI) API.
118 AudioOutputStream* AudioManagerWin::MakeAudioOutputStream( 119 AudioOutputStream* AudioManagerWin::MakeAudioOutputStream(
119 const AudioParameters& params) { 120 const AudioParameters& params) {
120 if (!params.IsValid() || (params.channels > kWinMaxChannels)) 121 if (!params.IsValid() || (params.channels > kWinMaxChannels))
121 return NULL; 122 return NULL;
122 123
123 // Limit the number of audio streams opened. 124 // Limit the number of audio streams opened.
124 if (num_output_streams_ >= kMaxOutputStreams) { 125 if (num_output_streams_ >= kMaxOutputStreams) {
125 return NULL; 126 return NULL;
126 } 127 }
127 128
128 if (params.format == AudioParameters::AUDIO_MOCK) { 129 if (params.format == AudioParameters::AUDIO_MOCK) {
129 return FakeAudioOutputStream::MakeFakeStream(params); 130 return FakeAudioOutputStream::MakeFakeStream(params);
130 } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) { 131 } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) {
131 num_output_streams_++; 132 num_output_streams_++;
132 return new PCMWaveOutAudioOutputStream(this, params, 3, WAVE_MAPPER); 133 return new PCMWaveOutAudioOutputStream(this, params, 3, WAVE_MAPPER);
133 } else if (params.format == AudioParameters::AUDIO_PCM_LOW_LATENCY) { 134 } else if (params.format == AudioParameters::AUDIO_PCM_LOW_LATENCY) {
134 num_output_streams_++; 135 num_output_streams_++;
135 // TODO(cpu): waveout cannot hit 20ms latency. Use other method. 136 if (base::win::GetVersion() <= base::win::VERSION_XP) {
136 return new PCMWaveOutAudioOutputStream(this, params, 2, WAVE_MAPPER); 137 // Fall back to Windows Wave implementation on Windows XP or lower.
138 DLOG(INFO) << "Using WaveOut since WASAPI requires at least Vista.";
139 return new PCMWaveOutAudioOutputStream(this, params, 2, WAVE_MAPPER);
140 } else {
141 // TODO(henrika): improve possibility to specify audio endpoint.
142 // Use the default device (same as for Wave) for now to be compatible.
143 return new WASAPIAudioOutputStream(this, params, eConsole);
144 }
137 } 145 }
138 return NULL; 146 return NULL;
139 } 147 }
140 148
141 // Factory for the implementations of AudioInputStream. 149 // Factory for the implementations of AudioInputStream.
142 AudioInputStream* AudioManagerWin::MakeAudioInputStream( 150 AudioInputStream* AudioManagerWin::MakeAudioInputStream(
143 const AudioParameters& params) { 151 const AudioParameters& params) {
144 if (!params.IsValid() || (params.channels > kWinMaxInputChannels)) 152 if (!params.IsValid() || (params.channels > kWinMaxInputChannels))
145 return NULL; 153 return NULL;
146 154
(...skipping 10 matching lines...) Expand all
157 WAVE_MAPPER); 165 WAVE_MAPPER);
158 } else { 166 } else {
159 // TODO(henrika): improve possibility to specify audio endpoint. 167 // TODO(henrika): improve possibility to specify audio endpoint.
160 // Use the default device (same as for Wave) for now to be compatible. 168 // Use the default device (same as for Wave) for now to be compatible.
161 return new WASAPIAudioInputStream(this, params, eConsole); 169 return new WASAPIAudioInputStream(this, params, eConsole);
162 } 170 }
163 } 171 }
164 return NULL; 172 return NULL;
165 } 173 }
166 174
167 void AudioManagerWin::ReleaseOutputStream(PCMWaveOutAudioOutputStream* stream) { 175 void AudioManagerWin::ReleaseOutputStream(AudioOutputStream* stream) {
168 DCHECK(stream); 176 DCHECK(stream);
169 num_output_streams_--; 177 num_output_streams_--;
170 delete stream; 178 delete stream;
171 } 179 }
172 180
173 void AudioManagerWin::ReleaseInputStream(AudioInputStream* stream) { 181 void AudioManagerWin::ReleaseInputStream(AudioInputStream* stream) {
174 delete stream; 182 delete stream;
175 } 183 }
176 184
177 void AudioManagerWin::MuteAll() { 185 void AudioManagerWin::MuteAll() {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 name.device_name = AudioManagerBase::kDefaultDeviceName; 284 name.device_name = AudioManagerBase::kDefaultDeviceName;
277 name.unique_id = "0"; 285 name.unique_id = "0";
278 device_names->push_back(name); 286 device_names->push_back(name);
279 } 287 }
280 } 288 }
281 289
282 // static 290 // static
283 AudioManager* AudioManager::CreateAudioManager() { 291 AudioManager* AudioManager::CreateAudioManager() {
284 return new AudioManagerWin(); 292 return new AudioManagerWin();
285 } 293 }
OLDNEW
« no previous file with comments | « media/audio/win/audio_manager_win.h ('k') | media/media.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698