niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 14 | #include <map> |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 17 | #include "typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | #include "rtp_utility.h" |
| 19 | #include "rtcp_utility.h" |
| 20 | #include "rtp_rtcp_defines.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | #include "rtcp_receiver_help.h" |
pwestin@webrtc.org | cac7878 | 2012-04-05 08:30:10 +0000 | [diff] [blame] | 22 | #include "tmmbr_help.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 25 | class ModuleRtpRtcpImpl; |
| 26 | |
pwestin@webrtc.org | cac7878 | 2012-04-05 08:30:10 +0000 | [diff] [blame] | 27 | class RTCPReceiver : public TMMBRHelp |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | { |
| 29 | public: |
stefan@webrtc.org | 20ed36d | 2013-01-17 14:01:20 +0000 | [diff] [blame] | 30 | RTCPReceiver(const WebRtc_Word32 id, Clock* clock, |
pwestin@webrtc.org | 0644b1d | 2011-12-01 15:42:31 +0000 | [diff] [blame] | 31 | ModuleRtpRtcpImpl* owner); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 32 | virtual ~RTCPReceiver(); |
| 33 | |
| 34 | void ChangeUniqueId(const WebRtc_Word32 id); |
| 35 | |
| 36 | RTCPMethod Status() const; |
| 37 | WebRtc_Word32 SetRTCPStatus(const RTCPMethod method); |
| 38 | |
pwestin@webrtc.org | 1853005 | 2012-07-03 10:41:54 +0000 | [diff] [blame] | 39 | WebRtc_Word64 LastReceived(); |
stefan@webrtc.org | b586507 | 2013-02-01 14:33:42 +0000 | [diff] [blame^] | 40 | WebRtc_Word64 LastReceivedReceiverReport() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 41 | |
| 42 | void SetSSRC( const WebRtc_UWord32 ssrc); |
| 43 | void SetRelaySSRC( const WebRtc_UWord32 ssrc); |
| 44 | WebRtc_Word32 SetRemoteSSRC( const WebRtc_UWord32 ssrc); |
| 45 | |
| 46 | WebRtc_UWord32 RelaySSRC() const; |
| 47 | |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 48 | void RegisterRtcpObservers(RtcpIntraFrameObserver* intra_frame_callback, |
| 49 | RtcpBandwidthObserver* bandwidth_callback, |
| 50 | RtcpFeedback* feedback_callback); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | |
| 52 | WebRtc_Word32 IncomingRTCPPacket(RTCPHelp::RTCPPacketInformation& rtcpPacketInformation, |
| 53 | RTCPUtility::RTCPParserV2 *rtcpParser); |
| 54 | |
| 55 | void TriggerCallbacksFromRTCPPacket(RTCPHelp::RTCPPacketInformation& rtcpPacketInformation); |
| 56 | |
| 57 | // get received cname |
| 58 | WebRtc_Word32 CNAME(const WebRtc_UWord32 remoteSSRC, |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 59 | char cName[RTCP_CNAME_SIZE]) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 60 | |
| 61 | // get received NTP |
| 62 | WebRtc_Word32 NTP(WebRtc_UWord32 *ReceivedNTPsecs, |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 63 | WebRtc_UWord32 *ReceivedNTPfrac, |
| 64 | WebRtc_UWord32 *RTCPArrivalTimeSecs, |
stefan@webrtc.org | 7c3523c | 2012-09-11 07:00:42 +0000 | [diff] [blame] | 65 | WebRtc_UWord32 *RTCPArrivalTimeFrac, |
| 66 | WebRtc_UWord32 *rtcp_timestamp) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | |
| 68 | // get rtt |
| 69 | WebRtc_Word32 RTT(const WebRtc_UWord32 remoteSSRC, |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 70 | WebRtc_UWord16* RTT, |
| 71 | WebRtc_UWord16* avgRTT, |
| 72 | WebRtc_UWord16* minRTT, |
| 73 | WebRtc_UWord16* maxRTT) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 74 | |
mflodman@webrtc.org | d7d4688 | 2012-02-14 12:49:59 +0000 | [diff] [blame] | 75 | WebRtc_UWord16 RTT() const; |
| 76 | |
| 77 | int SetRTT(WebRtc_UWord16 rtt); |
| 78 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | WebRtc_Word32 ResetRTT(const WebRtc_UWord32 remoteSSRC); |
| 80 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 81 | WebRtc_Word32 SenderInfoReceived(RTCPSenderInfo* senderInfo) const; |
| 82 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 83 | // get statistics |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 84 | WebRtc_Word32 StatisticsReceived( |
| 85 | std::vector<RTCPReportBlock>* receiveBlocks) const; |
| 86 | |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 87 | // Returns true if we haven't received an RTCP RR for several RTCP |
| 88 | // intervals, but only triggers true once. |
| 89 | bool RtcpRrTimeout(int64_t rtcp_interval_ms); |
| 90 | |
| 91 | // Returns true if we haven't received an RTCP RR telling the receive side |
| 92 | // has not received RTP packets for too long, i.e. extended highest sequence |
| 93 | // number hasn't increased for several RTCP intervals. The function only |
| 94 | // returns true once until a new RR is received. |
| 95 | bool RtcpRrSequenceNumberTimeout(int64_t rtcp_interval_ms); |
| 96 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 97 | // Get TMMBR |
| 98 | WebRtc_Word32 TMMBRReceived(const WebRtc_UWord32 size, |
pwestin@webrtc.org | 1da1ce0 | 2011-10-13 15:19:55 +0000 | [diff] [blame] | 99 | const WebRtc_UWord32 accNumCandidates, |
| 100 | TMMBRSet* candidateSet) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 101 | |
| 102 | bool UpdateRTCPReceiveInformationTimers(); |
| 103 | |
hta@webrtc.org | 65a4e4e | 2012-04-30 11:23:41 +0000 | [diff] [blame] | 104 | WebRtc_Word32 BoundingSet(bool &tmmbrOwner, TMMBRSet* boundingSetRec); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 105 | |
pwestin@webrtc.org | cac7878 | 2012-04-05 08:30:10 +0000 | [diff] [blame] | 106 | WebRtc_Word32 UpdateTMMBR(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | |
| 108 | WebRtc_Word32 SetPacketTimeout(const WebRtc_UWord32 timeoutMS); |
| 109 | void PacketTimeout(); |
| 110 | |
| 111 | protected: |
| 112 | RTCPHelp::RTCPReportBlockInformation* CreateReportBlockInformation(const WebRtc_UWord32 remoteSSRC); |
| 113 | RTCPHelp::RTCPReportBlockInformation* GetReportBlockInformation(const WebRtc_UWord32 remoteSSRC) const; |
| 114 | |
| 115 | RTCPUtility::RTCPCnameInformation* CreateCnameInformation(const WebRtc_UWord32 remoteSSRC); |
| 116 | RTCPUtility::RTCPCnameInformation* GetCnameInformation(const WebRtc_UWord32 remoteSSRC) const; |
| 117 | |
| 118 | RTCPHelp::RTCPReceiveInformation* CreateReceiveInformation(const WebRtc_UWord32 remoteSSRC); |
| 119 | RTCPHelp::RTCPReceiveInformation* GetReceiveInformation(const WebRtc_UWord32 remoteSSRC); |
| 120 | |
| 121 | void UpdateReceiveInformation( RTCPHelp::RTCPReceiveInformation& receiveInformation); |
| 122 | |
| 123 | void HandleSenderReceiverReport(RTCPUtility::RTCPParserV2& rtcpParser, |
| 124 | RTCPHelp::RTCPPacketInformation& rtcpPacketInformation); |
| 125 | |
| 126 | void HandleReportBlock(const RTCPUtility::RTCPPacket& rtcpPacket, |
| 127 | RTCPHelp::RTCPPacketInformation& rtcpPacketInformation, |
| 128 | const WebRtc_UWord32 remoteSSRC, |
| 129 | const WebRtc_UWord8 numberOfReportBlocks); |
| 130 | |
| 131 | void HandleSDES(RTCPUtility::RTCPParserV2& rtcpParser); |
| 132 | |
| 133 | void HandleSDESChunk(RTCPUtility::RTCPParserV2& rtcpParser); |
| 134 | |
| 135 | void HandleXRVOIPMetric(RTCPUtility::RTCPParserV2& rtcpParser, |
| 136 | RTCPHelp::RTCPPacketInformation& rtcpPacketInformation); |
| 137 | |
| 138 | void HandleNACK(RTCPUtility::RTCPParserV2& rtcpParser, |
| 139 | RTCPHelp::RTCPPacketInformation& rtcpPacketInformation); |
| 140 | |
| 141 | void HandleNACKItem(const RTCPUtility::RTCPPacket& rtcpPacket, |
| 142 | RTCPHelp::RTCPPacketInformation& rtcpPacketInformation); |
| 143 | |
| 144 | void HandleBYE(RTCPUtility::RTCPParserV2& rtcpParser); |
| 145 | |
| 146 | void HandlePLI(RTCPUtility::RTCPParserV2& rtcpParser, |
| 147 | RTCPHelp::RTCPPacketInformation& rtcpPacketInformation); |
| 148 | |
| 149 | void HandleSLI(RTCPUtility::RTCPParserV2& rtcpParser, |
| 150 | RTCPHelp::RTCPPacketInformation& rtcpPacketInformation); |
| 151 | |
| 152 | void HandleSLIItem(const RTCPUtility::RTCPPacket& rtcpPacket, |
| 153 | RTCPHelp::RTCPPacketInformation& rtcpPacketInformation); |
| 154 | |
| 155 | void HandleRPSI(RTCPUtility::RTCPParserV2& rtcpParser, |
| 156 | RTCPHelp::RTCPPacketInformation& rtcpPacketInformation); |
| 157 | |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 158 | void HandlePsfbApp(RTCPUtility::RTCPParserV2& rtcpParser, |
| 159 | RTCPHelp::RTCPPacketInformation& rtcpPacketInformation); |
| 160 | |
| 161 | void HandleREMBItem(RTCPUtility::RTCPParserV2& rtcpParser, |
| 162 | RTCPHelp::RTCPPacketInformation& rtcpPacketInformation); |
| 163 | |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 164 | void HandleIJ(RTCPUtility::RTCPParserV2& rtcpParser, |
| 165 | RTCPHelp::RTCPPacketInformation& rtcpPacketInformation); |
| 166 | |
| 167 | void HandleIJItem(const RTCPUtility::RTCPPacket& rtcpPacket, |
| 168 | RTCPHelp::RTCPPacketInformation& rtcpPacketInformation); |
| 169 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 170 | void HandleTMMBR(RTCPUtility::RTCPParserV2& rtcpParser, |
| 171 | RTCPHelp::RTCPPacketInformation& rtcpPacketInformation); |
| 172 | |
| 173 | void HandleTMMBRItem(RTCPHelp::RTCPReceiveInformation& receiveInfo, |
| 174 | const RTCPUtility::RTCPPacket& rtcpPacket, |
| 175 | RTCPHelp::RTCPPacketInformation& rtcpPacketInformation, |
| 176 | const WebRtc_UWord32 senderSSRC); |
| 177 | |
hta@webrtc.org | 9d54cd1 | 2012-04-30 08:24:55 +0000 | [diff] [blame] | 178 | void HandleTMMBN(RTCPUtility::RTCPParserV2& rtcpParser, |
| 179 | RTCPHelp::RTCPPacketInformation& rtcpPacketInformation); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 180 | |
| 181 | void HandleSR_REQ(RTCPUtility::RTCPParserV2& rtcpParser, |
| 182 | RTCPHelp::RTCPPacketInformation& rtcpPacketInformation); |
| 183 | |
| 184 | void HandleTMMBNItem(RTCPHelp::RTCPReceiveInformation& receiveInfo, |
| 185 | const RTCPUtility::RTCPPacket& rtcpPacket); |
| 186 | |
| 187 | void HandleFIR(RTCPUtility::RTCPParserV2& rtcpParser, |
| 188 | RTCPHelp::RTCPPacketInformation& rtcpPacketInformation); |
| 189 | |
pwestin@webrtc.org | b2179c2 | 2012-05-21 12:00:49 +0000 | [diff] [blame] | 190 | void HandleFIRItem(RTCPHelp::RTCPReceiveInformation* receiveInfo, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 191 | const RTCPUtility::RTCPPacket& rtcpPacket, |
| 192 | RTCPHelp::RTCPPacketInformation& rtcpPacketInformation); |
| 193 | |
| 194 | void HandleAPP(RTCPUtility::RTCPParserV2& rtcpParser, |
| 195 | RTCPHelp::RTCPPacketInformation& rtcpPacketInformation); |
| 196 | |
| 197 | void HandleAPPItem(RTCPUtility::RTCPParserV2& rtcpParser, |
| 198 | RTCPHelp::RTCPPacketInformation& rtcpPacketInformation); |
| 199 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 200 | private: |
stefan@webrtc.org | b586507 | 2013-02-01 14:33:42 +0000 | [diff] [blame^] | 201 | typedef std::map<WebRtc_UWord32, RTCPHelp::RTCPReceiveInformation*> |
| 202 | ReceivedInfoMap; |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 203 | WebRtc_Word32 _id; |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 204 | Clock* _clock; |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 205 | RTCPMethod _method; |
pwestin@webrtc.org | 1853005 | 2012-07-03 10:41:54 +0000 | [diff] [blame] | 206 | WebRtc_Word64 _lastReceived; |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 207 | ModuleRtpRtcpImpl& _rtpRtcp; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 208 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 209 | CriticalSectionWrapper* _criticalSectionFeedbacks; |
| 210 | RtcpFeedback* _cbRtcpFeedback; |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 211 | RtcpBandwidthObserver* _cbRtcpBandwidthObserver; |
| 212 | RtcpIntraFrameObserver* _cbRtcpIntraFrameObserver; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 213 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 214 | CriticalSectionWrapper* _criticalSectionRTCPReceiver; |
| 215 | WebRtc_UWord32 _SSRC; |
| 216 | WebRtc_UWord32 _remoteSSRC; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 217 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 218 | // Received send report |
| 219 | RTCPSenderInfo _remoteSenderInfo; |
| 220 | // when did we receive the last send report |
| 221 | WebRtc_UWord32 _lastReceivedSRNTPsecs; |
| 222 | WebRtc_UWord32 _lastReceivedSRNTPfrac; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 223 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 224 | // Received report blocks. |
| 225 | std::map<WebRtc_UWord32, RTCPHelp::RTCPReportBlockInformation*> |
| 226 | _receivedReportBlockMap; |
stefan@webrtc.org | b586507 | 2013-02-01 14:33:42 +0000 | [diff] [blame^] | 227 | ReceivedInfoMap _receivedInfoMap; |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 228 | std::map<WebRtc_UWord32, RTCPUtility::RTCPCnameInformation*> |
| 229 | _receivedCnameMap; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 230 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 231 | WebRtc_UWord32 _packetTimeOutMS; |
mflodman@webrtc.org | d7d4688 | 2012-02-14 12:49:59 +0000 | [diff] [blame] | 232 | |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 233 | // The last time we received an RTCP RR. |
| 234 | int64_t _lastReceivedRrMs; |
| 235 | |
| 236 | // The time we last received an RTCP RR telling we have ssuccessfully |
| 237 | // delivered RTP packet to the remote side. |
| 238 | int64_t _lastIncreasedSequenceNumberMs; |
| 239 | |
mflodman@webrtc.org | d7d4688 | 2012-02-14 12:49:59 +0000 | [diff] [blame] | 240 | // Externally set RTT. This value can only be used if there are no valid |
| 241 | // RTT estimates. |
| 242 | WebRtc_UWord16 _rtt; |
| 243 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 244 | }; |
| 245 | } // namespace webrtc |
| 246 | #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_H_ |