blob: da5c2e6c0dc1dd76ce1b59b91684a43744505e4d [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
11#ifndef WEBRTC_VIDEO_ENGINE_CALL_STATS_H_
12#define WEBRTC_VIDEO_ENGINE_CALL_STATS_H_
13
14#include <list>
15
henrike@webrtc.org88fbb2d2014-05-21 21:18:46 +000016#include "webrtc/base/constructormagic.h"
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000017#include "webrtc/modules/interface/module.h"
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000018#include "webrtc/system_wrappers/interface/scoped_ptr.h"
19
20namespace webrtc {
21
fischman@webrtc.orgaea96d32013-02-19 22:09:36 +000022class CallStatsObserver;
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +000023class CriticalSectionWrapper;
24class RtcpRttStats;
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000025
26// CallStats keeps track of statistics for a call.
27class CallStats : public Module {
28 public:
29 friend class RtcpObserver;
30
31 CallStats();
32 ~CallStats();
33
34 // Implements Module, to use the process thread.
pkasting@chromium.org0b1534c2014-12-15 22:09:40 +000035 virtual int64_t TimeUntilNextProcess() OVERRIDE;
henrik.lundin@webrtc.org1972ff82014-09-11 06:20:28 +000036 virtual int32_t Process() OVERRIDE;
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000037
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +000038 // Returns a RtcpRttStats to register at a statistics provider. The object
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000039 // has the same lifetime as the CallStats instance.
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +000040 RtcpRttStats* rtcp_rtt_stats() const;
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000041
42 // Registers/deregisters a new observer to receive statistics updates.
fischman@webrtc.orgaea96d32013-02-19 22:09:36 +000043 void RegisterStatsObserver(CallStatsObserver* observer);
44 void DeregisterStatsObserver(CallStatsObserver* observer);
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000045
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000046 // Helper struct keeping track of the time a rtt value is reported.
47 struct RttTime {
pkasting@chromium.org16825b12015-01-12 21:51:21 +000048 RttTime(int64_t new_rtt, int64_t rtt_time)
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000049 : rtt(new_rtt), time(rtt_time) {}
pkasting@chromium.org16825b12015-01-12 21:51:21 +000050 const int64_t rtt;
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000051 const int64_t time;
52 };
53
asapersson@webrtc.org8084f952014-12-10 11:04:13 +000054 protected:
pkasting@chromium.org16825b12015-01-12 21:51:21 +000055 void OnRttUpdate(int64_t rtt);
asapersson@webrtc.org8084f952014-12-10 11:04:13 +000056
pkasting@chromium.org16825b12015-01-12 21:51:21 +000057 int64_t avg_rtt_ms() const;
asapersson@webrtc.org8084f952014-12-10 11:04:13 +000058
59 private:
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000060 // Protecting all members.
61 scoped_ptr<CriticalSectionWrapper> crit_;
62 // Observer receiving statistics updates.
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +000063 scoped_ptr<RtcpRttStats> rtcp_rtt_stats_;
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000064 // The last time 'Process' resulted in statistic update.
65 int64_t last_process_time_;
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +000066 // The last RTT in the statistics update (zero if there is no valid estimate).
pkasting@chromium.org16825b12015-01-12 21:51:21 +000067 int64_t max_rtt_ms_;
68 int64_t avg_rtt_ms_;
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000069
70 // All Rtt reports within valid time interval, oldest first.
71 std::list<RttTime> reports_;
72
73 // Observers getting stats reports.
fischman@webrtc.orgaea96d32013-02-19 22:09:36 +000074 std::list<CallStatsObserver*> observers_;
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000075
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000076 DISALLOW_COPY_AND_ASSIGN(CallStats);
77};
78
79} // namespace webrtc
80
81#endif // WEBRTC_VIDEO_ENGINE_CALL_STATS_H_