summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/AV/RTCP_Packet.h
blob: 696378258af1b42cad88f570d84633ec2676e692 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
// -*- C++ -*-

// $Id$

#ifndef RTCP_PACKET_INCLUDE
#define RTCP_PACKET_INCLUDE

#include /**/ "ace/pre.h"

#include "tao/orbconf.h"
#include "tao/Versioned_Namespace.h"


TAO_BEGIN_VERSIONED_NAMESPACE_DECL

/**
 * @struct RTCP_Common_Header
 * @brief This is the header data that is common to all RTCP messages.
 */
typedef struct
{
  /// the RTP version being used
  unsigned int ver_:2;

  /// indicates whether or not the end of the packet is padded with zeros
  unsigned int pad_:1;

  /// this value varies by packet type
  unsigned int count_:5;

  /// RTCP packet type (eg BYE, SR, RR, SDES)
  unsigned int pt_:8;

  /// packet length in words without this word
  ACE_UINT16 length_;
} RTCP_Common_Header;

/**
 * @class RTCP_Packet
 * @brief This is an abstract class from which all RTCP packet types are derived.
 * It contains code used to validate the RTCP packet.
 */

class RTCP_Packet
{
public:
  /// Constructor for outgoing RTCP packets.
  RTCP_Packet(void);

  /// Constructor for incoming RTCP packets.
  RTCP_Packet(char *buffer);

  /// Destructor
  virtual ~RTCP_Packet();

  /// Returns a pointer to a local buffer containing the packet.
  void get_packet_data(char **buffer, ACE_UINT16 &length);

  /// Returns the size of the packet.
  /// Defined in child class.
  virtual unsigned int packet_size(void) = 0;

  /// Checks the validity of an RTCP packet.  RTCP packets can be sent
  /// together in a compound packet and is_first indicates the first packet
  /// in a compound packet
  int is_valid (char is_first);

protected:
  /// Header data common to all RTCP packets.
  RTCP_Common_Header chd_;

  /// Buffer to hold byte representation of the RTCP packet.
  char *packet_data_;

  /// Used to create the byte representation of the RTCP packet.
  /// Defined in child class.
  virtual void build_packet(void) = 0;
};

/**
 * @class RTCP_BYE_Packet
 * @brief The BYE RTCP packet is sent by a party when leaving an RTP session.
 */

class RTCP_BYE_Packet : public RTCP_Packet
{
public:
  /// 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.
  RTCP_BYE_Packet (ACE_UINT32 *srcList,
                   unsigned char length,
                   const char* text=0);

  /// Constructor for incoming BYE RTCP packets.
  RTCP_BYE_Packet (char *buffer,
                   int *len);

  /// Destructor.
  virtual ~RTCP_BYE_Packet (void);

  /// Returns the size of the packet in bytes.
  unsigned int packet_size (void);

  /// Returns a pointer to a local list of synchronization source ids that are
  /// leaving the session.
  void ssrc_list (ACE_UINT32 **ssrc_list,
                  unsigned char &length);

  /// Returns the reason for leaving the session.
  const char *reason (void);

  /// Prints the contents of the packet.
  void dump (void);

private:
  /// Used to create the byte representation of the RTCP packet.
  void build_packet();

  /// List of synchronization source ids that are leaving the session.
  ACE_UINT32 *ssrc_list_;

  /// The number of ssrc's that are leaving the session (1 for non-mixers).
  unsigned char ssrc_list_length_;

  /// An optional reason for leaving the session.
  char reason_[256];

  /// The number of bytes in the reason for leaving the session.
  unsigned char reason_length_;
};

/**
 * @struct RR_Block
 * @brief The receiver report block encapsulates the data that represents the
 * reception statistics for a particular stream.
 */

struct RR_Block
{
  /// The synchronization source id of the source of the data.
  ACE_UINT32 ssrc_;

  /// The fraction of RTP data packets lost since the previous SR or RR was sent.
  unsigned int fraction_:8;

  /// The cumulative number of packets lost.
  int lost_:24;

  /// The highest extended sequence number received in an RTP packet.
  ACE_UINT32 last_seq_;

  /// An estimate of the statistical variance of the RTP data packet interarrival
  /// time measured in timestamp units.
  ACE_UINT32 jitter_;

  /// The middle 32 bits of the NTP timestamp received in the most recent sender
  /// report.
  ACE_UINT32 lsr_;

  /// The delay in 1/65536 seconds since receiving the last sender report.
  ACE_UINT32 dlsr_;

  /// Link to the next receiver report block.
  RR_Block *next_;
};

/**
 * @class RTCP_RR_Packet
 * @brief The Receiver Report packet is sent by all members of a session that
 * are not sending data.  It contains a list of RR_Block to represent each
 * source this party is receiving data from.
 */

class RTCP_RR_Packet : public RTCP_Packet
{
public:
  /// Constructor for incoming receiver reports.
  RTCP_RR_Packet (char *buffer, int* len);

  /// Constructor for outgoing receiver reports.
  RTCP_RR_Packet (ACE_UINT32 ssrc, RR_Block *blocks);

  /// Destructor.
  virtual ~RTCP_RR_Packet (void);

  /// Returns the size of the packet in bytes.
  unsigned int packet_size(void);

  /// Returns the synchronization source id of the source sending this packet.
  ACE_INT32 ssrc (void) { return this->ssrc_; }

  /// Prints the contents of the packet.
  void dump (void);

private:
  /// Used to create the byte representation of the RTCP packet.
  void build_packet(void);

  /// The synchronization source id of the sender of this report.
  ACE_UINT32 ssrc_;

  /// A linked list of the receiver report block(s) being sent.
  RR_Block *rr_;
};

typedef struct sdesItem_s sdesItem_t;

/**
 * @struct sdesItem_s
 * @brief This is a linked list of structures containing source description
 * 'items' such as canonical name, email, location etc.
 */

struct sdesItem_s
{
  /// link to next item.
  sdesItem_t *next_;

  /// Type of item (eg canonical name).
  unsigned char type_;

  union
  {
    struct
    {
      /// Length of an item (in octets).
      unsigned char length_;

      /// Item text, not null-terminated.
      char *data_;
    } standard_;
    struct
    {
      /// Length of the name of an item (in octets).
      unsigned char name_length_;

      /// Length of the item data (in octets).
      unsigned char data_length_;

      /// The name of the item, not null-terminated.
      char *name_;

      /// Item data, not null-terminated.
      char *data_;
    } priv_;
  } info_;
};

typedef struct sdesChunk_s sdesChunk_t;

/**
 * @struct sdesChunk_s
 * @brief This is a linked list of structures containing groups of source
 * description items.  A group of items for a particular synchronization source
 * id is referred to as a 'chunk'.
 */
struct sdesChunk_s
{
  /// Link to next item.
  sdesChunk_t *next_;

  /// The synchronization source id that this chunk describes.
  ACE_UINT32 ssrc_;

  /// A linked list of items to describe this source.
  sdesItem_t *item_;
};

/**
 * @class RTCP_SDES_Packet
 * @brief 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.
 */
class RTCP_SDES_Packet : public RTCP_Packet
{
public:
  /// Constructor for incoming SDES packets.
  RTCP_SDES_Packet(char* buffer, int *len);

  /// Constructor for outgoing SDES packets.
  RTCP_SDES_Packet(void);

  /// Destructor.
  virtual ~RTCP_SDES_Packet(void);

  /// 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.
  void add_item(ACE_UINT32 ssrc,
                unsigned char type,
                unsigned char length,
                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.
  void add_priv_item(ACE_UINT32 ssrc,
                     unsigned char nameLength,
                     const char *name,
                     unsigned char dataLength,
                     const char *data);

  /// Returns the size of the packet in bytes.
  unsigned int packet_size(void);

  /// Prints the contents of the packet.
  void dump (void);

  /// 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)
  ACE_UINT32 ssrc (void) { return this->chunk_->ssrc_; }

private:
  /// Used to create the byte representation of the RTCP packet.
  void build_packet(void);

  /// Add a chunk to the packet.
  void add_chunk(ACE_UINT32 ssrc);

  /// The number of chunks contained in this packet.
  /// 1 for end systems, 1+ for mixers
  unsigned long num_chunks_;

//  unsigned long num_items_;

  /// A linked list of chunks for this packet (only 1 for non-mixers).
  sdesChunk_t *chunk_;
};

/**
 * @class RTCP_SR_Packet
 * @brief The Sender Report packet is sent by all members of a session that
 * are sending data.  It contains statistics on the data being sent out. It
 * also contains a list of RR_Block to represent each source this party is
 * receiving data from.
 */

class RTCP_SR_Packet : public RTCP_Packet
{
public:
  /// Constructor for incoming SR packets.
  RTCP_SR_Packet(char *buffer, int *len);

  /// Constructor for outgoing SR packets.
  RTCP_SR_Packet(ACE_UINT32 ssrcVal,
                 ACE_UINT32 ntpMSByte,
                 ACE_UINT32 ntpLSByte,
                 ACE_UINT32 timestamp,
                 ACE_UINT32 pktsSent,
                 ACE_UINT32 octetsSent,
                 RR_Block *rrBlocks);

  /// Destructor
  virtual ~RTCP_SR_Packet(void);

  /// Returns the size of the packet in bytes.
  unsigned int packet_size(void);

  /// Returns the synchronization source id for the sender of this packet.
  ACE_UINT32 ssrc (void) { return this->ssrc_; }

  /// Returns the most significant word of the NTP timestamp.
  ACE_UINT32 ntp_ts_msw (void) { return this->ntp_ts_msw_; }

  /// Returns the least significant word of the NTP timestamp.
  ACE_UINT32 ntp_ts_lsw (void) { return this->ntp_ts_lsw_; }

  /// Prints the contents of the packet.
  void dump (void);

private:
  /// Used to create the byte representation of the RTCP packet.
  void build_packet(void);

  /// The synchronization source id of the sender generating this report.
  ACE_UINT32 ssrc_;

  /// The most significant word of the NTP timestamp.
  ACE_UINT32 ntp_ts_msw_;

  /// The least significant word of the NTP timestamp.
  ACE_UINT32 ntp_ts_lsw_;

  /// The RTP timestamp
  ACE_UINT32 rtp_ts_;

  /// The total number of packets sent.
  ACE_UINT32 psent_;

  /// The total number of octets sent.
  ACE_UINT32 osent_;

  /// A linked list of receiver report blocks.
  RR_Block *rr_;
};

TAO_END_VERSIONED_NAMESPACE_DECL

#include /**/ "ace/post.h"
#endif  /*  RTCP_PACKET_INCLUDE  */