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_CQUEUE_H_ 00044 #define CCXX_RTP_CQUEUE_H_ 00045 00046 #include <ccrtp/ioqueue.h> 00047 #include <ccrtp/CryptoContextCtrl.h> 00048 #include <list> 00049 00050 NAMESPACE_COMMONCPP 00051 00079 class __EXPORT QueueRTCPManager : public RTPDataQueue, 00080 protected RTCPCompoundHandler 00081 { 00082 public: 00092 RTCPSenderInfo* getMRSenderInfo(SyncSource& src); 00093 00104 RTCPReceiverInfo* getMRReceiverInfo(SyncSource& srcFrom); 00105 00114 void setLeavingDelay(microtimeout_t delay) 00115 { leavingDelay = delay; } 00116 00131 inline void 00132 setEnd2EndDelay(microtimeout_t t) 00133 { end2EndDelay = t; } 00134 00135 inline microtimeout_t 00136 getDefaultEnd2EndDelay() const 00137 { return defaultEnd2EndDelay; } 00138 00139 inline microtimeout_t 00140 getEnd2EndDelay() const 00141 { return end2EndDelay; } 00142 00156 inline void 00157 setSendersControlFraction(float fraction) 00158 { sendControlBwFract = fraction; recvControlBwFract = 1 - fraction;} 00159 00169 void 00170 setMinRTCPInterval(microtimeout_t interval) 00171 { rtcpMinInterval = interval; } 00172 00176 inline uint32 00177 getSendRTCPPacketCount() const 00178 { return ctrlSendCount; } 00179 00188 void 00189 setOutQueueCryptoContextCtrl(CryptoContextCtrl* cc); 00190 00199 void 00200 removeOutQueueCryptoContextCtrl(CryptoContextCtrl* cc); 00201 00209 CryptoContextCtrl* 00210 getOutQueueCryptoContextCtrl(uint32 ssrc); 00211 00212 00221 void 00222 setInQueueCryptoContextCtrl(CryptoContextCtrl* cc); 00223 00234 void 00235 removeInQueueCryptoContextCtrl(CryptoContextCtrl* cc); 00236 00244 CryptoContextCtrl* 00245 getInQueueCryptoContextCtrl(uint32 ssrc); 00246 00247 protected: 00248 QueueRTCPManager(uint32 size = RTPDataQueue::defaultMembersHashSize, 00249 RTPApplication& app = defaultApplication()); 00250 00251 QueueRTCPManager(uint32 ssrc, 00252 uint32 size = RTPDataQueue::defaultMembersHashSize, 00253 RTPApplication& app = defaultApplication()); 00254 00255 virtual 00256 ~QueueRTCPManager(); 00257 00258 const RTPApplication& 00259 getApplication() 00260 { return queueApplication; } 00261 00262 inline void 00263 setControlBandwidth(float fraction) 00264 { controlBwFract = fraction; } 00265 00266 float 00267 getControlBandwidth() const 00268 { return controlBwFract; } 00269 00274 void 00275 controlTransmissionService(); 00276 00281 void 00282 controlReceptionService(); 00283 00296 bool checkSSRCInRTCPPkt(SyncSourceLink& sourceLink, bool is_new, 00297 InetAddress& na, tpport_t tp); 00298 00299 void 00300 endQueueRTCPManager(); 00301 00312 virtual void 00313 onGotSR(SyncSource& source, SendReport& SR, uint8 blocks); 00314 00325 virtual void 00326 onGotRR(SyncSource& source, RecvReport& RR, uint8 blocks); 00327 00332 bool 00333 onGotSDES(SyncSource& source, RTCPPacket& pkt); 00334 00344 virtual bool 00345 onGotSDESChunk(SyncSource& source, SDESChunk& chunk, size_t len); 00346 00356 inline virtual void 00357 onGotAPP(SyncSource&, RTCPCompoundHandler::APPPacket&, 00358 size_t) 00359 { return; } 00360 00361 inline timeval 00362 getRTCPCheckInterval() 00363 { return rtcpCheckInterval; } 00364 00369 uint32 00370 getLastSendPacketCount() const 00371 { return lastSendPacketCount; } 00372 00376 inline void 00377 setPrevMembersNum(uint32 n) 00378 { reconsInfo.rtcpPMembers = n; } 00379 00380 inline uint32 00381 getPrevMembersCount() const 00382 { return reconsInfo.rtcpPMembers; } 00383 00402 size_t 00403 dispatchBYE(const std::string& reason); 00404 00405 size_t 00406 sendControlToDestinations(unsigned char* buffer, size_t len); 00407 00408 private: 00409 QueueRTCPManager(const QueueRTCPManager &o); 00410 00411 QueueRTCPManager& 00412 operator=(const QueueRTCPManager &o); 00413 00419 size_t 00420 dispatchControlPacket(); 00421 00433 void 00434 takeInControlPacket(); 00435 00449 virtual timeval 00450 computeRTCPInterval(); 00451 00459 virtual SDESItemType 00460 scheduleSDESItem(); 00461 00467 inline virtual void 00468 onSSRCCollision(const SyncSource&) 00469 { } 00470 00474 virtual bool 00475 end2EndDelayed(IncomingRTPPktLink& p); 00476 00485 inline virtual void 00486 onGotRRSRExtension(unsigned char*, size_t) 00487 { return; } 00488 00498 inline virtual void 00499 onGotGoodbye(const SyncSource&, const std::string&) 00500 { return; } 00501 00514 bool 00515 getBYE(RTCPPacket &pkt, size_t &pointer, size_t len); 00516 00520 uint8 00521 packReportBlocks(RRBlock* blocks, uint16& len, uint16& available); 00522 00531 void 00532 packSDES(uint16& len); 00533 00545 void 00546 updateAvgRTCPSize(size_t len); 00547 00553 void 00554 reverseReconsideration(); 00555 00556 bool 00557 timerReconsideration(); 00558 00567 void 00568 expireSSRCs(); 00569 00573 void 00574 getOnlyBye(); 00575 00580 void 00581 setSDESItem(Participant* part, SDESItemType type, 00582 const char* const value, size_t len); 00583 00588 void 00589 setPRIVPrefix(Participant* part, const char* const value, size_t len); 00590 00602 inline virtual uint16 00603 networkHeaderSize() 00604 { return 20; } 00605 00617 inline virtual uint16 00618 transportHeaderSize() 00619 { return 8; } 00620 00621 00622 int32 protect(uint8* pkt, size_t len, CryptoContextCtrl* cc); 00623 int32 unprotect(uint8* pkt, size_t len, CryptoContextCtrl* cc); 00624 00625 00626 SDESItemType 00627 nextSDESType(SDESItemType t); 00628 00629 virtual size_t 00630 sendControl(const unsigned char* const buffer, size_t len) = 0; 00631 00632 virtual size_t 00633 recvControl(unsigned char* buffer, size_t len, 00634 InetHostAddress& na, tpport_t& tp) = 0; 00635 00636 virtual bool 00637 isPendingControl(microtimeout_t timeout) = 0; 00638 00639 // whether the RTCP service is active 00640 volatile bool controlServiceActive; 00641 float controlBwFract, sendControlBwFract, recvControlBwFract; 00642 // number of RTCP packets sent since the beginning 00643 uint32 ctrlSendCount; 00644 00645 // Network + transport headers size, typically size of IP + 00646 // UDP headers 00647 uint16 lowerHeadersSize; 00648 00649 SDESItemType nextScheduledSDESItem; 00650 static const SDESItemType firstSchedulable; 00651 static const SDESItemType lastSchedulable; 00652 00653 // state for rtcp timing. Its meaning is defined in 00654 // draft-ietf-avt-rtp-new, 6.3. 00655 00656 // Parameters for timer reconsideration algorithm 00657 struct { 00658 timeval rtcpTp, rtcpTc, rtcpTn; 00659 uint32 rtcpPMembers; 00660 } reconsInfo; 00661 bool rtcpWeSent; 00662 uint16 rtcpAvgSize; 00663 bool rtcpInitial; 00664 // last time we checked if there were incoming RTCP packets 00665 timeval rtcpLastCheck; 00666 // interval to check if there are incoming RTCP packets 00667 timeval rtcpCheckInterval; 00668 // next time to check if there are incoming RTCP packets 00669 timeval rtcpNextCheck; 00670 00671 // number of RTP data packets sent at the time of the last 00672 // RTCP packet transmission. 00673 uint32 lastSendPacketCount; 00674 00675 // minimum interval for transmission of RTCP packets. The 00676 // result of computeRTCPInterval will always be >= (times a 00677 // random number between 0.5 and 1.5). 00678 microtimeout_t rtcpMinInterval; 00679 00680 microtimeout_t leavingDelay; 00681 static const microtimeout_t defaultEnd2EndDelay; 00682 // Maximum delay allowed between packet timestamping and 00683 // packet availability for the application. 00684 microtimeout_t end2EndDelay; 00685 // Application this queue is bound to. 00686 RTPApplication& queueApplication; 00687 00688 // an empty RTPData 00689 static const uint16 TIMEOUT_MULTIPLIER; 00690 static const double RECONSIDERATION_COMPENSATION; 00691 00692 mutable Mutex outCryptoMutex; 00693 std::list<CryptoContextCtrl *> outCryptoContexts; 00694 uint32 srtcpIndex; 00695 00696 mutable Mutex inCryptoMutex; 00697 std::list<CryptoContextCtrl *> inCryptoContexts; 00698 00699 }; 00700 00708 class __EXPORT AVPQueue : public QueueRTCPManager 00709 { 00710 public: 00726 inline void 00727 setControlBandwidth(float fraction) 00728 { QueueRTCPManager::setControlBandwidth(fraction); } 00729 00730 float 00731 getControlBandwidth() const 00732 { return QueueRTCPManager::getControlBandwidth(); } 00733 00734 protected: 00735 AVPQueue(uint32 size = RTPDataQueue::defaultMembersHashSize, 00736 RTPApplication& app = defaultApplication()) : 00737 QueueRTCPManager(size,app) 00738 { } 00739 00743 AVPQueue(uint32 ssrc, uint32 size = 00744 RTPDataQueue::defaultMembersHashSize, 00745 RTPApplication& app = defaultApplication()) : 00746 QueueRTCPManager(ssrc,size,app) 00747 { } 00748 inline virtual ~AVPQueue() 00749 { } 00750 }; 00751 // cqueue 00753 00754 END_NAMESPACE 00755 00756 #endif //CCXX_RTP_CQUEUE_H_ 00757