| 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/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 dispatcher_->output_params == dispatcher_in->output_params && | 67 dispatcher_->output_params == dispatcher_in->output_params && |
| 68 (!dispatcher_->input_params.input_channels() || | 68 (!dispatcher_->input_params.input_channels() || |
| 69 dispatcher_->input_device_id == dispatcher_in->input_device_id)); | 69 dispatcher_->input_device_id == dispatcher_in->input_device_id)); |
| 70 } | 70 } |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 const DispatcherParams* dispatcher_; | 73 const DispatcherParams* dispatcher_; |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 AudioManagerBase::AudioManagerBase() | 76 AudioManagerBase::AudioManagerBase() |
| 77 : num_active_input_streams_(0), | 77 : max_num_output_streams_(kDefaultMaxOutputStreams), |
| 78 max_num_output_streams_(kDefaultMaxOutputStreams), | |
| 79 max_num_input_streams_(kDefaultMaxInputStreams), | 78 max_num_input_streams_(kDefaultMaxInputStreams), |
| 80 num_output_streams_(0), | 79 num_output_streams_(0), |
| 81 num_input_streams_(0), | 80 num_input_streams_(0), |
| 82 // TODO(dalecurtis): Switch this to an ObserverListThreadSafe, so we don't | 81 // TODO(dalecurtis): Switch this to an ObserverListThreadSafe, so we don't |
| 83 // block the UI thread when swapping devices. | 82 // block the UI thread when swapping devices. |
| 84 output_listeners_( | 83 output_listeners_( |
| 85 ObserverList<AudioDeviceListener>::NOTIFY_EXISTING_ONLY), | 84 ObserverList<AudioDeviceListener>::NOTIFY_EXISTING_ONLY), |
| 86 audio_thread_(new base::Thread("AudioThread")) { | 85 audio_thread_(new base::Thread("AudioThread")) { |
| 87 #if defined(OS_WIN) | 86 #if defined(OS_WIN) |
| 88 audio_thread_->init_com_with_mta(true); | 87 audio_thread_->init_com_with_mta(true); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 delete stream; | 303 delete stream; |
| 305 } | 304 } |
| 306 | 305 |
| 307 void AudioManagerBase::ReleaseInputStream(AudioInputStream* stream) { | 306 void AudioManagerBase::ReleaseInputStream(AudioInputStream* stream) { |
| 308 DCHECK(stream); | 307 DCHECK(stream); |
| 309 // TODO(xians) : Have a clearer destruction path for the AudioInputStream. | 308 // TODO(xians) : Have a clearer destruction path for the AudioInputStream. |
| 310 --num_input_streams_; | 309 --num_input_streams_; |
| 311 delete stream; | 310 delete stream; |
| 312 } | 311 } |
| 313 | 312 |
| 314 void AudioManagerBase::IncreaseActiveInputStreamCount() { | |
| 315 base::AtomicRefCountInc(&num_active_input_streams_); | |
| 316 } | |
| 317 | |
| 318 void AudioManagerBase::DecreaseActiveInputStreamCount() { | |
| 319 DCHECK(IsRecordingInProcess()); | |
| 320 base::AtomicRefCountDec(&num_active_input_streams_); | |
| 321 } | |
| 322 | |
| 323 bool AudioManagerBase::IsRecordingInProcess() { | |
| 324 return !base::AtomicRefCountIsZero(&num_active_input_streams_); | |
| 325 } | |
| 326 | |
| 327 void AudioManagerBase::Shutdown() { | 313 void AudioManagerBase::Shutdown() { |
| 328 // To avoid running into deadlocks while we stop the thread, shut it down | 314 // To avoid running into deadlocks while we stop the thread, shut it down |
| 329 // via a local variable while not holding the audio thread lock. | 315 // via a local variable while not holding the audio thread lock. |
| 330 scoped_ptr<base::Thread> audio_thread; | 316 scoped_ptr<base::Thread> audio_thread; |
| 331 { | 317 { |
| 332 base::AutoLock lock(audio_thread_lock_); | 318 base::AutoLock lock(audio_thread_lock_); |
| 333 audio_thread_.swap(audio_thread); | 319 audio_thread_.swap(audio_thread); |
| 334 } | 320 } |
| 335 | 321 |
| 336 if (!audio_thread) | 322 if (!audio_thread) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 return GetPreferredOutputStreamParameters(AudioParameters()); | 385 return GetPreferredOutputStreamParameters(AudioParameters()); |
| 400 } | 386 } |
| 401 | 387 |
| 402 AudioParameters AudioManagerBase::GetInputStreamParameters( | 388 AudioParameters AudioManagerBase::GetInputStreamParameters( |
| 403 const std::string& device_id) { | 389 const std::string& device_id) { |
| 404 NOTREACHED(); | 390 NOTREACHED(); |
| 405 return AudioParameters(); | 391 return AudioParameters(); |
| 406 } | 392 } |
| 407 | 393 |
| 408 } // namespace media | 394 } // namespace media |
| OLD | NEW |