Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

rtpext.h

Go to the documentation of this file.
00001 // Copyright (C) 1999-2001 Open Source Telecom Corporation.
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 to the GNU General Public License, permission is 
00018 // granted for additional uses of the text contained in its release 
00019 // of ccRTP.
00020 // 
00021 // The exception is that, if you link the ccRTP library with other
00022 // files to produce an executable, this does not by itself cause the
00023 // resulting executable to be covered by the GNU General Public License.
00024 // Your use of that executable is in no way restricted on account of
00025 // linking the ccRTP library code into it.
00026 // 
00027 // This exception does not however invalidate any other reasons why
00028 // the executable file might be covered by the GNU General Public License.
00029 // 
00030 // This exception applies only to the code released under the 
00031 // name ccRTP.  If you copy code from other releases into a copy of
00032 // ccRTP, as the General Public License permits, the exception does
00033 // not apply to the code that you add in this way.  To avoid misleading
00034 // anyone as to the status of such modified files, you must delete
00035 // this exception notice from them.
00036 // 
00037 // If you write modifications of your own for ccRTP, it is your choice
00038 // whether to permit this exception to apply to your modifications.
00039 // If you do not wish that, delete this exception notice.  
00040 
00049 #ifndef  CCXX_RTPEXT_H
00050 #   define   CCXX_RTPEXT_H
00051 
00052 #ifdef  __NAMESPACES__
00053 namespace ost {
00054 #endif
00055 
00065 class CCXX_CLASS_EXPORT RTPPacket
00066 {
00067 protected:
00068 #pragma pack(1)
00069 
00081         struct RTPFixedHeader
00082         {
00083 #if     __BYTE_ORDER == __BIG_ENDIAN
00084 
00085                 unsigned char version:2;       
00086                 unsigned char padding:1;       
00087                 unsigned char extension:1;     
00088                 unsigned char cc:4;            
00089                 unsigned char marker:1;        
00090                 unsigned char payload:7;       
00091 #else
00092 
00093                 unsigned char cc:4;            
00094                 unsigned char extension:1;     
00095                 unsigned char padding:1;       
00096                 unsigned char version:2;       
00097                 unsigned char payload:7;       
00098                 unsigned char marker:1;        
00099 #endif
00100                 uint16 sequence;       
00101                 uint32 timestamp;       
00102                 uint32 sources[1];      
00103         };
00104         
00112         typedef struct
00113         {
00114                 uint16 undefined; 
00115                 uint16 length;    
00116         }       RTPHeaderExt;
00117 #pragma pack()
00118 
00119         // size of the header, including contributing sources and extensions
00120         uint32 hdrsize;
00121         // note: payload (not full packet) size.
00122         uint32 payload_size;
00123         // total length, including header, extension, payload and padding
00124         uint32 total;
00125         // packet in memory
00126         unsigned char* buffer;
00127         // whether the object was contructed with duplicated = true
00128         bool duplicated;
00129 
00130 public:
00142         RTPPacket(const unsigned char* const block, size_t len, 
00143                   bool duplicate = false);
00144 
00153         RTPPacket(size_t hdrlen, size_t plen);
00154 
00158         //      virtual
00159         ~RTPPacket()
00160         { endPacket(); };
00161         
00167         inline const RTPFixedHeader*
00168         getHeader(void) const
00169         { return reinterpret_cast<const RTPFixedHeader*>(buffer); };
00170         
00177         inline uint32
00178         getHeaderSize(void) const
00179         { return hdrsize; };
00180 
00188         inline const RTPHeaderExt*
00189         getHeaderExt() const
00190         { uint32 fixsize = sizeof(RTPFixedHeader) + 
00191                   (getHeader()->cc << 2); 
00192           return (reinterpret_cast<RTPHeaderExt*>(buffer + fixsize));
00193         } 
00194 
00199         inline const unsigned char* const
00200         getPayload(void) const
00201         { return buffer + getHeaderSize(); };
00202 
00206         inline uint32
00207         getPayloadSize() const
00208         { return payload_size; };
00209 
00213         inline rtp_payload_t 
00214         getPayloadType() const
00215         { return static_cast<rtp_payload_t>(getHeader()->payload); };
00216 
00220         inline uint16
00221         getSeqNum() const
00222         { return ntohs(getHeader()->sequence); };
00223 
00229         inline uint32
00230         getRawTimestamp(void) const
00231         { return ntohl(getHeader()->timestamp); };
00232         
00237         inline bool
00238         isPadded() const
00239         { return getHeader()->padding; };
00240 
00246         inline uint8
00247         getPaddingSize() const
00248         { return buffer[total - 1]; };
00249 
00255         inline bool
00256         isMarked() const
00257         { return getHeader()->marker; };
00258 
00263         inline bool
00264         isExtended() const
00265         { return getHeader()->extension; };
00266 
00271         inline uint16
00272         getCSRCsCount() const
00273         { return getHeader()->cc; };
00274 
00279         inline const uint32*
00280         getCSRCs() const
00281         { return static_cast<const uint32*>(&(getHeader()->sources[1])); };
00282 
00289         inline const unsigned char* const
00290         getRawPacket() const
00291         { return buffer; };
00292 
00299         inline uint32
00300         getRawPacketSize() const
00301         { return total; };
00302 
00303 protected:
00304         inline void 
00305         setbuffer(const void* src, size_t len, size_t pos)
00306         { memcpy(buffer + pos,src,len); }
00307 
00311         void 
00312         endPacket();
00313 };
00314 
00326 class CCXX_CLASS_EXPORT OutgoingRTPPkt: public RTPPacket
00327 {
00328 public:
00346         OutgoingRTPPkt::OutgoingRTPPkt(
00347                const uint32* const csrcs, uint16 numcsrc, 
00348                const unsigned char* const hdrext, uint32 hdrextlen,
00349                const unsigned char* const data, uint32 datalen);
00350 
00362          OutgoingRTPPkt::OutgoingRTPPkt(
00363                 const uint32* const csrcs, uint16 numcsrc, 
00364                 const unsigned char* const data, uint32 datalen);
00365 
00366         /*
00367          * Construct a new packet to be sent containing no
00368          * contributing source identifiers nor header extension. A new
00369          * copy in memory is done prepending the fixed header.
00370          *
00371          * @param csrcs array of countributing source 32-bit identifiers
00372          * @param numcsrc number of CSRC identifiers in the array
00373          * @param data payload
00374          * @param datalen payload length, in octets
00375          * */
00376         OutgoingRTPPkt::OutgoingRTPPkt(
00377                const unsigned char* const data, uint32 datalen);
00378 
00382         ~OutgoingRTPPkt();
00383         
00387         inline void
00388         setPayloadType(rtp_payload_t pt)
00389         { const_cast<RTPFixedHeader*>(getHeader())->payload = pt; };
00390 
00394         inline void
00395         setSeqNum(uint16 seq)
00396         { const_cast<RTPFixedHeader*>(getHeader())->sequence = htons(seq); };
00397 
00401         inline void
00402         setTimestamp(uint32 ts)
00403         { const_cast<RTPFixedHeader*>(getHeader())->timestamp = 
00404                   htonl(ts); };
00405 
00412         inline void 
00413         setSSRC(uint32 ssrc) const
00414         { const_cast<RTPFixedHeader*>(getHeader())->sources[0] = ssrc; };
00415 
00419         inline void
00420         setMarker(bool mark)
00421         { const_cast<RTPFixedHeader*>(getHeader())->marker = mark; };
00422 
00427         inline uint32
00428         getTimestamp() const
00429         { return getRawTimestamp(); };
00430 
00434         inline bool 
00435         operator==(const OutgoingRTPPkt &p) const
00436         { return ( this->getSeqNum() == p.getSeqNum() ); }
00437 
00441         inline bool
00442         operator!=(const OutgoingRTPPkt &p) const
00443         { return !( *this==p ); };
00444 
00445 private:
00450         OutgoingRTPPkt(const OutgoingRTPPkt &o);
00451         
00456         OutgoingRTPPkt&
00457         operator=(const OutgoingRTPPkt &o);
00458 
00459         // prev/next in the sending list
00460         OutgoingRTPPkt *next, *prev;       
00461 
00462         friend RTPQueue;
00463 };      
00464 
00478 class CCXX_CLASS_EXPORT IncomingRTPPkt : public RTPPacket
00479 {
00480 public:
00500         IncomingRTPPkt(RTPQueue &queue, const unsigned char* block, 
00501                        size_t len, struct timeval recvtime);
00502 
00506         ~IncomingRTPPkt();
00507 
00513         inline bool
00514         isHeaderValid()
00515         { return valid; }
00516 
00520         inline bool 
00521         operator==(const IncomingRTPPkt &p) const
00522         { return ( (this->getSeqNum() == p.getSeqNum()) && 
00523                    (this->getSSRC() == p.getSSRC()) ); }
00524         
00528         inline bool
00529         operator!=(const IncomingRTPPkt &p) const
00530         { return !( *this == p ); };
00531 
00538         inline uint32 
00539         getSSRC() const
00540         { return static_cast<uint32>(getHeader()->sources[0]); };
00541         
00548         inline RTPSource& 
00549         getSource() const
00550         { return source; };
00551 
00560         inline uint32
00561         getTimestamp() const
00562         { return cached_timestamp; };
00563 
00571         inline void 
00572         setRecvTimestamp(const timeval &t)
00573         { reception_timestamp = t; }
00574 
00582         inline timeval
00583         getRecvTimestamp() const
00584         { return reception_timestamp; }
00585 
00598         inline uint16
00599         getExtUndefined() const
00600         { return (isExtended()? getHeaderExt()->undefined : 0); };
00601 
00613         inline uint32
00614         getExtSize() const
00615         { return (isExtended()? getHeaderExt()->length : 0); };
00616 
00617 private:
00622         IncomingRTPPkt(const IncomingRTPPkt &ip);
00623 
00628         IncomingRTPPkt&
00629         operator=(const IncomingRTPPkt &ip);
00630 
00631         // prev/next in the general list
00632         IncomingRTPPkt *next, *prev;       
00633         // prev/next in the source specific list
00634         IncomingRTPPkt *srcnext, *srcprev; 
00635         // source of the packet
00636         RTPSource &source;
00637         // time this packet was received at
00638         struct timeval reception_timestamp;
00639         // header validity, checked at construction time
00640         bool valid;
00641         // timestamp of the packet in host order and after
00642         // substracting the initial timestamp for its source (it is an
00643         // increment from the initial timestamp).
00644         uint32 cached_timestamp;
00645 
00646         // masks for RTP header validation: type not matching SR nor RR 
00647         static const uint16 RTP_INVALID_MASK = (0x7e);
00648         static const uint16 RTP_INVALID_VALUE = (0x48);
00649 
00650         friend RTPQueue;
00651         friend RTPSource;
00652 };      
00653 
00654 #pragma pack(1)
00655 
00659 typedef struct 
00660 {
00661 #if     __BYTE_ORDER == __BIG_ENDIAN
00662 
00663         unsigned char version:2;       
00664         unsigned char padding:1;       
00665         unsigned char block_count:5;   
00666 #else
00667 
00668         unsigned char block_count:5;   
00669         unsigned char padding:1;       
00670         unsigned char version:2;       
00671 #endif
00672         uint8 type;              
00673         uint16 length;           
00674 }       RTCPFixedHeader;
00675 #pragma pack()
00676 
00677 #ifdef  __NAMESPACES__
00678 };
00679 #endif
00680 
00681 #endif //CCXX_RTPEXT_H
00682 

Generated at Sat Nov 3 09:44:13 2001 for ccRTP by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001