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

SimulcastConsumer::GetDesiredBitrate(): Choose the highest bitrate among all Producer streams #992

Merged
merged 13 commits into from
Jan 27, 2023
2 changes: 1 addition & 1 deletion worker/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,5 @@ fn main() {
}

println!("cargo:rustc-link-lib=static=mediasoup-worker");
println!("cargo:rustc-link-search=native={}", out_dir);
println!("cargo:rustc-link-search=native={out_dir}");
}
11 changes: 8 additions & 3 deletions worker/src/RTC/SimulcastConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,17 +630,22 @@ namespace RTC
auto nowMs = DepLibUV::GetTimeMs();
uint32_t desiredBitrate{ 0u };

// Let's iterate all streams of the Producer (from highest to lowest) and
// obtain their bitrate. Choose the highest one.
// NOTE: When the Producer enables a higher stream, initially the bitrate of
// it could be less than the bitrate of a lower stream. That's why we
// iterate all streams here anyway.
for (auto sIdx{ static_cast<int16_t>(this->producerRtpStreams.size() - 1) }; sIdx >= 0; --sIdx)
{
auto* producerRtpStream = this->producerRtpStreams.at(sIdx);

if (!producerRtpStream)
continue;

desiredBitrate = producerRtpStream->GetBitrate(nowMs);
auto streamBitrate = producerRtpStream->GetBitrate(nowMs);

if (desiredBitrate)
break;
if (streamBitrate > desiredBitrate)
desiredBitrate = streamBitrate;
}

// If consumer.rtpParameters.encodings[0].maxBitrate was given and it's
Expand Down
11 changes: 2 additions & 9 deletions worker/src/RTC/Transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2324,16 +2324,9 @@ namespace RTC
for (uint8_t i{ 1u }; i <= (baseAllocation ? 1u : priority); ++i)
{
uint32_t usedBitrate{ 0u };
bool considerLoss = (bweType == RTC::BweType::REMB);

switch (bweType)
{
case RTC::BweType::TRANSPORT_CC:
usedBitrate = consumer->IncreaseLayer(availableBitrate, /*considerLoss*/ false);
break;
case RTC::BweType::REMB:
usedBitrate = consumer->IncreaseLayer(availableBitrate, /*considerLoss*/ true);
break;
}
usedBitrate = consumer->IncreaseLayer(availableBitrate, considerLoss);

MS_ASSERT(usedBitrate <= availableBitrate, "Consumer used more layer bitrate than given");

Expand Down