Add ability to set bitrate of DegradedCall via PeerConnection::SetBitrate

Bug: None
Change-Id: Iac8970c95a01c1322fa65a19ab11ffd8f94412e0
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/279200
Commit-Queue: Daniel.L (Byoungchan) Lee <daniel.l@hpcnt.com>
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38442}
diff --git a/call/degraded_call.cc b/call/degraded_call.cc
index 0090d3a..c59a63b 100644
--- a/call/degraded_call.cc
+++ b/call/degraded_call.cc
@@ -414,6 +414,11 @@
   return status;
 }
 
+void DegradedCall::SetClientBitratePreferences(
+    const webrtc::BitrateSettings& preferences) {
+  call_->SetClientBitratePreferences(preferences);
+}
+
 void DegradedCall::UpdateSendNetworkConfig() {
   send_config_index_ = (send_config_index_ + 1) % send_configs_.size();
   send_simulated_network_->SetConfig(send_configs_[send_config_index_]);
diff --git a/call/degraded_call.h b/call/degraded_call.h
index dcdd480..5906e55 100644
--- a/call/degraded_call.h
+++ b/call/degraded_call.h
@@ -191,7 +191,7 @@
   };
 
   void SetClientBitratePreferences(
-      const webrtc::BitrateSettings& preferences) override {}
+      const webrtc::BitrateSettings& preferences) override;
   void UpdateSendNetworkConfig();
   void UpdateReceiveNetworkConfig();
 
diff --git a/pc/peer_connection_field_trial_tests.cc b/pc/peer_connection_field_trial_tests.cc
index 0e6e451..784cfa4 100644
--- a/pc/peer_connection_field_trial_tests.cc
+++ b/pc/peer_connection_field_trial_tests.cc
@@ -17,6 +17,7 @@
 #include "api/audio_codecs/builtin_audio_encoder_factory.h"
 #include "api/create_peerconnection_factory.h"
 #include "api/peer_connection_interface.h"
+#include "api/stats/rtcstats_objects.h"
 #include "api/task_queue/default_task_queue_factory.h"
 #include "api/video_codecs/builtin_video_decoder_factory.h"
 #include "api/video_codecs/builtin_video_encoder_factory.h"
@@ -228,6 +229,10 @@
   CreatePCFactory(std::move(field_trials));
 
   WrapperPtr caller = CreatePeerConnection();
+  BitrateSettings bitrate_settings;
+  bitrate_settings.start_bitrate_bps = 1'000'000;
+  bitrate_settings.max_bitrate_bps = 1'000'000;
+  caller->pc()->SetBitrate(bitrate_settings);
   FrameGeneratorCapturerVideoTrackSource::Config config;
   auto video_track_source =
       rtc::make_ref_counted<FrameGeneratorCapturerVideoTrackSource>(
@@ -259,9 +264,14 @@
   ASSERT_TRUE_WAIT(caller->IsIceConnected(), kDefaultTimeoutMs);
 
   // Send packets for kDefaultTimeoutMs
-  // For now, whether this field trial works or not is checked by
-  // whether a crash occurs. Additional validation can be added later.
   WAIT(false, kDefaultTimeoutMs);
+
+  std::vector<const RTCOutboundRTPStreamStats*> outbound_rtp_stats =
+      caller->GetStats()->GetStatsOfType<RTCOutboundRTPStreamStats>();
+  ASSERT_GE(outbound_rtp_stats.size(), 1u);
+  ASSERT_TRUE(outbound_rtp_stats[0]->target_bitrate.is_defined());
+  // Link capacity is limited to 500k, so BWE is expected to be close to 500k.
+  ASSERT_LE(*outbound_rtp_stats[0]->target_bitrate, 500'000 * 1.1);
 }
 
 }  // namespace webrtc