Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

rtp.h

Go to the documentation of this file.
00001 // Copyright (C) 1999-2000 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 ccscript.
00020 // 
00021 // The exception is that, if you link the ccscript 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 ccscript 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 ccscript.  If you copy code from other releases into a copy of
00032 // ccscript, 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 ccscript, 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 
00041 #ifndef __CCXX_RTP_H__
00042 #define __CCXX_RTP_H__
00043 
00044 #ifndef __CCXX_SOCKET_H__
00045 #include <cc++/socket.h>
00046 #else
00047 #ifdef  __CCXX_NAMESPACE_H__
00048 #include <cc++/macros.h>
00049 #endif
00050 #endif
00051 
00052 typedef enum
00053 {
00054         RTP_PAYLOAD_PCMU = 0,
00055         RTP_PAYLOAD_1016,
00056         RTP_PAYLOAD_G726,
00057         RTP_PAYLOAD_GSM,
00058         RTP_PAYLOAD_G723,
00059         RTP_PAYLOAD_DVI4_8000,
00060         RTP_PAYLOAD_DVI4_16000,
00061         RTP_PAYLOAD_LPC,
00062         RTP_PAYLOAD_PCMA,
00063         RTP_PAYLOAD_G722,
00064         RTP_PAYLOAD_L16_DUAL,
00065         RTP_PAYLOAD_L16_MONO,
00066         RTP_PAYLOAD_QCELP,
00067 
00068         RTP_PAYLOAD_MPA = 14,
00069         RTP_PAYLOAD_G728,
00070         RTP_PAYLOAD_DVI4_11025,
00071         RTP_PAYLOAD_DVI4_22050,
00072         RTP_PAYLOAD_G729,
00073 
00074         RTP_PAYLOAD_CELB = 25,
00075         RTP_PAYLOAD_JPEG,
00076 
00077         RTP_PAYLOAD_NV = 28, 
00078 
00079         RTP_PAYLOAD_H261 = 31,
00080         RTP_PAYLOAD_MPV,
00081         RTP_PAYLOAD_MP2T,
00082         RTP_PAYLOAD_H263,
00083 
00084         RTP_PAYLOAD_INVALID = 128
00085 }       payload_t;
00086 
00087 class   RTPPacket;
00088 
00098 class RTPQueue : protected Thread
00099 {
00100 private:
00101         RTPPacket *sendfirst, *recvfirst;
00102         RTPPacket *sendlast, *recvlast;
00103         Mutex   sendlock, recvlock;
00104         unsigned short sendseq, recvseq;
00105         unsigned long sendsources[17];
00106         unsigned sendcc, segment;
00107         unsigned char buffer[8192];     // packet receive workspace
00108         bool marked;
00109         bool complete;
00110 
00111         timeout_t       timeout;
00112         timeout_t       expired;        // time for expired packets
00113 
00114         void Run(void);
00115         
00116 protected:
00117         struct timeval starttimer;
00118         volatile bool active;
00119 
00128         virtual time_t getControlTimer(void)
00129                 {return 0;};
00130 
00141         virtual unsigned getControl(void)
00142                 {return 0;};
00143 
00147         virtual void Bye(void)
00148                 {return;};
00149         
00153         virtual void putControl(void)
00154                 {return;};
00155 
00165         timeout_t getTimeout(void);
00166 
00174         virtual bool isPendingArrival(timeout_t timeout);
00175 
00182         int sendPacket(void);
00183 
00193         virtual int writePacket(unsigned char *packet, unsigned len);
00194 
00201         int recvPacket(void);
00202 
00212         virtual int readPacket(unsigned char *buffer, unsigned len);
00213 
00221         RTPPacket *getWaiting(unsigned long timestamp);
00222 
00226         void endQueue(void);
00227         
00228 public:
00229         RTPQueue(int pri);
00230         ~RTPQueue()
00231                 {endQueue();};
00232 
00246         void putPacket(unsigned long stamp, payload_t payload, unsigned char *data = NULL, unsigned len = 0);
00247 
00257         unsigned getPacket(unsigned long stamp, unsigned char *data, unsigned max);
00258 
00265         payload_t getPayload(unsigned long timestamp);
00266 
00277         unsigned setPartial(unsigned long timestamp, unsigned char *data, unsigned offset, unsigned max);
00278 
00290         unsigned getPartial(unsigned long timestamp, unsigned char *data, unsigned int offset, unsigned int max);
00291 
00297         inline bool isActive(void)
00298                 {return active;};
00299 
00306         inline void setTimeout(timeout_t t)
00307                 {timeout = t;};
00308 
00316         inline void setExpired(timeout_t t)
00317                 {expired = t;};
00318 
00324         inline void setSegmentSize(unsigned size)
00325                 {segment = size;};
00326 
00333         inline bool isComplete(void)
00334                 {return complete;};
00335 
00342         inline bool isMarked(void)
00343                 {return marked;};
00344 };
00345 
00352 class RTCPSocket : private UDPSocket
00353 {
00354 protected:
00355         RTCPSocket(const InetAddress &bind, tpport_t port);
00356 
00357         sockerror_t Connect(const InetHostAddress &ia, tpport_t port);
00358 
00359         inline bool isPendingControl(timeout_t timeout)
00360                 {return isPending(SOCKET_PENDING_INPUT, timeout);};
00361 
00362         inline int getControl(unsigned char *buffer, size_t len)
00363                 {return ::read(so, buffer, len);};
00364 
00365         inline int putControl(unsigned char *buffer, size_t len)
00366                 {return ::send(so, buffer, len, MSG_DONTWAIT);};
00367                 
00368 public:
00369         inline void endControl(void)
00370                 {endSocket();};
00371 };
00372 
00383 class RTPSocket : public RTPQueue, protected UDPReceive, public UDPTransmit, protected RTCPSocket
00384 {
00385 protected:
00386         volatile bool active;
00387         tpport_t base;
00388 
00389         bool isPendingArrival(timeout_t timeout)
00390                 {return UDPReceive::isPendingReceive(timeout);};
00391 
00392         int readPacket(unsigned char *buffer, unsigned len)
00393                 {return Receive(buffer, len);};
00394 
00395         int writePacket(unsigned char *buffer, unsigned len)
00396                 {return Transmit(buffer, len);};
00397 
00398 public:
00399         RTPSocket(InetAddress &bind, tpport_t port = 5004, int pri = 0);
00400         ~RTPSocket();
00401         void endSocket(void);
00402 
00412         sockerror_t Connect(const InetHostAddress &ia, tpport_t port = 0);
00413 };
00414 
00415 
00424 class RTPDuplex : public RTPQueue, protected UDPReceive, public UDPTransmit
00425 {
00426 private:
00427         tpport_t base;
00428 protected:
00429         bool isPendingArrival(timeout_t timeout)
00430                 {return isPendingReceive(timeout);};
00431 
00432         int writePacket(unsigned char *buffer, unsigned len)
00433                 {return Transmit(buffer, len);};
00434 
00435         int readPacket(unsigned char *buffer, unsigned len)
00436                 {return Receive(buffer, len);};
00437 
00438 public:
00439         RTPDuplex(InetAddress &bind, tpport_t local, tpport_t remote, int pri);
00440         ~RTPDuplex();
00441 
00442         sockerror_t Connect(const InetHostAddress &host, tpport_t port = 0);
00443 };
00444 
00445 #endif
00446 

Generated at Fri Dec 15 11:45:38 2000 for CommonC++ by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000