| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 friend class base::RefCounted<WebRtcAudioCapturer::ConfiguredBuffer>; | 102 friend class base::RefCounted<WebRtcAudioCapturer::ConfiguredBuffer>; |
| 103 | 103 |
| 104 scoped_ptr<int16[]> buffer_; | 104 scoped_ptr<int16[]> buffer_; |
| 105 | 105 |
| 106 // Cached values of utilized audio parameters. | 106 // Cached values of utilized audio parameters. |
| 107 media::AudioParameters params_; | 107 media::AudioParameters params_; |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 // static | 110 // static |
| 111 scoped_refptr<WebRtcAudioCapturer> WebRtcAudioCapturer::CreateCapturer() { | 111 scoped_refptr<WebRtcAudioCapturer> WebRtcAudioCapturer::CreateCapturer() { |
| 112 scoped_refptr<WebRtcAudioCapturer> capturer = new WebRtcAudioCapturer(); | 112 scoped_refptr<WebRtcAudioCapturer> capturer = new WebRtcAudioCapturer(); |
| 113 return capturer; | 113 return capturer; |
| 114 } | 114 } |
| 115 | 115 |
| 116 bool WebRtcAudioCapturer::Reconfigure(int sample_rate, | 116 bool WebRtcAudioCapturer::Reconfigure(int sample_rate, |
| 117 media::ChannelLayout channel_layout) { | 117 media::ChannelLayout channel_layout) { |
| 118 scoped_refptr<ConfiguredBuffer> new_buffer(new ConfiguredBuffer()); | 118 scoped_refptr<ConfiguredBuffer> new_buffer(new ConfiguredBuffer()); |
| 119 if (!new_buffer->Initialize(sample_rate, channel_layout)) | 119 if (!new_buffer->Initialize(sample_rate, channel_layout)) |
| 120 return false; | 120 return false; |
| 121 | 121 |
| 122 SinkList sinks; | 122 SinkList sinks; |
| 123 { | 123 { |
| 124 base::AutoLock auto_lock(lock_); | 124 base::AutoLock auto_lock(lock_); |
| 125 | 125 |
| 126 buffer_ = new_buffer; | 126 buffer_ = new_buffer; |
| 127 sinks = sinks_; | 127 sinks = sinks_; |
| 128 } | 128 } |
| 129 | 129 |
| 130 // Tell all sinks which format we use. | 130 // Tell all sinks which format we use. |
| 131 for (SinkList::const_iterator it = sinks.begin(); it != sinks.end(); ++it) | 131 for (SinkList::const_iterator it = sinks.begin(); it != sinks.end(); ++it) |
| 132 (*it)->SetCaptureFormat(new_buffer->params()); | 132 (*it)->SetCaptureFormat(new_buffer->params()); |
| 133 | 133 |
| 134 return true; | 134 return true; |
| 135 } | 135 } |
| 136 | 136 |
| 137 bool WebRtcAudioCapturer::Initialize(media::ChannelLayout channel_layout, | 137 bool WebRtcAudioCapturer::Initialize(int render_view_id, |
| 138 media::ChannelLayout channel_layout, |
| 138 int sample_rate) { | 139 int sample_rate) { |
| 139 DCHECK(thread_checker_.CalledOnValidThread()); | 140 DCHECK(thread_checker_.CalledOnValidThread()); |
| 140 DCHECK(!sinks_.empty()); | 141 DCHECK(!sinks_.empty()); |
| 141 DVLOG(1) << "WebRtcAudioCapturer::Initialize()"; | 142 DVLOG(1) << "WebRtcAudioCapturer::Initialize()"; |
| 142 | 143 |
| 143 DVLOG(1) << "Audio input hardware channel layout: " << channel_layout; | 144 DVLOG(1) << "Audio input hardware channel layout: " << channel_layout; |
| 144 UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioInputChannelLayout", | 145 UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioInputChannelLayout", |
| 145 channel_layout, media::CHANNEL_LAYOUT_MAX); | 146 channel_layout, media::CHANNEL_LAYOUT_MAX); |
| 146 | 147 |
| 147 // Verify that the reported input channel configuration is supported. | 148 // Verify that the reported input channel configuration is supported. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 164 &kValidInputRates[arraysize(kValidInputRates)]) { | 165 &kValidInputRates[arraysize(kValidInputRates)]) { |
| 165 DLOG(ERROR) << sample_rate << " is not a supported input rate."; | 166 DLOG(ERROR) << sample_rate << " is not a supported input rate."; |
| 166 return false; | 167 return false; |
| 167 } | 168 } |
| 168 | 169 |
| 169 if (!Reconfigure(sample_rate, channel_layout)) | 170 if (!Reconfigure(sample_rate, channel_layout)) |
| 170 return false; | 171 return false; |
| 171 | 172 |
| 172 // Create and configure the default audio capturing source. The |source_| | 173 // Create and configure the default audio capturing source. The |source_| |
| 173 // will be overwritten if an external client later calls SetCapturerSource() | 174 // will be overwritten if an external client later calls SetCapturerSource() |
| 174 // providing an alternaive media::AudioCapturerSource. | 175 // providing an alternative media::AudioCapturerSource. |
| 175 SetCapturerSource(AudioDeviceFactory::NewInputDevice(), | 176 SetCapturerSource(AudioDeviceFactory::NewInputDevice(render_view_id), |
| 176 channel_layout, | 177 channel_layout, |
| 177 static_cast<float>(sample_rate)); | 178 static_cast<float>(sample_rate)); |
| 178 | 179 |
| 179 return true; | 180 return true; |
| 180 } | 181 } |
| 181 | 182 |
| 182 WebRtcAudioCapturer::WebRtcAudioCapturer() | 183 WebRtcAudioCapturer::WebRtcAudioCapturer() |
| 183 : source_(NULL), | 184 : source_(NULL), |
| 184 running_(false), | 185 running_(false), |
| 185 buffering_(false), | 186 buffering_(false), |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 if (!on_device_stopped_cb_.is_null()) | 489 if (!on_device_stopped_cb_.is_null()) |
| 489 on_device_stopped_cb_.Run(); | 490 on_device_stopped_cb_.Run(); |
| 490 } | 491 } |
| 491 | 492 |
| 492 media::AudioParameters WebRtcAudioCapturer::audio_parameters() const { | 493 media::AudioParameters WebRtcAudioCapturer::audio_parameters() const { |
| 493 base::AutoLock auto_lock(lock_); | 494 base::AutoLock auto_lock(lock_); |
| 494 return buffer_->params(); | 495 return buffer_->params(); |
| 495 } | 496 } |
| 496 | 497 |
| 497 } // namespace content | 498 } // namespace content |
| OLD | NEW |