blob: 707adaa0cd3bd03401cac0f938bb2e99d4761c02 [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 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.org822fbd82013-08-15 23:38:54 +000034 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.org286fe0b2013-08-21 20:58:21 +000041 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;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000047
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000048 // Resets all statistics.
49 virtual void ResetStatistics() = 0;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000050
51 // Returns true if the packet with RTP header |header| is likely to be a
52 // retransmitted packet, false otherwise.
53 virtual bool IsRetransmitOfOldPacket(const RTPHeader& header,
54 int min_rtt) const = 0;
55
56 // Returns true if |sequence_number| is received in order, false otherwise.
57 virtual bool IsPacketInOrder(uint16_t sequence_number) const = 0;
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000058};
59
60typedef std::map<uint32_t, StreamStatistician*> StatisticianMap;
61
62class ReceiveStatistics : public Module {
63 public:
wu@webrtc.org822fbd82013-08-15 23:38:54 +000064 virtual ~ReceiveStatistics() {}
65
66 static ReceiveStatistics* Create(Clock* clock);
67
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000068 // Updates the receive statistics with this packet.
wu@webrtc.org822fbd82013-08-15 23:38:54 +000069 virtual void IncomingPacket(const RTPHeader& rtp_header, size_t bytes,
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000070 bool retransmitted) = 0;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000071
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000072 // Returns a map of all statisticians which have seen an incoming packet
73 // during the last two seconds.
74 virtual StatisticianMap GetActiveStatisticians() const = 0;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000075
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000076 // Returns a pointer to the statistician of an ssrc.
77 virtual StreamStatistician* GetStatistician(uint32_t ssrc) const = 0;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000078
79 // Sets the max reordering threshold in number of packets.
80 virtual void SetMaxReorderingThreshold(int max_reordering_threshold) = 0;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000081};
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000082
83class NullReceiveStatistics : public ReceiveStatistics {
84 public:
85 virtual void IncomingPacket(const RTPHeader& rtp_header, size_t bytes,
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000086 bool retransmitted) OVERRIDE;
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000087 virtual StatisticianMap GetActiveStatisticians() const OVERRIDE;
88 virtual StreamStatistician* GetStatistician(uint32_t ssrc) const OVERRIDE;
89 virtual int32_t TimeUntilNextProcess() OVERRIDE;
90 virtual int32_t Process() OVERRIDE;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000091 virtual void SetMaxReorderingThreshold(int max_reordering_threshold) OVERRIDE;
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000092};
93
wu@webrtc.org822fbd82013-08-15 23:38:54 +000094} // namespace webrtc
95#endif // WEBRTC_MODULES_RTP_RTCP_INTERFACE_RECEIVE_STATISTICS_H_