12 #ifndef ROC_RTCP_HEADERS_H_
13 #define ROC_RTCP_HEADERS_H_
33 void set_bitfield(T& v0,
const T v1,
const size_t shift,
const size_t mask) {
34 v0 &= T(~(mask << shift));
42 return (uint16_t)x / 4 - 1;
55 inline size_t padding_len(
const size_t size,
const size_t min_padding) {
56 const size_t size_to_pad = size + min_padding;
57 return min_padding + (size_to_pad & 0x03 ? 4 - (size_to_pad & 0x03) : 0);
61 template <
class Blk,
class Pkt>
65 const char* pkt_type) {
66 if (block_index >= num_blocks) {
67 roc_panic(
"%s: out of bounds: index=%lu size=%lu", pkt_type,
68 (
unsigned long)block_index, (
unsigned long)num_blocks);
70 return ((Blk*)(
const_cast<char*
>((
const char*)pkt) +
sizeof(*pkt)))[block_index];
89 static const size_t PacketMaxBlocks = 31;
106 NTP_HIGH_mask = 0xFFFFFFFF00000000,
109 NTP_LOW_mask = 0x00000000FFFFFFFF
129 (((uint64_t)
core::ntoh32u(high_ntp_) << NTP_HIGH_shift) & NTP_HIGH_mask)
130 | (((uint64_t)
core::ntoh32u(low_ntp_) << NTP_LOW_shift) & NTP_LOW_mask);
136 high_ntp_ =
core::hton32u(uint32_t((t >> NTP_HIGH_shift) & NTP_LOW_mask));
137 low_ntp_ =
core::hton32u(uint32_t((t >> NTP_LOW_shift) & NTP_LOW_mask));
155 Flag_VersionShift = 6,
156 Flag_VersionMask = 0x03,
161 Flag_PaddingShift = 5,
162 Flag_PaddingMask = 0x01,
167 Flag_CounterShift = 0,
168 Flag_CounterMask = 0x1F
200 return (count_ >> Flag_CounterShift) & Flag_CounterMask;
206 set_bitfield<uint8_t>(count_, (uint8_t)c, Flag_CounterShift, Flag_CounterMask);
216 return (count_ >> Flag_VersionShift) & Flag_VersionMask;
222 set_bitfield<uint8_t>(count_, v, Flag_VersionShift, Flag_VersionMask);
227 return (count_ & (Flag_PaddingMask << Flag_PaddingShift));
232 set_bitfield(count_, (uint8_t)v, Flag_PaddingShift, Flag_PaddingMask);
293 Losses_FractLost_shift = 24,
294 Losses_FractLost_mask = 0x0F,
299 Losses_CumLoss_shift = 24,
300 Losses_CumLoss_mask = 0x0FFF
330 ssrc_ = losses_ = last_seq_ = jitter_ = lsr_ = dlsr_ = 0;
346 uint8_t losses8 = (tmp >> Losses_FractLost_shift) & Losses_FractLost_mask;
347 float res = float(losses8) / float(1 << Losses_FractLost_shift);
358 if (nlost <= 0 || noverall == 0) {
360 }
else if ((
size_t)nlost >= noverall) {
363 l8 = (uint8_t)((uint32_t)(nlost << 8) / noverall);
367 set_bitfield<uint32_t>(losses, l8, Losses_FractLost_shift, Losses_FractLost_mask);
377 if (res & (1 << (Losses_CumLoss_shift - 1))) {
379 res |= ~(uint32_t)Losses_CumLoss_mask;
390 if (l > Losses_CumLoss_mask) {
391 l = Losses_CumLoss_mask;
392 }
else if (l < -(int32_t)Losses_CumLoss_mask) {
393 l = -Losses_CumLoss_mask;
395 set_bitfield<uint32_t>(losses, (uint32_t)l,
396 sizeof(losses_) * 8 - Losses_CumLoss_shift,
397 Losses_CumLoss_mask);
519 return get_block_by_index<const ReceptionReportBlock>(
this, i,
header().counter(),
525 return get_block_by_index<ReceptionReportBlock>(
this, i,
header().counter(),
578 uint32_t rtp_timestamp_;
579 uint32_t packet_cnt_;
664 return get_block_by_index<const ReceptionReportBlock>(
this, i,
header().counter(),
670 return get_block_by_index<ReceptionReportBlock>(
this, i,
header().counter(),
776 return (
const uint8_t*)
this +
sizeof(*this);
782 return (uint8_t*)
this +
sizeof(*this);
916 return (
const uint8_t*)
this +
sizeof(*this);
922 return (uint8_t*)
this +
sizeof(*this);
1044 uint8_t block_type_;
1045 uint8_t type_specific_;
1055 block_type_ = type_specific_ = 0;
1068 block_type_ = (uint8_t)bt;
1073 return type_specific_;
1145 return ntp_.
value();
1173 uint32_t delay_last_rr_;
1182 ssrc_ = last_rr_ = delay_last_rr_ = 0;
1268 return get_block_by_index<const XrDlrrSubblock>(
this, i,
num_subblocks(),
1274 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.
Utitilies for 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.