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

Side by Side Diff: chrome/browser/media/audio_stream_indicator.h

Issue 14600025: Replace AudioSilenceDetector with an AudioPowerMonitor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Replace RMS scheme with 1st-order low-pass filter, per crogers@. Simpler, single-threaded unit tes… Created 7 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 | Annotate | Revision Log
OLDNEW
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_dBFS,
DaleCurtis 2013/07/02 22:26:34 Style should be all lowercase I think.
miu 2013/07/09 00:59:56 Done.
27 bool clipped);
27 28
28 // This method should be called on the UI thread. 29 // This method should be called on the UI thread.
29 bool IsPlayingAudio(content::WebContents* contents); 30 bool IsPlayingAudio(const content::WebContents* contents);
31
32 // Returns the audible |level| in the range [0.0,1.0], where 0.0 means the
33 // audio signal is imperceivably silent and 1.0 means it is at maximum
34 // volume. |signal_has_clipped| is set to true if any part of the audio
35 // signal has clipped since the last call to this method.
36 //
37 // This method should be called on the UI thread.
38 //
39 // TODO(miu): Consider replacing this "pull" API with an event-driven "push"
40 // API.
41 void CurrentAudibleLevel(const content::WebContents* contents,
42 float* level, bool* signal_has_clipped);
30 43
31 private: 44 private:
32 struct RenderViewId { 45 struct RenderViewId {
DaleCurtis 2013/07/02 22:26:34 If you just use std::pair<int, int> you can avoid
miu 2013/07/09 00:59:56 Done. I absolutely agree. There was a past discu
33 RenderViewId(int render_process_id, 46 RenderViewId(int render_process_id,
34 int render_view_id); 47 int render_view_id);
35 48
36 // Required to use this struct in the std::multiset below. 49 // Required to use this struct in the std::map below.
37 bool operator<(const RenderViewId& other) const; 50 bool operator<(const RenderViewId& other) const;
38 51
39 int render_process_id; 52 int render_process_id;
40 int render_view_id; 53 int render_view_id;
41 }; 54 };
42 55
56 struct SignalPower {
57 float power_dBFS;
58 bool clipped;
59 };
60
43 friend class base::RefCountedThreadSafe<AudioStreamIndicator>; 61 friend class base::RefCountedThreadSafe<AudioStreamIndicator>;
44 virtual ~AudioStreamIndicator(); 62 virtual ~AudioStreamIndicator();
45 63
46 void UpdateWebContentsStatusOnUIThread(int render_process_id, 64 void UpdateWebContentsStatusOnUIThread(int render_process_id,
47 int render_view_id, 65 int render_view_id,
48 int stream_id, 66 int stream_id,
49 bool playing); 67 bool is_playing,
68 float power_dBFS,
69 bool clipped);
50 70
51 // A map from RenderViews to sets of streams playing in them (each RenderView 71 // A map from RenderViews to the streams playing in them (each RenderView
52 // might have more than one stream). 72 // might have more than one stream). An inner map associates each stream with
53 std::map<RenderViewId, std::set<int> > audio_streams_; 73 // its last-known power level.
74 typedef std::map<int, SignalPower> StreamPowerLevelMap;
DaleCurtis 2013/07/02 22:26:34 About how many streams/renderview are we expecting
miu 2013/07/09 00:59:56 Took your advice on eliminating the nested map sin
75 typedef std::map<RenderViewId, StreamPowerLevelMap> RenderViewStreamMap;
76 RenderViewStreamMap audio_streams_;
54 }; 77 };
55 78
56 #endif // CHROME_BROWSER_MEDIA_AUDIO_STREAM_INDICATOR_H_ 79 #endif // CHROME_BROWSER_MEDIA_AUDIO_STREAM_INDICATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698