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