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
00037
00044 #ifndef CCXX_RTP_CQUEUE_H_
00045 #define CCXX_RTP_CQUEUE_H_
00046
00047 #include <ccrtp/ioqueue.h>
00048 #include <ccrtp/CryptoContextCtrl.h>
00049 #include <list>
00050
00051 NAMESPACE_COMMONCPP
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
00189 void
00190 setOutQueueCryptoContextCtrl(CryptoContextCtrl* cc);
00191
00200 void
00201 removeOutQueueCryptoContextCtrl(CryptoContextCtrl* cc);
00202
00210 CryptoContextCtrl*
00211 getOutQueueCryptoContextCtrl(uint32 ssrc);
00212
00213
00222 void
00223 setInQueueCryptoContextCtrl(CryptoContextCtrl* cc);
00224
00235 void
00236 removeInQueueCryptoContextCtrl(CryptoContextCtrl* cc);
00237
00245 CryptoContextCtrl*
00246 getInQueueCryptoContextCtrl(uint32 ssrc);
00247
00248 protected:
00249 QueueRTCPManager(uint32 size = RTPDataQueue::defaultMembersHashSize,
00250 RTPApplication& app = defaultApplication());
00251
00252 QueueRTCPManager(uint32 ssrc,
00253 uint32 size = RTPDataQueue::defaultMembersHashSize,
00254 RTPApplication& app = defaultApplication());
00255
00256 virtual
00257 ~QueueRTCPManager();
00258
00259 const RTPApplication&
00260 getApplication()
00261 { return queueApplication; }
00262
00263 inline void
00264 setControlBandwidth(float fraction)
00265 { controlBwFract = fraction; }
00266
00267 float
00268 getControlBandwidth() const
00269 { return controlBwFract; }
00270
00275 void
00276 controlTransmissionService();
00277
00282 void
00283 controlReceptionService();
00284
00297 bool checkSSRCInRTCPPkt(SyncSourceLink& sourceLink, bool is_new,
00298 InetAddress& na, tpport_t tp);
00299
00300 void
00301 endQueueRTCPManager();
00302
00313 virtual void
00314 onGotSR(SyncSource& source, SendReport& SR, uint8 blocks);
00315
00326 virtual void
00327 onGotRR(SyncSource& source, RecvReport& RR, uint8 blocks);
00328
00333 bool
00334 onGotSDES(SyncSource& source, RTCPPacket& pkt);
00335
00345 virtual bool
00346 onGotSDESChunk(SyncSource& source, SDESChunk& chunk, size_t len);
00347
00357 inline virtual void
00358 onGotAPP(SyncSource&, RTCPCompoundHandler::APPPacket&,
00359 size_t)
00360 { return; }
00361
00362 inline timeval
00363 getRTCPCheckInterval()
00364 { return rtcpCheckInterval; }
00365
00370 uint32
00371 getLastSendPacketCount() const
00372 { return lastSendPacketCount; }
00373
00377 inline void
00378 setPrevMembersNum(uint32 n)
00379 { reconsInfo.rtcpPMembers = n; }
00380
00381 inline uint32
00382 getPrevMembersCount() const
00383 { return reconsInfo.rtcpPMembers; }
00384
00403 size_t
00404 dispatchBYE(const std::string& reason);
00405
00406 size_t
00407 sendControlToDestinations(unsigned char* buffer, size_t len);
00408
00409 private:
00410 QueueRTCPManager(const QueueRTCPManager &o);
00411
00412 QueueRTCPManager&
00413 operator=(const QueueRTCPManager &o);
00414
00420 size_t
00421 dispatchControlPacket();
00422
00434 void
00435 takeInControlPacket();
00436
00450 virtual timeval
00451 computeRTCPInterval();
00452
00460 virtual SDESItemType
00461 scheduleSDESItem();
00462
00468 inline virtual void
00469 onSSRCCollision(const SyncSource&)
00470 { }
00471
00475 virtual bool
00476 end2EndDelayed(IncomingRTPPktLink& p);
00477
00486 inline virtual void
00487 onGotRRSRExtension(unsigned char*, size_t)
00488 { return; }
00489
00499 inline virtual void
00500 onGotGoodbye(const SyncSource&, const std::string&)
00501 { return; }
00502
00515 bool
00516 getBYE(RTCPPacket &pkt, size_t &pointer, size_t len);
00517
00521 uint8
00522 packReportBlocks(RRBlock* blocks, uint16& len, uint16& available);
00523
00532 void
00533 packSDES(uint16& len);
00534
00546 void
00547 updateAvgRTCPSize(size_t len);
00548
00554 void
00555 reverseReconsideration();
00556
00557 bool
00558 timerReconsideration();
00559
00568 void
00569 expireSSRCs();
00570
00574 void
00575 getOnlyBye();
00576
00581 void
00582 setSDESItem(Participant* part, SDESItemType type,
00583 const char* const value, size_t len);
00584
00589 void
00590 setPRIVPrefix(Participant* part, const char* const value, size_t len);
00591
00603 inline virtual uint16
00604 networkHeaderSize()
00605 { return 20; }
00606
00618 inline virtual uint16
00619 transportHeaderSize()
00620 { return 8; }
00621
00622
00623 int32 protect(uint8* pkt, size_t len, CryptoContextCtrl* cc);
00624 int32 unprotect(uint8* pkt, size_t len, CryptoContextCtrl* cc);
00625
00626
00627 SDESItemType
00628 nextSDESType(SDESItemType t);
00629
00630 virtual size_t
00631 sendControl(const unsigned char* const buffer, size_t len) = 0;
00632
00633 virtual size_t
00634 recvControl(unsigned char* buffer, size_t len,
00635 InetHostAddress& na, tpport_t& tp) = 0;
00636
00637 virtual bool
00638 isPendingControl(microtimeout_t timeout) = 0;
00639
00640
00641 volatile bool controlServiceActive;
00642 float controlBwFract, sendControlBwFract, recvControlBwFract;
00643
00644 uint32 ctrlSendCount;
00645
00646
00647
00648 uint16 lowerHeadersSize;
00649
00650 SDESItemType nextScheduledSDESItem;
00651 static const SDESItemType firstSchedulable;
00652 static const SDESItemType lastSchedulable;
00653
00654
00655
00656
00657
00658 struct {
00659 timeval rtcpTp, rtcpTc, rtcpTn;
00660 uint32 rtcpPMembers;
00661 } reconsInfo;
00662 bool rtcpWeSent;
00663 uint16 rtcpAvgSize;
00664 bool rtcpInitial;
00665
00666 timeval rtcpLastCheck;
00667
00668 timeval rtcpCheckInterval;
00669
00670 timeval rtcpNextCheck;
00671
00672
00673
00674 uint32 lastSendPacketCount;
00675
00676
00677
00678
00679 microtimeout_t rtcpMinInterval;
00680
00681 microtimeout_t leavingDelay;
00682 static const microtimeout_t defaultEnd2EndDelay;
00683
00684
00685 microtimeout_t end2EndDelay;
00686
00687 RTPApplication& queueApplication;
00688
00689
00690 static const uint16 TIMEOUT_MULTIPLIER;
00691 static const double RECONSIDERATION_COMPENSATION;
00692
00693 mutable Mutex outCryptoMutex;
00694 std::list<CryptoContextCtrl *> outCryptoContexts;
00695 uint32 srtcpIndex;
00696
00697 mutable Mutex inCryptoMutex;
00698 std::list<CryptoContextCtrl *> inCryptoContexts;
00699
00700 };
00701
00709 class __EXPORT AVPQueue : public QueueRTCPManager
00710 {
00711 public:
00727 inline void
00728 setControlBandwidth(float fraction)
00729 { QueueRTCPManager::setControlBandwidth(fraction); }
00730
00731 float
00732 getControlBandwidth() const
00733 { return QueueRTCPManager::getControlBandwidth(); }
00734
00735 protected:
00736 AVPQueue(uint32 size = RTPDataQueue::defaultMembersHashSize,
00737 RTPApplication& app = defaultApplication()) :
00738 QueueRTCPManager(size,app)
00739 { }
00740
00744 AVPQueue(uint32 ssrc, uint32 size =
00745 RTPDataQueue::defaultMembersHashSize,
00746 RTPApplication& app = defaultApplication()) :
00747 QueueRTCPManager(ssrc,size,app)
00748 { }
00749 inline virtual ~AVPQueue()
00750 { }
00751 };
00752
00754
00755 END_NAMESPACE
00756
00757 #endif //CCXX_RTP_CQUEUE_H_
00758