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

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

Issue 2784433002: Ensures that audio tasks cannot run after AudioManager is deleted. (Closed)
Patch Set: rebase Created 3 years, 7 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
« no previous file with comments | « media/audio/win/audio_manager_win.h ('k') | media/audio/win/audio_output_win_unittest.cc » ('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) 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
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
161 // Destroy AudioDeviceListenerWin instance on the audio thread because it
162 // expects to be constructed and destroyed on the same thread.
163 output_device_listener_.reset();
162 } 164 }
163 165
164 bool AudioManagerWin::HasAudioOutputDevices() { 166 bool AudioManagerWin::HasAudioOutputDevices() {
165 return (::waveOutGetNumDevs() != 0); 167 return (::waveOutGetNumDevs() != 0);
166 } 168 }
167 169
168 bool AudioManagerWin::HasAudioInputDevices() { 170 bool AudioManagerWin::HasAudioInputDevices() {
169 return (::waveInGetNumDevs() != 0); 171 return (::waveInGetNumDevs() != 0);
170 } 172 }
171 173
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 if (user_buffer_size) 459 if (user_buffer_size)
458 buffer_size = user_buffer_size; 460 buffer_size = user_buffer_size;
459 461
460 AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, 462 AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout,
461 sample_rate, bits_per_sample, buffer_size); 463 sample_rate, bits_per_sample, buffer_size);
462 params.set_effects(effects); 464 params.set_effects(effects);
463 return params; 465 return params;
464 } 466 }
465 467
466 // static 468 // static
467 ScopedAudioManagerPtr CreateAudioManager( 469 std::unique_ptr<AudioManager> CreateAudioManager(
468 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 470 std::unique_ptr<AudioThread> audio_thread,
469 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner,
470 AudioLogFactory* audio_log_factory) { 471 AudioLogFactory* audio_log_factory) {
471 return ScopedAudioManagerPtr( 472 return base::MakeUnique<AudioManagerWin>(std::move(audio_thread),
472 new AudioManagerWin(std::move(task_runner), std::move(worker_task_runner), 473 audio_log_factory);
473 audio_log_factory));
474 } 474 }
475 475
476 } // namespace media 476 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/win/audio_manager_win.h ('k') | media/audio/win/audio_output_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698