mflodman@webrtc.org | b2f474e | 2012-11-16 13:57:26 +0000 | [diff] [blame^] | 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/modules/interface/module.h" |
| 17 | #include "webrtc/system_wrappers/interface/constructor_magic.h" |
| 18 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
| 19 | |
| 20 | namespace webrtc { |
| 21 | |
| 22 | class CriticalSectionWrapper; |
| 23 | class RtcpRttObserver; |
| 24 | |
| 25 | // Interface used to distribute call statistics. Callbacks will be triggered as |
| 26 | // soon as the class has been registered using RegisterStatsObserver. |
| 27 | class StatsObserver { |
| 28 | public: |
| 29 | virtual void OnRttUpdate(uint32_t rtt) = 0; |
| 30 | |
| 31 | virtual ~StatsObserver() {} |
| 32 | }; |
| 33 | |
| 34 | // CallStats keeps track of statistics for a call. |
| 35 | class CallStats : public Module { |
| 36 | public: |
| 37 | friend class RtcpObserver; |
| 38 | |
| 39 | CallStats(); |
| 40 | ~CallStats(); |
| 41 | |
| 42 | // Implements Module, to use the process thread. |
| 43 | virtual int32_t TimeUntilNextProcess(); |
| 44 | virtual int32_t Process(); |
| 45 | |
| 46 | // Returns a RtcpRttObserver to register at a statistics provider. The object |
| 47 | // has the same lifetime as the CallStats instance. |
| 48 | RtcpRttObserver* rtcp_rtt_observer() const; |
| 49 | |
| 50 | // Registers/deregisters a new observer to receive statistics updates. |
| 51 | void RegisterStatsObserver(StatsObserver* observer); |
| 52 | void DeregisterStatsObserver(StatsObserver* observer); |
| 53 | |
| 54 | protected: |
| 55 | void OnRttUpdate(uint32_t rtt); |
| 56 | |
| 57 | private: |
| 58 | // Helper struct keeping track of the time a rtt value is reported. |
| 59 | struct RttTime { |
| 60 | RttTime(uint32_t new_rtt, int64_t rtt_time) |
| 61 | : rtt(new_rtt), time(rtt_time) {} |
| 62 | const uint32_t rtt; |
| 63 | const int64_t time; |
| 64 | }; |
| 65 | |
| 66 | // Protecting all members. |
| 67 | scoped_ptr<CriticalSectionWrapper> crit_; |
| 68 | // Observer receiving statistics updates. |
| 69 | scoped_ptr<RtcpRttObserver> rtcp_rtt_observer_; |
| 70 | // The last time 'Process' resulted in statistic update. |
| 71 | int64_t last_process_time_; |
| 72 | |
| 73 | // All Rtt reports within valid time interval, oldest first. |
| 74 | std::list<RttTime> reports_; |
| 75 | |
| 76 | // Observers getting stats reports. |
| 77 | std::list<StatsObserver*> observers_; |
| 78 | |
| 79 | DISALLOW_COPY_AND_ASSIGN(CallStats); |
| 80 | }; |
| 81 | |
| 82 | } // namespace webrtc |
| 83 | |
| 84 | #endif // WEBRTC_VIDEO_ENGINE_CALL_STATS_H_ |