blob: 5fd93a7624188c97f3973096ccf9bb628d772ca5 [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
22class CriticalSectionWrapper;
23class RtcpRttObserver;
fischman@webrtc.orgaea96d32013-02-19 22:09:36 +000024class CallStatsObserver;
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
38 // Returns a RtcpRttObserver to register at a statistics provider. The object
39 // has the same lifetime as the CallStats instance.
40 RtcpRttObserver* rtcp_rtt_observer() const;
41
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
49 private:
50 // Helper struct keeping track of the time a rtt value is reported.
51 struct RttTime {
52 RttTime(uint32_t new_rtt, int64_t rtt_time)
53 : rtt(new_rtt), time(rtt_time) {}
54 const uint32_t rtt;
55 const int64_t time;
56 };
57
58 // Protecting all members.
59 scoped_ptr<CriticalSectionWrapper> crit_;
60 // Observer receiving statistics updates.
61 scoped_ptr<RtcpRttObserver> rtcp_rtt_observer_;
62 // The last time 'Process' resulted in statistic update.
63 int64_t last_process_time_;
64
65 // All Rtt reports within valid time interval, oldest first.
66 std::list<RttTime> reports_;
67
68 // Observers getting stats reports.
fischman@webrtc.orgaea96d32013-02-19 22:09:36 +000069 std::list<CallStatsObserver*> observers_;
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000070
mflodman@webrtc.orgb2f474e2012-11-16 13:57:26 +000071 DISALLOW_COPY_AND_ASSIGN(CallStats);
72};
73
74} // namespace webrtc
75
76#endif // WEBRTC_VIDEO_ENGINE_CALL_STATS_H_