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

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

Issue 11048029: Allow Thread to initialize COM for Windows consumers who need it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « media/audio/audio_manager_base.h ('k') | media/audio/fake_audio_output_stream.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_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/command_line.h" 8 #include "base/command_line.h"
9 #include "base/message_loop_proxy.h" 9 #include "base/message_loop_proxy.h"
10 #include "base/threading/thread.h"
10 #include "media/audio/audio_output_dispatcher_impl.h" 11 #include "media/audio/audio_output_dispatcher_impl.h"
11 #include "media/audio/audio_output_proxy.h" 12 #include "media/audio/audio_output_proxy.h"
12 #include "media/audio/audio_output_resampler.h" 13 #include "media/audio/audio_output_resampler.h"
13 #include "media/audio/audio_util.h" 14 #include "media/audio/audio_util.h"
14 #include "media/audio/fake_audio_input_stream.h" 15 #include "media/audio/fake_audio_input_stream.h"
15 #include "media/audio/fake_audio_output_stream.h" 16 #include "media/audio/fake_audio_output_stream.h"
16 #include "media/base/media_switches.h" 17 #include "media/base/media_switches.h"
17 18
18 // TODO(dalecurtis): Temporarily disabled while switching pipeline to use float, 19 // TODO(dalecurtis): Temporarily disabled while switching pipeline to use float,
19 // http://crbug.com/114700 20 // http://crbug.com/114700
(...skipping 11 matching lines...) Expand all
31 32
32 // Default maximum number of input streams that can be open simultaneously 33 // Default maximum number of input streams that can be open simultaneously
33 // for all platforms. 34 // for all platforms.
34 static const int kDefaultMaxInputStreams = 16; 35 static const int kDefaultMaxInputStreams = 16;
35 36
36 static const int kMaxInputChannels = 2; 37 static const int kMaxInputChannels = 2;
37 38
38 const char AudioManagerBase::kDefaultDeviceName[] = "Default"; 39 const char AudioManagerBase::kDefaultDeviceName[] = "Default";
39 const char AudioManagerBase::kDefaultDeviceId[] = "default"; 40 const char AudioManagerBase::kDefaultDeviceId[] = "default";
40 41
41 #if defined(OS_WIN)
42 AudioThread::AudioThread(const char* name) : base::Thread(name) {
43 }
44
45 AudioThread::~AudioThread() {
46 Stop();
47 }
48
49 void AudioThread::Init() {
50 com_initializer_.reset(new base::win::ScopedCOMInitializer(
51 base::win::ScopedCOMInitializer::kMTA));
52 }
53
54 void AudioThread::CleanUp() {
55 com_initializer_.reset();
56 }
57 #endif
58
59 AudioManagerBase::AudioManagerBase() 42 AudioManagerBase::AudioManagerBase()
60 : num_active_input_streams_(0), 43 : num_active_input_streams_(0),
61 max_num_output_streams_(kDefaultMaxOutputStreams), 44 max_num_output_streams_(kDefaultMaxOutputStreams),
62 max_num_input_streams_(kDefaultMaxInputStreams), 45 max_num_input_streams_(kDefaultMaxInputStreams),
63 num_output_streams_(0), 46 num_output_streams_(0),
64 num_input_streams_(0) { 47 num_input_streams_(0) {
65 } 48 }
66 49
67 AudioManagerBase::~AudioManagerBase() { 50 AudioManagerBase::~AudioManagerBase() {
68 // The platform specific AudioManager implementation must have already 51 // The platform specific AudioManager implementation must have already
69 // stopped the audio thread. Otherwise, we may destroy audio streams before 52 // stopped the audio thread. Otherwise, we may destroy audio streams before
70 // stopping the thread, resulting an unexpected behavior. 53 // stopping the thread, resulting an unexpected behavior.
71 // This way we make sure activities of the audio streams are all stopped 54 // This way we make sure activities of the audio streams are all stopped
72 // before we destroy them. 55 // before we destroy them.
73 CHECK(!audio_thread_.get()); 56 CHECK(!audio_thread_.get());
74 // All the output streams should have been deleted. 57 // All the output streams should have been deleted.
75 DCHECK_EQ(0, num_output_streams_); 58 DCHECK_EQ(0, num_output_streams_);
76 // All the input streams should have been deleted. 59 // All the input streams should have been deleted.
77 DCHECK_EQ(0, num_input_streams_); 60 DCHECK_EQ(0, num_input_streams_);
78 } 61 }
79 62
80 void AudioManagerBase::Init() { 63 void AudioManagerBase::Init() {
81 base::AutoLock lock(audio_thread_lock_); 64 base::AutoLock lock(audio_thread_lock_);
82 DCHECK(!audio_thread_.get()); 65 DCHECK(!audio_thread_.get());
83 audio_thread_.reset(new AudioThread("AudioThread")); 66 audio_thread_.reset(new base::Thread("AudioThread"));
67 #if defined(OS_WIN)
68 audio_thread_->init_com_with_mta(true);
69 #endif
84 CHECK(audio_thread_->Start()); 70 CHECK(audio_thread_->Start());
85 } 71 }
86 72
87 string16 AudioManagerBase::GetAudioInputDeviceModel() { 73 string16 AudioManagerBase::GetAudioInputDeviceModel() {
88 return string16(); 74 return string16();
89 } 75 }
90 76
91 scoped_refptr<base::MessageLoopProxy> AudioManagerBase::GetMessageLoop() { 77 scoped_refptr<base::MessageLoopProxy> AudioManagerBase::GetMessageLoop() {
92 base::AutoLock lock(audio_thread_lock_); 78 base::AutoLock lock(audio_thread_lock_);
93 return audio_thread_.get() ? audio_thread_->message_loop_proxy() : NULL; 79 return audio_thread_.get() ? audio_thread_->message_loop_proxy() : NULL;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 base::AtomicRefCountDec(&num_active_input_streams_); 250 base::AtomicRefCountDec(&num_active_input_streams_);
265 } 251 }
266 252
267 bool AudioManagerBase::IsRecordingInProcess() { 253 bool AudioManagerBase::IsRecordingInProcess() {
268 return !base::AtomicRefCountIsZero(&num_active_input_streams_); 254 return !base::AtomicRefCountIsZero(&num_active_input_streams_);
269 } 255 }
270 256
271 void AudioManagerBase::Shutdown() { 257 void AudioManagerBase::Shutdown() {
272 // To avoid running into deadlocks while we stop the thread, shut it down 258 // To avoid running into deadlocks while we stop the thread, shut it down
273 // via a local variable while not holding the audio thread lock. 259 // via a local variable while not holding the audio thread lock.
274 scoped_ptr<AudioThread> audio_thread; 260 scoped_ptr<base::Thread> audio_thread;
275 { 261 {
276 base::AutoLock lock(audio_thread_lock_); 262 base::AutoLock lock(audio_thread_lock_);
277 audio_thread_.swap(audio_thread); 263 audio_thread_.swap(audio_thread);
278 } 264 }
279 265
280 if (!audio_thread.get()) 266 if (!audio_thread.get())
281 return; 267 return;
282 268
283 CHECK_NE(MessageLoop::current(), audio_thread->message_loop()); 269 CHECK_NE(MessageLoop::current(), audio_thread->message_loop());
284 270
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 #else 315 #else
330 // TODO(dalecurtis): This should include bits per channel and channel layout 316 // TODO(dalecurtis): This should include bits per channel and channel layout
331 // eventually. 317 // eventually.
332 return AudioParameters( 318 return AudioParameters(
333 AudioParameters::AUDIO_PCM_LOW_LATENCY, input_params.channel_layout(), 319 AudioParameters::AUDIO_PCM_LOW_LATENCY, input_params.channel_layout(),
334 GetAudioHardwareSampleRate(), 16, GetAudioHardwareBufferSize()); 320 GetAudioHardwareSampleRate(), 16, GetAudioHardwareBufferSize());
335 #endif // defined(OS_IOS) 321 #endif // defined(OS_IOS)
336 } 322 }
337 323
338 } // namespace media 324 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_manager_base.h ('k') | media/audio/fake_audio_output_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698