ccRTP 2.1.2
 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-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 
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 
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 
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
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
325  // 32-bit SSRC identifier.
326  uint32 SSRC;
327  // A valid source not always is active
329  // The corresponding participant.
331 
332  // Network protocol address for data and control connection
333  // (both are assumed to be the same).
334  InetAddress networkAddress;
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 
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 
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:
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 
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; }
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;
489  ParticipantLink* firstPart, * lastPart;
490 };
491 
502  // sources
504 
505 END_NAMESPACE
506 
507 #endif //CCXX_RTP_SOURCES_H_
508 
const Participant * pointer
Definition: sources.h:407
friend bool operator!=(const ParticipantsIterator &l, const ParticipantsIterator &r)
Definition: sources.h:438
uint32 SSRC
Definition: sources.h:326
void setPRIVPrefix(const std::string &val)
Definition: sources.h:386
ParticipantLink * lastPart
Definition: sources.h:489
const std::string & getPRIVPrefix() const
Definition: sources.h:394
const std::string & getItem(SDESItemType type) const
Definition: source.cpp:99
tpport_t getDataTransportPort() const
Definition: sources.h:271
Last defined code.
Definition: rtcppkt.h:76
An RTP application, holding identifying RTCP SDES item values.
Definition: sources.h:364
Synchronization source in an RTP session.
Definition: sources.h:192
void setParticipant(Participant &p)
Definition: sources.h:304
ParticipantsIterator operator++(int)
Definition: sources.h:429
Participant * participant
Definition: sources.h:330
void setControlTransportPort(tpport_t p)
Definition: sources.h:310
Some packets have been.
Definition: sources.h:227
No valid packet has been received.
Definition: sources.h:226
void * link
Definition: sources.h:341
ParticipantsIterator begin()
Definition: sources.h:445
InetAddress networkAddress
Definition: sources.h:334
ParticipantsIterator(ParticipantLink *p=NULL)
Definition: sources.h:410
const Participant & reference
Definition: sources.h:408
Participant objects modification methods.
Definition: iqueue.h:179
void setState(State st)
Definition: sources.h:293
std::forward_iterator_tag iterator_category
Definition: sources.h:404
RTCP packets handling.
State
Synchronization source states during an RTP session.
Definition: sources.h:225
Application objects modification methods.
Definition: iqueue.h:205
A class of objects representing remote participants (RTP applications) in a multimedia session...
Definition: sources.h:124
void setItem(SDESItemType item, const std::string &val)
Definition: source.cpp:91
ParticipantsIterator end()
Definition: sources.h:448
State getState() const
Definition: sources.h:248
tpport_t controlTransportPort
Definition: sources.h:336
ParticipantsIterator(const ParticipantsIterator &pi)
Definition: sources.h:414
virtual ~SDESItemsHolder()
Definition: sources.h:85
Participant * getParticipant() const
Get the participant this synchronization source is asociated to.
Definition: sources.h:268
void setSDESItem(SDESItemType item, const std::string &val)
Definition: sources.h:382
END of SDES item list.
Definition: rtcppkt.h:66
#define __EXPORT
Definition: ZrtpCallback.h:40
void setLink(void *l)
Definition: sources.h:317
reference operator*() const
Definition: sources.h:418
const InetAddress & getNetworkAddress() const
Definition: sources.h:277
Iterator through the list of participants in this session.
Definition: sources.h:401
void setSender(bool active)
Mark this source as an active sender.
Definition: sources.h:300
tpport_t getControlTransportPort() const
Definition: sources.h:274
bool isSender() const
Whether this source sends RTP data packets.
Definition: sources.h:254
Holds the SDES items and related information from a participant in an RTP application.
Definition: sources.h:64
const std::string & getPRIVPrefix() const
Definition: sources.h:71
friend bool operator==(const ParticipantsIterator &l, const ParticipantsIterator &r)
Definition: sources.h:434
void * getLink() const
Definition: sources.h:320
tpport_t dataTransportPort
Definition: sources.h:335
void setPRIVPrefix(const std::string &val)
Definition: sources.h:78
static const size_t defaultParticipantsNum
Hash table with sources of RTP and RTCP packets.
Definition: sources.h:486
State state
Definition: sources.h:324
Participant ** participants
Definition: sources.h:487
uint32 getID() const
Definition: sources.h:257
void setDataTransportPort(tpport_t p)
Definition: sources.h:307
const std::string & getSDESItem(SDESItemType item) const
Definition: sources.h:390
SyncSource objects modification methods.
Definition: iqueue.h:124
__EXPORT RTPApplication & defaultApplication()
Get the RTPApplication object for the "default" application (the only one used by common applications...
Definition: source.cpp:128
bool activeSender
Definition: sources.h:328
void setPRIVPrefix(const std::string val)
Set prefix value for the PRIV SDES item.
Definition: sources.h:177
const std::string & getPRIVPrefix() const
Get the prefix value for the PRIV SDES item.
Definition: sources.h:151
SDESItemType
SDES items that may be carried in a Source DEScription RTCP packet.
Definition: rtcppkt.h:64
const std::string & getSDESItem(SDESItemType type) const
Get the value of an SDES item.
Definition: sources.h:140
void setSDESItem(SDESItemType item, const std::string &val)
Set the value of a SDES item.
Definition: sources.h:170
void setNetworkAddress(InetAddress addr)
Definition: sources.h:313
ParticipantsIterator & operator++()
Definition: sources.h:424