Chromium Code Reviews| Index: media/audio/audio_manager_base.cc |
| diff --git a/media/audio/audio_manager_base.cc b/media/audio/audio_manager_base.cc |
| index 435cf9ee8c677ac4aa09f9f4490d40e366e75904..edc8bb41f71a8c09492fae668a82140e598be8d7 100644 |
| --- a/media/audio/audio_manager_base.cc |
| +++ b/media/audio/audio_manager_base.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/command_line.h" |
| #include "base/message_loop_proxy.h" |
| #include "base/threading/thread.h" |
| +#include "base/win/scoped_com_initializer.h" |
| #include "media/audio/audio_output_dispatcher_impl.h" |
| #include "media/audio/audio_output_proxy.h" |
| #include "media/audio/audio_output_resampler.h" |
| @@ -39,6 +40,40 @@ static const int kMaxInputChannels = 2; |
| const char AudioManagerBase::kDefaultDeviceName[] = "Default"; |
| const char AudioManagerBase::kDefaultDeviceId[] = "default"; |
| +// Initializes the COM library for use by this thread and sets the thread's |
| +// COM threading model on Windows to MTA. |
| +class AudioThread : public base::Thread { |
| +public: |
|
scherkus (not reviewing)
2012/09/17 16:50:04
indent one space
henrika (OOO until Aug 14)
2012/09/17 17:00:50
Done.
|
| + AudioThread(); |
| + virtual ~AudioThread(); |
| + |
| +protected: |
|
scherkus (not reviewing)
2012/09/17 16:50:04
indent one space
henrika (OOO until Aug 14)
2012/09/17 17:00:50
Done.
|
| + virtual void Init() OVERRIDE; |
| + virtual void CleanUp() OVERRIDE; |
| + |
| +private: |
|
scherkus (not reviewing)
2012/09/17 16:50:04
indent one space
henrika (OOO until Aug 14)
2012/09/17 17:00:50
Done.
|
| + scoped_ptr<base::win::ScopedCOMInitializer> com_initializer_; |
|
scherkus (not reviewing)
2012/09/17 16:50:04
q: this has to be a scoped_ptr<> because we need t
henrika (OOO until Aug 14)
2012/09/17 17:00:50
Good question. I base it on a similar design in th
|
| + DISALLOW_COPY_AND_ASSIGN(AudioThread); |
| +}; |
| + |
| +AudioThread::AudioThread() |
| + : base::Thread("AudioThread") { |
|
scherkus (not reviewing)
2012/09/17 16:50:04
nit: can fit on previous line
henrika (OOO until Aug 14)
2012/09/17 17:00:50
Done.
|
| +} |
| + |
| +AudioThread::~AudioThread() { |
| + Stop(); |
| +} |
| + |
| +void AudioThread::Init() { |
| + using base::win::ScopedCOMInitializer; |
|
scherkus (not reviewing)
2012/09/17 16:50:04
nit: move this statement to before "namespace medi
henrika (OOO until Aug 14)
2012/09/17 17:00:50
Cool. Thanks.
|
| + com_initializer_.reset(new ScopedCOMInitializer(ScopedCOMInitializer::kMTA)); |
| + CHECK(com_initializer_->succeeded()); |
| +} |
| + |
| +void AudioThread::CleanUp() { |
| + com_initializer_.reset(); |
| +} |
| + |
| AudioManagerBase::AudioManagerBase() |
| : num_active_input_streams_(0), |
| max_num_output_streams_(kDefaultMaxOutputStreams), |
| @@ -63,7 +98,7 @@ AudioManagerBase::~AudioManagerBase() { |
| void AudioManagerBase::Init() { |
| base::AutoLock lock(audio_thread_lock_); |
| DCHECK(!audio_thread_.get()); |
| - audio_thread_.reset(new base::Thread("AudioThread")); |
| + audio_thread_.reset(new media::AudioThread()); |
| CHECK(audio_thread_->Start()); |
| } |
| @@ -228,7 +263,7 @@ bool AudioManagerBase::IsRecordingInProcess() { |
| void AudioManagerBase::Shutdown() { |
| // To avoid running into deadlocks while we stop the thread, shut it down |
| // via a local variable while not holding the audio thread lock. |
| - scoped_ptr<base::Thread> audio_thread; |
| + scoped_ptr<media::AudioThread> audio_thread; |
| { |
| base::AutoLock lock(audio_thread_lock_); |
| audio_thread_.swap(audio_thread); |