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