blob: 11e18be841f3e8b257ff393c72048ea24577a6e6 [file] [log] [blame]
Henrik Kjellanderff761fb2015-11-04 08:31:52 +01001/*
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_INCLUDE_RECEIVE_STATISTICS_H_
12#define WEBRTC_MODULES_RTP_RTCP_INCLUDE_RECEIVE_STATISTICS_H_
13
14#include <map>
danilchapf5f793c2017-07-27 04:44:18 -070015#include <vector>
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010016
17#include "webrtc/modules/include/module.h"
18#include "webrtc/modules/include/module_common_types.h"
danilchapf5f793c2017-07-27 04:44:18 -070019#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/report_block.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010020#include "webrtc/typedefs.h"
21
22namespace webrtc {
23
24class Clock;
25
danilchapf5f793c2017-07-27 04:44:18 -070026class ReceiveStatisticsProvider {
27 public:
28 virtual ~ReceiveStatisticsProvider() = default;
29 // Collects receive statistic in a form of rtcp report blocks.
30 // Returns at most |max_blocks| report blocks.
31 virtual std::vector<rtcp::ReportBlock> RtcpReportBlocks(
32 size_t max_blocks) = 0;
33};
34
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010035class StreamStatistician {
36 public:
37 virtual ~StreamStatistician();
38
39 virtual bool GetStatistics(RtcpStatistics* statistics, bool reset) = 0;
40 virtual void GetDataCounters(size_t* bytes_received,
41 uint32_t* packets_received) const = 0;
42
43 // Gets received stream data counters (includes reset counter values).
44 virtual void GetReceiveStreamDataCounters(
45 StreamDataCounters* data_counters) const = 0;
46
47 virtual uint32_t BitrateReceived() const = 0;
48
49 // Returns true if the packet with RTP header |header| is likely to be a
50 // retransmitted packet, false otherwise.
51 virtual bool IsRetransmitOfOldPacket(const RTPHeader& header,
52 int64_t min_rtt) const = 0;
53
54 // Returns true if |sequence_number| is received in order, false otherwise.
55 virtual bool IsPacketInOrder(uint16_t sequence_number) const = 0;
56};
57
58typedef std::map<uint32_t, StreamStatistician*> StatisticianMap;
59
danilchapf5f793c2017-07-27 04:44:18 -070060class ReceiveStatistics : public ReceiveStatisticsProvider {
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010061 public:
danilchapf5f793c2017-07-27 04:44:18 -070062 ~ReceiveStatistics() override = default;
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010063
64 static ReceiveStatistics* Create(Clock* clock);
65
66 // Updates the receive statistics with this packet.
67 virtual void IncomingPacket(const RTPHeader& rtp_header,
68 size_t packet_length,
69 bool retransmitted) = 0;
70
71 // Increment counter for number of FEC packets received.
72 virtual void FecPacketReceived(const RTPHeader& header,
73 size_t packet_length) = 0;
74
75 // Returns a map of all statisticians which have seen an incoming packet
76 // during the last two seconds.
77 virtual StatisticianMap GetActiveStatisticians() const = 0;
78
79 // Returns a pointer to the statistician of an ssrc.
80 virtual StreamStatistician* GetStatistician(uint32_t ssrc) const = 0;
81
82 // Sets the max reordering threshold in number of packets.
83 virtual void SetMaxReorderingThreshold(int max_reordering_threshold) = 0;
84
85 // Called on new RTCP stats creation.
86 virtual void RegisterRtcpStatisticsCallback(
87 RtcpStatisticsCallback* callback) = 0;
88
89 // Called on new RTP stats creation.
90 virtual void RegisterRtpStatisticsCallback(
91 StreamDataCountersCallback* callback) = 0;
92};
93
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010094} // namespace webrtc
95#endif // WEBRTC_MODULES_RTP_RTCP_INCLUDE_RECEIVE_STATISTICS_H_