Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Examples

rtcppkt.h

Go to the documentation of this file.
00001 // Copyright (C) 2001, 2002, 2004 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 #pragma pack(1) 
00102 
00109         struct ReceiverInfo
00110         {
00111                 uint8 fractionLost;      
00112                 uint8 lostMSB;           
00113                 uint16 lostLSW;          
00114                 uint32 highestSeqNum;    
00115                 uint32 jitter;           
00116                 uint32 lsr;              
00117                 uint32 dlsr;             
00118         };
00119         
00126         struct RRBlock
00127         {
00128                 uint32 ssrc;                   
00129                 ReceiverInfo rinfo;            
00130         };
00131         
00138         struct RecvReport
00139         {
00140                 uint32 ssrc;                 
00141                 RRBlock blocks[1];           
00142         };
00143         
00150         struct SenderInfo
00151         {
00152                 uint32 NTPMSW;              
00153                 uint32 NTPLSW;              
00154                 uint32 RTPTimestamp;        
00155                 uint32 packetCount;         
00156                 uint32 octetCount;          
00157         };
00158         
00164         struct SendReport
00165         {
00166                 uint32 ssrc;       
00167                 SenderInfo sinfo;  
00168                 RRBlock blocks[1]; 
00169         };
00170         
00176         struct SDESItem 
00177         {
00178                 uint8 type;       
00179                 uint8 len;        
00180                 char data[1];     
00181         };
00182 
00188         struct SDESChunk 
00189         {
00190                 uint32 getSSRC() const
00191                 { return (ntohl(ssrc)); }
00192 
00193                 uint32 ssrc;      
00194                 SDESItem item;    
00195         };
00196 
00202         struct BYEPacket 
00203         {
00204                 uint32 ssrc;          
00205                 uint8 length;         
00206         };
00207         
00213         struct APPPacket
00214         {
00215                 uint32 ssrc;           
00216                 char name [4];         
00217 
00218 
00219                 unsigned char data[1]; 
00220         };
00221 
00228         struct FIRPacket
00229         {
00230                 uint32 ssrc;           
00231         };
00232 
00239         struct NACKPacket
00240         {
00241                 uint32 ssrc;           
00242                 uint16 fsn;            
00243                 uint16 blp;            
00244         };
00245 
00251         struct RTCPFixedHeader
00252         {
00253 #if     __BYTE_ORDER == __BIG_ENDIAN
00254 
00255                 unsigned char version:2;      
00256                 unsigned char padding:1;      
00257                 unsigned char block_count:5;  
00258 #else
00259 
00260                 unsigned char block_count:5;  
00261                 unsigned char padding:1;      
00262                 unsigned char version:2;      
00263 #endif
00264                 uint8 type;    
00265                 uint16 length; 
00266         };
00267 
00278         struct RTCPPacket
00279         {
00285                 typedef enum {
00286                         tSR = 200,      
00287                         tRR,            
00288                         tSDES,          
00289                         tBYE,           
00290                         tAPP,           
00291                         tFIR   = 192,   
00292                         tNACK  = 193,   
00293                         tXR             
00294                 }       Type;
00295                 
00300                 uint32 getLength() const
00301                 { return ((ntohs(fh.length) + 1) << 2); }
00302 
00307                 uint32 getSSRC()  const                 
00308                 { return (ntohl(info.RR.ssrc)); } // SSRC is always the first
00309                                                   // word after fh.
00310 
00311                 RTCPFixedHeader fh;           
00312 
00313                 // An RTCP packet may be of any of the types defined
00314                 // above, including APP specific ones.
00315                 union
00316                 {
00317                         SendReport SR;
00318                         RecvReport RR;
00319                         SDESChunk SDES; 
00320                         BYEPacket BYE;
00321                         APPPacket APP;
00322                         NACKPacket NACK;
00323                         FIRPacket FIR;
00324                 }       info;        
00325         };
00326 #pragma pack()
00327 
00328 protected:
00329         enum { defaultPathMTU = 1500 };
00330 
00331         RTCPCompoundHandler(uint16 mtu = defaultPathMTU);
00332 
00333         ~RTCPCompoundHandler();
00334 
00346         bool
00347         checkCompoundRTCPHeader(size_t len);
00348 
00349         // buffer to hold RTCP compound packets being sent. Allocated
00350         // in construction time
00351         unsigned char* rtcpSendBuffer;
00352         // buffer to hold RTCP compound packets being
00353         // received. Allocated at construction time
00354         unsigned char* rtcpRecvBuffer;
00355 
00356         friend class RTCPSenderInfo;
00357         friend class RTCPReceiverInfo;
00358 private:
00359         // path MTU. RTCP packets should not be greater than this
00360         uint16 pathMTU;
00361         // masks for RTCP header validation;
00362         static const uint16 RTCP_VALID_MASK;
00363         static const uint16 RTCP_VALID_VALUE;
00364 };
00365 
00372 class __EXPORT RTCPReceiverInfo
00373 {
00374 public:
00375         RTCPReceiverInfo(void* ri)
00376         { memcpy(&receiverInfo,&ri,
00377                  sizeof(RTCPCompoundHandler::ReceiverInfo));}
00378 
00379         ~RTCPReceiverInfo()
00380         { }
00381 
00386         inline uint8
00387         getFractionLost() const
00388         { return receiverInfo.fractionLost; }
00389 
00390         inline uint32
00391         getCumulativePacketLost() const
00392         { return ( ((uint32)ntohs(receiverInfo.lostLSW)) + 
00393                    (((uint32)receiverInfo.lostMSB) << 16) ); }
00394         
00395         inline uint32
00396         getExtendedSeqNum() const
00397         { return ntohl(receiverInfo.highestSeqNum); }
00398 
00405         uint32
00406         getJitter() const
00407         { return ntohl(receiverInfo.jitter); }
00408 
00414         uint16
00415         getLastSRNTPTimestampInt() const
00416         { return (uint16)((ntohl(receiverInfo.lsr) & 0xFFFF0000) >> 16); }
00417 
00423         uint16
00424         getLastSRNTPTimestampFrac() const
00425         { return (uint16)(ntohl(receiverInfo.lsr) & 0xFFFF); }
00426 
00433         uint32
00434         getDelayLastSR() const
00435         { return ntohl(receiverInfo.dlsr); }    
00436 
00437 private:
00438         RTCPCompoundHandler::ReceiverInfo receiverInfo;
00439 };
00440 
00447 class __EXPORT RTCPSenderInfo
00448 {
00449 public:
00450         RTCPSenderInfo(void* si)
00451         { memcpy(&senderInfo,&si,
00452                  sizeof(RTCPCompoundHandler::SenderInfo));}
00453 
00454         ~RTCPSenderInfo()
00455         { }
00456 
00461         uint32
00462         getNTPTimestampInt() const
00463         { return ntohl(senderInfo.NTPMSW); }
00464 
00469         uint32
00470         getNTPTimestampFrac() const
00471         { return ntohl(senderInfo.NTPLSW); }
00472 
00473         inline uint32
00474         getRTPTimestamp() const
00475         { return ntohl(senderInfo.RTPTimestamp); }
00476 
00480         inline uint32
00481         getPacketCount() const
00482         { return ntohl(senderInfo.octetCount); }
00483         
00484         inline uint32
00485         getOctetCount() const
00486         { return ntohl(senderInfo.packetCount); }
00487 
00488 private:
00489         RTCPCompoundHandler::SenderInfo senderInfo;
00490 };
00491 
00500 timeval
00501 NTP2Timeval(uint32 msw, uint32 lsw);
00502 
00510 uint32
00511 timevalIntervalTo65536(timeval& t);
00512  // rtcppacket
00514 
00515 #ifdef  CCXX_NAMESPACES
00516 }
00517 #endif
00518 
00519 #endif  // ndef CCXX_RTP_RTCPPKT_H_
00520 

Generated on Tue Jun 7 17:18:46 2005 for ccRTP by  doxygen 1.4.2