Bayonne2 / Common C++ 2 Framework
 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,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 
81  protected RTCPCompoundHandler
82 {
83 public:
93  RTCPSenderInfo* getMRSenderInfo(SyncSource& src);
94 
105  RTCPReceiverInfo* getMRReceiverInfo(SyncSource& srcFrom);
106 
116  { leavingDelay = delay; }
117 
132  inline void
134  { end2EndDelay = t; }
135 
136  inline microtimeout_t
138  { return defaultEnd2EndDelay; }
139 
140  inline microtimeout_t
142  { return end2EndDelay; }
143 
157  inline void
159  { sendControlBwFract = fraction; recvControlBwFract = 1 - fraction;}
160 
170  void
172  { rtcpMinInterval = interval; }
173 
177  inline uint32
179  { return ctrlSendCount; }
180 
181 protected:
184 
185  QueueRTCPManager(uint32 ssrc,
188 
189  virtual
190  ~QueueRTCPManager();
191 
192  const RTPApplication&
194  { return queueApplication; }
195 
196  inline void
197  setControlBandwidth(float fraction)
198  { controlBwFract = fraction; }
199 
200  float
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
297  { return rtcpCheckInterval; }
298 
303  uint32
305  { return lastSendPacketCount; }
306 
310  inline void
312  { reconsInfo.rtcpPMembers = n; }
313 
314  inline uint32
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
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
538  { return 20; }
539 
551  inline virtual uint16
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
573 
574  // Network + transport headers size, typically size of IP +
575  // UDP headers
577 
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;
591  uint16 rtcpAvgSize;
593  // last time we checked if there were incoming RTCP packets
594  timeval rtcpLastCheck;
595  // interval to check if there are incoming RTCP packets
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.
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).
608 
611  // Maximum delay allowed between packet timestamping and
612  // packet availability for the application.
614  // Application this queue is bound to.
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
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 
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:304
uint32 rtcpPMembers
Definition: cqueue.h:588
microtimeout_t getDefaultEnd2EndDelay() const
Definition: cqueue.h:137
microtimeout_t getEnd2EndDelay() const
Definition: cqueue.h:141
low level structs and RTCP packet parsing and building methods.
Definition: rtcppkt.h:92
An RTP application, holding identifying RTCP SDES item values.
Definition: sources.h:367
float getControlBandwidth() const
Definition: cqueue.h:652
Synchronization source in an RTP session.
Definition: sources.h:195
static const SDESItemType firstSchedulable
Definition: cqueue.h:579
float getControlBandwidth() const
Definition: cqueue.h:201
uint32 getPrevMembersCount() const
Definition: cqueue.h:315
volatile bool controlServiceActive
Definition: cqueue.h:569
uint32 microtimeout_t
Time interval expressed in microseconds.
Definition: base.h:69
Sender block information of SR RTCP reports.
Definition: rtcppkt.h:456
timeval rtcpTp
Definition: cqueue.h:587
microtimeout_t end2EndDelay
Definition: cqueue.h:613
Adds generic management of RTCP functions to an RTP data queue.
Definition: cqueue.h:80
uint16 lowerHeadersSize
Definition: cqueue.h:576
unsigned short tpport_t
Transport Protocol Ports.
Definition: address.h:86
void setMinRTCPInterval(microtimeout_t interval)
Manually set the minimum interval for sending RTP compound packets.
Definition: cqueue.h:171
timeval rtcpCheckInterval
Definition: cqueue.h:596
uint32 ctrlSendCount
Definition: cqueue.h:572
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:115
timeval rtcpNextCheck
Definition: cqueue.h:598
AVPQueue(uint32 size=RTPDataQueue::defaultMembersHashSize, RTPApplication &app=defaultApplication())
Definition: cqueue.h:656
static const microtimeout_t defaultEnd2EndDelay
Definition: cqueue.h:610
AVPQueue(uint32 ssrc, uint32 size=RTPDataQueue::defaultMembersHashSize, RTPApplication &app=defaultApplication())
Local SSRC is given instead of computed by the queue.
Definition: cqueue.h:664
virtual void onGotAPP(SyncSource &, RTCPCompoundHandler::APPPacket &, size_t)
Plug-in for handling of APP (application specific) RTCP packets.
Definition: cqueue.h:291
timeval getRTCPCheckInterval()
Definition: cqueue.h:296
bool rtcpWeSent
Definition: cqueue.h:590
virtual void onGotGoodbye(const SyncSource &, const std::string &)
A plugin point for goodbye message.
Definition: cqueue.h:433
uint32 getSendRTCPPacketCount() const
Get the total number of RTCP packets sent until now.
Definition: cqueue.h:178
static const double RECONSIDERATION_COMPENSATION
Definition: cqueue.h:619
A class of objects representing remote participants (RTP applications) in a multimedia session...
Definition: sources.h:127
#define InetHostAddress
Definition: address.h:76
virtual uint16 transportHeaderSize()
For certain control calculations in RTCP, the size of the underlying network and transport protocols ...
Definition: cqueue.h:552
microtimeout_t rtcpMinInterval
Definition: cqueue.h:607
static const size_t defaultMembersHashSize
Definition: iqueue.h:854
void setControlBandwidth(float fraction)
Specify the bandwith available for control (RTCP) packets.
Definition: cqueue.h:648
void setControlBandwidth(float fraction)
Definition: cqueue.h:197
SDESItemType nextScheduledSDESItem
Definition: cqueue.h:578
const RTPApplication & getApplication()
Definition: cqueue.h:193
#define InetAddress
Definition: address.h:75
uint16 rtcpAvgSize
Definition: cqueue.h:591
bool rtcpInitial
Definition: cqueue.h:592
timeval rtcpLastCheck
Definition: cqueue.h:594
static const SDESItemType lastSchedulable
Definition: cqueue.h:580
virtual uint16 networkHeaderSize()
For certain control calculations in RTCP, the size of the underlying network and transport protocols ...
Definition: cqueue.h:537
void setSendersControlFraction(float fraction)
Specify the fraction of the total control bandwith to be dedicated to senders reports.
Definition: cqueue.h:158
#define __EXPORT
Definition: audio2.h:51
static const uint16 TIMEOUT_MULTIPLIER
Definition: cqueue.h:618
float sendControlBwFract
Definition: cqueue.h:570
Report block information of SR/RR RTCP reports.
Definition: rtcppkt.h:376
microtimeout_t leavingDelay
Definition: cqueue.h:609
virtual ~AVPQueue()
Definition: cqueue.h:669
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:420
Struct for APP (application specific) RTCP packets.
Definition: rtcppkt.h:215
void setPrevMembersNum(uint32 n)
Definition: cqueue.h:311
__EXPORT RTPApplication & defaultApplication()
Get the RTPApplication object for the "default" application (the only one used by common applications...
virtual void onSSRCCollision(const SyncSource &)
Plug-in for SSRC collision handling.
Definition: cqueue.h:402
uint32 lastSendPacketCount
Definition: cqueue.h:602
void setEnd2EndDelay(microtimeout_t t)
This method sets the maximum end to end delay allowed.
Definition: cqueue.h:133
A packet queue handler for building different kinds of RTP protocol systems.
Definition: ioqueue.h:77
SDESItemType
SDES items that may be carried in a Source DEScription RTCP packet.
Definition: rtcppkt.h:67
RTPApplication & queueApplication
Definition: cqueue.h:615
This class, an RTP/RTCP queue, adds audio/video profile (AVP) specific methods to the generic RTCP se...
Definition: cqueue.h:629