Skip to content

Commit

Permalink
[core] Fixed MAVG msRcvBuf and msSndBuf (#1289)
Browse files Browse the repository at this point in the history
Co-authored-by: Maria Sharabayko <msharabayko@haivision.com>
  • Loading branch information
maxsharabayko and mbakholdina authored May 27, 2020
1 parent e7adb3f commit 3979f83
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
32 changes: 21 additions & 11 deletions srtcore/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1591,20 +1591,30 @@ void CRcvBuffer::updRcvAvgDataSize(const steady_clock::time_point& now)
}
else if (elapsed_ms >= (SRT_MAVG_BASE_PERIOD / SRT_MAVG_SAMPLING_RATE) / SRT_us2ms)
{
/*
* Weight last average value between -1 sec and last sampling time (LST)
* and new value between last sampling time and now
* |elapsed|
* +----------------------------------+-------+
* -1 LST 0(now)
*/
int instspan;
int bytescount;
int count = getRcvDataSize(bytescount, instspan);
const int count = getRcvDataSize(bytescount, instspan);

m_iCountMAvg = (int)(((count * (1000 - elapsed_ms)) + (count * elapsed_ms)) / 1000);
m_iBytesCountMAvg = (int)(((bytescount * (1000 - elapsed_ms)) + (bytescount * elapsed_ms)) / 1000);
m_TimespanMAvg = (int)(((instspan * (1000 - elapsed_ms)) + (instspan * elapsed_ms)) / 1000);
if (m_iCountMAvg == 0)
{
// This is the first call, so just take the new value
m_iCountMAvg = count;
m_iBytesCountMAvg = bytescount;
m_TimespanMAvg = instspan;
}
else
{
/*
* Weight last average value between -1 sec from now and last sampling time (LST)
* and new value between last sampling time and now
* |elapsed|
* +----------------------------------+-------+
* -1 sec LST 0(now)
*/
m_iCountMAvg = avg_iir_w<1000>(m_iCountMAvg, count, elapsed_ms);
m_iBytesCountMAvg = avg_iir_w<1000>(m_iBytesCountMAvg, bytescount, elapsed_ms);
m_TimespanMAvg = avg_iir_w<1000>(m_TimespanMAvg, instspan, elapsed_ms);
}
m_tsLastSamplingTime = now;

HLOGC(dlog.Debug, log << "getRcvDataSize: " << count << " " << bytescount << " " << instspan
Expand Down
6 changes: 6 additions & 0 deletions srtcore/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,12 @@ inline ValueType avg_iir(ValueType old_value, ValueType new_value)
return (old_value * (DEPRLEN - 1) + new_value) / DEPRLEN;
}

template <size_t DEPRLEN, typename ValueType>
inline ValueType avg_iir_w(ValueType old_value, ValueType new_value, size_t new_val_weight)
{
return (old_value * (DEPRLEN - new_val_weight) + new_value * new_val_weight) / DEPRLEN;
}

// Property accessor definitions
//
// "Property" is a special method that accesses given field.
Expand Down

0 comments on commit 3979f83

Please sign in to comment.