Unverified 提交 5d31b535 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo 提交者: GitHub

Fix jitter calculation in RtpStreamRecv (#1117)

上级 dfbd6184
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
### Next ### Next
* `Worker`: Add `Transport::Destroying()` protected method ([PR #1114](https://github.com/versatica/mediasoup/pull/1114)). * `Worker`: Add `Transport::Destroying()` protected method ([PR #1114](https://github.com/versatica/mediasoup/pull/1114)).
* `RtpStreamRecv`: Fix jitter calculation ([PR #1117](https://github.com/versatica/mediasoup/pull/1117), thanks to @penguinol).
### 3.12.5 ### 3.12.5
......
...@@ -102,9 +102,9 @@ namespace RTC ...@@ -102,9 +102,9 @@ namespace RTC
{ {
return uint32_t{ ntohl(this->header->jitter) }; return uint32_t{ ntohl(this->header->jitter) };
} }
void SetJitter(uint32_t jitter) void SetJitter(float jitter)
{ {
this->header->jitter = uint32_t{ htonl(jitter) }; this->header->jitter = uint32_t{ htonl(static_cast<uint32_t>(jitter)) };
} }
uint32_t GetLastSenderReport() const uint32_t GetLastSenderReport() const
{ {
......
...@@ -114,8 +114,9 @@ namespace RTC ...@@ -114,8 +114,9 @@ namespace RTC
uint64_t lastSrReceived{ 0u }; uint64_t lastSrReceived{ 0u };
// Relative transit time for prev packet. // Relative transit time for prev packet.
int32_t transit{ 0u }; int32_t transit{ 0u };
// Jitter in ms. // Jitter in RTP timestamp units. As per spec it's kept as floating value
uint32_t jitter{ 0u }; // although it's exposed as integer in the stats.
float jitter{ 0 };
uint8_t firSeqNumber{ 0u }; uint8_t firSeqNumber{ 0u };
uint32_t reportedPacketLost{ 0u }; uint32_t reportedPacketLost{ 0u };
std::unique_ptr<RTC::NackGenerator> nackGenerator; std::unique_ptr<RTC::NackGenerator> nackGenerator;
......
...@@ -236,7 +236,7 @@ namespace RTC ...@@ -236,7 +236,7 @@ namespace RTC
RTC::RtpStream::FillJsonStats(jsonObject); RTC::RtpStream::FillJsonStats(jsonObject);
jsonObject["type"] = "inbound-rtp"; jsonObject["type"] = "inbound-rtp";
jsonObject["jitter"] = this->jitter; jsonObject["jitter"] = static_cast<uint32_t>(this->jitter);
jsonObject["packetCount"] = this->transmissionCounter.GetPacketCount(); jsonObject["packetCount"] = this->transmissionCounter.GetPacketCount();
jsonObject["byteCount"] = this->transmissionCounter.GetBytes(); jsonObject["byteCount"] = this->transmissionCounter.GetBytes();
jsonObject["bitrate"] = this->transmissionCounter.GetBitrate(nowMs); jsonObject["bitrate"] = this->transmissionCounter.GetBitrate(nowMs);
...@@ -692,15 +692,14 @@ namespace RTC ...@@ -692,15 +692,14 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
if (this->params.clockRate == 0u) if (GetClockRate() == 0u)
{ {
return; return;
} }
// NOTE: Based on https://github.com/versatica/mediasoup/issues/1018. // NOTE: Based on https://github.com/versatica/mediasoup/issues/1018.
auto transit = static_cast<int>( auto transit = static_cast<int>((DepLibUV::GetTimeMs() * GetClockRate() / 1000) - rtpTimestamp);
DepLibUV::GetTimeMs() - (static_cast<uint64_t>(rtpTimestamp) * 1000 / this->params.clockRate)); int d = transit - this->transit;
int d = transit - this->transit;
// First transit calculation, save and return. // First transit calculation, save and return.
if (this->transit == 0) if (this->transit == 0)
...@@ -717,7 +716,7 @@ namespace RTC ...@@ -717,7 +716,7 @@ namespace RTC
d = -d; d = -d;
} }
this->jitter += (1. / 16.) * (static_cast<double>(d) - this->jitter); this->jitter += (1. / 16.) * (static_cast<float>(d) - this->jitter);
} }
void RtpStreamRecv::UpdateScore() void RtpStreamRecv::UpdateScore()
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论