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
00043 #ifndef CCXX_RTP_POOL_H
00044 #define CCXX_RTP_POOL_H
00045
00046 #include <list>
00047 #include <ccrtp/rtp.h>
00048
00049 #ifdef CCXX_NAMESPACES
00050 namespace ost {
00051 using std::list;
00052 #endif
00053
00054 typedef TRTPSessionBase<> RTPSessionBase;
00055
00056 class RTPSessionBaseHandler
00057 {
00058 public:
00059 inline microtimeout_t getSchedulingTimeout(RTPSessionBase& s)
00060 { return s.getSchedulingTimeout(); }
00061
00062 inline timeval getRTCPCheckInterval(RTPSessionBase& s)
00063 { return s.getRTCPCheckInterval(); }
00064
00065 size_t
00066 takeInDataPacket(RTPSessionBase& s)
00067 { return s.takeInDataPacket(); }
00068
00069 size_t
00070 dispatchDataPacket(RTPSessionBase& s)
00071 { return s.dispatchDataPacket(); }
00072
00073 void
00074 controlReceptionService(RTPSessionBase& s)
00075 { s.controlReceptionService(); }
00076
00077 void
00078 controlTransmissionService(RTPSessionBase& s)
00079 { s.controlTransmissionService(); }
00080
00081 inline SOCKET getDataRecvSocket(RTPSessionBase& s) const
00082 { return s.getDataRecvSocket(); }
00083
00084 inline SOCKET getControlRecvSocket(RTPSessionBase& s) const
00085 { return s.getControlRecvSocket(); }
00086 };
00087
00095 class SessionListElement {
00096 private:
00097 RTPSessionBase* elem;
00098 bool cleared;
00099
00100 public:
00101 SessionListElement(RTPSessionBase* e);
00102 void clear();
00103 bool isCleared();
00104 RTPSessionBase* get();
00105 };
00106
00107
00108 inline SessionListElement::SessionListElement(RTPSessionBase* e)
00109 : elem(e), cleared(false) {
00110 }
00111
00112 inline void SessionListElement::clear() {
00113 cleared = true;
00114 delete elem;
00115 elem = 0;
00116 }
00117
00118 inline bool SessionListElement::isCleared() {
00119 return cleared;
00120 }
00121
00122 inline RTPSessionBase* SessionListElement::get() {
00123 return elem;
00124 }
00125
00131 class PredEquals
00132 {
00133 protected:
00134 RTPSessionBase* elem;
00135 public:
00136 PredEquals(RTPSessionBase* e) : elem(e) {}
00137
00138 bool operator() (SessionListElement* e)
00139 {
00140 return e->get() == elem;
00141 }
00142 };
00143
00157 class __EXPORT RTPSessionPool: public RTPSessionBaseHandler
00158 {
00159 public:
00160 RTPSessionPool();
00161
00162 inline virtual ~RTPSessionPool()
00163 { }
00164
00165 bool
00166 addSession(RTPSessionBase& session);
00167
00168 bool
00169 removeSession(RTPSessionBase& session);
00170
00171 size_t
00172 getPoolLength() const;
00173
00174 virtual void startRunning() = 0;
00175
00176 inline bool isActive()
00177 { return poolActive; }
00178
00179 protected:
00180 inline void setActive()
00181 { poolActive = true; }
00182
00183 inline timeval getPoolTimeout()
00184 { return poolTimeout; }
00185
00186 inline void setPoolTimeout(int sec, int usec)
00187 { poolTimeout.tv_sec = sec; poolTimeout.tv_usec = usec; }
00188
00189 inline void setPoolTimeout(struct timeval to)
00190 { poolTimeout = to; }
00191
00192 std::list<SessionListElement*> sessionList;
00193 typedef std::list<SessionListElement*>::iterator PoolIterator;
00194
00195 mutable ThreadLock poolLock;
00196
00197 #ifndef WIN32
00198 fd_set recvSocketSet;
00199 SOCKET highestSocket;
00200 #endif
00201
00202 private:
00203 timeval poolTimeout;
00204 mutable bool poolActive;
00205 };
00206
00207
00208 class __EXPORT SingleRTPSessionPool :
00209 public RTPSessionPool,
00210 public Thread
00211 {
00212 public:
00216 SingleRTPSessionPool(int pri = 0) :
00217 RTPSessionPool(),
00218 Thread(pri)
00219 { }
00220
00221 ~SingleRTPSessionPool()
00222 { }
00223
00224 void startRunning()
00225 { setActive(); Thread::start(); }
00226
00227 protected:
00232 void run();
00233 };
00234
00235 #ifdef CCXX_NAMESPACES
00236 }
00237 #endif
00238
00239 #endif //CCXX_RTP_POOL_H
00240