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>
49#include <list>
50
51NAMESPACE_COMMONCPP
52
80class __EXPORT QueueRTCPManager : public RTPDataQueue,
81 protected RTCPCompoundHandler
82{
83public:
94
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
189 void
191
200 void
202
212
213
222 void
224
235 void
237
247
248protected:
251
252 QueueRTCPManager(uint32 ssrc,
255
256 virtual
258
259 const RTPApplication&
261 { return queueApplication; }
262
263 inline void
264 setControlBandwidth(float fraction)
265 { controlBwFract = fraction; }
266
267 float
269 { return controlBwFract; }
270
275 void
277
282 void
284
297 bool checkSSRCInRTCPPkt(SyncSourceLink& sourceLink, bool is_new,
298 InetAddress& na, tpport_t tp);
299
300 void
302
313 virtual void
314 onGotSR(SyncSource& source, SendReport& SR, uint8 blocks);
315
326 virtual void
327 onGotRR(SyncSource& source, RecvReport& RR, uint8 blocks);
328
333 bool
335
345 virtual bool
346 onGotSDESChunk(SyncSource& source, SDESChunk& chunk, size_t len);
347
357 inline virtual void
359 size_t)
360 { return; }
361
362 inline timeval
364 { return rtcpCheckInterval; }
365
370 uint32
372 { return lastSendPacketCount; }
373
377 inline void
379 { reconsInfo.rtcpPMembers = n; }
380
381 inline uint32
383 { return reconsInfo.rtcpPMembers; }
384
403 size_t
404 dispatchBYE(const std::string& reason);
405
406 size_t
407 sendControlToDestinations(unsigned char* buffer, size_t len);
408
409private:
411
413 operator=(const QueueRTCPManager &o);
414
420 size_t
421 dispatchControlPacket();
422
434 void
435 takeInControlPacket();
436
450 virtual timeval
451 computeRTCPInterval();
452
460 virtual SDESItemType
461 scheduleSDESItem();
462
468 inline virtual void
469 onSSRCCollision(const SyncSource&)
470 { }
471
475 virtual bool
476 end2EndDelayed(IncomingRTPPktLink& p);
477
486 inline virtual void
487 onGotRRSRExtension(unsigned char*, size_t)
488 { return; }
489
499 inline virtual void
500 onGotGoodbye(const SyncSource&, const std::string&)
501 { return; }
502
515 bool
516 getBYE(RTCPPacket &pkt, size_t &pointer, size_t len);
517
521 uint8
522 packReportBlocks(RRBlock* blocks, uint16& len, uint16& available);
523
532 void
533 packSDES(uint16& len);
534
546 void
547 updateAvgRTCPSize(size_t len);
548
554 void
555 reverseReconsideration();
556
557 bool
558 timerReconsideration();
559
568 void
569 expireSSRCs();
570
574 void
575 getOnlyBye();
576
581 void
583 const char* const value, size_t len);
584
589 void
590 setPRIVPrefix(Participant* part, const char* const value, size_t len);
591
603 inline virtual uint16
604 networkHeaderSize()
605 { return 20; }
606
618 inline virtual uint16
619 transportHeaderSize()
620 { return 8; }
621
622
623 int32 protect(uint8* pkt, size_t len, CryptoContextCtrl* cc);
624 int32 unprotect(uint8* pkt, size_t len, CryptoContextCtrl* cc);
625
626
628 nextSDESType(SDESItemType t);
629
630 virtual size_t
631 sendControl(const unsigned char* const buffer, size_t len) = 0;
632
633 virtual size_t
634 recvControl(unsigned char* buffer, size_t len,
635 InetHostAddress& na, tpport_t& tp) = 0;
636
637 virtual bool
638 isPendingControl(microtimeout_t timeout) = 0;
639
640 // whether the RTCP service is active
641 volatile bool controlServiceActive;
642 float controlBwFract, sendControlBwFract, recvControlBwFract;
643 // number of RTCP packets sent since the beginning
644 uint32 ctrlSendCount;
645
646 // Network + transport headers size, typically size of IP +
647 // UDP headers
648 uint16 lowerHeadersSize;
649
650 SDESItemType nextScheduledSDESItem;
651 static const SDESItemType firstSchedulable;
652 static const SDESItemType lastSchedulable;
653
654 // state for rtcp timing. Its meaning is defined in
655 // draft-ietf-avt-rtp-new, 6.3.
656
657 // Parameters for timer reconsideration algorithm
658 struct {
659 timeval rtcpTp, rtcpTc, rtcpTn;
661 } reconsInfo;
662 bool rtcpWeSent;
663 uint16 rtcpAvgSize;
664 bool rtcpInitial;
665 // last time we checked if there were incoming RTCP packets
666 timeval rtcpLastCheck;
667 // interval to check if there are incoming RTCP packets
668 timeval rtcpCheckInterval;
669 // next time to check if there are incoming RTCP packets
670 timeval rtcpNextCheck;
671
672 // number of RTP data packets sent at the time of the last
673 // RTCP packet transmission.
674 uint32 lastSendPacketCount;
675
676 // minimum interval for transmission of RTCP packets. The
677 // result of computeRTCPInterval will always be >= (times a
678 // random number between 0.5 and 1.5).
679 microtimeout_t rtcpMinInterval;
680
681 microtimeout_t leavingDelay;
682 static const microtimeout_t defaultEnd2EndDelay;
683 // Maximum delay allowed between packet timestamping and
684 // packet availability for the application.
685 microtimeout_t end2EndDelay;
686 // Application this queue is bound to.
687 RTPApplication& queueApplication;
688
689 // an empty RTPData
690 static const uint16 TIMEOUT_MULTIPLIER;
691 static const double RECONSIDERATION_COMPENSATION;
692
693 mutable Mutex outCryptoMutex;
694 std::list<CryptoContextCtrl *> outCryptoContexts;
695 uint32 srtcpIndex;
696
697 mutable Mutex inCryptoMutex;
698 std::list<CryptoContextCtrl *> inCryptoContexts;
699
700};
701
709class __EXPORT AVPQueue : public QueueRTCPManager
710{
711public:
727 inline void
728 setControlBandwidth(float fraction)
730
731 float
734
735protected:
738 QueueRTCPManager(size,app)
739 { }
740
744 AVPQueue(uint32 ssrc, uint32 size =
747 QueueRTCPManager(ssrc,size,app)
748 { }
749 inline virtual ~AVPQueue()
750 { }
751};
752 // cqueue
754
755END_NAMESPACE
756
757#endif //CCXX_RTP_CQUEUE_H_
758
uint32 microtimeout_t
Time interval expressed in microseconds.
Definition: base.h:68
This class, an RTP/RTCP queue, adds audio/video profile (AVP) specific methods to the generic RTCP se...
Definition: cqueue.h:710
void setControlBandwidth(float fraction)
Specify the bandwith available for control (RTCP) packets.
Definition: cqueue.h:728
AVPQueue(uint32 ssrc, uint32 size=RTPDataQueue::defaultMembersHashSize, RTPApplication &app=defaultApplication())
Local SSRC is given instead of computed by the queue.
Definition: cqueue.h:744
float getControlBandwidth() const
Definition: cqueue.h:732
virtual ~AVPQueue()
Definition: cqueue.h:749
AVPQueue(uint32 size=RTPDataQueue::defaultMembersHashSize, RTPApplication &app=defaultApplication())
Definition: cqueue.h:736
The implementation for a SRTCP cryptographic context.
Definition: CryptoContextCtrl.h:62
virtual bool end2EndDelayed(IncomingRTPPktLink &)
Definition: iqueue.h:1239
static const size_t defaultMembersHashSize
Definition: iqueue.h:855
void setSDESItem(Participant *part, SDESItemType item, const std::string &val)
Definition: iqueue.h:184
void setPRIVPrefix(Participant *part, const std::string val)
Definition: iqueue.h:189
A class of objects representing remote participants (RTP applications) in a multimedia session.
Definition: sources.h:127
Adds generic management of RTCP functions to an RTP data queue.
Definition: cqueue.h:82
void setMinRTCPInterval(microtimeout_t interval)
Manually set the minimum interval for sending RTP compound packets.
Definition: cqueue.h:171
RTCPSenderInfo * getMRSenderInfo(SyncSource &src)
Get the most recent sender report received from a synchronization source.
void setInQueueCryptoContextCtrl(CryptoContextCtrl *cc)
Set input queue CryptoContext.
timeval rtcpTc
Definition: cqueue.h:659
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:178
void controlTransmissionService()
Build and send RTCP packets following timing rules (including the "timer reconsideration" algorithm).
uint32 rtcpPMembers
Definition: cqueue.h:660
CryptoContextCtrl * getOutQueueCryptoContextCtrl(uint32 ssrc)
Get an output queue CryptoContext identified by SSRC.
uint32 getLastSendPacketCount() const
Get the number of data packets sent at the time the last SR was generated.
Definition: cqueue.h:371
void setPrevMembersNum(uint32 n)
Definition: cqueue.h:378
virtual ~QueueRTCPManager()
uint32 getPrevMembersCount() const
Definition: cqueue.h:382
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 output queue CryptoContext.
microtimeout_t getDefaultEnd2EndDelay() const
Definition: cqueue.h:137
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:158
RTCPReceiverInfo * getMRReceiverInfo(SyncSource &srcFrom)
Ask for the info in the most recent receiver report about the local source received from the source g...
timeval getRTCPCheckInterval()
Definition: cqueue.h:363
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:268
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
const RTPApplication & getApplication()
Definition: cqueue.h:260
void endQueueRTCPManager()
microtimeout_t getEnd2EndDelay() const
Definition: cqueue.h:141
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:133
virtual void onGotAPP(SyncSource &, RTCPCompoundHandler::APPPacket &, size_t)
Plug-in for handling of APP (application specific) RTCP packets.
Definition: cqueue.h:358
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:264
size_t sendControlToDestinations(unsigned char *buffer, size_t len)
QueueRTCPManager(uint32 size=RTPDataQueue::defaultMembersHashSize, RTPApplication &app=defaultApplication())
CryptoContextCtrl * getInQueueCryptoContextCtrl(uint32 ssrc)
Get an input queue CryptoContext identified by SSRC.
low level structs and RTCP packet parsing and building methods.
Definition: rtcppkt.h:91
Report block information of SR/RR RTCP reports.
Definition: rtcppkt.h:375
Sender block information of SR RTCP reports.
Definition: rtcppkt.h:455
An RTP application, holding identifying RTCP SDES item values.
Definition: sources.h:367
A packet queue handler for building different kinds of RTP protocol systems.
Definition: ioqueue.h:78
Synchronization source in an RTP session.
Definition: sources.h:195
SDESItemType
SDES items that may be carried in a Source DEScription RTCP packet.
Definition: rtcppkt.h:66
__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:214
Struct representing general RTCP packet headers as they are sent through the network.
Definition: rtcppkt.h:279
raw structure of the source and every receiver report in an SR or RR RTCP packet.
Definition: rtcppkt.h:139
Struct for a chunk of items in a SDES RTCP packet.
Definition: rtcppkt.h:189
Struct for SR (sender report) RTCP packets.
Definition: rtcppkt.h:165