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