Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages | 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 #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()
00384         { }
00385 
00390         inline uint8
00391         getFractionLost() const
00392         { return receiverInfo.fractionLost; }
00393 
00394         inline uint32
00395         getCumulativePacketLost() const
00396         { return ( ((uint32)ntohs(receiverInfo.lostLSW)) + 
00397                    (((uint32)receiverInfo.lostMSB) << 16) ); }
00398         
00399         inline uint32
00400         getExtendedSeqNum() const
00401         { return ntohl(receiverInfo.highestSeqNum); }
00402 
00409         uint32
00410         getJitter() const
00411         { return ntohl(receiverInfo.jitter); }
00412 
00418         uint16
00419         getLastSRNTPTimestampInt() const
00420         { return (uint16)((ntohl(receiverInfo.lsr) & 0xFFFF0000) >> 16); }
00421 
00427         uint16
00428         getLastSRNTPTimestampFrac() const
00429         { return (uint16)(ntohl(receiverInfo.lsr) & 0xFFFF); }
00430 
00437         uint32
00438         getDelayLastSR() const
00439         { return ntohl(receiverInfo.dlsr); }    
00440 
00441 private:
00442         RTCPCompoundHandler::ReceiverInfo receiverInfo;
00443 };
00444 
00451 class __EXPORT RTCPSenderInfo
00452 {
00453 public:
00454         RTCPSenderInfo(void* si)
00455         { memcpy(&senderInfo,&si,
00456                  sizeof(RTCPCompoundHandler::SenderInfo));}
00457 
00458         ~RTCPSenderInfo()
00459         { }
00460 
00465         uint32
00466         getNTPTimestampInt() const
00467         { return ntohl(senderInfo.NTPMSW); }
00468 
00473         uint32
00474         getNTPTimestampFrac() const
00475         { return ntohl(senderInfo.NTPLSW); }
00476 
00477         inline uint32
00478         getRTPTimestamp() const
00479         { return ntohl(senderInfo.RTPTimestamp); }
00480 
00484         inline uint32
00485         getPacketCount() const
00486         { return ntohl(senderInfo.octetCount); }
00487         
00488         inline uint32
00489         getOctetCount() const
00490         { return ntohl(senderInfo.packetCount); }
00491 
00492 private:
00493         RTCPCompoundHandler::SenderInfo senderInfo;
00494 };
00495 
00504 timeval
00505 NTP2Timeval(uint32 msw, uint32 lsw);
00506 
00514 uint32
00515 timevalIntervalTo65536(timeval& t);
00516  // rtcppacket
00518 
00519 #ifdef  CCXX_NAMESPACES
00520 }
00521 #endif
00522 
00523 #endif  // ndef CCXX_RTP_RTCPPKT_H_
00524 

Generated on Sun Apr 30 08:50:28 2006 for ccRTP by  doxygen 1.4.4