Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "content/browser/renderer_host/media/audio_renderer_host.h" | 5 #include "content/browser/renderer_host/media/audio_renderer_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | |
| 8 | |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 10 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 11 #include "base/process.h" | 13 #include "base/process.h" |
| 12 #include "base/shared_memory.h" | 14 #include "base/shared_memory.h" |
| 13 #include "content/browser/browser_main_loop.h" | 15 #include "content/browser/browser_main_loop.h" |
| 14 #include "content/browser/media/media_internals.h" | 16 #include "content/browser/media/media_internals.h" |
| 15 #include "content/browser/renderer_host/media/audio_input_device_manager.h" | 17 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
| 16 #include "content/browser/renderer_host/media/audio_mirroring_manager.h" | 18 #include "content/browser/renderer_host/media/audio_mirroring_manager.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 } | 58 } |
| 57 | 59 |
| 58 media::AudioOutputController::SyncReader* reader() const { | 60 media::AudioOutputController::SyncReader* reader() const { |
| 59 return reader_.get(); | 61 return reader_.get(); |
| 60 } | 62 } |
| 61 | 63 |
| 62 private: | 64 private: |
| 63 // media::AudioOutputController::EventHandler implementation. | 65 // media::AudioOutputController::EventHandler implementation. |
| 64 virtual void OnCreated() OVERRIDE; | 66 virtual void OnCreated() OVERRIDE; |
| 65 virtual void OnPlaying() OVERRIDE; | 67 virtual void OnPlaying() OVERRIDE; |
| 66 virtual void OnAudible(bool is_audible) OVERRIDE; | 68 virtual void OnPowerMeasured(float power_dBFS, bool clipped) OVERRIDE; |
| 67 virtual void OnPaused() OVERRIDE; | 69 virtual void OnPaused() OVERRIDE; |
| 68 virtual void OnError() OVERRIDE; | 70 virtual void OnError() OVERRIDE; |
| 69 virtual void OnDeviceChange(int new_buffer_size, int new_sample_rate) | 71 virtual void OnDeviceChange(int new_buffer_size, int new_sample_rate) |
| 70 OVERRIDE; | 72 OVERRIDE; |
| 71 | 73 |
| 72 AudioRendererHost* const host_; | 74 AudioRendererHost* const host_; |
| 73 const int stream_id_; | 75 const int stream_id_; |
| 74 | 76 |
| 75 // The routing ID of the source render view. | 77 // The routing ID of the source render view. |
| 76 const int render_view_id_; | 78 const int render_view_id_; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 void AudioRendererHost::AudioEntry::OnPlaying() { | 152 void AudioRendererHost::AudioEntry::OnPlaying() { |
| 151 BrowserThread::PostTask( | 153 BrowserThread::PostTask( |
| 152 BrowserThread::IO, | 154 BrowserThread::IO, |
| 153 FROM_HERE, | 155 FROM_HERE, |
| 154 base::Bind( | 156 base::Bind( |
| 155 base::IgnoreResult(&AudioRendererHost::Send), host_, | 157 base::IgnoreResult(&AudioRendererHost::Send), host_, |
| 156 new AudioMsg_NotifyStreamStateChanged( | 158 new AudioMsg_NotifyStreamStateChanged( |
| 157 stream_id_, media::AudioOutputIPCDelegate::kPlaying))); | 159 stream_id_, media::AudioOutputIPCDelegate::kPlaying))); |
| 158 } | 160 } |
| 159 | 161 |
| 160 void AudioRendererHost::AudioEntry::OnAudible(bool is_audible) { | 162 void AudioRendererHost::AudioEntry::OnPowerMeasured(float power_dBFS, |
| 163 bool clipped) { | |
| 161 BrowserThread::PostTask( | 164 BrowserThread::PostTask( |
| 162 BrowserThread::IO, | 165 BrowserThread::IO, |
| 163 FROM_HERE, | 166 FROM_HERE, |
| 164 base::Bind(&AudioRendererHost::DoNotifyAudibleState, host_, | 167 base::Bind(&AudioRendererHost::DoNotifyAudioPowerLevel, host_, |
| 165 this, is_audible)); | 168 this, power_dBFS, clipped)); |
| 166 } | 169 } |
| 167 | 170 |
| 168 void AudioRendererHost::AudioEntry::OnPaused() { | 171 void AudioRendererHost::AudioEntry::OnPaused() { |
| 169 BrowserThread::PostTask( | 172 BrowserThread::PostTask( |
| 170 BrowserThread::IO, | 173 BrowserThread::IO, |
| 171 FROM_HERE, | 174 FROM_HERE, |
| 172 base::Bind( | 175 base::Bind( |
| 173 base::IgnoreResult(&AudioRendererHost::Send), host_, | 176 base::IgnoreResult(&AudioRendererHost::Send), host_, |
| 174 new AudioMsg_NotifyStreamStateChanged( | 177 new AudioMsg_NotifyStreamStateChanged( |
| 175 stream_id_, media::AudioOutputIPCDelegate::kPaused))); | 178 stream_id_, media::AudioOutputIPCDelegate::kPaused))); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 return; | 231 return; |
| 229 } | 232 } |
| 230 | 233 |
| 231 Send(new AudioMsg_NotifyStreamCreated( | 234 Send(new AudioMsg_NotifyStreamCreated( |
| 232 entry->stream_id(), | 235 entry->stream_id(), |
| 233 foreign_memory_handle, | 236 foreign_memory_handle, |
| 234 foreign_socket_handle, | 237 foreign_socket_handle, |
| 235 media::PacketSizeInBytes(entry->shared_memory()->requested_size()))); | 238 media::PacketSizeInBytes(entry->shared_memory()->requested_size()))); |
| 236 } | 239 } |
| 237 | 240 |
| 238 void AudioRendererHost::DoNotifyAudibleState(AudioEntry* entry, | 241 void AudioRendererHost::DoNotifyAudioPowerLevel(AudioEntry* entry, |
| 239 bool is_audible) { | 242 float power_dBFS, |
| 243 bool clipped) { | |
| 240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 241 | 245 |
| 242 MediaObserver* const media_observer = | 246 MediaObserver* const media_observer = |
| 243 GetContentClient()->browser()->GetMediaObserver(); | 247 GetContentClient()->browser()->GetMediaObserver(); |
| 244 if (media_observer) { | 248 if (media_observer) { |
| 245 DVLOG(1) << "AudioRendererHost@" << this | 249 #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.
| |
| 246 << "::DoNotifyAudibleState(is_audible=" << is_audible | 250 // Convenient debug tool: A simple text-mode power meter. |
| 247 << ") for stream_id=" << entry->stream_id(); | 251 if (VLOG_IS_ON(2)) { |
| 252 static const int kNumBars = 24; | |
| 253 static const float kBottomThreshold = -72.0f; | |
| 254 const float capped_power = | |
| 255 std::max(kBottomThreshold, std::min(0.0f, power_dBFS)); | |
| 256 const int bars_lit = static_cast<int>( | |
| 257 kNumBars * (1.0f - (capped_power / kBottomThreshold))); | |
| 258 DVLOG(2) << "AudioRendererHost@" << this | |
| 259 << "::DoNotifyAudioPowerLevel(" | |
| 260 << std::string(bars_lit, '#') | |
| 261 << std::string(kNumBars - bars_lit, '_') | |
| 262 << (clipped ? "!!! " : " ") | |
| 263 << static_cast<int>(power_dBFS) << " dBFS" | |
| 264 << ") for stream_id=" << entry->stream_id(); | |
| 265 } | |
| 266 #endif | |
| 248 | 267 |
| 249 if (CommandLine::ForCurrentProcess()->HasSwitch( | 268 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 250 switches::kEnableAudibleNotifications)) { | 269 switches::kEnableAudibleNotifications)) { |
| 251 media_observer->OnAudioStreamPlayingChanged( | 270 media_observer->OnAudioStreamPlayingChanged( |
| 252 render_process_id_, entry->render_view_id(), entry->stream_id(), | 271 render_process_id_, entry->render_view_id(), entry->stream_id(), |
| 253 is_audible); | 272 true, power_dBFS, clipped); |
| 254 } | 273 } |
| 255 } | 274 } |
| 256 } | 275 } |
| 257 | 276 |
| 258 /////////////////////////////////////////////////////////////////////////////// | 277 /////////////////////////////////////////////////////////////////////////////// |
| 259 // IPC Messages handler | 278 // IPC Messages handler |
| 260 bool AudioRendererHost::OnMessageReceived(const IPC::Message& message, | 279 bool AudioRendererHost::OnMessageReceived(const IPC::Message& message, |
| 261 bool* message_was_ok) { | 280 bool* message_was_ok) { |
| 262 bool handled = true; | 281 bool handled = true; |
| 263 IPC_BEGIN_MESSAGE_MAP_EX(AudioRendererHost, message, *message_was_ok) | 282 IPC_BEGIN_MESSAGE_MAP_EX(AudioRendererHost, message, *message_was_ok) |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 } | 439 } |
| 421 | 440 |
| 422 void AudioRendererHost::DeleteEntry(scoped_ptr<AudioEntry> entry) { | 441 void AudioRendererHost::DeleteEntry(scoped_ptr<AudioEntry> entry) { |
| 423 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 442 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 424 | 443 |
| 425 // At this point, make the final "say" in audio playback state. | 444 // At this point, make the final "say" in audio playback state. |
| 426 MediaObserver* const media_observer = | 445 MediaObserver* const media_observer = |
| 427 GetContentClient()->browser()->GetMediaObserver(); | 446 GetContentClient()->browser()->GetMediaObserver(); |
| 428 if (media_observer) { | 447 if (media_observer) { |
| 429 media_observer->OnAudioStreamPlayingChanged( | 448 media_observer->OnAudioStreamPlayingChanged( |
| 430 render_process_id_, entry->render_view_id(), entry->stream_id(), false); | 449 render_process_id_, entry->render_view_id(), entry->stream_id(), |
| 450 false, -std::numeric_limits<float>::infinity(), false); | |
| 431 } | 451 } |
| 432 | 452 |
| 433 // Notify the media observer. | 453 // Notify the media observer. |
| 434 if (media_internals_) | 454 if (media_internals_) |
| 435 media_internals_->OnDeleteAudioStream(this, entry->stream_id()); | 455 media_internals_->OnDeleteAudioStream(this, entry->stream_id()); |
| 436 | 456 |
| 437 // Note: |entry| will be deleted upon leaving this scope. | 457 // Note: |entry| will be deleted upon leaving this scope. |
| 438 } | 458 } |
| 439 | 459 |
| 440 void AudioRendererHost::ReportErrorAndClose(int stream_id) { | 460 void AudioRendererHost::ReportErrorAndClose(int stream_id) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 455 } | 475 } |
| 456 | 476 |
| 457 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { | 477 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { |
| 458 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 478 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 459 | 479 |
| 460 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id); | 480 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id); |
| 461 return i != audio_entries_.end() ? i->second : NULL; | 481 return i != audio_entries_.end() ? i->second : NULL; |
| 462 } | 482 } |
| 463 | 483 |
| 464 } // namespace content | 484 } // namespace content |
| OLD | NEW |