blob: 223da7692fabbd6d5bb207de18888509feca1f63 [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:
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +000032 RTCPReceiver(int32_t id, Clock* clock, ModuleRtpRtcpImpl* owner);
niklase@google.com470e71d2011-07-07 08:21:25 +000033 virtual ~RTCPReceiver();
34
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +000035 void ChangeUniqueId(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +000036
37 RTCPMethod Status() const;
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +000038 void SetRTCPStatus(RTCPMethod method);
niklase@google.com470e71d2011-07-07 08:21:25 +000039
pbos@webrtc.org2f446732013-04-08 11:08:41 +000040 int64_t LastReceived();
41 int64_t LastReceivedReceiverReport() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000042
stefan@webrtc.org28a331e2013-09-17 07:49:56 +000043 void SetSsrcs(uint32_t main_ssrc,
44 const std::set<uint32_t>& registered_ssrcs);
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +000045 void SetRelaySSRC(uint32_t ssrc);
46 int32_t SetRemoteSSRC(uint32_t ssrc);
wu@webrtc.org822fbd82013-08-15 23:38:54 +000047 uint32_t RemoteSSRC() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000048
pbos@webrtc.org2f446732013-04-08 11:08:41 +000049 uint32_t RelaySSRC() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000050
pwestin@webrtc.org49888ce2012-04-27 05:25:53 +000051 void RegisterRtcpObservers(RtcpIntraFrameObserver* intra_frame_callback,
pbos@webrtc.orgece38902014-11-14 11:52:04 +000052 RtcpBandwidthObserver* bandwidth_callback);
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
58 void TriggerCallbacksFromRTCPPacket(RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
59
60 // get received cname
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +000061 int32_t CNAME(uint32_t remoteSSRC, char cName[RTCP_CNAME_SIZE]) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000062
63 // get received NTP
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +000064 bool NTP(uint32_t* ReceivedNTPsecs,
65 uint32_t* ReceivedNTPfrac,
66 uint32_t* RTCPArrivalTimeSecs,
67 uint32_t* RTCPArrivalTimeFrac,
68 uint32_t* rtcp_timestamp) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000069
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +000070 bool LastReceivedXrReferenceTimeInfo(RtcpReceiveTimeInfo* info) const;
71
niklase@google.com470e71d2011-07-07 08:21:25 +000072 // get rtt
wu@webrtc.org822fbd82013-08-15 23:38:54 +000073 int32_t RTT(uint32_t remoteSSRC,
pbos@webrtc.org2f446732013-04-08 11:08:41 +000074 uint16_t* RTT,
75 uint16_t* avgRTT,
76 uint16_t* minRTT,
77 uint16_t* maxRTT) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000078
pbos@webrtc.org2f446732013-04-08 11:08:41 +000079 int32_t SenderInfoReceived(RTCPSenderInfo* senderInfo) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000080
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +000081 bool GetAndResetXrRrRtt(uint16_t* rtt_ms);
82
niklase@google.com470e71d2011-07-07 08:21:25 +000083 // get statistics
pbos@webrtc.org2f446732013-04-08 11:08:41 +000084 int32_t StatisticsReceived(
perkj@webrtc.orgce5990c2012-01-11 13:00:08 +000085 std::vector<RTCPReportBlock>* receiveBlocks) const;
86
asapersson@webrtc.org8098e072014-02-19 11:59:02 +000087 void GetPacketTypeCounter(RtcpPacketTypeCounter* packet_counter) const;
88
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +000089 // Returns true if we haven't received an RTCP RR for several RTCP
90 // intervals, but only triggers true once.
91 bool RtcpRrTimeout(int64_t rtcp_interval_ms);
92
93 // Returns true if we haven't received an RTCP RR telling the receive side
94 // has not received RTP packets for too long, i.e. extended highest sequence
95 // number hasn't increased for several RTCP intervals. The function only
96 // returns true once until a new RR is received.
97 bool RtcpRrSequenceNumberTimeout(int64_t rtcp_interval_ms);
98
niklase@google.com470e71d2011-07-07 08:21:25 +000099 // Get TMMBR
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000100 int32_t TMMBRReceived(uint32_t size,
101 uint32_t accNumCandidates,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000102 TMMBRSet* candidateSet) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
104 bool UpdateRTCPReceiveInformationTimers();
105
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000106 int32_t BoundingSet(bool &tmmbrOwner, TMMBRSet* boundingSetRec);
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000108 int32_t UpdateTMMBR();
niklase@google.com470e71d2011-07-07 08:21:25 +0000109
sprang@webrtc.orga6ad6e52013-12-05 09:48:44 +0000110 void RegisterRtcpStatisticsCallback(RtcpStatisticsCallback* callback);
111 RtcpStatisticsCallback* GetRtcpStatisticsCallback();
112
niklase@google.com470e71d2011-07-07 08:21:25 +0000113protected:
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000114 RTCPUtility::RTCPCnameInformation* CreateCnameInformation(uint32_t remoteSSRC);
115 RTCPUtility::RTCPCnameInformation* GetCnameInformation(
116 uint32_t remoteSSRC) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000117
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000118 RTCPHelp::RTCPReceiveInformation* CreateReceiveInformation(
119 uint32_t remoteSSRC);
120 RTCPHelp::RTCPReceiveInformation* GetReceiveInformation(uint32_t remoteSSRC);
niklase@google.com470e71d2011-07-07 08:21:25 +0000121
122 void UpdateReceiveInformation( RTCPHelp::RTCPReceiveInformation& receiveInformation);
123
124 void HandleSenderReceiverReport(RTCPUtility::RTCPParserV2& rtcpParser,
125 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
126
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000127 void HandleReportBlock(
128 const RTCPUtility::RTCPPacket& rtcpPacket,
129 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation,
130 uint32_t remoteSSRC,
131 uint8_t numberOfReportBlocks);
niklase@google.com470e71d2011-07-07 08:21:25 +0000132
133 void HandleSDES(RTCPUtility::RTCPParserV2& rtcpParser);
134
135 void HandleSDESChunk(RTCPUtility::RTCPParserV2& rtcpParser);
136
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000137 void HandleXrHeader(RTCPUtility::RTCPParserV2& parser,
138 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
139
140 void HandleXrReceiveReferenceTime(
141 RTCPUtility::RTCPParserV2& parser,
142 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
143
144 void HandleXrDlrrReportBlock(
145 RTCPUtility::RTCPParserV2& parser,
146 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
147
148 void HandleXrDlrrReportBlockItem(
149 const RTCPUtility::RTCPPacket& packet,
150 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
151
niklase@google.com470e71d2011-07-07 08:21:25 +0000152 void HandleXRVOIPMetric(RTCPUtility::RTCPParserV2& rtcpParser,
153 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
154
155 void HandleNACK(RTCPUtility::RTCPParserV2& rtcpParser,
156 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
157
158 void HandleNACKItem(const RTCPUtility::RTCPPacket& rtcpPacket,
159 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
160
161 void HandleBYE(RTCPUtility::RTCPParserV2& rtcpParser);
162
163 void HandlePLI(RTCPUtility::RTCPParserV2& rtcpParser,
164 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
165
166 void HandleSLI(RTCPUtility::RTCPParserV2& rtcpParser,
167 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
168
169 void HandleSLIItem(const RTCPUtility::RTCPPacket& rtcpPacket,
170 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
171
172 void HandleRPSI(RTCPUtility::RTCPParserV2& rtcpParser,
173 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
174
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000175 void HandlePsfbApp(RTCPUtility::RTCPParserV2& rtcpParser,
176 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
177
178 void HandleREMBItem(RTCPUtility::RTCPParserV2& rtcpParser,
179 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
180
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000181 void HandleIJ(RTCPUtility::RTCPParserV2& rtcpParser,
182 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
183
184 void HandleIJItem(const RTCPUtility::RTCPPacket& rtcpPacket,
185 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
186
niklase@google.com470e71d2011-07-07 08:21:25 +0000187 void HandleTMMBR(RTCPUtility::RTCPParserV2& rtcpParser,
188 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
189
190 void HandleTMMBRItem(RTCPHelp::RTCPReceiveInformation& receiveInfo,
191 const RTCPUtility::RTCPPacket& rtcpPacket,
192 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation,
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000193 uint32_t senderSSRC);
niklase@google.com470e71d2011-07-07 08:21:25 +0000194
hta@webrtc.org9d54cd12012-04-30 08:24:55 +0000195 void HandleTMMBN(RTCPUtility::RTCPParserV2& rtcpParser,
196 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
niklase@google.com470e71d2011-07-07 08:21:25 +0000197
198 void HandleSR_REQ(RTCPUtility::RTCPParserV2& rtcpParser,
199 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
200
201 void HandleTMMBNItem(RTCPHelp::RTCPReceiveInformation& receiveInfo,
202 const RTCPUtility::RTCPPacket& rtcpPacket);
203
204 void HandleFIR(RTCPUtility::RTCPParserV2& rtcpParser,
205 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
206
pwestin@webrtc.orgb2179c22012-05-21 12:00:49 +0000207 void HandleFIRItem(RTCPHelp::RTCPReceiveInformation* receiveInfo,
niklase@google.com470e71d2011-07-07 08:21:25 +0000208 const RTCPUtility::RTCPPacket& rtcpPacket,
209 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
210
211 void HandleAPP(RTCPUtility::RTCPParserV2& rtcpParser,
212 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
213
214 void HandleAPPItem(RTCPUtility::RTCPParserV2& rtcpParser,
215 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
216
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000217 private:
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000218 typedef std::map<uint32_t, RTCPHelp::RTCPReceiveInformation*>
stefan@webrtc.orgb5865072013-02-01 14:33:42 +0000219 ReceivedInfoMap;
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000220 // RTCP report block information mapped by remote SSRC.
221 typedef std::map<uint32_t, RTCPHelp::RTCPReportBlockInformation*>
222 ReportBlockInfoMap;
223 // RTCP report block information map mapped by source SSRC.
224 typedef std::map<uint32_t, ReportBlockInfoMap> ReportBlockMap;
225
226 RTCPHelp::RTCPReportBlockInformation* CreateOrGetReportBlockInformation(
227 uint32_t remote_ssrc, uint32_t source_ssrc)
228 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
229 RTCPHelp::RTCPReportBlockInformation* GetReportBlockInformation(
230 uint32_t remote_ssrc, uint32_t source_ssrc) const
231 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
232
233 int32_t _id;
234 Clock* _clock;
235 RTCPMethod _method;
236 int64_t _lastReceived;
237 ModuleRtpRtcpImpl& _rtpRtcp;
niklase@google.com470e71d2011-07-07 08:21:25 +0000238
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000239 CriticalSectionWrapper* _criticalSectionFeedbacks;
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000240 RtcpBandwidthObserver* _cbRtcpBandwidthObserver;
pwestin@webrtc.org49888ce2012-04-27 05:25:53 +0000241 RtcpIntraFrameObserver* _cbRtcpIntraFrameObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +0000242
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000243 CriticalSectionWrapper* _criticalSectionRTCPReceiver;
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000244 uint32_t main_ssrc_;
245 uint32_t _remoteSSRC;
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000246 std::set<uint32_t> registered_ssrcs_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000247
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000248 // Received send report
249 RTCPSenderInfo _remoteSenderInfo;
250 // when did we receive the last send report
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000251 uint32_t _lastReceivedSRNTPsecs;
252 uint32_t _lastReceivedSRNTPfrac;
niklase@google.com470e71d2011-07-07 08:21:25 +0000253
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000254 // Received XR receive time report.
255 RtcpReceiveTimeInfo _remoteXRReceiveTimeInfo;
256 // Time when the report was received.
257 uint32_t _lastReceivedXRNTPsecs;
258 uint32_t _lastReceivedXRNTPfrac;
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +0000259 // Estimated rtt, zero when there is no valid estimate.
260 uint16_t xr_rr_rtt_ms_;
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000261
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000262 // Received report blocks.
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000263 ReportBlockMap _receivedReportBlockMap
264 GUARDED_BY(_criticalSectionRTCPReceiver);
stefan@webrtc.orgb5865072013-02-01 14:33:42 +0000265 ReceivedInfoMap _receivedInfoMap;
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000266 std::map<uint32_t, RTCPUtility::RTCPCnameInformation*> _receivedCnameMap;
niklase@google.com470e71d2011-07-07 08:21:25 +0000267
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000268 uint32_t _packetTimeOutMS;
mflodman@webrtc.orgd7d46882012-02-14 12:49:59 +0000269
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +0000270 // The last time we received an RTCP RR.
271 int64_t _lastReceivedRrMs;
272
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000273 // The time we last received an RTCP RR telling we have successfully
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +0000274 // delivered RTP packet to the remote side.
275 int64_t _lastIncreasedSequenceNumberMs;
stefan@webrtc.org8ca8a712013-04-23 16:48:32 +0000276
sprang@webrtc.orga6ad6e52013-12-05 09:48:44 +0000277 RtcpStatisticsCallback* stats_callback_;
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000278
279 RtcpPacketTypeCounter packet_type_counter_;
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000280
281 RTCPUtility::NackStats nack_stats_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000282};
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000283} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000284#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_H_