| Index: media/audio/audio_output_controller.cc
|
| diff --git a/media/audio/audio_output_controller.cc b/media/audio/audio_output_controller.cc
|
| index f41ed74b65bed526c318cbabc05ec50e2fd5eed6..35c1aec191d652be0762fef5fc1020a1f8f2f805 100644
|
| --- a/media/audio/audio_output_controller.cc
|
| +++ b/media/audio/audio_output_controller.cc
|
| @@ -11,7 +11,7 @@
|
| #include "base/threading/platform_thread.h"
|
| #include "base/time.h"
|
| #include "build/build_config.h"
|
| -#include "media/audio/audio_silence_detector.h"
|
| +#include "media/audio/audio_power_monitor.h"
|
| #include "media/audio/audio_util.h"
|
| #include "media/audio/shared_memory_util.h"
|
|
|
| @@ -20,16 +20,9 @@ using base::TimeDelta;
|
|
|
| namespace media {
|
|
|
| -// Amount of contiguous time where all audio is silent before considering the
|
| -// stream to have transitioned and EventHandler::OnAudible() should be called.
|
| -static const int kQuestionableSilencePeriodMillis = 50;
|
| -
|
| -// Sample value range below which audio is considered indistinguishably silent.
|
| -//
|
| -// TODO(miu): This value should be specified in dbFS units rather than full
|
| -// scale. See TODO in audio_silence_detector.h.
|
| -static const float kIndistinguishableSilenceThreshold =
|
| - 1.0f / 4096.0f; // Note: This is approximately -72 dbFS.
|
| +// Amount of time between calls to EventHandler::OnPowerMeasured() to report
|
| +// current power levels in the audio signal.
|
| +static const int kPowerMeasurementPeriodMillis = 50;
|
|
|
| // Polling-related constants.
|
| const int AudioOutputController::kPollNumAttempts = 3;
|
| @@ -189,20 +182,20 @@ void AudioOutputController::StartStream() {
|
| DCHECK(message_loop_->BelongsToCurrentThread());
|
| state_ = kPlaying;
|
|
|
| - silence_detector_.reset(new AudioSilenceDetector(
|
| + // Start monitoring power levels and send an initial notification that we're
|
| + // starting in silence.
|
| + handler_->OnPowerMeasured(AudioPowerMonitor::kZeroPowerDBFS);
|
| + power_monitor_.reset(new AudioPowerMonitor(
|
| params_.sample_rate(),
|
| - TimeDelta::FromMilliseconds(kQuestionableSilencePeriodMillis),
|
| - kIndistinguishableSilenceThreshold));
|
| + TimeDelta::FromMilliseconds(kPowerMeasurementPeriodMillis),
|
| + MessageLoop::current(),
|
| + base::Bind(&EventHandler::OnPowerMeasured, base::Unretained(handler_))));
|
|
|
| // We start the AudioOutputStream lazily.
|
| AllowEntryToOnMoreIOData();
|
| stream_->Start(this);
|
|
|
| - // Tell the event handler that we are now playing, and also start the silence
|
| - // detection notifications.
|
| handler_->OnPlaying();
|
| - silence_detector_->Start(
|
| - base::Bind(&EventHandler::OnAudible, base::Unretained(handler_)));
|
| }
|
|
|
| void AudioOutputController::StopStream() {
|
| @@ -215,8 +208,9 @@ void AudioOutputController::StopStream() {
|
| } else if (state_ == kPlaying) {
|
| stream_->Stop();
|
| DisallowEntryToOnMoreIOData();
|
| - silence_detector_->Stop(true);
|
| - silence_detector_.reset();
|
| + power_monitor_.reset();
|
| + // Send a final notification that we're ending in silence.
|
| + handler_->OnPowerMeasured(AudioPowerMonitor::kZeroPowerDBFS);
|
| state_ = kPaused;
|
| }
|
| }
|
| @@ -296,7 +290,7 @@ int AudioOutputController::OnMoreIOData(AudioBus* source,
|
| sync_reader_->UpdatePendingBytes(
|
| buffers_state.total_bytes() + frames * params_.GetBytesPerFrame());
|
|
|
| - silence_detector_->Scan(dest, frames);
|
| + power_monitor_->Scan(*dest, frames);
|
|
|
| AllowEntryToOnMoreIOData();
|
| return frames;
|
|
|