ccRTP
sources.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
43#ifndef CCXX_RTP_SOURCES_H_
44#define CCXX_RTP_SOURCES_H_
45
46#include <string>
47#include <ccrtp/rtcppkt.h>
48
49NAMESPACE_COMMONCPP
50
64class __EXPORT SDESItemsHolder
65{
66public:
67 const std::string&
68 getItem(SDESItemType type) const;
69
70 inline const std::string&
72 { return sdesItems[SDESItemTypeEND]; }
73
74 void
75 setItem(SDESItemType item, const std::string& val);
76
77 inline void
78 setPRIVPrefix(const std::string& val)
79 { sdesItems[SDESItemTypeEND] = val; }
80
81protected:
83 { }
84
85 inline virtual ~SDESItemsHolder()
86 { }
87
88private:
89 // SDES items for a participant.
90 // sdesItems[0] (== sdesItems[SDESItemTypeEND]) holds the prefix
91 // value for the PRIV item. The rest of entries hold the
92 // correponding SDES item value.
93 std::string sdesItems[SDESItemTypeLast + 1];
94};
95
124class __EXPORT Participant : private SDESItemsHolder
125{
126public:
139 const std::string&
141 { return SDESItemsHolder::getItem(type); }
142
150 inline const std::string&
153
159 Participant(const std::string& cname);
160
162
163private:
164 friend class ParticipantHandler;
165
169 inline void
170 setSDESItem(SDESItemType item, const std::string& val)
171 { SDESItemsHolder::setItem(item,val); }
172
176 inline void
177 setPRIVPrefix(const std::string val)
179};
180
192class __EXPORT SyncSource
193{
194public:
225 typedef enum {
235 stateLeaving
237 } State;
238
243 SyncSource(uint32 ssrc);
244
246
247 State
248 getState() const
249 { return state; }
250
254 bool isSender() const
255 { return activeSender; }
256
257 uint32 getID() const
258 { return SSRC; }
259
267 inline Participant*
269 { return participant; }
270
271 tpport_t getDataTransportPort() const
272 { return dataTransportPort; }
273
274 tpport_t getControlTransportPort() const
275 { return controlTransportPort; }
276
277 const InetAddress& getNetworkAddress() const
278 { return networkAddress; }
279
280protected:
284 SyncSource(const SyncSource& source);
285
287 operator=(const SyncSource& source);
288
289private:
290 friend class SyncSourceHandler;
291
292 inline void
293 setState(State st)
294 { state = st; }
295
299 inline void
300 setSender(bool active)
301 { activeSender = active; }
302
303 inline void
304 setParticipant(Participant& p)
305 { participant = &p; }
306
307 void setDataTransportPort(tpport_t p)
308 { dataTransportPort = p; }
309
310 void setControlTransportPort(tpport_t p)
311 { controlTransportPort = p; }
312
313 void setNetworkAddress(InetAddress addr)
314 { networkAddress = addr; }
315
316 inline void
317 setLink(void *l)
318 { link = l; }
319
320 void *getLink() const
321 { return link; }
322
323 // validity state of this source
324 State state;
325 // 32-bit SSRC identifier.
326 uint32 SSRC;
327 // A valid source not always is active
328 bool activeSender;
329 // The corresponding participant.
330 Participant* participant;
331
332 // Network protocol address for data and control connection
333 // (both are assumed to be the same).
334 InetAddress networkAddress;
335 tpport_t dataTransportPort;
336 tpport_t controlTransportPort;
337
338 // Pointer to the SyncSourceLink or similar object in the
339 // service queue. Saves a lot of searches in the membership
340 // table.
341 void* link;
342};
343
364class __EXPORT RTPApplication : private SDESItemsHolder
365{
366private:
367 struct ParticipantLink;
368
369public:
377 RTPApplication(const std::string& cname);
378
380
381 inline void
382 setSDESItem(SDESItemType item, const std::string& val)
383 { SDESItemsHolder::setItem(item,val); }
384
385 inline void
386 setPRIVPrefix(const std::string& val)
388
389 const std::string&
391 { return SDESItemsHolder::getItem(item); }
392
393 inline const std::string&
396
402 {
403 public:
404 typedef std::forward_iterator_tag iterator_category;
406 typedef std::ptrdiff_t difference_type;
407 typedef const Participant* pointer;
408 typedef const Participant& reference;
409
410 ParticipantsIterator(ParticipantLink* p = NULL) :
411 link(p)
412 { }
413
415 link(pi.link)
416 { }
417
419 { return *(link->getParticipant()); }
420
422 { return link->getParticipant(); }
423
425 link = link->getNext();
426 return *this;
427 }
428
430 ParticipantsIterator result(*this);
431 ++(*this);
432 return result;
433 }
434 friend bool operator==(const ParticipantsIterator& l,
435 const ParticipantsIterator& r)
436 { return l.link == r.link; }
437
438 friend bool operator!=(const ParticipantsIterator& l,
439 const ParticipantsIterator& r)
440 { return l.link != r.link; }
441 private:
442 ParticipantLink *link;
443 };
444
446 { return ParticipantsIterator(firstPart); }
447
449 { return ParticipantsIterator(NULL); }
450
451 const Participant*
452 getParticipant(const std::string& cname) const;
453
454private:
455 friend class ApplicationHandler;
456
457 struct ParticipantLink {
458 ParticipantLink(Participant& p,
459 ParticipantLink* l) :
460 participant(&p), next(l)
461 { }
462 inline ~ParticipantLink() { delete participant; }
463 inline Participant* getParticipant() { return participant; }
464 inline ParticipantLink* getPrev() { return prev; }
465 inline ParticipantLink* getNext() { return next; }
466 inline void setPrev(ParticipantLink* l) { prev = l; }
467 inline void setNext(ParticipantLink* l) { next = l; }
468 Participant* participant;
469 ParticipantLink* next, *prev;
470 };
471
472 void
473 addParticipant(Participant& part);
474
475 void
476 removeParticipant(ParticipantLink* part);
477
482 void
483 findCNAME();
484
486 static const size_t defaultParticipantsNum;
487 Participant** participants;
489 ParticipantLink* firstPart, * lastPart;
490};
491
502 // sources
504
505END_NAMESPACE
506
507#endif //CCXX_RTP_SOURCES_H_
508
Application objects modification methods.
Definition iqueue.h:206
Participant objects modification methods.
Definition iqueue.h:180
A class of objects representing remote participants (RTP applications) in a multimedia session.
Definition sources.h:125
const std::string & getSDESItem(SDESItemType type) const
Get the value of an SDES item.
Definition sources.h:140
Participant(const std::string &cname)
Construct a new participant.
const std::string & getPRIVPrefix() const
Get the prefix value for the PRIV SDES item.
Definition sources.h:151
Iterator through the list of participants in this session.
Definition sources.h:402
ParticipantsIterator(const ParticipantsIterator &pi)
Definition sources.h:414
pointer operator->() const
Definition sources.h:421
ParticipantsIterator operator++(int)
Definition sources.h:429
reference operator*() const
Definition sources.h:418
ParticipantsIterator(ParticipantLink *p=NULL)
Definition sources.h:410
const Participant & reference
Definition sources.h:408
const Participant * pointer
Definition sources.h:407
Participant value_type
Definition sources.h:405
friend bool operator!=(const ParticipantsIterator &l, const ParticipantsIterator &r)
Definition sources.h:438
std::ptrdiff_t difference_type
Definition sources.h:406
friend bool operator==(const ParticipantsIterator &l, const ParticipantsIterator &r)
Definition sources.h:434
std::forward_iterator_tag iterator_category
Definition sources.h:404
ParticipantsIterator & operator++()
Definition sources.h:424
An RTP application, holding identifying RTCP SDES item values.
Definition sources.h:365
const std::string & getSDESItem(SDESItemType item) const
Definition sources.h:390
void setPRIVPrefix(const std::string &val)
Definition sources.h:386
const Participant * getParticipant(const std::string &cname) const
const std::string & getPRIVPrefix() const
Definition sources.h:394
ParticipantsIterator end()
Definition sources.h:448
ParticipantsIterator begin()
Definition sources.h:445
void setSDESItem(SDESItemType item, const std::string &val)
Definition sources.h:382
RTPApplication(const std::string &cname)
Create a new RTP application.
Holds the SDES items and related information from a participant in an RTP application.
Definition sources.h:65
const std::string & getItem(SDESItemType type) const
virtual ~SDESItemsHolder()
Definition sources.h:85
void setItem(SDESItemType item, const std::string &val)
void setPRIVPrefix(const std::string &val)
Definition sources.h:78
SDESItemsHolder()
Definition sources.h:82
const std::string & getPRIVPrefix() const
Definition sources.h:71
SyncSource objects modification methods.
Definition iqueue.h:125
Synchronization source in an RTP session.
Definition sources.h:193
tpport_t getDataTransportPort() const
Definition sources.h:271
tpport_t getControlTransportPort() const
Definition sources.h:274
Participant * getParticipant() const
Get the participant this synchronization source is asociated to.
Definition sources.h:268
State getState() const
Definition sources.h:248
SyncSource(const SyncSource &source)
uint32 getID() const
Definition sources.h:257
bool isSender() const
Whether this source sends RTP data packets.
Definition sources.h:254
const InetAddress & getNetworkAddress() const
Definition sources.h:277
SyncSource & operator=(const SyncSource &source)
State
Synchronization source states during an RTP session.
Definition sources.h:225
@ statePrevalid
Some packets have been.
Definition sources.h:227
@ stateInactive
(data or control) from this source.
Definition sources.h:232
@ stateActive
received, but source validity not yet guaranteed.
Definition sources.h:230
@ stateUnknown
No valid packet has been received.
Definition sources.h:226
SyncSource(uint32 ssrc)
SDESItemType
SDES items that may be carried in a Source DEScription RTCP packet.
Definition rtcppkt.h:65
@ SDESItemTypeEND
END of SDES item list.
Definition rtcppkt.h:66
@ SDESItemTypeLast
Last defined code.
Definition rtcppkt.h:76
__EXPORT RTPApplication & defaultApplication()
Get the RTPApplication object for the "default" application (the only one used by common applications...
RTCP packets handling.