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