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

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

Issue 2948613002: [AudioStreamMonitor] Adds API to collect frame-level audibility. (Closed)
Patch Set: Removed public API, fixed tests Created 3 years, 6 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 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
11 #include "base/callback_forward.h" 11 #include "base/callback_forward.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/threading/thread_checker.h" 13 #include "base/threading/thread_checker.h"
14 #include "base/time/default_tick_clock.h" 14 #include "base/time/default_tick_clock.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "base/timer/timer.h" 16 #include "base/timer/timer.h"
17 #include "base/tuple.h"
17 #include "build/build_config.h" 18 #include "build/build_config.h"
18 #include "content/common/content_export.h" 19 #include "content/common/content_export.h"
19 #include "media/audio/audio_output_controller.h" 20 #include "media/audio/audio_output_controller.h"
20 21
21 namespace base { 22 namespace base {
22 class TickClock; 23 class TickClock;
23 } 24 }
24 25
25 namespace content { 26 namespace content {
26 27
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 int render_frame_id, 105 int render_frame_id,
105 int stream_id, 106 int stream_id,
106 const ReadPowerAndClipCallback& read_power_callback); 107 const ReadPowerAndClipCallback& read_power_callback);
107 static void StopMonitoringHelper(int render_process_id, 108 static void StopMonitoringHelper(int render_process_id,
108 int render_frame_id, 109 int render_frame_id,
109 int stream_id); 110 int stream_id);
110 111
111 // Starts polling the stream for audio stream power levels using |callback|. 112 // Starts polling the stream for audio stream power levels using |callback|.
112 void StartMonitoringStreamOnUIThread( 113 void StartMonitoringStreamOnUIThread(
113 int render_process_id, 114 int render_process_id,
115 int render_frame_id,
114 int stream_id, 116 int stream_id,
115 const ReadPowerAndClipCallback& callback); 117 const ReadPowerAndClipCallback& callback);
116 118
117 // Stops polling the stream, discarding the internal copy of the |callback| 119 // Stops polling the stream, discarding the internal copy of the |callback|
118 // provided in the call to StartMonitoringStream(). 120 // provided in the call to StartMonitoringStream().
119 void StopMonitoringStreamOnUIThread(int render_process_id, int stream_id); 121 void StopMonitoringStreamOnUIThread(int render_process_id,
122 int render_frame_id,
123 int stream_id);
120 124
121 // Called by |poll_timer_| to sample the power levels from each of the streams 125 // Called by |poll_timer_| to sample the power levels from each of the streams
122 // playing in the tab. 126 // playing in the tab.
123 void Poll(); 127 void Poll();
124 128
125 // Compares last known indicator state with what it should be, and triggers UI 129 // Compares last known indicator state with what it should be, and triggers UI
126 // updates through |web_contents_| if needed. When the indicator is turned 130 // updates through |web_contents_| if needed. When the indicator is turned
127 // on, |off_timer_| is started to re-invoke this method in the future. 131 // on, |off_timer_| is started to re-invoke this method in the future.
128 void MaybeToggle(); 132 void MaybeToggle();
129 133
130 // Helper functions to track number of active streams when power level 134 // Helper functions to track number of active streams when power level
131 // monitoring is not available. 135 // monitoring is not available.
132 void OnStreamAdded(); 136 void OnStreamAdded();
133 void OnStreamRemoved(); 137 void OnStreamRemoved();
134 138
135 // The WebContents instance to receive indicator toggle notifications. This 139 // The WebContents instance to receive indicator toggle notifications. This
136 // pointer should be valid for the lifetime of AudioStreamMonitor. 140 // pointer should be valid for the lifetime of AudioStreamMonitor.
137 WebContents* const web_contents_; 141 WebContents* const web_contents_;
138 142
139 // Note: |clock_| is always |&default_tick_clock_|, except during unit 143 // Note: |clock_| is always |&default_tick_clock_|, except during unit
140 // testing. 144 // testing.
141 base::DefaultTickClock default_tick_clock_; 145 base::DefaultTickClock default_tick_clock_;
142 base::TickClock* const clock_; 146 base::TickClock* const clock_;
143 147
144 // Confirms single-threaded access in debug builds. 148 // Confirms single-threaded access in debug builds.
145 base::ThreadChecker thread_checker_; 149 base::ThreadChecker thread_checker_;
146 150
147 // The callbacks to read power levels for each stream. Only playing (i.e., 151 // The callbacks to read power levels for each stream. Only playing (i.e.,
148 // not paused) streams will have an entry in this map. 152 // not paused) streams will have an entry in this map.
149 using StreamID = std::pair<int, int>; 153 // StreamID is formed by <render_process_id, render_frame_id, stream_id>
154 using StreamID = std::tuple<int, int, int>;
DaleCurtis 2017/06/22 00:35:55 This would be clearer as: struct StreamID { int
lpy 2017/06/22 02:28:52 Done.
150 using StreamPollCallbackMap = std::map<StreamID, ReadPowerAndClipCallback>; 155 using StreamPollCallbackMap = std::map<StreamID, ReadPowerAndClipCallback>;
151 StreamPollCallbackMap poll_callbacks_; 156 StreamPollCallbackMap poll_callbacks_;
152 157
153 // Records the last time at which sound was audible from any stream. 158 // Records the last time at which sound was audible from any stream.
154 base::TimeTicks last_blurt_time_; 159 base::TimeTicks last_blurt_time_;
155 160
156 // Set to true if the last call to MaybeToggle() determined the indicator 161 // Set to true if the last call to MaybeToggle() determined the indicator
157 // should be turned on. 162 // should be turned on.
158 bool was_recently_audible_; 163 bool was_recently_audible_;
159 164
160 // Whether the WebContents is currently audible. 165 // Whether the WebContents is currently audible.
161 bool is_audible_; 166 bool is_audible_;
162 167
163 // Calls Poll() at regular intervals while |poll_callbacks_| is non-empty. 168 // Calls Poll() at regular intervals while |poll_callbacks_| is non-empty.
164 base::RepeatingTimer poll_timer_; 169 base::RepeatingTimer poll_timer_;
165 170
166 // Started only when an indicator is toggled on, to turn it off again in the 171 // Started only when an indicator is toggled on, to turn it off again in the
167 // future. 172 // future.
168 base::OneShotTimer off_timer_; 173 base::OneShotTimer off_timer_;
169 174
170 DISALLOW_COPY_AND_ASSIGN(AudioStreamMonitor); 175 DISALLOW_COPY_AND_ASSIGN(AudioStreamMonitor);
171 }; 176 };
172 177
173 } // namespace content 178 } // namespace content
174 179
175 #endif // CONTENT_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_ 180 #endif // CONTENT_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698