OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_audio_device_impl.h" | 5 #include "content/renderer/media/webrtc_audio_device_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/win/windows_version.h" | 10 #include "base/win/windows_version.h" |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 215 |
216 int32_t WebRtcAudioDeviceImpl::Init() { | 216 int32_t WebRtcAudioDeviceImpl::Init() { |
217 DVLOG(1) << "WebRtcAudioDeviceImpl::Init()"; | 217 DVLOG(1) << "WebRtcAudioDeviceImpl::Init()"; |
218 DCHECK(thread_checker_.CalledOnValidThread()); | 218 DCHECK(thread_checker_.CalledOnValidThread()); |
219 | 219 |
220 if (initialized_) | 220 if (initialized_) |
221 return 0; | 221 return 0; |
222 | 222 |
223 DCHECK(!capturer_.get()); | 223 DCHECK(!capturer_.get()); |
224 capturer_ = WebRtcAudioCapturer::CreateCapturer(); | 224 capturer_ = WebRtcAudioCapturer::CreateCapturer(); |
| 225 |
225 // Add itself as an audio track to the |capturer_|. This is because WebRTC | 226 // Add itself as an audio track to the |capturer_|. This is because WebRTC |
226 // supports only one ADM but multiple audio tracks, so the ADM can't be the | 227 // supports only one ADM but multiple audio tracks, so the ADM can't be the |
227 // sink of certain audio track now. | 228 // sink of certain audio track now. |
228 // TODO(xians): Register the ADM as the sink of the audio track if WebRTC | 229 // TODO(xians): Register the ADM as the sink of the audio track if WebRTC |
229 // supports one ADM for each audio track. | 230 // supports one ADM for each audio track. See http://crbug/247027. |
230 if (capturer_.get()) | 231 capturer_->SetDefaultSink(this); |
231 capturer_->AddSink(this); | |
232 | 232 |
233 // We need to return a success to continue the initialization of WebRtc VoE | 233 // We need to return a success to continue the initialization of WebRtc VoE |
234 // because failure on the capturer_ initialization should not prevent WebRTC | 234 // because failure on the capturer_ initialization should not prevent WebRTC |
235 // from working. See issue http://crbug.com/144421 for details. | 235 // from working. See issue http://crbug.com/144421 for details. |
236 initialized_ = true; | 236 initialized_ = true; |
237 | 237 |
238 return 0; | 238 return 0; |
239 } | 239 } |
240 | 240 |
241 int32_t WebRtcAudioDeviceImpl::Terminate() { | 241 int32_t WebRtcAudioDeviceImpl::Terminate() { |
(...skipping 12 matching lines...) Expand all Loading... |
254 // Grab a local reference while we call Stop(), which will trigger a call to | 254 // Grab a local reference while we call Stop(), which will trigger a call to |
255 // RemoveAudioRenderer that clears our reference to the audio renderer. | 255 // RemoveAudioRenderer that clears our reference to the audio renderer. |
256 scoped_refptr<WebRtcAudioRenderer> local_renderer(renderer_); | 256 scoped_refptr<WebRtcAudioRenderer> local_renderer(renderer_); |
257 local_renderer->Stop(); | 257 local_renderer->Stop(); |
258 DCHECK(!renderer_.get()); | 258 DCHECK(!renderer_.get()); |
259 } | 259 } |
260 | 260 |
261 if (capturer_.get()) { | 261 if (capturer_.get()) { |
262 // |capturer_| is stopped by the media stream, so do not need to | 262 // |capturer_| is stopped by the media stream, so do not need to |
263 // call Stop() here. | 263 // call Stop() here. |
264 capturer_->RemoveSink(this); | 264 capturer_->SetDefaultSink(NULL); |
265 capturer_ = NULL; | 265 capturer_ = NULL; |
266 } | 266 } |
267 | 267 |
268 initialized_ = false; | 268 initialized_ = false; |
269 return 0; | 269 return 0; |
270 } | 270 } |
271 | 271 |
272 bool WebRtcAudioDeviceImpl::Initialized() const { | 272 bool WebRtcAudioDeviceImpl::Initialized() const { |
273 return initialized_; | 273 return initialized_; |
274 } | 274 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 } | 336 } |
337 | 337 |
338 int32_t WebRtcAudioDeviceImpl::StartRecording() { | 338 int32_t WebRtcAudioDeviceImpl::StartRecording() { |
339 DVLOG(1) << "WebRtcAudioDeviceImpl::StartRecording()"; | 339 DVLOG(1) << "WebRtcAudioDeviceImpl::StartRecording()"; |
340 DCHECK(initialized_); | 340 DCHECK(initialized_); |
341 LOG_IF(ERROR, !audio_transport_callback_) << "Audio transport is missing"; | 341 LOG_IF(ERROR, !audio_transport_callback_) << "Audio transport is missing"; |
342 if (!audio_transport_callback_) { | 342 if (!audio_transport_callback_) { |
343 return -1; | 343 return -1; |
344 } | 344 } |
345 | 345 |
| 346 { |
| 347 base::AutoLock auto_lock(lock_); |
| 348 if (recording_) |
| 349 return 0; |
| 350 |
| 351 recording_ = true; |
| 352 } |
| 353 |
346 start_capture_time_ = base::Time::Now(); | 354 start_capture_time_ = base::Time::Now(); |
347 | 355 |
348 base::AutoLock auto_lock(lock_); | |
349 recording_ = true; | |
350 | |
351 return 0; | 356 return 0; |
352 } | 357 } |
353 | 358 |
354 int32_t WebRtcAudioDeviceImpl::StopRecording() { | 359 int32_t WebRtcAudioDeviceImpl::StopRecording() { |
355 DVLOG(1) << "WebRtcAudioDeviceImpl::StopRecording()"; | 360 DVLOG(1) << "WebRtcAudioDeviceImpl::StopRecording()"; |
356 if (!recording_) { | 361 { |
357 return 0; | 362 base::AutoLock auto_lock(lock_); |
| 363 if (!recording_) |
| 364 return 0; |
| 365 |
| 366 recording_ = false; |
358 } | 367 } |
359 | 368 |
360 // Add histogram data to be uploaded as part of an UMA logging event. | 369 // Add histogram data to be uploaded as part of an UMA logging event. |
361 // This histogram keeps track of total recording times. | 370 // This histogram keeps track of total recording times. |
362 if (!start_capture_time_.is_null()) { | 371 if (!start_capture_time_.is_null()) { |
363 base::TimeDelta capture_time = base::Time::Now() - start_capture_time_; | 372 base::TimeDelta capture_time = base::Time::Now() - start_capture_time_; |
364 UMA_HISTOGRAM_LONG_TIMES("WebRTC.AudioCaptureTime", capture_time); | 373 UMA_HISTOGRAM_LONG_TIMES("WebRTC.AudioCaptureTime", capture_time); |
365 } | 374 } |
366 | 375 |
367 base::AutoLock auto_lock(lock_); | |
368 recording_ = false; | |
369 | |
370 return 0; | 376 return 0; |
371 } | 377 } |
372 | 378 |
373 bool WebRtcAudioDeviceImpl::Recording() const { | 379 bool WebRtcAudioDeviceImpl::Recording() const { |
374 base::AutoLock auto_lock(lock_); | 380 base::AutoLock auto_lock(lock_); |
375 return recording_; | 381 return recording_; |
376 } | 382 } |
377 | 383 |
378 int32_t WebRtcAudioDeviceImpl::SetAGC(bool enable) { | 384 int32_t WebRtcAudioDeviceImpl::SetAGC(bool enable) { |
379 DVLOG(1) << "WebRtcAudioDeviceImpl::SetAGC(enable=" << enable << ")"; | 385 DVLOG(1) << "WebRtcAudioDeviceImpl::SetAGC(enable=" << enable << ")"; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 return false; | 497 return false; |
492 | 498 |
493 if (!renderer->Initialize(this)) | 499 if (!renderer->Initialize(this)) |
494 return false; | 500 return false; |
495 | 501 |
496 renderer_ = renderer; | 502 renderer_ = renderer; |
497 return true; | 503 return true; |
498 } | 504 } |
499 | 505 |
500 } // namespace content | 506 } // namespace content |
OLD | NEW |