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

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

Issue 169803003: Adding typing detection to the APM in chrome. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: addressed the comments. Created 6 years, 10 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
« no previous file with comments | « content/renderer/media/media_stream_audio_processor.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 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"
11 #include "content/renderer/media/rtc_media_constraints.h" 11 #include "content/renderer/media/rtc_media_constraints.h"
12 #include "media/audio/audio_parameters.h" 12 #include "media/audio/audio_parameters.h"
13 #include "media/base/audio_converter.h" 13 #include "media/base/audio_converter.h"
14 #include "media/base/audio_fifo.h" 14 #include "media/base/audio_fifo.h"
15 #include "media/base/channel_layout.h" 15 #include "media/base/channel_layout.h"
16 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" 16 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
17 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface .h" 17 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface .h"
18 #include "third_party/webrtc/modules/audio_processing/typing_detection.h"
18 19
19 namespace content { 20 namespace content {
20 21
21 namespace { 22 namespace {
22 23
23 using webrtc::AudioProcessing; 24 using webrtc::AudioProcessing;
24 using webrtc::MediaConstraintsInterface; 25 using webrtc::MediaConstraintsInterface;
25 26
26 #if defined(OS_ANDROID) 27 #if defined(OS_ANDROID)
27 const int kAudioProcessingSampleRate = 16000; 28 const int kAudioProcessingSampleRate = 16000;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 media::AudioConverter audio_converter_; 137 media::AudioConverter audio_converter_;
137 scoped_ptr<media::AudioBus> audio_wrapper_; 138 scoped_ptr<media::AudioBus> audio_wrapper_;
138 scoped_ptr<media::AudioFifo> fifo_; 139 scoped_ptr<media::AudioFifo> fifo_;
139 }; 140 };
140 141
141 MediaStreamAudioProcessor::MediaStreamAudioProcessor( 142 MediaStreamAudioProcessor::MediaStreamAudioProcessor(
142 const media::AudioParameters& source_params, 143 const media::AudioParameters& source_params,
143 const blink::WebMediaConstraints& constraints, 144 const blink::WebMediaConstraints& constraints,
144 int effects) 145 int effects)
145 : render_delay_ms_(0), 146 : render_delay_ms_(0),
146 audio_mirroring_(false) { 147 audio_mirroring_(false),
148 typing_detected_(false) {
147 capture_thread_checker_.DetachFromThread(); 149 capture_thread_checker_.DetachFromThread();
148 render_thread_checker_.DetachFromThread(); 150 render_thread_checker_.DetachFromThread();
149 InitializeAudioProcessingModule(constraints, effects); 151 InitializeAudioProcessingModule(constraints, effects);
150 InitializeCaptureConverter(source_params); 152 InitializeCaptureConverter(source_params);
151 } 153 }
152 154
153 MediaStreamAudioProcessor::~MediaStreamAudioProcessor() { 155 MediaStreamAudioProcessor::~MediaStreamAudioProcessor() {
154 DCHECK(main_thread_checker_.CalledOnValidThread()); 156 DCHECK(main_thread_checker_.CalledOnValidThread());
155 StopAudioProcessing(); 157 StopAudioProcessing();
156 } 158 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 const bool enable_ns = GetPropertyFromConstraints( 259 const bool enable_ns = GetPropertyFromConstraints(
258 &native_constraints, MediaConstraintsInterface::kNoiseSuppression); 260 &native_constraints, MediaConstraintsInterface::kNoiseSuppression);
259 const bool enable_high_pass_filter = GetPropertyFromConstraints( 261 const bool enable_high_pass_filter = GetPropertyFromConstraints(
260 &native_constraints, MediaConstraintsInterface::kHighpassFilter); 262 &native_constraints, MediaConstraintsInterface::kHighpassFilter);
261 263
262 audio_mirroring_ = GetPropertyFromConstraints( 264 audio_mirroring_ = GetPropertyFromConstraints(
263 &native_constraints, webrtc::MediaConstraintsInterface::kAudioMirroring); 265 &native_constraints, webrtc::MediaConstraintsInterface::kAudioMirroring);
264 266
265 // Return immediately if no audio processing component is enabled. 267 // Return immediately if no audio processing component is enabled.
266 if (!enable_aec && !enable_experimental_aec && !enable_ns && 268 if (!enable_aec && !enable_experimental_aec && !enable_ns &&
267 !enable_high_pass_filter && !enable_typing_detection && !enable_agc) { 269 !enable_high_pass_filter && !enable_typing_detection && !enable_agc &&
270 !audio_mirroring_) {
268 return; 271 return;
269 } 272 }
270 273
271 // Create and configure the webrtc::AudioProcessing. 274 // Create and configure the webrtc::AudioProcessing.
272 audio_processing_.reset(webrtc::AudioProcessing::Create(0)); 275 audio_processing_.reset(webrtc::AudioProcessing::Create(0));
273 276
274 // Enable the audio processing components. 277 // Enable the audio processing components.
275 if (enable_aec) { 278 if (enable_aec) {
276 EnableEchoCancellation(audio_processing_.get()); 279 EnableEchoCancellation(audio_processing_.get());
277 if (enable_experimental_aec) 280 if (enable_experimental_aec)
278 EnableExperimentalEchoCancellation(audio_processing_.get()); 281 EnableExperimentalEchoCancellation(audio_processing_.get());
279 } 282 }
280 283
281 if (enable_ns) 284 if (enable_ns)
282 EnableNoiseSuppression(audio_processing_.get()); 285 EnableNoiseSuppression(audio_processing_.get());
283 286
284 if (enable_high_pass_filter) 287 if (enable_high_pass_filter)
285 EnableHighPassFilter(audio_processing_.get()); 288 EnableHighPassFilter(audio_processing_.get());
286 289
287 if (enable_typing_detection) 290 if (enable_typing_detection) {
288 EnableTypingDetection(audio_processing_.get()); 291 EnableTypingDetection(audio_processing_.get());
Henrik Grunell 2014/02/19 06:54:42 The semantics/naming is a bit unclear. EnableTypin
no longer working on chromium 2014/02/20 12:44:13 The naming of EnableTypingDetection is correspondi
292 // TODO(xians): Remove this |typing_detector_| after the typing suppression
293 // is enabled by default.
294 typing_detector_.reset(new webrtc::TypingDetection());
295
296 // Configure the update period to 100ms (10 * 10ms) in the typing detector.
Henrik Grunell 2014/02/19 06:54:42 Nit: space between number and "ms".
no longer working on chromium 2014/02/20 12:44:13 Discussed offline, in Chrome, it is very common to
297 typing_detector_->SetParameters(0, 0, 0, 0, 0, 10);
298 }
289 299
290 if (enable_agc) 300 if (enable_agc)
291 EnableAutomaticGainControl(audio_processing_.get()); 301 EnableAutomaticGainControl(audio_processing_.get());
292 302
293 // Configure the audio format the audio processing is running on. This 303 // Configure the audio format the audio processing is running on. This
294 // has to be done after all the needed components are enabled. 304 // has to be done after all the needed components are enabled.
295 CHECK_EQ(audio_processing_->set_sample_rate_hz(kAudioProcessingSampleRate), 305 CHECK_EQ(audio_processing_->set_sample_rate_hz(kAudioProcessingSampleRate),
296 0); 306 0);
297 CHECK_EQ(audio_processing_->set_num_channels(kAudioProcessingNumberOfChannel, 307 CHECK_EQ(audio_processing_->set_num_channels(kAudioProcessingNumberOfChannel,
298 kAudioProcessingNumberOfChannel), 308 kAudioProcessingNumberOfChannel),
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 DCHECK_EQ(err, 0) << "set_stream_analog_level() error: " << err; 401 DCHECK_EQ(err, 0) << "set_stream_analog_level() error: " << err;
392 err = audio_processing_->ProcessStream(audio_frame); 402 err = audio_processing_->ProcessStream(audio_frame);
393 DCHECK_EQ(err, 0) << "ProcessStream() error: " << err; 403 DCHECK_EQ(err, 0) << "ProcessStream() error: " << err;
394 404
395 // TODO(xians): Add support for typing detection, audio level calculation. 405 // TODO(xians): Add support for typing detection, audio level calculation.
396 406
397 if (audio_mirroring_ && audio_frame->num_channels_ == 2) { 407 if (audio_mirroring_ && audio_frame->num_channels_ == 2) {
398 // TODO(xians): Swap the stereo channels after switching to media::AudioBus. 408 // TODO(xians): Swap the stereo channels after switching to media::AudioBus.
399 } 409 }
400 410
411 if (typing_detector_ &&
412 audio_frame->vad_activity_ != webrtc::AudioFrame::kVadUnknown) {
413 bool vad_active =
414 (audio_frame->vad_activity_ == webrtc::AudioFrame::kVadActive);
415 // TODO(xians): Pass this |typing_detected_| to peer connection.
416 typing_detected_ = typing_detector_->Process(key_pressed, vad_active);
417 }
418
401 // Return 0 if the volume has not been changed, otherwise return the new 419 // Return 0 if the volume has not been changed, otherwise return the new
402 // volume. 420 // volume.
403 return (agc->stream_analog_level() == volume) ? 421 return (agc->stream_analog_level() == volume) ?
404 0 : agc->stream_analog_level(); 422 0 : agc->stream_analog_level();
405 } 423 }
406 424
407 void MediaStreamAudioProcessor::StopAudioProcessing() { 425 void MediaStreamAudioProcessor::StopAudioProcessing() {
408 if (!audio_processing_.get()) 426 if (!audio_processing_.get())
409 return; 427 return;
410 428
411 audio_processing_.reset(); 429 audio_processing_.reset();
412 } 430 }
413 431
414 } // namespace content 432 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_audio_processor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698