rtcppkt.h
Go to the documentation of this file.
// Copyright (C) 2001,2002,2004,2007 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_RTCPPKT_H_
#define CCXX_RTP_RTCPPKT_H_
#include <ccrtp/base.h>
NAMESPACE_COMMONCPP
typedef enum
{
SDESItemTypeEND = 0,
SDESItemTypeCNAME,
SDESItemTypeNAME,
SDESItemTypeEMAIL,
SDESItemTypePHONE,
SDESItemTypeLOC,
SDESItemTypeTOOL,
SDESItemTypeNOTE,
SDESItemTypePRIV,
SDESItemTypeH323CADDR,
SDESItemTypeLast = SDESItemTypeH323CADDR
} SDESItemType;
class __EXPORT RTCPCompoundHandler
{
public:
inline void setPathMTU(uint16 mtu)
{ pathMTU = mtu; }
inline uint16 getPathMTU()
{ return pathMTU; }
#ifdef CCXX_PACKED
#pragma pack(1)
#endif
struct ReceiverInfo
{
uint8 fractionLost;
uint8 lostMSB;
uint16 lostLSW;
uint32 highestSeqNum;
uint32 jitter;
uint32 lsr;
uint32 dlsr;
};
struct RRBlock
{
uint32 ssrc;
ReceiverInfo rinfo;
};
struct RecvReport
{
uint32 ssrc;
RRBlock blocks[1];
};
struct SenderInfo
{
uint32 NTPMSW;
uint32 NTPLSW;
uint32 RTPTimestamp;
uint32 packetCount;
uint32 octetCount;
};
struct SendReport
{
uint32 ssrc;
SenderInfo sinfo;
RRBlock blocks[1];
};
struct SDESItem
{
uint8 type;
uint8 len;
char data[1];
};
struct SDESChunk
{
uint32 getSSRC() const
{ return (ntohl(ssrc)); }
uint32 ssrc;
SDESItem item;
};
struct BYEPacket
{
uint32 ssrc;
uint8 length;
};
struct APPPacket
{
uint32 ssrc;
char name [4];
unsigned char data[1];
};
struct FIRPacket
{
uint32 ssrc;
};
struct NACKPacket
{
uint32 ssrc;
uint16 fsn;
uint16 blp;
};
struct RTCPFixedHeader
{
#if __BYTE_ORDER == __BIG_ENDIAN
unsigned char version:2;
unsigned char padding:1;
unsigned char block_count:5;
#else
unsigned char block_count:5;
unsigned char padding:1;
unsigned char version:2;
#endif
uint8 type;
uint16 length;
};
struct RTCPPacket
{
typedef enum {
tSR = 200,
tRR,
tSDES,
tBYE,
tAPP,
tFIR = 192,
tNACK = 193,
tXR
} Type;
uint32 getLength() const
{ return ((ntohs(fh.length) + 1) << 2); }
uint32 getSSRC() const
{ return (ntohl(info.RR.ssrc)); } // SSRC is always the first
// word after fh.
RTCPFixedHeader fh;
// An RTCP packet may be of any of the types defined
// above, including APP specific ones.
union
{
SendReport SR;
RecvReport RR;
SDESChunk SDES;
BYEPacket BYE;
APPPacket APP;
NACKPacket NACK;
FIRPacket FIR;
} info;
};
#ifdef CCXX_PACKED
#pragma pack()
#endif
protected:
enum { defaultPathMTU = 1500 };
RTCPCompoundHandler(uint16 mtu = defaultPathMTU);
~RTCPCompoundHandler();
bool
checkCompoundRTCPHeader(size_t len);
// buffer to hold RTCP compound packets being sent. Allocated
// in construction time
unsigned char* rtcpSendBuffer;
// buffer to hold RTCP compound packets being
// received. Allocated at construction time
unsigned char* rtcpRecvBuffer;
friend class RTCPSenderInfo;
friend class RTCPReceiverInfo;
private:
// path MTU. RTCP packets should not be greater than this
uint16 pathMTU;
// masks for RTCP header validation;
static const uint16 RTCP_VALID_MASK;
static const uint16 RTCP_VALID_VALUE;
};
class __EXPORT RTCPReceiverInfo
{
public:
RTCPReceiverInfo(void* ri)
{ memcpy(&receiverInfo,&ri,
sizeof(RTCPCompoundHandler::ReceiverInfo));}
RTCPReceiverInfo(RTCPCompoundHandler::ReceiverInfo& si)
: receiverInfo( si )
{
}
~RTCPReceiverInfo()
{ }
inline uint8
getFractionLost() const
{ return receiverInfo.fractionLost; }
inline uint32
getCumulativePacketLost() const
{ return ( ((uint32)ntohs(receiverInfo.lostLSW)) +
(((uint32)receiverInfo.lostMSB) << 16) ); }
inline uint32
getExtendedSeqNum() const
{ return ntohl(receiverInfo.highestSeqNum); }
uint32
getJitter() const
{ return ntohl(receiverInfo.jitter); }
uint16
getLastSRNTPTimestampInt() const
{ return (uint16)((ntohl(receiverInfo.lsr) & 0xFFFF0000) >> 16); }
uint16
getLastSRNTPTimestampFrac() const
{ return (uint16)(ntohl(receiverInfo.lsr) & 0xFFFF); }
uint32
getDelayLastSR() const
{ return ntohl(receiverInfo.dlsr); }
private:
RTCPCompoundHandler::ReceiverInfo receiverInfo;
};
class __EXPORT RTCPSenderInfo
{
public:
RTCPSenderInfo(void* si)
{ memcpy(&senderInfo,&si,
sizeof(RTCPCompoundHandler::SenderInfo));}
RTCPSenderInfo(RTCPCompoundHandler::SenderInfo& si)
: senderInfo( si )
{
}
~RTCPSenderInfo()
{ }
uint32
getNTPTimestampInt() const
{ return ntohl(senderInfo.NTPMSW); }
uint32
getNTPTimestampFrac() const
{ return ntohl(senderInfo.NTPLSW); }
inline uint32
getRTPTimestamp() const
{ return ntohl(senderInfo.RTPTimestamp); }
inline uint32
getPacketCount() const
{ return ntohl(senderInfo.packetCount); }
inline uint32
getOctetCount() const
{ return ntohl(senderInfo.octetCount); }
private:
RTCPCompoundHandler::SenderInfo senderInfo;
};
timeval
NTP2Timeval(uint32 msw, uint32 lsw);
uint32
timevalIntervalTo65536(timeval& t);
// rtcppacket
END_NAMESPACE
#endif // ndef CCXX_RTP_RTCPPKT_H_
RTCPCompoundHandler::rtcpRecvBuffer
unsigned char * rtcpRecvBuffer
Definition: rtcppkt.h:356
RTCPSenderInfo::getRTPTimestamp
uint32 getRTPTimestamp() const
Definition: rtcppkt.h:486
RTCPCompoundHandler::SendReport
Struct for SR (sender report) RTCP packets.
Definition: rtcppkt.h:164
RTCPCompoundHandler::BYEPacket::length
uint8 length
[optional] length of reason.
Definition: rtcppkt.h:205
RTCPReceiverInfo::RTCPReceiverInfo
RTCPReceiverInfo(void *ri)
Definition: rtcppkt.h:377
RTCPCompoundHandler::NACKPacket::ssrc
uint32 ssrc
ssrc identifier of source.
Definition: rtcppkt.h:241
RTCPCompoundHandler::SenderInfo
Struct for the sender info block in a SR (sender report) RTCP packet.
Definition: rtcppkt.h:150
RTCPCompoundHandler::RTCPPacket::FIR
FIRPacket FIR
Definition: rtcppkt.h:323
RTCPCompoundHandler::SDESChunk::item
SDESItem item
SDES item from sender.
Definition: rtcppkt.h:194
SDESItemTypeLast
Last defined code.
Definition: rtcppkt.h:77
RTCPCompoundHandler::SenderInfo::RTPTimestamp
uint32 RTPTimestamp
RTP timestamp.
Definition: rtcppkt.h:154
RTCPSenderInfo::RTCPSenderInfo
RTCPSenderInfo(void *si)
Definition: rtcppkt.h:457
RTCPCompoundHandler::RTCPPacket::tSDES
Source DEScription.
Definition: rtcppkt.h:288
RTCPCompoundHandler::SenderInfo::packetCount
uint32 packetCount
cumulative packet counter.
Definition: rtcppkt.h:155
RTCPCompoundHandler::NACKPacket::fsn
uint16 fsn
First Sequence Number lost.
Definition: rtcppkt.h:242
RTCPCompoundHandler::getPathMTU
uint16 getPathMTU()
Definition: rtcppkt.h:96
RTCPCompoundHandler::ReceiverInfo
Struct for the data contained in a receiver info block.
Definition: rtcppkt.h:109
SDESItemTypeCNAME
Canonical end-point identifier.
Definition: rtcppkt.h:68
RTCPCompoundHandler::RRBlock
Struct for a receiver info block in a SR (sender report) or an RR (receiver report) RTCP packet...
Definition: rtcppkt.h:126
SDESItemTypeNOTE
Comment usually reporting state.
Definition: rtcppkt.h:74
RTCPCompoundHandler::SDESItem::type
uint8 type
item identifier.
Definition: rtcppkt.h:178
RTCPCompoundHandler::SenderInfo::octetCount
uint32 octetCount
cumulative octet counter.
Definition: rtcppkt.h:156
RTCPCompoundHandler::ReceiverInfo::jitter
uint32 jitter
arrival jitter.
Definition: rtcppkt.h:115
RTCPCompoundHandler::ReceiverInfo::lostLSW
uint16 lostLSW
cumulative lost two LSB.
Definition: rtcppkt.h:113
RTCPReceiverInfo
Report block information of SR/RR RTCP reports.
Definition: rtcppkt.h:374
RTCPCompoundHandler::RTCPPacket::tBYE
End of participation.
Definition: rtcppkt.h:289
RTCPCompoundHandler::RTCPPacket::tAPP
APPlication specific.
Definition: rtcppkt.h:290
RTCPCompoundHandler::RTCPPacket::BYE
BYEPacket BYE
Definition: rtcppkt.h:320
RTCPCompoundHandler::RTCPPacket::tRR
Receiver Report.
Definition: rtcppkt.h:287
RTCPCompoundHandler::SDESChunk
Struct for a chunk of items in a SDES RTCP packet.
Definition: rtcppkt.h:188
RTCPCompoundHandler::RecvReport::ssrc
uint32 ssrc
source identifier.
Definition: rtcppkt.h:140
SDESItemTypePHONE
Phone number of the user.
Definition: rtcppkt.h:71
RTCPSenderInfo::getNTPTimestampFrac
uint32 getNTPTimestampFrac() const
Get fractional part of the NTP timestamp of this packet.
Definition: rtcppkt.h:482
RTCPCompoundHandler::RRBlock::rinfo
ReceiverInfo rinfo
info about the source.
Definition: rtcppkt.h:129
RTCPReceiverInfo::getLastSRNTPTimestampInt
uint16 getLastSRNTPTimestampInt() const
Get the integer part of the NTP timestamp of the last SR RTCP packet received from the source this re...
Definition: rtcppkt.h:422
RTCPCompoundHandler::RTCPPacket::SDES
SDESChunk SDES
Definition: rtcppkt.h:319
RTCPCompoundHandler::APPPacket::ssrc
uint32 ssrc
ssrc identifier of source.
Definition: rtcppkt.h:215
RTCPCompoundHandler::BYEPacket
Struct for BYE (leaving session) RTCP packets.
Definition: rtcppkt.h:202
RTCPCompoundHandler::FIRPacket::ssrc
uint32 ssrc
ssrc identifier of source.
Definition: rtcppkt.h:230
RTCPReceiverInfo::getJitter
uint32 getJitter() const
Get the statistical variance of the RTP data packets interarrival time.
Definition: rtcppkt.h:413
RTCPCompoundHandler::RTCPFixedHeader
Fixed RTCP packet header.
Definition: rtcppkt.h:251
RTCPCompoundHandler::RTCPPacket::getLength
uint32 getLength() const
Get the packet length specified in its header, in octets and in host order.
Definition: rtcppkt.h:300
RTCPCompoundHandler::rtcpSendBuffer
unsigned char * rtcpSendBuffer
Definition: rtcppkt.h:353
RTCPCompoundHandler::ReceiverInfo::lostMSB
uint8 lostMSB
cumulative lost MSB of 3 octets.
Definition: rtcppkt.h:112
SDESItemTypeEND
END of SDES item list.
Definition: rtcppkt.h:67
RTCPCompoundHandler
low level structs and RTCP packet parsing and building methods.
Definition: rtcppkt.h:90
RTCPCompoundHandler::RTCPPacket::getSSRC
uint32 getSSRC() const
Get the SSRC identifier specified in the packet header, in host order.
Definition: rtcppkt.h:307
RTCPCompoundHandler::ReceiverInfo::highestSeqNum
uint32 highestSeqNum
highest sequence number.
Definition: rtcppkt.h:114
RTCPSenderInfo
Sender block information of SR RTCP reports.
Definition: rtcppkt.h:454
SDESItemTypePRIV
Private extension.
Definition: rtcppkt.h:75
RTCPReceiverInfo::getFractionLost
uint8 getFractionLost() const
Get fraction of lost packets, as a number between 0 and 255.
Definition: rtcppkt.h:394
RTCPReceiverInfo::~RTCPReceiverInfo
~RTCPReceiverInfo()
Definition: rtcppkt.h:386
RTCPCompoundHandler::NACKPacket
Struct for Negative ACKnowledgements (NACK) RTCP packet.
Definition: rtcppkt.h:239
timevalIntervalTo65536
uint32 timevalIntervalTo65536(timeval &t)
Convert a time interval, expressed as a timeval, into a 32-bit time interval expressed in units of 1/...
RTCPCompoundHandler::FIRPacket
Struct for Full Intra-frame Request (FIR) RTCP packet.
Definition: rtcppkt.h:228
RTCPReceiverInfo::RTCPReceiverInfo
RTCPReceiverInfo(RTCPCompoundHandler::ReceiverInfo &si)
Definition: rtcppkt.h:381
RTCPCompoundHandler::RTCPFixedHeader::length
uint16 length
number of 32-bit words in the packet (minus one).
Definition: rtcppkt.h:265
RTCPCompoundHandler::SDESItem
Struct for an item description of a SDES packet.
Definition: rtcppkt.h:176
RTCPSenderInfo::RTCPSenderInfo
RTCPSenderInfo(RTCPCompoundHandler::SenderInfo &si)
Definition: rtcppkt.h:461
RTCPCompoundHandler::RTCPPacket
Struct representing general RTCP packet headers as they are sent through the network.
Definition: rtcppkt.h:278
SDESItemTypeNAME
Personal NAME of the user.
Definition: rtcppkt.h:69
RTCPCompoundHandler::NACKPacket::blp
uint16 blp
Bitmask of following Lost Packets.
Definition: rtcppkt.h:243
RTCPCompoundHandler::SDESChunk::getSSRC
uint32 getSSRC() const
Definition: rtcppkt.h:190
SDESItemTypeH323CADDR
H323 callable address.
Definition: rtcppkt.h:76
RTCPReceiverInfo::getLastSRNTPTimestampFrac
uint16 getLastSRNTPTimestampFrac() const
Get the fractional part of the NTP timestamp of the last SR RTCP packet received from the source this...
Definition: rtcppkt.h:431
RTCPCompoundHandler::setPathMTU
void setPathMTU(uint16 mtu)
Definition: rtcppkt.h:93
base.h
Base elements for RTP stacks: constants, types and global functions.
RTCPCompoundHandler::RTCPPacket::NACK
NACKPacket NACK
Definition: rtcppkt.h:322
RTCPCompoundHandler::APPPacket
Struct for APP (application specific) RTCP packets.
Definition: rtcppkt.h:213
RTCPCompoundHandler::RTCPFixedHeader::type
uint8 type
type of RTCP packet.
Definition: rtcppkt.h:264
RTCPCompoundHandler::RTCPPacket::RR
RecvReport RR
Definition: rtcppkt.h:318
NTP2Timeval
timeval NTP2Timeval(uint32 msw, uint32 lsw)
Convert a NTP timestamp, expressed as two 32-bit long words, into a timeval value.
RTCPCompoundHandler::RRBlock::ssrc
uint32 ssrc
source identifier.
Definition: rtcppkt.h:128
RTCPReceiverInfo::getExtendedSeqNum
uint32 getExtendedSeqNum() const
Definition: rtcppkt.h:403
RTCPCompoundHandler::ReceiverInfo::lsr
uint32 lsr
last sender report timestamp.
Definition: rtcppkt.h:116
RTCPCompoundHandler::SDESItem::len
uint8 len
item len in octets.
Definition: rtcppkt.h:179
RTCPCompoundHandler::RTCPPacket::APP
APPPacket APP
Definition: rtcppkt.h:321
RTCPCompoundHandler::RTCPPacket::fh
RTCPFixedHeader fh
Fixed RTCP header.
Definition: rtcppkt.h:311
RTCPReceiverInfo::getCumulativePacketLost
uint32 getCumulativePacketLost() const
Definition: rtcppkt.h:398
RTCPSenderInfo::getPacketCount
uint32 getPacketCount() const
Get count of sent data packets.
Definition: rtcppkt.h:493
RTCPSenderInfo::getNTPTimestampInt
uint32 getNTPTimestampInt() const
Get integer part of the NTP timestamp of this packet.
Definition: rtcppkt.h:474
SDESItemTypeTOOL
Application or tool.
Definition: rtcppkt.h:73
RTCPSenderInfo::~RTCPSenderInfo
~RTCPSenderInfo()
Definition: rtcppkt.h:466
RTCPSenderInfo::getOctetCount
uint32 getOctetCount() const
Definition: rtcppkt.h:497
RTCPCompoundHandler::ReceiverInfo::fractionLost
uint8 fractionLost
packet fraction lost.
Definition: rtcppkt.h:111
RTCPCompoundHandler::SenderInfo::NTPMSW
uint32 NTPMSW
NTP timestamp higher octets.
Definition: rtcppkt.h:152
SDESItemTypeEMAIL
EMAIL address of the user.
Definition: rtcppkt.h:70
RTCPCompoundHandler::SenderInfo::NTPLSW
uint32 NTPLSW
NTP timestamp lower octets.
Definition: rtcppkt.h:153
SDESItemType
SDESItemType
SDES items that may be carried in a Source DEScription RTCP packet.
Definition: rtcppkt.h:65
RTCPCompoundHandler::ReceiverInfo::dlsr
uint32 dlsr
delay since last sender report.
Definition: rtcppkt.h:117
RTCPReceiverInfo::getDelayLastSR
uint32 getDelayLastSR() const
Get the delay between the last SR packet received and the transmission of this report.
Definition: rtcppkt.h:441
RTCPCompoundHandler::RTCPPacket::SR
SendReport SR
Definition: rtcppkt.h:317
RTCPCompoundHandler::SendReport::sinfo
SenderInfo sinfo
actual sender info.
Definition: rtcppkt.h:167
RTCPCompoundHandler::SendReport::ssrc
uint32 ssrc
source identifier.
Definition: rtcppkt.h:166
RTCPCompoundHandler::BYEPacket::ssrc
uint32 ssrc
ssrc identifier of source leaving.
Definition: rtcppkt.h:204
SDESItemTypeLOC
Location where the user is.
Definition: rtcppkt.h:72
RTCPCompoundHandler::RecvReport
raw structure of the source and every receiver report in an SR or RR RTCP packet. ...
Definition: rtcppkt.h:138
RTCPCompoundHandler::SDESChunk::ssrc
uint32 ssrc
SSRC identifer from sender.
Definition: rtcppkt.h:193