diff options
author | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-14 01:11:25 +0000 |
---|---|---|
committer | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-14 01:11:25 +0000 |
commit | 6f0321a0afe77f052ade3c9848edf0b56409e4c8 (patch) | |
tree | bf7de722b70bb89042839714bf37d2b9ac68178c /content | |
parent | 45a6ee05b536b41be6a218a994318bca50a5d86c (diff) | |
download | chromium_src-6f0321a0afe77f052ade3c9848edf0b56409e4c8.zip chromium_src-6f0321a0afe77f052ade3c9848edf0b56409e4c8.tar.gz chromium_src-6f0321a0afe77f052ade3c9848edf0b56409e4c8.tar.bz2 |
Add a method to tab_utils.h to find out whether a tab is playing audio.
BUG=3541
Review URL: https://chromiumcodereview.appspot.com/11573066
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182364 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/browser/renderer_host/media/audio_renderer_host.cc | 39 | ||||
-rw-r--r-- | content/browser/renderer_host/media/mock_media_observer.h | 5 | ||||
-rw-r--r-- | content/public/browser/media_observer.h | 7 |
3 files changed, 49 insertions, 2 deletions
diff --git a/content/browser/renderer_host/media/audio_renderer_host.cc b/content/browser/renderer_host/media/audio_renderer_host.cc index 6c028bb..f57d182 100644 --- a/content/browser/renderer_host/media/audio_renderer_host.cc +++ b/content/browser/renderer_host/media/audio_renderer_host.cc @@ -13,6 +13,8 @@ #include "content/browser/renderer_host/media/audio_mirroring_manager.h" #include "content/browser/renderer_host/media/audio_sync_reader.h" #include "content/common/media/audio_messages.h" +#include "content/public/browser/content_browser_client.h" +#include "content/public/browser/media_observer.h" #include "media/audio/shared_memory_util.h" #include "media/base/audio_bus.h" #include "media/base/limits.h" @@ -332,6 +334,9 @@ void AudioRendererHost::OnAssociateStreamWithProducer(int stream_id, if (entry->render_view_id == render_view_id) return; + // TODO(miu): Merge "AssociateWithProducer" message into "CreateStream" + // message so AudioRendererHost can assume a simpler "render_view_id is set + // once" scheme. http://crbug.com/166779 if (mirroring_manager_) { mirroring_manager_->RemoveDiverter( render_process_id_, entry->render_view_id, entry->controller); @@ -355,6 +360,13 @@ void AudioRendererHost::OnPlayStream(int stream_id) { entry->controller->Play(); if (media_internals_) media_internals_->OnSetAudioStreamPlaying(this, stream_id, true); + + MediaObserver* media_observer = + GetContentClient()->browser()->GetMediaObserver(); + if (media_observer) { + media_observer->OnAudioStreamPlayingChanged( + render_process_id_, entry->render_view_id, stream_id, true); + } } void AudioRendererHost::OnPauseStream(int stream_id) { @@ -369,6 +381,13 @@ void AudioRendererHost::OnPauseStream(int stream_id) { entry->controller->Pause(); if (media_internals_) media_internals_->OnSetAudioStreamPlaying(this, stream_id, false); + + MediaObserver* media_observer = + GetContentClient()->browser()->GetMediaObserver(); + if (media_observer) { + media_observer->OnAudioStreamPlayingChanged( + render_process_id_, entry->render_view_id, stream_id, false); + } } void AudioRendererHost::OnFlushStream(int stream_id) { @@ -393,8 +412,10 @@ void AudioRendererHost::OnCloseStream(int stream_id) { AudioEntry* entry = LookupById(stream_id); - if (entry) - CloseAndDeleteStream(entry); + if (!entry) + return; + + CloseAndDeleteStream(entry); } void AudioRendererHost::OnSetVolume(int stream_id, double volume) { @@ -412,6 +433,14 @@ void AudioRendererHost::OnSetVolume(int stream_id, double volume) { entry->controller->SetVolume(volume); if (media_internals_) media_internals_->OnSetAudioStreamVolume(this, stream_id, volume); + + MediaObserver* media_observer = + GetContentClient()->browser()->GetMediaObserver(); + if (media_observer) { + bool playing = volume > 0; + media_observer->OnAudioStreamPlayingChanged( + render_process_id_, entry->render_view_id, stream_id, playing); + } } void AudioRendererHost::SendErrorMessage(int32 stream_id) { @@ -431,6 +460,12 @@ void AudioRendererHost::DeleteEntries() { void AudioRendererHost::CloseAndDeleteStream(AudioEntry* entry) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + MediaObserver* media_observer = + GetContentClient()->browser()->GetMediaObserver(); + if (media_observer) { + media_observer->OnAudioStreamPlayingChanged( + render_process_id_, entry->render_view_id, entry->stream_id, false); + } if (!entry->pending_close) { if (mirroring_manager_) { mirroring_manager_->RemoveDiverter( diff --git a/content/browser/renderer_host/media/mock_media_observer.h b/content/browser/renderer_host/media/mock_media_observer.h index 3c97f0a..f2a7bd7 100644 --- a/content/browser/renderer_host/media/mock_media_observer.h +++ b/content/browser/renderer_host/media/mock_media_observer.h @@ -34,6 +34,11 @@ class MockMediaObserver : public MediaObserver { void(int render_process_id, int render_view_id, const MediaStreamDevice& device, const MediaRequestState state)); + MOCK_METHOD4(OnAudioStreamPlayingChanged, + void(int render_process_id, + int render_view_id, + int stream_id, + bool playing)); }; class MockMediaInternals : public MediaInternals { diff --git a/content/public/browser/media_observer.h b/content/public/browser/media_observer.h index 4bf7c00..c1727df 100644 --- a/content/public/browser/media_observer.h +++ b/content/public/browser/media_observer.h @@ -41,6 +41,13 @@ class MediaObserver { const MediaStreamDevice& device, MediaRequestState state) = 0; + // Called when an audio stream is played or paused. + virtual void OnAudioStreamPlayingChanged( + int render_process_id, + int render_view_id, + int stream_id, + bool playing) = 0; + protected: virtual ~MediaObserver() {} }; |