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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 static bool monitoring_available() { | 45 static bool monitoring_available() { |
| 46 return media::AudioOutputController::will_monitor_audio_levels(); | 46 return media::AudioOutputController::will_monitor_audio_levels(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 // Returns true if audio has recently been audible from the tab. This is | 49 // 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 | 50 // 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 | 51 // other use cases as well (e.g., the OOM killer uses this to de-prioritize |
| 52 // the killing of tabs making sounds). | 52 // the killing of tabs making sounds). |
| 53 bool WasRecentlyAudible() const; | 53 bool WasRecentlyAudible() const; |
| 54 | 54 |
| 55 // Returns true if the audio is currently audible from the given WebContents. | |
| 56 // The difference from WasRecentlyAudible() is that this method will return | |
| 57 // false as soon as the WebContents stop producing sound. | |
|
whywhat
2016/01/15 19:01:20
hm, won't this create some noise in the metrics? s
mlamouri (slow - plz ping)
2016/01/19 12:18:43
Sure, this is going to have an effect on playlist.
| |
| 58 bool IsCurrentlyAudible() const; | |
| 59 | |
| 55 // Starts or stops audio level monitoring respectively for the stream owned by | 60 // Starts or stops audio level monitoring respectively for the stream owned by |
| 56 // the specified renderer. Safe to call from any thread. | 61 // the specified renderer. Safe to call from any thread. |
| 57 // | 62 // |
| 58 // The callback returns the current power level (in dBFS units) and the clip | 63 // The callback returns the current power level (in dBFS units) and the clip |
| 59 // status (true if any part of the audio signal has clipped since the last | 64 // status (true if any part of the audio signal has clipped since the last |
| 60 // callback run). |stream_id| must be unique within a |render_process_id|. | 65 // callback run). |stream_id| must be unique within a |render_process_id|. |
| 61 typedef base::Callback<std::pair<float, bool>()> ReadPowerAndClipCallback; | 66 typedef base::Callback<std::pair<float, bool>()> ReadPowerAndClipCallback; |
| 62 static void StartMonitoringStream( | 67 static void StartMonitoringStream( |
| 63 int render_process_id, | 68 int render_process_id, |
| 64 int render_frame_id, | 69 int render_frame_id, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 typedef std::map<StreamID, ReadPowerAndClipCallback> StreamPollCallbackMap; | 137 typedef std::map<StreamID, ReadPowerAndClipCallback> StreamPollCallbackMap; |
| 133 StreamPollCallbackMap poll_callbacks_; | 138 StreamPollCallbackMap poll_callbacks_; |
| 134 | 139 |
| 135 // Records the last time at which sound was audible from any stream. | 140 // Records the last time at which sound was audible from any stream. |
| 136 base::TimeTicks last_blurt_time_; | 141 base::TimeTicks last_blurt_time_; |
| 137 | 142 |
| 138 // Set to true if the last call to MaybeToggle() determined the indicator | 143 // Set to true if the last call to MaybeToggle() determined the indicator |
| 139 // should be turned on. | 144 // should be turned on. |
| 140 bool was_recently_audible_; | 145 bool was_recently_audible_; |
| 141 | 146 |
| 147 // Whether the WebContents is currently audible. | |
| 148 bool is_audible_; | |
| 149 | |
| 142 // Calls Poll() at regular intervals while |poll_callbacks_| is non-empty. | 150 // Calls Poll() at regular intervals while |poll_callbacks_| is non-empty. |
| 143 base::RepeatingTimer poll_timer_; | 151 base::RepeatingTimer poll_timer_; |
| 144 | 152 |
| 145 // Started only when an indicator is toggled on, to turn it off again in the | 153 // Started only when an indicator is toggled on, to turn it off again in the |
| 146 // future. | 154 // future. |
| 147 base::OneShotTimer off_timer_; | 155 base::OneShotTimer off_timer_; |
| 148 | 156 |
| 149 DISALLOW_COPY_AND_ASSIGN(AudioStreamMonitor); | 157 DISALLOW_COPY_AND_ASSIGN(AudioStreamMonitor); |
| 150 }; | 158 }; |
| 151 | 159 |
| 152 } // namespace content | 160 } // namespace content |
| 153 | 161 |
| 154 #endif // CONTENT_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_ | 162 #endif // CONTENT_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_ |
| OLD | NEW |