| 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/webaudio_capturer_source.h" | 5 #include "content/renderer/media/webaudio_capturer_source.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "content/renderer/media/webrtc_audio_capturer.h" | 9 #include "content/renderer/media/webrtc_audio_capturer.h" |
| 10 #include "content/renderer/media/webrtc_local_audio_track.h" | 10 #include "content/renderer/media/webrtc_local_audio_track.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 capture_bus_ = AudioBus::Create(params_); | 56 capture_bus_ = AudioBus::Create(params_); |
| 57 fifo_.reset(new AudioFifo( | 57 fifo_.reset(new AudioFifo( |
| 58 params_.channels(), | 58 params_.channels(), |
| 59 kMaxNumberOfBuffersInFifo * params_.frames_per_buffer())); | 59 kMaxNumberOfBuffersInFifo * params_.frames_per_buffer())); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void WebAudioCapturerSource::Start( | 62 void WebAudioCapturerSource::Start( |
| 63 WebRtcLocalAudioTrack* track, WebRtcAudioCapturer* capturer) { | 63 WebRtcLocalAudioTrack* track, WebRtcAudioCapturer* capturer) { |
| 64 DCHECK(thread_checker_.CalledOnValidThread()); | 64 DCHECK(thread_checker_.CalledOnValidThread()); |
| 65 DCHECK(track); | 65 DCHECK(track); |
| 66 // The downstream client should be configured the same as what WebKit | |
| 67 // is feeding it. | |
| 68 if (params_.IsValid()) | |
| 69 track->SetCaptureFormat(params_); | |
| 70 | |
| 71 base::AutoLock auto_lock(lock_); | 66 base::AutoLock auto_lock(lock_); |
| 72 track_ = track; | 67 track_ = track; |
| 73 capturer_ = capturer; | 68 capturer_ = capturer; |
| 74 } | 69 } |
| 75 | 70 |
| 76 void WebAudioCapturerSource::Stop() { | 71 void WebAudioCapturerSource::Stop() { |
| 77 DCHECK(thread_checker_.CalledOnValidThread()); | 72 DCHECK(thread_checker_.CalledOnValidThread()); |
| 78 base::AutoLock auto_lock(lock_); | 73 base::AutoLock auto_lock(lock_); |
| 79 track_ = NULL; | 74 track_ = NULL; |
| 80 capturer_ = NULL; | 75 capturer_ = NULL; |
| 81 } | 76 } |
| 82 | 77 |
| 83 void WebAudioCapturerSource::consumeAudio( | 78 void WebAudioCapturerSource::consumeAudio( |
| 84 const blink::WebVector<const float*>& audio_data, | 79 const blink::WebVector<const float*>& audio_data, |
| 85 size_t number_of_frames) { | 80 size_t number_of_frames) { |
| 86 base::AutoLock auto_lock(lock_); | 81 base::AutoLock auto_lock(lock_); |
| 87 if (!track_) | 82 if (!track_) |
| 88 return; | 83 return; |
| 89 | 84 |
| 90 // Update the downstream client if the audio format has been changed. | 85 // Update the downstream client if the audio format has been changed. |
| 91 if (audio_format_changed_) { | 86 if (audio_format_changed_) { |
| 92 track_->SetCaptureFormat(params_); | 87 track_->OnSetFormat(params_); |
| 93 audio_format_changed_ = false; | 88 audio_format_changed_ = false; |
| 94 } | 89 } |
| 95 | 90 |
| 96 wrapper_bus_->set_frames(number_of_frames); | 91 wrapper_bus_->set_frames(number_of_frames); |
| 97 | 92 |
| 98 // Make sure WebKit is honoring what it told us up front | 93 // Make sure WebKit is honoring what it told us up front |
| 99 // about the channels. | 94 // about the channels. |
| 100 DCHECK_EQ(params_.channels(), static_cast<int>(audio_data.size())); | 95 DCHECK_EQ(params_.channels(), static_cast<int>(audio_data.size())); |
| 101 | 96 |
| 102 for (size_t i = 0; i < audio_data.size(); ++i) | 97 for (size_t i = 0; i < audio_data.size(); ++i) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 118 capturer_->GetAudioProcessingParams(&delay, &volume, &key_pressed); | 113 capturer_->GetAudioProcessingParams(&delay, &volume, &key_pressed); |
| 119 } | 114 } |
| 120 while (fifo_->frames() >= capture_frames) { | 115 while (fifo_->frames() >= capture_frames) { |
| 121 fifo_->Consume(capture_bus_.get(), 0, capture_frames); | 116 fifo_->Consume(capture_bus_.get(), 0, capture_frames); |
| 122 track_->Capture(capture_bus_.get(), delay.InMilliseconds(), | 117 track_->Capture(capture_bus_.get(), delay.InMilliseconds(), |
| 123 volume, key_pressed); | 118 volume, key_pressed); |
| 124 } | 119 } |
| 125 } | 120 } |
| 126 | 121 |
| 127 } // namespace content | 122 } // namespace content |
| OLD | NEW |