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-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 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 typedef enum
00088 {
00089         RTP_PURGE_SEND,
00090         RTP_PURGE_RECV,
00091         RTP_PURGE_BOTH
00092 }       rtppurge_t;
00093 
00094 class   RTPPacket;
00095 
00105 class __EXPORT RTPQueue : protected Thread
00106 {
00107 private:
00108         RTPPacket *sendfirst, *recvfirst;
00109         RTPPacket *sendlast, *recvlast;
00110         Mutex   sendlock, recvlock;
00111         unsigned short sendseq, recvseq;
00112         unsigned long sendsources[17];
00113         unsigned sendcc, segment;
00114         unsigned char buffer[8192];     // packet receive workspace
00115         bool marked;
00116         bool complete;
00117         TimerPort       timeclock;
00118 
00119         timeout_t       timeout;
00120         timeout_t       expired;        // time for expired packets
00121 
00122         void Run(void);
00123         
00124 protected:
00125         struct timeval starttimer;
00126         volatile bool active;
00127 
00136         virtual time_t getControlTimer(void)
00137                 {return 0;};
00138 
00149         virtual unsigned getControl(void)
00150                 {return 0;};
00151 
00152 
00156         virtual void Bye(void)
00157                 {return;};
00158         
00162         virtual void putControl(void)
00163                 {return;};
00164 
00168         virtual void timerTick(void)
00169                 {return;};
00170 
00180         timeout_t getTimeout(void);
00181 
00189         virtual bool isPendingArrival(timeout_t timeout) = 0;
00190 
00197         int sendPacket(void);
00198 
00202         void Purge(rtppurge_t flag);
00203 
00213         virtual int writePacket(unsigned char *packet, unsigned len) = 0;
00214 
00221         int recvPacket(void);
00222 
00231         virtual bool gotPacket(RTPPacket *packet)
00232                 {return true;};
00233 
00243         virtual int readPacket(unsigned char *buffer, unsigned len) = 0;
00244 
00252         RTPPacket *getWaiting(unsigned long timestamp);
00253 
00257         void endQueue(void);
00258         
00259 public:
00260         RTPQueue(int pri);
00261         virtual ~RTPQueue()
00262                 {endQueue();};
00263 
00277         void putPacket(unsigned long stamp, payload_t payload, unsigned char *data = NULL, unsigned len = 0);
00278 
00288         unsigned getPacket(unsigned long stamp, unsigned char *data, unsigned max);
00289 
00296         payload_t getPayload(unsigned long timestamp);
00297 
00308         unsigned setPartial(unsigned long timestamp, unsigned char *data, unsigned offset, unsigned max);
00309 
00321         unsigned getPartial(unsigned long timestamp, unsigned char *data, unsigned int offset, unsigned int max);
00322 
00328         inline bool isActive(void)
00329                 {return active;};
00330 
00337         inline void setTimeout(timeout_t t)
00338                 {timeout = t;};
00339 
00347         inline void setExpired(timeout_t t)
00348                 {expired = t;};
00349 
00355         inline void setSegmentSize(unsigned size)
00356                 {segment = size;};
00357 
00364         inline bool isComplete(void)
00365                 {return complete;};
00366 
00373         inline bool isMarked(void)
00374                 {return marked;};
00375 
00381         bool isWaiting(void);
00382 
00388         bool isSending(void);
00389 
00395         unsigned long getFirstTimestamp(void);
00396 
00402         unsigned short getFirstSequence(void);
00403 
00409         void setSequence(unsigned short seq);
00410 
00414         inline void setTimeclock(void)
00415                 {timeclock.setTimer();};
00416 
00422         inline timeout_t getTimeclock(void)
00423                 {timeclock.getElapsed();};
00424 };
00425 
00432 class __EXPORT RTCPSocket : private UDPSocket
00433 {
00434 protected:
00435         RTCPSocket(const InetAddress &bind, tpport_t port);
00436 
00437         sockerror_t Connect(const InetHostAddress &ia, tpport_t port);
00438 
00439         inline bool isPendingControl(timeout_t timeout)
00440                 {return isPending(SOCKET_PENDING_INPUT, timeout);};
00441 
00442         inline int getControl(unsigned char *buffer, size_t len)
00443                 {return ::read(so, buffer, len);};
00444 
00445         inline int putControl(unsigned char *buffer, size_t len)
00446                 {return ::send(so, buffer, len, MSG_DONTWAIT);};
00447 
00451         virtual void gotHello(const char *sdes)
00452                 {return;};
00453 
00457         virtual void gotGoodbye(void)
00458                 {return;};
00459                 
00460 public:
00461         inline void endControl(void)
00462                 {endSocket();};
00463 };
00464 
00475 class __EXPORT RTPSocket : public RTPQueue, protected UDPReceive, public UDPTransmit, protected RTCPSocket
00476 {
00477 protected:
00478 
00479         tpport_t base;
00480 
00481         bool isPendingArrival(timeout_t timeout)
00482                 {return UDPReceive::isPendingReceive(timeout);};
00483 
00484         int readPacket(unsigned char *buffer, unsigned len)
00485                 {return Receive(buffer, len);};
00486 
00487         int writePacket(unsigned char *buffer, unsigned len)
00488                 {return Transmit((const char *)buffer, len);};
00489 
00490 public:
00491         RTPSocket(const InetAddress &bind, tpport_t port = 5004, int pri = 0);
00492         ~RTPSocket();
00493         void endSocket(void);
00494 
00504         sockerror_t Connect(const InetHostAddress &ia, tpport_t port = 0);
00505 };
00506 
00507 
00516 class __EXPORT RTPDuplex : public RTPQueue, protected UDPReceive, public UDPTransmit
00517 {
00518 private:
00519         tpport_t base;
00520 protected:
00521         bool isPendingArrival(timeout_t timeout)
00522                 {return isPendingReceive(timeout);};
00523 
00524         int writePacket(unsigned char *buffer, unsigned len)
00525                 {return Transmit((const char *)buffer, len);};
00526 
00527         int readPacket(unsigned char *buffer, unsigned len)
00528                 {return Receive(buffer, len);};
00529 
00530 public:
00531         RTPDuplex(const InetAddress &bind, tpport_t local, tpport_t remote, int pri);
00532         ~RTPDuplex();
00533 
00534         sockerror_t Connect(const InetHostAddress &host, tpport_t port = 0);
00535 };
00536 
00537 #endif
00538 

Generated at Thu Jun 21 12:18:47 2001 for CommonC++ by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000