Allows audio bitrate allocation in video calls without enabling TWCC (Transport Wide Congestion Control as defined at https://tools.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01.html) for audio stream.

This will allow experimenting with audio bitrate allocation in video calls without increasing transport overhead.

Bug: webrtc:8243
Change-Id: If961780921d53bdce95b68c26641df6875509c1f
Reviewed-on: https://webrtc-review.googlesource.com/84501
Commit-Queue: Alex Narest <alexnarest@webrtc.org>
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23755}
diff --git a/audio/audio_send_stream.cc b/audio/audio_send_stream.cc
index d2e26cd..9fdf5f6 100644
--- a/audio/audio_send_stream.cc
+++ b/audio/audio_send_stream.cc
@@ -294,7 +294,8 @@
       !webrtc::field_trial::IsEnabled("WebRTC-Audio-ForceNoTWCC");
   if (config_.min_bitrate_bps != -1 && config_.max_bitrate_bps != -1 &&
       (has_transport_sequence_number ||
-       !webrtc::field_trial::IsEnabled("WebRTC-Audio-SendSideBwe"))) {
+       !webrtc::field_trial::IsEnabled("WebRTC-Audio-SendSideBwe") ||
+       webrtc::field_trial::IsEnabled("WebRTC-Audio-ABWENoTWCC"))) {
     // Audio BWE is enabled.
     transport_->packet_sender()->SetAccountForAudioPackets(true);
     ConfigureBitrateObserver(config_.min_bitrate_bps, config_.max_bitrate_bps,
@@ -409,6 +410,12 @@
                                            uint8_t fraction_loss,
                                            int64_t rtt,
                                            int64_t bwe_period_ms) {
+  // Audio transport feedback will not be reported in this mode, instead update
+  // acknowledged bitrate estimator with the bitrate allocated for audio.
+  if (webrtc::field_trial::IsEnabled("WebRTC-Audio-ABWENoTWCC")) {
+    transport_->SetAllocatedBitrateWithoutFeedback(bitrate_bps);
+  }
+
   // A send stream may be allocated a bitrate of zero if the allocator decides
   // to disable it. For now we ignore this decision and keep sending on min
   // bitrate.
diff --git a/call/rtp_transport_controller_send.cc b/call/rtp_transport_controller_send.cc
index a0e47b5..92215d1 100644
--- a/call/rtp_transport_controller_send.cc
+++ b/call/rtp_transport_controller_send.cc
@@ -264,4 +264,9 @@
         << "nothing to update";
   }
 }
+
+void RtpTransportControllerSend::SetAllocatedBitrateWithoutFeedback(
+    uint32_t bitrate_bps) {
+  send_side_cc_->SetAllocatedBitrateWithoutFeedback(bitrate_bps);
+}
 }  // namespace webrtc
diff --git a/call/rtp_transport_controller_send.h b/call/rtp_transport_controller_send.h
index 0027696..d9a4e18 100644
--- a/call/rtp_transport_controller_send.h
+++ b/call/rtp_transport_controller_send.h
@@ -85,6 +85,8 @@
   void SetSdpBitrateParameters(const BitrateConstraints& constraints) override;
   void SetClientBitratePreferences(const BitrateSettings& preferences) override;
 
+  void SetAllocatedBitrateWithoutFeedback(uint32_t bitrate_bps) override;
+
  private:
   const Clock* const clock_;
   PacketRouter packet_router_;
diff --git a/call/rtp_transport_controller_send_interface.h b/call/rtp_transport_controller_send_interface.h
index 65b9d7d..c3a56ad 100644
--- a/call/rtp_transport_controller_send_interface.h
+++ b/call/rtp_transport_controller_send_interface.h
@@ -110,6 +110,8 @@
       const BitrateConstraints& constraints) = 0;
   virtual void SetClientBitratePreferences(
       const BitrateSettings& preferences) = 0;
+
+  virtual void SetAllocatedBitrateWithoutFeedback(uint32_t bitrate_bps) = 0;
 };
 
 }  // namespace webrtc
diff --git a/call/test/mock_rtp_transport_controller_send.h b/call/test/mock_rtp_transport_controller_send.h
index e7c27d6..419ad77 100644
--- a/call/test/mock_rtp_transport_controller_send.h
+++ b/call/test/mock_rtp_transport_controller_send.h
@@ -51,6 +51,7 @@
   MOCK_METHOD1(OnSentPacket, void(const rtc::SentPacket&));
   MOCK_METHOD1(SetSdpBitrateParameters, void(const BitrateConstraints&));
   MOCK_METHOD1(SetClientBitratePreferences, void(const BitrateSettings&));
+  MOCK_METHOD1(SetAllocatedBitrateWithoutFeedback, void(uint32_t));
 };
 }  // namespace webrtc
 #endif  // CALL_TEST_MOCK_RTP_TRANSPORT_CONTROLLER_SEND_H_
diff --git a/media/engine/webrtcvoiceengine.cc b/media/engine/webrtcvoiceengine.cc
index 8367f02..aca853f 100644
--- a/media/engine/webrtcvoiceengine.cc
+++ b/media/engine/webrtcvoiceengine.cc
@@ -596,7 +596,8 @@
   capabilities.header_extensions.push_back(
       webrtc::RtpExtension(webrtc::RtpExtension::kAudioLevelUri,
                            webrtc::RtpExtension::kAudioLevelDefaultId));
-  if (webrtc::field_trial::IsEnabled("WebRTC-Audio-SendSideBwe")) {
+  if (webrtc::field_trial::IsEnabled("WebRTC-Audio-SendSideBwe") &&
+      !webrtc::field_trial::IsEnabled("WebRTC-Audio-ABWENoTWCC")) {
     capabilities.header_extensions.push_back(webrtc::RtpExtension(
         webrtc::RtpExtension::kTransportSequenceNumberUri,
         webrtc::RtpExtension::kTransportSequenceNumberDefaultId));
diff --git a/modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.cc b/modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.cc
index c5d4289..70318c4 100644
--- a/modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.cc
+++ b/modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.cc
@@ -48,7 +48,11 @@
 }
 
 absl::optional<uint32_t> AcknowledgedBitrateEstimator::bitrate_bps() const {
-  return bitrate_estimator_->bitrate_bps();
+  auto estimated_bitrate = bitrate_estimator_->bitrate_bps();
+  return estimated_bitrate
+             ? *estimated_bitrate +
+                   allocated_bitrate_without_feedback_bps_.value_or(0)
+             : estimated_bitrate;
 }
 
 void AcknowledgedBitrateEstimator::SetAlrEndedTimeMs(
@@ -56,6 +60,11 @@
   alr_ended_time_ms_.emplace(alr_ended_time_ms);
 }
 
+void AcknowledgedBitrateEstimator::SetAllocatedBitrateWithoutFeedback(
+    uint32_t bitrate_bps) {
+  allocated_bitrate_without_feedback_bps_.emplace(bitrate_bps);
+}
+
 void AcknowledgedBitrateEstimator::MaybeExpectFastRateChange(
     int64_t packet_send_time_ms) {
   if (alr_ended_time_ms_ && packet_send_time_ms > *alr_ended_time_ms_) {
diff --git a/modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.h b/modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.h
index faa6b48..ccb9718 100644
--- a/modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.h
+++ b/modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.h
@@ -33,11 +33,13 @@
       const std::vector<PacketFeedback>& packet_feedback_vector);
   absl::optional<uint32_t> bitrate_bps() const;
   void SetAlrEndedTimeMs(int64_t alr_ended_time_ms);
+  void SetAllocatedBitrateWithoutFeedback(uint32_t bitrate_bps);
 
  private:
   void MaybeExpectFastRateChange(int64_t packet_arrival_time_ms);
   absl::optional<int64_t> alr_ended_time_ms_;
   std::unique_ptr<BitrateEstimator> bitrate_estimator_;
+  absl::optional<uint32_t> allocated_bitrate_without_feedback_bps_;
 };
 
 }  // namespace webrtc
diff --git a/modules/congestion_controller/include/send_side_congestion_controller.h b/modules/congestion_controller/include/send_side_congestion_controller.h
index e19a5c5..53ad7bd 100644
--- a/modules/congestion_controller/include/send_side_congestion_controller.h
+++ b/modules/congestion_controller/include/send_side_congestion_controller.h
@@ -120,6 +120,8 @@
 
   void SetPacingFactor(float pacing_factor) override;
 
+  void SetAllocatedBitrateWithoutFeedback(uint32_t bitrate_bps) override;
+
  private:
   void MaybeTriggerOnNetworkChanged();
 
diff --git a/modules/congestion_controller/include/send_side_congestion_controller_interface.h b/modules/congestion_controller/include/send_side_congestion_controller_interface.h
index 0f00255..91866fc 100644
--- a/modules/congestion_controller/include/send_side_congestion_controller_interface.h
+++ b/modules/congestion_controller/include/send_side_congestion_controller_interface.h
@@ -64,6 +64,7 @@
   virtual void EnablePeriodicAlrProbing(bool enable) = 0;
   virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0;
   virtual void SetPacingFactor(float pacing_factor) = 0;
+  virtual void SetAllocatedBitrateWithoutFeedback(uint32_t bitrate_bps) = 0;
   RTC_DISALLOW_COPY_AND_ASSIGN(SendSideCongestionControllerInterface);
 };
 
diff --git a/modules/congestion_controller/rtp/include/send_side_congestion_controller.h b/modules/congestion_controller/rtp/include/send_side_congestion_controller.h
index 7d41e27..9ab19ae 100644
--- a/modules/congestion_controller/rtp/include/send_side_congestion_controller.h
+++ b/modules/congestion_controller/rtp/include/send_side_congestion_controller.h
@@ -139,6 +139,8 @@
 
   void SetPacingFactor(float pacing_factor) override;
 
+  void SetAllocatedBitrateWithoutFeedback(uint32_t bitrate_bps) override;
+
  protected:
   // TODO(srte): The tests should be rewritten to not depend on internals and
   // these functions should be removed.
diff --git a/modules/congestion_controller/rtp/send_side_congestion_controller.cc b/modules/congestion_controller/rtp/send_side_congestion_controller.cc
index 6e0af24..78a9b94 100644
--- a/modules/congestion_controller/rtp/send_side_congestion_controller.cc
+++ b/modules/congestion_controller/rtp/send_side_congestion_controller.cc
@@ -773,6 +773,9 @@
   });
 }
 
+void SendSideCongestionController::SetAllocatedBitrateWithoutFeedback(
+    uint32_t bitrate_bps) {}
+
 void SendSideCongestionController::DisablePeriodicTasks() {
   task_queue_->PostTask([this]() {
     RTC_DCHECK_RUN_ON(task_queue_);
diff --git a/modules/congestion_controller/send_side_congestion_controller.cc b/modules/congestion_controller/send_side_congestion_controller.cc
index 480b741..3065c8b 100644
--- a/modules/congestion_controller/send_side_congestion_controller.cc
+++ b/modules/congestion_controller/send_side_congestion_controller.cc
@@ -415,6 +415,12 @@
   pacer_->SetPacingFactor(pacing_factor);
 }
 
+void SendSideCongestionController::SetAllocatedBitrateWithoutFeedback(
+    uint32_t bitrate_bps) {
+  acknowledged_bitrate_estimator_->SetAllocatedBitrateWithoutFeedback(
+      bitrate_bps);
+}
+
 void SendSideCongestionController::MaybeTriggerOnNetworkChanged() {
   uint32_t bitrate_bps;
   uint8_t fraction_loss;