Skip to content

Commit

Permalink
Merge branch 'master' into fix-getAvailRcvBufferSize
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko authored Sep 27, 2022
2 parents 968979e + 90af35a commit f79c6f8
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 39 deletions.
34 changes: 21 additions & 13 deletions apps/uriparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,27 @@

using namespace std;

map<string, UriParser::Type> types;
map<string, UriParser::Type> g_types;

// Map construction using the initializer list is only available starting from C++11.
// This dummy structure is used instead.
struct UriParserInit
{
UriParserInit()
{
types["file"] = UriParser::FILE;
types["udp"] = UriParser::UDP;
types["tcp"] = UriParser::TCP;
types["srt"] = UriParser::SRT;
types["rtmp"] = UriParser::RTMP;
types["http"] = UriParser::HTTP;
types["rtp"] = UriParser::RTP;
types[""] = UriParser::UNKNOWN;
g_types["file"] = UriParser::FILE;
g_types["udp"] = UriParser::UDP;
g_types["tcp"] = UriParser::TCP;
g_types["srt"] = UriParser::SRT;
g_types["rtmp"] = UriParser::RTMP;
g_types["http"] = UriParser::HTTP;
g_types["rtp"] = UriParser::RTP;
g_types[""] = UriParser::UNKNOWN;
}
} g_uriparser_init;

UriParser::UriParser(const string& strUrl, DefaultExpect exp)
: m_uriType(UNKNOWN)
{
m_expect = exp;
Parse(strUrl, exp);
Expand Down Expand Up @@ -196,7 +199,7 @@ void UriParser::Parse(const string& strUrl, DefaultExpect exp)

// Check special things in the HOST entry.
size_t atp = m_host.find('@');
if ( atp != string::npos )
if (atp != string::npos)
{
string realhost = m_host.substr(atp+1);
string prehost;
Expand Down Expand Up @@ -309,22 +312,27 @@ void UriParser::Parse(const string& strUrl, DefaultExpect exp)
}
}

if ( m_proto == "file" )
if (m_proto == "file")
{
if ( m_path.size() > 3 && m_path.substr(0, 3) == "/./" )
m_path = m_path.substr(3);
}

// Post-parse fixes
// Treat empty protocol as a file. In this case, merge the host and path.
if ( exp == EXPECT_FILE && m_proto == "" && m_port == "" )
if (exp == EXPECT_FILE && m_proto == "" && m_port == "")
{
m_proto = "file";
m_path = m_host + m_path;
m_host = "";
}

m_uriType = types[m_proto]; // default-constructed UNKNOWN will be used if not found (although also inserted)
const auto proto_it = g_types.find(m_proto);
// Default-constructed UNKNOWN will be used if not found.
if (proto_it != g_types.end())
{
m_uriType = proto_it->second;
}
m_origUri = strUrl;
}

Expand Down
13 changes: 9 additions & 4 deletions srtcore/buffer_rcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1004,12 +1004,18 @@ void CRcvBufferNew::updateTsbPdTimeBase(uint32_t usPktTimestamp)
m_tsbpd.updateTsbPdTimeBase(usPktTimestamp);
}

string CRcvBufferNew::strFullnessState(int iFirstUnackSeqNo, const time_point& tsNow) const
string CRcvBufferNew::strFullnessState(bool enable_debug_log, int iFirstUnackSeqNo, const time_point& tsNow) const
{
stringstream ss;

ss << "Space avail " << getAvailSize(iFirstUnackSeqNo) << "/" << m_szSize;
ss << " pkts. ";
if (enable_debug_log)
{
ss << "iFirstUnackSeqNo=" << iFirstUnackSeqNo << " m_iStartSeqNo=" << m_iStartSeqNo
<< " m_iStartPos=" << m_iStartPos << " m_iMaxPosInc=" << m_iMaxPosInc << ". ";
}

ss << "Space avail " << getAvailSize(iFirstUnackSeqNo) << "/" << m_szSize << " pkts. ";

if (m_tsbpd.isEnabled() && m_iMaxPosInc > 0)
{
const PacketInfo nextValidPkt = getFirstValidPacketInfo();
Expand All @@ -1030,7 +1036,6 @@ string CRcvBufferNew::strFullnessState(int iFirstUnackSeqNo, const time_point& t
{
ss << "n/a";
}

ss << "). ";
}

Expand Down
2 changes: 1 addition & 1 deletion srtcore/buffer_rcv.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ class CRcvBufferNew

/// Form a string of the current buffer fullness state.
/// number of packets acknowledged, TSBPD readiness, etc.
std::string strFullnessState(int iFirstUnackSeqNo, const time_point& tsNow) const;
std::string strFullnessState(bool enable_debug_log, int iFirstUnackSeqNo, const time_point& tsNow) const;

private:
CTsbpdTime m_tsbpd;
Expand Down
25 changes: 16 additions & 9 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7723,9 +7723,15 @@ void srt::CUDT::releaseSynch()
void srt::CUDT::ackDataUpTo(int32_t ack)
{
const int acksize SRT_ATR_UNUSED = CSeqNo::seqoff(m_iRcvLastSkipAck, ack);

HLOGC(xtlog.Debug, log << "ackDataUpTo: %" << m_iRcvLastSkipAck << " -> %" << ack
<< " (" << acksize << " packets)");
if (acksize < 0)
{
LOGC(xtlog.Error,
log << CONID() << " ackDataUpTo: IPE: invalid ACK from %" << m_iRcvLastSkipAck << " to %" << ack << " ("
<< acksize << " packets)");
return;
}
HLOGC(xtlog.Debug,
log << "ackDataUpTo: %" << m_iRcvLastSkipAck << " -> %" << ack << " (" << acksize << " packets)");

m_iRcvLastAck = ack;
m_iRcvLastSkipAck = ack;
Expand Down Expand Up @@ -8652,7 +8658,7 @@ void srt::CUDT::processCtrlLossReport(const CPacket& ctrlpkt)

// This variable is used in "normal" logs, so it may cause a warning
// when logging is forcefully off.
int32_t wrong_loss SRT_ATR_UNUSED = CSeqNo::m_iMaxSeqNo;
int32_t wrong_loss SRT_ATR_UNUSED = SRT_SEQNO_NONE;

// protect packet retransmission
{
Expand Down Expand Up @@ -10130,10 +10136,11 @@ int srt::CUDT::processData(CUnit* in_unit)
else
{
#if ENABLE_NEW_RCVBUFFER
LOGC(qrlog.Warn, log << CONID() << "No room to store incoming packet seqno " << rpkt.m_iSeqNo
<< ", insert offset " << offset << ". "
<< m_pRcvBuffer->strFullnessState(m_iRcvLastSkipAck, steady_clock::now())
);
LOGC(qrlog.Warn,
log << CONID() << "No room to store incoming packet seqno " << rpkt.m_iSeqNo
<< ", insert offset " << offset << ". "
<< m_pRcvBuffer->strFullnessState(
qrlog.Debug.CheckEnabled(), m_iRcvLastSkipAck, steady_clock::now()));
#else
LOGC(qrlog.Warn, log << CONID() << "No room to store incoming packet seqno " << rpkt.m_iSeqNo
<< ", insert offset " << offset << ". "
Expand Down Expand Up @@ -10706,7 +10713,7 @@ void srt::CUDT::dropFromLossLists(int32_t from, int32_t to)
ScopedLock lg(m_RcvLossLock);
m_pRcvLossList->remove(from, to);

HLOGF(qrlog.Debug, "%sTLPKTDROP seq %d-%d (%d packets)", CONID().c_str(), from, to, CSeqNo::seqoff(from, to));
HLOGF(qrlog.Debug, "%sTLPKTDROP seq %d-%d (%d packets)", CONID().c_str(), from, to, CSeqNo::seqlen(from, to));

if (m_bPeerRexmitFlag == 0 || m_iReorderTolerance == 0)
return;
Expand Down
4 changes: 2 additions & 2 deletions srtcore/fec.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class FECFilterBuiltin: public SrtPacketFilterBase
size_t drop; //< by how much the sequence should increase to get to the next series
size_t collected; //< how many packets were taken to collect the clip

Group(): base(CSeqNo::m_iMaxSeqNo), step(0), drop(0), collected(0)
Group(): base(SRT_SEQNO_NONE), step(0), drop(0), collected(0)
{
}

Expand Down Expand Up @@ -87,7 +87,7 @@ class FECFilterBuiltin: public SrtPacketFilterBase
#if ENABLE_HEAVY_LOGGING
std::string DisplayStats()
{
if (base == CSeqNo::m_iMaxSeqNo)
if (base == SRT_SEQNO_NONE)
return "UNINITIALIZED!!!";

std::ostringstream os;
Expand Down
13 changes: 4 additions & 9 deletions srtcore/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,19 +715,14 @@ bool srt::CRcvLossList::remove(int32_t seqno)

bool srt::CRcvLossList::remove(int32_t seqno1, int32_t seqno2)
{
if (seqno1 <= seqno2)
if (CSeqNo::seqcmp(seqno1, seqno2) > 0)
{
for (int32_t i = seqno1; i <= seqno2; ++i)
remove(i);
return false;
}
else
for (int32_t i = seqno1; CSeqNo::seqcmp(i, seqno2) <= 0; i = CSeqNo::incseq(i))
{
for (int32_t j = seqno1; j < CSeqNo::m_iMaxSeqNo; ++j)
remove(j);
for (int32_t k = 0; k <= seqno2; ++k)
remove(k);
remove(i);
}

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion srtcore/socketconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ struct CSrtConfigSetter<SRTO_CONNTIMEO>
if (val < 0)
throw CUDTException(MJ_NOTSUP, MN_INVAL, 0);

using namespace sync;
using namespace srt::sync;
co.tdConnTimeOut = milliseconds_from(val);
}
};
Expand Down

0 comments on commit f79c6f8

Please sign in to comment.