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

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

Issue 1806313003: Pass task runners to AudioManager constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 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 122
123 // Use 4 buffers for Vista, 3 for everyone else: 123 // Use 4 buffers for Vista, 3 for everyone else:
124 // - The entire Windows audio stack was rewritten for Windows Vista and wave 124 // - The entire Windows audio stack was rewritten for Windows Vista and wave
125 // out performance was degraded compared to XP. 125 // out performance was degraded compared to XP.
126 // - The regression was fixed in Windows 7 and most configurations will work 126 // - The regression was fixed in Windows 7 and most configurations will work
127 // with 2, but some (e.g., some Sound Blasters) still need 3. 127 // with 2, but some (e.g., some Sound Blasters) still need 3.
128 // - Some XP configurations (even multi-processor ones) also need 3. 128 // - Some XP configurations (even multi-processor ones) also need 3.
129 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3; 129 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3;
130 } 130 }
131 131
132 AudioManagerWin::AudioManagerWin(AudioLogFactory* audio_log_factory) 132 AudioManagerWin::AudioManagerWin(
133 : AudioManagerBase(audio_log_factory), 133 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
134 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner,
135 AudioLogFactory* audio_log_factory)
136 : AudioManagerBase(std::move(task_runner),
137 std::move(worker_task_runner),
138 audio_log_factory),
134 // |CoreAudioUtil::IsSupported()| uses static variables to avoid doing 139 // |CoreAudioUtil::IsSupported()| uses static variables to avoid doing
135 // multiple initializations. This is however not thread safe. 140 // multiple initializations. This is however not thread safe.
136 // So, here we call it explicitly before we kick off the audio thread 141 // So, here we call it explicitly before we kick off the audio thread
137 // or do any other work. 142 // or do any other work.
138 enumeration_type_(CoreAudioUtil::IsSupported() ? 143 enumeration_type_(CoreAudioUtil::IsSupported() ? kMMDeviceEnumeration
139 kMMDeviceEnumeration : kWaveEnumeration) { 144 : kWaveEnumeration) {
140 SetMaxOutputStreamsAllowed(kMaxOutputStreams); 145 SetMaxOutputStreamsAllowed(kMaxOutputStreams);
141 146
142 // WARNING: This is executed on the UI loop, do not add any code here which 147 // WARNING: This is executed on the UI loop, do not add any code here which
143 // loads libraries or attempts to call out into the OS. Instead add such code 148 // loads libraries or attempts to call out into the OS. Instead add such code
144 // to the InitializeOnAudioThread() method below. 149 // to the InitializeOnAudioThread() method below.
145 150
146 // Task must be posted last to avoid races from handing out "this" to the 151 // Task must be posted last to avoid races from handing out "this" to the
147 // audio thread. 152 // audio thread.
148 GetTaskRunner()->PostTask(FROM_HERE, base::Bind( 153 GetTaskRunner()->PostTask(FROM_HERE, base::Bind(
149 &AudioManagerWin::InitializeOnAudioThread, base::Unretained(this))); 154 &AudioManagerWin::InitializeOnAudioThread, base::Unretained(this)));
150 } 155 }
151 156
152 AudioManagerWin::~AudioManagerWin() { 157 AudioManagerWin::~AudioManagerWin() {
153 // It's safe to post a task here since Shutdown() will wait for all tasks to 158 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
154 // complete before returning. 159
155 GetTaskRunner()->PostTask(FROM_HERE, base::Bind(
156 &AudioManagerWin::ShutdownOnAudioThread, base::Unretained(this)));
157 Shutdown(); 160 Shutdown();
161 ShutdownOnAudioThread();
158 } 162 }
159 163
160 bool AudioManagerWin::HasAudioOutputDevices() { 164 bool AudioManagerWin::HasAudioOutputDevices() {
161 return (::waveOutGetNumDevs() != 0); 165 return (::waveOutGetNumDevs() != 0);
162 } 166 }
163 167
164 bool AudioManagerWin::HasAudioInputDevices() { 168 bool AudioManagerWin::HasAudioInputDevices() {
165 return (::waveInGetNumDevs() != 0); 169 return (::waveInGetNumDevs() != 0);
166 } 170 }
167 171
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 << device_id; 537 << device_id;
534 return NULL; 538 return NULL;
535 } 539 }
536 } 540 }
537 541
538 return new PCMWaveInAudioInputStream(this, params, kNumInputBuffers, 542 return new PCMWaveInAudioInputStream(this, params, kNumInputBuffers,
539 xp_device_id); 543 xp_device_id);
540 } 544 }
541 545
542 /// static 546 /// static
543 AudioManager* CreateAudioManager(AudioLogFactory* audio_log_factory) { 547 ScopedAudioManagerPtr CreateAudioManager(
544 return new AudioManagerWin(audio_log_factory); 548 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
549 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner,
550 AudioLogFactory* audio_log_factory) {
551 return ScopedAudioManagerPtr(
552 new AudioManagerWin(std::move(task_runner), std::move(worker_task_runner),
553 audio_log_factory));
545 } 554 }
546 555
547 } // namespace media 556 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698