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

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

Issue 1214883004: Fixed the audio backgrounding bug (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments 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
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 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 DCHECK_CURRENTLY_ON(BrowserThread::IO); 747 DCHECK_CURRENTLY_ON(BrowserThread::IO);
738 if (entry->playing() == is_playing) 748 if (entry->playing() == is_playing)
739 return; 749 return;
740 750
741 bool should_alert_resource_scheduler; 751 bool should_alert_resource_scheduler;
742 if (is_playing) { 752 if (is_playing) {
743 should_alert_resource_scheduler = 753 should_alert_resource_scheduler =
744 !RenderFrameHasActiveAudio(entry->render_frame_id()); 754 !RenderFrameHasActiveAudio(entry->render_frame_id());
745 entry->set_playing(true); 755 entry->set_playing(true);
746 base::AtomicRefCountInc(&num_playing_streams_); 756 base::AtomicRefCountInc(&num_playing_streams_);
757
758 // Inform the RenderProcessHost when audio starts playing for the first
759 // time.
760 if (base::AtomicRefCountIsOne(&num_playing_streams_)) {
761 BrowserThread::PostTask(
762 BrowserThread::UI, FROM_HERE,
763 base::Bind(&NotifyRenderProcessHostThatAudioStateChanged,
764 render_process_id_));
765 }
747 } else { 766 } else {
748 entry->set_playing(false); 767 entry->set_playing(false);
749 should_alert_resource_scheduler = 768 should_alert_resource_scheduler =
750 !RenderFrameHasActiveAudio(entry->render_frame_id()); 769 !RenderFrameHasActiveAudio(entry->render_frame_id());
751 base::AtomicRefCountDec(&num_playing_streams_); 770
771 // Inform the RenderProcessHost when there is no more audio playing.
772 if (!base::AtomicRefCountDec(&num_playing_streams_)) {
773 BrowserThread::PostTask(
774 BrowserThread::UI, FROM_HERE,
775 base::Bind(&NotifyRenderProcessHostThatAudioStateChanged,
776 render_process_id_));
777 }
752 } 778 }
753 779
754 if (should_alert_resource_scheduler && ResourceDispatcherHostImpl::Get()) { 780 if (should_alert_resource_scheduler && ResourceDispatcherHostImpl::Get()) {
755 BrowserThread::PostTaskAndReplyWithResult( 781 BrowserThread::PostTaskAndReplyWithResult(
756 BrowserThread::UI, FROM_HERE, 782 BrowserThread::UI, FROM_HERE,
757 base::Bind(&RenderFrameIdToRenderViewId, render_process_id_, 783 base::Bind(&RenderFrameIdToRenderViewId, render_process_id_,
758 entry->render_frame_id()), 784 entry->render_frame_id()),
759 base::Bind(&NotifyResourceDispatcherOfAudioStateChange, 785 base::Bind(&NotifyResourceDispatcherOfAudioStateChange,
760 render_process_id_, is_playing)); 786 render_process_id_, is_playing));
761 } 787 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 callback.Run(success, *new_info); 924 callback.Run(success, *new_info);
899 } 925 }
900 926
901 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { 927 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) {
902 DCHECK_CURRENTLY_ON(BrowserThread::IO); 928 DCHECK_CURRENTLY_ON(BrowserThread::IO);
903 const auto& i = authorizations_.find(stream_id); 929 const auto& i = authorizations_.find(stream_id);
904 return i != authorizations_.end(); 930 return i != authorizations_.end();
905 } 931 }
906 932
907 } // namespace content 933 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698