Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
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_packet/units.h"
20
21namespace roc {
22namespace rtcp {
23namespace header {
24
25//! Set some bits in v0.
26//!
27//! @param v0 Where to write the bits.
28//! @param v1 The bits to write.
29//! @param shift From which bit num the field start.
30//! @param mask The bitmask.
31template <typename T>
32void set_bitfield(T& v0, const T v1, const size_t shift, const size_t mask) {
33 v0 &= ~(mask << shift);
34 v0 |= (v1 << shift);
35}
36
37//! Computes the value of RTCP packet header length field from input number.
38inline uint16_t size_t_2_rtcp_length(const size_t x) {
39 roc_panic_if(x < 4);
40 roc_panic_if(x > uint16_t(-1));
41 return (uint16_t)x / 4 - 1;
42}
43
44//! Converts RTCP header length field into conventional size_t value.
45inline size_t rtcp_length_2_size_t(const size_t x) {
46 return (x + 1) * 4;
47}
48
49//! How much padding bytes do we need in order to align with 32-bits.
50//!
51//! @param size defines data length in bytes.
52//! @param min_padding defines minimum number of padding bytes required.
53//! @return How much should be added to x.
54inline size_t padding_len(const size_t size, const size_t min_padding) {
55 const size_t size_to_pad = size + min_padding;
56 return min_padding + (size_to_pad & 0x03 ? 4 - (size_to_pad & 0x03) : 0);
57}
58
59//! Get a block that follows header, by index.
60template <class Blk, class Pkt>
61Blk& get_block_by_index(Pkt* pkt,
62 size_t block_index,
63 size_t num_blocks,
64 const char* pkt_type) {
65 if (block_index >= num_blocks) {
66 roc_panic("%s: out of bounds: index=%lu size=%lu", pkt_type,
67 (unsigned long)block_index, (unsigned long)num_blocks);
68 }
69 return ((Blk*)(const_cast<char*>((const char*)pkt) + sizeof(*pkt)))[block_index];
70}
71
72//! RTP protocol version.
73enum Version {
74 V2 = 2 //!< RTP version 2.
75};
76
77//! RTCP packet type.
79 RTCP_SR = 200, //!< Sender report packet.
80 RTCP_RR = 201, //!< Receiver report packet.
81 RTCP_SDES = 202, //!< Source Description packet.
82 RTCP_BYE = 203, //!< BYE packet.
83 RTCP_APP = 204, //!< APP-specific packet.
84 RTCP_XR = 207 //!< Extended report packet.
85};
86
87//! Maximum number of inner blocks/chunks in RTCP packet.
88static const size_t PacketMaxBlocks = 31;
89
90//! Helper to store 64-bit ntp timestamp in a common way among RTCP.
91//!
92//! @code
93//! 0 1 2 3
94//! 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
95//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
96//! | NTP timestamp, most significant word |
97//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
98//! | NTP timestamp, least significant word |
99//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
100//! @endcode
102private:
103 enum {
104 NTP_HIGH_shift = 32,
105 NTP_HIGH_mask = 0xFFFFFFFF00000000,
106
107 NTP_LOW_shift = 0,
108 NTP_LOW_mask = 0x00000000FFFFFFFF
109 };
110
111 uint32_t high_ntp_;
112 uint32_t low_ntp_;
113
114public:
115 NtpTimestamp() {
116 reset();
117 }
118
119 //! Reset to initial state (all zeros).
120 void reset() {
121 high_ntp_ = 0;
122 low_ntp_ = 0;
123 }
124
125 //! Get NTP timestamp value.
127 uint64_t tmp =
128 (((uint64_t)core::ntoh32u(high_ntp_) << NTP_HIGH_shift) & NTP_HIGH_mask)
129 | (((uint64_t)core::ntoh32u(low_ntp_) << NTP_LOW_shift) & NTP_LOW_mask);
130 return (packet::ntp_timestamp_t)tmp;
131 }
132
133 //! Set NTP timestamp value.
135 high_ntp_ = core::hton32u((t >> NTP_HIGH_shift) & NTP_LOW_mask);
136 low_ntp_ = core::hton32u((t >> NTP_LOW_shift) & NTP_LOW_mask);
137 }
139
140//! RTCP packet header, common for all RTCP packet types.
141//!
142//! @code
143//! 0 1 2 3
144//! 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
145//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
146//! |V=2|P| RC | PT=SR=200 | length |
147//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
148//! @endcode
150private:
151 enum {
152 //! @name RTCP protocol version.
153 // @{
154 Flag_VersionShift = 6,
155 Flag_VersionMask = 0x03,
156 // @}
157
158 //! @name RTCP padding flag.
159 // @{
160 Flag_PaddingShift = 5,
161 Flag_PaddingMask = 0x01,
162 // @}
163
164 //! @name RTCP packets counter.
165 // @{
166 Flag_CounterShift = 0,
167 Flag_CounterMask = 0x1F
168 // @}
169 };
170
171 //! Protocol version.
172 //! Padding flag.
173 //! Varies by packet type.
174 uint8_t count_;
175
176 //! RTCP packet type.
177 uint8_t type_;
178
179 //! Packet length in words, w/o common packet header word.
180 uint16_t length_;
181
182public:
183 PacketHeader() {
184 reset(PacketType(0));
185 }
186
187 //! Reset to initial state (all zeros).
188 void reset(const PacketType t) {
189 count_ = type_ = length_ = 0;
190
192 set_type(t);
193 }
194
195 //! Get number of blocks/chunks following.
196 size_t counter() const {
197 return (count_ >> Flag_CounterShift) & Flag_CounterMask;
198 }
199
200 //! Set number of blocks/chunks.
201 void set_counter(const size_t c) {
202 roc_panic_if(c > PacketMaxBlocks);
203 set_bitfield<uint8_t>(count_, (uint8_t)c, Flag_CounterShift, Flag_CounterMask);
204 }
205
206 //! Increment packet counter,
207 void inc_counter() {
208 return set_counter(counter() + 1);
209 }
210
211 //! Get protocol version.
212 uint8_t version() const {
213 return (count_ >> Flag_VersionShift) & Flag_VersionMask;
214 }
215
216 //! Set protocol version.
218 roc_panic_if((v & Flag_VersionMask) != v);
219 set_bitfield<uint8_t>(count_, v, Flag_VersionShift, Flag_VersionMask);
220 }
221
222 //! Get padding flag.
223 bool has_padding() const {
224 return (count_ & (Flag_PaddingMask << Flag_PaddingShift));
225 }
226
227 //! Set padding flag.
228 void set_padding(bool v) {
229 set_bitfield(count_, (uint8_t)v, Flag_PaddingShift, Flag_PaddingMask);
230 }
231
232 //! Get packet type.
233 PacketType type() const {
234 return PacketType(type_);
235 }
236
237 //! Set packet type.
238 void set_type(const PacketType t) {
239 roc_panic_if_not(t == 0 || (t >= RTCP_SR && t <= RTCP_XR));
240 type_ = t;
241 }
242
243 //! Get packet length, including the header, in 32-bit words minus one.
244 uint16_t len_words() const {
245 return core::ntoh16u(length_);
246 }
247
248 //! Set packet length in words.
249 void set_len_words(const uint16_t ln) {
250 length_ = core::hton16u(ln);
251 }
252
253 //! Get packet length, including the header, in bytes.
254 size_t len_bytes() const {
256 }
257
258 //! Set packet length in bytes.
259 void set_len_bytes(const size_t ln) {
261 }
263
264//! Reception report block.
265//!
266//! Part of RR and SR packets.
267//!
268//! @code
269//! 0 1 2 3
270//! 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
271//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
272//! | SSRC |
273//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
274//! | fraction lost | cumulative number of packets lost |
275//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
276//! | extended highest sequence number received |
277//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
278//! | interarrival jitter |
279//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
280//! | last SR (LSR) |
281//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
282//! | delay since last SR (DLSR) |
283//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
284//! @endcode
286private:
287 enum {
288 //! @name Fraction lost since last SR/RR.
289 // @{
290 Losses_FractLost_shift = 24,
291 Losses_FractLost_mask = 0x0F,
292 // @}
293
294 //! @name cumul. no. pkts lost (signed!).
295 // @{
296 Losses_CumLoss_shift = 24,
297 Losses_CumLoss_mask = 0x0FFF
298 // @}
299 };
300
301 //! Data source being reported.
302 uint32_t ssrc_;
303
304 //! Fraction lost since last SR/RR.
305 //! cumul. no. pkts lost (signed!).
306 uint32_t losses_;
307
308 //! Extended last seq. no. received.
309 uint32_t last_seq_;
310
311 //! Interarrival jitter.
312 uint32_t jitter_;
313
314 //! Last SR packet from this source.
315 uint32_t lsr_;
316
317 //! Delay since last SR packet.
318 uint32_t dlsr_;
319
320public:
322 reset();
323 }
324
325 //! Reset to initial state (all zeros).
326 void reset() {
327 ssrc_ = losses_ = last_seq_ = jitter_ = lsr_ = dlsr_ = 0;
328 }
329
330 //! Get SSRC.
331 uint32_t ssrc() const {
332 return core::ntoh32u(ssrc_);
333 }
334
335 //! Set SSRC.
336 void set_ssrc(const uint32_t s) {
337 ssrc_ = core::hton32u(s);
338 }
339
340 //! Get fraction lost.
341 float fract_loss() const {
342 const uint32_t tmp = core::ntoh32u(losses_);
343 uint8_t losses8 = (tmp >> Losses_FractLost_shift) & Losses_FractLost_mask;
344 float res = float(losses8) / float(1 << Losses_FractLost_shift);
345
346 return res;
347 }
348
349 //! Set fractional loss.
350 //!
351 //! Fractional loss is stored in Q.8 format.
352 void set_fract_loss(const ssize_t nlost, const size_t noverall) {
353 uint8_t l8;
354
355 if (nlost <= 0 || noverall == 0) {
356 l8 = 0;
357 } else if ((size_t)nlost >= noverall) {
358 l8 = (uint8_t)-1;
359 } else {
360 l8 = (uint8_t)((uint32_t)(nlost << 8) / noverall);
361 }
362
363 uint32_t losses = core::ntoh32u(losses_);
364 set_bitfield<uint32_t>(losses, l8, Losses_FractLost_shift, Losses_FractLost_mask);
365 losses_ = core::hton32u(losses);
366 }
367
368 //! Get cumulative loss.
369 //!
370 //! May be negative in case of packet repeats.
371 int32_t cumloss() const {
372 uint32_t res = core::ntoh32u(losses_) & Losses_CumLoss_mask;
373 // If res is negative
374 if (res & (1 << (Losses_CumLoss_shift - 1))) {
375 // Make whole leftest byte filled with 1.
376 res |= ~(uint32_t)Losses_CumLoss_mask;
377 }
378 return int32_t(res);
379 }
380
381 //! Set cumulative loss.
382 //!
383 //! May be negative in case of packet repeats.
384 void set_cumloss(int32_t l) {
385 uint32_t losses = core::ntoh32u(losses_);
386
387 if (l > Losses_CumLoss_mask) {
388 l = Losses_CumLoss_mask;
389 } else if (l < -(int32_t)Losses_CumLoss_mask) {
390 l = -Losses_CumLoss_mask;
391 }
392 set_bitfield<uint32_t>(losses, (uint32_t)l,
393 sizeof(losses_) * 8 - Losses_CumLoss_shift,
394 Losses_CumLoss_mask);
395
396 losses_ = core::hton32u(losses);
397 }
398
399 //! Get last seqnum.
400 uint32_t last_seqnum() const {
401 return core::ntoh32u(last_seq_);
402 }
403
404 //! Set last seqnum.
405 void set_last_seqnum(const uint32_t x) {
406 last_seq_ = core::hton32u(x);
407 }
408
409 //! Get jitter.
410 uint32_t jitter() const {
411 return core::ntoh32u(jitter_);
412 }
413
414 //! Set jitter.
415 void set_jitter(const uint32_t x) {
416 jitter_ = core::hton32u(x);
417 }
418
419 //! Get LSR.
420 uint32_t last_sr() const {
421 return core::ntoh32u(lsr_);
422 }
423
424 //! Set LSR.
425 void set_last_sr(const uint32_t x) {
426 lsr_ = core::hton32u(x);
427 }
428
429 //! Get DLSR.
430 uint32_t delay_last_sr() const {
431 return core::ntoh32u(dlsr_);
432 }
433
434 //! Set DLSR.
435 void set_delay_last_sr(const uint32_t x) {
436 dlsr_ = core::hton32u(x);
437 }
439
440//! Receiver Report RTCP packet (RR).
441//!
442//! RFC 3550 6.4.2. "RR: Receiver Report RTCP packet"
443//!
444//! @code
445//! 0 1 2 3
446//! 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
447//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
448//! header |V=2|P| RC | PT=RR=201 | length |
449//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
450//! | SSRC of packet sender |
451//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
452//! report | SSRC_1 (SSRC of first source) |
453//! block +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
454//! 1 | fraction lost | cumulative number of packets lost |
455//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
456//! | extended highest sequence number received |
457//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
458//! | interarrival jitter |
459//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
460//! | last SR (LSR) |
461//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
462//! | delay since last SR (DLSR) |
463//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
464//! report | SSRC_2 (SSRC of second source) |
465//! block +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
466//! 2 : ... :
467//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
468//! | profile-specific extensions |
469//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
470//! @endcode
472private:
473 PacketHeader header_;
474
475 //! Data source being reported.
476 uint32_t ssrc_;
477
478public:
480 reset();
481 }
482
483 //! Reset to initial state (all zeros).
484 void reset() {
485 header_.reset(RTCP_RR);
486 ssrc_ = 0;
487 }
488
489 //! Get common packet header.
490 const PacketHeader& header() const {
491 return header_;
492 }
493
494 //! Get common packet header.
496 return header_;
497 }
498
499 //! Get SSRC of packet sender.
500 uint32_t ssrc() const {
501 return core::ntoh32u(ssrc_);
502 }
503
504 //! Set SSRC of packet sender.
505 void set_ssrc(const uint32_t s) {
506 ssrc_ = core::hton32u(s);
507 }
508
509 //! Get number of blocks.
510 size_t num_blocks() const {
511 return header_.counter();
512 }
513
514 //! Get reception block by index.
515 const ReceptionReportBlock& get_block(const size_t i) const {
516 return get_block_by_index<const ReceptionReportBlock>(this, i, header().counter(),
517 "rtcp rr");
518 }
519
520 //! Get reception block by index.
522 return get_block_by_index<ReceptionReportBlock>(this, i, header().counter(),
523 "rtcp rr");
524 }
526
527//! Sender Report RTCP packet (SR).
528//!
529//! RFC 3550 6.4.1. "SR: Sender Report RTCP packet"
530//!
531//! @code
532//! 0 1 2 3
533//! 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
534//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
535//! header |V=2|P| RC | PT=SR=200 | length |
536//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
537//! | SSRC of sender |
538//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
539//! sender | NTP timestamp, most significant word |
540//! info +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
541//! | NTP timestamp, least significant word |
542//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
543//! | RTP timestamp |
544//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
545//! | sender's packet count |
546//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
547//! | sender's octet count |
548//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
549//! report | SSRC_1 (SSRC of first source) |
550//! block +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
551//! 1 | fraction lost | cumulative number of packets lost |
552//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
553//! | extended highest sequence number received |
554//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
555//! | interarrival jitter |
556//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
557//! | last SR (LSR) |
558//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
559//! | delay since last SR (DLSR) |
560//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
561//! report | SSRC_2 (SSRC of second source) |
562//! block +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
563//! 2 : ... :
564//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
565//! | profile-specific extensions |
566//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
567//! @endcode
569private:
570 PacketHeader header_;
571
572 uint32_t ssrc_;
573 NtpTimestamp ntp_;
574
575 uint32_t rtp_timestamp_;
576 uint32_t packet_cnt_;
577 uint32_t bytes_cnt_;
578
579public:
581 reset();
582 }
583
584 //! Reset to initial state (all zeros).
585 void reset() {
586 header_.reset(RTCP_SR);
587 ssrc_ = 0;
588 ntp_.reset();
589 rtp_timestamp_ = 0;
590 packet_cnt_ = 0;
591 bytes_cnt_ = 0;
592 }
593
594 //! Get common packet header.
595 const PacketHeader& header() const {
596 return header_;
597 }
598
599 //! Get common packet header.
601 return header_;
602 }
603
604 //! Get SSRC of sender.
605 uint32_t ssrc() const {
606 return core::ntoh32u(ssrc_);
607 }
608
609 //! Set SSRC of sender.
610 void set_ssrc(const uint32_t s) {
611 ssrc_ = core::hton32u(s);
612 }
613
614 //! Get NTP timestamp.
616 return ntp_.value();
617 }
618
619 //! Set NTP timestamp.
621 ntp_.set_value(t);
622 }
623
624 //! Get RTP timestamp.
625 uint32_t rtp_timestamp() const {
626 return core::ntoh32u(rtp_timestamp_);
627 }
628
629 //! Get RTP timestamp.
630 void set_rtp_timestamp(const uint32_t& t) {
631 rtp_timestamp_ = core::hton32u(t);
632 }
633
634 //! Get packet count.
635 size_t packet_count() const {
636 return core::ntoh32u(packet_cnt_);
637 }
638
639 //! Set packet count.
640 void set_packet_count(const size_t cnt) {
641 packet_cnt_ = core::hton32u((uint32_t)cnt);
642 }
643
644 //! Get byte count.
645 size_t byte_count() const {
646 return core::ntoh32u(bytes_cnt_);
647 }
648
649 //! Set byte count.
650 void set_byte_count(const size_t cnt) {
651 bytes_cnt_ = core::hton32u((uint32_t)cnt);
652 }
653
654 //! Get number of blocks.
655 size_t num_blocks() const {
656 return header_.counter();
657 }
658
659 //! Get reception block by index.
660 const ReceptionReportBlock& get_block(const size_t i) const {
661 return get_block_by_index<const ReceptionReportBlock>(this, i, header().counter(),
662 "rtcp sr");
663 }
664
665 //! Get reception block by index.
667 return get_block_by_index<ReceptionReportBlock>(this, i, header().counter(),
668 "rtcp sr");
669 }
671
672//! SDES item type.
674 SDES_CNAME = 1, //!< Canonical End-Point Identifier.
675 SDES_NAME = 2, //!< User Name.
676 SDES_EMAIL = 3, //!< Electronic Mail Address.
677 SDES_PHONE = 4, //!< Phone Number.
678 SDES_LOC = 5, //!< Geographic User Location.
679 SDES_TOOL = 6, //!< Application or Tool Name.
680 SDES_NOTE = 7, //!< Notice/Status.
681 SDES_PRIV = 8 //!< Private Extensions.
683
684//! SDES chunk header.
685//!
686//! Part of SDES packet.
687//!
688//! @code
689//! 0 1 2 3
690//! 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
691//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
692//! | SSRC |
693//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
694//! @endcode
696private:
697 uint32_t ssrc_;
698
699public:
701 reset();
702 }
703
704 //! Reset to initial state (all zeros).
705 void reset() {
706 ssrc_ = 0;
707 }
708
709 //! Get SSRC.
710 uint32_t ssrc() const {
711 return core::ntoh32u(ssrc_);
712 }
713
714 //! Set SSRC.
715 void set_ssrc(const uint32_t s) {
716 ssrc_ = core::hton32u(s);
717 }
719
720//! SDES item header.
721//!
722//! Part of SDES packet.
723//!
724//! @code
725//! 0 1 2 3
726//! 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
727//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
728//! | Type | Length | Text in UTF-8 ...
729//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
730//! @endcode
732private:
733 uint8_t type_;
734 uint8_t len_;
735
736public:
737 //! Get maximum allowed item text length.
738 static const size_t MaxTextLen = 255;
739
741 reset();
742 }
743
744 //! Reset to initial state (all zeros).
745 void reset() {
746 type_ = len_ = 0;
747 }
748
749 //! Get item type.
751 return SdesItemType(type_);
752 }
753
754 //! Set type.
755 void set_type(const SdesItemType t) {
756 type_ = t;
757 }
758
759 //! Get item text length.
760 size_t text_len() const {
761 return len_;
762 }
763
764 //! Set item text length.
765 void set_text_len(const size_t ln) {
767 len_ = (uint8_t)ln;
768 }
769
770 //! Get pointer to item text.
771 //! The text is NOT zero-terminated.
772 const uint8_t* text() const {
773 return (const uint8_t*)this + sizeof(*this);
774 }
775
776 //! Get pointer to item text.
777 //! The text is NOT zero-terminated.
778 uint8_t* text() {
779 return (uint8_t*)this + sizeof(*this);
780 }
782
783//! Source Description RTCP packet (SDES).
784//!
785//! RFC 3550 6.5. "SDES: Source Description RTCP packet"
786//!
787//! @code
788//! 0 1 2 3
789//! 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
790//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
791//! header |V=2|P| RC | PT=Sdes=202 | length |
792//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
793//! Chunk1 | SSRC_1 (SSRC of first source) |
794//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
795//! Item1 | Type | Length | Text in UTF-8 |
796//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
797//! Item2 | Type | Length | Text in UTF-8 |
798//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
799//! Item 3 | Type | Length | Text in UTF-8 |
800//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
801//! Chunk2 | SSRC_2 (SSRC of second source) |
802//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
803//! Item1 | Type | Length | Text in UTF-8 |
804//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
805//! Item2 | Type | Length | Text in UTF-8 |
806//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
807//! : ... :
808//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
809//! @endcode
811private:
812 PacketHeader header_;
813
814public:
815 SdesPacket() {
816 reset();
817 }
818
819 //! Reset to initial state (all zeros).
820 void reset() {
821 header_.reset(RTCP_SDES);
822 }
823
824 //! Get common packet header.
825 const PacketHeader& header() const {
826 return header_;
827 }
828
829 //! Get common packet header.
831 return header_;
832 }
834
835//! BYE source header.
836//!
837//! Part of BYE packet.
838//!
839//! @code
840//! 0 1 2 3
841//! 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
842//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
843//! | SSRC |
844//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
845//! @endcode
847private:
848 uint32_t ssrc_;
849
850public:
852 reset();
853 }
854
855 //! Reset to initial state (all zeros).
856 void reset() {
857 ssrc_ = 0;
858 }
859
860 //! Get SSRC.
861 uint32_t ssrc() const {
862 return core::ntoh32u(ssrc_);
863 }
864
865 //! Set SSRC.
866 void set_ssrc(const uint32_t s) {
867 ssrc_ = core::hton32u(s);
868 }
870
871//! BYE reason header.
872//!
873//! Part of BYE packet.
874//!
875//! @code
876//! 0 1 2 3
877//! 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
878//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
879//! | length | reason for leaving ...
880//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
881//! @endcode
883private:
884 uint8_t len_;
885
886public:
887 //! Get maximum allowed reason text length.
888 static const size_t MaxTextLen = 255;
889
891 reset();
892 }
893
894 //! Reset to initial state (all zeros).
895 void reset() {
896 len_ = 0;
897 }
898
899 //! Get text length.
900 size_t text_len() const {
901 return len_;
902 }
903
904 //! Set text length.
905 void set_text_len(const size_t ln) {
907 len_ = (uint8_t)ln;
908 }
909
910 //! Get pointer to text.
911 //! The text is NOT zero-terminated.
912 const uint8_t* text() const {
913 return (const uint8_t*)this + sizeof(*this);
914 }
915
916 //! Get pointer to text.
917 //! The text is NOT zero-terminated.
918 uint8_t* text() {
919 return (uint8_t*)this + sizeof(*this);
920 }
922
923//! Goodbye RTCP packet (BYE).
924//!
925//! RFC 3550 6.6. "BYE: Goodbye RTCP packet"
926//!
927//! @code
928//! 0 1 2 3
929//! 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
930//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
931//! |V=2|P| SC | PT=Bye=203 | length |
932//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
933//! | SSRC/CSRC |
934//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
935//! : ... :
936//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
937//! (opt) | length | reason for leaving ...
938//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
939//! @endcode
941private:
942 PacketHeader header_;
943
944public:
945 ByePacket() {
946 reset();
947 }
948
949 //! Reset to initial state (all zeros).
950 void reset() {
951 header_.reset(RTCP_BYE);
952 }
953
954 //! Get common packet header.
955 const PacketHeader& header() const {
956 return header_;
957 }
958
959 //! Get common packet header.
961 return header_;
962 }
964
965//! RTCP Extended Report Packet.
966//!
967//! RFC 3611 2. "XR Packet Format"
968//!
969//! @code
970//! 0 1 2 3
971//! 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
972//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
973//! |V=2|P|reserved | PT=Xr=207 | length |
974//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
975//! | SSRC |
976//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
977//! : report blocks :
978//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
979//! @endcode
981private:
982 PacketHeader header_;
983 uint32_t ssrc_;
984
985public:
986 XrPacket() {
987 reset();
988 }
989
990 //! Reset to initial state (all zeros).
991 void reset() {
992 header_.reset(RTCP_XR);
993 ssrc_ = 0;
994 }
995
996 //! Get common packet header.
997 const PacketHeader& header() const {
998 return header_;
999 }
1000
1001 //! Get common packet header.
1003 return header_;
1004 }
1005
1006 //! Get SSRC of packet originator.
1007 uint32_t ssrc() const {
1008 return core::ntoh32u(ssrc_);
1009 }
1010
1011 //! Set SSRC of packet originator.
1012 void set_ssrc(const uint32_t ssrc) {
1013 ssrc_ = core::hton32u(ssrc);
1014 }
1016
1017//! XR Block Type.
1019 XR_LOSS_RLE = 1, //!< Loss RLE Report Block.
1020 XR_DUPLICATE_RLE = 2, //!< Duplicate RLE Report Block.
1021 XR_PACKET_RECPT_TIME = 3, //!< Packet Receipt Times Report Block.
1022 XR_RRTR = 4, //!< Receiver Reference Time Report Block.
1023 XR_DLRR = 5, //!< DLRR Report Block.
1024 XR_STAT_SUMMARY = 6, //!< Statistics Summary Report Block.
1025 XR_VOIP_METRICS = 7 //!< VoIP Metrics Report Block.
1027
1028//! XR Block Header.
1029//!
1030//! @code
1031//! 0 1 2 3
1032//! 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
1033//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1034//! | BT | type-specific | block length |
1035//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1036//! : type-specific block contents :
1037//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1038//! @endcode
1040private:
1041 uint8_t block_type_;
1042 uint8_t type_specific_;
1043 uint16_t length_;
1044
1045public:
1046 XrBlockHeader() {
1047 reset(XrBlockType(0));
1048 }
1049
1050 //! Reset to initial state (all zeros).
1051 void reset(const XrBlockType bt) {
1052 block_type_ = type_specific_ = 0;
1053 length_ = 0;
1054 set_block_type(bt);
1055 }
1056
1057 //! Get XR block type.
1059 return (XrBlockType)block_type_;
1060 }
1061
1062 //! Set XR block type.
1064 roc_panic_if_not(bt == 0 || (bt >= XR_LOSS_RLE && bt <= XR_VOIP_METRICS));
1065 block_type_ = (uint8_t)bt;
1066 }
1067
1068 //! Get type-specific byte.
1069 uint8_t type_specific() const {
1070 return type_specific_;
1071 }
1072
1073 //! Set type-specific byte.
1074 void set_type_specific(const uint8_t t) {
1075 type_specific_ = t;
1076 }
1077
1078 //! Get block length, including the header, in 32-bit words minus one.
1079 uint16_t len_words() const {
1080 return core::ntoh16u(length_);
1081 }
1082
1083 //! Set block length in words.
1084 void set_len_words(const uint16_t ln) {
1085 length_ = core::hton16u(ln);
1086 }
1087
1088 //! Get block length, including the header, in bytes.
1089 size_t len_bytes() const {
1091 }
1092
1093 //! Set block length in bytes.
1094 void set_len_bytes(const size_t ln) {
1096 }
1098
1099//! XR Receiver Reference Time Report block.
1100//!
1101//! RFC 3611 4.4. "Receiver Reference Time Report Block"
1102//!
1103//! @code
1104//! 0 1 2 3
1105//! 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
1106//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1107//! | BT=4 | reserved | block length = 2 |
1108//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1109//! | NTP timestamp, most significant word |
1110//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1111//! | NTP timestamp, least significant word |
1112//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1113//! @endcode
1115private:
1116 XrBlockHeader header_;
1117 NtpTimestamp ntp_;
1118
1119public:
1120 XrRrtrBlock() {
1121 reset();
1122 }
1123
1124 //! Reset to initial state (all zeros).
1125 void reset() {
1126 header_.reset(XR_RRTR);
1127 ntp_.reset();
1128 }
1129
1130 //! Get common block header.
1131 const XrBlockHeader& header() const {
1132 return header_;
1133 }
1134
1135 //! Get common block header.
1137 return header_;
1138 }
1139
1140 //! Get NTP timestamp.
1142 return ntp_.value();
1143 }
1144
1145 //! Set NTP timestamp.
1147 ntp_.set_value(t);
1148 }
1150
1151//! XR DLRR Report sub-block.
1152//!
1153//! RFC 3611 4.5. "DLRR Report Sub-block"
1154//!
1155//! @code
1156//! 0 1 2 3
1157//! 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
1158//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
1159//! | SSRC |
1160//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1161//! | last RR (LRR) |
1162//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1163//! | delay since last RR (DLRR) |
1164//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
1165//! @endcode
1167private:
1168 uint32_t ssrc_;
1169 uint32_t last_rr_;
1170 uint32_t delay_last_rr_;
1171
1172public:
1173 XrDlrrSubblock() {
1174 reset();
1175 }
1176
1177 //! Reset to initial state (all zeros).
1178 void reset() {
1179 ssrc_ = last_rr_ = delay_last_rr_ = 0;
1180 }
1181
1182 //! Get SSRC of receiver.
1183 uint32_t ssrc() const {
1184 return core::ntoh32u(ssrc_);
1185 }
1186
1187 //! Set SSRC of receiver.
1188 void set_ssrc(const uint32_t ssrc) {
1189 ssrc_ = core::hton32u(ssrc);
1190 }
1191
1192 //! Get LRR.
1193 uint32_t last_rr() const {
1194 return core::ntoh32u(last_rr_);
1195 }
1196
1197 //! Set LRR.
1198 void set_last_rr(const uint32_t lrr) {
1199 last_rr_ = core::hton32u(lrr);
1200 }
1201
1202 //! Get DLRR.
1203 uint32_t delay_last_rr() const {
1204 return core::ntoh32u(delay_last_rr_);
1205 }
1206
1207 //! Set DLRR.
1208 void set_delay_last_rr(const uint32_t dlrr) {
1209 delay_last_rr_ = core::hton32u(dlrr);
1210 }
1212
1213//! XR DLRR Report block.
1214//!
1215//! RFC 3611 4.5. "DLRR Report 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//! | BT=5 | reserved | block length |
1222//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
1223//! | SSRC_1 (SSRC of first receiver) | sub-
1224//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ block
1225//! | last RR (LRR) | 1
1226//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1227//! | delay since last RR (DLRR) |
1228//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
1229//! | SSRC_2 (SSRC of second receiver) | sub-
1230//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ block
1231//! : ... : 2
1232//! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
1233//! @endcode
1235private:
1236 XrBlockHeader header_;
1237
1238public:
1239 XrDlrrBlock() {
1240 reset();
1241 }
1242
1243 //! Reset to initial state (all zeros).
1244 void reset() {
1245 header_.reset(XR_DLRR);
1246 }
1247
1248 //! Get common block header.
1249 const XrBlockHeader& header() const {
1250 return header_;
1251 }
1252
1253 //! Get common block header.
1255 return header_;
1256 }
1257
1258 //! Get number of sub-blocks.
1259 size_t num_subblocks() const {
1260 return (header_.len_bytes() - sizeof(header_)) / sizeof(XrDlrrSubblock);
1261 }
1262
1263 //! Get DLRR sub-block by index.
1264 const XrDlrrSubblock& get_subblock(const size_t i) const {
1265 return get_block_by_index<const XrDlrrSubblock>(this, i, num_subblocks(),
1266 "rtcp xr_dlrr");
1267 }
1268
1269 //! Get DLRR sub-block by index.
1270 XrDlrrSubblock& get_subblock(const size_t i) {
1271 return get_block_by_index<XrDlrrSubblock>(this, i, num_subblocks(),
1272 "rtcp xr_dlrr");
1273 }
1275
1276} // namespace header
1277} // namespace rtcp
1278} // namespace roc
1279
1280#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:47
#define ROC_ATTR_PACKED_END
Pack structure fields. Place these between '}' and ';'.
Definition: attributes.h:50
Goodbye RTCP packet (BYE).
Definition: headers.h:940
void reset()
Reset to initial state (all zeros).
Definition: headers.h:950
PacketHeader & header()
Get common packet header.
Definition: headers.h:960
const PacketHeader & header() const
Get common packet header.
Definition: headers.h:955
void set_text_len(const size_t ln)
Set text length.
Definition: headers.h:905
size_t text_len() const
Get text length.
Definition: headers.h:900
static const size_t MaxTextLen
Get maximum allowed reason text length.
Definition: headers.h:888
uint8_t * text()
Get pointer to text. The text is NOT zero-terminated.
Definition: headers.h:918
void reset()
Reset to initial state (all zeros).
Definition: headers.h:895
const uint8_t * text() const
Get pointer to text. The text is NOT zero-terminated.
Definition: headers.h:912
void reset()
Reset to initial state (all zeros).
Definition: headers.h:856
uint32_t ssrc() const
Get SSRC.
Definition: headers.h:861
void set_ssrc(const uint32_t s)
Set SSRC.
Definition: headers.h:866
Helper to store 64-bit ntp timestamp in a common way among RTCP.
Definition: headers.h:101
packet::ntp_timestamp_t value() const
Get NTP timestamp value.
Definition: headers.h:126
void set_value(const packet::ntp_timestamp_t t)
Set NTP timestamp value.
Definition: headers.h:134
void reset()
Reset to initial state (all zeros).
Definition: headers.h:120
RTCP packet header, common for all RTCP packet types.
Definition: headers.h:149
void set_len_bytes(const size_t ln)
Set packet length in bytes.
Definition: headers.h:259
void set_len_words(const uint16_t ln)
Set packet length in words.
Definition: headers.h:249
uint16_t len_words() const
Get packet length, including the header, in 32-bit words minus one.
Definition: headers.h:244
PacketType type() const
Get packet type.
Definition: headers.h:233
void set_counter(const size_t c)
Set number of blocks/chunks.
Definition: headers.h:201
uint8_t version() const
Get protocol version.
Definition: headers.h:212
void reset(const PacketType t)
Reset to initial state (all zeros).
Definition: headers.h:188
void inc_counter()
Increment packet counter,.
Definition: headers.h:207
void set_padding(bool v)
Set padding flag.
Definition: headers.h:228
void set_version(Version v)
Set protocol version.
Definition: headers.h:217
size_t counter() const
Get number of blocks/chunks following.
Definition: headers.h:196
void set_type(const PacketType t)
Set packet type.
Definition: headers.h:238
bool has_padding() const
Get padding flag.
Definition: headers.h:223
size_t len_bytes() const
Get packet length, including the header, in bytes.
Definition: headers.h:254
Receiver Report RTCP packet (RR).
Definition: headers.h:471
const PacketHeader & header() const
Get common packet header.
Definition: headers.h:490
PacketHeader & header()
Get common packet header.
Definition: headers.h:495
void set_ssrc(const uint32_t s)
Set SSRC of packet sender.
Definition: headers.h:505
ReceptionReportBlock & get_block(const size_t i)
Get reception block by index.
Definition: headers.h:521
const ReceptionReportBlock & get_block(const size_t i) const
Get reception block by index.
Definition: headers.h:515
uint32_t ssrc() const
Get SSRC of packet sender.
Definition: headers.h:500
void reset()
Reset to initial state (all zeros).
Definition: headers.h:484
size_t num_blocks() const
Get number of blocks.
Definition: headers.h:510
Reception report block.
Definition: headers.h:285
uint32_t ssrc() const
Get SSRC.
Definition: headers.h:331
uint32_t last_sr() const
Get LSR.
Definition: headers.h:420
void set_fract_loss(const ssize_t nlost, const size_t noverall)
Set fractional loss.
Definition: headers.h:352
void set_delay_last_sr(const uint32_t x)
Set DLSR.
Definition: headers.h:435
void set_jitter(const uint32_t x)
Set jitter.
Definition: headers.h:415
uint32_t delay_last_sr() const
Get DLSR.
Definition: headers.h:430
void set_cumloss(int32_t l)
Set cumulative loss.
Definition: headers.h:384
float fract_loss() const
Get fraction lost.
Definition: headers.h:341
void set_last_seqnum(const uint32_t x)
Set last seqnum.
Definition: headers.h:405
uint32_t last_seqnum() const
Get last seqnum.
Definition: headers.h:400
void set_last_sr(const uint32_t x)
Set LSR.
Definition: headers.h:425
uint32_t jitter() const
Get jitter.
Definition: headers.h:410
int32_t cumloss() const
Get cumulative loss.
Definition: headers.h:371
void set_ssrc(const uint32_t s)
Set SSRC.
Definition: headers.h:336
void reset()
Reset to initial state (all zeros).
Definition: headers.h:326
uint32_t ssrc() const
Get SSRC.
Definition: headers.h:710
void reset()
Reset to initial state (all zeros).
Definition: headers.h:705
void set_ssrc(const uint32_t s)
Set SSRC.
Definition: headers.h:715
SdesItemType type() const
Get item type.
Definition: headers.h:750
void set_text_len(const size_t ln)
Set item text length.
Definition: headers.h:765
const uint8_t * text() const
Get pointer to item text. The text is NOT zero-terminated.
Definition: headers.h:772
size_t text_len() const
Get item text length.
Definition: headers.h:760
void set_type(const SdesItemType t)
Set type.
Definition: headers.h:755
void reset()
Reset to initial state (all zeros).
Definition: headers.h:745
static const size_t MaxTextLen
Get maximum allowed item text length.
Definition: headers.h:738
uint8_t * text()
Get pointer to item text. The text is NOT zero-terminated.
Definition: headers.h:778
Source Description RTCP packet (SDES).
Definition: headers.h:810
void reset()
Reset to initial state (all zeros).
Definition: headers.h:820
const PacketHeader & header() const
Get common packet header.
Definition: headers.h:825
PacketHeader & header()
Get common packet header.
Definition: headers.h:830
Sender Report RTCP packet (SR).
Definition: headers.h:568
size_t packet_count() const
Get packet count.
Definition: headers.h:635
uint32_t ssrc() const
Get SSRC of sender.
Definition: headers.h:605
uint32_t rtp_timestamp() const
Get RTP timestamp.
Definition: headers.h:625
void set_packet_count(const size_t cnt)
Set packet count.
Definition: headers.h:640
const ReceptionReportBlock & get_block(const size_t i) const
Get reception block by index.
Definition: headers.h:660
void set_byte_count(const size_t cnt)
Set byte count.
Definition: headers.h:650
void set_rtp_timestamp(const uint32_t &t)
Get RTP timestamp.
Definition: headers.h:630
void reset()
Reset to initial state (all zeros).
Definition: headers.h:585
size_t num_blocks() const
Get number of blocks.
Definition: headers.h:655
packet::ntp_timestamp_t ntp_timestamp() const
Get NTP timestamp.
Definition: headers.h:615
void set_ssrc(const uint32_t s)
Set SSRC of sender.
Definition: headers.h:610
PacketHeader & header()
Get common packet header.
Definition: headers.h:600
const PacketHeader & header() const
Get common packet header.
Definition: headers.h:595
ReceptionReportBlock & get_block(const size_t i)
Get reception block by index.
Definition: headers.h:666
void set_ntp_timestamp(const packet::ntp_timestamp_t t)
Set NTP timestamp.
Definition: headers.h:620
size_t byte_count() const
Get byte count.
Definition: headers.h:645
void set_len_words(const uint16_t ln)
Set block length in words.
Definition: headers.h:1084
uint16_t len_words() const
Get block length, including the header, in 32-bit words minus one.
Definition: headers.h:1079
void set_len_bytes(const size_t ln)
Set block length in bytes.
Definition: headers.h:1094
void set_type_specific(const uint8_t t)
Set type-specific byte.
Definition: headers.h:1074
void reset(const XrBlockType bt)
Reset to initial state (all zeros).
Definition: headers.h:1051
size_t len_bytes() const
Get block length, including the header, in bytes.
Definition: headers.h:1089
void set_block_type(const XrBlockType bt)
Set XR block type.
Definition: headers.h:1063
uint8_t type_specific() const
Get type-specific byte.
Definition: headers.h:1069
XrBlockType block_type() const
Get XR block type.
Definition: headers.h:1058
XR DLRR Report block.
Definition: headers.h:1234
const XrDlrrSubblock & get_subblock(const size_t i) const
Get DLRR sub-block by index.
Definition: headers.h:1264
XrDlrrSubblock & get_subblock(const size_t i)
Get DLRR sub-block by index.
Definition: headers.h:1270
const XrBlockHeader & header() const
Get common block header.
Definition: headers.h:1249
size_t num_subblocks() const
Get number of sub-blocks.
Definition: headers.h:1259
void reset()
Reset to initial state (all zeros).
Definition: headers.h:1244
XrBlockHeader & header()
Get common block header.
Definition: headers.h:1254
XR DLRR Report sub-block.
Definition: headers.h:1166
void set_last_rr(const uint32_t lrr)
Set LRR.
Definition: headers.h:1198
void set_ssrc(const uint32_t ssrc)
Set SSRC of receiver.
Definition: headers.h:1188
void reset()
Reset to initial state (all zeros).
Definition: headers.h:1178
void set_delay_last_rr(const uint32_t dlrr)
Set DLRR.
Definition: headers.h:1208
uint32_t delay_last_rr() const
Get DLRR.
Definition: headers.h:1203
uint32_t last_rr() const
Get LRR.
Definition: headers.h:1193
uint32_t ssrc() const
Get SSRC of receiver.
Definition: headers.h:1183
RTCP Extended Report Packet.
Definition: headers.h:980
void set_ssrc(const uint32_t ssrc)
Set SSRC of packet originator.
Definition: headers.h:1012
const PacketHeader & header() const
Get common packet header.
Definition: headers.h:997
uint32_t ssrc() const
Get SSRC of packet originator.
Definition: headers.h:1007
PacketHeader & header()
Get common packet header.
Definition: headers.h:1002
void reset()
Reset to initial state (all zeros).
Definition: headers.h:991
XR Receiver Reference Time Report block.
Definition: headers.h:1114
const XrBlockHeader & header() const
Get common block header.
Definition: headers.h:1131
void set_ntp_timestamp(const packet::ntp_timestamp_t t)
Set NTP timestamp.
Definition: headers.h:1146
XrBlockHeader & header()
Get common block header.
Definition: headers.h:1136
packet::ntp_timestamp_t ntp_timestamp() const
Get NTP timestamp.
Definition: headers.h:1141
void reset()
Reset to initial state (all zeros).
Definition: headers.h:1125
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
uint64_t ntp_timestamp_t
NTP timestamp.
Definition: units.h:91
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
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:54
XrBlockType
XR Block Type.
Definition: headers.h:1018
@ XR_RRTR
Receiver Reference Time Report Block.
Definition: headers.h:1022
@ XR_DLRR
DLRR Report Block.
Definition: headers.h:1023
@ XR_PACKET_RECPT_TIME
Packet Receipt Times Report Block.
Definition: headers.h:1021
@ XR_STAT_SUMMARY
Statistics Summary Report Block.
Definition: headers.h:1024
@ XR_LOSS_RLE
Loss RLE Report Block.
Definition: headers.h:1019
@ XR_VOIP_METRICS
VoIP Metrics Report Block.
Definition: headers.h:1025
@ XR_DUPLICATE_RLE
Duplicate RLE Report Block.
Definition: headers.h:1020
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:38
void set_bitfield(T &v0, const T v1, const size_t shift, const size_t mask)
Set some bits in v0.
Definition: headers.h:32
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:61
Version
RTP protocol version.
Definition: headers.h:73
@ V2
RTP version 2.
Definition: headers.h:74
SdesItemType
SDES item type.
Definition: headers.h:673
@ SDES_PHONE
Phone Number.
Definition: headers.h:677
@ SDES_NOTE
Notice/Status.
Definition: headers.h:680
@ SDES_EMAIL
Electronic Mail Address.
Definition: headers.h:676
@ SDES_PRIV
Private Extensions.
Definition: headers.h:681
@ SDES_LOC
Geographic User Location.
Definition: headers.h:678
@ SDES_NAME
User Name.
Definition: headers.h:675
@ SDES_TOOL
Application or Tool Name.
Definition: headers.h:679
@ SDES_CNAME
Canonical End-Point Identifier.
Definition: headers.h:674
PacketType
RTCP packet type.
Definition: headers.h:78
@ RTCP_APP
APP-specific packet.
Definition: headers.h:83
@ RTCP_SR
Sender report packet.
Definition: headers.h:79
@ RTCP_SDES
Source Description packet.
Definition: headers.h:81
@ RTCP_RR
Receiver report packet.
Definition: headers.h:80
@ RTCP_XR
Extended report packet.
Definition: headers.h:84
@ RTCP_BYE
BYE packet.
Definition: headers.h:82
size_t rtcp_length_2_size_t(const size_t x)
Converts RTCP header length field into conventional size_t value.
Definition: headers.h:45
Commonly used types and functions.
Various units used in packets.