1 /*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "modules/audio_processing/aec3/block_processor_metrics.h"
12
13 #include "modules/audio_processing/aec3/aec3_common.h"
14 #include "rtc_base/checks.h"
15 #include "system_wrappers/include/metrics.h"
16
17 namespace webrtc {
18
19 namespace {
20
21 enum class RenderUnderrunCategory {
22 kNone,
23 kFew,
24 kSeveral,
25 kMany,
26 kConstant,
27 kNumCategories
28 };
29
30 enum class RenderOverrunCategory {
31 kNone,
32 kFew,
33 kSeveral,
34 kMany,
35 kConstant,
36 kNumCategories
37 };
38
39 } // namespace
40
UpdateCapture(bool underrun)41 void BlockProcessorMetrics::UpdateCapture(bool underrun) {
42 ++capture_block_counter_;
43 if (underrun) {
44 ++render_buffer_underruns_;
45 }
46
47 if (capture_block_counter_ == kMetricsReportingIntervalBlocks) {
48 metrics_reported_ = true;
49
50 RenderUnderrunCategory underrun_category;
51 if (render_buffer_underruns_ == 0) {
52 underrun_category = RenderUnderrunCategory::kNone;
53 } else if (render_buffer_underruns_ > (capture_block_counter_ >> 1)) {
54 underrun_category = RenderUnderrunCategory::kConstant;
55 } else if (render_buffer_underruns_ > 100) {
56 underrun_category = RenderUnderrunCategory::kMany;
57 } else if (render_buffer_underruns_ > 10) {
58 underrun_category = RenderUnderrunCategory::kSeveral;
59 } else {
60 underrun_category = RenderUnderrunCategory::kFew;
61 }
62 RTC_HISTOGRAM_ENUMERATION(
63 "WebRTC.Audio.EchoCanceller.RenderUnderruns",
64 static_cast<int>(underrun_category),
65 static_cast<int>(RenderUnderrunCategory::kNumCategories));
66
67 RenderOverrunCategory overrun_category;
68 if (render_buffer_overruns_ == 0) {
69 overrun_category = RenderOverrunCategory::kNone;
70 } else if (render_buffer_overruns_ > (buffer_render_calls_ >> 1)) {
71 overrun_category = RenderOverrunCategory::kConstant;
72 } else if (render_buffer_overruns_ > 100) {
73 overrun_category = RenderOverrunCategory::kMany;
74 } else if (render_buffer_overruns_ > 10) {
75 overrun_category = RenderOverrunCategory::kSeveral;
76 } else {
77 overrun_category = RenderOverrunCategory::kFew;
78 }
79 RTC_HISTOGRAM_ENUMERATION(
80 "WebRTC.Audio.EchoCanceller.RenderOverruns",
81 static_cast<int>(overrun_category),
82 static_cast<int>(RenderOverrunCategory::kNumCategories));
83
84 ResetMetrics();
85 capture_block_counter_ = 0;
86 } else {
87 metrics_reported_ = false;
88 }
89 }
90
UpdateRender(bool overrun)91 void BlockProcessorMetrics::UpdateRender(bool overrun) {
92 ++buffer_render_calls_;
93 if (overrun) {
94 ++render_buffer_overruns_;
95 }
96 }
97
ResetMetrics()98 void BlockProcessorMetrics::ResetMetrics() {
99 render_buffer_underruns_ = 0;
100 render_buffer_overruns_ = 0;
101 buffer_render_calls_ = 0;
102 }
103
104 } // namespace webrtc
105