blob: 6f2ea4fb3e69152ddfffac3a93ed80529330c02d [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.
sprang@webrtc.org0e932572014-01-23 10:00:39 +000054 virtual void IncomingPacket(const RTPHeader& rtp_header,
55 size_t bytes,
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000056 bool retransmitted) = 0;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000057
sprang@webrtc.org0e932572014-01-23 10:00:39 +000058 // Increment counter for number of FEC packets received.
59 virtual void FecPacketReceived(uint32_t ssrc) = 0;
60
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000061 // Returns a map of all statisticians which have seen an incoming packet
62 // during the last two seconds.
63 virtual StatisticianMap GetActiveStatisticians() const = 0;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000064
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000065 // Returns a pointer to the statistician of an ssrc.
66 virtual StreamStatistician* GetStatistician(uint32_t ssrc) const = 0;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000067
68 // Sets the max reordering threshold in number of packets.
69 virtual void SetMaxReorderingThreshold(int max_reordering_threshold) = 0;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +000070
71 // Called on new RTCP stats creation.
72 virtual void RegisterRtcpStatisticsCallback(
73 RtcpStatisticsCallback* callback) = 0;
sprang@webrtc.org0e932572014-01-23 10:00:39 +000074
75 // Called on new RTP stats creation.
76 virtual void RegisterRtpStatisticsCallback(
77 StreamDataCountersCallback* callback) = 0;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000078};
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000079
80class NullReceiveStatistics : public ReceiveStatistics {
81 public:
sprang@webrtc.org0e932572014-01-23 10:00:39 +000082 virtual void IncomingPacket(const RTPHeader& rtp_header,
83 size_t bytes,
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000084 bool retransmitted) OVERRIDE;
sprang@webrtc.org0e932572014-01-23 10:00:39 +000085 virtual void FecPacketReceived(uint32_t ssrc) OVERRIDE;
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000086 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;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000090 virtual void SetMaxReorderingThreshold(int max_reordering_threshold) OVERRIDE;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +000091 virtual void RegisterRtcpStatisticsCallback(RtcpStatisticsCallback* callback)
92 OVERRIDE;
sprang@webrtc.org0e932572014-01-23 10:00:39 +000093 virtual void RegisterRtpStatisticsCallback(
94 StreamDataCountersCallback* callback) OVERRIDE;
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000095};
96
wu@webrtc.org822fbd82013-08-15 23:38:54 +000097} // namespace webrtc
98#endif // WEBRTC_MODULES_RTP_RTCP_INTERFACE_RECEIVE_STATISTICS_H_