• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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/base/constructormagic.h"
17 #include "webrtc/modules/interface/module.h"
18 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
19 
20 namespace webrtc {
21 
22 class CallStatsObserver;
23 class CriticalSectionWrapper;
24 class RtcpRttStats;
25 
26 // CallStats keeps track of statistics for a call.
27 class 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 RtcpRttStats to register at a statistics provider. The object
39   // has the same lifetime as the CallStats instance.
40   RtcpRttStats* rtcp_rtt_stats() const;
41 
42   // Registers/deregisters a new observer to receive statistics updates.
43   void RegisterStatsObserver(CallStatsObserver* observer);
44   void DeregisterStatsObserver(CallStatsObserver* observer);
45 
46  protected:
47   void OnRttUpdate(uint32_t rtt);
48 
49   uint32_t last_processed_rtt_ms() const;
50 
51  private:
52   // Helper struct keeping track of the time a rtt value is reported.
53   struct RttTime {
RttTimeRttTime54     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.
63   scoped_ptr<RtcpRttStats> rtcp_rtt_stats_;
64   // The last time 'Process' resulted in statistic update.
65   int64_t last_process_time_;
66   // The last RTT in the statistics update (zero if there is no valid estimate).
67   uint32_t last_processed_rtt_ms_;
68 
69   // All Rtt reports within valid time interval, oldest first.
70   std::list<RttTime> reports_;
71 
72   // Observers getting stats reports.
73   std::list<CallStatsObserver*> observers_;
74 
75   DISALLOW_COPY_AND_ASSIGN(CallStats);
76 };
77 
78 }  // namespace webrtc
79 
80 #endif  // WEBRTC_VIDEO_ENGINE_CALL_STATS_H_
81