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

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

Issue 2578983003: Add AudioStreamRegistry. Move stream counting logic (Closed)
Patch Set: Remove active audio tracking from ARH to see what tests break. Created 3 years, 11 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/renderer_host/media/audio_stream_registry_impl.h"
6
7 #include <algorithm>
8
9 #include "base/lazy_instance.h"
10 #include "base/metrics/histogram_macros.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/render_process_host.h"
13 #include "media/audio/audio_streams_tracker.h"
14
15 namespace content {
16
17 namespace {
18
19 base::LazyInstance<media::AudioStreamsTracker> g_audio_output_streams_tracker =
20 LAZY_INSTANCE_INITIALIZER;
21
22 void NotifyRenderProcessHostThatAudioStateChanged(int render_process_id) {
23 DCHECK_CURRENTLY_ON(BrowserThread::UI);
24
25 RenderProcessHost* render_process_host =
26 RenderProcessHost::FromID(render_process_id);
27
28 if (render_process_host)
29 ;
30 //render_process_host->AudioStateChanged();
31 }
32
33 } // namespace
34
35 AudioStreamRegistryImpl::AudioStreamRegistryImpl(int render_process_id)
36 : render_process_id_(render_process_id) {}
37
38 AudioStreamRegistryImpl::~AudioStreamRegistryImpl() {
39 DCHECK_CURRENTLY_ON(BrowserThread::IO);
40 DCHECK_EQ(num_output_streams_, 0);
41 DCHECK_EQ(num_playing_output_streams_, 0);
42
43 if (max_simultaneous_output_streams_ > 0) {
44 UMA_HISTOGRAM_CUSTOM_COUNTS("Media.AudioRendererIpcStreams",
45 max_simultaneous_output_streams_, 1, 50, 51);
46 UMA_HISTOGRAM_CUSTOM_COUNTS(
47 "Media.AudioRendererIpcStreamsTotal",
48 g_audio_output_streams_tracker.Get().max_stream_count(), 1, 100, 101);
49 g_audio_output_streams_tracker.Get().ResetMaxStreamCount();
50 }
51 }
52
53 // static
54 AudioStreamRegistryImpl::UniquePtr AudioStreamRegistryImpl::Create(
55 int render_process_id) {
56 return {new AudioStreamRegistryImpl(render_process_id), {}};
57 }
58
59 bool AudioStreamRegistryImpl::HasActiveAudio() {
60 return false;
61 //return !base::AtomicRefCountIsZero(&num_playing_output_streams_);
62 }
63
64 void AudioStreamRegistryImpl::RegisterStream() {
65 DCHECK_CURRENTLY_ON(BrowserThread::IO);
66 ++num_output_streams_;
67 max_simultaneous_output_streams_ =
68 std::max(max_simultaneous_output_streams_, num_output_streams_);
69 g_audio_output_streams_tracker.Get().IncreaseStreamCount();
70 }
71
72 void AudioStreamRegistryImpl::DeregisterStream() {
73 DCHECK_CURRENTLY_ON(BrowserThread::IO);
74 DCHECK_GT(num_output_streams_, 0);
75 --num_output_streams_;
76 g_audio_output_streams_tracker.Get().DecreaseStreamCount();
77 }
78
79 void AudioStreamRegistryImpl::StreamStateChanged(bool playing) {
80 DCHECK_CURRENTLY_ON(BrowserThread::IO);
81 if (playing) {
82 base::AtomicRefCountInc(&num_playing_output_streams_);
83
84 // Inform the RenderProcessHost when audio starts playing for the first
85 // time. The nonatomic increment-and-read is ok since this is the only
86 // thread that |num_playing_output_streams_| may be updated on.
87 if (base::AtomicRefCountIsOne(&num_playing_output_streams_)) {
88 BrowserThread::PostTask(
89 BrowserThread::UI, FROM_HERE,
90 base::Bind(&NotifyRenderProcessHostThatAudioStateChanged,
91 render_process_id_));
92 }
93 } else {
94 // Inform the RenderProcessHost when there is no more audio playing.
95 DCHECK(!base::AtomicRefCountIsZero(&num_playing_output_streams_));
96 if (!base::AtomicRefCountDec(&num_playing_output_streams_)) {
97 BrowserThread::PostTask(
98 BrowserThread::UI, FROM_HERE,
99 base::Bind(&NotifyRenderProcessHostThatAudioStateChanged,
100 render_process_id_));
101 }
102 }
103 DCHECK_LE(num_playing_output_streams_, num_output_streams_);
104 }
105
106 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698