| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 } | 56 } |
| 57 | 57 |
| 58 media::AudioOutputController::SyncReader* reader() const { | 58 media::AudioOutputController::SyncReader* reader() const { |
| 59 return reader_.get(); | 59 return reader_.get(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 private: | 62 private: |
| 63 // media::AudioOutputController::EventHandler implementation. | 63 // media::AudioOutputController::EventHandler implementation. |
| 64 virtual void OnCreated() OVERRIDE; | 64 virtual void OnCreated() OVERRIDE; |
| 65 virtual void OnPlaying() OVERRIDE; | 65 virtual void OnPlaying() OVERRIDE; |
| 66 virtual void OnAudible(bool is_audible) OVERRIDE; | 66 virtual void OnPowerMeasured(float power_dbfs, bool clipped) OVERRIDE; |
| 67 virtual void OnPaused() OVERRIDE; | 67 virtual void OnPaused() OVERRIDE; |
| 68 virtual void OnError() OVERRIDE; | 68 virtual void OnError() OVERRIDE; |
| 69 virtual void OnDeviceChange(int new_buffer_size, int new_sample_rate) | 69 virtual void OnDeviceChange(int new_buffer_size, int new_sample_rate) |
| 70 OVERRIDE; | 70 OVERRIDE; |
| 71 | 71 |
| 72 AudioRendererHost* const host_; | 72 AudioRendererHost* const host_; |
| 73 const int stream_id_; | 73 const int stream_id_; |
| 74 | 74 |
| 75 // The routing ID of the source render view. | 75 // The routing ID of the source render view. |
| 76 const int render_view_id_; | 76 const int render_view_id_; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 void AudioRendererHost::AudioEntry::OnPlaying() { | 150 void AudioRendererHost::AudioEntry::OnPlaying() { |
| 151 BrowserThread::PostTask( | 151 BrowserThread::PostTask( |
| 152 BrowserThread::IO, | 152 BrowserThread::IO, |
| 153 FROM_HERE, | 153 FROM_HERE, |
| 154 base::Bind( | 154 base::Bind( |
| 155 base::IgnoreResult(&AudioRendererHost::Send), host_, | 155 base::IgnoreResult(&AudioRendererHost::Send), host_, |
| 156 new AudioMsg_NotifyStreamStateChanged( | 156 new AudioMsg_NotifyStreamStateChanged( |
| 157 stream_id_, media::AudioOutputIPCDelegate::kPlaying))); | 157 stream_id_, media::AudioOutputIPCDelegate::kPlaying))); |
| 158 } | 158 } |
| 159 | 159 |
| 160 void AudioRendererHost::AudioEntry::OnAudible(bool is_audible) { | 160 void AudioRendererHost::AudioEntry::OnPowerMeasured(float power_dbfs, |
| 161 bool clipped) { |
| 161 BrowserThread::PostTask( | 162 BrowserThread::PostTask( |
| 162 BrowserThread::IO, | 163 BrowserThread::IO, |
| 163 FROM_HERE, | 164 FROM_HERE, |
| 164 base::Bind(&AudioRendererHost::DoNotifyAudibleState, host_, | 165 base::Bind(&AudioRendererHost::DoNotifyAudioPowerLevel, host_, |
| 165 this, is_audible)); | 166 this, power_dbfs, clipped)); |
| 166 } | 167 } |
| 167 | 168 |
| 168 void AudioRendererHost::AudioEntry::OnPaused() { | 169 void AudioRendererHost::AudioEntry::OnPaused() { |
| 169 BrowserThread::PostTask( | 170 BrowserThread::PostTask( |
| 170 BrowserThread::IO, | 171 BrowserThread::IO, |
| 171 FROM_HERE, | 172 FROM_HERE, |
| 172 base::Bind( | 173 base::Bind( |
| 173 base::IgnoreResult(&AudioRendererHost::Send), host_, | 174 base::IgnoreResult(&AudioRendererHost::Send), host_, |
| 174 new AudioMsg_NotifyStreamStateChanged( | 175 new AudioMsg_NotifyStreamStateChanged( |
| 175 stream_id_, media::AudioOutputIPCDelegate::kPaused))); | 176 stream_id_, media::AudioOutputIPCDelegate::kPaused))); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 return; | 229 return; |
| 229 } | 230 } |
| 230 | 231 |
| 231 Send(new AudioMsg_NotifyStreamCreated( | 232 Send(new AudioMsg_NotifyStreamCreated( |
| 232 entry->stream_id(), | 233 entry->stream_id(), |
| 233 foreign_memory_handle, | 234 foreign_memory_handle, |
| 234 foreign_socket_handle, | 235 foreign_socket_handle, |
| 235 media::PacketSizeInBytes(entry->shared_memory()->requested_size()))); | 236 media::PacketSizeInBytes(entry->shared_memory()->requested_size()))); |
| 236 } | 237 } |
| 237 | 238 |
| 238 void AudioRendererHost::DoNotifyAudibleState(AudioEntry* entry, | 239 void AudioRendererHost::DoNotifyAudioPowerLevel(AudioEntry* entry, |
| 239 bool is_audible) { | 240 float power_dbfs, |
| 241 bool clipped) { |
| 240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 241 | 243 |
| 242 MediaObserver* const media_observer = | 244 MediaObserver* const media_observer = |
| 243 GetContentClient()->browser()->GetMediaObserver(); | 245 GetContentClient()->browser()->GetMediaObserver(); |
| 244 if (media_observer) { | 246 if (media_observer) { |
| 245 DVLOG(1) << "AudioRendererHost@" << this | |
| 246 << "::DoNotifyAudibleState(is_audible=" << is_audible | |
| 247 << ") for stream_id=" << entry->stream_id(); | |
| 248 | |
| 249 if (CommandLine::ForCurrentProcess()->HasSwitch( | 247 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 250 switches::kEnableAudibleNotifications)) { | 248 switches::kEnableAudibleNotifications)) { |
| 251 media_observer->OnAudioStreamPlayingChanged( | 249 media_observer->OnAudioStreamPlayingChanged( |
| 252 render_process_id_, entry->render_view_id(), entry->stream_id(), | 250 render_process_id_, entry->render_view_id(), entry->stream_id(), |
| 253 is_audible); | 251 true, power_dbfs, clipped); |
| 254 } | 252 } |
| 255 } | 253 } |
| 256 } | 254 } |
| 257 | 255 |
| 258 /////////////////////////////////////////////////////////////////////////////// | 256 /////////////////////////////////////////////////////////////////////////////// |
| 259 // IPC Messages handler | 257 // IPC Messages handler |
| 260 bool AudioRendererHost::OnMessageReceived(const IPC::Message& message, | 258 bool AudioRendererHost::OnMessageReceived(const IPC::Message& message, |
| 261 bool* message_was_ok) { | 259 bool* message_was_ok) { |
| 262 bool handled = true; | 260 bool handled = true; |
| 263 IPC_BEGIN_MESSAGE_MAP_EX(AudioRendererHost, message, *message_was_ok) | 261 IPC_BEGIN_MESSAGE_MAP_EX(AudioRendererHost, message, *message_was_ok) |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 } | 418 } |
| 421 | 419 |
| 422 void AudioRendererHost::DeleteEntry(scoped_ptr<AudioEntry> entry) { | 420 void AudioRendererHost::DeleteEntry(scoped_ptr<AudioEntry> entry) { |
| 423 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 421 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 424 | 422 |
| 425 // At this point, make the final "say" in audio playback state. | 423 // At this point, make the final "say" in audio playback state. |
| 426 MediaObserver* const media_observer = | 424 MediaObserver* const media_observer = |
| 427 GetContentClient()->browser()->GetMediaObserver(); | 425 GetContentClient()->browser()->GetMediaObserver(); |
| 428 if (media_observer) { | 426 if (media_observer) { |
| 429 media_observer->OnAudioStreamPlayingChanged( | 427 media_observer->OnAudioStreamPlayingChanged( |
| 430 render_process_id_, entry->render_view_id(), entry->stream_id(), false); | 428 render_process_id_, entry->render_view_id(), entry->stream_id(), |
| 429 false, -std::numeric_limits<float>::infinity(), false); |
| 431 } | 430 } |
| 432 | 431 |
| 433 // Notify the media observer. | 432 // Notify the media observer. |
| 434 if (media_internals_) | 433 if (media_internals_) |
| 435 media_internals_->OnDeleteAudioStream(this, entry->stream_id()); | 434 media_internals_->OnDeleteAudioStream(this, entry->stream_id()); |
| 436 | 435 |
| 437 // Note: |entry| will be deleted upon leaving this scope. | 436 // Note: |entry| will be deleted upon leaving this scope. |
| 438 } | 437 } |
| 439 | 438 |
| 440 void AudioRendererHost::ReportErrorAndClose(int stream_id) { | 439 void AudioRendererHost::ReportErrorAndClose(int stream_id) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 455 } | 454 } |
| 456 | 455 |
| 457 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { | 456 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { |
| 458 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 457 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 459 | 458 |
| 460 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id); | 459 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id); |
| 461 return i != audio_entries_.end() ? i->second : NULL; | 460 return i != audio_entries_.end() ? i->second : NULL; |
| 462 } | 461 } |
| 463 | 462 |
| 464 } // namespace content | 463 } // namespace content |
| OLD | NEW |