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

Unified Diff: content/browser/renderer_host/media/audio_renderer_host.cc

Issue 562273008: Add audio signal to the ResourceScheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use render_view level HasActiveAudio instead of process level. Created 6 years, 3 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
« no previous file with comments | « content/browser/renderer_host/media/audio_renderer_host.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/renderer_host/media/audio_renderer_host.cc
diff --git a/content/browser/renderer_host/media/audio_renderer_host.cc b/content/browser/renderer_host/media/audio_renderer_host.cc
index 8c06395eca68ecf94496c47946a26066060004d0..a454571476d34877619f6dcedae58ec45b770147 100644
--- a/content/browser/renderer_host/media/audio_renderer_host.cc
+++ b/content/browser/renderer_host/media/audio_renderer_host.cc
@@ -10,6 +10,7 @@
#include "base/metrics/histogram.h"
#include "base/process/process.h"
#include "content/browser/browser_main_loop.h"
+#include "content/browser/loader/resource_dispatcher_host_impl.h"
#include "content/browser/media/audio_stream_monitor.h"
#include "content/browser/media/capture/audio_mirroring_manager.h"
#include "content/browser/media/media_internals.h"
@@ -257,7 +258,7 @@ void AudioRendererHost::DoNotifyStreamStateChanged(int stream_id,
bool is_playing) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- AudioEntry* const entry = LookupById(stream_id);
+ AudioEntry* const entry(LookupById(stream_id));
if (!entry)
return;
@@ -273,20 +274,11 @@ void AudioRendererHost::DoNotifyStreamStateChanged(int stream_id,
entry->stream_id(),
base::Bind(&media::AudioOutputController::ReadCurrentPowerAndClip,
entry->controller()));
- // TODO(dalecurtis): See about using AudioStreamMonitor instead.
- if (!entry->playing()) {
- entry->set_playing(true);
- base::AtomicRefCountInc(&num_playing_streams_);
- }
} else {
AudioStreamMonitor::StopMonitoringStream(
render_process_id_, entry->render_frame_id(), entry->stream_id());
- // TODO(dalecurtis): See about using AudioStreamMonitor instead.
- if (entry->playing()) {
- entry->set_playing(false);
- base::AtomicRefCountDec(&num_playing_streams_);
- }
}
+ UpdateNumPlayingStreams(entry, is_playing);
}
RenderViewHost::AudioOutputControllerList
@@ -454,8 +446,7 @@ void AudioRendererHost::DeleteEntry(scoped_ptr<AudioEntry> entry) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
AudioStreamMonitor::StopMonitoringStream(
render_process_id_, entry->render_frame_id(), entry->stream_id());
- if (entry->playing())
- base::AtomicRefCountDec(&num_playing_streams_);
+ UpdateNumPlayingStreams(entry.get(), false);
}
void AudioRendererHost::ReportErrorAndClose(int stream_id) {
@@ -480,8 +471,37 @@ AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) {
return i != audio_entries_.end() ? i->second : NULL;
}
+void AudioRendererHost::UpdateNumPlayingStreams(AudioEntry* entry,
+ bool is_playing) {
+ if (entry->playing() != is_playing) {
+ entry->set_playing(is_playing);
+ if (is_playing) {
DaleCurtis 2014/09/19 00:42:39 no {} for single line statements.
aiolos (Not reviewing) 2014/09/19 00:52:46 Done.
+ base::AtomicRefCountInc(&num_playing_streams_);
+ } else {
+ base::AtomicRefCountDec(&num_playing_streams_);
+ }
+
+ if (is_playing || !RenderViewHasActiveAudio(entry->render_view_id())) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
DaleCurtis 2014/09/19 00:42:38 Why here? Can this just go at the top like elsewhe
aiolos (Not reviewing) 2014/09/19 00:52:46 Done.
+ ResourceDispatcherHostImpl::Get()->OnAudioRenderHostStreamStateChanged(
+ render_process_id_, entry->render_view_id(), is_playing);
+ }
+ }
+}
+
bool AudioRendererHost::HasActiveAudio() {
return !base::AtomicRefCountIsZero(&num_playing_streams_);
}
+bool AudioRendererHost::RenderViewHasActiveAudio(int render_view_id) {
+ AudioEntryMap::const_iterator it = audio_entries_.begin();
DaleCurtis 2014/09/19 00:42:39 Assign within for?
aiolos (Not reviewing) 2014/09/19 00:52:45 Done. Also changed another iterator in the code th
+ for (; it != audio_entries_.end(); ++it) {
+ AudioEntry* entry = it->second;
+ if (entry->render_view_id() == render_view_id && entry->playing()) {
DaleCurtis 2014/09/19 00:42:39 No {} again.
aiolos (Not reviewing) 2014/09/19 00:52:45 Done.
+ return true;
+ }
+ }
+ return false;
+}
+
} // namespace content
« no previous file with comments | « content/browser/renderer_host/media/audio_renderer_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698