Chromium Code Reviews| 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/win/audio_manager_win.h" | 5 #include "media/audio/win/audio_manager_win.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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 | 124 |
| 125 // Use 4 buffers for Vista, 3 for everyone else: | 125 // Use 4 buffers for Vista, 3 for everyone else: |
| 126 // - The entire Windows audio stack was rewritten for Windows Vista and wave | 126 // - The entire Windows audio stack was rewritten for Windows Vista and wave |
| 127 // out performance was degraded compared to XP. | 127 // out performance was degraded compared to XP. |
| 128 // - The regression was fixed in Windows 7 and most configurations will work | 128 // - The regression was fixed in Windows 7 and most configurations will work |
| 129 // with 2, but some (e.g., some Sound Blasters) still need 3. | 129 // with 2, but some (e.g., some Sound Blasters) still need 3. |
| 130 // - Some XP configurations (even multi-processor ones) also need 3. | 130 // - Some XP configurations (even multi-processor ones) also need 3. |
| 131 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3; | 131 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3; |
| 132 } | 132 } |
| 133 | 133 |
| 134 AudioManagerWin::AudioManagerWin( | 134 AudioManagerWin::AudioManagerWin(std::unique_ptr<AudioThread> audio_thread, |
| 135 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 135 AudioLogFactory* audio_log_factory) |
| 136 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | 136 : AudioManagerBase(std::move(audio_thread), audio_log_factory) { |
| 137 AudioLogFactory* audio_log_factory) | |
| 138 : AudioManagerBase(std::move(task_runner), | |
| 139 std::move(worker_task_runner), | |
| 140 audio_log_factory) { | |
| 141 // |CoreAudioUtil::IsSupported()| uses static variables to avoid doing | 137 // |CoreAudioUtil::IsSupported()| uses static variables to avoid doing |
| 142 // multiple initializations. This is however not thread safe. | 138 // multiple initializations. This is however not thread safe. |
| 143 // So, here we call it explicitly before we kick off the audio thread | 139 // So, here we call it explicitly before we kick off the audio thread |
| 144 // or do any other work. | 140 // or do any other work. |
| 145 CoreAudioUtil::IsSupported(); | 141 CoreAudioUtil::IsSupported(); |
| 146 | 142 |
| 147 SetMaxOutputStreamsAllowed(kMaxOutputStreams); | 143 SetMaxOutputStreamsAllowed(kMaxOutputStreams); |
| 148 | 144 |
| 149 // WARNING: This is executed on the UI loop, do not add any code here which | 145 // WARNING: This is executed on the UI loop, do not add any code here which |
| 150 // loads libraries or attempts to call out into the OS. Instead add such code | 146 // loads libraries or attempts to call out into the OS. Instead add such code |
| 151 // to the InitializeOnAudioThread() method below. | 147 // to the InitializeOnAudioThread() method below. |
| 152 | 148 |
| 153 // Task must be posted last to avoid races from handing out "this" to the | 149 // Task must be posted last to avoid races from handing out "this" to the |
| 154 // audio thread. | 150 // audio thread. |
| 155 GetTaskRunner()->PostTask( | 151 GetTaskRunner()->PostTask( |
| 156 FROM_HERE, base::Bind(&AudioManagerWin::InitializeOnAudioThread, | 152 FROM_HERE, base::Bind(&AudioManagerWin::InitializeOnAudioThread, |
| 157 base::Unretained(this))); | 153 base::Unretained(this))); |
| 158 } | 154 } |
| 159 | 155 |
| 160 AudioManagerWin::~AudioManagerWin() { | 156 AudioManagerWin::~AudioManagerWin() = default; |
| 161 Shutdown(); | 157 |
| 158 void AudioManagerWin::ShutdownOnAudioThread() { | |
| 159 AudioManagerBase::ShutdownOnAudioThread(); | |
| 160 output_device_listener_.reset(); | |
|
o1ka
2017/05/10 15:57:57
Add a comment why it's done here?
alokp
2017/05/10 18:04:03
Done.
| |
| 162 } | 161 } |
| 163 | 162 |
| 164 bool AudioManagerWin::HasAudioOutputDevices() { | 163 bool AudioManagerWin::HasAudioOutputDevices() { |
| 165 return (::waveOutGetNumDevs() != 0); | 164 return (::waveOutGetNumDevs() != 0); |
| 166 } | 165 } |
| 167 | 166 |
| 168 bool AudioManagerWin::HasAudioInputDevices() { | 167 bool AudioManagerWin::HasAudioInputDevices() { |
| 169 return (::waveInGetNumDevs() != 0); | 168 return (::waveInGetNumDevs() != 0); |
| 170 } | 169 } |
| 171 | 170 |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 457 if (user_buffer_size) | 456 if (user_buffer_size) |
| 458 buffer_size = user_buffer_size; | 457 buffer_size = user_buffer_size; |
| 459 | 458 |
| 460 AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, | 459 AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, |
| 461 sample_rate, bits_per_sample, buffer_size); | 460 sample_rate, bits_per_sample, buffer_size); |
| 462 params.set_effects(effects); | 461 params.set_effects(effects); |
| 463 return params; | 462 return params; |
| 464 } | 463 } |
| 465 | 464 |
| 466 // static | 465 // static |
| 467 ScopedAudioManagerPtr CreateAudioManager( | 466 std::unique_ptr<AudioManager> CreateAudioManager( |
| 468 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 467 std::unique_ptr<AudioThread> audio_thread, |
| 469 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | |
| 470 AudioLogFactory* audio_log_factory) { | 468 AudioLogFactory* audio_log_factory) { |
| 471 return ScopedAudioManagerPtr( | 469 return base::MakeUnique<AudioManagerWin>(std::move(audio_thread), |
| 472 new AudioManagerWin(std::move(task_runner), std::move(worker_task_runner), | 470 audio_log_factory); |
| 473 audio_log_factory)); | |
| 474 } | 471 } |
| 475 | 472 |
| 476 } // namespace media | 473 } // namespace media |
| OLD | NEW |