blob: e34656c8dddbaf53ba7aef2f24596090930ac38d [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>
danilchapb8b6fbb2015-12-10 05:05:27 -080016#include <vector>
perkj@webrtc.orgce5990c2012-01-11 13:00:08 +000017
danilchap7c9426c2016-04-14 03:05:31 -070018#include "webrtc/base/criticalsection.h"
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +000019#include "webrtc/base/thread_annotations.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010020#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
pbos@webrtc.orga048d7c2013-05-29 14:27:38 +000021#include "webrtc/modules/rtp_rtcp/source/rtcp_receiver_help.h"
22#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
pbos@webrtc.orga048d7c2013-05-29 14:27:38 +000023#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000024
25namespace webrtc {
danilchap59cb2bd2016-08-29 11:08:47 -070026namespace rtcp {
27class TmmbItem;
28} // namespace rtcp
pwestin@webrtc.org741da942011-09-20 13:52:04 +000029
danilchapda161d72016-08-19 07:29:46 -070030class RTCPReceiver {
31 public:
danilchap59cb2bd2016-08-29 11:08:47 -070032 class ModuleRtpRtcp {
33 public:
34 virtual void SetTmmbn(std::vector<rtcp::TmmbItem> bounding_set) = 0;
35 virtual void OnRequestSendReport() = 0;
36 virtual void OnReceivedNack(
37 const std::vector<uint16_t>& nack_sequence_numbers) = 0;
38 virtual void OnReceivedRtcpReportBlocks(
39 const ReportBlockList& report_blocks) = 0;
40
41 protected:
42 virtual ~ModuleRtpRtcp() = default;
43 };
44
danilchapda161d72016-08-19 07:29:46 -070045 RTCPReceiver(Clock* clock,
46 bool receiver_only,
47 RtcpPacketTypeCounterObserver* packet_type_counter_observer,
48 RtcpBandwidthObserver* rtcp_bandwidth_observer,
49 RtcpIntraFrameObserver* rtcp_intra_frame_observer,
50 TransportFeedbackObserver* transport_feedback_observer,
danilchap59cb2bd2016-08-29 11:08:47 -070051 ModuleRtpRtcp* owner);
danilchapda161d72016-08-19 07:29:46 -070052 virtual ~RTCPReceiver();
niklase@google.com470e71d2011-07-07 08:21:25 +000053
danilchap59cb2bd2016-08-29 11:08:47 -070054 bool IncomingPacket(const uint8_t* packet, size_t packet_size);
55
danilchapda161d72016-08-19 07:29:46 -070056 int64_t LastReceived();
57 int64_t LastReceivedReceiverReport() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000058
danilchapda161d72016-08-19 07:29:46 -070059 void SetSsrcs(uint32_t main_ssrc, const std::set<uint32_t>& registered_ssrcs);
60 void SetRemoteSSRC(uint32_t ssrc);
61 uint32_t RemoteSSRC() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000062
danilchapda161d72016-08-19 07:29:46 -070063 // get received cname
64 int32_t CNAME(uint32_t remoteSSRC, char cName[RTCP_CNAME_SIZE]) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000065
danilchapda161d72016-08-19 07:29:46 -070066 // get received NTP
67 bool NTP(uint32_t* ReceivedNTPsecs,
68 uint32_t* ReceivedNTPfrac,
69 uint32_t* RTCPArrivalTimeSecs,
70 uint32_t* RTCPArrivalTimeFrac,
71 uint32_t* rtcp_timestamp) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000072
danilchapda161d72016-08-19 07:29:46 -070073 bool LastReceivedXrReferenceTimeInfo(RtcpReceiveTimeInfo* info) const;
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +000074
danilchapda161d72016-08-19 07:29:46 -070075 // get rtt
76 int32_t RTT(uint32_t remoteSSRC,
77 int64_t* RTT,
78 int64_t* avgRTT,
79 int64_t* minRTT,
80 int64_t* maxRTT) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000081
danilchapda161d72016-08-19 07:29:46 -070082 int32_t SenderInfoReceived(RTCPSenderInfo* senderInfo) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000083
danilchapda161d72016-08-19 07:29:46 -070084 void SetRtcpXrRrtrStatus(bool enable);
85 bool GetAndResetXrRrRtt(int64_t* rtt_ms);
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +000086
danilchapda161d72016-08-19 07:29:46 -070087 // get statistics
88 int32_t StatisticsReceived(std::vector<RTCPReportBlock>* receiveBlocks) const;
perkj@webrtc.orgce5990c2012-01-11 13:00:08 +000089
danilchapda161d72016-08-19 07:29:46 -070090 // Returns true if we haven't received an RTCP RR for several RTCP
91 // intervals, but only triggers true once.
92 bool RtcpRrTimeout(int64_t rtcp_interval_ms);
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +000093
danilchapda161d72016-08-19 07:29:46 -070094 // Returns true if we haven't received an RTCP RR telling the receive side
95 // has not received RTP packets for too long, i.e. extended highest sequence
96 // number hasn't increased for several RTCP intervals. The function only
97 // returns true once until a new RR is received.
98 bool RtcpRrSequenceNumberTimeout(int64_t rtcp_interval_ms);
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +000099
danilchap853ecb22016-08-22 08:26:15 -0700100 std::vector<rtcp::TmmbItem> TmmbrReceived() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000101
danilchapda161d72016-08-19 07:29:46 -0700102 bool UpdateRTCPReceiveInformationTimers();
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
danilchapda161d72016-08-19 07:29:46 -0700104 std::vector<rtcp::TmmbItem> BoundingSet(bool* tmmbr_owner);
niklase@google.com470e71d2011-07-07 08:21:25 +0000105
danilchap853ecb22016-08-22 08:26:15 -0700106 void UpdateTmmbr();
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
danilchapda161d72016-08-19 07:29:46 -0700108 void RegisterRtcpStatisticsCallback(RtcpStatisticsCallback* callback);
109 RtcpStatisticsCallback* GetRtcpStatisticsCallback();
sprang@webrtc.orga6ad6e52013-12-05 09:48:44 +0000110
danilchapdd128922016-09-13 12:23:29 -0700111 private:
112 using ReceivedInfoMap = std::map<uint32_t, RTCPHelp::RTCPReceiveInformation*>;
113 // RTCP report block information mapped by remote SSRC.
114 using ReportBlockInfoMap =
115 std::map<uint32_t, RTCPHelp::RTCPReportBlockInformation*>;
116 // RTCP report block information map mapped by source SSRC.
117 using ReportBlockMap = std::map<uint32_t, ReportBlockInfoMap>;
118
119 int32_t IncomingRTCPPacket(
120 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation,
121 RTCPUtility::RTCPParserV2* rtcpParser);
122
123 void TriggerCallbacksFromRTCPPacket(
124 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
125
danilchapda161d72016-08-19 07:29:46 -0700126 RTCPUtility::RTCPCnameInformation* CreateCnameInformation(
127 uint32_t remoteSSRC);
128 RTCPUtility::RTCPCnameInformation* GetCnameInformation(
129 uint32_t remoteSSRC) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000130
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
Danil Chapovalov91511f12016-09-15 16:24:02 +0200135 void HandleSenderReport(
136 RTCPUtility::RTCPParserV2& rtcpParser,
137 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation)
138 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
139
140 void HandleReceiverReport(
danilchapda161d72016-08-19 07:29:46 -0700141 RTCPUtility::RTCPParserV2& rtcpParser,
142 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation)
143 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000144
danilchapda161d72016-08-19 07:29:46 -0700145 void HandleReportBlock(const RTCPUtility::RTCPPacket& rtcpPacket,
niklase@google.com470e71d2011-07-07 08:21:25 +0000146 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation,
danilchapda161d72016-08-19 07:29:46 -0700147 uint32_t remoteSSRC)
148 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000149
danilchapda161d72016-08-19 07:29:46 -0700150 void HandleSDES(RTCPUtility::RTCPParserV2& rtcpParser,
151 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation)
152 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000153
danilchapda161d72016-08-19 07:29:46 -0700154 void HandleXrHeader(RTCPUtility::RTCPParserV2& parser,
sprang7dc39f32015-10-13 09:17:48 -0700155 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation)
danilchapda161d72016-08-19 07:29:46 -0700156 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000157
danilchapda161d72016-08-19 07:29:46 -0700158 void HandleXrReceiveReferenceTime(
159 RTCPUtility::RTCPParserV2& parser,
160 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation)
161 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000162
danilchapda161d72016-08-19 07:29:46 -0700163 void HandleXrDlrrReportBlock(
164 RTCPUtility::RTCPParserV2& parser,
165 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation)
166 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
167
danilchapda161d72016-08-19 07:29:46 -0700168 void HandleNACK(RTCPUtility::RTCPParserV2& rtcpParser,
169 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation)
170 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
171
danilchapda161d72016-08-19 07:29:46 -0700172 void HandleBYE(RTCPUtility::RTCPParserV2& rtcpParser)
173 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
174
175 void HandlePLI(RTCPUtility::RTCPParserV2& rtcpParser,
176 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation)
177 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
178
179 void HandleSLI(RTCPUtility::RTCPParserV2& rtcpParser,
180 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation)
181 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
182
danilchapda161d72016-08-19 07:29:46 -0700183 void HandleRPSI(RTCPUtility::RTCPParserV2& rtcpParser,
184 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation)
185 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
186
187 void HandlePsfbApp(RTCPUtility::RTCPParserV2& rtcpParser,
188 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation)
189 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
190
danilchapda161d72016-08-19 07:29:46 -0700191 void HandleTMMBR(RTCPUtility::RTCPParserV2& rtcpParser,
sprang7dc39f32015-10-13 09:17:48 -0700192 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation)
danilchapda161d72016-08-19 07:29:46 -0700193 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000194
danilchapda161d72016-08-19 07:29:46 -0700195 void HandleTMMBN(RTCPUtility::RTCPParserV2& rtcpParser,
sprang7dc39f32015-10-13 09:17:48 -0700196 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation)
danilchapda161d72016-08-19 07:29:46 -0700197 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000198
danilchapda161d72016-08-19 07:29:46 -0700199 void HandleSR_REQ(RTCPUtility::RTCPParserV2& rtcpParser,
200 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation)
201 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000202
danilchapda161d72016-08-19 07:29:46 -0700203 void HandleFIR(RTCPUtility::RTCPParserV2& rtcpParser,
204 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation)
205 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
206
danilchapda161d72016-08-19 07:29:46 -0700207 void HandleTransportFeedback(
208 RTCPUtility::RTCPParserV2* rtcp_parser,
209 RTCPHelp::RTCPPacketInformation* rtcp_packet_information)
210 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
Erik Språng6b8d3552015-09-24 15:06:57 +0200211
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000212 RTCPHelp::RTCPReportBlockInformation* CreateOrGetReportBlockInformation(
danilchapda161d72016-08-19 07:29:46 -0700213 uint32_t remote_ssrc,
214 uint32_t source_ssrc)
215 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000216 RTCPHelp::RTCPReportBlockInformation* GetReportBlockInformation(
danilchapda161d72016-08-19 07:29:46 -0700217 uint32_t remote_ssrc,
218 uint32_t source_ssrc) const
219 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000220
Peter Boströmfe7a80c2015-04-23 17:53:17 +0200221 Clock* const _clock;
222 const bool receiver_only_;
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000223 int64_t _lastReceived;
danilchap59cb2bd2016-08-29 11:08:47 -0700224 ModuleRtpRtcp& _rtpRtcp;
niklase@google.com470e71d2011-07-07 08:21:25 +0000225
danilchap7c9426c2016-04-14 03:05:31 -0700226 rtc::CriticalSection _criticalSectionFeedbacks;
mflodman@webrtc.org96abda02015-02-25 13:50:10 +0000227 RtcpBandwidthObserver* const _cbRtcpBandwidthObserver;
228 RtcpIntraFrameObserver* const _cbRtcpIntraFrameObserver;
Erik Språng6b8d3552015-09-24 15:06:57 +0200229 TransportFeedbackObserver* const _cbTransportFeedbackObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +0000230
danilchap7c9426c2016-04-14 03:05:31 -0700231 rtc::CriticalSection _criticalSectionRTCPReceiver;
sprang7dc39f32015-10-13 09:17:48 -0700232 uint32_t main_ssrc_ GUARDED_BY(_criticalSectionRTCPReceiver);
233 uint32_t _remoteSSRC GUARDED_BY(_criticalSectionRTCPReceiver);
234 std::set<uint32_t> registered_ssrcs_ GUARDED_BY(_criticalSectionRTCPReceiver);
niklase@google.com470e71d2011-07-07 08:21:25 +0000235
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000236 // Received send report
237 RTCPSenderInfo _remoteSenderInfo;
238 // when did we receive the last send report
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000239 uint32_t _lastReceivedSRNTPsecs;
240 uint32_t _lastReceivedSRNTPfrac;
niklase@google.com470e71d2011-07-07 08:21:25 +0000241
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000242 // Received XR receive time report.
243 RtcpReceiveTimeInfo _remoteXRReceiveTimeInfo;
244 // Time when the report was received.
245 uint32_t _lastReceivedXRNTPsecs;
246 uint32_t _lastReceivedXRNTPfrac;
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +0000247 // Estimated rtt, zero when there is no valid estimate.
Danil Chapovalovc1e55c72016-03-09 15:14:35 +0100248 bool xr_rrtr_status_ GUARDED_BY(_criticalSectionRTCPReceiver);
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000249 int64_t xr_rr_rtt_ms_;
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000250
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000251 // Received report blocks.
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000252 ReportBlockMap _receivedReportBlockMap
253 GUARDED_BY(_criticalSectionRTCPReceiver);
stefan@webrtc.orgb5865072013-02-01 14:33:42 +0000254 ReceivedInfoMap _receivedInfoMap;
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000255 std::map<uint32_t, RTCPUtility::RTCPCnameInformation*> _receivedCnameMap;
niklase@google.com470e71d2011-07-07 08:21:25 +0000256
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +0000257 // The last time we received an RTCP RR.
258 int64_t _lastReceivedRrMs;
259
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000260 // The time we last received an RTCP RR telling we have successfully
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +0000261 // delivered RTP packet to the remote side.
262 int64_t _lastIncreasedSequenceNumberMs;
stefan@webrtc.org8ca8a712013-04-23 16:48:32 +0000263
pbos@webrtc.orga28a91d2015-02-17 14:45:08 +0000264 RtcpStatisticsCallback* stats_callback_ GUARDED_BY(_criticalSectionFeedbacks);
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000265
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000266 RtcpPacketTypeCounterObserver* const packet_type_counter_observer_;
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000267 RtcpPacketTypeCounter packet_type_counter_;
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000268
269 RTCPUtility::NackStats nack_stats_;
Erik Språng6b8d3552015-09-24 15:06:57 +0200270
271 size_t num_skipped_packets_;
272 int64_t last_skipped_packets_warning_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000273};
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000274} // namespace webrtc
danilchapda161d72016-08-19 07:29:46 -0700275#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_H_