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

TCC client optimizations for faster and more stable bwe (#712)

* TCC client optimizations for faster and more stable bwe

* Fix style comments

* Address comments with provided patch
上级 3d313f0f
...@@ -84,6 +84,9 @@ namespace RTC ...@@ -84,6 +84,9 @@ namespace RTC
void MayEmitAvailableBitrateEvent(uint32_t previousAvailableBitrate); void MayEmitAvailableBitrateEvent(uint32_t previousAvailableBitrate);
void UpdatePacketLoss(double packetLoss); void UpdatePacketLoss(double packetLoss);
void InitializeController();
void DestroyController();
// jmillan: missing. // jmillan: missing.
// void OnRemoteNetworkEstimate(NetworkStateEstimate estimate) override; // void OnRemoteNetworkEstimate(NetworkStateEstimate estimate) override;
......
...@@ -13,9 +13,10 @@ namespace RTC ...@@ -13,9 +13,10 @@ namespace RTC
/* Static. */ /* Static. */
static constexpr uint32_t MinBitrate{ 30000u }; static constexpr uint32_t MinBitrate{ 30000u };
static constexpr float MaxBitrateMarginFactor{ 0.1f };
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{ 1000u }; // In ms.
static constexpr size_t PacketLossHistogramLength{ 24 }; static constexpr size_t PacketLossHistogramLength{ 24 };
/* Instance methods. */ /* Instance methods. */
...@@ -37,9 +38,23 @@ namespace RTC ...@@ -37,9 +38,23 @@ namespace RTC
config.feedback_only = false; config.feedback_only = false;
this->controllerFactory = new webrtc::GoogCcNetworkControllerFactory(std::move(config)); this->controllerFactory = new webrtc::GoogCcNetworkControllerFactory(std::move(config));
}
webrtc::BitrateConstraints bitrateConfig; TransportCongestionControlClient::~TransportCongestionControlClient()
{
MS_TRACE();
delete this->controllerFactory;
this->controllerFactory = nullptr;
DestroyController();
}
void TransportCongestionControlClient::InitializeController()
{
MS_ASSERT(this->rtpTransportControllerSend == nullptr, "transport controller already initialized");
webrtc::BitrateConstraints bitrateConfig;
bitrateConfig.start_bitrate_bps = static_cast<int>(this->initialAvailableBitrate); bitrateConfig.start_bitrate_bps = static_cast<int>(this->initialAvailableBitrate);
this->rtpTransportControllerSend = this->rtpTransportControllerSend =
...@@ -49,12 +64,13 @@ namespace RTC ...@@ -49,12 +64,13 @@ namespace RTC
this->probationGenerator = new RTC::RtpProbationGenerator(); this->probationGenerator = new RTC::RtpProbationGenerator();
this->processTimer = new Timer(this); // This makes sure that periodic probing is used when the application is send
// less bitrate than needed to measure the bandwidth estimation. (f.e. when
// NOTE: This is supposed to recover computed available bandwidth after // videos are muted or using screensharing with still images)
// network issues.
this->rtpTransportControllerSend->EnablePeriodicAlrProbing(true); this->rtpTransportControllerSend->EnablePeriodicAlrProbing(true);
this->processTimer = new Timer(this);
// clang-format off // clang-format off
this->processTimer->Start(std::min( this->processTimer->Start(std::min(
// Depends on probation being done and WebRTC-Pacer-MinPacketLimitMs field trial. // Depends on probation being done and WebRTC-Pacer-MinPacketLimitMs field trial.
...@@ -65,13 +81,8 @@ namespace RTC ...@@ -65,13 +81,8 @@ namespace RTC
// clang-format on // clang-format on
} }
TransportCongestionControlClient::~TransportCongestionControlClient() void TransportCongestionControlClient::DestroyController()
{ {
MS_TRACE();
delete this->controllerFactory;
this->controllerFactory = nullptr;
delete this->rtpTransportControllerSend; delete this->rtpTransportControllerSend;
this->rtpTransportControllerSend = nullptr; this->rtpTransportControllerSend = nullptr;
...@@ -86,6 +97,11 @@ namespace RTC ...@@ -86,6 +97,11 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
if (this->rtpTransportControllerSend == nullptr)
{
InitializeController();
}
this->rtpTransportControllerSend->OnNetworkAvailability(true); this->rtpTransportControllerSend->OnNetworkAvailability(true);
} }
...@@ -106,6 +122,11 @@ namespace RTC ...@@ -106,6 +122,11 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
if (this->rtpTransportControllerSend == nullptr)
{
return;
}
this->rtpTransportControllerSend->packet_sender()->InsertPacket(packetInfo.length); this->rtpTransportControllerSend->packet_sender()->InsertPacket(packetInfo.length);
this->rtpTransportControllerSend->OnAddPacket(packetInfo); this->rtpTransportControllerSend->OnAddPacket(packetInfo);
} }
...@@ -114,6 +135,11 @@ namespace RTC ...@@ -114,6 +135,11 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
if (this->rtpTransportControllerSend == nullptr)
{
return {};
}
return this->rtpTransportControllerSend->packet_sender()->GetPacingInfo(); return this->rtpTransportControllerSend->packet_sender()->GetPacingInfo();
} }
...@@ -121,6 +147,11 @@ namespace RTC ...@@ -121,6 +147,11 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
if (this->rtpTransportControllerSend == nullptr)
{
return;
}
// Notify the transport feedback adapter about the sent packet. // Notify the transport feedback adapter about the sent packet.
rtc::SentPacket sentPacket(packetInfo.transport_sequence_number, nowMs); rtc::SentPacket sentPacket(packetInfo.transport_sequence_number, nowMs);
this->rtpTransportControllerSend->OnSentPacket(sentPacket, packetInfo.length); this->rtpTransportControllerSend->OnSentPacket(sentPacket, packetInfo.length);
...@@ -130,6 +161,11 @@ namespace RTC ...@@ -130,6 +161,11 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
if (this->rtpTransportControllerSend == nullptr)
{
return;
}
this->rtpTransportControllerSend->OnReceivedEstimatedBitrate(bitrate); this->rtpTransportControllerSend->OnReceivedEstimatedBitrate(bitrate);
} }
...@@ -155,6 +191,11 @@ namespace RTC ...@@ -155,6 +191,11 @@ namespace RTC
report->GetDelaySinceLastSenderReport()); report->GetDelaySinceLastSenderReport());
} }
if (this->rtpTransportControllerSend == nullptr)
{
return;
}
this->rtpTransportControllerSend->OnReceivedRtcpReceiverReport( this->rtpTransportControllerSend->OnReceivedRtcpReceiverReport(
reportBlockList, static_cast<int64_t>(rtt), nowMs); reportBlockList, static_cast<int64_t>(rtt), nowMs);
} }
...@@ -174,6 +215,11 @@ namespace RTC ...@@ -174,6 +215,11 @@ namespace RTC
} }
this->UpdatePacketLoss(static_cast<double>(lost_packets) / expected_packets); this->UpdatePacketLoss(static_cast<double>(lost_packets) / expected_packets);
if (this->rtpTransportControllerSend == nullptr)
{
return;
}
this->rtpTransportControllerSend->OnTransportFeedback(*feedback); this->rtpTransportControllerSend->OnTransportFeedback(*feedback);
} }
...@@ -244,35 +290,55 @@ namespace RTC ...@@ -244,35 +290,55 @@ namespace RTC
// more stable values. // more stable values.
this->bitrates.startBitrate = std::max<uint32_t>(MinBitrate, this->bitrates.availableBitrate); this->bitrates.startBitrate = std::max<uint32_t>(MinBitrate, this->bitrates.availableBitrate);
auto currentMaxBitrate = this->bitrates.maxBitrate;
uint32_t newMaxBitrate = 0;
if (this->desiredBitrateTrend.GetValue() > 0u) if (this->desiredBitrateTrend.GetValue() > 0u)
{ {
this->bitrates.maxBitrate = std::max<uint32_t>( newMaxBitrate = std::max<uint32_t>(
this->initialAvailableBitrate, this->initialAvailableBitrate,
this->desiredBitrateTrend.GetValue() * MaxBitrateIncrementFactor); this->desiredBitrateTrend.GetValue() * MaxBitrateIncrementFactor);
if (this->maxOutgoingBitrate > 0u) // If max bitrate requested didn't change by more than a small % keep the previous settings
// to avoid constant small fluctuations requiring extra probing and making the estimation
// less stable (requires constant redistribution of bitrate accross consumers).
auto maxBitrateMargin = newMaxBitrate * MaxBitrateMarginFactor;
if (currentMaxBitrate > newMaxBitrate - maxBitrateMargin && currentMaxBitrate < newMaxBitrate + maxBitrateMargin)
{ {
this->bitrates.maxBitrate = newMaxBitrate = currentMaxBitrate;
std::min<uint32_t>(this->maxOutgoingBitrate, this->bitrates.maxBitrate);
} }
this->bitrates.maxPaddingBitrate = this->bitrates.maxBitrate * MaxPaddingBitrateFactor;
} }
else else
{ {
this->bitrates.maxBitrate = this->initialAvailableBitrate; newMaxBitrate = this->initialAvailableBitrate;
this->bitrates.maxPaddingBitrate = 0u; }
if (this->maxOutgoingBitrate > 0u)
{
newMaxBitrate = std::min<uint32_t>(this->maxOutgoingBitrate, newMaxBitrate);
}
if (newMaxBitrate != currentMaxBitrate)
{
this->bitrates.maxPaddingBitrate = newMaxBitrate * MaxPaddingBitrateFactor;
this->bitrates.maxBitrate = newMaxBitrate;
} }
MS_DEBUG_DEV( MS_DEBUG_DEV(
"[desiredBitrate:%" PRIu32 ", startBitrate:%" PRIu32 ", minBitrate:%" PRIu32 "[desiredBitrate:%" PRIu32 ", desiredBitrateTrend:%" PRIu32 ", startBitrate:%" PRIu32
", maxBitrate:%" PRIu32 ", maxPaddingBitrate:%" PRIu32 "]", ", minBitrate:%" PRIu32 ", maxBitrate:%" PRIu32 ", maxPaddingBitrate:%" PRIu32 "]",
this->bitrates.desiredBitrate, this->bitrates.desiredBitrate,
this->desiredBitrateTrend.GetValue(),
this->bitrates.startBitrate, this->bitrates.startBitrate,
this->bitrates.minBitrate, this->bitrates.minBitrate,
this->bitrates.maxBitrate, this->bitrates.maxBitrate,
this->bitrates.maxPaddingBitrate); this->bitrates.maxPaddingBitrate);
if (this->rtpTransportControllerSend == nullptr)
{
return;
}
this->rtpTransportControllerSend->SetAllocatedSendBitrateLimits( this->rtpTransportControllerSend->SetAllocatedSendBitrateLimits(
this->bitrates.minBitrate, this->bitrates.maxPaddingBitrate, this->bitrates.maxBitrate); this->bitrates.minBitrate, this->bitrates.maxPaddingBitrate, this->bitrates.maxBitrate);
...@@ -417,6 +483,7 @@ namespace RTC ...@@ -417,6 +483,7 @@ namespace RTC
RTC::RtpPacket* TransportCongestionControlClient::GeneratePadding(size_t size) RTC::RtpPacket* TransportCongestionControlClient::GeneratePadding(size_t size)
{ {
MS_TRACE(); MS_TRACE();
MS_ASSERT(this->probationGenerator, "probation generator not initialized")
return this->probationGenerator->GetNextPacket(size); return this->probationGenerator->GetNextPacket(size);
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论