blob: af5c45c996e94ced2eb4c6d95175f0ac1d9569df [file] [log] [blame]
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +00001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef VIDEO_CALL_STATS_H_
12#define VIDEO_CALL_STATS_H_
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000013
14#include <list>
kwiberg27f982b2016-03-01 11:52:33 -080015#include <memory>
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000016
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#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.orgb2f474e2012-11-16 13:57:26 +000021
22namespace webrtc {
23
fischman@webrtc.orgaea96d32013-02-19 22:09:36 +000024class CallStatsObserver;
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +000025class RtcpRttStats;
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000026
27// CallStats keeps track of statistics for a call.
28class CallStats : public Module {
29 public:
30 friend class RtcpObserver;
31
Peter Boströmd3c94472015-12-09 11:20:58 +010032 explicit CallStats(Clock* clock);
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000033 ~CallStats();
34
35 // Implements Module, to use the process thread.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000036 int64_t TimeUntilNextProcess() override;
pbosa26ac922016-02-25 04:50:01 -080037 void Process() override;
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000038
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +000039 // Returns a RtcpRttStats to register at a statistics provider. The object
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000040 // has the same lifetime as the CallStats instance.
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +000041 RtcpRttStats* rtcp_rtt_stats() const;
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000042
43 // Registers/deregisters a new observer to receive statistics updates.
fischman@webrtc.orgaea96d32013-02-19 22:09:36 +000044 void RegisterStatsObserver(CallStatsObserver* observer);
45 void DeregisterStatsObserver(CallStatsObserver* observer);
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000046
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000047 // Helper struct keeping track of the time a rtt value is reported.
48 struct RttTime {
pkasting@chromium.org16825b12015-01-12 21:51:21 +000049 RttTime(int64_t new_rtt, int64_t rtt_time)
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000050 : rtt(new_rtt), time(rtt_time) {}
pkasting@chromium.org16825b12015-01-12 21:51:21 +000051 const int64_t rtt;
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000052 const int64_t time;
53 };
54
asapersson@webrtc.org8084f952014-12-10 11:04:13 +000055 protected:
pkasting@chromium.org16825b12015-01-12 21:51:21 +000056 void OnRttUpdate(int64_t rtt);
asapersson@webrtc.org8084f952014-12-10 11:04:13 +000057
pkasting@chromium.org16825b12015-01-12 21:51:21 +000058 int64_t avg_rtt_ms() const;
asapersson@webrtc.org8084f952014-12-10 11:04:13 +000059
60 private:
sprange2d83d62016-02-19 09:03:26 -080061 void UpdateHistograms();
62
Peter Boströmd3c94472015-12-09 11:20:58 +010063 Clock* const clock_;
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000064 // Protecting all members.
pbosd8de1152016-02-01 09:00:51 -080065 rtc::CriticalSection crit_;
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000066 // Observer receiving statistics updates.
kwiberg27f982b2016-03-01 11:52:33 -080067 std::unique_ptr<RtcpRttStats> rtcp_rtt_stats_;
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000068 // The last time 'Process' resulted in statistic update.
69 int64_t last_process_time_;
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +000070 // The last RTT in the statistics update (zero if there is no valid estimate).
pkasting@chromium.org16825b12015-01-12 21:51:21 +000071 int64_t max_rtt_ms_;
72 int64_t avg_rtt_ms_;
danilchapa37de392017-09-09 04:17:22 -070073 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.orgb2f474e2012-11-16 13:57:26 +000076
77 // All Rtt reports within valid time interval, oldest first.
78 std::list<RttTime> reports_;
79
80 // Observers getting stats reports.
fischman@webrtc.orgaea96d32013-02-19 22:09:36 +000081 std::list<CallStatsObserver*> observers_;
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000082
henrikg3c089d72015-09-16 05:37:44 -070083 RTC_DISALLOW_COPY_AND_ASSIGN(CallStats);
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000084};
85
86} // namespace webrtc
87
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020088#endif // VIDEO_CALL_STATS_H_