| 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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
| 12 #include "content/renderer/media/audio_device_factory.h" | 12 #include "content/renderer/media/audio_device_factory.h" |
| 13 #include "content/renderer/media/media_stream_dispatcher.h" | 13 #include "content/renderer/media/media_stream_dispatcher.h" |
| 14 #include "content/renderer/media/webrtc_audio_capturer.h" | 14 #include "content/renderer/media/webrtc_audio_capturer.h" |
| 15 #include "content/renderer/media/webrtc_audio_renderer.h" |
| 15 #include "content/renderer/render_frame_impl.h" | 16 #include "content/renderer/render_frame_impl.h" |
| 16 #include "media/audio/audio_output_device.h" | 17 #include "media/audio/audio_output_device.h" |
| 17 #include "media/base/audio_block_fifo.h" | 18 #include "media/base/audio_block_fifo.h" |
| 18 #include "media/base/audio_bus.h" | 19 #include "media/base/audio_bus.h" |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 enum LocalRendererSinkStates { | 25 enum LocalRendererSinkStates { |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 return; | 278 return; |
| 278 | 279 |
| 279 // Reset the |source_params_|, |sink_params_| and |loopback_fifo_| to match | 280 // Reset the |source_params_|, |sink_params_| and |loopback_fifo_| to match |
| 280 // the new format. | 281 // the new format. |
| 281 | 282 |
| 282 source_params_ = params; | 283 source_params_ = params; |
| 283 | 284 |
| 284 sink_params_ = media::AudioParameters(source_params_.format(), | 285 sink_params_ = media::AudioParameters(source_params_.format(), |
| 285 source_params_.channel_layout(), source_params_.sample_rate(), | 286 source_params_.channel_layout(), source_params_.sample_rate(), |
| 286 source_params_.bits_per_sample(), | 287 source_params_.bits_per_sample(), |
| 287 #if defined(OS_ANDROID) | 288 WebRtcAudioRenderer::GetOptimalBufferSize(source_params_.sample_rate(), |
| 288 // On Android, input and output use the same sample rate. In order to | 289 frames_per_buffer_), |
| 289 // use the low latency mode, we need to use the buffer size suggested by | |
| 290 // the AudioManager for the sink. It will later be used to decide | |
| 291 // the buffer size of the shared memory buffer. | |
| 292 frames_per_buffer_, | |
| 293 #else | |
| 294 2 * source_params_.frames_per_buffer(), | |
| 295 #endif | |
| 296 // If DUCKING is enabled on the source, it needs to be enabled on the | 290 // If DUCKING is enabled on the source, it needs to be enabled on the |
| 297 // sink as well. | 291 // sink as well. |
| 298 source_params_.effects() | implicit_ducking_effect); | 292 source_params_.effects() | implicit_ducking_effect); |
| 299 | 293 |
| 300 { | 294 { |
| 301 // TODO(henrika): we could add a more dynamic solution here but I prefer | 295 // TODO(henrika): we could add a more dynamic solution here but I prefer |
| 302 // a fixed size combined with bad audio at overflow. The alternative is | 296 // a fixed size combined with bad audio at overflow. The alternative is |
| 303 // that we start to build up latency and that can be more difficult to | 297 // that we start to build up latency and that can be more difficult to |
| 304 // detect. Tests have shown that the FIFO never contains more than 2 or 3 | 298 // detect. Tests have shown that the FIFO never contains more than 2 or 3 |
| 305 // audio frames but I have selected a max size of ten buffers just | 299 // audio frames but I have selected a max size of ten buffers just |
| (...skipping 18 matching lines...) Expand all Loading... |
| 324 sink_->Stop(); | 318 sink_->Stop(); |
| 325 sink_started_ = false; | 319 sink_started_ = false; |
| 326 } | 320 } |
| 327 | 321 |
| 328 sink_ = AudioDeviceFactory::NewOutputDevice(source_render_view_id_, | 322 sink_ = AudioDeviceFactory::NewOutputDevice(source_render_view_id_, |
| 329 source_render_frame_id_); | 323 source_render_frame_id_); |
| 330 MaybeStartSink(); | 324 MaybeStartSink(); |
| 331 } | 325 } |
| 332 | 326 |
| 333 } // namespace content | 327 } // namespace content |
| OLD | NEW |