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

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

Issue 10909271: Adds COM init to AudioManager thread for Windows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes Created 8 years, 3 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 | Annotate | Revision Log
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 "base/threading/thread.h"
(...skipping 21 matching lines...) Expand all
32 32
33 // Default maximum number of input streams that can be open simultaneously 33 // Default maximum number of input streams that can be open simultaneously
34 // for all platforms. 34 // for all platforms.
35 static const int kDefaultMaxInputStreams = 16; 35 static const int kDefaultMaxInputStreams = 16;
36 36
37 static const int kMaxInputChannels = 2; 37 static const int kMaxInputChannels = 2;
38 38
39 const char AudioManagerBase::kDefaultDeviceName[] = "Default"; 39 const char AudioManagerBase::kDefaultDeviceName[] = "Default";
40 const char AudioManagerBase::kDefaultDeviceId[] = "default"; 40 const char AudioManagerBase::kDefaultDeviceId[] = "default";
41 41
42 // Initializes the COM library for use by this thread and sets the thread's
43 // COM threading model on Windows to MTA.
44 class AudioThread : public base::Thread {
45 public:
46 AudioThread();
47 virtual ~AudioThread();
48
49 protected:
50 virtual void Init() OVERRIDE;
51 virtual void CleanUp() OVERRIDE;
52
53 private:
54 scoped_ptr<base::win::ScopedCOMInitializer> com_initializer_;
55 DISALLOW_COPY_AND_ASSIGN(AudioThread);
56 };
57
58 AudioThread::AudioThread()
59 : base::Thread("AudioThread") {
60 }
61
62 AudioThread::~AudioThread() {
63 Stop();
64 }
65
66 void AudioThread::Init() {
67 using base::win::ScopedCOMInitializer;
68 com_initializer_.reset(new ScopedCOMInitializer(ScopedCOMInitializer::kMTA));
69 CHECK(com_initializer_->succeeded());
70 }
71
72 void AudioThread::CleanUp() {
73 com_initializer_.reset();
74 }
75
42 AudioManagerBase::AudioManagerBase() 76 AudioManagerBase::AudioManagerBase()
43 : num_active_input_streams_(0), 77 : num_active_input_streams_(0),
44 max_num_output_streams_(kDefaultMaxOutputStreams), 78 max_num_output_streams_(kDefaultMaxOutputStreams),
45 max_num_input_streams_(kDefaultMaxInputStreams), 79 max_num_input_streams_(kDefaultMaxInputStreams),
46 num_output_streams_(0), 80 num_output_streams_(0),
47 num_input_streams_(0) { 81 num_input_streams_(0) {
48 } 82 }
49 83
50 AudioManagerBase::~AudioManagerBase() { 84 AudioManagerBase::~AudioManagerBase() {
51 // The platform specific AudioManager implementation must have already 85 // The platform specific AudioManager implementation must have already
52 // stopped the audio thread. Otherwise, we may destroy audio streams before 86 // stopped the audio thread. Otherwise, we may destroy audio streams before
53 // stopping the thread, resulting an unexpected behavior. 87 // stopping the thread, resulting an unexpected behavior.
54 // This way we make sure activities of the audio streams are all stopped 88 // This way we make sure activities of the audio streams are all stopped
55 // before we destroy them. 89 // before we destroy them.
56 CHECK(!audio_thread_.get()); 90 CHECK(!audio_thread_.get());
57 // All the output streams should have been deleted. 91 // All the output streams should have been deleted.
58 DCHECK_EQ(0, num_output_streams_); 92 DCHECK_EQ(0, num_output_streams_);
59 // All the input streams should have been deleted. 93 // All the input streams should have been deleted.
60 DCHECK_EQ(0, num_input_streams_); 94 DCHECK_EQ(0, num_input_streams_);
61 } 95 }
62 96
63 void AudioManagerBase::Init() { 97 void AudioManagerBase::Init() {
64 base::AutoLock lock(audio_thread_lock_); 98 base::AutoLock lock(audio_thread_lock_);
65 DCHECK(!audio_thread_.get()); 99 DCHECK(!audio_thread_.get());
66 audio_thread_.reset(new base::Thread("AudioThread")); 100 audio_thread_.reset(new media::AudioThread());
67 CHECK(audio_thread_->Start()); 101 CHECK(audio_thread_->Start());
68 } 102 }
69 103
70 string16 AudioManagerBase::GetAudioInputDeviceModel() { 104 string16 AudioManagerBase::GetAudioInputDeviceModel() {
71 return string16(); 105 return string16();
72 } 106 }
73 107
74 scoped_refptr<base::MessageLoopProxy> AudioManagerBase::GetMessageLoop() { 108 scoped_refptr<base::MessageLoopProxy> AudioManagerBase::GetMessageLoop() {
75 base::AutoLock lock(audio_thread_lock_); 109 base::AutoLock lock(audio_thread_lock_);
76 return audio_thread_.get() ? audio_thread_->message_loop_proxy() : NULL; 110 return audio_thread_.get() ? audio_thread_->message_loop_proxy() : NULL;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 base::AtomicRefCountDec(&num_active_input_streams_); 255 base::AtomicRefCountDec(&num_active_input_streams_);
222 } 256 }
223 257
224 bool AudioManagerBase::IsRecordingInProcess() { 258 bool AudioManagerBase::IsRecordingInProcess() {
225 return !base::AtomicRefCountIsZero(&num_active_input_streams_); 259 return !base::AtomicRefCountIsZero(&num_active_input_streams_);
226 } 260 }
227 261
228 void AudioManagerBase::Shutdown() { 262 void AudioManagerBase::Shutdown() {
229 // To avoid running into deadlocks while we stop the thread, shut it down 263 // To avoid running into deadlocks while we stop the thread, shut it down
230 // via a local variable while not holding the audio thread lock. 264 // via a local variable while not holding the audio thread lock.
231 scoped_ptr<base::Thread> audio_thread; 265 scoped_ptr<media::AudioThread> audio_thread;
232 { 266 {
233 base::AutoLock lock(audio_thread_lock_); 267 base::AutoLock lock(audio_thread_lock_);
234 audio_thread_.swap(audio_thread); 268 audio_thread_.swap(audio_thread);
235 } 269 }
236 270
237 if (!audio_thread.get()) 271 if (!audio_thread.get())
238 return; 272 return;
239 273
240 CHECK_NE(MessageLoop::current(), audio_thread->message_loop()); 274 CHECK_NE(MessageLoop::current(), audio_thread->message_loop());
241 275
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 #else 320 #else
287 // TODO(dalecurtis): This should include bits per channel and channel layout 321 // TODO(dalecurtis): This should include bits per channel and channel layout
288 // eventually. 322 // eventually.
289 return AudioParameters( 323 return AudioParameters(
290 AudioParameters::AUDIO_PCM_LOW_LATENCY, input_params.channel_layout(), 324 AudioParameters::AUDIO_PCM_LOW_LATENCY, input_params.channel_layout(),
291 GetAudioHardwareSampleRate(), 16, GetAudioHardwareBufferSize()); 325 GetAudioHardwareSampleRate(), 16, GetAudioHardwareBufferSize());
292 #endif // defined(OS_IOS) 326 #endif // defined(OS_IOS)
293 } 327 }
294 328
295 } // namespace media 329 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698