RTCP_SDES_Packet Class Reference

The Source Description packet is sent by all members of a session. At a minimum, the canonical name (or CNAME) is sent with each RTCP packet. Other items such as name, email, or location are included less frequently. More...

#include <RTCP_Packet.h>

Inheritance diagram for RTCP_SDES_Packet:

Inheritance graph
[legend]
Collaboration diagram for RTCP_SDES_Packet:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 RTCP_SDES_Packet (char *buffer, int *len)
 Constructor for incoming SDES packets.
 RTCP_SDES_Packet (void)
 Constructor for outgoing SDES packets.
virtual ~RTCP_SDES_Packet (void)
 Destructor.
void add_item (ACE_UINT32 ssrc, unsigned char type, unsigned char length, const char *data)
void add_priv_item (ACE_UINT32 ssrc, unsigned char nameLength, const char *name, unsigned char dataLength, const char *data)
unsigned int packet_size (void)
 Returns the size of the packet in bytes.
void dump (void)
 Prints the contents of the packet.
ACE_UINT32 ssrc (void)

Private Member Functions

void build_packet (void)
 Used to create the byte representation of the RTCP packet.
void add_chunk (ACE_UINT32 ssrc)
 Add a chunk to the packet.

Private Attributes

unsigned long num_chunks_
sdesChunk_tchunk_
 A linked list of chunks for this packet (only 1 for non-mixers).

Detailed Description

The Source Description packet is sent by all members of a session. At a minimum, the canonical name (or CNAME) is sent with each RTCP packet. Other items such as name, email, or location are included less frequently.

Definition at line 276 of file RTCP_Packet.h.


Constructor & Destructor Documentation

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

Constructor for incoming SDES packets.

Definition at line 464 of file RTCP_Packet.cpp.

References ACE_NEW, ACE_NTOHL, RTCP_Packet::chd_, RTCP_Common_Header::count_, sdesItem_s::info_, sdesChunk_s::item_, RTCP_Common_Header::length_, ACE_OS::memcpy(), sdesItem_s::next_, sdesChunk_s::next_, num_chunks_, RTCP_Packet::packet_data_, sdesItem_s::priv_, RTCP_SDES_END, RTCP_SDES_PRIV, sdesChunk_s::ssrc_, sdesItem_s::standard_, and sdesItem_s::type_.

00464                                                         :
00465                    RTCP_Packet (buffer)
00466 {
00467   unsigned int i;
00468   sdesChunk_t *cp = 0; // pointer to chunk
00469   sdesItem_t *ip = 0; // pointer to item
00470 
00471   // The common part of the control packet header is processed
00472   // in the parent. It is 4 bytes long.
00473 
00474   i=4;
00475   for (unsigned int j=0; j<this->chd_.count_; j++)
00476     {
00477       if (j==0)
00478         {
00479           ACE_NEW (this->chunk_,
00480                    sdesChunk_t);
00481           cp = this->chunk_;
00482 
00483           this->num_chunks_ = 1;
00484         }
00485       else
00486         {
00487           ACE_NEW (cp->next_,
00488                    sdesChunk_t);
00489           cp = cp->next_;
00490 
00491           this->num_chunks_++;
00492         }
00493       cp->next_ = 0;
00494       cp->item_ = 0;
00495       cp->ssrc_ = ACE_NTOHL(*(ACE_UINT32*)&buffer[i]);
00496       i+=4;
00497 
00498       while (buffer[i]!=RTCP_SDES_END)
00499         {
00500           if (!cp->item_)
00501             {
00502               ACE_NEW (cp->item_,
00503                        sdesItem_t);
00504               ip = cp->item_;
00505 
00506 //              this->num_items_ = 1;
00507             }
00508           else
00509             {
00510               ACE_NEW (ip->next_,
00511                        sdesItem_t);
00512               ip = ip->next_;
00513 
00514 //              this->num_items_++;
00515             }
00516           ip->next_ = 0;
00517           ip->type_ = buffer[i];
00518           i++;
00519           if (ip->type_ != RTCP_SDES_PRIV)
00520             {
00521               ip->info_.standard_.length_ = buffer[i];
00522               i++;
00523               ACE_NEW (ip->info_.standard_.data_,
00524                        char[ip->info_.standard_.length_+1]);
00525               ACE_OS::memcpy(ip->info_.standard_.data_,
00526                              &buffer[i],
00527                              ip->info_.standard_.length_);
00528               ip->info_.standard_.data_[ip->info_.standard_.length_] = 0;
00529               i+=ip->info_.standard_.length_;
00530             }
00531           else
00532             {
00533               ip->info_.priv_.name_length_ = buffer[i];
00534               i++;
00535               ip->info_.priv_.data_length_ = buffer[i];
00536               i++;
00537               ACE_NEW (ip->info_.priv_.name_,
00538                        char[ip->info_.priv_.name_length_+1]);
00539               ACE_OS::memcpy(ip->info_.priv_.name_,
00540                              &buffer[i],
00541                              ip->info_.priv_.name_length_);
00542               ip->info_.priv_.name_[ip->info_.priv_.name_length_] = 0;
00543               i+=ip->info_.priv_.name_length_;
00544               ACE_NEW (ip->info_.priv_.data_,
00545                        char[ip->info_.priv_.data_length_+1]);
00546               ACE_OS::memcpy(ip->info_.priv_.data_,
00547                              &buffer[i],
00548                              ip->info_.priv_.data_length_);
00549               ip->info_.priv_.data_[ip->info_.priv_.data_length_] = 0;
00550               i+=ip->info_.priv_.data_length_;
00551             }
00552         }
00553         i++; // each chunk ends with a zero (END) item
00554         // each chunk must end on an even 32 bit boundary
00555         while (i%4) i++;
00556     }
00557 
00558   *len-=(this->chd_.length_+1)*4;
00559 
00560   this->packet_data_ = 0;
00561 }

RTCP_SDES_Packet::RTCP_SDES_Packet ( void   ) 

Constructor for outgoing SDES packets.

Definition at line 452 of file RTCP_Packet.cpp.

References RTCP_Packet::chd_, chunk_, num_chunks_, RTCP_Packet::packet_data_, RTCP_Common_Header::pt_, and RTCP_PT_SDES.

00452                                        :
00453                    RTCP_Packet ()
00454 {
00455   this->chd_.pt_ = RTCP_PT_SDES;
00456   this->chunk_ = 0;
00457   this->packet_data_ = 0;
00458   this->num_chunks_ = 0;
00459 //  this->num_items_ = 0;
00460 }

RTCP_SDES_Packet::~RTCP_SDES_Packet ( void   )  [virtual]

Destructor.

Definition at line 565 of file RTCP_Packet.cpp.

References chunk_, sdesItem_s::info_, sdesChunk_s::item_, sdesChunk_s::next_, sdesItem_s::next_, RTCP_Packet::packet_data_, sdesItem_s::priv_, RTCP_SDES_PRIV, sdesItem_s::standard_, and sdesItem_s::type_.

00566 {
00567   sdesChunk_t *cp; // pointer to chunk
00568   sdesChunk_t *cpprev;
00569   sdesItem_t *ip; // pointer to item
00570   sdesItem_t *ipprev;
00571 
00572   cp = this->chunk_;
00573   while (cp)
00574     {
00575       ip = cp->item_;
00576       while (ip)
00577         {
00578           ipprev = ip;
00579           ip = ip->next_;
00580           if (ipprev->type_ != RTCP_SDES_PRIV)
00581             {
00582               delete []ipprev->info_.standard_.data_;
00583             }
00584           else
00585             {
00586               delete []ipprev->info_.priv_.name_;
00587               delete []ipprev->info_.priv_.data_;
00588             }
00589 
00590           delete ipprev;
00591         }
00592       cpprev = cp;
00593       cp = cp->next_;
00594       delete cpprev;
00595     }
00596 
00597   if (this->packet_data_)
00598     delete []this->packet_data_;
00599 }


Member Function Documentation

void RTCP_SDES_Packet::add_chunk ( ACE_UINT32  ssrc  )  [private]

Add a chunk to the packet.

Definition at line 604 of file RTCP_Packet.cpp.

References ACE_NEW, RTCP_Packet::chd_, chunk_, RTCP_Common_Header::count_, sdesChunk_s::item_, sdesChunk_s::next_, and sdesChunk_s::ssrc_.

Referenced by add_item(), and add_priv_item().

00605 {
00606   sdesChunk_t *cp = 0; // pointer to chunk
00607 
00608   // If this is the first chunk.
00609   if (chd_.count_ == 0)
00610     {
00611       ACE_NEW (this->chunk_,
00612                sdesChunk_t);
00613       this->chunk_->next_ = 0;
00614       this->chunk_->item_ = 0;
00615       cp = this->chunk_;
00616     }
00617   else
00618     {
00619       cp = this->chunk_;
00620       while (cp->next_)
00621         cp = cp->next_;
00622 
00623       ACE_NEW (cp->next_,
00624                sdesChunk_t);
00625       cp = cp->next_;
00626       cp->next_ = 0;
00627       cp->item_ = 0;
00628     }
00629   cp->ssrc_ = ssrc;    // store the source
00630   chd_.count_++;       // increment the source count
00631 }

void RTCP_SDES_Packet::add_item ( ACE_UINT32  ssrc,
unsigned char  type,
unsigned char  length,
const char *  data 
)

This will add a standard item of type and length for the ssrc specified. When the first item for a ssrc is added, a chunk is created. Subsequent items for that ssrc are added to the same chunk. New chunks are created for each unique ssrc.

Definition at line 636 of file RTCP_Packet.cpp.

References ACE_NEW, add_chunk(), chunk_, sdesItem_s::info_, sdesChunk_s::item_, ACE_OS::memcpy(), sdesItem_s::next_, sdesChunk_s::next_, sdesChunk_s::ssrc_, sdesItem_s::standard_, and sdesItem_s::type_.

Referenced by TAO_AV_RTCP_Callback::send_report().

00640 {
00641   sdesChunk_t *cp; // pointer to chunk
00642   sdesItem_t *ip; // pointer to item
00643 
00644   if (this->chunk_ == 0)
00645     {
00646       this->add_chunk(ssrc);
00647     }
00648 
00649   cp = this->chunk_;
00650 
00651   while (cp != 0)
00652     {
00653       if (cp->ssrc_ == ssrc)
00654         {
00655           break;
00656         }
00657 
00658       if (!cp->next_)
00659         {
00660           this->add_chunk(ssrc);
00661           cp = cp->next_;
00662           break;
00663         }
00664 
00665       cp = cp->next_;
00666     }
00667 
00668   ip = cp->item_;
00669 
00670   if (ip == 0)
00671     {
00672       ACE_NEW (cp->item_,
00673                sdesItem_t);
00674 
00675       ip = cp->item_;
00676       ip->next_= 0;
00677     }
00678   else
00679     {
00680       while (ip->next_)
00681         {
00682           ip = ip->next_;
00683         }
00684 
00685       ACE_NEW (ip->next_,
00686                sdesItem_t);
00687 
00688       ip = ip->next_;
00689       ip->next_ = 0;
00690     }
00691 
00692   ip->type_ = type;
00693 
00694   ip->info_.standard_.length_ = length;
00695 
00696   ACE_NEW (ip->info_.standard_.data_,
00697            char[length]);
00698 
00699   ACE_OS::memcpy(ip->info_.standard_.data_, data, length);
00700 }

void RTCP_SDES_Packet::add_priv_item ( ACE_UINT32  ssrc,
unsigned char  nameLength,
const char *  name,
unsigned char  dataLength,
const char *  data 
)

This will add a private item using the name and data for the ssrc specified. When the first item for a ssrc is added, a chunk is created. Subsequent items for that ssrc are added to the same chunk. New chunks are created for each unique ssrc.

Definition at line 705 of file RTCP_Packet.cpp.

References ACE_NEW, add_chunk(), chunk_, sdesItem_s::info_, sdesChunk_s::item_, ACE_OS::memcpy(), sdesItem_s::next_, sdesChunk_s::next_, sdesItem_s::priv_, RTCP_SDES_PRIV, sdesChunk_s::ssrc_, and sdesItem_s::type_.

00710 {
00711   sdesChunk_t *cp; // pointer to chunk
00712   sdesItem_t *ip; // pointer to item
00713 
00714   if (this->chunk_ == 0)
00715     {
00716       this->add_chunk(ssrc);
00717     }
00718 
00719   cp = this->chunk_;
00720 
00721   while (cp != 0)
00722     {
00723       if (cp->ssrc_ == ssrc)
00724         {
00725           break;
00726         }
00727 
00728       if (!cp->next_)
00729         {
00730           this->add_chunk(ssrc);
00731           cp = cp->next_;
00732           break;
00733         }
00734 
00735       cp = cp->next_;
00736     }
00737 
00738   ip = cp->item_;
00739 
00740   if (ip == 0)
00741     {
00742       ACE_NEW (cp->item_,
00743                sdesItem_t);
00744 
00745       ip = cp->item_;
00746       ip->next_ = 0;
00747     }
00748   else
00749     {
00750       while (ip->next_)
00751         {
00752           ip = ip->next_;
00753         }
00754 
00755       ACE_NEW (ip->next_,
00756                sdesItem_t);
00757 
00758       ip = ip->next_;
00759       ip->next_ = 0;
00760     }
00761 
00762   ip->type_ = RTCP_SDES_PRIV;
00763 
00764   ip->info_.priv_.name_length_ = nameLength;
00765   ip->info_.priv_.data_length_ = dataLength;
00766 
00767   ACE_NEW (ip->info_.priv_.name_,
00768            char[nameLength]);
00769 
00770   ACE_NEW (ip->info_.priv_.data_,
00771            char[dataLength]);
00772 
00773   ACE_OS::memcpy(ip->info_.priv_.name_, name, nameLength);
00774   ACE_OS::memcpy(ip->info_.priv_.data_, data, dataLength);
00775 }

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

Used to create the byte representation of the RTCP packet.

Implements RTCP_Packet.

Definition at line 819 of file RTCP_Packet.cpp.

References ACE_HTONL, ACE_HTONS, ACE_NEW, RTCP_Packet::chd_, chunk_, RTCP_Common_Header::count_, sdesItem_s::info_, sdesChunk_s::item_, RTCP_Common_Header::length_, sdesChunk_s::next_, sdesItem_s::next_, RTCP_Packet::packet_data_, RTCP_Common_Header::pad_, sdesItem_s::priv_, RTCP_Common_Header::pt_, RTCP_SDES_PRIV, sdesChunk_s::ssrc_, sdesItem_s::standard_, sdesItem_s::type_, and RTCP_Common_Header::ver_.

00820 {
00821   sdesChunk_t *cp; // pointer to chunk
00822   sdesItem_t *ip; // pointer to item
00823   int index, i;
00824 
00825   if (this->packet_data_)
00826     delete this->packet_data_;
00827 
00828   ACE_NEW (this->packet_data_,
00829            char[this->packet_size()]);
00830 
00831   index = 0;
00832   this->packet_data_[index] = static_cast<char> ((chd_.ver_ << 6) |
00833                                                  (chd_.pad_ << 5) |
00834                                      chd_.count_);
00835   index++;
00836   this->packet_data_[index] = chd_.pt_;
00837   index++;
00838   *((ACE_UINT16*)&this->packet_data_[index]) = ACE_HTONS(chd_.length_);
00839   index+=2;
00840 
00841   cp = this->chunk_;
00842   while (cp)
00843     {
00844       *((ACE_UINT32*)&this->packet_data_[index]) = ACE_HTONL(cp->ssrc_);
00845       index+=4;
00846 
00847       ip = cp->item_;
00848       while (ip && (ip->type_ != 0))
00849         {
00850           this->packet_data_[index] = ip->type_;
00851           index++;
00852           if (ip->type_ != RTCP_SDES_PRIV)
00853             {
00854               this->packet_data_[index] = ip->info_.standard_.length_;
00855               index++;
00856               for (i=0; i<ip->info_.standard_.length_; i++)
00857                 {
00858                   this->packet_data_[index] = ip->info_.standard_.data_[i];
00859                   index++;
00860                 }
00861             }
00862           else
00863             {
00864               this->packet_data_[index] = ip->info_.priv_.name_length_;
00865               index++;
00866               this->packet_data_[index] = ip->info_.priv_.data_length_;
00867               index++;
00868               for (i=0; i<ip->info_.priv_.name_length_; i++)
00869                 {
00870                   this->packet_data_[index] = ip->info_.priv_.name_[i];
00871                   index++;
00872                 }
00873               for (i=0; i<ip->info_.priv_.data_length_; i++)
00874                 {
00875                   this->packet_data_[index] = ip->info_.priv_.data_[i];
00876                   index++;
00877                 }
00878             }
00879 
00880           ip = ip->next_;
00881         }
00882 
00883       this->packet_data_[index] = 0;
00884       index++;
00885 
00886       i=1;
00887       while ((index)%4)
00888         { // pad chunk with zeros to 32 bit bound
00889           this->packet_data_[index] = 0;
00890           index++;
00891           i++;
00892         }
00893 
00894       // Store the number of bytes added. TODO: do we need this
00895       // this->packet_data_[index - 1] = i;
00896 
00897       cp = cp->next_;
00898     }
00899 }

void RTCP_SDES_Packet::dump ( void   ) 

Prints the contents of the packet.

Definition at line 902 of file RTCP_Packet.cpp.

References ACE_DEBUG, chunk_, sdesItem_s::info_, sdesChunk_s::item_, LM_DEBUG, sdesItem_s::next_, sdesItem_s::priv_, RTCP_SDES_CNAME, RTCP_SDES_EMAIL, RTCP_SDES_END, RTCP_SDES_LOC, RTCP_SDES_NAME, RTCP_SDES_NOTE, RTCP_SDES_PHONE, RTCP_SDES_PRIV, RTCP_SDES_TOOL, sdesItem_s::standard_, and sdesItem_s::type_.

Referenced by TAO_AV_RTCP_Callback::receive_control_frame().

00903 {
00904   sdesItem_t *ip;
00905 
00906   ACE_DEBUG ((LM_DEBUG,
00907               "\nRTCP_SDES_Packet:: "));
00908 
00909   if (this->num_chunks_ != 1)
00910     {
00911       ACE_DEBUG ((LM_DEBUG,
00912                   "Mixers not currently supported.\n"));
00913       return;
00914     }
00915 
00916   ACE_DEBUG ((LM_DEBUG,
00917               "from ssrc %u\n",
00918               this->chunk_->ssrc_));
00919 
00920   // Loop through all of the items.
00921   ip = this->chunk_->item_;
00922 
00923   while (ip)
00924     {
00925       // If there is no data to store, continue.
00926       if (ip->info_.standard_.length_ == 0)
00927         {
00928           ip = ip->next_;
00929           continue;
00930         }
00931 
00932       switch (ip->type_)
00933       {
00934         case RTCP_SDES_END:
00935              break;
00936         case RTCP_SDES_CNAME:
00937              ACE_DEBUG ((LM_DEBUG,
00938                          "    CNAME '%s'\n",
00939                          ip->info_.standard_.data_));
00940              break;
00941         case RTCP_SDES_NAME:
00942              ACE_DEBUG ((LM_DEBUG,
00943                          "    NAME '%s'\n",
00944                          ip->info_.standard_.data_));
00945              break;
00946         case RTCP_SDES_EMAIL:
00947              ACE_DEBUG ((LM_DEBUG,
00948                          "    EMAIL '%s'\n",
00949                          ip->info_.standard_.data_));
00950              break;
00951         case RTCP_SDES_PHONE:
00952              ACE_DEBUG ((LM_DEBUG,
00953                          "    PHONE '%s'\n",
00954                          ip->info_.standard_.data_));
00955              break;
00956         case RTCP_SDES_LOC:
00957              ACE_DEBUG ((LM_DEBUG,
00958                          "    LOC '%s'\n",
00959                          ip->info_.standard_.data_));
00960              break;
00961         case RTCP_SDES_TOOL:
00962              ACE_DEBUG ((LM_DEBUG,
00963                          "    TOOL '%s'\n",
00964                          ip->info_.standard_.data_));
00965              break;
00966         case RTCP_SDES_NOTE:
00967              ACE_DEBUG ((LM_DEBUG,
00968                          "    NOTE '%s'\n",
00969                          ip->info_.standard_.data_));
00970              break;
00971         case RTCP_SDES_PRIV:
00972              ACE_DEBUG ((LM_DEBUG,
00973                          "    '%s' '%s'\n",
00974                          ip->info_.priv_.name_,
00975                          ip->info_.priv_.data_));
00976              break;
00977       }
00978       ip = ip->next_;
00979     }
00980 
00981 }

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

Returns the size of the packet in bytes.

Implements RTCP_Packet.

Definition at line 780 of file RTCP_Packet.cpp.

References RTCP_Packet::chd_, chunk_, sdesItem_s::info_, sdesChunk_s::item_, RTCP_Common_Header::length_, sdesChunk_s::next_, sdesItem_s::next_, sdesItem_s::priv_, RTCP_SDES_PRIV, sdesItem_s::standard_, and sdesItem_s::type_.

00781 {
00782   int size;
00783   sdesChunk_t *cp; // pointer to chunk
00784   sdesItem_t *ip; // pointer to item
00785 
00786   // Determine the size of the packet.
00787   size = 4;  // size of common header data in octets
00788 
00789   cp = this->chunk_;
00790   while (cp)
00791     {
00792       size += 4; // size of ssrc
00793       ip = cp->item_;
00794 
00795       while (ip && (ip->type_ != 0))
00796         {
00797           if (ip->type_ != RTCP_SDES_PRIV)
00798             {
00799               size += 2 + ip->info_.standard_.length_;  // size of item
00800             }
00801           else
00802             {
00803               size += 3 + ip->info_.priv_.name_length_ + ip->info_.priv_.data_length_;
00804             }
00805           ip = ip->next_;
00806         }
00807       size += 4 - size%4;           // pad with zeros to even 32 bit bound
00808       cp = cp->next_;
00809     }
00810 
00811   chd_.length_ = static_cast<ACE_UINT16> (size/4 - 1);
00812 
00813   return size;
00814 }

ACE_UINT32 RTCP_SDES_Packet::ssrc ( void   )  [inline]

This returns the synchronization source id for this packet. This assumes that this source is only receiving messages from end systems (i.e. only one source id per SDES)

Definition at line 316 of file RTCP_Packet.h.

References chunk_, and sdesChunk_s::ssrc_.

00316 { return this->chunk_->ssrc_; }


Member Data Documentation

sdesChunk_t* RTCP_SDES_Packet::chunk_ [private]

A linked list of chunks for this packet (only 1 for non-mixers).

Definition at line 332 of file RTCP_Packet.h.

Referenced by add_chunk(), add_item(), add_priv_item(), build_packet(), dump(), packet_size(), RTCP_SDES_Packet(), ssrc(), and ~RTCP_SDES_Packet().

unsigned long RTCP_SDES_Packet::num_chunks_ [private]

The number of chunks contained in this packet. 1 for end systems, 1+ for mixers

Definition at line 327 of file RTCP_Packet.h.

Referenced by RTCP_SDES_Packet().


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:47:58 2010 for TAO_AV by  doxygen 1.4.7