blob: 6bb771b066caf748d043f1e31ba0c5d0c0c0f80b [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
pwestin@webrtc.orgf6bb77a2012-01-24 17:16:59 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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_RTCP_RECEIVER_H_
12#define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_H_
13
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +000014#include <map>
stefan@webrtc.org28a331e2013-09-17 07:49:56 +000015#include <set>
danilchap95321242016-09-27 07:05:32 -070016#include <string>
danilchapb8b6fbb2015-12-10 05:05:27 -080017#include <vector>
perkj@webrtc.orgce5990c2012-01-11 13:00:08 +000018
danilchap7c9426c2016-04-14 03:05:31 -070019#include "webrtc/base/criticalsection.h"
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +000020#include "webrtc/base/thread_annotations.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010021#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
danilchap798896a2016-09-28 02:54:25 -070022#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/dlrr.h"
pbos@webrtc.orga048d7c2013-05-29 14:27:38 +000023#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
danilchap0b4b7272016-10-06 09:24:45 -070024#include "webrtc/system_wrappers/include/ntp_time.h"
pbos@webrtc.orga048d7c2013-05-29 14:27:38 +000025#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000026
27namespace webrtc {
danilchap59cb2bd2016-08-29 11:08:47 -070028namespace rtcp {
danilchap1b1863a2016-09-20 01:39:54 -070029class CommonHeader;
danilchap1b1863a2016-09-20 01:39:54 -070030class ReportBlock;
31class Rrtr;
danilchap59cb2bd2016-08-29 11:08:47 -070032class TmmbItem;
33} // namespace rtcp
pwestin@webrtc.org741da942011-09-20 13:52:04 +000034
danilchapda161d72016-08-19 07:29:46 -070035class RTCPReceiver {
36 public:
danilchap59cb2bd2016-08-29 11:08:47 -070037 class ModuleRtpRtcp {
38 public:
39 virtual void SetTmmbn(std::vector<rtcp::TmmbItem> bounding_set) = 0;
40 virtual void OnRequestSendReport() = 0;
41 virtual void OnReceivedNack(
42 const std::vector<uint16_t>& nack_sequence_numbers) = 0;
43 virtual void OnReceivedRtcpReportBlocks(
44 const ReportBlockList& report_blocks) = 0;
45
46 protected:
47 virtual ~ModuleRtpRtcp() = default;
48 };
49
danilchapda161d72016-08-19 07:29:46 -070050 RTCPReceiver(Clock* clock,
51 bool receiver_only,
52 RtcpPacketTypeCounterObserver* packet_type_counter_observer,
53 RtcpBandwidthObserver* rtcp_bandwidth_observer,
54 RtcpIntraFrameObserver* rtcp_intra_frame_observer,
55 TransportFeedbackObserver* transport_feedback_observer,
danilchap59cb2bd2016-08-29 11:08:47 -070056 ModuleRtpRtcp* owner);
danilchapda161d72016-08-19 07:29:46 -070057 virtual ~RTCPReceiver();
niklase@google.com470e71d2011-07-07 08:21:25 +000058
danilchap59cb2bd2016-08-29 11:08:47 -070059 bool IncomingPacket(const uint8_t* packet, size_t packet_size);
60
danilchapda161d72016-08-19 07:29:46 -070061 int64_t LastReceivedReceiverReport() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000062
danilchapda161d72016-08-19 07:29:46 -070063 void SetSsrcs(uint32_t main_ssrc, const std::set<uint32_t>& registered_ssrcs);
64 void SetRemoteSSRC(uint32_t ssrc);
65 uint32_t RemoteSSRC() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000066
danilchapda161d72016-08-19 07:29:46 -070067 // get received cname
68 int32_t CNAME(uint32_t remoteSSRC, char cName[RTCP_CNAME_SIZE]) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000069
danilchapda161d72016-08-19 07:29:46 -070070 // get received NTP
71 bool NTP(uint32_t* ReceivedNTPsecs,
72 uint32_t* ReceivedNTPfrac,
73 uint32_t* RTCPArrivalTimeSecs,
74 uint32_t* RTCPArrivalTimeFrac,
75 uint32_t* rtcp_timestamp) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000076
danilchap798896a2016-09-28 02:54:25 -070077 bool LastReceivedXrReferenceTimeInfo(rtcp::ReceiveTimeInfo* info) const;
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +000078
danilchap28b03eb2016-10-05 06:59:44 -070079 // Get rtt.
80 int32_t RTT(uint32_t remote_ssrc,
81 int64_t* last_rtt_ms,
82 int64_t* avg_rtt_ms,
83 int64_t* min_rtt_ms,
84 int64_t* max_rtt_ms) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000085
danilchapda161d72016-08-19 07:29:46 -070086 int32_t SenderInfoReceived(RTCPSenderInfo* senderInfo) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000087
danilchapda161d72016-08-19 07:29:46 -070088 void SetRtcpXrRrtrStatus(bool enable);
89 bool GetAndResetXrRrRtt(int64_t* rtt_ms);
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +000090
danilchapda161d72016-08-19 07:29:46 -070091 // get statistics
92 int32_t StatisticsReceived(std::vector<RTCPReportBlock>* receiveBlocks) const;
perkj@webrtc.orgce5990c2012-01-11 13:00:08 +000093
danilchapda161d72016-08-19 07:29:46 -070094 // Returns true if we haven't received an RTCP RR for several RTCP
95 // intervals, but only triggers true once.
96 bool RtcpRrTimeout(int64_t rtcp_interval_ms);
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +000097
danilchapda161d72016-08-19 07:29:46 -070098 // Returns true if we haven't received an RTCP RR telling the receive side
99 // has not received RTP packets for too long, i.e. extended highest sequence
100 // number hasn't increased for several RTCP intervals. The function only
101 // returns true once until a new RR is received.
102 bool RtcpRrSequenceNumberTimeout(int64_t rtcp_interval_ms);
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +0000103
danilchap7851bda2016-09-29 15:28:07 -0700104 std::vector<rtcp::TmmbItem> TmmbrReceived();
niklase@google.com470e71d2011-07-07 08:21:25 +0000105
danilchapda161d72016-08-19 07:29:46 -0700106 bool UpdateRTCPReceiveInformationTimers();
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
danilchapda161d72016-08-19 07:29:46 -0700108 std::vector<rtcp::TmmbItem> BoundingSet(bool* tmmbr_owner);
niklase@google.com470e71d2011-07-07 08:21:25 +0000109
danilchap853ecb22016-08-22 08:26:15 -0700110 void UpdateTmmbr();
niklase@google.com470e71d2011-07-07 08:21:25 +0000111
danilchapda161d72016-08-19 07:29:46 -0700112 void RegisterRtcpStatisticsCallback(RtcpStatisticsCallback* callback);
113 RtcpStatisticsCallback* GetRtcpStatisticsCallback();
sprang@webrtc.orga6ad6e52013-12-05 09:48:44 +0000114
danilchapdd128922016-09-13 12:23:29 -0700115 private:
danilchap92ea6012016-09-23 10:36:03 -0700116 struct PacketInformation;
danilchap7851bda2016-09-29 15:28:07 -0700117 struct ReceiveInformation;
danilchap28b03eb2016-10-05 06:59:44 -0700118 struct ReportBlockWithRtt;
danilchap7851bda2016-09-29 15:28:07 -0700119 // Mapped by remote ssrc.
120 using ReceivedInfoMap = std::map<uint32_t, ReceiveInformation>;
danilchap28b03eb2016-10-05 06:59:44 -0700121 // RTCP report blocks mapped by remote SSRC.
122 using ReportBlockInfoMap = std::map<uint32_t, ReportBlockWithRtt>;
123 // RTCP report blocks map mapped by source SSRC.
danilchapdd128922016-09-13 12:23:29 -0700124 using ReportBlockMap = std::map<uint32_t, ReportBlockInfoMap>;
125
danilchap1b1863a2016-09-20 01:39:54 -0700126 bool ParseCompoundPacket(const uint8_t* packet_begin,
127 const uint8_t* packet_end,
danilchap92ea6012016-09-23 10:36:03 -0700128 PacketInformation* packet_information);
danilchapdd128922016-09-13 12:23:29 -0700129
130 void TriggerCallbacksFromRTCPPacket(
danilchap92ea6012016-09-23 10:36:03 -0700131 const PacketInformation& packet_information);
danilchapdd128922016-09-13 12:23:29 -0700132
danilchap7851bda2016-09-29 15:28:07 -0700133 void CreateReceiveInformation(uint32_t remote_ssrc)
134 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
135 ReceiveInformation* GetReceiveInformation(uint32_t remote_ssrc)
136 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000137
danilchap92ea6012016-09-23 10:36:03 -0700138 void HandleSenderReport(const rtcp::CommonHeader& rtcp_block,
139 PacketInformation* packet_information)
Danil Chapovalov91511f12016-09-15 16:24:02 +0200140 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
141
danilchap92ea6012016-09-23 10:36:03 -0700142 void HandleReceiverReport(const rtcp::CommonHeader& rtcp_block,
143 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700144 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000145
danilchap1b1863a2016-09-20 01:39:54 -0700146 void HandleReportBlock(const rtcp::ReportBlock& report_block,
danilchap92ea6012016-09-23 10:36:03 -0700147 PacketInformation* packet_information,
danilchapda161d72016-08-19 07:29:46 -0700148 uint32_t remoteSSRC)
149 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000150
danilchap1b1863a2016-09-20 01:39:54 -0700151 void HandleSDES(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700152 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700153 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000154
danilchap1b1863a2016-09-20 01:39:54 -0700155 void HandleXr(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700156 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700157 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000158
danilchap92ea6012016-09-23 10:36:03 -0700159 void HandleXrReceiveReferenceTime(uint32_t sender_ssrc,
160 const rtcp::Rrtr& rrtr)
danilchapda161d72016-08-19 07:29:46 -0700161 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000162
danilchap92ea6012016-09-23 10:36:03 -0700163 void HandleXrDlrrReportBlock(const rtcp::ReceiveTimeInfo& rti)
danilchapda161d72016-08-19 07:29:46 -0700164 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
165
danilchap1b1863a2016-09-20 01:39:54 -0700166 void HandleNACK(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700167 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700168 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
169
danilchap1b1863a2016-09-20 01:39:54 -0700170 void HandleBYE(const rtcp::CommonHeader& rtcp_block)
danilchapda161d72016-08-19 07:29:46 -0700171 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
172
danilchap1b1863a2016-09-20 01:39:54 -0700173 void HandlePLI(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700174 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700175 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
176
danilchap1b1863a2016-09-20 01:39:54 -0700177 void HandleSLI(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700178 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700179 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
180
danilchap1b1863a2016-09-20 01:39:54 -0700181 void HandleRPSI(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700182 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700183 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
184
danilchap1b1863a2016-09-20 01:39:54 -0700185 void HandlePsfbApp(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700186 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700187 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
188
danilchap1b1863a2016-09-20 01:39:54 -0700189 void HandleTMMBR(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700190 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700191 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000192
danilchap1b1863a2016-09-20 01:39:54 -0700193 void HandleTMMBN(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700194 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700195 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000196
danilchap1b1863a2016-09-20 01:39:54 -0700197 void HandleSR_REQ(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700198 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700199 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000200
danilchap1b1863a2016-09-20 01:39:54 -0700201 void HandleFIR(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700202 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700203 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
204
danilchap92ea6012016-09-23 10:36:03 -0700205 void HandleTransportFeedback(const rtcp::CommonHeader& rtcp_block,
206 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700207 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
Erik Språng6b8d3552015-09-24 15:06:57 +0200208
Peter Boströmfe7a80c2015-04-23 17:53:17 +0200209 Clock* const _clock;
210 const bool receiver_only_;
danilchap59cb2bd2016-08-29 11:08:47 -0700211 ModuleRtpRtcp& _rtpRtcp;
niklase@google.com470e71d2011-07-07 08:21:25 +0000212
danilchap7c9426c2016-04-14 03:05:31 -0700213 rtc::CriticalSection _criticalSectionFeedbacks;
mflodman@webrtc.org96abda02015-02-25 13:50:10 +0000214 RtcpBandwidthObserver* const _cbRtcpBandwidthObserver;
215 RtcpIntraFrameObserver* const _cbRtcpIntraFrameObserver;
Erik Språng6b8d3552015-09-24 15:06:57 +0200216 TransportFeedbackObserver* const _cbTransportFeedbackObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +0000217
danilchap7c9426c2016-04-14 03:05:31 -0700218 rtc::CriticalSection _criticalSectionRTCPReceiver;
sprang7dc39f32015-10-13 09:17:48 -0700219 uint32_t main_ssrc_ GUARDED_BY(_criticalSectionRTCPReceiver);
220 uint32_t _remoteSSRC GUARDED_BY(_criticalSectionRTCPReceiver);
221 std::set<uint32_t> registered_ssrcs_ GUARDED_BY(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000222
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000223 // Received send report
224 RTCPSenderInfo _remoteSenderInfo;
danilchap0b4b7272016-10-06 09:24:45 -0700225 // When did we receive the last send report.
226 NtpTime last_received_sr_ntp_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000227
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000228 // Received XR receive time report.
danilchap798896a2016-09-28 02:54:25 -0700229 rtcp::ReceiveTimeInfo remote_time_info_;
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000230 // Time when the report was received.
danilchap0b4b7272016-10-06 09:24:45 -0700231 NtpTime last_received_xr_ntp_;
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +0000232 // Estimated rtt, zero when there is no valid estimate.
Danil Chapovalovc1e55c72016-03-09 15:14:35 +0100233 bool xr_rrtr_status_ GUARDED_BY(_criticalSectionRTCPReceiver);
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000234 int64_t xr_rr_rtt_ms_;
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000235
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000236 // Received report blocks.
danilchap28b03eb2016-10-05 06:59:44 -0700237 ReportBlockMap received_report_blocks_
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000238 GUARDED_BY(_criticalSectionRTCPReceiver);
danilchap7851bda2016-09-29 15:28:07 -0700239 ReceivedInfoMap received_infos_ GUARDED_BY(_criticalSectionRTCPReceiver);
danilchap95321242016-09-27 07:05:32 -0700240 std::map<uint32_t, std::string> received_cnames_
241 GUARDED_BY(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000242
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +0000243 // The last time we received an RTCP RR.
244 int64_t _lastReceivedRrMs;
245
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000246 // The time we last received an RTCP RR telling we have successfully
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +0000247 // delivered RTP packet to the remote side.
248 int64_t _lastIncreasedSequenceNumberMs;
stefan@webrtc.org8ca8a712013-04-23 16:48:32 +0000249
pbos@webrtc.orga28a91d2015-02-17 14:45:08 +0000250 RtcpStatisticsCallback* stats_callback_ GUARDED_BY(_criticalSectionFeedbacks);
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000251
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000252 RtcpPacketTypeCounterObserver* const packet_type_counter_observer_;
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000253 RtcpPacketTypeCounter packet_type_counter_;
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000254
255 RTCPUtility::NackStats nack_stats_;
Erik Språng6b8d3552015-09-24 15:06:57 +0200256
257 size_t num_skipped_packets_;
258 int64_t last_skipped_packets_warning_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000259};
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000260} // namespace webrtc
danilchapda161d72016-08-19 07:29:46 -0700261#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_H_