oqueue.h
Go to the documentation of this file.
// Copyright (C) 2001,2002,2004,2005 Federico Montesino Pouzols <fedemp@altern.org>.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
//
// This exception applies only to the code released under the name GNU
// ccRTP. If you copy code from other releases into a copy of GNU
// ccRTP, as the General Public License permits, the exception does
// not apply to the code that you add in this way. To avoid misleading
// anyone as to the status of such modified files, you must delete
// this exception notice from them.
//
// If you write modifications of your own for GNU ccRTP, it is your choice
// whether to permit this exception to apply to your modifications.
// If you do not wish that, delete this exception notice.
//
#ifndef CCXX_RTP_OQUEUE_H_
#define CCXX_RTP_OQUEUE_H_
#include <ccrtp/queuebase.h>
#include <ccrtp/CryptoContext.h>
#include <list>
NAMESPACE_COMMONCPP
class __EXPORT DestinationListHandler
{
protected:
struct TransportAddress;
std::list<TransportAddress*> destList;
public:
DestinationListHandler();
~DestinationListHandler();
inline bool isSingleDestination() const
{ return (1 == destList.size()); }
inline TransportAddress* getFirstDestination() const
{ return destList.front(); }
inline void lockDestinationList() const
{ destinationLock.readLock(); }
inline void unlockDestinationList() const
{ destinationLock.unlock(); }
protected:
inline void writeLockDestinationList() const
{ destinationLock.writeLock(); }
bool
addDestinationToList(const InetAddress& ia, tpport_t data,
tpport_t control);
bool removeDestinationFromList(const InetAddress& ia,
tpport_t dataPort,
tpport_t controlPort);
struct TransportAddress
{
TransportAddress(InetAddress na, tpport_t dtp, tpport_t ctp) :
networkAddress(na), dataTransportPort(dtp),
controlTransportPort(ctp)
{ }
inline const InetAddress& getNetworkAddress() const
{ return networkAddress; }
inline tpport_t getDataTransportPort() const
{ return dataTransportPort; }
inline tpport_t getControlTransportPort() const
{ return controlTransportPort; }
InetAddress networkAddress;
tpport_t dataTransportPort, controlTransportPort;
};
private:
mutable ThreadLock destinationLock;
};
#ifdef CCXX_IPV6
class __EXPORT DestinationListHandlerIPV6
{
protected:
struct TransportAddressIPV6;
std::list<TransportAddressIPV6*> destListIPV6;
public:
DestinationListHandlerIPV6();
~DestinationListHandlerIPV6();
inline bool isSingleDestinationIPV6() const
{ return (1 == destListIPV6.size()); }
inline TransportAddressIPV6* getFirstDestinationIPV6() const
{ return destListIPV6.front(); }
inline void lockDestinationListIPV6() const
{ destinationLock.readLock(); }
inline void unlockDestinationListIPV6() const
{ destinationLock.unlock(); }
protected:
inline void writeLockDestinationListIPV6() const
{ destinationLock.writeLock(); }
bool
addDestinationToListIPV6(const IPV6Address& ia, tpport_t data,
tpport_t control);
bool removeDestinationFromListIPV6(const IPV6Address& ia,
tpport_t dataPort,
tpport_t controlPort);
struct TransportAddressIPV6
{
TransportAddressIPV6(IPV6Address na, tpport_t dtp, tpport_t ctp) :
networkAddress(na), dataTransportPort(dtp),
controlTransportPort(ctp)
{ }
inline const IPV6Address& getNetworkAddress() const
{ return networkAddress; }
inline tpport_t getDataTransportPort() const
{ return dataTransportPort; }
inline tpport_t getControlTransportPort() const
{ return controlTransportPort; }
IPV6Address networkAddress;
tpport_t dataTransportPort, controlTransportPort;
};
private:
mutable ThreadLock destinationLock;
};
#endif
class __EXPORT OutgoingDataQueue:
public OutgoingDataQueueBase,
#ifdef CCXX_IPV6
protected DestinationListHandlerIPV6,
#endif
protected DestinationListHandler
{
public:
#ifdef CCXX_IPV6
bool
addDestination(const IPV6Address& ia,
tpport_t dataPort = DefaultRTPDataPort,
tpport_t controlPort = 0);
bool
forgetDestination(const IPV6Address& ia,
tpport_t dataPort = DefaultRTPDataPort,
tpport_t controlPort = 0);
#endif
bool
addDestination(const InetHostAddress& ia,
tpport_t dataPort = DefaultRTPDataPort,
tpport_t controlPort = 0);
bool
addDestination(const InetMcastAddress& ia,
tpport_t dataPort = DefaultRTPDataPort,
tpport_t controlPort = 0);
bool
forgetDestination(const InetHostAddress& ia,
tpport_t dataPort = DefaultRTPDataPort,
tpport_t controlPort = 0);
bool
forgetDestination(const InetMcastAddress& ia,
tpport_t dataPort = DefaultRTPDataPort,
tpport_t controlPort = 0);
void
addContributor(uint32 csrc);
bool
removeContributor(uint32 csrc);
bool
isSending() const;
void
putData(uint32 stamp, const unsigned char* data = NULL, size_t len = 0);
void
sendImmediate(uint32 stamp, const unsigned char* data = NULL, size_t len = 0);
void setPadding(uint8 paddinglen)
{ sendInfo.paddinglen = paddinglen; }
void setMark(bool mark)
{ sendInfo.marked = mark; }
inline bool getMark() const
{ return sendInfo.marked; }
size_t
setPartial(uint32 timestamp, unsigned char* data, size_t offset, size_t max);
inline microtimeout_t
getDefaultSchedulingTimeout() const
{ return defaultSchedulingTimeout; }
inline void
setSchedulingTimeout(microtimeout_t to)
{ schedulingTimeout = to; }
inline microtimeout_t
getDefaultExpireTimeout() const
{ return defaultExpireTimeout; }
inline void
setExpireTimeout(microtimeout_t to)
{ expireTimeout = to; }
inline microtimeout_t getExpireTimeout() const
{ return expireTimeout; }
inline uint32
getSendPacketCount() const
{ return sendInfo.packetCount; }
inline uint32
getSendOctetCount() const
{ return sendInfo.octetCount; }
inline uint16
getSequenceNumber() const
{ return sendInfo.sendSeq; }
void
setOutQueueCryptoContext(CryptoContext* cc);
void
removeOutQueueCryptoContext(CryptoContext* cc);
CryptoContext*
getOutQueueCryptoContext(uint32 ssrc);
protected:
OutgoingDataQueue();
virtual ~OutgoingDataQueue()
{ }
struct OutgoingRTPPktLink
{
OutgoingRTPPktLink(OutgoingRTPPkt* pkt,
OutgoingRTPPktLink* p,
OutgoingRTPPktLink* n) :
packet(pkt), prev(p), next(n) { }
~OutgoingRTPPktLink() { delete packet; }
inline OutgoingRTPPkt* getPacket() { return packet; }
inline void setPacket(OutgoingRTPPkt* pkt) { packet = pkt; }
inline OutgoingRTPPktLink* getPrev() { return prev; }
inline void setPrev(OutgoingRTPPktLink* p) { prev = p; }
inline OutgoingRTPPktLink* getNext() { return next; }
inline void setNext(OutgoingRTPPktLink* n) { next = n; }
// the packet this link refers to.
OutgoingRTPPkt* packet;
// global outgoing packets queue.
OutgoingRTPPktLink * prev, * next;
};
void
dispatchImmediate(OutgoingRTPPkt *packet);
microtimeout_t
getSchedulingTimeout();
size_t
dispatchDataPacket();
inline void
setNextSeqNum(uint32 seqNum)
{ sendInfo.sendSeq = seqNum; }
inline uint32
getCurrentSeqNum(void)
{ return sendInfo.sendSeq; }
inline void
setInitialTimestamp(uint32 ts)
{ initialTimestamp = ts; }
inline uint32
getInitialTimestamp()
{ return initialTimestamp; }
void purgeOutgoingQueue();
virtual void
setControlPeer(const InetAddress &host, tpport_t port) {}
#ifdef CCXX_IPV6
virtual void
setControlPeerIPV6(const IPV6Address &host, tpport_t port) {}
#endif
// The crypto contexts for outgoing SRTP sessions.
mutable Mutex cryptoMutex;
std::list<CryptoContext *> cryptoContexts;
private:
inline virtual void onExpireSend(OutgoingRTPPkt&)
{ }
virtual void
setDataPeer(const InetAddress &host, tpport_t port) {}
#ifdef CCXX_IPV6
virtual void
setDataPeerIPV6(const IPV6Address &host, tpport_t port) {}
#endif
virtual size_t
sendData(const unsigned char* const buffer, size_t len) {return 0;}
#ifdef CCXX_IPV6
virtual size_t
sendDataIPV6(const unsigned char* const buffer, size_t len) {return 0;}
#endif
static const microtimeout_t defaultSchedulingTimeout;
static const microtimeout_t defaultExpireTimeout;
mutable ThreadLock sendLock;
// outgoing data packets queue
OutgoingRTPPktLink* sendFirst, * sendLast;
uint32 initialTimestamp;
// transmission scheduling timeout for the service thread
microtimeout_t schedulingTimeout;
// how old a packet can reach in the sending queue before deletetion
microtimeout_t expireTimeout;
struct {
// number of packets sent from the beginning
uint32 packetCount;
// number of payload octets sent from the beginning
uint32 octetCount;
// the sequence number of the next packet to sent
uint16 sendSeq;
// contributing sources
uint32 sendSources[16];
// how many CSRCs to send.
uint16 sendCC;
// pad packets to a paddinglen multiple
uint8 paddinglen;
// This flags tells whether to set the bit M in the
// RTP fixed header of the packet in which the next
// provided data will be sent.
bool marked;
// whether there was not loss.
bool complete;
// ramdonly generated offset for the timestamp of sent packets
uint32 initialTimestamp;
// elapsed time accumulated through successive overflows of
// the local timestamp field
timeval overflowTime;
} sendInfo;
};
// oqueue
END_NAMESPACE
#endif //CCXX_RTP_OQUEUE_H_
DestinationListHandler::TransportAddress::getNetworkAddress
const InetAddress & getNetworkAddress() const
Definition: oqueue.h:117
CryptoContext
The implementation for a SRTP cryptographic context.
Definition: CryptoContext.h:83
OutgoingDataQueue::getDefaultExpireTimeout
microtimeout_t getDefaultExpireTimeout() const
Definition: oqueue.h:369
OutgoingDataQueue::getSendPacketCount
uint32 getSendPacketCount() const
Get the total number of packets sent so far.
Definition: oqueue.h:392
OutgoingDataQueue::setPadding
void setPadding(uint8 paddinglen)
Set padding.
Definition: oqueue.h:321
microtimeout_t
uint32 microtimeout_t
Time interval expressed in microseconds.
Definition: base.h:68
DestinationListHandler::lockDestinationList
void lockDestinationList() const
Definition: oqueue.h:86
OutgoingDataQueue::OutgoingRTPPktLink::packet
OutgoingRTPPkt * packet
Definition: oqueue.h:474
OutgoingDataQueue::~OutgoingDataQueue
virtual ~OutgoingDataQueue()
Definition: oqueue.h:449
OutgoingDataQueue::overflowTime
timeval overflowTime
Definition: oqueue.h:621
OutgoingDataQueue::OutgoingRTPPktLink::~OutgoingRTPPktLink
~OutgoingRTPPktLink()
Definition: oqueue.h:459
OutgoingDataQueue::setExpireTimeout
void setExpireTimeout(microtimeout_t to)
Set the "expired" timer for expiring packets pending in the send queue which have gone unsent and are...
Definition: oqueue.h:380
DestinationListHandler::TransportAddress::getControlTransportPort
tpport_t getControlTransportPort() const
Definition: oqueue.h:123
DestinationListHandler::TransportAddress::TransportAddress
TransportAddress(InetAddress na, tpport_t dtp, tpport_t ctp)
Definition: oqueue.h:112
DestinationListHandler::getFirstDestination
TransportAddress * getFirstDestination() const
Definition: oqueue.h:83
DestinationListHandler::TransportAddress::dataTransportPort
tpport_t dataTransportPort
Definition: oqueue.h:127
OutgoingDataQueue::OutgoingRTPPktLink
Definition: oqueue.h:452
OutgoingDataQueue::packetCount
uint32 packetCount
Definition: oqueue.h:600
OutgoingDataQueue::marked
bool marked
Definition: oqueue.h:614
DestinationListHandler::unlockDestinationList
void unlockDestinationList() const
Definition: oqueue.h:89
DestinationListHandler::isSingleDestination
bool isSingleDestination() const
Get whether there is only a destination in the list.
Definition: oqueue.h:80
OutgoingDataQueue::setSchedulingTimeout
void setSchedulingTimeout(microtimeout_t to)
Set the default scheduling timeout to use when no data packets are waiting to be sent.
Definition: oqueue.h:365
OutgoingDataQueue::setNextSeqNum
void setNextSeqNum(uint32 seqNum)
For thoses cases in which the application requires a method to set the sequence number for the outgoi...
Definition: oqueue.h:519
DestinationListHandler::writeLockDestinationList
void writeLockDestinationList() const
Definition: oqueue.h:93
OutgoingDataQueue::sendCC
uint16 sendCC
Definition: oqueue.h:608
OutgoingRTPPkt
RTP packets being sent.
Definition: rtppkt.h:508
CryptoContext.h
OutgoingDataQueue::paddinglen
uint8 paddinglen
Definition: oqueue.h:610
queuebase.h
Base classes for RTP queues.
OutgoingDataQueue::getSendOctetCount
uint32 getSendOctetCount() const
Get the total number of octets (payload only) sent so far.
Definition: oqueue.h:401
OutgoingDataQueue::OutgoingRTPPktLink::getNext
OutgoingRTPPktLink * getNext()
Definition: oqueue.h:469
OutgoingDataQueue::OutgoingRTPPktLink::getPacket
OutgoingRTPPkt * getPacket()
Definition: oqueue.h:461
OutgoingDataQueue::setMark
void setMark(bool mark)
Set marker bit for the packet in which the next data provided will be send.
Definition: oqueue.h:332
OutgoingDataQueue::OutgoingRTPPktLink::prev
OutgoingRTPPktLink * prev
Definition: oqueue.h:476
OutgoingDataQueue::getInitialTimestamp
uint32 getInitialTimestamp()
Definition: oqueue.h:535
OutgoingDataQueue::sendSeq
uint16 sendSeq
Definition: oqueue.h:604
OutgoingDataQueue::OutgoingRTPPktLink::setPacket
void setPacket(OutgoingRTPPkt *pkt)
Definition: oqueue.h:463
DestinationListHandler
This class handles a list of destination addresses.
Definition: oqueue.h:66
OutgoingDataQueue::complete
bool complete
Definition: oqueue.h:616
DefaultRTPDataPort
const tpport_t DefaultRTPDataPort
registered default RTP data transport port
Definition: base.h:110
OutgoingDataQueue::OutgoingRTPPktLink::setPrev
void setPrev(OutgoingRTPPktLink *p)
Definition: oqueue.h:467
OutgoingDataQueue::octetCount
uint32 octetCount
Definition: oqueue.h:602
OutgoingDataQueue::cryptoMutex
Mutex cryptoMutex
Definition: oqueue.h:549
OutgoingDataQueue::getCurrentSeqNum
uint32 getCurrentSeqNum(void)
Definition: oqueue.h:523
OutgoingDataQueue::getMark
bool getMark() const
Get whether the mark bit will be set in the next packet.
Definition: oqueue.h:338
OutgoingDataQueue::setInitialTimestamp
void setInitialTimestamp(uint32 ts)
Definition: oqueue.h:529
DestinationListHandler::TransportAddress::getDataTransportPort
tpport_t getDataTransportPort() const
Definition: oqueue.h:120
OutgoingDataQueue::OutgoingRTPPktLink::OutgoingRTPPktLink
OutgoingRTPPktLink(OutgoingRTPPkt *pkt, OutgoingRTPPktLink *p, OutgoingRTPPktLink *n)
Definition: oqueue.h:454
DestinationListHandler::TransportAddress
Definition: oqueue.h:110
DestinationListHandler::TransportAddress::networkAddress
InetAddress networkAddress
Definition: oqueue.h:126
OutgoingDataQueue::OutgoingRTPPktLink::setNext
void setNext(OutgoingRTPPktLink *n)
Definition: oqueue.h:471
DestinationListHandler::destList
std::list< TransportAddress * > destList
Definition: oqueue.h:69
OutgoingDataQueue::getSequenceNumber
uint16 getSequenceNumber() const
Get the sequence number of the next outgoing packet.
Definition: oqueue.h:410
OutgoingDataQueue::setControlPeer
virtual void setControlPeer(const InetAddress &host, tpport_t port)
Definition: oqueue.h:541
OutgoingDataQueue
A generic outgoing RTP data queue supporting multiple destinations.
Definition: oqueue.h:220
OutgoingDataQueue::OutgoingRTPPktLink::getPrev
OutgoingRTPPktLink * getPrev()
Definition: oqueue.h:465
OutgoingDataQueueBase
Definition: queuebase.h:255
OutgoingDataQueue::getExpireTimeout
microtimeout_t getExpireTimeout() const
Definition: oqueue.h:383
OutgoingDataQueue::getDefaultSchedulingTimeout
microtimeout_t getDefaultSchedulingTimeout() const
Definition: oqueue.h:355
OutgoingDataQueue::cryptoContexts
std::list< CryptoContext * > cryptoContexts
Definition: oqueue.h:550