Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TransportCongestionControlClient: allow setting maxOutgoingBitrate before created #833

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions worker/include/RTC/RtpPacket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ using json = nlohmann::json;

namespace RTC
{
// Max RTP length.
constexpr size_t RtpBufferSize{ 65536u };
// Max MTU size.
constexpr size_t MtuSize{ 1500u };
// MID header extension max length (just used when setting/updating MID
Expand Down
2 changes: 2 additions & 0 deletions worker/include/RTC/TransportCongestionControlClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

namespace RTC
{
constexpr uint32_t TransportCongestionControlMinOutgoingBitrate{ 30000u };

class TransportCongestionControlClient : public webrtc::PacketRouter,
public webrtc::TargetTransferRateObserver,
public Timer::Listener
Expand Down
19 changes: 14 additions & 5 deletions worker/src/RTC/Transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,20 +630,29 @@ namespace RTC
MS_THROW_TYPE_ERROR("missing bitrate");
}

if (this->tccClient)
uint32_t bitrate = jsonBitrateIt->get<uint32_t>();

if (bitrate < RTC::TransportCongestionControlMinOutgoingBitrate)
{
uint32_t bitrate = jsonBitrateIt->get<uint32_t>();
MS_THROW_TYPE_ERROR(
"bitrate must be >= %" PRIu32 " bps", RTC::TransportCongestionControlMinOutgoingBitrate);
}

// NOTE: This may throw if given bitrate is less than current
// initialAvailableOutgoingBitrate, so don't update things before
// calling this method.
if (this->tccClient)
{
// NOTE: This may throw so don't update things before calling this
// method.
this->tccClient->SetMaxOutgoingBitrate(bitrate);
this->maxOutgoingBitrate = bitrate;

MS_DEBUG_TAG(bwe, "maximum outgoing bitrate set to %" PRIu32, this->maxOutgoingBitrate);

ComputeOutgoingDesiredBitrate();
}
else
{
this->maxOutgoingBitrate = bitrate;
}

request->Accept();

Expand Down
14 changes: 7 additions & 7 deletions worker/src/RTC/TransportCongestionControlClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace RTC
{
/* Static. */

static constexpr uint32_t MinBitrate{ 30000u };
// NOTE: TransportCongestionControlMinOutgoingBitrate is defined in
// TransportCongestionControlClient.hpp and exposed publicly.
static constexpr float MaxBitrateMarginFactor{ 0.1f };
static constexpr float MaxBitrateIncrementFactor{ 1.35f };
static constexpr float MaxPaddingBitrateFactor{ 0.85f };
Expand All @@ -27,7 +28,8 @@ namespace RTC
uint32_t initialAvailableBitrate,
uint32_t maxOutgoingBitrate)
: listener(listener), bweType(bweType),
initialAvailableBitrate(std::max<uint32_t>(initialAvailableBitrate, MinBitrate)),
initialAvailableBitrate(std::max<uint32_t>(
initialAvailableBitrate, RTC::TransportCongestionControlMinOutgoingBitrate)),
maxOutgoingBitrate(maxOutgoingBitrate)
{
MS_TRACE();
Expand Down Expand Up @@ -262,9 +264,6 @@ namespace RTC

void TransportCongestionControlClient::SetMaxOutgoingBitrate(uint32_t maxBitrate)
{
if (maxBitrate < MinBitrate)
MS_THROW_ERROR("maxOutgoingBitrate must be >= 30000bps");

this->maxOutgoingBitrate = maxBitrate;

ApplyBitrateUpdates();
Expand All @@ -290,10 +289,11 @@ namespace RTC

this->bitrates.desiredBitrate = desiredBitrate;
this->bitrates.effectiveDesiredBitrate = this->desiredBitrateTrend.GetValue();
this->bitrates.minBitrate = MinBitrate;
this->bitrates.minBitrate = RTC::TransportCongestionControlMinOutgoingBitrate;
// NOTE: Setting 'startBitrate' to 'availableBitrate' has proven to generate
// more stable values.
this->bitrates.startBitrate = std::max<uint32_t>(MinBitrate, this->bitrates.availableBitrate);
this->bitrates.startBitrate = std::max<uint32_t>(
RTC::TransportCongestionControlMinOutgoingBitrate, this->bitrates.availableBitrate);

ApplyBitrateUpdates();
}
Expand Down