00001 // -*- C++ -*- 00002 00003 // $Id: RTCP_Packet.h 69284 2005-11-10 06:47:24Z ossama $ 00004 00005 #ifndef RTCP_PACKET_INCLUDE 00006 #define RTCP_PACKET_INCLUDE 00007 00008 #include /**/ "ace/pre.h" 00009 00010 #include "tao/orbconf.h" 00011 #include "tao/Versioned_Namespace.h" 00012 00013 00014 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00015 00016 /** 00017 * @struct RTCP_Common_Header 00018 * @brief This is the header data that is common to all RTCP messages. 00019 */ 00020 typedef struct 00021 { 00022 /// the RTP version being used 00023 unsigned int ver_:2; 00024 00025 /// indicates whether or not the end of the packet is padded with zeros 00026 unsigned int pad_:1; 00027 00028 /// this value varies by packet type 00029 unsigned int count_:5; 00030 00031 /// RTCP packet type (eg BYE, SR, RR, SDES) 00032 unsigned int pt_:8; 00033 00034 /// packet length in words without this word 00035 ACE_UINT16 length_; 00036 } RTCP_Common_Header; 00037 00038 /** 00039 * @class RTCP_Packet 00040 * @brief This is an abstract class from which all RTCP packet types are derived. 00041 * It contains code used to validate the RTCP packet. 00042 */ 00043 00044 class RTCP_Packet 00045 { 00046 public: 00047 /// Constructor for outgoing RTCP packets. 00048 RTCP_Packet(void); 00049 00050 /// Constructor for incoming RTCP packets. 00051 RTCP_Packet(char *buffer); 00052 00053 /// Destructor 00054 virtual ~RTCP_Packet(); 00055 00056 /// Returns a pointer to a local buffer containing the packet. 00057 void get_packet_data(char **buffer, ACE_UINT16 &length); 00058 00059 /// Returns the size of the packet. 00060 /// Defined in child class. 00061 virtual unsigned int packet_size(void) = 0; 00062 00063 /// Checks the validity of an RTCP packet. RTCP packets can be sent 00064 /// together in a compound packet and is_first indicates the first packet 00065 /// in a compound packet 00066 int is_valid (char is_first); 00067 00068 protected: 00069 /// Header data common to all RTCP packets. 00070 RTCP_Common_Header chd_; 00071 00072 /// Buffer to hold byte representation of the RTCP packet. 00073 char *packet_data_; 00074 00075 /// Used to create the byte representation of the RTCP packet. 00076 /// Defined in child class. 00077 virtual void build_packet(void) = 0; 00078 }; 00079 00080 /** 00081 * @class RTCP_BYE_Packet 00082 * @brief The BYE RTCP packet is sent by a party when leaving an RTP session. 00083 */ 00084 00085 class RTCP_BYE_Packet : public RTCP_Packet 00086 { 00087 public: 00088 /// Constructor for outgoing BYE RTCP packets. 00089 /// Takes a synchronization source id list, the list length (1 for non-mixers), 00090 /// and an optional reason for leaving the session. 00091 RTCP_BYE_Packet (ACE_UINT32 *srcList, 00092 unsigned char length, 00093 const char* text=0); 00094 00095 /// Constructor for incoming BYE RTCP packets. 00096 RTCP_BYE_Packet (char *buffer, 00097 int *len); 00098 00099 /// Destructor. 00100 virtual ~RTCP_BYE_Packet (void); 00101 00102 /// Returns the size of the packet in bytes. 00103 unsigned int packet_size (void); 00104 00105 /// Returns a pointer to a local list of synchronization source ids that are 00106 /// leaving the session. 00107 void ssrc_list (ACE_UINT32 **ssrc_list, 00108 unsigned char &length); 00109 00110 /// Returns the reason for leaving the session. 00111 const char *reason (void); 00112 00113 /// Prints the contents of the packet. 00114 void dump (void); 00115 00116 private: 00117 /// Used to create the byte representation of the RTCP packet. 00118 void build_packet(); 00119 00120 /// List of synchronization source ids that are leaving the session. 00121 ACE_UINT32 *ssrc_list_; 00122 00123 /// The number of ssrc's that are leaving the session (1 for non-mixers). 00124 unsigned char ssrc_list_length_; 00125 00126 /// An optional reason for leaving the session. 00127 char reason_[256]; 00128 00129 /// The number of bytes in the reason for leaving the session. 00130 unsigned char reason_length_; 00131 }; 00132 00133 /** 00134 * @struct RR_Block 00135 * @brief The receiver report block encapsulates the data that represents the 00136 * reception statistics for a particular stream. 00137 */ 00138 00139 struct RR_Block 00140 { 00141 /// The synchronization source id of the source of the data. 00142 ACE_UINT32 ssrc_; 00143 00144 /// The fraction of RTP data packets lost since the previous SR or RR was sent. 00145 unsigned int fraction_:8; 00146 00147 /// The cumulative number of packets lost. 00148 int lost_:24; 00149 00150 /// The highest extended sequence number received in an RTP packet. 00151 ACE_UINT32 last_seq_; 00152 00153 /// An estimate of the statistical variance of the RTP data packet interarrival 00154 /// time measured in timestamp units. 00155 ACE_UINT32 jitter_; 00156 00157 /// The middle 32 bits of the NTP timestamp received in the most recent sender 00158 /// report. 00159 ACE_UINT32 lsr_; 00160 00161 /// The delay in 1/65536 seconds since receiving the last sender report. 00162 ACE_UINT32 dlsr_; 00163 00164 /// Link to the next receiver report block. 00165 RR_Block *next_; 00166 }; 00167 00168 /** 00169 * @class RTCP_RR_Packet 00170 * @brief The Receiver Report packet is sent by all members of a session that 00171 * are not sending data. It contains a list of RR_Block to represent each 00172 * source this party is receiving data from. 00173 */ 00174 00175 class RTCP_RR_Packet : public RTCP_Packet 00176 { 00177 public: 00178 /// Constructor for incoming receiver reports. 00179 RTCP_RR_Packet (char *buffer, int* len); 00180 00181 /// Constructor for outgoing receiver reports. 00182 RTCP_RR_Packet (ACE_UINT32 ssrc, RR_Block *blocks); 00183 00184 /// Destructor. 00185 virtual ~RTCP_RR_Packet (void); 00186 00187 /// Returns the size of the packet in bytes. 00188 unsigned int packet_size(void); 00189 00190 /// Returns the synchronization source id of the source sending this packet. 00191 ACE_INT32 ssrc (void) { return this->ssrc_; } 00192 00193 /// Prints the contents of the packet. 00194 void dump (void); 00195 00196 private: 00197 /// Used to create the byte representation of the RTCP packet. 00198 void build_packet(void); 00199 00200 /// The synchronization source id of the sender of this report. 00201 ACE_UINT32 ssrc_; 00202 00203 /// A linked list of the receiver report block(s) being sent. 00204 RR_Block *rr_; 00205 }; 00206 00207 typedef struct sdesItem_s sdesItem_t; 00208 00209 /** 00210 * @struct sdesItem_s 00211 * @brief This is a linked list of structures containing source description 00212 * 'items' such as canonical name, email, location etc. 00213 */ 00214 00215 struct sdesItem_s 00216 { 00217 /// link to next item. 00218 sdesItem_t *next_; 00219 00220 /// Type of item (eg canonical name). 00221 unsigned char type_; 00222 00223 union 00224 { 00225 struct 00226 { 00227 /// Length of an item (in octets). 00228 unsigned char length_; 00229 00230 /// Item text, not null-terminated. 00231 char *data_; 00232 } standard_; 00233 struct 00234 { 00235 /// Length of the name of an item (in octets). 00236 unsigned char name_length_; 00237 00238 /// Length of the item data (in octets). 00239 unsigned char data_length_; 00240 00241 /// The name of the item, not null-terminated. 00242 char *name_; 00243 00244 /// Item data, not null-terminated. 00245 char *data_; 00246 } priv_; 00247 } info_; 00248 }; 00249 00250 typedef struct sdesChunk_s sdesChunk_t; 00251 00252 /** 00253 * @struct sdesChunk_s 00254 * @brief This is a linked list of structures containing groups of source 00255 * description items. A group of items for a particular synchronization source 00256 * id is referred to as a 'chunk'. 00257 */ 00258 struct sdesChunk_s 00259 { 00260 /// Link to next item. 00261 sdesChunk_t *next_; 00262 00263 /// The synchronization source id that this chunk describes. 00264 ACE_UINT32 ssrc_; 00265 00266 /// A linked list of items to describe this source. 00267 sdesItem_t *item_; 00268 }; 00269 00270 /** 00271 * @class RTCP_SDES_Packet 00272 * @brief The Source Description packet is sent by all members of a session. 00273 * At a minimum, the canonical name (or CNAME) is sent with each RTCP packet. 00274 * Other items such as name, email, or location are included less frequently. 00275 */ 00276 class RTCP_SDES_Packet : public RTCP_Packet 00277 { 00278 public: 00279 /// Constructor for incoming SDES packets. 00280 RTCP_SDES_Packet(char* buffer, int *len); 00281 00282 /// Constructor for outgoing SDES packets. 00283 RTCP_SDES_Packet(void); 00284 00285 /// Destructor. 00286 virtual ~RTCP_SDES_Packet(void); 00287 00288 /// This will add a standard item of type and length for the ssrc specified. 00289 /// When the first item for a ssrc is added, a chunk is created. Subsequent 00290 /// items for that ssrc are added to the same chunk. New chunks are created 00291 /// for each unique ssrc. 00292 void add_item(ACE_UINT32 ssrc, 00293 unsigned char type, 00294 unsigned char length, 00295 const char* data); 00296 00297 /// This will add a private item using the name and data for the ssrc specified. 00298 /// When the first item for a ssrc is added, a chunk is created. Subsequent 00299 /// items for that ssrc are added to the same chunk. New chunks are created 00300 /// for each unique ssrc. 00301 void add_priv_item(ACE_UINT32 ssrc, 00302 unsigned char nameLength, 00303 const char *name, 00304 unsigned char dataLength, 00305 const char *data); 00306 00307 /// Returns the size of the packet in bytes. 00308 unsigned int packet_size(void); 00309 00310 /// Prints the contents of the packet. 00311 void dump (void); 00312 00313 /// This returns the synchronization source id for this packet. This assumes 00314 /// that this source is only receiving messages from end systems (i.e. only 00315 /// one source id per SDES) 00316 ACE_UINT32 ssrc (void) { return this->chunk_->ssrc_; } 00317 00318 private: 00319 /// Used to create the byte representation of the RTCP packet. 00320 void build_packet(void); 00321 00322 /// Add a chunk to the packet. 00323 void add_chunk(ACE_UINT32 ssrc); 00324 00325 /// The number of chunks contained in this packet. 00326 /// 1 for end systems, 1+ for mixers 00327 unsigned long num_chunks_; 00328 00329 // unsigned long num_items_; 00330 00331 /// A linked list of chunks for this packet (only 1 for non-mixers). 00332 sdesChunk_t *chunk_; 00333 }; 00334 00335 /** 00336 * @class RTCP_SR_Packet 00337 * @brief The Sender Report packet is sent by all members of a session that 00338 * are sending data. It contains statistics on the data being sent out. It 00339 * also contains a list of RR_Block to represent each source this party is 00340 * receiving data from. 00341 */ 00342 00343 class RTCP_SR_Packet : public RTCP_Packet 00344 { 00345 public: 00346 /// Constructor for incoming SR packets. 00347 RTCP_SR_Packet(char *buffer, int *len); 00348 00349 /// Constructor for outgoing SR packets. 00350 RTCP_SR_Packet(ACE_UINT32 ssrcVal, 00351 ACE_UINT32 ntpMSByte, 00352 ACE_UINT32 ntpLSByte, 00353 ACE_UINT32 timestamp, 00354 ACE_UINT32 pktsSent, 00355 ACE_UINT32 octetsSent, 00356 RR_Block *rrBlocks); 00357 00358 /// Destructor 00359 virtual ~RTCP_SR_Packet(void); 00360 00361 /// Returns the size of the packet in bytes. 00362 unsigned int packet_size(void); 00363 00364 /// Returns the synchronization source id for the sender of this packet. 00365 ACE_UINT32 ssrc (void) { return this->ssrc_; } 00366 00367 /// Returns the most significant word of the NTP timestamp. 00368 ACE_UINT32 ntp_ts_msw (void) { return this->ntp_ts_msw_; } 00369 00370 /// Returns the least significant word of the NTP timestamp. 00371 ACE_UINT32 ntp_ts_lsw (void) { return this->ntp_ts_lsw_; } 00372 00373 /// Prints the contents of the packet. 00374 void dump (void); 00375 00376 private: 00377 /// Used to create the byte representation of the RTCP packet. 00378 void build_packet(void); 00379 00380 /// The synchronization source id of the sender generating this report. 00381 ACE_UINT32 ssrc_; 00382 00383 /// The most significant word of the NTP timestamp. 00384 ACE_UINT32 ntp_ts_msw_; 00385 00386 /// The least significant word of the NTP timestamp. 00387 ACE_UINT32 ntp_ts_lsw_; 00388 00389 /// The RTP timestamp 00390 ACE_UINT32 rtp_ts_; 00391 00392 /// The total number of packets sent. 00393 ACE_UINT32 psent_; 00394 00395 /// The total number of octets sent. 00396 ACE_UINT32 osent_; 00397 00398 /// A linked list of receiver report blocks. 00399 RR_Block *rr_; 00400 }; 00401 00402 TAO_END_VERSIONED_NAMESPACE_DECL 00403 00404 #include /**/ "ace/post.h" 00405 #endif /* RTCP_PACKET_INCLUDE */