Public Member Functions | Private Member Functions | Private Attributes

RTCP_BYE_Packet Class Reference

The BYE RTCP packet is sent by a party when leaving an RTP session. More...

#include <RTCP_Packet.h>

Inheritance diagram for RTCP_BYE_Packet:
Inheritance graph
[legend]
Collaboration diagram for RTCP_BYE_Packet:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 RTCP_BYE_Packet (ACE_UINT32 *srcList, unsigned char length, const char *text=0)
 RTCP_BYE_Packet (char *buffer, int *len)
 Constructor for incoming BYE RTCP packets.
virtual ~RTCP_BYE_Packet (void)
 Destructor.
unsigned int packet_size (void)
 Returns the size of the packet in bytes.
void ssrc_list (ACE_UINT32 **ssrc_list, unsigned char &length)
const char * reason (void)
 Returns the reason for leaving the session.
void dump (void)
 Prints the contents of the packet.

Private Member Functions

void build_packet ()
 Used to create the byte representation of the RTCP packet.

Private Attributes

ACE_UINT32 * ssrc_list_
 List of synchronization source ids that are leaving the session.
unsigned char ssrc_list_length_
 The number of ssrc's that are leaving the session (1 for non-mixers).
char reason_ [256]
 An optional reason for leaving the session.
unsigned char reason_length_
 The number of bytes in the reason for leaving the session.

Detailed Description

The BYE RTCP packet is sent by a party when leaving an RTP session.

Definition at line 85 of file RTCP_Packet.h.


Constructor & Destructor Documentation

RTCP_BYE_Packet::RTCP_BYE_Packet ( ACE_UINT32 *  srcList,
unsigned char  length,
const char *  text = 0 
)

Constructor for outgoing BYE RTCP packets. Takes a synchronization source id list, the list length (1 for non-mixers), and an optional reason for leaving the session.

Definition at line 75 of file RTCP_Packet.cpp.

{
  this->chd_.ver_ = 2;
  this->chd_.count_ = length;
  this->chd_.pt_ = RTCP_PT_BYE;

  if (length)
    {
      ACE_NEW (this->ssrc_list_,
               ACE_UINT32[length]);

      this->ssrc_list_length_ = length;

      for (int i=0; i<length; i++)
        this->ssrc_list_[i] = ssrc_list[i];
    }

  // Optional - if there is a reason for leaving, store it.
  // The reason is padded with extra zeros because the packet must
  // end on an even 32-bit boundary.
  ACE_OS::memset(this->reason_, 0, sizeof(this->reason_));
  if (text)
    {
      size_t text_length = ACE_OS::strlen(text);
      ACE_OS::memcpy(this->reason_, text, text_length);
      this->reason_length_ = static_cast<unsigned char> (text_length);
    }
  else
    this->reason_length_ = 0;

  // Set the packet length
  this->chd_.length_ = static_cast<ACE_UINT16> (this->chd_.count_ + (this->reason_length_+1)/4);
  if ((this->reason_length_+1)%4)
    this->chd_.length_++;

  this->packet_data_ = 0;
}

RTCP_BYE_Packet::RTCP_BYE_Packet ( char *  buffer,
int *  len 
)

Constructor for incoming BYE RTCP packets.

Definition at line 117 of file RTCP_Packet.cpp.

                 : RTCP_Packet(buffer)
{
  unsigned int index = 0;
  unsigned int j;

  // The common part of the header is initialized in the parent.
  index=4;

  ACE_NEW (this->ssrc_list_,
           ACE_UINT32[this->chd_.count_]);
  this->ssrc_list_length_ = this->chd_.count_;

  // Store the source ids of the sources leaving the session
  for (j=0; j<this->chd_.count_; j++)
    {
      this->ssrc_list_[j] = ACE_NTOHL(*(ACE_UINT32*)&buffer[index]);
      index+=4;
    }

  // Optional - store the reason for leaving
  unsigned int temp = this->chd_.length_; // Borland reports a warning on the
                                          // following line with out this.
  ACE_OS::memset(this->reason_, 0, sizeof(this->reason_));
  if (temp > this->chd_.count_)
    {
      this->reason_length_ = buffer[index];
      index++;
      ACE_OS::memcpy(this->reason_, &buffer[index], this->reason_length_);
      index+=this->reason_length_;

    }
  else
    this->reason_length_ = 0;

  // Decrement the length by the size of this message. This is necessary
  // because multiple RTCP packets may be contained in a single UDP packet.
  *len-=(chd_.length_+1)*4;

  this->packet_data_ = 0;
}

RTCP_BYE_Packet::~RTCP_BYE_Packet ( void   )  [virtual]

Destructor.

Definition at line 161 of file RTCP_Packet.cpp.

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


Member Function Documentation

void RTCP_BYE_Packet::build_packet ( void   )  [private, virtual]

Used to create the byte representation of the RTCP packet.

Implements RTCP_Packet.

Definition at line 208 of file RTCP_Packet.cpp.

{
  unsigned int index;
  unsigned int i;

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

  ACE_NEW (this->packet_data_,
           char[this->packet_size()]);

  index = 0;
  this->packet_data_[index] = static_cast<char> ((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]) = ACE_HTONS(this->chd_.length_);
  index+=2;

  for (i=0; i<this->chd_.count_; i++)
    {
      *((ACE_UINT32*)&this->packet_data_[index]) = ACE_HTONL(this->ssrc_list_[i]);
      index+=4;
    }

  if (this->reason_)
    {
      this->packet_data_[index] = this->reason_length_;
      index++;
      ACE_OS::memcpy(&this->packet_data_[index], this->reason_, this->reason_length_);
      index += this->reason_length_;
      while (index < this->packet_size())
        {
          this->packet_data_[index] = 0;
          index ++;
        }
    }
}

void RTCP_BYE_Packet::dump ( void   ) 

Prints the contents of the packet.

Definition at line 250 of file RTCP_Packet.cpp.

{
  ACE_DEBUG ((LM_DEBUG,
              "\nRTCP_BYE_Packet:: from ssrc(s) "));
  for (int i=0; i< this->ssrc_list_length_; i++)
    ACE_DEBUG ((LM_DEBUG,
                "%u ",
                this->ssrc_list_[i]));
  ACE_DEBUG ((LM_DEBUG,
              "\n    Reason '%s'\n",
              this->reason_));
}

unsigned int RTCP_BYE_Packet::packet_size ( void   )  [virtual]

Returns the size of the packet in bytes.

Implements RTCP_Packet.

Definition at line 172 of file RTCP_Packet.cpp.

{
  ACE_UINT16 size = static_cast<ACE_UINT16> ((1+chd_.count_) * 4);

  if (this->reason_length_ > 0)
    {
      size += this->reason_length_ + 1;
      if (size%4)
        size += 4 - size%4; // pad with zeros to even 32 bit bound
    }

  return size;
}

const char * RTCP_BYE_Packet::reason ( void   ) 

Returns the reason for leaving the session.

Definition at line 198 of file RTCP_Packet.cpp.

{
  ACE_CString reason = (const char *)this->reason_;

  return reason.c_str();
}

void RTCP_BYE_Packet::ssrc_list ( ACE_UINT32 **  ssrc_list,
unsigned char &  length 
)

Returns a pointer to a local list of synchronization source ids that are leaving the session.

Definition at line 189 of file RTCP_Packet.cpp.

{
  *ssrc_list = this->ssrc_list_;
  length = this->ssrc_list_length_;
}


Member Data Documentation

char RTCP_BYE_Packet::reason_[256] [private]

An optional reason for leaving the session.

Definition at line 127 of file RTCP_Packet.h.

unsigned char RTCP_BYE_Packet::reason_length_ [private]

The number of bytes in the reason for leaving the session.

Definition at line 130 of file RTCP_Packet.h.

ACE_UINT32* RTCP_BYE_Packet::ssrc_list_ [private]

List of synchronization source ids that are leaving the session.

Definition at line 121 of file RTCP_Packet.h.

unsigned char RTCP_BYE_Packet::ssrc_list_length_ [private]

The number of ssrc's that are leaving the session (1 for non-mixers).

Definition at line 124 of file RTCP_Packet.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines