提交 694d28c5 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

WIP: RembClient

上级 064a883c
...@@ -32,33 +32,12 @@ namespace RTC ...@@ -32,33 +32,12 @@ namespace RTC
private: private:
Listener* listener; Listener* listener;
RTC::RtpDataCounter transmissionCounter; RTC::RtpDataCounter transmissionCounter;
uint32_t averageBitrate{ 0 }; uint32_t bitrateInUse{ 0 };
uint32_t extraBitrate{ 0 }; uint32_t extraBitrateInUse{ 0 };
uint32_t rembBitrate{ 0 };
uint32_t availableBitrate{ 0 }; uint32_t availableBitrate{ 0 };
uint64_t lastEventAt{ 0 };
}; };
/* Inline methods. */
inline uint32_t RembClient::GetAvailableBitrate() const
{
if (this->availableBitrate >= this->extraBitrate)
return this->availableBitrate - this->extraBitrate;
else
return 0;
}
inline void RembClient::AddExtraBitrate(uint32_t extraBitrate)
{
this->extraBitrate += extraBitrate;
}
inline void RembClient::RemoveExtraBitrate(uint32_t extraBitrate)
{
if (this->extraBitrate >= extraBitrate)
this->extraBitrate -= extraBitrate;
else
this->extraBitrate = 0;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -20,7 +20,7 @@ public: ...@@ -20,7 +20,7 @@ public:
bool srtp{ false }; bool srtp{ false };
bool rtcp{ false }; bool rtcp{ false };
bool rtx{ false }; bool rtx{ false };
bool rbe{ false }; bool bwe{ false };
bool score{ false }; bool score{ false };
bool simulcast{ false }; bool simulcast{ false };
bool svc{ false }; bool svc{ false };
......
#define MS_CLASS "RTC::RembClient" #define MS_CLASS "RTC::RembClient"
// #define MS_LOG_DEV #define MS_LOG_DEV // TODO
#include "RTC/RembClient.hpp" #include "RTC/RembClient.hpp"
#include "DepLibUV.hpp" #include "DepLibUV.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include <limits>
namespace RTC namespace RTC
{ {
/* Static. */
static constexpr uint64_t EventInterval{ 1500 }; // In ms.
static constexpr uint64_t MaxEventInterval{ 3000 }; // In ms.
/* Instance methods. */ /* Instance methods. */
RembClient::RembClient(RTC::RembClient::Listener* listener) : listener(listener) RembClient::RembClient(RTC::RembClient::Listener* listener)
: listener(listener), lastEventAt(DepLibUV::GetTime())
{ {
MS_TRACE(); MS_TRACE();
} }
...@@ -30,21 +37,106 @@ namespace RTC ...@@ -30,21 +37,106 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
// Update available bitrate. // Check if we should fire the event.
this->availableBitrate = static_cast<uint32_t>(remb->GetBitrate()); uint64_t now = DepLibUV::GetTime();
if (now - this->lastEventAt >= MaxEventInterval)
{
MS_DEBUG_TAG(bwe, "ignoring first REMB after inactivity");
// Update last event time.
this->lastEventAt = now;
return;
}
else if (now - this->lastEventAt < EventInterval)
{
return;
}
uint32_t newRembBitrate = static_cast<uint32_t>(remb->GetBitrate());
auto rembTrend = static_cast<int64_t>(newRembBitrate) - static_cast<int64_t>(this->rembBitrate);
// TODO: Testing. // Update REMB bitrate.
this->rembBitrate = newRembBitrate;
// Update bitrate in use.
this->bitrateInUse = this->transmissionCounter.GetRate(now);
// Update last event time.
this->lastEventAt = now;
if (this->rembBitrate >= this->bitrateInUse)
{
uint32_t availableBitrate = this->rembBitrate - this->bitrateInUse;
MS_DEBUG_TAG(
bwe,
"available bitrate [REMB:%" PRIu32 " >= bitrateInUse:%" PRIu32 ", availableBitrate:%" PRIu32
"]",
this->rembBitrate,
this->bitrateInUse,
availableBitrate);
}
else if (rembTrend > 0)
{
MS_DEBUG_TAG(
bwe,
"positive REMT trend [REMB:%" PRIu32 " < bitrateInUse:%" PRIu32 ", trend:%" PRIi64 "]",
this->rembBitrate,
this->bitrateInUse,
rembTrend);
}
else
{
uint32_t exceedingBitrate = this->bitrateInUse - this->rembBitrate;
MS_WARN_TAG(
bwe,
"exceeding bitrate [REMB:%" PRIu32 " < bitrateInUse:%" PRIu32 ", exceedingBitrate:%" PRIu32
"]",
this->rembBitrate,
this->bitrateInUse,
exceedingBitrate);
}
}
uint32_t RembClient::GetAvailableBitrate() const
{
MS_TRACE();
// if (this->bitrateInUse == 0)
// return std::numeric_limits<uint32_t>::max();
// else if (this->availableBitrate >= this->extraBitrateInUse)
// return this->availableBitrate - this->extraBitrateInUse;
// else
// return 0;
return 1234;
}
void RembClient::AddExtraBitrate(uint32_t extraBitrate)
{
MS_TRACE();
// Update last event time.
this->lastEventAt = DepLibUV::GetTime();
// Increase extra bitrate in use.
this->extraBitrateInUse += extraBitrate;
}
void RembClient::RemoveExtraBitrate(uint32_t extraBitrate)
{
MS_TRACE();
// uint32_t rembBitrate = static_cast<uint32_t>(remb->GetBitrate()); // Update last event time.
// uint64_t now = DepLibUV::GetTime(); this->lastEventAt = DepLibUV::GetTime();
// uint32_t bitrate = this->transmissionCounter.GetRate(now);
// int32_t diff = rembBitrate - bitrate;
// MS_ERROR( // Decrease extra bitrate in use.
// "REMB received [sending bitrate:%" PRIu32 ", REMB available bitrate:%" PRIu32 if (this->extraBitrateInUse >= extraBitrate)
// ", diff:%" PRIi32 "]", this->extraBitrateInUse -= extraBitrate;
// bitrate, else
// rembBitrate, this->extraBitrateInUse = 0;
// diff);
} }
} // namespace RTC } // namespace RTC
...@@ -69,7 +69,7 @@ namespace RTC ...@@ -69,7 +69,7 @@ namespace RTC
if (*arrivalTimeDeltaMs - systemTimeDeltaMs >= ArrivalTimeOffsetThresholdMs) if (*arrivalTimeDeltaMs - systemTimeDeltaMs >= ArrivalTimeOffsetThresholdMs)
{ {
MS_WARN_TAG( MS_WARN_TAG(
rbe, bwe,
"the arrival time clock offset has changed, resetting" "the arrival time clock offset has changed, resetting"
"[diff:%" PRId64 "ms]", "[diff:%" PRId64 "ms]",
*arrivalTimeDeltaMs - systemTimeDeltaMs); *arrivalTimeDeltaMs - systemTimeDeltaMs);
...@@ -87,7 +87,7 @@ namespace RTC ...@@ -87,7 +87,7 @@ namespace RTC
if (this->numConsecutiveReorderedPackets >= ReorderedResetThreshold) if (this->numConsecutiveReorderedPackets >= ReorderedResetThreshold)
{ {
MS_WARN_TAG( MS_WARN_TAG(
rbe, bwe,
"packets are being reordered on the path from the " "packets are being reordered on the path from the "
"socket to the bandwidth estimator, ignoring this " "socket to the bandwidth estimator, ignoring this "
"packet for bandwidth estimation, resetting"); "packet for bandwidth estimation, resetting");
......
...@@ -146,7 +146,7 @@ namespace RTC ...@@ -146,7 +146,7 @@ namespace RTC
int recvBitrateBps = it->meanSize * 8 * 1000 / it->recvMeanMs; int recvBitrateBps = it->meanSize * 8 * 1000 / it->recvMeanMs;
MS_DEBUG_TAG( MS_DEBUG_TAG(
rbe, bwe,
"probe failed, sent at %d bps, received at %d bps [mean " "probe failed, sent at %d bps, received at %d bps [mean "
"send delta:%fms, mean recv delta:%fms, num probes:%d]", "send delta:%fms, mean recv delta:%fms, num probes:%d]",
sendBitrateBps, sendBitrateBps,
...@@ -190,7 +190,7 @@ namespace RTC ...@@ -190,7 +190,7 @@ namespace RTC
if (IsBitrateImproving(probeBitrateBps)) if (IsBitrateImproving(probeBitrateBps))
{ {
MS_DEBUG_TAG( MS_DEBUG_TAG(
rbe, bwe,
"probe successful, sent at %d bps, received at %d bps " "probe successful, sent at %d bps, received at %d bps "
"[mean send delta:%fms, mean recv delta:%f ms, " "[mean send delta:%fms, mean recv delta:%f ms, "
"num probes:%d", "num probes:%d",
...@@ -309,7 +309,7 @@ namespace RTC ...@@ -309,7 +309,7 @@ namespace RTC
} }
MS_DEBUG_TAG( MS_DEBUG_TAG(
rbe, bwe,
"probe packet received [send time:%" PRId64 "probe packet received [send time:%" PRId64
"ms, recv " "ms, recv "
"time:%" PRId64 "ms, send delta:%dms, recv delta:%d ms]", "time:%" PRId64 "ms, send delta:%dms, recv delta:%d ms]",
......
...@@ -777,14 +777,14 @@ namespace RTC ...@@ -777,14 +777,14 @@ namespace RTC
if (producerScore == 0) if (producerScore == 0)
continue; continue;
if (producerScore >= maxProducerScore) if (producerScore >= maxProducerScore || producerScore >= 7)
{ {
maxProducerScore = producerScore; maxProducerScore = producerScore;
newTargetSpatialLayer = spatialLayer; newTargetSpatialLayer = spatialLayer;
// If this is the preferred or higher spatial layer and has good score, // If this is the preferred or higher spatial layer and has good score,
// take it and exit. // take it and exit.
if (spatialLayer >= this->preferredSpatialLayer && maxProducerScore >= 7) if (spatialLayer >= this->preferredSpatialLayer && producerScore >= 7)
break; break;
} }
} }
......
...@@ -626,7 +626,7 @@ namespace RTC ...@@ -626,7 +626,7 @@ namespace RTC
this->maxIncomingBitrate = bitrate; this->maxIncomingBitrate = bitrate;
MS_DEBUG_TAG(rbe, "WebRtcTransport maximum incoming bitrate set to %" PRIu32 "bps", bitrate); MS_DEBUG_TAG(bwe, "WebRtcTransport maximum incoming bitrate set to %" PRIu32 "bps", bitrate);
request->Accept(); request->Accept();
...@@ -1101,7 +1101,7 @@ namespace RTC ...@@ -1101,7 +1101,7 @@ namespace RTC
) )
// clang-format on // clang-format on
{ {
MS_DEBUG_TAG(rbe, "enabling REMB server"); MS_DEBUG_TAG(bwe, "enabling REMB server");
this->rembServer = new RTC::RembServer::RemoteBitrateEstimatorAbsSendTime(this); this->rembServer = new RTC::RembServer::RemoteBitrateEstimatorAbsSendTime(this);
} }
...@@ -1135,7 +1135,7 @@ namespace RTC ...@@ -1135,7 +1135,7 @@ namespace RTC
) )
// clang-format on // clang-format on
{ {
MS_DEBUG_TAG(rbe, "enabling REMB client"); MS_DEBUG_TAG(bwe, "enabling REMB client");
this->rembClient = new RTC::RembClient(this); this->rembClient = new RTC::RembClient(this);
} }
...@@ -1448,7 +1448,7 @@ namespace RTC ...@@ -1448,7 +1448,7 @@ namespace RTC
if (this->maxIncomingBitrate != 0u) if (this->maxIncomingBitrate != 0u)
availableBitrate = std::min(availableBitrate, this->maxIncomingBitrate); availableBitrate = std::min(availableBitrate, this->maxIncomingBitrate);
if (MS_HAS_DEBUG_TAG(rbe)) if (MS_HAS_DEBUG_TAG(bwe))
{ {
std::ostringstream ssrcsStream; std::ostringstream ssrcsStream;
...@@ -1459,7 +1459,7 @@ namespace RTC ...@@ -1459,7 +1459,7 @@ namespace RTC
} }
MS_DEBUG_TAG( MS_DEBUG_TAG(
rbe, bwe,
"sending RTCP REMB packet [bitrate:%" PRIu32 "bps, ssrcs:%s]", "sending RTCP REMB packet [bitrate:%" PRIu32 "bps, ssrcs:%s]",
availableBitrate, availableBitrate,
ssrcsStream.str().c_str()); ssrcsStream.str().c_str());
......
...@@ -187,8 +187,8 @@ void Settings::PrintConfiguration() ...@@ -187,8 +187,8 @@ void Settings::PrintConfiguration()
logTags.emplace_back("rtcp"); logTags.emplace_back("rtcp");
if (Settings::configuration.logTags.rtx) if (Settings::configuration.logTags.rtx)
logTags.emplace_back("rtx"); logTags.emplace_back("rtx");
if (Settings::configuration.logTags.rbe) if (Settings::configuration.logTags.bwe)
logTags.emplace_back("rbe"); logTags.emplace_back("bwe");
if (Settings::configuration.logTags.score) if (Settings::configuration.logTags.score)
logTags.emplace_back("score"); logTags.emplace_back("score");
if (Settings::configuration.logTags.simulcast) if (Settings::configuration.logTags.simulcast)
...@@ -308,8 +308,8 @@ void Settings::SetLogTags(const std::vector<std::string>& tags) ...@@ -308,8 +308,8 @@ void Settings::SetLogTags(const std::vector<std::string>& tags)
newLogTags.rtcp = true; newLogTags.rtcp = true;
else if (tag == "rtx") else if (tag == "rtx")
newLogTags.rtx = true; newLogTags.rtx = true;
else if (tag == "rbe") else if (tag == "bwe")
newLogTags.rbe = true; newLogTags.bwe = true;
else if (tag == "score") else if (tag == "score")
newLogTags.score = true; newLogTags.score = true;
else if (tag == "simulcast") else if (tag == "simulcast")
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论