@@ -52,7 +52,6 @@ modified by
5252
5353#include " platform_sys.h"
5454
55- #include < cstring>
5655#include < cmath>
5756#include " buffer_snd.h"
5857#include " packet.h"
@@ -65,103 +64,6 @@ using namespace std;
6564using namespace srt_logging ;
6665using namespace sync ;
6766
68- // You can change this value at build config by using "ENFORCE" options.
69- #if !defined(SRT_MAVG_SAMPLING_RATE)
70- #define SRT_MAVG_SAMPLING_RATE 40
71- #endif
72-
73- bool AvgBufSize::isTimeToUpdate (const time_point& now) const
74- {
75- const int usMAvgBasePeriod = 1000000 ; // 1s in microseconds
76- const int us2ms = 1000 ;
77- const int msMAvgPeriod = (usMAvgBasePeriod / SRT_MAVG_SAMPLING_RATE) / us2ms;
78- const uint64_t elapsed_ms = count_milliseconds (now - m_tsLastSamplingTime); // ms since last sampling
79- return (elapsed_ms >= msMAvgPeriod);
80- }
81-
82- void AvgBufSize::update (const steady_clock::time_point& now, int pkts, int bytes, int timespan_ms)
83- {
84- const uint64_t elapsed_ms = count_milliseconds (now - m_tsLastSamplingTime); // ms since last sampling
85- m_tsLastSamplingTime = now;
86- const uint64_t one_second_in_ms = 1000 ;
87- if (elapsed_ms > one_second_in_ms)
88- {
89- // No sampling in last 1 sec, initialize average
90- m_dCountMAvg = pkts;
91- m_dBytesCountMAvg = bytes;
92- m_dTimespanMAvg = timespan_ms;
93- return ;
94- }
95-
96- //
97- // weight last average value between -1 sec and last sampling time (LST)
98- // and new value between last sampling time and now
99- // |elapsed_ms|
100- // +----------------------------------+-------+
101- // -1 LST 0(now)
102- //
103- m_dCountMAvg = avg_iir_w<1000 , double >(m_dCountMAvg, pkts, elapsed_ms);
104- m_dBytesCountMAvg = avg_iir_w<1000 , double >(m_dBytesCountMAvg, bytes, elapsed_ms);
105- m_dTimespanMAvg = avg_iir_w<1000 , double >(m_dTimespanMAvg, timespan_ms, elapsed_ms);
106- }
107-
108- int round_val (double val)
109- {
110- return static_cast <int >(round (val));
111- }
112-
113- CRateEstimator::CRateEstimator ()
114- : m_iInRatePktsCount(0 )
115- , m_iInRateBytesCount(0 )
116- , m_InRatePeriod(INPUTRATE_FAST_START_US) // 0.5 sec (fast start)
117- , m_iInRateBps(INPUTRATE_INITIAL_BYTESPS)
118- {}
119-
120- void CRateEstimator::setInputRateSmpPeriod (int period)
121- {
122- m_InRatePeriod = (uint64_t )period; // (usec) 0=no input rate calculation
123- }
124-
125- void CRateEstimator::updateInputRate (const time_point& time, int pkts, int bytes)
126- {
127- // no input rate calculation
128- if (m_InRatePeriod == 0 )
129- return ;
130-
131- if (is_zero (m_tsInRateStartTime))
132- {
133- m_tsInRateStartTime = time;
134- return ;
135- }
136- else if (time < m_tsInRateStartTime)
137- {
138- // Old packets are being submitted for estimation, e.g. during the backup link activation.
139- return ;
140- }
141-
142- m_iInRatePktsCount += pkts;
143- m_iInRateBytesCount += bytes;
144-
145- // Trigger early update in fast start mode
146- const bool early_update = (m_InRatePeriod < INPUTRATE_RUNNING_US) && (m_iInRatePktsCount > INPUTRATE_MAX_PACKETS);
147-
148- const uint64_t period_us = count_microseconds (time - m_tsInRateStartTime);
149- if (early_update || period_us > m_InRatePeriod)
150- {
151- // Required Byte/sec rate (payload + headers)
152- m_iInRateBytesCount += (m_iInRatePktsCount * CPacket::SRT_DATA_HDR_SIZE);
153- m_iInRateBps = (int )(((int64_t )m_iInRateBytesCount * 1000000 ) / period_us);
154- HLOGC (bslog.Debug ,
155- log << " updateInputRate: pkts:" << m_iInRateBytesCount << " bytes:" << m_iInRatePktsCount
156- << " rate=" << (m_iInRateBps * 8 ) / 1000 << " kbps interval=" << period_us);
157- m_iInRatePktsCount = 0 ;
158- m_iInRateBytesCount = 0 ;
159- m_tsInRateStartTime = time;
160-
161- setInputRateSmpPeriod (INPUTRATE_RUNNING_US);
162- }
163- }
164-
16567CSndBuffer::CSndBuffer (int size, int maxpld, int authtag)
16668 : m_BufLock()
16769 , m_pBlock(NULL )
@@ -654,6 +556,13 @@ int CSndBuffer::getCurrBufSize() const
654556 return m_iCount;
655557}
656558
559+ namespace {
560+ int round_val (double val)
561+ {
562+ return static_cast <int >(round (val));
563+ }
564+ }
565+
657566int CSndBuffer::getAvgBufSize (int & w_bytes, int & w_tsp)
658567{
659568 ScopedLock bufferguard (m_BufLock); /* Consistency of pkts vs. bytes vs. spantime */
0 commit comments