⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtcp_packet.cpp

📁 这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用于网络游戏医学图像网关的高qos要求.更详细的内容可阅读相应的材料
💻 CPP
📖 第 1 页 / 共 3 页
字号:
                              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_RR_Packet::dump (void)
{
  RR_Block *b = this->rr_;
  int count = 1;

  ACE_DEBUG ((LM_DEBUG,
              "\nRTCP_RR_Packet:: from %u - %d rr blocks follow.\n",
              this->ssrc_,
              this->chd_.count_));

  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;
    }
}


RTCP_SDES_Packet::RTCP_SDES_Packet(void) :
                   RTCP_Packet ()
{
  this->chd_.pt_ = RTCP_PT_SDES;
  this->chunk_ = 0;
  this->packet_data_ = 0;
  this->num_chunks_ = 0;
//  this->num_items_ = 0;
}

//==============================================================================

RTCP_SDES_Packet::RTCP_SDES_Packet(char* buffer, int *len):
                   RTCP_Packet (buffer)
{
  unsigned int i;
  sdesChunk_t *cp = 0; // pointer to chunk
  sdesItem_t *ip = 0; // pointer to item

  // The common part of the control packet header is processed
  // in the parent. It is 4 bytes long.

  i=4;
  for (unsigned int j=0; j<this->chd_.count_; j++)
    {
      if (j==0)
        {
          ACE_NEW (this->chunk_,
                   sdesChunk_t);
          cp = this->chunk_;

          this->num_chunks_ = 1;
        }
      else
        {
          ACE_NEW (cp->next_,
                   sdesChunk_t);
          cp = cp->next_;

          this->num_chunks_++;
        }
      cp->next_ = 0;
      cp->item_ = 0;
      cp->ssrc_ = ntohl(*(ACE_UINT32*)&buffer[i]);
      i+=4;

      while (buffer[i]!=RTCP_SDES_END)
        {
          if (!cp->item_)
            {
              ACE_NEW (cp->item_,
                       sdesItem_t);
              ip = cp->item_;

//              this->num_items_ = 1;
            }
          else
            {
              ACE_NEW (ip->next_,
                       sdesItem_t);
              ip = ip->next_;

//              this->num_items_++;
            }
          ip->next_ = 0;
          ip->type_ = buffer[i];
          i++;
          if (ip->type_ != RTCP_SDES_PRIV)
            {
              ip->info_.standard_.length_ = buffer[i];
              i++;
              ACE_NEW (ip->info_.standard_.data_,
                       char[ip->info_.standard_.length_+1]);
              memcpy(ip->info_.standard_.data_,
                     &buffer[i],
                     ip->info_.standard_.length_);
              ip->info_.standard_.data_[ip->info_.standard_.length_] = 0;
              i+=ip->info_.standard_.length_;
            }
          else
            {
              ip->info_.priv_.name_length_ = buffer[i];
              i++;
              ip->info_.priv_.data_length_ = buffer[i];
              i++;
              ACE_NEW (ip->info_.priv_.name_,
                       char[ip->info_.priv_.name_length_+1]);
              memcpy(ip->info_.priv_.name_,
                     &buffer[i],
                     ip->info_.priv_.name_length_);
              ip->info_.priv_.name_[ip->info_.priv_.name_length_] = 0;
              i+=ip->info_.priv_.name_length_;
              ACE_NEW (ip->info_.priv_.data_,
                       char[ip->info_.priv_.data_length_+1]);
              memcpy(ip->info_.priv_.data_,
                     &buffer[i],
                     ip->info_.priv_.data_length_);
              ip->info_.priv_.data_[ip->info_.priv_.data_length_] = 0;
              i+=ip->info_.priv_.data_length_;
            }
        }
        i++; // each chunk ends with a zero (END) item
        // each chunk must end on an even 32 bit boundary
        while (i%4) i++;
    }

  *len-=(this->chd_.length_+1)*4;

  this->packet_data_ = 0;
}

//==============================================================================

RTCP_SDES_Packet::~RTCP_SDES_Packet(void)
{
  sdesChunk_t *cp; // pointer to chunk
  sdesChunk_t *cpprev;
  sdesItem_t *ip; // pointer to item
  sdesItem_t *ipprev;

  cp = this->chunk_;
  while (cp)
    {
      ip = cp->item_;
      while (ip)
        {
          ipprev = ip;
          ip = ip->next_;
          if (ipprev->type_ != RTCP_SDES_PRIV)
            {
              delete []ipprev->info_.standard_.data_;
            }
          else
            {
              delete []ipprev->info_.priv_.name_;
              delete []ipprev->info_.priv_.data_;
            }

          delete ipprev;
        }
      cpprev = cp;
      cp = cp->next_;
      delete cpprev;
    }

  if (this->packet_data_)
    delete []this->packet_data_;
}

//==============================================================================

void
RTCP_SDES_Packet::add_chunk(ACE_UINT32 ssrc)
{
  sdesChunk_t *cp; // pointer to chunk

  // If this is the first chunk.
  if (chd_.count_ == 0)
    {
      ACE_NEW (this->chunk_,
               sdesChunk_t);
      this->chunk_->next_ = 0;
      this->chunk_->item_ = 0;
      cp = this->chunk_;
    }
  else
    {
      cp = this->chunk_;
      while (cp->next_)
        cp = cp->next_;

      ACE_NEW (cp->next_,
               sdesChunk_t);
      cp = cp->next_;
      cp->next_ = 0;
      cp->item_ = 0;
    }
  cp->ssrc_ = ssrc;    // store the source
  chd_.count_++;       // increment the source count
}

//==============================================================================

void
RTCP_SDES_Packet::add_item (ACE_UINT32 ssrc,
                            unsigned char type,
                            unsigned char length,
                            const char *data)
{
  sdesChunk_t *cp; // pointer to chunk
  sdesItem_t *ip; // pointer to item

  if (this->chunk_ == 0)
    {
      this->add_chunk(ssrc);
    }

  cp = this->chunk_;

  while (cp != 0)
    {
      if (cp->ssrc_ == ssrc)
        {
          break;
        }

      if (!cp->next_)
        {
          this->add_chunk(ssrc);
          cp = cp->next_;
          break;
        }

      cp = cp->next_;
    }

  ip = cp->item_;

  if (ip == 0)
    {
      ACE_NEW (cp->item_,
               sdesItem_t);

      ip = cp->item_;
      ip->next_= 0;
    }
  else
    {
      while (ip->next_)
        {
          ip = ip->next_;
        }

      ACE_NEW (ip->next_,
               sdesItem_t);

      ip = ip->next_;
      ip->next_ = 0;
    }

  ip->type_ = type;
  
  ip->info_.standard_.length_ = length;

  ACE_NEW (ip->info_.standard_.data_,
           char[length]);

  memcpy(ip->info_.standard_.data_, data, length);
}

//==============================================================================

void
RTCP_SDES_Packet::add_priv_item (ACE_UINT32 ssrc,
                                 unsigned char nameLength, 
                                 const char* name,
                                 unsigned char dataLength, 
                                 const char* data)
{
  sdesChunk_t *cp; // pointer to chunk
  sdesItem_t *ip; // pointer to item

  if (this->chunk_ == 0)
    {
      this->add_chunk(ssrc);
    }

  cp = this->chunk_;

  while (cp != 0)
    {
      if (cp->ssrc_ == ssrc)
        {
          break;
        }

      if (!cp->next_)
        {
          this->add_chunk(ssrc);
          cp = cp->next_;
          break;
        }

      cp = cp->next_;
    }

  ip = cp->item_;

  if (ip == 0)
    {
      ACE_NEW (cp->item_,
               sdesItem_t);

      ip = cp->item_;
      ip->next_ = 0;
    }
  else
    {
      while (ip->next_)
        {
          ip = ip->next_;
        }

      ACE_NEW (ip->next_,
               sdesItem_t);

      ip = ip->next_;
      ip->next_ = 0;
    }

  ip->type_ = RTCP_SDES_PRIV;

  ip->info_.priv_.name_length_ = nameLength;
  ip->info_.priv_.data_length_ = dataLength;

  ACE_NEW (ip->info_.priv_.name_,
           char[nameLength]);

  ACE_NEW (ip->info_.priv_.data_,
           char[dataLength]);

  memcpy(ip->info_.priv_.name_, name, nameLength);
  memcpy(ip->info_.priv_.data_, data, dataLength);
}

//==============================================================================

unsigned int
RTCP_SDES_Packet::packet_size(void)
{
  int size;
  sdesChunk_t *cp; // pointer to chunk
  sdesItem_t *ip; // pointer to item

  // Determine the size of the packet.
  size = 4;  // size of common header data in octets

  cp = this->chunk_;
  while (cp)
    {
      size += 4; // size of ssrc
      ip = cp->item_;

      while (ip && (ip->type_ != 0))
        {
          if (ip->type_ != RTCP_SDES_PRIV)
            {
              size += 2 + ip->info_.standard_.length_;  // size of item
            }
          else
            {
              size += 3 + ip->info_.priv_.name_length_ + ip->info_.priv_.data_length_;
            }
          ip = ip->next_;
        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -