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 
00061 class RTPPacket
00062 {
00063 protected:
00064 #pragma pack(1)
00065 
00077         struct RTPFixedHeader
00078         {
00079 #if     __BYTE_ORDER == __BIG_ENDIAN
00080 
00081                 unsigned char version:2;       
00082                 unsigned char padding:1;       
00083                 unsigned char extension:1;     
00084                 unsigned char cc:4;            
00085                 unsigned char marker:1;        
00086                 unsigned char payload:7;       
00087 #else
00088 
00089                 unsigned char cc:4;            
00090                 unsigned char extension:1;     
00091                 unsigned char padding:1;       
00092                 unsigned char version:2;       
00093                 unsigned char payload:7;       
00094                 unsigned char marker:1;        
00095 #endif
00096                 uint16 sequence;       
00097                 uint32 timestamp;       
00098                 uint32 sources[1];      
00099         };
00100         
00108         typedef struct
00109         {
00110                 uint16 undefined; 
00111                 uint16 length;    
00112         }       RTPHeaderExt;
00113 #pragma pack()
00114 
00115         // size of the header, including contributing sources and extensions
00116         uint32 hdrsize;
00117         // note: payload (not full packet) size.
00118         uint32 payload_size;
00119         // total length, including header, extension, payload and padding
00120         uint32 total;
00121         // packet in memory
00122         unsigned char* buffer;
00123         // whether the object was contructed with duplicated = true
00124         bool duplicated;
00125 
00126 public:
00138         RTPPacket(const unsigned char* const block, size_t len, 
00139                   bool duplicate = false);
00140 
00149         RTPPacket(size_t hdrlen, size_t plen);
00150 
00154         //      virtual
00155         ~RTPPacket()
00156         { endPacket(); };
00157         
00163         inline const RTPFixedHeader*
00164         getHeader(void) const
00165         { return reinterpret_cast<const RTPFixedHeader*>(buffer); };
00166         
00173         inline uint32
00174         getHeaderSize(void) const
00175         { return hdrsize; };
00176 
00184         inline const RTPHeaderExt*
00185         getHeaderExt() const
00186         { uint32 fixsize = sizeof(RTPFixedHeader) + 
00187                   (getHeader()->cc << 2); 
00188           return (reinterpret_cast<RTPHeaderExt*>(buffer + fixsize));
00189         } 
00190 
00195         inline const unsigned char* const
00196         getPayload(void) const
00197         { return buffer + getHeaderSize(); };
00198 
00202         inline uint32
00203         getPayloadSize() const
00204         { return payload_size; };
00205 
00209         inline rtp_payload_t 
00210         getPayloadType() const
00211         { return static_cast<rtp_payload_t>(getHeader()->payload); };
00212 
00216         inline uint16
00217         getSeqNum() const
00218         { return ntohs(getHeader()->sequence); };
00219 
00225         inline uint32
00226         getRawTimestamp(void) const
00227         { return ntohl(getHeader()->timestamp); };
00228         
00233         inline bool
00234         isPadded() const
00235         { return getHeader()->padding; };
00236 
00242         inline uint8
00243         getPaddingSize() const
00244         { return buffer[total - 1]; };
00245 
00251         inline bool
00252         isMarked() const
00253         { return getHeader()->marker; };
00254 
00259         inline bool
00260         isExtended() const
00261         { return getHeader()->extension; };
00262 
00267         inline uint16
00268         getCSRCsCount() const
00269         { return getHeader()->cc; };
00270 
00275         inline const uint32*
00276         getCSRCs() const
00277         { return static_cast<const uint32*>(&(getHeader()->sources[1])); };
00278 
00285         inline const unsigned char* const
00286         getRawPacket() const
00287         { return buffer; };
00288 
00295         inline uint32
00296         getRawPacketSize() const
00297         { return total; };
00298 
00299 protected:
00300         inline void 
00301         setbuffer(const void* src, size_t len, size_t pos)
00302         { memcpy(buffer + pos,src,len); }
00303 
00307         void 
00308         endPacket();
00309 };
00310 
00322 class OutgoingRTPPkt: public RTPPacket
00323 {
00324 public:
00342         OutgoingRTPPkt::OutgoingRTPPkt(
00343                const uint32* const csrcs, uint16 numcsrc, 
00344                const unsigned char* const hdrext, uint32 hdrextlen,
00345                const unsigned char* const data, uint32 datalen);
00346 
00358          OutgoingRTPPkt::OutgoingRTPPkt(
00359                 const uint32* const csrcs, uint16 numcsrc, 
00360                 const unsigned char* const data, uint32 datalen);
00361 
00362         /*
00363          * Construct a new packet to be sent containing no
00364          * contributing source identifiers nor header extension. A new
00365          * copy in memory is done prepending the fixed header.
00366          *
00367          * @param csrcs array of countributing source 32-bit identifiers
00368          * @param numcsrc number of CSRC identifiers in the array
00369          * @param data payload
00370          * @param datalen payload length, in octets
00371          * */
00372         OutgoingRTPPkt::OutgoingRTPPkt(
00373                const unsigned char* const data, uint32 datalen);
00374 
00378         ~OutgoingRTPPkt();
00379         
00383         inline void
00384         setPayloadType(rtp_payload_t pt)
00385         { const_cast<RTPFixedHeader*>(getHeader())->payload = pt; };
00386 
00390         inline void
00391         setSeqNum(uint16 seq)
00392         { const_cast<RTPFixedHeader*>(getHeader())->sequence = htons(seq); };
00393 
00397         inline void
00398         setTimestamp(uint32 ts)
00399         { const_cast<RTPFixedHeader*>(getHeader())->timestamp = 
00400                   htonl(ts); };
00401 
00408         inline void 
00409         setSSRC(uint32 ssrc) const
00410         { const_cast<RTPFixedHeader*>(getHeader())->sources[0] = ssrc; };
00411 
00415         inline void
00416         setMarker(bool mark)
00417         { const_cast<RTPFixedHeader*>(getHeader())->marker = mark; };
00418 
00423         inline uint32
00424         getTimestamp() const
00425         { return getRawTimestamp(); };
00426 
00430         inline bool 
00431         operator==(const OutgoingRTPPkt &p) const
00432         { return ( this->getSeqNum() == p.getSeqNum() ); }
00433 
00437         inline bool
00438         operator!=(const OutgoingRTPPkt &p) const
00439         { return !( *this==p ); };
00440 
00441 private:
00446         OutgoingRTPPkt(const OutgoingRTPPkt &o);
00447         
00452         OutgoingRTPPkt&
00453         operator=(const OutgoingRTPPkt &o);
00454 
00455         // prev/next in the sending list
00456         OutgoingRTPPkt *next, *prev;       
00457 
00458         friend RTPQueue;
00459 };      
00460 
00474 class IncomingRTPPkt : public RTPPacket
00475 {
00476 public:
00496         IncomingRTPPkt(RTPQueue &queue, const unsigned char* block, 
00497                        size_t len, struct timeval recvtime);
00498 
00502         ~IncomingRTPPkt();
00503 
00509         inline bool
00510         isHeaderValid()
00511         { return valid; }
00512 
00516         inline bool 
00517         operator==(const IncomingRTPPkt &p) const
00518         { return ( (this->getSeqNum() == p.getSeqNum()) && 
00519                    (this->getSSRC() == p.getSSRC()) ); }
00520         
00524         inline bool
00525         operator!=(const IncomingRTPPkt &p) const
00526         { return !( *this == p ); };
00527 
00534         inline uint32 
00535         getSSRC() const
00536         { return static_cast<uint32>(getHeader()->sources[0]); };
00537         
00544         inline RTPSource& 
00545         getSource() const
00546         { return source; };
00547 
00556         inline uint32
00557         getTimestamp() const
00558         { return cached_timestamp; };
00559 
00567         inline void 
00568         setRecvTimestamp(const timeval &t)
00569         { reception_timestamp = t; }
00570 
00578         inline timeval
00579         getRecvTimestamp() const
00580         { return reception_timestamp; }
00581 
00594         inline uint16
00595         getExtUndefined() const
00596         { return (isExtended()? getHeaderExt()->undefined : 0); };
00597 
00609         inline uint32
00610         getExtSize() const
00611         { return (isExtended()? getHeaderExt()->length : 0); };
00612 
00613 private:
00618         IncomingRTPPkt(const IncomingRTPPkt &ip);
00619 
00624         IncomingRTPPkt&
00625         operator=(const IncomingRTPPkt &ip);
00626 
00627         // prev/next in the general list
00628         IncomingRTPPkt *next, *prev;       
00629         // prev/next in the source specific list
00630         IncomingRTPPkt *srcnext, *srcprev; 
00631         // source of the packet
00632         RTPSource &source;
00633         // time this packet was received at
00634         struct timeval reception_timestamp;
00635         // header validity, checked at construction time
00636         bool valid;
00637         // timestamp of the packet in host order and after
00638         // substracting the initial timestamp for its source (it is an
00639         // increment from the initial timestamp).
00640         uint32 cached_timestamp;
00641 
00642         // masks for RTP header validation: type not matching SR nor RR 
00643         static const uint16 RTP_INVALID_MASK = (0x7e);
00644         static const uint16 RTP_INVALID_VALUE = (0x48);
00645 
00646         friend RTPQueue;
00647         friend RTPSource;
00648 };      
00649 
00650 #pragma pack(1)
00651 
00655 typedef struct 
00656 {
00657 #if     __BYTE_ORDER == __BIG_ENDIAN
00658 
00659         unsigned char version:2;       
00660         unsigned char padding:1;       
00661         unsigned char block_count:5;   
00662 #else
00663 
00664         unsigned char block_count:5;   
00665         unsigned char padding:1;       
00666         unsigned char version:2;       
00667 #endif
00668         uint8 type;              
00669         uint16 length;           
00670 }       RTCPFixedHeader;
00671 #pragma pack()
00672 
00673 #endif //CCXX_RTPEXT_H
00674 

Generated at Tue Oct 16 11:17:52 2001 for ccRTP by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001