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 #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_STATISTICS_CALCULATOR_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_STATISTICS_CALCULATOR_H_ |
12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_STATISTICS_CALCULATOR_H_ | 12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_STATISTICS_CALCULATOR_H_ |
13 | 13 |
| 14 #include <string> |
14 #include <vector> | 15 #include <vector> |
15 | 16 |
16 #include "webrtc/base/constructormagic.h" | 17 #include "webrtc/base/constructormagic.h" |
17 #include "webrtc/modules/audio_coding/neteq/interface/neteq.h" | 18 #include "webrtc/modules/audio_coding/neteq/interface/neteq.h" |
18 #include "webrtc/typedefs.h" | 19 #include "webrtc/typedefs.h" |
19 | 20 |
20 namespace webrtc { | 21 namespace webrtc { |
21 | 22 |
22 // Forward declarations. | 23 // Forward declarations. |
23 class DecisionLogic; | 24 class DecisionLogic; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 // Reports that |num_samples| zeros were inserted into the output. | 58 // Reports that |num_samples| zeros were inserted into the output. |
58 void AddZeros(int num_samples); | 59 void AddZeros(int num_samples); |
59 | 60 |
60 // Reports that |num_packets| packets were discarded. | 61 // Reports that |num_packets| packets were discarded. |
61 void PacketsDiscarded(int num_packets); | 62 void PacketsDiscarded(int num_packets); |
62 | 63 |
63 // Reports that |num_samples| were lost. | 64 // Reports that |num_samples| were lost. |
64 void LostSamples(int num_samples); | 65 void LostSamples(int num_samples); |
65 | 66 |
66 // Increases the report interval counter with |num_samples| at a sample rate | 67 // Increases the report interval counter with |num_samples| at a sample rate |
67 // of |fs_hz|. | 68 // of |fs_hz|. This is how the StatisticsCalculator gets notified that current |
| 69 // time is increasing. |
68 void IncreaseCounter(int num_samples, int fs_hz); | 70 void IncreaseCounter(int num_samples, int fs_hz); |
69 | 71 |
70 // Stores new packet waiting time in waiting time statistics. | 72 // Stores new packet waiting time in waiting time statistics. |
71 void StoreWaitingTime(int waiting_time_ms); | 73 void StoreWaitingTime(int waiting_time_ms); |
72 | 74 |
73 // Reports that |num_samples| samples were decoded from secondary packets. | 75 // Reports that |num_samples| samples were decoded from secondary packets. |
74 void SecondaryDecodedSamples(int num_samples); | 76 void SecondaryDecodedSamples(int num_samples); |
75 | 77 |
76 // Logs a delayed packet outage event of |outage_duration_ms|. A delayed | 78 // Logs a delayed packet outage event of |outage_duration_ms|. A delayed |
77 // packet outage event is defined as an expand period caused not by an actual | 79 // packet outage event is defined as an expand period caused not by an actual |
(...skipping 10 matching lines...) Expand all Loading... |
88 const DelayManager& delay_manager, | 90 const DelayManager& delay_manager, |
89 const DecisionLogic& decision_logic, | 91 const DecisionLogic& decision_logic, |
90 NetEqNetworkStatistics *stats); | 92 NetEqNetworkStatistics *stats); |
91 | 93 |
92 void WaitingTimes(std::vector<int>* waiting_times); | 94 void WaitingTimes(std::vector<int>* waiting_times); |
93 | 95 |
94 private: | 96 private: |
95 static const int kMaxReportPeriod = 60; // Seconds before auto-reset. | 97 static const int kMaxReportPeriod = 60; // Seconds before auto-reset. |
96 static const int kLenWaitingTimes = 100; | 98 static const int kLenWaitingTimes = 100; |
97 | 99 |
| 100 class PeriodicUmaLogger { |
| 101 public: |
| 102 PeriodicUmaLogger(const std::string& uma_name, |
| 103 int report_interval_ms, |
| 104 int max_value); |
| 105 virtual ~PeriodicUmaLogger(); |
| 106 void AdvanceClock(int step_ms); |
| 107 |
| 108 protected: |
| 109 void LogToUma(int value) const; |
| 110 virtual int Metric() const = 0; |
| 111 virtual void Reset() = 0; |
| 112 |
| 113 const std::string uma_name_; |
| 114 const int report_interval_ms_; |
| 115 const int max_value_; |
| 116 int timer_ = 0; |
| 117 }; |
| 118 |
| 119 class PeriodicUmaCount final : public PeriodicUmaLogger { |
| 120 public: |
| 121 PeriodicUmaCount(const std::string& uma_name, |
| 122 int report_interval_ms, |
| 123 int max_value); |
| 124 ~PeriodicUmaCount() override; |
| 125 void RegisterSample(); |
| 126 |
| 127 protected: |
| 128 int Metric() const override; |
| 129 void Reset() override; |
| 130 |
| 131 private: |
| 132 int counter_ = 0; |
| 133 }; |
| 134 |
| 135 class PeriodicUmaAverage final : public PeriodicUmaLogger { |
| 136 public: |
| 137 PeriodicUmaAverage(const std::string& uma_name, |
| 138 int report_interval_ms, |
| 139 int max_value); |
| 140 ~PeriodicUmaAverage() override; |
| 141 void RegisterSample(int value); |
| 142 |
| 143 protected: |
| 144 int Metric() const override; |
| 145 void Reset() override; |
| 146 |
| 147 private: |
| 148 double sum_ = 0.0; |
| 149 int counter_ = 0; |
| 150 }; |
| 151 |
98 // Calculates numerator / denominator, and returns the value in Q14. | 152 // Calculates numerator / denominator, and returns the value in Q14. |
99 static uint16_t CalculateQ14Ratio(uint32_t numerator, uint32_t denominator); | 153 static uint16_t CalculateQ14Ratio(uint32_t numerator, uint32_t denominator); |
100 | 154 |
101 uint32_t preemptive_samples_; | 155 uint32_t preemptive_samples_; |
102 uint32_t accelerate_samples_; | 156 uint32_t accelerate_samples_; |
103 int added_zero_samples_; | 157 int added_zero_samples_; |
104 uint32_t expanded_speech_samples_; | 158 uint32_t expanded_speech_samples_; |
105 uint32_t expanded_noise_samples_; | 159 uint32_t expanded_noise_samples_; |
106 int discarded_packets_; | 160 int discarded_packets_; |
107 uint32_t lost_timestamps_; | 161 uint32_t lost_timestamps_; |
108 uint32_t timestamps_since_last_report_; | 162 uint32_t timestamps_since_last_report_; |
109 int waiting_times_[kLenWaitingTimes]; // Used as a circular buffer. | 163 int waiting_times_[kLenWaitingTimes]; // Used as a circular buffer. |
110 int len_waiting_times_; | 164 int len_waiting_times_; |
111 int next_waiting_time_index_; | 165 int next_waiting_time_index_; |
112 uint32_t secondary_decoded_samples_; | 166 uint32_t secondary_decoded_samples_; |
| 167 PeriodicUmaCount delayed_packet_outage_counter_; |
| 168 PeriodicUmaAverage excess_buffer_delay_; |
113 | 169 |
114 DISALLOW_COPY_AND_ASSIGN(StatisticsCalculator); | 170 DISALLOW_COPY_AND_ASSIGN(StatisticsCalculator); |
115 }; | 171 }; |
116 | 172 |
117 } // namespace webrtc | 173 } // namespace webrtc |
118 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_STATISTICS_CALCULATOR_H_ | 174 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_STATISTICS_CALCULATOR_H_ |
OLD | NEW |