Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 int render_frame_id, | 104 int render_frame_id, |
| 105 int stream_id, | 105 int stream_id, |
| 106 const ReadPowerAndClipCallback& read_power_callback); | 106 const ReadPowerAndClipCallback& read_power_callback); |
| 107 static void StopMonitoringHelper(int render_process_id, | 107 static void StopMonitoringHelper(int render_process_id, |
| 108 int render_frame_id, | 108 int render_frame_id, |
| 109 int stream_id); | 109 int stream_id); |
| 110 | 110 |
| 111 // Starts polling the stream for audio stream power levels using |callback|. | 111 // Starts polling the stream for audio stream power levels using |callback|. |
| 112 void StartMonitoringStreamOnUIThread( | 112 void StartMonitoringStreamOnUIThread( |
| 113 int render_process_id, | 113 int render_process_id, |
| 114 int render_frame_id, | |
| 114 int stream_id, | 115 int stream_id, |
| 115 const ReadPowerAndClipCallback& callback); | 116 const ReadPowerAndClipCallback& callback); |
| 116 | 117 |
| 117 // Stops polling the stream, discarding the internal copy of the |callback| | 118 // Stops polling the stream, discarding the internal copy of the |callback| |
| 118 // provided in the call to StartMonitoringStream(). | 119 // provided in the call to StartMonitoringStream(). |
| 119 void StopMonitoringStreamOnUIThread(int render_process_id, int stream_id); | 120 void StopMonitoringStreamOnUIThread(int render_process_id, |
| 121 int render_frame_id, | |
| 122 int stream_id); | |
| 120 | 123 |
| 121 // Called by |poll_timer_| to sample the power levels from each of the streams | 124 // Called by |poll_timer_| to sample the power levels from each of the streams |
| 122 // playing in the tab. | 125 // playing in the tab. |
| 123 void Poll(); | 126 void Poll(); |
| 124 | 127 |
| 125 // Compares last known indicator state with what it should be, and triggers UI | 128 // 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 | 129 // 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. | 130 // on, |off_timer_| is started to re-invoke this method in the future. |
| 128 void MaybeToggle(); | 131 void MaybeToggle(); |
| 129 | 132 |
| 130 // Helper functions to track number of active streams when power level | 133 // Helper functions to track number of active streams when power level |
| 131 // monitoring is not available. | 134 // monitoring is not available. |
| 132 void OnStreamAdded(); | 135 void OnStreamAdded(); |
| 133 void OnStreamRemoved(); | 136 void OnStreamRemoved(); |
| 134 | 137 |
| 135 // The WebContents instance to receive indicator toggle notifications. This | 138 // The WebContents instance to receive indicator toggle notifications. This |
| 136 // pointer should be valid for the lifetime of AudioStreamMonitor. | 139 // pointer should be valid for the lifetime of AudioStreamMonitor. |
| 137 WebContents* const web_contents_; | 140 WebContents* const web_contents_; |
| 138 | 141 |
| 139 // Note: |clock_| is always |&default_tick_clock_|, except during unit | 142 // Note: |clock_| is always |&default_tick_clock_|, except during unit |
| 140 // testing. | 143 // testing. |
| 141 base::DefaultTickClock default_tick_clock_; | 144 base::DefaultTickClock default_tick_clock_; |
| 142 base::TickClock* const clock_; | 145 base::TickClock* const clock_; |
| 143 | 146 |
| 144 // Confirms single-threaded access in debug builds. | 147 // Confirms single-threaded access in debug builds. |
| 145 base::ThreadChecker thread_checker_; | 148 base::ThreadChecker thread_checker_; |
| 146 | 149 |
| 147 // The callbacks to read power levels for each stream. Only playing (i.e., | 150 // The callbacks to read power levels for each stream. Only playing (i.e., |
| 148 // not paused) streams will have an entry in this map. | 151 // not paused) streams will have an entry in this map. |
| 149 using StreamID = std::pair<int, int>; | 152 struct StreamID { |
| 153 int render_process_id; | |
| 154 int render_frame_id; | |
| 155 int stream_id; | |
| 156 bool operator<(const StreamID& other) const; | |
| 157 }; | |
| 150 using StreamPollCallbackMap = std::map<StreamID, ReadPowerAndClipCallback>; | 158 using StreamPollCallbackMap = std::map<StreamID, ReadPowerAndClipCallback>; |
|
DaleCurtis
2017/06/22 03:15:40
Can probably use flat_map here too.
lpy
2017/06/22 20:14:04
Done.
| |
| 151 StreamPollCallbackMap poll_callbacks_; | 159 StreamPollCallbackMap poll_callbacks_; |
| 152 | 160 |
| 153 // Records the last time at which sound was audible from any stream. | 161 // Records the last time at which sound was audible from any stream. |
| 154 base::TimeTicks last_blurt_time_; | 162 base::TimeTicks last_blurt_time_; |
| 155 | 163 |
| 156 // Set to true if the last call to MaybeToggle() determined the indicator | 164 // Set to true if the last call to MaybeToggle() determined the indicator |
| 157 // should be turned on. | 165 // should be turned on. |
| 158 bool was_recently_audible_; | 166 bool was_recently_audible_; |
| 159 | 167 |
| 160 // Whether the WebContents is currently audible. | 168 // Whether the WebContents is currently audible. |
| 161 bool is_audible_; | 169 bool is_audible_; |
| 162 | 170 |
| 163 // Calls Poll() at regular intervals while |poll_callbacks_| is non-empty. | 171 // Calls Poll() at regular intervals while |poll_callbacks_| is non-empty. |
| 164 base::RepeatingTimer poll_timer_; | 172 base::RepeatingTimer poll_timer_; |
| 165 | 173 |
| 166 // Started only when an indicator is toggled on, to turn it off again in the | 174 // Started only when an indicator is toggled on, to turn it off again in the |
| 167 // future. | 175 // future. |
| 168 base::OneShotTimer off_timer_; | 176 base::OneShotTimer off_timer_; |
| 169 | 177 |
| 170 DISALLOW_COPY_AND_ASSIGN(AudioStreamMonitor); | 178 DISALLOW_COPY_AND_ASSIGN(AudioStreamMonitor); |
| 171 }; | 179 }; |
| 172 | 180 |
| 173 } // namespace content | 181 } // namespace content |
| 174 | 182 |
| 175 #endif // CONTENT_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_ | 183 #endif // CONTENT_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_ |
| OLD | NEW |