1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Upgrade libsrt to v1.5.3. v5.0.183 v6.0.81 (#3808)

fix https://github.com/ossrs/srs/issues/3155
Build srt-1-fit fails with `standard attributes in middle of
decl-specifiers` on GCC 12,Arch Linux.

See https://github.com/Haivision/srt/releases/tag/v1.5.3
This commit is contained in:
Haibo Chen 2023-09-21 22:23:56 +08:00 committed by GitHub
parent f9bba0a9b0
commit c5e067fb0b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
94 changed files with 5974 additions and 6273 deletions

View file

@ -115,9 +115,10 @@ public:
/// Send a packet to the given address.
/// @param [in] addr pointer to the destination address.
/// @param [in] packet reference to a CPacket entity.
/// @param [in] src source address to sent on an outgoing packet (if not ANY)
/// @return Actual size of data sent.
int sendto(const sockaddr_any& addr, srt::CPacket& packet) const;
int sendto(const sockaddr_any& addr, srt::CPacket& packet, const sockaddr_any& src) const;
/// Receive a packet from the channel and record the source address.
/// @param [in] addr pointer to the source address.
@ -128,6 +129,21 @@ public:
void setConfig(const CSrtMuxerConfig& config);
void getSocketOption(int level, int sockoptname, char* pw_dataptr, socklen_t& w_len, int& w_status);
template<class Type>
Type sockopt(int level, int sockoptname, Type deflt)
{
Type retval;
socklen_t socklen = sizeof retval;
int status;
getSocketOption(level, sockoptname, ((char*)&retval), (socklen), (status));
if (status == -1)
return deflt;
return retval;
}
/// Get the IP TTL.
/// @param [in] ttl IP Time To Live.
/// @return TTL.
@ -160,6 +176,121 @@ private:
// although the object itself isn't considered modified.
mutable CSrtMuxerConfig m_mcfg; // Note: ReuseAddr is unused and ineffective.
sockaddr_any m_BindAddr;
// This feature is not enabled on Windows, for now.
// This is also turned off in case of MinGW
#ifdef SRT_ENABLE_PKTINFO
bool m_bBindMasked; // True if m_BindAddr is INADDR_ANY. Need for quick check.
// Calculating the required space is extremely tricky, and whereas on most
// platforms it's possible to define it this way:
//
// size_t s = max( CMSG_SPACE(sizeof(in_pktinfo)), CMSG_SPACE(sizeof(in6_pktinfo)) )
//
// ...on some platforms however CMSG_SPACE macro can't be resolved as constexpr.
//
// This structure is exclusively used to determine the required size for
// CMSG buffer so that it can be allocated in a solid block with CChannel.
// NOT TO BE USED to access any data inside the CMSG message.
struct CMSGNodeIPv4
{
in_pktinfo in4;
size_t extrafill;
cmsghdr hdr;
};
struct CMSGNodeIPv6
{
in6_pktinfo in6;
size_t extrafill;
cmsghdr hdr;
};
// This is 'mutable' because it's a utility buffer defined here
// to avoid unnecessary re-allocations.
mutable char m_acCmsgRecvBuffer [sizeof (CMSGNodeIPv4) + sizeof (CMSGNodeIPv6)]; // Reserved space for ancillary data with pktinfo
mutable char m_acCmsgSendBuffer [sizeof (CMSGNodeIPv4) + sizeof (CMSGNodeIPv6)]; // Reserved space for ancillary data with pktinfo
// IMPORTANT!!! This function shall be called EXCLUSIVELY just after
// calling ::recvmsg function. It uses a static buffer to supply data
// for the call, and it's stated that only one thread is trying to
// use a CChannel object in receiving mode.
sockaddr_any getTargetAddress(const msghdr& msg) const
{
// Loop through IP header messages
cmsghdr* cmsg = CMSG_FIRSTHDR(&msg);
for (cmsg = CMSG_FIRSTHDR(&msg);
cmsg != NULL;
cmsg = CMSG_NXTHDR(((msghdr*)&msg), cmsg))
{
// This should be safe - this packet contains always either
// IPv4 headers or IPv6 headers.
if (cmsg->cmsg_level == IPPROTO_IP && cmsg->cmsg_type == IP_PKTINFO)
{
in_pktinfo *dest_ip_ptr = (in_pktinfo*)CMSG_DATA(cmsg);
return sockaddr_any(dest_ip_ptr->ipi_addr, 0);
}
if (cmsg->cmsg_level == IPPROTO_IPV6 && cmsg->cmsg_type == IPV6_PKTINFO)
{
in6_pktinfo* dest_ip_ptr = (in6_pktinfo*)CMSG_DATA(cmsg);
return sockaddr_any(dest_ip_ptr->ipi6_addr, 0);
}
}
// Fallback for an error
return sockaddr_any(m_BindAddr.family());
}
// IMPORTANT!!! This function shall be called EXCLUSIVELY just before
// calling ::sendmsg function. It uses a static buffer to supply data
// for the call, and it's stated that only one thread is trying to
// use a CChannel object in sending mode.
bool setSourceAddress(msghdr& mh, const sockaddr_any& adr) const
{
// In contrast to an advice followed on the net, there's no case of putting
// both IPv4 and IPv6 ancillary data, case we could have them. Only one
// IP version is used and it's the version as found in @a adr, which should
// be the version used for binding.
if (adr.family() == AF_INET)
{
mh.msg_control = m_acCmsgSendBuffer;
mh.msg_controllen = CMSG_SPACE(sizeof(in_pktinfo));
cmsghdr* cmsg_send = CMSG_FIRSTHDR(&mh);
// after initializing msghdr & control data to CMSG_SPACE(sizeof(struct in_pktinfo))
cmsg_send->cmsg_level = IPPROTO_IP;
cmsg_send->cmsg_type = IP_PKTINFO;
cmsg_send->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo));
in_pktinfo* pktinfo = (in_pktinfo*) CMSG_DATA(cmsg_send);
pktinfo->ipi_ifindex = 0;
pktinfo->ipi_spec_dst = adr.sin.sin_addr;
return true;
}
if (adr.family() == AF_INET6)
{
mh.msg_control = m_acCmsgSendBuffer;
mh.msg_controllen = CMSG_SPACE(sizeof(in6_pktinfo));
cmsghdr* cmsg_send = CMSG_FIRSTHDR(&mh);
cmsg_send->cmsg_level = IPPROTO_IPV6;
cmsg_send->cmsg_type = IPV6_PKTINFO;
cmsg_send->cmsg_len = CMSG_LEN(sizeof(in6_pktinfo));
in6_pktinfo* pktinfo = (in6_pktinfo*) CMSG_DATA(cmsg_send);
pktinfo->ipi6_ifindex = 0;
pktinfo->ipi6_addr = adr.sin6.sin6_addr;
return true;
}
return false;
}
#endif // SRT_ENABLE_PKTINFO
};
} // namespace srt