Bayonne2 / Common C++ 2 Framework
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
50 #ifdef CCXX_NAMESPACES
51 namespace ost {
52 #endif
53 
68 {
69 public:
70  const std::string&
71  getItem(SDESItemType type) const;
72 
73  inline const std::string&
74  getPRIVPrefix() const
75  { return sdesItems[SDESItemTypeEND]; }
76 
77  void
78  setItem(SDESItemType item, const std::string& val);
79 
80  inline void
81  setPRIVPrefix(const std::string& val)
82  { sdesItems[SDESItemTypeEND] = val; }
83 
84 protected:
86  { }
87 
88  inline virtual ~SDESItemsHolder()
89  { }
90 
91 private:
92  // SDES items for a participant.
93  // sdesItems[0] (== sdesItems[SDESItemTypeEND]) holds the prefix
94  // value for the PRIV item. The rest of entries hold the
95  // correponding SDES item value.
96  std::string sdesItems[SDESItemTypeLast + 1];
97 };
98 
128 {
129 public:
142  const std::string&
144  { return SDESItemsHolder::getItem(type); }
145 
153  inline const std::string&
155  { return SDESItemsHolder::getPRIVPrefix(); }
156 
162  Participant(const std::string& cname);
163 
164  ~Participant();
165 
166 private:
167  friend class ParticipantHandler;
168 
172  inline void
173  setSDESItem(SDESItemType item, const std::string& val)
174  { SDESItemsHolder::setItem(item,val); }
175 
179  inline void
180  setPRIVPrefix(const std::string val)
182 };
183 
196 {
197 public:
228  typedef enum {
230  statePrevalid,
231  stateActive,
234  stateInactive,
236  stateLeaving
239  } State;
241 
246  SyncSource(uint32 ssrc);
247 
248  ~SyncSource();
249 
250  State
251  getState() const
252  { return state; }
253 
257  bool isSender() const
258  { return activeSender; }
259 
260  uint32 getID() const
261  { return SSRC; }
262 
270  inline Participant*
272  { return participant; }
273 
275  { return dataTransportPort; }
276 
278  { return controlTransportPort; }
279 
281  { return networkAddress; }
282 
283 protected:
287  SyncSource(const SyncSource& source);
288 
289  SyncSource&
290  operator=(const SyncSource& source);
291 
292 private:
293  friend class SyncSourceHandler;
294 
295  inline void
297  { state = st; }
298 
302  inline void
303  setSender(bool active)
304  { activeSender = active; }
305 
306  inline void
308  { participant = &p; }
309 
311  { dataTransportPort = p; }
312 
314  { controlTransportPort = p; }
315 
317  { networkAddress = addr; }
318 
319  inline void
320  setLink(void *l)
321  { link = l; }
322 
323  void *getLink() const
324  { return link; }
325 
326  // validity state of this source
328  // 32-bit SSRC identifier.
329  uint32 SSRC;
330  // A valid source not always is active
332  // The corresponding participant.
334 
335  // Network protocol address for data and control connection
336  // (both are assumed to be the same).
340 
341  // Pointer to the SyncSourceLink or similar object in the
342  // service queue. Saves a lot of searches in the membership
343  // table.
344  void* link;
345 };
346 
368 {
369 private:
370  struct ParticipantLink;
371 
372 public:
380  RTPApplication(const std::string& cname);
381 
382  ~RTPApplication();
383 
384  inline void
385  setSDESItem(SDESItemType item, const std::string& val)
386  { SDESItemsHolder::setItem(item,val); }
387 
388  inline void
389  setPRIVPrefix(const std::string& val)
391 
392  const std::string&
394  { return SDESItemsHolder::getItem(item); }
395 
396  inline const std::string&
398  { return SDESItemsHolder::getPRIVPrefix(); }
399 
405  {
406  public:
407  typedef std::forward_iterator_tag iterator_category;
409  typedef ptrdiff_t difference_type;
410  typedef const Participant* pointer;
411  typedef const Participant& reference;
412 
414  link(p)
415  { }
416 
418  link(pi.link)
419  { }
420 
422  { return *(link->getParticipant()); }
423 
425  { return link->getParticipant(); }
426 
428  link = link->getNext();
429  return *this;
430  }
431 
433  ParticipantsIterator result(*this);
434  ++(*this);
435  return result;
436  }
437  friend bool operator==(const ParticipantsIterator& l,
438  const ParticipantsIterator& r)
439  { return l.link == r.link; }
440 
441  friend bool operator!=(const ParticipantsIterator& l,
442  const ParticipantsIterator& r)
443  { return l.link != r.link; }
444  private:
446  };
447 
449  { return ParticipantsIterator(firstPart); }
450 
452  { return ParticipantsIterator(NULL); }
453 
454  const Participant*
455  getParticipant(const std::string& cname) const;
456 
457 private:
458  friend class ApplicationHandler;
459 
462  ParticipantLink* l) :
463  participant(&p), next(l)
464  { }
465  inline ~ParticipantLink() { delete participant; }
466  inline Participant* getParticipant() { return participant; }
467  inline ParticipantLink* getPrev() { return prev; }
468  inline ParticipantLink* getNext() { return next; }
469  inline void setPrev(ParticipantLink* l) { prev = l; }
470  inline void setNext(ParticipantLink* l) { next = l; }
473  };
474 
475  void
476  addParticipant(Participant& part);
477 
478  void
479  removeParticipant(ParticipantLink* part);
480 
485  void
486  findCNAME();
487 
489  static const size_t defaultParticipantsNum;
492  ParticipantLink* firstPart, * lastPart;
493 };
494 
505  // sources
507 
508 #ifdef CCXX_NAMESPACES
509 }
510 #endif
511 
512 #endif //CCXX_RTP_SOURCES_H_
513 
const Participant * pointer
Definition: sources.h:410
friend bool operator!=(const ParticipantsIterator &l, const ParticipantsIterator &r)
Definition: sources.h:441
uint32 SSRC
Definition: sources.h:329
void setPRIVPrefix(const std::string &val)
Definition: sources.h:389
ParticipantLink * lastPart
Definition: sources.h:492
const std::string & getPRIVPrefix() const
Definition: sources.h:397
tpport_t getDataTransportPort() const
Definition: sources.h:274
Last defined code.
Definition: rtcppkt.h:79
An RTP application, holding identifying RTCP SDES item values.
Definition: sources.h:367
Synchronization source in an RTP session.
Definition: sources.h:195
void setParticipant(Participant &p)
Definition: sources.h:307
ParticipantsIterator operator++(int)
Definition: sources.h:432
Participant * participant
Definition: sources.h:333
void setControlTransportPort(tpport_t p)
Definition: sources.h:313
No valid packet has been received.
Definition: sources.h:229
void * link
Definition: sources.h:344
ParticipantsIterator begin()
Definition: sources.h:448
unsigned short tpport_t
Transport Protocol Ports.
Definition: address.h:86
InetAddress networkAddress
Definition: sources.h:337
ParticipantsIterator(ParticipantLink *p=NULL)
Definition: sources.h:413
const Participant & reference
Definition: sources.h:411
Participant objects modification methods.
Definition: iqueue.h:182
void setState(State st)
Definition: sources.h:296
std::forward_iterator_tag iterator_category
Definition: sources.h:407
RTCP packets handling.
const std::string & getItem(SDESItemType type) const
State
Synchronization source states during an RTP session.
Definition: sources.h:228
Application objects modification methods.
Definition: iqueue.h:208
A class of objects representing remote participants (RTP applications) in a multimedia session...
Definition: sources.h:127
void setItem(SDESItemType item, const std::string &val)
ParticipantsIterator end()
Definition: sources.h:451
State getState() const
Definition: sources.h:251
tpport_t controlTransportPort
Definition: sources.h:339
ParticipantsIterator(const ParticipantsIterator &pi)
Definition: sources.h:417
virtual ~SDESItemsHolder()
Definition: sources.h:88
Participant * getParticipant() const
Get the participant this synchronization source is asociated to.
Definition: sources.h:271
void setSDESItem(SDESItemType item, const std::string &val)
Definition: sources.h:385
END of SDES item list.
Definition: rtcppkt.h:69
void setLink(void *l)
Definition: sources.h:320
reference operator*() const
Definition: sources.h:421
const InetAddress & getNetworkAddress() const
Definition: sources.h:280
#define InetAddress
Definition: address.h:75
Iterator through the list of participants in this session.
Definition: sources.h:404
void setSender(bool active)
Mark this source as an active sender.
Definition: sources.h:303
tpport_t getControlTransportPort() const
Definition: sources.h:277
bool isSender() const
Whether this source sends RTP data packets.
Definition: sources.h:257
#define __EXPORT
Definition: audio2.h:51
Holds the SDES items and related information from a participant in an RTP application.
Definition: sources.h:67
const std::string & getPRIVPrefix() const
Definition: sources.h:74
friend bool operator==(const ParticipantsIterator &l, const ParticipantsIterator &r)
Definition: sources.h:437
void * getLink() const
Definition: sources.h:323
tpport_t dataTransportPort
Definition: sources.h:338
void setPRIVPrefix(const std::string &val)
Definition: sources.h:81
static const size_t defaultParticipantsNum
Hash table with sources of RTP and RTCP packets.
Definition: sources.h:489
State state
Definition: sources.h:327
Participant ** participants
Definition: sources.h:490
uint32 getID() const
Definition: sources.h:260
void setDataTransportPort(tpport_t p)
Definition: sources.h:310
const std::string & getSDESItem(SDESItemType item) const
Definition: sources.h:393
SyncSource objects modification methods.
Definition: iqueue.h:127
__EXPORT RTPApplication & defaultApplication()
Get the RTPApplication object for the "default" application (the only one used by common applications...
bool activeSender
Definition: sources.h:331
void setPRIVPrefix(const std::string val)
Set prefix value for the PRIV SDES item.
Definition: sources.h:180
const std::string & getPRIVPrefix() const
Get the prefix value for the PRIV SDES item.
Definition: sources.h:154
SDESItemType
SDES items that may be carried in a Source DEScription RTCP packet.
Definition: rtcppkt.h:67
const std::string & getSDESItem(SDESItemType type) const
Get the value of an SDES item.
Definition: sources.h:143
void setSDESItem(SDESItemType item, const std::string &val)
Set the value of a SDES item.
Definition: sources.h:173
void setNetworkAddress(InetAddress addr)
Definition: sources.h:316
ParticipantsIterator & operator++()
Definition: sources.h:427