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
49NAMESPACE_COMMONCPP
50using std::list;
51
53
55{
56public:
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
74
75 void
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
94private:
95 RTPSessionBase* elem;
96 bool cleared;
97
98public:
100 void clear();
101 bool isCleared();
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{
131protected:
133public:
135
137 {
138 return e->get() == elem;
139 }
140};
141
156{
157public:
159
160 inline virtual ~RTPSessionPool()
161 { }
162
163 bool
165
166 bool
168
169 size_t
171
172 virtual void startRunning() = 0;
173
174 inline bool isActive()
175 { return poolActive; }
176
177protected:
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
200private:
201 timeval poolTimeout;
202 mutable bool poolActive;
203};
204
205
206class __EXPORT SingleRTPSessionPool :
207 public RTPSessionPool,
208 public Thread
209{
210public:
214 SingleRTPSessionPool(int pri = 0) :
216 Thread(pri)
217 { }
218
220 { }
221
223 { setActive(); Thread::start(); }
224
225protected:
230 void run();
231};
232
233END_NAMESPACE
234
235#endif //CCXX_RTP_POOL_H
236
uint32 microtimeout_t
Time interval expressed in microseconds.
Definition base.h:68
virtual size_t takeInDataPacket()
This function is used by the service thread to process the next incoming packet and place it in the r...
microtimeout_t getSchedulingTimeout()
This computes the timeout period for scheduling transmission of the next packet at the "head" of the ...
size_t dispatchDataPacket()
This function is used by the service thread to process the next outgoing packet pending in the sendin...
std equality for SessionListElement objects.
Definition pool.h:130
RTPSessionBase * elem
Definition pool.h:132
PredEquals(RTPSessionBase *e)
Definition pool.h:134
bool operator()(SessionListElement *e)
Definition pool.h:136
void controlReceptionService()
Process incoming RTCP packets pending in the control reception socket.
void controlTransmissionService()
Build and send RTCP packets following timing rules (including the "timer reconsideration" algorithm).
timeval getRTCPCheckInterval()
Definition cqueue.h:363
Definition pool.h:55
void controlReceptionService(RTPSessionBase &s)
Definition pool.h:72
void controlTransmissionService(RTPSessionBase &s)
Definition pool.h:76
size_t dispatchDataPacket(RTPSessionBase &s)
Definition pool.h:68
timeval getRTCPCheckInterval(RTPSessionBase &s)
Definition pool.h:60
microtimeout_t getSchedulingTimeout(RTPSessionBase &s)
Definition pool.h:57
SOCKET getDataRecvSocket(RTPSessionBase &s) const
Definition pool.h:79
size_t takeInDataPacket(RTPSessionBase &s)
Definition pool.h:64
SOCKET getControlRecvSocket(RTPSessionBase &s) const
Definition pool.h:82
This class is a base class for classes that define a group of RTP sessions that will be served by one...
Definition pool.h:156
virtual void startRunning()=0
size_t getPoolLength() const
std::list< SessionListElement * >::iterator PoolIterator
Definition pool.h:191
timeval getPoolTimeout()
Definition pool.h:181
virtual ~RTPSessionPool()
Definition pool.h:160
bool removeSession(RTPSessionBase &session)
SOCKET highestSocket
Definition pool.h:197
bool addSession(RTPSessionBase &session)
bool isActive()
Definition pool.h:174
void setPoolTimeout(int sec, int usec)
Definition pool.h:184
std::list< SessionListElement * > sessionList
Definition pool.h:190
void setActive()
Definition pool.h:178
ThreadLock poolLock
Definition pool.h:193
void setPoolTimeout(struct timeval to)
Definition pool.h:187
fd_set recvSocketSet
Definition pool.h:196
Class for tracking session status.
Definition pool.h:93
SessionListElement(RTPSessionBase *e)
Definition pool.h:106
RTPSessionBase * get()
Definition pool.h:120
void clear()
Definition pool.h:110
bool isCleared()
Definition pool.h:116
Definition pool.h:209
void run()
Runnable method for the thread.
~SingleRTPSessionPool()
Definition pool.h:219
SingleRTPSessionPool(int pri=0)
Definition pool.h:214
void startRunning()
Definition pool.h:222
Definition rtp.h:87
SOCKET getDataRecvSocket() const
Definition rtp.h:236
SOCKET getControlRecvSocket() const
Definition rtp.h:278
TRTPSessionBase RTPSessionBase
Definition pool.h:52
Generic and audio/video profile specific RTP interface of ccRTP.