OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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_coding/neteq/statistics_calculator.h" | 11 #include "webrtc/modules/audio_coding/neteq/statistics_calculator.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 #include <string.h> // memset | 14 #include <string.h> // memset |
15 | 15 |
| 16 #include "webrtc/base/checks.h" |
16 #include "webrtc/modules/audio_coding/neteq/decision_logic.h" | 17 #include "webrtc/modules/audio_coding/neteq/decision_logic.h" |
17 #include "webrtc/modules/audio_coding/neteq/delay_manager.h" | 18 #include "webrtc/modules/audio_coding/neteq/delay_manager.h" |
18 #include "webrtc/system_wrappers/interface/metrics.h" | 19 #include "webrtc/system_wrappers/interface/metrics.h" |
19 | 20 |
20 namespace webrtc { | 21 namespace webrtc { |
21 | 22 |
| 23 StatisticsCalculator::PeriodicUmaLogger::PeriodicUmaLogger( |
| 24 const std::string& uma_name, |
| 25 int report_interval_ms, |
| 26 int max_value) |
| 27 : uma_name_(uma_name), |
| 28 report_interval_ms_(report_interval_ms), |
| 29 max_value_(max_value), |
| 30 timer_(0) { |
| 31 } |
| 32 |
| 33 StatisticsCalculator::PeriodicUmaLogger::~PeriodicUmaLogger() = default; |
| 34 |
| 35 void StatisticsCalculator::PeriodicUmaLogger::AdvanceClock(int step_ms) { |
| 36 timer_ += step_ms; |
| 37 if (timer_ < report_interval_ms_) { |
| 38 return; |
| 39 } |
| 40 LogToUma(Metric()); |
| 41 Reset(); |
| 42 timer_ -= report_interval_ms_; |
| 43 DCHECK_GE(timer_, 0); |
| 44 } |
| 45 |
| 46 void StatisticsCalculator::PeriodicUmaLogger::LogToUma(int value) const { |
| 47 RTC_HISTOGRAM_COUNTS(uma_name_, value, 1, max_value_, 50); |
| 48 } |
| 49 |
| 50 StatisticsCalculator::PeriodicUmaCount::PeriodicUmaCount( |
| 51 const std::string& uma_name, |
| 52 int report_interval_ms, |
| 53 int max_value) |
| 54 : PeriodicUmaLogger(uma_name, report_interval_ms, max_value) { |
| 55 } |
| 56 |
| 57 StatisticsCalculator::PeriodicUmaCount::~PeriodicUmaCount() { |
| 58 // Log the count for the current (incomplete) interval. |
| 59 LogToUma(Metric()); |
| 60 } |
| 61 |
| 62 void StatisticsCalculator::PeriodicUmaCount::RegisterSample() { |
| 63 ++counter_; |
| 64 } |
| 65 |
| 66 int StatisticsCalculator::PeriodicUmaCount::Metric() const { |
| 67 return counter_; |
| 68 } |
| 69 |
| 70 void StatisticsCalculator::PeriodicUmaCount::Reset() { |
| 71 counter_ = 0; |
| 72 } |
| 73 |
| 74 StatisticsCalculator::PeriodicUmaAverage::PeriodicUmaAverage( |
| 75 const std::string& uma_name, |
| 76 int report_interval_ms, |
| 77 int max_value) |
| 78 : PeriodicUmaLogger(uma_name, report_interval_ms, max_value) { |
| 79 } |
| 80 |
| 81 StatisticsCalculator::PeriodicUmaAverage::~PeriodicUmaAverage() { |
| 82 // Log the average for the current (incomplete) interval. |
| 83 LogToUma(Metric()); |
| 84 } |
| 85 |
| 86 void StatisticsCalculator::PeriodicUmaAverage::RegisterSample(int value) { |
| 87 sum_ += value; |
| 88 ++counter_; |
| 89 } |
| 90 |
| 91 int StatisticsCalculator::PeriodicUmaAverage::Metric() const { |
| 92 return static_cast<int>(sum_ / counter_); |
| 93 } |
| 94 |
| 95 void StatisticsCalculator::PeriodicUmaAverage::Reset() { |
| 96 sum_ = 0.0; |
| 97 counter_ = 0; |
| 98 } |
| 99 |
22 StatisticsCalculator::StatisticsCalculator() | 100 StatisticsCalculator::StatisticsCalculator() |
23 : preemptive_samples_(0), | 101 : preemptive_samples_(0), |
24 accelerate_samples_(0), | 102 accelerate_samples_(0), |
25 added_zero_samples_(0), | 103 added_zero_samples_(0), |
26 expanded_speech_samples_(0), | 104 expanded_speech_samples_(0), |
27 expanded_noise_samples_(0), | 105 expanded_noise_samples_(0), |
28 discarded_packets_(0), | 106 discarded_packets_(0), |
29 lost_timestamps_(0), | 107 lost_timestamps_(0), |
30 timestamps_since_last_report_(0), | 108 timestamps_since_last_report_(0), |
31 len_waiting_times_(0), | 109 len_waiting_times_(0), |
32 next_waiting_time_index_(0), | 110 next_waiting_time_index_(0), |
33 secondary_decoded_samples_(0) { | 111 secondary_decoded_samples_(0), |
| 112 delayed_packet_outage_counter_( |
| 113 "WebRTC.Audio.DelayedPacketOutageEventsPerMinute", |
| 114 60000, // 60 seconds report interval. |
| 115 100), |
| 116 excess_buffer_delay_("WebRTC.Audio.AverageExcessBufferDelayMs", |
| 117 60000, // 60 seconds report interval. |
| 118 1000) { |
34 memset(waiting_times_, 0, kLenWaitingTimes * sizeof(waiting_times_[0])); | 119 memset(waiting_times_, 0, kLenWaitingTimes * sizeof(waiting_times_[0])); |
35 } | 120 } |
36 | 121 |
37 void StatisticsCalculator::Reset() { | 122 void StatisticsCalculator::Reset() { |
38 preemptive_samples_ = 0; | 123 preemptive_samples_ = 0; |
39 accelerate_samples_ = 0; | 124 accelerate_samples_ = 0; |
40 added_zero_samples_ = 0; | 125 added_zero_samples_ = 0; |
41 expanded_speech_samples_ = 0; | 126 expanded_speech_samples_ = 0; |
42 expanded_noise_samples_ = 0; | 127 expanded_noise_samples_ = 0; |
43 secondary_decoded_samples_ = 0; | 128 secondary_decoded_samples_ = 0; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 162 |
78 void StatisticsCalculator::PacketsDiscarded(int num_packets) { | 163 void StatisticsCalculator::PacketsDiscarded(int num_packets) { |
79 discarded_packets_ += num_packets; | 164 discarded_packets_ += num_packets; |
80 } | 165 } |
81 | 166 |
82 void StatisticsCalculator::LostSamples(int num_samples) { | 167 void StatisticsCalculator::LostSamples(int num_samples) { |
83 lost_timestamps_ += num_samples; | 168 lost_timestamps_ += num_samples; |
84 } | 169 } |
85 | 170 |
86 void StatisticsCalculator::IncreaseCounter(int num_samples, int fs_hz) { | 171 void StatisticsCalculator::IncreaseCounter(int num_samples, int fs_hz) { |
| 172 const int time_step_ms = rtc::CheckedDivExact(1000 * num_samples, fs_hz); |
| 173 delayed_packet_outage_counter_.AdvanceClock(time_step_ms); |
| 174 excess_buffer_delay_.AdvanceClock(time_step_ms); |
87 timestamps_since_last_report_ += static_cast<uint32_t>(num_samples); | 175 timestamps_since_last_report_ += static_cast<uint32_t>(num_samples); |
88 if (timestamps_since_last_report_ > | 176 if (timestamps_since_last_report_ > |
89 static_cast<uint32_t>(fs_hz * kMaxReportPeriod)) { | 177 static_cast<uint32_t>(fs_hz * kMaxReportPeriod)) { |
90 lost_timestamps_ = 0; | 178 lost_timestamps_ = 0; |
91 timestamps_since_last_report_ = 0; | 179 timestamps_since_last_report_ = 0; |
92 discarded_packets_ = 0; | 180 discarded_packets_ = 0; |
93 } | 181 } |
94 } | 182 } |
95 | 183 |
96 void StatisticsCalculator::SecondaryDecodedSamples(int num_samples) { | 184 void StatisticsCalculator::SecondaryDecodedSamples(int num_samples) { |
97 secondary_decoded_samples_ += num_samples; | 185 secondary_decoded_samples_ += num_samples; |
98 } | 186 } |
99 | 187 |
100 void StatisticsCalculator::LogDelayedPacketOutageEvent(int outage_duration_ms) { | 188 void StatisticsCalculator::LogDelayedPacketOutageEvent(int outage_duration_ms) { |
101 RTC_HISTOGRAM_COUNTS("WebRTC.Audio.DelayedPacketOutageEventMs", | 189 RTC_HISTOGRAM_COUNTS("WebRTC.Audio.DelayedPacketOutageEventMs", |
102 outage_duration_ms, 1 /* min */, 2000 /* max */, | 190 outage_duration_ms, 1 /* min */, 2000 /* max */, |
103 100 /* bucket count */); | 191 100 /* bucket count */); |
| 192 delayed_packet_outage_counter_.RegisterSample(); |
104 } | 193 } |
105 | 194 |
106 void StatisticsCalculator::StoreWaitingTime(int waiting_time_ms) { | 195 void StatisticsCalculator::StoreWaitingTime(int waiting_time_ms) { |
| 196 excess_buffer_delay_.RegisterSample(waiting_time_ms); |
107 assert(next_waiting_time_index_ < kLenWaitingTimes); | 197 assert(next_waiting_time_index_ < kLenWaitingTimes); |
108 waiting_times_[next_waiting_time_index_] = waiting_time_ms; | 198 waiting_times_[next_waiting_time_index_] = waiting_time_ms; |
109 next_waiting_time_index_++; | 199 next_waiting_time_index_++; |
110 if (next_waiting_time_index_ >= kLenWaitingTimes) { | 200 if (next_waiting_time_index_ >= kLenWaitingTimes) { |
111 next_waiting_time_index_ = 0; | 201 next_waiting_time_index_ = 0; |
112 } | 202 } |
113 if (len_waiting_times_ < kLenWaitingTimes) { | 203 if (len_waiting_times_ < kLenWaitingTimes) { |
114 len_waiting_times_++; | 204 len_waiting_times_++; |
115 } | 205 } |
116 } | 206 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 // Ratio must be smaller than 1 in Q14. | 273 // Ratio must be smaller than 1 in Q14. |
184 assert((numerator << 14) / denominator < (1 << 14)); | 274 assert((numerator << 14) / denominator < (1 << 14)); |
185 return static_cast<uint16_t>((numerator << 14) / denominator); | 275 return static_cast<uint16_t>((numerator << 14) / denominator); |
186 } else { | 276 } else { |
187 // Will not produce a ratio larger than 1, since this is probably an error. | 277 // Will not produce a ratio larger than 1, since this is probably an error. |
188 return 1 << 14; | 278 return 1 << 14; |
189 } | 279 } |
190 } | 280 } |
191 | 281 |
192 } // namespace webrtc | 282 } // namespace webrtc |
OLD | NEW |