diff --git a/apps/uriparser.cpp b/apps/uriparser.cpp index 4dae60a8b1..d962d1bb30 100644 --- a/apps/uriparser.cpp +++ b/apps/uriparser.cpp @@ -25,24 +25,27 @@ using namespace std; -map types; +map 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); @@ -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; @@ -309,7 +312,7 @@ 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); @@ -317,14 +320,19 @@ void UriParser::Parse(const string& strUrl, DefaultExpect exp) // 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; } diff --git a/srtcore/buffer_rcv.cpp b/srtcore/buffer_rcv.cpp index 8ecbd10fe1..974bb68de0 100644 --- a/srtcore/buffer_rcv.cpp +++ b/srtcore/buffer_rcv.cpp @@ -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(); @@ -1030,7 +1036,6 @@ string CRcvBufferNew::strFullnessState(int iFirstUnackSeqNo, const time_point& t { ss << "n/a"; } - ss << "). "; } diff --git a/srtcore/buffer_rcv.h b/srtcore/buffer_rcv.h index d628c459fd..ab5ebc165e 100644 --- a/srtcore/buffer_rcv.h +++ b/srtcore/buffer_rcv.h @@ -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; diff --git a/srtcore/core.cpp b/srtcore/core.cpp index 30cafcbd3f..03a7170e1c 100644 --- a/srtcore/core.cpp +++ b/srtcore/core.cpp @@ -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; @@ -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 { @@ -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 << ". " @@ -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; diff --git a/srtcore/fec.h b/srtcore/fec.h index 71a6adfa7d..23b5a58f11 100644 --- a/srtcore/fec.h +++ b/srtcore/fec.h @@ -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) { } @@ -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; diff --git a/srtcore/list.cpp b/srtcore/list.cpp index 2125995958..4eb592abcb 100644 --- a/srtcore/list.cpp +++ b/srtcore/list.cpp @@ -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; } diff --git a/srtcore/socketconfig.cpp b/srtcore/socketconfig.cpp index a49d1d639e..27862ef3c5 100644 --- a/srtcore/socketconfig.cpp +++ b/srtcore/socketconfig.cpp @@ -502,7 +502,7 @@ struct CSrtConfigSetter if (val < 0) throw CUDTException(MJ_NOTSUP, MN_INVAL, 0); - using namespace sync; + using namespace srt::sync; co.tdConnTimeOut = milliseconds_from(val); } };