OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/audio_processing/audio_processing_impl.h" | 11 #include "webrtc/modules/audio_processing/audio_processing_impl.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 | 14 |
| 15 #include "webrtc/base/checks.h" |
15 #include "webrtc/base/platform_file.h" | 16 #include "webrtc/base/platform_file.h" |
16 #include "webrtc/common_audio/include/audio_util.h" | 17 #include "webrtc/common_audio/include/audio_util.h" |
17 #include "webrtc/common_audio/channel_buffer.h" | 18 #include "webrtc/common_audio/channel_buffer.h" |
18 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" | 19 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" |
| 20 extern "C" { |
| 21 #include "webrtc/modules/audio_processing/aec/aec_core.h" |
| 22 } |
19 #include "webrtc/modules/audio_processing/agc/agc_manager_direct.h" | 23 #include "webrtc/modules/audio_processing/agc/agc_manager_direct.h" |
20 #include "webrtc/modules/audio_processing/audio_buffer.h" | 24 #include "webrtc/modules/audio_processing/audio_buffer.h" |
21 #include "webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h" | 25 #include "webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h" |
22 #include "webrtc/modules/audio_processing/common.h" | 26 #include "webrtc/modules/audio_processing/common.h" |
23 #include "webrtc/modules/audio_processing/echo_cancellation_impl.h" | 27 #include "webrtc/modules/audio_processing/echo_cancellation_impl.h" |
24 #include "webrtc/modules/audio_processing/echo_control_mobile_impl.h" | 28 #include "webrtc/modules/audio_processing/echo_control_mobile_impl.h" |
25 #include "webrtc/modules/audio_processing/gain_control_impl.h" | 29 #include "webrtc/modules/audio_processing/gain_control_impl.h" |
26 #include "webrtc/modules/audio_processing/high_pass_filter_impl.h" | 30 #include "webrtc/modules/audio_processing/high_pass_filter_impl.h" |
27 #include "webrtc/modules/audio_processing/level_estimator_impl.h" | 31 #include "webrtc/modules/audio_processing/level_estimator_impl.h" |
28 #include "webrtc/modules/audio_processing/noise_suppression_impl.h" | 32 #include "webrtc/modules/audio_processing/noise_suppression_impl.h" |
29 #include "webrtc/modules/audio_processing/processing_component.h" | 33 #include "webrtc/modules/audio_processing/processing_component.h" |
30 #include "webrtc/modules/audio_processing/transient/transient_suppressor.h" | 34 #include "webrtc/modules/audio_processing/transient/transient_suppressor.h" |
31 #include "webrtc/modules/audio_processing/voice_detection_impl.h" | 35 #include "webrtc/modules/audio_processing/voice_detection_impl.h" |
32 #include "webrtc/modules/interface/module_common_types.h" | 36 #include "webrtc/modules/interface/module_common_types.h" |
33 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" | 37 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
34 #include "webrtc/system_wrappers/interface/file_wrapper.h" | 38 #include "webrtc/system_wrappers/interface/file_wrapper.h" |
35 #include "webrtc/system_wrappers/interface/logging.h" | 39 #include "webrtc/system_wrappers/interface/logging.h" |
| 40 #include "webrtc/system_wrappers/interface/metrics.h" |
36 | 41 |
37 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 42 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
38 // Files generated at build-time by the protobuf compiler. | 43 // Files generated at build-time by the protobuf compiler. |
39 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | 44 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
40 #include "external/webrtc/webrtc/modules/audio_processing/debug.pb.h" | 45 #include "external/webrtc/webrtc/modules/audio_processing/debug.pb.h" |
41 #else | 46 #else |
42 #include "webrtc/audio_processing/debug.pb.h" | 47 #include "webrtc/audio_processing/debug.pb.h" |
43 #endif | 48 #endif |
44 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 49 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
45 | 50 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 #endif | 168 #endif |
164 fwd_in_format_(kSampleRate16kHz, 1), | 169 fwd_in_format_(kSampleRate16kHz, 1), |
165 fwd_proc_format_(kSampleRate16kHz), | 170 fwd_proc_format_(kSampleRate16kHz), |
166 fwd_out_format_(kSampleRate16kHz, 1), | 171 fwd_out_format_(kSampleRate16kHz, 1), |
167 rev_in_format_(kSampleRate16kHz, 1), | 172 rev_in_format_(kSampleRate16kHz, 1), |
168 rev_proc_format_(kSampleRate16kHz, 1), | 173 rev_proc_format_(kSampleRate16kHz, 1), |
169 split_rate_(kSampleRate16kHz), | 174 split_rate_(kSampleRate16kHz), |
170 stream_delay_ms_(0), | 175 stream_delay_ms_(0), |
171 delay_offset_ms_(0), | 176 delay_offset_ms_(0), |
172 was_stream_delay_set_(false), | 177 was_stream_delay_set_(false), |
| 178 last_stream_delay_ms_(0), |
| 179 last_aec_system_delay_ms_(0), |
173 output_will_be_muted_(false), | 180 output_will_be_muted_(false), |
174 key_pressed_(false), | 181 key_pressed_(false), |
175 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) | 182 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) |
176 use_new_agc_(false), | 183 use_new_agc_(false), |
177 #else | 184 #else |
178 use_new_agc_(config.Get<ExperimentalAgc>().enabled), | 185 use_new_agc_(config.Get<ExperimentalAgc>().enabled), |
179 #endif | 186 #endif |
180 agc_startup_min_volume_(config.Get<ExperimentalAgc>().startup_min_volume), | 187 agc_startup_min_volume_(config.Get<ExperimentalAgc>().startup_min_volume), |
181 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) | 188 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) |
182 transient_suppressor_enabled_(false), | 189 transient_suppressor_enabled_(false), |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 587 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
581 if (debug_file_->Open()) { | 588 if (debug_file_->Open()) { |
582 audioproc::Stream* msg = event_msg_->mutable_stream(); | 589 audioproc::Stream* msg = event_msg_->mutable_stream(); |
583 msg->set_delay(stream_delay_ms_); | 590 msg->set_delay(stream_delay_ms_); |
584 msg->set_drift(echo_cancellation_->stream_drift_samples()); | 591 msg->set_drift(echo_cancellation_->stream_drift_samples()); |
585 msg->set_level(gain_control()->stream_analog_level()); | 592 msg->set_level(gain_control()->stream_analog_level()); |
586 msg->set_keypress(key_pressed_); | 593 msg->set_keypress(key_pressed_); |
587 } | 594 } |
588 #endif | 595 #endif |
589 | 596 |
| 597 MaybeUpdateHistograms(); |
| 598 |
590 AudioBuffer* ca = capture_audio_.get(); // For brevity. | 599 AudioBuffer* ca = capture_audio_.get(); // For brevity. |
591 if (use_new_agc_ && gain_control_->is_enabled()) { | 600 if (use_new_agc_ && gain_control_->is_enabled()) { |
592 agc_manager_->AnalyzePreProcess(ca->channels()[0], | 601 agc_manager_->AnalyzePreProcess(ca->channels()[0], |
593 ca->num_channels(), | 602 ca->num_channels(), |
594 fwd_proc_format_.samples_per_channel()); | 603 fwd_proc_format_.samples_per_channel()); |
595 } | 604 } |
596 | 605 |
597 bool data_processed = is_data_processed(); | 606 bool data_processed = is_data_processed(); |
598 if (analysis_needed(data_processed)) { | 607 if (analysis_needed(data_processed)) { |
599 ca->SplitIntoFrequencyBands(); | 608 ca->SplitIntoFrequencyBands(); |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
983 | 992 |
984 void AudioProcessingImpl::InitializeBeamformer() { | 993 void AudioProcessingImpl::InitializeBeamformer() { |
985 if (beamformer_enabled_) { | 994 if (beamformer_enabled_) { |
986 if (!beamformer_) { | 995 if (!beamformer_) { |
987 beamformer_.reset(new NonlinearBeamformer(array_geometry_)); | 996 beamformer_.reset(new NonlinearBeamformer(array_geometry_)); |
988 } | 997 } |
989 beamformer_->Initialize(kChunkSizeMs, split_rate_); | 998 beamformer_->Initialize(kChunkSizeMs, split_rate_); |
990 } | 999 } |
991 } | 1000 } |
992 | 1001 |
| 1002 void AudioProcessingImpl::MaybeUpdateHistograms() { |
| 1003 static const int kMinDiffDelayMs = 50; |
| 1004 |
| 1005 if (echo_cancellation()->is_enabled()) { |
| 1006 // Detect a jump in platform reported system delay and log the difference. |
| 1007 const int diff_stream_delay_ms = stream_delay_ms_ - last_stream_delay_ms_; |
| 1008 if (diff_stream_delay_ms > kMinDiffDelayMs && last_stream_delay_ms_ != 0) { |
| 1009 RTC_HISTOGRAM_COUNTS("WebRTC.Audio.PlatformReportedStreamDelayJump", |
| 1010 diff_stream_delay_ms, kMinDiffDelayMs, 1000, 100); |
| 1011 } |
| 1012 last_stream_delay_ms_ = stream_delay_ms_; |
| 1013 |
| 1014 // Detect a jump in AEC system delay and log the difference. |
| 1015 const int frames_per_ms = rtc::CheckedDivExact(split_rate_, 1000); |
| 1016 const int aec_system_delay_ms = |
| 1017 WebRtcAec_system_delay(echo_cancellation()->aec_core()) / frames_per_ms; |
| 1018 const int diff_aec_system_delay_ms = aec_system_delay_ms - |
| 1019 last_aec_system_delay_ms_; |
| 1020 if (diff_aec_system_delay_ms > kMinDiffDelayMs && |
| 1021 last_aec_system_delay_ms_ != 0) { |
| 1022 RTC_HISTOGRAM_COUNTS("WebRTC.Audio.AecSystemDelayJump", |
| 1023 diff_aec_system_delay_ms, kMinDiffDelayMs, 1000, |
| 1024 100); |
| 1025 } |
| 1026 last_aec_system_delay_ms_ = aec_system_delay_ms; |
| 1027 } |
| 1028 } |
| 1029 |
993 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 1030 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
994 int AudioProcessingImpl::WriteMessageToDebugFile() { | 1031 int AudioProcessingImpl::WriteMessageToDebugFile() { |
995 int32_t size = event_msg_->ByteSize(); | 1032 int32_t size = event_msg_->ByteSize(); |
996 if (size <= 0) { | 1033 if (size <= 0) { |
997 return kUnspecifiedError; | 1034 return kUnspecifiedError; |
998 } | 1035 } |
999 #if defined(WEBRTC_ARCH_BIG_ENDIAN) | 1036 #if defined(WEBRTC_ARCH_BIG_ENDIAN) |
1000 // TODO(ajm): Use little-endian "on the wire". For the moment, we can be | 1037 // TODO(ajm): Use little-endian "on the wire". For the moment, we can be |
1001 // pretty safe in assuming little-endian. | 1038 // pretty safe in assuming little-endian. |
1002 #endif | 1039 #endif |
(...skipping 28 matching lines...) Expand all Loading... |
1031 int err = WriteMessageToDebugFile(); | 1068 int err = WriteMessageToDebugFile(); |
1032 if (err != kNoError) { | 1069 if (err != kNoError) { |
1033 return err; | 1070 return err; |
1034 } | 1071 } |
1035 | 1072 |
1036 return kNoError; | 1073 return kNoError; |
1037 } | 1074 } |
1038 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 1075 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
1039 | 1076 |
1040 } // namespace webrtc | 1077 } // namespace webrtc |
OLD | NEW |