ccRTP
queuebase.h
Go to the documentation of this file.
00001 // Copyright (C) 2001-2015 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 Lesser General Public License
00014 // along with GNU ccRTP.  If not, see <http://www.gnu.org/licenses/>.
00015 //
00016 // As a special exception, you may use this file as part of a free software
00017 // library without restriction.  Specifically, if other files instantiate
00018 // templates or use macros or inline functions from this file, or you compile
00019 // this file and link it with other files to produce an executable, this
00020 // file does not by itself cause the resulting executable to be covered by
00021 // the GNU General Public License.  This exception does not however
00022 // invalidate any other reasons why the executable file might be covered by
00023 // the GNU General Public License.
00024 //
00025 // This exception applies only to the code released under the name GNU
00026 // ccRTP.  If you copy code from other releases into a copy of GNU
00027 // ccRTP, as the General Public License permits, the exception does
00028 // not apply to the code that you add in this way.  To avoid misleading
00029 // anyone as to the status of such modified files, you must delete
00030 // this exception notice from them.
00031 //
00032 // If you write modifications of your own for GNU ccRTP, it is your choice
00033 // whether to permit this exception to apply to your modifications.
00034 // If you do not wish that, delete this exception notice.
00035 //
00036 
00043 #ifndef CCXX_RTP_QUEUEBASE_H_
00044 #define CCXX_RTP_QUEUEBASE_H_
00045 
00046 #include <commoncpp/pointer.h>
00047 #include <ccrtp/rtppkt.h>
00048 #include <ccrtp/sources.h>
00049 
00050 NAMESPACE_COMMONCPP
00051 
00068 class __EXPORT AppDataUnit
00069 {
00070 public:
00071     AppDataUnit(const IncomingRTPPkt& packet, const SyncSource& src);
00072 
00073     inline ~AppDataUnit()
00074     { }
00075 
00079     AppDataUnit(const AppDataUnit& src);
00080 
00087     AppDataUnit&
00088     operator=(const AppDataUnit& source);
00089 
00093     inline PayloadType
00094     getType() const
00095     { return datablock->getPayloadType(); }
00096 
00104     inline const uint8* const
00105     getData() const
00106     { return datablock->getPayload(); }
00107 
00111     size_t
00112     getSize() const
00113     { return datablock->getPayloadSize(); }
00114 
00118     inline const SyncSource&
00119     getSource() const
00120     { return *source; }
00121 
00127     inline bool
00128     isMarked() const
00129     { return datablock->isMarked(); }
00130 
00134     inline uint16
00135     getSeqNum() const
00136     { return datablock->getSeqNum(); }
00137 
00141     inline uint8
00142     getContributorsCount() const
00143     { return (uint8)datablock->getCSRCsCount(); }
00144 
00150     inline const uint32*
00151     getContributorsID() const
00152     { return datablock->getCSRCs(); }
00153 
00154 private:
00155     Pointer<const IncomingRTPPkt> datablock;
00156     const SyncSource* source;
00157 };
00158 
00166 class __EXPORT RTPQueueBase
00167 {
00168 public:
00176     inline bool
00177     setPayloadFormat(const PayloadFormat& pf)
00178     {
00179         currentPayloadType = pf.getPayloadType();
00180         currentRTPClockRate = pf.getRTPClockRate();
00181         return true;
00182     }
00183 
00184     inline uint32 getLocalSSRC() const
00185     { return localSSRC; }
00186 
00195     inline uint32 getCurrentRTPClockRate() const
00196     { return currentRTPClockRate; }
00197 
00198     inline PayloadType getCurrentPayloadType() const
00199     { return currentPayloadType; }
00200 
00201     inline timeval getInitialTime() const
00202     { return initialTime; }
00203 
00204 protected:
00209     RTPQueueBase(uint32 *ssrc = NULL);
00210 
00211     inline void setLocalSSRC(uint32 ssrc)
00212     { localSSRC = ssrc; localSSRCNetwork = htonl(ssrc); }
00213 
00214     inline uint32 getLocalSSRCNetwork() const
00215     { return localSSRCNetwork; }
00216 
00217     virtual
00218     ~RTPQueueBase()
00219     { }
00220 
00227     inline virtual size_t
00228     dispatchBYE(const std::string&)
00229     { return 0; }
00230 
00231     inline virtual void
00232     renewLocalSSRC()
00233     { }
00234 
00235 private:
00236     // local SSRC 32-bit identifier
00237     uint32 localSSRC;
00238     // SSRC in network byte order
00239     uint32 localSSRCNetwork;
00240     // RTP clock rate for the current payload type.
00241     uint32 currentRTPClockRate;
00242     // Current payload type set for outgoing packets and expected
00243     // from incoming packets.
00244     PayloadType currentPayloadType;
00245     // when the queue is created
00246     timeval initialTime;
00247 };
00248 
00254 class __EXPORT OutgoingDataQueueBase:
00255     public virtual RTPQueueBase
00256 {
00257 public:
00258     inline size_t
00259     getDefaultMaxSendSegmentSize()
00260     { return defaultMaxSendSegmentSize;}
00261 
00268     inline void
00269     setMaxSendSegmentSize(size_t size)
00270     { maxSendSegmentSize = size; }
00271 
00272     inline size_t
00273     getMaxSendSegmentSize()
00274     { return maxSendSegmentSize; }
00275 
00276 protected:
00277     OutgoingDataQueueBase();
00278 
00279     inline virtual
00280     ~OutgoingDataQueueBase()
00281     { }
00282 
00283 private:
00284     static const size_t defaultMaxSendSegmentSize;
00285     // maximum packet size before fragmenting sends.
00286     size_t maxSendSegmentSize;
00287 };
00288 
00294 class __EXPORT IncomingDataQueueBase:
00295     public virtual RTPQueueBase
00296 {
00297 public:
00298     inline size_t getDefaultMaxRecvPacketSize() const
00299     { return defaultMaxRecvPacketSize; }
00300 
00301     inline size_t
00302     getMaxRecvPacketSize() const
00303     { return maxRecvPacketSize; }
00304 
00315     inline void
00316     setMaxRecvPacketSize(size_t maxsize)
00317     { maxRecvPacketSize = maxsize; }
00318 
00319 protected:
00320     IncomingDataQueueBase()
00321     { setMaxRecvPacketSize(getDefaultMaxRecvPacketSize()); }
00322 
00323     inline virtual
00324     ~IncomingDataQueueBase()
00325     { }
00326 
00327 private:
00328     static const size_t defaultMaxRecvPacketSize;
00329     // filter value for received packets length.
00330     size_t maxRecvPacketSize;
00331 };
00332  // queuebase
00334 
00335 END_NAMESPACE
00336 
00337 #endif  //CCXX_RTP_QUEUEBASE_H_
00338