ccRTP
cqueue.h
Go to the documentation of this file.
1 // Copyright (C) 2001,2002,2004 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 General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 //
17 // As a special exception, you may use this file as part of a free software
18 // library without restriction. Specifically, if other files instantiate
19 // templates or use macros or inline functions from this file, or you compile
20 // this file and link it with other files to produce an executable, this
21 // file does not by itself cause the resulting executable to be covered by
22 // the GNU General Public License. This exception does not however
23 // invalidate any other reasons why the executable file might be covered by
24 // the GNU General Public License.
25 //
26 // This exception applies only to the code released under the name GNU
27 // ccRTP. If you copy code from other releases into a copy of GNU
28 // ccRTP, as the General Public License permits, the exception does
29 // not apply to the code that you add in this way. To avoid misleading
30 // anyone as to the status of such modified files, you must delete
31 // this exception notice from them.
32 //
33 // If you write modifications of your own for GNU ccRTP, it is your choice
34 // whether to permit this exception to apply to your modifications.
35 // If you do not wish that, delete this exception notice.
36 //
37 
44 #ifndef CCXX_RTP_CQUEUE_H_
45 #define CCXX_RTP_CQUEUE_H_
46 
47 #include <ccrtp/ioqueue.h>
48 
49 #ifdef CCXX_NAMESPACES
50 namespace ost {
51 #endif
52 
80 class __EXPORT QueueRTCPManager : public RTPDataQueue,
81  protected RTCPCompoundHandler
82 {
83 public:
93  RTCPSenderInfo* getMRSenderInfo(SyncSource& src);
94 
105  RTCPReceiverInfo* getMRReceiverInfo(SyncSource& srcFrom);
106 
115  void setLeavingDelay(microtimeout_t delay)
116  { leavingDelay = delay; }
117 
132  inline void
133  setEnd2EndDelay(microtimeout_t t)
134  { end2EndDelay = t; }
135 
136  inline microtimeout_t
137  getDefaultEnd2EndDelay() const
138  { return defaultEnd2EndDelay; }
139 
140  inline microtimeout_t
141  getEnd2EndDelay() const
142  { return end2EndDelay; }
143 
157  inline void
158  setSendersControlFraction(float fraction)
159  { sendControlBwFract = fraction; recvControlBwFract = 1 - fraction;}
160 
170  void
171  setMinRTCPInterval(microtimeout_t interval)
172  { rtcpMinInterval = interval; }
173 
177  inline uint32
178  getSendRTCPPacketCount() const
179  { return ctrlSendCount; }
180 
181 protected:
184 
185  QueueRTCPManager(uint32 ssrc,
188 
189  virtual
190  ~QueueRTCPManager();
191 
192  const RTPApplication&
193  getApplication()
194  { return queueApplication; }
195 
196  inline void
197  setControlBandwidth(float fraction)
198  { controlBwFract = fraction; }
199 
200  float
201  getControlBandwidth() const
202  { return controlBwFract; }
203 
208  void
209  controlTransmissionService();
210 
215  void
216  controlReceptionService();
217 
230  bool checkSSRCInRTCPPkt(SyncSourceLink& sourceLink, bool is_new,
231  InetAddress& na, tpport_t tp);
232 
233  void
234  endQueueRTCPManager();
235 
246  virtual void
247  onGotSR(SyncSource& source, SendReport& SR, uint8 blocks);
248 
259  virtual void
260  onGotRR(SyncSource& source, RecvReport& RR, uint8 blocks);
261 
266  bool
267  onGotSDES(SyncSource& source, RTCPPacket& pkt);
268 
278  virtual bool
279  onGotSDESChunk(SyncSource& source, SDESChunk& chunk, size_t len);
280 
290  inline virtual void
292  size_t)
293  { return; }
294 
295  inline timeval
296  getRTCPCheckInterval()
297  { return rtcpCheckInterval; }
298 
303  uint32
304  getLastSendPacketCount() const
305  { return lastSendPacketCount; }
306 
310  inline void
311  setPrevMembersNum(uint32 n)
312  { reconsInfo.rtcpPMembers = n; }
313 
314  inline uint32
315  getPrevMembersCount() const
316  { return reconsInfo.rtcpPMembers; }
317 
336  size_t
337  dispatchBYE(const std::string& reason);
338 
339  size_t
340  sendControlToDestinations(unsigned char* buffer, size_t len);
341 
342 private:
344 
346  operator=(const QueueRTCPManager &o);
347 
353  size_t
354  dispatchControlPacket();
355 
367  void
368  takeInControlPacket();
369 
383  virtual timeval
384  computeRTCPInterval();
385 
393  virtual SDESItemType
394  scheduleSDESItem();
395 
401  inline virtual void
402  onSSRCCollision(const SyncSource&)
403  { }
404 
408  virtual bool
409  end2EndDelayed(IncomingRTPPktLink& p);
410 
419  inline virtual void
420  onGotRRSRExtension(unsigned char*, size_t)
421  { return; }
422 
432  inline virtual void
433  onGotGoodbye(const SyncSource&, const std::string&)
434  { return; }
435 
448  bool
449  getBYE(RTCPPacket &pkt, size_t &pointer, size_t len);
450 
454  uint8
455  packReportBlocks(RRBlock* blocks, uint16& len, uint16& available);
456 
465  void
466  packSDES(uint16& len);
467 
479  void
480  updateAvgRTCPSize(size_t len);
481 
487  void
488  reverseReconsideration();
489 
490  bool
491  timerReconsideration();
492 
501  void
502  expireSSRCs();
503 
507  void
508  getOnlyBye();
509 
514  void
515  setSDESItem(Participant* part, SDESItemType type,
516  const char* const value, size_t len);
517 
522  void
523  setPRIVPrefix(Participant* part, const char* const value, size_t len);
524 
536  inline virtual uint16
537  networkHeaderSize()
538  { return 20; }
539 
551  inline virtual uint16
552  transportHeaderSize()
553  { return 8; }
554 
556  nextSDESType(SDESItemType t);
557 
558  virtual size_t
559  sendControl(const unsigned char* const buffer, size_t len) = 0;
560 
561  virtual size_t
562  recvControl(unsigned char* buffer, size_t len,
563  InetHostAddress& na, tpport_t& tp) = 0;
564 
565  virtual bool
566  isPendingControl(microtimeout_t timeout) = 0;
567 
568  // whether the RTCP service is active
569  volatile bool controlServiceActive;
570  float controlBwFract, sendControlBwFract, recvControlBwFract;
571  // number of RTCP packets sent since the beginning
572  uint32 ctrlSendCount;
573 
574  // Network + transport headers size, typically size of IP +
575  // UDP headers
576  uint16 lowerHeadersSize;
577 
578  SDESItemType nextScheduledSDESItem;
579  static const SDESItemType firstSchedulable;
580  static const SDESItemType lastSchedulable;
581 
582  // state for rtcp timing. Its meaning is defined in
583  // draft-ietf-avt-rtp-new, 6.3.
584 
585  // Parameters for timer reconsideration algorithm
586  struct {
587  timeval rtcpTp, rtcpTc, rtcpTn;
588  uint32 rtcpPMembers;
589  } reconsInfo;
590  bool rtcpWeSent;
591  uint16 rtcpAvgSize;
592  bool rtcpInitial;
593  // last time we checked if there were incoming RTCP packets
594  timeval rtcpLastCheck;
595  // interval to check if there are incoming RTCP packets
596  timeval rtcpCheckInterval;
597  // next time to check if there are incoming RTCP packets
598  timeval rtcpNextCheck;
599 
600  // number of RTP data packets sent at the time of the last
601  // RTCP packet transmission.
602  uint32 lastSendPacketCount;
603 
604  // minimum interval for transmission of RTCP packets. The
605  // result of computeRTCPInterval will always be >= (times a
606  // random number between 0.5 and 1.5).
607  microtimeout_t rtcpMinInterval;
608 
609  microtimeout_t leavingDelay;
610  static const microtimeout_t defaultEnd2EndDelay;
611  // Maximum delay allowed between packet timestamping and
612  // packet availability for the application.
613  microtimeout_t end2EndDelay;
614  // Application this queue is bound to.
615  RTPApplication& queueApplication;
616 
617  // an empty RTPData
618  static const uint16 TIMEOUT_MULTIPLIER;
619  static const double RECONSIDERATION_COMPENSATION;
620 };
621 
630 {
631 public:
647  inline void
648  setControlBandwidth(float fraction)
650 
651  float
652  getControlBandwidth() const
654 
655 protected:
658  QueueRTCPManager(size,app)
659  { }
660 
664  AVPQueue(uint32 ssrc, uint32 size =
667  QueueRTCPManager(ssrc,size,app)
668  { }
669  inline virtual ~AVPQueue()
670  { }
671 };
672  // cqueue
674 
675 #ifdef CCXX_NAMESPACES
676 }
677 #endif
678 
679 #endif //CCXX_RTP_CQUEUE_H_
680