From c9516a5791c1fc0ff92a311a68990f43f05ff177 Mon Sep 17 00:00:00 2001 From: Maxim Sharabayko Date: Wed, 14 Aug 2024 14:53:54 +0200 Subject: [PATCH] [core] Include packet header in rexmit BW calculation. --- srtcore/buffer_tools.cpp | 5 +++-- srtcore/buffer_tools.h | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/srtcore/buffer_tools.cpp b/srtcore/buffer_tools.cpp index 3f7a77be6..7473e3824 100644 --- a/srtcore/buffer_tools.cpp +++ b/srtcore/buffer_tools.cpp @@ -234,7 +234,7 @@ void CSndRateEstimator::addSample(const time_point& ts, int pkts, size_t bytes) } else { - m_iRateBps = sum.m_iBytesCount * 1000 / (iNumPeriods * SAMPLE_DURATION_MS); + m_iRateBps = (sum.m_iBytesCount + CPacket::HDR_SIZE * sum.m_iPktsCount) * 1000 / (iNumPeriods * SAMPLE_DURATION_MS); } HLOGC(bslog.Note, @@ -260,7 +260,8 @@ void CSndRateEstimator::addSample(const time_point& ts, int pkts, size_t bytes) int CSndRateEstimator::getCurrentRate() const { SRT_ASSERT(m_iCurSampleIdx >= 0 && m_iCurSampleIdx < NUM_PERIODS); - return (int) avg_iir<16, unsigned long long>(m_iRateBps, m_Samples[m_iCurSampleIdx].m_iBytesCount * 1000 / SAMPLE_DURATION_MS); + const Sample& s = m_Samples[m_iCurSampleIdx]; + return (int) avg_iir<16, unsigned long long>(m_iRateBps, (CPacket::HDR_SIZE * s.m_iPktsCount + s.m_iBytesCount) * 1000 / SAMPLE_DURATION_MS); } int CSndRateEstimator::incSampleIdx(int val, int inc) const diff --git a/srtcore/buffer_tools.h b/srtcore/buffer_tools.h index aacbd8310..88479827d 100644 --- a/srtcore/buffer_tools.h +++ b/srtcore/buffer_tools.h @@ -141,10 +141,11 @@ class CSndRateEstimator /// @param [in] bytes number of payload bytes in the sample. void addSample(const time_point& time, int pkts = 0, size_t bytes = 0); - /// Retrieve estimated bitrate in bytes per second + /// Retrieve estimated bitrate in bytes per second with 16-byte packet header. int getRate() const { return m_iRateBps; } - /// Retrieve estimated bitrate in bytes per second inluding the current sampling interval. + /// Retrieve estimated bitrate in bytes per second (with 16-byte packet header) + /// including the current sampling interval. int getCurrentRate() const; private: @@ -191,10 +192,10 @@ class CSndRateEstimator Sample m_Samples[NUM_PERIODS]; - time_point m_tsFirstSampleTime; //< Start time of the first sameple. + time_point m_tsFirstSampleTime; //< Start time of the first sample. int m_iFirstSampleIdx; //< Index of the first sample. int m_iCurSampleIdx; //< Index of the current sample being collected. - int m_iRateBps; // Input Rate in Bytes/sec + int m_iRateBps; //< Rate in Bytes/sec. }; } // namespace srt