blob: f459003bca72d2a5a9dc1f588ac1f30353800b9a [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_receiver_help.h"
24#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.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
danilchapda161d72016-08-19 07:29:46 -070079 // get rtt
80 int32_t RTT(uint32_t remoteSSRC,
81 int64_t* RTT,
82 int64_t* avgRTT,
83 int64_t* minRTT,
84 int64_t* maxRTT) 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
danilchap853ecb22016-08-22 08:26:15 -0700104 std::vector<rtcp::TmmbItem> TmmbrReceived() const;
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;
danilchapdd128922016-09-13 12:23:29 -0700117 using ReceivedInfoMap = std::map<uint32_t, RTCPHelp::RTCPReceiveInformation*>;
118 // RTCP report block information mapped by remote SSRC.
119 using ReportBlockInfoMap =
120 std::map<uint32_t, RTCPHelp::RTCPReportBlockInformation*>;
121 // RTCP report block information map mapped by source SSRC.
122 using ReportBlockMap = std::map<uint32_t, ReportBlockInfoMap>;
123
danilchap1b1863a2016-09-20 01:39:54 -0700124 bool ParseCompoundPacket(const uint8_t* packet_begin,
125 const uint8_t* packet_end,
danilchap92ea6012016-09-23 10:36:03 -0700126 PacketInformation* packet_information);
danilchapdd128922016-09-13 12:23:29 -0700127
128 void TriggerCallbacksFromRTCPPacket(
danilchap92ea6012016-09-23 10:36:03 -0700129 const PacketInformation& packet_information);
danilchapdd128922016-09-13 12:23:29 -0700130
danilchapda161d72016-08-19 07:29:46 -0700131 RTCPHelp::RTCPReceiveInformation* CreateReceiveInformation(
132 uint32_t remoteSSRC);
133 RTCPHelp::RTCPReceiveInformation* GetReceiveInformation(uint32_t remoteSSRC);
niklase@google.com470e71d2011-07-07 08:21:25 +0000134
danilchap92ea6012016-09-23 10:36:03 -0700135 void HandleSenderReport(const rtcp::CommonHeader& rtcp_block,
136 PacketInformation* packet_information)
Danil Chapovalov91511f12016-09-15 16:24:02 +0200137 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
138
danilchap92ea6012016-09-23 10:36:03 -0700139 void HandleReceiverReport(const rtcp::CommonHeader& rtcp_block,
140 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700141 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000142
danilchap1b1863a2016-09-20 01:39:54 -0700143 void HandleReportBlock(const rtcp::ReportBlock& report_block,
danilchap92ea6012016-09-23 10:36:03 -0700144 PacketInformation* packet_information,
danilchapda161d72016-08-19 07:29:46 -0700145 uint32_t remoteSSRC)
146 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000147
danilchap1b1863a2016-09-20 01:39:54 -0700148 void HandleSDES(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700149 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700150 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000151
danilchap1b1863a2016-09-20 01:39:54 -0700152 void HandleXr(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700153 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700154 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000155
danilchap92ea6012016-09-23 10:36:03 -0700156 void HandleXrReceiveReferenceTime(uint32_t sender_ssrc,
157 const rtcp::Rrtr& rrtr)
danilchapda161d72016-08-19 07:29:46 -0700158 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000159
danilchap92ea6012016-09-23 10:36:03 -0700160 void HandleXrDlrrReportBlock(const rtcp::ReceiveTimeInfo& rti)
danilchapda161d72016-08-19 07:29:46 -0700161 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
162
danilchap1b1863a2016-09-20 01:39:54 -0700163 void HandleNACK(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700164 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700165 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
166
danilchap1b1863a2016-09-20 01:39:54 -0700167 void HandleBYE(const rtcp::CommonHeader& rtcp_block)
danilchapda161d72016-08-19 07:29:46 -0700168 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
169
danilchap1b1863a2016-09-20 01:39:54 -0700170 void HandlePLI(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700171 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700172 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
173
danilchap1b1863a2016-09-20 01:39:54 -0700174 void HandleSLI(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700175 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700176 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
177
danilchap1b1863a2016-09-20 01:39:54 -0700178 void HandleRPSI(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700179 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700180 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
181
danilchap1b1863a2016-09-20 01:39:54 -0700182 void HandlePsfbApp(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700183 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700184 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
185
danilchap1b1863a2016-09-20 01:39:54 -0700186 void HandleTMMBR(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700187 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700188 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000189
danilchap1b1863a2016-09-20 01:39:54 -0700190 void HandleTMMBN(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700191 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700192 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000193
danilchap1b1863a2016-09-20 01:39:54 -0700194 void HandleSR_REQ(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700195 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700196 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000197
danilchap1b1863a2016-09-20 01:39:54 -0700198 void HandleFIR(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700199 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700200 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
201
danilchap92ea6012016-09-23 10:36:03 -0700202 void HandleTransportFeedback(const rtcp::CommonHeader& rtcp_block,
203 PacketInformation* packet_information)
danilchapda161d72016-08-19 07:29:46 -0700204 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
Erik Språng6b8d3552015-09-24 15:06:57 +0200205
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000206 RTCPHelp::RTCPReportBlockInformation* CreateOrGetReportBlockInformation(
danilchapda161d72016-08-19 07:29:46 -0700207 uint32_t remote_ssrc,
208 uint32_t source_ssrc)
209 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000210 RTCPHelp::RTCPReportBlockInformation* GetReportBlockInformation(
danilchapda161d72016-08-19 07:29:46 -0700211 uint32_t remote_ssrc,
212 uint32_t source_ssrc) const
213 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000214
Peter Boströmfe7a80c2015-04-23 17:53:17 +0200215 Clock* const _clock;
216 const bool receiver_only_;
danilchap59cb2bd2016-08-29 11:08:47 -0700217 ModuleRtpRtcp& _rtpRtcp;
niklase@google.com470e71d2011-07-07 08:21:25 +0000218
danilchap7c9426c2016-04-14 03:05:31 -0700219 rtc::CriticalSection _criticalSectionFeedbacks;
mflodman@webrtc.org96abda02015-02-25 13:50:10 +0000220 RtcpBandwidthObserver* const _cbRtcpBandwidthObserver;
221 RtcpIntraFrameObserver* const _cbRtcpIntraFrameObserver;
Erik Språng6b8d3552015-09-24 15:06:57 +0200222 TransportFeedbackObserver* const _cbTransportFeedbackObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +0000223
danilchap7c9426c2016-04-14 03:05:31 -0700224 rtc::CriticalSection _criticalSectionRTCPReceiver;
sprang7dc39f32015-10-13 09:17:48 -0700225 uint32_t main_ssrc_ GUARDED_BY(_criticalSectionRTCPReceiver);
226 uint32_t _remoteSSRC GUARDED_BY(_criticalSectionRTCPReceiver);
227 std::set<uint32_t> registered_ssrcs_ GUARDED_BY(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000228
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000229 // Received send report
230 RTCPSenderInfo _remoteSenderInfo;
231 // when did we receive the last send report
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000232 uint32_t _lastReceivedSRNTPsecs;
233 uint32_t _lastReceivedSRNTPfrac;
niklase@google.com470e71d2011-07-07 08:21:25 +0000234
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000235 // Received XR receive time report.
danilchap798896a2016-09-28 02:54:25 -0700236 rtcp::ReceiveTimeInfo remote_time_info_;
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000237 // Time when the report was received.
238 uint32_t _lastReceivedXRNTPsecs;
239 uint32_t _lastReceivedXRNTPfrac;
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +0000240 // Estimated rtt, zero when there is no valid estimate.
Danil Chapovalovc1e55c72016-03-09 15:14:35 +0100241 bool xr_rrtr_status_ GUARDED_BY(_criticalSectionRTCPReceiver);
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000242 int64_t xr_rr_rtt_ms_;
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000243
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000244 // Received report blocks.
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000245 ReportBlockMap _receivedReportBlockMap
246 GUARDED_BY(_criticalSectionRTCPReceiver);
stefan@webrtc.orgb5865072013-02-01 14:33:42 +0000247 ReceivedInfoMap _receivedInfoMap;
danilchap95321242016-09-27 07:05:32 -0700248 std::map<uint32_t, std::string> received_cnames_
249 GUARDED_BY(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000250
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +0000251 // The last time we received an RTCP RR.
252 int64_t _lastReceivedRrMs;
253
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000254 // The time we last received an RTCP RR telling we have successfully
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +0000255 // delivered RTP packet to the remote side.
256 int64_t _lastIncreasedSequenceNumberMs;
stefan@webrtc.org8ca8a712013-04-23 16:48:32 +0000257
pbos@webrtc.orga28a91d2015-02-17 14:45:08 +0000258 RtcpStatisticsCallback* stats_callback_ GUARDED_BY(_criticalSectionFeedbacks);
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000259
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000260 RtcpPacketTypeCounterObserver* const packet_type_counter_observer_;
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000261 RtcpPacketTypeCounter packet_type_counter_;
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000262
263 RTCPUtility::NackStats nack_stats_;
Erik Språng6b8d3552015-09-24 15:06:57 +0200264
265 size_t num_skipped_packets_;
266 int64_t last_skipped_packets_warning_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000267};
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000268} // namespace webrtc
danilchapda161d72016-08-19 07:29:46 -0700269#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_H_