1#if defined(HAVE_CONFIG_H)
19#define RESIPROCATE_SUBSYSTEM Subsystem::EEP
22 : mCaptureHost(captureHost), mCapturePort(capturePort), mCaptureAgentID(captureAgentID)
24 bool initV4Socket =
true;
25 struct sockaddr_storage myaddr;
26 memset(&myaddr, 0,
sizeof(myaddr));
33 struct sockaddr_in6* myaddrv6 = (
struct sockaddr_in6*)&myaddr;
34 sockaddrlen =
sizeof(
struct sockaddr_in6);
35 myaddrv6->sin6_family = AF_INET6;
36 myaddrv6->sin6_addr = in6addr_any;
37 myaddrv6->sin6_port = 0;
38 mSocket = ::socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
42 ::setsockopt(mSocket, IPPROTO_IPV6, IPV6_V6ONLY, &no,
sizeof(no));
48 ::setsockopt(mSocket, IPPROTO_IPV6, IPV6_V6ONLY, (
const char*)&no,
sizeof(no));
56 struct sockaddr_in* myaddrv4 = (
struct sockaddr_in*)&myaddr;
57 sockaddrlen =
sizeof(
struct sockaddr_in);
58 myaddrv4->sin_family = AF_INET;
59 myaddrv4->sin_addr.s_addr = INADDR_ANY;
60 myaddrv4->sin_port = 0;
62 mSocket = ::socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
67 ErrLog(<<
"Failed to create socket");
68 throw std::runtime_error(
"Failed to create socket");
76 ErrLog(<<
"Failed to set O_NONBLOCK");
77 throw std::runtime_error(
"Failed to set O_NONBLOCK");
80 if(::bind(mSocket, (
struct sockaddr*)&myaddr, sockaddrlen) < 0)
83 throw std::runtime_error(
"bind failed");
87 struct addrinfo *rset;
88 if(getaddrinfo(mCaptureHost.
c_str(), 0, 0, &rset) != 0)
90 ErrLog(<<
"getaddrinfo failed");
91 throw std::runtime_error(
"getaddrinfo failed");
95 ErrLog(<<
"no results from getaddrinfo");
96 throw std::runtime_error(
"no results from getaddrinfo");
98 const struct addrinfo& dest = rset[0];
99 switch(dest.ai_family)
102 memcpy(&mDestination.
v4Address, dest.ai_addr, dest.ai_addrlen);
103 mDestination.
v4Address.sin_port = htons(mCapturePort);
107 memcpy(&mDestination.v6Address, dest.ai_addr, dest.ai_addrlen);
108 mDestination.v6Address.sin6_port = htons(mCapturePort);
112 ErrLog(<<
"unsupported address family");
113 throw std::runtime_error(
"unsupported address family");
116 InfoLog(<<
"HEP capture agent ready to send to " << mDestination);
132 c[0] = (c[1] & 0x80) ? 0xff : 0;
140 stream <<
"\"report_blocks\":[";
142 for(
int i = 0 ; i < rrCount; i++)
144 const struct rtcp_rr *rr = &rr_vec[i];
145 stream << ((i>0) ?
"," :
"")
147 <<
"\"source_ssrc\":" << ntohl(rr->
ssrc) <<
","
148 <<
"\"highest_seq_no\":" << ntohl(rr->
last_seq) <<
","
150 <<
"\"ia_jitter\":" << ntohl(rr->
jitter) <<
","
152 <<
"\"lsr\":" << ntohl(rr->
lsr) <<
","
153 <<
"\"dlsr\":" << ntohl(rr->
dlsr)
157 stream <<
"],\"report_count\":" << rrCount;
169 if(rtcpRaw.
size() < 8)
171 ErrLog(<<
"too small to be a valid RTCP packet");
182#ifdef RTCP_TRUST_BIT_FIELD_ORDER
184 unsigned int rrCount = msg->
hdr.
count;
191 unsigned int version = (byte0 & 0xc0) >> 6;
192 unsigned int rrCount = (byte0 & 0x1f);
193 bool p = (byte0 & 0x20) >> 5;
195 unsigned int pt = msg->
hdr.
pt;
197 StackLog(<<
"RTCP version: " << version <<
" p " << p
198 <<
" RR count: " << rrCount
199 <<
" packet type: " << pt
200 <<
" length: " << (ntohs(msg->
hdr.
length)*2) <<
" bytes");
205 ErrLog(<<
"unsupported RTCP version: " << version);
209 stream <<
"{" <<
"\"type\":" << pt <<
",";
215 stream <<
"\"sender_information\":{"
216 <<
"\"ntp_timestamp_sec\":" << ntohl(msg->
r.
sr.
ntp_sec) <<
","
217 <<
"\"ntp_timestamp_usec\":" << ntohl(msg->
r.
sr.
ntp_frac) <<
","
218 <<
"\"octets\":" << ntohl(msg->
r.
sr.
osent) <<
","
219 <<
"\"rtp_timestamp\":" << ntohl(msg->
r.
sr.
rtp_ts) <<
","
220 <<
"\"packets\":" << ntohl(msg->
r.
sr.
psent)
222 <<
"\"ssrc\":" << ntohl(msg->
r.
sr.
ssrc) <<
",";
223 rr =
reinterpret_cast<const struct
rtcp_rr*
>(&msg->
r.
sr.
rrv);
228 stream <<
"\"ssrc\":" << ntohl(msg->
r.
rr.
ssrc) <<
",";
229 rr =
reinterpret_cast<const struct
rtcp_rr*
>(&msg->
r.
rr.
rrv);
234 WarningLog(<<
"unhandled RTCP packet type: " << pt);
249 <<
" destination: " << destination
250 <<
" constructed RTCP JSON: " <<
json);
261 return sendto(mSocket, buf.
data(), (
int)buf.
size(), 0, &mDestination.
address, (
int)mDestination.
length()) < 0;
void encodeRRvec(DataStream &stream, const struct rtcp_rr *rr_vec, int rrCount)
int32_t ntoh_cpl(const void *x)
#define WarningLog(args_)
#define resip_assert(x)
This file needs to work for both C and C++ code.
An iostream that operates on an existing Data.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
const char * c_str() const
Returns a null-terminated string representing.
size_type size() const noexcept
Returns the number of bytes in this Data.
const char * data() const noexcept
Returns a pointer to the contents of this Data.
static bool isIpV4Address(const Data &ipAddress)
HepAgent(const Data &captureHost, int capturePort, int captureAgentID)
virtual Data convertRTCPtoJSON(const Data &rtcpRaw)
void sendRTCP(const TransportType type, const GenericIPAddress &source, const GenericIPAddress &destination, const Data &rtcpRaw, const Data &correlationId)
virtual bool sendToWire(const Data &buf) const
dcm! – add UnusedChecking(_enum) below;
TransportType
An enumeration of transport protocols.
bool makeSocketNonBlocking(Socket fd)
Interface to Real-time Transport Protocol and RTCP.
Represents an IP-address and port (V4 or V6).
unsigned int p
Padding flag
unsigned int pt
RTCP packet type
unsigned int count
Varies by packet type
unsigned int version
Protocol version
uint16_t length
Packet length in words.
uint32_t ntp_sec
NTP timestamp - seconds
uint32_t osent
RTP octets sent
struct rtcp_msg::rtcp_hdr hdr
struct rtcp_msg::@11::@12 sr
Sender report (SR)
uint32_t ssrc
Sender generating report
struct rtcp_msg::@11::@13 rr
Reception report (RR)
uint32_t ntp_frac
NTP timestamp - fractions.
struct rtcp_rr rrv[1]
Reception report blocks
uint32_t psent
RTP packets sent
uint32_t rtp_ts
RTP timestamp
uint32_t lsr
Last SR packet from this source.
uint32_t dlsr
Delay since last SR packet
uint32_t jitter
Interarrival jitter
uint32_t fraction_lost_32
Combine the previous two fields.
uint32_t ssrc
Data source being reported
uint32_t last_seq
Extended last seq.