Skip to content

Commit

Permalink
[core] Include packet header in rexmit BW calculation.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Aug 15, 2024
1 parent bd071e1 commit 49cab20
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions srtcore/buffer_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions srtcore/buffer_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 49cab20

Please sign in to comment.