MCPcopy Create free account
hub / github.com/Haivision/srt / updateInputRate

Method updateInputRate

srtcore/buffer_tools.cpp:118–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116}
117
118void CRateEstimator::updateInputRate(const time_point& time, int pkts, int bytes)
119{
120 // no input rate calculation
121 if (m_InRatePeriod == 0)
122 return;
123
124 if (is_zero(m_tsInRateStartTime))
125 {
126 m_tsInRateStartTime = time;
127 return;
128 }
129 else if (time < m_tsInRateStartTime)
130 {
131 // Old packets are being submitted for estimation, e.g. during the backup link activation.
132 return;
133 }
134
135 m_iInRatePktsCount += pkts;
136 m_iInRateBytesCount += bytes;
137
138 // Trigger early update in fast start mode
139 const bool early_update = (m_InRatePeriod < INPUTRATE_RUNNING_US) && (m_iInRatePktsCount > INPUTRATE_MAX_PACKETS);
140
141 const uint64_t period_us = count_microseconds(time - m_tsInRateStartTime);
142 if (!early_update && period_us <= m_InRatePeriod)
143 return;
144
145 // Required Byte/sec rate (payload + headers)
146 m_iInRateBytesCount += (m_iInRatePktsCount * m_iFullHeaderSize);
147 m_iInRateBps = (int)(((int64_t)m_iInRateBytesCount * 1000000) / period_us);
148 HLOGC(bslog.Debug,
149 log << "updateInputRate: pkts:" << m_iInRateBytesCount << " bytes:" << m_iInRatePktsCount
150 << " rate=" << (m_iInRateBps * 8) / 1000 << "kbps interval=" << period_us);
151 m_iInRatePktsCount = 0;
152 m_iInRateBytesCount = 0;
153 m_tsInRateStartTime = time;
154
155 setInputRateSmpPeriod(INPUTRATE_RUNNING_US);
156}
157
158CSndRateEstimator::CSndRateEstimator(const time_point& tsNow)
159 : m_tsFirstSampleTime(tsNow)

Callers 1

addBufferMethod · 0.80

Calls 2

is_zeroFunction · 0.85
count_microsecondsFunction · 0.85

Tested by

no test coverage detected