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/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 } | 97 } |
98 | 98 |
99 return true; | 99 return true; |
100 } | 100 } |
101 | 101 |
102 std::string TranslateDefaultId(const std::string& device_id) { | 102 std::string TranslateDefaultId(const std::string& device_id) { |
103 return device_id.empty() ? media::AudioManagerBase::kDefaultDeviceId | 103 return device_id.empty() ? media::AudioManagerBase::kDefaultDeviceId |
104 : device_id; | 104 : device_id; |
105 } | 105 } |
106 | 106 |
| 107 void NotifyRenderProcessHostThatAudioStateChanged(int render_process_id) { |
| 108 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 109 |
| 110 RenderProcessHost* render_process_host = |
| 111 RenderProcessHost::FromID(render_process_id); |
| 112 |
| 113 if (render_process_host) |
| 114 render_process_host->AudioStateChanged(); |
| 115 } |
| 116 |
107 } // namespace | 117 } // namespace |
108 | 118 |
109 class AudioRendererHost::AudioEntry | 119 class AudioRendererHost::AudioEntry |
110 : public media::AudioOutputController::EventHandler { | 120 : public media::AudioOutputController::EventHandler { |
111 public: | 121 public: |
112 AudioEntry(AudioRendererHost* host, | 122 AudioEntry(AudioRendererHost* host, |
113 int stream_id, | 123 int stream_id, |
114 int render_frame_id, | 124 int render_frame_id, |
115 const media::AudioParameters& params, | 125 const media::AudioParameters& params, |
116 const std::string& output_device_id, | 126 const std::string& output_device_id, |
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 759 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
750 if (entry->playing() == is_playing) | 760 if (entry->playing() == is_playing) |
751 return; | 761 return; |
752 | 762 |
753 bool should_alert_resource_scheduler; | 763 bool should_alert_resource_scheduler; |
754 if (is_playing) { | 764 if (is_playing) { |
755 should_alert_resource_scheduler = | 765 should_alert_resource_scheduler = |
756 !RenderFrameHasActiveAudio(entry->render_frame_id()); | 766 !RenderFrameHasActiveAudio(entry->render_frame_id()); |
757 entry->set_playing(true); | 767 entry->set_playing(true); |
758 base::AtomicRefCountInc(&num_playing_streams_); | 768 base::AtomicRefCountInc(&num_playing_streams_); |
| 769 |
| 770 // Inform the RenderProcessHost when audio starts playing for the first |
| 771 // time. |
| 772 if (base::AtomicRefCountIsOne(&num_playing_streams_)) { |
| 773 BrowserThread::PostTask( |
| 774 BrowserThread::UI, FROM_HERE, |
| 775 base::Bind(&NotifyRenderProcessHostThatAudioStateChanged, |
| 776 render_process_id_)); |
| 777 } |
759 } else { | 778 } else { |
760 entry->set_playing(false); | 779 entry->set_playing(false); |
761 should_alert_resource_scheduler = | 780 should_alert_resource_scheduler = |
762 !RenderFrameHasActiveAudio(entry->render_frame_id()); | 781 !RenderFrameHasActiveAudio(entry->render_frame_id()); |
763 base::AtomicRefCountDec(&num_playing_streams_); | 782 |
| 783 // Inform the RenderProcessHost when there is no more audio playing. |
| 784 if (!base::AtomicRefCountDec(&num_playing_streams_)) { |
| 785 BrowserThread::PostTask( |
| 786 BrowserThread::UI, FROM_HERE, |
| 787 base::Bind(&NotifyRenderProcessHostThatAudioStateChanged, |
| 788 render_process_id_)); |
| 789 } |
764 } | 790 } |
765 | 791 |
766 if (should_alert_resource_scheduler && ResourceDispatcherHostImpl::Get()) { | 792 if (should_alert_resource_scheduler && ResourceDispatcherHostImpl::Get()) { |
767 BrowserThread::PostTaskAndReplyWithResult( | 793 BrowserThread::PostTaskAndReplyWithResult( |
768 BrowserThread::UI, FROM_HERE, | 794 BrowserThread::UI, FROM_HERE, |
769 base::Bind(&RenderFrameIdToRenderViewId, render_process_id_, | 795 base::Bind(&RenderFrameIdToRenderViewId, render_process_id_, |
770 entry->render_frame_id()), | 796 entry->render_frame_id()), |
771 base::Bind(&NotifyResourceDispatcherOfAudioStateChange, | 797 base::Bind(&NotifyResourceDispatcherOfAudioStateChange, |
772 render_process_id_, is_playing)); | 798 render_process_id_, is_playing)); |
773 } | 799 } |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 callback.Run(success, *new_info); | 936 callback.Run(success, *new_info); |
911 } | 937 } |
912 | 938 |
913 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { | 939 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { |
914 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 940 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
915 const auto& i = authorizations_.find(stream_id); | 941 const auto& i = authorizations_.find(stream_id); |
916 return i != authorizations_.end(); | 942 return i != authorizations_.end(); |
917 } | 943 } |
918 | 944 |
919 } // namespace content | 945 } // namespace content |
OLD | NEW |