blob: 5c021a484ea32643e8f0188ca71ee494886685ef [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
16#include "webrtc/modules/interface/module.h"
17#include "webrtc/system_wrappers/interface/constructor_magic.h"
18#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.
35 virtual int32_t TimeUntilNextProcess();
36 virtual int32_t Process();
37
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
46 protected:
47 void OnRttUpdate(uint32_t rtt);
48
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +000049 uint32_t last_processed_rtt_ms() const;
50
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000051 private:
52 // Helper struct keeping track of the time a rtt value is reported.
53 struct RttTime {
54 RttTime(uint32_t new_rtt, int64_t rtt_time)
55 : rtt(new_rtt), time(rtt_time) {}
56 const uint32_t rtt;
57 const int64_t time;
58 };
59
60 // 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).
67 uint32_t last_processed_rtt_ms_;
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000068
69 // All Rtt reports within valid time interval, oldest first.
70 std::list<RttTime> reports_;
71
72 // Observers getting stats reports.
fischman@webrtc.orgaea96d32013-02-19 22:09:36 +000073 std::list<CallStatsObserver*> observers_;
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000074
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000075 DISALLOW_COPY_AND_ASSIGN(CallStats);
76};
77
78} // namespace webrtc
79
80#endif // WEBRTC_VIDEO_ENGINE_CALL_STATS_H_