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

Unified Diff: content/renderer/media/audio_renderer_mixer_manager.cc

Issue 10636036: Enable renderer side mixing behind a flag. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove new mixer address != old mixer address test. Created 8 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/audio_renderer_mixer_manager.cc
diff --git a/content/renderer/media/audio_renderer_mixer_manager.cc b/content/renderer/media/audio_renderer_mixer_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..03e638e7799dafc54074c53e6c8da9800a72fc19
--- /dev/null
+++ b/content/renderer/media/audio_renderer_mixer_manager.cc
@@ -0,0 +1,73 @@
+// Copyright (c) 2012 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/renderer/media/audio_renderer_mixer_manager.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "content/renderer/media/audio_device_factory.h"
+#include "media/base/audio_renderer_mixer.h"
+#include "media/base/audio_renderer_mixer_input.h"
+
+namespace content {
+
+AudioRendererMixerManager::AudioRendererMixerManager(int hardware_sample_rate,
+ int hardware_buffer_size)
+ : hardware_sample_rate_(hardware_sample_rate),
+ hardware_buffer_size_(hardware_buffer_size) {
+}
+
+AudioRendererMixerManager::~AudioRendererMixerManager() {
+ DCHECK(mixers_.empty());
+}
+
+media::AudioRendererMixerInput* AudioRendererMixerManager::CreateInput() {
+ return new media::AudioRendererMixerInput(
+ base::Bind(
+ &AudioRendererMixerManager::GetMixer, base::Unretained(this)),
+ base::Bind(
+ &AudioRendererMixerManager::RemoveMixer, base::Unretained(this)));
+}
+
+media::AudioRendererMixer* AudioRendererMixerManager::GetMixer(
+ const media::AudioParameters& params) {
+ base::AutoLock auto_lock(mixers_lock_);
+
+ AudioRendererMixerMap::iterator it = mixers_.find(params);
+ if (it != mixers_.end()) {
+ it->second.ref_count++;
+ return it->second.mixer;
+ }
+
+ // Create output parameters based on the audio hardware configuration for
+ // passing on to the output sink. Force to 16-bit output for now since we
+ // know that works well for WebAudio and WebRTC.
+ media::AudioParameters output_params(
+ media::AudioParameters::AUDIO_PCM_LOW_LATENCY, params.channel_layout(),
+ hardware_sample_rate_, 16, hardware_buffer_size_);
+
+ media::AudioRendererMixer* mixer = new media::AudioRendererMixer(
+ params, output_params, AudioDeviceFactory::Create());
+
+ AudioRendererMixerReference mixer_reference = { mixer, 1 };
+ mixers_[params] = mixer_reference;
+ return mixer;
+}
+
+void AudioRendererMixerManager::RemoveMixer(
+ const media::AudioParameters& params) {
+ base::AutoLock auto_lock(mixers_lock_);
+
+ AudioRendererMixerMap::iterator it = mixers_.find(params);
+ DCHECK(it != mixers_.end());
+
+ // Only remove the mixer if AudioRendererMixerManager is the last owner.
+ it->second.ref_count--;
+ if (it->second.ref_count == 0) {
+ delete it->second.mixer;
+ mixers_.erase(it);
+ }
+}
+
+} // namespace content
« no previous file with comments | « content/renderer/media/audio_renderer_mixer_manager.h ('k') | content/renderer/media/audio_renderer_mixer_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698