Chromium Code Reviews| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 bool is_playing, | 54 bool is_playing, |
| 55 int render_view_id) { | 55 int render_view_id) { |
| 56 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 56 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 57 if (render_view_id == MSG_ROUTING_NONE || !ResourceDispatcherHostImpl::Get()) | 57 if (render_view_id == MSG_ROUTING_NONE || !ResourceDispatcherHostImpl::Get()) |
| 58 return; | 58 return; |
| 59 | 59 |
| 60 ResourceDispatcherHostImpl::Get()->OnAudioRenderHostStreamStateChanged( | 60 ResourceDispatcherHostImpl::Get()->OnAudioRenderHostStreamStateChanged( |
| 61 render_process_id, render_view_id, is_playing); | 61 render_process_id, render_view_id, is_playing); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void NotifyRenderProcessHostThatAudioStarted(int render_process_id) { | |
| 65 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 66 | |
| 67 RenderProcessHost* render_process_host = | |
| 68 RenderProcessHost::FromID(render_process_id); | |
| 69 | |
| 70 if (render_process_host) | |
| 71 render_process_host->AudioStarted(); | |
| 72 } | |
| 73 | |
| 74 void NotifyRenderProcessHostThatAudioStopped(int render_process_id) { | |
| 75 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 76 | |
| 77 RenderProcessHost* render_process_host = | |
| 78 RenderProcessHost::FromID(render_process_id); | |
| 79 | |
| 80 if (render_process_host) | |
| 81 render_process_host->AudioStopped(); | |
| 82 } | |
| 83 | |
| 64 } // namespace | 84 } // namespace |
| 65 | 85 |
| 66 class AudioRendererHost::AudioEntry | 86 class AudioRendererHost::AudioEntry |
| 67 : public media::AudioOutputController::EventHandler { | 87 : public media::AudioOutputController::EventHandler { |
| 68 public: | 88 public: |
| 69 AudioEntry(AudioRendererHost* host, | 89 AudioEntry(AudioRendererHost* host, |
| 70 int stream_id, | 90 int stream_id, |
| 71 int render_frame_id, | 91 int render_frame_id, |
| 72 const media::AudioParameters& params, | 92 const media::AudioParameters& params, |
| 73 const std::string& output_device_id, | 93 const std::string& output_device_id, |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 644 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 664 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 645 if (entry->playing() == is_playing) | 665 if (entry->playing() == is_playing) |
| 646 return; | 666 return; |
| 647 | 667 |
| 648 bool should_alert_resource_scheduler; | 668 bool should_alert_resource_scheduler; |
| 649 if (is_playing) { | 669 if (is_playing) { |
| 650 should_alert_resource_scheduler = | 670 should_alert_resource_scheduler = |
| 651 !RenderFrameHasActiveAudio(entry->render_frame_id()); | 671 !RenderFrameHasActiveAudio(entry->render_frame_id()); |
| 652 entry->set_playing(true); | 672 entry->set_playing(true); |
| 653 base::AtomicRefCountInc(&num_playing_streams_); | 673 base::AtomicRefCountInc(&num_playing_streams_); |
| 674 | |
| 675 // Inform the renderer that audio started playing for the first time so the | |
|
gab
2015/07/02 13:11:53
s/renderer/renderer host/
gab
2015/07/02 13:11:53
Since this comment is outside the "if", I'd s/that
sebsg
2015/07/06 18:24:53
Done.
sebsg
2015/07/06 18:24:53
Done.
| |
| 676 // process can be un-backgrounded if necessary. | |
|
gab
2015/07/02 13:11:53
Remove " so the process can be...". What the Rende
sebsg
2015/07/06 18:24:53
Done.
| |
| 677 if (base::AtomicRefCountIsOne(&num_playing_streams_)) { | |
|
gab
2015/07/06 17:24:09
Note that this depends on this thread being the on
sebsg
2015/07/06 18:24:53
Done.
| |
| 678 BrowserThread::PostTask( | |
| 679 BrowserThread::UI, FROM_HERE, | |
| 680 base::Bind(&NotifyRenderProcessHostThatAudioStarted, | |
| 681 render_process_id_)); | |
| 682 } | |
| 654 } else { | 683 } else { |
| 655 entry->set_playing(false); | 684 entry->set_playing(false); |
| 656 should_alert_resource_scheduler = | 685 should_alert_resource_scheduler = |
| 657 !RenderFrameHasActiveAudio(entry->render_frame_id()); | 686 !RenderFrameHasActiveAudio(entry->render_frame_id()); |
| 658 base::AtomicRefCountDec(&num_playing_streams_); | 687 |
| 688 // Inform the renderer that there is no more audio playing so the process | |
|
gab
2015/07/02 13:11:53
s/that there is/when there is/
sebsg
2015/07/06 18:24:53
Done.
| |
| 689 // can be backgrounded if possible. | |
|
gab
2015/07/02 13:11:53
Remove " so the process (...)".
sebsg
2015/07/06 18:24:53
Done.
| |
| 690 if (!base::AtomicRefCountDec(&num_playing_streams_)) { | |
| 691 BrowserThread::PostTask( | |
| 692 BrowserThread::UI, FROM_HERE, | |
| 693 base::Bind(&NotifyRenderProcessHostThatAudioStopped, | |
| 694 render_process_id_)); | |
| 695 } | |
| 659 } | 696 } |
| 660 | 697 |
| 661 if (should_alert_resource_scheduler && ResourceDispatcherHostImpl::Get()) { | 698 if (should_alert_resource_scheduler && ResourceDispatcherHostImpl::Get()) { |
| 662 BrowserThread::PostTaskAndReplyWithResult( | 699 BrowserThread::PostTaskAndReplyWithResult( |
| 663 BrowserThread::UI, FROM_HERE, | 700 BrowserThread::UI, FROM_HERE, |
| 664 base::Bind(&RenderFrameIdToRenderViewId, render_process_id_, | 701 base::Bind(&RenderFrameIdToRenderViewId, render_process_id_, |
| 665 entry->render_frame_id()), | 702 entry->render_frame_id()), |
| 666 base::Bind(&NotifyResourceDispatcherOfAudioStateChange, | 703 base::Bind(&NotifyResourceDispatcherOfAudioStateChange, |
| 667 render_process_id_, is_playing)); | 704 render_process_id_, is_playing)); |
| 668 } | 705 } |
| 669 } | 706 } |
| 670 | 707 |
| 671 bool AudioRendererHost::HasActiveAudio() { | 708 bool AudioRendererHost::HasActiveAudio() { |
| 672 return !base::AtomicRefCountIsZero(&num_playing_streams_); | 709 return !base::AtomicRefCountIsZero(&num_playing_streams_); |
| 673 } | 710 } |
| 674 | 711 |
| 675 bool AudioRendererHost::RenderFrameHasActiveAudio(int render_frame_id) const { | 712 bool AudioRendererHost::RenderFrameHasActiveAudio(int render_frame_id) const { |
| 676 for (AudioEntryMap::const_iterator it = audio_entries_.begin(); | 713 for (AudioEntryMap::const_iterator it = audio_entries_.begin(); |
| 677 it != audio_entries_.end(); | 714 it != audio_entries_.end(); |
| 678 ++it) { | 715 ++it) { |
| 679 AudioEntry* entry = it->second; | 716 AudioEntry* entry = it->second; |
| 680 if (entry->render_frame_id() == render_frame_id && entry->playing()) | 717 if (entry->render_frame_id() == render_frame_id && entry->playing()) |
| 681 return true; | 718 return true; |
| 682 } | 719 } |
| 683 return false; | 720 return false; |
| 684 } | 721 } |
| 685 | 722 |
| 686 } // namespace content | 723 } // namespace content |
| OLD | NEW |