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/threading/thread_restrictions.h" | 8 #include "base/threading/thread_restrictions.h" |
9 #include "media/base/limits.h" | 9 #include "media/base/limits.h" |
| 10 #include "media/base/scoped_histogram_timer.h" |
10 | 11 |
11 namespace { | 12 namespace { |
12 const int kMaxInputChannels = 2; | 13 const int kMaxInputChannels = 2; |
13 | 14 |
14 // TODO(henrika): remove usage of timers and add support for proper | 15 // TODO(henrika): remove usage of timers and add support for proper |
15 // notification of when the input device is removed. This was originally added | 16 // notification of when the input device is removed. This was originally added |
16 // to resolve http://crbug.com/79936 for Windows platforms. This then caused | 17 // to resolve http://crbug.com/79936 for Windows platforms. This then caused |
17 // breakage (very hard to repro bugs!) on other platforms: See | 18 // breakage (very hard to repro bugs!) on other platforms: See |
18 // http://crbug.com/226327 and http://crbug.com/230972. | 19 // http://crbug.com/226327 and http://crbug.com/230972. |
19 const int kTimerResetIntervalSeconds = 1; | 20 const int kTimerResetIntervalSeconds = 1; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 | 162 |
162 void AudioInputController::SetAutomaticGainControl(bool enabled) { | 163 void AudioInputController::SetAutomaticGainControl(bool enabled) { |
163 message_loop_->PostTask(FROM_HERE, base::Bind( | 164 message_loop_->PostTask(FROM_HERE, base::Bind( |
164 &AudioInputController::DoSetAutomaticGainControl, this, enabled)); | 165 &AudioInputController::DoSetAutomaticGainControl, this, enabled)); |
165 } | 166 } |
166 | 167 |
167 void AudioInputController::DoCreate(AudioManager* audio_manager, | 168 void AudioInputController::DoCreate(AudioManager* audio_manager, |
168 const AudioParameters& params, | 169 const AudioParameters& params, |
169 const std::string& device_id) { | 170 const std::string& device_id) { |
170 DCHECK(message_loop_->BelongsToCurrentThread()); | 171 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 172 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioInputController.CreateTime"); |
171 // TODO(miu): See TODO at top of file. Until that's resolved, assume all | 173 // TODO(miu): See TODO at top of file. Until that's resolved, assume all |
172 // platform audio input requires the |no_data_timer_| be used to auto-detect | 174 // platform audio input requires the |no_data_timer_| be used to auto-detect |
173 // errors. In reality, probably only Windows and IOS need to be treated as | 175 // errors. In reality, probably only Windows and IOS need to be treated as |
174 // unreliable here. | 176 // unreliable here. |
175 DoCreateForStream(audio_manager->MakeAudioInputStream(params, device_id), | 177 DoCreateForStream(audio_manager->MakeAudioInputStream(params, device_id), |
176 true); | 178 true); |
177 } | 179 } |
178 | 180 |
179 void AudioInputController::DoCreateForStream( | 181 void AudioInputController::DoCreateForStream( |
180 AudioInputStream* stream_to_control, bool enable_nodata_timer) { | 182 AudioInputStream* stream_to_control, bool enable_nodata_timer) { |
(...skipping 26 matching lines...) Expand all Loading... |
207 } else { | 209 } else { |
208 DVLOG(1) << "Disabled: timer check for no data."; | 210 DVLOG(1) << "Disabled: timer check for no data."; |
209 } | 211 } |
210 | 212 |
211 state_ = kCreated; | 213 state_ = kCreated; |
212 handler_->OnCreated(this); | 214 handler_->OnCreated(this); |
213 } | 215 } |
214 | 216 |
215 void AudioInputController::DoRecord() { | 217 void AudioInputController::DoRecord() { |
216 DCHECK(message_loop_->BelongsToCurrentThread()); | 218 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 219 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioInputController.RecordTime"); |
217 | 220 |
218 if (state_ != kCreated) | 221 if (state_ != kCreated) |
219 return; | 222 return; |
220 | 223 |
221 { | 224 { |
222 base::AutoLock auto_lock(lock_); | 225 base::AutoLock auto_lock(lock_); |
223 state_ = kRecording; | 226 state_ = kRecording; |
224 } | 227 } |
225 | 228 |
226 if (no_data_timer_) { | 229 if (no_data_timer_) { |
227 // Start the data timer. Once |kTimerResetIntervalSeconds| have passed, | 230 // Start the data timer. Once |kTimerResetIntervalSeconds| have passed, |
228 // a callback to DoCheckForNoData() is made. | 231 // a callback to DoCheckForNoData() is made. |
229 no_data_timer_->Reset(); | 232 no_data_timer_->Reset(); |
230 } | 233 } |
231 | 234 |
232 stream_->Start(this); | 235 stream_->Start(this); |
233 handler_->OnRecording(this); | 236 handler_->OnRecording(this); |
234 } | 237 } |
235 | 238 |
236 void AudioInputController::DoClose() { | 239 void AudioInputController::DoClose() { |
237 DCHECK(message_loop_->BelongsToCurrentThread()); | 240 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 241 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioInputController.CloseTime"); |
238 | 242 |
239 // Delete the timer on the same thread that created it. | 243 // Delete the timer on the same thread that created it. |
240 no_data_timer_.reset(); | 244 no_data_timer_.reset(); |
241 | 245 |
242 if (state_ != kClosed) { | 246 if (state_ != kClosed) { |
243 DoStopCloseAndClearStream(NULL); | 247 DoStopCloseAndClearStream(NULL); |
244 SetDataIsActive(false); | 248 SetDataIsActive(false); |
245 | 249 |
246 if (LowLatencyMode()) { | 250 if (LowLatencyMode()) { |
247 sync_writer_->Close(); | 251 sync_writer_->Close(); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 | 372 |
369 void AudioInputController::SetDataIsActive(bool enabled) { | 373 void AudioInputController::SetDataIsActive(bool enabled) { |
370 base::subtle::Release_Store(&data_is_active_, enabled); | 374 base::subtle::Release_Store(&data_is_active_, enabled); |
371 } | 375 } |
372 | 376 |
373 bool AudioInputController::GetDataIsActive() { | 377 bool AudioInputController::GetDataIsActive() { |
374 return (base::subtle::Acquire_Load(&data_is_active_) != false); | 378 return (base::subtle::Acquire_Load(&data_is_active_) != false); |
375 } | 379 } |
376 | 380 |
377 } // namespace media | 381 } // namespace media |
OLD | NEW |