00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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
00640 volatile bool controlServiceActive;
00641 float controlBwFract, sendControlBwFract, recvControlBwFract;
00642
00643 uint32 ctrlSendCount;
00644
00645
00646
00647 uint16 lowerHeadersSize;
00648
00649 SDESItemType nextScheduledSDESItem;
00650 static const SDESItemType firstSchedulable;
00651 static const SDESItemType lastSchedulable;
00652
00653
00654
00655
00656
00657 struct {
00658 timeval rtcpTp, rtcpTc, rtcpTn;
00659 uint32 rtcpPMembers;
00660 } reconsInfo;
00661 bool rtcpWeSent;
00662 uint16 rtcpAvgSize;
00663 bool rtcpInitial;
00664
00665 timeval rtcpLastCheck;
00666
00667 timeval rtcpCheckInterval;
00668
00669 timeval rtcpNextCheck;
00670
00671
00672
00673 uint32 lastSendPacketCount;
00674
00675
00676
00677
00678 microtimeout_t rtcpMinInterval;
00679
00680 microtimeout_t leavingDelay;
00681 static const microtimeout_t defaultEnd2EndDelay;
00682
00683
00684 microtimeout_t end2EndDelay;
00685
00686 RTPApplication& queueApplication;
00687
00688
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
00753
00754 END_NAMESPACE
00755
00756 #endif //CCXX_RTP_CQUEUE_H_
00757