ccRTP
|
00001 // Copyright (C) 2001,2002,2003,2004 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 General Public License 00014 // along with this program; if not, write to the Free Software 00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00016 // 00017 // As a special exception, you may use this file as part of a free software 00018 // library without restriction. Specifically, if other files instantiate 00019 // templates or use macros or inline functions from this file, or you compile 00020 // this file and link it with other files to produce an executable, this 00021 // file does not by itself cause the resulting executable to be covered by 00022 // the GNU General Public License. This exception does not however 00023 // invalidate any other reasons why the executable file might be covered by 00024 // the GNU General Public License. 00025 // 00026 // This exception applies only to the code released under the name GNU 00027 // ccRTP. If you copy code from other releases into a copy of GNU 00028 // ccRTP, as the General Public License permits, the exception does 00029 // not apply to the code that you add in this way. To avoid misleading 00030 // anyone as to the status of such modified files, you must delete 00031 // this exception notice from them. 00032 // 00033 // If you write modifications of your own for GNU ccRTP, it is your choice 00034 // whether to permit this exception to apply to your modifications. 00035 // If you do not wish that, delete this exception notice. 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 // SDES items for a participant. 00091 // sdesItems[0] (== sdesItems[SDESItemTypeEND]) holds the prefix 00092 // value for the PRIV item. The rest of entries hold the 00093 // correponding SDES item value. 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 // validity state of this source 00325 State state; 00326 // 32-bit SSRC identifier. 00327 uint32 SSRC; 00328 // A valid source not always is active 00329 bool activeSender; 00330 // The corresponding participant. 00331 Participant* participant; 00332 00333 // Network protocol address for data and control connection 00334 // (both are assumed to be the same). 00335 InetAddress networkAddress; 00336 tpport_t dataTransportPort; 00337 tpport_t controlTransportPort; 00338 00339 // Pointer to the SyncSourceLink or similar object in the 00340 // service queue. Saves a lot of searches in the membership 00341 // table. 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 // sources 00505 00506 END_NAMESPACE 00507 00508 #endif //CCXX_RTP_SOURCES_H_ 00509