Chromium Code Reviews| Index: content/browser/renderer_host/media/audio_renderer_host.cc |
| diff --git a/content/browser/renderer_host/media/audio_renderer_host.cc b/content/browser/renderer_host/media/audio_renderer_host.cc |
| index 0c8c310350bcfb86116470fc0889e092fdbd6d3e..c6ff85a176b1765ea819cce20690dd02df642028 100644 |
| --- a/content/browser/renderer_host/media/audio_renderer_host.cc |
| +++ b/content/browser/renderer_host/media/audio_renderer_host.cc |
| @@ -4,6 +4,8 @@ |
| #include "content/browser/renderer_host/media/audio_renderer_host.h" |
| +#include <algorithm> |
| + |
| #include "base/bind.h" |
| #include "base/bind_helpers.h" |
| #include "base/command_line.h" |
| @@ -63,7 +65,7 @@ class AudioRendererHost::AudioEntry |
| // media::AudioOutputController::EventHandler implementation. |
| virtual void OnCreated() OVERRIDE; |
| virtual void OnPlaying() OVERRIDE; |
| - virtual void OnAudible(bool is_audible) OVERRIDE; |
| + virtual void OnPowerMeasured(float power_dBFS, bool clipped) OVERRIDE; |
| virtual void OnPaused() OVERRIDE; |
| virtual void OnError() OVERRIDE; |
| virtual void OnDeviceChange(int new_buffer_size, int new_sample_rate) |
| @@ -157,12 +159,13 @@ void AudioRendererHost::AudioEntry::OnPlaying() { |
| stream_id_, media::AudioOutputIPCDelegate::kPlaying))); |
| } |
| -void AudioRendererHost::AudioEntry::OnAudible(bool is_audible) { |
| +void AudioRendererHost::AudioEntry::OnPowerMeasured(float power_dBFS, |
| + bool clipped) { |
| BrowserThread::PostTask( |
| BrowserThread::IO, |
| FROM_HERE, |
| - base::Bind(&AudioRendererHost::DoNotifyAudibleState, host_, |
| - this, is_audible)); |
| + base::Bind(&AudioRendererHost::DoNotifyAudioPowerLevel, host_, |
| + this, power_dBFS, clipped)); |
| } |
| void AudioRendererHost::AudioEntry::OnPaused() { |
| @@ -235,22 +238,38 @@ void AudioRendererHost::DoCompleteCreation(AudioEntry* entry) { |
| media::PacketSizeInBytes(entry->shared_memory()->requested_size()))); |
| } |
| -void AudioRendererHost::DoNotifyAudibleState(AudioEntry* entry, |
| - bool is_audible) { |
| +void AudioRendererHost::DoNotifyAudioPowerLevel(AudioEntry* entry, |
| + float power_dBFS, |
| + bool clipped) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| MediaObserver* const media_observer = |
| GetContentClient()->browser()->GetMediaObserver(); |
| if (media_observer) { |
| - DVLOG(1) << "AudioRendererHost@" << this |
| - << "::DoNotifyAudibleState(is_audible=" << is_audible |
| - << ") for stream_id=" << entry->stream_id(); |
| +#ifndef NDEBUG |
|
DaleCurtis
2013/07/02 22:26:34
As nice as it looks, you should probably remove pr
miu
2013/07/09 00:59:56
Done.
|
| + // Convenient debug tool: A simple text-mode power meter. |
| + if (VLOG_IS_ON(2)) { |
| + static const int kNumBars = 24; |
| + static const float kBottomThreshold = -72.0f; |
| + const float capped_power = |
| + std::max(kBottomThreshold, std::min(0.0f, power_dBFS)); |
| + const int bars_lit = static_cast<int>( |
| + kNumBars * (1.0f - (capped_power / kBottomThreshold))); |
| + DVLOG(2) << "AudioRendererHost@" << this |
| + << "::DoNotifyAudioPowerLevel(" |
| + << std::string(bars_lit, '#') |
| + << std::string(kNumBars - bars_lit, '_') |
| + << (clipped ? "!!! " : " ") |
| + << static_cast<int>(power_dBFS) << " dBFS" |
| + << ") for stream_id=" << entry->stream_id(); |
| + } |
| +#endif |
| if (CommandLine::ForCurrentProcess()->HasSwitch( |
| switches::kEnableAudibleNotifications)) { |
| media_observer->OnAudioStreamPlayingChanged( |
| render_process_id_, entry->render_view_id(), entry->stream_id(), |
| - is_audible); |
| + true, power_dBFS, clipped); |
| } |
| } |
| } |
| @@ -427,7 +446,8 @@ void AudioRendererHost::DeleteEntry(scoped_ptr<AudioEntry> entry) { |
| GetContentClient()->browser()->GetMediaObserver(); |
| if (media_observer) { |
| media_observer->OnAudioStreamPlayingChanged( |
| - render_process_id_, entry->render_view_id(), entry->stream_id(), false); |
| + render_process_id_, entry->render_view_id(), entry->stream_id(), |
| + false, -std::numeric_limits<float>::infinity(), false); |
| } |
| // Notify the media observer. |