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/webrtc_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 "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface
.h" |
| 11 #include "third_party/webrtc/modules/audio_processing/include/audio_processing.h
" |
| 12 |
| 13 namespace content { |
| 14 |
| 15 bool GetPropertyFromConstraints(const MediaConstraintsInterface* constraints, |
| 16 const std::string& key) { |
| 17 bool value = false; |
| 18 return webrtc::FindConstraint(constraints, key, &value, NULL) && value; |
| 19 } |
| 20 |
| 21 void EnableEchoCancellation(AudioProcessing* audio_processing) { |
| 22 #if defined(OS_IOS) |
| 23 // On iOS, VPIO provides built-in EC and AGC. |
| 24 return; |
| 25 #elif defined(OS_ANDROID) |
| 26 // Mobile devices are using AECM. |
| 27 if (audio_processing->echo_control_mobile()->Enable(true)) |
| 28 NOTREACHED(); |
| 29 |
| 30 if (audio_processing->echo_control_mobile()->set_routing_mode( |
| 31 webrtc::EchoControlMobile::kSpeakerphone)) |
| 32 NOTREACHED(); |
| 33 #else |
| 34 if (audio_processing->echo_cancellation()->Enable(true)) |
| 35 NOTREACHED(); |
| 36 if (audio_processing->echo_cancellation()->set_suppression_level( |
| 37 webrtc::EchoCancellation::kHighSuppression)) |
| 38 NOTREACHED(); |
| 39 |
| 40 // Enable the metrics for AEC. |
| 41 if (audio_processing->echo_cancellation()->enable_metrics(true)) |
| 42 NOTREACHED(); |
| 43 if (audio_processing->echo_cancellation()->enable_delay_logging(true)) |
| 44 NOTREACHED(); |
| 45 #endif |
| 46 } |
| 47 |
| 48 void EnableNoiseSuppression(AudioProcessing* audio_processing) { |
| 49 if (audio_processing->noise_suppression()->set_level( |
| 50 webrtc::NoiseSuppression::kHigh)) |
| 51 NOTREACHED(); |
| 52 |
| 53 if (audio_processing->noise_suppression()->Enable(true)) |
| 54 NOTREACHED(); |
| 55 } |
| 56 |
| 57 void EnableHighPassFilter(AudioProcessing* audio_processing) { |
| 58 if (audio_processing->high_pass_filter()->Enable(true)) |
| 59 NOTREACHED(); |
| 60 } |
| 61 |
| 62 // TODO(xians): stereo swapping |
| 63 void EnableTypingDetection(AudioProcessing* audio_processing) { |
| 64 if (audio_processing->voice_detection()->Enable(true)) |
| 65 NOTREACHED(); |
| 66 |
| 67 if (audio_processing->voice_detection()->set_likelihood( |
| 68 webrtc::VoiceDetection::kVeryLowLikelihood)) |
| 69 NOTREACHED(); |
| 70 } |
| 71 |
| 72 void EnableExperimentalEchoCancellation(AudioProcessing* audio_processing) { |
| 73 webrtc::Config config; |
| 74 config.Set<webrtc::DelayCorrection>(new webrtc::DelayCorrection(true)); |
| 75 audio_processing->SetExtraOptions(config); |
| 76 } |
| 77 |
| 78 void StartAecDump(AudioProcessing* audio_processing) { |
| 79 // TODO(xians): Figure out a more suitable directory for the audio dump data. |
| 80 base::FilePath path; |
| 81 #if defined(CHROMEOS) |
| 82 PathService::Get(base::DIR_TEMP, &path); |
| 83 #elif defined(ANDROID) |
| 84 path = base::FilePath(FILE_PATH_LITERAL("sdcard")); |
| 85 #else |
| 86 PathService::Get(base::DIR_EXE, &path); |
| 87 #endif |
| 88 base::FilePath file = path.Append(FILE_PATH_LITERAL("audio.aecdump")); |
| 89 if (audio_processing->StartDebugRecording(file.value().c_str())) |
| 90 DLOG(ERROR) << "Fail to start AEC debug recording"; |
| 91 } |
| 92 |
| 93 void StopAecDump(AudioProcessing* audio_processing) { |
| 94 if (audio_processing->StopDebugRecording()) |
| 95 DLOG(ERROR) << "Fail to stop AEC debug recording"; |
| 96 } |
| 97 |
| 98 } // namespace content |
OLD | NEW |