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
3 // found in the LICENSE file.
5 #include "content/renderer/media/media_stream_audio_processor_options.h"
7 #include "base/files/file_path.h"
8 #include "base/logging.h"
9 #include "base/path_service.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface.h"
12 #include "third_party/webrtc/modules/audio_processing/include/audio_processing.h"
16 bool GetPropertyFromConstraints(const MediaConstraintsInterface
* constraints
,
17 const std::string
& key
) {
19 return webrtc::FindConstraint(constraints
, key
, &value
, NULL
) && value
;
22 void EnableEchoCancellation(AudioProcessing
* audio_processing
) {
24 // On iOS, VPIO provides built-in EC and AGC.
26 #elif defined(OS_ANDROID)
27 // Mobile devices are using AECM.
28 int err
= audio_processing
->echo_control_mobile()->Enable(true);
29 err
|= audio_processing
->echo_control_mobile()->set_routing_mode(
30 webrtc::EchoControlMobile::kSpeakerphone
);
33 int err
= audio_processing
->echo_cancellation()->Enable(true);
34 err
|= audio_processing
->echo_cancellation()->set_suppression_level(
35 webrtc::EchoCancellation::kHighSuppression
);
37 // Enable the metrics for AEC.
38 err
|= audio_processing
->echo_cancellation()->enable_metrics(true);
39 err
|= audio_processing
->echo_cancellation()->enable_delay_logging(true);
44 void EnableNoiseSuppression(AudioProcessing
* audio_processing
) {
45 int err
= audio_processing
->noise_suppression()->set_level(
46 webrtc::NoiseSuppression::kHigh
);
47 err
|= audio_processing
->noise_suppression()->Enable(true);
51 void EnableHighPassFilter(AudioProcessing
* audio_processing
) {
52 CHECK_EQ(audio_processing
->high_pass_filter()->Enable(true), 0);
55 // TODO(xians): stereo swapping
56 void EnableTypingDetection(AudioProcessing
* audio_processing
) {
57 int err
= audio_processing
->voice_detection()->Enable(true);
58 err
|= audio_processing
->voice_detection()->set_likelihood(
59 webrtc::VoiceDetection::kVeryLowLikelihood
);
63 void EnableExperimentalEchoCancellation(AudioProcessing
* audio_processing
) {
64 webrtc::Config config
;
65 config
.Set
<webrtc::DelayCorrection
>(new webrtc::DelayCorrection(true));
66 audio_processing
->SetExtraOptions(config
);
69 void StartAecDump(AudioProcessing
* audio_processing
) {
70 // TODO(grunell): Figure out a more suitable directory for the audio dump
74 PathService::Get(base::DIR_TEMP
, &path
);
75 #elif defined(ANDROID)
76 path
= base::FilePath(FILE_PATH_LITERAL("sdcard"));
78 PathService::Get(base::DIR_EXE
, &path
);
80 base::FilePath file
= path
.Append(FILE_PATH_LITERAL("audio.aecdump"));
83 const std::string file_name
= base::WideToUTF8(file
.value());
85 const std::string file_name
= file
.value();
87 if (audio_processing
->StartDebugRecording(file_name
.c_str()))
88 DLOG(ERROR
) << "Fail to start AEC debug recording";
91 void StopAecDump(AudioProcessing
* audio_processing
) {
92 if (audio_processing
->StopDebugRecording())
93 DLOG(ERROR
) << "Fail to stop AEC debug recording";
96 } // namespace content