| Index: content/browser/media/audio_stream_monitor.h
|
| diff --git a/chrome/browser/media/audio_stream_monitor.h b/content/browser/media/audio_stream_monitor.h
|
| similarity index 65%
|
| rename from chrome/browser/media/audio_stream_monitor.h
|
| rename to content/browser/media/audio_stream_monitor.h
|
| index 3282dbd8ba77edde54c6c35afb17bd4f49e5068e..2f8f05bb9c735d7a9a11d83bc252561eb83135c0 100644
|
| --- a/chrome/browser/media/audio_stream_monitor.h
|
| +++ b/content/browser/media/audio_stream_monitor.h
|
| @@ -2,8 +2,8 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#ifndef CHROME_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_
|
| -#define CHROME_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_
|
| +#ifndef CONTENT_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_
|
| +#define CONTENT_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_
|
|
|
| #include <map>
|
|
|
| @@ -18,6 +18,9 @@ namespace base {
|
| class TickClock;
|
| }
|
|
|
| +namespace content {
|
| +class PowerSaveBlocker;
|
| +
|
| // Repeatedly polls audio streams for their power levels, and "debounces" the
|
| // information into a simple, binary "was recently audible" result for the audio
|
| // indicators in the tab UI. The debouncing logic is to: 1) Turn on immediately
|
| @@ -31,8 +34,11 @@ class TickClock;
|
| // AudioStreamMonitor is created on-demand, and automatically destroyed when its
|
| // associated WebContents is destroyed. See content::WebContentsUserData for
|
| // usage.
|
| -class AudioStreamMonitor
|
| - : public content::WebContentsUserData<AudioStreamMonitor> {
|
| +//
|
| +// AudioStreamMonitor will additionally create a PowerSaveBlocker to prevent app
|
| +// suspension when audible audio is being produced.
|
| +class CONTENT_EXPORT AudioStreamMonitor
|
| + : public WebContentsUserData<AudioStreamMonitor> {
|
| public:
|
| // Returns true if audio has recently been audible from the tab. This is
|
| // usually called whenever the tab data model is refreshed; but there are
|
| @@ -40,17 +46,24 @@ class AudioStreamMonitor
|
| // the killing of tabs making sounds).
|
| bool WasRecentlyAudible() const;
|
|
|
| - // Starts polling the stream for audio stream power levels using |callback|.
|
| + // Starts or stops audio level monitoring respectively for the stream owned by
|
| + // the specified renderer. Safe to call from any thread.
|
| + //
|
| + // The callback returns the current power level (in dBFS units) and the clip
|
| + // status (true if any part of the audio signal has clipped since the last
|
| + // callback run).
|
| typedef base::Callback<std::pair<float, bool>()> ReadPowerAndClipCallback;
|
| - void StartMonitoringStream(int stream_id,
|
| - const ReadPowerAndClipCallback& callback);
|
| -
|
| - // Stops polling the stream, discarding the internal copy of the |callback|
|
| - // provided in the call to StartMonitoringStream().
|
| - void StopMonitoringStream(int stream_id);
|
| + static void StartMonitoringStream(
|
| + int render_process_id,
|
| + int render_frame_id,
|
| + int stream_id,
|
| + const ReadPowerAndClipCallback& read_power_callback);
|
| + static void StopMonitoringStream(int render_process_id,
|
| + int render_frame_id,
|
| + int stream_id);
|
|
|
| private:
|
| - friend class content::WebContentsUserData<AudioStreamMonitor>;
|
| + friend class WebContentsUserData<AudioStreamMonitor>;
|
| friend class AudioStreamMonitorTest;
|
|
|
| enum {
|
| @@ -62,10 +75,30 @@ class AudioStreamMonitor
|
| kHoldOnMilliseconds = 2000
|
| };
|
|
|
| - // Invoked by content::WebContentsUserData only.
|
| - explicit AudioStreamMonitor(content::WebContents* contents);
|
| + // Invoked by WebContentsUserData only.
|
| + explicit AudioStreamMonitor(WebContents* contents);
|
| virtual ~AudioStreamMonitor();
|
|
|
| + // Helper methods for starting and stopping monitoring which lookup the
|
| + // identified renderer and forward calls to the correct AudioStreamMonitor.
|
| + static void StartMonitoringHelper(
|
| + int render_process_id,
|
| + int render_frame_id,
|
| + int stream_id,
|
| + const ReadPowerAndClipCallback& read_power_callback);
|
| + static void StopMonitoringHelper(int render_process_id,
|
| + int render_frame_id,
|
| + int stream_id);
|
| +
|
| + // Starts polling the stream for audio stream power levels using |callback|.
|
| + void StartMonitoringStreamOnUIThread(
|
| + int stream_id,
|
| + const ReadPowerAndClipCallback& callback);
|
| +
|
| + // Stops polling the stream, discarding the internal copy of the |callback|
|
| + // provided in the call to StartMonitoringStream().
|
| + void StopMonitoringStreamOnUIThread(int stream_id);
|
| +
|
| // Called by |poll_timer_| to sample the power levels from each of the streams
|
| // playing in the tab.
|
| void Poll();
|
| @@ -78,7 +111,7 @@ class AudioStreamMonitor
|
| // The WebContents instance instance to receive indicator toggle
|
| // notifications. This pointer should be valid for the lifetime of
|
| // AudioStreamMonitor.
|
| - content::WebContents* const web_contents_;
|
| + WebContents* const web_contents_;
|
|
|
| // Note: |clock_| is always |&default_tick_clock_|, except during unit
|
| // testing.
|
| @@ -107,7 +140,12 @@ class AudioStreamMonitor
|
| // future.
|
| base::OneShotTimer<AudioStreamMonitor> off_timer_;
|
|
|
| + // Prevent app suspension when audio is active.
|
| + scoped_ptr<PowerSaveBlocker> blocker_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(AudioStreamMonitor);
|
| };
|
|
|
| -#endif // CHROME_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_
|
| +} // namespace content
|
| +
|
| +#endif // CONTENT_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_
|
|
|