mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef VIDEO_CALL_STATS_H_ |
| 12 | #define VIDEO_CALL_STATS_H_ |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 +0000 | [diff] [blame] | 13 | |
| 14 | #include <list> |
kwiberg | 27f982b | 2016-03-01 11:52:33 -0800 | [diff] [blame] | 15 | #include <memory> |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 +0000 | [diff] [blame] | 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "modules/include/module.h" |
| 18 | #include "rtc_base/constructormagic.h" |
| 19 | #include "rtc_base/criticalsection.h" |
| 20 | #include "system_wrappers/include/clock.h" |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 +0000 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | |
fischman@webrtc.org | aea96d3 | 2013-02-19 22:09:36 +0000 | [diff] [blame] | 24 | class CallStatsObserver; |
asapersson@webrtc.org | 1ae1d0c | 2013-11-20 12:46:11 +0000 | [diff] [blame] | 25 | class RtcpRttStats; |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 +0000 | [diff] [blame] | 26 | |
| 27 | // CallStats keeps track of statistics for a call. |
| 28 | class CallStats : public Module { |
| 29 | public: |
| 30 | friend class RtcpObserver; |
| 31 | |
Peter Boström | d3c9447 | 2015-12-09 11:20:58 +0100 | [diff] [blame] | 32 | explicit CallStats(Clock* clock); |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 +0000 | [diff] [blame] | 33 | ~CallStats(); |
| 34 | |
| 35 | // Implements Module, to use the process thread. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 36 | int64_t TimeUntilNextProcess() override; |
pbos | a26ac92 | 2016-02-25 04:50:01 -0800 | [diff] [blame] | 37 | void Process() override; |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 +0000 | [diff] [blame] | 38 | |
asapersson@webrtc.org | 1ae1d0c | 2013-11-20 12:46:11 +0000 | [diff] [blame] | 39 | // Returns a RtcpRttStats to register at a statistics provider. The object |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 +0000 | [diff] [blame] | 40 | // has the same lifetime as the CallStats instance. |
asapersson@webrtc.org | 1ae1d0c | 2013-11-20 12:46:11 +0000 | [diff] [blame] | 41 | RtcpRttStats* rtcp_rtt_stats() const; |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 +0000 | [diff] [blame] | 42 | |
| 43 | // Registers/deregisters a new observer to receive statistics updates. |
fischman@webrtc.org | aea96d3 | 2013-02-19 22:09:36 +0000 | [diff] [blame] | 44 | void RegisterStatsObserver(CallStatsObserver* observer); |
| 45 | void DeregisterStatsObserver(CallStatsObserver* observer); |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 +0000 | [diff] [blame] | 46 | |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 +0000 | [diff] [blame] | 47 | // Helper struct keeping track of the time a rtt value is reported. |
| 48 | struct RttTime { |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 49 | RttTime(int64_t new_rtt, int64_t rtt_time) |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 +0000 | [diff] [blame] | 50 | : rtt(new_rtt), time(rtt_time) {} |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 51 | const int64_t rtt; |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 +0000 | [diff] [blame] | 52 | const int64_t time; |
| 53 | }; |
| 54 | |
asapersson@webrtc.org | 8084f95 | 2014-12-10 11:04:13 +0000 | [diff] [blame] | 55 | protected: |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 56 | void OnRttUpdate(int64_t rtt); |
asapersson@webrtc.org | 8084f95 | 2014-12-10 11:04:13 +0000 | [diff] [blame] | 57 | |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 58 | int64_t avg_rtt_ms() const; |
asapersson@webrtc.org | 8084f95 | 2014-12-10 11:04:13 +0000 | [diff] [blame] | 59 | |
| 60 | private: |
sprang | e2d83d6 | 2016-02-19 09:03:26 -0800 | [diff] [blame] | 61 | void UpdateHistograms(); |
| 62 | |
Peter Boström | d3c9447 | 2015-12-09 11:20:58 +0100 | [diff] [blame] | 63 | Clock* const clock_; |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 +0000 | [diff] [blame] | 64 | // Protecting all members. |
pbos | d8de115 | 2016-02-01 09:00:51 -0800 | [diff] [blame] | 65 | rtc::CriticalSection crit_; |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 +0000 | [diff] [blame] | 66 | // Observer receiving statistics updates. |
kwiberg | 27f982b | 2016-03-01 11:52:33 -0800 | [diff] [blame] | 67 | std::unique_ptr<RtcpRttStats> rtcp_rtt_stats_; |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 +0000 | [diff] [blame] | 68 | // The last time 'Process' resulted in statistic update. |
| 69 | int64_t last_process_time_; |
asapersson@webrtc.org | 1ae1d0c | 2013-11-20 12:46:11 +0000 | [diff] [blame] | 70 | // The last RTT in the statistics update (zero if there is no valid estimate). |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 71 | int64_t max_rtt_ms_; |
| 72 | int64_t avg_rtt_ms_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 73 | int64_t sum_avg_rtt_ms_ RTC_GUARDED_BY(crit_); |
| 74 | int64_t num_avg_rtt_ RTC_GUARDED_BY(crit_); |
| 75 | int64_t time_of_first_rtt_ms_ RTC_GUARDED_BY(crit_); |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 +0000 | [diff] [blame] | 76 | |
| 77 | // All Rtt reports within valid time interval, oldest first. |
| 78 | std::list<RttTime> reports_; |
| 79 | |
| 80 | // Observers getting stats reports. |
fischman@webrtc.org | aea96d3 | 2013-02-19 22:09:36 +0000 | [diff] [blame] | 81 | std::list<CallStatsObserver*> observers_; |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 +0000 | [diff] [blame] | 82 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 83 | RTC_DISALLOW_COPY_AND_ASSIGN(CallStats); |
mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | } // namespace webrtc |
| 87 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 88 | #endif // VIDEO_CALL_STATS_H_ |