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

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

Issue 1272223003: Implement writing mic audio input data to file for debugging purposes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 3 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
« no previous file with comments | « media/audio/audio_input_controller.h ('k') | media/audio/audio_input_writer.h » ('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/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/thread_task_runner_handle.h" 12 #include "base/thread_task_runner_handle.h"
13 #include "base/threading/thread_restrictions.h" 13 #include "base/threading/thread_restrictions.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "media/audio/audio_input_writer.h"
15 #include "media/base/user_input_monitor.h" 16 #include "media/base/user_input_monitor.h"
16 17
17 using base::TimeDelta; 18 using base::TimeDelta;
18 19
19 namespace { 20 namespace {
20 21
21 const int kMaxInputChannels = 3; 22 const int kMaxInputChannels = 3;
22 23
23 // TODO(henrika): remove usage of timers and add support for proper 24 // TODO(henrika): remove usage of timers and add support for proper
24 // notification of when the input device is removed. This was originally added 25 // notification of when the input device is removed. This was originally added
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 state_(CLOSED), 128 state_(CLOSED),
128 sync_writer_(sync_writer), 129 sync_writer_(sync_writer),
129 max_volume_(0.0), 130 max_volume_(0.0),
130 user_input_monitor_(user_input_monitor), 131 user_input_monitor_(user_input_monitor),
131 agc_is_enabled_(agc_is_enabled), 132 agc_is_enabled_(agc_is_enabled),
132 #if defined(AUDIO_POWER_MONITORING) 133 #if defined(AUDIO_POWER_MONITORING)
133 power_measurement_is_enabled_(false), 134 power_measurement_is_enabled_(false),
134 log_silence_state_(false), 135 log_silence_state_(false),
135 silence_state_(SILENCE_STATE_NO_MEASUREMENT), 136 silence_state_(SILENCE_STATE_NO_MEASUREMENT),
136 #endif 137 #endif
137 prev_key_down_count_(0) { 138 prev_key_down_count_(0),
139 input_writer_(nullptr) {
138 DCHECK(creator_task_runner_.get()); 140 DCHECK(creator_task_runner_.get());
139 } 141 }
140 142
141 AudioInputController::~AudioInputController() { 143 AudioInputController::~AudioInputController() {
142 DCHECK_EQ(state_, CLOSED); 144 DCHECK_EQ(state_, CLOSED);
143 } 145 }
144 146
145 // static 147 // static
146 scoped_refptr<AudioInputController> AudioInputController::Create( 148 scoped_refptr<AudioInputController> AudioInputController::Create(
147 AudioManager* audio_manager, 149 AudioManager* audio_manager,
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 if (user_input_monitor_) 427 if (user_input_monitor_)
426 user_input_monitor_->DisableKeyPressMonitoring(); 428 user_input_monitor_->DisableKeyPressMonitoring();
427 429
428 #if defined(AUDIO_POWER_MONITORING) 430 #if defined(AUDIO_POWER_MONITORING)
429 // Send UMA stats if enabled. 431 // Send UMA stats if enabled.
430 if (log_silence_state_) 432 if (log_silence_state_)
431 LogSilenceState(silence_state_); 433 LogSilenceState(silence_state_);
432 log_silence_state_ = false; 434 log_silence_state_ = false;
433 #endif 435 #endif
434 436
437 input_writer_ = nullptr;
438
435 state_ = CLOSED; 439 state_ = CLOSED;
436 } 440 }
437 441
438 void AudioInputController::DoReportError() { 442 void AudioInputController::DoReportError() {
439 DCHECK(task_runner_->BelongsToCurrentThread()); 443 DCHECK(task_runner_->BelongsToCurrentThread());
440 if (handler_) 444 if (handler_)
441 handler_->OnError(this, STREAM_ERROR); 445 handler_->OnError(this, STREAM_ERROR);
442 } 446 }
443 447
444 void AudioInputController::DoSetVolume(double volume) { 448 void AudioInputController::DoSetVolume(double volume) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 no_data_timer_->Start( 502 no_data_timer_->Start(
499 FROM_HERE, base::TimeDelta::FromSeconds(kTimerResetIntervalSeconds), 503 FROM_HERE, base::TimeDelta::FromSeconds(kTimerResetIntervalSeconds),
500 base::Bind(&AudioInputController::DoCheckForNoData, 504 base::Bind(&AudioInputController::DoCheckForNoData,
501 base::Unretained(this))); 505 base::Unretained(this)));
502 } 506 }
503 507
504 void AudioInputController::OnData(AudioInputStream* stream, 508 void AudioInputController::OnData(AudioInputStream* stream,
505 const AudioBus* source, 509 const AudioBus* source,
506 uint32 hardware_delay_bytes, 510 uint32 hardware_delay_bytes,
507 double volume) { 511 double volume) {
512 // |input_writer_| should only be accessed on the audio thread, but as a means
513 // to avoid copying data and posting on the audio thread, we just check for
514 // non-null here.
515 if (input_writer_) {
516 scoped_ptr<AudioBus> source_copy =
517 AudioBus::Create(source->channels(), source->frames());
518 source->CopyTo(source_copy.get());
519 task_runner_->PostTask(
520 FROM_HERE,
521 base::Bind(
522 &AudioInputController::WriteInputDataForDebugging,
523 this,
524 base::Passed(&source_copy)));
525 }
526
508 // Mark data as active to ensure that the periodic calls to 527 // Mark data as active to ensure that the periodic calls to
509 // DoCheckForNoData() does not report an error to the event handler. 528 // DoCheckForNoData() does not report an error to the event handler.
510 SetDataIsActive(true); 529 SetDataIsActive(true);
511 530
512 { 531 {
513 base::AutoLock auto_lock(lock_); 532 base::AutoLock auto_lock(lock_);
514 if (state_ != RECORDING) 533 if (state_ != RECORDING)
515 return; 534 return;
516 } 535 }
517 536
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 handler_->OnLog(this, log_string); 635 handler_->OnLog(this, log_string);
617 #endif 636 #endif
618 } 637 }
619 638
620 void AudioInputController::OnError(AudioInputStream* stream) { 639 void AudioInputController::OnError(AudioInputStream* stream) {
621 // Handle error on the audio-manager thread. 640 // Handle error on the audio-manager thread.
622 task_runner_->PostTask(FROM_HERE, base::Bind( 641 task_runner_->PostTask(FROM_HERE, base::Bind(
623 &AudioInputController::DoReportError, this)); 642 &AudioInputController::DoReportError, this));
624 } 643 }
625 644
645 void AudioInputController::EnableDebugRecording(
646 AudioInputWriter* input_writer) {
647 task_runner_->PostTask(FROM_HERE, base::Bind(
648 &AudioInputController::DoEnableDebugRecording,
649 this,
650 input_writer));
651 }
652
653 void AudioInputController::DisableDebugRecording(
654 const base::Closure& callback) {
655 DCHECK(creator_task_runner_->BelongsToCurrentThread());
656 DCHECK(!callback.is_null());
657
658 task_runner_->PostTaskAndReply(
659 FROM_HERE,
660 base::Bind(&AudioInputController::DoDisableDebugRecording,
661 this),
662 callback);
663 }
664
626 void AudioInputController::DoStopCloseAndClearStream() { 665 void AudioInputController::DoStopCloseAndClearStream() {
627 DCHECK(task_runner_->BelongsToCurrentThread()); 666 DCHECK(task_runner_->BelongsToCurrentThread());
628 667
629 // Allow calling unconditionally and bail if we don't have a stream to close. 668 // Allow calling unconditionally and bail if we don't have a stream to close.
630 if (stream_ != NULL) { 669 if (stream_ != NULL) {
631 stream_->Stop(); 670 stream_->Stop();
632 stream_->Close(); 671 stream_->Close();
633 stream_ = NULL; 672 stream_ = NULL;
634 } 673 }
635 674
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 } 707 }
669 } 708 }
670 709
671 void AudioInputController::LogSilenceState(SilenceState value) { 710 void AudioInputController::LogSilenceState(SilenceState value) {
672 UMA_HISTOGRAM_ENUMERATION("Media.AudioInputControllerSessionSilenceReport", 711 UMA_HISTOGRAM_ENUMERATION("Media.AudioInputControllerSessionSilenceReport",
673 value, 712 value,
674 SILENCE_STATE_MAX + 1); 713 SILENCE_STATE_MAX + 1);
675 } 714 }
676 #endif 715 #endif
677 716
717 void AudioInputController::DoEnableDebugRecording(
718 AudioInputWriter* input_writer) {
719 DCHECK(task_runner_->BelongsToCurrentThread());
720 DCHECK(!input_writer_);
721 input_writer_ = input_writer;
722 }
723
724 void AudioInputController::DoDisableDebugRecording() {
725 DCHECK(task_runner_->BelongsToCurrentThread());
726 input_writer_ = nullptr;
727 }
728
729 void AudioInputController::WriteInputDataForDebugging(
730 scoped_ptr<AudioBus> data) {
731 DCHECK(task_runner_->BelongsToCurrentThread());
732 if (input_writer_)
733 input_writer_->Write(data.Pass());
734 }
735
678 } // namespace media 736 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_input_controller.h ('k') | media/audio/audio_input_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698