1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef MS_RTC_RTCP_XR_RECEIVER_REFERENCE_TIME_HPP
#define MS_RTC_RTCP_XR_RECEIVER_REFERENCE_TIME_HPP
#include "common.hpp"
#include "RTC/RTCP/XR.hpp"
/* https://tools.ietf.org/html/rfc3611
* Receiver Reference Time Report Block
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| BT=4 | reserved | block length = 2 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| NTP timestamp, most significant word |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| NTP timestamp, least significant word |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
namespace RTC
{
namespace RTCP
{
class ReceiverReferenceTime : public ExtendedReportBlock
{
public:
/**
* @remarks
* - This struct is guaranteed to be aligned to 4 bytes.
*/
struct Body
{
uint32_t ntpSec;
uint32_t ntpFrac;
};
public:
static const size_t BodySize{ 8 };
static ReceiverReferenceTime* Parse(const uint8_t* data, size_t len);
public:
// Locally generated Report. Holds the data internally.
ReceiverReferenceTime() : ExtendedReportBlock(RTCP::ExtendedReportBlock::Type::RRT)
{
this->body = reinterpret_cast<Body*>(this->raw);
}
// Parsed Report. Points to an external data.
explicit ReceiverReferenceTime(CommonHeader* header)
: ExtendedReportBlock(ExtendedReportBlock::Type::RRT)
{
this->header = header;
this->body = reinterpret_cast<Body*>((header) + 1);
}
public:
uint32_t GetNtpSec() const
{
return ntohl(this->body->ntpSec);
}
void SetNtpSec(uint32_t ntpSec)
{
this->body->ntpSec = htonl(ntpSec);
}
uint32_t GetNtpFrac() const
{
return ntohl(this->body->ntpFrac);
}
void SetNtpFrac(uint32_t ntpFrac)
{
this->body->ntpFrac = htonl(ntpFrac);
}
/* Pure virtual methods inherited from ExtendedReportBlock. */
public:
void Dump(int indentation = 0) const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override
{
size_t size{ 4 }; // Common header.
size += BodySize;
return size;
}
private:
Body* body{ nullptr };
uint8_t raw[BodySize] = { 0 };
};
} // namespace RTCP
} // namespace RTC
#endif