Skip to content

Commit

Permalink
[core] Pre-refax of change-independent parts for Haivision#2677 (Haiv…
Browse files Browse the repository at this point in the history
  • Loading branch information
ethouris authored Sep 18, 2023
1 parent 09f35c0 commit 0d804ec
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
9 changes: 7 additions & 2 deletions srtcore/buffer_rcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ CRcvBuffer::CRcvBuffer(int initSeqNo, size_t size, CUnitQueue* unitqueue, bool b
, m_bMessageAPI(bMessageAPI)
, m_iBytesCount(0)
, m_iPktsCount(0)
, m_uAvgPayloadSz(SRT_LIVE_DEF_PLSIZE)
, m_uAvgPayloadSz(0)
{
SRT_ASSERT(size < size_t(std::numeric_limits<int>::max())); // All position pointers are integers
}
Expand Down Expand Up @@ -758,7 +758,12 @@ void CRcvBuffer::countBytes(int pkts, int bytes)
m_iBytesCount += bytes; // added or removed bytes from rcv buffer
m_iPktsCount += pkts;
if (bytes > 0) // Assuming one pkt when adding bytes
m_uAvgPayloadSz = avg_iir<100>(m_uAvgPayloadSz, (unsigned) bytes);
{
if (!m_uAvgPayloadSz)
m_uAvgPayloadSz = bytes;
else
m_uAvgPayloadSz = avg_iir<100>(m_uAvgPayloadSz, (unsigned) bytes);
}
}

void CRcvBuffer::releaseUnitInPos(int pos)
Expand Down
9 changes: 9 additions & 0 deletions srtcore/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,15 @@ srt::EReadStatus srt::CChannel::recvfrom(sockaddr_any& w_addr, CPacket& w_packet
if ((msg_flags & errmsgflg[i].first) != 0)
flg << " " << errmsgflg[i].second;

if (msg_flags & MSG_TRUNC)
{
// Additionally show buffer information in this case
flg << " buffers: ";
for (size_t i = 0; i < CPacket::PV_SIZE; ++i)
{
flg << "[" << w_packet.m_PacketVector[i].iov_len << "] ";
}
}
// This doesn't work the same way on Windows, so on Windows just skip it.
#endif

Expand Down
2 changes: 1 addition & 1 deletion srtcore/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ void srt::CIPAddress::pton(sockaddr_any& w_addr, const uint32_t ip[4], const soc
{
// Check if the peer address is a model of IPv4-mapped-on-IPv6.
// If so, it means that the `ip` array should be interpreted as IPv4.
const bool is_mapped_ipv4 = checkMappedIPv4((uint16_t*)peer.sin6.sin6_addr.s6_addr);
const bool is_mapped_ipv4 = checkMappedIPv4(peer.sin6);

sockaddr_in6* a = (&w_addr.sin6);

Expand Down
9 changes: 9 additions & 0 deletions srtcore/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,15 @@ inline std::string SrtVersionString(int version)

bool SrtParseConfig(const std::string& s, SrtConfig& w_config);

bool checkMappedIPv4(const uint16_t* sa);

inline bool checkMappedIPv4(const sockaddr_in6& sa)
{
const uint16_t* addr = reinterpret_cast<const uint16_t*>(&sa.sin6_addr.s6_addr);
return checkMappedIPv4(addr);
}


} // namespace srt

#endif
5 changes: 4 additions & 1 deletion srtcore/congctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class LiveCC: public SrtCongestionControlBase
int64_t m_llSndMaxBW; //Max bandwidth (bytes/sec)
srt::sync::atomic<size_t> m_zSndAvgPayloadSize; //Average Payload Size of packets to xmit
size_t m_zMaxPayloadSize;
size_t m_zHeaderSize;

// NAKREPORT stuff.
int m_iMinNakInterval_us; // Minimum NAK Report Period (usec)
Expand All @@ -81,6 +82,8 @@ class LiveCC: public SrtCongestionControlBase
m_zMaxPayloadSize = parent->maxPayloadSize();
m_zSndAvgPayloadSize = m_zMaxPayloadSize;

m_zHeaderSize = parent->m_config.iMSS - parent->maxPayloadSize();

m_iMinNakInterval_us = 20000; //Minimum NAK Report Period (usec)
m_iNakReportAccel = 2; //Default NAK Report Period (RTT) accelerator (send periodic NAK every RTT/2)

Expand Down Expand Up @@ -173,7 +176,7 @@ class LiveCC: public SrtCongestionControlBase
void updatePktSndPeriod()
{
// packet = payload + header
const double pktsize = (double) m_zSndAvgPayloadSize.load() + CPacket::SRT_DATA_HDR_SIZE;
const double pktsize = (double) m_zSndAvgPayloadSize.load() + m_zHeaderSize;
m_dPktSndPeriod = 1000 * 1000.0 * (pktsize / m_llSndMaxBW);
HLOGC(cclog.Debug, log << "LiveCC: sending period updated: " << m_dPktSndPeriod
<< " by avg pktsize=" << m_zSndAvgPayloadSize
Expand Down

0 comments on commit 0d804ec

Please sign in to comment.