| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_MEDIA_AUDIO_STREAM_INDICATOR_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_AUDIO_STREAM_INDICATOR_H_ |
| 6 #define CHROME_BROWSER_MEDIA_AUDIO_STREAM_INDICATOR_H_ | 6 #define CHROME_BROWSER_MEDIA_AUDIO_STREAM_INDICATOR_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | |
| 10 | 9 |
| 11 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 12 | 11 |
| 13 namespace content { | 12 namespace content { |
| 14 class WebContents; | 13 class WebContents; |
| 15 } | 14 } |
| 16 | 15 |
| 17 class AudioStreamIndicator | 16 class AudioStreamIndicator |
| 18 : public base::RefCountedThreadSafe<AudioStreamIndicator> { | 17 : public base::RefCountedThreadSafe<AudioStreamIndicator> { |
| 19 public: | 18 public: |
| 20 AudioStreamIndicator(); | 19 AudioStreamIndicator(); |
| 21 | 20 |
| 22 // This method should be called on the IO thread. | 21 // This method should be called on the IO thread. |
| 23 void UpdateWebContentsStatus(int render_process_id, | 22 void UpdateWebContentsStatus(int render_process_id, |
| 24 int render_view_id, | 23 int render_view_id, |
| 25 int stream_id, | 24 int stream_id, |
| 26 bool is_playing_and_audible); | 25 bool is_playing, |
| 26 float power_in_dbfs); |
| 27 | 27 |
| 28 // This method should be called on the UI thread. | 28 // These methods should be called on the UI thread. |
| 29 bool IsPlayingAudio(content::WebContents* contents); | 29 bool IsPlayingAudio(content::WebContents* contents) const; |
| 30 float GetAudioPowerLevelInDBFS(content::WebContents* contents) const; |
| 30 | 31 |
| 31 private: | 32 private: |
| 32 struct RenderViewId { | 33 struct RenderViewId { |
| 33 RenderViewId(int render_process_id, | 34 RenderViewId(int render_process_id, |
| 34 int render_view_id); | 35 int render_view_id); |
| 35 | 36 |
| 36 // Required to use this struct in the std::multiset below. | 37 // Required to use this struct in the std::map below. |
| 37 bool operator<(const RenderViewId& other) const; | 38 bool operator<(const RenderViewId& other) const; |
| 38 | 39 |
| 39 int render_process_id; | 40 int render_process_id; |
| 40 int render_view_id; | 41 int render_view_id; |
| 41 }; | 42 }; |
| 42 | 43 |
| 43 friend class base::RefCountedThreadSafe<AudioStreamIndicator>; | 44 friend class base::RefCountedThreadSafe<AudioStreamIndicator>; |
| 44 virtual ~AudioStreamIndicator(); | 45 virtual ~AudioStreamIndicator(); |
| 45 | 46 |
| 46 void UpdateWebContentsStatusOnUIThread(int render_process_id, | 47 void UpdateWebContentsStatusOnUIThread(int render_process_id, |
| 47 int render_view_id, | 48 int render_view_id, |
| 48 int stream_id, | 49 int stream_id, |
| 49 bool playing); | 50 bool is_playing, |
| 51 float power_in_dbfs); |
| 50 | 52 |
| 51 // A map from RenderViews to sets of streams playing in them (each RenderView | 53 // A map from RenderViews to the streams playing in them (each RenderView |
| 52 // might have more than one stream). | 54 // might have more than one stream). An inner map associates each stream with |
| 53 std::map<RenderViewId, std::set<int> > audio_streams_; | 55 // its last-known power level. |
| 56 typedef std::map<int, float> StreamPowerLevelMap; |
| 57 typedef std::map<RenderViewId, StreamPowerLevelMap> RenderViewStreamMap; |
| 58 RenderViewStreamMap audio_streams_; |
| 54 }; | 59 }; |
| 55 | 60 |
| 56 #endif // CHROME_BROWSER_MEDIA_AUDIO_STREAM_INDICATOR_H_ | 61 #endif // CHROME_BROWSER_MEDIA_AUDIO_STREAM_INDICATOR_H_ |
| OLD | NEW |