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

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: Created 5 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
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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 handler_->OnLog(this, log_string); 636 handler_->OnLog(this, log_string);
618 #endif 637 #endif
619 } 638 }
620 639
621 void AudioInputController::OnError(AudioInputStream* stream) { 640 void AudioInputController::OnError(AudioInputStream* stream) {
622 // Handle error on the audio-manager thread. 641 // Handle error on the audio-manager thread.
623 task_runner_->PostTask(FROM_HERE, base::Bind( 642 task_runner_->PostTask(FROM_HERE, base::Bind(
624 &AudioInputController::DoReportError, this)); 643 &AudioInputController::DoReportError, this));
625 } 644 }
626 645
646 void AudioInputController::EnableDebugRecording(
647 AudioInputWriter* input_writer) {
648 task_runner_->PostTask(FROM_HERE, base::Bind(
649 &AudioInputController::DoEnableDebugRecording,
650 this,
651 input_writer));
652 }
653
654 void AudioInputController::DisableDebugRecording(
655 const base::Closure& callback) {
656 DCHECK(creator_task_runner_->BelongsToCurrentThread());
657 DCHECK(!callback.is_null());
658
659 task_runner_->PostTaskAndReply(
660 FROM_HERE,
661 base::Bind(&AudioInputController::DoDisableDebugRecording,
662 this),
663 callback);
664 }
665
627 void AudioInputController::DoStopCloseAndClearStream() { 666 void AudioInputController::DoStopCloseAndClearStream() {
628 DCHECK(task_runner_->BelongsToCurrentThread()); 667 DCHECK(task_runner_->BelongsToCurrentThread());
629 668
630 // Allow calling unconditionally and bail if we don't have a stream to close. 669 // Allow calling unconditionally and bail if we don't have a stream to close.
631 if (stream_ != NULL) { 670 if (stream_ != NULL) {
632 stream_->Stop(); 671 stream_->Stop();
633 stream_->Close(); 672 stream_->Close();
634 stream_ = NULL; 673 stream_ = NULL;
635 } 674 }
636 675
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 } 708 }
670 } 709 }
671 710
672 void AudioInputController::LogSilenceState(SilenceState value) { 711 void AudioInputController::LogSilenceState(SilenceState value) {
673 UMA_HISTOGRAM_ENUMERATION("Media.AudioInputControllerSessionSilenceReport", 712 UMA_HISTOGRAM_ENUMERATION("Media.AudioInputControllerSessionSilenceReport",
674 value, 713 value,
675 SILENCE_STATE_MAX + 1); 714 SILENCE_STATE_MAX + 1);
676 } 715 }
677 #endif 716 #endif
678 717
718 void AudioInputController::DoEnableDebugRecording(
719 AudioInputWriter* input_writer) {
720 DCHECK(task_runner_->BelongsToCurrentThread());
721 DCHECK(!input_writer_);
722 input_writer_ = input_writer;
723 }
724
725 void AudioInputController::DoDisableDebugRecording() {
726 DCHECK(task_runner_->BelongsToCurrentThread());
727 input_writer_ = nullptr;
728 }
729
730 void AudioInputController::WriteInputDataForDebugging(
731 scoped_ptr<AudioBus> data) {
732 DCHECK(task_runner_->BelongsToCurrentThread());
733 if (input_writer_)
734 input_writer_->Write(data.Pass());
735 }
736
679 } // namespace media 737 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698