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

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

Issue 2578983003: Add AudioStreamRegistry. Move stream counting logic (Closed)
Patch Set: Remove active audio tracking from ARH to see what tests break. Created 3 years, 11 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: content/browser/renderer_host/media/audio_stream_registry_impl.cc
diff --git a/content/browser/renderer_host/media/audio_stream_registry_impl.cc b/content/browser/renderer_host/media/audio_stream_registry_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2060eb3783c0243e577689e623d7aabf67490a7e
--- /dev/null
+++ b/content/browser/renderer_host/media/audio_stream_registry_impl.cc
@@ -0,0 +1,106 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/renderer_host/media/audio_stream_registry_impl.h"
+
+#include <algorithm>
+
+#include "base/lazy_instance.h"
+#include "base/metrics/histogram_macros.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_process_host.h"
+#include "media/audio/audio_streams_tracker.h"
+
+namespace content {
+
+namespace {
+
+base::LazyInstance<media::AudioStreamsTracker> g_audio_output_streams_tracker =
+ LAZY_INSTANCE_INITIALIZER;
+
+void NotifyRenderProcessHostThatAudioStateChanged(int render_process_id) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+
+ RenderProcessHost* render_process_host =
+ RenderProcessHost::FromID(render_process_id);
+
+ if (render_process_host)
+ ;
+ //render_process_host->AudioStateChanged();
+}
+
+} // namespace
+
+AudioStreamRegistryImpl::AudioStreamRegistryImpl(int render_process_id)
+ : render_process_id_(render_process_id) {}
+
+AudioStreamRegistryImpl::~AudioStreamRegistryImpl() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK_EQ(num_output_streams_, 0);
+ DCHECK_EQ(num_playing_output_streams_, 0);
+
+ if (max_simultaneous_output_streams_ > 0) {
+ UMA_HISTOGRAM_CUSTOM_COUNTS("Media.AudioRendererIpcStreams",
+ max_simultaneous_output_streams_, 1, 50, 51);
+ UMA_HISTOGRAM_CUSTOM_COUNTS(
+ "Media.AudioRendererIpcStreamsTotal",
+ g_audio_output_streams_tracker.Get().max_stream_count(), 1, 100, 101);
+ g_audio_output_streams_tracker.Get().ResetMaxStreamCount();
+ }
+}
+
+// static
+AudioStreamRegistryImpl::UniquePtr AudioStreamRegistryImpl::Create(
+ int render_process_id) {
+ return {new AudioStreamRegistryImpl(render_process_id), {}};
+}
+
+bool AudioStreamRegistryImpl::HasActiveAudio() {
+ return false;
+ //return !base::AtomicRefCountIsZero(&num_playing_output_streams_);
+}
+
+void AudioStreamRegistryImpl::RegisterStream() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ ++num_output_streams_;
+ max_simultaneous_output_streams_ =
+ std::max(max_simultaneous_output_streams_, num_output_streams_);
+ g_audio_output_streams_tracker.Get().IncreaseStreamCount();
+}
+
+void AudioStreamRegistryImpl::DeregisterStream() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK_GT(num_output_streams_, 0);
+ --num_output_streams_;
+ g_audio_output_streams_tracker.Get().DecreaseStreamCount();
+}
+
+void AudioStreamRegistryImpl::StreamStateChanged(bool playing) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ if (playing) {
+ base::AtomicRefCountInc(&num_playing_output_streams_);
+
+ // Inform the RenderProcessHost when audio starts playing for the first
+ // time. The nonatomic increment-and-read is ok since this is the only
+ // thread that |num_playing_output_streams_| may be updated on.
+ if (base::AtomicRefCountIsOne(&num_playing_output_streams_)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&NotifyRenderProcessHostThatAudioStateChanged,
+ render_process_id_));
+ }
+ } else {
+ // Inform the RenderProcessHost when there is no more audio playing.
+ DCHECK(!base::AtomicRefCountIsZero(&num_playing_output_streams_));
+ if (!base::AtomicRefCountDec(&num_playing_output_streams_)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&NotifyRenderProcessHostThatAudioStateChanged,
+ render_process_id_));
+ }
+ }
+ DCHECK_LE(num_playing_output_streams_, num_output_streams_);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698