Public Member Functions | Private Attributes

RTP_Packet Class Reference

This class encapsulates all the necessary information to break down or build up an RTP data packet as well as operations to access all data items in the packet. More...

#include <RTP.h>

List of all members.

Public Member Functions

 RTP_Packet (char *buffer, int length)
 Constructor for incoming RTP packets.
 RTP_Packet (unsigned char padding, unsigned char marker, unsigned char payloadType, ACE_UINT32 sequenceNumber, ACE_UINT32 timeStamp, ACE_UINT32 syncSource, unsigned char contribSourcCount, ACE_UINT32 contribSourceList[], char *data, ACE_UINT16 dataSize)
 Constructor for outgoing RTP packets.
 ~RTP_Packet (void)
 Destructor.
ACE_UINT16 packet_size (void)
 Returns the size of the RTP packet in bytes.
ACE_UINT16 payload_size (void)
 Returns the size of the payload in bytes.
void get_frame_info (TAO_AV_frame_info *frame_info)
 Populates the passed in frame_info.
int is_valid (void)
 Returns 1 if packet is valid and 0 if not.
unsigned int ver (void)
 Returns the RTP version of the packet.
unsigned int pad (void)
 Returns 1 if the padding bit is set, 0 if not.
unsigned int ext (void)
 Returns 1 if the header extension bit is set, 0 if not.
unsigned int ext_bytes (void)
 Returns the number of bytes in the header extension or 0 if no extension.
unsigned int cc (void)
unsigned int mrk (void)
 Returns 1 if the marker bit is set, 0 if not.
unsigned int pt (void)
 Returns the payload type of the packet.
ACE_UINT16 sn (void)
 Returns the sequence number of the packet.
ACE_UINT32 ts (void)
 Returns the timestamp of the packet.
ACE_UINT32 ssrc (void)
 Returns the synchronization source id of the packet.
void get_csrc_list (ACE_UINT32 **csrc_list, ACE_UINT16 &length)
void get_payload (char **payload, ACE_UINT16 &size)
void get_packet_data (char **packet, ACE_UINT16 &size)

Private Attributes

char packet_ [RTP_MTU]
 Local buffer to hold the RTP packet.
ACE_UINT32 host_byte_order_csrc_list_ [15]
char host_byte_order_payload_ [RTP_MTU]
 Local buffer to hold the payload with the values stored in host byte order.
unsigned int extension_bytes_
 The number of bytes in the header extension - 0 if no extension.
ACE_UINT16 packet_size_
 The size of the overall data packet.
ACE_UINT16 payload_size_
 The size of the payload portion of the packet.

Detailed Description

This class encapsulates all the necessary information to break down or build up an RTP data packet as well as operations to access all data items in the packet.

Definition at line 254 of file RTP.h.


Constructor & Destructor Documentation

RTP_Packet::RTP_Packet ( char *  buffer,
int  length 
)

Constructor for incoming RTP packets.

Definition at line 49 of file RTP.cpp.

{
  // skip the standard header info
  int index = 12;

  ACE_OS::memcpy(this->packet_, buffer, length);

  for (int j=0; j<(int)this->cc(); j++)
    {
      this->host_byte_order_csrc_list_[j] = ntohl(*(ACE_UINT32*)&buffer[index]);
      index+=4;
    }

  // ignore the header extension if there is one
  if (this->ext())
    {
      index+=2;
      int extension_data_size = ntohs(*(ACE_UINT16*)&buffer[index]);
      index+=2;
      index+=extension_data_size;

      this->extension_bytes_ = 4 + extension_data_size;
    }
  else
    this->extension_bytes_ = 0;

  this->packet_size_ = static_cast<ACE_UINT16> (length);
  this->payload_size_ = static_cast<ACE_UINT16> (length-index);

  // This is necessary only for payload types that have 16 bit values to correct
  //  the network byte ordering.
  if ((this->pt() == RTP_PT_L16_OTHER) ||
      (this->pt() == RTP_PT_L16_STEREO) ||
      (this->pt() == RTP_PT_L16_MONO))
    {
      for (int i=0; i < payload_size_; i+=2)
        {
          *(ACE_UINT16*)&this->host_byte_order_payload_[i] = ntohs(*(ACE_UINT16*)&this->packet_[index]);
          index+=2;
        }
    }
  else
    for (int i=0; i<this->payload_size_; i++)
      {
        this->host_byte_order_payload_[i] = this->packet_[index];
        index++;
      }
}

RTP_Packet::RTP_Packet ( unsigned char  padding,
unsigned char  marker,
unsigned char  payloadType,
ACE_UINT32  sequenceNumber,
ACE_UINT32  timeStamp,
ACE_UINT32  syncSource,
unsigned char  contribSourcCount,
ACE_UINT32  contribSourceList[],
char *  data,
ACE_UINT16  dataSize 
)

Constructor for outgoing RTP packets.

RTP_Packet::~RTP_Packet ( void   ) 

Destructor.

Definition at line 178 of file RTP.cpp.

{
}


Member Function Documentation

unsigned int RTP_Packet::cc ( void   ) 

Returns the contributing source count. This should only be non-zero for mixers.

Definition at line 213 of file RTP.cpp.

{
  return ( this->packet_[0] & 0x0F ) ;
}

unsigned int RTP_Packet::ext ( void   ) 

Returns 1 if the header extension bit is set, 0 if not.

Definition at line 207 of file RTP.cpp.

{
  return ( this->packet_[0] & 0x10 ) >> 4;
}

unsigned int RTP_Packet::ext_bytes ( void   ) 

Returns the number of bytes in the header extension or 0 if no extension.

Definition at line 249 of file RTP.cpp.

{
  return this->extension_bytes_;
}

void RTP_Packet::get_csrc_list ( ACE_UINT32 **  csrc_list,
ACE_UINT16 &  length 
)

Returns a pointer to the local contributing source list and its length. This should be empty except for mixers. RTP_Packet retains ownership.

Definition at line 294 of file RTP.cpp.

{
  *csrc_list = this->host_byte_order_csrc_list_;
  length = static_cast<ACE_UINT16> (this->cc ());
}

void RTP_Packet::get_frame_info ( TAO_AV_frame_info frame_info  ) 

Populates the passed in frame_info.

Definition at line 255 of file RTP.cpp.

{
  frame_info->timestamp = this->mrk();
  frame_info->timestamp = this->ts();
  frame_info->ssrc = this->ssrc();
  frame_info->sequence_num = this->sn();
  frame_info->format = static_cast<CORBA::Octet> (this->pt());
}

void RTP_Packet::get_packet_data ( char **  packet,
ACE_UINT16 &  size 
)

Returns a pointer to the locally stored rtp packet and its size in bytes. RTP_Packet retains ownership.

Definition at line 308 of file RTP.cpp.

{
  *packet = this->packet_;
  length = this->packet_size_;
}

void RTP_Packet::get_payload ( char **  payload,
ACE_UINT16 &  size 
)

Returns a pointer to the locally stored payload and its size in bytes. The payload is returned in host byte order. RTP_Packet retains ownership.

Definition at line 301 of file RTP.cpp.

{
  *payload = this->host_byte_order_payload_ ;
  length = this->payload_size_;
}

int RTP_Packet::is_valid ( void   ) 

Returns 1 if packet is valid and 0 if not.

Definition at line 265 of file RTP.cpp.

{
  // taken from RFC 1889 - Appendix A.1

  // make sure the RTP version is correct
  if (this->ver() != RTP_VERSION)
    return 0;

  // make sure the payload type is not SR or RR
  if ((this->pt() == RTCP_PT_SR) || (this->pt() == RTCP_PT_RR))
    return 0;

  // if the p bit is set, the last octet of the packet must contain a valid
  // octet count, in particular, less than the total packet length minus
  // the header size.
  if (this->pad() != 0)
    if ((unsigned int)this->packet_[this->packet_size_] >=
        (this->packet_size_ - (12 + this->cc() + this->extension_bytes_)))
      return 0;

  // If there is an extension, it is ignored (taken care of in constructor)

  // The length of the packet must be consistent with CC and payload type (if
  // payloads have a known length)

  return 1;
}

unsigned int RTP_Packet::mrk ( void   ) 

Returns 1 if the marker bit is set, 0 if not.

Definition at line 219 of file RTP.cpp.

{
  return ( this->packet_[1] & 0x80 ) >> 7;
}

ACE_UINT16 RTP_Packet::packet_size ( void   ) 

Returns the size of the RTP packet in bytes.

Definition at line 183 of file RTP.cpp.

{
    return this->packet_size_;
}

unsigned int RTP_Packet::pad ( void   ) 

Returns 1 if the padding bit is set, 0 if not.

Definition at line 201 of file RTP.cpp.

{
  return ( this->packet_[0] & 0x20 ) >> 5;
}

ACE_UINT16 RTP_Packet::payload_size ( void   ) 

Returns the size of the payload in bytes.

Definition at line 189 of file RTP.cpp.

{
    return this->payload_size_;
}

unsigned int RTP_Packet::pt ( void   ) 

Returns the payload type of the packet.

Definition at line 225 of file RTP.cpp.

{
  return ( this->packet_[1] & 0x7F ) ;
}

ACE_UINT16 RTP_Packet::sn ( void   ) 

Returns the sequence number of the packet.

Definition at line 231 of file RTP.cpp.

{
  return ntohs(*(ACE_UINT16*)(&this->packet_[2])) ;
}

ACE_UINT32 RTP_Packet::ssrc ( void   ) 

Returns the synchronization source id of the packet.

Definition at line 243 of file RTP.cpp.

{
  return ntohl(*(ACE_UINT32*)(&this->packet_[8])) ;
}

ACE_UINT32 RTP_Packet::ts ( void   ) 

Returns the timestamp of the packet.

Definition at line 237 of file RTP.cpp.

{
  return ntohl(*(ACE_UINT32*)(&this->packet_[4])) ;
}

unsigned int RTP_Packet::ver ( void   ) 

Returns the RTP version of the packet.

Definition at line 195 of file RTP.cpp.

{
  return ( this->packet_[0] & 0xC0 ) >> 6;
}


Member Data Documentation

unsigned int RTP_Packet::extension_bytes_ [private]

The number of bytes in the header extension - 0 if no extension.

Definition at line 345 of file RTP.h.

ACE_UINT32 RTP_Packet::host_byte_order_csrc_list_[15] [private]

Local buffer to hold the contributing source list with the values stored in host byte order.

Definition at line 339 of file RTP.h.

char RTP_Packet::host_byte_order_payload_[RTP_MTU] [private]

Local buffer to hold the payload with the values stored in host byte order.

Definition at line 342 of file RTP.h.

char RTP_Packet::packet_[RTP_MTU] [private]

Local buffer to hold the RTP packet.

Definition at line 335 of file RTP.h.

ACE_UINT16 RTP_Packet::packet_size_ [private]

The size of the overall data packet.

Definition at line 348 of file RTP.h.

ACE_UINT16 RTP_Packet::payload_size_ [private]

The size of the payload portion of the packet.

Definition at line 351 of file RTP.h.


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