OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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_VIDEO_STATS_COUNTER_H_ | 11 #ifndef WEBRTC_VIDEO_STATS_COUNTER_H_ |
12 #define WEBRTC_VIDEO_STATS_COUNTER_H_ | 12 #define WEBRTC_VIDEO_STATS_COUNTER_H_ |
13 | 13 |
14 #include <memory> | 14 #include <memory> |
15 | 15 |
16 #include "webrtc/base/constructormagic.h" | 16 #include "webrtc/base/constructormagic.h" |
17 #include "webrtc/typedefs.h" | 17 #include "webrtc/typedefs.h" |
18 | 18 |
19 namespace webrtc { | 19 namespace webrtc { |
20 | 20 |
21 class AggregatedCounter; | 21 class AggregatedCounter; |
22 class Clock; | 22 class Clock; |
| 23 class Samples; |
23 | 24 |
24 // |StatsCounterObserver| is called periodically when a metric is updated. | 25 // |StatsCounterObserver| is called periodically when a metric is updated. |
25 class StatsCounterObserver { | 26 class StatsCounterObserver { |
26 public: | 27 public: |
27 virtual void OnMetricUpdated(int sample) = 0; | 28 virtual void OnMetricUpdated(int sample) = 0; |
28 | 29 |
29 virtual ~StatsCounterObserver() {} | 30 virtual ~StatsCounterObserver() {} |
30 }; | 31 }; |
31 | 32 |
32 struct AggregatedStats { | 33 struct AggregatedStats { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 virtual bool GetMetric(int* metric) const = 0; | 82 virtual bool GetMetric(int* metric) const = 0; |
82 | 83 |
83 AggregatedStats GetStats(); | 84 AggregatedStats GetStats(); |
84 | 85 |
85 protected: | 86 protected: |
86 StatsCounter(Clock* clock, | 87 StatsCounter(Clock* clock, |
87 bool include_empty_intervals, | 88 bool include_empty_intervals, |
88 StatsCounterObserver* observer); | 89 StatsCounterObserver* observer); |
89 | 90 |
90 void Add(int sample); | 91 void Add(int sample); |
91 void Set(int sample); | 92 void Set(int sample, uint32_t ssrc); |
92 | 93 |
93 int max_; | 94 const std::unique_ptr<Samples> samples_; |
94 int64_t sum_; | 95 const bool include_empty_intervals_; |
95 int64_t num_samples_; | |
96 int64_t last_sum_; | |
97 | 96 |
98 private: | 97 private: |
99 bool TimeToProcess(); | 98 bool TimeToProcess(); |
100 void TryProcess(); | 99 void TryProcess(); |
101 | 100 |
102 Clock* const clock_; | 101 Clock* const clock_; |
103 const bool include_empty_intervals_; | |
104 const std::unique_ptr<StatsCounterObserver> observer_; | 102 const std::unique_ptr<StatsCounterObserver> observer_; |
105 const std::unique_ptr<AggregatedCounter> aggregated_counter_; | 103 const std::unique_ptr<AggregatedCounter> aggregated_counter_; |
106 int64_t last_process_time_ms_; | 104 int64_t last_process_time_ms_; |
107 }; | 105 }; |
108 | 106 |
109 // AvgCounter: average of samples | 107 // AvgCounter: average of samples |
110 // | 108 // |
111 // | * * * | * * | ... | 109 // | * * * | * * | ... |
112 // | Add(5) Add(1) Add(6) | Add(5) Add(5) | | 110 // | Add(5) Add(1) Add(6) | Add(5) Add(5) | |
113 // GetMetric | (5 + 1 + 6) / 3 | (5 + 5) / 2 | | 111 // GetMetric | (5 + 1 + 6) / 3 | (5 + 5) / 2 | |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 // |<------ 2 sec ------->| | | 209 // |<------ 2 sec ------->| | |
212 // GetMetric | 8 / 2 | (13 - 8) / 2 | | 210 // GetMetric | 8 / 2 | (13 - 8) / 2 | |
213 // | 211 // |
214 class RateAccCounter : public StatsCounter { | 212 class RateAccCounter : public StatsCounter { |
215 public: | 213 public: |
216 RateAccCounter(Clock* clock, | 214 RateAccCounter(Clock* clock, |
217 StatsCounterObserver* observer, | 215 StatsCounterObserver* observer, |
218 bool include_empty_intervals); | 216 bool include_empty_intervals); |
219 ~RateAccCounter() override {} | 217 ~RateAccCounter() override {} |
220 | 218 |
221 void Set(int sample); | 219 void Set(int sample, uint32_t ssrc); |
222 | 220 |
223 private: | 221 private: |
224 bool GetMetric(int* metric) const override; | 222 bool GetMetric(int* metric) const override; |
225 | 223 |
226 RTC_DISALLOW_COPY_AND_ASSIGN(RateAccCounter); | 224 RTC_DISALLOW_COPY_AND_ASSIGN(RateAccCounter); |
227 }; | 225 }; |
228 | 226 |
229 } // namespace webrtc | 227 } // namespace webrtc |
230 | 228 |
231 #endif // WEBRTC_VIDEO_STATS_COUNTER_H_ | 229 #endif // WEBRTC_VIDEO_STATS_COUNTER_H_ |
OLD | NEW |