blob: 9392e51d26be28ed9c2a700691c29a7f5afa532d [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>
perkj@webrtc.orgce5990c2012-01-11 13:00:08 +000015#include <vector>
stefan@webrtc.org28a331e2013-09-17 07:49:56 +000016#include <set>
perkj@webrtc.orgce5990c2012-01-11 13:00:08 +000017
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +000018#include "webrtc/base/thread_annotations.h"
pbos@webrtc.orga048d7c2013-05-29 14:27:38 +000019#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
20#include "webrtc/modules/rtp_rtcp/source/rtcp_receiver_help.h"
21#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
22#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
23#include "webrtc/modules/rtp_rtcp/source/tmmbr_help.h"
24#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000025
26namespace webrtc {
pwestin@webrtc.org741da942011-09-20 13:52:04 +000027class ModuleRtpRtcpImpl;
28
pwestin@webrtc.orgcac78782012-04-05 08:30:10 +000029class RTCPReceiver : public TMMBRHelp
niklase@google.com470e71d2011-07-07 08:21:25 +000030{
31public:
Peter Boströmac547a62015-09-17 23:03:57 +020032 RTCPReceiver(Clock* clock,
Peter Boströmfe7a80c2015-04-23 17:53:17 +020033 bool receiver_only,
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +000034 RtcpPacketTypeCounterObserver* packet_type_counter_observer,
mflodman@webrtc.org96abda02015-02-25 13:50:10 +000035 RtcpBandwidthObserver* rtcp_bandwidth_observer,
36 RtcpIntraFrameObserver* rtcp_intra_frame_observer,
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +000037 ModuleRtpRtcpImpl* owner);
niklase@google.com470e71d2011-07-07 08:21:25 +000038 virtual ~RTCPReceiver();
39
niklase@google.com470e71d2011-07-07 08:21:25 +000040 RTCPMethod Status() const;
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +000041 void SetRTCPStatus(RTCPMethod method);
niklase@google.com470e71d2011-07-07 08:21:25 +000042
pbos@webrtc.org2f446732013-04-08 11:08:41 +000043 int64_t LastReceived();
44 int64_t LastReceivedReceiverReport() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000045
stefan@webrtc.org28a331e2013-09-17 07:49:56 +000046 void SetSsrcs(uint32_t main_ssrc,
47 const std::set<uint32_t>& registered_ssrcs);
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +000048 void SetRelaySSRC(uint32_t ssrc);
asapersson@webrtc.orgdf7b65b2015-01-21 13:07:04 +000049 void SetRemoteSSRC(uint32_t ssrc);
wu@webrtc.org822fbd82013-08-15 23:38:54 +000050 uint32_t RemoteSSRC() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000051
pbos@webrtc.org2f446732013-04-08 11:08:41 +000052 uint32_t RelaySSRC() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000053
pbos@webrtc.org2f446732013-04-08 11:08:41 +000054 int32_t IncomingRTCPPacket(
55 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation,
56 RTCPUtility::RTCPParserV2 *rtcpParser);
niklase@google.com470e71d2011-07-07 08:21:25 +000057
asapersson@webrtc.orgdf7b65b2015-01-21 13:07:04 +000058 void TriggerCallbacksFromRTCPPacket(
59 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
niklase@google.com470e71d2011-07-07 08:21:25 +000060
61 // get received cname
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +000062 int32_t CNAME(uint32_t remoteSSRC, char cName[RTCP_CNAME_SIZE]) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000063
64 // get received NTP
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +000065 bool NTP(uint32_t* ReceivedNTPsecs,
66 uint32_t* ReceivedNTPfrac,
67 uint32_t* RTCPArrivalTimeSecs,
68 uint32_t* RTCPArrivalTimeFrac,
69 uint32_t* rtcp_timestamp) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000070
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +000071 bool LastReceivedXrReferenceTimeInfo(RtcpReceiveTimeInfo* info) const;
72
niklase@google.com470e71d2011-07-07 08:21:25 +000073 // get rtt
wu@webrtc.org822fbd82013-08-15 23:38:54 +000074 int32_t RTT(uint32_t remoteSSRC,
pkasting@chromium.org16825b12015-01-12 21:51:21 +000075 int64_t* RTT,
76 int64_t* avgRTT,
77 int64_t* minRTT,
78 int64_t* maxRTT) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000079
pbos@webrtc.org2f446732013-04-08 11:08:41 +000080 int32_t SenderInfoReceived(RTCPSenderInfo* senderInfo) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000081
pkasting@chromium.org16825b12015-01-12 21:51:21 +000082 bool GetAndResetXrRrRtt(int64_t* rtt_ms);
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +000083
niklase@google.com470e71d2011-07-07 08:21:25 +000084 // get statistics
pbos@webrtc.org2f446732013-04-08 11:08:41 +000085 int32_t StatisticsReceived(
perkj@webrtc.orgce5990c2012-01-11 13:00:08 +000086 std::vector<RTCPReportBlock>* receiveBlocks) const;
87
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +000088 // Returns true if we haven't received an RTCP RR for several RTCP
89 // intervals, but only triggers true once.
90 bool RtcpRrTimeout(int64_t rtcp_interval_ms);
91
92 // Returns true if we haven't received an RTCP RR telling the receive side
93 // has not received RTP packets for too long, i.e. extended highest sequence
94 // number hasn't increased for several RTCP intervals. The function only
95 // returns true once until a new RR is received.
96 bool RtcpRrSequenceNumberTimeout(int64_t rtcp_interval_ms);
97
niklase@google.com470e71d2011-07-07 08:21:25 +000098 // Get TMMBR
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +000099 int32_t TMMBRReceived(uint32_t size,
100 uint32_t accNumCandidates,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000101 TMMBRSet* candidateSet) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000102
103 bool UpdateRTCPReceiveInformationTimers();
104
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000105 int32_t BoundingSet(bool &tmmbrOwner, TMMBRSet* boundingSetRec);
niklase@google.com470e71d2011-07-07 08:21:25 +0000106
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000107 int32_t UpdateTMMBR();
niklase@google.com470e71d2011-07-07 08:21:25 +0000108
sprang@webrtc.orga6ad6e52013-12-05 09:48:44 +0000109 void RegisterRtcpStatisticsCallback(RtcpStatisticsCallback* callback);
110 RtcpStatisticsCallback* GetRtcpStatisticsCallback();
111
niklase@google.com470e71d2011-07-07 08:21:25 +0000112protected:
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000113 RTCPUtility::RTCPCnameInformation* CreateCnameInformation(uint32_t remoteSSRC);
114 RTCPUtility::RTCPCnameInformation* GetCnameInformation(
115 uint32_t remoteSSRC) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000116
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000117 RTCPHelp::RTCPReceiveInformation* CreateReceiveInformation(
118 uint32_t remoteSSRC);
119 RTCPHelp::RTCPReceiveInformation* GetReceiveInformation(uint32_t remoteSSRC);
niklase@google.com470e71d2011-07-07 08:21:25 +0000120
asapersson@webrtc.orgdf7b65b2015-01-21 13:07:04 +0000121 void UpdateReceiveInformation(
122 RTCPHelp::RTCPReceiveInformation& receiveInformation);
niklase@google.com470e71d2011-07-07 08:21:25 +0000123
asapersson@webrtc.orgdf7b65b2015-01-21 13:07:04 +0000124 void HandleSenderReceiverReport(
125 RTCPUtility::RTCPParserV2& rtcpParser,
126 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
niklase@google.com470e71d2011-07-07 08:21:25 +0000127
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000128 void HandleReportBlock(
129 const RTCPUtility::RTCPPacket& rtcpPacket,
130 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation,
asapersson@webrtc.orgdf7b65b2015-01-21 13:07:04 +0000131 uint32_t remoteSSRC);
niklase@google.com470e71d2011-07-07 08:21:25 +0000132
Erik Språnga38233a2015-07-24 09:58:18 +0200133 void HandleSDES(RTCPUtility::RTCPParserV2& rtcpParser,
134 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
niklase@google.com470e71d2011-07-07 08:21:25 +0000135
136 void HandleSDESChunk(RTCPUtility::RTCPParserV2& rtcpParser);
137
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000138 void HandleXrHeader(RTCPUtility::RTCPParserV2& parser,
139 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
140
141 void HandleXrReceiveReferenceTime(
142 RTCPUtility::RTCPParserV2& parser,
143 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
144
145 void HandleXrDlrrReportBlock(
146 RTCPUtility::RTCPParserV2& parser,
147 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
148
149 void HandleXrDlrrReportBlockItem(
150 const RTCPUtility::RTCPPacket& packet,
151 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
152
asapersson@webrtc.orgdf7b65b2015-01-21 13:07:04 +0000153 void HandleXRVOIPMetric(
154 RTCPUtility::RTCPParserV2& rtcpParser,
155 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
niklase@google.com470e71d2011-07-07 08:21:25 +0000156
157 void HandleNACK(RTCPUtility::RTCPParserV2& rtcpParser,
158 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
159
160 void HandleNACKItem(const RTCPUtility::RTCPPacket& rtcpPacket,
161 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
162
163 void HandleBYE(RTCPUtility::RTCPParserV2& rtcpParser);
164
165 void HandlePLI(RTCPUtility::RTCPParserV2& rtcpParser,
166 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
167
168 void HandleSLI(RTCPUtility::RTCPParserV2& rtcpParser,
169 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
170
171 void HandleSLIItem(const RTCPUtility::RTCPPacket& rtcpPacket,
172 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
173
174 void HandleRPSI(RTCPUtility::RTCPParserV2& rtcpParser,
175 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
176
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000177 void HandlePsfbApp(RTCPUtility::RTCPParserV2& rtcpParser,
178 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
179
180 void HandleREMBItem(RTCPUtility::RTCPParserV2& rtcpParser,
181 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
182
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000183 void HandleIJ(RTCPUtility::RTCPParserV2& rtcpParser,
184 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
185
186 void HandleIJItem(const RTCPUtility::RTCPPacket& rtcpPacket,
187 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
188
niklase@google.com470e71d2011-07-07 08:21:25 +0000189 void HandleTMMBR(RTCPUtility::RTCPParserV2& rtcpParser,
190 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
191
192 void HandleTMMBRItem(RTCPHelp::RTCPReceiveInformation& receiveInfo,
193 const RTCPUtility::RTCPPacket& rtcpPacket,
194 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation,
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000195 uint32_t senderSSRC);
niklase@google.com470e71d2011-07-07 08:21:25 +0000196
hta@webrtc.org9d54cd12012-04-30 08:24:55 +0000197 void HandleTMMBN(RTCPUtility::RTCPParserV2& rtcpParser,
198 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
niklase@google.com470e71d2011-07-07 08:21:25 +0000199
200 void HandleSR_REQ(RTCPUtility::RTCPParserV2& rtcpParser,
201 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
202
203 void HandleTMMBNItem(RTCPHelp::RTCPReceiveInformation& receiveInfo,
204 const RTCPUtility::RTCPPacket& rtcpPacket);
205
206 void HandleFIR(RTCPUtility::RTCPParserV2& rtcpParser,
207 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
208
pwestin@webrtc.orgb2179c22012-05-21 12:00:49 +0000209 void HandleFIRItem(RTCPHelp::RTCPReceiveInformation* receiveInfo,
niklase@google.com470e71d2011-07-07 08:21:25 +0000210 const RTCPUtility::RTCPPacket& rtcpPacket,
211 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
212
213 void HandleAPP(RTCPUtility::RTCPParserV2& rtcpParser,
214 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
215
216 void HandleAPPItem(RTCPUtility::RTCPParserV2& rtcpParser,
217 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
218
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000219 private:
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000220 typedef std::map<uint32_t, RTCPHelp::RTCPReceiveInformation*>
stefan@webrtc.orgb5865072013-02-01 14:33:42 +0000221 ReceivedInfoMap;
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000222 // RTCP report block information mapped by remote SSRC.
223 typedef std::map<uint32_t, RTCPHelp::RTCPReportBlockInformation*>
224 ReportBlockInfoMap;
225 // RTCP report block information map mapped by source SSRC.
226 typedef std::map<uint32_t, ReportBlockInfoMap> ReportBlockMap;
227
228 RTCPHelp::RTCPReportBlockInformation* CreateOrGetReportBlockInformation(
229 uint32_t remote_ssrc, uint32_t source_ssrc)
230 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
231 RTCPHelp::RTCPReportBlockInformation* GetReportBlockInformation(
232 uint32_t remote_ssrc, uint32_t source_ssrc) const
233 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
234
Peter Boströmfe7a80c2015-04-23 17:53:17 +0200235 Clock* const _clock;
236 const bool receiver_only_;
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000237 RTCPMethod _method;
238 int64_t _lastReceived;
239 ModuleRtpRtcpImpl& _rtpRtcp;
niklase@google.com470e71d2011-07-07 08:21:25 +0000240
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000241 CriticalSectionWrapper* _criticalSectionFeedbacks;
mflodman@webrtc.org96abda02015-02-25 13:50:10 +0000242 RtcpBandwidthObserver* const _cbRtcpBandwidthObserver;
243 RtcpIntraFrameObserver* const _cbRtcpIntraFrameObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +0000244
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000245 CriticalSectionWrapper* _criticalSectionRTCPReceiver;
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000246 uint32_t main_ssrc_;
247 uint32_t _remoteSSRC;
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000248 std::set<uint32_t> registered_ssrcs_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000249
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000250 // Received send report
251 RTCPSenderInfo _remoteSenderInfo;
252 // when did we receive the last send report
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000253 uint32_t _lastReceivedSRNTPsecs;
254 uint32_t _lastReceivedSRNTPfrac;
niklase@google.com470e71d2011-07-07 08:21:25 +0000255
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000256 // Received XR receive time report.
257 RtcpReceiveTimeInfo _remoteXRReceiveTimeInfo;
258 // Time when the report was received.
259 uint32_t _lastReceivedXRNTPsecs;
260 uint32_t _lastReceivedXRNTPfrac;
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +0000261 // Estimated rtt, zero when there is no valid estimate.
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000262 int64_t xr_rr_rtt_ms_;
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000263
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000264 // Received report blocks.
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000265 ReportBlockMap _receivedReportBlockMap
266 GUARDED_BY(_criticalSectionRTCPReceiver);
stefan@webrtc.orgb5865072013-02-01 14:33:42 +0000267 ReceivedInfoMap _receivedInfoMap;
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000268 std::map<uint32_t, RTCPUtility::RTCPCnameInformation*> _receivedCnameMap;
niklase@google.com470e71d2011-07-07 08:21:25 +0000269
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000270 uint32_t _packetTimeOutMS;
mflodman@webrtc.orgd7d46882012-02-14 12:49:59 +0000271
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +0000272 // The last time we received an RTCP RR.
273 int64_t _lastReceivedRrMs;
274
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000275 // The time we last received an RTCP RR telling we have successfully
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +0000276 // delivered RTP packet to the remote side.
277 int64_t _lastIncreasedSequenceNumberMs;
stefan@webrtc.org8ca8a712013-04-23 16:48:32 +0000278
pbos@webrtc.orga28a91d2015-02-17 14:45:08 +0000279 RtcpStatisticsCallback* stats_callback_ GUARDED_BY(_criticalSectionFeedbacks);
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000280
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000281 RtcpPacketTypeCounterObserver* const packet_type_counter_observer_;
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000282 RtcpPacketTypeCounter packet_type_counter_;
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000283
284 RTCPUtility::NackStats nack_stats_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000285};
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000286} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000287#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_H_