12#ifndef ROC_RTCP_HEADERS_H_
13#define ROC_RTCP_HEADERS_H_
32void set_bitfield(T& v0,
const T v1,
const size_t shift,
const size_t mask) {
33 v0 &= ~(mask << shift);
41 return (uint16_t)x / 4 - 1;
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);
60template <
class Blk,
class Pkt>
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);
69 return ((Blk*)(
const_cast<char*
>((
const char*)pkt) +
sizeof(*pkt)))[block_index];
88static const size_t PacketMaxBlocks = 31;
105 NTP_HIGH_mask = 0xFFFFFFFF00000000,
108 NTP_LOW_mask = 0x00000000FFFFFFFF
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);
135 high_ntp_ =
core::hton32u((t >> NTP_HIGH_shift) & NTP_LOW_mask);
136 low_ntp_ =
core::hton32u((t >> NTP_LOW_shift) & NTP_LOW_mask);
154 Flag_VersionShift = 6,
155 Flag_VersionMask = 0x03,
160 Flag_PaddingShift = 5,
161 Flag_PaddingMask = 0x01,
166 Flag_CounterShift = 0,
167 Flag_CounterMask = 0x1F
189 count_ = type_ = length_ = 0;
197 return (count_ >> Flag_CounterShift) & Flag_CounterMask;
203 set_bitfield<uint8_t>(count_, (uint8_t)c, Flag_CounterShift, Flag_CounterMask);
213 return (count_ >> Flag_VersionShift) & Flag_VersionMask;
219 set_bitfield<uint8_t>(count_, v, Flag_VersionShift, Flag_VersionMask);
224 return (count_ & (Flag_PaddingMask << Flag_PaddingShift));
229 set_bitfield(count_, (uint8_t)v, Flag_PaddingShift, Flag_PaddingMask);
290 Losses_FractLost_shift = 24,
291 Losses_FractLost_mask = 0x0F,
296 Losses_CumLoss_shift = 24,
297 Losses_CumLoss_mask = 0x0FFF
327 ssrc_ = losses_ = last_seq_ = jitter_ = lsr_ = dlsr_ = 0;
343 uint8_t losses8 = (tmp >> Losses_FractLost_shift) & Losses_FractLost_mask;
344 float res = float(losses8) / float(1 << Losses_FractLost_shift);
355 if (nlost <= 0 || noverall == 0) {
357 }
else if ((
size_t)nlost >= noverall) {
360 l8 = (uint8_t)((uint32_t)(nlost << 8) / noverall);
364 set_bitfield<uint32_t>(losses, l8, Losses_FractLost_shift, Losses_FractLost_mask);
374 if (res & (1 << (Losses_CumLoss_shift - 1))) {
376 res |= ~(uint32_t)Losses_CumLoss_mask;
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;
392 set_bitfield<uint32_t>(losses, (uint32_t)l,
393 sizeof(losses_) * 8 - Losses_CumLoss_shift,
394 Losses_CumLoss_mask);
516 return get_block_by_index<const ReceptionReportBlock>(
this, i,
header().counter(),
522 return get_block_by_index<ReceptionReportBlock>(
this, i,
header().counter(),
575 uint32_t rtp_timestamp_;
576 uint32_t packet_cnt_;
661 return get_block_by_index<const ReceptionReportBlock>(
this, i,
header().counter(),
667 return get_block_by_index<ReceptionReportBlock>(
this, i,
header().counter(),
773 return (
const uint8_t*)
this +
sizeof(*this);
779 return (uint8_t*)
this +
sizeof(*this);
913 return (
const uint8_t*)
this +
sizeof(*this);
919 return (uint8_t*)
this +
sizeof(*this);
1041 uint8_t block_type_;
1042 uint8_t type_specific_;
1052 block_type_ = type_specific_ = 0;
1065 block_type_ = (uint8_t)bt;
1070 return type_specific_;
1142 return ntp_.
value();
1170 uint32_t delay_last_rr_;
1179 ssrc_ = last_rr_ = delay_last_rr_ = 0;
1265 return get_block_by_index<const XrDlrrSubblock>(
this, i,
num_subblocks(),
1271 return get_block_by_index<XrDlrrSubblock>(
this, i,
num_subblocks(),
#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).
uint64_t ntp_timestamp_t
NTP timestamp.
#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.
Commonly used types and functions.
Various units used in packets.