Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(578)

Unified Diff: webrtc/modules/congestion_controller/congestion_controller.cc

Issue 1917793002: Remove SendPacer from ViEEncoder (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Renamed SenderDelegate to PacketSender. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/congestion_controller/congestion_controller.cc
diff --git a/webrtc/modules/congestion_controller/congestion_controller.cc b/webrtc/modules/congestion_controller/congestion_controller.cc
index 14a73fe1cdccfb1a3bdaed8f6771f5fe1af3cc1f..f3a8432310cb257ddc33bd978b623a7c2756422b 100644
--- a/webrtc/modules/congestion_controller/congestion_controller.cc
+++ b/webrtc/modules/congestion_controller/congestion_controller.cc
@@ -20,7 +20,6 @@
#include "webrtc/base/socket.h"
#include "webrtc/base/thread_annotations.h"
#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
-#include "webrtc/modules/pacing/paced_sender.h"
#include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h"
#include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.h"
#include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h"
@@ -138,31 +137,58 @@ class WrappingBitrateEstimator : public RemoteBitrateEstimator {
CongestionController::CongestionController(
Clock* clock,
- BitrateObserver* bitrate_observer,
+ Observer* observer,
RemoteBitrateObserver* remote_bitrate_observer)
: clock_(clock),
+ observer_(observer),
+ packet_router_(new PacketRouter()),
pacer_(new PacedSender(clock_,
- &packet_router_,
- BitrateController::kDefaultStartBitrateKbps,
- PacedSender::kDefaultPaceMultiplier *
- BitrateController::kDefaultStartBitrateKbps,
- 0)),
+ packet_router_.get(),
+ BitrateController::kDefaultStartBitratebps)),
+ remote_bitrate_estimator_(
+ new WrappingBitrateEstimator(remote_bitrate_observer, clock_)),
+ bitrate_controller_(BitrateController::CreateBitrateController(clock_)),
+ remote_estimator_proxy_(clock_, packet_router_.get()),
+ transport_feedback_adapter_(bitrate_controller_.get(), clock_),
+ min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps),
+ send_queue_is_full_(false) {
+ Init();
+}
+
+CongestionController::CongestionController(
+ Clock* clock,
+ Observer* observer,
+ RemoteBitrateObserver* remote_bitrate_observer,
+ std::unique_ptr<PacketRouter> packet_router,
+ std::unique_ptr<PacedSender> pacer)
+ : clock_(clock),
+ observer_(observer),
+ packet_router_(std::move(packet_router)),
+ pacer_(std::move(pacer)),
remote_bitrate_estimator_(
new WrappingBitrateEstimator(remote_bitrate_observer, clock_)),
// Constructed last as this object calls the provided callback on
// construction.
- bitrate_controller_(
- BitrateController::CreateBitrateController(clock_, bitrate_observer)),
- remote_estimator_proxy_(clock_, &packet_router_),
+ bitrate_controller_(BitrateController::CreateBitrateController(clock_)),
+ remote_estimator_proxy_(clock_, packet_router_.get()),
transport_feedback_adapter_(bitrate_controller_.get(), clock_),
- min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps) {
+ min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps),
+ send_queue_is_full_(false) {
+ Init();
+}
+
+CongestionController::~CongestionController() {}
+
+void CongestionController::Init() {
transport_feedback_adapter_.SetBitrateEstimator(
new RemoteBitrateEstimatorAbsSendTime(&transport_feedback_adapter_));
transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate(
min_bitrate_bps_);
-}
-
-CongestionController::~CongestionController() {
+ // This calls the observer_, which means that the observer provided by the
+ // user must be ready to accept a bitrate update when it constructs the
+ // controller. We do this to avoid having to keep synchronized initial values
+ // in both the controller and the allocator.
+ MaybeTriggerOnNetworkChanged();
}
@@ -189,6 +215,7 @@ void CongestionController::SetBweBitrates(int min_bitrate_bps,
min_bitrate_bps_ = min_bitrate_bps;
transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate(
min_bitrate_bps_);
+ MaybeTriggerOnNetworkChanged();
}
BitrateController* CongestionController::GetBitrateController() const {
@@ -209,10 +236,9 @@ CongestionController::GetTransportFeedbackObserver() {
return &transport_feedback_adapter_;
}
-void CongestionController::UpdatePacerBitrate(int bitrate_kbps,
- int max_bitrate_kbps,
- int min_bitrate_kbps) {
- pacer_->UpdateBitrate(bitrate_kbps, max_bitrate_kbps, min_bitrate_kbps);
+void CongestionController::SetAllocatedSendBitrate(int allocated_bitrate_bps,
+ int padding_bitrate_bps) {
+ pacer_->SetAllocatedSendBitrate(allocated_bitrate_bps, padding_bitrate_bps);
}
int64_t CongestionController::GetPacerQueuingDelayMs() const {
@@ -245,6 +271,31 @@ int64_t CongestionController::TimeUntilNextProcess() {
void CongestionController::Process() {
bitrate_controller_->Process();
remote_bitrate_estimator_->Process();
+ MaybeTriggerOnNetworkChanged();
+}
+
+void CongestionController::MaybeTriggerOnNetworkChanged() {
+ uint32_t bitrate_bps;
+ uint8_t fraction_loss;
+ int64_t rtt;
+ bool network_changed = bitrate_controller_->GetNetworkParameters(
+ &bitrate_bps, &fraction_loss, &rtt);
+ if (network_changed)
+ pacer_->SetEstimatedBitrate(bitrate_bps);
+ bool send_queue_is_full =
+ pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs;
+ bitrate_bps = send_queue_is_full ? 0 : bitrate_bps;
+ if ((network_changed && !send_queue_is_full) ||
+ UpdateSendQueueStatus(send_queue_is_full)) {
+ observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt);
+ }
+}
+
+bool CongestionController::UpdateSendQueueStatus(bool send_queue_is_full) {
+ rtc::CritScope cs(&critsect_);
+ bool result = send_queue_is_full_ != send_queue_is_full;
+ send_queue_is_full_ = send_queue_is_full;
+ return result;
}
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698