Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(448)

Side by Side Diff: content/renderer/media/webrtc_audio_capturer.cc

Issue 11369171: Add chromium support for MediaStreamAudioDestinationNode (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/renderer/media/webrtc_audio_capturer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 base::AutoLock auto_lock(lock_); 93 base::AutoLock auto_lock(lock_);
94 for (SinkList::iterator it = sinks_.begin(); it != sinks_.end(); ++it) { 94 for (SinkList::iterator it = sinks_.begin(); it != sinks_.end(); ++it) {
95 if (sink == *it) { 95 if (sink == *it) {
96 sinks_.erase(it); 96 sinks_.erase(it);
97 break; 97 break;
98 } 98 }
99 } 99 }
100 } 100 }
101 101
102 void WebRtcAudioCapturer::SetCapturerSource( 102 void WebRtcAudioCapturer::SetCapturerSource(
103 const scoped_refptr<media::AudioCapturerSource>& source) { 103 const scoped_refptr<media::AudioCapturerSource>& source,
104 media::ChannelLayout channel_layout,
105 float sample_rate) {
104 DVLOG(1) << "SetCapturerSource()"; 106 DVLOG(1) << "SetCapturerSource()";
105 scoped_refptr<media::AudioCapturerSource> old_source; 107 scoped_refptr<media::AudioCapturerSource> old_source;
106 { 108 {
107 base::AutoLock auto_lock(lock_); 109 base::AutoLock auto_lock(lock_);
108 if (source_ == source) 110 if (source_ == source)
109 return; 111 return;
110 112
111 source_.swap(old_source); 113 source_.swap(old_source);
112 source_ = source; 114 source_ = source;
113 } 115 }
114 116
115 // Detach the old source from normal recording. 117 // Detach the old source from normal recording.
116 if (old_source) 118 if (old_source) {
117 old_source->Stop(); 119 old_source->Stop();
118 120
121 // Dispatch the new parameters both to the
122 // sink(s) and to the new source. The idea is to get rid of any dependency
123 // of the microphone parameters which are used as base otherwise.
124
125 // henrika:
henrika (OOO until Aug 14) 2013/01/08 09:52:27 Guess we could clean up here now. Also, I did not
Chris Rogers 2013/01/14 23:12:14 Done.
126 // I guess we could add this info to AudioCapturerSource to enable a
127 // query here. E.g.:
128 // source->ModifyAudioParameters(&params_);
129 //
130 // crogers: we could do as you suggest, but instead I've modified
131 // SetCapturerSource() to take the |channel_layout| and |sample_rate|.
132 // Neither solution seems that great, since we just end up calling
133 // source->Initialize(params_, this, this);
134 // anyway, but we have to do something...
135
136 params_.Reset(params_.format(),
henrika (OOO until Aug 14) 2013/01/08 09:52:27 I had anticipated that the sample rate would be th
Chris Rogers 2013/01/14 23:12:14 The sample-rate will generally be the hardware sam
137 channel_layout,
138 sample_rate,
139 16, // this value is not really used
140 440); // requires knowledge about WebRTC @ 10ms
henrika (OOO until Aug 14) 2013/01/07 10:14:28 Chris, what range of sample rates can we expect fr
Chris Rogers 2013/01/14 23:12:14 It will be the hardware sample-rate that the Audio
141
142 buffer_.reset(new int16[params_.frames_per_buffer() * params_.channels()]);
143
144 for (SinkList::const_iterator it = sinks_.begin();
145 it != sinks_.end(); ++it) {
146 (*it)->SetCaptureFormat(params_);
147 }
148 }
149
119 if (source) 150 if (source)
120 source->Initialize(params_, this, this); 151 source->Initialize(params_, this, this);
121 } 152 }
122 153
123 void WebRtcAudioCapturer::SetStopCallback( 154 void WebRtcAudioCapturer::SetStopCallback(
124 const base::Closure& on_device_stopped_cb) { 155 const base::Closure& on_device_stopped_cb) {
125 DVLOG(1) << "WebRtcAudioCapturer::SetStopCallback()"; 156 DVLOG(1) << "WebRtcAudioCapturer::SetStopCallback()";
126 base::AutoLock auto_lock(lock_); 157 base::AutoLock auto_lock(lock_);
127 on_device_stopped_cb_ = on_device_stopped_cb; 158 on_device_stopped_cb_ = on_device_stopped_cb;
128 } 159 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 return false; 236 return false;
206 } 237 }
207 238
208 params_.Reset(format, channel_layout, sample_rate, 16, buffer_size); 239 params_.Reset(format, channel_layout, sample_rate, 16, buffer_size);
209 240
210 buffer_.reset(new int16[params_.frames_per_buffer() * params_.channels()]); 241 buffer_.reset(new int16[params_.frames_per_buffer() * params_.channels()]);
211 242
212 // Create and configure the default audio capturing source. The |source_| 243 // Create and configure the default audio capturing source. The |source_|
213 // will be overwritten if the client call the source calls 244 // will be overwritten if the client call the source calls
214 // SetCapturerSource(). 245 // SetCapturerSource().
215 SetCapturerSource(AudioDeviceFactory::NewInputDevice()); 246 SetCapturerSource(
247 AudioDeviceFactory::NewInputDevice(), channel_layout, sample_rate);
216 248
217 UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioInputChannelLayout", 249 UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioInputChannelLayout",
218 channel_layout, media::CHANNEL_LAYOUT_MAX); 250 channel_layout, media::CHANNEL_LAYOUT_MAX);
219 251
220 return true; 252 return true;
221 } 253 }
222 254
223 void WebRtcAudioCapturer::ProvideInput(media::AudioBus* dest) { 255 void WebRtcAudioCapturer::ProvideInput(media::AudioBus* dest) {
224 base::AutoLock auto_lock(lock_); 256 base::AutoLock auto_lock(lock_);
225 DCHECK(loopback_fifo_.get() != NULL); 257 DCHECK(loopback_fifo_.get() != NULL);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 // Inform the local renderer about the stopped device. 402 // Inform the local renderer about the stopped device.
371 // The renderer can then save resources by not asking for more data from 403 // The renderer can then save resources by not asking for more data from
372 // the stopped source. We are on the IO thread but the callback task will 404 // the stopped source. We are on the IO thread but the callback task will
373 // be posted on the message loop of the main render thread thanks to 405 // be posted on the message loop of the main render thread thanks to
374 // usage of BindToLoop() when the callback was initialized. 406 // usage of BindToLoop() when the callback was initialized.
375 if (!on_device_stopped_cb_.is_null()) 407 if (!on_device_stopped_cb_.is_null())
376 on_device_stopped_cb_.Run(); 408 on_device_stopped_cb_.Run();
377 } 409 }
378 410
379 } // namespace content 411 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc_audio_capturer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698