| 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/macros.h" | 10 #include "base/macros.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // All the input streams should have been deleted. | 98 // All the input streams should have been deleted. |
| 99 CHECK_EQ(0, num_input_streams_); | 99 CHECK_EQ(0, num_input_streams_); |
| 100 } | 100 } |
| 101 | 101 |
| 102 base::string16 AudioManagerBase::GetAudioInputDeviceModel() { | 102 base::string16 AudioManagerBase::GetAudioInputDeviceModel() { |
| 103 return base::string16(); | 103 return base::string16(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 AudioOutputStream* AudioManagerBase::MakeAudioOutputStream( | 106 AudioOutputStream* AudioManagerBase::MakeAudioOutputStream( |
| 107 const AudioParameters& params, | 107 const AudioParameters& params, |
| 108 const std::string& device_id) { | 108 const std::string& device_id, |
| 109 const LogCallback& log_callback) { |
| 109 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 110 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 110 | 111 |
| 111 if (!params.IsValid()) { | 112 if (!params.IsValid()) { |
| 112 DLOG(ERROR) << "Audio parameters are invalid"; | 113 DLOG(ERROR) << "Audio parameters are invalid"; |
| 113 return NULL; | 114 return NULL; |
| 114 } | 115 } |
| 115 | 116 |
| 116 // Limit the number of audio streams opened. This is to prevent using | 117 // Limit the number of audio streams opened. This is to prevent using |
| 117 // excessive resources for a large number of audio streams. More | 118 // excessive resources for a large number of audio streams. More |
| 118 // importantly it prevents instability on certain systems. | 119 // importantly it prevents instability on certain systems. |
| 119 // See bug: http://crbug.com/30242. | 120 // See bug: http://crbug.com/30242. |
| 120 if (num_output_streams_ >= max_num_output_streams_) { | 121 if (num_output_streams_ >= max_num_output_streams_) { |
| 121 DLOG(ERROR) << "Number of opened output audio streams " | 122 DLOG(ERROR) << "Number of opened output audio streams " |
| 122 << num_output_streams_ | 123 << num_output_streams_ |
| 123 << " exceed the max allowed number " | 124 << " exceed the max allowed number " |
| 124 << max_num_output_streams_; | 125 << max_num_output_streams_; |
| 125 return NULL; | 126 return NULL; |
| 126 } | 127 } |
| 127 | 128 |
| 128 AudioOutputStream* stream; | 129 AudioOutputStream* stream; |
| 129 switch (params.format()) { | 130 switch (params.format()) { |
| 130 case AudioParameters::AUDIO_PCM_LINEAR: | 131 case AudioParameters::AUDIO_PCM_LINEAR: |
| 131 DCHECK(AudioDeviceDescription::IsDefaultDevice(device_id)) | 132 DCHECK(AudioDeviceDescription::IsDefaultDevice(device_id)) |
| 132 << "AUDIO_PCM_LINEAR supports only the default device."; | 133 << "AUDIO_PCM_LINEAR supports only the default device."; |
| 133 stream = MakeLinearOutputStream(params); | 134 stream = MakeLinearOutputStream(params, log_callback); |
| 134 break; | 135 break; |
| 135 case AudioParameters::AUDIO_PCM_LOW_LATENCY: | 136 case AudioParameters::AUDIO_PCM_LOW_LATENCY: |
| 136 stream = MakeLowLatencyOutputStream(params, device_id); | 137 stream = MakeLowLatencyOutputStream(params, device_id, log_callback); |
| 137 break; | 138 break; |
| 138 case AudioParameters::AUDIO_FAKE: | 139 case AudioParameters::AUDIO_FAKE: |
| 139 stream = FakeAudioOutputStream::MakeFakeStream(this, params); | 140 stream = FakeAudioOutputStream::MakeFakeStream(this, params); |
| 140 break; | 141 break; |
| 141 default: | 142 default: |
| 142 stream = NULL; | 143 stream = NULL; |
| 143 break; | 144 break; |
| 144 } | 145 } |
| 145 | 146 |
| 146 if (stream) { | 147 if (stream) { |
| 147 ++num_output_streams_; | 148 ++num_output_streams_; |
| 148 } | 149 } |
| 149 | 150 |
| 150 return stream; | 151 return stream; |
| 151 } | 152 } |
| 152 | 153 |
| 153 AudioInputStream* AudioManagerBase::MakeAudioInputStream( | 154 AudioInputStream* AudioManagerBase::MakeAudioInputStream( |
| 154 const AudioParameters& params, | 155 const AudioParameters& params, |
| 155 const std::string& device_id) { | 156 const std::string& device_id, |
| 157 const LogCallback& log_callback) { |
| 156 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 158 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 157 | 159 |
| 158 if (!params.IsValid() || (params.channels() > kMaxInputChannels) || | 160 if (!params.IsValid() || (params.channels() > kMaxInputChannels) || |
| 159 device_id.empty()) { | 161 device_id.empty()) { |
| 160 DLOG(ERROR) << "Audio parameters are invalid for device " << device_id; | 162 DLOG(ERROR) << "Audio parameters are invalid for device " << device_id; |
| 161 return NULL; | 163 return NULL; |
| 162 } | 164 } |
| 163 | 165 |
| 164 if (num_input_streams_ >= max_num_input_streams_) { | 166 if (num_input_streams_ >= max_num_input_streams_) { |
| 165 DLOG(ERROR) << "Number of opened input audio streams " | 167 DLOG(ERROR) << "Number of opened input audio streams " |
| 166 << num_input_streams_ | 168 << num_input_streams_ |
| 167 << " exceed the max allowed number " << max_num_input_streams_; | 169 << " exceed the max allowed number " << max_num_input_streams_; |
| 168 return NULL; | 170 return NULL; |
| 169 } | 171 } |
| 170 | 172 |
| 171 DVLOG(2) << "Creating a new AudioInputStream with buffer size = " | 173 DVLOG(2) << "Creating a new AudioInputStream with buffer size = " |
| 172 << params.frames_per_buffer(); | 174 << params.frames_per_buffer(); |
| 173 | 175 |
| 174 AudioInputStream* stream; | 176 AudioInputStream* stream; |
| 175 switch (params.format()) { | 177 switch (params.format()) { |
| 176 case AudioParameters::AUDIO_PCM_LINEAR: | 178 case AudioParameters::AUDIO_PCM_LINEAR: |
| 177 stream = MakeLinearInputStream(params, device_id); | 179 stream = MakeLinearInputStream(params, device_id, log_callback); |
| 178 break; | 180 break; |
| 179 case AudioParameters::AUDIO_PCM_LOW_LATENCY: | 181 case AudioParameters::AUDIO_PCM_LOW_LATENCY: |
| 180 stream = MakeLowLatencyInputStream(params, device_id); | 182 stream = MakeLowLatencyInputStream(params, device_id, log_callback); |
| 181 break; | 183 break; |
| 182 case AudioParameters::AUDIO_FAKE: | 184 case AudioParameters::AUDIO_FAKE: |
| 183 stream = FakeAudioInputStream::MakeFakeStream(this, params); | 185 stream = FakeAudioInputStream::MakeFakeStream(this, params); |
| 184 break; | 186 break; |
| 185 default: | 187 default: |
| 186 stream = NULL; | 188 stream = NULL; |
| 187 break; | 189 break; |
| 188 } | 190 } |
| 189 | 191 |
| 190 if (stream) { | 192 if (stream) { |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 | 359 |
| 358 return 0; | 360 return 0; |
| 359 } | 361 } |
| 360 | 362 |
| 361 std::unique_ptr<AudioLog> AudioManagerBase::CreateAudioLog( | 363 std::unique_ptr<AudioLog> AudioManagerBase::CreateAudioLog( |
| 362 AudioLogFactory::AudioComponent component) { | 364 AudioLogFactory::AudioComponent component) { |
| 363 return audio_log_factory_->CreateAudioLog(component); | 365 return audio_log_factory_->CreateAudioLog(component); |
| 364 } | 366 } |
| 365 | 367 |
| 366 } // namespace media | 368 } // namespace media |
| OLD | NEW |