Line data Source code
1 : /*
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_SOURCE_RECEIVE_STATISTICS_IMPL_H_
12 : #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RECEIVE_STATISTICS_IMPL_H_
13 :
14 : #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h"
15 :
16 : #include <algorithm>
17 : #include <map>
18 :
19 : #include "webrtc/base/criticalsection.h"
20 : #include "webrtc/base/rate_statistics.h"
21 : #include "webrtc/system_wrappers/include/ntp_time.h"
22 :
23 : namespace webrtc {
24 :
25 : class StreamStatisticianImpl : public StreamStatistician {
26 : public:
27 : StreamStatisticianImpl(Clock* clock,
28 : RtcpStatisticsCallback* rtcp_callback,
29 : StreamDataCountersCallback* rtp_callback);
30 0 : virtual ~StreamStatisticianImpl() {}
31 :
32 : bool GetStatistics(RtcpStatistics* statistics, bool reset) override;
33 : void GetDataCounters(size_t* bytes_received,
34 : uint32_t* packets_received) const override;
35 : void GetReceiveStreamDataCounters(
36 : StreamDataCounters* data_counters) const override;
37 : uint32_t BitrateReceived() const override;
38 : bool IsRetransmitOfOldPacket(const RTPHeader& header,
39 : int64_t min_rtt) const override;
40 : bool IsPacketInOrder(uint16_t sequence_number) const override;
41 :
42 : void IncomingPacket(const RTPHeader& rtp_header,
43 : size_t packet_length,
44 : bool retransmitted);
45 : void FecPacketReceived(const RTPHeader& header, size_t packet_length);
46 : void SetMaxReorderingThreshold(int max_reordering_threshold);
47 : virtual void LastReceiveTimeNtp(uint32_t* secs, uint32_t* frac) const;
48 :
49 : private:
50 : bool InOrderPacketInternal(uint16_t sequence_number) const;
51 : RtcpStatistics CalculateRtcpStatistics();
52 : void UpdateJitter(const RTPHeader& header, NtpTime receive_time);
53 : void UpdateCounters(const RTPHeader& rtp_header,
54 : size_t packet_length,
55 : bool retransmitted);
56 : void NotifyRtpCallback() LOCKS_EXCLUDED(stream_lock_);
57 : void NotifyRtcpCallback() LOCKS_EXCLUDED(stream_lock_);
58 :
59 : Clock* const clock_;
60 : rtc::CriticalSection stream_lock_;
61 : RateStatistics incoming_bitrate_;
62 : uint32_t ssrc_;
63 : int max_reordering_threshold_; // In number of packets or sequence numbers.
64 :
65 : // Stats on received RTP packets.
66 : uint32_t jitter_q4_;
67 : uint32_t cumulative_loss_;
68 : uint32_t jitter_q4_transmission_time_offset_;
69 :
70 : int64_t last_receive_time_ms_;
71 : NtpTime last_receive_time_ntp_;
72 : uint32_t last_received_timestamp_;
73 : int32_t last_received_transmission_time_offset_;
74 : uint16_t received_seq_first_;
75 : uint16_t received_seq_max_;
76 : uint16_t received_seq_wraps_;
77 :
78 : // Current counter values.
79 : size_t received_packet_overhead_;
80 : StreamDataCounters receive_counters_;
81 :
82 : // Counter values when we sent the last report.
83 : uint32_t last_report_inorder_packets_;
84 : uint32_t last_report_old_packets_;
85 : uint16_t last_report_seq_max_;
86 : RtcpStatistics last_reported_statistics_;
87 :
88 : RtcpStatisticsCallback* const rtcp_callback_;
89 : StreamDataCountersCallback* const rtp_callback_;
90 : };
91 :
92 : class ReceiveStatisticsImpl : public ReceiveStatistics,
93 : public RtcpStatisticsCallback,
94 : public StreamDataCountersCallback {
95 : public:
96 : explicit ReceiveStatisticsImpl(Clock* clock);
97 :
98 : ~ReceiveStatisticsImpl();
99 :
100 : // Implement ReceiveStatistics.
101 : void IncomingPacket(const RTPHeader& header,
102 : size_t packet_length,
103 : bool retransmitted) override;
104 : void FecPacketReceived(const RTPHeader& header,
105 : size_t packet_length) override;
106 : StatisticianMap GetActiveStatisticians() const override;
107 : StreamStatistician* GetStatistician(uint32_t ssrc) const override;
108 : void SetMaxReorderingThreshold(int max_reordering_threshold) override;
109 :
110 : void RegisterRtcpStatisticsCallback(
111 : RtcpStatisticsCallback* callback) override;
112 :
113 : void RegisterRtpStatisticsCallback(
114 : StreamDataCountersCallback* callback) override;
115 :
116 : private:
117 : void StatisticsUpdated(const RtcpStatistics& statistics,
118 : uint32_t ssrc) override;
119 : void CNameChanged(const char* cname, uint32_t ssrc) override;
120 : void DataCountersUpdated(const StreamDataCounters& counters,
121 : uint32_t ssrc) override;
122 :
123 : typedef std::map<uint32_t, StreamStatisticianImpl*> StatisticianImplMap;
124 :
125 : Clock* const clock_;
126 : rtc::CriticalSection receive_statistics_lock_;
127 : StatisticianImplMap statisticians_;
128 :
129 : RtcpStatisticsCallback* rtcp_stats_callback_;
130 : StreamDataCountersCallback* rtp_stats_callback_;
131 : };
132 : } // namespace webrtc
133 : #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RECEIVE_STATISTICS_IMPL_H_
|