00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
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];
00108 bool marked;
00109 bool complete;
00110
00111 timeout_t timeout;
00112 timeout_t expired;
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