ccRTP
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 
79 class __EXPORT QueueRTCPManager : public RTPDataQueue,
80  protected RTCPCompoundHandler
81 {
82 public:
93 
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
190 
199  void
201 
211 
212 
221  void
223 
234  void
236 
246 
247 protected:
250 
251  QueueRTCPManager(uint32 ssrc,
254 
255  virtual
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
276 
281  void
283 
296  bool checkSSRCInRTCPPkt(SyncSourceLink& sourceLink, bool is_new,
297  InetAddress& na, tpport_t tp);
298 
299  void
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
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
468  onSSRCCollision(const SyncSource&)
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
603  networkHeaderSize()
604  { return 20; }
605 
617  inline virtual uint16
618  transportHeaderSize()
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
643  uint32 ctrlSendCount;
644 
645  // Network + transport headers size, typically size of IP +
646  // UDP headers
647  uint16 lowerHeadersSize;
648 
649  SDESItemType nextScheduledSDESItem;
650  static const SDESItemType firstSchedulable;
651  static const SDESItemType lastSchedulable;
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;
661  bool rtcpWeSent;
662  uint16 rtcpAvgSize;
663  bool rtcpInitial;
664  // last time we checked if there were incoming RTCP packets
665  timeval rtcpLastCheck;
666  // interval to check if there are incoming RTCP packets
667  timeval rtcpCheckInterval;
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.
673  uint32 lastSendPacketCount;
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).
678  microtimeout_t rtcpMinInterval;
679 
680  microtimeout_t leavingDelay;
681  static const microtimeout_t defaultEnd2EndDelay;
682  // Maximum delay allowed between packet timestamping and
683  // packet availability for the application.
684  microtimeout_t end2EndDelay;
685  // Application this queue is bound to.
686  RTPApplication& queueApplication;
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 
708 class __EXPORT AVPQueue : public QueueRTCPManager
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 
uint32 microtimeout_t
Time interval expressed in microseconds.
Definition: base.h:67
This class, an RTP/RTCP queue, adds audio/video profile (AVP) specific methods to the generic RTCP se...
Definition: cqueue.h:709
void setControlBandwidth(float fraction)
Specify the bandwith available for control (RTCP) packets.
Definition: cqueue.h:727
AVPQueue(uint32 ssrc, uint32 size=RTPDataQueue::defaultMembersHashSize, RTPApplication &app=defaultApplication())
Local SSRC is given instead of computed by the queue.
Definition: cqueue.h:743
float getControlBandwidth() const
Definition: cqueue.h:731
virtual ~AVPQueue()
Definition: cqueue.h:748
AVPQueue(uint32 size=RTPDataQueue::defaultMembersHashSize, RTPApplication &app=defaultApplication())
Definition: cqueue.h:735
The implementation for a SRTCP cryptographic context.
Definition: CryptoContextCtrl.h:61
virtual bool end2EndDelayed(IncomingRTPPktLink &)
Definition: iqueue.h:1238
static const size_t defaultMembersHashSize
Definition: iqueue.h:854
void setSDESItem(Participant *part, SDESItemType item, const std::string &val)
Definition: iqueue.h:183
void setPRIVPrefix(Participant *part, const std::string val)
Definition: iqueue.h:188
A class of objects representing remote participants (RTP applications) in a multimedia session.
Definition: sources.h:125
Adds generic management of RTCP functions to an RTP data queue.
Definition: cqueue.h:81
void setMinRTCPInterval(microtimeout_t interval)
Manually set the minimum interval for sending RTP compound packets.
Definition: cqueue.h:170
void setInQueueCryptoContextCtrl(CryptoContextCtrl *cc)
Set input queue CryptoContext.
timeval rtcpTc
Definition: cqueue.h:658
RTCPSenderInfo * getMRSenderInfo(SyncSource &src)
Get the most recent sender report received from a synchronization source.
void controlReceptionService()
Process incoming RTCP packets pending in the control reception socket.
uint32 getSendRTCPPacketCount() const
Get the total number of RTCP packets sent until now.
Definition: cqueue.h:177
void controlTransmissionService()
Build and send RTCP packets following timing rules (including the "timer reconsideration" algorithm).
uint32 rtcpPMembers
Definition: cqueue.h:659
uint32 getLastSendPacketCount() const
Get the number of data packets sent at the time the last SR was generated.
Definition: cqueue.h:370
void setPrevMembersNum(uint32 n)
Definition: cqueue.h:377
RTCPReceiverInfo * getMRReceiverInfo(SyncSource &srcFrom)
Ask for the info in the most recent receiver report about the local source received from the source g...
virtual ~QueueRTCPManager()
uint32 getPrevMembersCount() const
Definition: cqueue.h:381
bool checkSSRCInRTCPPkt(SyncSourceLink &sourceLink, bool is_new, InetAddress &na, tpport_t tp)
Appy collision and loop detection and correction algorithm when receiving RTCP packets.
virtual bool onGotSDESChunk(SyncSource &source, SDESChunk &chunk, size_t len)
Plug-in for handling of SDES chunks.
void setOutQueueCryptoContextCtrl(CryptoContextCtrl *cc)
Set ouput queue CryptoContext.
microtimeout_t getDefaultEnd2EndDelay() const
Definition: cqueue.h:136
void removeInQueueCryptoContextCtrl(CryptoContextCtrl *cc)
Remove input queue CryptoContext.
bool onGotSDES(SyncSource &source, RTCPPacket &pkt)
void setSendersControlFraction(float fraction)
Specify the fraction of the total control bandwith to be dedicated to senders reports.
Definition: cqueue.h:157
const RTPApplication & getApplication()
Definition: cqueue.h:259
timeval getRTCPCheckInterval()
Definition: cqueue.h:362
QueueRTCPManager(uint32 ssrc, uint32 size=RTPDataQueue::defaultMembersHashSize, RTPApplication &app=defaultApplication())
virtual void onGotSR(SyncSource &source, SendReport &SR, uint8 blocks)
Plug-in for processing (acquire information carried in) an incoming RTCP Sender Report.
size_t dispatchBYE(const std::string &reason)
This method is used to send an RTCP BYE packet.
float getControlBandwidth() const
Definition: cqueue.h:267
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
void endQueueRTCPManager()
microtimeout_t getEnd2EndDelay() const
Definition: cqueue.h:140
void removeOutQueueCryptoContextCtrl(CryptoContextCtrl *cc)
Remove output queue CryptoContext.
void setEnd2EndDelay(microtimeout_t t)
This method sets the maximum end to end delay allowed.
Definition: cqueue.h:132
CryptoContextCtrl * getInQueueCryptoContextCtrl(uint32 ssrc)
Get an input queue CryptoContext identified by SSRC.
virtual void onGotAPP(SyncSource &, RTCPCompoundHandler::APPPacket &, size_t)
Plug-in for handling of APP (application specific) RTCP packets.
Definition: cqueue.h:357
CryptoContextCtrl * getOutQueueCryptoContextCtrl(uint32 ssrc)
Get an output queue CryptoContext identified by SSRC.
virtual void onGotRR(SyncSource &source, RecvReport &RR, uint8 blocks)
Plug-in for processing (acquire information carried in) an incoming RTCP Receiver Report.
void setControlBandwidth(float fraction)
Definition: cqueue.h:263
size_t sendControlToDestinations(unsigned char *buffer, size_t len)
QueueRTCPManager(uint32 size=RTPDataQueue::defaultMembersHashSize, RTPApplication &app=defaultApplication())
low level structs and RTCP packet parsing and building methods.
Definition: rtcppkt.h:90
Report block information of SR/RR RTCP reports.
Definition: rtcppkt.h:374
Sender block information of SR RTCP reports.
Definition: rtcppkt.h:454
An RTP application, holding identifying RTCP SDES item values.
Definition: sources.h:365
A packet queue handler for building different kinds of RTP protocol systems.
Definition: ioqueue.h:77
Synchronization source in an RTP session.
Definition: sources.h:193
SDESItemType
SDES items that may be carried in a Source DEScription RTCP packet.
Definition: rtcppkt.h:65
__EXPORT RTPApplication & defaultApplication()
Get the RTPApplication object for the "default" application (the only one used by common applications...
Generic RTP input/output queues.
Struct for APP (application specific) RTCP packets.
Definition: rtcppkt.h:213
Struct representing general RTCP packet headers as they are sent through the network.
Definition: rtcppkt.h:278
raw structure of the source and every receiver report in an SR or RR RTCP packet.
Definition: rtcppkt.h:138
Struct for a chunk of items in a SDES RTCP packet.
Definition: rtcppkt.h:188
Struct for SR (sender report) RTCP packets.
Definition: rtcppkt.h:164