12 #ifndef ROC_RTCP_HEADERS_H_
13 #define ROC_RTCP_HEADERS_H_
32 template <
typename T> T
get_bit_field(T v0,
const size_t shift,
const size_t mask) {
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);
54 return (uint16_t)x / 4 - 1;
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);
72 template <
class Blk,
class Pkt>
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);
81 return ((Blk*)(
const_cast<char*
>((
const char*)pkt) +
sizeof(*pkt)))[block_index];
85 static const size_t MaxPacketBlocks = 31;
88 static const size_t MaxTextLen = 255;
173 return get_bit_field<uint8_t>(count_, Counter_shift, Counter_mask);
179 set_bit_field<uint8_t>(count_, (uint8_t)c, Counter_shift, Counter_mask);
189 return get_bit_field<uint8_t>(count_, Version_shift, Version_mask);
195 set_bit_field<uint8_t>(count_, v, Version_shift, Version_mask);
205 set_bit_field(count_, (uint8_t)v, Padding_shift, Padding_mask);
338 FractLost_shift = 24,
340 FractLost_mask = 0xFF,
347 CumLoss_mask = 0xFFFFFF
372 ssrc_ = losses_ = last_seq_ = jitter_ = 0;
391 const uint8_t fract_loss8 =
392 get_bit_field<uint32_t>(losses, FractLost_shift, FractLost_mask);
394 return float(fract_loss8) / float(1 << FractLoss_width);
407 uint32_t fract_loss8 = (uint32_t)(
fract_loss *
float(1 << FractLoss_width));
408 if (fract_loss8 > 0xFF) {
413 set_bit_field<uint32_t>(losses, fract_loss8, FractLost_shift, FractLost_mask);
423 uint32_t
cum_loss = get_bit_field<uint32_t>(losses, CumLoss_shift, CumLoss_mask);
426 if (
cum_loss & (1 << (CumLoss_width - 1))) {
428 cum_loss |= ~(uint32_t)CumLoss_mask;
439 }
else if (
cum_loss < -0x7FFFFF - 1) {
444 set_bit_field<uint32_t>(losses, (uint32_t)(int32_t)
cum_loss, CumLoss_shift,
472 return last_sr_.
value();
483 return delay_last_sr_.
value();
569 return get_block_by_index<const ReceptionReportBlock>(
this, i,
header().counter(),
575 return get_block_by_index<ReceptionReportBlock>(
this, i,
header().counter(),
627 uint32_t rtp_timestamp_;
628 uint32_t packet_cnt_;
668 return ntp_timestamp_.
value();
713 return get_block_by_index<const ReceptionReportBlock>(
this, i,
header().counter(),
719 return get_block_by_index<ReceptionReportBlock>(
this, i,
header().counter(),
827 return (
const uint8_t*)
this +
sizeof(*this);
833 return (uint8_t*)
this +
sizeof(*this);
968 return (
const uint8_t*)
this +
sizeof(*this);
974 return (uint8_t*)
this +
sizeof(*this);
1102 uint8_t block_type_;
1103 uint8_t type_specific_;
1113 block_type_ = type_specific_ = 0;
1125 block_type_ = (uint8_t)bt;
1130 return type_specific_;
1204 return ntp_timestamp_.
value();
1258 return last_rr_.
value();
1269 return delay_last_rr_.
value();
1334 return get_block_by_index<const XrDlrrSubblock>(
this, i,
num_subblocks(),
1340 return get_block_by_index<XrDlrrSubblock>(
this, i,
num_subblocks(),
1379 uint16_t first_seq_;
1380 uint32_t interval_first_seq_;
1381 uint32_t interval_last_seq_;
1396 interval_first_seq_ = interval_last_seq_ = 0;
1454 return interval_duration_.
value();
1466 return cum_duration_.
value();
1518 MetricFlag_shift = 6,
1519 MetricFlag_mask = 0x03,
1542 e2e_latency_.
set_value(MetricUnavail_64);
1558 MetricFlag_shift, MetricFlag_mask);
1564 set_bit_field<uint8_t>(t, (uint8_t)f, MetricFlag_shift, MetricFlag_mask);
1580 return mean_rtt_.
value() != MetricUnavail_32;
1585 return mean_rtt_.
value();
1596 return min_rtt_.
value() != MetricUnavail_32;
1601 return min_rtt_.
value();
1612 return max_rtt_.
value() != MetricUnavail_32;
1617 return max_rtt_.
value();
1628 return e2e_latency_.
value() != MetricUnavail_64;
1633 return e2e_latency_.
value();
1671 MetricFlag_shift = 6,
1672 MetricFlag_mask = 0x03,
1690 niq_latency_.
set_value(MetricUnavail_32);
1691 niq_stalling_.
set_value(MetricUnavail_32);
1707 MetricFlag_shift, MetricFlag_mask);
1713 set_bit_field<uint8_t>(t, (uint8_t)f, MetricFlag_shift, MetricFlag_mask);
1729 return niq_latency_.
value() != MetricUnavail_32;
1734 return niq_latency_.
value();
1744 return niq_stalling_.
value() != MetricUnavail_32;
1749 return niq_stalling_.
value();
#define ROC_ATTR_PACKED_BEGIN
Pack structure fields. Place these before class or struct keyword.
#define ROC_ATTR_PACKED_END
Pack structure fields. Place these between '}' and ';'.
Endian conversion functions.
uint16_t hton16u(uint16_t v)
Host to network byte order (unsigned 16-bit).
uint16_t ntoh16u(uint16_t v)
Network to host byte order (unsigned 16-bit).
uint32_t hton32u(uint32_t v)
Host to network byte order (unsigned 32-bit).
uint32_t ntoh32u(uint32_t v)
Network to host byte order (unsigned 32-bit).
uint32_t ext_seqnum_t
Extended sequence number.
uint32_t stream_source_t
Packet stream identifier.
uint16_t seqnum_t
Packet sequence number.
uint32_t stream_timestamp_t
Packet stream timestamp.
uint64_t ntp_timestamp_t
NTP timestamp.
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.
#define roc_panic_if_not(x)
Panic if condition is false.
#define roc_panic_if(x)
Panic if condition is true.
#define roc_panic(...)
Print error message and terminate program gracefully.
Utitilies for NTP timestamp.
RTCP-specific NTP helpers.
Commonly used types and functions.
Various units used in packets.