2017-02-28 22:08:53 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_processing/aec3/render_delay_controller_metrics.h"
|
2017-02-28 22:08:53 -08:00
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_processing/aec3/aec3_common.h"
|
2018-10-23 12:03:01 +02:00
|
|
|
#include "rtc_base/checks.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "system_wrappers/include/metrics.h"
|
2017-02-28 22:08:53 -08:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
enum class DelayReliabilityCategory {
|
|
|
|
|
kNone,
|
|
|
|
|
kPoor,
|
|
|
|
|
kMedium,
|
|
|
|
|
kGood,
|
|
|
|
|
kExcellent,
|
|
|
|
|
kNumCategories
|
|
|
|
|
};
|
|
|
|
|
enum class DelayChangesCategory {
|
|
|
|
|
kNone,
|
|
|
|
|
kFew,
|
|
|
|
|
kSeveral,
|
|
|
|
|
kMany,
|
|
|
|
|
kConstant,
|
|
|
|
|
kNumCategories
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2018-02-22 17:51:39 +01:00
|
|
|
RenderDelayControllerMetrics::RenderDelayControllerMetrics() = default;
|
|
|
|
|
|
|
|
|
|
void RenderDelayControllerMetrics::Update(
|
2018-06-19 10:50:11 +02:00
|
|
|
absl::optional<size_t> delay_samples,
|
2022-10-12 17:14:31 +02:00
|
|
|
absl::optional<size_t> buffer_delay_blocks,
|
AEC3: Clockdrift detection
This change introduces a clockdrift detector operating on the estimated
delay of the echo path delay estimator. Each time the delay estimate
changes it is compared to previous estimates. If the estimates are
slowly increasing or decreasing, clockdrift is detected.
Four different patterns are considered clockdrift:
- k, k+1, k+2, k+3
- k, k+2, k+1, k+3
- k, k-1, k-2, k-3
- k, k-2, k-1, k-3
A delay estimate history matching the three last elements in one of the
patterns is considered probable clockdrift. Matching all four elements
is considered verified clockdrift.
If the delay is constant for some time after clockdrift is detected the
clockdrift detector will revert to no detected clockdrift.
The level of clockdrift is reported via an UMA histogram.
Bug: webrtc:10014
Change-Id: I1cce4d593e101a8b3fa99df6935e59b4243cb97a
Reviewed-on: https://webrtc-review.googlesource.com/c/111381
Commit-Queue: Gustaf Ullberg <gustaf@webrtc.org>
Reviewed-by: Per Åhgren <peah@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25758}
2018-11-22 16:02:34 +01:00
|
|
|
ClockdriftDetector::Level clockdrift) {
|
2017-02-28 22:08:53 -08:00
|
|
|
++call_counter_;
|
|
|
|
|
|
|
|
|
|
if (!initial_update) {
|
2018-06-13 16:13:46 +02:00
|
|
|
size_t delay_blocks;
|
2017-02-28 22:08:53 -08:00
|
|
|
if (delay_samples) {
|
|
|
|
|
++reliable_delay_estimate_counter_;
|
2022-10-12 17:14:31 +02:00
|
|
|
// Add an offset by 1 (metric is halved before reporting) to reserve 0 for
|
|
|
|
|
// absent delay.
|
2018-06-13 16:13:46 +02:00
|
|
|
delay_blocks = (*delay_samples) / kBlockSize + 2;
|
|
|
|
|
} else {
|
|
|
|
|
delay_blocks = 0;
|
|
|
|
|
}
|
2017-02-28 22:08:53 -08:00
|
|
|
|
2018-06-13 16:13:46 +02:00
|
|
|
if (delay_blocks != delay_blocks_) {
|
|
|
|
|
++delay_change_counter_;
|
|
|
|
|
delay_blocks_ = delay_blocks;
|
2017-02-28 22:08:53 -08:00
|
|
|
}
|
2018-02-22 17:51:39 +01:00
|
|
|
|
2017-04-06 15:45:32 -07:00
|
|
|
} else if (++initial_call_counter_ == 5 * kNumBlocksPerSecond) {
|
2017-02-28 22:08:53 -08:00
|
|
|
initial_update = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (call_counter_ == kMetricsReportingIntervalBlocks) {
|
|
|
|
|
int value_to_report = static_cast<int>(delay_blocks_);
|
2022-10-12 17:14:31 +02:00
|
|
|
// Divide by 2 to compress metric range.
|
2018-06-13 16:13:46 +02:00
|
|
|
value_to_report = std::min(124, value_to_report >> 1);
|
2017-02-28 22:08:53 -08:00
|
|
|
RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.EchoCanceller.EchoPathDelay",
|
|
|
|
|
value_to_report, 0, 124, 125);
|
|
|
|
|
|
2022-10-12 17:14:31 +02:00
|
|
|
// Divide by 2 to compress metric range.
|
|
|
|
|
// Offset by 1 to reserve 0 for absent delay.
|
|
|
|
|
value_to_report = buffer_delay_blocks ? (*buffer_delay_blocks + 2) >> 1 : 0;
|
|
|
|
|
value_to_report = std::min(124, value_to_report);
|
2017-02-28 22:08:53 -08:00
|
|
|
RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.EchoCanceller.BufferDelay",
|
|
|
|
|
value_to_report, 0, 124, 125);
|
|
|
|
|
|
|
|
|
|
DelayReliabilityCategory delay_reliability;
|
|
|
|
|
if (reliable_delay_estimate_counter_ == 0) {
|
|
|
|
|
delay_reliability = DelayReliabilityCategory::kNone;
|
|
|
|
|
} else if (reliable_delay_estimate_counter_ > (call_counter_ >> 1)) {
|
|
|
|
|
delay_reliability = DelayReliabilityCategory::kExcellent;
|
|
|
|
|
} else if (reliable_delay_estimate_counter_ > 100) {
|
|
|
|
|
delay_reliability = DelayReliabilityCategory::kGood;
|
|
|
|
|
} else if (reliable_delay_estimate_counter_ > 10) {
|
|
|
|
|
delay_reliability = DelayReliabilityCategory::kMedium;
|
|
|
|
|
} else {
|
|
|
|
|
delay_reliability = DelayReliabilityCategory::kPoor;
|
|
|
|
|
}
|
|
|
|
|
RTC_HISTOGRAM_ENUMERATION(
|
|
|
|
|
"WebRTC.Audio.EchoCanceller.ReliableDelayEstimates",
|
|
|
|
|
static_cast<int>(delay_reliability),
|
|
|
|
|
static_cast<int>(DelayReliabilityCategory::kNumCategories));
|
|
|
|
|
|
|
|
|
|
DelayChangesCategory delay_changes;
|
|
|
|
|
if (delay_change_counter_ == 0) {
|
|
|
|
|
delay_changes = DelayChangesCategory::kNone;
|
|
|
|
|
} else if (delay_change_counter_ > 10) {
|
|
|
|
|
delay_changes = DelayChangesCategory::kConstant;
|
|
|
|
|
} else if (delay_change_counter_ > 5) {
|
|
|
|
|
delay_changes = DelayChangesCategory::kMany;
|
|
|
|
|
} else if (delay_change_counter_ > 2) {
|
|
|
|
|
delay_changes = DelayChangesCategory::kSeveral;
|
|
|
|
|
} else {
|
|
|
|
|
delay_changes = DelayChangesCategory::kFew;
|
|
|
|
|
}
|
|
|
|
|
RTC_HISTOGRAM_ENUMERATION(
|
|
|
|
|
"WebRTC.Audio.EchoCanceller.DelayChanges",
|
|
|
|
|
static_cast<int>(delay_changes),
|
|
|
|
|
static_cast<int>(DelayChangesCategory::kNumCategories));
|
|
|
|
|
|
AEC3: Clockdrift detection
This change introduces a clockdrift detector operating on the estimated
delay of the echo path delay estimator. Each time the delay estimate
changes it is compared to previous estimates. If the estimates are
slowly increasing or decreasing, clockdrift is detected.
Four different patterns are considered clockdrift:
- k, k+1, k+2, k+3
- k, k+2, k+1, k+3
- k, k-1, k-2, k-3
- k, k-2, k-1, k-3
A delay estimate history matching the three last elements in one of the
patterns is considered probable clockdrift. Matching all four elements
is considered verified clockdrift.
If the delay is constant for some time after clockdrift is detected the
clockdrift detector will revert to no detected clockdrift.
The level of clockdrift is reported via an UMA histogram.
Bug: webrtc:10014
Change-Id: I1cce4d593e101a8b3fa99df6935e59b4243cb97a
Reviewed-on: https://webrtc-review.googlesource.com/c/111381
Commit-Queue: Gustaf Ullberg <gustaf@webrtc.org>
Reviewed-by: Per Åhgren <peah@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25758}
2018-11-22 16:02:34 +01:00
|
|
|
RTC_HISTOGRAM_ENUMERATION(
|
|
|
|
|
"WebRTC.Audio.EchoCanceller.Clockdrift", static_cast<int>(clockdrift),
|
|
|
|
|
static_cast<int>(ClockdriftDetector::Level::kNumCategories));
|
|
|
|
|
|
2017-02-28 22:08:53 -08:00
|
|
|
call_counter_ = 0;
|
|
|
|
|
ResetMetrics();
|
2018-02-22 17:51:39 +01:00
|
|
|
}
|
2017-02-28 22:08:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RenderDelayControllerMetrics::ResetMetrics() {
|
|
|
|
|
delay_change_counter_ = 0;
|
|
|
|
|
reliable_delay_estimate_counter_ = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|