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 
42 NAMESPACE_COMMONCPP
43 
64 typedef enum
65 {
77 } SDESItemType;
78 
89 class __EXPORT RTCPCompoundHandler
90 {
91 public:
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
101 
109  {
110  uint8 fractionLost;
111  uint8 lostMSB;
112  uint16 lostLSW;
113  uint32 highestSeqNum;
114  uint32 jitter;
115  uint32 lsr;
116  uint32 dlsr;
117  };
118 
125  struct RRBlock
126  {
127  uint32 ssrc;
129  };
130 
137  struct RecvReport
138  {
139  uint32 ssrc;
140  RRBlock blocks[1];
141  };
142 
149  struct SenderInfo
150  {
151  uint32 NTPMSW;
152  uint32 NTPLSW;
153  uint32 RTPTimestamp;
154  uint32 packetCount;
155  uint32 octetCount;
156  };
157 
163  struct SendReport
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 
187  struct SDESChunk
188  {
189  uint32 getSSRC() const
190  { return (ntohl(ssrc)); }
191 
192  uint32 ssrc;
194  };
195 
201  struct BYEPacket
202  {
203  uint32 ssrc;
204  uint8 length;
205  };
206 
212  struct APPPacket
213  {
214  uint32 ssrc;
215  char name [4];
216 
217 
218  unsigned char data[1];
219  };
220 
227  struct FIRPacket
228  {
229  uint32 ssrc;
230  };
231 
238  struct NACKPacket
239  {
240  uint32 ssrc;
241  uint16 fsn;
242  uint16 blp;
243  };
244 
251  {
252 #if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN
253 
254  unsigned char version:2;
255  unsigned char padding:1;
256  unsigned char block_count:5;
257 #else
258 
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 
277  struct RTCPPacket
278  {
284  typedef enum {
285  tSR = 200,
286  tRR,
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 
329 protected:
330  enum { defaultPathMTU = 1500 };
331 
332  RTCPCompoundHandler(uint16 mtu = defaultPathMTU);
333 
335 
347  bool
348  checkCompoundRTCPHeader(size_t len);
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;
359 private:
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 
373 class __EXPORT RTCPReceiverInfo
374 {
375 public:
377  { memcpy(&receiverInfo,&ri,
379 
381  : receiverInfo( si )
382  {
383  }
384 
386  { }
387 
392  inline uint8
393  getFractionLost() const
394  { return receiverInfo.fractionLost; }
395 
396  inline uint32
397  getCumulativePacketLost() const
398  { return ( ((uint32)ntohs(receiverInfo.lostLSW)) +
399  (((uint32)receiverInfo.lostMSB) << 16) ); }
400 
401  inline uint32
402  getExtendedSeqNum() const
403  { return ntohl(receiverInfo.highestSeqNum); }
404 
411  uint32
412  getJitter() const
413  { return ntohl(receiverInfo.jitter); }
414 
420  uint16
421  getLastSRNTPTimestampInt() const
422  { return (uint16)((ntohl(receiverInfo.lsr) & 0xFFFF0000) >> 16); }
423 
429  uint16
430  getLastSRNTPTimestampFrac() const
431  { return (uint16)(ntohl(receiverInfo.lsr) & 0xFFFF); }
432 
439  uint32
440  getDelayLastSR() const
441  { return ntohl(receiverInfo.dlsr); }
442 
443 private:
445 };
446 
453 class __EXPORT RTCPSenderInfo
454 {
455 public:
456  RTCPSenderInfo(void* si)
457  { memcpy(&senderInfo,&si,
459 
461  : senderInfo( si )
462  {
463  }
464 
466  { }
467 
472  uint32
473  getNTPTimestampInt() const
474  { return ntohl(senderInfo.NTPMSW); }
475 
480  uint32
481  getNTPTimestampFrac() const
482  { return ntohl(senderInfo.NTPLSW); }
483 
484  inline uint32
485  getRTPTimestamp() const
486  { return ntohl(senderInfo.RTPTimestamp); }
487 
491  inline uint32
492  getPacketCount() const
493  { return ntohl(senderInfo.packetCount); }
494 
495  inline uint32
496  getOctetCount() const
497  { return ntohl(senderInfo.octetCount); }
498 
499 private:
501 };
502 
511 timeval
512 NTP2Timeval(uint32 msw, uint32 lsw);
513 
521 uint32
522 timevalIntervalTo65536(timeval& t);
523  // rtcppacket
525 
526 END_NAMESPACE
527 
528 #endif // ndef CCXX_RTP_RTCPPKT_H_
529