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 #include <cstddef> 00050 00051 #ifdef CCXX_NAMESPACES 00052 namespace ost { 00053 #endif 00054 00068 class __EXPORT SDESItemsHolder 00069 { 00070 public: 00071 const std::string& 00072 getItem(SDESItemType type) const; 00073 00074 inline const std::string& 00075 getPRIVPrefix() const 00076 { return sdesItems[SDESItemTypeEND]; } 00077 00078 void 00079 setItem(SDESItemType item, const std::string& val); 00080 00081 inline void 00082 setPRIVPrefix(const std::string& val) 00083 { sdesItems[SDESItemTypeEND] = val; } 00084 00085 protected: 00086 SDESItemsHolder() 00087 { } 00088 00089 inline virtual ~SDESItemsHolder() 00090 { } 00091 00092 private: 00093 // SDES items for a participant. 00094 // sdesItems[0] (== sdesItems[SDESItemTypeEND]) holds the prefix 00095 // value for the PRIV item. The rest of entries hold the 00096 // correponding SDES item value. 00097 std::string sdesItems[SDESItemTypeLast + 1]; 00098 }; 00099 00128 class __EXPORT Participant : private SDESItemsHolder 00129 { 00130 public: 00143 const std::string& 00144 getSDESItem(SDESItemType type) const 00145 { return SDESItemsHolder::getItem(type); } 00146 00154 inline const std::string& 00155 getPRIVPrefix() const 00156 { return SDESItemsHolder::getPRIVPrefix(); } 00157 00163 Participant(const std::string& cname); 00164 00165 ~Participant(); 00166 00167 private: 00168 friend class ParticipantHandler; 00169 00173 inline void 00174 setSDESItem(SDESItemType item, const std::string& val) 00175 { SDESItemsHolder::setItem(item,val); } 00176 00180 inline void 00181 setPRIVPrefix(const std::string val) 00182 { SDESItemsHolder::setPRIVPrefix(val); } 00183 }; 00184 00196 class __EXPORT SyncSource 00197 { 00198 public: 00229 typedef enum { 00230 stateUnknown, 00231 statePrevalid, 00232 00233 00234 stateActive, 00235 00236 stateInactive, 00237 00238 00239 stateLeaving 00240 00241 } State; 00242 00247 SyncSource(uint32 ssrc); 00248 00249 ~SyncSource(); 00250 00251 State 00252 getState() const 00253 { return state; } 00254 00258 bool isSender() const 00259 { return activeSender; } 00260 00261 uint32 getID() const 00262 { return SSRC; } 00263 00271 inline Participant* 00272 getParticipant() const 00273 { return participant; } 00274 00275 tpport_t getDataTransportPort() const 00276 { return dataTransportPort; } 00277 00278 tpport_t getControlTransportPort() const 00279 { return controlTransportPort; } 00280 00281 const InetAddress& getNetworkAddress() const 00282 { return networkAddress; } 00283 00284 protected: 00288 SyncSource(const SyncSource& source); 00289 00290 SyncSource& 00291 operator=(const SyncSource& source); 00292 00293 private: 00294 friend class SyncSourceHandler; 00295 00296 inline void 00297 setState(State st) 00298 { state = st; } 00299 00303 inline void 00304 setSender(bool active) 00305 { activeSender = active; } 00306 00307 inline void 00308 setParticipant(Participant& p) 00309 { participant = &p; } 00310 00311 void setDataTransportPort(tpport_t p) 00312 { dataTransportPort = p; } 00313 00314 void setControlTransportPort(tpport_t p) 00315 { controlTransportPort = p; } 00316 00317 void setNetworkAddress(InetAddress addr) 00318 { networkAddress = addr; } 00319 00320 inline void 00321 setLink(void *l) 00322 { link = l; } 00323 00324 void *getLink() const 00325 { return link; } 00326 00327 // validity state of this source 00328 State state; 00329 // 32-bit SSRC identifier. 00330 uint32 SSRC; 00331 // A valid source not always is active 00332 bool activeSender; 00333 // The corresponding participant. 00334 Participant* participant; 00335 00336 // Network protocol address for data and control connection 00337 // (both are assumed to be the same). 00338 InetAddress networkAddress; 00339 tpport_t dataTransportPort; 00340 tpport_t controlTransportPort; 00341 00342 // Pointer to the SyncSourceLink or similar object in the 00343 // service queue. Saves a lot of searches in the membership 00344 // table. 00345 void* link; 00346 }; 00347 00368 class __EXPORT RTPApplication : private SDESItemsHolder 00369 { 00370 private: 00371 struct ParticipantLink; 00372 00373 public: 00381 RTPApplication(const std::string& cname); 00382 00383 ~RTPApplication(); 00384 00385 inline void 00386 setSDESItem(SDESItemType item, const std::string& val) 00387 { SDESItemsHolder::setItem(item,val); } 00388 00389 inline void 00390 setPRIVPrefix(const std::string& val) 00391 { SDESItemsHolder::setPRIVPrefix(val); } 00392 00393 const std::string& 00394 getSDESItem(SDESItemType item) const 00395 { return SDESItemsHolder::getItem(item); } 00396 00397 inline const std::string& 00398 getPRIVPrefix() const 00399 { return SDESItemsHolder::getPRIVPrefix(); } 00400 00405 class ParticipantsIterator 00406 { 00407 public: 00408 typedef std::forward_iterator_tag iterator_category; 00409 typedef Participant value_type; 00410 typedef ptrdiff_t difference_type; 00411 typedef const Participant* pointer; 00412 typedef const Participant& reference; 00413 00414 ParticipantsIterator(ParticipantLink* p = NULL) : 00415 link(p) 00416 { } 00417 00418 ParticipantsIterator(const ParticipantsIterator& pi) : 00419 link(pi.link) 00420 { } 00421 00422 reference operator*() const 00423 { return *(link->getParticipant()); } 00424 00425 pointer operator->() const 00426 { return link->getParticipant(); } 00427 00428 ParticipantsIterator& operator++() { 00429 link = link->getNext(); 00430 return *this; 00431 } 00432 00433 ParticipantsIterator operator++(int) { 00434 ParticipantsIterator result(*this); 00435 ++(*this); 00436 return result; 00437 } 00438 friend bool operator==(const ParticipantsIterator& l, 00439 const ParticipantsIterator& r) 00440 { return l.link == r.link; } 00441 00442 friend bool operator!=(const ParticipantsIterator& l, 00443 const ParticipantsIterator& r) 00444 { return l.link != r.link; } 00445 private: 00446 ParticipantLink *link; 00447 }; 00448 00449 ParticipantsIterator begin() 00450 { return ParticipantsIterator(firstPart); } 00451 00452 ParticipantsIterator end() 00453 { return ParticipantsIterator(NULL); } 00454 00455 const Participant* 00456 getParticipant(const std::string& cname) const; 00457 00458 private: 00459 friend class ApplicationHandler; 00460 00461 struct ParticipantLink { 00462 ParticipantLink(Participant& p, 00463 ParticipantLink* l) : 00464 participant(&p), next(l) 00465 { } 00466 inline ~ParticipantLink() { delete participant; } 00467 inline Participant* getParticipant() { return participant; } 00468 inline ParticipantLink* getPrev() { return prev; } 00469 inline ParticipantLink* getNext() { return next; } 00470 inline void setPrev(ParticipantLink* l) { prev = l; } 00471 inline void setNext(ParticipantLink* l) { next = l; } 00472 Participant* participant; 00473 ParticipantLink* next, *prev; 00474 }; 00475 00476 void 00477 addParticipant(Participant& part); 00478 00479 void 00480 removeParticipant(ParticipantLink* part); 00481 00486 void 00487 findCNAME(); 00488 00490 static const size_t defaultParticipantsNum; 00491 Participant** participants; 00493 ParticipantLink* firstPart, * lastPart; 00494 }; 00495 00505 __EXPORT RTPApplication& defaultApplication(); 00506 // sources 00508 00509 #ifdef CCXX_NAMESPACES 00510 } 00511 #endif 00512 00513 #endif //CCXX_RTP_SOURCES_H_ 00514