Chromium Code Reviews| Index: media/audio/audio_input_controller.cc |
| diff --git a/media/audio/audio_input_controller.cc b/media/audio/audio_input_controller.cc |
| index bcd9c7281e61d1ff3b3b66b73cf59f717c33296a..4bcfc948dc43f1a1a12c641cc05b602c08a0f576 100644 |
| --- a/media/audio/audio_input_controller.cc |
| +++ b/media/audio/audio_input_controller.cc |
| @@ -73,11 +73,13 @@ namespace media { |
| // static |
| AudioInputController::Factory* AudioInputController::factory_ = NULL; |
| -AudioInputController::AudioInputController(EventHandler* handler, |
| +AudioInputController::AudioInputController(AudioManager* audio_manager, |
| + EventHandler* handler, |
| SyncWriter* sync_writer, |
| UserInputMonitor* user_input_monitor) |
| : creator_task_runner_(base::MessageLoopProxy::current()), |
| handler_(handler), |
| + audio_manager_(audio_manager), |
| stream_(NULL), |
| data_is_active_(false), |
| state_(CLOSED), |
| @@ -111,16 +113,19 @@ scoped_refptr<AudioInputController> AudioInputController::Create( |
| return factory_->Create( |
| audio_manager, event_handler, params, user_input_monitor); |
| } |
| - scoped_refptr<AudioInputController> controller( |
| - new AudioInputController(event_handler, NULL, user_input_monitor)); |
| + scoped_refptr<AudioInputController> controller(new AudioInputController( |
| + audio_manager, event_handler, NULL, user_input_monitor)); |
| controller->task_runner_ = audio_manager->GetTaskRunner(); |
| // Create and open a new audio input stream from the existing |
| // audio-device thread. |
| - if (!controller->task_runner_->PostTask(FROM_HERE, |
| - base::Bind(&AudioInputController::DoCreate, controller, |
| - base::Unretained(audio_manager), params, device_id))) { |
| + if (!controller->task_runner_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&AudioInputController::DoCreate, |
| + controller, |
| + params, |
| + device_id))) { |
| controller = NULL; |
| } |
| @@ -143,15 +148,18 @@ scoped_refptr<AudioInputController> AudioInputController::CreateLowLatency( |
| // Create the AudioInputController object and ensure that it runs on |
| // the audio-manager thread. |
| - scoped_refptr<AudioInputController> controller( |
| - new AudioInputController(event_handler, sync_writer, user_input_monitor)); |
| + scoped_refptr<AudioInputController> controller(new AudioInputController( |
| + audio_manager, event_handler, sync_writer, user_input_monitor)); |
| controller->task_runner_ = audio_manager->GetTaskRunner(); |
| // Create and open a new audio input stream from the existing |
| // audio-device thread. Use the provided audio-input device. |
| - if (!controller->task_runner_->PostTask(FROM_HERE, |
| - base::Bind(&AudioInputController::DoCreate, controller, |
| - base::Unretained(audio_manager), params, device_id))) { |
| + if (!controller->task_runner_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&AudioInputController::DoCreate, |
| + controller, |
| + params, |
| + device_id))) { |
| controller = NULL; |
| } |
| @@ -170,8 +178,8 @@ scoped_refptr<AudioInputController> AudioInputController::CreateForStream( |
| // Create the AudioInputController object and ensure that it runs on |
| // the audio-manager thread. |
| - scoped_refptr<AudioInputController> controller( |
| - new AudioInputController(event_handler, sync_writer, user_input_monitor)); |
| + scoped_refptr<AudioInputController> controller(new AudioInputController( |
| + NULL, event_handler, sync_writer, user_input_monitor)); |
| controller->task_runner_ = task_runner; |
| // TODO(miu): See TODO at top of file. Until that's resolved, we need to |
| @@ -213,11 +221,15 @@ void AudioInputController::SetAutomaticGainControl(bool enabled) { |
| &AudioInputController::DoSetAutomaticGainControl, this, enabled)); |
| } |
| -void AudioInputController::DoCreate(AudioManager* audio_manager, |
| - const AudioParameters& params, |
| +void AudioInputController::DoCreate(const AudioParameters& params, |
| const std::string& device_id) { |
| DCHECK(task_runner_->BelongsToCurrentThread()); |
| SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioInputController.CreateTime"); |
| + if (handler_) { |
| + std::string log_string = |
| + base::StringPrintf("AIC::DoCreate(device_id=%s)", device_id.c_str()); |
|
Henrik Grunell
2014/08/22 16:14:42
What device id is this? Unique in what way? Can it
no longer working on chromium
2014/08/25 08:20:05
This is the uniqie id of the device, we can't log
henrika (OOO until Aug 14)
2014/08/25 12:47:44
Removing. Thanks.
|
| + handler_->OnLog(this, log_string); |
| + } |
| #if defined(AUDIO_POWER_MONITORING) |
| // Create the audio (power) level meter given the provided audio parameters. |
| @@ -231,11 +243,14 @@ void AudioInputController::DoCreate(AudioManager* audio_manager, |
| silence_state_ = SILENCE_STATE_NO_MEASUREMENT; |
| #endif |
| + if (audio_manager_) |
| + audio_manager_->AddStateChangeListener(this); |
| + |
| // TODO(miu): See TODO at top of file. Until that's resolved, assume all |
| // platform audio input requires the |no_data_timer_| be used to auto-detect |
| // errors. In reality, probably only Windows needs to be treated as |
| // unreliable here. |
| - DoCreateForStream(audio_manager->MakeAudioInputStream(params, device_id)); |
| + DoCreateForStream(audio_manager_->MakeAudioInputStream(params, device_id)); |
| } |
| void AudioInputController::DoCreateForStream( |
| @@ -298,6 +313,9 @@ void AudioInputController::DoRecord() { |
| state_ = RECORDING; |
| } |
| + if (handler_) |
| + handler_->OnLog(this, "AIC::DoRecord"); |
|
no longer working on chromium
2014/08/25 08:20:05
I don't really think you should log these, DoRecor
henrika (OOO until Aug 14)
2014/08/25 12:47:44
Well, if it does that may very well be a reason wh
|
| + |
| if (no_data_timer_) { |
| // Start the data timer. Once |kTimerResetIntervalSeconds| have passed, |
| // a callback to FirstCheckForNoData() is made. |
| @@ -316,12 +334,18 @@ void AudioInputController::DoClose() { |
| if (state_ == CLOSED) |
| return; |
| + if (handler_) |
| + handler_->OnLog(this, "AIC::DoClose"); |
| + |
| // Delete the timer on the same thread that created it. |
| no_data_timer_.reset(); |
| DoStopCloseAndClearStream(); |
| SetDataIsActive(false); |
| + if (audio_manager_) |
| + audio_manager_->RemoveStateChangeListener(this); |
|
Henrik Grunell
2014/08/22 16:14:43
Should the raw |audio_manager_| pointer be set to
henrika (OOO until Aug 14)
2014/08/25 12:47:44
It could but I can't really see the gain actually
|
| + |
| if (SharedMemoryAndSyncSocketMode()) |
| sync_writer_->Close(); |
| @@ -383,6 +407,12 @@ void AudioInputController::FirstCheckForNoData() { |
| LogCaptureStartupResult(GetDataIsActive() ? |
| CAPTURE_STARTUP_OK : |
| CAPTURE_STARTUP_NO_DATA_CALLBACK); |
| + if (handler_) { |
| + GetDataIsActive() |
| + ? handler_->OnLog(this, "AIC::FirstCheckForNoData => data is active") |
|
no longer working on chromium
2014/08/25 08:20:05
this does not look like clang format, could you pl
henrika (OOO until Aug 14)
2014/08/25 12:47:44
I did run git cl format and this is what it gives
|
| + : handler_->OnLog(this, |
| + "AIC::FirstCheckForNoData => data is NOT active"); |
| + } |
| DoCheckForNoData(); |
| } |
| @@ -526,6 +556,12 @@ void AudioInputController::DoLogAudioLevel(float level_dbfs) { |
| #endif |
| } |
| +void AudioInputController::OnStateChange(const std::string state) { |
| + DCHECK(task_runner_->BelongsToCurrentThread()); |
| + if (handler_) |
| + handler_->OnLog(this, state); |
| +} |
| + |
| void AudioInputController::OnError(AudioInputStream* stream) { |
| // Handle error on the audio-manager thread. |
| task_runner_->PostTask(FROM_HERE, base::Bind( |