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

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

Issue 833643005: Add a media constraint to enable beamforming. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Configure beamforming depending on device Created 5 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
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/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #if defined(OS_MACOSX) 8 #if defined(OS_MACOSX)
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #endif 10 #endif
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "content/renderer/media/media_stream_audio_processor_options.h" 12 #include "content/renderer/media/media_stream_audio_processor_options.h"
13 #include "content/renderer/media/rtc_media_constraints.h" 13 #include "content/renderer/media/rtc_media_constraints.h"
14 #include "content/renderer/media/webrtc_audio_device_impl.h" 14 #include "content/renderer/media/webrtc_audio_device_impl.h"
15 #include "media/audio/audio_parameters.h" 15 #include "media/audio/audio_parameters.h"
16 #include "media/base/audio_converter.h" 16 #include "media/base/audio_converter.h"
17 #include "media/base/audio_fifo.h" 17 #include "media/base/audio_fifo.h"
18 #include "media/base/channel_layout.h" 18 #include "media/base/channel_layout.h"
19 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" 19 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
20 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface .h" 20 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface .h"
21 #include "third_party/webrtc/modules/audio_processing/typing_detection.h" 21 #include "third_party/webrtc/modules/audio_processing/typing_detection.h"
22 22
23 #if defined(OS_CHROMEOS)
24 #include "base/sys_info.h"
25 #endif
26
23 namespace content { 27 namespace content {
24 28
25 namespace { 29 namespace {
26 30
27 using webrtc::AudioProcessing; 31 using webrtc::AudioProcessing;
28 32
29 #if defined(OS_ANDROID) 33 #if defined(OS_ANDROID)
30 const int kAudioProcessingSampleRate = 16000; 34 const int kAudioProcessingSampleRate = 16000;
31 #else 35 #else
32 const int kAudioProcessingSampleRate = 32000; 36 const int kAudioProcessingSampleRate = 32000;
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 const bool goog_experimental_aec = audio_constraints.GetProperty( 442 const bool goog_experimental_aec = audio_constraints.GetProperty(
439 MediaAudioConstraints::kGoogExperimentalEchoCancellation); 443 MediaAudioConstraints::kGoogExperimentalEchoCancellation);
440 const bool goog_typing_detection = audio_constraints.GetProperty( 444 const bool goog_typing_detection = audio_constraints.GetProperty(
441 MediaAudioConstraints::kGoogTypingNoiseDetection); 445 MediaAudioConstraints::kGoogTypingNoiseDetection);
442 #endif 446 #endif
443 447
444 const bool goog_ns = audio_constraints.GetProperty( 448 const bool goog_ns = audio_constraints.GetProperty(
445 MediaAudioConstraints::kGoogNoiseSuppression); 449 MediaAudioConstraints::kGoogNoiseSuppression);
446 const bool goog_experimental_ns = audio_constraints.GetProperty( 450 const bool goog_experimental_ns = audio_constraints.GetProperty(
447 MediaAudioConstraints::kGoogExperimentalNoiseSuppression); 451 MediaAudioConstraints::kGoogExperimentalNoiseSuppression);
452 const bool goog_beamforming = audio_constraints.GetProperty(
453 MediaAudioConstraints::kGoogBeamforming);
448 const bool goog_high_pass_filter = audio_constraints.GetProperty( 454 const bool goog_high_pass_filter = audio_constraints.GetProperty(
449 MediaAudioConstraints::kGoogHighpassFilter); 455 MediaAudioConstraints::kGoogHighpassFilter);
450 456
451 // Return immediately if no goog constraint is enabled. 457 // Return immediately if no goog constraint is enabled.
452 if (!echo_cancellation && !goog_experimental_aec && !goog_ns && 458 if (!echo_cancellation && !goog_experimental_aec && !goog_ns &&
453 !goog_high_pass_filter && !goog_typing_detection && 459 !goog_high_pass_filter && !goog_typing_detection &&
454 !goog_agc && !goog_experimental_ns) { 460 !goog_agc && !goog_experimental_ns && !goog_beamforming) {
455 RecordProcessingState(AUDIO_PROCESSING_DISABLED); 461 RecordProcessingState(AUDIO_PROCESSING_DISABLED);
456 return; 462 return;
457 } 463 }
458 464
459 // Experimental options provided at creation. 465 // Experimental options provided at creation.
460 webrtc::Config config; 466 webrtc::Config config;
461 if (goog_experimental_aec) 467 if (goog_experimental_aec)
462 config.Set<webrtc::DelayCorrection>(new webrtc::DelayCorrection(true)); 468 config.Set<webrtc::DelayCorrection>(new webrtc::DelayCorrection(true));
463 if (goog_experimental_ns) 469 if (goog_experimental_ns)
464 config.Set<webrtc::ExperimentalNs>(new webrtc::ExperimentalNs(true)); 470 config.Set<webrtc::ExperimentalNs>(new webrtc::ExperimentalNs(true));
465 #if defined(OS_MACOSX) 471 #if defined(OS_MACOSX)
466 if (base::FieldTrialList::FindFullName("NoReportedDelayOnMac") == "Enabled") 472 if (base::FieldTrialList::FindFullName("NoReportedDelayOnMac") == "Enabled")
467 config.Set<webrtc::ReportedDelay>(new webrtc::ReportedDelay(false)); 473 config.Set<webrtc::ReportedDelay>(new webrtc::ReportedDelay(false));
468 #endif 474 #endif
475 if (goog_beamforming) {
476 ConfigBeamforming(&config);
477 }
469 478
470 // Create and configure the webrtc::AudioProcessing. 479 // Create and configure the webrtc::AudioProcessing.
471 audio_processing_.reset(webrtc::AudioProcessing::Create(config)); 480 audio_processing_.reset(webrtc::AudioProcessing::Create(config));
472 481
473 // Enable the audio processing components. 482 // Enable the audio processing components.
474 if (echo_cancellation) { 483 if (echo_cancellation) {
475 EnableEchoCancellation(audio_processing_.get()); 484 EnableEchoCancellation(audio_processing_.get());
476 485
477 if (playout_data_source_) 486 if (playout_data_source_)
478 playout_data_source_->AddPlayoutSink(this); 487 playout_data_source_->AddPlayoutSink(this);
(...skipping 15 matching lines...) Expand all
494 typing_detector_.reset(new webrtc::TypingDetection()); 503 typing_detector_.reset(new webrtc::TypingDetection());
495 EnableTypingDetection(audio_processing_.get(), typing_detector_.get()); 504 EnableTypingDetection(audio_processing_.get(), typing_detector_.get());
496 } 505 }
497 506
498 if (goog_agc) 507 if (goog_agc)
499 EnableAutomaticGainControl(audio_processing_.get()); 508 EnableAutomaticGainControl(audio_processing_.get());
500 509
501 RecordProcessingState(AUDIO_PROCESSING_ENABLED); 510 RecordProcessingState(AUDIO_PROCESSING_ENABLED);
502 } 511 }
503 512
513 void MediaStreamAudioProcessor::ConfigBeamforming(webrtc::Config* config) {
514 bool enabled = false;
515 std::vector<webrtc::Point> geometry;
516 geometry.push_back(webrtc::Point(0.f, 0.f, 0.f));
517 #if defined(OS_CHROMEOS)
518 const std::string board = base::SysInfo::GetLsbReleaseBoard();
519 if (board == "peach_pi") {
520 enabled = true;
521 geometry.push_back(webrtc::Point(0.05f, 0.f, 0.f));
ajm 2015/01/08 00:03:17 nit: perhaps use 0.050f to indicate the measuremen
aluebs-chromium 2015/01/08 00:29:17 Done.
522 } else if (board == "swanky") {
523 // TODO(aluebs): Verify beamforming works on Swanky and enable.
524 enabled = false;
525 geometry.push_back(webrtc::Point(0.052f, 0.f, 0.f));
526 }
527 #endif
528 config->Set<webrtc::Beamforming>(new webrtc::Beamforming(enabled, geometry));
529 }
530
504 void MediaStreamAudioProcessor::InitializeCaptureFifo( 531 void MediaStreamAudioProcessor::InitializeCaptureFifo(
505 const media::AudioParameters& input_format) { 532 const media::AudioParameters& input_format) {
506 DCHECK(main_thread_checker_.CalledOnValidThread()); 533 DCHECK(main_thread_checker_.CalledOnValidThread());
507 DCHECK(input_format.IsValid()); 534 DCHECK(input_format.IsValid());
508 input_format_ = input_format; 535 input_format_ = input_format;
509 536
510 // TODO(ajm): For now, we assume fixed parameters for the output when audio 537 // TODO(ajm): For now, we assume fixed parameters for the output when audio
511 // processing is enabled, to match the previous behavior. We should either 538 // processing is enabled, to match the previous behavior. We should either
512 // use the input parameters (in which case, audio processing will convert 539 // use the input parameters (in which case, audio processing will convert
513 // at output) or ideally, have a backchannel from the sink to know what 540 // at output) or ideally, have a backchannel from the sink to know what
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 vad->stream_has_voice()); 671 vad->stream_has_voice());
645 base::subtle::Release_Store(&typing_detected_, detected); 672 base::subtle::Release_Store(&typing_detected_, detected);
646 } 673 }
647 674
648 // Return 0 if the volume hasn't been changed, and otherwise the new volume. 675 // Return 0 if the volume hasn't been changed, and otherwise the new volume.
649 return (agc->stream_analog_level() == volume) ? 676 return (agc->stream_analog_level() == volume) ?
650 0 : agc->stream_analog_level(); 677 0 : agc->stream_analog_level();
651 } 678 }
652 679
653 } // namespace content 680 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698