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 #ifdef CCXX_NAMESPACES
44 namespace ost {
45 #endif
46 
67 typedef enum
68 {
80 } SDESItemType;
81 
92 class __EXPORT RTCPCompoundHandler
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 
220 
221  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 
257  unsigned char version:2;
258  unsigned char padding:1;
259  unsigned char block_count:5;
260 #else
261 
262  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 
376 class __EXPORT RTCPReceiverInfo
377 {
378 public:
380  { memcpy(&receiverInfo,&ri,
382 
384  : receiverInfo( si )
385  {
386  }
387 
389  { }
390 
395  inline uint8
396  getFractionLost() const
397  { return receiverInfo.fractionLost; }
398 
399  inline uint32
400  getCumulativePacketLost() const
401  { return ( ((uint32)ntohs(receiverInfo.lostLSW)) +
402  (((uint32)receiverInfo.lostMSB) << 16) ); }
403 
404  inline uint32
405  getExtendedSeqNum() const
406  { return ntohl(receiverInfo.highestSeqNum); }
407 
414  uint32
415  getJitter() const
416  { return ntohl(receiverInfo.jitter); }
417 
423  uint16
424  getLastSRNTPTimestampInt() const
425  { return (uint16)((ntohl(receiverInfo.lsr) & 0xFFFF0000) >> 16); }
426 
432  uint16
433  getLastSRNTPTimestampFrac() const
434  { return (uint16)(ntohl(receiverInfo.lsr) & 0xFFFF); }
435 
442  uint32
443  getDelayLastSR() const
444  { return ntohl(receiverInfo.dlsr); }
445 
446 private:
448 };
449 
456 class __EXPORT RTCPSenderInfo
457 {
458 public:
459  RTCPSenderInfo(void* si)
460  { memcpy(&senderInfo,&si,
462 
464  : senderInfo( si )
465  {
466  }
467 
469  { }
470 
475  uint32
476  getNTPTimestampInt() const
477  { return ntohl(senderInfo.NTPMSW); }
478 
483  uint32
484  getNTPTimestampFrac() const
485  { return ntohl(senderInfo.NTPLSW); }
486 
487  inline uint32
488  getRTPTimestamp() const
489  { return ntohl(senderInfo.RTPTimestamp); }
490 
494  inline uint32
495  getPacketCount() const
496  { return ntohl(senderInfo.packetCount); }
497 
498  inline uint32
499  getOctetCount() const
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