Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1432)

Side by Side Diff: content/browser/renderer_host/media/audio_renderer_host.cc

Issue 1383123003: Revert of Fixed the audio backgrounding bug (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
117 } // namespace 107 } // namespace
118 108
119 class AudioRendererHost::AudioEntry 109 class AudioRendererHost::AudioEntry
120 : public media::AudioOutputController::EventHandler { 110 : public media::AudioOutputController::EventHandler {
121 public: 111 public:
122 AudioEntry(AudioRendererHost* host, 112 AudioEntry(AudioRendererHost* host,
123 int stream_id, 113 int stream_id,
124 int render_frame_id, 114 int render_frame_id,
125 const media::AudioParameters& params, 115 const media::AudioParameters& params,
126 const std::string& output_device_id, 116 const std::string& output_device_id,
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 DCHECK_CURRENTLY_ON(BrowserThread::IO); 749 DCHECK_CURRENTLY_ON(BrowserThread::IO);
760 if (entry->playing() == is_playing) 750 if (entry->playing() == is_playing)
761 return; 751 return;
762 752
763 bool should_alert_resource_scheduler; 753 bool should_alert_resource_scheduler;
764 if (is_playing) { 754 if (is_playing) {
765 should_alert_resource_scheduler = 755 should_alert_resource_scheduler =
766 !RenderFrameHasActiveAudio(entry->render_frame_id()); 756 !RenderFrameHasActiveAudio(entry->render_frame_id());
767 entry->set_playing(true); 757 entry->set_playing(true);
768 base::AtomicRefCountInc(&num_playing_streams_); 758 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 }
778 } else { 759 } else {
779 entry->set_playing(false); 760 entry->set_playing(false);
780 should_alert_resource_scheduler = 761 should_alert_resource_scheduler =
781 !RenderFrameHasActiveAudio(entry->render_frame_id()); 762 !RenderFrameHasActiveAudio(entry->render_frame_id());
782 763 base::AtomicRefCountDec(&num_playing_streams_);
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 }
790 } 764 }
791 765
792 if (should_alert_resource_scheduler && ResourceDispatcherHostImpl::Get()) { 766 if (should_alert_resource_scheduler && ResourceDispatcherHostImpl::Get()) {
793 BrowserThread::PostTaskAndReplyWithResult( 767 BrowserThread::PostTaskAndReplyWithResult(
794 BrowserThread::UI, FROM_HERE, 768 BrowserThread::UI, FROM_HERE,
795 base::Bind(&RenderFrameIdToRenderViewId, render_process_id_, 769 base::Bind(&RenderFrameIdToRenderViewId, render_process_id_,
796 entry->render_frame_id()), 770 entry->render_frame_id()),
797 base::Bind(&NotifyResourceDispatcherOfAudioStateChange, 771 base::Bind(&NotifyResourceDispatcherOfAudioStateChange,
798 render_process_id_, is_playing)); 772 render_process_id_, is_playing));
799 } 773 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 callback.Run(success, *new_info); 910 callback.Run(success, *new_info);
937 } 911 }
938 912
939 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { 913 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) {
940 DCHECK_CURRENTLY_ON(BrowserThread::IO); 914 DCHECK_CURRENTLY_ON(BrowserThread::IO);
941 const auto& i = authorizations_.find(stream_id); 915 const auto& i = authorizations_.find(stream_id);
942 return i != authorizations_.end(); 916 return i != authorizations_.end();
943 } 917 }
944 918
945 } // namespace content 919 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/audio_renderer_host.h ('k') | content/browser/renderer_host/render_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698