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

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

Issue 2383473002: [scheduler] Teach scheduler about audio state (Closed)
Patch Set: Created 4 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 <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 return false; 68 return false;
69 69
70 for (const char& c : device_id) { 70 for (const char& c : device_id) {
71 if ((c < 'a' || c > 'f') && (c < '0' || c > '9')) 71 if ((c < 'a' || c > 'f') && (c < '0' || c > '9'))
72 return false; 72 return false;
73 } 73 }
74 74
75 return true; 75 return true;
76 } 76 }
77 77
78 void NotifyRenderProcessHostThatAudioStateChanged(int render_process_id) { 78 void NotifyRenderProcessHostThatAudioStateChanged(int render_process_id,
79 bool is_audio_active) {
Sami 2016/09/29 13:36:07 nit: also call this is_playing? (elsewhere too)
altimin 2016/09/29 16:29:42 Done.
79 DCHECK_CURRENTLY_ON(BrowserThread::UI); 80 DCHECK_CURRENTLY_ON(BrowserThread::UI);
80 81
81 RenderProcessHost* render_process_host = 82 RenderProcessHost* render_process_host =
82 RenderProcessHost::FromID(render_process_id); 83 RenderProcessHost::FromID(render_process_id);
83 84
84 if (render_process_host) 85 if (render_process_host)
85 render_process_host->AudioStateChanged(); 86 render_process_host->AudioStateChanged(is_audio_active);
86 } 87 }
87 88
88 void MaybeFixAudioParameters(media::AudioParameters* params) { 89 void MaybeFixAudioParameters(media::AudioParameters* params) {
89 // If the number of output channels is greater than the maximum, use the 90 // If the number of output channels is greater than the maximum, use the
90 // maximum allowed value. Hardware channels are ignored upstream, so it is 91 // maximum allowed value. Hardware channels are ignored upstream, so it is
91 // better to report a valid value if this is the only problem. 92 // better to report a valid value if this is the only problem.
92 if (params->channels() > media::limits::kMaxChannels) 93 if (params->channels() > media::limits::kMaxChannels)
93 params->set_channels_for_discrete(media::limits::kMaxChannels); 94 params->set_channels_for_discrete(media::limits::kMaxChannels);
94 95
95 // If hardware parameters are still invalid, use dummy parameters with 96 // If hardware parameters are still invalid, use dummy parameters with
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 if (is_playing) { 670 if (is_playing) {
670 entry->set_playing(true); 671 entry->set_playing(true);
671 base::AtomicRefCountInc(&num_playing_streams_); 672 base::AtomicRefCountInc(&num_playing_streams_);
672 673
673 // Inform the RenderProcessHost when audio starts playing for the first 674 // Inform the RenderProcessHost when audio starts playing for the first
674 // time. 675 // time.
675 if (base::AtomicRefCountIsOne(&num_playing_streams_)) { 676 if (base::AtomicRefCountIsOne(&num_playing_streams_)) {
676 BrowserThread::PostTask( 677 BrowserThread::PostTask(
677 BrowserThread::UI, FROM_HERE, 678 BrowserThread::UI, FROM_HERE,
678 base::Bind(&NotifyRenderProcessHostThatAudioStateChanged, 679 base::Bind(&NotifyRenderProcessHostThatAudioStateChanged,
679 render_process_id_)); 680 render_process_id_, is_playing));
680 } 681 }
681 } else { 682 } else {
682 entry->set_playing(false); 683 entry->set_playing(false);
683 // Inform the RenderProcessHost when there is no more audio playing. 684 // Inform the RenderProcessHost when there is no more audio playing.
684 if (!base::AtomicRefCountDec(&num_playing_streams_)) { 685 if (!base::AtomicRefCountDec(&num_playing_streams_)) {
685 BrowserThread::PostTask( 686 BrowserThread::PostTask(
686 BrowserThread::UI, FROM_HERE, 687 BrowserThread::UI, FROM_HERE,
687 base::Bind(&NotifyRenderProcessHostThatAudioStateChanged, 688 base::Bind(&NotifyRenderProcessHostThatAudioStateChanged,
688 render_process_id_)); 689 render_process_id_, is_playing));
689 } 690 }
690 } 691 }
691 } 692 }
692 693
693 bool AudioRendererHost::HasActiveAudio() { 694 bool AudioRendererHost::HasActiveAudio() {
694 return !base::AtomicRefCountIsZero(&num_playing_streams_); 695 return !base::AtomicRefCountIsZero(&num_playing_streams_);
695 } 696 }
696 697
697 void AudioRendererHost::CheckOutputDeviceAccess( 698 void AudioRendererHost::CheckOutputDeviceAccess(
698 int render_frame_id, 699 int render_frame_id,
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 std::string() /* matched_device_id */)); 851 std::string() /* matched_device_id */));
851 } 852 }
852 853
853 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { 854 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) {
854 DCHECK_CURRENTLY_ON(BrowserThread::IO); 855 DCHECK_CURRENTLY_ON(BrowserThread::IO);
855 const auto& i = authorizations_.find(stream_id); 856 const auto& i = authorizations_.find(stream_id);
856 return i != authorizations_.end(); 857 return i != authorizations_.end();
857 } 858 }
858 859
859 } // namespace content 860 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/render_process_host_impl.h » ('j') | content/common/child_process_messages.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698