OLD | NEW |
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_device_factory.h" | 9 #include "content/renderer/media/audio_device_factory.h" |
10 #include "content/renderer/media/renderer_audio_output_device.h" | 10 #include "content/renderer/media/renderer_audio_output_device.h" |
| 11 #include "media/base/audio_hardware_config.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" |
13 | 14 |
14 namespace content { | 15 namespace content { |
15 | 16 |
16 AudioRendererMixerManager::AudioRendererMixerManager(int hardware_sample_rate, | 17 AudioRendererMixerManager::AudioRendererMixerManager( |
17 int hardware_buffer_size) | 18 media::AudioHardwareConfig* hardware_config) |
18 : hardware_sample_rate_(hardware_sample_rate), | 19 : hardware_config_(hardware_config), |
19 hardware_buffer_size_(hardware_buffer_size), | |
20 sink_for_testing_(NULL) { | 20 sink_for_testing_(NULL) { |
21 } | 21 } |
22 | 22 |
23 AudioRendererMixerManager::~AudioRendererMixerManager() { | 23 AudioRendererMixerManager::~AudioRendererMixerManager() { |
24 DCHECK(mixers_.empty()); | 24 DCHECK(mixers_.empty()); |
25 } | 25 } |
26 | 26 |
27 media::AudioRendererMixerInput* AudioRendererMixerManager::CreateInput( | 27 media::AudioRendererMixerInput* AudioRendererMixerManager::CreateInput( |
28 int source_render_view_id) { | 28 int source_render_view_id) { |
29 return new media::AudioRendererMixerInput( | 29 return new media::AudioRendererMixerInput( |
(...skipping 20 matching lines...) Expand all Loading... |
50 if (it != mixers_.end()) { | 50 if (it != mixers_.end()) { |
51 it->second.ref_count++; | 51 it->second.ref_count++; |
52 return it->second.mixer; | 52 return it->second.mixer; |
53 } | 53 } |
54 | 54 |
55 // On Linux and ChromeOS we can rely on the playback device to handle | 55 // On Linux and ChromeOS we can rely on the playback device to handle |
56 // resampling, so don't waste cycles on it here. | 56 // resampling, so don't waste cycles on it here. |
57 #if defined(OS_LINUX) | 57 #if defined(OS_LINUX) |
58 int sample_rate = params.sample_rate(); | 58 int sample_rate = params.sample_rate(); |
59 #else | 59 #else |
60 int sample_rate = hardware_sample_rate_; | 60 int sample_rate = hardware_config_->GetOutputSampleRate(); |
61 #endif | 61 #endif |
62 | 62 |
63 // Create output parameters based on the audio hardware configuration for | 63 // 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 | 64 // passing on to the output sink. Force to 16-bit output for now since we |
65 // know that works well for WebAudio and WebRTC. | 65 // know that works well for WebAudio and WebRTC. |
66 media::AudioParameters output_params( | 66 media::AudioParameters output_params( |
67 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, params.channel_layout(), | 67 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, params.channel_layout(), |
68 sample_rate, 16, hardware_buffer_size_); | 68 sample_rate, 16, hardware_config_->GetOutputBufferSize()); |
69 | 69 |
70 // If we've created invalid output parameters, simply pass on the input params | 70 // If we've created invalid output parameters, simply pass on the input params |
71 // and let the browser side handle automatic fallback. | 71 // and let the browser side handle automatic fallback. |
72 if (!output_params.IsValid()) | 72 if (!output_params.IsValid()) |
73 output_params = params; | 73 output_params = params; |
74 | 74 |
75 media::AudioRendererMixer* mixer; | 75 media::AudioRendererMixer* mixer; |
76 if (sink_for_testing_) { | 76 if (sink_for_testing_) { |
77 mixer = new media::AudioRendererMixer( | 77 mixer = new media::AudioRendererMixer( |
78 params, output_params, sink_for_testing_); | 78 params, output_params, sink_for_testing_); |
(...skipping 20 matching lines...) Expand all Loading... |
99 | 99 |
100 // Only remove the mixer if AudioRendererMixerManager is the last owner. | 100 // Only remove the mixer if AudioRendererMixerManager is the last owner. |
101 it->second.ref_count--; | 101 it->second.ref_count--; |
102 if (it->second.ref_count == 0) { | 102 if (it->second.ref_count == 0) { |
103 delete it->second.mixer; | 103 delete it->second.mixer; |
104 mixers_.erase(it); | 104 mixers_.erase(it); |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 } // namespace content | 108 } // namespace content |
OLD | NEW |