| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 } | 54 } |
| 55 | 55 |
| 56 media::AudioOutputController::SyncReader* reader() const { | 56 media::AudioOutputController::SyncReader* reader() const { |
| 57 return reader_.get(); | 57 return reader_.get(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 private: | 60 private: |
| 61 // media::AudioOutputController::EventHandler implementation. | 61 // media::AudioOutputController::EventHandler implementation. |
| 62 virtual void OnCreated() OVERRIDE; | 62 virtual void OnCreated() OVERRIDE; |
| 63 virtual void OnPlaying() OVERRIDE; | 63 virtual void OnPlaying() OVERRIDE; |
| 64 virtual void OnAudible(bool is_audible) OVERRIDE; | 64 virtual void OnPowerMeasured(float power_in_dbfs) OVERRIDE; |
| 65 virtual void OnPaused() OVERRIDE; | 65 virtual void OnPaused() OVERRIDE; |
| 66 virtual void OnError() OVERRIDE; | 66 virtual void OnError() OVERRIDE; |
| 67 virtual void OnDeviceChange(int new_buffer_size, int new_sample_rate) | 67 virtual void OnDeviceChange(int new_buffer_size, int new_sample_rate) |
| 68 OVERRIDE; | 68 OVERRIDE; |
| 69 | 69 |
| 70 AudioRendererHost* const host_; | 70 AudioRendererHost* const host_; |
| 71 const int stream_id_; | 71 const int stream_id_; |
| 72 | 72 |
| 73 // The routing ID of the source render view. | 73 // The routing ID of the source render view. |
| 74 const int render_view_id_; | 74 const int render_view_id_; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 void AudioRendererHost::AudioEntry::OnPlaying() { | 144 void AudioRendererHost::AudioEntry::OnPlaying() { |
| 145 BrowserThread::PostTask( | 145 BrowserThread::PostTask( |
| 146 BrowserThread::IO, | 146 BrowserThread::IO, |
| 147 FROM_HERE, | 147 FROM_HERE, |
| 148 base::Bind( | 148 base::Bind( |
| 149 base::IgnoreResult(&AudioRendererHost::Send), host_, | 149 base::IgnoreResult(&AudioRendererHost::Send), host_, |
| 150 new AudioMsg_NotifyStreamStateChanged( | 150 new AudioMsg_NotifyStreamStateChanged( |
| 151 stream_id_, media::AudioOutputIPCDelegate::kPlaying))); | 151 stream_id_, media::AudioOutputIPCDelegate::kPlaying))); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void AudioRendererHost::AudioEntry::OnAudible(bool is_audible) { | 154 void AudioRendererHost::AudioEntry::OnPowerMeasured(float power_in_dbfs) { |
| 155 BrowserThread::PostTask( | 155 BrowserThread::PostTask( |
| 156 BrowserThread::IO, | 156 BrowserThread::IO, |
| 157 FROM_HERE, | 157 FROM_HERE, |
| 158 base::Bind(&AudioRendererHost::DoNotifyAudibleState, host_, | 158 base::Bind(&AudioRendererHost::DoNotifyAudioPowerLevel, host_, |
| 159 this, is_audible)); | 159 this, power_in_dbfs)); |
| 160 } | 160 } |
| 161 | 161 |
| 162 void AudioRendererHost::AudioEntry::OnPaused() { | 162 void AudioRendererHost::AudioEntry::OnPaused() { |
| 163 BrowserThread::PostTask( | 163 BrowserThread::PostTask( |
| 164 BrowserThread::IO, | 164 BrowserThread::IO, |
| 165 FROM_HERE, | 165 FROM_HERE, |
| 166 base::Bind( | 166 base::Bind( |
| 167 base::IgnoreResult(&AudioRendererHost::Send), host_, | 167 base::IgnoreResult(&AudioRendererHost::Send), host_, |
| 168 new AudioMsg_NotifyStreamStateChanged( | 168 new AudioMsg_NotifyStreamStateChanged( |
| 169 stream_id_, media::AudioOutputIPCDelegate::kPaused))); | 169 stream_id_, media::AudioOutputIPCDelegate::kPaused))); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 return; | 222 return; |
| 223 } | 223 } |
| 224 | 224 |
| 225 Send(new AudioMsg_NotifyStreamCreated( | 225 Send(new AudioMsg_NotifyStreamCreated( |
| 226 entry->stream_id(), | 226 entry->stream_id(), |
| 227 foreign_memory_handle, | 227 foreign_memory_handle, |
| 228 foreign_socket_handle, | 228 foreign_socket_handle, |
| 229 media::PacketSizeInBytes(entry->shared_memory()->requested_size()))); | 229 media::PacketSizeInBytes(entry->shared_memory()->requested_size()))); |
| 230 } | 230 } |
| 231 | 231 |
| 232 void AudioRendererHost::DoNotifyAudibleState(AudioEntry* entry, | 232 void AudioRendererHost::DoNotifyAudioPowerLevel(AudioEntry* entry, |
| 233 bool is_audible) { | 233 float power_in_dbfs) { |
| 234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 235 | 235 |
| 236 MediaObserver* const media_observer = | 236 MediaObserver* const media_observer = |
| 237 GetContentClient()->browser()->GetMediaObserver(); | 237 GetContentClient()->browser()->GetMediaObserver(); |
| 238 if (media_observer) { | 238 if (media_observer) { |
| 239 DVLOG(1) << "AudioRendererHost@" << this | 239 DVLOG(2) << "AudioRendererHost@" << this |
| 240 << "::DoNotifyAudibleState(is_audible=" << is_audible | 240 << "::DoNotifyAudioPowerLevel(power_in_dbfs=" << power_in_dbfs |
| 241 << ") for stream_id=" << entry->stream_id(); | 241 << ") for stream_id=" << entry->stream_id(); |
| 242 | 242 |
| 243 if (CommandLine::ForCurrentProcess()->HasSwitch( | 243 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 244 switches::kEnableAudibleNotifications)) { | 244 switches::kEnableAudibleNotifications)) { |
| 245 media_observer->OnAudioStreamPlayingChanged( | 245 media_observer->OnAudioStreamPlayingChanged( |
| 246 render_process_id_, entry->render_view_id(), entry->stream_id(), | 246 render_process_id_, entry->render_view_id(), entry->stream_id(), |
| 247 is_audible); | 247 true, power_in_dbfs); |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 } | 250 } |
| 251 | 251 |
| 252 /////////////////////////////////////////////////////////////////////////////// | 252 /////////////////////////////////////////////////////////////////////////////// |
| 253 // IPC Messages handler | 253 // IPC Messages handler |
| 254 bool AudioRendererHost::OnMessageReceived(const IPC::Message& message, | 254 bool AudioRendererHost::OnMessageReceived(const IPC::Message& message, |
| 255 bool* message_was_ok) { | 255 bool* message_was_ok) { |
| 256 bool handled = true; | 256 bool handled = true; |
| 257 IPC_BEGIN_MESSAGE_MAP_EX(AudioRendererHost, message, *message_was_ok) | 257 IPC_BEGIN_MESSAGE_MAP_EX(AudioRendererHost, message, *message_was_ok) |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 } | 395 } |
| 396 | 396 |
| 397 void AudioRendererHost::DeleteEntry(scoped_ptr<AudioEntry> entry) { | 397 void AudioRendererHost::DeleteEntry(scoped_ptr<AudioEntry> entry) { |
| 398 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 398 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 399 | 399 |
| 400 // At this point, make the final "say" in audio playback state. | 400 // At this point, make the final "say" in audio playback state. |
| 401 MediaObserver* const media_observer = | 401 MediaObserver* const media_observer = |
| 402 GetContentClient()->browser()->GetMediaObserver(); | 402 GetContentClient()->browser()->GetMediaObserver(); |
| 403 if (media_observer) { | 403 if (media_observer) { |
| 404 media_observer->OnAudioStreamPlayingChanged( | 404 media_observer->OnAudioStreamPlayingChanged( |
| 405 render_process_id_, entry->render_view_id(), entry->stream_id(), false); | 405 render_process_id_, entry->render_view_id(), entry->stream_id(), |
| 406 false, -std::numeric_limits<float>::infinity()); |
| 406 } | 407 } |
| 407 | 408 |
| 408 // Notify the media observer. | 409 // Notify the media observer. |
| 409 if (media_internals_) | 410 if (media_internals_) |
| 410 media_internals_->OnDeleteAudioStream(this, entry->stream_id()); | 411 media_internals_->OnDeleteAudioStream(this, entry->stream_id()); |
| 411 | 412 |
| 412 // Note: |entry| will be deleted upon leaving this scope. | 413 // Note: |entry| will be deleted upon leaving this scope. |
| 413 } | 414 } |
| 414 | 415 |
| 415 void AudioRendererHost::ReportErrorAndClose(int stream_id) { | 416 void AudioRendererHost::ReportErrorAndClose(int stream_id) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 430 } | 431 } |
| 431 | 432 |
| 432 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { | 433 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { |
| 433 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 434 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 434 | 435 |
| 435 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id); | 436 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id); |
| 436 return i != audio_entries_.end() ? i->second : NULL; | 437 return i != audio_entries_.end() ? i->second : NULL; |
| 437 } | 438 } |
| 438 | 439 |
| 439 } // namespace content | 440 } // namespace content |
| OLD | NEW |