Bayonne2 / Common C++ 2 Framework
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 #ifdef CCXX_NAMESPACES
44 namespace ost {
45 #endif
46 
67 typedef enum
68 {
80 } SDESItemType;
81 
93 {
94 public:
95  inline void setPathMTU(uint16 mtu)
96  { pathMTU = mtu; }
97 
98  inline uint16 getPathMTU()
99  { return pathMTU; }
100 
101 #ifdef CCXX_PACKED
102 #pragma pack(1)
103 #endif
104 
112  {
113  uint8 fractionLost;
114  uint8 lostMSB;
115  uint16 lostLSW;
116  uint32 highestSeqNum;
117  uint32 jitter;
118  uint32 lsr;
119  uint32 dlsr;
120  };
121 
128  struct RRBlock
129  {
130  uint32 ssrc;
132  };
133 
140  struct RecvReport
141  {
142  uint32 ssrc;
143  RRBlock blocks[1];
144  };
145 
152  struct SenderInfo
153  {
154  uint32 NTPMSW;
155  uint32 NTPLSW;
156  uint32 RTPTimestamp;
157  uint32 packetCount;
158  uint32 octetCount;
159  };
160 
166  struct SendReport
167  {
168  uint32 ssrc;
170  RRBlock blocks[1];
171  };
172 
178  struct SDESItem
179  {
180  uint8 type;
181  uint8 len;
182  char data[1];
183  };
184 
190  struct SDESChunk
191  {
192  uint32 getSSRC() const
193  { return (ntohl(ssrc)); }
194 
195  uint32 ssrc;
197  };
198 
204  struct BYEPacket
205  {
206  uint32 ssrc;
207  uint8 length;
208  };
209 
215  struct APPPacket
216  {
217  uint32 ssrc;
218  char name [4];
219  unsigned char data[1];
222  };
223 
230  struct FIRPacket
231  {
232  uint32 ssrc;
233  };
234 
241  struct NACKPacket
242  {
243  uint32 ssrc;
244  uint16 fsn;
245  uint16 blp;
246  };
247 
254  {
255 #if __BYTE_ORDER == __BIG_ENDIAN
256  unsigned char version:2;
258  unsigned char padding:1;
259  unsigned char block_count:5;
260 #else
261  unsigned char block_count:5;
263  unsigned char padding:1;
264  unsigned char version:2;
265 #endif
266  uint8 type;
267  uint16 length;
268  };
269 
280  struct RTCPPacket
281  {
287  typedef enum {
288  tSR = 200,
289  tRR,
293  tFIR = 192,
294  tNACK = 193,
295  tXR
296  } Type;
297 
302  uint32 getLength() const
303  { return ((ntohs(fh.length) + 1) << 2); }
304 
309  uint32 getSSRC() const
310  { return (ntohl(info.RR.ssrc)); } // SSRC is always the first
311  // word after fh.
312 
314 
315  // An RTCP packet may be of any of the types defined
316  // above, including APP specific ones.
317  union
318  {
326  } info;
327  };
328 #ifdef CCXX_PACKED
329 #pragma pack()
330 #endif
331 
332 protected:
333  enum { defaultPathMTU = 1500 };
334 
335  RTCPCompoundHandler(uint16 mtu = defaultPathMTU);
336 
338 
350  bool
351  checkCompoundRTCPHeader(size_t len);
352 
353  // buffer to hold RTCP compound packets being sent. Allocated
354  // in construction time
355  unsigned char* rtcpSendBuffer;
356  // buffer to hold RTCP compound packets being
357  // received. Allocated at construction time
358  unsigned char* rtcpRecvBuffer;
359 
360  friend class RTCPSenderInfo;
361  friend class RTCPReceiverInfo;
362 private:
363  // path MTU. RTCP packets should not be greater than this
364  uint16 pathMTU;
365  // masks for RTCP header validation;
366  static const uint16 RTCP_VALID_MASK;
367  static const uint16 RTCP_VALID_VALUE;
368 };
369 
377 {
378 public:
380  { memcpy(&receiverInfo,&ri,
382 
384  : receiverInfo( si )
385  {
386  }
387 
389  { }
390 
395  inline uint8
397  { return receiverInfo.fractionLost; }
398 
399  inline uint32
401  { return ( ((uint32)ntohs(receiverInfo.lostLSW)) +
402  (((uint32)receiverInfo.lostMSB) << 16) ); }
403 
404  inline uint32
406  { return ntohl(receiverInfo.highestSeqNum); }
407 
414  uint32
415  getJitter() const
416  { return ntohl(receiverInfo.jitter); }
417 
423  uint16
425  { return (uint16)((ntohl(receiverInfo.lsr) & 0xFFFF0000) >> 16); }
426 
432  uint16
434  { return (uint16)(ntohl(receiverInfo.lsr) & 0xFFFF); }
435 
442  uint32
444  { return ntohl(receiverInfo.dlsr); }
445 
446 private:
448 };
449 
457 {
458 public:
459  RTCPSenderInfo(void* si)
460  { memcpy(&senderInfo,&si,
462 
464  : senderInfo( si )
465  {
466  }
467 
469  { }
470 
475  uint32
477  { return ntohl(senderInfo.NTPMSW); }
478 
483  uint32
485  { return ntohl(senderInfo.NTPLSW); }
486 
487  inline uint32
489  { return ntohl(senderInfo.RTPTimestamp); }
490 
494  inline uint32
496  { return ntohl(senderInfo.packetCount); }
497 
498  inline uint32
500  { return ntohl(senderInfo.octetCount); }
501 
502 private:
504 };
505 
514 timeval
515 NTP2Timeval(uint32 msw, uint32 lsw);
516 
524 uint32
525 timevalIntervalTo65536(timeval& t);
526  // rtcppacket
528 
529 #ifdef CCXX_NAMESPACES
530 }
531 #endif
532 
533 #endif // ndef CCXX_RTP_RTCPPKT_H_
534 
Struct for a receiver info block in a SR (sender report) or an RR (receiver report) RTCP packet...
Definition: rtcppkt.h:128
uint32 lsr
last sender report timestamp.
Definition: rtcppkt.h:118
uint32 getNTPTimestampFrac() const
Get fractional part of the NTP timestamp of this packet.
Definition: rtcppkt.h:484
uint32 getNTPTimestampInt() const
Get integer part of the NTP timestamp of this packet.
Definition: rtcppkt.h:476
RTCPReceiverInfo(RTCPCompoundHandler::ReceiverInfo &si)
Definition: rtcppkt.h:383
unsigned char * rtcpSendBuffer
Definition: rtcppkt.h:355
low level structs and RTCP packet parsing and building methods.
Definition: rtcppkt.h:92
Last defined code.
Definition: rtcppkt.h:79
End of participation.
Definition: rtcppkt.h:291
ReceiverInfo rinfo
info about the source.
Definition: rtcppkt.h:131
uint32 highestSeqNum
highest sequence number.
Definition: rtcppkt.h:116
uint32 ssrc
ssrc identifier of source leaving.
Definition: rtcppkt.h:206
uint32 jitter
arrival jitter.
Definition: rtcppkt.h:117
uint32 octetCount
cumulative octet counter.
Definition: rtcppkt.h:158
static const uint16 RTCP_VALID_MASK
Definition: rtcppkt.h:366
Sender block information of SR RTCP reports.
Definition: rtcppkt.h:456
APPlication specific.
Definition: rtcppkt.h:292
Canonical end-point identifier.
Definition: rtcppkt.h:70
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:433
Comment usually reporting state.
Definition: rtcppkt.h:76
static const uint16 RTCP_VALID_VALUE
Definition: rtcppkt.h:367
uint32 getLength() const
Get the packet length specified in its header, in octets and in host order.
Definition: rtcppkt.h:302
__EXPORT AppLog & info(AppLog &sl)
Manipulator for info level.
Definition: applog.h:581
void setPathMTU(uint16 mtu)
Definition: rtcppkt.h:95
RTCPReceiverInfo(void *ri)
Definition: rtcppkt.h:379
uint32 dlsr
delay since last sender report.
Definition: rtcppkt.h:119
Fixed RTCP packet header.
Definition: rtcppkt.h:253
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:424
Phone number of the user.
Definition: rtcppkt.h:73
uint16 lostLSW
cumulative lost two LSB.
Definition: rtcppkt.h:115
Struct for BYE (leaving session) RTCP packets.
Definition: rtcppkt.h:204
uint8 lostMSB
cumulative lost MSB of 3 octets.
Definition: rtcppkt.h:114
uint8 len
item len in octets.
Definition: rtcppkt.h:181
uint8 type
type of RTCP packet.
Definition: rtcppkt.h:266
uint32 ssrc
SSRC identifer from sender.
Definition: rtcppkt.h:195
uint32 NTPMSW
NTP timestamp higher octets.
Definition: rtcppkt.h:154
uint32 ssrc
ssrc identifier of source.
Definition: rtcppkt.h:243
uint32 getOctetCount() const
Definition: rtcppkt.h:499
Struct for the sender info block in a SR (sender report) RTCP packet.
Definition: rtcppkt.h:152
Struct for SR (sender report) RTCP packets.
Definition: rtcppkt.h:166
uint8 length
[optional] length of reason.
Definition: rtcppkt.h:207
uint32 getSSRC() const
Definition: rtcppkt.h:192
uint16 blp
Bitmask of following Lost Packets.
Definition: rtcppkt.h:245
uint8 type
item identifier.
Definition: rtcppkt.h:180
SenderInfo sinfo
actual sender info.
Definition: rtcppkt.h:169
RTCPSenderInfo(void *si)
Definition: rtcppkt.h:459
SDESItem item
SDES item from sender.
Definition: rtcppkt.h:196
Struct for a chunk of items in a SDES RTCP packet.
Definition: rtcppkt.h:190
END of SDES item list.
Definition: rtcppkt.h:69
Struct representing general RTCP packet headers as they are sent through the network.
Definition: rtcppkt.h:280
Private extension.
Definition: rtcppkt.h:77
uint32 timevalIntervalTo65536(timeval &t)
Convert a time interval, expressed as a timeval, into a 32-bit time interval expressed in units of 1/...
uint32 getPacketCount() const
Get count of sent data packets.
Definition: rtcppkt.h:495
RTCPCompoundHandler::SenderInfo senderInfo
Definition: rtcppkt.h:503
Struct for Full Intra-frame Request (FIR) RTCP packet.
Definition: rtcppkt.h:230
Personal NAME of the user.
Definition: rtcppkt.h:71
uint16 getPathMTU()
Definition: rtcppkt.h:98
uint32 RTPTimestamp
RTP timestamp.
Definition: rtcppkt.h:156
H323 callable address.
Definition: rtcppkt.h:78
uint16 fsn
First Sequence Number lost.
Definition: rtcppkt.h:244
raw structure of the source and every receiver report in an SR or RR RTCP packet. ...
Definition: rtcppkt.h:140
#define __EXPORT
Definition: audio2.h:51
unsigned char * rtcpRecvBuffer
Definition: rtcppkt.h:358
uint32 ssrc
source identifier.
Definition: rtcppkt.h:142
uint32 getSSRC() const
Get the SSRC identifier specified in the packet header, in host order.
Definition: rtcppkt.h:309
uint16 length
number of 32-bit words in the packet (minus one).
Definition: rtcppkt.h:267
Struct for an item description of a SDES packet.
Definition: rtcppkt.h:178
Base elements for RTP stacks: constants, types and global functions.
uint32 getRTPTimestamp() const
Definition: rtcppkt.h:488
RTCPSenderInfo(RTCPCompoundHandler::SenderInfo &si)
Definition: rtcppkt.h:463
Struct for Negative ACKnowledgements (NACK) RTCP packet.
Definition: rtcppkt.h:241
uint8 fractionLost
packet fraction lost.
Definition: rtcppkt.h:113
Report block information of SR/RR RTCP reports.
Definition: rtcppkt.h:376
timeval NTP2Timeval(uint32 msw, uint32 lsw)
Convert a NTP timestamp, expressed as two 32-bit long words, into a timeval value.
uint32 getDelayLastSR() const
Get the delay between the last SR packet received and the transmission of this report.
Definition: rtcppkt.h:443
RTCPCompoundHandler::ReceiverInfo receiverInfo
Definition: rtcppkt.h:447
uint32 ssrc
ssrc identifier of source.
Definition: rtcppkt.h:217
uint32 ssrc
source identifier.
Definition: rtcppkt.h:130
uint32 getCumulativePacketLost() const
Definition: rtcppkt.h:400
Struct for APP (application specific) RTCP packets.
Definition: rtcppkt.h:215
uint8 getFractionLost() const
Get fraction of lost packets, as a number between 0 and 255.
Definition: rtcppkt.h:396
uint32 getJitter() const
Get the statistical variance of the RTP data packets interarrival time.
Definition: rtcppkt.h:415
RTCPFixedHeader fh
Fixed RTCP header.
Definition: rtcppkt.h:313
Application or tool.
Definition: rtcppkt.h:75
uint32 packetCount
cumulative packet counter.
Definition: rtcppkt.h:157
uint32 ssrc
ssrc identifier of source.
Definition: rtcppkt.h:232
uint32 NTPLSW
NTP timestamp lower octets.
Definition: rtcppkt.h:155
uint32 getExtendedSeqNum() const
Definition: rtcppkt.h:405
EMAIL address of the user.
Definition: rtcppkt.h:72
SDESItemType
SDES items that may be carried in a Source DEScription RTCP packet.
Definition: rtcppkt.h:67
Struct for the data contained in a receiver info block.
Definition: rtcppkt.h:111
Location where the user is.
Definition: rtcppkt.h:74
uint32 ssrc
source identifier.
Definition: rtcppkt.h:168