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" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | #include "remote_rate_control.h" |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 21 | #include "tmmbr_help.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 24 | |
| 25 | class ModuleRtpRtcpImpl; |
| 26 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | class RTCPSender |
| 28 | { |
| 29 | public: |
pwestin@webrtc.org | 0644b1d | 2011-12-01 15:42:31 +0000 | [diff] [blame] | 30 | RTCPSender(const WebRtc_Word32 id, const bool audio, |
| 31 | RtpRtcpClock* clock, ModuleRtpRtcpImpl* owner); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 32 | virtual ~RTCPSender(); |
| 33 | |
| 34 | void ChangeUniqueId(const WebRtc_Word32 id); |
| 35 | |
| 36 | WebRtc_Word32 Init(); |
| 37 | |
| 38 | WebRtc_Word32 RegisterSendTransport(Transport* outgoingTransport); |
| 39 | |
| 40 | RTCPMethod Status() const; |
| 41 | WebRtc_Word32 SetRTCPStatus(const RTCPMethod method); |
| 42 | |
| 43 | bool Sending() const; |
| 44 | WebRtc_Word32 SetSendingStatus(const bool enabled); // combine the functions |
| 45 | |
| 46 | WebRtc_Word32 SetNackStatus(const bool enable); |
| 47 | |
| 48 | void SetSSRC( const WebRtc_UWord32 ssrc); |
| 49 | |
| 50 | WebRtc_Word32 SetRemoteSSRC( const WebRtc_UWord32 ssrc); |
| 51 | |
| 52 | WebRtc_Word32 SetCameraDelay(const WebRtc_Word32 delayMS); |
| 53 | |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame^] | 54 | WebRtc_Word32 CNAME(char cName[RTCP_CNAME_SIZE]); |
| 55 | WebRtc_Word32 SetCNAME(const char cName[RTCP_CNAME_SIZE]); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 56 | |
| 57 | WebRtc_Word32 AddMixedCNAME(const WebRtc_UWord32 SSRC, |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame^] | 58 | const char cName[RTCP_CNAME_SIZE]); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | |
| 60 | WebRtc_Word32 RemoveMixedCNAME(const WebRtc_UWord32 SSRC); |
| 61 | |
| 62 | WebRtc_UWord32 SendTimeOfSendReport(const WebRtc_UWord32 sendReport); |
| 63 | |
| 64 | bool TimeToSendRTCPReport(const bool sendKeyframeBeforeRTP = false) const; |
| 65 | |
| 66 | WebRtc_UWord32 LastSendReport(WebRtc_UWord32& lastRTCPTime); |
| 67 | |
| 68 | WebRtc_Word32 SendRTCP(const WebRtc_UWord32 rtcpPacketTypeFlags, |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 69 | const WebRtc_Word32 nackSize = 0, |
| 70 | const WebRtc_UWord16* nackList = 0, |
| 71 | const WebRtc_UWord32 RTT = 0, |
| 72 | const WebRtc_UWord64 pictureID = 0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 73 | |
| 74 | WebRtc_Word32 AddReportBlock(const WebRtc_UWord32 SSRC, |
| 75 | const RTCPReportBlock* receiveBlock); |
| 76 | |
| 77 | WebRtc_Word32 RemoveReportBlock(const WebRtc_UWord32 SSRC); |
| 78 | |
| 79 | /* |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 80 | * REMB |
| 81 | */ |
| 82 | bool REMB() const; |
| 83 | |
| 84 | WebRtc_Word32 SetREMBStatus(const bool enable); |
| 85 | |
| 86 | WebRtc_Word32 SetREMBData(const WebRtc_UWord32 bitrate, |
| 87 | const WebRtc_UWord8 numberOfSSRC, |
| 88 | const WebRtc_UWord32* SSRC); |
mflodman@webrtc.org | 84dc3d1 | 2011-12-22 10:26:13 +0000 | [diff] [blame] | 89 | |
| 90 | bool SetRemoteBitrateObserver(RtpRemoteBitrateObserver* observer); |
| 91 | |
| 92 | void UpdateRemoteBitrateEstimate(unsigned int target_bitrate); |
| 93 | |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 94 | /* |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 95 | * TMMBR |
| 96 | */ |
| 97 | bool TMMBR() const; |
| 98 | |
| 99 | WebRtc_Word32 SetTMMBRStatus(const bool enable); |
| 100 | |
| 101 | WebRtc_Word32 SetTMMBN(const TMMBRSet* boundingSet, |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 102 | const WebRtc_UWord32 maxBitrateKbit); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | |
| 104 | WebRtc_Word32 RequestTMMBR(const WebRtc_UWord32 estimatedBW, |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 105 | const WebRtc_UWord32 packetOH); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 106 | |
| 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 | |
| 130 | /* |
| 131 | * New bandwidth estimation |
| 132 | */ |
| 133 | |
| 134 | RateControlRegion UpdateOverUseState(const RateControlInput& rateControlInput, bool& firstOverUse); |
| 135 | |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 136 | WebRtc_UWord32 CalculateNewTargetBitrate(WebRtc_UWord32 RTT); |
| 137 | |
mflodman@webrtc.org | 117c119 | 2012-01-13 08:52:58 +0000 | [diff] [blame] | 138 | // Returns true if there is a valid estimate of the incoming bitrate, false |
| 139 | // otherwise. |
| 140 | bool ValidBitrateEstimate(); |
| 141 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 142 | private: |
| 143 | WebRtc_Word32 SendToNetwork(const WebRtc_UWord8* dataBuffer, |
| 144 | const WebRtc_UWord16 length); |
| 145 | |
| 146 | void UpdatePacketRate(); |
| 147 | |
| 148 | WebRtc_Word32 AddReportBlocks(WebRtc_UWord8* rtcpbuffer, |
| 149 | WebRtc_UWord32& pos, |
| 150 | WebRtc_UWord8& numberOfReportBlocks, |
| 151 | const RTCPReportBlock* received, |
| 152 | const WebRtc_UWord32 NTPsec, |
| 153 | const WebRtc_UWord32 NTPfrac); |
| 154 | |
| 155 | WebRtc_Word32 BuildSR(WebRtc_UWord8* rtcpbuffer, |
| 156 | WebRtc_UWord32& pos, |
| 157 | const WebRtc_UWord32 NTPsec, |
| 158 | const WebRtc_UWord32 NTPfrac, |
| 159 | const RTCPReportBlock* received = NULL); |
| 160 | |
| 161 | WebRtc_Word32 BuildRR(WebRtc_UWord8* rtcpbuffer, |
| 162 | WebRtc_UWord32& pos, |
| 163 | const WebRtc_UWord32 NTPsec, |
| 164 | const WebRtc_UWord32 NTPfrac, |
| 165 | const RTCPReportBlock* received = NULL); |
| 166 | |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 167 | WebRtc_Word32 BuildExtendedJitterReport( |
| 168 | WebRtc_UWord8* rtcpbuffer, |
| 169 | WebRtc_UWord32& pos, |
| 170 | const WebRtc_UWord32 jitterTransmissionTimeOffset); |
| 171 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 172 | WebRtc_Word32 BuildSDEC(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos); |
| 173 | WebRtc_Word32 BuildPLI(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos); |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 174 | WebRtc_Word32 BuildREMB(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos); |
| 175 | WebRtc_Word32 BuildTMMBR(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 176 | WebRtc_Word32 BuildTMMBN(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos); |
| 177 | WebRtc_Word32 BuildAPP(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos); |
| 178 | WebRtc_Word32 BuildVoIPMetric(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos); |
| 179 | WebRtc_Word32 BuildBYE(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos); |
| 180 | WebRtc_Word32 BuildFIR(WebRtc_UWord8* rtcpbuffer, |
| 181 | WebRtc_UWord32& pos, |
| 182 | const WebRtc_UWord32 RTT); |
| 183 | WebRtc_Word32 BuildSLI(WebRtc_UWord8* rtcpbuffer, |
| 184 | WebRtc_UWord32& pos, |
| 185 | const WebRtc_UWord8 pictureID); |
| 186 | WebRtc_Word32 BuildRPSI(WebRtc_UWord8* rtcpbuffer, |
| 187 | WebRtc_UWord32& pos, |
| 188 | const WebRtc_UWord64 pictureID, |
| 189 | const WebRtc_UWord8 payloadType); |
| 190 | |
| 191 | WebRtc_Word32 BuildNACK(WebRtc_UWord8* rtcpbuffer, |
| 192 | WebRtc_UWord32& pos, |
| 193 | const WebRtc_Word32 nackSize, |
| 194 | const WebRtc_UWord16* nackList); |
| 195 | |
| 196 | private: |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 197 | WebRtc_Word32 _id; |
| 198 | const bool _audio; |
pwestin@webrtc.org | 0644b1d | 2011-12-01 15:42:31 +0000 | [diff] [blame] | 199 | RtpRtcpClock& _clock; |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 200 | RTCPMethod _method; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 201 | |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 202 | ModuleRtpRtcpImpl& _rtpRtcp; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 203 | |
henrike@webrtc.org | 65573f2 | 2011-12-13 19:17:27 +0000 | [diff] [blame] | 204 | CriticalSectionWrapper* _criticalSectionTransport; |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 205 | Transport* _cbTransport; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 206 | |
henrike@webrtc.org | 65573f2 | 2011-12-13 19:17:27 +0000 | [diff] [blame] | 207 | CriticalSectionWrapper* _criticalSectionRTCPSender; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 208 | bool _usingNack; |
| 209 | bool _sending; |
| 210 | bool _sendTMMBN; |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 211 | bool _REMB; |
| 212 | bool _sendREMB; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 213 | bool _TMMBR; |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 214 | bool _IJ; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 215 | |
| 216 | WebRtc_UWord32 _nextTimeToSendRTCP; |
| 217 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 218 | WebRtc_UWord32 _SSRC; |
| 219 | WebRtc_UWord32 _remoteSSRC; // SSRC that we receive on our RTP channel |
| 220 | char _CNAME[RTCP_CNAME_SIZE]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 221 | |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 222 | std::map<WebRtc_UWord32, RTCPReportBlock*> _reportBlocks; |
| 223 | std::map<WebRtc_UWord32, RTCPUtility::RTCPCnameInformation*> _csrcCNAMEs; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 224 | |
| 225 | WebRtc_Word32 _cameraDelayMS; |
| 226 | |
| 227 | // Sent |
| 228 | WebRtc_UWord32 _lastSendReport[RTCP_NUMBER_OF_SR]; // allow packet loss and RTT above 1 sec |
| 229 | WebRtc_UWord32 _lastRTCPTime[RTCP_NUMBER_OF_SR]; |
| 230 | |
| 231 | // send CSRCs |
| 232 | WebRtc_UWord8 _CSRCs; |
| 233 | WebRtc_UWord32 _CSRC[kRtpCsrcSize]; |
| 234 | bool _includeCSRCs; |
| 235 | |
| 236 | // Full intra request |
| 237 | WebRtc_UWord8 _sequenceNumberFIR; |
| 238 | WebRtc_UWord32 _lastTimeFIR; |
| 239 | |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 240 | // REMB |
| 241 | WebRtc_UWord8 _lengthRembSSRC; |
| 242 | WebRtc_UWord8 _sizeRembSSRC; |
| 243 | WebRtc_UWord32* _rembSSRC; |
| 244 | WebRtc_UWord32 _rembBitrate; |
mflodman@webrtc.org | 84dc3d1 | 2011-12-22 10:26:13 +0000 | [diff] [blame] | 245 | RtpRemoteBitrateObserver* _bitrate_observer; |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 246 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 247 | TMMBRHelp _tmmbrHelp; |
| 248 | WebRtc_UWord32 _tmmbr_Send; |
| 249 | WebRtc_UWord32 _packetOH_Send; |
| 250 | RemoteRateControl _remoteRateControl; |
| 251 | |
| 252 | // APP |
| 253 | bool _appSend; |
| 254 | WebRtc_UWord8 _appSubType; |
| 255 | WebRtc_UWord32 _appName; |
| 256 | WebRtc_UWord8* _appData; |
| 257 | WebRtc_UWord16 _appLength; |
| 258 | |
| 259 | // XR VoIP metric |
| 260 | bool _xrSendVoIPMetric; |
| 261 | RTCPVoIPMetric _xrVoIPMetric; |
| 262 | }; |
| 263 | } // namespace webrtc |
| 264 | |
| 265 | #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_SENDER_H_ |