blob: 385f6ffbe0c81c921a669b3de60f4eaa3f2bd6e7 [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
Peter Boström7623ce42015-12-09 12:13:30 +010011#ifndef WEBRTC_VIDEO_CALL_STATS_H_
12#define WEBRTC_VIDEO_CALL_STATS_H_
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000013
14#include <list>
15
henrike@webrtc.org88fbb2d2014-05-21 21:18:46 +000016#include "webrtc/base/constructormagic.h"
Tommi97888bd2016-01-21 23:24:59 +010017#include "webrtc/base/criticalsection.h"
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000018#include "webrtc/base/scoped_ptr.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010019#include "webrtc/modules/include/module.h"
Peter Boströmd3c94472015-12-09 11:20:58 +010020#include "webrtc/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;
37 int32_t 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.
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000067 rtc::scoped_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_;
sprange2d83d62016-02-19 09:03:26 -080073 int64_t sum_avg_rtt_ms_ GUARDED_BY(crit_);
74 int64_t num_avg_rtt_ GUARDED_BY(crit_);
75 int64_t time_of_first_rtt_ms_ 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
Peter Boström7623ce42015-12-09 12:13:30 +010088#endif // WEBRTC_VIDEO_CALL_STATS_H_