blob: 45e3b680c5928afd6fc0db4d838df18e554ddd6e [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>
16
pbos@webrtc.orga048d7c2013-05-29 14:27:38 +000017#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
18#include "webrtc/modules/rtp_rtcp/source/rtcp_receiver_help.h"
19#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
20#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
21#include "webrtc/modules/rtp_rtcp/source/tmmbr_help.h"
22#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000023
24namespace webrtc {
pwestin@webrtc.org741da942011-09-20 13:52:04 +000025class ModuleRtpRtcpImpl;
26
pwestin@webrtc.orgcac78782012-04-05 08:30:10 +000027class RTCPReceiver : public TMMBRHelp
niklase@google.com470e71d2011-07-07 08:21:25 +000028{
29public:
pbos@webrtc.org2f446732013-04-08 11:08:41 +000030 RTCPReceiver(const int32_t id, Clock* clock,
pwestin@webrtc.org0644b1d2011-12-01 15:42:31 +000031 ModuleRtpRtcpImpl* owner);
niklase@google.com470e71d2011-07-07 08:21:25 +000032 virtual ~RTCPReceiver();
33
pbos@webrtc.org2f446732013-04-08 11:08:41 +000034 void ChangeUniqueId(const int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +000035
36 RTCPMethod Status() const;
pbos@webrtc.org2f446732013-04-08 11:08:41 +000037 int32_t SetRTCPStatus(const RTCPMethod method);
niklase@google.com470e71d2011-07-07 08:21:25 +000038
pbos@webrtc.org2f446732013-04-08 11:08:41 +000039 int64_t LastReceived();
40 int64_t LastReceivedReceiverReport() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000041
pbos@webrtc.org2f446732013-04-08 11:08:41 +000042 void SetSSRC( const uint32_t ssrc);
43 void SetRelaySSRC( const uint32_t ssrc);
44 int32_t SetRemoteSSRC( const uint32_t ssrc);
wu@webrtc.org822fbd82013-08-15 23:38:54 +000045 uint32_t RemoteSSRC() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000046
pbos@webrtc.org2f446732013-04-08 11:08:41 +000047 uint32_t RelaySSRC() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000048
pwestin@webrtc.org49888ce2012-04-27 05:25:53 +000049 void RegisterRtcpObservers(RtcpIntraFrameObserver* intra_frame_callback,
50 RtcpBandwidthObserver* bandwidth_callback,
51 RtcpFeedback* feedback_callback);
niklase@google.com470e71d2011-07-07 08:21:25 +000052
pbos@webrtc.org2f446732013-04-08 11:08:41 +000053 int32_t IncomingRTCPPacket(
54 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation,
55 RTCPUtility::RTCPParserV2 *rtcpParser);
niklase@google.com470e71d2011-07-07 08:21:25 +000056
57 void TriggerCallbacksFromRTCPPacket(RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
58
59 // get received cname
pbos@webrtc.org2f446732013-04-08 11:08:41 +000060 int32_t CNAME(const uint32_t remoteSSRC,
61 char cName[RTCP_CNAME_SIZE]) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000062
63 // get received NTP
pbos@webrtc.org2f446732013-04-08 11:08:41 +000064 int32_t 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
70 // get rtt
wu@webrtc.org822fbd82013-08-15 23:38:54 +000071 int32_t RTT(uint32_t remoteSSRC,
pbos@webrtc.org2f446732013-04-08 11:08:41 +000072 uint16_t* RTT,
73 uint16_t* avgRTT,
74 uint16_t* minRTT,
75 uint16_t* maxRTT) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000076
pbos@webrtc.org2f446732013-04-08 11:08:41 +000077 uint16_t RTT() const;
mflodman@webrtc.orgd7d46882012-02-14 12:49:59 +000078
pbos@webrtc.org2f446732013-04-08 11:08:41 +000079 int SetRTT(uint16_t rtt);
mflodman@webrtc.orgd7d46882012-02-14 12:49:59 +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
niklase@google.com470e71d2011-07-07 08:21:25 +000085 // get statistics
pbos@webrtc.org2f446732013-04-08 11:08:41 +000086 int32_t StatisticsReceived(
perkj@webrtc.orgce5990c2012-01-11 13:00:08 +000087 std::vector<RTCPReportBlock>* receiveBlocks) 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.org2f446732013-04-08 11:08:41 +0000100 int32_t TMMBRReceived(const uint32_t size,
101 const uint32_t accNumCandidates,
102 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
niklase@google.com470e71d2011-07-07 08:21:25 +0000110protected:
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000111 RTCPHelp::RTCPReportBlockInformation* CreateReportBlockInformation(const uint32_t remoteSSRC);
112 RTCPHelp::RTCPReportBlockInformation* GetReportBlockInformation(const uint32_t remoteSSRC) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000113
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000114 RTCPUtility::RTCPCnameInformation* CreateCnameInformation(const uint32_t remoteSSRC);
115 RTCPUtility::RTCPCnameInformation* GetCnameInformation(const uint32_t remoteSSRC) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000116
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000117 RTCPHelp::RTCPReceiveInformation* CreateReceiveInformation(const uint32_t remoteSSRC);
118 RTCPHelp::RTCPReceiveInformation* GetReceiveInformation(const uint32_t remoteSSRC);
niklase@google.com470e71d2011-07-07 08:21:25 +0000119
120 void UpdateReceiveInformation( RTCPHelp::RTCPReceiveInformation& receiveInformation);
121
122 void HandleSenderReceiverReport(RTCPUtility::RTCPParserV2& rtcpParser,
123 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
124
125 void HandleReportBlock(const RTCPUtility::RTCPPacket& rtcpPacket,
126 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000127 const uint32_t remoteSSRC,
128 const uint8_t numberOfReportBlocks);
niklase@google.com470e71d2011-07-07 08:21:25 +0000129
130 void HandleSDES(RTCPUtility::RTCPParserV2& rtcpParser);
131
132 void HandleSDESChunk(RTCPUtility::RTCPParserV2& rtcpParser);
133
134 void HandleXRVOIPMetric(RTCPUtility::RTCPParserV2& rtcpParser,
135 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
136
137 void HandleNACK(RTCPUtility::RTCPParserV2& rtcpParser,
138 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
139
140 void HandleNACKItem(const RTCPUtility::RTCPPacket& rtcpPacket,
141 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
142
143 void HandleBYE(RTCPUtility::RTCPParserV2& rtcpParser);
144
145 void HandlePLI(RTCPUtility::RTCPParserV2& rtcpParser,
146 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
147
148 void HandleSLI(RTCPUtility::RTCPParserV2& rtcpParser,
149 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
150
151 void HandleSLIItem(const RTCPUtility::RTCPPacket& rtcpPacket,
152 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
153
154 void HandleRPSI(RTCPUtility::RTCPParserV2& rtcpParser,
155 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
156
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000157 void HandlePsfbApp(RTCPUtility::RTCPParserV2& rtcpParser,
158 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
159
160 void HandleREMBItem(RTCPUtility::RTCPParserV2& rtcpParser,
161 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
162
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000163 void HandleIJ(RTCPUtility::RTCPParserV2& rtcpParser,
164 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
165
166 void HandleIJItem(const RTCPUtility::RTCPPacket& rtcpPacket,
167 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
168
niklase@google.com470e71d2011-07-07 08:21:25 +0000169 void HandleTMMBR(RTCPUtility::RTCPParserV2& rtcpParser,
170 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
171
172 void HandleTMMBRItem(RTCPHelp::RTCPReceiveInformation& receiveInfo,
173 const RTCPUtility::RTCPPacket& rtcpPacket,
174 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000175 const uint32_t senderSSRC);
niklase@google.com470e71d2011-07-07 08:21:25 +0000176
hta@webrtc.org9d54cd12012-04-30 08:24:55 +0000177 void HandleTMMBN(RTCPUtility::RTCPParserV2& rtcpParser,
178 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
niklase@google.com470e71d2011-07-07 08:21:25 +0000179
180 void HandleSR_REQ(RTCPUtility::RTCPParserV2& rtcpParser,
181 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
182
183 void HandleTMMBNItem(RTCPHelp::RTCPReceiveInformation& receiveInfo,
184 const RTCPUtility::RTCPPacket& rtcpPacket);
185
186 void HandleFIR(RTCPUtility::RTCPParserV2& rtcpParser,
187 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
188
pwestin@webrtc.orgb2179c22012-05-21 12:00:49 +0000189 void HandleFIRItem(RTCPHelp::RTCPReceiveInformation* receiveInfo,
niklase@google.com470e71d2011-07-07 08:21:25 +0000190 const RTCPUtility::RTCPPacket& rtcpPacket,
191 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
192
193 void HandleAPP(RTCPUtility::RTCPParserV2& rtcpParser,
194 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
195
196 void HandleAPPItem(RTCPUtility::RTCPParserV2& rtcpParser,
197 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
198
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000199 private:
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000200 typedef std::map<uint32_t, RTCPHelp::RTCPReceiveInformation*>
stefan@webrtc.orgb5865072013-02-01 14:33:42 +0000201 ReceivedInfoMap;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000202 int32_t _id;
stefan@webrtc.orga678a3b2013-01-21 07:42:11 +0000203 Clock* _clock;
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000204 RTCPMethod _method;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000205 int64_t _lastReceived;
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000206 ModuleRtpRtcpImpl& _rtpRtcp;
niklase@google.com470e71d2011-07-07 08:21:25 +0000207
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000208 CriticalSectionWrapper* _criticalSectionFeedbacks;
209 RtcpFeedback* _cbRtcpFeedback;
pwestin@webrtc.org49888ce2012-04-27 05:25:53 +0000210 RtcpBandwidthObserver* _cbRtcpBandwidthObserver;
211 RtcpIntraFrameObserver* _cbRtcpIntraFrameObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +0000212
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000213 CriticalSectionWrapper* _criticalSectionRTCPReceiver;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000214 uint32_t _SSRC;
215 uint32_t _remoteSSRC;
niklase@google.com470e71d2011-07-07 08:21:25 +0000216
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000217 // Received send report
218 RTCPSenderInfo _remoteSenderInfo;
219 // when did we receive the last send report
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000220 uint32_t _lastReceivedSRNTPsecs;
221 uint32_t _lastReceivedSRNTPfrac;
niklase@google.com470e71d2011-07-07 08:21:25 +0000222
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000223 // Received report blocks.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000224 std::map<uint32_t, RTCPHelp::RTCPReportBlockInformation*>
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000225 _receivedReportBlockMap;
stefan@webrtc.orgb5865072013-02-01 14:33:42 +0000226 ReceivedInfoMap _receivedInfoMap;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000227 std::map<uint32_t, RTCPUtility::RTCPCnameInformation*>
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000228 _receivedCnameMap;
niklase@google.com470e71d2011-07-07 08:21:25 +0000229
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000230 uint32_t _packetTimeOutMS;
mflodman@webrtc.orgd7d46882012-02-14 12:49:59 +0000231
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +0000232 // The last time we received an RTCP RR.
233 int64_t _lastReceivedRrMs;
234
235 // The time we last received an RTCP RR telling we have ssuccessfully
236 // delivered RTP packet to the remote side.
237 int64_t _lastIncreasedSequenceNumberMs;
stefan@webrtc.org8ca8a712013-04-23 16:48:32 +0000238
239 // Externally set RTT. This value can only be used if there are no valid
240 // RTT estimates.
241 uint16_t _rtt;
242
niklase@google.com470e71d2011-07-07 08:21:25 +0000243};
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000244} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000245#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_H_