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

Unified Diff: chrome/browser/media/audio_stream_indicator.cc

Issue 14600025: Replace AudioSilenceDetector with an AudioPowerMonitor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media/audio_stream_indicator.cc
diff --git a/chrome/browser/media/audio_stream_indicator.cc b/chrome/browser/media/audio_stream_indicator.cc
index 6cd623212e72fcf8dcc722241af868ec291d5755..adc3b71a41e1ab77c5ac5184da3948337ea4fed4 100644
--- a/chrome/browser/media/audio_stream_indicator.cc
+++ b/chrome/browser/media/audio_stream_indicator.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/media/audio_stream_indicator.h"
+#include <limits>
+
#include "base/bind.h"
#include "chrome/browser/tab_contents/tab_util.h"
#include "content/public/browser/browser_thread.h"
@@ -20,17 +22,17 @@ AudioStreamIndicator::~AudioStreamIndicator() {}
void AudioStreamIndicator::UpdateWebContentsStatus(
int render_process_id, int render_view_id, int stream_id,
- bool is_playing_and_audible) {
+ bool is_playing, float power_in_dbfs) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&AudioStreamIndicator::UpdateWebContentsStatusOnUIThread, this,
render_process_id, render_view_id, stream_id,
- is_playing_and_audible));
+ is_playing, power_in_dbfs));
}
-bool AudioStreamIndicator::IsPlayingAudio(WebContents* contents) {
+bool AudioStreamIndicator::IsPlayingAudio(WebContents* contents) const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
RenderViewId id(contents->GetRenderProcessHost()->GetID(),
@@ -38,6 +40,28 @@ bool AudioStreamIndicator::IsPlayingAudio(WebContents* contents) {
return audio_streams_.find(id) != audio_streams_.end();
}
+float AudioStreamIndicator::GetAudioPowerLevelInDBFS(
DaleCurtis 2013/05/16 18:24:45 Seems like there should be a simpler way to do thi
miu 2013/05/16 21:44:11 Acknowledged.
+ content::WebContents* contents) const {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ // Since a RenderView can have more than one stream playing back, return the
+ // maximum of the last-reported power levels. For more information about how
+ // the power level is measured, see media/audio/audio_power_monitor.h.
+ float max_power_dbfs = -std::numeric_limits<float>::infinity();
+ RenderViewId id(contents->GetRenderProcessHost()->GetID(),
+ contents->GetRenderViewHost()->GetRoutingID());
+ RenderViewStreamMap::const_iterator stream_it = audio_streams_.find(id);
+ if (stream_it != audio_streams_.end()) {
+ const StreamPowerLevelMap& power_levels = stream_it->second;
+ for (StreamPowerLevelMap::const_iterator power_it = power_levels.begin();
+ power_it != power_levels.end(); ++power_it) {
+ if (power_it->second > max_power_dbfs)
+ max_power_dbfs = power_it->second;
+ }
+ }
+ return max_power_dbfs;
+}
+
AudioStreamIndicator::RenderViewId::RenderViewId(int render_process_id,
int render_view_id)
: render_process_id(render_process_id),
@@ -56,20 +80,23 @@ void AudioStreamIndicator::UpdateWebContentsStatusOnUIThread(
int render_process_id,
int render_view_id,
int stream_id,
- bool is_playing_and_audible) {
+ bool is_playing,
+ float power_in_dbfs) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
RenderViewId id(render_process_id, render_view_id);
- if (is_playing_and_audible) {
- audio_streams_[id].insert(stream_id);
+ if (is_playing) {
+ audio_streams_[id][stream_id] = power_in_dbfs;
} else {
- std::map<RenderViewId, std::set<int> >::iterator it =
- audio_streams_.find(id);
- if (it == audio_streams_.end())
+ RenderViewStreamMap::iterator stream_it = audio_streams_.find(id);
+ if (stream_it == audio_streams_.end())
return;
-
- it->second.erase(stream_id);
- if (it->second.empty())
- audio_streams_.erase(it);
+ StreamPowerLevelMap& power_levels = stream_it->second;
+ StreamPowerLevelMap::iterator power_it = power_levels.find(stream_id);
+ if (power_it == power_levels.end())
+ return;
+ power_levels.erase(power_it);
+ if (power_levels.empty())
+ audio_streams_.erase(stream_it);
}
WebContents* web_contents = tab_util::GetWebContentsByID(render_process_id,

Powered by Google App Engine
This is Rietveld 408576698