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 // Extract all these methods to a helper class. |
| 22 void EnableEchoCancellation(AudioProcessing* audio_processing) { |
| 23 #if defined(IOS) || defined(ANDROID) |
| 24 // Mobile devices are using AECM. |
| 25 if (audio_processing->echo_control_mobile()->Enable(true)) |
| 26 NOTREACHED(); |
| 27 |
| 28 if (audio_processing->echo_control_mobile()->set_routing_mode( |
| 29 webrtc::EchoControlMobile::kSpeakerphone)) |
| 30 NOTREACHED(); |
| 31 #else |
| 32 if (audio_processing->echo_cancellation()->Enable(true)) |
| 33 NOTREACHED(); |
| 34 if (audio_processing->echo_cancellation()->set_suppression_level( |
| 35 webrtc::EchoCancellation::kHighSuppression)) |
| 36 NOTREACHED(); |
| 37 |
| 38 // Enable the metrics for AEC. |
| 39 if (audio_processing->echo_cancellation()->enable_metrics(true)) |
| 40 NOTREACHED(); |
| 41 if (audio_processing->echo_cancellation()->enable_delay_logging(true)) |
| 42 NOTREACHED(); |
| 43 #endif |
| 44 } |
| 45 |
| 46 void EnableNoiseSuppression(AudioProcessing* audio_processing) { |
| 47 if (audio_processing->noise_suppression()->set_level( |
| 48 webrtc::NoiseSuppression::kHigh)) |
| 49 NOTREACHED(); |
| 50 |
| 51 if (audio_processing->noise_suppression()->Enable(true)) |
| 52 NOTREACHED(); |
| 53 } |
| 54 |
| 55 void EnableHighPassFilter(AudioProcessing* audio_processing) { |
| 56 if (audio_processing->high_pass_filter()->Enable(true)) |
| 57 NOTREACHED(); |
| 58 } |
| 59 |
| 60 // TODO(xians): stereo swapping |
| 61 void EnableTypingDetection(AudioProcessing* audio_processing) { |
| 62 if (audio_processing->voice_detection()->Enable(true)) |
| 63 NOTREACHED(); |
| 64 |
| 65 if (audio_processing->voice_detection()->set_likelihood( |
| 66 webrtc::VoiceDetection::kVeryLowLikelihood)) |
| 67 NOTREACHED(); |
| 68 } |
| 69 |
| 70 void EnableExperimentalEchoCancellation(AudioProcessing* audio_processing) { |
| 71 webrtc::Config config; |
| 72 config.Set<webrtc::DelayCorrection>(new webrtc::DelayCorrection(true)); |
| 73 audio_processing->SetExtraOptions(config); |
| 74 } |
| 75 |
| 76 void StartAecDump(AudioProcessing* audio_processing) { |
| 77 // TODO(xians): Figure out a more suitable directory for the audio dump data. |
| 78 base::FilePath path; |
| 79 #if defined(CHROMEOS) |
| 80 PathService::Get(base::DIR_TEMP, &path); |
| 81 #elif defined(ANDROID) |
| 82 path = base::FilePath(FILE_PATH_LITERAL("sdcard")); |
| 83 #else |
| 84 PathService::Get(base::DIR_EXE, &path); |
| 85 #endif |
| 86 base::FilePath file = path.Append(FILE_PATH_LITERAL("audio.aecdump")); |
| 87 if (audio_processing->StartDebugRecording(file.value().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 |