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

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

Issue 2948613002: [AudioStreamMonitor] Adds API to collect frame-level audibility. (Closed)
Patch Set: Fix windows build Created 3 years, 5 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/containers/flat_map.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
14 #include "base/time/default_tick_clock.h" 15 #include "base/time/default_tick_clock.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 #include "base/timer/timer.h" 17 #include "base/timer/timer.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 {
(...skipping 82 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 struct CONTENT_EXPORT StreamID {
150 using StreamPollCallbackMap = std::map<StreamID, ReadPowerAndClipCallback>; 154 int render_process_id;
155 int render_frame_id;
156 int stream_id;
157 bool operator<(const StreamID& other) const;
158 bool operator==(const StreamID& other) const;
159 };
160 using StreamPollCallbackMap =
161 base::flat_map<StreamID, ReadPowerAndClipCallback>;
151 StreamPollCallbackMap poll_callbacks_; 162 StreamPollCallbackMap poll_callbacks_;
152 163
153 // Records the last time at which sound was audible from any stream. 164 // Records the last time at which sound was audible from any stream.
154 base::TimeTicks last_blurt_time_; 165 base::TimeTicks last_blurt_time_;
155 166
156 // Set to true if the last call to MaybeToggle() determined the indicator 167 // Set to true if the last call to MaybeToggle() determined the indicator
157 // should be turned on. 168 // should be turned on.
158 bool was_recently_audible_; 169 bool was_recently_audible_;
159 170
160 // Whether the WebContents is currently audible. 171 // Whether the WebContents is currently audible.
161 bool is_audible_; 172 bool is_audible_;
162 173
163 // Calls Poll() at regular intervals while |poll_callbacks_| is non-empty. 174 // Calls Poll() at regular intervals while |poll_callbacks_| is non-empty.
164 base::RepeatingTimer poll_timer_; 175 base::RepeatingTimer poll_timer_;
165 176
166 // Started only when an indicator is toggled on, to turn it off again in the 177 // Started only when an indicator is toggled on, to turn it off again in the
167 // future. 178 // future.
168 base::OneShotTimer off_timer_; 179 base::OneShotTimer off_timer_;
169 180
170 DISALLOW_COPY_AND_ASSIGN(AudioStreamMonitor); 181 DISALLOW_COPY_AND_ASSIGN(AudioStreamMonitor);
171 }; 182 };
172 183
173 } // namespace content 184 } // namespace content
174 185
175 #endif // CONTENT_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_ 186 #endif // CONTENT_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_host_impl.cc ('k') | content/browser/media/audio_stream_monitor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698