# Clamping sendBitrate \<= maxBitrate

**URL:** <https://mediasoup.discourse.group/t/clamping-sendbitrate-maxbitrate/3861>\
**Category:** mediasoup libraries\
**Created:** [January 26, 2022, 3:52pm UTC](https://mediasoup.discourse.group/t/clamping-sendbitrate-maxbitrate/3861 "2022-01-26T15:52:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![steve.mcfarlin](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/steve.mcfarlin/32/1186_2.png) [@steve.mcfarlin](https://mediasoup.discourse.group/u/steve.mcfarlin)\
**Post date:** [January 26, 2022, 3:52pm UTC](https://mediasoup.discourse.group/t/clamping-sendbitrate-maxbitrate/3861/1 "2022-01-26T15:52:30Z")

</div>

### “Issue” description

When setting **maxBitrate** via TRANSPORT\_SET\_MAX\_OUTGOING\_BITRATE the maximum outgoing bitrate is not reduced for some time. My conclusion is given the **startBitrate** in TransportCongestionControlClient is larger than the max bitrate at the time of setting that it takes time for the Transport CC algo to reduce this.

I added code to reduce the **startBitrate** in TransportCongestionControlClient

```auto
// NOTE: Setting 'startBitrate' to 'availableBitrate' has proven to generate
// more stable values.
this->bitrates.startBitrate = std::max<uint32_t>(MinBitrate, this->bitrates.availableBitrate);
// Reduce startBitrate to 90% of maxBitrate
if (this->bitrates.startBitrate > this->bitrates.maxBitrate) {
	this->bitrates.startBitrate = this->bitrates.maxBitrate * 0.9;
}

```

By doing this the maximum outgoing bitrate is immediately reduced. In the case of VP8/VP9 the scalability layers is immediately downgraded/selected. I understand this could potentially cause video artifacts, frozen video, etc, and by not doing this the transport CC algo is allowed to slowly reduce the bitrate. I am wondering what your thoughts are on this.

Additional Info:

The issue I am seeing is the total outgoing bitrate is not being honored after setting maxBitrate. It can take some time for the reduction to happen.

```auto
RTC::Transport::HandleRequest() | !!!!!!!!! SETTING MAX OUTGOING: 750000
RTC::Transport::DistributeAvailableOutgoingBitrate() | availableBitrate [1995354]
RTC::Transport::ComputeOutgoingDesiredBitrate() | total desired bitrate: 1390304
RTC::TransportCongestionControlClient::SetDesiredBitrate() | [desiredBitrate:1390304, startBitrate:1995354, minBitrate:30000, maxBitrate:750000, maxPaddingBitrate:637500, availableBitrate:1995354]
**<SNIP>**
RTC::TransportCongestionControlClient::SetDesiredBitrate() | [desiredBitrate:1428134, startBitrate:1995354, minBitrate:30000, maxBitrate:750000, maxPaddingBitrate:637500, availableBitrate:1995354]
RTC::Transport::DistributeAvailableOutgoingBitrate() | availableBitrate [750000]
RTC::Transport::ComputeOutgoingDesiredBitrate() | total desired bitrate: 1406034
RTC::TransportCongestionControlClient::SetDesiredBitrate() | [desiredBitrate:1406034, startBitrate:750000, minBitrate:30000, maxBitrate:750000, maxPaddingBitrate:637500, availableBitrate:750000]
RTC::Transport::DistributeAvailableOutgoingBitrate() | availableBitrate [750000]
RTC::Transport::ComputeOutgoingDesiredBitrate() | total desired bitrate: 1373334

```

### Your environment

- mediasoup version: e7d4f874275dad69cd584a1b7cdd6be4656d1791

---

<div class="post-metadata">

**Author:** ![jmillan](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/jmillan/32/9_2.png) [@jmillan](https://mediasoup.discourse.group/u/jmillan)\
**Post date:** [January 27, 2022, 9:35am UTC](https://mediasoup.discourse.group/t/clamping-sendbitrate-maxbitrate/3861/2 "2022-01-27T09:35:47Z")

</div>

> [@steve.mcfarlin](#):
>
> e7d4f874275dad69cd584a1b7cdd6be4656d1791

We have just pushed TCC enhancements to mediasoup v3. Can you try the latest commit?

---

<div class="post-metadata">

**Author:** ![steve.mcfarlin](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/steve.mcfarlin/32/1186_2.png) [@steve.mcfarlin](https://mediasoup.discourse.group/u/steve.mcfarlin)\
**Post date:** [January 27, 2022, 4:04pm UTC](https://mediasoup.discourse.group/t/clamping-sendbitrate-maxbitrate/3861/3 "2022-01-27T16:04:21Z")

</div>

Thanks. I will test that.

---

<div class="post-metadata">

**Author:** ![steve.mcfarlin](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/steve.mcfarlin/32/1186_2.png) [@steve.mcfarlin](https://mediasoup.discourse.group/u/steve.mcfarlin)\
**Post date:** [February 2, 2022, 9:58pm UTC](https://mediasoup.discourse.group/t/clamping-sendbitrate-maxbitrate/3861/4 "2022-02-02T21:58:08Z")

</div>

The change Gustavo made speeds up the change when reducing the max outgoing bitrate.

---

<div class="post-metadata">

**Author:** ![steve.mcfarlin](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/steve.mcfarlin/32/1186_2.png) [@steve.mcfarlin](https://mediasoup.discourse.group/u/steve.mcfarlin)\
**Post date:** [February 2, 2022, 10:13pm UTC](https://mediasoup.discourse.group/t/clamping-sendbitrate-maxbitrate/3861/5 "2022-02-02T22:13:57Z")

</div>

After further testing the time for the max outgoing bitrate to reduce is variable. The TCC change did not really effect the bitrate change. Currently we do not have a pressing need to _force_ the change immediately.
