Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: media/audio/audio_input_controller.cc

Issue 462813004: Add UMA stats for silence AudioInputController. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changed to report 4 silence cases. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 SyncWriter* sync_writer, 56 SyncWriter* sync_writer,
57 UserInputMonitor* user_input_monitor) 57 UserInputMonitor* user_input_monitor)
58 : creator_task_runner_(base::MessageLoopProxy::current()), 58 : creator_task_runner_(base::MessageLoopProxy::current()),
59 handler_(handler), 59 handler_(handler),
60 stream_(NULL), 60 stream_(NULL),
61 data_is_active_(false), 61 data_is_active_(false),
62 state_(CLOSED), 62 state_(CLOSED),
63 sync_writer_(sync_writer), 63 sync_writer_(sync_writer),
64 max_volume_(0.0), 64 max_volume_(0.0),
65 user_input_monitor_(user_input_monitor), 65 user_input_monitor_(user_input_monitor),
66 #if defined(AUDIO_POWER_MONITORING)
67 silence_state_(SILENCE_STATE_NO_MEASUREMENT),
68 #endif
66 prev_key_down_count_(0) { 69 prev_key_down_count_(0) {
67 DCHECK(creator_task_runner_.get()); 70 DCHECK(creator_task_runner_.get());
68 } 71 }
69 72
70 AudioInputController::~AudioInputController() { 73 AudioInputController::~AudioInputController() {
71 DCHECK_EQ(state_, CLOSED); 74 DCHECK_EQ(state_, CLOSED);
72 } 75 }
73 76
74 // static 77 // static
75 scoped_refptr<AudioInputController> AudioInputController::Create( 78 scoped_refptr<AudioInputController> AudioInputController::Create(
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 199
197 #if defined(AUDIO_POWER_MONITORING) 200 #if defined(AUDIO_POWER_MONITORING)
198 // Create the audio (power) level meter given the provided audio parameters. 201 // 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 202 // An AudioBus is also needed to wrap the raw data buffer from the native
200 // layer to match AudioPowerMonitor::Scan(). 203 // layer to match AudioPowerMonitor::Scan().
201 // TODO(henrika): Remove use of extra AudioBus. See http://crbug.com/375155. 204 // TODO(henrika): Remove use of extra AudioBus. See http://crbug.com/375155.
202 audio_level_.reset(new media::AudioPowerMonitor( 205 audio_level_.reset(new media::AudioPowerMonitor(
203 params.sample_rate(), 206 params.sample_rate(),
204 TimeDelta::FromMilliseconds(kPowerMeasurementTimeConstantMilliseconds))); 207 TimeDelta::FromMilliseconds(kPowerMeasurementTimeConstantMilliseconds)));
205 audio_params_ = params; 208 audio_params_ = params;
209 silence_state_ = SILENCE_STATE_NO_MEASUREMENT;
206 #endif 210 #endif
207 211
208 // TODO(miu): See TODO at top of file. Until that's resolved, assume all 212 // TODO(miu): See TODO at top of file. Until that's resolved, assume all
209 // platform audio input requires the |no_data_timer_| be used to auto-detect 213 // platform audio input requires the |no_data_timer_| be used to auto-detect
210 // errors. In reality, probably only Windows needs to be treated as 214 // errors. In reality, probably only Windows needs to be treated as
211 // unreliable here. 215 // unreliable here.
212 DoCreateForStream(audio_manager->MakeAudioInputStream(params, device_id), 216 DoCreateForStream(audio_manager->MakeAudioInputStream(params, device_id),
213 true); 217 true);
214 } 218 }
215 219
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 304
301 DoStopCloseAndClearStream(); 305 DoStopCloseAndClearStream();
302 SetDataIsActive(false); 306 SetDataIsActive(false);
303 307
304 if (SharedMemoryAndSyncSocketMode()) 308 if (SharedMemoryAndSyncSocketMode())
305 sync_writer_->Close(); 309 sync_writer_->Close();
306 310
307 if (user_input_monitor_) 311 if (user_input_monitor_)
308 user_input_monitor_->DisableKeyPressMonitoring(); 312 user_input_monitor_->DisableKeyPressMonitoring();
309 313
314 #if defined(AUDIO_POWER_MONITORING)
315 // Send UMA stats if we have enabled power monitoring.
316 if (audio_level_) {
317 LogSilenceState(silence_state_);
318 }
319 #endif
320
310 state_ = CLOSED; 321 state_ = CLOSED;
311 } 322 }
312 323
313 void AudioInputController::DoReportError() { 324 void AudioInputController::DoReportError() {
314 DCHECK(task_runner_->BelongsToCurrentThread()); 325 DCHECK(task_runner_->BelongsToCurrentThread());
315 if (handler_) 326 if (handler_)
316 handler_->OnError(this, STREAM_ERROR); 327 handler_->OnError(this, STREAM_ERROR);
317 } 328 }
318 329
319 void AudioInputController::DoSetVolume(double volume) { 330 void AudioInputController::DoSetVolume(double volume) {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 478
468 void AudioInputController::DoLogAudioLevel(float level_dbfs) { 479 void AudioInputController::DoLogAudioLevel(float level_dbfs) {
469 #if defined(AUDIO_POWER_MONITORING) 480 #if defined(AUDIO_POWER_MONITORING)
470 DCHECK(task_runner_->BelongsToCurrentThread()); 481 DCHECK(task_runner_->BelongsToCurrentThread());
471 if (!handler_) 482 if (!handler_)
472 return; 483 return;
473 484
474 std::string log_string = base::StringPrintf( 485 std::string log_string = base::StringPrintf(
475 "AIC::OnData: average audio level=%.2f dBFS", level_dbfs); 486 "AIC::OnData: average audio level=%.2f dBFS", level_dbfs);
476 static const float kSilenceThresholdDBFS = -72.24719896f; 487 static const float kSilenceThresholdDBFS = -72.24719896f;
477 if (level_dbfs < kSilenceThresholdDBFS) 488 if (level_dbfs < kSilenceThresholdDBFS) {
478 log_string += " <=> no audio input!"; 489 log_string += " <=> no audio input!";
490 if (silence_state_ == SILENCE_STATE_NO_MEASUREMENT)
491 silence_state_ = SILENCE_STATE_ONLY_SILENCE;
492 else if (silence_state_ == SILENCE_STATE_NO_SILENCE)
tommi (sloooow) - chröme 2014/08/13 18:28:04 nit: I find "NO_SILENCE" to be a bit confusing whe
Henrik Grunell 2014/08/14 11:21:45 I changed it to ONLY_AUDIO. And the PARTIAL_SILENC
493 silence_state_ = SILENCE_STATE_PARTIAL_SILENCE;
tommi (sloooow) - chröme 2014/08/13 18:28:04 nit: else DCHECK_EQ(silence_state_, SILENCE_STAT
Henrik Grunell 2014/08/14 11:21:45 Well it can be that or ONLY_SILENCE. Done.
494 } else {
495 if (silence_state_ == SILENCE_STATE_NO_MEASUREMENT)
496 silence_state_ = SILENCE_STATE_NO_SILENCE;
497 else if (silence_state_ == SILENCE_STATE_ONLY_SILENCE)
498 silence_state_ = SILENCE_STATE_PARTIAL_SILENCE;
tommi (sloooow) - chröme 2014/08/13 18:28:04 nit: same else case here. good for sanity checkin
Henrik Grunell 2014/08/14 11:21:45 Done.
499 }
479 500
480 handler_->OnLog(this, log_string); 501 handler_->OnLog(this, log_string);
481 #endif 502 #endif
482 } 503 }
483 504
484 void AudioInputController::OnError(AudioInputStream* stream) { 505 void AudioInputController::OnError(AudioInputStream* stream) {
485 // Handle error on the audio-manager thread. 506 // Handle error on the audio-manager thread.
486 task_runner_->PostTask(FROM_HERE, base::Bind( 507 task_runner_->PostTask(FROM_HERE, base::Bind(
487 &AudioInputController::DoReportError, this)); 508 &AudioInputController::DoReportError, this));
488 } 509 }
(...skipping 13 matching lines...) Expand all
502 } 523 }
503 524
504 void AudioInputController::SetDataIsActive(bool enabled) { 525 void AudioInputController::SetDataIsActive(bool enabled) {
505 base::subtle::Release_Store(&data_is_active_, enabled); 526 base::subtle::Release_Store(&data_is_active_, enabled);
506 } 527 }
507 528
508 bool AudioInputController::GetDataIsActive() { 529 bool AudioInputController::GetDataIsActive() {
509 return (base::subtle::Acquire_Load(&data_is_active_) != false); 530 return (base::subtle::Acquire_Load(&data_is_active_) != false);
510 } 531 }
511 532
533 #if defined(AUDIO_POWER_MONITORING)
534 void AudioInputController::LogSilenceState(SilenceState value) {
535 UMA_HISTOGRAM_ENUMERATION("Media.AudioInputControllerSessionSilenceReport",
536 value,
537 SILENCE_STATE_MAX + 1);
538 }
539 #endif
540
512 } // namespace media 541 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698