blob: d034b4957e48b52609e286cdbdc2d6417f57ab1f [file] [log] [blame]
wu@webrtc.org822fbd82013-08-15 23:38:54 +00001/*
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.org286fe0b2013-08-21 20:58:21 +000014#include <map>
15
wu@webrtc.org822fbd82013-08-15 23:38:54 +000016#include "webrtc/modules/interface/module.h"
17#include "webrtc/modules/interface/module_common_types.h"
18#include "webrtc/typedefs.h"
19
20namespace webrtc {
21
22class Clock;
23
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000024class StreamStatistician {
wu@webrtc.org822fbd82013-08-15 23:38:54 +000025 public:
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000026 virtual ~StreamStatistician();
27
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +000028 virtual bool GetStatistics(RtcpStatistics* statistics, bool reset) = 0;
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000029 virtual void GetDataCounters(uint32_t* bytes_received,
30 uint32_t* packets_received) const = 0;
31 virtual uint32_t BitrateReceived() const = 0;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000032
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000033 // Resets all statistics.
34 virtual void ResetStatistics() = 0;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000035
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;
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000043};
44
45typedef std::map<uint32_t, StreamStatistician*> StatisticianMap;
46
47class ReceiveStatistics : public Module {
48 public:
wu@webrtc.org822fbd82013-08-15 23:38:54 +000049 virtual ~ReceiveStatistics() {}
50
51 static ReceiveStatistics* Create(Clock* clock);
52
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000053 // Updates the receive statistics with this packet.
wu@webrtc.org822fbd82013-08-15 23:38:54 +000054 virtual void IncomingPacket(const RTPHeader& rtp_header, size_t bytes,
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000055 bool retransmitted) = 0;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000056
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000057 // Returns a map of all statisticians which have seen an incoming packet
58 // during the last two seconds.
59 virtual StatisticianMap GetActiveStatisticians() const = 0;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000060
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000061 // Returns a pointer to the statistician of an ssrc.
62 virtual StreamStatistician* GetStatistician(uint32_t ssrc) const = 0;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000063
64 // Sets the max reordering threshold in number of packets.
65 virtual void SetMaxReorderingThreshold(int max_reordering_threshold) = 0;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +000066
67 // Called on new RTCP stats creation.
68 virtual void RegisterRtcpStatisticsCallback(
69 RtcpStatisticsCallback* callback) = 0;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000070};
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000071
72class NullReceiveStatistics : public ReceiveStatistics {
73 public:
74 virtual void IncomingPacket(const RTPHeader& rtp_header, size_t bytes,
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000075 bool retransmitted) OVERRIDE;
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000076 virtual StatisticianMap GetActiveStatisticians() const OVERRIDE;
77 virtual StreamStatistician* GetStatistician(uint32_t ssrc) const OVERRIDE;
78 virtual int32_t TimeUntilNextProcess() OVERRIDE;
79 virtual int32_t Process() OVERRIDE;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000080 virtual void SetMaxReorderingThreshold(int max_reordering_threshold) OVERRIDE;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +000081 virtual void RegisterRtcpStatisticsCallback(RtcpStatisticsCallback* callback)
82 OVERRIDE;
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000083};
84
wu@webrtc.org822fbd82013-08-15 23:38:54 +000085} // namespace webrtc
86#endif // WEBRTC_MODULES_RTP_RTCP_INTERFACE_RECEIVE_STATISTICS_H_