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 NAMESPACE_COMMONCPP
00051
00065 class __EXPORT SDESItemsHolder
00066 {
00067 public:
00068 const std::string&
00069 getItem(SDESItemType type) const;
00070
00071 inline const std::string&
00072 getPRIVPrefix() const
00073 { return sdesItems[SDESItemTypeEND]; }
00074
00075 void
00076 setItem(SDESItemType item, const std::string& val);
00077
00078 inline void
00079 setPRIVPrefix(const std::string& val)
00080 { sdesItems[SDESItemTypeEND] = val; }
00081
00082 protected:
00083 SDESItemsHolder()
00084 { }
00085
00086 inline virtual ~SDESItemsHolder()
00087 { }
00088
00089 private:
00090
00091
00092
00093
00094 std::string sdesItems[SDESItemTypeLast + 1];
00095 };
00096
00125 class __EXPORT Participant : private SDESItemsHolder
00126 {
00127 public:
00140 const std::string&
00141 getSDESItem(SDESItemType type) const
00142 { return SDESItemsHolder::getItem(type); }
00143
00151 inline const std::string&
00152 getPRIVPrefix() const
00153 { return SDESItemsHolder::getPRIVPrefix(); }
00154
00160 Participant(const std::string& cname);
00161
00162 ~Participant();
00163
00164 private:
00165 friend class ParticipantHandler;
00166
00170 inline void
00171 setSDESItem(SDESItemType item, const std::string& val)
00172 { SDESItemsHolder::setItem(item,val); }
00173
00177 inline void
00178 setPRIVPrefix(const std::string val)
00179 { SDESItemsHolder::setPRIVPrefix(val); }
00180 };
00181
00193 class __EXPORT SyncSource
00194 {
00195 public:
00226 typedef enum {
00227 stateUnknown,
00228 statePrevalid,
00229
00230
00231 stateActive,
00232
00233 stateInactive,
00234
00235
00236 stateLeaving
00237
00238 } State;
00239
00244 SyncSource(uint32 ssrc);
00245
00246 ~SyncSource();
00247
00248 State
00249 getState() const
00250 { return state; }
00251
00255 bool isSender() const
00256 { return activeSender; }
00257
00258 uint32 getID() const
00259 { return SSRC; }
00260
00268 inline Participant*
00269 getParticipant() const
00270 { return participant; }
00271
00272 tpport_t getDataTransportPort() const
00273 { return dataTransportPort; }
00274
00275 tpport_t getControlTransportPort() const
00276 { return controlTransportPort; }
00277
00278 const InetAddress& getNetworkAddress() const
00279 { return networkAddress; }
00280
00281 protected:
00285 SyncSource(const SyncSource& source);
00286
00287 SyncSource&
00288 operator=(const SyncSource& source);
00289
00290 private:
00291 friend class SyncSourceHandler;
00292
00293 inline void
00294 setState(State st)
00295 { state = st; }
00296
00300 inline void
00301 setSender(bool active)
00302 { activeSender = active; }
00303
00304 inline void
00305 setParticipant(Participant& p)
00306 { participant = &p; }
00307
00308 void setDataTransportPort(tpport_t p)
00309 { dataTransportPort = p; }
00310
00311 void setControlTransportPort(tpport_t p)
00312 { controlTransportPort = p; }
00313
00314 void setNetworkAddress(InetAddress addr)
00315 { networkAddress = addr; }
00316
00317 inline void
00318 setLink(void *l)
00319 { link = l; }
00320
00321 void *getLink() const
00322 { return link; }
00323
00324
00325 State state;
00326
00327 uint32 SSRC;
00328
00329 bool activeSender;
00330
00331 Participant* participant;
00332
00333
00334
00335 InetAddress networkAddress;
00336 tpport_t dataTransportPort;
00337 tpport_t controlTransportPort;
00338
00339
00340
00341
00342 void* link;
00343 };
00344
00365 class __EXPORT RTPApplication : private SDESItemsHolder
00366 {
00367 private:
00368 struct ParticipantLink;
00369
00370 public:
00378 RTPApplication(const std::string& cname);
00379
00380 ~RTPApplication();
00381
00382 inline void
00383 setSDESItem(SDESItemType item, const std::string& val)
00384 { SDESItemsHolder::setItem(item,val); }
00385
00386 inline void
00387 setPRIVPrefix(const std::string& val)
00388 { SDESItemsHolder::setPRIVPrefix(val); }
00389
00390 const std::string&
00391 getSDESItem(SDESItemType item) const
00392 { return SDESItemsHolder::getItem(item); }
00393
00394 inline const std::string&
00395 getPRIVPrefix() const
00396 { return SDESItemsHolder::getPRIVPrefix(); }
00397
00402 class ParticipantsIterator
00403 {
00404 public:
00405 typedef std::forward_iterator_tag iterator_category;
00406 typedef Participant value_type;
00407 typedef std::ptrdiff_t difference_type;
00408 typedef const Participant* pointer;
00409 typedef const Participant& reference;
00410
00411 ParticipantsIterator(ParticipantLink* p = NULL) :
00412 link(p)
00413 { }
00414
00415 ParticipantsIterator(const ParticipantsIterator& pi) :
00416 link(pi.link)
00417 { }
00418
00419 reference operator*() const
00420 { return *(link->getParticipant()); }
00421
00422 pointer operator->() const
00423 { return link->getParticipant(); }
00424
00425 ParticipantsIterator& operator++() {
00426 link = link->getNext();
00427 return *this;
00428 }
00429
00430 ParticipantsIterator operator++(int) {
00431 ParticipantsIterator result(*this);
00432 ++(*this);
00433 return result;
00434 }
00435 friend bool operator==(const ParticipantsIterator& l,
00436 const ParticipantsIterator& r)
00437 { return l.link == r.link; }
00438
00439 friend bool operator!=(const ParticipantsIterator& l,
00440 const ParticipantsIterator& r)
00441 { return l.link != r.link; }
00442 private:
00443 ParticipantLink *link;
00444 };
00445
00446 ParticipantsIterator begin()
00447 { return ParticipantsIterator(firstPart); }
00448
00449 ParticipantsIterator end()
00450 { return ParticipantsIterator(NULL); }
00451
00452 const Participant*
00453 getParticipant(const std::string& cname) const;
00454
00455 private:
00456 friend class ApplicationHandler;
00457
00458 struct ParticipantLink {
00459 ParticipantLink(Participant& p,
00460 ParticipantLink* l) :
00461 participant(&p), next(l)
00462 { }
00463 inline ~ParticipantLink() { delete participant; }
00464 inline Participant* getParticipant() { return participant; }
00465 inline ParticipantLink* getPrev() { return prev; }
00466 inline ParticipantLink* getNext() { return next; }
00467 inline void setPrev(ParticipantLink* l) { prev = l; }
00468 inline void setNext(ParticipantLink* l) { next = l; }
00469 Participant* participant;
00470 ParticipantLink* next, *prev;
00471 };
00472
00473 void
00474 addParticipant(Participant& part);
00475
00476 void
00477 removeParticipant(ParticipantLink* part);
00478
00483 void
00484 findCNAME();
00485
00487 static const size_t defaultParticipantsNum;
00488 Participant** participants;
00490 ParticipantLink* firstPart, * lastPart;
00491 };
00492
00502 __EXPORT RTPApplication& defaultApplication();
00503
00505
00506 END_NAMESPACE
00507
00508 #endif //CCXX_RTP_SOURCES_H_
00509