ccRTP
pool.h
Go to the documentation of this file.
1// Copyright (C) 2001-2015 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 Lesser General Public License
14// along with GNU ccRTP. If not, see <http://www.gnu.org/licenses/>.
15//
16// As a special exception, you may use this file as part of a free software
17// library without restriction. Specifically, if other files instantiate
18// templates or use macros or inline functions from this file, or you compile
19// this file and link it with other files to produce an executable, this
20// file does not by itself cause the resulting executable to be covered by
21// the GNU General Public License. This exception does not however
22// invalidate any other reasons why the executable file might be covered by
23// the GNU General Public License.
24//
25// This exception applies only to the code released under the name GNU
26// ccRTP. If you copy code from other releases into a copy of GNU
27// ccRTP, as the General Public License permits, the exception does
28// not apply to the code that you add in this way. To avoid misleading
29// anyone as to the status of such modified files, you must delete
30// this exception notice from them.
31//
32// If you write modifications of your own for GNU ccRTP, it is your choice
33// whether to permit this exception to apply to your modifications.
34// If you do not wish that, delete this exception notice.
35//
36
42#ifndef CCXX_RTP_POOL_H
43#define CCXX_RTP_POOL_H
44
45#include <list>
46#include <ccrtp/rtp.h>
47
48NAMESPACE_COMMONCPP
49using std::list;
50
52
54{
55public:
57 { return s.getSchedulingTimeout(); }
58
60 { return s.getRTCPCheckInterval(); }
61
62 size_t
64 { return s.takeInDataPacket(); }
65
66 size_t
68 { return s.dispatchDataPacket(); }
69
70 void
72 { s.controlReceptionService(); }
73
74 void
76 { s.controlTransmissionService(); }
77
78 inline SOCKET getDataRecvSocket(RTPSessionBase& s) const
79 { return s.getDataRecvSocket(); }
80
81 inline SOCKET getControlRecvSocket(RTPSessionBase& s) const
82 { return s.getControlRecvSocket(); }
83};
84
93private:
94 RTPSessionBase* elem;
95 bool cleared;
96
97public:
99 void clear();
100 bool isCleared();
102};
103
104
106 : elem(e), cleared(false) {
107}
108
110 cleared = true;
111 delete elem;
112 elem = 0;
113}
114
116 return cleared;
117}
118
120 return elem;
121}
122
129{
130protected:
132public:
134
136 {
137 return e->get() == elem;
138 }
139};
140
155{
156public:
158
159 inline virtual ~RTPSessionPool()
160 { }
161
162 bool
164
165 bool
167
168 size_t
170
171 virtual void startRunning() = 0;
172
173 inline bool isActive()
174 { return poolActive; }
175
176protected:
177 inline void setActive()
178 { poolActive = true; }
179
180 inline timeval getPoolTimeout()
181 { return poolTimeout; }
182
183 inline void setPoolTimeout(int sec, int usec)
184 { poolTimeout.tv_sec = sec; poolTimeout.tv_usec = usec; }
185
186 inline void setPoolTimeout(struct timeval to)
187 { poolTimeout = to; }
188
189 std::list<SessionListElement*> sessionList;
190 typedef std::list<SessionListElement*>::iterator PoolIterator;
191
192 mutable ThreadLock poolLock;
193
194#ifndef _MSWINDOWS_
196 SOCKET highestSocket; // highest socket number + 1
197#endif
198
199private:
200 timeval poolTimeout;
201 mutable bool poolActive;
202};
203
204
205class __EXPORT SingleRTPSessionPool :
206 public RTPSessionPool,
207 public Thread
208{
209public:
213 SingleRTPSessionPool(int pri = 0) :
215 Thread(pri)
216 { }
217
219 { }
220
222 { setActive(); Thread::start(); }
223
224protected:
229 void run();
230};
231
232END_NAMESPACE
233
234#endif //CCXX_RTP_POOL_H
235
uint32 microtimeout_t
Time interval expressed in microseconds.
Definition: base.h:67
std equality for SessionListElement objects.
Definition: pool.h:129
RTPSessionBase * elem
Definition: pool.h:131
PredEquals(RTPSessionBase *e)
Definition: pool.h:133
bool operator()(SessionListElement *e)
Definition: pool.h:135
Definition: pool.h:54
void controlReceptionService(RTPSessionBase &s)
Definition: pool.h:71
void controlTransmissionService(RTPSessionBase &s)
Definition: pool.h:75
size_t dispatchDataPacket(RTPSessionBase &s)
Definition: pool.h:67
timeval getRTCPCheckInterval(RTPSessionBase &s)
Definition: pool.h:59
microtimeout_t getSchedulingTimeout(RTPSessionBase &s)
Definition: pool.h:56
SOCKET getDataRecvSocket(RTPSessionBase &s) const
Definition: pool.h:78
size_t takeInDataPacket(RTPSessionBase &s)
Definition: pool.h:63
SOCKET getControlRecvSocket(RTPSessionBase &s) const
Definition: pool.h:81
Generic RTP protocol stack for exchange of realtime data.
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
virtual void startRunning()=0
size_t getPoolLength() const
std::list< SessionListElement * >::iterator PoolIterator
Definition: pool.h:190
timeval getPoolTimeout()
Definition: pool.h:180
virtual ~RTPSessionPool()
Definition: pool.h:159
bool removeSession(RTPSessionBase &session)
SOCKET highestSocket
Definition: pool.h:196
bool addSession(RTPSessionBase &session)
bool isActive()
Definition: pool.h:173
void setPoolTimeout(int sec, int usec)
Definition: pool.h:183
std::list< SessionListElement * > sessionList
Definition: pool.h:189
void setActive()
Definition: pool.h:177
ThreadLock poolLock
Definition: pool.h:192
void setPoolTimeout(struct timeval to)
Definition: pool.h:186
fd_set recvSocketSet
Definition: pool.h:195
Class for tracking session status.
Definition: pool.h:92
SessionListElement(RTPSessionBase *e)
Definition: pool.h:105
RTPSessionBase * get()
Definition: pool.h:119
void clear()
Definition: pool.h:109
bool isCleared()
Definition: pool.h:115
Definition: pool.h:208
void run()
Runnable method for the thread.
~SingleRTPSessionPool()
Definition: pool.h:218
SingleRTPSessionPool(int pri=0)
Definition: pool.h:213
void startRunning()
Definition: pool.h:221
Definition: rtp.h:88
TRTPSessionBase RTPSessionBase
Definition: pool.h:51
Generic and audio/video profile specific RTP interface of ccRTP.