Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
headers.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 Roc Streaming authors
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 
9 //! @file roc_rtcp/headers.h
10 //! @brief RTCP headers.
11 
12 #ifndef ROC_RTCP_HEADERS_H_
13 #define ROC_RTCP_HEADERS_H_
14 
15 #include "roc_core/attributes.h"
16 #include "roc_core/endian.h"
17 #include "roc_core/panic.h"
18 #include "roc_core/stddefs.h"
19 #include "roc_core/time.h"
20 #include "roc_packet/ntp.h"
21 #include "roc_packet/units.h"
22 #include "roc_rtcp/ntp.h"
23 
24 namespace roc {
25 namespace rtcp {
26 namespace header {
27 
28 //! Get bits from v0.
29 //! @param v0 Where to read the bits.
30 //! @param shift From which bit num the field start.
31 //! @param mask The bitmask.
32 template <typename T> T get_bit_field(T v0, const size_t shift, const size_t mask) {
33  v0 >>= shift;
34  v0 &= mask;
35  return v0;
36 }
37 
38 //! Set bits in v0.
39 //! @param v0 Where to write the bits.
40 //! @param v1 The bits to write.
41 //! @param shift From which bit num the field start.
42 //! @param mask The bitmask.
43 template <typename T>
44 void set_bit_field(T& v0, const T v1, const size_t shift, const size_t mask) {
45  v0 &= T(~(mask << shift));
46  v0 |= T((v1 & mask) << shift);
47 }
48 
49 //! Computes the value of RTCP packet header length field from input number.
50 inline uint16_t size_t_2_rtcp_length(const size_t x) {
51  roc_panic_if(x < 4);
52  roc_panic_if(x > uint16_t(-1));
53  roc_panic_if(x % 4 != 0);
54  return (uint16_t)x / 4 - 1;
55 }
56 
57 //! Converts RTCP header length field into conventional size_t value.
58 inline size_t rtcp_length_2_size_t(const size_t x) {
59  return (x + 1) * 4;
60 }
61 
62 //! How much padding bytes do we need in order to align with 32-bits.
63 //! @param size defines data length in bytes.
64 //! @param min_padding defines minimum number of padding bytes required.
65 //! @return How much should be added to x.
66 inline size_t padding_len(const size_t size, const size_t min_padding) {
67  const size_t size_to_pad = size + min_padding;
68  return min_padding + (size_to_pad & 0x03 ? 4 - (size_to_pad & 0x03) : 0);
69 }
70 
71 //! Get a block that follows header, by index.
72 template <class Blk, class Pkt>
73 Blk& get_block_by_index(Pkt* pkt,
74  size_t block_index,
75  size_t num_blocks,
76  const char* pkt_type) {
77  if (block_index >= num_blocks) {
78  roc_panic("%s: out of bounds: index=%lu size=%lu", pkt_type,
79  (unsigned long)block_index, (unsigned long)num_blocks);
80  }
81  return ((Blk*)(const_cast<char*>((const char*)pkt) + sizeof(*pkt)))[block_index];
82 }
83 
84 //! Maximum number of inner blocks/chunks in RTCP packet.
85 static const size_t MaxPacketBlocks = 31;
86 
87 //! Maximum allowed SDES/BYE text length.
88 static const size_t MaxTextLen = 255;
89 
90 //! Maximum allowed DLSR/DLRR value.
91 static const packet::ntp_timestamp_t MaxDelay = 0x0000FFFFFFFFFFFF;
92 
93 //! Special value when metric is not available (64-bit).
94 static const packet::ntp_timestamp_t MetricUnavail_64 = 0xFFFFFFFFFFFFFFFF;
95 
96 //! Special value when metric is not available (32-bit).
97 static const packet::ntp_timestamp_t MetricUnavail_32 = 0x0000FFFFFFFF0000;
98 
99 //! RTP protocol version.
100 enum Version {
101  V2 = 2 //!< RTP version 2.
102 };
103 
104 //! RTCP packet type.
106  RTCP_SR = 200, //!< Sender report packet.
107  RTCP_RR = 201, //!< Receiver report packet.
108  RTCP_SDES = 202, //!< Source Description packet.
109  RTCP_BYE = 203, //!< BYE packet.
110  RTCP_APP = 204, //!< APP-specific packet.
111  RTCP_XR = 207 //!< Extended report packet.
112 };
113 
114 //! RTCP packet header, common for all RTCP packet types.
115 //!
116 //! RFC 3550 6.4.1: "SR: Sender Report RTCP Packet"
117 //! RFC 3550 6.4.2: "RR: Receiver Report RTCP Packet"
118 //!
119 //! @code
120 //! 0 1 2 3
121 //! 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
122 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
123 //! |V=2|P| RC | PT | length |
124 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
125 //! @endcode
127 private:
128  enum {
129  //! @name RTCP protocol version.
130  // @{
131  Version_shift = 6,
132  Version_mask = 0x03,
133  // @}
134 
135  //! @name RTCP padding flag.
136  // @{
137  Padding_shift = 5,
138  Padding_mask = 0x01,
139  // @}
140 
141  //! @name RTCP packets counter.
142  // @{
143  Counter_shift = 0,
144  Counter_mask = 0x1F
145  // @}
146  };
147 
148  // Protocol version, padding flag, and block/chunk counter.
149  // Varies by packet type.
150  uint8_t count_;
151  // RTCP packet type.
152  uint8_t type_;
153  // Packet length in 4-byte words, w/o common packet header word.
154  uint16_t length_;
155 
156 public:
157  PacketHeader() {
158  reset(PacketType(0));
159  }
160 
161  //! Reset to initial state (all zeros).
162  void reset(const PacketType t) {
163  count_ = 0;
164  type_ = 0;
165  length_ = 0;
166 
167  set_version(V2);
168  set_type(t);
169  }
170 
171  //! Get number of blocks/chunks following.
172  size_t counter() const {
173  return get_bit_field<uint8_t>(count_, Counter_shift, Counter_mask);
174  }
175 
176  //! Set number of blocks/chunks.
177  void set_counter(const size_t c) {
178  roc_panic_if(c > MaxPacketBlocks);
179  set_bit_field<uint8_t>(count_, (uint8_t)c, Counter_shift, Counter_mask);
180  }
181 
182  //! Increment packet counter,
183  void inc_counter() {
184  return set_counter(counter() + 1);
185  }
186 
187  //! Get protocol version.
188  uint8_t version() const {
189  return get_bit_field<uint8_t>(count_, Version_shift, Version_mask);
190  }
191 
192  //! Set protocol version.
193  void set_version(const Version v) {
194  roc_panic_if((v & Version_mask) != v);
195  set_bit_field<uint8_t>(count_, v, Version_shift, Version_mask);
196  }
197 
198  //! Get padding flag.
199  bool has_padding() const {
200  return get_bit_field(count_, Padding_shift, Padding_mask);
201  }
202 
203  //! Set padding flag.
204  void set_padding(const bool v) {
205  set_bit_field(count_, (uint8_t)v, Padding_shift, Padding_mask);
206  }
207 
208  //! Get packet type.
209  PacketType type() const {
210  return PacketType(type_);
211  }
212 
213  //! Set packet type.
214  void set_type(const PacketType t) {
215  roc_panic_if_not(t == 0 || (t >= RTCP_SR && t <= RTCP_XR));
216  type_ = t;
217  }
218 
219  //! Get packet length, including the header, in 32-bit words minus one.
220  uint16_t len_words() const {
221  return core::ntoh16u(length_);
222  }
223 
224  //! Set packet length in words.
225  void set_len_words(const uint16_t len) {
226  length_ = core::hton16u(len);
227  }
228 
229  //! Get packet length, including the header, in bytes.
230  size_t len_bytes() const {
232  }
233 
234  //! Set packet length in bytes.
235  void set_len_bytes(const size_t len) {
237  }
239 
240 //! 64-bit NTP timestamp.
241 //!
242 //! @code
243 //! 0 1 2 3
244 //! 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
245 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
246 //! | NTP timestamp, most significant word |
247 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
248 //! | NTP timestamp, least significant word |
249 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
250 //! @endcode
251 //!
252 //! From RFC 3550.
254 private:
255  uint32_t high_;
256  uint32_t low_;
257 
258 public:
259  NtpTimestamp64() {
260  set_value(0);
261  }
262 
263  //! Get NTP timestamp value.
265  return ((packet::ntp_timestamp_t)core::ntoh32u(high_) << 32)
267  }
268 
269  //! Set NTP timestamp value.
271  high_ = core::hton32u((uint32_t)(t >> 32));
272  low_ = core::hton32u((uint32_t)t);
273  }
275 
276 //! 32-bit NTP absolute time (stored as middle 32 bits of 64-bit timestamp).
277 //!
278 //! @code
279 //! 0 1 2 3
280 //! 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
281 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
282 //! | Time |
283 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
284 //! @endcode
285 //!
286 //! From RFC 3550.
288 private:
289  uint32_t mid_;
290 
291 public:
292  NtpTimestamp32() {
293  set_value(0);
294  }
295 
296  //! Get NTP timestamp value.
298  return (packet::ntp_timestamp_t)core::ntoh32u(mid_) << 16;
299  }
300 
301  //! Set NTP timestamp value.
302  //! Stores middle 32 bits of timestamp.
303  //! High and low 16 bits are just truncated.
305  mid_ = core::hton32u(t >> 16);
306  }
308 
309 //! Reception report block.
310 //!
311 //! Part of RR and SR packets.
312 //!
313 //! RFC 3550 6.4.1: "SR: Sender Report RTCP Packet"
314 //! RFC 3550 6.4.2: "RR: Receiver Report RTCP Packet"
315 //!
316 //! @code
317 //! 0 1 2 3
318 //! 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
319 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
320 //! | SSRC |
321 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
322 //! | fraction lost | cumulative number of packets lost |
323 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
324 //! | extended highest sequence number received |
325 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
326 //! | interarrival jitter |
327 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
328 //! | last SR (LSR) |
329 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
330 //! | delay since last SR (DLSR) |
331 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
332 //! @endcode
334 private:
335  enum {
336  //! @name Fraction lost since last SR/RR.
337  // @{
338  FractLost_shift = 24,
339  FractLoss_width = 8,
340  FractLost_mask = 0xFF,
341  // @}
342 
343  //! @name Cumulative number of packets lost since the beginning.
344  // @{
345  CumLoss_shift = 0,
346  CumLoss_width = 24,
347  CumLoss_mask = 0xFFFFFF
348  // @}
349  };
350 
351  // Data source being reported.
352  uint32_t ssrc_;
353  // Fraction lost since last SR/RR and cumulative number of
354  // packets lost since the beginning of reception (signed!).
355  uint32_t losses_;
356  // Extended last seq. no. received.
357  uint32_t last_seq_;
358  // Interarrival jitter.
359  uint32_t jitter_;
360  // Last SR packet from this source.
361  NtpTimestamp32 last_sr_;
362  // Delay since last SR packet.
363  NtpTimestamp32 delay_last_sr_;
364 
365 public:
367  reset();
368  }
369 
370  //! Reset to initial state (all zeros).
371  void reset() {
372  ssrc_ = losses_ = last_seq_ = jitter_ = 0;
373  last_sr_.set_value(0);
374  delay_last_sr_.set_value(0);
375  }
376 
377  //! Get SSRC.
379  return core::ntoh32u(ssrc_);
380  }
381 
382  //! Set SSRC.
384  ssrc_ = core::hton32u(s);
385  }
386 
387  //! Get fraction lost.
388  float fract_loss() const {
389  const uint32_t losses = core::ntoh32u(losses_);
390 
391  const uint8_t fract_loss8 =
392  get_bit_field<uint32_t>(losses, FractLost_shift, FractLost_mask);
393 
394  return float(fract_loss8) / float(1 << FractLoss_width);
395  }
396 
397  //! Set fractional loss.
398  //! Fractional loss is stored in Q.8 format.
400  if (fract_loss > 1) {
401  fract_loss = 1;
402  }
403  if (fract_loss < 0) {
404  fract_loss = 0;
405  }
406 
407  uint32_t fract_loss8 = (uint32_t)(fract_loss * float(1 << FractLoss_width));
408  if (fract_loss8 > 0xFF) {
409  fract_loss8 = 0xFF;
410  }
411 
412  uint32_t losses = core::ntoh32u(losses_);
413  set_bit_field<uint32_t>(losses, fract_loss8, FractLost_shift, FractLost_mask);
414 
415  losses_ = core::hton32u(losses);
416  }
417 
418  //! Get cumulative loss.
419  //! May be negative in case of packet duplications.
420  int64_t cum_loss() const {
421  const uint32_t losses = core::ntoh32u(losses_);
422 
423  uint32_t cum_loss = get_bit_field<uint32_t>(losses, CumLoss_shift, CumLoss_mask);
424 
425  // If cum_loss is negative
426  if (cum_loss & (1 << (CumLoss_width - 1))) {
427  // Make whole leftest byte filled with 1.
428  cum_loss |= ~(uint32_t)CumLoss_mask;
429  }
430 
431  return (int64_t)(int32_t)cum_loss;
432  }
433 
434  //! Set cumulative loss.
435  //! May be negative in case of packet duplications.
436  void set_cum_loss(int64_t cum_loss) {
437  if (cum_loss > 0x7FFFFF) {
438  cum_loss = 0x7FFFFF;
439  } else if (cum_loss < -0x7FFFFF - 1) {
440  cum_loss = -0x7FFFFF - 1;
441  }
442 
443  uint32_t losses = core::ntoh32u(losses_);
444  set_bit_field<uint32_t>(losses, (uint32_t)(int32_t)cum_loss, CumLoss_shift,
445  CumLoss_mask);
446 
447  losses_ = core::hton32u(losses);
448  }
449 
450  //! Get last seqnum.
452  return core::ntoh32u(last_seq_);
453  }
454 
455  //! Set last seqnum.
457  last_seq_ = core::hton32u(x);
458  }
459 
460  //! Get jitter.
462  return core::ntoh32u(jitter_);
463  }
464 
465  //! Set jitter.
467  jitter_ = core::hton32u(x);
468  }
469 
470  //! Get LSR.
472  return last_sr_.value();
473  }
474 
475  //! Set LSR.
476  //! Stores only the middle 32 bits out of 64 in the NTP timestamp.
478  last_sr_.set_value(x);
479  }
480 
481  //! Get DLSR.
483  return delay_last_sr_.value();
484  }
485 
486  //! Set DLSR.
487  //! Stores only the middle 32 bits out of 64 in the NTP timestamp.
489  delay_last_sr_.set_value(ntp_clamp_32(x, MaxDelay));
490  }
492 
493 //! Receiver Report RTCP packet (RR).
494 //!
495 //! RFC 3550 6.4.2: "RR: Receiver Report RTCP packet"
496 //!
497 //! @code
498 //! 0 1 2 3
499 //! 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
500 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
501 //! header |V=2|P| RC | PT=RR=201 | length |
502 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
503 //! | SSRC of packet sender |
504 //! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
505 //! report | SSRC_1 (SSRC of first source) |
506 //! block +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
507 //! 1 | fraction lost | cumulative number of packets lost |
508 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
509 //! | extended highest sequence number received |
510 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
511 //! | interarrival jitter |
512 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
513 //! | last SR (LSR) |
514 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
515 //! | delay since last SR (DLSR) |
516 //! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
517 //! report | SSRC_2 (SSRC of second source) |
518 //! block +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
519 //! 2 : ... :
520 //! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
521 //! | profile-specific extensions |
522 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
523 //! @endcode
525 private:
526  PacketHeader header_;
527 
528  // Data source being reported.
529  uint32_t ssrc_;
530 
531 public:
533  reset();
534  }
535 
536  //! Reset to initial state (all zeros).
537  void reset() {
538  header_.reset(RTCP_RR);
539  ssrc_ = 0;
540  }
541 
542  //! Get common packet header.
543  const PacketHeader& header() const {
544  return header_;
545  }
546 
547  //! Get common packet header.
549  return header_;
550  }
551 
552  //! Get SSRC of packet sender.
554  return core::ntoh32u(ssrc_);
555  }
556 
557  //! Set SSRC of packet sender.
559  ssrc_ = core::hton32u(s);
560  }
561 
562  //! Get number of blocks.
563  size_t num_blocks() const {
564  return header_.counter();
565  }
566 
567  //! Get reception block by index.
568  const ReceptionReportBlock& get_block(const size_t i) const {
569  return get_block_by_index<const ReceptionReportBlock>(this, i, header().counter(),
570  "rtcp rr");
571  }
572 
573  //! Get reception block by index.
574  ReceptionReportBlock& get_block(const size_t i) {
575  return get_block_by_index<ReceptionReportBlock>(this, i, header().counter(),
576  "rtcp rr");
577  }
579 
580 //! Sender Report RTCP packet (SR).
581 //!
582 //! RFC 3550 6.4.1. "SR: Sender Report RTCP packet"
583 //!
584 //! @code
585 //! 0 1 2 3
586 //! 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
587 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
588 //! header |V=2|P| RC | PT=SR=200 | length |
589 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
590 //! | SSRC of sender |
591 //! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
592 //! sender | NTP timestamp, most significant word |
593 //! info +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
594 //! | NTP timestamp, least significant word |
595 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
596 //! | RTP timestamp |
597 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
598 //! | sender's packet count |
599 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
600 //! | sender's octet count |
601 //! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
602 //! report | SSRC_1 (SSRC of first source) |
603 //! block +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
604 //! 1 | fraction lost | cumulative number of packets lost |
605 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
606 //! | extended highest sequence number received |
607 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
608 //! | interarrival jitter |
609 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
610 //! | last SR (LSR) |
611 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
612 //! | delay since last SR (DLSR) |
613 //! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
614 //! report | SSRC_2 (SSRC of second source) |
615 //! block +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
616 //! 2 : ... :
617 //! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
618 //! | profile-specific extensions |
619 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
620 //! @endcode
622 private:
623  PacketHeader header_;
624 
625  uint32_t ssrc_;
626  NtpTimestamp64 ntp_timestamp_;
627  uint32_t rtp_timestamp_;
628  uint32_t packet_cnt_;
629  uint32_t bytes_cnt_;
630 
631 public:
633  reset();
634  }
635 
636  //! Reset to initial state (all zeros).
637  void reset() {
638  header_.reset(RTCP_SR);
639  ssrc_ = 0;
640  ntp_timestamp_.set_value(0);
641  rtp_timestamp_ = 0;
642  packet_cnt_ = 0;
643  bytes_cnt_ = 0;
644  }
645 
646  //! Get common packet header.
647  const PacketHeader& header() const {
648  return header_;
649  }
650 
651  //! Get common packet header.
653  return header_;
654  }
655 
656  //! Get SSRC of sender.
658  return core::ntoh32u(ssrc_);
659  }
660 
661  //! Set SSRC of sender.
663  ssrc_ = core::hton32u(s);
664  }
665 
666  //! Get NTP timestamp.
668  return ntp_timestamp_.value();
669  }
670 
671  //! Set NTP timestamp.
673  ntp_timestamp_.set_value(t);
674  }
675 
676  //! Get RTP timestamp.
678  return core::ntoh32u(rtp_timestamp_);
679  }
680 
681  //! Get RTP timestamp.
683  rtp_timestamp_ = core::hton32u(t);
684  }
685 
686  //! Get packet count.
687  uint32_t packet_count() const {
688  return core::ntoh32u(packet_cnt_);
689  }
690 
691  //! Set packet count.
692  void set_packet_count(const uint32_t cnt) {
693  packet_cnt_ = core::hton32u(cnt);
694  }
695 
696  //! Get byte count.
697  uint32_t byte_count() const {
698  return core::ntoh32u(bytes_cnt_);
699  }
700 
701  //! Set byte count.
702  void set_byte_count(const uint32_t cnt) {
703  bytes_cnt_ = core::hton32u(cnt);
704  }
705 
706  //! Get number of blocks.
707  size_t num_blocks() const {
708  return header_.counter();
709  }
710 
711  //! Get reception block by index.
712  const ReceptionReportBlock& get_block(const size_t i) const {
713  return get_block_by_index<const ReceptionReportBlock>(this, i, header().counter(),
714  "rtcp sr");
715  }
716 
717  //! Get reception block by index.
718  ReceptionReportBlock& get_block(const size_t i) {
719  return get_block_by_index<ReceptionReportBlock>(this, i, header().counter(),
720  "rtcp sr");
721  }
723 
724 //! SDES item type.
726  // RFC 3550
727  SDES_CNAME = 1, //!< Canonical End-Point Identifier.
728  SDES_NAME = 2, //!< User Name.
729  SDES_EMAIL = 3, //!< Electronic Mail Address.
730  SDES_PHONE = 4, //!< Phone Number.
731  SDES_LOC = 5, //!< Geographic User Location.
732  SDES_TOOL = 6, //!< Application or Tool Name.
733  SDES_NOTE = 7, //!< Notice/Status.
734  SDES_PRIV = 8 //!< Private Extensions.
735 };
736 
737 //! SDES chunk header.
738 //!
739 //! Part of SDES packet.
740 //!
741 //! RFC 3550 6.5: "SDES: Source Description RTCP packet"
742 //!
743 //! @code
744 //! 0 1 2 3
745 //! 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
746 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
747 //! | SSRC |
748 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
749 //! @endcode
751 private:
752  uint32_t ssrc_;
753 
754 public:
755  SdesChunkHeader() {
756  reset();
757  }
758 
759  //! Reset to initial state (all zeros).
760  void reset() {
761  ssrc_ = 0;
762  }
763 
764  //! Get SSRC.
766  return core::ntoh32u(ssrc_);
767  }
768 
769  //! Set SSRC.
771  ssrc_ = core::hton32u(s);
772  }
774 
775 //! SDES item header.
776 //!
777 //! Part of SDES packet.
778 //!
779 //! RFC 3550 6.5: "SDES: Source Description RTCP packet"
780 //!
781 //! @code
782 //! 0 1 2 3
783 //! 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
784 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
785 //! | Type | Length | Text in UTF-8 ...
786 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
787 //! @endcode
789 private:
790  uint8_t type_;
791  uint8_t len_;
792 
793 public:
794  SdesItemHeader() {
795  reset();
796  }
797 
798  //! Reset to initial state (all zeros).
799  void reset() {
800  type_ = len_ = 0;
801  }
802 
803  //! Get item type.
804  SdesItemType type() const {
805  return SdesItemType(type_);
806  }
807 
808  //! Set type.
809  void set_type(const SdesItemType t) {
810  type_ = t;
811  }
812 
813  //! Get item text length.
814  size_t text_len() const {
815  return len_;
816  }
817 
818  //! Set item text length.
819  void set_text_len(const size_t len) {
820  roc_panic_if(len > MaxTextLen);
821  len_ = (uint8_t)len;
822  }
823 
824  //! Get pointer to item text.
825  //! The text is NOT zero-terminated.
826  const uint8_t* text() const {
827  return (const uint8_t*)this + sizeof(*this);
828  }
829 
830  //! Get pointer to item text.
831  //! The text is NOT zero-terminated.
832  uint8_t* text() {
833  return (uint8_t*)this + sizeof(*this);
834  }
836 
837 //! Source Description RTCP packet (SDES).
838 //!
839 //! RFC 3550 6.5: "SDES: Source Description RTCP packet"
840 //!
841 //! @code
842 //! 0 1 2 3
843 //! 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
844 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
845 //! header |V=2|P| RC | PT=SDES=202 | length |
846 //! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
847 //! Chunk1 | SSRC_1 (SSRC of first source) |
848 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
849 //! Item1 | Type | Length | Text in UTF-8 |
850 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
851 //! Item2 | Type | Length | Text in UTF-8 |
852 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
853 //! Item 3 | Type | Length | Text in UTF-8 |
854 //! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
855 //! Chunk2 | SSRC_2 (SSRC of second source) |
856 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
857 //! Item1 | Type | Length | Text in UTF-8 |
858 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
859 //! Item2 | Type | Length | Text in UTF-8 |
860 //! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
861 //! : ... :
862 //! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
863 //! @endcode
865 private:
866  PacketHeader header_;
867 
868 public:
869  SdesPacket() {
870  reset();
871  }
872 
873  //! Reset to initial state (all zeros).
874  void reset() {
875  header_.reset(RTCP_SDES);
876  }
877 
878  //! Get common packet header.
879  const PacketHeader& header() const {
880  return header_;
881  }
882 
883  //! Get common packet header.
885  return header_;
886  }
888 
889 //! BYE source header.
890 //!
891 //! Part of BYE packet.
892 //!
893 //! RFC 3550 6.6: "BYE: Goodbye RTCP Packet"
894 //!
895 //! @code
896 //! 0 1 2 3
897 //! 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
898 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
899 //! | SSRC |
900 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
901 //! @endcode
903 private:
904  uint32_t ssrc_;
905 
906 public:
907  ByeSourceHeader() {
908  reset();
909  }
910 
911  //! Reset to initial state (all zeros).
912  void reset() {
913  ssrc_ = 0;
914  }
915 
916  //! Get SSRC.
918  return core::ntoh32u(ssrc_);
919  }
920 
921  //! Set SSRC.
923  ssrc_ = core::hton32u(s);
924  }
926 
927 //! BYE reason header.
928 //!
929 //! Part of BYE packet.
930 //!
931 //! RFC 3550 6.6: "BYE: Goodbye RTCP Packet"
932 //!
933 //! @code
934 //! 0 1 2 3
935 //! 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
936 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
937 //! | length | reason for leaving ...
938 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
939 //! @endcode
941 private:
942  uint8_t len_;
943 
944 public:
945  ByeReasonHeader() {
946  reset();
947  }
948 
949  //! Reset to initial state (all zeros).
950  void reset() {
951  len_ = 0;
952  }
953 
954  //! Get text length.
955  size_t text_len() const {
956  return len_;
957  }
958 
959  //! Set text length.
960  void set_text_len(const size_t len) {
961  roc_panic_if(len > MaxTextLen);
962  len_ = (uint8_t)len;
963  }
964 
965  //! Get pointer to text.
966  //! The text is NOT zero-terminated.
967  const uint8_t* text() const {
968  return (const uint8_t*)this + sizeof(*this);
969  }
970 
971  //! Get pointer to text.
972  //! The text is NOT zero-terminated.
973  uint8_t* text() {
974  return (uint8_t*)this + sizeof(*this);
975  }
977 
978 //! Goodbye RTCP packet (BYE).
979 //!
980 //! RFC 3550 6.6. "BYE: Goodbye RTCP packet"
981 //!
982 //! @code
983 //! 0 1 2 3
984 //! 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
985 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
986 //! |V=2|P| SC | PT=BYE=203 | length |
987 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
988 //! | SSRC/CSRC |
989 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
990 //! : ... :
991 //! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
992 //! (opt) | length | reason for leaving ...
993 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
994 //! @endcode
996 private:
997  PacketHeader header_;
998 
999 public:
1000  ByePacket() {
1001  reset();
1002  }
1003 
1004  //! Reset to initial state (all zeros).
1005  void reset() {
1006  header_.reset(RTCP_BYE);
1007  }
1008 
1009  //! Get common packet header.
1010  const PacketHeader& header() const {
1011  return header_;
1012  }
1013 
1014  //! Get common packet header.
1016  return header_;
1017  }
1019 
1020 //! RTCP Extended Report Packet.
1021 //!
1022 //! RFC 3611 2: "XR Packet Format"
1023 //!
1024 //! @code
1025 //! 0 1 2 3
1026 //! 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1027 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1028 //! |V=2|P|reserved | PT=XR=207 | length |
1029 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1030 //! | SSRC |
1031 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1032 //! : report blocks :
1033 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1034 //! @endcode
1036 private:
1037  PacketHeader header_;
1038 
1039  // Data source being reported.
1040  uint32_t ssrc_;
1041 
1042 public:
1043  XrPacket() {
1044  reset();
1045  }
1046 
1047  //! Reset to initial state (all zeros).
1048  void reset() {
1049  header_.reset(RTCP_XR);
1050  ssrc_ = 0;
1051  }
1052 
1053  //! Get common packet header.
1054  const PacketHeader& header() const {
1055  return header_;
1056  }
1057 
1058  //! Get common packet header.
1060  return header_;
1061  }
1062 
1063  //! Get SSRC of packet originator.
1065  return core::ntoh32u(ssrc_);
1066  }
1067 
1068  //! Set SSRC of packet originator.
1070  ssrc_ = core::hton32u(ssrc);
1071  }
1073 
1074 //! XR Block Type.
1076  // RFC 3611
1077  XR_RRTR = 4, //!< RRTR Report Block.
1078  XR_DLRR = 5, //!< DLRR Report Block.
1079  // RFC 6776
1080  XR_MEASUREMENT_INFO = 14, //!< Measurement Information Report Block.
1081  // RFC 6843
1082  XR_DELAY_METRICS = 16, //!< Delay Metrics Report Block.
1083  // Non-standard
1084  XR_QUEUE_METRICS = 220 //!< Queue Metrics Report Block.
1085 };
1086 
1087 //! XR Block Header.
1088 //!
1089 //! RFC 3611 3: "Extended Report Block Framework"
1090 //!
1091 //! @code
1092 //! 0 1 2 3
1093 //! 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1094 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1095 //! | BT | type-specific | block length |
1096 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1097 //! : type-specific block contents :
1098 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1099 //! @endcode
1101 private:
1102  uint8_t block_type_;
1103  uint8_t type_specific_;
1104  uint16_t length_;
1105 
1106 public:
1107  XrBlockHeader() {
1108  reset(XrBlockType(0));
1109  }
1110 
1111  //! Reset to initial state (all zeros).
1112  void reset(const XrBlockType bt) {
1113  block_type_ = type_specific_ = 0;
1114  length_ = 0;
1115  set_block_type(bt);
1116  }
1117 
1118  //! Get XR block type.
1120  return (XrBlockType)block_type_;
1121  }
1122 
1123  //! Set XR block type.
1124  void set_block_type(const XrBlockType bt) {
1125  block_type_ = (uint8_t)bt;
1126  }
1127 
1128  //! Get type-specific byte.
1129  uint8_t type_specific() const {
1130  return type_specific_;
1131  }
1132 
1133  //! Set type-specific byte.
1134  void set_type_specific(const uint8_t t) {
1135  type_specific_ = t;
1136  }
1137 
1138  //! Get block length, including the header, in 32-bit words minus one.
1139  uint16_t len_words() const {
1140  return core::ntoh16u(length_);
1141  }
1142 
1143  //! Set block length in words.
1144  void set_len_words(const uint16_t len) {
1145  length_ = core::hton16u(len);
1146  }
1147 
1148  //! Get block length, including the header, in bytes.
1149  size_t len_bytes() const {
1150  return rtcp_length_2_size_t(len_words());
1151  }
1152 
1153  //! Set block length in bytes.
1154  void set_len_bytes(const size_t len) {
1156  }
1158 
1159 //! XR Receiver Reference Time Report block.
1160 //!
1161 //! RFC 3611 4.4: "Receiver Reference Time Report Block"
1162 //!
1163 //! @code
1164 //! 0 1 2 3
1165 //! 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1166 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1167 //! | BT=4 | reserved | block length = 2 |
1168 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1169 //! | NTP timestamp, most significant word |
1170 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1171 //! | NTP timestamp, least significant word |
1172 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1173 //! @endcode
1175 private:
1176  XrBlockHeader header_;
1177 
1178  // Report time.
1179  NtpTimestamp64 ntp_timestamp_;
1180 
1181 public:
1182  XrRrtrBlock() {
1183  reset();
1184  }
1185 
1186  //! Reset to initial state (all zeros).
1187  void reset() {
1188  header_.reset(XR_RRTR);
1189  ntp_timestamp_.set_value(0);
1190  }
1191 
1192  //! Get common block header.
1193  const XrBlockHeader& header() const {
1194  return header_;
1195  }
1196 
1197  //! Get common block header.
1199  return header_;
1200  }
1201 
1202  //! Get NTP timestamp.
1204  return ntp_timestamp_.value();
1205  }
1206 
1207  //! Set NTP timestamp.
1209  ntp_timestamp_.set_value(t);
1210  }
1212 
1213 //! XR DLRR Report sub-block.
1214 //!
1215 //! RFC 3611 4.5: "DLRR Report Sub-block"
1216 //!
1217 //! @code
1218 //! 0 1 2 3
1219 //! 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1220 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1221 //! | SSRC |
1222 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1223 //! | last RR (LRR) |
1224 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1225 //! | delay since last RR (DLRR) |
1226 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1227 //! @endcode
1229 private:
1230  uint32_t ssrc_;
1231  NtpTimestamp32 last_rr_;
1232  NtpTimestamp32 delay_last_rr_;
1233 
1234 public:
1235  XrDlrrSubblock() {
1236  reset();
1237  }
1238 
1239  //! Reset to initial state (all zeros).
1240  void reset() {
1241  ssrc_ = 0;
1242  last_rr_.set_value(0);
1243  delay_last_rr_.set_value(0);
1244  }
1245 
1246  //! Get SSRC of receiver.
1248  return core::ntoh32u(ssrc_);
1249  }
1250 
1251  //! Set SSRC of receiver.
1253  ssrc_ = core::hton32u(ssrc);
1254  }
1255 
1256  //! Get LRR.
1258  return last_rr_.value();
1259  }
1260 
1261  //! Set LRR.
1262  //! Stores only the middle 32 bits out of 64 in the NTP timestamp.
1264  last_rr_.set_value(x);
1265  }
1266 
1267  //! Get DLRR.
1269  return delay_last_rr_.value();
1270  }
1271 
1272  //! Set DLRR.
1273  //! Stores only the middle 32 bits out of 64 in the NTP timestamp.
1275  delay_last_rr_.set_value(ntp_clamp_32(x, MaxDelay));
1276  }
1278 
1279 //! XR DLRR Report block.
1280 //!
1281 //! Provides delay since last receiver report (DLRR) for each receiver,
1282 //! complementing to DLSR.
1283 //!
1284 //! RFC 3611 4.5: "DLRR Report Block"
1285 //!
1286 //! @code
1287 //! 0 1 2 3
1288 //! 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1289 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1290 //! | BT=5 | reserved | block length |
1291 //! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
1292 //! | SSRC_1 (SSRC of first receiver) | sub-
1293 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ block
1294 //! | last RR (LRR) | 1
1295 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1296 //! | delay since last RR (DLRR) |
1297 //! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
1298 //! | SSRC_2 (SSRC of second receiver) | sub-
1299 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ block
1300 //! : ... : 2
1301 //! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
1302 //! @endcode
1304 private:
1305  XrBlockHeader header_;
1306 
1307 public:
1308  XrDlrrBlock() {
1309  reset();
1310  }
1311 
1312  //! Reset to initial state (all zeros).
1313  void reset() {
1314  header_.reset(XR_DLRR);
1315  }
1316 
1317  //! Get common block header.
1318  const XrBlockHeader& header() const {
1319  return header_;
1320  }
1321 
1322  //! Get common block header.
1324  return header_;
1325  }
1326 
1327  //! Get number of sub-blocks.
1328  size_t num_subblocks() const {
1329  return (header_.len_bytes() - sizeof(header_)) / sizeof(XrDlrrSubblock);
1330  }
1331 
1332  //! Get DLRR sub-block by index.
1333  const XrDlrrSubblock& get_subblock(const size_t i) const {
1334  return get_block_by_index<const XrDlrrSubblock>(this, i, num_subblocks(),
1335  "rtcp xr_dlrr");
1336  }
1337 
1338  //! Get DLRR sub-block by index.
1339  XrDlrrSubblock& get_subblock(const size_t i) {
1340  return get_block_by_index<XrDlrrSubblock>(this, i, num_subblocks(),
1341  "rtcp xr_dlrr");
1342  }
1344 
1345 //! XR Measurement Info Report Block.
1346 //!
1347 //! Defines measurement interval associated with other metrics blocks,
1348 //! in particular XrDelayMetricsBlock.
1349 //!
1350 //! RFC 6776 4.1: "Report Block Structure"
1351 //!
1352 //! @code
1353 //! 0 1 2 3
1354 //! 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
1355 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1356 //! | BT=14 | Reserved | block length = 7 |
1357 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1358 //! | SSRC of stream source |
1359 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1360 //! | Reserved | first sequence number |
1361 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1362 //! | extended first sequence number of interval |
1363 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1364 //! | extended last sequence number |
1365 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1366 //! | Measurement Duration (Interval) |
1367 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1368 //! | Measurement Duration (Cumulative) - Seconds (bit 0-31) |
1369 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1370 //! | Measurement Duration (Cumulative) - Fraction (bit 0-31) |
1371 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1372 //! @endcode
1374 private:
1375  XrBlockHeader header_;
1376 
1377  uint32_t ssrc_;
1378  uint16_t reserved_;
1379  uint16_t first_seq_;
1380  uint32_t interval_first_seq_;
1381  uint32_t interval_last_seq_;
1382  NtpTimestamp32 interval_duration_;
1383  NtpTimestamp64 cum_duration_;
1384 
1385 public:
1387  reset();
1388  }
1389 
1390  //! Reset to initial state (all zeros).
1391  void reset() {
1392  header_.reset(XR_MEASUREMENT_INFO);
1393  ssrc_ = 0;
1394  reserved_ = 0;
1395  first_seq_ = 0;
1396  interval_first_seq_ = interval_last_seq_ = 0;
1397  interval_duration_.set_value(0);
1398  cum_duration_.set_value(0);
1399  }
1400 
1401  //! Get common block header.
1402  const XrBlockHeader& header() const {
1403  return header_;
1404  }
1405 
1406  //! Get common block header.
1408  return header_;
1409  }
1410 
1411  //! Get SSRC of source being reported.
1413  return core::ntoh32u(ssrc_);
1414  }
1415 
1416  //! Set SSRC of source being reported.
1418  ssrc_ = core::hton32u(ssrc);
1419  }
1420 
1421  //! Get seqnum of first ever received packet.
1423  return core::ntoh16u(first_seq_);
1424  }
1425 
1426  //! Set seqnum of first ever received packet.
1428  first_seq_ = core::hton16u(x);
1429  }
1430 
1431  //! Get extended seqnum of first packet in interval.
1433  return core::ntoh32u(interval_first_seq_);
1434  }
1435 
1436  //! Set extended seqnum of first packet in interval.
1438  interval_first_seq_ = core::hton32u(x);
1439  }
1440 
1441  //! Get extended seqnum of last packet in interval.
1443  return core::ntoh32u(interval_last_seq_);
1444  }
1445 
1446  //! Set extended seqnum of last packet in interval.
1448  interval_last_seq_ = core::hton32u(x);
1449  }
1450 
1451  //! Get measurement interval duration.
1452  //! Applicable to MetricFlag_IntervalDuration reports.
1454  return interval_duration_.value();
1455  }
1456 
1457  //! Set measurement interval duration.
1458  //! Stores only the middle 32 bits out of 64 in the NTP timestamp.
1460  interval_duration_.set_value(ntp_clamp_32(x, MaxDelay));
1461  }
1462 
1463  //! Get measurement cumulative duration.
1464  //! Applicable to MetricFlag_CumulativeDuration reports.
1466  return cum_duration_.value();
1467  }
1468 
1469  //! Set measurement cumulative duration.
1471  cum_duration_.set_value(t);
1472  }
1473 };
1474 
1475 //! Interval Metric flag for XR Delay Metrics Block.
1477  //! Interval Duration.
1478  //! The reported value applies to the most recent measurement interval
1479  //! duration between successive metrics reports.
1481 
1482  //! Cumulative Duration.
1483  //! The reported value applies to the accumulation period characteristic
1484  //! of cumulative measurements.
1486 
1487  //! Sampled Value.
1488  //! The reported value is a sampled instantaneous value.
1490 };
1491 
1492 //! XR Delay Metrics Block.
1493 //!
1494 //! RFC 6843 3.1: "Report Block Structure"
1495 //!
1496 //! @code
1497 //! 0 1 2 3
1498 //! 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
1499 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1500 //! | BT=16 | I | resv. | block length = 6 |
1501 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1502 //! | SSRC of Source |
1503 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1504 //! | Mean Network Round-Trip Delay |
1505 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1506 //! | Min Network Round-Trip Delay |
1507 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1508 //! | Max Network Round-Trip Delay |
1509 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1510 //! | End System Delay - Seconds (bit 0-31) |
1511 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1512 //! | End System Delay - Fraction (bit 0-31) |
1513 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1514 //! @endcode
1516 private:
1517  enum {
1518  MetricFlag_shift = 6,
1519  MetricFlag_mask = 0x03,
1520  };
1521 
1522  XrBlockHeader header_;
1523 
1524  uint32_t ssrc_;
1525  NtpTimestamp32 mean_rtt_;
1526  NtpTimestamp32 min_rtt_;
1527  NtpTimestamp32 max_rtt_;
1528  NtpTimestamp64 e2e_latency_;
1529 
1530 public:
1532  reset();
1533  }
1534 
1535  //! Reset to initial state (all zeros).
1536  void reset() {
1537  header_.reset(XR_DELAY_METRICS);
1538  ssrc_ = 0;
1539  mean_rtt_.set_value(MetricUnavail_32);
1540  min_rtt_.set_value(MetricUnavail_32);
1541  max_rtt_.set_value(MetricUnavail_32);
1542  e2e_latency_.set_value(MetricUnavail_64);
1543  }
1544 
1545  //! Get common block header.
1546  const XrBlockHeader& header() const {
1547  return header_;
1548  }
1549 
1550  //! Get common block header.
1552  return header_;
1553  }
1554 
1555  //! Get Interval Metrics flag.
1557  return (MetricFlag)get_bit_field<uint8_t>(header_.type_specific(),
1558  MetricFlag_shift, MetricFlag_mask);
1559  }
1560 
1561  //! Set Interval Metrics flag.
1562  void set_metric_flag(const MetricFlag f) {
1563  uint8_t t = header_.type_specific();
1564  set_bit_field<uint8_t>(t, (uint8_t)f, MetricFlag_shift, MetricFlag_mask);
1565  header_.set_type_specific(t);
1566  }
1567 
1568  //! Get SSRC of source being reported.
1570  return core::ntoh32u(ssrc_);
1571  }
1572 
1573  //! Set SSRC of source being reported.
1575  ssrc_ = core::hton32u(ssrc);
1576  }
1577 
1578  //! Check if Mean Network Round-Trip Delay is set.
1579  bool has_mean_rtt() const {
1580  return mean_rtt_.value() != MetricUnavail_32;
1581  }
1582 
1583  //! Get Mean Network Round-Trip Delay.
1585  return mean_rtt_.value();
1586  }
1587 
1588  //! Set Mean Network Round-Trip Delay.
1589  //! Stores only the middle 32 bits out of 64 in the NTP timestamp.
1591  mean_rtt_.set_value(ntp_clamp_32(x, MetricUnavail_32 - 1));
1592  }
1593 
1594  //! Check if Minimum Network Round-Trip Delay is set.
1595  bool has_min_rtt() const {
1596  return min_rtt_.value() != MetricUnavail_32;
1597  }
1598 
1599  //! Get Minimum Network Round-Trip Delay.
1601  return min_rtt_.value();
1602  }
1603 
1604  //! Set Minimum Network Round-Trip Delay.
1605  //! Stores only the middle 32 bits out of 64 in the NTP timestamp.
1607  min_rtt_.set_value(ntp_clamp_32(x, MetricUnavail_32 - 1));
1608  }
1609 
1610  //! Check if Maximum Network Round-Trip Delay is set.
1611  bool has_max_rtt() const {
1612  return max_rtt_.value() != MetricUnavail_32;
1613  }
1614 
1615  //! Get Maximum Network Round-Trip Delay.
1617  return max_rtt_.value();
1618  }
1619 
1620  //! Set Maximum Network Round-Trip Delay.
1621  //! Stores only the middle 32 bits out of 64 in the NTP timestamp.
1623  max_rtt_.set_value(ntp_clamp_32(x, MetricUnavail_32 - 1));
1624  }
1625 
1626  //! Check if End System Delay is set.
1627  bool has_e2e_latency() const {
1628  return e2e_latency_.value() != MetricUnavail_64;
1629  }
1630 
1631  //! Get End System Delay.
1633  return e2e_latency_.value();
1634  }
1635 
1636  //! Set End System Delay.
1638  e2e_latency_.set_value(ntp_clamp_64(t, MetricUnavail_64 - 1));
1639  }
1641 
1642 //! XR Queue Metrics Block.
1643 //!
1644 //! Non-standard.
1645 //!
1646 //! Reports two metrics from receiver to sender:
1647 //!
1648 //! - niq_latency: current length of network incoming queue, measured via timestamp
1649 //! difference between last received packet and last decoded packet
1650 //! (expressed in units of 1/65536 seconds)
1651 //!
1652 //! - niq_stalling: current elapsed time since last received packet
1653 //! (expressed in units of 1/65536 seconds)
1654 //!
1655 //! @code
1656 //! 0 1 2 3
1657 //! 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
1658 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1659 //! | BT=220 | I | resv. | block length = 3 |
1660 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1661 //! | SSRC of Source |
1662 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1663 //! | Network Incoming Queue Latency |
1664 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1665 //! | Network Incoming Queue Stalling |
1666 //! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1667 //! @endcode
1669 private:
1670  enum {
1671  MetricFlag_shift = 6,
1672  MetricFlag_mask = 0x03,
1673  };
1674 
1675  XrBlockHeader header_;
1676 
1677  uint32_t ssrc_;
1678  NtpTimestamp32 niq_latency_;
1679  NtpTimestamp32 niq_stalling_;
1680 
1681 public:
1683  reset();
1684  }
1685 
1686  //! Reset to initial state (all zeros).
1687  void reset() {
1688  header_.reset(XR_QUEUE_METRICS);
1689  ssrc_ = 0;
1690  niq_latency_.set_value(MetricUnavail_32);
1691  niq_stalling_.set_value(MetricUnavail_32);
1692  }
1693 
1694  //! Get common block header.
1695  const XrBlockHeader& header() const {
1696  return header_;
1697  }
1698 
1699  //! Get common block header.
1701  return header_;
1702  }
1703 
1704  //! Get Interval Metrics flag.
1706  return (MetricFlag)get_bit_field<uint8_t>(header_.type_specific(),
1707  MetricFlag_shift, MetricFlag_mask);
1708  }
1709 
1710  //! Set Interval Metrics flag.
1711  void set_metric_flag(const MetricFlag f) {
1712  uint8_t t = header_.type_specific();
1713  set_bit_field<uint8_t>(t, (uint8_t)f, MetricFlag_shift, MetricFlag_mask);
1714  header_.set_type_specific(t);
1715  }
1716 
1717  //! Get SSRC of source being reported.
1719  return core::ntoh32u(ssrc_);
1720  }
1721 
1722  //! Set SSRC of source being reported.
1724  ssrc_ = core::hton32u(ssrc);
1725  }
1726 
1727  //! Check if Network Incoming Queue Delay is set.
1728  bool has_niq_latency() const {
1729  return niq_latency_.value() != MetricUnavail_32;
1730  }
1731 
1732  //! Get Network Incoming Queue Delay.
1734  return niq_latency_.value();
1735  }
1736 
1737  //! Set Network Incoming Queue Delay.
1739  niq_latency_.set_value(ntp_clamp_32(t, MetricUnavail_32 - 1));
1740  }
1741 
1742  //! Check if Network Incoming Queue Stalling is set.
1743  bool has_niq_stalling() const {
1744  return niq_stalling_.value() != MetricUnavail_32;
1745  }
1746 
1747  //! Get Network Incoming Queue Stalling.
1749  return niq_stalling_.value();
1750  }
1751 
1752  //! Set Network Incoming Queue Stalling.
1754  niq_stalling_.set_value(ntp_clamp_32(t, MetricUnavail_32 - 1));
1755  }
1757 
1758 } // namespace header
1759 } // namespace rtcp
1760 } // namespace roc
1761 
1762 #endif // ROC_RTCP_HEADERS_H_
Compiler attributes.
#define ROC_ATTR_PACKED_BEGIN
Pack structure fields. Place these before class or struct keyword.
Definition: attributes.h:55
#define ROC_ATTR_PACKED_END
Pack structure fields. Place these between '}' and ';'.
Definition: attributes.h:58
Goodbye RTCP packet (BYE).
Definition: headers.h:995
const PacketHeader & header() const
Get common packet header.
Definition: headers.h:1010
void reset()
Reset to initial state (all zeros).
Definition: headers.h:1005
PacketHeader & header()
Get common packet header.
Definition: headers.h:1015
const uint8_t * text() const
Get pointer to text. The text is NOT zero-terminated.
Definition: headers.h:967
size_t text_len() const
Get text length.
Definition: headers.h:955
uint8_t * text()
Get pointer to text. The text is NOT zero-terminated.
Definition: headers.h:973
void set_text_len(const size_t len)
Set text length.
Definition: headers.h:960
void reset()
Reset to initial state (all zeros).
Definition: headers.h:950
void reset()
Reset to initial state (all zeros).
Definition: headers.h:912
packet::stream_source_t ssrc() const
Get SSRC.
Definition: headers.h:917
void set_ssrc(const packet::stream_source_t s)
Set SSRC.
Definition: headers.h:922
32-bit NTP absolute time (stored as middle 32 bits of 64-bit timestamp).
Definition: headers.h:287
packet::ntp_timestamp_t value() const
Get NTP timestamp value.
Definition: headers.h:297
void set_value(const packet::ntp_timestamp_t t)
Set NTP timestamp value. Stores middle 32 bits of timestamp. High and low 16 bits are just truncated.
Definition: headers.h:304
64-bit NTP timestamp.
Definition: headers.h:253
packet::ntp_timestamp_t value() const
Get NTP timestamp value.
Definition: headers.h:264
void set_value(const packet::ntp_timestamp_t t)
Set NTP timestamp value.
Definition: headers.h:270
RTCP packet header, common for all RTCP packet types.
Definition: headers.h:126
uint16_t len_words() const
Get packet length, including the header, in 32-bit words minus one.
Definition: headers.h:220
PacketType type() const
Get packet type.
Definition: headers.h:209
void set_padding(const bool v)
Set padding flag.
Definition: headers.h:204
void set_counter(const size_t c)
Set number of blocks/chunks.
Definition: headers.h:177
uint8_t version() const
Get protocol version.
Definition: headers.h:188
void reset(const PacketType t)
Reset to initial state (all zeros).
Definition: headers.h:162
void inc_counter()
Increment packet counter,.
Definition: headers.h:183
void set_version(const Version v)
Set protocol version.
Definition: headers.h:193
void set_len_words(const uint16_t len)
Set packet length in words.
Definition: headers.h:225
size_t counter() const
Get number of blocks/chunks following.
Definition: headers.h:172
void set_type(const PacketType t)
Set packet type.
Definition: headers.h:214
bool has_padding() const
Get padding flag.
Definition: headers.h:199
size_t len_bytes() const
Get packet length, including the header, in bytes.
Definition: headers.h:230
void set_len_bytes(const size_t len)
Set packet length in bytes.
Definition: headers.h:235
Receiver Report RTCP packet (RR).
Definition: headers.h:524
PacketHeader & header()
Get common packet header.
Definition: headers.h:548
packet::stream_source_t ssrc() const
Get SSRC of packet sender.
Definition: headers.h:553
void set_ssrc(const packet::stream_source_t s)
Set SSRC of packet sender.
Definition: headers.h:558
const PacketHeader & header() const
Get common packet header.
Definition: headers.h:543
ReceptionReportBlock & get_block(const size_t i)
Get reception block by index.
Definition: headers.h:574
const ReceptionReportBlock & get_block(const size_t i) const
Get reception block by index.
Definition: headers.h:568
void reset()
Reset to initial state (all zeros).
Definition: headers.h:537
size_t num_blocks() const
Get number of blocks.
Definition: headers.h:563
Reception report block.
Definition: headers.h:333
void set_jitter(const packet::stream_timestamp_t x)
Set jitter.
Definition: headers.h:466
packet::stream_timestamp_t jitter() const
Get jitter.
Definition: headers.h:461
void set_cum_loss(int64_t cum_loss)
Set cumulative loss. May be negative in case of packet duplications.
Definition: headers.h:436
void set_fract_loss(float fract_loss)
Set fractional loss. Fractional loss is stored in Q.8 format.
Definition: headers.h:399
int64_t cum_loss() const
Get cumulative loss. May be negative in case of packet duplications.
Definition: headers.h:420
float fract_loss() const
Get fraction lost.
Definition: headers.h:388
void set_ssrc(const packet::stream_source_t s)
Set SSRC.
Definition: headers.h:383
void set_delay_last_sr(const packet::ntp_timestamp_t x)
Set DLSR. Stores only the middle 32 bits out of 64 in the NTP timestamp.
Definition: headers.h:488
void set_last_sr(const packet::ntp_timestamp_t x)
Set LSR. Stores only the middle 32 bits out of 64 in the NTP timestamp.
Definition: headers.h:477
packet::stream_source_t ssrc() const
Get SSRC.
Definition: headers.h:378
packet::ntp_timestamp_t delay_last_sr() const
Get DLSR.
Definition: headers.h:482
packet::ntp_timestamp_t last_sr() const
Get LSR.
Definition: headers.h:471
void set_last_seqnum(const packet::ext_seqnum_t x)
Set last seqnum.
Definition: headers.h:456
packet::ext_seqnum_t last_seqnum() const
Get last seqnum.
Definition: headers.h:451
void reset()
Reset to initial state (all zeros).
Definition: headers.h:371
void set_ssrc(const packet::stream_source_t s)
Set SSRC.
Definition: headers.h:770
void reset()
Reset to initial state (all zeros).
Definition: headers.h:760
packet::stream_source_t ssrc() const
Get SSRC.
Definition: headers.h:765
SdesItemType type() const
Get item type.
Definition: headers.h:804
uint8_t * text()
Get pointer to item text. The text is NOT zero-terminated.
Definition: headers.h:832
size_t text_len() const
Get item text length.
Definition: headers.h:814
void set_type(const SdesItemType t)
Set type.
Definition: headers.h:809
void set_text_len(const size_t len)
Set item text length.
Definition: headers.h:819
const uint8_t * text() const
Get pointer to item text. The text is NOT zero-terminated.
Definition: headers.h:826
void reset()
Reset to initial state (all zeros).
Definition: headers.h:799
Source Description RTCP packet (SDES).
Definition: headers.h:864
const PacketHeader & header() const
Get common packet header.
Definition: headers.h:879
PacketHeader & header()
Get common packet header.
Definition: headers.h:884
void reset()
Reset to initial state (all zeros).
Definition: headers.h:874
Sender Report RTCP packet (SR).
Definition: headers.h:621
void set_ssrc(const packet::stream_source_t s)
Set SSRC of sender.
Definition: headers.h:662
uint32_t packet_count() const
Get packet count.
Definition: headers.h:687
const ReceptionReportBlock & get_block(const size_t i) const
Get reception block by index.
Definition: headers.h:712
ReceptionReportBlock & get_block(const size_t i)
Get reception block by index.
Definition: headers.h:718
PacketHeader & header()
Get common packet header.
Definition: headers.h:652
void reset()
Reset to initial state (all zeros).
Definition: headers.h:637
size_t num_blocks() const
Get number of blocks.
Definition: headers.h:707
void set_rtp_timestamp(const packet::stream_timestamp_t t)
Get RTP timestamp.
Definition: headers.h:682
packet::ntp_timestamp_t ntp_timestamp() const
Get NTP timestamp.
Definition: headers.h:667
const PacketHeader & header() const
Get common packet header.
Definition: headers.h:647
void set_byte_count(const uint32_t cnt)
Set byte count.
Definition: headers.h:702
packet::stream_timestamp_t rtp_timestamp() const
Get RTP timestamp.
Definition: headers.h:677
uint32_t byte_count() const
Get byte count.
Definition: headers.h:697
void set_ntp_timestamp(const packet::ntp_timestamp_t t)
Set NTP timestamp.
Definition: headers.h:672
void set_packet_count(const uint32_t cnt)
Set packet count.
Definition: headers.h:692
packet::stream_source_t ssrc() const
Get SSRC of sender.
Definition: headers.h:657
uint16_t len_words() const
Get block length, including the header, in 32-bit words minus one.
Definition: headers.h:1139
void set_len_words(const uint16_t len)
Set block length in words.
Definition: headers.h:1144
void set_type_specific(const uint8_t t)
Set type-specific byte.
Definition: headers.h:1134
void reset(const XrBlockType bt)
Reset to initial state (all zeros).
Definition: headers.h:1112
size_t len_bytes() const
Get block length, including the header, in bytes.
Definition: headers.h:1149
void set_len_bytes(const size_t len)
Set block length in bytes.
Definition: headers.h:1154
void set_block_type(const XrBlockType bt)
Set XR block type.
Definition: headers.h:1124
uint8_t type_specific() const
Get type-specific byte.
Definition: headers.h:1129
XrBlockType block_type() const
Get XR block type.
Definition: headers.h:1119
XR Delay Metrics Block.
Definition: headers.h:1515
packet::stream_source_t ssrc() const
Get SSRC of source being reported.
Definition: headers.h:1569
bool has_min_rtt() const
Check if Minimum Network Round-Trip Delay is set.
Definition: headers.h:1595
void set_e2e_latency(const packet::ntp_timestamp_t t)
Set End System Delay.
Definition: headers.h:1637
packet::ntp_timestamp_t min_rtt() const
Get Minimum Network Round-Trip Delay.
Definition: headers.h:1600
bool has_max_rtt() const
Check if Maximum Network Round-Trip Delay is set.
Definition: headers.h:1611
packet::ntp_timestamp_t mean_rtt() const
Get Mean Network Round-Trip Delay.
Definition: headers.h:1584
XrBlockHeader & header()
Get common block header.
Definition: headers.h:1551
void set_metric_flag(const MetricFlag f)
Set Interval Metrics flag.
Definition: headers.h:1562
void reset()
Reset to initial state (all zeros).
Definition: headers.h:1536
void set_ssrc(const packet::stream_source_t ssrc)
Set SSRC of source being reported.
Definition: headers.h:1574
bool has_mean_rtt() const
Check if Mean Network Round-Trip Delay is set.
Definition: headers.h:1579
void set_min_rtt(const packet::ntp_timestamp_t x)
Set Minimum Network Round-Trip Delay. Stores only the middle 32 bits out of 64 in the NTP timestamp.
Definition: headers.h:1606
bool has_e2e_latency() const
Check if End System Delay is set.
Definition: headers.h:1627
void set_mean_rtt(const packet::ntp_timestamp_t x)
Set Mean Network Round-Trip Delay. Stores only the middle 32 bits out of 64 in the NTP timestamp.
Definition: headers.h:1590
packet::ntp_timestamp_t e2e_latency() const
Get End System Delay.
Definition: headers.h:1632
MetricFlag metric_flag() const
Get Interval Metrics flag.
Definition: headers.h:1556
void set_max_rtt(const packet::ntp_timestamp_t x)
Set Maximum Network Round-Trip Delay. Stores only the middle 32 bits out of 64 in the NTP timestamp.
Definition: headers.h:1622
packet::ntp_timestamp_t max_rtt() const
Get Maximum Network Round-Trip Delay.
Definition: headers.h:1616
const XrBlockHeader & header() const
Get common block header.
Definition: headers.h:1546
XR DLRR Report block.
Definition: headers.h:1303
const XrBlockHeader & header() const
Get common block header.
Definition: headers.h:1318
const XrDlrrSubblock & get_subblock(const size_t i) const
Get DLRR sub-block by index.
Definition: headers.h:1333
XrDlrrSubblock & get_subblock(const size_t i)
Get DLRR sub-block by index.
Definition: headers.h:1339
XrBlockHeader & header()
Get common block header.
Definition: headers.h:1323
size_t num_subblocks() const
Get number of sub-blocks.
Definition: headers.h:1328
void reset()
Reset to initial state (all zeros).
Definition: headers.h:1313
XR DLRR Report sub-block.
Definition: headers.h:1228
void set_delay_last_rr(const packet::ntp_timestamp_t x)
Set DLRR. Stores only the middle 32 bits out of 64 in the NTP timestamp.
Definition: headers.h:1274
void set_last_rr(const packet::ntp_timestamp_t x)
Set LRR. Stores only the middle 32 bits out of 64 in the NTP timestamp.
Definition: headers.h:1263
void reset()
Reset to initial state (all zeros).
Definition: headers.h:1240
packet::ntp_timestamp_t last_rr() const
Get LRR.
Definition: headers.h:1257
packet::ntp_timestamp_t delay_last_rr() const
Get DLRR.
Definition: headers.h:1268
packet::stream_source_t ssrc() const
Get SSRC of receiver.
Definition: headers.h:1247
void set_ssrc(const packet::stream_source_t ssrc)
Set SSRC of receiver.
Definition: headers.h:1252
XR Measurement Info Report Block.
Definition: headers.h:1373
void set_interval_last_seq(const packet::ext_seqnum_t x)
Set extended seqnum of last packet in interval.
Definition: headers.h:1447
packet::ntp_timestamp_t cum_duration() const
Get measurement cumulative duration. Applicable to MetricFlag_CumulativeDuration reports.
Definition: headers.h:1465
void reset()
Reset to initial state (all zeros).
Definition: headers.h:1391
const XrBlockHeader & header() const
Get common block header.
Definition: headers.h:1402
void set_cum_duration(const packet::ntp_timestamp_t t)
Set measurement cumulative duration.
Definition: headers.h:1470
void set_interval_duration(const packet::ntp_timestamp_t x)
Set measurement interval duration. Stores only the middle 32 bits out of 64 in the NTP timestamp.
Definition: headers.h:1459
void set_first_seq(const packet::seqnum_t x)
Set seqnum of first ever received packet.
Definition: headers.h:1427
packet::ext_seqnum_t interval_first_seq() const
Get extended seqnum of first packet in interval.
Definition: headers.h:1432
void set_interval_first_seq(const packet::ext_seqnum_t x)
Set extended seqnum of first packet in interval.
Definition: headers.h:1437
packet::seqnum_t first_seq() const
Get seqnum of first ever received packet.
Definition: headers.h:1422
packet::ext_seqnum_t interval_last_seq() const
Get extended seqnum of last packet in interval.
Definition: headers.h:1442
packet::ntp_timestamp_t interval_duration() const
Get measurement interval duration. Applicable to MetricFlag_IntervalDuration reports.
Definition: headers.h:1453
packet::stream_source_t ssrc() const
Get SSRC of source being reported.
Definition: headers.h:1412
XrBlockHeader & header()
Get common block header.
Definition: headers.h:1407
void set_ssrc(const packet::stream_source_t ssrc)
Set SSRC of source being reported.
Definition: headers.h:1417
RTCP Extended Report Packet.
Definition: headers.h:1035
void set_ssrc(const packet::stream_source_t ssrc)
Set SSRC of packet originator.
Definition: headers.h:1069
const PacketHeader & header() const
Get common packet header.
Definition: headers.h:1054
PacketHeader & header()
Get common packet header.
Definition: headers.h:1059
packet::stream_source_t ssrc() const
Get SSRC of packet originator.
Definition: headers.h:1064
void reset()
Reset to initial state (all zeros).
Definition: headers.h:1048
XR Queue Metrics Block.
Definition: headers.h:1668
MetricFlag metric_flag() const
Get Interval Metrics flag.
Definition: headers.h:1705
void set_ssrc(const packet::stream_source_t ssrc)
Set SSRC of source being reported.
Definition: headers.h:1723
XrBlockHeader & header()
Get common block header.
Definition: headers.h:1700
void set_metric_flag(const MetricFlag f)
Set Interval Metrics flag.
Definition: headers.h:1711
bool has_niq_latency() const
Check if Network Incoming Queue Delay is set.
Definition: headers.h:1728
packet::ntp_timestamp_t niq_latency() const
Get Network Incoming Queue Delay.
Definition: headers.h:1733
packet::ntp_timestamp_t niq_stalling() const
Get Network Incoming Queue Stalling.
Definition: headers.h:1748
packet::stream_source_t ssrc() const
Get SSRC of source being reported.
Definition: headers.h:1718
void reset()
Reset to initial state (all zeros).
Definition: headers.h:1687
void set_niq_latency(const packet::ntp_timestamp_t t)
Set Network Incoming Queue Delay.
Definition: headers.h:1738
bool has_niq_stalling() const
Check if Network Incoming Queue Stalling is set.
Definition: headers.h:1743
const XrBlockHeader & header() const
Get common block header.
Definition: headers.h:1695
void set_niq_stalling(const packet::ntp_timestamp_t t)
Set Network Incoming Queue Stalling.
Definition: headers.h:1753
XR Receiver Reference Time Report block.
Definition: headers.h:1174
XrBlockHeader & header()
Get common block header.
Definition: headers.h:1198
void set_ntp_timestamp(const packet::ntp_timestamp_t t)
Set NTP timestamp.
Definition: headers.h:1208
const XrBlockHeader & header() const
Get common block header.
Definition: headers.h:1193
packet::ntp_timestamp_t ntp_timestamp() const
Get NTP timestamp.
Definition: headers.h:1203
void reset()
Reset to initial state (all zeros).
Definition: headers.h:1187
Endian conversion functions.
uint16_t hton16u(uint16_t v)
Host to network byte order (unsigned 16-bit).
Definition: endian.h:54
uint16_t ntoh16u(uint16_t v)
Network to host byte order (unsigned 16-bit).
Definition: endian.h:24
uint32_t hton32u(uint32_t v)
Host to network byte order (unsigned 32-bit).
Definition: endian.h:64
uint32_t ntoh32u(uint32_t v)
Network to host byte order (unsigned 32-bit).
Definition: endian.h:34
uint32_t ext_seqnum_t
Extended sequence number.
Definition: units.h:103
uint32_t stream_source_t
Packet stream identifier.
Definition: units.h:27
uint16_t seqnum_t
Packet sequence number.
Definition: units.h:78
uint32_t stream_timestamp_t
Packet stream timestamp.
Definition: units.h:36
uint64_t ntp_timestamp_t
NTP timestamp.
Definition: ntp.h:35
packet::ntp_timestamp_t ntp_clamp_32(packet::ntp_timestamp_t value, packet::ntp_timestamp_t max_value)
Clamp 64-bit NTP timestamp so that it fits into middle 32-bits. Value is rounded to the new resolutio...
packet::ntp_timestamp_t ntp_clamp_64(packet::ntp_timestamp_t value, packet::ntp_timestamp_t max_value)
Clamp 64-bit NTP timestamp so that it does not exceed maximum.
@ V2
RTP version 2.
Definition: headers.h:26
Root namespace.
Panic.
#define roc_panic_if_not(x)
Panic if condition is false.
Definition: panic.h:37
#define roc_panic_if(x)
Panic if condition is true.
Definition: panic.h:26
#define roc_panic(...)
Print error message and terminate program gracefully.
Definition: panic.h:50
Utitilies for NTP timestamp.
size_t padding_len(const size_t size, const size_t min_padding)
How much padding bytes do we need in order to align with 32-bits.
Definition: headers.h:66
XrBlockType
XR Block Type.
Definition: headers.h:1075
@ XR_RRTR
RRTR Report Block.
Definition: headers.h:1077
@ XR_DLRR
DLRR Report Block.
Definition: headers.h:1078
@ XR_DELAY_METRICS
Delay Metrics Report Block.
Definition: headers.h:1082
@ XR_QUEUE_METRICS
Queue Metrics Report Block.
Definition: headers.h:1084
@ XR_MEASUREMENT_INFO
Measurement Information Report Block.
Definition: headers.h:1080
uint16_t size_t_2_rtcp_length(const size_t x)
Computes the value of RTCP packet header length field from input number.
Definition: headers.h:50
void set_bit_field(T &v0, const T v1, const size_t shift, const size_t mask)
Set bits in v0.
Definition: headers.h:44
Version
RTP protocol version.
Definition: headers.h:100
SdesItemType
SDES item type.
Definition: headers.h:725
@ SDES_PHONE
Phone Number.
Definition: headers.h:730
@ SDES_NOTE
Notice/Status.
Definition: headers.h:733
@ SDES_EMAIL
Electronic Mail Address.
Definition: headers.h:729
@ SDES_PRIV
Private Extensions.
Definition: headers.h:734
@ SDES_LOC
Geographic User Location.
Definition: headers.h:731
@ SDES_NAME
User Name.
Definition: headers.h:728
@ SDES_TOOL
Application or Tool Name.
Definition: headers.h:732
@ SDES_CNAME
Canonical End-Point Identifier.
Definition: headers.h:727
PacketType
RTCP packet type.
Definition: headers.h:105
@ RTCP_APP
APP-specific packet.
Definition: headers.h:110
@ RTCP_SR
Sender report packet.
Definition: headers.h:106
@ RTCP_SDES
Source Description packet.
Definition: headers.h:108
@ RTCP_RR
Receiver report packet.
Definition: headers.h:107
@ RTCP_XR
Extended report packet.
Definition: headers.h:111
@ RTCP_BYE
BYE packet.
Definition: headers.h:109
T get_bit_field(T v0, const size_t shift, const size_t mask)
Get bits from v0.
Definition: headers.h:32
size_t rtcp_length_2_size_t(const size_t x)
Converts RTCP header length field into conventional size_t value.
Definition: headers.h:58
Blk & get_block_by_index(Pkt *pkt, size_t block_index, size_t num_blocks, const char *pkt_type)
Get a block that follows header, by index.
Definition: headers.h:73
MetricFlag
Interval Metric flag for XR Delay Metrics Block.
Definition: headers.h:1476
@ MetricFlag_CumulativeDuration
Cumulative Duration. The reported value applies to the accumulation period characteristic of cumulati...
Definition: headers.h:1485
@ MetricFlag_SampledValue
Sampled Value. The reported value is a sampled instantaneous value.
Definition: headers.h:1489
@ MetricFlag_IntervalDuration
Interval Duration. The reported value applies to the most recent measurement interval duration betwee...
Definition: headers.h:1480
RTCP-specific NTP helpers.
Commonly used types and functions.
Time definitions.
Various units used in packets.