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/audio_manager_base.h" | 5 #include "media/audio/audio_manager_base.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/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 ObserverList<AudioDeviceListener>::NOTIFY_EXISTING_ONLY), | 82 ObserverList<AudioDeviceListener>::NOTIFY_EXISTING_ONLY), |
83 audio_thread_("AudioThread"), | 83 audio_thread_("AudioThread"), |
84 audio_log_factory_(audio_log_factory) { | 84 audio_log_factory_(audio_log_factory) { |
85 #if defined(OS_WIN) | 85 #if defined(OS_WIN) |
86 audio_thread_.init_com_with_mta(true); | 86 audio_thread_.init_com_with_mta(true); |
87 #elif defined(OS_MACOSX) | 87 #elif defined(OS_MACOSX) |
88 // CoreAudio calls must occur on the main thread of the process, which in our | 88 // CoreAudio calls must occur on the main thread of the process, which in our |
89 // case is sadly the browser UI thread. Failure to execute calls on the right | 89 // case is sadly the browser UI thread. Failure to execute calls on the right |
90 // thread leads to crashes and odd behavior. See http://crbug.com/158170. | 90 // thread leads to crashes and odd behavior. See http://crbug.com/158170. |
91 // TODO(dalecurtis): We should require the message loop to be passed in. | 91 // TODO(dalecurtis): We should require the message loop to be passed in. |
92 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 92 if (base::MessageLoopForUI::IsCurrent()) { |
93 if (!cmd_line->HasSwitch(switches::kDisableMainThreadAudio) && | |
94 base::MessageLoopProxy::current().get() && | |
95 base::MessageLoopForUI::IsCurrent()) { | |
96 task_runner_ = base::MessageLoopProxy::current(); | 93 task_runner_ = base::MessageLoopProxy::current(); |
97 return; | 94 return; |
98 } | 95 } |
99 #endif | 96 #endif |
100 | 97 |
101 CHECK(audio_thread_.Start()); | 98 CHECK(audio_thread_.Start()); |
102 task_runner_ = audio_thread_.message_loop_proxy(); | 99 task_runner_ = audio_thread_.message_loop_proxy(); |
103 } | 100 } |
104 | 101 |
105 AudioManagerBase::~AudioManagerBase() { | 102 AudioManagerBase::~AudioManagerBase() { |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 (*it)->dispatcher->CloseStreamsForWedgeFix(); | 434 (*it)->dispatcher->CloseStreamsForWedgeFix(); |
438 } | 435 } |
439 for (AudioOutputDispatchers::iterator it = output_dispatchers_.begin(); | 436 for (AudioOutputDispatchers::iterator it = output_dispatchers_.begin(); |
440 it != output_dispatchers_.end(); ++it) { | 437 it != output_dispatchers_.end(); ++it) { |
441 (*it)->dispatcher->RestartStreamsForWedgeFix(); | 438 (*it)->dispatcher->RestartStreamsForWedgeFix(); |
442 } | 439 } |
443 #endif | 440 #endif |
444 } | 441 } |
445 | 442 |
446 } // namespace media | 443 } // namespace media |
OLD | NEW |