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 14 #include <map> 15 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 24 class StreamStatistician { 25 public: 26 virtual ~StreamStatistician(); 27 28 virtual bool GetStatistics(RtcpStatistics* statistics, bool reset) = 0; 29 virtual void GetDataCounters(size_t* bytes_received, 30 uint32_t* packets_received) const = 0; 31 32 // Gets received stream data counters (includes reset counter values). 33 virtual void GetReceiveStreamDataCounters( 34 StreamDataCounters* data_counters) const = 0; 35 36 virtual uint32_t BitrateReceived() const = 0; 37 38 // Resets all statistics. 39 virtual void ResetStatistics() = 0; 40 41 // Returns true if the packet with RTP header |header| is likely to be a 42 // retransmitted packet, false otherwise. 43 virtual bool IsRetransmitOfOldPacket(const RTPHeader& header, 44 int64_t min_rtt) const = 0; 45 46 // Returns true if |sequence_number| is received in order, false otherwise. 47 virtual bool IsPacketInOrder(uint16_t sequence_number) const = 0; 48 }; 49 50 typedef std::map<uint32_t, StreamStatistician*> StatisticianMap; 51 52 class ReceiveStatistics : public Module { 53 public: ~ReceiveStatistics()54 virtual ~ReceiveStatistics() {} 55 56 static ReceiveStatistics* Create(Clock* clock); 57 58 // Updates the receive statistics with this packet. 59 virtual void IncomingPacket(const RTPHeader& rtp_header, 60 size_t packet_length, 61 bool retransmitted) = 0; 62 63 // Increment counter for number of FEC packets received. 64 virtual void FecPacketReceived(const RTPHeader& header, 65 size_t packet_length) = 0; 66 67 // Returns a map of all statisticians which have seen an incoming packet 68 // during the last two seconds. 69 virtual StatisticianMap GetActiveStatisticians() const = 0; 70 71 // Returns a pointer to the statistician of an ssrc. 72 virtual StreamStatistician* GetStatistician(uint32_t ssrc) const = 0; 73 74 // Sets the max reordering threshold in number of packets. 75 virtual void SetMaxReorderingThreshold(int max_reordering_threshold) = 0; 76 77 // Called on new RTCP stats creation. 78 virtual void RegisterRtcpStatisticsCallback( 79 RtcpStatisticsCallback* callback) = 0; 80 81 // Called on new RTP stats creation. 82 virtual void RegisterRtpStatisticsCallback( 83 StreamDataCountersCallback* callback) = 0; 84 }; 85 86 class NullReceiveStatistics : public ReceiveStatistics { 87 public: 88 void IncomingPacket(const RTPHeader& rtp_header, 89 size_t packet_length, 90 bool retransmitted) override; 91 void FecPacketReceived(const RTPHeader& header, 92 size_t packet_length) override; 93 StatisticianMap GetActiveStatisticians() const override; 94 StreamStatistician* GetStatistician(uint32_t ssrc) const override; 95 int64_t TimeUntilNextProcess() override; 96 int32_t Process() override; 97 void SetMaxReorderingThreshold(int max_reordering_threshold) override; 98 void RegisterRtcpStatisticsCallback( 99 RtcpStatisticsCallback* callback) override; 100 void RegisterRtpStatisticsCallback( 101 StreamDataCountersCallback* callback) override; 102 }; 103 104 } // namespace webrtc 105 #endif // WEBRTC_MODULES_RTP_RTCP_INTERFACE_RECEIVE_STATISTICS_H_ 106