📄 rtcppacket.cpp
字号:
#include <libc\assert.h>
#include <libc\sys\time.h>
#include <libc\string.h>
#include "vtypes.h"
#include "cpLog.h"
#include "rtpTypes.h"
#include "rtpTools.h"
#include "NtpTime.h"
#include "RtcpPacket.h"
/* ----------------------------------------------------------------- */
/* --- rtcp Packet Constructor ------------------------------------- */
/* ----------------------------------------------------------------- */
RtcpPacket::RtcpPacket ()
{
packetData = NULL;
// create memory allocation
packetAlloc = PACKETSIZE;
assert (packetAlloc < RTP_MTU);
packetData = new char[packetAlloc];
assert (packetData);
memset (packetData, 0, packetAlloc);
unusedSize = packetAlloc;
}
RtcpPacket::~RtcpPacket ()
{
if(packetData)
{
delete []packetData;
packetData = NULL;
}
}
/* --- Size and Locations ------------------------------------------ */
char* RtcpPacket::getPacketData ()
{
return packetData;
}
char* RtcpPacket::freeData ()
{
return packetData + (packetAlloc - unusedSize);
}
int RtcpPacket::allocData (int s)
{
if (unusedSize < s)
{
//cpLog (LOG_ERR, "RTCP: Out of allocated memory for RTCP packet");
return -1;
}
unusedSize -= s;
memset (freeData(), 0, s);
return s;
}
/* unused memory */
int RtcpPacket::getPacketAlloc ()
{
return packetAlloc;
}
int RtcpPacket::getUnused ()
{
return unusedSize;
}
void RtcpPacket::setTotalUsage (int size)
{
assert (size <= packetAlloc);
unusedSize = packetAlloc - size;
}
int RtcpPacket::getTotalUsage ()
{
return packetAlloc - unusedSize;
}
/* --- Packet Header functions ------------------------------------- */
int RtcpPacket::getVersion ()
{
RtcpHeader* header = reinterpret_cast < RtcpHeader* > (packetData);
return header->version;
}
int RtcpPacket::getPadbyteFlag ()
{
RtcpHeader* header = reinterpret_cast < RtcpHeader* > (packetData);
return header->padding;
}
int RtcpPacket::getCount ()
{
RtcpHeader* header = reinterpret_cast < RtcpHeader* > (packetData);
return header->count;
}
RtcpType RtcpPacket::getPayloadType ()
{
RtcpHeader* header = reinterpret_cast < RtcpHeader* > (packetData);
return static_cast < RtcpType > (header->type);
}
int RtcpPacket::getLength ()
{
RtcpHeader* header = reinterpret_cast < RtcpHeader* > (packetData);
// return ntohs(header->length);//主机字节顺序和网络自己顺序直接的转换<-1>
return header->length;
}
void RtcpPacket::printPacket ()
{
printBits (packetData, getTotalUsage());
// cerr << "\n-----------------------------------\n";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -