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