@@ -110,6 +110,53 @@ int round_val(double val)
110
110
return static_cast<int>(round(val));
111
111
}
112
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
+
137
+
m_iInRatePktsCount += pkts;
138
+
m_iInRateBytesCount += bytes;
139
+
140
+
// Trigger early update in fast start mode
141
+
const bool early_update = (m_InRatePeriod < INPUTRATE_RUNNING_US) && (m_iInRatePktsCount > INPUTRATE_MAX_PACKETS);
142
+
143
+
const uint64_t period_us = count_microseconds(time - m_tsInRateStartTime);
144
+
if (early_update || period_us > m_InRatePeriod)
145
+
{
146
+
// Required Byte/sec rate (payload + headers)
147
+
m_iInRateBytesCount += (m_iInRatePktsCount * CPacket::SRT_DATA_HDR_SIZE);
148
+
m_iInRateBps = (int)(((int64_t)m_iInRateBytesCount * 1000000) / period_us);
149
+
HLOGC(bslog.Debug,
150
+
log << "updateInputRate: pkts:" << m_iInRateBytesCount << " bytes:" << m_iInRatePktsCount
151
+
<< " rate=" << (m_iInRateBps * 8) / 1000 << "kbps interval=" << period_us);
152
+
m_iInRatePktsCount = 0;
153
+
m_iInRateBytesCount = 0;
154
+
m_tsInRateStartTime = time;
155
+
156
+
setInputRateSmpPeriod(INPUTRATE_RUNNING_US);
157
+
}
158
+
}
159
+
113
160
CSndBuffer::CSndBuffer(int size, int mss)
114
161
: m_BufLock()
115
162
, m_pBlock(NULL)
@@ -122,10 +169,6 @@ CSndBuffer::CSndBuffer(int size, int mss)
122
169
, m_iMSS(mss)
123
170
, m_iCount(0)
124
171
, m_iBytesCount(0)
125
-
, m_iInRatePktsCount(0)
126
-
, m_iInRateBytesCount(0)
127
-
, m_InRatePeriod(INPUTRATE_FAST_START_US) // 0.5 sec (fast start)
128
-
, m_iInRateBps(INPUTRATE_INITIAL_BYTESPS)
129
172
{
130
173
// initial physical buffer of "size"
131
174
m_pBuffer = new Buffer;
@@ -273,7 +316,7 @@ void CSndBuffer::addBuffer(const char* data, int len, SRT_MSGCTRL& w_mctrl)
273
316
m_iCount += size;
274
317
m_iBytesCount += len;
275
318
276
-
updateInputRate(m_tsLastOriginTime, size, len);
319
+
m_rateEstimator.updateInputRate(m_tsLastOriginTime, size, len);
277
320
updAvgBufSize(m_tsLastOriginTime);
278
321
279
322
// MSGNO_SEQ::mask has a form: 00000011111111...
@@ -287,46 +330,6 @@ void CSndBuffer::addBuffer(const char* data, int len, SRT_MSGCTRL& w_mctrl)
287
330
m_iNextMsgNo = nextmsgno;
288
331
}
289
332
290
-
void CSndBuffer::setInputRateSmpPeriod(int period)
291
-
{
292
-
m_InRatePeriod = (uint64_t)period; //(usec) 0=no input rate calculation
293
-
}
294
-
295
-
void CSndBuffer::updateInputRate(const steady_clock::time_point& time, int pkts, int bytes)
296
-
{
297
-
// no input rate calculation
298
-
if (m_InRatePeriod == 0)
299
-
return;
300
-
301
-
if (is_zero(m_tsInRateStartTime))
302
-
{
303
-
m_tsInRateStartTime = time;
304
-
return;
305
-
}
306
-
307
-
m_iInRatePktsCount += pkts;
308
-
m_iInRateBytesCount += bytes;
309
-
310
-
// Trigger early update in fast start mode
311
-
const bool early_update = (m_InRatePeriod < INPUTRATE_RUNNING_US) && (m_iInRatePktsCount > INPUTRATE_MAX_PACKETS);
312
-
313
-
const uint64_t period_us = count_microseconds(time - m_tsInRateStartTime);
314
-
if (early_update || period_us > m_InRatePeriod)
315
-
{
316
-
// Required Byte/sec rate (payload + headers)
317
-
m_iInRateBytesCount += (m_iInRatePktsCount * CPacket::SRT_DATA_HDR_SIZE);
318
-
m_iInRateBps = (int)(((int64_t)m_iInRateBytesCount * 1000000) / period_us);
319
-
HLOGC(bslog.Debug,
320
-
log << "updateInputRate: pkts:" << m_iInRateBytesCount << " bytes:" << m_iInRatePktsCount
321
-
<< " rate=" << (m_iInRateBps * 8) / 1000 << "kbps interval=" << period_us);
322
-
m_iInRatePktsCount = 0;
323
-
m_iInRateBytesCount = 0;
324
-
m_tsInRateStartTime = time;
325
-
326
-
setInputRateSmpPeriod(INPUTRATE_RUNNING_US);
327
-
}
328
-
}
329
-
330
333
int CSndBuffer::addBufferFromFile(fstream& ifs, int len)
331
334
{
332
335
int size = len / m_iMSS;
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4