1 // Copyright (C) 2000-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 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
40
41 #include <algorithm>
42
43 NAMESPACE_COMMONCPP
44 using std::list;
45
47 {
48 #ifndef _MSWINDOWS_
52 #endif
53 }
54
55 bool
57 {
58 #ifndef _MSWINDOWS_
59 bool result = false;
61 // insert in list.
64 result = true;
66 } else {
67 result = false;
68 }
70 return result;
71 #else
72 return false;
73 #endif
74 }
75
76 bool
78 {
79 #ifndef _MSWINDOWS_
80 bool result = false;
82 // remove from list.
86 (*i)->clear();
87 result = true;
88 } else {
89 result = false;
90 }
92 return result;
93 #else
94 return false;
95 #endif
96 }
97
98 size_t
100 {
101 #ifndef _MSWINDOWS_
102 size_t result;
106 return result;
107 #else
108 return 0;
109 #endif
110 }
111
112 void
114 {
115 #ifndef _MSWINDOWS_
116 SOCKET so;
120 // Make a copy of the list so that add and remove does
121 // not affect the list during this loop iteration
124
126 while ( i != sessions.end() ) {
128 if (!(*i)->isCleared()) {
132 }
134 i++;
135 }
137
138 // Reinitializa fd set
142 for (
PoolIterator j = sessions.begin(); j != sessions.end (); j++) {
143 if (!(*j)->isCleared()) {
149 }
150 }
152
153
155 &timeout);
156
157 i = sessions.begin();
158 while ( (i != sessions.end()) ) {
160 if (!(*i)->isCleared()) {
165 }
166
167 // schedule by timestamp, as in
168 // SingleThreadRTPSession (by Joergen
169 // Terner)
170 if (packetTimeout < 1000) {
172 }
175 // make sure the scheduling timeout is
176 // <= the check interval for RTCP
177 // packets
178 packetTimeout = (packetTimeout > maxWait)? maxWait : packetTimeout;
179 if ( packetTimeout < 1000 ) { // !(packetTimeout/1000)
181 //timerTick();
182 } else {
183 packetTimeout = 0;
184 }
185 }
187 i++;
188 }
189
190 // Purge elements for removed sessions.
194 if ((*i)->isCleared()) {
197 delete element;
198 }
199 else {
200 ++i;
201 }
202 }
204
205 //GF we added that to allow the kernel scheduler to
206 // give other tasks some time as if we have lots of
207 // active sessions the thread cann take all the CPU if we
208 // don't pause at all. We haven't found the best way to
209 // do that yet.
210 // usleep (10);
211 yield();
212 }
213 #endif // ndef WIN32
214 }
215
216 #if defined(_MSC_VER) && _MSC_VER >= 1300
218 const InetHostAddress& ia, tpport_t dataPort, tpport_t controlPort, int pri,
221 (ia,dataPort,controlPort,memberssize,app)
222 {}
223
225 const InetMcastAddress& ia, tpport_t dataPort, tpport_t controlPort, int pri,
228 (ia,dataPort,controlPort,memberssize,app,iface)
229 {}
230
232 {
233 enableStack();
234 Thread::start();
235 }
236
238 {
240 }
241
243 {}
244
246 {
248 while ( ServiceQueue::isActive() ) {
249 if ( timeout < 1000 ){ // !(timeout/1000)
250 timeout = getSchedulingTimeout();
251 }
252 controlReceptionService();
253 controlTransmissionService();
256 // make sure the scheduling timeout is
257 // <= the check interval for RTCP
258 // packets
259 timeout = (timeout > maxWait)? maxWait : timeout;
260 if ( timeout < 1000 ) { // !(timeout/1000)
261 dispatchDataPacket();
262 timerTick();
263 } else {
264 if ( isPendingData(timeout/1000) ) {
265 takeInDataPacket();
266 }
267 timeout = 0;
268 }
269 }
270 dispatchBYE("GNU ccRTP stack finishing.");
271 Thread::exit();
272 }
273
274
275 #ifdef CCXX_IPV6
276
277 SingleThreadRTPSessionIPV6<DualRTPUDPIPv6Channel,DualRTPUDPIPv6Channel,AVPQueue>::SingleThreadRTPSessionIPV6<DualRTPUDPIPv6Channel,DualRTPUDPIPv6Channel,
AVPQueue>(
278 const IPV6Host& ia, tpport_t dataPort, tpport_t controlPort, int pri,
280 Thread(pri), TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>
281 (ia,dataPort,controlPort,memberssize,app)
282 {}
283
284 SingleThreadRTPSessionIPV6<DualRTPUDPIPv6Channel,DualRTPUDPIPv6Channel,AVPQueue>::SingleThreadRTPSessionIPV6<DualRTPUDPIPv6Channel,DualRTPUDPIPv6Channel,
AVPQueue>(
285 const IPV6Multicast& ia, tpport_t dataPort, tpport_t controlPort, int pri,
287 Thread(pri), TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>
288 (ia,dataPort,controlPort,memberssize,app,iface)
289 {}
290
291 void SingleThreadRTPSessionIPV6<DualRTPUDPIPv6Channel,DualRTPUDPIPv6Channel,AVPQueue>::startRunning()
292 {
293 enableStack();
294 Thread::start();
295 }
296
297 bool SingleThreadRTPSessionIPV6<DualRTPUDPIPv6Channel,DualRTPUDPIPv6Channel,AVPQueue>::isPendingData(
microtimeout_t timeout)
298 {
299 return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::isPendingData(timeout);
300 }
301
302 void SingleThreadRTPSessionIPV6<DualRTPUDPIPv6Channel,DualRTPUDPIPv6Channel,AVPQueue>::timerTick(void)
303 {}
304
305 void SingleThreadRTPSessionIPV6<DualRTPUDPIPv6Channel,DualRTPUDPIPv6Channel,AVPQueue>::run(void)
306 {
308 while ( ServiceQueue::isActive() ) {
309 if ( timeout < 1000 ){ // !(timeout/1000)
310 timeout = getSchedulingTimeout();
311 }
312 controlReceptionService();
313 controlTransmissionService();
316 // make sure the scheduling timeout is
317 // <= the check interval for RTCP
318 // packets
319 timeout = (timeout > maxWait)? maxWait : timeout;
320 if ( timeout < 1000 ) { // !(timeout/1000)
321 dispatchDataPacket();
322 timerTick();
323 } else {
324 if ( isPendingData(timeout/1000) ) {
325 takeInDataPacket();
326 }
327 timeout = 0;
328 }
329 }
330 dispatchBYE("GNU ccRTP stack finishing.");
331 Thread::exit();
332 }
333
334
335 #endif
336
337
338 #endif
339
340 END_NAMESPACE
341
std::list< SessionListElement * >::iterator PoolIterator
std::list< SessionListElement * > sessionList
size_t dispatchDataPacket(RTPSessionBase &s)
void controlTransmissionService(RTPSessionBase &s)
An RTP application, holding identifying RTCP SDES item values.
DualRTPChannel< RTPBaseUDPIPv4Socket > DualRTPUDPIPv4Channel
virtual void timerTick(void)
uint32 microtimeout_t
Time interval expressed in microseconds.
void run()
Runnable method for the thread.
Generic RTP protocol stack for exchange of realtime data.
microtimeout_t timeval2microtimeout(const timeval &t)
Convert a time interval, expressed as a timeval value into a microseconds counter.
SOCKET getDataRecvSocket(RTPSessionBase &s) const
Declaration of ccRTP internal stuff.
virtual bool isPendingData(microtimeout_t timeout)
size_t takeInDataPacket(RTPSessionBase &s)
std equality for SessionListElement objects.
timeval getRTCPCheckInterval(RTPSessionBase &s)
void startRunning()
Activate stack and start service thread.
bool isPendingData(microtimeout_t timeout)
virtual void run(void)
Single runnable method for this RTP stacks, schedules outgoing and incoming RTP data and RTCP packets...
Class for tracking session status.
bool removeSession(RTPSessionBase &session)
microtimeout_t getSchedulingTimeout(RTPSessionBase &s)
void controlReceptionService(RTPSessionBase &s)
This template class adds the threading aspect to the RTPSessionBase template in one of the many possi...
bool addSession(RTPSessionBase &session)
size_t getPoolLength() const
void setPoolTimeout(int sec, int usec)
This class, an RTP/RTCP queue, adds audio/video profile (AVP) specific methods to the generic RTCP se...