- Main Page
- Modules
- Classes
- Files
- Examples

- File List
- File Members

# rtcppkt.h

Go to the documentation of this file.

    00001 // Copyright (C) 2001,2002,2004,2007 Federico Montesino Pouzols <fedemp@altern.org>.
    00002 //
    00003 // This program is free software; you can redistribute it and/or modify
    00004 // it under the terms of the GNU General Public License as published by
    00005 // the Free Software Foundation; either version 2 of the License, or
    00006 // (at your option) any later version.
    00007 //
    00008 // This program is distributed in the hope that it will be useful,
    00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00011 // GNU General Public License for more details.
    00012 //
    00013 // You should have received a copy of the GNU General Public License
    00014 // along with this program; if not, write to the Free Software
    00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    00016 //
    00017 // As a special exception, you may use this file as part of a free software
    00018 // library without restriction.  Specifically, if other files instantiate
    00019 // templates or use macros or inline functions from this file, or you compile
    00020 // this file and link it with other files to produce an executable, this
    00021 // file does not by itself cause the resulting executable to be covered by
    00022 // the GNU General Public License.  This exception does not however
    00023 // invalidate any other reasons why the executable file might be covered by
    00024 // the GNU General Public License.
    00025 //
    00026 // This exception applies only to the code released under the name GNU
    00027 // ccRTP.  If you copy code from other releases into a copy of GNU
    00028 // ccRTP, as the General Public License permits, the exception does
    00029 // not apply to the code that you add in this way.  To avoid misleading
    00030 // anyone as to the status of such modified files, you must delete
    00031 // this exception notice from them.
    00032 //
    00033 // If you write modifications of your own for GNU ccRTP, it is your choice
    00034 // whether to permit this exception to apply to your modifications.
    00035 // If you do not wish that, delete this exception notice.
    00036 //
    00037
    00038 #ifndef CCXX_RTP_RTCPPKT_H_
    00039 #define CCXX_RTP_RTCPPKT_H_
    00040
    00041 #include <ccrtp/base.h>
    00042
    00043 #ifdef CCXX_NAMESPACES
    00044 namespace ost {
    00045 #endif
    00046
    00067 typedef enum
    00068 {
    00069         SDESItemTypeEND = 0,
    00070         SDESItemTypeCNAME,
    00071         SDESItemTypeNAME,
    00072         SDESItemTypeEMAIL,
    00073         SDESItemTypePHONE,
    00074         SDESItemTypeLOC,
    00075         SDESItemTypeTOOL,
    00076         SDESItemTypeNOTE,
    00077         SDESItemTypePRIV,
    00078         SDESItemTypeH323CADDR,
    00079         SDESItemTypeLast = SDESItemTypeH323CADDR
    00080 }       SDESItemType;
    00081
    00092 class __EXPORT RTCPCompoundHandler
    00093 {
    00094 public:
    00095         inline void setPathMTU(uint16 mtu)
    00096         { pathMTU = mtu; }
    00097
    00098         inline uint16 getPathMTU()
    00099         { return pathMTU; }
    00100
    00101 #ifdef  CCXX_PACKED
    00102 #pragma pack(1)
    00103 #endif
    00104
    00111         struct ReceiverInfo
    00112         {
    00113                 uint8 fractionLost;
    00114                 uint8 lostMSB;
    00115                 uint16 lostLSW;
    00116                 uint32 highestSeqNum;
    00117                 uint32 jitter;
    00118                 uint32 lsr;
    00119                 uint32 dlsr;
    00120         };
    00121
    00128         struct RRBlock
    00129         {
    00130                 uint32 ssrc;
    00131                 ReceiverInfo rinfo;
    00132         };
    00133
    00140         struct RecvReport
    00141         {
    00142                 uint32 ssrc;
    00143                 RRBlock blocks[1];
    00144         };
    00145
    00152         struct SenderInfo
    00153         {
    00154                 uint32 NTPMSW;
    00155                 uint32 NTPLSW;
    00156                 uint32 RTPTimestamp;
    00157                 uint32 packetCount;
    00158                 uint32 octetCount;
    00159         };
    00160
    00166         struct SendReport
    00167         {
    00168                 uint32 ssrc;
    00169                 SenderInfo sinfo;
    00170                 RRBlock blocks[1];
    00171         };
    00172
    00178         struct SDESItem
    00179         {
    00180                 uint8 type;
    00181                 uint8 len;
    00182                 char data[1];
    00183         };
    00184
    00190         struct SDESChunk
    00191         {
    00192                 uint32 getSSRC() const
    00193                 { return (ntohl(ssrc)); }
    00194
    00195                 uint32 ssrc;
    00196                 SDESItem item;
    00197         };
    00198
    00204         struct BYEPacket
    00205         {
    00206                 uint32 ssrc;
    00207                 uint8 length;
    00208         };
    00209
    00215         struct APPPacket
    00216         {
    00217                 uint32 ssrc;
    00218                 char name [4];
    00219
    00220
    00221                 unsigned char data[1];
    00222         };
    00223
    00230         struct FIRPacket
    00231         {
    00232                 uint32 ssrc;
    00233         };
    00234
    00241         struct NACKPacket
    00242         {
    00243                 uint32 ssrc;
    00244                 uint16 fsn;
    00245                 uint16 blp;
    00246         };
    00247
    00253         struct RTCPFixedHeader
    00254         {
    00255 #if     __BYTE_ORDER == __BIG_ENDIAN
    00256
    00257                 unsigned char version:2;
    00258                 unsigned char padding:1;
    00259                 unsigned char block_count:5;
    00260 #else
    00261
    00262                 unsigned char block_count:5;
    00263                 unsigned char padding:1;
    00264                 unsigned char version:2;
    00265 #endif
    00266                 uint8 type;
    00267                 uint16 length;
    00268         };
    00269
    00280         struct RTCPPacket
    00281         {
    00287                 typedef enum {
    00288                         tSR = 200,
    00289                         tRR,
    00290                         tSDES,
    00291                         tBYE,
    00292                         tAPP,
    00293                         tFIR   = 192,
    00294                         tNACK  = 193,
    00295                         tXR
    00296                 }       Type;
    00297
    00302                 uint32 getLength() const
    00303                 { return ((ntohs(fh.length) + 1) << 2); }
    00304
    00309                 uint32 getSSRC()  const
    00310                 { return (ntohl(info.RR.ssrc)); } // SSRC is always the first
    00311                                                   // word after fh.
    00312
    00313                 RTCPFixedHeader fh;
    00314
    00315                 // An RTCP packet may be of any of the types defined
    00316                 // above, including APP specific ones.
    00317                 union
    00318                 {
    00319                         SendReport SR;
    00320                         RecvReport RR;
    00321                         SDESChunk SDES;
    00322                         BYEPacket BYE;
    00323                         APPPacket APP;
    00324                         NACKPacket NACK;
    00325                         FIRPacket FIR;
    00326                 }       info;
    00327         };
    00328 #ifdef  CCXX_PACKED
    00329 #pragma pack()
    00330 #endif
    00331
    00332 protected:
    00333         enum { defaultPathMTU = 1500 };
    00334
    00335         RTCPCompoundHandler(uint16 mtu = defaultPathMTU);
    00336
    00337         ~RTCPCompoundHandler();
    00338
    00350         bool
    00351         checkCompoundRTCPHeader(size_t len);
    00352
    00353         // buffer to hold RTCP compound packets being sent. Allocated
    00354         // in construction time
    00355         unsigned char* rtcpSendBuffer;
    00356         // buffer to hold RTCP compound packets being
    00357         // received. Allocated at construction time
    00358         unsigned char* rtcpRecvBuffer;
    00359
    00360         friend class RTCPSenderInfo;
    00361         friend class RTCPReceiverInfo;
    00362 private:
    00363         // path MTU. RTCP packets should not be greater than this
    00364         uint16 pathMTU;
    00365         // masks for RTCP header validation;
    00366         static const uint16 RTCP_VALID_MASK;
    00367         static const uint16 RTCP_VALID_VALUE;
    00368 };
    00369
    00376 class __EXPORT RTCPReceiverInfo
    00377 {
    00378 public:
    00379         RTCPReceiverInfo(void* ri)
    00380         { memcpy(&receiverInfo,&ri,
    00381                  sizeof(RTCPCompoundHandler::ReceiverInfo));}
    00382
    00383         RTCPReceiverInfo(RTCPCompoundHandler::ReceiverInfo& si)
    00384                 : receiverInfo( si )
    00385         {
    00386         }
    00387
    00388         ~RTCPReceiverInfo()
    00389         { }
    00390
    00395         inline uint8
    00396         getFractionLost() const
    00397         { return receiverInfo.fractionLost; }
    00398
    00399         inline uint32
    00400         getCumulativePacketLost() const
    00401         { return ( ((uint32)ntohs(receiverInfo.lostLSW)) +
    00402                    (((uint32)receiverInfo.lostMSB) << 16) ); }
    00403
    00404         inline uint32
    00405         getExtendedSeqNum() const
    00406         { return ntohl(receiverInfo.highestSeqNum); }
    00407
    00414         uint32
    00415         getJitter() const
    00416         { return ntohl(receiverInfo.jitter); }
    00417
    00423         uint16
    00424         getLastSRNTPTimestampInt() const
    00425         { return (uint16)((ntohl(receiverInfo.lsr) & 0xFFFF0000) >> 16); }
    00426
    00432         uint16
    00433         getLastSRNTPTimestampFrac() const
    00434         { return (uint16)(ntohl(receiverInfo.lsr) & 0xFFFF); }
    00435
    00442         uint32
    00443         getDelayLastSR() const
    00444         { return ntohl(receiverInfo.dlsr); }
    00445
    00446 private:
    00447         RTCPCompoundHandler::ReceiverInfo receiverInfo;
    00448 };
    00449
    00456 class __EXPORT RTCPSenderInfo
    00457 {
    00458 public:
    00459         RTCPSenderInfo(void* si)
    00460         { memcpy(&senderInfo,&si,
    00461                  sizeof(RTCPCompoundHandler::SenderInfo));}
    00462
    00463         RTCPSenderInfo(RTCPCompoundHandler::SenderInfo& si)
    00464                 : senderInfo( si )
    00465         {
    00466         }
    00467
    00468         ~RTCPSenderInfo()
    00469         { }
    00470
    00475         uint32
    00476         getNTPTimestampInt() const
    00477         { return ntohl(senderInfo.NTPMSW); }
    00478
    00483         uint32
    00484         getNTPTimestampFrac() const
    00485         { return ntohl(senderInfo.NTPLSW); }
    00486
    00487         inline uint32
    00488         getRTPTimestamp() const
    00489         { return ntohl(senderInfo.RTPTimestamp); }
    00490
    00494         inline uint32
    00495         getPacketCount() const
    00496         { return ntohl(senderInfo.packetCount); }
    00497
    00498         inline uint32
    00499         getOctetCount() const
    00500         { return ntohl(senderInfo.octetCount); }
    00501
    00502 private:
    00503         RTCPCompoundHandler::SenderInfo senderInfo;
    00504 };
    00505
    00514 timeval
    00515 NTP2Timeval(uint32 msw, uint32 lsw);
    00516
    00524 uint32
    00525 timevalIntervalTo65536(timeval& t);
    00526  // rtcppacket
    00528
    00529 #ifdef  CCXX_NAMESPACES
    00530 }
    00531 #endif
    00532
    00533 #endif  // ndef CCXX_RTP_RTCPPKT_H_
    00534