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/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 friend class base::RefCounted<WebRtcAudioCapturer::ConfiguredBuffer>; | 172 friend class base::RefCounted<WebRtcAudioCapturer::ConfiguredBuffer>; |
173 | 173 |
174 scoped_ptr<int16[]> buffer_; | 174 scoped_ptr<int16[]> buffer_; |
175 | 175 |
176 // Cached values of utilized audio parameters. | 176 // Cached values of utilized audio parameters. |
177 media::AudioParameters params_; | 177 media::AudioParameters params_; |
178 }; | 178 }; |
179 | 179 |
180 // static | 180 // static |
181 scoped_refptr<WebRtcAudioCapturer> WebRtcAudioCapturer::CreateCapturer() { | 181 scoped_refptr<WebRtcAudioCapturer> WebRtcAudioCapturer::CreateCapturer() { |
182 scoped_refptr<WebRtcAudioCapturer> capturer = new WebRtcAudioCapturer(); | 182 scoped_refptr<WebRtcAudioCapturer> capturer = new WebRtcAudioCapturer(); |
183 return capturer; | 183 return capturer; |
184 } | 184 } |
185 | 185 |
186 bool WebRtcAudioCapturer::Reconfigure(int sample_rate, | 186 bool WebRtcAudioCapturer::Reconfigure(int sample_rate, |
187 media::ChannelLayout channel_layout) { | 187 media::ChannelLayout channel_layout) { |
188 scoped_refptr<ConfiguredBuffer> new_buffer(new ConfiguredBuffer()); | 188 scoped_refptr<ConfiguredBuffer> new_buffer(new ConfiguredBuffer()); |
189 if (!new_buffer->Initialize(sample_rate, channel_layout)) | 189 if (!new_buffer->Initialize(sample_rate, channel_layout)) |
190 return false; | 190 return false; |
191 | 191 |
192 SinkList sinks; | 192 SinkList sinks; |
193 { | 193 { |
194 base::AutoLock auto_lock(lock_); | 194 base::AutoLock auto_lock(lock_); |
195 | 195 |
196 buffer_ = new_buffer; | 196 buffer_ = new_buffer; |
197 sinks = sinks_; | 197 sinks = sinks_; |
198 } | 198 } |
199 | 199 |
200 // Tell all sinks which format we use. | 200 // Tell all sinks which format we use. |
201 for (SinkList::const_iterator it = sinks.begin(); it != sinks.end(); ++it) | 201 for (SinkList::const_iterator it = sinks.begin(); it != sinks.end(); ++it) |
202 (*it)->SetCaptureFormat(new_buffer->params()); | 202 (*it)->SetCaptureFormat(new_buffer->params()); |
203 | 203 |
204 return true; | 204 return true; |
205 } | 205 } |
206 | 206 |
207 bool WebRtcAudioCapturer::Initialize(media::ChannelLayout channel_layout, | 207 bool WebRtcAudioCapturer::Initialize(int render_view_id, |
| 208 media::ChannelLayout channel_layout, |
208 int sample_rate, | 209 int sample_rate, |
209 int session_id) { | 210 int session_id) { |
210 DCHECK(thread_checker_.CalledOnValidThread()); | 211 DCHECK(thread_checker_.CalledOnValidThread()); |
211 DCHECK(!sinks_.empty()); | 212 DCHECK(!sinks_.empty()); |
212 DVLOG(1) << "WebRtcAudioCapturer::Initialize()"; | 213 DVLOG(1) << "WebRtcAudioCapturer::Initialize()"; |
213 | 214 |
214 DVLOG(1) << "Audio input hardware channel layout: " << channel_layout; | 215 DVLOG(1) << "Audio input hardware channel layout: " << channel_layout; |
215 UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioInputChannelLayout", | 216 UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioInputChannelLayout", |
216 channel_layout, media::CHANNEL_LAYOUT_MAX); | 217 channel_layout, media::CHANNEL_LAYOUT_MAX); |
217 | 218 |
(...skipping 20 matching lines...) Expand all Loading... |
238 DLOG(ERROR) << sample_rate << " is not a supported input rate."; | 239 DLOG(ERROR) << sample_rate << " is not a supported input rate."; |
239 return false; | 240 return false; |
240 } | 241 } |
241 | 242 |
242 if (!Reconfigure(sample_rate, channel_layout)) | 243 if (!Reconfigure(sample_rate, channel_layout)) |
243 return false; | 244 return false; |
244 | 245 |
245 // Create and configure the default audio capturing source. The |source_| | 246 // Create and configure the default audio capturing source. The |source_| |
246 // will be overwritten if an external client later calls SetCapturerSource() | 247 // will be overwritten if an external client later calls SetCapturerSource() |
247 // providing an alternative media::AudioCapturerSource. | 248 // providing an alternative media::AudioCapturerSource. |
248 SetCapturerSource(AudioDeviceFactory::NewInputDevice(), | 249 SetCapturerSource(AudioDeviceFactory::NewInputDevice(render_view_id), |
249 channel_layout, | 250 channel_layout, |
250 static_cast<float>(sample_rate)); | 251 static_cast<float>(sample_rate)); |
251 | 252 |
252 return true; | 253 return true; |
253 } | 254 } |
254 | 255 |
255 WebRtcAudioCapturer::WebRtcAudioCapturer() | 256 WebRtcAudioCapturer::WebRtcAudioCapturer() |
256 : source_(NULL), | 257 : source_(NULL), |
257 running_(false), | 258 running_(false), |
258 agc_is_enabled_(false), | 259 agc_is_enabled_(false), |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 void WebRtcAudioCapturer::OnCaptureError() { | 441 void WebRtcAudioCapturer::OnCaptureError() { |
441 NOTIMPLEMENTED(); | 442 NOTIMPLEMENTED(); |
442 } | 443 } |
443 | 444 |
444 media::AudioParameters WebRtcAudioCapturer::audio_parameters() const { | 445 media::AudioParameters WebRtcAudioCapturer::audio_parameters() const { |
445 base::AutoLock auto_lock(lock_); | 446 base::AutoLock auto_lock(lock_); |
446 return buffer_->params(); | 447 return buffer_->params(); |
447 } | 448 } |
448 | 449 |
449 } // namespace content | 450 } // namespace content |
OLD | NEW |