ccRTP
pool.h
Go to the documentation of this file.
1 // Copyright (C) 2001,2002,2006 Federico Montesino Pouzols <fedemp@altern.org>
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 //
17 // As a special exception, you may use this file as part of a free software
18 // library without restriction. Specifically, if other files instantiate
19 // templates or use macros or inline functions from this file, or you compile
20 // this file and link it with other files to produce an executable, this
21 // file does not by itself cause the resulting executable to be covered by
22 // the GNU General Public License. This exception does not however
23 // invalidate any other reasons why the executable file might be covered by
24 // the GNU General Public License.
25 //
26 // This exception applies only to the code released under the name GNU
27 // ccRTP. If you copy code from other releases into a copy of GNU
28 // ccRTP, as the General Public License permits, the exception does
29 // not apply to the code that you add in this way. To avoid misleading
30 // anyone as to the status of such modified files, you must delete
31 // this exception notice from them.
32 //
33 // If you write modifications of your own for GNU ccRTP, it is your choice
34 // whether to permit this exception to apply to your modifications.
35 // If you do not wish that, delete this exception notice.
36 //
37 
43 #ifndef CCXX_RTP_POOL_H
44 #define CCXX_RTP_POOL_H
45 
46 #include <list>
47 #include <ccrtp/rtp.h>
48 
49 NAMESPACE_COMMONCPP
50 using std::list;
51 
53 
55 {
56 public:
58  { return s.getSchedulingTimeout(); }
59 
61  { return s.getRTCPCheckInterval(); }
62 
63  size_t
65  { return s.takeInDataPacket(); }
66 
67  size_t
69  { return s.dispatchDataPacket(); }
70 
71  void
73  { s.controlReceptionService(); }
74 
75  void
77  { s.controlTransmissionService(); }
78 
79  inline SOCKET getDataRecvSocket(RTPSessionBase& s) const
80  { return s.getDataRecvSocket(); }
81 
82  inline SOCKET getControlRecvSocket(RTPSessionBase& s) const
83  { return s.getControlRecvSocket(); }
84 };
85 
94 private:
95  RTPSessionBase* elem;
96  bool cleared;
97 
98 public:
100  void clear();
101  bool isCleared();
102  RTPSessionBase* get();
103 };
104 
105 
107  : elem(e), cleared(false) {
108 }
109 
111  cleared = true;
112  delete elem;
113  elem = 0;
114 }
115 
117  return cleared;
118 }
119 
121  return elem;
122 }
123 
130 {
131 protected:
133 public:
134  PredEquals(RTPSessionBase* e) : elem(e) {}
135 
137  {
138  return e->get() == elem;
139  }
140 };
141 
155 class __EXPORT RTPSessionPool: public RTPSessionBaseHandler
156 {
157 public:
158  RTPSessionPool();
159 
160  inline virtual ~RTPSessionPool()
161  { }
162 
163  bool
164  addSession(RTPSessionBase& session);
165 
166  bool
167  removeSession(RTPSessionBase& session);
168 
169  size_t
170  getPoolLength() const;
171 
172  virtual void startRunning() = 0;
173 
174  inline bool isActive()
175  { return poolActive; }
176 
177 protected:
178  inline void setActive()
179  { poolActive = true; }
180 
181  inline timeval getPoolTimeout()
182  { return poolTimeout; }
183 
184  inline void setPoolTimeout(int sec, int usec)
185  { poolTimeout.tv_sec = sec; poolTimeout.tv_usec = usec; }
186 
187  inline void setPoolTimeout(struct timeval to)
188  { poolTimeout = to; }
189 
190  std::list<SessionListElement*> sessionList;
191  typedef std::list<SessionListElement*>::iterator PoolIterator;
192 
193  mutable ThreadLock poolLock;
194 
195 #ifndef _MSWINDOWS_
197  SOCKET highestSocket; // highest socket number + 1
198 #endif
199 
200 private:
201  timeval poolTimeout;
202  mutable bool poolActive;
203 };
204 
205 
206 class __EXPORT SingleRTPSessionPool :
207  public RTPSessionPool,
208  public Thread
209 {
210 public:
214  SingleRTPSessionPool(int pri = 0) :
215  RTPSessionPool(),
216  Thread(pri)
217  { }
218 
220  { }
221 
223  { setActive(); Thread::start(); }
224 
225 protected:
230  void run();
231 };
232 
233 END_NAMESPACE
234 
235 #endif //CCXX_RTP_POOL_H
236 
void setPoolTimeout(int sec, int usec)
Definition: pool.h:184
size_t takeInDataPacket(RTPSessionBase &s)
Definition: pool.h:64
SOCKET highestSocket
Definition: pool.h:197
Class for tracking session status.
Definition: pool.h:93
This class is a base class for classes that define a group of RTP sessions that will be served by one...
Definition: pool.h:155
std equality for SessionListElement objects.
Definition: pool.h:129
microtimeout_t getSchedulingTimeout(RTPSessionBase &s)
Definition: pool.h:57
uint32 microtimeout_t
Time interval expressed in microseconds.
Definition: base.h:68
RTPSessionBase * get()
Definition: pool.h:120
timeval getPoolTimeout()
Definition: pool.h:181
void clear()
Definition: pool.h:110
~SingleRTPSessionPool()
Definition: pool.h:219
void controlTransmissionService(RTPSessionBase &s)
Definition: pool.h:76
Generic RTP protocol stack for exchange of realtime data.
SingleRTPSessionPool(int pri=0)
Definition: pool.h:214
fd_set recvSocketSet
Definition: pool.h:196
Definition: pool.h:54
ThreadLock poolLock
Definition: pool.h:193
std::list< SessionListElement * >::iterator PoolIterator
Definition: pool.h:191
timeval getRTCPCheckInterval(RTPSessionBase &s)
Definition: pool.h:60
bool isCleared()
Definition: pool.h:116
void controlReceptionService(RTPSessionBase &s)
Definition: pool.h:72
bool operator()(SessionListElement *e)
Definition: pool.h:136
void setPoolTimeout(struct timeval to)
Definition: pool.h:187
PredEquals(RTPSessionBase *e)
Definition: pool.h:134
SOCKET getDataRecvSocket(RTPSessionBase &s) const
Definition: pool.h:79
Definition: pool.h:206
void setActive()
Definition: pool.h:178
RTPSessionBase * elem
Definition: pool.h:132
TRTPSessionBase RTPSessionBase
Definition: pool.h:52
Definition: rtp.h:86
Generic and audio/video profile specific RTP interface of ccRTP.
SOCKET getControlRecvSocket(RTPSessionBase &s) const
Definition: pool.h:82
bool isActive()
Definition: pool.h:174
std::list< SessionListElement * > sessionList
Definition: pool.h:190
void startRunning()
Definition: pool.h:222
virtual ~RTPSessionPool()
Definition: pool.h:160
SessionListElement(RTPSessionBase *e)
Definition: pool.h:106
size_t dispatchDataPacket(RTPSessionBase &s)
Definition: pool.h:68