| 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 "media/audio/audio_output_device.h" | 10 #include "media/audio/audio_output_device.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 void AudioRendererMixerManager::SetAudioRendererSinkForTesting( | 41 void AudioRendererMixerManager::SetAudioRendererSinkForTesting( |
| 42 media::AudioRendererSink* sink) { | 42 media::AudioRendererSink* sink) { |
| 43 sink_for_testing_ = sink; | 43 sink_for_testing_ = sink; |
| 44 } | 44 } |
| 45 | 45 |
| 46 media::AudioRendererMixer* AudioRendererMixerManager::GetMixer( | 46 media::AudioRendererMixer* AudioRendererMixerManager::GetMixer( |
| 47 int source_render_view_id, | 47 int source_render_view_id, |
| 48 int source_render_frame_id, | 48 int source_render_frame_id, |
| 49 const media::AudioParameters& params) { | 49 const media::AudioParameters& params) { |
| 50 // Effects are not passed through to output creation, so ensure none are set. |
| 51 DCHECK_EQ(params.effects(), media::AudioParameters::NO_EFFECTS); |
| 52 |
| 50 const MixerKey key(source_render_view_id, params); | 53 const MixerKey key(source_render_view_id, params); |
| 51 base::AutoLock auto_lock(mixers_lock_); | 54 base::AutoLock auto_lock(mixers_lock_); |
| 52 | 55 |
| 53 AudioRendererMixerMap::iterator it = mixers_.find(key); | 56 AudioRendererMixerMap::iterator it = mixers_.find(key); |
| 54 if (it != mixers_.end()) { | 57 if (it != mixers_.end()) { |
| 55 it->second.ref_count++; | 58 it->second.ref_count++; |
| 56 return it->second.mixer; | 59 return it->second.mixer; |
| 57 } | 60 } |
| 58 | 61 |
| 59 // On ChromeOS we can rely on the playback device to handle resampling, so | 62 // On ChromeOS we can rely on the playback device to handle resampling, so |
| 60 // don't waste cycles on it here. | 63 // don't waste cycles on it here. |
| 61 #if defined(OS_CHROMEOS) | 64 #if defined(OS_CHROMEOS) |
| 62 int sample_rate = params.sample_rate(); | 65 int sample_rate = params.sample_rate(); |
| 63 #else | 66 #else |
| 64 int sample_rate = hardware_config_->GetOutputSampleRate(); | 67 int sample_rate = hardware_config_->GetOutputSampleRate(); |
| 65 #endif | 68 #endif |
| 66 | 69 |
| 67 // Create output parameters based on the audio hardware configuration for | 70 // Create output parameters based on the audio hardware configuration for |
| 68 // passing on to the output sink. Force to 16-bit output for now since we | 71 // passing on to the output sink. Force to 16-bit output for now since we |
| 69 // know that works well for WebAudio and WebRTC. | 72 // know that works everywhere; ChromeOS does not support other bit depths. |
| 70 media::AudioParameters output_params( | 73 media::AudioParameters output_params( |
| 71 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, params.channel_layout(), | 74 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, params.channel_layout(), |
| 72 sample_rate, 16, hardware_config_->GetHighLatencyBufferSize()); | 75 sample_rate, 16, hardware_config_->GetHighLatencyBufferSize()); |
| 73 | 76 |
| 74 // If we've created invalid output parameters, simply pass on the input params | 77 // If we've created invalid output parameters, simply pass on the input params |
| 75 // and let the browser side handle automatic fallback. | 78 // and let the browser side handle automatic fallback. |
| 76 if (!output_params.IsValid()) | 79 if (!output_params.IsValid()) |
| 77 output_params = params; | 80 output_params = params; |
| 78 | 81 |
| 79 media::AudioRendererMixer* mixer; | 82 media::AudioRendererMixer* mixer; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 102 | 105 |
| 103 // Only remove the mixer if AudioRendererMixerManager is the last owner. | 106 // Only remove the mixer if AudioRendererMixerManager is the last owner. |
| 104 it->second.ref_count--; | 107 it->second.ref_count--; |
| 105 if (it->second.ref_count == 0) { | 108 if (it->second.ref_count == 0) { |
| 106 delete it->second.mixer; | 109 delete it->second.mixer; |
| 107 mixers_.erase(it); | 110 mixers_.erase(it); |
| 108 } | 111 } |
| 109 } | 112 } |
| 110 | 113 |
| 111 } // namespace content | 114 } // namespace content |
| OLD | NEW |