Skip to content

Commit

Permalink
Adjust min bitrate with the number of streams (#1809)
Browse files Browse the repository at this point in the history
  • Loading branch information
lodoyun authored Mar 24, 2022
1 parent 2a30dbb commit ed24236
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
18 changes: 15 additions & 3 deletions erizo/src/erizo/rtp/SenderBandwidthEstimantionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void SenderBandwidthEstimationHandler::disable() {

void SenderBandwidthEstimationHandler::notifyUpdate() {
if (initialized_) {
updateMaxListSizes();
updateNumberOfStreams();
return;
}
auto pipeline = getContext()->getPipelineShared();
Expand All @@ -68,24 +68,36 @@ void SenderBandwidthEstimationHandler::notifyUpdate() {
if (!connection_) {
return;
}
updateMaxListSizes();
updateNumberOfStreams();
stats_ = pipeline->getService<Stats>();
if (!stats_) {
return;
}
initialized_ = true;
}

void SenderBandwidthEstimationHandler::updateMaxListSizes() {
void SenderBandwidthEstimationHandler::updateNumberOfStreams() {
size_t num_streams = 0;
connection_->forEachMediaStream([&num_streams] (std::shared_ptr<MediaStream> media_stream) {
if (!media_stream->isPublisher()) {
num_streams++;
}
});
// update max list sizes
max_sr_delay_data_size_ = num_streams * kMaxSrListSize;
max_rr_delay_data_size_ = num_streams;
updateReceiverBlockFromList();
// if there are streams update bitrate limits
if (num_streams > 0) {
uint32_t min_send_bitrate = std::min(kMinSendBitrate * static_cast<uint32_t>(num_streams), kMinSendBitrateLimit);
ELOG_DEBUG("SetBitrates, estimated: %u, min: %u, max: %u", estimated_bitrate_, min_send_bitrate, kMaxSendBitrate);

sender_bwe_->SetBitrates(
absl::optional<webrtc::DataRate>(),
webrtc::DataRate::BitsPerSec(min_send_bitrate),
webrtc::DataRate::BitsPerSec(kMaxSendBitrate),
getNowTimestamp());
}
}

void SenderBandwidthEstimationHandler::read(Context *ctx, std::shared_ptr<DataPacket> packet) {
Expand Down
3 changes: 2 additions & 1 deletion erizo/src/erizo/rtp/SenderBandwidthEstimationHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class SenderBandwidthEstimationHandler : public Handler,
static const uint16_t kMaxSrListSize = 20;
static const uint32_t kStartSendBitrate = 300000;
static const uint32_t kMinSendBitrate = 30000;
static const uint32_t kMinSendBitrateLimit = 1000000;
static const uint32_t kMaxSendBitrate = 1000000000;
static constexpr duration kMinUpdateEstimateInterval = std::chrono::milliseconds(25);

Expand All @@ -53,7 +54,7 @@ class SenderBandwidthEstimationHandler : public Handler,
bwe_listener_ = listener;
}
private:
void updateMaxListSizes();
void updateNumberOfStreams();
void updateReceiverBlockFromList();
webrtc::Timestamp getNowTimestamp();

Expand Down

0 comments on commit ed24236

Please sign in to comment.