| 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_audio_capturer.h" | 5 #include "content/renderer/media/webrtc_audio_capturer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.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/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 DVLOG(1) << "WebRtcAudioCapturer::AddTrack()"; | 257 DVLOG(1) << "WebRtcAudioCapturer::AddTrack()"; |
| 258 | 258 |
| 259 { | 259 { |
| 260 base::AutoLock auto_lock(lock_); | 260 base::AutoLock auto_lock(lock_); |
| 261 // Verify that |track| is not already added to the list. | 261 // Verify that |track| is not already added to the list. |
| 262 DCHECK(!tracks_.Contains(TrackOwner::TrackWrapper(track))); | 262 DCHECK(!tracks_.Contains(TrackOwner::TrackWrapper(track))); |
| 263 | 263 |
| 264 // Add with a tag, so we remember to call OnSetFormat() on the new | 264 // Add with a tag, so we remember to call OnSetFormat() on the new |
| 265 // track. | 265 // track. |
| 266 scoped_refptr<TrackOwner> track_owner(new TrackOwner(track)); | 266 scoped_refptr<TrackOwner> track_owner(new TrackOwner(track)); |
| 267 tracks_.AddAndTag(track_owner); | 267 tracks_.AddAndTag(track_owner.get()); |
| 268 } | 268 } |
| 269 } | 269 } |
| 270 | 270 |
| 271 void WebRtcAudioCapturer::RemoveTrack(WebRtcLocalAudioTrack* track) { | 271 void WebRtcAudioCapturer::RemoveTrack(WebRtcLocalAudioTrack* track) { |
| 272 DCHECK(thread_checker_.CalledOnValidThread()); | 272 DCHECK(thread_checker_.CalledOnValidThread()); |
| 273 DVLOG(1) << "WebRtcAudioCapturer::RemoveTrack()"; | 273 DVLOG(1) << "WebRtcAudioCapturer::RemoveTrack()"; |
| 274 bool stop_source = false; | 274 bool stop_source = false; |
| 275 { | 275 { |
| 276 base::AutoLock auto_lock(lock_); | 276 base::AutoLock auto_lock(lock_); |
| 277 | 277 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 // WebRtc native buffer size. | 380 // WebRtc native buffer size. |
| 381 SetCapturerSource(AudioDeviceFactory::NewInputDevice(render_view_id), | 381 SetCapturerSource(AudioDeviceFactory::NewInputDevice(render_view_id), |
| 382 input_params.channel_layout(), | 382 input_params.channel_layout(), |
| 383 static_cast<float>(input_params.sample_rate())); | 383 static_cast<float>(input_params.sample_rate())); |
| 384 } | 384 } |
| 385 | 385 |
| 386 void WebRtcAudioCapturer::Start() { | 386 void WebRtcAudioCapturer::Start() { |
| 387 DCHECK(thread_checker_.CalledOnValidThread()); | 387 DCHECK(thread_checker_.CalledOnValidThread()); |
| 388 DVLOG(1) << "WebRtcAudioCapturer::Start()"; | 388 DVLOG(1) << "WebRtcAudioCapturer::Start()"; |
| 389 base::AutoLock auto_lock(lock_); | 389 base::AutoLock auto_lock(lock_); |
| 390 if (running_ || !source_) | 390 if (running_ || !source_.get()) |
| 391 return; | 391 return; |
| 392 | 392 |
| 393 // Start the data source, i.e., start capturing data from the current source. | 393 // Start the data source, i.e., start capturing data from the current source. |
| 394 // We need to set the AGC control before starting the stream. | 394 // We need to set the AGC control before starting the stream. |
| 395 source_->SetAutomaticGainControl(true); | 395 source_->SetAutomaticGainControl(true); |
| 396 source_->Start(); | 396 source_->Start(); |
| 397 running_ = true; | 397 running_ = true; |
| 398 } | 398 } |
| 399 | 399 |
| 400 void WebRtcAudioCapturer::Stop() { | 400 void WebRtcAudioCapturer::Stop() { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 } | 547 } |
| 548 } | 548 } |
| 549 } | 549 } |
| 550 | 550 |
| 551 void WebRtcAudioCapturer::OnCaptureError() { | 551 void WebRtcAudioCapturer::OnCaptureError() { |
| 552 NOTIMPLEMENTED(); | 552 NOTIMPLEMENTED(); |
| 553 } | 553 } |
| 554 | 554 |
| 555 media::AudioParameters WebRtcAudioCapturer::source_audio_parameters() const { | 555 media::AudioParameters WebRtcAudioCapturer::source_audio_parameters() const { |
| 556 base::AutoLock auto_lock(lock_); | 556 base::AutoLock auto_lock(lock_); |
| 557 return audio_processor_ ? | 557 return audio_processor_.get() ? audio_processor_->InputFormat() |
| 558 audio_processor_->InputFormat() : media::AudioParameters(); | 558 : media::AudioParameters(); |
| 559 } | 559 } |
| 560 | 560 |
| 561 bool WebRtcAudioCapturer::GetPairedOutputParameters( | 561 bool WebRtcAudioCapturer::GetPairedOutputParameters( |
| 562 int* session_id, | 562 int* session_id, |
| 563 int* output_sample_rate, | 563 int* output_sample_rate, |
| 564 int* output_frames_per_buffer) const { | 564 int* output_frames_per_buffer) const { |
| 565 // Don't set output parameters unless all of them are valid. | 565 // Don't set output parameters unless all of them are valid. |
| 566 if (device_info_.session_id <= 0 || | 566 if (device_info_.session_id <= 0 || |
| 567 !device_info_.device.matched_output.sample_rate || | 567 !device_info_.device.matched_output.sample_rate || |
| 568 !device_info_.device.matched_output.frames_per_buffer) | 568 !device_info_.device.matched_output.frames_per_buffer) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 | 609 |
| 610 void WebRtcAudioCapturer::SetCapturerSourceForTesting( | 610 void WebRtcAudioCapturer::SetCapturerSourceForTesting( |
| 611 const scoped_refptr<media::AudioCapturerSource>& source, | 611 const scoped_refptr<media::AudioCapturerSource>& source, |
| 612 media::AudioParameters params) { | 612 media::AudioParameters params) { |
| 613 // Create a new audio stream as source which uses the new source. | 613 // Create a new audio stream as source which uses the new source. |
| 614 SetCapturerSource(source, params.channel_layout(), | 614 SetCapturerSource(source, params.channel_layout(), |
| 615 static_cast<float>(params.sample_rate())); | 615 static_cast<float>(params.sample_rate())); |
| 616 } | 616 } |
| 617 | 617 |
| 618 } // namespace content | 618 } // namespace content |
| OLD | NEW |