ccRTP 2.1.2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cqueue.h
Go to the documentation of this file.
1 // Copyright (C) 2001-2015 Federico Montesino Pouzols <fedemp@altern.org>.
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public License
14 // along with GNU ccRTP. If not, see <http://www.gnu.org/licenses/>.
15 //
16 // As a special exception, you may use this file as part of a free software
17 // library without restriction. Specifically, if other files instantiate
18 // templates or use macros or inline functions from this file, or you compile
19 // this file and link it with other files to produce an executable, this
20 // file does not by itself cause the resulting executable to be covered by
21 // the GNU General Public License. This exception does not however
22 // invalidate any other reasons why the executable file might be covered by
23 // the GNU General Public License.
24 //
25 // This exception applies only to the code released under the name GNU
26 // ccRTP. If you copy code from other releases into a copy of GNU
27 // ccRTP, as the General Public License permits, the exception does
28 // not apply to the code that you add in this way. To avoid misleading
29 // anyone as to the status of such modified files, you must delete
30 // this exception notice from them.
31 //
32 // If you write modifications of your own for GNU ccRTP, it is your choice
33 // whether to permit this exception to apply to your modifications.
34 // If you do not wish that, delete this exception notice.
35 //
36 
43 #ifndef CCXX_RTP_CQUEUE_H_
44 #define CCXX_RTP_CQUEUE_H_
45 
46 #include <ccrtp/ioqueue.h>
48 #include <list>
49 
50 NAMESPACE_COMMONCPP
51 
80  protected RTCPCompoundHandler
81 {
82 public:
92  RTCPSenderInfo* getMRSenderInfo(SyncSource& src);
93 
104  RTCPReceiverInfo* getMRReceiverInfo(SyncSource& srcFrom);
105 
115  { leavingDelay = delay; }
116 
131  inline void
133  { end2EndDelay = t; }
134 
135  inline microtimeout_t
137  { return defaultEnd2EndDelay; }
138 
139  inline microtimeout_t
141  { return end2EndDelay; }
142 
156  inline void
158  { sendControlBwFract = fraction; recvControlBwFract = 1 - fraction;}
159 
169  void
171  { rtcpMinInterval = interval; }
172 
176  inline uint32
178  { return ctrlSendCount; }
179 
188  void
189  setOutQueueCryptoContextCtrl(CryptoContextCtrl* cc);
190 
199  void
200  removeOutQueueCryptoContextCtrl(CryptoContextCtrl* cc);
201 
210  getOutQueueCryptoContextCtrl(uint32 ssrc);
211 
212 
221  void
222  setInQueueCryptoContextCtrl(CryptoContextCtrl* cc);
223 
234  void
235  removeInQueueCryptoContextCtrl(CryptoContextCtrl* cc);
236 
245  getInQueueCryptoContextCtrl(uint32 ssrc);
246 
247 protected:
250 
251  QueueRTCPManager(uint32 ssrc,
254 
255  virtual
256  ~QueueRTCPManager();
257 
258  const RTPApplication&
260  { return queueApplication; }
261 
262  inline void
263  setControlBandwidth(float fraction)
264  { controlBwFract = fraction; }
265 
266  float
268  { return controlBwFract; }
269 
274  void
275  controlTransmissionService();
276 
281  void
282  controlReceptionService();
283 
296  bool checkSSRCInRTCPPkt(SyncSourceLink& sourceLink, bool is_new,
297  InetAddress& na, tpport_t tp);
298 
299  void
300  endQueueRTCPManager();
301 
312  virtual void
313  onGotSR(SyncSource& source, SendReport& SR, uint8 blocks);
314 
325  virtual void
326  onGotRR(SyncSource& source, RecvReport& RR, uint8 blocks);
327 
332  bool
333  onGotSDES(SyncSource& source, RTCPPacket& pkt);
334 
344  virtual bool
345  onGotSDESChunk(SyncSource& source, SDESChunk& chunk, size_t len);
346 
356  inline virtual void
358  size_t)
359  { return; }
360 
361  inline timeval
363  { return rtcpCheckInterval; }
364 
369  uint32
371  { return lastSendPacketCount; }
372 
376  inline void
378  { reconsInfo.rtcpPMembers = n; }
379 
380  inline uint32
382  { return reconsInfo.rtcpPMembers; }
383 
402  size_t
403  dispatchBYE(const std::string& reason);
404 
405  size_t
406  sendControlToDestinations(unsigned char* buffer, size_t len);
407 
408 private:
410 
412  operator=(const QueueRTCPManager &o);
413 
419  size_t
420  dispatchControlPacket();
421 
433  void
434  takeInControlPacket();
435 
449  virtual timeval
450  computeRTCPInterval();
451 
459  virtual SDESItemType
460  scheduleSDESItem();
461 
467  inline virtual void
469  { }
470 
474  virtual bool
475  end2EndDelayed(IncomingRTPPktLink& p);
476 
485  inline virtual void
486  onGotRRSRExtension(unsigned char*, size_t)
487  { return; }
488 
498  inline virtual void
499  onGotGoodbye(const SyncSource&, const std::string&)
500  { return; }
501 
514  bool
515  getBYE(RTCPPacket &pkt, size_t &pointer, size_t len);
516 
520  uint8
521  packReportBlocks(RRBlock* blocks, uint16& len, uint16& available);
522 
531  void
532  packSDES(uint16& len);
533 
545  void
546  updateAvgRTCPSize(size_t len);
547 
553  void
554  reverseReconsideration();
555 
556  bool
557  timerReconsideration();
558 
567  void
568  expireSSRCs();
569 
573  void
574  getOnlyBye();
575 
580  void
582  const char* const value, size_t len);
583 
588  void
589  setPRIVPrefix(Participant* part, const char* const value, size_t len);
590 
602  inline virtual uint16
604  { return 20; }
605 
617  inline virtual uint16
619  { return 8; }
620 
621 
622  int32 protect(uint8* pkt, size_t len, CryptoContextCtrl* cc);
623  int32 unprotect(uint8* pkt, size_t len, CryptoContextCtrl* cc);
624 
625 
627  nextSDESType(SDESItemType t);
628 
629  virtual size_t
630  sendControl(const unsigned char* const buffer, size_t len) = 0;
631 
632  virtual size_t
633  recvControl(unsigned char* buffer, size_t len,
634  InetHostAddress& na, tpport_t& tp) = 0;
635 
636  virtual bool
637  isPendingControl(microtimeout_t timeout) = 0;
638 
639  // whether the RTCP service is active
640  volatile bool controlServiceActive;
641  float controlBwFract, sendControlBwFract, recvControlBwFract;
642  // number of RTCP packets sent since the beginning
644 
645  // Network + transport headers size, typically size of IP +
646  // UDP headers
648 
652 
653  // state for rtcp timing. Its meaning is defined in
654  // draft-ietf-avt-rtp-new, 6.3.
655 
656  // Parameters for timer reconsideration algorithm
657  struct {
658  timeval rtcpTp, rtcpTc, rtcpTn;
659  uint32 rtcpPMembers;
660  } reconsInfo;
662  uint16 rtcpAvgSize;
664  // last time we checked if there were incoming RTCP packets
665  timeval rtcpLastCheck;
666  // interval to check if there are incoming RTCP packets
668  // next time to check if there are incoming RTCP packets
669  timeval rtcpNextCheck;
670 
671  // number of RTP data packets sent at the time of the last
672  // RTCP packet transmission.
674 
675  // minimum interval for transmission of RTCP packets. The
676  // result of computeRTCPInterval will always be >= (times a
677  // random number between 0.5 and 1.5).
679 
682  // Maximum delay allowed between packet timestamping and
683  // packet availability for the application.
685  // Application this queue is bound to.
687 
688  // an empty RTPData
689  static const uint16 TIMEOUT_MULTIPLIER;
690  static const double RECONSIDERATION_COMPENSATION;
691 
692  mutable Mutex outCryptoMutex;
693  std::list<CryptoContextCtrl *> outCryptoContexts;
694  uint32 srtcpIndex;
695 
696  mutable Mutex inCryptoMutex;
697  std::list<CryptoContextCtrl *> inCryptoContexts;
698 
699 };
700 
709 {
710 public:
726  inline void
727  setControlBandwidth(float fraction)
729 
730  float
733 
734 protected:
737  QueueRTCPManager(size,app)
738  { }
739 
743  AVPQueue(uint32 ssrc, uint32 size =
746  QueueRTCPManager(ssrc,size,app)
747  { }
748  inline virtual ~AVPQueue()
749  { }
750 };
751  // cqueue
753 
754 END_NAMESPACE
755 
756 #endif //CCXX_RTP_CQUEUE_H_
757 
Generic RTP input/output queues.
uint32 getLastSendPacketCount() const
Get the number of data packets sent at the time the last SR was generated.
Definition: cqueue.h:370
uint32 rtcpPMembers
Definition: cqueue.h:659
microtimeout_t getDefaultEnd2EndDelay() const
Definition: cqueue.h:136
The implementation for a SRTCP cryptographic context.
virtual size_t dispatchBYE(const std::string &)
A plugin point for posting of BYE messages.
Definition: queuebase.h:228
microtimeout_t getEnd2EndDelay() const
Definition: cqueue.h:140
low level structs and RTCP packet parsing and building methods.
Definition: rtcppkt.h:89
std::list< CryptoContextCtrl * > outCryptoContexts
Definition: cqueue.h:693
An RTP application, holding identifying RTCP SDES item values.
Definition: sources.h:364
float getControlBandwidth() const
Definition: cqueue.h:731
Synchronization source in an RTP session.
Definition: sources.h:192
static const SDESItemType firstSchedulable
Definition: cqueue.h:650
float getControlBandwidth() const
Definition: cqueue.h:267
void setPRIVPrefix(Participant *part, const std::string val)
Definition: iqueue.h:188
uint32 getPrevMembersCount() const
Definition: cqueue.h:381
volatile bool controlServiceActive
Definition: cqueue.h:640
uint32 microtimeout_t
Time interval expressed in microseconds.
Definition: base.h:67
Sender block information of SR RTCP reports.
Definition: rtcppkt.h:453
timeval rtcpTp
Definition: cqueue.h:658
microtimeout_t end2EndDelay
Definition: cqueue.h:684
Adds generic management of RTCP functions to an RTP data queue.
Definition: cqueue.h:79
uint16 lowerHeadersSize
Definition: cqueue.h:647
virtual bool end2EndDelayed(IncomingRTPPktLink &)
Definition: iqueue.h:1238
void setMinRTCPInterval(microtimeout_t interval)
Manually set the minimum interval for sending RTP compound packets.
Definition: cqueue.h:170
timeval rtcpCheckInterval
Definition: cqueue.h:667
uint32 ctrlSendCount
Definition: cqueue.h:643
void setLeavingDelay(microtimeout_t delay)
Set how much time the stack will wait before deleting a synchronization source that has sent an RTCP ...
Definition: cqueue.h:114
timeval rtcpNextCheck
Definition: cqueue.h:669
AVPQueue(uint32 size=RTPDataQueue::defaultMembersHashSize, RTPApplication &app=defaultApplication())
Definition: cqueue.h:735
static const microtimeout_t defaultEnd2EndDelay
maximum end to end delay: unlimited
Definition: cqueue.h:681
AVPQueue(uint32 ssrc, uint32 size=RTPDataQueue::defaultMembersHashSize, RTPApplication &app=defaultApplication())
Local SSRC is given instead of computed by the queue.
Definition: cqueue.h:743
virtual void onGotAPP(SyncSource &, RTCPCompoundHandler::APPPacket &, size_t)
Plug-in for handling of APP (application specific) RTCP packets.
Definition: cqueue.h:357
timeval getRTCPCheckInterval()
Definition: cqueue.h:362
bool rtcpWeSent
Definition: cqueue.h:661
virtual void onGotGoodbye(const SyncSource &, const std::string &)
A plugin point for goodbye message.
Definition: cqueue.h:499
uint32 getSendRTCPPacketCount() const
Get the total number of RTCP packets sent until now.
Definition: cqueue.h:177
static const double RECONSIDERATION_COMPENSATION
Definition: cqueue.h:690
A class of objects representing remote participants (RTP applications) in a multimedia session...
Definition: sources.h:124
Mutex outCryptoMutex
Definition: cqueue.h:692
RTPDataQueue & operator=(const RTPDataQueue &o)
virtual uint16 transportHeaderSize()
For certain control calculations in RTCP, the size of the underlying network and transport protocols ...
Definition: cqueue.h:618
microtimeout_t rtcpMinInterval
Definition: cqueue.h:678
void setSDESItem(Participant *part, SDESItemType item, const std::string &val)
Definition: iqueue.h:183
static const size_t defaultMembersHashSize
Definition: iqueue.h:854
void setControlBandwidth(float fraction)
Specify the bandwith available for control (RTCP) packets.
Definition: cqueue.h:727
void setControlBandwidth(float fraction)
Definition: cqueue.h:263
#define __EXPORT
Definition: ZrtpCallback.h:40
SDESItemType nextScheduledSDESItem
Definition: cqueue.h:649
const RTPApplication & getApplication()
Definition: cqueue.h:259
uint32 srtcpIndex
Definition: cqueue.h:694
uint16 rtcpAvgSize
Definition: cqueue.h:662
bool rtcpInitial
Definition: cqueue.h:663
timeval rtcpLastCheck
Definition: cqueue.h:665
static const SDESItemType lastSchedulable
Definition: cqueue.h:651
virtual uint16 networkHeaderSize()
For certain control calculations in RTCP, the size of the underlying network and transport protocols ...
Definition: cqueue.h:603
void setSendersControlFraction(float fraction)
Specify the fraction of the total control bandwith to be dedicated to senders reports.
Definition: cqueue.h:157
static const uint16 TIMEOUT_MULTIPLIER
Definition: cqueue.h:689
Mutex inCryptoMutex
Definition: cqueue.h:696
float sendControlBwFract
Definition: cqueue.h:641
Report block information of SR/RR RTCP reports.
Definition: rtcppkt.h:373
microtimeout_t leavingDelay
Definition: cqueue.h:680
virtual ~AVPQueue()
Definition: cqueue.h:748
std::list< CryptoContextCtrl * > inCryptoContexts
Definition: cqueue.h:697
virtual void onGotRRSRExtension(unsigned char *, size_t)
Plug-in for processing of SR/RR RTCP packet profile-specific extensions (third part of SR reports or ...
Definition: cqueue.h:486
Struct for APP (application specific) RTCP packets.
Definition: rtcppkt.h:212
void setPrevMembersNum(uint32 n)
Definition: cqueue.h:377
__EXPORT RTPApplication & defaultApplication()
Get the RTPApplication object for the "default" application (the only one used by common applications...
Definition: source.cpp:128
virtual void onSSRCCollision(const SyncSource &)
Plug-in for SSRC collision handling.
Definition: cqueue.h:468
uint32 lastSendPacketCount
Definition: cqueue.h:673
void setEnd2EndDelay(microtimeout_t t)
This method sets the maximum end to end delay allowed.
Definition: cqueue.h:132
A packet queue handler for building different kinds of RTP protocol systems.
Definition: ioqueue.h:74
SDESItemType
SDES items that may be carried in a Source DEScription RTCP packet.
Definition: rtcppkt.h:64
RTPApplication & queueApplication
Definition: cqueue.h:686
This class, an RTP/RTCP queue, adds audio/video profile (AVP) specific methods to the generic RTCP se...
Definition: cqueue.h:708