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

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

Issue 187913002: Support the Aec dump for the APM in chrome (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: only allow calling StartAecDump() on one APM. Created 6 years, 9 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/media_stream_audio_processor.h" 5 #include "content/renderer/media/media_stream_audio_processor.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "content/public/common/content_switches.h" 9 #include "content/public/common/content_switches.h"
10 #include "content/renderer/media/media_stream_audio_processor_options.h" 10 #include "content/renderer/media/media_stream_audio_processor_options.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 const media::AudioParameters sink_params_; 133 const media::AudioParameters sink_params_;
134 134
135 // TODO(xians): consider using SincResampler to save some memcpy. 135 // TODO(xians): consider using SincResampler to save some memcpy.
136 // Handles mixing and resampling between input and output parameters. 136 // Handles mixing and resampling between input and output parameters.
137 media::AudioConverter audio_converter_; 137 media::AudioConverter audio_converter_;
138 scoped_ptr<media::AudioBus> audio_wrapper_; 138 scoped_ptr<media::AudioBus> audio_wrapper_;
139 scoped_ptr<media::AudioFifo> fifo_; 139 scoped_ptr<media::AudioFifo> fifo_;
140 }; 140 };
141 141
142 MediaStreamAudioProcessor::MediaStreamAudioProcessor( 142 MediaStreamAudioProcessor::MediaStreamAudioProcessor(
143 const media::AudioParameters& source_params,
144 const blink::WebMediaConstraints& constraints, 143 const blink::WebMediaConstraints& constraints,
145 int effects, 144 int effects,
146 WebRtcPlayoutDataSource* playout_data_source) 145 WebRtcPlayoutDataSource* playout_data_source)
147 : render_delay_ms_(0), 146 : render_delay_ms_(0),
148 playout_data_source_(playout_data_source), 147 playout_data_source_(playout_data_source),
149 audio_mirroring_(false), 148 audio_mirroring_(false),
150 typing_detected_(false) { 149 typing_detected_(false) {
151 capture_thread_checker_.DetachFromThread(); 150 capture_thread_checker_.DetachFromThread();
152 render_thread_checker_.DetachFromThread(); 151 render_thread_checker_.DetachFromThread();
153 InitializeAudioProcessingModule(constraints, effects); 152 InitializeAudioProcessingModule(constraints, effects);
154 InitializeCaptureConverter(source_params);
155 } 153 }
156 154
157 MediaStreamAudioProcessor::~MediaStreamAudioProcessor() { 155 MediaStreamAudioProcessor::~MediaStreamAudioProcessor() {
158 DCHECK(main_thread_checker_.CalledOnValidThread()); 156 DCHECK(main_thread_checker_.CalledOnValidThread());
159 StopAudioProcessing(); 157 StopAudioProcessing();
160 } 158 }
161 159
160 void MediaStreamAudioProcessor::OnCaptureFormatChanged(
161 const media::AudioParameters& source_params) {
162 DCHECK(main_thread_checker_.CalledOnValidThread());
163 // There is no need to hold a lock here since the caller guarantees that
164 // there is no more PushCaptureData() and ProcessAndConsumeData() callbacks
165 // on the capture thread.
166 InitializeCaptureConverter(source_params);
Henrik Grunell 2014/03/07 09:14:57 Is InitializeCaptureConverter() OK to call multipl
no longer working on chromium 2014/03/07 10:14:54 Yes.
167
168 // Reset the |capture_thread_checker_| since the capture data will come from
169 // a new capture thread.
170 capture_thread_checker_.DetachFromThread();
171 }
172
162 void MediaStreamAudioProcessor::PushCaptureData(media::AudioBus* audio_source) { 173 void MediaStreamAudioProcessor::PushCaptureData(media::AudioBus* audio_source) {
163 DCHECK(capture_thread_checker_.CalledOnValidThread()); 174 DCHECK(capture_thread_checker_.CalledOnValidThread());
175 DCHECK_EQ(audio_source->channels(),
176 capture_converter_->source_parameters().channels());
177 DCHECK_EQ(audio_source->frames(),
178 capture_converter_->source_parameters().frames_per_buffer());
179
164 if (audio_mirroring_ && 180 if (audio_mirroring_ &&
165 capture_converter_->source_parameters().channel_layout() == 181 capture_converter_->source_parameters().channel_layout() ==
166 media::CHANNEL_LAYOUT_STEREO) { 182 media::CHANNEL_LAYOUT_STEREO) {
167 // Swap the first and second channels. 183 // Swap the first and second channels.
168 audio_source->SwapChannels(0, 1); 184 audio_source->SwapChannels(0, 1);
169 } 185 }
170 186
171 capture_converter_->Push(audio_source); 187 capture_converter_->Push(audio_source);
172 } 188 }
173 189
(...skipping 14 matching lines...) Expand all
188 } 204 }
189 205
190 const media::AudioParameters& MediaStreamAudioProcessor::InputFormat() const { 206 const media::AudioParameters& MediaStreamAudioProcessor::InputFormat() const {
191 return capture_converter_->source_parameters(); 207 return capture_converter_->source_parameters();
192 } 208 }
193 209
194 const media::AudioParameters& MediaStreamAudioProcessor::OutputFormat() const { 210 const media::AudioParameters& MediaStreamAudioProcessor::OutputFormat() const {
195 return capture_converter_->sink_parameters(); 211 return capture_converter_->sink_parameters();
196 } 212 }
197 213
214 void MediaStreamAudioProcessor::StartAecDump(
215 const base::PlatformFile& aec_dump_file) {
216 if (audio_processing_)
217 StartEchoCancellationDump(audio_processing_.get(), aec_dump_file);
218 }
219
220 void MediaStreamAudioProcessor::StopAecDump() {
221 if (audio_processing_)
222 StopEchoCancellationDump(audio_processing_.get());
223 }
224
198 void MediaStreamAudioProcessor::OnPlayoutData(media::AudioBus* audio_bus, 225 void MediaStreamAudioProcessor::OnPlayoutData(media::AudioBus* audio_bus,
199 int sample_rate, 226 int sample_rate,
200 int audio_delay_milliseconds) { 227 int audio_delay_milliseconds) {
201 DCHECK(render_thread_checker_.CalledOnValidThread()); 228 DCHECK(render_thread_checker_.CalledOnValidThread());
202 #if defined(OS_ANDROID) || defined(OS_IOS) 229 #if defined(OS_ANDROID) || defined(OS_IOS)
203 DCHECK(audio_processing_->echo_control_mobile()->is_enabled()); 230 DCHECK(audio_processing_->echo_control_mobile()->is_enabled());
204 #else 231 #else
205 DCHECK(audio_processing_->echo_cancellation()->is_enabled()); 232 DCHECK(audio_processing_->echo_cancellation()->is_enabled());
206 #endif 233 #endif
207 234
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 // has to be done after all the needed components are enabled. 346 // has to be done after all the needed components are enabled.
320 CHECK_EQ(audio_processing_->set_sample_rate_hz(kAudioProcessingSampleRate), 347 CHECK_EQ(audio_processing_->set_sample_rate_hz(kAudioProcessingSampleRate),
321 0); 348 0);
322 CHECK_EQ(audio_processing_->set_num_channels(kAudioProcessingNumberOfChannel, 349 CHECK_EQ(audio_processing_->set_num_channels(kAudioProcessingNumberOfChannel,
323 kAudioProcessingNumberOfChannel), 350 kAudioProcessingNumberOfChannel),
324 0); 351 0);
325 } 352 }
326 353
327 void MediaStreamAudioProcessor::InitializeCaptureConverter( 354 void MediaStreamAudioProcessor::InitializeCaptureConverter(
328 const media::AudioParameters& source_params) { 355 const media::AudioParameters& source_params) {
356 DCHECK(main_thread_checker_.CalledOnValidThread());
329 DCHECK(source_params.IsValid()); 357 DCHECK(source_params.IsValid());
330 358
331 // Create and initialize audio converter for the source data. 359 // Create and initialize audio converter for the source data.
332 // When the webrtc AudioProcessing is enabled, the sink format of the 360 // When the webrtc AudioProcessing is enabled, the sink format of the
333 // converter will be the same as the post-processed data format, which is 361 // converter will be the same as the post-processed data format, which is
334 // 32k mono for desktops and 16k mono for Android. When the AudioProcessing 362 // 32k mono for desktops and 16k mono for Android. When the AudioProcessing
335 // is disabled, the sink format will be the same as the source format. 363 // is disabled, the sink format will be the same as the source format.
336 const int sink_sample_rate = audio_processing_ ? 364 const int sink_sample_rate = audio_processing_ ?
337 kAudioProcessingSampleRate : source_params.sample_rate(); 365 kAudioProcessingSampleRate : source_params.sample_rate();
338 const media::ChannelLayout sink_channel_layout = audio_processing_ ? 366 const media::ChannelLayout sink_channel_layout = audio_processing_ ?
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 // Return 0 if the volume has not been changed, otherwise return the new 460 // Return 0 if the volume has not been changed, otherwise return the new
433 // volume. 461 // volume.
434 return (agc->stream_analog_level() == volume) ? 462 return (agc->stream_analog_level() == volume) ?
435 0 : agc->stream_analog_level(); 463 0 : agc->stream_analog_level();
436 } 464 }
437 465
438 void MediaStreamAudioProcessor::StopAudioProcessing() { 466 void MediaStreamAudioProcessor::StopAudioProcessing() {
439 if (!audio_processing_.get()) 467 if (!audio_processing_.get())
440 return; 468 return;
441 469
470 StopAecDump();
Henrik Grunell 2014/03/07 09:14:57 This shouldn't be necessary, it will be stopped wh
no longer working on chromium 2014/03/07 10:14:54 As discussed offline, lets keep this.
471
442 if (playout_data_source_) 472 if (playout_data_source_)
443 playout_data_source_->RemovePlayoutSink(this); 473 playout_data_source_->RemovePlayoutSink(this);
444 474
445 audio_processing_.reset(); 475 audio_processing_.reset();
446 } 476 }
447 477
448 } // namespace content 478 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698