| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 } | 114 } |
| 115 | 115 |
| 116 void WebRtcLocalAudioRenderer::Start() { | 116 void WebRtcLocalAudioRenderer::Start() { |
| 117 DVLOG(1) << "WebRtcLocalAudioRenderer::Start()"; | 117 DVLOG(1) << "WebRtcLocalAudioRenderer::Start()"; |
| 118 DCHECK(task_runner_->BelongsToCurrentThread()); | 118 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 119 | 119 |
| 120 // We get audio data from |audio_track_|... | 120 // We get audio data from |audio_track_|... |
| 121 MediaStreamAudioSink::AddToAudioTrack(this, audio_track_); | 121 MediaStreamAudioSink::AddToAudioTrack(this, audio_track_); |
| 122 // ...and |sink_| will get audio data from us. | 122 // ...and |sink_| will get audio data from us. |
| 123 DCHECK(!sink_.get()); | 123 DCHECK(!sink_.get()); |
| 124 sink_ = AudioDeviceFactory::NewOutputDevice(source_render_frame_id_); | 124 sink_ = AudioDeviceFactory::NewOutputDevice( |
| 125 source_render_frame_id_, session_id_, std::string(), url::Origin()); |
| 125 | 126 |
| 126 base::AutoLock auto_lock(thread_lock_); | 127 base::AutoLock auto_lock(thread_lock_); |
| 127 last_render_time_ = base::TimeTicks::Now(); | 128 last_render_time_ = base::TimeTicks::Now(); |
| 128 playing_ = false; | 129 playing_ = false; |
| 129 } | 130 } |
| 130 | 131 |
| 131 void WebRtcLocalAudioRenderer::Stop() { | 132 void WebRtcLocalAudioRenderer::Stop() { |
| 132 DVLOG(1) << "WebRtcLocalAudioRenderer::Stop()"; | 133 DVLOG(1) << "WebRtcLocalAudioRenderer::Stop()"; |
| 133 DCHECK(task_runner_->BelongsToCurrentThread()); | 134 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 134 | 135 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 { | 236 { |
| 236 // Clear up the old data in the FIFO. | 237 // Clear up the old data in the FIFO. |
| 237 base::AutoLock auto_lock(thread_lock_); | 238 base::AutoLock auto_lock(thread_lock_); |
| 238 audio_shifter_->Flush(); | 239 audio_shifter_->Flush(); |
| 239 } | 240 } |
| 240 | 241 |
| 241 if (!sink_params_.IsValid() || !playing_ || !volume_ || sink_started_) | 242 if (!sink_params_.IsValid() || !playing_ || !volume_ || sink_started_) |
| 242 return; | 243 return; |
| 243 | 244 |
| 244 DVLOG(1) << "WebRtcLocalAudioRenderer::MaybeStartSink() -- Starting sink_."; | 245 DVLOG(1) << "WebRtcLocalAudioRenderer::MaybeStartSink() -- Starting sink_."; |
| 245 sink_->InitializeWithSessionId(sink_params_, this, session_id_); | 246 sink_->Initialize(sink_params_, this); |
| 246 sink_->Start(); | 247 sink_->Start(); |
| 247 sink_started_ = true; | 248 sink_started_ = true; |
| 248 UMA_HISTOGRAM_ENUMERATION("Media.LocalRendererSinkStates", | 249 UMA_HISTOGRAM_ENUMERATION("Media.LocalRendererSinkStates", |
| 249 kSinkStarted, kSinkStatesMax); | 250 kSinkStarted, kSinkStatesMax); |
| 250 } | 251 } |
| 251 | 252 |
| 252 void WebRtcLocalAudioRenderer::ReconfigureSink( | 253 void WebRtcLocalAudioRenderer::ReconfigureSink( |
| 253 const media::AudioParameters& params) { | 254 const media::AudioParameters& params) { |
| 254 DCHECK(task_runner_->BelongsToCurrentThread()); | 255 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 255 | 256 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 279 | 280 |
| 280 base::AutoLock auto_lock(thread_lock_); | 281 base::AutoLock auto_lock(thread_lock_); |
| 281 audio_shifter_.reset(new_shifter); | 282 audio_shifter_.reset(new_shifter); |
| 282 } | 283 } |
| 283 | 284 |
| 284 if (!sink_.get()) | 285 if (!sink_.get()) |
| 285 return; // WebRtcLocalAudioRenderer has not yet been started. | 286 return; // WebRtcLocalAudioRenderer has not yet been started. |
| 286 | 287 |
| 287 // Stop |sink_| and re-create a new one to be initialized with different audio | 288 // Stop |sink_| and re-create a new one to be initialized with different audio |
| 288 // parameters. Then, invoke MaybeStartSink() to restart everything again. | 289 // parameters. Then, invoke MaybeStartSink() to restart everything again. |
| 289 if (sink_started_) { | 290 sink_->Stop(); |
| 290 sink_->Stop(); | 291 sink_started_ = false; |
| 291 sink_started_ = false; | |
| 292 } | |
| 293 | 292 |
| 294 sink_ = AudioDeviceFactory::NewOutputDevice(source_render_frame_id_); | 293 sink_ = AudioDeviceFactory::NewOutputDevice( |
| 294 source_render_frame_id_, session_id_, std::string(), url::Origin()); |
| 295 MaybeStartSink(); | 295 MaybeStartSink(); |
| 296 } | 296 } |
| 297 | 297 |
| 298 } // namespace content | 298 } // namespace content |
| OLD | NEW |