ccRTP
|
00001 // Copyright (C) 2001-2015 Federico Montesino Pouzols <fedemp@altern.org>. 00002 // 00003 // This program is free software; you can redistribute it and/or modify 00004 // it under the terms of the GNU General Public License as published by 00005 // the Free Software Foundation; either version 2 of the License, or 00006 // (at your option) any later version. 00007 // 00008 // This program is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 // GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU Lesser General Public License 00014 // along with GNU ccRTP. If not, see <http://www.gnu.org/licenses/>. 00015 // 00016 // As a special exception, you may use this file as part of a free software 00017 // library without restriction. Specifically, if other files instantiate 00018 // templates or use macros or inline functions from this file, or you compile 00019 // this file and link it with other files to produce an executable, this 00020 // file does not by itself cause the resulting executable to be covered by 00021 // the GNU General Public License. This exception does not however 00022 // invalidate any other reasons why the executable file might be covered by 00023 // the GNU General Public License. 00024 // 00025 // This exception applies only to the code released under the name GNU 00026 // ccRTP. If you copy code from other releases into a copy of GNU 00027 // ccRTP, as the General Public License permits, the exception does 00028 // not apply to the code that you add in this way. To avoid misleading 00029 // anyone as to the status of such modified files, you must delete 00030 // this exception notice from them. 00031 // 00032 // If you write modifications of your own for GNU ccRTP, it is your choice 00033 // whether to permit this exception to apply to your modifications. 00034 // If you do not wish that, delete this exception notice. 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 // SDES items for a participant. 00090 // sdesItems[0] (== sdesItems[SDESItemTypeEND]) holds the prefix 00091 // value for the PRIV item. The rest of entries hold the 00092 // correponding SDES item value. 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 // validity state of this source 00324 State state; 00325 // 32-bit SSRC identifier. 00326 uint32 SSRC; 00327 // A valid source not always is active 00328 bool activeSender; 00329 // The corresponding participant. 00330 Participant* participant; 00331 00332 // Network protocol address for data and control connection 00333 // (both are assumed to be the same). 00334 InetAddress networkAddress; 00335 tpport_t dataTransportPort; 00336 tpport_t controlTransportPort; 00337 00338 // Pointer to the SyncSourceLink or similar object in the 00339 // service queue. Saves a lot of searches in the membership 00340 // table. 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 // sources 00504 00505 END_NAMESPACE 00506 00507 #endif //CCXX_RTP_SOURCES_H_ 00508