wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 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_MODULES_RTP_RTCP_INTERFACE_RECEIVE_STATISTICS_H_ |
| 12 | #define WEBRTC_MODULES_RTP_RTCP_INTERFACE_RECEIVE_STATISTICS_H_ |
| 13 | |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 14 | #include <map> |
| 15 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 16 | #include "webrtc/modules/interface/module.h" |
| 17 | #include "webrtc/modules/interface/module_common_types.h" |
| 18 | #include "webrtc/typedefs.h" |
| 19 | |
| 20 | namespace webrtc { |
| 21 | |
| 22 | class Clock; |
| 23 | |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 24 | class StreamStatistician { |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 25 | public: |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 26 | struct Statistics { |
| 27 | Statistics() |
| 28 | : fraction_lost(0), |
| 29 | cumulative_lost(0), |
| 30 | extended_max_sequence_number(0), |
| 31 | jitter(0), |
| 32 | max_jitter(0) {} |
| 33 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 34 | uint8_t fraction_lost; |
| 35 | uint32_t cumulative_lost; |
| 36 | uint32_t extended_max_sequence_number; |
| 37 | uint32_t jitter; |
| 38 | uint32_t max_jitter; |
| 39 | }; |
| 40 | |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 41 | virtual ~StreamStatistician(); |
| 42 | |
| 43 | virtual bool GetStatistics(Statistics* statistics, bool reset) = 0; |
| 44 | virtual void GetDataCounters(uint32_t* bytes_received, |
| 45 | uint32_t* packets_received) const = 0; |
| 46 | virtual uint32_t BitrateReceived() const = 0; |
| 47 | // Resets all statistics. |
| 48 | virtual void ResetStatistics() = 0; |
| 49 | }; |
| 50 | |
| 51 | typedef std::map<uint32_t, StreamStatistician*> StatisticianMap; |
| 52 | |
| 53 | class ReceiveStatistics : public Module { |
| 54 | public: |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 55 | virtual ~ReceiveStatistics() {} |
| 56 | |
| 57 | static ReceiveStatistics* Create(Clock* clock); |
| 58 | |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 59 | // Updates the receive statistics with this packet. |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 60 | virtual void IncomingPacket(const RTPHeader& rtp_header, size_t bytes, |
| 61 | bool retransmitted, bool in_order) = 0; |
| 62 | |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 63 | // Returns a map of all statisticians which have seen an incoming packet |
| 64 | // during the last two seconds. |
| 65 | virtual StatisticianMap GetActiveStatisticians() const = 0; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 66 | |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 67 | // Returns a pointer to the statistician of an ssrc. |
| 68 | virtual StreamStatistician* GetStatistician(uint32_t ssrc) const = 0; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 69 | }; |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 70 | |
| 71 | class NullReceiveStatistics : public ReceiveStatistics { |
| 72 | public: |
| 73 | virtual void IncomingPacket(const RTPHeader& rtp_header, size_t bytes, |
| 74 | bool retransmitted, bool in_order) OVERRIDE; |
| 75 | virtual StatisticianMap GetActiveStatisticians() const OVERRIDE; |
| 76 | virtual StreamStatistician* GetStatistician(uint32_t ssrc) const OVERRIDE; |
| 77 | virtual int32_t TimeUntilNextProcess() OVERRIDE; |
| 78 | virtual int32_t Process() OVERRIDE; |
| 79 | }; |
| 80 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 81 | } // namespace webrtc |
| 82 | #endif // WEBRTC_MODULES_RTP_RTCP_INTERFACE_RECEIVE_STATISTICS_H_ |