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

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: Code review + rebase. 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
« no previous file with comments | « media/audio/audio_input_controller.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 SyncWriter* sync_writer, 77 SyncWriter* sync_writer,
78 UserInputMonitor* user_input_monitor) 78 UserInputMonitor* user_input_monitor)
79 : creator_task_runner_(base::MessageLoopProxy::current()), 79 : creator_task_runner_(base::MessageLoopProxy::current()),
80 handler_(handler), 80 handler_(handler),
81 stream_(NULL), 81 stream_(NULL),
82 data_is_active_(false), 82 data_is_active_(false),
83 state_(CLOSED), 83 state_(CLOSED),
84 sync_writer_(sync_writer), 84 sync_writer_(sync_writer),
85 max_volume_(0.0), 85 max_volume_(0.0),
86 user_input_monitor_(user_input_monitor), 86 user_input_monitor_(user_input_monitor),
87 #if defined(AUDIO_POWER_MONITORING)
88 silence_state_(SILENCE_STATE_NO_MEASUREMENT),
89 #endif
87 prev_key_down_count_(0) { 90 prev_key_down_count_(0) {
88 DCHECK(creator_task_runner_.get()); 91 DCHECK(creator_task_runner_.get());
89 } 92 }
90 93
91 AudioInputController::~AudioInputController() { 94 AudioInputController::~AudioInputController() {
92 DCHECK_EQ(state_, CLOSED); 95 DCHECK_EQ(state_, CLOSED);
93 } 96 }
94 97
95 // static 98 // static
96 scoped_refptr<AudioInputController> AudioInputController::Create( 99 scoped_refptr<AudioInputController> AudioInputController::Create(
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 221
219 #if defined(AUDIO_POWER_MONITORING) 222 #if defined(AUDIO_POWER_MONITORING)
220 // Create the audio (power) level meter given the provided audio parameters. 223 // Create the audio (power) level meter given the provided audio parameters.
221 // An AudioBus is also needed to wrap the raw data buffer from the native 224 // An AudioBus is also needed to wrap the raw data buffer from the native
222 // layer to match AudioPowerMonitor::Scan(). 225 // layer to match AudioPowerMonitor::Scan().
223 // TODO(henrika): Remove use of extra AudioBus. See http://crbug.com/375155. 226 // TODO(henrika): Remove use of extra AudioBus. See http://crbug.com/375155.
224 audio_level_.reset(new media::AudioPowerMonitor( 227 audio_level_.reset(new media::AudioPowerMonitor(
225 params.sample_rate(), 228 params.sample_rate(),
226 TimeDelta::FromMilliseconds(kPowerMeasurementTimeConstantMilliseconds))); 229 TimeDelta::FromMilliseconds(kPowerMeasurementTimeConstantMilliseconds)));
227 audio_params_ = params; 230 audio_params_ = params;
231 silence_state_ = SILENCE_STATE_NO_MEASUREMENT;
228 #endif 232 #endif
229 233
230 // TODO(miu): See TODO at top of file. Until that's resolved, assume all 234 // TODO(miu): See TODO at top of file. Until that's resolved, assume all
231 // platform audio input requires the |no_data_timer_| be used to auto-detect 235 // platform audio input requires the |no_data_timer_| be used to auto-detect
232 // errors. In reality, probably only Windows needs to be treated as 236 // errors. In reality, probably only Windows needs to be treated as
233 // unreliable here. 237 // unreliable here.
234 DoCreateForStream(audio_manager->MakeAudioInputStream(params, device_id)); 238 DoCreateForStream(audio_manager->MakeAudioInputStream(params, device_id));
235 } 239 }
236 240
237 void AudioInputController::DoCreateForStream( 241 void AudioInputController::DoCreateForStream(
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 321
318 DoStopCloseAndClearStream(); 322 DoStopCloseAndClearStream();
319 SetDataIsActive(false); 323 SetDataIsActive(false);
320 324
321 if (SharedMemoryAndSyncSocketMode()) 325 if (SharedMemoryAndSyncSocketMode())
322 sync_writer_->Close(); 326 sync_writer_->Close();
323 327
324 if (user_input_monitor_) 328 if (user_input_monitor_)
325 user_input_monitor_->DisableKeyPressMonitoring(); 329 user_input_monitor_->DisableKeyPressMonitoring();
326 330
331 #if defined(AUDIO_POWER_MONITORING)
332 // Send UMA stats if we have enabled power monitoring.
333 if (audio_level_) {
334 LogSilenceState(silence_state_);
335 }
336 #endif
337
327 state_ = CLOSED; 338 state_ = CLOSED;
328 } 339 }
329 340
330 void AudioInputController::DoReportError() { 341 void AudioInputController::DoReportError() {
331 DCHECK(task_runner_->BelongsToCurrentThread()); 342 DCHECK(task_runner_->BelongsToCurrentThread());
332 if (handler_) 343 if (handler_)
333 handler_->OnError(this, STREAM_ERROR); 344 handler_->OnError(this, STREAM_ERROR);
334 } 345 }
335 346
336 void AudioInputController::DoSetVolume(double volume) { 347 void AudioInputController::DoSetVolume(double volume) {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 496
486 void AudioInputController::DoLogAudioLevel(float level_dbfs) { 497 void AudioInputController::DoLogAudioLevel(float level_dbfs) {
487 #if defined(AUDIO_POWER_MONITORING) 498 #if defined(AUDIO_POWER_MONITORING)
488 DCHECK(task_runner_->BelongsToCurrentThread()); 499 DCHECK(task_runner_->BelongsToCurrentThread());
489 if (!handler_) 500 if (!handler_)
490 return; 501 return;
491 502
492 std::string log_string = base::StringPrintf( 503 std::string log_string = base::StringPrintf(
493 "AIC::OnData: average audio level=%.2f dBFS", level_dbfs); 504 "AIC::OnData: average audio level=%.2f dBFS", level_dbfs);
494 static const float kSilenceThresholdDBFS = -72.24719896f; 505 static const float kSilenceThresholdDBFS = -72.24719896f;
495 if (level_dbfs < kSilenceThresholdDBFS) 506 if (level_dbfs < kSilenceThresholdDBFS) {
496 log_string += " <=> no audio input!"; 507 log_string += " <=> no audio input!";
508 if (silence_state_ == SILENCE_STATE_NO_MEASUREMENT)
509 silence_state_ = SILENCE_STATE_ONLY_SILENCE;
510 else if (silence_state_ == SILENCE_STATE_ONLY_AUDIO)
511 silence_state_ = SILENCE_STATE_AUDIO_AND_SILENCE;
512 else
513 DCHECK(silence_state_ == SILENCE_STATE_ONLY_SILENCE ||
514 silence_state_ == SILENCE_STATE_AUDIO_AND_SILENCE);
515 } else {
516 if (silence_state_ == SILENCE_STATE_NO_MEASUREMENT)
517 silence_state_ = SILENCE_STATE_ONLY_AUDIO;
518 else if (silence_state_ == SILENCE_STATE_ONLY_SILENCE)
519 silence_state_ = SILENCE_STATE_AUDIO_AND_SILENCE;
520 else
521 DCHECK(silence_state_ == SILENCE_STATE_ONLY_AUDIO ||
522 silence_state_ == SILENCE_STATE_AUDIO_AND_SILENCE);
523 }
497 524
498 handler_->OnLog(this, log_string); 525 handler_->OnLog(this, log_string);
499 #endif 526 #endif
500 } 527 }
501 528
502 void AudioInputController::OnError(AudioInputStream* stream) { 529 void AudioInputController::OnError(AudioInputStream* stream) {
503 // Handle error on the audio-manager thread. 530 // Handle error on the audio-manager thread.
504 task_runner_->PostTask(FROM_HERE, base::Bind( 531 task_runner_->PostTask(FROM_HERE, base::Bind(
505 &AudioInputController::DoReportError, this)); 532 &AudioInputController::DoReportError, this));
506 } 533 }
(...skipping 13 matching lines...) Expand all
520 } 547 }
521 548
522 void AudioInputController::SetDataIsActive(bool enabled) { 549 void AudioInputController::SetDataIsActive(bool enabled) {
523 base::subtle::Release_Store(&data_is_active_, enabled); 550 base::subtle::Release_Store(&data_is_active_, enabled);
524 } 551 }
525 552
526 bool AudioInputController::GetDataIsActive() { 553 bool AudioInputController::GetDataIsActive() {
527 return (base::subtle::Acquire_Load(&data_is_active_) != false); 554 return (base::subtle::Acquire_Load(&data_is_active_) != false);
528 } 555 }
529 556
557 #if defined(AUDIO_POWER_MONITORING)
558 void AudioInputController::LogSilenceState(SilenceState value) {
559 UMA_HISTOGRAM_ENUMERATION("Media.AudioInputControllerSessionSilenceReport",
560 value,
561 SILENCE_STATE_MAX + 1);
562 }
563 #endif
564
530 } // namespace media 565 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_input_controller.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698