2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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.
11 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_H_
12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_H_
18 #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"
26 class ModuleRtpRtcpImpl;
28 class RTCPReceiver : public TMMBRHelp
31 RTCPReceiver(const int32_t id, Clock* clock,
32 ModuleRtpRtcpImpl* owner);
33 virtual ~RTCPReceiver();
35 void ChangeUniqueId(const int32_t id);
37 RTCPMethod Status() const;
38 int32_t SetRTCPStatus(const RTCPMethod method);
40 int64_t LastReceived();
41 int64_t LastReceivedReceiverReport() const;
43 void SetSsrcs(uint32_t main_ssrc,
44 const std::set<uint32_t>& registered_ssrcs);
45 void SetRelaySSRC( const uint32_t ssrc);
46 int32_t SetRemoteSSRC( const uint32_t ssrc);
47 uint32_t RemoteSSRC() const;
49 uint32_t RelaySSRC() const;
51 void RegisterRtcpObservers(RtcpIntraFrameObserver* intra_frame_callback,
52 RtcpBandwidthObserver* bandwidth_callback,
53 RtcpFeedback* feedback_callback);
55 int32_t IncomingRTCPPacket(
56 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation,
57 RTCPUtility::RTCPParserV2 *rtcpParser);
59 void TriggerCallbacksFromRTCPPacket(RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
62 int32_t CNAME(const uint32_t remoteSSRC,
63 char cName[RTCP_CNAME_SIZE]) const;
66 bool NTP(uint32_t* ReceivedNTPsecs,
67 uint32_t* ReceivedNTPfrac,
68 uint32_t* RTCPArrivalTimeSecs,
69 uint32_t* RTCPArrivalTimeFrac,
70 uint32_t* rtcp_timestamp) const;
72 bool LastReceivedXrReferenceTimeInfo(RtcpReceiveTimeInfo* info) const;
75 int32_t RTT(uint32_t remoteSSRC,
79 uint16_t* maxRTT) const;
81 int32_t ResetRTT(const uint32_t remoteSSRC);
83 int32_t SenderInfoReceived(RTCPSenderInfo* senderInfo) const;
85 bool GetAndResetXrRrRtt(uint16_t* rtt_ms);
88 int32_t StatisticsReceived(
89 std::vector<RTCPReportBlock>* receiveBlocks) const;
91 void GetPacketTypeCounter(RtcpPacketTypeCounter* packet_counter) const;
93 // 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);
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);
104 int32_t TMMBRReceived(const uint32_t size,
105 const uint32_t accNumCandidates,
106 TMMBRSet* candidateSet) const;
108 bool UpdateRTCPReceiveInformationTimers();
110 int32_t BoundingSet(bool &tmmbrOwner, TMMBRSet* boundingSetRec);
112 int32_t UpdateTMMBR();
114 void RegisterRtcpStatisticsCallback(RtcpStatisticsCallback* callback);
115 RtcpStatisticsCallback* GetRtcpStatisticsCallback();
118 RTCPHelp::RTCPReportBlockInformation* CreateReportBlockInformation(const uint32_t remoteSSRC);
119 RTCPHelp::RTCPReportBlockInformation* GetReportBlockInformation(const uint32_t remoteSSRC) const;
121 RTCPUtility::RTCPCnameInformation* CreateCnameInformation(const uint32_t remoteSSRC);
122 RTCPUtility::RTCPCnameInformation* GetCnameInformation(const uint32_t remoteSSRC) const;
124 RTCPHelp::RTCPReceiveInformation* CreateReceiveInformation(const uint32_t remoteSSRC);
125 RTCPHelp::RTCPReceiveInformation* GetReceiveInformation(const uint32_t remoteSSRC);
127 void UpdateReceiveInformation( RTCPHelp::RTCPReceiveInformation& receiveInformation);
129 void HandleSenderReceiverReport(RTCPUtility::RTCPParserV2& rtcpParser,
130 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
132 void HandleReportBlock(const RTCPUtility::RTCPPacket& rtcpPacket,
133 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation,
134 const uint32_t remoteSSRC,
135 const uint8_t numberOfReportBlocks);
137 void HandleSDES(RTCPUtility::RTCPParserV2& rtcpParser);
139 void HandleSDESChunk(RTCPUtility::RTCPParserV2& rtcpParser);
141 void HandleXrHeader(RTCPUtility::RTCPParserV2& parser,
142 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
144 void HandleXrReceiveReferenceTime(
145 RTCPUtility::RTCPParserV2& parser,
146 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
148 void HandleXrDlrrReportBlock(
149 RTCPUtility::RTCPParserV2& parser,
150 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
152 void HandleXrDlrrReportBlockItem(
153 const RTCPUtility::RTCPPacket& packet,
154 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
156 void HandleXRVOIPMetric(RTCPUtility::RTCPParserV2& rtcpParser,
157 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
159 void HandleNACK(RTCPUtility::RTCPParserV2& rtcpParser,
160 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
162 void HandleNACKItem(const RTCPUtility::RTCPPacket& rtcpPacket,
163 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
165 void HandleBYE(RTCPUtility::RTCPParserV2& rtcpParser);
167 void HandlePLI(RTCPUtility::RTCPParserV2& rtcpParser,
168 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
170 void HandleSLI(RTCPUtility::RTCPParserV2& rtcpParser,
171 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
173 void HandleSLIItem(const RTCPUtility::RTCPPacket& rtcpPacket,
174 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
176 void HandleRPSI(RTCPUtility::RTCPParserV2& rtcpParser,
177 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
179 void HandlePsfbApp(RTCPUtility::RTCPParserV2& rtcpParser,
180 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
182 void HandleREMBItem(RTCPUtility::RTCPParserV2& rtcpParser,
183 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
185 void HandleIJ(RTCPUtility::RTCPParserV2& rtcpParser,
186 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
188 void HandleIJItem(const RTCPUtility::RTCPPacket& rtcpPacket,
189 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
191 void HandleTMMBR(RTCPUtility::RTCPParserV2& rtcpParser,
192 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
194 void HandleTMMBRItem(RTCPHelp::RTCPReceiveInformation& receiveInfo,
195 const RTCPUtility::RTCPPacket& rtcpPacket,
196 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation,
197 const uint32_t senderSSRC);
199 void HandleTMMBN(RTCPUtility::RTCPParserV2& rtcpParser,
200 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
202 void HandleSR_REQ(RTCPUtility::RTCPParserV2& rtcpParser,
203 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
205 void HandleTMMBNItem(RTCPHelp::RTCPReceiveInformation& receiveInfo,
206 const RTCPUtility::RTCPPacket& rtcpPacket);
208 void HandleFIR(RTCPUtility::RTCPParserV2& rtcpParser,
209 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
211 void HandleFIRItem(RTCPHelp::RTCPReceiveInformation* receiveInfo,
212 const RTCPUtility::RTCPPacket& rtcpPacket,
213 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
215 void HandleAPP(RTCPUtility::RTCPParserV2& rtcpParser,
216 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
218 void HandleAPPItem(RTCPUtility::RTCPParserV2& rtcpParser,
219 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
222 typedef std::map<uint32_t, RTCPHelp::RTCPReceiveInformation*>
227 int64_t _lastReceived;
228 ModuleRtpRtcpImpl& _rtpRtcp;
230 CriticalSectionWrapper* _criticalSectionFeedbacks;
231 RtcpFeedback* _cbRtcpFeedback;
232 RtcpBandwidthObserver* _cbRtcpBandwidthObserver;
233 RtcpIntraFrameObserver* _cbRtcpIntraFrameObserver;
235 CriticalSectionWrapper* _criticalSectionRTCPReceiver;
237 uint32_t _remoteSSRC;
238 std::set<uint32_t> registered_ssrcs_;
240 // Received send report
241 RTCPSenderInfo _remoteSenderInfo;
242 // when did we receive the last send report
243 uint32_t _lastReceivedSRNTPsecs;
244 uint32_t _lastReceivedSRNTPfrac;
246 // Received XR receive time report.
247 RtcpReceiveTimeInfo _remoteXRReceiveTimeInfo;
248 // Time when the report was received.
249 uint32_t _lastReceivedXRNTPsecs;
250 uint32_t _lastReceivedXRNTPfrac;
251 // Estimated rtt, zero when there is no valid estimate.
252 uint16_t xr_rr_rtt_ms_;
254 // Received report blocks.
255 std::map<uint32_t, RTCPHelp::RTCPReportBlockInformation*>
256 _receivedReportBlockMap;
257 ReceivedInfoMap _receivedInfoMap;
258 std::map<uint32_t, RTCPUtility::RTCPCnameInformation*>
261 uint32_t _packetTimeOutMS;
263 // The last time we received an RTCP RR.
264 int64_t _lastReceivedRrMs;
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;
270 RtcpStatisticsCallback* stats_callback_;
272 RtcpPacketTypeCounter packet_type_counter_;
274 } // namespace webrtc
275 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_H_