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 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 644 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 644 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 645 if (entry->playing() == is_playing) | 645 if (entry->playing() == is_playing) |
| 646 return; | 646 return; |
| 647 | 647 |
| 648 bool should_alert_resource_scheduler; | 648 bool should_alert_resource_scheduler; |
| 649 if (is_playing) { | 649 if (is_playing) { |
| 650 should_alert_resource_scheduler = | 650 should_alert_resource_scheduler = |
| 651 !RenderFrameHasActiveAudio(entry->render_frame_id()); | 651 !RenderFrameHasActiveAudio(entry->render_frame_id()); |
| 652 entry->set_playing(true); | 652 entry->set_playing(true); |
| 653 base::AtomicRefCountInc(&num_playing_streams_); | 653 base::AtomicRefCountInc(&num_playing_streams_); |
| 654 | |
| 655 // If it's the first audio stream to start for this renderer. | |
| 656 if (base::AtomicRefCountIsOne(&num_playing_streams_)) { | |
| 657 RenderProcessHost* render_process_host = | |
| 658 RenderProcessHost::FromID(render_process_id_); | |
| 659 | |
| 660 BrowserThread::PostTask( | |
| 661 BrowserThread::UI, FROM_HERE, | |
| 662 base::Bind(&RenderProcessHost::AudioStarted, | |
| 663 base::Unretained(render_process_host))); | |
| 664 } | |
| 654 } else { | 665 } else { |
| 655 entry->set_playing(false); | 666 entry->set_playing(false); |
| 656 should_alert_resource_scheduler = | 667 should_alert_resource_scheduler = |
| 657 !RenderFrameHasActiveAudio(entry->render_frame_id()); | 668 !RenderFrameHasActiveAudio(entry->render_frame_id()); |
| 658 base::AtomicRefCountDec(&num_playing_streams_); | 669 base::AtomicRefCountDec(&num_playing_streams_); |
| 670 | |
| 671 // If it was the last audio stream playing for this renderer. | |
| 672 if (base::AtomicRefCountIsZero(&num_playing_streams_)) { | |
|
DaleCurtis
2015/06/29 22:21:40
You can use the result of AtomicRefCountDec instea
sebsg
2015/06/29 22:35:00
Done.
| |
| 673 RenderProcessHost* render_process_host = | |
| 674 RenderProcessHost::FromID(render_process_id_); | |
| 675 | |
| 676 BrowserThread::PostTask( | |
| 677 BrowserThread::UI, FROM_HERE, | |
| 678 base::Bind(&RenderProcessHost::AudioStopped, | |
| 679 base::Unretained(render_process_host))); | |
| 680 } | |
| 659 } | 681 } |
| 660 | 682 |
| 661 if (should_alert_resource_scheduler && ResourceDispatcherHostImpl::Get()) { | 683 if (should_alert_resource_scheduler && ResourceDispatcherHostImpl::Get()) { |
| 662 BrowserThread::PostTaskAndReplyWithResult( | 684 BrowserThread::PostTaskAndReplyWithResult( |
| 663 BrowserThread::UI, FROM_HERE, | 685 BrowserThread::UI, FROM_HERE, |
| 664 base::Bind(&RenderFrameIdToRenderViewId, render_process_id_, | 686 base::Bind(&RenderFrameIdToRenderViewId, render_process_id_, |
| 665 entry->render_frame_id()), | 687 entry->render_frame_id()), |
| 666 base::Bind(&NotifyResourceDispatcherOfAudioStateChange, | 688 base::Bind(&NotifyResourceDispatcherOfAudioStateChange, |
| 667 render_process_id_, is_playing)); | 689 render_process_id_, is_playing)); |
| 668 } | 690 } |
| 669 } | 691 } |
| 670 | 692 |
| 671 bool AudioRendererHost::HasActiveAudio() { | 693 bool AudioRendererHost::HasActiveAudio() { |
| 672 return !base::AtomicRefCountIsZero(&num_playing_streams_); | 694 return !base::AtomicRefCountIsZero(&num_playing_streams_); |
| 673 } | 695 } |
| 674 | 696 |
| 675 bool AudioRendererHost::RenderFrameHasActiveAudio(int render_frame_id) const { | 697 bool AudioRendererHost::RenderFrameHasActiveAudio(int render_frame_id) const { |
| 676 for (AudioEntryMap::const_iterator it = audio_entries_.begin(); | 698 for (AudioEntryMap::const_iterator it = audio_entries_.begin(); |
| 677 it != audio_entries_.end(); | 699 it != audio_entries_.end(); |
| 678 ++it) { | 700 ++it) { |
| 679 AudioEntry* entry = it->second; | 701 AudioEntry* entry = it->second; |
| 680 if (entry->render_frame_id() == render_frame_id && entry->playing()) | 702 if (entry->render_frame_id() == render_frame_id && entry->playing()) |
| 681 return true; | 703 return true; |
| 682 } | 704 } |
| 683 return false; | 705 return false; |
| 684 } | 706 } |
| 685 | 707 |
| 686 } // namespace content | 708 } // namespace content |
| OLD | NEW |