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

Side by Side Diff: content/renderer/media/audio_renderer_mixer_manager.cc

Issue 12102004: Renderer side audio device change wip... Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 #include "content/renderer/media/audio_renderer_mixer_manager.h" 5 #include "content/renderer/media/audio_renderer_mixer_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 // #include "content/renderer/media/audio_hardware.h"
9 #include "content/renderer/media/audio_device_factory.h" 10 #include "content/renderer/media/audio_device_factory.h"
10 #include "content/renderer/media/renderer_audio_output_device.h" 11 #include "content/renderer/media/renderer_audio_output_device.h"
11 #include "media/base/audio_renderer_mixer.h" 12 #include "media/base/audio_renderer_mixer.h"
12 #include "media/base/audio_renderer_mixer_input.h" 13 #include "media/base/audio_renderer_mixer_input.h"
14 #include "media/base/audio_hardware_config.h"
13 15
14 namespace content { 16 namespace content {
15 17
16 AudioRendererMixerManager::AudioRendererMixerManager(int hardware_sample_rate, 18 // AudioRendererMixerManager::AudioRendererMixerManager(int hardware_sample_rate ,
17 int hardware_buffer_size) 19 // int hardware_buffer_size )
18 : hardware_sample_rate_(hardware_sample_rate), 20 // : hardware_sample_rate_(hardware_sample_rate),
19 hardware_buffer_size_(hardware_buffer_size), 21 // hardware_buffer_size_(hardware_buffer_size),
22 AudioRendererMixerManager::AudioRendererMixerManager(
23 media::AudioHardwareConfig* hardware_config)
24 : hardware_config_(hardware_config),
20 sink_for_testing_(NULL) { 25 sink_for_testing_(NULL) {
26 // TODO(dalecurtis): Fix this so that buffer size and sample rate are only
27 // passed in for testing. Though RendererViewImpl still needs to initialize
28 // the AudioHardware cache...
21 } 29 }
22 30
23 AudioRendererMixerManager::~AudioRendererMixerManager() { 31 AudioRendererMixerManager::~AudioRendererMixerManager() {
24 DCHECK(mixers_.empty()); 32 DCHECK(mixers_.empty());
25 } 33 }
26 34
27 media::AudioRendererMixerInput* AudioRendererMixerManager::CreateInput( 35 media::AudioRendererMixerInput* AudioRendererMixerManager::CreateInput(
28 int source_render_view_id) { 36 int source_render_view_id) {
29 return new media::AudioRendererMixerInput( 37 return new media::AudioRendererMixerInput(
30 base::Bind( 38 base::Bind(
31 &AudioRendererMixerManager::GetMixer, base::Unretained(this), 39 &AudioRendererMixerManager::GetMixer, base::Unretained(this),
32 source_render_view_id), 40 source_render_view_id),
33 base::Bind( 41 base::Bind(
34 &AudioRendererMixerManager::RemoveMixer, base::Unretained(this), 42 &AudioRendererMixerManager::RemoveMixer, base::Unretained(this),
35 source_render_view_id)); 43 source_render_view_id));
36 } 44 }
37 45
38 void AudioRendererMixerManager::SetAudioRendererSinkForTesting( 46 void AudioRendererMixerManager::SetAudioRendererSinkForTesting(
39 media::AudioRendererSink* sink) { 47 media::AudioRendererSink* sink) {
40 sink_for_testing_ = sink; 48 sink_for_testing_ = sink;
41 } 49 }
42 50
43 media::AudioRendererMixer* AudioRendererMixerManager::GetMixer( 51 media::AudioRendererMixer* AudioRendererMixerManager::GetMixer(
44 int source_render_view_id, 52 int source_render_view_id,
45 const media::AudioParameters& params) { 53 const media::AudioParameters& params) {
46 const MixerKey key(source_render_view_id, params); 54 const MixerKey key(source_render_view_id, params);
47 base::AutoLock auto_lock(mixers_lock_); 55 base::AutoLock auto_lock(mixers_lock_);
48 56
49 AudioRendererMixerMap::iterator it = mixers_.find(key); 57 // AudioRendererMixerMap::iterator it = mixers_.find(key);
50 if (it != mixers_.end()) { 58 // if (it != mixers_.end()) {
51 it->second.ref_count++; 59 // it->second.ref_count++;
52 return it->second.mixer; 60 // return it->second.mixer;
53 } 61 // }
62
63 LOG(ERROR) << "Getting mixer...";
54 64
55 // On Linux and ChromeOS we can rely on the playback device to handle 65 // On Linux and ChromeOS we can rely on the playback device to handle
56 // resampling, so don't waste cycles on it here. 66 // resampling, so don't waste cycles on it here.
57 #if defined(OS_LINUX) 67 // #if defined(OS_LINUX)
58 int sample_rate = params.sample_rate(); 68 // int sample_rate = params.sample_rate();
59 #else 69 // #else
60 int sample_rate = hardware_sample_rate_; 70 // int sample_rate = hardware_sample_rate_;
61 #endif 71 // #endif
62 72
63 // Create output parameters based on the audio hardware configuration for 73 // Create output parameters based on the audio hardware configuration for
64 // passing on to the output sink. Force to 16-bit output for now since we 74 // passing on to the output sink. Force to 16-bit output for now since we
65 // know that works well for WebAudio and WebRTC. 75 // know that works well for WebAudio and WebRTC.
66 media::AudioParameters output_params( 76 media::AudioParameters output_params(
67 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, params.channel_layout(), 77 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, params.channel_layout(),
68 sample_rate, 16, hardware_buffer_size_); 78 // hardware_sample_rate_, 16, hardware_buffer_size_);
79 hardware_config_->GetOutputSampleRate(), 16,
80 hardware_config_->GetOutputBufferSize());
81
82 // GetAudioOutputSampleRate(), 16, GetAudioOutputBufferSize());
83 // TODO(justinlin): Fix and uncomment the above.
84 LOG(ERROR) << "GetAudioOutputSampleRate() and GetAudioOutputBufferSize() will"
85 << " fail if no cache exists since we're not on the RenderThread!";
69 86
70 // If we've created invalid output parameters, simply pass on the input params 87 // If we've created invalid output parameters, simply pass on the input params
71 // and let the browser side handle automatic fallback. 88 // and let the browser side handle automatic fallback.
72 if (!output_params.IsValid()) 89 if (!output_params.IsValid())
73 output_params = params; 90 output_params = params;
74 91
92 IOParamsKey mixer_key = std::make_pair(params, output_params);
93 AudioRendererMixerMap::iterator it = mixers_.find(mixer_key);
94 if (it != mixers_.end()) {
95 it->second.ref_count++;
96 return it->second.mixer;
97 }
98
75 media::AudioRendererMixer* mixer; 99 media::AudioRendererMixer* mixer;
76 if (sink_for_testing_) { 100 if (sink_for_testing_) {
77 mixer = new media::AudioRendererMixer( 101 mixer = new media::AudioRendererMixer(
78 params, output_params, sink_for_testing_); 102 params, output_params, sink_for_testing_);
79 } else { 103 } else {
80 scoped_refptr<RendererAudioOutputDevice> device = 104 scoped_refptr<RendererAudioOutputDevice> device =
81 AudioDeviceFactory::NewOutputDevice(); 105 AudioDeviceFactory::NewOutputDevice();
82 device->SetSourceRenderView(source_render_view_id); 106 device->SetSourceRenderView(source_render_view_id);
83 mixer = new media::AudioRendererMixer(params, output_params, device); 107 mixer = new media::AudioRendererMixer(params, output_params, device);
84 } 108 }
85 109
86 AudioRendererMixerReference mixer_reference = { mixer, 1 }; 110 AudioRendererMixerReference mixer_reference = { mixer, 1 };
87 mixers_[key] = mixer_reference; 111 // mixers_[key] = mixer_reference;
112 mixers_[mixer_key] = mixer_reference;
88 return mixer; 113 return mixer;
89 } 114 }
90 115
91 void AudioRendererMixerManager::RemoveMixer( 116 void AudioRendererMixerManager::RemoveMixer(
92 int source_render_view_id, 117 int source_render_view_id,
93 const media::AudioParameters& params) { 118 media::AudioRendererMixer* mixer/*const media::AudioParameters& params*/) {
94 const MixerKey key(source_render_view_id, params); 119 // +void AudioRendererMixerManager::RemoveMixer(media::AudioRendererMixer* mixer ) {
120 // base::AutoLock auto_lock(mixers_lock_);
121
122 // const MixerKey key(source_render_view_id, params);
95 base::AutoLock auto_lock(mixers_lock_); 123 base::AutoLock auto_lock(mixers_lock_);
96 124
97 AudioRendererMixerMap::iterator it = mixers_.find(key); 125 // AudioRendererMixerMap::iterator it = mixers_.find(key);
126 IOParamsKey mixer_key = std::make_pair(
127 mixer->input_params(), mixer->output_params());
128
129 AudioRendererMixerMap::iterator it = mixers_.find(mixer_key);
98 DCHECK(it != mixers_.end()); 130 DCHECK(it != mixers_.end());
99 131
100 // Only remove the mixer if AudioRendererMixerManager is the last owner. 132 // Only remove the mixer if AudioRendererMixerManager is the last owner.
101 it->second.ref_count--; 133 it->second.ref_count--;
102 if (it->second.ref_count == 0) { 134 if (it->second.ref_count == 0) {
103 delete it->second.mixer; 135 delete it->second.mixer;
104 mixers_.erase(it); 136 mixers_.erase(it);
105 } 137 }
106 } 138 }
107 139
108 } // namespace content 140 } // namespace content
OLDNEW
« 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