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_SENDER_H_ |
| 12 | #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_SENDER_H_ |
| 13 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 14 | #include <map> |
| 15 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 16 | #include "typedefs.h" |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 17 | #include "rtcp_utility.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | #include "rtp_utility.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 19 | #include "rtp_rtcp_defines.h" |
stefan@webrtc.org | 9354cc9 | 2012-06-07 08:10:14 +0000 | [diff] [blame] | 20 | #include "scoped_ptr.h" |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 21 | #include "tmmbr_help.h" |
stefan@webrtc.org | 9354cc9 | 2012-06-07 08:10:14 +0000 | [diff] [blame] | 22 | #include "modules/remote_bitrate_estimator/include/bwe_defines.h" |
| 23 | #include "modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | |
| 25 | namespace webrtc { |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 26 | |
| 27 | class ModuleRtpRtcpImpl; |
| 28 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | class RTCPSender |
| 30 | { |
| 31 | public: |
pwestin@webrtc.org | 0644b1d | 2011-12-01 15:42:31 +0000 | [diff] [blame] | 32 | RTCPSender(const WebRtc_Word32 id, const bool audio, |
| 33 | RtpRtcpClock* clock, ModuleRtpRtcpImpl* owner); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | virtual ~RTCPSender(); |
| 35 | |
| 36 | void ChangeUniqueId(const WebRtc_Word32 id); |
| 37 | |
| 38 | WebRtc_Word32 Init(); |
| 39 | |
| 40 | WebRtc_Word32 RegisterSendTransport(Transport* outgoingTransport); |
| 41 | |
| 42 | RTCPMethod Status() const; |
| 43 | WebRtc_Word32 SetRTCPStatus(const RTCPMethod method); |
| 44 | |
| 45 | bool Sending() const; |
| 46 | WebRtc_Word32 SetSendingStatus(const bool enabled); // combine the functions |
| 47 | |
| 48 | WebRtc_Word32 SetNackStatus(const bool enable); |
| 49 | |
stefan@webrtc.org | 7c3523c | 2012-09-11 07:00:42 +0000 | [diff] [blame] | 50 | void SetStartTimestamp(uint32_t start_timestamp); |
| 51 | |
| 52 | void SetLastRtpTime(uint32_t rtp_timestamp, |
| 53 | int64_t capture_time_ms); |
| 54 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | void SetSSRC( const WebRtc_UWord32 ssrc); |
| 56 | |
| 57 | WebRtc_Word32 SetRemoteSSRC( const WebRtc_UWord32 ssrc); |
| 58 | |
| 59 | WebRtc_Word32 SetCameraDelay(const WebRtc_Word32 delayMS); |
| 60 | |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 61 | WebRtc_Word32 CNAME(char cName[RTCP_CNAME_SIZE]); |
| 62 | WebRtc_Word32 SetCNAME(const char cName[RTCP_CNAME_SIZE]); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | |
| 64 | WebRtc_Word32 AddMixedCNAME(const WebRtc_UWord32 SSRC, |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 65 | const char cName[RTCP_CNAME_SIZE]); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 66 | |
| 67 | WebRtc_Word32 RemoveMixedCNAME(const WebRtc_UWord32 SSRC); |
| 68 | |
| 69 | WebRtc_UWord32 SendTimeOfSendReport(const WebRtc_UWord32 sendReport); |
| 70 | |
| 71 | bool TimeToSendRTCPReport(const bool sendKeyframeBeforeRTP = false) const; |
| 72 | |
| 73 | WebRtc_UWord32 LastSendReport(WebRtc_UWord32& lastRTCPTime); |
| 74 | |
| 75 | WebRtc_Word32 SendRTCP(const WebRtc_UWord32 rtcpPacketTypeFlags, |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 76 | const WebRtc_Word32 nackSize = 0, |
| 77 | const WebRtc_UWord16* nackList = 0, |
pwestin@webrtc.org | 5e95481 | 2012-02-10 12:13:12 +0000 | [diff] [blame] | 78 | const bool repeat = false, |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 79 | const WebRtc_UWord64 pictureID = 0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | |
| 81 | WebRtc_Word32 AddReportBlock(const WebRtc_UWord32 SSRC, |
| 82 | const RTCPReportBlock* receiveBlock); |
| 83 | |
| 84 | WebRtc_Word32 RemoveReportBlock(const WebRtc_UWord32 SSRC); |
| 85 | |
| 86 | /* |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 87 | * REMB |
| 88 | */ |
| 89 | bool REMB() const; |
| 90 | |
| 91 | WebRtc_Word32 SetREMBStatus(const bool enable); |
| 92 | |
| 93 | WebRtc_Word32 SetREMBData(const WebRtc_UWord32 bitrate, |
| 94 | const WebRtc_UWord8 numberOfSSRC, |
| 95 | const WebRtc_UWord32* SSRC); |
mflodman@webrtc.org | 84dc3d1 | 2011-12-22 10:26:13 +0000 | [diff] [blame] | 96 | |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 97 | /* |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | * TMMBR |
| 99 | */ |
| 100 | bool TMMBR() const; |
| 101 | |
| 102 | WebRtc_Word32 SetTMMBRStatus(const bool enable); |
| 103 | |
| 104 | WebRtc_Word32 SetTMMBN(const TMMBRSet* boundingSet, |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 105 | const WebRtc_UWord32 maxBitrateKbit); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 106 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | /* |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 108 | * Extended jitter report |
| 109 | */ |
| 110 | bool IJ() const; |
| 111 | |
| 112 | WebRtc_Word32 SetIJStatus(const bool enable); |
| 113 | |
| 114 | /* |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 115 | * |
| 116 | */ |
| 117 | |
| 118 | WebRtc_Word32 SetApplicationSpecificData(const WebRtc_UWord8 subType, |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 119 | const WebRtc_UWord32 name, |
| 120 | const WebRtc_UWord8* data, |
| 121 | const WebRtc_UWord16 length); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 122 | |
| 123 | WebRtc_Word32 SetRTCPVoIPMetrics(const RTCPVoIPMetric* VoIPMetric); |
| 124 | |
| 125 | WebRtc_Word32 SetCSRCs(const WebRtc_UWord32 arrOfCSRC[kRtpCsrcSize], |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 126 | const WebRtc_UWord8 arrLength); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 127 | |
| 128 | WebRtc_Word32 SetCSRCStatus(const bool include); |
| 129 | |
stefan@webrtc.org | 9354cc9 | 2012-06-07 08:10:14 +0000 | [diff] [blame] | 130 | void SetTargetBitrate(unsigned int target_bitrate); |
mflodman@webrtc.org | 117c119 | 2012-01-13 08:52:58 +0000 | [diff] [blame] | 131 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 132 | private: |
| 133 | WebRtc_Word32 SendToNetwork(const WebRtc_UWord8* dataBuffer, |
stefan@webrtc.org | 439be29 | 2012-02-16 14:45:37 +0000 | [diff] [blame] | 134 | const WebRtc_UWord16 length); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 135 | |
| 136 | void UpdatePacketRate(); |
| 137 | |
| 138 | WebRtc_Word32 AddReportBlocks(WebRtc_UWord8* rtcpbuffer, |
| 139 | WebRtc_UWord32& pos, |
| 140 | WebRtc_UWord8& numberOfReportBlocks, |
| 141 | const RTCPReportBlock* received, |
| 142 | const WebRtc_UWord32 NTPsec, |
| 143 | const WebRtc_UWord32 NTPfrac); |
| 144 | |
| 145 | WebRtc_Word32 BuildSR(WebRtc_UWord8* rtcpbuffer, |
| 146 | WebRtc_UWord32& pos, |
| 147 | const WebRtc_UWord32 NTPsec, |
| 148 | const WebRtc_UWord32 NTPfrac, |
| 149 | const RTCPReportBlock* received = NULL); |
| 150 | |
| 151 | WebRtc_Word32 BuildRR(WebRtc_UWord8* rtcpbuffer, |
| 152 | WebRtc_UWord32& pos, |
| 153 | const WebRtc_UWord32 NTPsec, |
| 154 | const WebRtc_UWord32 NTPfrac, |
| 155 | const RTCPReportBlock* received = NULL); |
| 156 | |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 157 | WebRtc_Word32 BuildExtendedJitterReport( |
| 158 | WebRtc_UWord8* rtcpbuffer, |
| 159 | WebRtc_UWord32& pos, |
| 160 | const WebRtc_UWord32 jitterTransmissionTimeOffset); |
| 161 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 162 | WebRtc_Word32 BuildSDEC(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos); |
| 163 | WebRtc_Word32 BuildPLI(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos); |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 164 | WebRtc_Word32 BuildREMB(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos); |
| 165 | WebRtc_Word32 BuildTMMBR(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 166 | WebRtc_Word32 BuildTMMBN(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos); |
| 167 | WebRtc_Word32 BuildAPP(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos); |
| 168 | WebRtc_Word32 BuildVoIPMetric(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos); |
| 169 | WebRtc_Word32 BuildBYE(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos); |
| 170 | WebRtc_Word32 BuildFIR(WebRtc_UWord8* rtcpbuffer, |
pwestin@webrtc.org | 5e95481 | 2012-02-10 12:13:12 +0000 | [diff] [blame] | 171 | WebRtc_UWord32& pos, |
| 172 | bool repeat); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 173 | WebRtc_Word32 BuildSLI(WebRtc_UWord8* rtcpbuffer, |
| 174 | WebRtc_UWord32& pos, |
| 175 | const WebRtc_UWord8 pictureID); |
| 176 | WebRtc_Word32 BuildRPSI(WebRtc_UWord8* rtcpbuffer, |
| 177 | WebRtc_UWord32& pos, |
| 178 | const WebRtc_UWord64 pictureID, |
| 179 | const WebRtc_UWord8 payloadType); |
| 180 | |
| 181 | WebRtc_Word32 BuildNACK(WebRtc_UWord8* rtcpbuffer, |
| 182 | WebRtc_UWord32& pos, |
| 183 | const WebRtc_Word32 nackSize, |
| 184 | const WebRtc_UWord16* nackList); |
| 185 | |
| 186 | private: |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 187 | WebRtc_Word32 _id; |
| 188 | const bool _audio; |
pwestin@webrtc.org | 0644b1d | 2011-12-01 15:42:31 +0000 | [diff] [blame] | 189 | RtpRtcpClock& _clock; |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 190 | RTCPMethod _method; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 191 | |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 192 | ModuleRtpRtcpImpl& _rtpRtcp; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 193 | |
henrike@webrtc.org | 65573f2 | 2011-12-13 19:17:27 +0000 | [diff] [blame] | 194 | CriticalSectionWrapper* _criticalSectionTransport; |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 195 | Transport* _cbTransport; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 196 | |
henrike@webrtc.org | 65573f2 | 2011-12-13 19:17:27 +0000 | [diff] [blame] | 197 | CriticalSectionWrapper* _criticalSectionRTCPSender; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 198 | bool _usingNack; |
| 199 | bool _sending; |
| 200 | bool _sendTMMBN; |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 201 | bool _REMB; |
| 202 | bool _sendREMB; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 203 | bool _TMMBR; |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 204 | bool _IJ; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 205 | |
pwestin@webrtc.org | 1853005 | 2012-07-03 10:41:54 +0000 | [diff] [blame] | 206 | WebRtc_Word64 _nextTimeToSendRTCP; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 207 | |
stefan@webrtc.org | 7c3523c | 2012-09-11 07:00:42 +0000 | [diff] [blame] | 208 | uint32_t start_timestamp_; |
| 209 | uint32_t last_rtp_timestamp_; |
| 210 | int64_t last_frame_capture_time_ms_; |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 211 | WebRtc_UWord32 _SSRC; |
| 212 | WebRtc_UWord32 _remoteSSRC; // SSRC that we receive on our RTP channel |
| 213 | char _CNAME[RTCP_CNAME_SIZE]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 214 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 215 | std::map<WebRtc_UWord32, RTCPReportBlock*> _reportBlocks; |
| 216 | std::map<WebRtc_UWord32, RTCPUtility::RTCPCnameInformation*> _csrcCNAMEs; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 217 | |
| 218 | WebRtc_Word32 _cameraDelayMS; |
| 219 | |
| 220 | // Sent |
| 221 | WebRtc_UWord32 _lastSendReport[RTCP_NUMBER_OF_SR]; // allow packet loss and RTT above 1 sec |
| 222 | WebRtc_UWord32 _lastRTCPTime[RTCP_NUMBER_OF_SR]; |
| 223 | |
| 224 | // send CSRCs |
| 225 | WebRtc_UWord8 _CSRCs; |
| 226 | WebRtc_UWord32 _CSRC[kRtpCsrcSize]; |
| 227 | bool _includeCSRCs; |
| 228 | |
| 229 | // Full intra request |
| 230 | WebRtc_UWord8 _sequenceNumberFIR; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 231 | |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 232 | // REMB |
| 233 | WebRtc_UWord8 _lengthRembSSRC; |
| 234 | WebRtc_UWord8 _sizeRembSSRC; |
| 235 | WebRtc_UWord32* _rembSSRC; |
| 236 | WebRtc_UWord32 _rembBitrate; |
| 237 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 238 | TMMBRHelp _tmmbrHelp; |
| 239 | WebRtc_UWord32 _tmmbr_Send; |
| 240 | WebRtc_UWord32 _packetOH_Send; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 241 | |
| 242 | // APP |
| 243 | bool _appSend; |
| 244 | WebRtc_UWord8 _appSubType; |
| 245 | WebRtc_UWord32 _appName; |
| 246 | WebRtc_UWord8* _appData; |
| 247 | WebRtc_UWord16 _appLength; |
| 248 | |
| 249 | // XR VoIP metric |
| 250 | bool _xrSendVoIPMetric; |
| 251 | RTCPVoIPMetric _xrVoIPMetric; |
| 252 | }; |
| 253 | } // namespace webrtc |
| 254 | |
| 255 | #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_SENDER_H_ |