Line data Source code
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_INCLUDE_RTP_RTCP_DEFINES_H_
12 : #define WEBRTC_MODULES_RTP_RTCP_INCLUDE_RTP_RTCP_DEFINES_H_
13 :
14 : #include <stddef.h>
15 : #include <list>
16 : #include <vector>
17 :
18 : #include "webrtc/common_types.h"
19 : #include "webrtc/modules/include/module_common_types.h"
20 : #include "webrtc/system_wrappers/include/clock.h"
21 : #include "webrtc/typedefs.h"
22 :
23 : #define RTCP_CNAME_SIZE 256 // RFC 3550 page 44, including null termination
24 : #define IP_PACKET_SIZE 1500 // we assume ethernet
25 : #define MAX_NUMBER_OF_PARALLEL_TELEPHONE_EVENTS 10
26 :
27 : namespace webrtc {
28 : namespace rtcp {
29 : class TransportFeedback;
30 : }
31 :
32 : const int kVideoPayloadTypeFrequency = 90000;
33 : // TODO(solenberg): RTP time stamp rate for RTCP is fixed at 8k, this is legacy
34 : // and should be fixed.
35 : // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=6458
36 : const int kBogusRtpRateForAudioRtcp = 8000;
37 :
38 : // Minimum RTP header size in bytes.
39 : const uint8_t kRtpHeaderSize = 12;
40 :
41 : struct AudioPayload {
42 : uint32_t frequency;
43 : size_t channels;
44 : uint32_t rate;
45 : };
46 :
47 : struct VideoPayload {
48 : RtpVideoCodecTypes videoCodecType;
49 : // The H264 profile only matters if videoCodecType == kRtpVideoH264.
50 : H264::Profile h264_profile;
51 : };
52 :
53 : union PayloadUnion {
54 : AudioPayload Audio;
55 : VideoPayload Video;
56 : };
57 :
58 : enum RTPAliveType { kRtpDead = 0, kRtpNoRtp = 1, kRtpAlive = 2 };
59 :
60 : enum ProtectionType {
61 : kUnprotectedPacket,
62 : kProtectedPacket
63 : };
64 :
65 : enum StorageType {
66 : kDontRetransmit,
67 : kAllowRetransmission
68 : };
69 :
70 : enum RTPExtensionType {
71 : kRtpExtensionNone,
72 : kRtpExtensionTransmissionTimeOffset,
73 : kRtpExtensionAudioLevel,
74 : kRtpExtensionAbsoluteSendTime,
75 : kRtpExtensionVideoRotation,
76 : kRtpExtensionTransportSequenceNumber,
77 : kRtpExtensionPlayoutDelay,
78 : kRtpExtensionRtpStreamId,
79 : kRtpExtensionNumberOfExtensions,
80 : };
81 :
82 : enum RTCPAppSubTypes { kAppSubtypeBwe = 0x00 };
83 :
84 : // TODO(sprang): Make this an enum class once rtcp_receiver has been cleaned up.
85 : enum RTCPPacketType : uint32_t {
86 : kRtcpReport = 0x0001,
87 : kRtcpSr = 0x0002,
88 : kRtcpRr = 0x0004,
89 : kRtcpSdes = 0x0008,
90 : kRtcpBye = 0x0010,
91 : kRtcpPli = 0x0020,
92 : kRtcpNack = 0x0040,
93 : kRtcpFir = 0x0080,
94 : kRtcpTmmbr = 0x0100,
95 : kRtcpTmmbn = 0x0200,
96 : kRtcpSrReq = 0x0400,
97 : kRtcpXrVoipMetric = 0x0800,
98 : kRtcpApp = 0x1000,
99 : kRtcpSli = 0x4000,
100 : kRtcpRpsi = 0x8000,
101 : kRtcpRemb = 0x10000,
102 : kRtcpTransmissionTimeOffset = 0x20000,
103 : kRtcpXrReceiverReferenceTime = 0x40000,
104 : kRtcpXrDlrrReportBlock = 0x80000,
105 : kRtcpTransportFeedback = 0x100000,
106 : kRtcpXrTargetBitrate = 0x200000
107 : };
108 :
109 : enum KeyFrameRequestMethod { kKeyFrameReqPliRtcp, kKeyFrameReqFirRtcp };
110 :
111 : enum RtpRtcpPacketType { kPacketRtp = 0, kPacketKeepAlive = 1 };
112 :
113 : enum RetransmissionMode : uint8_t {
114 : kRetransmitOff = 0x0,
115 : kRetransmitFECPackets = 0x1,
116 : kRetransmitBaseLayer = 0x2,
117 : kRetransmitHigherLayers = 0x4,
118 : kRetransmitAllPackets = 0xFF
119 : };
120 :
121 : enum RtxMode {
122 : kRtxOff = 0x0,
123 : kRtxRetransmitted = 0x1, // Only send retransmissions over RTX.
124 : kRtxRedundantPayloads = 0x2 // Preventively send redundant payloads
125 : // instead of padding.
126 : };
127 :
128 : const size_t kRtxHeaderSize = 2;
129 :
130 : struct RTCPSenderInfo {
131 : uint32_t NTPseconds;
132 : uint32_t NTPfraction;
133 : uint32_t RTPtimeStamp;
134 : uint32_t sendPacketCount;
135 : uint32_t sendOctetCount;
136 : };
137 :
138 : struct RTCPReportBlock {
139 0 : RTCPReportBlock()
140 0 : : remoteSSRC(0), sourceSSRC(0), fractionLost(0), cumulativeLost(0),
141 : extendedHighSeqNum(0), jitter(0), lastSR(0),
142 0 : delaySinceLastSR(0) {}
143 :
144 : RTCPReportBlock(uint32_t remote_ssrc,
145 : uint32_t source_ssrc,
146 : uint8_t fraction_lost,
147 : uint32_t cumulative_lost,
148 : uint32_t extended_high_sequence_number,
149 : uint32_t jitter,
150 : uint32_t last_sender_report,
151 : uint32_t delay_since_last_sender_report)
152 : : remoteSSRC(remote_ssrc),
153 : sourceSSRC(source_ssrc),
154 : fractionLost(fraction_lost),
155 : cumulativeLost(cumulative_lost),
156 : extendedHighSeqNum(extended_high_sequence_number),
157 : jitter(jitter),
158 : lastSR(last_sender_report),
159 : delaySinceLastSR(delay_since_last_sender_report) {}
160 :
161 : // Fields as described by RFC 3550 6.4.2.
162 : uint32_t remoteSSRC; // SSRC of sender of this report.
163 : uint32_t sourceSSRC; // SSRC of the RTP packet sender.
164 : uint8_t fractionLost;
165 : uint32_t cumulativeLost; // 24 bits valid.
166 : uint32_t extendedHighSeqNum;
167 : uint32_t jitter;
168 : uint32_t lastSR;
169 : uint32_t delaySinceLastSR;
170 : };
171 :
172 : typedef std::list<RTCPReportBlock> ReportBlockList;
173 :
174 : struct RtpState {
175 0 : RtpState()
176 0 : : sequence_number(0),
177 : start_timestamp(0),
178 : timestamp(0),
179 : capture_time_ms(-1),
180 : last_timestamp_time_ms(-1),
181 0 : media_has_been_sent(false) {}
182 : uint16_t sequence_number;
183 : uint32_t start_timestamp;
184 : uint32_t timestamp;
185 : int64_t capture_time_ms;
186 : int64_t last_timestamp_time_ms;
187 : bool media_has_been_sent;
188 : };
189 :
190 0 : class RtpData {
191 : public:
192 0 : virtual ~RtpData() {}
193 :
194 : virtual int32_t OnReceivedPayloadData(const uint8_t* payload_data,
195 : size_t payload_size,
196 : const WebRtcRTPHeader* rtp_header) = 0;
197 :
198 : virtual bool OnRecoveredPacket(const uint8_t* packet,
199 : size_t packet_length) = 0;
200 : };
201 :
202 0 : class RtpFeedback {
203 : public:
204 0 : virtual ~RtpFeedback() {}
205 :
206 : // Receiving payload change or SSRC change. (return success!)
207 : /*
208 : * channels - number of channels in codec (1 = mono, 2 = stereo)
209 : */
210 : virtual int32_t OnInitializeDecoder(
211 : int8_t payload_type,
212 : const char payload_name[RTP_PAYLOAD_NAME_SIZE],
213 : int frequency,
214 : size_t channels,
215 : uint32_t rate) = 0;
216 :
217 : virtual void OnIncomingSSRCChanged(uint32_t ssrc) = 0;
218 :
219 : virtual void OnIncomingCSRCChanged(uint32_t csrc, bool added) = 0;
220 : };
221 :
222 0 : class RtcpIntraFrameObserver {
223 : public:
224 : virtual void OnReceivedIntraFrameRequest(uint32_t ssrc) = 0;
225 :
226 : virtual void OnReceivedSLI(uint32_t ssrc,
227 : uint8_t picture_id) = 0;
228 :
229 : virtual void OnReceivedRPSI(uint32_t ssrc,
230 : uint64_t picture_id) = 0;
231 :
232 0 : virtual ~RtcpIntraFrameObserver() {}
233 : };
234 :
235 0 : class RtcpBandwidthObserver {
236 : public:
237 : // REMB or TMMBR
238 : virtual void OnReceivedEstimatedBitrate(uint32_t bitrate) = 0;
239 :
240 : virtual void OnReceivedRtcpReceiverReport(
241 : const ReportBlockList& report_blocks,
242 : int64_t rtt,
243 : int64_t now_ms) = 0;
244 :
245 0 : virtual ~RtcpBandwidthObserver() {}
246 : };
247 :
248 : struct PacketInfo {
249 0 : PacketInfo(int64_t arrival_time_ms, uint16_t sequence_number)
250 0 : : PacketInfo(-1,
251 : arrival_time_ms,
252 : -1,
253 : sequence_number,
254 : 0,
255 0 : kNotAProbe) {}
256 :
257 : PacketInfo(int64_t arrival_time_ms,
258 : int64_t send_time_ms,
259 : uint16_t sequence_number,
260 : size_t payload_size,
261 : int probe_cluster_id)
262 : : PacketInfo(-1,
263 : arrival_time_ms,
264 : send_time_ms,
265 : sequence_number,
266 : payload_size,
267 : probe_cluster_id) {}
268 :
269 0 : PacketInfo(int64_t creation_time_ms,
270 : int64_t arrival_time_ms,
271 : int64_t send_time_ms,
272 : uint16_t sequence_number,
273 : size_t payload_size,
274 : int probe_cluster_id)
275 0 : : creation_time_ms(creation_time_ms),
276 : arrival_time_ms(arrival_time_ms),
277 : send_time_ms(send_time_ms),
278 : sequence_number(sequence_number),
279 : payload_size(payload_size),
280 0 : probe_cluster_id(probe_cluster_id) {}
281 :
282 : static constexpr int kNotAProbe = -1;
283 :
284 : // Time corresponding to when this object was created.
285 : int64_t creation_time_ms;
286 : // Time corresponding to when the packet was received. Timestamped with the
287 : // receiver's clock.
288 : int64_t arrival_time_ms;
289 : // Time corresponding to when the packet was sent, timestamped with the
290 : // sender's clock.
291 : int64_t send_time_ms;
292 : // Packet identifier, incremented with 1 for every packet generated by the
293 : // sender.
294 : uint16_t sequence_number;
295 : // Size of the packet excluding RTP headers.
296 : size_t payload_size;
297 : // Which probing cluster this packets belongs to.
298 : int probe_cluster_id;
299 : };
300 :
301 : class TransportFeedbackObserver {
302 : public:
303 0 : TransportFeedbackObserver() {}
304 0 : virtual ~TransportFeedbackObserver() {}
305 :
306 : // Note: Transport-wide sequence number as sequence number. Arrival time
307 : // must be set to 0.
308 : virtual void AddPacket(uint16_t sequence_number,
309 : size_t length,
310 : int probe_cluster_id) = 0;
311 :
312 : virtual void OnTransportFeedback(const rtcp::TransportFeedback& feedback) = 0;
313 :
314 : virtual std::vector<PacketInfo> GetTransportFeedbackVector() const = 0;
315 : };
316 :
317 0 : class RtcpRttStats {
318 : public:
319 : virtual void OnRttUpdate(int64_t rtt) = 0;
320 :
321 : virtual int64_t LastProcessedRtt() const = 0;
322 :
323 0 : virtual ~RtcpRttStats() {}
324 : };
325 :
326 : // Null object version of RtpFeedback.
327 : class NullRtpFeedback : public RtpFeedback {
328 : public:
329 0 : virtual ~NullRtpFeedback() {}
330 :
331 0 : int32_t OnInitializeDecoder(int8_t payload_type,
332 : const char payloadName[RTP_PAYLOAD_NAME_SIZE],
333 : int frequency,
334 : size_t channels,
335 : uint32_t rate) override {
336 0 : return 0;
337 : }
338 :
339 0 : void OnIncomingSSRCChanged(uint32_t ssrc) override {}
340 0 : void OnIncomingCSRCChanged(uint32_t csrc, bool added) override {}
341 : };
342 :
343 : // Null object version of RtpData.
344 : class NullRtpData : public RtpData {
345 : public:
346 0 : virtual ~NullRtpData() {}
347 :
348 0 : int32_t OnReceivedPayloadData(const uint8_t* payload_data,
349 : size_t payload_size,
350 : const WebRtcRTPHeader* rtp_header) override {
351 0 : return 0;
352 : }
353 :
354 0 : bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override {
355 0 : return true;
356 : }
357 : };
358 :
359 : // Statistics about packet loss for a single directional connection. All values
360 : // are totals since the connection initiated.
361 : struct RtpPacketLossStats {
362 : // The number of packets lost in events where no adjacent packets were also
363 : // lost.
364 : uint64_t single_packet_loss_count;
365 : // The number of events in which more than one adjacent packet was lost.
366 : uint64_t multiple_packet_loss_event_count;
367 : // The number of packets lost in events where more than one adjacent packet
368 : // was lost.
369 : uint64_t multiple_packet_loss_packet_count;
370 : };
371 :
372 : class RtpPacketSender {
373 : public:
374 0 : RtpPacketSender() {}
375 0 : virtual ~RtpPacketSender() {}
376 :
377 : enum Priority {
378 : kHighPriority = 0, // Pass through; will be sent immediately.
379 : kNormalPriority = 2, // Put in back of the line.
380 : kLowPriority = 3, // Put in back of the low priority line.
381 : };
382 : // Low priority packets are mixed with the normal priority packets
383 : // while we are paused.
384 :
385 : // Returns true if we send the packet now, else it will add the packet
386 : // information to the queue and call TimeToSendPacket when it's time to send.
387 : virtual void InsertPacket(Priority priority,
388 : uint32_t ssrc,
389 : uint16_t sequence_number,
390 : int64_t capture_time_ms,
391 : size_t bytes,
392 : bool retransmission) = 0;
393 : };
394 :
395 : class TransportSequenceNumberAllocator {
396 : public:
397 0 : TransportSequenceNumberAllocator() {}
398 0 : virtual ~TransportSequenceNumberAllocator() {}
399 :
400 : virtual uint16_t AllocateSequenceNumber() = 0;
401 : };
402 :
403 : } // namespace webrtc
404 : #endif // WEBRTC_MODULES_RTP_RTCP_INCLUDE_RTP_RTCP_DEFINES_H_
|