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

Side by Side Diff: media/audio/audio_manager.cc

Issue 1130753005: Get audio_unittests passing with h/w on windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: MTA -> STA Created 5 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/audio_input_volume_unittest.cc ('k') | media/audio/audio_manager_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/audio_manager.h" 5 #include "media/audio/audio_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/alias.h" 10 #include "base/debug/alias.h"
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/power_monitor/power_monitor.h" 14 #include "base/power_monitor/power_monitor.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "media/audio/audio_manager_factory.h" 16 #include "media/audio/audio_manager_factory.h"
17 #include "media/audio/fake_audio_log_factory.h" 17 #include "media/audio/fake_audio_log_factory.h"
18 #include "media/base/media_switches.h" 18 #include "media/base/media_switches.h"
19 19
20 #if defined(OS_WIN)
21 #include "base/win/scoped_com_initializer.h"
22 #endif
23
20 namespace media { 24 namespace media {
21 namespace { 25 namespace {
22 26
23 // The singleton instance of AudioManager. This is set when Create() is called. 27 // The singleton instance of AudioManager. This is set when Create() is called.
24 AudioManager* g_last_created = NULL; 28 AudioManager* g_last_created = NULL;
25 29
26 // The singleton instance of AudioManagerFactory. This is only set if 30 // The singleton instance of AudioManagerFactory. This is only set if
27 // SetFactory() is called. If it is set when Create() is called, its 31 // SetFactory() is called. If it is set when Create() is called, its
28 // CreateInstance() function is used to set |g_last_created|. Otherwise, the 32 // CreateInstance() function is used to set |g_last_created|. Otherwise, the
29 // linked implementation of media::CreateAudioManager is used to set 33 // linked implementation of media::CreateAudioManager is used to set
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 // Don't hold the lock while posting the next task. 116 // Don't hold the lock while posting the next task.
113 g_last_created->GetTaskRunner()->PostDelayedTask( 117 g_last_created->GetTaskRunner()->PostDelayedTask(
114 FROM_HERE, 118 FROM_HERE,
115 base::Bind(&AudioManagerHelper::UpdateLastAudioThreadTimeTick, 119 base::Bind(&AudioManagerHelper::UpdateLastAudioThreadTimeTick,
116 base::Unretained(this)), 120 base::Unretained(this)),
117 max_hung_task_time_ / 10); 121 max_hung_task_time_ / 10);
118 } 122 }
119 123
120 AudioLogFactory* fake_log_factory() { return &fake_log_factory_; } 124 AudioLogFactory* fake_log_factory() { return &fake_log_factory_; }
121 125
126 #if defined(OS_WIN)
127 // This should be called before creating an AudioManager in tests to ensure
128 // that the creating thread is COM initialized.
129 void InitializeCOMForTesting() {
130 com_initializer_for_testing_.reset(new base::win::ScopedCOMInitializer());
131 }
132 #endif
133
122 private: 134 private:
123 FakeAudioLogFactory fake_log_factory_; 135 FakeAudioLogFactory fake_log_factory_;
124 136
125 const base::TimeDelta max_hung_task_time_; 137 const base::TimeDelta max_hung_task_time_;
126 scoped_refptr<base::SingleThreadTaskRunner> monitor_task_runner_; 138 scoped_refptr<base::SingleThreadTaskRunner> monitor_task_runner_;
127 139
128 base::Lock hang_lock_; 140 base::Lock hang_lock_;
129 bool hang_detection_enabled_; 141 bool hang_detection_enabled_;
130 base::TimeTicks last_audio_thread_timer_tick_; 142 base::TimeTicks last_audio_thread_timer_tick_;
131 int hang_failures_; 143 int hang_failures_;
132 144
145 #if defined(OS_WIN)
146 scoped_ptr<base::win::ScopedCOMInitializer> com_initializer_for_testing_;
147 #endif
148
133 DISALLOW_COPY_AND_ASSIGN(AudioManagerHelper); 149 DISALLOW_COPY_AND_ASSIGN(AudioManagerHelper);
134 }; 150 };
135 151
136 static bool g_hang_monitor_enabled = false; 152 static bool g_hang_monitor_enabled = false;
137 153
138 static base::LazyInstance<AudioManagerHelper>::Leaky g_helper = 154 static base::LazyInstance<AudioManagerHelper>::Leaky g_helper =
139 LAZY_INSTANCE_INITIALIZER; 155 LAZY_INSTANCE_INITIALIZER;
140 } // namespace 156 } // namespace
141 157
142 // Forward declaration of the platform specific AudioManager factory function. 158 // Forward declaration of the platform specific AudioManager factory function.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 if (g_hang_monitor_enabled || 200 if (g_hang_monitor_enabled ||
185 base::CommandLine::ForCurrentProcess()->HasSwitch( 201 base::CommandLine::ForCurrentProcess()->HasSwitch(
186 switches::kEnableAudioHangMonitor)) { 202 switches::kEnableAudioHangMonitor)) {
187 g_helper.Pointer()->StartHangTimer(monitor_task_runner); 203 g_helper.Pointer()->StartHangTimer(monitor_task_runner);
188 } 204 }
189 return manager; 205 return manager;
190 } 206 }
191 207
192 // static 208 // static
193 AudioManager* AudioManager::CreateForTesting() { 209 AudioManager* AudioManager::CreateForTesting() {
210 #if defined(OS_WIN)
211 g_helper.Pointer()->InitializeCOMForTesting();
212 #endif
194 return Create(g_helper.Pointer()->fake_log_factory()); 213 return Create(g_helper.Pointer()->fake_log_factory());
195 } 214 }
196 215
197 // static 216 // static
198 void AudioManager::EnableHangMonitor() { 217 void AudioManager::EnableHangMonitor() {
199 CHECK(!g_last_created); 218 CHECK(!g_last_created);
200 // On OSX the audio thread is the UI thread, for which a hang monitor is not 219 // On OSX the audio thread is the UI thread, for which a hang monitor is not
201 // necessary or recommended. If it's manually requested, we should allow it 220 // necessary or recommended. If it's manually requested, we should allow it
202 // to start though. 221 // to start though.
203 #if !defined(OS_MACOSX) 222 #if !defined(OS_MACOSX)
204 g_hang_monitor_enabled = true; 223 g_hang_monitor_enabled = true;
205 #endif 224 #endif
206 } 225 }
207 226
208 // static 227 // static
209 AudioManager* AudioManager::Get() { 228 AudioManager* AudioManager::Get() {
210 return g_last_created; 229 return g_last_created;
211 } 230 }
212 231
213 } // namespace media 232 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_input_volume_unittest.cc ('k') | media/audio/audio_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698