ccRTP
rtcppkt.h
Go to the documentation of this file.
1// Copyright (C) 2001-2015 Federico Montesino Pouzols <fedemp@altern.org>.
2//
3// This program is free software; you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation; either version 2 of the License, or
6// (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU Lesser General Public License
14// along with GNU ccRTP. If not, see <http://www.gnu.org/licenses/>.
15//
16// As a special exception, you may use this file as part of a free software
17// library without restriction. Specifically, if other files instantiate
18// templates or use macros or inline functions from this file, or you compile
19// this file and link it with other files to produce an executable, this
20// file does not by itself cause the resulting executable to be covered by
21// the GNU General Public License. This exception does not however
22// invalidate any other reasons why the executable file might be covered by
23// the GNU General Public License.
24//
25// This exception applies only to the code released under the name GNU
26// ccRTP. If you copy code from other releases into a copy of GNU
27// ccRTP, as the General Public License permits, the exception does
28// not apply to the code that you add in this way. To avoid misleading
29// anyone as to the status of such modified files, you must delete
30// this exception notice from them.
31//
32// If you write modifications of your own for GNU ccRTP, it is your choice
33// whether to permit this exception to apply to your modifications.
34// If you do not wish that, delete this exception notice.
35//
36
37#ifndef CCXX_RTP_RTCPPKT_H_
38#define CCXX_RTP_RTCPPKT_H_
39
40#include <ccrtp/base.h>
41
42NAMESPACE_COMMONCPP
43
64typedef enum
65{
78
89class __EXPORT RTCPCompoundHandler
90{
91public:
92 inline void setPathMTU(uint16 mtu)
93 { pathMTU = mtu; }
94
95 inline uint16 getPathMTU()
96 { return pathMTU; }
97
98#ifdef CCXX_PACKED
99#pragma pack(1)
100#endif
109 {
111 uint8 lostMSB;
112 uint16 lostLSW;
114 uint32 jitter;
115 uint32 lsr;
116 uint32 dlsr;
117 };
118
125 struct RRBlock
126 {
127 uint32 ssrc;
129 };
130
138 {
139 uint32 ssrc;
140 RRBlock blocks[1];
141 };
142
150 {
151 uint32 NTPMSW;
152 uint32 NTPLSW;
154 uint32 packetCount;
155 uint32 octetCount;
156 };
157
164 {
165 uint32 ssrc;
167 RRBlock blocks[1];
168 };
169
175 struct SDESItem
176 {
177 uint8 type;
178 uint8 len;
179 char data[1];
180 };
181
188 {
189 uint32 getSSRC() const
190 { return (ntohl(ssrc)); }
191
192 uint32 ssrc;
194 };
195
202 {
203 uint32 ssrc;
204 uint8 length;
205 };
206
213 {
214 uint32 ssrc;
215 char name [4];
218 unsigned char data[1];
219 };
220
228 {
229 uint32 ssrc;
230 };
231
239 {
240 uint32 ssrc;
241 uint16 fsn;
242 uint16 blp;
243 };
244
251 {
252#if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN
254 unsigned char version:2;
255 unsigned char padding:1;
256 unsigned char block_count:5;
257#else
259 unsigned char block_count:5;
260 unsigned char padding:1;
261 unsigned char version:2;
262#endif
263 uint8 type;
264 uint16 length;
265 };
266
278 {
284 typedef enum {
285 tSR = 200,
290 tFIR = 192,
291 tNACK = 193,
292 tXR
293 } Type;
294
299 uint32 getLength() const
300 { return ((ntohs(fh.length) + 1) << 2); }
301
306 uint32 getSSRC() const
307 { return (ntohl(info.RR.ssrc)); } // SSRC is always the first
308 // word after fh.
309
311
312 // An RTCP packet may be of any of the types defined
313 // above, including APP specific ones.
314 union
315 {
323 } info;
324 };
325#ifdef CCXX_PACKED
326#pragma pack()
327#endif
328
329protected:
330 enum { defaultPathMTU = 1500 };
331
332 RTCPCompoundHandler(uint16 mtu = defaultPathMTU);
333
335
347 bool
349
350 // buffer to hold RTCP compound packets being sent. Allocated
351 // in construction time
352 unsigned char* rtcpSendBuffer;
353 // buffer to hold RTCP compound packets being
354 // received. Allocated at construction time
355 unsigned char* rtcpRecvBuffer;
356
357 friend class RTCPSenderInfo;
358 friend class RTCPReceiverInfo;
359private:
360 // path MTU. RTCP packets should not be greater than this
361 uint16 pathMTU;
362 // masks for RTCP header validation;
363 static const uint16 RTCP_VALID_MASK;
364 static const uint16 RTCP_VALID_VALUE;
365};
366
373class __EXPORT RTCPReceiverInfo
374{
375public:
377 { memcpy(&receiverInfo,&ri,
379
381 : receiverInfo( si )
382 {
383 }
384
386 { }
387
392 inline uint8
394 { return receiverInfo.fractionLost; }
395
396 inline uint32
398 { return ( ((uint32)ntohs(receiverInfo.lostLSW)) +
399 (((uint32)receiverInfo.lostMSB) << 16) ); }
400
401 inline uint32
403 { return ntohl(receiverInfo.highestSeqNum); }
404
411 uint32
412 getJitter() const
413 { return ntohl(receiverInfo.jitter); }
414
420 uint16
422 { return (uint16)((ntohl(receiverInfo.lsr) & 0xFFFF0000) >> 16); }
423
429 uint16
431 { return (uint16)(ntohl(receiverInfo.lsr) & 0xFFFF); }
432
439 uint32
441 { return ntohl(receiverInfo.dlsr); }
442
443private:
445};
446
453class __EXPORT RTCPSenderInfo
454{
455public:
457 { memcpy(&senderInfo,&si,
459
461 : senderInfo( si )
462 {
463 }
464
466 { }
467
472 uint32
474 { return ntohl(senderInfo.NTPMSW); }
475
480 uint32
482 { return ntohl(senderInfo.NTPLSW); }
483
484 inline uint32
486 { return ntohl(senderInfo.RTPTimestamp); }
487
491 inline uint32
493 { return ntohl(senderInfo.packetCount); }
494
495 inline uint32
497 { return ntohl(senderInfo.octetCount); }
498
499private:
501};
502
511timeval
512NTP2Timeval(uint32 msw, uint32 lsw);
513
521uint32
523 // rtcppacket
525
526END_NAMESPACE
527
528#endif // ndef CCXX_RTP_RTCPPKT_H_
529
Base elements for RTP stacks: constants, types and global functions.
low level structs and RTCP packet parsing and building methods.
Definition rtcppkt.h:90
bool checkCompoundRTCPHeader(size_t len)
Perform RTCP compound packet header validity check as specified in draft-ietv-avt-rtp-new.
void setPathMTU(uint16 mtu)
Definition rtcppkt.h:92
unsigned char * rtcpSendBuffer
Definition rtcppkt.h:352
RTCPCompoundHandler(uint16 mtu=defaultPathMTU)
uint16 getPathMTU()
Definition rtcppkt.h:95
unsigned char * rtcpRecvBuffer
Definition rtcppkt.h:355
Report block information of SR/RR RTCP reports.
Definition rtcppkt.h:374
RTCPReceiverInfo(RTCPCompoundHandler::ReceiverInfo &si)
Definition rtcppkt.h:380
uint8 getFractionLost() const
Get fraction of lost packets, as a number between 0 and 255.
Definition rtcppkt.h:393
~RTCPReceiverInfo()
Definition rtcppkt.h:385
uint16 getLastSRNTPTimestampInt() const
Get the integer part of the NTP timestamp of the last SR RTCP packet received from the source this re...
Definition rtcppkt.h:421
uint16 getLastSRNTPTimestampFrac() const
Get the fractional part of the NTP timestamp of the last SR RTCP packet received from the source this...
Definition rtcppkt.h:430
RTCPReceiverInfo(void *ri)
Definition rtcppkt.h:376
uint32 getCumulativePacketLost() const
Definition rtcppkt.h:397
uint32 getJitter() const
Get the statistical variance of the RTP data packets interarrival time.
Definition rtcppkt.h:412
uint32 getExtendedSeqNum() const
Definition rtcppkt.h:402
uint32 getDelayLastSR() const
Get the delay between the last SR packet received and the transmission of this report.
Definition rtcppkt.h:440
Sender block information of SR RTCP reports.
Definition rtcppkt.h:454
uint32 getOctetCount() const
Definition rtcppkt.h:496
RTCPSenderInfo(RTCPCompoundHandler::SenderInfo &si)
Definition rtcppkt.h:460
uint32 getPacketCount() const
Get count of sent data packets.
Definition rtcppkt.h:492
~RTCPSenderInfo()
Definition rtcppkt.h:465
uint32 getRTPTimestamp() const
Definition rtcppkt.h:485
uint32 getNTPTimestampFrac() const
Get fractional part of the NTP timestamp of this packet.
Definition rtcppkt.h:481
RTCPSenderInfo(void *si)
Definition rtcppkt.h:456
uint32 getNTPTimestampInt() const
Get integer part of the NTP timestamp of this packet.
Definition rtcppkt.h:473
timeval NTP2Timeval(uint32 msw, uint32 lsw)
Convert a NTP timestamp, expressed as two 32-bit long words, into a timeval value.
uint32 timevalIntervalTo65536(timeval &t)
Convert a time interval, expressed as a timeval, into a 32-bit time interval expressed in units of 1/...
SDESItemType
SDES items that may be carried in a Source DEScription RTCP packet.
Definition rtcppkt.h:65
@ SDESItemTypeLOC
Location where the user is.
Definition rtcppkt.h:71
@ SDESItemTypePHONE
Phone number of the user.
Definition rtcppkt.h:70
@ SDESItemTypeEND
END of SDES item list.
Definition rtcppkt.h:66
@ SDESItemTypeTOOL
Application or tool.
Definition rtcppkt.h:72
@ SDESItemTypeCNAME
Canonical end-point identifier.
Definition rtcppkt.h:67
@ SDESItemTypeNOTE
Comment usually reporting state.
Definition rtcppkt.h:73
@ SDESItemTypePRIV
Private extension.
Definition rtcppkt.h:74
@ SDESItemTypeNAME
Personal NAME of the user.
Definition rtcppkt.h:68
@ SDESItemTypeLast
Last defined code.
Definition rtcppkt.h:76
@ SDESItemTypeH323CADDR
H323 callable address.
Definition rtcppkt.h:75
@ SDESItemTypeEMAIL
EMAIL address of the user.
Definition rtcppkt.h:69
Struct for APP (application specific) RTCP packets.
Definition rtcppkt.h:213
uint32 ssrc
ssrc identifier of source.
Definition rtcppkt.h:214
Struct for BYE (leaving session) RTCP packets.
Definition rtcppkt.h:202
uint8 length
[optional] length of reason.
Definition rtcppkt.h:204
uint32 ssrc
ssrc identifier of source leaving.
Definition rtcppkt.h:203
Struct for Full Intra-frame Request (FIR) RTCP packet.
Definition rtcppkt.h:228
uint32 ssrc
ssrc identifier of source.
Definition rtcppkt.h:229
Struct for Negative ACKnowledgements (NACK) RTCP packet.
Definition rtcppkt.h:239
uint32 ssrc
ssrc identifier of source.
Definition rtcppkt.h:240
uint16 fsn
First Sequence Number lost.
Definition rtcppkt.h:241
uint16 blp
Bitmask of following Lost Packets.
Definition rtcppkt.h:242
Struct for a receiver info block in a SR (sender report) or an RR (receiver report) RTCP packet.
Definition rtcppkt.h:126
uint32 ssrc
source identifier.
Definition rtcppkt.h:127
ReceiverInfo rinfo
info about the source.
Definition rtcppkt.h:128
Fixed RTCP packet header.
Definition rtcppkt.h:251
uint16 length
number of 32-bit words in the packet (minus one).
Definition rtcppkt.h:264
unsigned char version
Version, currently 2.
Definition rtcppkt.h:261
unsigned char padding
Padding bit.
Definition rtcppkt.h:260
unsigned char block_count
< For little endian boxes
Definition rtcppkt.h:259
uint8 type
type of RTCP packet.
Definition rtcppkt.h:263
Struct representing general RTCP packet headers as they are sent through the network.
Definition rtcppkt.h:278
RTCPFixedHeader fh
Fixed RTCP header.
Definition rtcppkt.h:310
APPPacket APP
Definition rtcppkt.h:320
SDESChunk SDES
Definition rtcppkt.h:318
NACKPacket NACK
Definition rtcppkt.h:321
RecvReport RR
Definition rtcppkt.h:317
SendReport SR
Definition rtcppkt.h:316
uint32 getLength() const
Get the packet length specified in its header, in octets and in host order.
Definition rtcppkt.h:299
@ tAPP
APPlication specific.
Definition rtcppkt.h:289
@ tSDES
Source DEScription.
Definition rtcppkt.h:287
@ tBYE
End of participation.
Definition rtcppkt.h:288
@ tRR
Receiver Report.
Definition rtcppkt.h:286
uint32 getSSRC() const
Get the SSRC identifier specified in the packet header, in host order.
Definition rtcppkt.h:306
BYEPacket BYE
Definition rtcppkt.h:319
FIRPacket FIR
Definition rtcppkt.h:322
Struct for the data contained in a receiver info block.
Definition rtcppkt.h:109
uint32 jitter
arrival jitter.
Definition rtcppkt.h:114
uint32 lsr
last sender report timestamp.
Definition rtcppkt.h:115
uint32 highestSeqNum
highest sequence number.
Definition rtcppkt.h:113
uint8 lostMSB
cumulative lost MSB of 3 octets.
Definition rtcppkt.h:111
uint16 lostLSW
cumulative lost two LSB.
Definition rtcppkt.h:112
uint8 fractionLost
packet fraction lost.
Definition rtcppkt.h:110
uint32 dlsr
delay since last sender report.
Definition rtcppkt.h:116
raw structure of the source and every receiver report in an SR or RR RTCP packet.
Definition rtcppkt.h:138
uint32 ssrc
source identifier.
Definition rtcppkt.h:139
Struct for a chunk of items in a SDES RTCP packet.
Definition rtcppkt.h:188
SDESItem item
SDES item from sender.
Definition rtcppkt.h:193
uint32 ssrc
SSRC identifer from sender.
Definition rtcppkt.h:192
uint32 getSSRC() const
Definition rtcppkt.h:189
Struct for an item description of a SDES packet.
Definition rtcppkt.h:176
uint8 len
item len in octets.
Definition rtcppkt.h:178
uint8 type
item identifier.
Definition rtcppkt.h:177
Struct for SR (sender report) RTCP packets.
Definition rtcppkt.h:164
SenderInfo sinfo
actual sender info.
Definition rtcppkt.h:166
uint32 ssrc
source identifier.
Definition rtcppkt.h:165
Struct for the sender info block in a SR (sender report) RTCP packet.
Definition rtcppkt.h:150
uint32 NTPMSW
NTP timestamp higher octets.
Definition rtcppkt.h:151
uint32 octetCount
cumulative octet counter.
Definition rtcppkt.h:155
uint32 packetCount
cumulative packet counter.
Definition rtcppkt.h:154
uint32 NTPLSW
NTP timestamp lower octets.
Definition rtcppkt.h:152
uint32 RTPTimestamp
RTP timestamp.
Definition rtcppkt.h:153