| 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/atomicops.h" | 7 #include "base/atomicops.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/message_loop_proxy.h" | 13 #include "base/message_loop_proxy.h" |
| 14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 15 #include "content/renderer/media/audio_device_factory.h" | 15 #include "content/renderer/media/audio_device_factory.h" |
| 16 #include "content/renderer/media/renderer_audio_output_device.h" | |
| 17 #include "content/renderer/media/webrtc_audio_capturer.h" | 16 #include "content/renderer/media/webrtc_audio_capturer.h" |
| 17 #include "media/audio/audio_output_device.h" |
| 18 #include "media/base/bind_to_loop.h" | 18 #include "media/base/bind_to_loop.h" |
| 19 #include "media/base/media_switches.h" | 19 #include "media/base/media_switches.h" |
| 20 | 20 |
| 21 namespace content { | 21 namespace content { |
| 22 | 22 |
| 23 // WebRtcLocalAudioRenderer::AudioCallback wraps the AudioOutputDevice thread, | 23 // WebRtcLocalAudioRenderer::AudioCallback wraps the AudioOutputDevice thread, |
| 24 // receives callbacks on that thread and proxies these requests to the capture | 24 // receives callbacks on that thread and proxies these requests to the capture |
| 25 // sink. | 25 // sink. |
| 26 class WebRtcLocalAudioRenderer::AudioCallback | 26 class WebRtcLocalAudioRenderer::AudioCallback |
| 27 : public media::AudioRendererSink::RenderCallback { | 27 : public media::AudioRendererSink::RenderCallback { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 // tests have shown that it resolves issues with audio glitches for some | 162 // tests have shown that it resolves issues with audio glitches for some |
| 163 // cases where resampling is needed on the output side. | 163 // cases where resampling is needed on the output side. |
| 164 // TODO(henrika): verify this scheme on as many different devices and | 164 // TODO(henrika): verify this scheme on as many different devices and |
| 165 // combinations of sample rates as possible | 165 // combinations of sample rates as possible |
| 166 media::AudioParameters source_params = source_->audio_parameters(); | 166 media::AudioParameters source_params = source_->audio_parameters(); |
| 167 media::AudioParameters sink_params(source_params.format(), | 167 media::AudioParameters sink_params(source_params.format(), |
| 168 source_params.channel_layout(), | 168 source_params.channel_layout(), |
| 169 source_params.sample_rate(), | 169 source_params.sample_rate(), |
| 170 source_params.bits_per_sample(), | 170 source_params.bits_per_sample(), |
| 171 2 * source_params.frames_per_buffer()); | 171 2 * source_params.frames_per_buffer()); |
| 172 sink_ = AudioDeviceFactory::NewOutputDevice(); | 172 sink_ = AudioDeviceFactory::NewOutputDevice(source_render_view_id_); |
| 173 if (CommandLine::ForCurrentProcess()->HasSwitch( | 173 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 174 switches::kEnableWebAudioInput)) { | 174 switches::kEnableWebAudioInput)) { |
| 175 // TODO(henrika): we could utilize the unified audio here instead and do | 175 // TODO(henrika): we could utilize the unified audio here instead and do |
| 176 // sink_->InitializeIO(sink_params, 2, callback_.get()); | 176 // sink_->InitializeIO(sink_params, 2, callback_.get()); |
| 177 // It would then be possible to avoid using the WebRtcAudioCapturer. | 177 // It would then be possible to avoid using the WebRtcAudioCapturer. |
| 178 DVLOG(1) << "enable-webaudio-input command-line flag is enabled"; | 178 DVLOG(1) << "enable-webaudio-input command-line flag is enabled"; |
| 179 } | 179 } |
| 180 sink_->Initialize(sink_params, callback_.get()); | 180 sink_->Initialize(sink_params, callback_.get()); |
| 181 sink_->SetSourceRenderView(source_render_view_id_); | |
| 182 | 181 |
| 183 // Start local rendering and the capturer. Note that, the capturer is owned | 182 // Start local rendering and the capturer. Note that, the capturer is owned |
| 184 // by the WebRTC ADM and might already bee running. | 183 // by the WebRTC ADM and might already bee running. |
| 185 source_->Start(); | 184 source_->Start(); |
| 186 sink_->Start(); | 185 sink_->Start(); |
| 187 callback_->Start(); | 186 callback_->Start(); |
| 188 } | 187 } |
| 189 | 188 |
| 190 void WebRtcLocalAudioRenderer::Stop() { | 189 void WebRtcLocalAudioRenderer::Stop() { |
| 191 DCHECK(thread_checker_.CalledOnValidThread()); | 190 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 DVLOG(1) << "WebRtcLocalAudioRenderer::OnSourceCaptureDeviceStopped()"; | 260 DVLOG(1) << "WebRtcLocalAudioRenderer::OnSourceCaptureDeviceStopped()"; |
| 262 if (!Started()) | 261 if (!Started()) |
| 263 return; | 262 return; |
| 264 | 263 |
| 265 // The capture device has stopped and we should therefore stop all activity | 264 // The capture device has stopped and we should therefore stop all activity |
| 266 // as well to save resources. | 265 // as well to save resources. |
| 267 Stop(); | 266 Stop(); |
| 268 } | 267 } |
| 269 | 268 |
| 270 } // namespace content | 269 } // namespace content |
| OLD | NEW |