OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "content/renderer/media/media_stream_audio_processor_options.h" |
| 6 |
| 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
" |
| 13 |
| 14 namespace content { |
| 15 |
| 16 bool GetPropertyFromConstraints(const MediaConstraintsInterface* constraints, |
| 17 const std::string& key) { |
| 18 bool value = false; |
| 19 return webrtc::FindConstraint(constraints, key, &value, NULL) && value; |
| 20 } |
| 21 |
| 22 void EnableEchoCancellation(AudioProcessing* audio_processing) { |
| 23 #if defined(OS_IOS) |
| 24 // On iOS, VPIO provides built-in EC and AGC. |
| 25 return; |
| 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); |
| 31 CHECK_EQ(err, 0); |
| 32 #else |
| 33 int err = audio_processing->echo_cancellation()->Enable(true); |
| 34 err |= audio_processing->echo_cancellation()->set_suppression_level( |
| 35 webrtc::EchoCancellation::kHighSuppression); |
| 36 |
| 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); |
| 40 CHECK_EQ(err, 0); |
| 41 #endif |
| 42 } |
| 43 |
| 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); |
| 48 CHECK_EQ(err, 0); |
| 49 } |
| 50 |
| 51 void EnableHighPassFilter(AudioProcessing* audio_processing) { |
| 52 CHECK_EQ(audio_processing->high_pass_filter()->Enable(true), 0); |
| 53 } |
| 54 |
| 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); |
| 60 CHECK_EQ(err, 0); |
| 61 } |
| 62 |
| 63 void EnableExperimentalEchoCancellation(AudioProcessing* audio_processing) { |
| 64 webrtc::Config config; |
| 65 config.Set<webrtc::DelayCorrection>(new webrtc::DelayCorrection(true)); |
| 66 audio_processing->SetExtraOptions(config); |
| 67 } |
| 68 |
| 69 void StartAecDump(AudioProcessing* audio_processing) { |
| 70 // TODO(grunell): Figure out a more suitable directory for the audio dump |
| 71 // data. |
| 72 base::FilePath path; |
| 73 #if defined(CHROMEOS) |
| 74 PathService::Get(base::DIR_TEMP, &path); |
| 75 #elif defined(ANDROID) |
| 76 path = base::FilePath(FILE_PATH_LITERAL("sdcard")); |
| 77 #else |
| 78 PathService::Get(base::DIR_EXE, &path); |
| 79 #endif |
| 80 base::FilePath file = path.Append(FILE_PATH_LITERAL("audio.aecdump")); |
| 81 |
| 82 #if defined(OS_WIN) |
| 83 const std::string file_name = WideToUTF8(file.value()); |
| 84 #else |
| 85 const std::string file_name = file.value(); |
| 86 #endif |
| 87 if (audio_processing->StartDebugRecording(file_name.c_str())) |
| 88 DLOG(ERROR) << "Fail to start AEC debug recording"; |
| 89 } |
| 90 |
| 91 void StopAecDump(AudioProcessing* audio_processing) { |
| 92 if (audio_processing->StopDebugRecording()) |
| 93 DLOG(ERROR) << "Fail to stop AEC debug recording"; |
| 94 } |
| 95 |
| 96 } // namespace content |
OLD | NEW |