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 
49 NAMESPACE_COMMONCPP
50 
64 class __EXPORT SDESItemsHolder
65 {
66 public:
67  const std::string&
68  getItem(SDESItemType type) const;
69 
70  inline const std::string&
71  getPRIVPrefix() const
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 
81 protected:
83  { }
84 
85  inline virtual ~SDESItemsHolder()
86  { }
87 
88 private:
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 
124 class __EXPORT Participant : private SDESItemsHolder
125 {
126 public:
139  const std::string&
141  { return SDESItemsHolder::getItem(type); }
142 
150  inline const std::string&
152  { return SDESItemsHolder::getPRIVPrefix(); }
153 
159  Participant(const std::string& cname);
160 
161  ~Participant();
162 
163 private:
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 
192 class __EXPORT SyncSource
193 {
194 public:
225  typedef enum {
228  stateActive,
231  stateInactive,
233  stateLeaving
236  } State;
238 
243  SyncSource(uint32 ssrc);
244 
245  ~SyncSource();
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 
280 protected:
284  SyncSource(const SyncSource& source);
285 
286  SyncSource&
287  operator=(const SyncSource& source);
288 
289 private:
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
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 
364 class __EXPORT RTPApplication : private SDESItemsHolder
365 {
366 private:
367  struct ParticipantLink;
368 
369 public:
377  RTPApplication(const std::string& cname);
378 
379  ~RTPApplication();
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&
395  { return SDESItemsHolder::getPRIVPrefix(); }
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 
418  reference operator*() const
419  { return *(link->getParticipant()); }
420 
421  pointer operator->() const
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 
454 private:
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 
505 END_NAMESPACE
506 
507 #endif //CCXX_RTP_SOURCES_H_
508 
SDESItemsHolder::SDESItemsHolder
SDESItemsHolder()
Definition: sources.h:82
SyncSourceHandler::setControlTransportPort
void setControlTransportPort(SyncSource &source, tpport_t p)
Definition: iqueue.h:158
SyncSourceHandler::getLink
void * getLink(const SyncSource &source) const
This requires SyncSource - SyncSourceHandler friendship.
Definition: iqueue.h:134
Participant::getPRIVPrefix
const std::string & getPRIVPrefix() const
Get the prefix value for the PRIV SDES item.
Definition: sources.h:151
RTPApplication::ParticipantsIterator::difference_type
std::ptrdiff_t difference_type
Definition: sources.h:406
RTPApplication::ParticipantsIterator::operator*
reference operator*() const
Definition: sources.h:418
SDESItemTypeLast
@ SDESItemTypeLast
Last defined code.
Definition: rtcppkt.h:76
RTPApplication::ParticipantsIterator::pointer
const typedef Participant * pointer
Definition: sources.h:407
RTPApplication::ParticipantsIterator::ParticipantsIterator
ParticipantsIterator(const ParticipantsIterator &pi)
Definition: sources.h:414
SyncSource
Synchronization source in an RTP session.
Definition: sources.h:192
RTPApplication::ParticipantsIterator::reference
const typedef Participant & reference
Definition: sources.h:408
RTPApplication::ParticipantsIterator::value_type
Participant value_type
Definition: sources.h:405
defaultApplication
__EXPORT RTPApplication & defaultApplication()
Get the RTPApplication object for the "default" application (the only one used by common applications...
SyncSourceHandler::setState
void setState(SyncSource &source, SyncSource::State ns)
Definition: iqueue.h:146
RTPApplication::ParticipantsIterator::operator->
pointer operator->() const
Definition: sources.h:421
SyncSourceHandler::setLink
void setLink(SyncSource &source, void *link)
Definition: iqueue.h:138
SyncSourceHandler::setSender
void setSender(SyncSource &source, bool active)
Definition: iqueue.h:150
SyncSource::statePrevalid
@ statePrevalid
Some packets have been.
Definition: sources.h:227
SDESItemsHolder::setItem
void setItem(SDESItemType item, const std::string &val)
SyncSource::getID
uint32 getID() const
Definition: sources.h:257
ApplicationHandler
Application objects modification methods.
Definition: iqueue.h:205
SyncSource::getNetworkAddress
const InetAddress & getNetworkAddress() const
Definition: sources.h:277
SDESItemsHolder::getItem
const std::string & getItem(SDESItemType type) const
rtcppkt.h
RTCP packets handling.
RTPApplication::ParticipantsIterator::iterator_category
std::forward_iterator_tag iterator_category
Definition: sources.h:404
RTPApplication::ParticipantsIterator
Iterator through the list of participants in this session.
Definition: sources.h:401
RTPApplication::ParticipantsIterator::operator++
ParticipantsIterator & operator++()
Definition: sources.h:424
SDESItemsHolder::~SDESItemsHolder
virtual ~SDESItemsHolder()
Definition: sources.h:85
ParticipantHandler
Participant objects modification methods.
Definition: iqueue.h:179
RTPApplication::getPRIVPrefix
const std::string & getPRIVPrefix() const
Definition: sources.h:394
SyncSource::getControlTransportPort
tpport_t getControlTransportPort() const
Definition: sources.h:274
SDESItemTypeEND
@ SDESItemTypeEND
END of SDES item list.
Definition: rtcppkt.h:66
SyncSource::stateUnknown
@ stateUnknown
No valid packet has been received.
Definition: sources.h:226
Participant
A class of objects representing remote participants (RTP applications) in a multimedia session.
Definition: sources.h:124
SyncSource::State
State
Synchronization source states during an RTP session.
Definition: sources.h:225
SDESItemsHolder::setPRIVPrefix
void setPRIVPrefix(const std::string &val)
Definition: sources.h:78
RTPApplication::ParticipantsIterator::operator++
ParticipantsIterator operator++(int)
Definition: sources.h:429
RTPApplication::end
ParticipantsIterator end()
Definition: sources.h:448
RTPApplication::getSDESItem
const std::string & getSDESItem(SDESItemType item) const
Definition: sources.h:390
SyncSource::isSender
bool isSender() const
Whether this source sends RTP data packets.
Definition: sources.h:254
RTPApplication::ParticipantsIterator::operator==
friend bool operator==(const ParticipantsIterator &l, const ParticipantsIterator &r)
Definition: sources.h:434
SyncSourceHandler::setNetworkAddress
void setNetworkAddress(SyncSource &source, InetAddress addr)
Definition: iqueue.h:162
RTPApplication::ParticipantsIterator::operator!=
friend bool operator!=(const ParticipantsIterator &l, const ParticipantsIterator &r)
Definition: sources.h:438
SyncSourceHandler
SyncSource objects modification methods.
Definition: iqueue.h:124
RTPApplication::setPRIVPrefix
void setPRIVPrefix(const std::string &val)
Definition: sources.h:386
RTPApplication::setSDESItem
void setSDESItem(SDESItemType item, const std::string &val)
Definition: sources.h:382
Participant::getSDESItem
const std::string & getSDESItem(SDESItemType type) const
Get the value of an SDES item.
Definition: sources.h:140
SyncSource::getParticipant
Participant * getParticipant() const
Get the participant this synchronization source is asociated to.
Definition: sources.h:268
RTPApplication::begin
ParticipantsIterator begin()
Definition: sources.h:445
SyncSource::getState
State getState() const
Definition: sources.h:248
RTPApplication
An RTP application, holding identifying RTCP SDES item values. Represents local participants.
Definition: sources.h:364
SDESItemsHolder
Definition: sources.h:64
SyncSource::getDataTransportPort
tpport_t getDataTransportPort() const
Definition: sources.h:271
ParticipantHandler::setSDESItem
void setSDESItem(Participant *part, SDESItemType item, const std::string &val)
Definition: iqueue.h:183
RTPApplication::ParticipantsIterator::ParticipantsIterator
ParticipantsIterator(ParticipantLink *p=NULL)
Definition: sources.h:410
SyncSourceHandler::setDataTransportPort
void setDataTransportPort(SyncSource &source, tpport_t p)
Definition: iqueue.h:154
SDESItemsHolder::getPRIVPrefix
const std::string & getPRIVPrefix() const
Definition: sources.h:71
SyncSourceHandler::setParticipant
void setParticipant(SyncSource &source, Participant &p)
Definition: iqueue.h:142
SDESItemType
SDESItemType
SDES items that may be carried in a Source DEScription RTCP packet.
Definition: rtcppkt.h:64