blob: 087722c42f97d1e14bd815952318401600ca091e [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
pbos@webrtc.orga048d7c2013-05-29 14:27:38 +000018#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
19#include "webrtc/modules/rtp_rtcp/source/rtcp_receiver_help.h"
20#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
21#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
22#include "webrtc/modules/rtp_rtcp/source/tmmbr_help.h"
23#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000024
25namespace webrtc {
pwestin@webrtc.org741da942011-09-20 13:52:04 +000026class ModuleRtpRtcpImpl;
27
pwestin@webrtc.orgcac78782012-04-05 08:30:10 +000028class RTCPReceiver : public TMMBRHelp
niklase@google.com470e71d2011-07-07 08:21:25 +000029{
30public:
pbos@webrtc.org2f446732013-04-08 11:08:41 +000031 RTCPReceiver(const int32_t id, Clock* clock,
pwestin@webrtc.org0644b1d2011-12-01 15:42:31 +000032 ModuleRtpRtcpImpl* owner);
niklase@google.com470e71d2011-07-07 08:21:25 +000033 virtual ~RTCPReceiver();
34
pbos@webrtc.org2f446732013-04-08 11:08:41 +000035 void ChangeUniqueId(const int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +000036
37 RTCPMethod Status() const;
pbos@webrtc.org2f446732013-04-08 11:08:41 +000038 int32_t SetRTCPStatus(const 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.org2f446732013-04-08 11:08:41 +000045 void SetRelaySSRC( const uint32_t ssrc);
46 int32_t SetRemoteSSRC( const 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,
52 RtcpBandwidthObserver* bandwidth_callback,
53 RtcpFeedback* feedback_callback);
niklase@google.com470e71d2011-07-07 08:21:25 +000054
pbos@webrtc.org2f446732013-04-08 11:08:41 +000055 int32_t IncomingRTCPPacket(
56 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation,
57 RTCPUtility::RTCPParserV2 *rtcpParser);
niklase@google.com470e71d2011-07-07 08:21:25 +000058
59 void TriggerCallbacksFromRTCPPacket(RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
60
61 // get received cname
pbos@webrtc.org2f446732013-04-08 11:08:41 +000062 int32_t CNAME(const uint32_t remoteSSRC,
63 char cName[RTCP_CNAME_SIZE]) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000064
65 // get received NTP
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +000066 bool NTP(uint32_t* ReceivedNTPsecs,
67 uint32_t* ReceivedNTPfrac,
68 uint32_t* RTCPArrivalTimeSecs,
69 uint32_t* RTCPArrivalTimeFrac,
70 uint32_t* rtcp_timestamp) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000071
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +000072 bool LastReceivedXrReferenceTimeInfo(RtcpReceiveTimeInfo* info) const;
73
niklase@google.com470e71d2011-07-07 08:21:25 +000074 // get rtt
wu@webrtc.org822fbd82013-08-15 23:38:54 +000075 int32_t RTT(uint32_t remoteSSRC,
pbos@webrtc.org2f446732013-04-08 11:08:41 +000076 uint16_t* RTT,
77 uint16_t* avgRTT,
78 uint16_t* minRTT,
79 uint16_t* maxRTT) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000080
pbos@webrtc.org2f446732013-04-08 11:08:41 +000081 int32_t ResetRTT(const uint32_t remoteSSRC);
niklase@google.com470e71d2011-07-07 08:21:25 +000082
pbos@webrtc.org2f446732013-04-08 11:08:41 +000083 int32_t SenderInfoReceived(RTCPSenderInfo* senderInfo) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000084
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +000085 bool GetAndResetXrRrRtt(uint16_t* rtt_ms);
86
niklase@google.com470e71d2011-07-07 08:21:25 +000087 // get statistics
pbos@webrtc.org2f446732013-04-08 11:08:41 +000088 int32_t StatisticsReceived(
perkj@webrtc.orgce5990c2012-01-11 13:00:08 +000089 std::vector<RTCPReportBlock>* receiveBlocks) const;
90
asapersson@webrtc.org8098e072014-02-19 11:59:02 +000091 void GetPacketTypeCounter(RtcpPacketTypeCounter* packet_counter) const;
92
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +000093 // 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);
96
97 // 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);
102
niklase@google.com470e71d2011-07-07 08:21:25 +0000103 // Get TMMBR
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000104 int32_t TMMBRReceived(const uint32_t size,
105 const uint32_t accNumCandidates,
106 TMMBRSet* candidateSet) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
108 bool UpdateRTCPReceiveInformationTimers();
109
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000110 int32_t BoundingSet(bool &tmmbrOwner, TMMBRSet* boundingSetRec);
niklase@google.com470e71d2011-07-07 08:21:25 +0000111
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000112 int32_t UpdateTMMBR();
niklase@google.com470e71d2011-07-07 08:21:25 +0000113
sprang@webrtc.orga6ad6e52013-12-05 09:48:44 +0000114 void RegisterRtcpStatisticsCallback(RtcpStatisticsCallback* callback);
115 RtcpStatisticsCallback* GetRtcpStatisticsCallback();
116
niklase@google.com470e71d2011-07-07 08:21:25 +0000117protected:
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000118 RTCPHelp::RTCPReportBlockInformation* CreateReportBlockInformation(const uint32_t remoteSSRC);
119 RTCPHelp::RTCPReportBlockInformation* GetReportBlockInformation(const uint32_t remoteSSRC) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000120
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000121 RTCPUtility::RTCPCnameInformation* CreateCnameInformation(const uint32_t remoteSSRC);
122 RTCPUtility::RTCPCnameInformation* GetCnameInformation(const uint32_t remoteSSRC) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000123
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000124 RTCPHelp::RTCPReceiveInformation* CreateReceiveInformation(const uint32_t remoteSSRC);
125 RTCPHelp::RTCPReceiveInformation* GetReceiveInformation(const uint32_t remoteSSRC);
niklase@google.com470e71d2011-07-07 08:21:25 +0000126
127 void UpdateReceiveInformation( RTCPHelp::RTCPReceiveInformation& receiveInformation);
128
129 void HandleSenderReceiverReport(RTCPUtility::RTCPParserV2& rtcpParser,
130 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
131
132 void HandleReportBlock(const RTCPUtility::RTCPPacket& rtcpPacket,
133 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000134 const uint32_t remoteSSRC,
135 const uint8_t numberOfReportBlocks);
niklase@google.com470e71d2011-07-07 08:21:25 +0000136
137 void HandleSDES(RTCPUtility::RTCPParserV2& rtcpParser);
138
139 void HandleSDESChunk(RTCPUtility::RTCPParserV2& rtcpParser);
140
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000141 void HandleXrHeader(RTCPUtility::RTCPParserV2& parser,
142 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
143
144 void HandleXrReceiveReferenceTime(
145 RTCPUtility::RTCPParserV2& parser,
146 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
147
148 void HandleXrDlrrReportBlock(
149 RTCPUtility::RTCPParserV2& parser,
150 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
151
152 void HandleXrDlrrReportBlockItem(
153 const RTCPUtility::RTCPPacket& packet,
154 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
155
niklase@google.com470e71d2011-07-07 08:21:25 +0000156 void HandleXRVOIPMetric(RTCPUtility::RTCPParserV2& rtcpParser,
157 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
158
159 void HandleNACK(RTCPUtility::RTCPParserV2& rtcpParser,
160 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
161
162 void HandleNACKItem(const RTCPUtility::RTCPPacket& rtcpPacket,
163 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
164
165 void HandleBYE(RTCPUtility::RTCPParserV2& rtcpParser);
166
167 void HandlePLI(RTCPUtility::RTCPParserV2& rtcpParser,
168 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
169
170 void HandleSLI(RTCPUtility::RTCPParserV2& rtcpParser,
171 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
172
173 void HandleSLIItem(const RTCPUtility::RTCPPacket& rtcpPacket,
174 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
175
176 void HandleRPSI(RTCPUtility::RTCPParserV2& rtcpParser,
177 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
178
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000179 void HandlePsfbApp(RTCPUtility::RTCPParserV2& rtcpParser,
180 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
181
182 void HandleREMBItem(RTCPUtility::RTCPParserV2& rtcpParser,
183 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
184
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000185 void HandleIJ(RTCPUtility::RTCPParserV2& rtcpParser,
186 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
187
188 void HandleIJItem(const RTCPUtility::RTCPPacket& rtcpPacket,
189 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
190
niklase@google.com470e71d2011-07-07 08:21:25 +0000191 void HandleTMMBR(RTCPUtility::RTCPParserV2& rtcpParser,
192 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
193
194 void HandleTMMBRItem(RTCPHelp::RTCPReceiveInformation& receiveInfo,
195 const RTCPUtility::RTCPPacket& rtcpPacket,
196 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000197 const uint32_t senderSSRC);
niklase@google.com470e71d2011-07-07 08:21:25 +0000198
hta@webrtc.org9d54cd12012-04-30 08:24:55 +0000199 void HandleTMMBN(RTCPUtility::RTCPParserV2& rtcpParser,
200 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
niklase@google.com470e71d2011-07-07 08:21:25 +0000201
202 void HandleSR_REQ(RTCPUtility::RTCPParserV2& rtcpParser,
203 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
204
205 void HandleTMMBNItem(RTCPHelp::RTCPReceiveInformation& receiveInfo,
206 const RTCPUtility::RTCPPacket& rtcpPacket);
207
208 void HandleFIR(RTCPUtility::RTCPParserV2& rtcpParser,
209 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
210
pwestin@webrtc.orgb2179c22012-05-21 12:00:49 +0000211 void HandleFIRItem(RTCPHelp::RTCPReceiveInformation* receiveInfo,
niklase@google.com470e71d2011-07-07 08:21:25 +0000212 const RTCPUtility::RTCPPacket& rtcpPacket,
213 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
214
215 void HandleAPP(RTCPUtility::RTCPParserV2& rtcpParser,
216 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
217
218 void HandleAPPItem(RTCPUtility::RTCPParserV2& rtcpParser,
219 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
220
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000221 private:
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000222 typedef std::map<uint32_t, RTCPHelp::RTCPReceiveInformation*>
stefan@webrtc.orgb5865072013-02-01 14:33:42 +0000223 ReceivedInfoMap;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000224 int32_t _id;
stefan@webrtc.orga678a3b2013-01-21 07:42:11 +0000225 Clock* _clock;
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000226 RTCPMethod _method;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000227 int64_t _lastReceived;
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000228 ModuleRtpRtcpImpl& _rtpRtcp;
niklase@google.com470e71d2011-07-07 08:21:25 +0000229
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000230 CriticalSectionWrapper* _criticalSectionFeedbacks;
231 RtcpFeedback* _cbRtcpFeedback;
pwestin@webrtc.org49888ce2012-04-27 05:25:53 +0000232 RtcpBandwidthObserver* _cbRtcpBandwidthObserver;
233 RtcpIntraFrameObserver* _cbRtcpIntraFrameObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +0000234
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000235 CriticalSectionWrapper* _criticalSectionRTCPReceiver;
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000236 uint32_t main_ssrc_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000237 uint32_t _remoteSSRC;
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000238 std::set<uint32_t> registered_ssrcs_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000239
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000240 // Received send report
241 RTCPSenderInfo _remoteSenderInfo;
242 // when did we receive the last send report
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000243 uint32_t _lastReceivedSRNTPsecs;
244 uint32_t _lastReceivedSRNTPfrac;
niklase@google.com470e71d2011-07-07 08:21:25 +0000245
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000246 // Received XR receive time report.
247 RtcpReceiveTimeInfo _remoteXRReceiveTimeInfo;
248 // Time when the report was received.
249 uint32_t _lastReceivedXRNTPsecs;
250 uint32_t _lastReceivedXRNTPfrac;
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +0000251 // Estimated rtt, zero when there is no valid estimate.
252 uint16_t xr_rr_rtt_ms_;
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000253
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000254 // Received report blocks.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000255 std::map<uint32_t, RTCPHelp::RTCPReportBlockInformation*>
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000256 _receivedReportBlockMap;
stefan@webrtc.orgb5865072013-02-01 14:33:42 +0000257 ReceivedInfoMap _receivedInfoMap;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000258 std::map<uint32_t, RTCPUtility::RTCPCnameInformation*>
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000259 _receivedCnameMap;
niklase@google.com470e71d2011-07-07 08:21:25 +0000260
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000261 uint32_t _packetTimeOutMS;
mflodman@webrtc.orgd7d46882012-02-14 12:49:59 +0000262
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +0000263 // The last time we received an RTCP RR.
264 int64_t _lastReceivedRrMs;
265
266 // The time we last received an RTCP RR telling we have ssuccessfully
267 // delivered RTP packet to the remote side.
268 int64_t _lastIncreasedSequenceNumberMs;
stefan@webrtc.org8ca8a712013-04-23 16:48:32 +0000269
sprang@webrtc.orga6ad6e52013-12-05 09:48:44 +0000270 RtcpStatisticsCallback* stats_callback_;
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000271
272 RtcpPacketTypeCounter packet_type_counter_;
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000273
274 RTCPUtility::NackStats nack_stats_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000275};
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000276} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000277#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_H_