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

Side by Side Diff: content/browser/media/audio_stream_monitor.h

Issue 2496173003: Communicate audio state to renderer process on Android. (Closed)
Patch Set: Second iteration Created 4 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef CONTENT_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_ 5 #ifndef CONTENT_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_
6 #define CONTENT_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_ 6 #define CONTENT_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_
7 7
8 #include <map> 8 #include <map>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 16 matching lines...) Expand all
27 class WebContents; 27 class WebContents;
28 28
29 // Repeatedly polls audio streams for their power levels, and "debounces" the 29 // Repeatedly polls audio streams for their power levels, and "debounces" the
30 // information into a simple, binary "was recently audible" result for the audio 30 // information into a simple, binary "was recently audible" result for the audio
31 // indicators in the tab UI. The debouncing logic is to: 1) Turn on immediately 31 // indicators in the tab UI. The debouncing logic is to: 1) Turn on immediately
32 // when sound is audible; and 2) Hold on for X amount of time after sound has 32 // when sound is audible; and 2) Hold on for X amount of time after sound has
33 // gone silent, then turn off. Said another way, we don't want tab indicators 33 // gone silent, then turn off. Said another way, we don't want tab indicators
34 // to turn on/off repeatedly and annoy the user. AudioStreamMonitor sends UI 34 // to turn on/off repeatedly and annoy the user. AudioStreamMonitor sends UI
35 // update notifications only when needed, but may be queried at any time. 35 // update notifications only when needed, but may be queried at any time.
36 // 36 //
37 // When power level monitoring is not available, audibility is approximated
38 // with having active audio streams.
39 //
37 // Each WebContentsImpl owns an AudioStreamMonitor. 40 // Each WebContentsImpl owns an AudioStreamMonitor.
38 class CONTENT_EXPORT AudioStreamMonitor { 41 class CONTENT_EXPORT AudioStreamMonitor {
39 public: 42 public:
40 explicit AudioStreamMonitor(WebContents* contents); 43 explicit AudioStreamMonitor(WebContents* contents);
41 ~AudioStreamMonitor(); 44 ~AudioStreamMonitor();
42 45
43 // Indicates if audio stream monitoring is available. It's only available if 46 // Indicates if monitoring of audio stream power level is available.
44 // AudioOutputController can and will monitor output power levels. 47 // It's only available if AudioOutputController can and will monitor
45 static bool monitoring_available() { 48 // output power levels.
49 static bool power_level_monitoring_available() {
46 return media::AudioOutputController::will_monitor_audio_levels(); 50 return media::AudioOutputController::will_monitor_audio_levels();
47 } 51 }
48 52
49 // Returns true if audio has recently been audible from the tab. This is 53 // Returns true if audio has recently been audible from the tab. This is
50 // usually called whenever the tab data model is refreshed; but there are 54 // usually called whenever the tab data model is refreshed; but there are
51 // other use cases as well (e.g., the OOM killer uses this to de-prioritize 55 // other use cases as well (e.g., the OOM killer uses this to de-prioritize
52 // the killing of tabs making sounds). 56 // the killing of tabs making sounds).
53 bool WasRecentlyAudible() const; 57 bool WasRecentlyAudible() const;
54 58
55 // Returns true if the audio is currently audible from the given WebContents. 59 // Returns true if the audio is currently audible from the given WebContents.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 116
113 // Called by |poll_timer_| to sample the power levels from each of the streams 117 // Called by |poll_timer_| to sample the power levels from each of the streams
114 // playing in the tab. 118 // playing in the tab.
115 void Poll(); 119 void Poll();
116 120
117 // Compares last known indicator state with what it should be, and triggers UI 121 // Compares last known indicator state with what it should be, and triggers UI
118 // updates through |web_contents_| if needed. When the indicator is turned 122 // updates through |web_contents_| if needed. When the indicator is turned
119 // on, |off_timer_| is started to re-invoke this method in the future. 123 // on, |off_timer_| is started to re-invoke this method in the future.
120 void MaybeToggle(); 124 void MaybeToggle();
121 125
126 // Helper functions to track number of active streams when power level
127 // monitoring
128 // is not available.
miu 2016/11/15 22:06:04 This can go on the above line.
altimin 2016/11/16 12:52:46 Done.
129 void OnStreamAdded();
130 void OnStreamRemoved();
131
122 // The WebContents instance to receive indicator toggle notifications. This 132 // The WebContents instance to receive indicator toggle notifications. This
123 // pointer should be valid for the lifetime of AudioStreamMonitor. 133 // pointer should be valid for the lifetime of AudioStreamMonitor.
124 WebContents* const web_contents_; 134 WebContents* const web_contents_;
125 135
126 // Note: |clock_| is always |&default_tick_clock_|, except during unit 136 // Note: |clock_| is always |&default_tick_clock_|, except during unit
127 // testing. 137 // testing.
128 base::DefaultTickClock default_tick_clock_; 138 base::DefaultTickClock default_tick_clock_;
129 base::TickClock* const clock_; 139 base::TickClock* const clock_;
130 140
131 // Confirms single-threaded access in debug builds. 141 // Confirms single-threaded access in debug builds.
(...skipping 15 matching lines...) Expand all
147 // Whether the WebContents is currently audible. 157 // Whether the WebContents is currently audible.
148 bool is_audible_; 158 bool is_audible_;
149 159
150 // Calls Poll() at regular intervals while |poll_callbacks_| is non-empty. 160 // Calls Poll() at regular intervals while |poll_callbacks_| is non-empty.
151 base::RepeatingTimer poll_timer_; 161 base::RepeatingTimer poll_timer_;
152 162
153 // Started only when an indicator is toggled on, to turn it off again in the 163 // Started only when an indicator is toggled on, to turn it off again in the
154 // future. 164 // future.
155 base::OneShotTimer off_timer_; 165 base::OneShotTimer off_timer_;
156 166
167 // Number of active streams to be used as a proxy for audibility when power
168 // level monitoring is not available.
169 size_t active_streams_;
170
157 DISALLOW_COPY_AND_ASSIGN(AudioStreamMonitor); 171 DISALLOW_COPY_AND_ASSIGN(AudioStreamMonitor);
158 }; 172 };
159 173
160 } // namespace content 174 } // namespace content
161 175
162 #endif // CONTENT_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_ 176 #endif // CONTENT_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/media/audio_stream_monitor.cc » ('j') | content/browser/media/audio_stream_monitor.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698