ccRTP
|
00001 // Copyright (C) 2001,2002,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_CQUEUE_H_ 00045 #define CCXX_RTP_CQUEUE_H_ 00046 00047 #include <ccrtp/ioqueue.h> 00048 00049 #ifdef CCXX_NAMESPACES 00050 namespace ost { 00051 #endif 00052 00080 class __EXPORT QueueRTCPManager : public RTPDataQueue, 00081 protected RTCPCompoundHandler 00082 { 00083 public: 00093 RTCPSenderInfo* getMRSenderInfo(SyncSource& src); 00094 00105 RTCPReceiverInfo* getMRReceiverInfo(SyncSource& srcFrom); 00106 00115 void setLeavingDelay(microtimeout_t delay) 00116 { leavingDelay = delay; } 00117 00132 inline void 00133 setEnd2EndDelay(microtimeout_t t) 00134 { end2EndDelay = t; } 00135 00136 inline microtimeout_t 00137 getDefaultEnd2EndDelay() const 00138 { return defaultEnd2EndDelay; } 00139 00140 inline microtimeout_t 00141 getEnd2EndDelay() const 00142 { return end2EndDelay; } 00143 00157 inline void 00158 setSendersControlFraction(float fraction) 00159 { sendControlBwFract = fraction; recvControlBwFract = 1 - fraction;} 00160 00170 void 00171 setMinRTCPInterval(microtimeout_t interval) 00172 { rtcpMinInterval = interval; } 00173 00177 inline uint32 00178 getSendRTCPPacketCount() const 00179 { return ctrlSendCount; } 00180 00181 protected: 00182 QueueRTCPManager(uint32 size = RTPDataQueue::defaultMembersHashSize, 00183 RTPApplication& app = defaultApplication()); 00184 00185 QueueRTCPManager(uint32 ssrc, 00186 uint32 size = RTPDataQueue::defaultMembersHashSize, 00187 RTPApplication& app = defaultApplication()); 00188 00189 virtual 00190 ~QueueRTCPManager(); 00191 00192 const RTPApplication& 00193 getApplication() 00194 { return queueApplication; } 00195 00196 inline void 00197 setControlBandwidth(float fraction) 00198 { controlBwFract = fraction; } 00199 00200 float 00201 getControlBandwidth() const 00202 { return controlBwFract; } 00203 00208 void 00209 controlTransmissionService(); 00210 00215 void 00216 controlReceptionService(); 00217 00230 bool checkSSRCInRTCPPkt(SyncSourceLink& sourceLink, bool is_new, 00231 InetAddress& na, tpport_t tp); 00232 00233 void 00234 endQueueRTCPManager(); 00235 00246 virtual void 00247 onGotSR(SyncSource& source, SendReport& SR, uint8 blocks); 00248 00259 virtual void 00260 onGotRR(SyncSource& source, RecvReport& RR, uint8 blocks); 00261 00266 bool 00267 onGotSDES(SyncSource& source, RTCPPacket& pkt); 00268 00278 virtual bool 00279 onGotSDESChunk(SyncSource& source, SDESChunk& chunk, size_t len); 00280 00290 inline virtual void 00291 onGotAPP(SyncSource&, RTCPCompoundHandler::APPPacket&, 00292 size_t) 00293 { return; } 00294 00295 inline timeval 00296 getRTCPCheckInterval() 00297 { return rtcpCheckInterval; } 00298 00303 uint32 00304 getLastSendPacketCount() const 00305 { return lastSendPacketCount; } 00306 00310 inline void 00311 setPrevMembersNum(uint32 n) 00312 { reconsInfo.rtcpPMembers = n; } 00313 00314 inline uint32 00315 getPrevMembersCount() const 00316 { return reconsInfo.rtcpPMembers; } 00317 00336 size_t 00337 dispatchBYE(const std::string& reason); 00338 00339 size_t 00340 sendControlToDestinations(unsigned char* buffer, size_t len); 00341 00342 private: 00343 QueueRTCPManager(const QueueRTCPManager &o); 00344 00345 QueueRTCPManager& 00346 operator=(const QueueRTCPManager &o); 00347 00353 size_t 00354 dispatchControlPacket(); 00355 00367 void 00368 takeInControlPacket(); 00369 00383 virtual timeval 00384 computeRTCPInterval(); 00385 00393 virtual SDESItemType 00394 scheduleSDESItem(); 00395 00401 inline virtual void 00402 onSSRCCollision(const SyncSource&) 00403 { } 00404 00408 virtual bool 00409 end2EndDelayed(IncomingRTPPktLink& p); 00410 00419 inline virtual void 00420 onGotRRSRExtension(unsigned char*, size_t) 00421 { return; } 00422 00432 inline virtual void 00433 onGotGoodbye(const SyncSource&, const std::string&) 00434 { return; } 00435 00448 bool 00449 getBYE(RTCPPacket &pkt, size_t &pointer, size_t len); 00450 00454 uint8 00455 packReportBlocks(RRBlock* blocks, uint16& len, uint16& available); 00456 00465 void 00466 packSDES(uint16& len); 00467 00479 void 00480 updateAvgRTCPSize(size_t len); 00481 00487 void 00488 reverseReconsideration(); 00489 00490 bool 00491 timerReconsideration(); 00492 00501 void 00502 expireSSRCs(); 00503 00507 void 00508 getOnlyBye(); 00509 00514 void 00515 setSDESItem(Participant* part, SDESItemType type, 00516 const char* const value, size_t len); 00517 00522 void 00523 setPRIVPrefix(Participant* part, const char* const value, size_t len); 00524 00536 inline virtual uint16 00537 networkHeaderSize() 00538 { return 20; } 00539 00551 inline virtual uint16 00552 transportHeaderSize() 00553 { return 8; } 00554 00555 SDESItemType 00556 nextSDESType(SDESItemType t); 00557 00558 virtual size_t 00559 sendControl(const unsigned char* const buffer, size_t len) = 0; 00560 00561 virtual size_t 00562 recvControl(unsigned char* buffer, size_t len, 00563 InetHostAddress& na, tpport_t& tp) = 0; 00564 00565 virtual bool 00566 isPendingControl(microtimeout_t timeout) = 0; 00567 00568 // whether the RTCP service is active 00569 volatile bool controlServiceActive; 00570 float controlBwFract, sendControlBwFract, recvControlBwFract; 00571 // number of RTCP packets sent since the beginning 00572 uint32 ctrlSendCount; 00573 00574 // Network + transport headers size, typically size of IP + 00575 // UDP headers 00576 uint16 lowerHeadersSize; 00577 00578 SDESItemType nextScheduledSDESItem; 00579 static const SDESItemType firstSchedulable; 00580 static const SDESItemType lastSchedulable; 00581 00582 // state for rtcp timing. Its meaning is defined in 00583 // draft-ietf-avt-rtp-new, 6.3. 00584 00585 // Parameters for timer reconsideration algorithm 00586 struct { 00587 timeval rtcpTp, rtcpTc, rtcpTn; 00588 uint32 rtcpPMembers; 00589 } reconsInfo; 00590 bool rtcpWeSent; 00591 uint16 rtcpAvgSize; 00592 bool rtcpInitial; 00593 // last time we checked if there were incoming RTCP packets 00594 timeval rtcpLastCheck; 00595 // interval to check if there are incoming RTCP packets 00596 timeval rtcpCheckInterval; 00597 // next time to check if there are incoming RTCP packets 00598 timeval rtcpNextCheck; 00599 00600 // number of RTP data packets sent at the time of the last 00601 // RTCP packet transmission. 00602 uint32 lastSendPacketCount; 00603 00604 // minimum interval for transmission of RTCP packets. The 00605 // result of computeRTCPInterval will always be >= (times a 00606 // random number between 0.5 and 1.5). 00607 microtimeout_t rtcpMinInterval; 00608 00609 microtimeout_t leavingDelay; 00610 static const microtimeout_t defaultEnd2EndDelay; 00611 // Maximum delay allowed between packet timestamping and 00612 // packet availability for the application. 00613 microtimeout_t end2EndDelay; 00614 // Application this queue is bound to. 00615 RTPApplication& queueApplication; 00616 00617 // an empty RTPData 00618 static const uint16 TIMEOUT_MULTIPLIER; 00619 static const double RECONSIDERATION_COMPENSATION; 00620 }; 00621 00629 class AVPQueue : public QueueRTCPManager 00630 { 00631 public: 00647 inline void 00648 setControlBandwidth(float fraction) 00649 { QueueRTCPManager::setControlBandwidth(fraction); } 00650 00651 float 00652 getControlBandwidth() const 00653 { return QueueRTCPManager::getControlBandwidth(); } 00654 00655 protected: 00656 AVPQueue(uint32 size = RTPDataQueue::defaultMembersHashSize, 00657 RTPApplication& app = defaultApplication()) : 00658 QueueRTCPManager(size,app) 00659 { } 00660 00664 AVPQueue(uint32 ssrc, uint32 size = 00665 RTPDataQueue::defaultMembersHashSize, 00666 RTPApplication& app = defaultApplication()) : 00667 QueueRTCPManager(ssrc,size,app) 00668 { } 00669 inline virtual ~AVPQueue() 00670 { } 00671 }; 00672 // cqueue 00674 00675 #ifdef CCXX_NAMESPACES 00676 } 00677 #endif 00678 00679 #endif //CCXX_RTP_CQUEUE_H_ 00680