• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 StorageType {
67   kDontStore,
68   kDontRetransmit,
69   kAllowRetransmission
70 };
71 
72 enum RTPExtensionType
73 {
74    kRtpExtensionNone,
75    kRtpExtensionTransmissionTimeOffset,
76    kRtpExtensionAudioLevel,
77    kRtpExtensionAbsoluteSendTime
78 };
79 
80 enum RTCPAppSubTypes
81 {
82     kAppSubtypeBwe     = 0x00
83 };
84 
85 enum RTCPPacketType
86 {
87     kRtcpReport         = 0x0001,
88     kRtcpSr             = 0x0002,
89     kRtcpRr             = 0x0004,
90     kRtcpBye            = 0x0008,
91     kRtcpPli            = 0x0010,
92     kRtcpNack           = 0x0020,
93     kRtcpFir            = 0x0040,
94     kRtcpTmmbr          = 0x0080,
95     kRtcpTmmbn          = 0x0100,
96     kRtcpSrReq          = 0x0200,
97     kRtcpXrVoipMetric   = 0x0400,
98     kRtcpApp            = 0x0800,
99     kRtcpSli            = 0x4000,
100     kRtcpRpsi           = 0x8000,
101     kRtcpRemb           = 0x10000,
102     kRtcpTransmissionTimeOffset = 0x20000,
103     kRtcpXrReceiverReferenceTime = 0x40000,
104     kRtcpXrDlrrReportBlock = 0x80000
105 };
106 
107 enum KeyFrameRequestMethod
108 {
109     kKeyFrameReqFirRtp    = 1,
110     kKeyFrameReqPliRtcp   = 2,
111     kKeyFrameReqFirRtcp   = 3
112 };
113 
114 enum RtpRtcpPacketType
115 {
116     kPacketRtp        = 0,
117     kPacketKeepAlive = 1
118 };
119 
120 enum NACKMethod
121 {
122     kNackOff      = 0,
123     kNackRtcp     = 2
124 };
125 
126 enum RetransmissionMode {
127   kRetransmitOff          = 0x0,
128   kRetransmitFECPackets   = 0x1,
129   kRetransmitBaseLayer    = 0x2,
130   kRetransmitHigherLayers = 0x4,
131   kRetransmitAllPackets   = 0xFF
132 };
133 
134 enum RtxMode {
135   kRtxOff                 = 0x0,
136   kRtxRetransmitted       = 0x1,  // Only send retransmissions over RTX.
137   kRtxRedundantPayloads   = 0x2   // Preventively send redundant payloads
138                                   // instead of padding.
139 };
140 
141 const int kRtxHeaderSize = 2;
142 
143 struct RTCPSenderInfo
144 {
145     uint32_t NTPseconds;
146     uint32_t NTPfraction;
147     uint32_t RTPtimeStamp;
148     uint32_t sendPacketCount;
149     uint32_t sendOctetCount;
150 };
151 
152 struct RTCPReportBlock {
RTCPReportBlockRTCPReportBlock153   RTCPReportBlock()
154       : remoteSSRC(0), sourceSSRC(0), fractionLost(0), cumulativeLost(0),
155         extendedHighSeqNum(0), jitter(0), lastSR(0),
156         delaySinceLastSR(0) {}
157 
RTCPReportBlockRTCPReportBlock158   RTCPReportBlock(uint32_t remote_ssrc,
159                   uint32_t source_ssrc,
160                   uint8_t fraction_lost,
161                   uint32_t cumulative_lost,
162                   uint32_t extended_high_sequence_number,
163                   uint32_t jitter,
164                   uint32_t last_sender_report,
165                   uint32_t delay_since_last_sender_report)
166       : remoteSSRC(remote_ssrc),
167         sourceSSRC(source_ssrc),
168         fractionLost(fraction_lost),
169         cumulativeLost(cumulative_lost),
170         extendedHighSeqNum(extended_high_sequence_number),
171         jitter(jitter),
172         lastSR(last_sender_report),
173         delaySinceLastSR(delay_since_last_sender_report) {}
174 
175   // Fields as described by RFC 3550 6.4.2.
176   uint32_t remoteSSRC;  // SSRC of sender of this report.
177   uint32_t sourceSSRC;  // SSRC of the RTP packet sender.
178   uint8_t fractionLost;
179   uint32_t cumulativeLost;  // 24 bits valid.
180   uint32_t extendedHighSeqNum;
181   uint32_t jitter;
182   uint32_t lastSR;
183   uint32_t delaySinceLastSR;
184 };
185 
186 struct RtcpReceiveTimeInfo {
187   // Fields as described by RFC 3611 4.5.
188   uint32_t sourceSSRC;
189   uint32_t lastRR;
190   uint32_t delaySinceLastRR;
191 };
192 
193 typedef std::list<RTCPReportBlock> ReportBlockList;
194 
195 class RtpData
196 {
197 public:
~RtpData()198     virtual ~RtpData() {}
199 
200     virtual int32_t OnReceivedPayloadData(
201         const uint8_t* payloadData,
202         const uint16_t payloadSize,
203         const WebRtcRTPHeader* rtpHeader) = 0;
204 
205     virtual bool OnRecoveredPacket(const uint8_t* packet,
206                                    int packet_length) = 0;
207 };
208 
209 class RtcpFeedback
210 {
211 public:
OnApplicationDataReceived(const int32_t,const uint8_t,const uint32_t,const uint16_t,const uint8_t *)212     virtual void OnApplicationDataReceived(const int32_t /*id*/,
213                                            const uint8_t /*subType*/,
214                                            const uint32_t /*name*/,
215                                            const uint16_t /*length*/,
216                                            const uint8_t* /*data*/)  {};
217 
OnXRVoIPMetricReceived(const int32_t,const RTCPVoIPMetric *)218     virtual void OnXRVoIPMetricReceived(
219         const int32_t /*id*/,
220         const RTCPVoIPMetric* /*metric*/)  {};
221 
OnReceiveReportReceived(const int32_t id,const uint32_t senderSSRC)222     virtual void OnReceiveReportReceived(const int32_t id,
223                                          const uint32_t senderSSRC)  {};
224 
225 protected:
~RtcpFeedback()226     virtual ~RtcpFeedback() {}
227 };
228 
229 class RtpFeedback
230 {
231 public:
~RtpFeedback()232     virtual ~RtpFeedback() {}
233 
234     // Receiving payload change or SSRC change. (return success!)
235     /*
236     *   channels    - number of channels in codec (1 = mono, 2 = stereo)
237     */
238     virtual int32_t OnInitializeDecoder(
239         const int32_t id,
240         const int8_t payloadType,
241         const char payloadName[RTP_PAYLOAD_NAME_SIZE],
242         const int frequency,
243         const uint8_t channels,
244         const uint32_t rate) = 0;
245 
246     virtual void OnIncomingSSRCChanged( const int32_t id,
247                                         const uint32_t ssrc) = 0;
248 
249     virtual void OnIncomingCSRCChanged( const int32_t id,
250                                         const uint32_t CSRC,
251                                         const bool added) = 0;
252 
253     virtual void ResetStatistics(uint32_t ssrc) = 0;
254 };
255 
256 class RtpAudioFeedback {
257  public:
258 
259   virtual void OnPlayTelephoneEvent(const int32_t id,
260                                     const uint8_t event,
261                                     const uint16_t lengthMs,
262                                     const uint8_t volume) = 0;
263  protected:
~RtpAudioFeedback()264   virtual ~RtpAudioFeedback() {}
265 };
266 
267 class RtcpIntraFrameObserver {
268  public:
269   virtual void OnReceivedIntraFrameRequest(uint32_t ssrc) = 0;
270 
271   virtual void OnReceivedSLI(uint32_t ssrc,
272                              uint8_t picture_id) = 0;
273 
274   virtual void OnReceivedRPSI(uint32_t ssrc,
275                               uint64_t picture_id) = 0;
276 
277   virtual void OnLocalSsrcChanged(uint32_t old_ssrc, uint32_t new_ssrc) = 0;
278 
~RtcpIntraFrameObserver()279   virtual ~RtcpIntraFrameObserver() {}
280 };
281 
282 class RtcpBandwidthObserver {
283  public:
284   // REMB or TMMBR
285   virtual void OnReceivedEstimatedBitrate(const uint32_t bitrate) = 0;
286 
287   virtual void OnReceivedRtcpReceiverReport(
288       const ReportBlockList& report_blocks,
289       uint16_t rtt,
290       int64_t now_ms) = 0;
291 
~RtcpBandwidthObserver()292   virtual ~RtcpBandwidthObserver() {}
293 };
294 
295 class RtcpRttStats {
296  public:
297   virtual void OnRttUpdate(uint32_t rtt) = 0;
298 
299   virtual uint32_t LastProcessedRtt() const = 0;
300 
~RtcpRttStats()301   virtual ~RtcpRttStats() {};
302 };
303 
304 // Null object version of RtpFeedback.
305 class NullRtpFeedback : public RtpFeedback {
306  public:
~NullRtpFeedback()307   virtual ~NullRtpFeedback() {}
308 
OnInitializeDecoder(const int32_t id,const int8_t payloadType,const char payloadName[RTP_PAYLOAD_NAME_SIZE],const int frequency,const uint8_t channels,const uint32_t rate)309   virtual int32_t OnInitializeDecoder(
310       const int32_t id,
311       const int8_t payloadType,
312       const char payloadName[RTP_PAYLOAD_NAME_SIZE],
313       const int frequency,
314       const uint8_t channels,
315       const uint32_t rate) OVERRIDE {
316     return 0;
317   }
318 
OnIncomingSSRCChanged(const int32_t id,const uint32_t ssrc)319   virtual void OnIncomingSSRCChanged(const int32_t id,
320                                      const uint32_t ssrc) OVERRIDE {}
321 
OnIncomingCSRCChanged(const int32_t id,const uint32_t CSRC,const bool added)322   virtual void OnIncomingCSRCChanged(const int32_t id,
323                                      const uint32_t CSRC,
324                                      const bool added) OVERRIDE {}
325 
ResetStatistics(uint32_t ssrc)326   virtual void ResetStatistics(uint32_t ssrc) OVERRIDE {}
327 };
328 
329 // Null object version of RtpData.
330 class NullRtpData : public RtpData {
331  public:
~NullRtpData()332   virtual ~NullRtpData() {}
333 
OnReceivedPayloadData(const uint8_t * payloadData,const uint16_t payloadSize,const WebRtcRTPHeader * rtpHeader)334   virtual int32_t OnReceivedPayloadData(
335       const uint8_t* payloadData,
336       const uint16_t payloadSize,
337       const WebRtcRTPHeader* rtpHeader) OVERRIDE {
338     return 0;
339   }
340 
OnRecoveredPacket(const uint8_t * packet,int packet_length)341   virtual bool OnRecoveredPacket(const uint8_t* packet,
342                                  int packet_length) {
343     return true;
344   }
345 };
346 
347 // Null object version of RtpAudioFeedback.
348 class NullRtpAudioFeedback : public RtpAudioFeedback {
349  public:
~NullRtpAudioFeedback()350   virtual ~NullRtpAudioFeedback() {}
351 
OnPlayTelephoneEvent(const int32_t id,const uint8_t event,const uint16_t lengthMs,const uint8_t volume)352   virtual void OnPlayTelephoneEvent(const int32_t id,
353                                     const uint8_t event,
354                                     const uint16_t lengthMs,
355                                     const uint8_t volume) OVERRIDE {}
356 };
357 
358 }  // namespace webrtc
359 #endif // WEBRTC_MODULES_RTP_RTCP_INTERFACE_RTP_RTCP_DEFINES_H_
360