blob: 0dd7bdbaaeeb9e10c72397c745dd78e6ab4fbc7d [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
kjellander8237abf2015-12-08 07:12:06 -080011#ifndef WEBRTC_VIDEO_ENGINE_CALL_STATS_H_
12#define WEBRTC_VIDEO_ENGINE_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"
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000017#include "webrtc/base/scoped_ptr.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010018#include "webrtc/modules/include/module.h"
Peter Boströmd3c94472015-12-09 11:20:58 +010019#include "webrtc/system_wrappers/include/clock.h"
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000020
21namespace webrtc {
22
fischman@webrtc.orgaea96d32013-02-19 22:09:36 +000023class CallStatsObserver;
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +000024class CriticalSectionWrapper;
25class 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:
Peter Boströmd3c94472015-12-09 11:20:58 +010061 Clock* const clock_;
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000062 // Protecting all members.
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000063 rtc::scoped_ptr<CriticalSectionWrapper> crit_;
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000064 // Observer receiving statistics updates.
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000065 rtc::scoped_ptr<RtcpRttStats> rtcp_rtt_stats_;
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000066 // The last time 'Process' resulted in statistic update.
67 int64_t last_process_time_;
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +000068 // The last RTT in the statistics update (zero if there is no valid estimate).
pkasting@chromium.org16825b12015-01-12 21:51:21 +000069 int64_t max_rtt_ms_;
70 int64_t avg_rtt_ms_;
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000071
72 // All Rtt reports within valid time interval, oldest first.
73 std::list<RttTime> reports_;
74
75 // Observers getting stats reports.
fischman@webrtc.orgaea96d32013-02-19 22:09:36 +000076 std::list<CallStatsObserver*> observers_;
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000077
henrikg3c089d72015-09-16 05:37:44 -070078 RTC_DISALLOW_COPY_AND_ASSIGN(CallStats);
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000079};
80
81} // namespace webrtc
82
kjellander8237abf2015-12-08 07:12:06 -080083#endif // WEBRTC_VIDEO_ENGINE_CALL_STATS_H_