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/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
| 9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
| 10 #include "media/audio/audio_output_dispatcher.h" | 10 #include "media/audio/audio_output_dispatcher.h" |
| 11 #include "media/audio/audio_output_proxy.h" | 11 #include "media/audio/audio_output_proxy.h" |
| 12 #include "media/audio/fake_audio_input_stream.h" | |
| 13 #include "media/audio/fake_audio_output_stream.h" | |
| 12 | 14 |
| 13 static const int kStreamCloseDelaySeconds = 5; | 15 static const int kStreamCloseDelaySeconds = 5; |
| 14 | 16 |
| 15 const char AudioManagerBase::kDefaultDeviceName[] = "Default"; | 17 const char AudioManagerBase::kDefaultDeviceName[] = "Default"; |
| 16 const char AudioManagerBase::kDefaultDeviceId[] = "default"; | 18 const char AudioManagerBase::kDefaultDeviceId[] = "default"; |
| 17 | 19 |
| 18 AudioManagerBase::AudioManagerBase() | 20 AudioManagerBase::AudioManagerBase() |
| 19 : num_active_input_streams_(0) { | 21 : num_active_input_streams_(0), |
| 22 num_output_streams_(0) { | |
| 20 } | 23 } |
| 21 | 24 |
| 22 AudioManagerBase::~AudioManagerBase() { | 25 AudioManagerBase::~AudioManagerBase() { |
| 23 Shutdown(); | 26 Shutdown(); |
| 27 // All the output streams should have been deleted. | |
| 28 DCHECK_EQ(0, num_output_streams_); | |
| 24 } | 29 } |
| 25 | 30 |
| 26 void AudioManagerBase::Init() { | 31 void AudioManagerBase::Init() { |
| 27 base::AutoLock lock(audio_thread_lock_); | 32 base::AutoLock lock(audio_thread_lock_); |
| 28 DCHECK(!audio_thread_.get()); | 33 DCHECK(!audio_thread_.get()); |
| 29 audio_thread_.reset(new base::Thread("AudioThread")); | 34 audio_thread_.reset(new base::Thread("AudioThread")); |
| 30 CHECK(audio_thread_->Start()); | 35 CHECK(audio_thread_->Start()); |
| 31 } | 36 } |
| 32 | 37 |
| 33 string16 AudioManagerBase::GetAudioInputDeviceModel() { | 38 string16 AudioManagerBase::GetAudioInputDeviceModel() { |
| 34 return string16(); | 39 return string16(); |
| 35 } | 40 } |
| 36 | 41 |
| 37 scoped_refptr<base::MessageLoopProxy> AudioManagerBase::GetMessageLoop() { | 42 scoped_refptr<base::MessageLoopProxy> AudioManagerBase::GetMessageLoop() { |
| 38 base::AutoLock lock(audio_thread_lock_); | 43 base::AutoLock lock(audio_thread_lock_); |
| 39 return audio_thread_.get() ? audio_thread_->message_loop_proxy() : NULL; | 44 return audio_thread_.get() ? audio_thread_->message_loop_proxy() : NULL; |
| 40 } | 45 } |
| 41 | 46 |
| 47 AudioOutputStream* AudioManagerBase::MakeAudioOutputStream( | |
| 48 const AudioParameters& params) { | |
| 49 if (!params.IsValid()) | |
| 50 return NULL; | |
|
tommi (sloooow) - chröme
2012/03/05 14:28:28
NOTREACHED?
no longer working on chromium
2012/03/06 15:27:07
We have some failed unittests which will try the i
| |
| 51 | |
| 52 // Limit the number of audio streams opened. This is to prevent using | |
| 53 // excessive resources for a large number of audio streams. More | |
| 54 // importantly it prevents instability on certain systems. | |
| 55 // See bug: http://crbug.com/30242. | |
| 56 if (num_output_streams_ >= GetMaxAudioOutputStreamsAllowed()) { | |
| 57 return NULL; | |
| 58 } | |
| 59 | |
| 60 AudioOutputStream* stream = NULL; | |
| 61 if (params.format == AudioParameters::AUDIO_MOCK) { | |
| 62 stream = FakeAudioOutputStream::MakeFakeStream(params); | |
|
tommi (sloooow) - chröme
2012/03/05 14:28:28
missing increment?
no longer working on chromium
2012/03/06 15:27:07
We do not need to limit the max number of the fake
| |
| 63 } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) { | |
| 64 num_output_streams_++; | |
|
tommi (sloooow) - chröme
2012/03/05 14:28:28
what about not incrementing inside every if/else a
no longer working on chromium
2012/03/06 15:27:07
it may not be a good idea since fake stream needs
| |
| 65 stream = MakeAudioLinearOutputStream(params); | |
| 66 } else if (params.format == AudioParameters::AUDIO_PCM_LOW_LATENCY) { | |
| 67 num_output_streams_++; | |
| 68 stream = MakeAudioLowLatencyOutputStream(params); | |
| 69 } | |
| 70 | |
| 71 return stream; | |
| 72 } | |
| 73 | |
| 74 AudioInputStream* AudioManagerBase::MakeAudioInputStream( | |
| 75 const AudioParameters& params, const std::string& device_id) { | |
| 76 if (!params.IsValid() || device_id.empty()) | |
| 77 return NULL; | |
|
tommi (sloooow) - chröme
2012/03/05 14:28:28
NOTREACHED?
no longer working on chromium
2012/03/06 15:27:07
The same here, added a DLOG instead.
| |
| 78 | |
| 79 AudioInputStream* stream = NULL; | |
| 80 if (params.format == AudioParameters::AUDIO_MOCK) { | |
| 81 stream = FakeAudioInputStream::MakeFakeStream(params); | |
| 82 } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) { | |
| 83 stream = MakeAudioLinearInputStream(params, device_id); | |
| 84 } else if (params.format == AudioParameters::AUDIO_PCM_LOW_LATENCY) { | |
| 85 stream = MakeAudioLowLatencyInputStream(params, device_id); | |
| 86 } | |
| 87 | |
| 88 return stream; | |
|
tommi (sloooow) - chröme
2012/03/05 14:28:28
just thinking out loud here...
we're not countin
no longer working on chromium
2012/03/06 15:27:07
These ActiveInputStreamCount APIs are added by spe
| |
| 89 } | |
| 90 | |
| 42 AudioOutputStream* AudioManagerBase::MakeAudioOutputStreamProxy( | 91 AudioOutputStream* AudioManagerBase::MakeAudioOutputStreamProxy( |
| 43 const AudioParameters& params) { | 92 const AudioParameters& params) { |
| 44 DCHECK(GetMessageLoop()->BelongsToCurrentThread()); | 93 DCHECK(GetMessageLoop()->BelongsToCurrentThread()); |
| 45 | 94 |
| 46 scoped_refptr<AudioOutputDispatcher>& dispatcher = | 95 scoped_refptr<AudioOutputDispatcher>& dispatcher = |
| 47 output_dispatchers_[params]; | 96 output_dispatchers_[params]; |
| 48 if (!dispatcher) | 97 if (!dispatcher) |
| 49 dispatcher = new AudioOutputDispatcher( | 98 dispatcher = new AudioOutputDispatcher( |
| 50 this, params, base::TimeDelta::FromSeconds(kStreamCloseDelaySeconds)); | 99 this, params, base::TimeDelta::FromSeconds(kStreamCloseDelaySeconds)); |
| 51 return new AudioOutputProxy(dispatcher); | 100 return new AudioOutputProxy(dispatcher); |
| 52 } | 101 } |
| 53 | 102 |
| 54 bool AudioManagerBase::CanShowAudioInputSettings() { | 103 bool AudioManagerBase::CanShowAudioInputSettings() { |
| 55 return false; | 104 return false; |
| 56 } | 105 } |
| 57 | 106 |
| 58 void AudioManagerBase::ShowAudioInputSettings() { | 107 void AudioManagerBase::ShowAudioInputSettings() { |
| 59 } | 108 } |
| 60 | 109 |
| 61 void AudioManagerBase::GetAudioInputDeviceNames( | 110 void AudioManagerBase::GetAudioInputDeviceNames( |
| 62 media::AudioDeviceNames* device_names) { | 111 media::AudioDeviceNames* device_names) { |
| 63 } | 112 } |
| 64 | 113 |
| 114 void AudioManagerBase::ReleaseOutputStream(AudioOutputStream* stream) { | |
| 115 DCHECK(stream); | |
| 116 num_output_streams_--; | |
| 117 delete stream; | |
| 118 } | |
| 119 | |
| 120 void AudioManagerBase::ReleaseInputStream(AudioInputStream* stream) { | |
| 121 DCHECK(stream); | |
| 122 delete stream; | |
| 123 } | |
| 124 | |
| 65 void AudioManagerBase::IncreaseActiveInputStreamCount() { | 125 void AudioManagerBase::IncreaseActiveInputStreamCount() { |
| 66 base::AtomicRefCountInc(&num_active_input_streams_); | 126 base::AtomicRefCountInc(&num_active_input_streams_); |
| 67 } | 127 } |
| 68 | 128 |
| 69 void AudioManagerBase::DecreaseActiveInputStreamCount() { | 129 void AudioManagerBase::DecreaseActiveInputStreamCount() { |
| 70 DCHECK(IsRecordingInProcess()); | 130 DCHECK(IsRecordingInProcess()); |
| 71 base::AtomicRefCountDec(&num_active_input_streams_); | 131 base::AtomicRefCountDec(&num_active_input_streams_); |
| 72 } | 132 } |
| 73 | 133 |
| 74 bool AudioManagerBase::IsRecordingInProcess() { | 134 bool AudioManagerBase::IsRecordingInProcess() { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 // both physical audio stream objects that belong to the dispatcher as | 174 // both physical audio stream objects that belong to the dispatcher as |
| 115 // well as the message loop of the audio thread that will soon go away. | 175 // well as the message loop of the audio thread that will soon go away. |
| 116 // So, better crash now than later. | 176 // So, better crash now than later. |
| 117 CHECK(dispatcher->HasOneRef()) << "AudioOutputProxies are still alive"; | 177 CHECK(dispatcher->HasOneRef()) << "AudioOutputProxies are still alive"; |
| 118 dispatcher = NULL; | 178 dispatcher = NULL; |
| 119 } | 179 } |
| 120 } | 180 } |
| 121 | 181 |
| 122 output_dispatchers_.clear(); | 182 output_dispatchers_.clear(); |
| 123 } | 183 } |
| OLD | NEW |