| Index: media/audio/audio_manager_base.cc
|
| diff --git a/media/audio/audio_manager_base.cc b/media/audio/audio_manager_base.cc
|
| index 2957e966f525232551c74e9b240d277973ba9ff9..c724a7b5fe642016fbd90867bd5c88f403105ebf 100644
|
| --- a/media/audio/audio_manager_base.cc
|
| +++ b/media/audio/audio_manager_base.cc
|
| @@ -9,6 +9,8 @@
|
| #include "base/threading/thread.h"
|
| #include "media/audio/audio_output_dispatcher.h"
|
| #include "media/audio/audio_output_proxy.h"
|
| +#include "media/audio/fake_audio_input_stream.h"
|
| +#include "media/audio/fake_audio_output_stream.h"
|
|
|
| static const int kStreamCloseDelaySeconds = 5;
|
|
|
| @@ -16,11 +18,14 @@ const char AudioManagerBase::kDefaultDeviceName[] = "Default";
|
| const char AudioManagerBase::kDefaultDeviceId[] = "default";
|
|
|
| AudioManagerBase::AudioManagerBase()
|
| - : num_active_input_streams_(0) {
|
| + : num_active_input_streams_(0),
|
| + num_output_streams_(0) {
|
| }
|
|
|
| AudioManagerBase::~AudioManagerBase() {
|
| Shutdown();
|
| + // All the output streams should have been deleted.
|
| + DCHECK_EQ(0, num_output_streams_);
|
| }
|
|
|
| void AudioManagerBase::Init() {
|
| @@ -39,6 +44,48 @@ scoped_refptr<base::MessageLoopProxy> AudioManagerBase::GetMessageLoop() {
|
| return audio_thread_.get() ? audio_thread_->message_loop_proxy() : NULL;
|
| }
|
|
|
| +AudioOutputStream* AudioManagerBase::MakeAudioOutputStream(
|
| + const AudioParameters& params) {
|
| + if (!params.IsValid())
|
| + return NULL;
|
| +
|
| + // Limit the number of audio streams opened. This is to prevent using
|
| + // excessive resources for a large number of audio streams. More
|
| + // importantly it prevents instability on certain systems.
|
| + // See bug: http://crbug.com/30242.
|
| + if (num_output_streams_ >= GetMaxAudioOutputStreamsAllowed()) {
|
| + return NULL;
|
| + }
|
| +
|
| + if (params.format == AudioParameters::AUDIO_MOCK) {
|
| + return FakeAudioOutputStream::MakeFakeStream(params);
|
| + } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) {
|
| + num_output_streams_++;
|
| + return MakeAudioLinearOutputStream(params);
|
| + } else if (params.format == AudioParameters::AUDIO_PCM_LOW_LATENCY) {
|
| + num_output_streams_++;
|
| + return MakeAudioLowLatencyOutputStream(params);
|
| + }
|
| +
|
| + return NULL;
|
| +}
|
| +
|
| +AudioInputStream* AudioManagerBase::MakeAudioInputStream(
|
| + const AudioParameters& params, const std::string& device_id) {
|
| + if (!params.IsValid() || device_id.empty())
|
| + return NULL;
|
| +
|
| + if (params.format == AudioParameters::AUDIO_MOCK) {
|
| + return FakeAudioInputStream::MakeFakeStream(params);
|
| + } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) {
|
| + return MakeAudioLinearInputStream(params, device_id);
|
| + } else if (params.format == AudioParameters::AUDIO_PCM_LOW_LATENCY) {
|
| + return MakeAudioLowLatencyInputStream(params, device_id);
|
| + }
|
| +
|
| + return NULL;
|
| +}
|
| +
|
| AudioOutputStream* AudioManagerBase::MakeAudioOutputStreamProxy(
|
| const AudioParameters& params) {
|
| DCHECK(GetMessageLoop()->BelongsToCurrentThread());
|
| @@ -71,6 +118,17 @@ void AudioManagerBase::DecreaseActiveInputStreamCount() {
|
| base::AtomicRefCountDec(&num_active_input_streams_);
|
| }
|
|
|
| +void AudioManagerBase::ReleaseOutputStream(AudioOutputStream* stream) {
|
| + DCHECK(stream);
|
| + num_output_streams_--;
|
| + delete stream;
|
| +}
|
| +
|
| +void AudioManagerBase::ReleaseInputStream(AudioInputStream* stream) {
|
| + DCHECK(stream);
|
| + delete stream;
|
| +}
|
| +
|
| bool AudioManagerBase::IsRecordingInProcess() {
|
| return !base::AtomicRefCountIsZero(&num_active_input_streams_);
|
| }
|
|
|