| 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_input_controller.h" | 5 #include "media/audio/audio_input_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 scoped_refptr<AudioInputController> AudioInputController::CreateLowLatency( | 107 scoped_refptr<AudioInputController> AudioInputController::CreateLowLatency( |
| 108 AudioManager* audio_manager, | 108 AudioManager* audio_manager, |
| 109 EventHandler* event_handler, | 109 EventHandler* event_handler, |
| 110 const AudioParameters& params, | 110 const AudioParameters& params, |
| 111 const std::string& device_id, | 111 const std::string& device_id, |
| 112 SyncWriter* sync_writer, | 112 SyncWriter* sync_writer, |
| 113 UserInputMonitor* user_input_monitor) { | 113 UserInputMonitor* user_input_monitor) { |
| 114 DCHECK(audio_manager); | 114 DCHECK(audio_manager); |
| 115 DCHECK(sync_writer); | 115 DCHECK(sync_writer); |
| 116 | 116 |
| 117 if (!params.IsValid() || (params.channels() > kMaxInputChannels)) | 117 if (!params.IsValid()) { |
| 118 NOTREACHED(); |
| 118 return NULL; | 119 return NULL; |
| 120 } |
| 121 |
| 122 if ((params.channels() > kMaxInputChannels)) { |
| 123 NOTREACHED() << params.channels(); |
| 124 return NULL; |
| 125 } |
| 119 | 126 |
| 120 // Create the AudioInputController object and ensure that it runs on | 127 // Create the AudioInputController object and ensure that it runs on |
| 121 // the audio-manager thread. | 128 // the audio-manager thread. |
| 122 scoped_refptr<AudioInputController> controller( | 129 scoped_refptr<AudioInputController> controller( |
| 123 new AudioInputController(event_handler, sync_writer, user_input_monitor)); | 130 new AudioInputController(event_handler, sync_writer, user_input_monitor)); |
| 124 controller->task_runner_ = audio_manager->GetTaskRunner(); | 131 controller->task_runner_ = audio_manager->GetTaskRunner(); |
| 125 | 132 |
| 126 // Create and open a new audio input stream from the existing | 133 // Create and open a new audio input stream from the existing |
| 127 // audio-device thread. Use the provided audio-input device. | 134 // audio-device thread. Use the provided audio-input device. |
| 128 if (!controller->task_runner_->PostTask(FROM_HERE, | 135 if (!controller->task_runner_->PostTask(FROM_HERE, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 } | 191 } |
| 185 | 192 |
| 186 void AudioInputController::SetAutomaticGainControl(bool enabled) { | 193 void AudioInputController::SetAutomaticGainControl(bool enabled) { |
| 187 task_runner_->PostTask(FROM_HERE, base::Bind( | 194 task_runner_->PostTask(FROM_HERE, base::Bind( |
| 188 &AudioInputController::DoSetAutomaticGainControl, this, enabled)); | 195 &AudioInputController::DoSetAutomaticGainControl, this, enabled)); |
| 189 } | 196 } |
| 190 | 197 |
| 191 void AudioInputController::DoCreate(AudioManager* audio_manager, | 198 void AudioInputController::DoCreate(AudioManager* audio_manager, |
| 192 const AudioParameters& params, | 199 const AudioParameters& params, |
| 193 const std::string& device_id) { | 200 const std::string& device_id) { |
| 201 // NOTREACHED(); |
| 194 DCHECK(task_runner_->BelongsToCurrentThread()); | 202 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 195 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioInputController.CreateTime"); | 203 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioInputController.CreateTime"); |
| 196 | 204 |
| 197 #if defined(AUDIO_POWER_MONITORING) | 205 #if defined(AUDIO_POWER_MONITORING) |
| 198 // Create the audio (power) level meter given the provided audio parameters. | 206 // Create the audio (power) level meter given the provided audio parameters. |
| 199 // An AudioBus is also needed to wrap the raw data buffer from the native | 207 // An AudioBus is also needed to wrap the raw data buffer from the native |
| 200 // layer to match AudioPowerMonitor::Scan(). | 208 // layer to match AudioPowerMonitor::Scan(). |
| 201 // TODO(henrika): Remove use of extra AudioBus. See http://crbug.com/375155. | 209 // TODO(henrika): Remove use of extra AudioBus. See http://crbug.com/375155. |
| 202 audio_level_.reset(new media::AudioPowerMonitor( | 210 audio_level_.reset(new media::AudioPowerMonitor( |
| 203 params.sample_rate(), | 211 params.sample_rate(), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 214 } | 222 } |
| 215 | 223 |
| 216 void AudioInputController::DoCreateForStream( | 224 void AudioInputController::DoCreateForStream( |
| 217 AudioInputStream* stream_to_control, bool enable_nodata_timer) { | 225 AudioInputStream* stream_to_control, bool enable_nodata_timer) { |
| 218 DCHECK(task_runner_->BelongsToCurrentThread()); | 226 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 219 | 227 |
| 220 DCHECK(!stream_); | 228 DCHECK(!stream_); |
| 221 stream_ = stream_to_control; | 229 stream_ = stream_to_control; |
| 222 | 230 |
| 223 if (!stream_) { | 231 if (!stream_) { |
| 232 LOG(ERROR) << "***** NO VALID STREAM OBJECT"; |
| 224 if (handler_) | 233 if (handler_) |
| 225 handler_->OnError(this, STREAM_CREATE_ERROR); | 234 handler_->OnError(this, STREAM_CREATE_ERROR); |
| 226 return; | 235 return; |
| 227 } | 236 } |
| 228 | 237 |
| 229 if (stream_ && !stream_->Open()) { | 238 if (stream_ && !stream_->Open()) { |
| 230 stream_->Close(); | 239 stream_->Close(); |
| 231 stream_ = NULL; | 240 stream_ = NULL; |
| 241 LOG(ERROR) << "***** CAN't OPEN STREAM"; |
| 232 if (handler_) | 242 if (handler_) |
| 233 handler_->OnError(this, STREAM_OPEN_ERROR); | 243 handler_->OnError(this, STREAM_OPEN_ERROR); |
| 234 return; | 244 return; |
| 235 } | 245 } |
| 236 | 246 |
| 237 DCHECK(!no_data_timer_.get()); | 247 DCHECK(!no_data_timer_.get()); |
| 238 | 248 |
| 239 // The timer is enabled for logging purposes. The NO_DATA_ERROR triggered | 249 // The timer is enabled for logging purposes. The NO_DATA_ERROR triggered |
| 240 // from the timer must be ignored by the EventHandler. | 250 // from the timer must be ignored by the EventHandler. |
| 241 // TODO(henrika): remove usage of timer when it has been verified on Canary | 251 // TODO(henrika): remove usage of timer when it has been verified on Canary |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 | 513 |
| 504 void AudioInputController::SetDataIsActive(bool enabled) { | 514 void AudioInputController::SetDataIsActive(bool enabled) { |
| 505 base::subtle::Release_Store(&data_is_active_, enabled); | 515 base::subtle::Release_Store(&data_is_active_, enabled); |
| 506 } | 516 } |
| 507 | 517 |
| 508 bool AudioInputController::GetDataIsActive() { | 518 bool AudioInputController::GetDataIsActive() { |
| 509 return (base::subtle::Acquire_Load(&data_is_active_) != false); | 519 return (base::subtle::Acquire_Load(&data_is_active_) != false); |
| 510 } | 520 } |
| 511 | 521 |
| 512 } // namespace media | 522 } // namespace media |
| OLD | NEW |