Unverified 提交 d4392bd0 authored 作者: Gustavo Garcia's avatar Gustavo Garcia 提交者: GitHub

Add packetLoss stats to transport (#648)

上级 304956c2
...@@ -105,6 +105,10 @@ pub struct DirectTransportStat { ...@@ -105,6 +105,10 @@ pub struct DirectTransportStat {
pub available_incoming_bitrate: Option<u32>, pub available_incoming_bitrate: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub max_incoming_bitrate: Option<u32>, pub max_incoming_bitrate: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rtp_packet_loss_received: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rtp_packet_loss_sent: Option<f64>,
} }
#[derive(Default)] #[derive(Default)]
......
...@@ -140,6 +140,10 @@ pub struct PipeTransportStat { ...@@ -140,6 +140,10 @@ pub struct PipeTransportStat {
pub available_incoming_bitrate: Option<u32>, pub available_incoming_bitrate: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub max_incoming_bitrate: Option<u32>, pub max_incoming_bitrate: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rtp_packet_loss_received: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rtp_packet_loss_sent: Option<f64>,
// PipeTransport specific. // PipeTransport specific.
pub tuple: Option<TransportTuple>, pub tuple: Option<TransportTuple>,
} }
......
...@@ -158,6 +158,10 @@ pub struct PlainTransportStat { ...@@ -158,6 +158,10 @@ pub struct PlainTransportStat {
pub available_incoming_bitrate: Option<u32>, pub available_incoming_bitrate: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub max_incoming_bitrate: Option<u32>, pub max_incoming_bitrate: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rtp_packet_loss_received: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rtp_packet_loss_sent: Option<f64>,
// PlainTransport specific. // PlainTransport specific.
pub rtcp_mux: bool, pub rtcp_mux: bool,
pub comedia: bool, pub comedia: bool,
......
...@@ -209,6 +209,10 @@ pub struct WebRtcTransportStat { ...@@ -209,6 +209,10 @@ pub struct WebRtcTransportStat {
pub available_incoming_bitrate: Option<u32>, pub available_incoming_bitrate: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub max_incoming_bitrate: Option<u32>, pub max_incoming_bitrate: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rtp_packet_loss_received: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rtp_packet_loss_sent: Option<f64>,
// WebRtcTransport specific. // WebRtcTransport specific.
pub ice_role: IceRole, pub ice_role: IceRole,
pub ice_state: IceState, pub ice_state: IceState,
......
...@@ -150,6 +150,8 @@ fn get_stats_succeeds() { ...@@ -150,6 +150,8 @@ fn get_stats_succeeds() {
assert_eq!(stats[0].rtx_send_bitrate, 0); assert_eq!(stats[0].rtx_send_bitrate, 0);
assert_eq!(stats[0].probation_bytes_sent, 0); assert_eq!(stats[0].probation_bytes_sent, 0);
assert_eq!(stats[0].probation_send_bitrate, 0); assert_eq!(stats[0].probation_send_bitrate, 0);
assert_eq!(stats[0].rtp_packet_loss_received, None);
assert_eq!(stats[0].rtp_packet_loss_sent, None);
}); });
} }
......
...@@ -411,6 +411,8 @@ fn get_stats_succeeds() { ...@@ -411,6 +411,8 @@ fn get_stats_succeeds() {
assert_eq!(stats[0].rtx_send_bitrate, 0); assert_eq!(stats[0].rtx_send_bitrate, 0);
assert_eq!(stats[0].probation_bytes_sent, 0); assert_eq!(stats[0].probation_bytes_sent, 0);
assert_eq!(stats[0].probation_send_bitrate, 0); assert_eq!(stats[0].probation_send_bitrate, 0);
assert_eq!(stats[0].rtp_packet_loss_received, None);
assert_eq!(stats[0].rtp_packet_loss_sent, None);
assert!(matches!( assert!(matches!(
stats[0].tuple, stats[0].tuple,
Some(TransportTuple::LocalOnly { .. }), Some(TransportTuple::LocalOnly { .. }),
......
...@@ -360,6 +360,8 @@ fn get_stats_succeeds() { ...@@ -360,6 +360,8 @@ fn get_stats_succeeds() {
assert_eq!(stats[0].probation_send_bitrate, 0); assert_eq!(stats[0].probation_send_bitrate, 0);
assert_eq!(stats[0].ice_selected_tuple, None); assert_eq!(stats[0].ice_selected_tuple, None);
assert_eq!(stats[0].max_incoming_bitrate, None); assert_eq!(stats[0].max_incoming_bitrate, None);
assert_eq!(stats[0].rtp_packet_loss_received, None);
assert_eq!(stats[0].rtp_packet_loss_sent, None);
}); });
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <libwebrtc/api/transport/network_types.h> #include <libwebrtc/api/transport/network_types.h>
#include <libwebrtc/call/rtp_transport_controller_send.h> #include <libwebrtc/call/rtp_transport_controller_send.h>
#include <libwebrtc/modules/pacing/packet_router.h> #include <libwebrtc/modules/pacing/packet_router.h>
#include <deque>
namespace RTC namespace RTC
{ {
...@@ -76,10 +77,12 @@ namespace RTC ...@@ -76,10 +77,12 @@ namespace RTC
return this->bitrates; return this->bitrates;
} }
uint32_t GetAvailableBitrate() const; uint32_t GetAvailableBitrate() const;
double GetPacketLoss() const;
void RescheduleNextAvailableBitrateEvent(); void RescheduleNextAvailableBitrateEvent();
private: private:
void MayEmitAvailableBitrateEvent(uint32_t previousAvailableBitrate); void MayEmitAvailableBitrateEvent(uint32_t previousAvailableBitrate);
void UpdatePacketLoss(double packetLoss);
// jmillan: missing. // jmillan: missing.
// void OnRemoteNetworkEstimate(NetworkStateEstimate estimate) override; // void OnRemoteNetworkEstimate(NetworkStateEstimate estimate) override;
...@@ -113,6 +116,8 @@ namespace RTC ...@@ -113,6 +116,8 @@ namespace RTC
bool availableBitrateEventCalled{ false }; bool availableBitrateEventCalled{ false };
uint64_t lastAvailableBitrateEventAtMs{ 0u }; uint64_t lastAvailableBitrateEventAtMs{ 0u };
RTC::TrendCalculator desiredBitrateTrend; RTC::TrendCalculator desiredBitrateTrend;
std::deque<double> packetLossHistory;
double packetLoss{ 0 };
}; };
} // namespace RTC } // namespace RTC
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "RTC/RtpPacket.hpp" #include "RTC/RtpPacket.hpp"
#include "handles/Timer.hpp" #include "handles/Timer.hpp"
#include <libwebrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.h> #include <libwebrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.h>
#include <deque>
namespace RTC namespace RTC
{ {
...@@ -50,12 +51,14 @@ namespace RTC ...@@ -50,12 +51,14 @@ namespace RTC
return 0u; return 0u;
} }
} }
double GetPacketLoss() const;
void IncomingPacket(uint64_t nowMs, const RTC::RtpPacket* packet); void IncomingPacket(uint64_t nowMs, const RTC::RtpPacket* packet);
void SetMaxIncomingBitrate(uint32_t bitrate); void SetMaxIncomingBitrate(uint32_t bitrate);
private: private:
void SendTransportCcFeedback(); void SendTransportCcFeedback();
void MaySendLimitationRembFeedback(); void MaySendLimitationRembFeedback();
void UpdatePacketLoss(double packetLoss);
/* Pure virtual methods inherited from webrtc::RemoteBitrateEstimator::Listener. */ /* Pure virtual methods inherited from webrtc::RemoteBitrateEstimator::Listener. */
public: public:
...@@ -84,6 +87,8 @@ namespace RTC ...@@ -84,6 +87,8 @@ namespace RTC
uint32_t maxIncomingBitrate{ 0u }; uint32_t maxIncomingBitrate{ 0u };
uint64_t limitationRembSentAtMs{ 0u }; uint64_t limitationRembSentAtMs{ 0u };
uint8_t unlimitedRembCounter{ 0u }; uint8_t unlimitedRembCounter{ 0u };
std::deque<double> packetLossHistory;
double packetLoss{ 0 };
}; };
} // namespace RTC } // namespace RTC
......
...@@ -552,6 +552,14 @@ namespace RTC ...@@ -552,6 +552,14 @@ namespace RTC
// Add maxIncomingBitrate. // Add maxIncomingBitrate.
if (this->maxIncomingBitrate != 0u) if (this->maxIncomingBitrate != 0u)
jsonObject["maxIncomingBitrate"] = this->maxIncomingBitrate; jsonObject["maxIncomingBitrate"] = this->maxIncomingBitrate;
// Add packetLossReceived.
if (this->tccServer)
jsonObject["rtpPacketLossReceived"] = this->tccServer->GetPacketLoss();
// Add packetLossSent.
if (this->tccClient)
jsonObject["rtpPacketLossSent"] = this->tccClient->GetPacketLoss();
} }
void Transport::HandleRequest(Channel::ChannelRequest* request) void Transport::HandleRequest(Channel::ChannelRequest* request)
......
...@@ -16,6 +16,7 @@ namespace RTC ...@@ -16,6 +16,7 @@ namespace RTC
static constexpr float MaxBitrateIncrementFactor{ 1.35f }; static constexpr float MaxBitrateIncrementFactor{ 1.35f };
static constexpr float MaxPaddingBitrateFactor{ 0.85f }; static constexpr float MaxPaddingBitrateFactor{ 0.85f };
static constexpr uint64_t AvailableBitrateEventInterval{ 2000u }; // In ms. static constexpr uint64_t AvailableBitrateEventInterval{ 2000u }; // In ms.
static constexpr size_t PacketLossHistogramLength{ 24 };
/* Instance methods. */ /* Instance methods. */
...@@ -163,9 +164,56 @@ namespace RTC ...@@ -163,9 +164,56 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
// Update packet loss history.
size_t expected_packets = feedback->GetPacketStatusCount();
size_t lost_packets = 0;
for (const auto& result : feedback->GetPacketResults())
{
if (!result.received)
lost_packets += 1;
}
this->UpdatePacketLoss(static_cast<double>(lost_packets) / expected_packets);
this->rtpTransportControllerSend->OnTransportFeedback(*feedback); this->rtpTransportControllerSend->OnTransportFeedback(*feedback);
} }
void TransportCongestionControlClient::UpdatePacketLoss(double packetLoss)
{
// Add the score into the histogram.
if (this->packetLossHistory.size() == PacketLossHistogramLength)
this->packetLossHistory.pop_front();
this->packetLossHistory.push_back(packetLoss);
/*
* Scoring mechanism is a weighted average.
*
* The more recent the score is, the more weight it has.
* The oldest score has a weight of 1 and subsequent scores weight is
* increased by one sequentially.
*
* Ie:
* - scores: [1,2,3,4]
* - this->scores = ((1) + (2+2) + (3+3+3) + (4+4+4+4)) / 10 = 2.8 => 3
*/
size_t weight{ 0 };
size_t samples{ 0 };
double totalPacketLoss{ 0 };
for (auto packetLossEntry : this->packetLossHistory)
{
weight++;
samples += weight;
totalPacketLoss += weight * packetLossEntry;
}
// clang-tidy "thinks" that this can lead to division by zero but we are
// smarter.
// NOLINTNEXTLINE(clang-analyzer-core.DivideZero)
this->packetLoss = totalPacketLoss / samples;
}
void TransportCongestionControlClient::SetMaxOutgoingBitrate(uint32_t maxBitrate) void TransportCongestionControlClient::SetMaxOutgoingBitrate(uint32_t maxBitrate)
{ {
if (maxBitrate < this->initialAvailableBitrate) if (maxBitrate < this->initialAvailableBitrate)
...@@ -245,6 +293,13 @@ namespace RTC ...@@ -245,6 +293,13 @@ namespace RTC
return this->bitrates.availableBitrate; return this->bitrates.availableBitrate;
} }
double TransportCongestionControlClient::GetPacketLoss() const
{
MS_TRACE();
return this->packetLoss;
}
void TransportCongestionControlClient::RescheduleNextAvailableBitrateEvent() void TransportCongestionControlClient::RescheduleNextAvailableBitrateEvent()
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -15,6 +15,7 @@ namespace RTC ...@@ -15,6 +15,7 @@ namespace RTC
static constexpr uint64_t TransportCcFeedbackSendInterval{ 100u }; // In ms. static constexpr uint64_t TransportCcFeedbackSendInterval{ 100u }; // In ms.
static constexpr uint64_t LimitationRembInterval{ 1500u }; // In ms. static constexpr uint64_t LimitationRembInterval{ 1500u }; // In ms.
static constexpr uint8_t UnlimitedRembNumPackets{ 4u }; static constexpr uint8_t UnlimitedRembNumPackets{ 4u };
static constexpr size_t PacketLossHistogramLength{ 24 };
/* Instance methods. */ /* Instance methods. */
...@@ -101,6 +102,13 @@ namespace RTC ...@@ -101,6 +102,13 @@ namespace RTC
} }
} }
double TransportCongestionControlServer::GetPacketLoss() const
{
MS_TRACE();
return this->packetLoss;
}
void TransportCongestionControlServer::IncomingPacket(uint64_t nowMs, const RTC::RtpPacket* packet) void TransportCongestionControlServer::IncomingPacket(uint64_t nowMs, const RTC::RtpPacket* packet)
{ {
MS_TRACE(); MS_TRACE();
...@@ -119,7 +127,7 @@ namespace RTC ...@@ -119,7 +127,7 @@ namespace RTC
this->transportCcFeedbackMediaSsrc = packet->GetSsrc(); this->transportCcFeedbackMediaSsrc = packet->GetSsrc();
this->transportCcFeedbackPacket->SetSenderSsrc(0u); this->transportCcFeedbackPacket->SetSenderSsrc(0u);
this->transportCcFeedbackPacket->SetMediaSsrc(packet->GetSsrc()); this->transportCcFeedbackPacket->SetMediaSsrc(this->transportCcFeedbackMediaSsrc);
// Provide the feedback packet with the RTP packet info. If it fails, // Provide the feedback packet with the RTP packet info. If it fails,
// send current feedback and add the packet info to a new one. // send current feedback and add the packet info to a new one.
...@@ -223,6 +231,17 @@ namespace RTC ...@@ -223,6 +231,17 @@ namespace RTC
this->listener->OnTransportCongestionControlServerSendRtcpPacket( this->listener->OnTransportCongestionControlServerSendRtcpPacket(
this, this->transportCcFeedbackPacket.get()); this, this->transportCcFeedbackPacket.get());
// Update packet loss history.
size_t expected_packets = this->transportCcFeedbackPacket->GetPacketStatusCount();
size_t lost_packets = 0;
for (const auto& result : this->transportCcFeedbackPacket->GetPacketResults())
{
if (!result.received)
lost_packets += 1;
}
this->UpdatePacketLoss(static_cast<double>(lost_packets) / expected_packets);
// Create a new feedback packet. // Create a new feedback packet.
this->transportCcFeedbackPacket.reset(new RTC::RTCP::FeedbackRtpTransportPacket( this->transportCcFeedbackPacket.reset(new RTC::RTCP::FeedbackRtpTransportPacket(
this->transportCcFeedbackSenderSsrc, this->transportCcFeedbackMediaSsrc)); this->transportCcFeedbackSenderSsrc, this->transportCcFeedbackMediaSsrc));
...@@ -280,6 +299,32 @@ namespace RTC ...@@ -280,6 +299,32 @@ namespace RTC
} }
} }
void TransportCongestionControlServer::UpdatePacketLoss(double packetLoss)
{
// Add the score into the histogram.
if (this->packetLossHistory.size() == PacketLossHistogramLength)
this->packetLossHistory.pop_front();
this->packetLossHistory.push_back(packetLoss);
// Calculate a weighted average
size_t weight{ 0 };
size_t samples{ 0 };
double totalPacketLoss{ 0 };
for (auto packetLossEntry : this->packetLossHistory)
{
weight++;
samples += weight;
totalPacketLoss += weight * packetLossEntry;
}
// clang-tidy "thinks" that this can lead to division by zero but we are
// smarter.
// NOLINTNEXTLINE(clang-analyzer-core.DivideZero)
this->packetLoss = totalPacketLoss / samples;
}
inline void TransportCongestionControlServer::OnRembServerAvailableBitrate( inline void TransportCongestionControlServer::OnRembServerAvailableBitrate(
const webrtc::RemoteBitrateEstimator* /*rembServer*/, const webrtc::RemoteBitrateEstimator* /*rembServer*/,
const std::vector<uint32_t>& ssrcs, const std::vector<uint32_t>& ssrcs,
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论