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 2957e966f525232551c74e9b240d277973ba9ff9..4df43346ae3208213f320d5abf514140dcfb5af7 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,54 @@ 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()) { |
| + DLOG(ERROR) << "Audio parameters are invalid"; |
| + 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_ >= GetMaxOutputStreamsAllowed()) { |
| + return NULL; |
| + } |
| + |
| + AudioOutputStream* stream = NULL; |
| + if (params.format == AudioParameters::AUDIO_MOCK) { |
| + stream = FakeAudioOutputStream::MakeFakeStream(params); |
| + } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) { |
| + num_output_streams_++; |
| + stream = MakeLinearOutputStream(params); |
| + } else if (params.format == AudioParameters::AUDIO_PCM_LOW_LATENCY) { |
| + num_output_streams_++; |
| + stream = MakeLowLatencyOutputStream(params); |
| + } |
| + |
| + return stream; |
| +} |
| + |
| +AudioInputStream* AudioManagerBase::MakeAudioInputStream( |
| + const AudioParameters& params, const std::string& device_id) { |
| + if (!params.IsValid() || device_id.empty()) { |
| + DLOG(ERROR) << "Audio parameters are invalid for device " << device_id; |
| + return NULL; |
| + } |
| + |
| + AudioInputStream* stream = NULL; |
| + if (params.format == AudioParameters::AUDIO_MOCK) { |
| + stream = FakeAudioInputStream::MakeFakeStream(params); |
| + } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) { |
| + stream = MakeLinearInputStream(params, device_id); |
| + } else if (params.format == AudioParameters::AUDIO_PCM_LOW_LATENCY) { |
| + stream = MakeLowLatencyInputStream(params, device_id); |
| + } |
| + |
| + return stream; |
| +} |
| + |
| AudioOutputStream* AudioManagerBase::MakeAudioOutputStreamProxy( |
| const AudioParameters& params) { |
| DCHECK(GetMessageLoop()->BelongsToCurrentThread()); |
| @@ -62,6 +115,17 @@ void AudioManagerBase::GetAudioInputDeviceNames( |
| media::AudioDeviceNames* device_names) { |
| } |
| +void AudioManagerBase::ReleaseOutputStream(AudioOutputStream* stream) { |
| + DCHECK(stream); |
|
tommi (sloooow) - chröme
2012/03/06 16:16:04
Can you add
DCHECK(GetMessageLoop()->BelongsToCurr
no longer working on chromium
2012/03/06 17:38:41
Doing this will break quite some unittests, since
|
| + num_output_streams_--; |
| + delete stream; |
| +} |
| + |
| +void AudioManagerBase::ReleaseInputStream(AudioInputStream* stream) { |
| + DCHECK(stream); |
|
tommi (sloooow) - chröme
2012/03/06 16:16:04
DCHECK(GetMessageLoop()->BelongsToCurrentThread())
no longer working on chromium
2012/03/06 17:38:41
same question.
|
| + delete stream; |
| +} |
| + |
| void AudioManagerBase::IncreaseActiveInputStreamCount() { |
| base::AtomicRefCountInc(&num_active_input_streams_); |
| } |