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

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
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 sink(s) and to the new source.
122 // The idea is to get rid of any dependency of the microphone parameters
123 // which would normally be used by default.
124
125 int buffer_size = GetBufferSizeForSampleRate(sample_rate);
126 if (!buffer_size) {
127 DLOG(ERROR) << "Unsupported sample-rate: " << sample_rate;
128 return;
129 }
130
131 params_.Reset(params_.format(),
132 channel_layout,
133 sample_rate,
134 16, // ignored since the audio stack uses float32.
135 buffer_size);
136
137 buffer_.reset(new int16[params_.frames_per_buffer() * params_.channels()]);
138
139 for (SinkList::const_iterator it = sinks_.begin();
140 it != sinks_.end(); ++it) {
141 (*it)->SetCaptureFormat(params_);
142 }
143 }
144
119 if (source) 145 if (source)
120 source->Initialize(params_, this, this); 146 source->Initialize(params_, this, this);
121 } 147 }
122 148
123 void WebRtcAudioCapturer::SetStopCallback( 149 void WebRtcAudioCapturer::SetStopCallback(
124 const base::Closure& on_device_stopped_cb) { 150 const base::Closure& on_device_stopped_cb) {
125 DVLOG(1) << "WebRtcAudioCapturer::SetStopCallback()"; 151 DVLOG(1) << "WebRtcAudioCapturer::SetStopCallback()";
126 base::AutoLock auto_lock(lock_); 152 base::AutoLock auto_lock(lock_);
127 on_device_stopped_cb_ = on_device_stopped_cb; 153 on_device_stopped_cb_ = on_device_stopped_cb;
128 } 154 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 return false; 231 return false;
206 } 232 }
207 233
208 params_.Reset(format, channel_layout, sample_rate, 16, buffer_size); 234 params_.Reset(format, channel_layout, sample_rate, 16, buffer_size);
209 235
210 buffer_.reset(new int16[params_.frames_per_buffer() * params_.channels()]); 236 buffer_.reset(new int16[params_.frames_per_buffer() * params_.channels()]);
211 237
212 // Create and configure the default audio capturing source. The |source_| 238 // Create and configure the default audio capturing source. The |source_|
213 // will be overwritten if the client call the source calls 239 // will be overwritten if the client call the source calls
214 // SetCapturerSource(). 240 // SetCapturerSource().
215 SetCapturerSource(AudioDeviceFactory::NewInputDevice()); 241 SetCapturerSource(
242 AudioDeviceFactory::NewInputDevice(), channel_layout, sample_rate);
216 243
217 UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioInputChannelLayout", 244 UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioInputChannelLayout",
218 channel_layout, media::CHANNEL_LAYOUT_MAX); 245 channel_layout, media::CHANNEL_LAYOUT_MAX);
219 246
220 return true; 247 return true;
221 } 248 }
222 249
223 void WebRtcAudioCapturer::ProvideInput(media::AudioBus* dest) { 250 void WebRtcAudioCapturer::ProvideInput(media::AudioBus* dest) {
224 base::AutoLock auto_lock(lock_); 251 base::AutoLock auto_lock(lock_);
225 DCHECK(loopback_fifo_.get() != NULL); 252 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. 397 // Inform the local renderer about the stopped device.
371 // The renderer can then save resources by not asking for more data from 398 // 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 399 // 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 400 // be posted on the message loop of the main render thread thanks to
374 // usage of BindToLoop() when the callback was initialized. 401 // usage of BindToLoop() when the callback was initialized.
375 if (!on_device_stopped_cb_.is_null()) 402 if (!on_device_stopped_cb_.is_null())
376 on_device_stopped_cb_.Run(); 403 on_device_stopped_cb_.Run();
377 } 404 }
378 405
379 } // namespace content 406 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698