Remove use of bwe_period from audio

BitrateAllocationUpdate::bwe_period is deprecated and being removed.
This removes bwe_period usage from AudioEncoder, AudioEncoderOpusImpl,
and audio unit tests.

Bug: webrtc:442860748
Change-Id: I7ba86cb8e22609d95fd7a9958ff186594c137d3f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/486540
Reviewed-by: Jakob Ivarsson‎ <jakobi@webrtc.org>
Reviewed-by: Per Åhgren <peah@webrtc.org>
Commit-Queue: Per Kjellander <perkj@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#48119}
diff --git a/api/audio_codecs/audio_encoder.cc b/api/audio_codecs/audio_encoder.cc
index 787c042..6eec440 100644
--- a/api/audio_codecs/audio_encoder.cc
+++ b/api/audio_codecs/audio_encoder.cc
@@ -110,10 +110,7 @@
 void AudioEncoder::OnReceivedUplinkAllocation(BitrateAllocationUpdate update) {
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
-  OnReceivedUplinkBandwidth(update.target_bitrate.bps(),
-                            update.bwe_period.IsFinite()
-                                ? std::make_optional(update.bwe_period.ms())
-                                : std::nullopt);
+  OnReceivedUplinkBandwidth(update.target_bitrate.bps(), std::nullopt);
 #pragma clang diagnostic pop
 }
 
diff --git a/audio/audio_send_stream_unittest.cc b/audio/audio_send_stream_unittest.cc
index 60f10ca..e4f1fb4 100644
--- a/audio/audio_send_stream_unittest.cc
+++ b/audio/audio_send_stream_unittest.cc
@@ -643,7 +643,6 @@
         DataRate::BitsPerSec(helper.config().max_bitrate_bps + 5000);
     update.packet_loss_ratio = 0;
     update.round_trip_time = TimeDelta::Millis(50);
-    update.bwe_period = TimeDelta::Millis(6000);
     send_stream->OnBitrateUpdated(update);
   }
 }
@@ -756,23 +755,6 @@
   }
 }
 
-TEST(AudioSendStreamTest, ProbingIntervalOnBitrateUpdated) {
-  for (bool use_null_audio_processing : {false, true}) {
-    ConfigHelper helper(false, true, use_null_audio_processing);
-    auto send_stream = helper.CreateAudioSendStream();
-
-    EXPECT_CALL(*helper.channel_send(),
-                OnBitrateAllocation(Field(&BitrateAllocationUpdate::bwe_period,
-                                          Eq(TimeDelta::Millis(5000)))));
-    BitrateAllocationUpdate update;
-    update.target_bitrate =
-        DataRate::BitsPerSec(helper.config().max_bitrate_bps + 5000);
-    update.packet_loss_ratio = 0;
-    update.round_trip_time = TimeDelta::Millis(50);
-    update.bwe_period = TimeDelta::Millis(5000);
-    send_stream->OnBitrateUpdated(update);
-  }
-}
 
 // Test that AudioSendStream doesn't recreate the encoder unnecessarily.
 TEST(AudioSendStreamTest, DontRecreateEncoder) {
diff --git a/audio/channel_send_unittest.cc b/audio/channel_send_unittest.cc
index abd6a52..9831e1d 100644
--- a/audio/channel_send_unittest.cc
+++ b/audio/channel_send_unittest.cc
@@ -369,8 +369,6 @@
   DataRate lowrate = DataRate::BitsPerSec(40000);
   DataRate highrate = DataRate::BitsPerSec(80000);
   BitrateAllocationUpdate update;
-  update.bwe_period = TimeDelta::Millis(100);
-
   update.target_bitrate = lowrate;
   channel_->OnBitrateAllocation(update);
   EXPECT_CALL(transport_, SendRtp).Times(1);
diff --git a/common_audio/mocks/mock_smoothing_filter.h b/common_audio/mocks/mock_smoothing_filter.h
index c170b4d..aa8e698 100644
--- a/common_audio/mocks/mock_smoothing_filter.h
+++ b/common_audio/mocks/mock_smoothing_filter.h
@@ -23,7 +23,6 @@
  public:
   MOCK_METHOD(void, AddSample, (float, Timestamp), (override));
   MOCK_METHOD(std::optional<float>, GetAverage, (Timestamp), (override));
-  MOCK_METHOD(bool, SetTimeConstantMs, (int), (override));
 };
 
 }  // namespace webrtc
diff --git a/common_audio/smoothing_filter.cc b/common_audio/smoothing_filter.cc
index 33cbe27..bfaf2db 100644
--- a/common_audio/smoothing_filter.cc
+++ b/common_audio/smoothing_filter.cc
@@ -33,9 +33,8 @@
       init_const_(init_time_ms_ == 0
                       ? 0.0f
                       : init_time_ms_ -
-                            powf(init_time_ms_, 1.0f - 1.0f / init_time_ms_)) {
-  UpdateAlpha(init_time_ms_);
-}
+                            powf(init_time_ms_, 1.0f - 1.0f / init_time_ms_)),
+      alpha_(init_time_ms == 0 ? 0.0f : std::exp(-1.0f / init_time_ms)) {}
 
 SmoothingFilterImpl::~SmoothingFilterImpl() = default;
 
@@ -64,18 +63,6 @@
   return state_;
 }
 
-bool SmoothingFilterImpl::SetTimeConstantMs(int time_constant_ms) {
-  if (!init_end_time_ms_ || last_state_time_ms_ < *init_end_time_ms_) {
-    return false;
-  }
-  UpdateAlpha(time_constant_ms);
-  return true;
-}
-
-void SmoothingFilterImpl::UpdateAlpha(int time_constant_ms) {
-  alpha_ = time_constant_ms == 0 ? 0.0f : std::exp(-1.0f / time_constant_ms);
-}
-
 void SmoothingFilterImpl::ExtrapolateLastSample(int64_t time_ms) {
   RTC_DCHECK_GE(time_ms, last_state_time_ms_);
   RTC_DCHECK(init_end_time_ms_);
diff --git a/common_audio/smoothing_filter.h b/common_audio/smoothing_filter.h
index 8ca6160..ce1a443 100644
--- a/common_audio/smoothing_filter.h
+++ b/common_audio/smoothing_filter.h
@@ -23,7 +23,6 @@
   virtual ~SmoothingFilter() = default;
   virtual void AddSample(float sample, Timestamp now) = 0;
   virtual std::optional<float> GetAverage(Timestamp now) = 0;
-  virtual bool SetTimeConstantMs(int time_constant_ms) = 0;
 };
 
 // SmoothingFilterImpl applies an exponential filter
@@ -39,8 +38,7 @@
   // filter uses a varying time constant so that a smaller time constant will be
   // applied to the earlier samples. This is to allow the the filter to adapt to
   // earlier samples quickly. After the initialization period, the time constant
-  // will be set to `init_time_ms` first and can be changed through
-  // `SetTimeConstantMs`.
+  // will be set to `init_time_ms`.
   explicit SmoothingFilterImpl(int init_time_ms);
 
   SmoothingFilterImpl() = delete;
@@ -51,22 +49,21 @@
 
   void AddSample(float sample, Timestamp now) override;
   std::optional<float> GetAverage(Timestamp now) override;
-  bool SetTimeConstantMs(int time_constant_ms) override;
 
   // Methods used for unittests.
   float alpha() const { return alpha_; }
 
  private:
-  void UpdateAlpha(int time_constant_ms);
   void ExtrapolateLastSample(int64_t time_ms);
 
   const int init_time_ms_;
   const float init_factor_;
   const float init_const_;
+  const float alpha_;
 
   std::optional<int64_t> init_end_time_ms_;
   float last_sample_;
-  float alpha_;
+
   float state_;
   int64_t last_state_time_ms_;
 };
diff --git a/common_audio/smoothing_filter_unittest.cc b/common_audio/smoothing_filter_unittest.cc
index 68a3182..28ff1f7 100644
--- a/common_audio/smoothing_filter_unittest.cc
+++ b/common_audio/smoothing_filter_unittest.cc
@@ -136,30 +136,4 @@
   EXPECT_EQ(kFirstSample, states.smoothing_filter.GetAverage(states.now));
 }
 
-TEST(SmoothingFilterTest, CannotChangeTimeConstantDuringInitialization) {
-  constexpr int kInitTimeMs = 100;
-  SmoothingFilterStates states(kInitTimeMs);
-  states.smoothing_filter.AddSample(0.0, states.now);
-
-  // During initialization, `SetTimeConstantMs` does not take effect.
-  states.now += TimeDelta::Millis(kInitTimeMs - 1);
-  states.smoothing_filter.AddSample(0.0, states.now);
-
-  EXPECT_FALSE(states.smoothing_filter.SetTimeConstantMs(kInitTimeMs * 2));
-  EXPECT_NE(std::exp(-1.0f / (kInitTimeMs * 2)),
-            states.smoothing_filter.alpha());
-
-  states.now += TimeDelta::Millis(1);
-  states.smoothing_filter.AddSample(0.0, states.now);
-  // When initialization finishes, the time constant should be come
-  // `kInitTimeConstantMs`.
-  EXPECT_FLOAT_EQ(std::exp(-1.0f / kInitTimeMs),
-                  states.smoothing_filter.alpha());
-
-  // After initialization, `SetTimeConstantMs` takes effect.
-  EXPECT_TRUE(states.smoothing_filter.SetTimeConstantMs(kInitTimeMs * 2));
-  EXPECT_FLOAT_EQ(std::exp(-1.0f / (kInitTimeMs * 2)),
-                  states.smoothing_filter.alpha());
-}
-
 }  // namespace webrtc
diff --git a/modules/audio_coding/codecs/opus/audio_encoder_opus.cc b/modules/audio_coding/codecs/opus/audio_encoder_opus.cc
index e9803f0..97aaddc 100644
--- a/modules/audio_coding/codecs/opus/audio_encoder_opus.cc
+++ b/modules/audio_coding/codecs/opus/audio_encoder_opus.cc
@@ -507,24 +507,8 @@
 void AudioEncoderOpusImpl::OnReceivedUplinkAllocation(
     BitrateAllocationUpdate update) {
   int target_audio_bitrate_bps = update.target_bitrate.bps();
-  std::optional<int64_t> bwe_period_ms =
-      update.bwe_period.IsFinite() ? std::make_optional(update.bwe_period.ms())
-                                   : std::nullopt;
   if (audio_network_adaptor_) {
     audio_network_adaptor_->SetTargetAudioBitrate(target_audio_bitrate_bps);
-    // We give smoothed bitrate allocation to audio network adaptor as
-    // the uplink bandwidth.
-    // The BWE spikes should not affect the bitrate smoother more than 25%.
-    // To simplify the calculations we use a step response as input signal.
-    // The step response of an exponential filter is
-    // u(t) = 1 - e^(-t / time_constant).
-    // In order to limit the affect of a BWE spike within 25% of its value
-    // before
-    // the next BWE update, we would choose a time constant that fulfills
-    // 1 - e^(-bwe_period_ms / time_constant) < 0.25
-    // Then 4 * bwe_period_ms is a good choice.
-    if (bwe_period_ms)
-      bitrate_smoother_->SetTimeConstantMs(*bwe_period_ms * 4);
     bitrate_smoother_->AddSample(target_audio_bitrate_bps,
                                  env_.clock().CurrentTime());
 
diff --git a/modules/audio_coding/codecs/opus/audio_encoder_opus_unittest.cc b/modules/audio_coding/codecs/opus/audio_encoder_opus_unittest.cc
index 290c46a..7503175 100644
--- a/modules/audio_coding/codecs/opus/audio_encoder_opus_unittest.cc
+++ b/modules/audio_coding/codecs/opus/audio_encoder_opus_unittest.cc
@@ -294,9 +294,10 @@
 
   BitrateAllocationUpdate update;
   update.target_bitrate = DataRate::BitsPerSec(30000);
-  update.bwe_period = TimeDelta::Millis(200);
   EXPECT_CALL(*states->mock_audio_network_adaptor,
               SetTargetAudioBitrate(update.target_bitrate.bps()));
+  EXPECT_CALL(*states->mock_bitrate_smoother,
+              AddSample(update.target_bitrate.bps(), _));
 
   states->encoder->OnReceivedUplinkAllocation(update);