diff --git a/srtcore/window.cpp b/srtcore/window.cpp index 96562d7a4..b077178c9 100644 --- a/srtcore/window.cpp +++ b/srtcore/window.cpp @@ -61,6 +61,8 @@ modified by using namespace std; using namespace srt::sync; +namespace srt +{ namespace ACKWindowTools { @@ -138,11 +140,12 @@ int acknowledge(Seq* r_aSeq, const size_t size, int& r_iHead, int& r_iTail, int3 return -1; } -} +} // namespace AckTools +} // namespace srt //////////////////////////////////////////////////////////////////////////////// -void CPktTimeWindowTools::initializeWindowArrays(int* r_pktWindow, int* r_probeWindow, int* r_bytesWindow, size_t asize, size_t psize) +void srt::CPktTimeWindowTools::initializeWindowArrays(int* r_pktWindow, int* r_probeWindow, int* r_bytesWindow, size_t asize, size_t psize) { for (size_t i = 0; i < asize; ++ i) r_pktWindow[i] = 1000000; //1 sec -> 1 pkt/sec @@ -155,7 +158,7 @@ void CPktTimeWindowTools::initializeWindowArrays(int* r_pktWindow, int* r_probeW } -int CPktTimeWindowTools::getPktRcvSpeed_in(const int* window, int* replica, const int* abytes, size_t asize, int& bytesps) +int srt::CPktTimeWindowTools::getPktRcvSpeed_in(const int* window, int* replica, const int* abytes, size_t asize, int& bytesps) { // get median value, but cannot change the original value order in the window std::copy(window, window + asize, replica); @@ -199,7 +202,7 @@ int CPktTimeWindowTools::getPktRcvSpeed_in(const int* window, int* replica, cons } } -int CPktTimeWindowTools::getBandwidth_in(const int* window, int* replica, size_t psize) +int srt::CPktTimeWindowTools::getBandwidth_in(const int* window, int* replica, size_t psize) { // This calculation does more-less the following: // diff --git a/srtcore/window.h b/srtcore/window.h index 72924112c..ecc4a4947 100644 --- a/srtcore/window.h +++ b/srtcore/window.h @@ -61,17 +61,20 @@ modified by #include "packet.h" #include "udt.h" +namespace srt +{ + namespace ACKWindowTools { struct Seq { int32_t iACKSeqNo; // Seq. No. of the ACK packet int32_t iACK; // Data packet Seq. No. carried by the ACK packet - srt::sync::steady_clock::time_point tsTimeStamp; // The timestamp when the ACK was sent + sync::steady_clock::time_point tsTimeStamp; // The timestamp when the ACK was sent }; void store(Seq* r_aSeq, const size_t size, int& r_iHead, int& r_iTail, int32_t seq, int32_t ack); - int acknowledge(Seq* r_aSeq, const size_t size, int& r_iHead, int& r_iTail, int32_t seq, int32_t& r_ack, const srt::sync::steady_clock::time_point& currtime); + int acknowledge(Seq* r_aSeq, const size_t size, int& r_iHead, int& r_iTail, int32_t seq, int32_t& r_ack, const sync::steady_clock::time_point& currtime); } template @@ -104,7 +107,7 @@ class CACKWindow /// @param [in] currtime The timestamp of ACKACK packet reception by the receiver /// @return RTT - int acknowledge(int32_t seq, int32_t& r_ack, const srt::sync::steady_clock::time_point& currtime) + int acknowledge(int32_t seq, int32_t& r_ack, const sync::steady_clock::time_point& currtime) { return ACKWindowTools::acknowledge(m_aSeq, SIZE, m_iHead, m_iTail, seq, r_ack, currtime); } @@ -145,14 +148,14 @@ class CPktTimeWindow: CPktTimeWindowTools m_iProbeWindowPtr(0), m_iLastSentTime(0), m_iMinPktSndInt(1000000), - m_tsLastArrTime(srt::sync::steady_clock::now()), + m_tsLastArrTime(sync::steady_clock::now()), m_tsCurrArrTime(), m_tsProbeTime(), m_Probe1Sequence(SRT_SEQNO_NONE) { // Exception: up to CUDT ctor - srt::sync::setupMutex(m_lockPktWindow, "PktWindow"); - srt::sync::setupMutex(m_lockProbeWindow, "ProbeWindow"); + sync::setupMutex(m_lockPktWindow, "PktWindow"); + sync::setupMutex(m_lockProbeWindow, "ProbeWindow"); CPktTimeWindowTools::initializeWindowArrays(m_aPktWindow, m_aProbeWindow, m_aBytesWindow, ASIZE, PSIZE); } @@ -172,7 +175,7 @@ class CPktTimeWindow: CPktTimeWindowTools int getPktRcvSpeed(int& w_bytesps) const { // Lock access to the packet Window - srt::sync::ScopedLock cg(m_lockPktWindow); + sync::ScopedLock cg(m_lockPktWindow); int pktReplica[ASIZE]; // packet information window (inter-packet time) return getPktRcvSpeed_in(m_aPktWindow, pktReplica, m_aBytesWindow, ASIZE, (w_bytesps)); @@ -190,7 +193,7 @@ class CPktTimeWindow: CPktTimeWindowTools int getBandwidth() const { // Lock access to the packet Window - srt::sync::ScopedLock cg(m_lockProbeWindow); + sync::ScopedLock cg(m_lockProbeWindow); int probeReplica[PSIZE]; return getBandwidth_in(m_aProbeWindow, probeReplica, PSIZE); @@ -213,12 +216,12 @@ class CPktTimeWindow: CPktTimeWindowTools void onPktArrival(int pktsz = 0) { - srt::sync::ScopedLock cg(m_lockPktWindow); + sync::ScopedLock cg(m_lockPktWindow); - m_tsCurrArrTime = srt::sync::steady_clock::now(); + m_tsCurrArrTime = sync::steady_clock::now(); // record the packet interval between the current and the last one - m_aPktWindow[m_iPktWindowPtr] = (int) srt::sync::count_microseconds(m_tsCurrArrTime - m_tsLastArrTime); + m_aPktWindow[m_iPktWindowPtr] = (int) sync::count_microseconds(m_tsCurrArrTime - m_tsLastArrTime); m_aBytesWindow[m_iPktWindowPtr] = pktsz; // the window is logically circular @@ -231,9 +234,9 @@ class CPktTimeWindow: CPktTimeWindowTools } /// Shortcut to test a packet for possible probe 1 or 2 - void probeArrival(const srt::CPacket& pkt, bool unordered) + void probeArrival(const CPacket& pkt, bool unordered) { - const int inorder16 = pkt.m_iSeqNo & srt::PUMASK_SEQNO_PROBE; + const int inorder16 = pkt.m_iSeqNo & PUMASK_SEQNO_PROBE; // for probe1, we want 16th packet if (inorder16 == 0) @@ -252,7 +255,7 @@ class CPktTimeWindow: CPktTimeWindowTools } /// Record the arrival time of the first probing packet. - void probe1Arrival(const srt::CPacket& pkt, bool unordered) + void probe1Arrival(const CPacket& pkt, bool unordered) { if (unordered && pkt.m_iSeqNo == m_Probe1Sequence) { @@ -263,13 +266,13 @@ class CPktTimeWindow: CPktTimeWindowTools return; } - m_tsProbeTime = srt::sync::steady_clock::now(); + m_tsProbeTime = sync::steady_clock::now(); m_Probe1Sequence = pkt.m_iSeqNo; // Record the sequence where 16th packet probe was taken } /// Record the arrival time of the second probing packet and the interval between packet pairs. - void probe2Arrival(const srt::CPacket& pkt) + void probe2Arrival(const CPacket& pkt) { // Reject probes that don't refer to the very next packet // towards the one that was lately notified by probe1Arrival. @@ -279,16 +282,16 @@ class CPktTimeWindow: CPktTimeWindowTools // expected packet pair, behave as if the 17th packet was lost. // no start point yet (or was reset) OR not very next packet - if (m_Probe1Sequence == SRT_SEQNO_NONE || srt::CSeqNo::incseq(m_Probe1Sequence) != pkt.m_iSeqNo) + if (m_Probe1Sequence == SRT_SEQNO_NONE || CSeqNo::incseq(m_Probe1Sequence) != pkt.m_iSeqNo) return; // Grab the current time before trying to acquire // a mutex. This might add extra delay and therefore // screw up the measurement. - const srt::sync::steady_clock::time_point now = srt::sync::steady_clock::now(); + const sync::steady_clock::time_point now = sync::steady_clock::now(); // Lock access to the packet Window - srt::sync::ScopedLock cg(m_lockProbeWindow); + sync::ScopedLock cg(m_lockProbeWindow); m_tsCurrArrTime = now; @@ -298,8 +301,8 @@ class CPktTimeWindow: CPktTimeWindowTools // record the probing packets interval // Adjust the time for what a complete packet would have take - const int64_t timediff = srt::sync::count_microseconds(m_tsCurrArrTime - m_tsProbeTime); - const int64_t timediff_times_pl_size = timediff * srt::CPacket::SRT_MAX_PAYLOAD_SIZE; + const int64_t timediff = sync::count_microseconds(m_tsCurrArrTime - m_tsProbeTime); + const int64_t timediff_times_pl_size = timediff * CPacket::SRT_MAX_PAYLOAD_SIZE; // Let's take it simpler than it is coded here: // (stating that a packet has never zero size) @@ -325,27 +328,28 @@ class CPktTimeWindow: CPktTimeWindowTools } private: - int m_aPktWindow[ASIZE]; // Packet information window (inter-packet time) + int m_aPktWindow[ASIZE]; // Packet information window (inter-packet time) int m_aBytesWindow[ASIZE]; - int m_iPktWindowPtr; // Position pointer of the packet info. window - mutable srt::sync::Mutex m_lockPktWindow; // Used to synchronize access to the packet window + int m_iPktWindowPtr; // Position pointer of the packet info. window + mutable sync::Mutex m_lockPktWindow; // Used to synchronize access to the packet window - int m_aProbeWindow[PSIZE]; // Record inter-packet time for probing packet pairs - int m_iProbeWindowPtr; // Position pointer to the probing window - mutable srt::sync::Mutex m_lockProbeWindow; // Used to synchronize access to the probe window + int m_aProbeWindow[PSIZE]; // Record inter-packet time for probing packet pairs + int m_iProbeWindowPtr; // Position pointer to the probing window + mutable sync::Mutex m_lockProbeWindow; // Used to synchronize access to the probe window - int m_iLastSentTime; // Last packet sending time - int m_iMinPktSndInt; // Minimum packet sending interval + int m_iLastSentTime; // Last packet sending time + int m_iMinPktSndInt; // Minimum packet sending interval - srt::sync::steady_clock::time_point m_tsLastArrTime; // Last packet arrival time - srt::sync::steady_clock::time_point m_tsCurrArrTime; // Current packet arrival time - srt::sync::steady_clock::time_point m_tsProbeTime; // Arrival time of the first probing packet - int32_t m_Probe1Sequence; // Sequence number for which the arrival time was notified + sync::steady_clock::time_point m_tsLastArrTime; // Last packet arrival time + sync::steady_clock::time_point m_tsCurrArrTime; // Current packet arrival time + sync::steady_clock::time_point m_tsProbeTime; // Arrival time of the first probing packet + int32_t m_Probe1Sequence; // Sequence number for which the arrival time was notified private: CPktTimeWindow(const CPktTimeWindow&); CPktTimeWindow &operator=(const CPktTimeWindow&); }; +} // namespace srt #endif