blob: 28a83663fa1a8804be2311213f2b2c355efbc48c [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"
pbos@webrtc.orga048d7c2013-05-29 14:27:38 +000024#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000025
26namespace webrtc {
danilchap59cb2bd2016-08-29 11:08:47 -070027namespace rtcp {
danilchap1b1863a2016-09-20 01:39:54 -070028class CommonHeader;
danilchap1b1863a2016-09-20 01:39:54 -070029class ReportBlock;
30class Rrtr;
danilchap59cb2bd2016-08-29 11:08:47 -070031class TmmbItem;
32} // namespace rtcp
pwestin@webrtc.org741da942011-09-20 13:52:04 +000033
danilchapda161d72016-08-19 07:29:46 -070034class RTCPReceiver {
35 public:
danilchap59cb2bd2016-08-29 11:08:47 -070036 class ModuleRtpRtcp {
37 public:
38 virtual void SetTmmbn(std::vector<rtcp::TmmbItem> bounding_set) = 0;
39 virtual void OnRequestSendReport() = 0;
40 virtual void OnReceivedNack(
41 const std::vector<uint16_t>& nack_sequence_numbers) = 0;
42 virtual void OnReceivedRtcpReportBlocks(
43 const ReportBlockList& report_blocks) = 0;
44
45 protected:
46 virtual ~ModuleRtpRtcp() = default;
47 };
48
danilchapda161d72016-08-19 07:29:46 -070049 RTCPReceiver(Clock* clock,
50 bool receiver_only,
51 RtcpPacketTypeCounterObserver* packet_type_counter_observer,
52 RtcpBandwidthObserver* rtcp_bandwidth_observer,
53 RtcpIntraFrameObserver* rtcp_intra_frame_observer,
54 TransportFeedbackObserver* transport_feedback_observer,
danilchap59cb2bd2016-08-29 11:08:47 -070055 ModuleRtpRtcp* owner);
danilchapda161d72016-08-19 07:29:46 -070056 virtual ~RTCPReceiver();
niklase@google.com470e71d2011-07-07 08:21:25 +000057
danilchap59cb2bd2016-08-29 11:08:47 -070058 bool IncomingPacket(const uint8_t* packet, size_t packet_size);
59
danilchapda161d72016-08-19 07:29:46 -070060 int64_t LastReceivedReceiverReport() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000061
danilchapda161d72016-08-19 07:29:46 -070062 void SetSsrcs(uint32_t main_ssrc, const std::set<uint32_t>& registered_ssrcs);
63 void SetRemoteSSRC(uint32_t ssrc);
64 uint32_t RemoteSSRC() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000065
danilchapda161d72016-08-19 07:29:46 -070066 // get received cname
67 int32_t CNAME(uint32_t remoteSSRC, char cName[RTCP_CNAME_SIZE]) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000068
danilchapda161d72016-08-19 07:29:46 -070069 // get received NTP
70 bool NTP(uint32_t* ReceivedNTPsecs,
71 uint32_t* ReceivedNTPfrac,
72 uint32_t* RTCPArrivalTimeSecs,
73 uint32_t* RTCPArrivalTimeFrac,
74 uint32_t* rtcp_timestamp) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000075
danilchap798896a2016-09-28 02:54:25 -070076 bool LastReceivedXrReferenceTimeInfo(rtcp::ReceiveTimeInfo* info) const;
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +000077
danilchap28b03eb2016-10-05 06:59:44 -070078 // Get rtt.
79 int32_t RTT(uint32_t remote_ssrc,
80 int64_t* last_rtt_ms,
81 int64_t* avg_rtt_ms,
82 int64_t* min_rtt_ms,
83 int64_t* max_rtt_ms) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000084
danilchapda161d72016-08-19 07:29:46 -070085 int32_t SenderInfoReceived(RTCPSenderInfo* senderInfo) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000086
danilchapda161d72016-08-19 07:29:46 -070087 void SetRtcpXrRrtrStatus(bool enable);
88 bool GetAndResetXrRrRtt(int64_t* rtt_ms);
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +000089
danilchapda161d72016-08-19 07:29:46 -070090 // get statistics
91 int32_t StatisticsReceived(std::vector<RTCPReportBlock>* receiveBlocks) const;
perkj@webrtc.orgce5990c2012-01-11 13:00:08 +000092
danilchapda161d72016-08-19 07:29:46 -070093 // Returns true if we haven't received an RTCP RR for several RTCP
94 // intervals, but only triggers true once.
95 bool RtcpRrTimeout(int64_t rtcp_interval_ms);
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +000096
danilchapda161d72016-08-19 07:29:46 -070097 // Returns true if we haven't received an RTCP RR telling the receive side
98 // has not received RTP packets for too long, i.e. extended highest sequence
99 // number hasn't increased for several RTCP intervals. The function only
100 // returns true once until a new RR is received.
101 bool RtcpRrSequenceNumberTimeout(int64_t rtcp_interval_ms);
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +0000102
danilchap7851bda2016-09-29 15:28:07 -0700103 std::vector<rtcp::TmmbItem> TmmbrReceived();
niklase@google.com470e71d2011-07-07 08:21:25 +0000104
danilchapda161d72016-08-19 07:29:46 -0700105 bool UpdateRTCPReceiveInformationTimers();
niklase@google.com470e71d2011-07-07 08:21:25 +0000106
danilchapda161d72016-08-19 07:29:46 -0700107 std::vector<rtcp::TmmbItem> BoundingSet(bool* tmmbr_owner);
niklase@google.com470e71d2011-07-07 08:21:25 +0000108
danilchap853ecb22016-08-22 08:26:15 -0700109 void UpdateTmmbr();
niklase@google.com470e71d2011-07-07 08:21:25 +0000110
danilchapda161d72016-08-19 07:29:46 -0700111 void RegisterRtcpStatisticsCallback(RtcpStatisticsCallback* callback);
112 RtcpStatisticsCallback* GetRtcpStatisticsCallback();
sprang@webrtc.orga6ad6e52013-12-05 09:48:44 +0000113
danilchapdd128922016-09-13 12:23:29 -0700114 private:
danilchap92ea6012016-09-23 10:36:03 -0700115 struct PacketInformation;
danilchap7851bda2016-09-29 15:28:07 -0700116 struct ReceiveInformation;
danilchap28b03eb2016-10-05 06:59:44 -0700117 struct ReportBlockWithRtt;
danilchap7851bda2016-09-29 15:28:07 -0700118 // Mapped by remote ssrc.
119 using ReceivedInfoMap = std::map<uint32_t, ReceiveInformation>;
danilchap28b03eb2016-10-05 06:59:44 -0700120 // RTCP report blocks mapped by remote SSRC.
121 using ReportBlockInfoMap = std::map<uint32_t, ReportBlockWithRtt>;
122 // RTCP report blocks map mapped by source SSRC.
danilchapdd128922016-09-13 12:23:29 -0700123 using ReportBlockMap = std::map<uint32_t, ReportBlockInfoMap>;
124
danilchap1b1863a2016-09-20 01:39:54 -0700125 bool ParseCompoundPacket(const uint8_t* packet_begin,
126 const uint8_t* packet_end,
danilchap92ea6012016-09-23 10:36:03 -0700127 PacketInformation* packet_information);
danilchapdd128922016-09-13 12:23:29 -0700128
129 void TriggerCallbacksFromRTCPPacket(
danilchap92ea6012016-09-23 10:36:03 -0700130 const PacketInformation& packet_information);
danilchapdd128922016-09-13 12:23:29 -0700131
danilchap7851bda2016-09-29 15:28:07 -0700132 void CreateReceiveInformation(uint32_t remote_ssrc)
133 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
134 ReceiveInformation* GetReceiveInformation(uint32_t remote_ssrc)
135 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000136
danilchap92ea6012016-09-23 10:36:03 -0700137 void HandleSenderReport(const rtcp::CommonHeader& rtcp_block,
138 PacketInformation* packet_information)
Danil Chapovalov91511f12016-09-15 16:24:02 +0200139 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
140
danilchap92ea6012016-09-23 10:36:03 -0700141 void HandleReceiverReport(const rtcp::CommonHeader& rtcp_block,
142 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700143 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000144
danilchap1b1863a2016-09-20 01:39:54 -0700145 void HandleReportBlock(const rtcp::ReportBlock& report_block,
danilchap92ea6012016-09-23 10:36:03 -0700146 PacketInformation* packet_information,
danilchapda161d72016-08-19 07:29:46 -0700147 uint32_t remoteSSRC)
148 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000149
danilchap1b1863a2016-09-20 01:39:54 -0700150 void HandleSDES(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700151 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700152 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000153
danilchap1b1863a2016-09-20 01:39:54 -0700154 void HandleXr(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700155 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700156 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000157
danilchap92ea6012016-09-23 10:36:03 -0700158 void HandleXrReceiveReferenceTime(uint32_t sender_ssrc,
159 const rtcp::Rrtr& rrtr)
danilchapda161d72016-08-19 07:29:46 -0700160 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000161
danilchap92ea6012016-09-23 10:36:03 -0700162 void HandleXrDlrrReportBlock(const rtcp::ReceiveTimeInfo& rti)
danilchapda161d72016-08-19 07:29:46 -0700163 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
164
danilchap1b1863a2016-09-20 01:39:54 -0700165 void HandleNACK(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700166 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700167 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
168
danilchap1b1863a2016-09-20 01:39:54 -0700169 void HandleBYE(const rtcp::CommonHeader& rtcp_block)
danilchapda161d72016-08-19 07:29:46 -0700170 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
171
danilchap1b1863a2016-09-20 01:39:54 -0700172 void HandlePLI(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700173 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700174 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
175
danilchap1b1863a2016-09-20 01:39:54 -0700176 void HandleSLI(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700177 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700178 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
179
danilchap1b1863a2016-09-20 01:39:54 -0700180 void HandleRPSI(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700181 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700182 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
183
danilchap1b1863a2016-09-20 01:39:54 -0700184 void HandlePsfbApp(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700185 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700186 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
187
danilchap1b1863a2016-09-20 01:39:54 -0700188 void HandleTMMBR(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700189 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700190 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000191
danilchap1b1863a2016-09-20 01:39:54 -0700192 void HandleTMMBN(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700193 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700194 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000195
danilchap1b1863a2016-09-20 01:39:54 -0700196 void HandleSR_REQ(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700197 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700198 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000199
danilchap1b1863a2016-09-20 01:39:54 -0700200 void HandleFIR(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700201 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700202 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
203
danilchap92ea6012016-09-23 10:36:03 -0700204 void HandleTransportFeedback(const rtcp::CommonHeader& rtcp_block,
205 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700206 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
Erik Språng6b8d3552015-09-24 15:06:57 +0200207
Peter Boströmfe7a80c2015-04-23 17:53:17 +0200208 Clock* const _clock;
209 const bool receiver_only_;
danilchap59cb2bd2016-08-29 11:08:47 -0700210 ModuleRtpRtcp& _rtpRtcp;
niklase@google.com470e71d2011-07-07 08:21:25 +0000211
danilchap7c9426c2016-04-14 03:05:31 -0700212 rtc::CriticalSection _criticalSectionFeedbacks;
mflodman@webrtc.org96abda02015-02-25 13:50:10 +0000213 RtcpBandwidthObserver* const _cbRtcpBandwidthObserver;
214 RtcpIntraFrameObserver* const _cbRtcpIntraFrameObserver;
Erik Språng6b8d3552015-09-24 15:06:57 +0200215 TransportFeedbackObserver* const _cbTransportFeedbackObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +0000216
danilchap7c9426c2016-04-14 03:05:31 -0700217 rtc::CriticalSection _criticalSectionRTCPReceiver;
sprang7dc39f32015-10-13 09:17:48 -0700218 uint32_t main_ssrc_ GUARDED_BY(_criticalSectionRTCPReceiver);
219 uint32_t _remoteSSRC GUARDED_BY(_criticalSectionRTCPReceiver);
220 std::set<uint32_t> registered_ssrcs_ GUARDED_BY(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000221
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000222 // Received send report
223 RTCPSenderInfo _remoteSenderInfo;
224 // when did we receive the last send report
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000225 uint32_t _lastReceivedSRNTPsecs;
226 uint32_t _lastReceivedSRNTPfrac;
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.
231 uint32_t _lastReceivedXRNTPsecs;
232 uint32_t _lastReceivedXRNTPfrac;
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +0000233 // Estimated rtt, zero when there is no valid estimate.
Danil Chapovalovc1e55c72016-03-09 15:14:35 +0100234 bool xr_rrtr_status_ GUARDED_BY(_criticalSectionRTCPReceiver);
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000235 int64_t xr_rr_rtt_ms_;
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000236
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000237 // Received report blocks.
danilchap28b03eb2016-10-05 06:59:44 -0700238 ReportBlockMap received_report_blocks_
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000239 GUARDED_BY(_criticalSectionRTCPReceiver);
danilchap7851bda2016-09-29 15:28:07 -0700240 ReceivedInfoMap received_infos_ GUARDED_BY(_criticalSectionRTCPReceiver);
danilchap95321242016-09-27 07:05:32 -0700241 std::map<uint32_t, std::string> received_cnames_
242 GUARDED_BY(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000243
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +0000244 // The last time we received an RTCP RR.
245 int64_t _lastReceivedRrMs;
246
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000247 // The time we last received an RTCP RR telling we have successfully
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +0000248 // delivered RTP packet to the remote side.
249 int64_t _lastIncreasedSequenceNumberMs;
stefan@webrtc.org8ca8a712013-04-23 16:48:32 +0000250
pbos@webrtc.orga28a91d2015-02-17 14:45:08 +0000251 RtcpStatisticsCallback* stats_callback_ GUARDED_BY(_criticalSectionFeedbacks);
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000252
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000253 RtcpPacketTypeCounterObserver* const packet_type_counter_observer_;
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000254 RtcpPacketTypeCounter packet_type_counter_;
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000255
256 RTCPUtility::NackStats nack_stats_;
Erik Språng6b8d3552015-09-24 15:06:57 +0200257
258 size_t num_skipped_packets_;
259 int64_t last_skipped_packets_warning_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000260};
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000261} // namespace webrtc
danilchapda161d72016-08-19 07:29:46 -0700262#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_H_