1 /* 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 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_INTERFACE_RTP_RTCP_DEFINES_H_ 12 #define WEBRTC_MODULES_RTP_RTCP_INTERFACE_RTP_RTCP_DEFINES_H_ 13 14 #include <stddef.h> 15 #include <list> 16 17 #include "webrtc/modules/interface/module_common_types.h" 18 #include "webrtc/system_wrappers/interface/clock.h" 19 #include "webrtc/typedefs.h" 20 21 #define RTCP_CNAME_SIZE 256 // RFC 3550 page 44, including null termination 22 #define IP_PACKET_SIZE 1500 // we assume ethernet 23 #define MAX_NUMBER_OF_PARALLEL_TELEPHONE_EVENTS 10 24 #define TIMEOUT_SEI_MESSAGES_MS 30000 // in milliseconds 25 26 namespace webrtc { 27 28 const int kVideoPayloadTypeFrequency = 90000; 29 30 // Minimum RTP header size in bytes. 31 const uint8_t kRtpHeaderSize = 12; 32 33 struct AudioPayload 34 { 35 uint32_t frequency; 36 uint8_t channels; 37 uint32_t rate; 38 }; 39 40 struct VideoPayload 41 { 42 RtpVideoCodecTypes videoCodecType; 43 uint32_t maxRate; 44 }; 45 46 union PayloadUnion 47 { 48 AudioPayload Audio; 49 VideoPayload Video; 50 }; 51 52 enum RTCPMethod 53 { 54 kRtcpOff = 0, 55 kRtcpCompound = 1, 56 kRtcpNonCompound = 2 57 }; 58 59 enum RTPAliveType 60 { 61 kRtpDead = 0, 62 kRtpNoRtp = 1, 63 kRtpAlive = 2 64 }; 65 66 enum ProtectionType { 67 kUnprotectedPacket, 68 kProtectedPacket 69 }; 70 71 enum StorageType { 72 kDontStore, 73 kDontRetransmit, 74 kAllowRetransmission 75 }; 76 77 enum RTPExtensionType 78 { 79 kRtpExtensionNone, 80 kRtpExtensionTransmissionTimeOffset, 81 kRtpExtensionAudioLevel, 82 kRtpExtensionAbsoluteSendTime 83 }; 84 85 enum RTCPAppSubTypes 86 { 87 kAppSubtypeBwe = 0x00 88 }; 89 90 enum RTCPPacketType 91 { 92 kRtcpReport = 0x0001, 93 kRtcpSr = 0x0002, 94 kRtcpRr = 0x0004, 95 kRtcpBye = 0x0008, 96 kRtcpPli = 0x0010, 97 kRtcpNack = 0x0020, 98 kRtcpFir = 0x0040, 99 kRtcpTmmbr = 0x0080, 100 kRtcpTmmbn = 0x0100, 101 kRtcpSrReq = 0x0200, 102 kRtcpXrVoipMetric = 0x0400, 103 kRtcpApp = 0x0800, 104 kRtcpSli = 0x4000, 105 kRtcpRpsi = 0x8000, 106 kRtcpRemb = 0x10000, 107 kRtcpTransmissionTimeOffset = 0x20000, 108 kRtcpXrReceiverReferenceTime = 0x40000, 109 kRtcpXrDlrrReportBlock = 0x80000 110 }; 111 112 enum KeyFrameRequestMethod 113 { 114 kKeyFrameReqFirRtp = 1, 115 kKeyFrameReqPliRtcp = 2, 116 kKeyFrameReqFirRtcp = 3 117 }; 118 119 enum RtpRtcpPacketType 120 { 121 kPacketRtp = 0, 122 kPacketKeepAlive = 1 123 }; 124 125 enum NACKMethod 126 { 127 kNackOff = 0, 128 kNackRtcp = 2 129 }; 130 131 enum RetransmissionMode { 132 kRetransmitOff = 0x0, 133 kRetransmitFECPackets = 0x1, 134 kRetransmitBaseLayer = 0x2, 135 kRetransmitHigherLayers = 0x4, 136 kRetransmitAllPackets = 0xFF 137 }; 138 139 enum RtxMode { 140 kRtxOff = 0x0, 141 kRtxRetransmitted = 0x1, // Only send retransmissions over RTX. 142 kRtxRedundantPayloads = 0x2 // Preventively send redundant payloads 143 // instead of padding. 144 }; 145 146 const int kRtxHeaderSize = 2; 147 148 struct RTCPSenderInfo 149 { 150 uint32_t NTPseconds; 151 uint32_t NTPfraction; 152 uint32_t RTPtimeStamp; 153 uint32_t sendPacketCount; 154 uint32_t sendOctetCount; 155 }; 156 157 struct RTCPReportBlock { 158 RTCPReportBlock() 159 : remoteSSRC(0), sourceSSRC(0), fractionLost(0), cumulativeLost(0), 160 extendedHighSeqNum(0), jitter(0), lastSR(0), 161 delaySinceLastSR(0) {} 162 163 RTCPReportBlock(uint32_t remote_ssrc, 164 uint32_t source_ssrc, 165 uint8_t fraction_lost, 166 uint32_t cumulative_lost, 167 uint32_t extended_high_sequence_number, 168 uint32_t jitter, 169 uint32_t last_sender_report, 170 uint32_t delay_since_last_sender_report) 171 : remoteSSRC(remote_ssrc), 172 sourceSSRC(source_ssrc), 173 fractionLost(fraction_lost), 174 cumulativeLost(cumulative_lost), 175 extendedHighSeqNum(extended_high_sequence_number), 176 jitter(jitter), 177 lastSR(last_sender_report), 178 delaySinceLastSR(delay_since_last_sender_report) {} 179 180 // Fields as described by RFC 3550 6.4.2. 181 uint32_t remoteSSRC; // SSRC of sender of this report. 182 uint32_t sourceSSRC; // SSRC of the RTP packet sender. 183 uint8_t fractionLost; 184 uint32_t cumulativeLost; // 24 bits valid. 185 uint32_t extendedHighSeqNum; 186 uint32_t jitter; 187 uint32_t lastSR; 188 uint32_t delaySinceLastSR; 189 }; 190 191 struct RtcpReceiveTimeInfo { 192 // Fields as described by RFC 3611 4.5. 193 uint32_t sourceSSRC; 194 uint32_t lastRR; 195 uint32_t delaySinceLastRR; 196 }; 197 198 typedef std::list<RTCPReportBlock> ReportBlockList; 199 200 struct RtpState { 201 RtpState() 202 : sequence_number(0), 203 start_timestamp(0), 204 timestamp(0), 205 capture_time_ms(-1), 206 last_timestamp_time_ms(-1), 207 media_has_been_sent(false) {} 208 uint16_t sequence_number; 209 uint32_t start_timestamp; 210 uint32_t timestamp; 211 int64_t capture_time_ms; 212 int64_t last_timestamp_time_ms; 213 bool media_has_been_sent; 214 }; 215 216 class RtpData 217 { 218 public: 219 virtual ~RtpData() {} 220 221 virtual int32_t OnReceivedPayloadData( 222 const uint8_t* payloadData, 223 const uint16_t payloadSize, 224 const WebRtcRTPHeader* rtpHeader) = 0; 225 226 virtual bool OnRecoveredPacket(const uint8_t* packet, 227 int packet_length) = 0; 228 }; 229 230 class RtcpFeedback 231 { 232 public: 233 virtual void OnApplicationDataReceived(const int32_t /*id*/, 234 const uint8_t /*subType*/, 235 const uint32_t /*name*/, 236 const uint16_t /*length*/, 237 const uint8_t* /*data*/) {}; 238 239 virtual void OnXRVoIPMetricReceived( 240 const int32_t /*id*/, 241 const RTCPVoIPMetric* /*metric*/) {}; 242 243 virtual void OnReceiveReportReceived(const int32_t id, 244 const uint32_t senderSSRC) {}; 245 246 protected: 247 virtual ~RtcpFeedback() {} 248 }; 249 250 class RtpFeedback 251 { 252 public: 253 virtual ~RtpFeedback() {} 254 255 // Receiving payload change or SSRC change. (return success!) 256 /* 257 * channels - number of channels in codec (1 = mono, 2 = stereo) 258 */ 259 virtual int32_t OnInitializeDecoder( 260 const int32_t id, 261 const int8_t payloadType, 262 const char payloadName[RTP_PAYLOAD_NAME_SIZE], 263 const int frequency, 264 const uint8_t channels, 265 const uint32_t rate) = 0; 266 267 virtual void OnIncomingSSRCChanged( const int32_t id, 268 const uint32_t ssrc) = 0; 269 270 virtual void OnIncomingCSRCChanged( const int32_t id, 271 const uint32_t CSRC, 272 const bool added) = 0; 273 274 virtual void ResetStatistics(uint32_t ssrc) = 0; 275 }; 276 277 class RtpAudioFeedback { 278 public: 279 280 virtual void OnPlayTelephoneEvent(const int32_t id, 281 const uint8_t event, 282 const uint16_t lengthMs, 283 const uint8_t volume) = 0; 284 protected: 285 virtual ~RtpAudioFeedback() {} 286 }; 287 288 class RtcpIntraFrameObserver { 289 public: 290 virtual void OnReceivedIntraFrameRequest(uint32_t ssrc) = 0; 291 292 virtual void OnReceivedSLI(uint32_t ssrc, 293 uint8_t picture_id) = 0; 294 295 virtual void OnReceivedRPSI(uint32_t ssrc, 296 uint64_t picture_id) = 0; 297 298 virtual void OnLocalSsrcChanged(uint32_t old_ssrc, uint32_t new_ssrc) = 0; 299 300 virtual ~RtcpIntraFrameObserver() {} 301 }; 302 303 class RtcpBandwidthObserver { 304 public: 305 // REMB or TMMBR 306 virtual void OnReceivedEstimatedBitrate(const uint32_t bitrate) = 0; 307 308 virtual void OnReceivedRtcpReceiverReport( 309 const ReportBlockList& report_blocks, 310 uint16_t rtt, 311 int64_t now_ms) = 0; 312 313 virtual ~RtcpBandwidthObserver() {} 314 }; 315 316 class RtcpRttStats { 317 public: 318 virtual void OnRttUpdate(uint32_t rtt) = 0; 319 320 virtual uint32_t LastProcessedRtt() const = 0; 321 322 virtual ~RtcpRttStats() {}; 323 }; 324 325 // Null object version of RtpFeedback. 326 class NullRtpFeedback : public RtpFeedback { 327 public: 328 virtual ~NullRtpFeedback() {} 329 330 virtual int32_t OnInitializeDecoder( 331 const int32_t id, 332 const int8_t payloadType, 333 const char payloadName[RTP_PAYLOAD_NAME_SIZE], 334 const int frequency, 335 const uint8_t channels, 336 const uint32_t rate) OVERRIDE { 337 return 0; 338 } 339 340 virtual void OnIncomingSSRCChanged(const int32_t id, 341 const uint32_t ssrc) OVERRIDE {} 342 343 virtual void OnIncomingCSRCChanged(const int32_t id, 344 const uint32_t CSRC, 345 const bool added) OVERRIDE {} 346 347 virtual void ResetStatistics(uint32_t ssrc) OVERRIDE {} 348 }; 349 350 // Null object version of RtpData. 351 class NullRtpData : public RtpData { 352 public: 353 virtual ~NullRtpData() {} 354 355 virtual int32_t OnReceivedPayloadData( 356 const uint8_t* payloadData, 357 const uint16_t payloadSize, 358 const WebRtcRTPHeader* rtpHeader) OVERRIDE { 359 return 0; 360 } 361 362 virtual bool OnRecoveredPacket(const uint8_t* packet, 363 int packet_length) OVERRIDE { 364 return true; 365 } 366 }; 367 368 // Null object version of RtpAudioFeedback. 369 class NullRtpAudioFeedback : public RtpAudioFeedback { 370 public: 371 virtual ~NullRtpAudioFeedback() {} 372 373 virtual void OnPlayTelephoneEvent(const int32_t id, 374 const uint8_t event, 375 const uint16_t lengthMs, 376 const uint8_t volume) OVERRIDE {} 377 }; 378 379 } // namespace webrtc 380 #endif // WEBRTC_MODULES_RTP_RTCP_INTERFACE_RTP_RTCP_DEFINES_H_ 381