00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00044 #ifndef CCXX_RTP_SOURCES_H_
00045 #define CCXX_RTP_SOURCES_H_
00046
00047 #include <string>
00048 #include <ccrtp/rtcppkt.h>
00049
00050 #ifdef CCXX_NAMESPACES
00051 namespace ost {
00052 #endif
00053
00067 class __EXPORT SDESItemsHolder
00068 {
00069 public:
00070 const std::string&
00071 getItem(SDESItemType type) const;
00072
00073 inline const std::string&
00074 getPRIVPrefix() const
00075 { return sdesItems[SDESItemTypeEND]; }
00076
00077 void
00078 setItem(SDESItemType item, const std::string& val);
00079
00080 inline void
00081 setPRIVPrefix(const std::string& val)
00082 { sdesItems[SDESItemTypeEND] = val; }
00083
00084 protected:
00085 SDESItemsHolder()
00086 { }
00087
00088 inline virtual ~SDESItemsHolder()
00089 { }
00090
00091 private:
00092
00093
00094
00095
00096 std::string sdesItems[SDESItemTypeLast + 1];
00097 };
00098
00127 class __EXPORT Participant : private SDESItemsHolder
00128 {
00129 public:
00142 const std::string&
00143 getSDESItem(SDESItemType type) const
00144 { return SDESItemsHolder::getItem(type); }
00145
00153 inline const std::string&
00154 getPRIVPrefix() const
00155 { return SDESItemsHolder::getPRIVPrefix(); }
00156
00162 Participant(const std::string& cname);
00163
00164 ~Participant();
00165
00166 private:
00167 friend class ParticipantHandler;
00168
00172 inline void
00173 setSDESItem(SDESItemType item, const std::string& val)
00174 { SDESItemsHolder::setItem(item,val); }
00175
00179 inline void
00180 setPRIVPrefix(const std::string val)
00181 { SDESItemsHolder::setPRIVPrefix(val); }
00182 };
00183
00195 class __EXPORT SyncSource
00196 {
00197 public:
00228 typedef enum {
00229 stateUnknown,
00230 statePrevalid,
00231
00232
00233 stateActive,
00234
00235 stateInactive,
00236
00237
00238 stateLeaving
00239
00240 } State;
00241
00246 SyncSource(uint32 ssrc);
00247
00248 ~SyncSource();
00249
00250 State
00251 getState() const
00252 { return state; }
00253
00257 bool isSender() const
00258 { return activeSender; }
00259
00260 uint32 getID() const
00261 { return SSRC; }
00262
00270 inline Participant*
00271 getParticipant() const
00272 { return participant; }
00273
00274 tpport_t getDataTransportPort() const
00275 { return dataTransportPort; }
00276
00277 tpport_t getControlTransportPort() const
00278 { return controlTransportPort; }
00279
00280 const InetAddress& getNetworkAddress() const
00281 { return networkAddress; }
00282
00283 protected:
00287 SyncSource(const SyncSource& source);
00288
00289 SyncSource&
00290 operator=(const SyncSource& source);
00291
00292 private:
00293 friend class SyncSourceHandler;
00294
00295 inline void
00296 setState(State st)
00297 { state = st; }
00298
00302 inline void
00303 setSender(bool active)
00304 { activeSender = active; }
00305
00306 inline void
00307 setParticipant(Participant& p)
00308 { participant = &p; }
00309
00310 void setDataTransportPort(tpport_t p)
00311 { dataTransportPort = p; }
00312
00313 void setControlTransportPort(tpport_t p)
00314 { controlTransportPort = p; }
00315
00316 void setNetworkAddress(InetAddress addr)
00317 { networkAddress = addr; }
00318
00319 inline void
00320 setLink(void *l)
00321 { link = l; }
00322
00323 void *getLink() const
00324 { return link; }
00325
00326
00327 State state;
00328
00329 uint32 SSRC;
00330
00331 bool activeSender;
00332
00333 Participant* participant;
00334
00335
00336
00337 InetAddress networkAddress;
00338 tpport_t dataTransportPort;
00339 tpport_t controlTransportPort;
00340
00341
00342
00343
00344 void* link;
00345 };
00346
00367 class __EXPORT RTPApplication : private SDESItemsHolder
00368 {
00369 private:
00370 struct ParticipantLink;
00371
00372 public:
00380 RTPApplication(const std::string& cname);
00381
00382 ~RTPApplication();
00383
00384 inline void
00385 setSDESItem(SDESItemType item, const std::string& val)
00386 { SDESItemsHolder::setItem(item,val); }
00387
00388 inline void
00389 setPRIVPrefix(const std::string& val)
00390 { SDESItemsHolder::setPRIVPrefix(val); }
00391
00392 const std::string&
00393 getSDESItem(SDESItemType item) const
00394 { return SDESItemsHolder::getItem(item); }
00395
00396 inline const std::string&
00397 getPRIVPrefix() const
00398 { return SDESItemsHolder::getPRIVPrefix(); }
00399
00404 class ParticipantsIterator
00405 {
00406 public:
00407 typedef std::forward_iterator_tag iterator_category;
00408 typedef Participant value_type;
00409 typedef ptrdiff_t difference_type;
00410 typedef const Participant* pointer;
00411 typedef const Participant& reference;
00412
00413 ParticipantsIterator(ParticipantLink* p = NULL) :
00414 link(p)
00415 { }
00416
00417 ParticipantsIterator(const ParticipantsIterator& pi) :
00418 link(pi.link)
00419 { }
00420
00421 reference operator*() const
00422 { return *(link->getParticipant()); }
00423
00424 pointer operator->() const
00425 { return link->getParticipant(); }
00426
00427 ParticipantsIterator& operator++() {
00428 link = link->getNext();
00429 return *this;
00430 }
00431
00432 ParticipantsIterator operator++(int) {
00433 ParticipantsIterator result(*this);
00434 ++(*this);
00435 return result;
00436 }
00437 friend bool operator==(const ParticipantsIterator& l,
00438 const ParticipantsIterator& r)
00439 { return l.link == r.link; }
00440
00441 friend bool operator!=(const ParticipantsIterator& l,
00442 const ParticipantsIterator& r)
00443 { return l.link != r.link; }
00444 private:
00445 ParticipantLink *link;
00446 };
00447
00448 ParticipantsIterator begin()
00449 { return ParticipantsIterator(firstPart); }
00450
00451 ParticipantsIterator end()
00452 { return ParticipantsIterator(NULL); }
00453
00454 const Participant*
00455 getParticipant(const std::string& cname) const;
00456
00457 private:
00458 friend class ApplicationHandler;
00459
00460 struct ParticipantLink {
00461 ParticipantLink(Participant& p,
00462 ParticipantLink* l) :
00463 participant(&p), next(l)
00464 { }
00465 inline ~ParticipantLink() { delete participant; }
00466 inline Participant* getParticipant() { return participant; }
00467 inline ParticipantLink* getPrev() { return prev; }
00468 inline ParticipantLink* getNext() { return next; }
00469 inline void setPrev(ParticipantLink* l) { prev = l; }
00470 inline void setNext(ParticipantLink* l) { next = l; }
00471 Participant* participant;
00472 ParticipantLink* next, *prev;
00473 };
00474
00475 void
00476 addParticipant(Participant& part);
00477
00478 void
00479 removeParticipant(ParticipantLink* part);
00480
00485 void
00486 findCNAME();
00487
00489 static const size_t defaultParticipantsNum;
00490 Participant** participants;
00492 ParticipantLink* firstPart, * lastPart;
00493 };
00494
00504 __EXPORT RTPApplication& defaultApplication();
00505
00507
00508 #ifdef CCXX_NAMESPACES
00509 }
00510 #endif
00511
00512 #endif //CCXX_RTP_SOURCES_H_
00513