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/webrtc_local_audio_renderer.h" | 5 #include "content/renderer/media/webrtc_local_audio_renderer.h" |
6 | 6 |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 UMA_HISTOGRAM_ENUMERATION("Media.LocalRendererSinkStates", | 248 UMA_HISTOGRAM_ENUMERATION("Media.LocalRendererSinkStates", |
249 kSinkStarted, kSinkStatesMax); | 249 kSinkStarted, kSinkStatesMax); |
250 } | 250 } |
251 | 251 |
252 void WebRtcLocalAudioRenderer::ReconfigureSink( | 252 void WebRtcLocalAudioRenderer::ReconfigureSink( |
253 const media::AudioParameters& params) { | 253 const media::AudioParameters& params) { |
254 DCHECK(task_runner_->BelongsToCurrentThread()); | 254 DCHECK(task_runner_->BelongsToCurrentThread()); |
255 | 255 |
256 DVLOG(1) << "WebRtcLocalAudioRenderer::ReconfigureSink()"; | 256 DVLOG(1) << "WebRtcLocalAudioRenderer::ReconfigureSink()"; |
257 | 257 |
258 int implicit_ducking_effect = 0; | |
259 RenderFrameImpl* const frame = | |
260 RenderFrameImpl::FromRoutingID(source_render_frame_id_); | |
261 MediaStreamDispatcher* const dispatcher = frame ? | |
262 frame->GetMediaStreamDispatcher() : NULL; | |
263 if (dispatcher && dispatcher->IsAudioDuckingActive()) { | |
264 DVLOG(1) << "Forcing DUCKING to be ON for output"; | |
265 implicit_ducking_effect = media::AudioParameters::DUCKING; | |
266 } else { | |
267 DVLOG(1) << "DUCKING not forced ON for output"; | |
268 } | |
269 | |
270 if (source_params_.Equals(params)) | 258 if (source_params_.Equals(params)) |
271 return; | 259 return; |
272 | 260 |
273 // Reset the |source_params_|, |sink_params_| and |loopback_fifo_| to match | 261 // Reset the |source_params_|, |sink_params_| and |loopback_fifo_| to match |
274 // the new format. | 262 // the new format. |
275 | 263 |
276 source_params_ = params; | 264 source_params_ = params; |
277 | 265 |
278 sink_params_ = media::AudioParameters(source_params_.format(), | 266 sink_params_ = media::AudioParameters(source_params_.format(), |
279 source_params_.channel_layout(), source_params_.sample_rate(), | 267 source_params_.channel_layout(), source_params_.sample_rate(), |
280 source_params_.bits_per_sample(), | 268 source_params_.bits_per_sample(), |
281 WebRtcAudioRenderer::GetOptimalBufferSize(source_params_.sample_rate(), | 269 WebRtcAudioRenderer::GetOptimalBufferSize(source_params_.sample_rate(), |
282 frames_per_buffer_), | 270 frames_per_buffer_), |
283 // If DUCKING is enabled on the source, it needs to be enabled on the | 271 source_params_.effects()); |
284 // sink as well. | |
285 source_params_.effects() | implicit_ducking_effect); | |
286 | 272 |
287 { | 273 { |
288 // Note: The max buffer is fairly large, but will rarely be used. | 274 // Note: The max buffer is fairly large, but will rarely be used. |
289 // Cast needs the buffer to hold at least one second of audio. | 275 // Cast needs the buffer to hold at least one second of audio. |
290 // The clock accuracy is set to 20ms because clock accuracy is | 276 // The clock accuracy is set to 20ms because clock accuracy is |
291 // ~15ms on windows. | 277 // ~15ms on windows. |
292 media::AudioShifter* const new_shifter = new media::AudioShifter( | 278 media::AudioShifter* const new_shifter = new media::AudioShifter( |
293 base::TimeDelta::FromSeconds(2), | 279 base::TimeDelta::FromSeconds(2), |
294 base::TimeDelta::FromMilliseconds(20), | 280 base::TimeDelta::FromMilliseconds(20), |
295 base::TimeDelta::FromSeconds(20), | 281 base::TimeDelta::FromSeconds(20), |
(...skipping 12 matching lines...) Expand all Loading... |
308 if (sink_started_) { | 294 if (sink_started_) { |
309 sink_->Stop(); | 295 sink_->Stop(); |
310 sink_started_ = false; | 296 sink_started_ = false; |
311 } | 297 } |
312 | 298 |
313 sink_ = AudioDeviceFactory::NewOutputDevice(source_render_frame_id_); | 299 sink_ = AudioDeviceFactory::NewOutputDevice(source_render_frame_id_); |
314 MaybeStartSink(); | 300 MaybeStartSink(); |
315 } | 301 } |
316 | 302 |
317 } // namespace content | 303 } // namespace content |
OLD | NEW |