📄 rtcp_packet.cpp
字号:
size += 4 - size%4; // pad with zeros to even 32 bit bound
cp = cp->next_;
}
chd_.length_ = size/4 - 1;
return size;
}
//==============================================================================
void
RTCP_SDES_Packet::build_packet(void)
{
sdesChunk_t *cp; // pointer to chunk
sdesItem_t *ip; // pointer to item
int index, i;
if (this->packet_data_)
delete this->packet_data_;
ACE_NEW (this->packet_data_,
char[this->packet_size()]);
index = 0;
this->packet_data_[index] = (chd_.ver_ << 6) | (chd_.pad_ << 5) | chd_.count_;
index++;
this->packet_data_[index] = chd_.pt_;
index++;
*((ACE_UINT16*)&this->packet_data_[index]) = htons(chd_.length_);
index+=2;
cp = this->chunk_;
while (cp)
{
*((ACE_UINT32*)&this->packet_data_[index]) = htonl(cp->ssrc_);
index+=4;
ip = cp->item_;
while (ip && (ip->type_ != 0))
{
this->packet_data_[index] = ip->type_;
index++;
if (ip->type_ != RTCP_SDES_PRIV)
{
this->packet_data_[index] = ip->info_.standard_.length_;
index++;
for (i=0; i<ip->info_.standard_.length_; i++)
{
this->packet_data_[index] = ip->info_.standard_.data_[i];
index++;
}
}
else
{
this->packet_data_[index] = ip->info_.priv_.name_length_;
index++;
this->packet_data_[index] = ip->info_.priv_.data_length_;
index++;
for (i=0; i<ip->info_.priv_.name_length_; i++)
{
this->packet_data_[index] = ip->info_.priv_.name_[i];
index++;
}
for (i=0; i<ip->info_.priv_.data_length_; i++)
{
this->packet_data_[index] = ip->info_.priv_.data_[i];
index++;
}
}
ip = ip->next_;
}
this->packet_data_[index] = 0;
index++;
i=1;
while ((index)%4)
{ // pad chunk with zeros to 32 bit bound
this->packet_data_[index] = 0;
index++;
i++;
}
// Store the number of bytes added. TODO: do we need this
// this->packet_data_[index - 1] = i;
cp = cp->next_;
}
}
void
RTCP_SDES_Packet::dump (void)
{
sdesItem_t *ip;
ACE_DEBUG ((LM_DEBUG,
"\nRTCP_SDES_Packet:: "));
if (this->num_chunks_ != 1)
{
ACE_DEBUG ((LM_DEBUG,
"Mixers not currently supported.\n"));
return;
}
ACE_DEBUG ((LM_DEBUG,
"from ssrc %u\n",
this->chunk_->ssrc_));
// Loop through all of the items.
ip = this->chunk_->item_;
while (ip)
{
// If there is no data to store, continue.
if (ip->info_.standard_.length_ == 0)
{
ip = ip->next_;
continue;
}
switch (ip->type_)
{
case RTCP_SDES_END:
break;
case RTCP_SDES_CNAME:
ACE_DEBUG ((LM_DEBUG,
" CNAME '%s'\n",
ip->info_.standard_.data_));
break;
case RTCP_SDES_NAME:
ACE_DEBUG ((LM_DEBUG,
" NAME '%s'\n",
ip->info_.standard_.data_));
break;
case RTCP_SDES_EMAIL:
ACE_DEBUG ((LM_DEBUG,
" EMAIL '%s'\n",
ip->info_.standard_.data_));
break;
case RTCP_SDES_PHONE:
ACE_DEBUG ((LM_DEBUG,
" PHONE '%s'\n",
ip->info_.standard_.data_));
break;
case RTCP_SDES_LOC:
ACE_DEBUG ((LM_DEBUG,
" LOC '%s'\n",
ip->info_.standard_.data_));
break;
case RTCP_SDES_TOOL:
ACE_DEBUG ((LM_DEBUG,
" TOOL '%s'\n",
ip->info_.standard_.data_));
break;
case RTCP_SDES_NOTE:
ACE_DEBUG ((LM_DEBUG,
" NOTE '%s'\n",
ip->info_.standard_.data_));
break;
case RTCP_SDES_PRIV:
ACE_DEBUG ((LM_DEBUG,
" '%s' '%s'\n",
ip->info_.priv_.name_,
ip->info_.priv_.data_));
break;
}
ip = ip->next_;
}
}
RTCP_SR_Packet::RTCP_SR_Packet(ACE_UINT32 ssrc,
ACE_UINT32 ntp_ts_msw,
ACE_UINT32 ntp_ts_lsw,
ACE_UINT32 timestamp,
ACE_UINT32 packets_sent,
ACE_UINT32 octets_sent,
RR_Block *blocks)
{
RR_Block *block_ptr= 0;
chd_.count_ = 0;
chd_.ver_ = 2;
chd_.pt_ = RTCP_PT_SR;
this->ssrc_ = ssrc;
this->ntp_ts_msw_ = ntp_ts_msw;
this->ntp_ts_lsw_ = ntp_ts_lsw;
this->rtp_ts_ = timestamp;
this->psent_ = packets_sent;
this->osent_ = octets_sent;
this->rr_ = blocks;
block_ptr = blocks;
while (block_ptr)
{
chd_.count_++;
// Can only have 31 receiver reports
if (this->chd_.count_ == 31)
{
block_ptr->next_ = 0;
break;
}
block_ptr = block_ptr->next_;
}
this->chd_.length_ = 6 + 6*chd_.count_; //+profile specific extensions ??
this->packet_data_ = 0;
}
//==============================================================================
RTCP_SR_Packet::RTCP_SR_Packet (char* buffer,
int *len)
: RTCP_Packet (buffer)
{
unsigned int i = 0;
RR_Block *local_block_ptr = 0;
this->rr_ = 0;
// The common part of the header is initialized in the parent.
i=4;
this->ssrc_ = ntohl(*(ACE_UINT32*)&buffer[i]);
i+=4;
this->ntp_ts_msw_ = ntohl(*(ACE_UINT32*)&buffer[i]);
i+=4;
this->ntp_ts_lsw_ = ntohl(*(ACE_UINT32*)&buffer[i]);
i+=4;
this->rtp_ts_ = ntohl(*(ACE_UINT32*)&buffer[i]);
i+=4;
this->psent_ = ntohl(*(ACE_UINT32*)&buffer[i]);
i+=4;
this->osent_ = ntohl(*(ACE_UINT32*)&buffer[i]);
i+=4;
for (unsigned int j=0; j<this->chd_.count_; j++)
{
if (j==0)
{
ACE_NEW (local_block_ptr,
RR_Block);
this->rr_ = local_block_ptr;
}
else
{
ACE_NEW (local_block_ptr->next_,
RR_Block);
local_block_ptr = local_block_ptr->next_;
}
local_block_ptr->next_ = 0;
local_block_ptr->ssrc_ = ntohl(*(ACE_UINT32*)&buffer[i]);
i+=4;
ACE_UINT32 temp = ntohl(*(ACE_UINT32*)&buffer[i]);
local_block_ptr->fraction_ = (temp&0xff000000) >> 24;
local_block_ptr->lost_ = temp & 0x00ffffff;
i+=4;
local_block_ptr->last_seq_ = ntohl(*(ACE_UINT32*)&buffer[i]);
i+=4;
local_block_ptr->jitter_ = ntohl(*(ACE_UINT32*)&buffer[i]);
i+=4;
local_block_ptr->lsr_ = ntohl(*(ACE_UINT32*)&buffer[i]);
i+=4;
local_block_ptr->dlsr_ = ntohl(*(ACE_UINT32*)&buffer[i]);
i+=4;
}
*len-=(this->chd_.length_+1)*4;
this->packet_data_ = 0;
}
//==============================================================================
RTCP_SR_Packet::~RTCP_SR_Packet(void)
{
RR_Block *prev;
if (this->rr_)
{
while (this->rr_)
{
prev = this->rr_;
this->rr_ = this->rr_->next_;
delete prev;
}
}
if (this->packet_data_)
delete []this->packet_data_;
}
//==============================================================================
unsigned int RTCP_SR_Packet::packet_size (void)
{
ACE_UINT16 size = (2+chd_.count_*6) * 4; // + profile specific extensions ?
size += 20; // the first line is the same as RR; 20 more bytes for SR
return size;
}
//==============================================================================
void RTCP_SR_Packet::build_packet(void)
{
int index = 0;
RR_Block *local_block_ptr;
if (this->packet_data_)
delete []this->packet_data_;
ACE_NEW (this->packet_data_,
char[this->packet_size()]);
this->packet_data_[index] = (this->chd_.ver_ << 6) | (this->chd_.pad_ << 5) | this->chd_.count_;
index++;
this->packet_data_[index] = this->chd_.pt_;
index++;
*((ACE_UINT16*)&this->packet_data_[index]) = htons(this->chd_.length_);
index+=2;
*((ACE_UINT32*)&this->packet_data_[index]) = htonl(this->ssrc_);
index+=4;
*((ACE_UINT32*)&this->packet_data_[index]) = htonl(this->ntp_ts_msw_);
index+=4;
*((ACE_UINT32*)&this->packet_data_[index]) = htonl(this->ntp_ts_lsw_);
index+=4;
*((ACE_UINT32*)&this->packet_data_[index]) = htonl(this->rtp_ts_);
index+=4;
*((ACE_UINT32*)&this->packet_data_[index]) = htonl(this->psent_);
index+=4;
*((ACE_UINT32*)&this->packet_data_[index]) = htonl(this->osent_);
index+=4;
local_block_ptr = this->rr_;
while (local_block_ptr)
{
*((ACE_UINT32*)&this->packet_data_[index]) = htonl(local_block_ptr->ssrc_);
index+=4;
ACE_UINT32 temp = htonl((local_block_ptr->fraction_&0xff) << 24) &
local_block_ptr->lost_;
*((ACE_UINT32*)&this->packet_data_[index]) = temp;
index+=4;
*((ACE_UINT32*)&this->packet_data_[index]) = htonl(local_block_ptr->last_seq_);
index+=4;
*((ACE_UINT32*)&this->packet_data_[index]) = htonl(local_block_ptr->jitter_);
index+=4;
*((ACE_UINT32*)&this->packet_data_[index]) = htonl(local_block_ptr->lsr_);
index+=4;
*((ACE_UINT32*)&this->packet_data_[index]) = htonl(local_block_ptr->dlsr_);
index+=4;
local_block_ptr = local_block_ptr->next_;
}
}
void
RTCP_SR_Packet::dump (void)
{
RR_Block *b = this->rr_;
int count = 1;
ACE_DEBUG ((LM_DEBUG,
"\nRTCP_SR_Packet:: from %u - %d rr blocks follow.\n",
this->ssrc_,
this->chd_.count_));
ACE_DEBUG ((LM_DEBUG,
" NTP(sec) %u.%u; RTP ts %u\n",
this->ntp_ts_msw_,
this->ntp_ts_lsw_,
this->rtp_ts_));
ACE_DEBUG ((LM_DEBUG,
" packets sent %u; octets sent %u\n",
this->psent_,
this->osent_));
while (b)
{
ACE_DEBUG ((LM_DEBUG,
" Block %d: ssrc %u; frac %u; lost %u; last seq %u\n",
count,
b->ssrc_,
b->fraction_,
b->lost_,
b->last_seq_));
ACE_DEBUG ((LM_DEBUG,
" jitter %u; lsr %u; dlsr %u;\n",
b->jitter_,
b->lsr_,
b->dlsr_));
b = b->next_;
++count;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -