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" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 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 AudioThread::AudioThread(const char* name) | |
| 43 : base::Thread(name) { | |
|
scherkus (not reviewing)
2012/09/17 16:23:48
fix indent
henrika (OOO until Aug 14)
2012/09/17 16:43:29
Done.
| |
| 44 } | |
| 45 | |
| 46 AudioThread::~AudioThread() { | |
| 47 Stop(); | |
| 48 } | |
| 49 | |
| 50 void AudioThread::Init() { | |
| 51 using base::win::ScopedCOMInitializer; | |
|
DaleCurtis
2012/09/17 15:57:16
This needs an IF (OS_WIN) block right?
henrika (OOO until Aug 14)
2012/09/17 16:43:29
No. As Tommi says; only adds one byte on other pla
| |
| 52 com_initializer_.reset(new ScopedCOMInitializer(ScopedCOMInitializer::kMTA)); | |
| 53 CHECK(com_initializer_->succeeded()); | |
| 54 } | |
| 55 | |
| 56 void AudioThread::CleanUp() { | |
| 57 com_initializer_.reset(); | |
| 58 } | |
| 59 | |
| 42 AudioManagerBase::AudioManagerBase() | 60 AudioManagerBase::AudioManagerBase() |
| 43 : num_active_input_streams_(0), | 61 : num_active_input_streams_(0), |
| 44 max_num_output_streams_(kDefaultMaxOutputStreams), | 62 max_num_output_streams_(kDefaultMaxOutputStreams), |
| 45 max_num_input_streams_(kDefaultMaxInputStreams), | 63 max_num_input_streams_(kDefaultMaxInputStreams), |
| 46 num_output_streams_(0), | 64 num_output_streams_(0), |
| 47 num_input_streams_(0) { | 65 num_input_streams_(0) { |
| 48 } | 66 } |
| 49 | 67 |
| 50 AudioManagerBase::~AudioManagerBase() { | 68 AudioManagerBase::~AudioManagerBase() { |
| 51 // The platform specific AudioManager implementation must have already | 69 // The platform specific AudioManager implementation must have already |
| 52 // stopped the audio thread. Otherwise, we may destroy audio streams before | 70 // stopped the audio thread. Otherwise, we may destroy audio streams before |
| 53 // stopping the thread, resulting an unexpected behavior. | 71 // stopping the thread, resulting an unexpected behavior. |
| 54 // This way we make sure activities of the audio streams are all stopped | 72 // This way we make sure activities of the audio streams are all stopped |
| 55 // before we destroy them. | 73 // before we destroy them. |
| 56 CHECK(!audio_thread_.get()); | 74 CHECK(!audio_thread_.get()); |
| 57 // All the output streams should have been deleted. | 75 // All the output streams should have been deleted. |
| 58 DCHECK_EQ(0, num_output_streams_); | 76 DCHECK_EQ(0, num_output_streams_); |
| 59 // All the input streams should have been deleted. | 77 // All the input streams should have been deleted. |
| 60 DCHECK_EQ(0, num_input_streams_); | 78 DCHECK_EQ(0, num_input_streams_); |
| 61 } | 79 } |
| 62 | 80 |
| 63 void AudioManagerBase::Init() { | 81 void AudioManagerBase::Init() { |
| 64 base::AutoLock lock(audio_thread_lock_); | 82 base::AutoLock lock(audio_thread_lock_); |
| 65 DCHECK(!audio_thread_.get()); | 83 DCHECK(!audio_thread_.get()); |
| 66 audio_thread_.reset(new base::Thread("AudioThread")); | 84 audio_thread_.reset(new media::AudioThread("AudioThread")); |
|
scherkus (not reviewing)
2012/09/17 16:23:48
nit: if you don't need to pass in multiple names f
| |
| 67 CHECK(audio_thread_->Start()); | 85 CHECK(audio_thread_->Start()); |
| 68 } | 86 } |
| 69 | 87 |
| 70 string16 AudioManagerBase::GetAudioInputDeviceModel() { | 88 string16 AudioManagerBase::GetAudioInputDeviceModel() { |
| 71 return string16(); | 89 return string16(); |
| 72 } | 90 } |
| 73 | 91 |
| 74 scoped_refptr<base::MessageLoopProxy> AudioManagerBase::GetMessageLoop() { | 92 scoped_refptr<base::MessageLoopProxy> AudioManagerBase::GetMessageLoop() { |
| 75 base::AutoLock lock(audio_thread_lock_); | 93 base::AutoLock lock(audio_thread_lock_); |
| 76 return audio_thread_.get() ? audio_thread_->message_loop_proxy() : NULL; | 94 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_); | 239 base::AtomicRefCountDec(&num_active_input_streams_); |
| 222 } | 240 } |
| 223 | 241 |
| 224 bool AudioManagerBase::IsRecordingInProcess() { | 242 bool AudioManagerBase::IsRecordingInProcess() { |
| 225 return !base::AtomicRefCountIsZero(&num_active_input_streams_); | 243 return !base::AtomicRefCountIsZero(&num_active_input_streams_); |
| 226 } | 244 } |
| 227 | 245 |
| 228 void AudioManagerBase::Shutdown() { | 246 void AudioManagerBase::Shutdown() { |
| 229 // To avoid running into deadlocks while we stop the thread, shut it down | 247 // 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. | 248 // via a local variable while not holding the audio thread lock. |
| 231 scoped_ptr<base::Thread> audio_thread; | 249 scoped_ptr<media::AudioThread> audio_thread; |
| 232 { | 250 { |
| 233 base::AutoLock lock(audio_thread_lock_); | 251 base::AutoLock lock(audio_thread_lock_); |
| 234 audio_thread_.swap(audio_thread); | 252 audio_thread_.swap(audio_thread); |
| 235 } | 253 } |
| 236 | 254 |
| 237 if (!audio_thread.get()) | 255 if (!audio_thread.get()) |
| 238 return; | 256 return; |
| 239 | 257 |
| 240 CHECK_NE(MessageLoop::current(), audio_thread->message_loop()); | 258 CHECK_NE(MessageLoop::current(), audio_thread->message_loop()); |
| 241 | 259 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 286 #else | 304 #else |
| 287 // TODO(dalecurtis): This should include bits per channel and channel layout | 305 // TODO(dalecurtis): This should include bits per channel and channel layout |
| 288 // eventually. | 306 // eventually. |
| 289 return AudioParameters( | 307 return AudioParameters( |
| 290 AudioParameters::AUDIO_PCM_LOW_LATENCY, input_params.channel_layout(), | 308 AudioParameters::AUDIO_PCM_LOW_LATENCY, input_params.channel_layout(), |
| 291 GetAudioHardwareSampleRate(), 16, GetAudioHardwareBufferSize()); | 309 GetAudioHardwareSampleRate(), 16, GetAudioHardwareBufferSize()); |
| 292 #endif // defined(OS_IOS) | 310 #endif // defined(OS_IOS) |
| 293 } | 311 } |
| 294 | 312 |
| 295 } // namespace media | 313 } // namespace media |
| OLD | NEW |