blob: 2ea155f9f425acbcd0806346e72bebf16b619f0d [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;
47 // Resets all statistics.
48 virtual void ResetStatistics() = 0;
49};
50
51typedef std::map<uint32_t, StreamStatistician*> StatisticianMap;
52
53class ReceiveStatistics : public Module {
54 public:
wu@webrtc.org822fbd82013-08-15 23:38:54 +000055 virtual ~ReceiveStatistics() {}
56
57 static ReceiveStatistics* Create(Clock* clock);
58
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000059 // Updates the receive statistics with this packet.
wu@webrtc.org822fbd82013-08-15 23:38:54 +000060 virtual void IncomingPacket(const RTPHeader& rtp_header, size_t bytes,
61 bool retransmitted, bool in_order) = 0;
62
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000063 // Returns a map of all statisticians which have seen an incoming packet
64 // during the last two seconds.
65 virtual StatisticianMap GetActiveStatisticians() const = 0;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000066
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000067 // Returns a pointer to the statistician of an ssrc.
68 virtual StreamStatistician* GetStatistician(uint32_t ssrc) const = 0;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000069};
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +000070
71class NullReceiveStatistics : public ReceiveStatistics {
72 public:
73 virtual void IncomingPacket(const RTPHeader& rtp_header, size_t bytes,
74 bool retransmitted, bool in_order) OVERRIDE;
75 virtual StatisticianMap GetActiveStatisticians() const OVERRIDE;
76 virtual StreamStatistician* GetStatistician(uint32_t ssrc) const OVERRIDE;
77 virtual int32_t TimeUntilNextProcess() OVERRIDE;
78 virtual int32_t Process() OVERRIDE;
79};
80
wu@webrtc.org822fbd82013-08-15 23:38:54 +000081} // namespace webrtc
82#endif // WEBRTC_MODULES_RTP_RTCP_INTERFACE_RECEIVE_STATISTICS_H_