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

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

Issue 1097553003: Switch to STA mode for audio thread and WASAPI I/O streams. (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments. Created 5 years, 8 months 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
OLDNEW
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>
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 // Use 4 buffers for Vista, 3 for everyone else: 122 // Use 4 buffers for Vista, 3 for everyone else:
123 // - The entire Windows audio stack was rewritten for Windows Vista and wave 123 // - The entire Windows audio stack was rewritten for Windows Vista and wave
124 // out performance was degraded compared to XP. 124 // out performance was degraded compared to XP.
125 // - The regression was fixed in Windows 7 and most configurations will work 125 // - The regression was fixed in Windows 7 and most configurations will work
126 // with 2, but some (e.g., some Sound Blasters) still need 3. 126 // with 2, but some (e.g., some Sound Blasters) still need 3.
127 // - Some XP configurations (even multi-processor ones) also need 3. 127 // - Some XP configurations (even multi-processor ones) also need 3.
128 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3; 128 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3;
129 } 129 }
130 130
131 AudioManagerWin::AudioManagerWin(AudioLogFactory* audio_log_factory) 131 AudioManagerWin::AudioManagerWin(AudioLogFactory* audio_log_factory)
132 : AudioManagerBase(audio_log_factory), 132 : AudioManagerBase(audio_log_factory), enumeration_type_(kNoEnumeration) {
133 // |CoreAudioUtil::IsSupported()| uses static variables to avoid doing
134 // multiple initializations. This is however not thread safe.
135 // So, here we call it explicitly before we kick off the audio thread
136 // or do any other work.
137 enumeration_type_(CoreAudioUtil::IsSupported() ?
tommi (sloooow) - chröme 2015/04/20 18:23:38 Is it safe to remove this call? The comment expla
DaleCurtis 2015/04/20 18:54:07 I've moved video capture enumeration back to the a
DaleCurtis 2015/04/20 23:06:10 Hmm, things are worse than I thought here, TrayAud
138 kMMDeviceEnumeration : kWaveEnumeration) {
139 SetMaxOutputStreamsAllowed(kMaxOutputStreams); 133 SetMaxOutputStreamsAllowed(kMaxOutputStreams);
140 134
141 // WARNING: This is executed on the UI loop, do not add any code here which 135 // WARNING: This is executed on the UI loop, do not add any code here which
142 // loads libraries or attempts to call out into the OS. Instead add such code 136 // loads libraries or attempts to call out into the OS. Instead add such code
143 // to the InitializeOnAudioThread() method below. 137 // to the InitializeOnAudioThread() method below.
138 //
139 // WARNING: Do not make any calls to CoreAudioUtil within the constructor, it
140 // will attempt to perform COM initialization.
144 141
145 // Task must be posted last to avoid races from handing out "this" to the 142 // Task must be posted last to avoid races from handing out "this" to the
146 // audio thread. 143 // audio thread.
147 GetTaskRunner()->PostTask(FROM_HERE, base::Bind( 144 GetTaskRunner()->PostTask(
148 &AudioManagerWin::InitializeOnAudioThread, base::Unretained(this))); 145 FROM_HERE, base::Bind(&AudioManagerWin::InitializeOnAudioThread,
146 base::Unretained(this)));
149 } 147 }
150 148
151 AudioManagerWin::~AudioManagerWin() { 149 AudioManagerWin::~AudioManagerWin() {
152 // It's safe to post a task here since Shutdown() will wait for all tasks to 150 // It's safe to post a task here since Shutdown() will wait for all tasks to
153 // complete before returning. 151 // complete before returning.
154 GetTaskRunner()->PostTask(FROM_HERE, base::Bind( 152 GetTaskRunner()->PostTask(FROM_HERE, base::Bind(
155 &AudioManagerWin::ShutdownOnAudioThread, base::Unretained(this))); 153 &AudioManagerWin::ShutdownOnAudioThread, base::Unretained(this)));
156 Shutdown(); 154 Shutdown();
157 } 155 }
158 156
159 bool AudioManagerWin::HasAudioOutputDevices() { 157 bool AudioManagerWin::HasAudioOutputDevices() {
160 return (::waveOutGetNumDevs() != 0); 158 return (::waveOutGetNumDevs() != 0);
161 } 159 }
162 160
163 bool AudioManagerWin::HasAudioInputDevices() { 161 bool AudioManagerWin::HasAudioInputDevices() {
164 return (::waveInGetNumDevs() != 0); 162 return (::waveInGetNumDevs() != 0);
165 } 163 }
166 164
167 void AudioManagerWin::InitializeOnAudioThread() { 165 void AudioManagerWin::InitializeOnAudioThread() {
168 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); 166 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
167 enumeration_type_ =
168 CoreAudioUtil::IsSupported() ? kMMDeviceEnumeration : kWaveEnumeration;
169 169
170 if (core_audio_supported()) { 170 if (core_audio_supported()) {
171 // AudioDeviceListenerWin must be initialized on a COM thread and should 171 // AudioDeviceListenerWin must be initialized on a COM thread and should
172 // only be used if WASAPI / Core Audio is supported. 172 // only be used if WASAPI / Core Audio is supported.
173 output_device_listener_.reset(new AudioDeviceListenerWin(BindToCurrentLoop( 173 output_device_listener_.reset(new AudioDeviceListenerWin(BindToCurrentLoop(
174 base::Bind(&AudioManagerWin::NotifyAllOutputDeviceChangeListeners, 174 base::Bind(&AudioManagerWin::NotifyAllOutputDeviceChangeListeners,
175 base::Unretained(this))))); 175 base::Unretained(this)))));
176 } 176 }
177 } 177 }
178 178
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 return AudioParameters( 510 return AudioParameters(
511 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, 511 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout,
512 sample_rate, bits_per_sample, buffer_size, effects); 512 sample_rate, bits_per_sample, buffer_size, effects);
513 } 513 }
514 514
515 AudioInputStream* AudioManagerWin::CreatePCMWaveInAudioInputStream( 515 AudioInputStream* AudioManagerWin::CreatePCMWaveInAudioInputStream(
516 const AudioParameters& params, 516 const AudioParameters& params,
517 const std::string& device_id) { 517 const std::string& device_id) {
518 std::string xp_device_id = device_id; 518 std::string xp_device_id = device_id;
519 if (device_id != AudioManagerBase::kDefaultDeviceId && 519 if (device_id != AudioManagerBase::kDefaultDeviceId &&
520 enumeration_type_ == kMMDeviceEnumeration) { 520 enumeration_type() == kMMDeviceEnumeration) {
521 xp_device_id = ConvertToWinXPInputDeviceId(device_id); 521 xp_device_id = ConvertToWinXPInputDeviceId(device_id);
522 if (xp_device_id.empty()) { 522 if (xp_device_id.empty()) {
523 DLOG(ERROR) << "Cannot find a waveIn device which matches the device ID " 523 DLOG(ERROR) << "Cannot find a waveIn device which matches the device ID "
524 << device_id; 524 << device_id;
525 return NULL; 525 return NULL;
526 } 526 }
527 } 527 }
528 528
529 return new PCMWaveInAudioInputStream(this, params, kNumInputBuffers, 529 return new PCMWaveInAudioInputStream(this, params, kNumInputBuffers,
530 xp_device_id); 530 xp_device_id);
531 } 531 }
532 532
533 /// static 533 /// static
534 AudioManager* CreateAudioManager(AudioLogFactory* audio_log_factory) { 534 AudioManager* CreateAudioManager(AudioLogFactory* audio_log_factory) {
535 return new AudioManagerWin(audio_log_factory); 535 return new AudioManagerWin(audio_log_factory);
536 } 536 }
537 537
538 } // namespace media 538 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698