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