diff --git a/erizo/src/erizo/rtp/SenderBandwidthEstimantionHandler.cpp b/erizo/src/erizo/rtp/SenderBandwidthEstimantionHandler.cpp index 42b5f6ad2..9f7b868d1 100644 --- a/erizo/src/erizo/rtp/SenderBandwidthEstimantionHandler.cpp +++ b/erizo/src/erizo/rtp/SenderBandwidthEstimantionHandler.cpp @@ -58,7 +58,7 @@ void SenderBandwidthEstimationHandler::disable() { void SenderBandwidthEstimationHandler::notifyUpdate() { if (initialized_) { - updateMaxListSizes(); + updateNumberOfStreams(); return; } auto pipeline = getContext()->getPipelineShared(); @@ -68,7 +68,7 @@ void SenderBandwidthEstimationHandler::notifyUpdate() { if (!connection_) { return; } - updateMaxListSizes(); + updateNumberOfStreams(); stats_ = pipeline->getService(); if (!stats_) { return; @@ -76,16 +76,28 @@ void SenderBandwidthEstimationHandler::notifyUpdate() { initialized_ = true; } -void SenderBandwidthEstimationHandler::updateMaxListSizes() { +void SenderBandwidthEstimationHandler::updateNumberOfStreams() { size_t num_streams = 0; connection_->forEachMediaStream([&num_streams] (std::shared_ptr 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(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::BitsPerSec(min_send_bitrate), + webrtc::DataRate::BitsPerSec(kMaxSendBitrate), + getNowTimestamp()); + } } void SenderBandwidthEstimationHandler::read(Context *ctx, std::shared_ptr packet) { diff --git a/erizo/src/erizo/rtp/SenderBandwidthEstimationHandler.h b/erizo/src/erizo/rtp/SenderBandwidthEstimationHandler.h index 543a6bd99..e72127964 100644 --- a/erizo/src/erizo/rtp/SenderBandwidthEstimationHandler.h +++ b/erizo/src/erizo/rtp/SenderBandwidthEstimationHandler.h @@ -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); @@ -53,7 +54,7 @@ class SenderBandwidthEstimationHandler : public Handler, bwe_listener_ = listener; } private: - void updateMaxListSizes(); + void updateNumberOfStreams(); void updateReceiverBlockFromList(); webrtc::Timestamp getNowTimestamp();