Using unit classes in BitrateAllocationUpdate struct.

This prepares for moving BitrateAllocationUpdate to API.

Bug: webrtc:9718
Change-Id: Ib2bcedb6b68fde33b6a2466f40829e86438aa973
Reviewed-on: https://webrtc-review.googlesource.com/c/111507
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25737}
diff --git a/call/BUILD.gn b/call/BUILD.gn
index 577cab8..c1dc650 100644
--- a/call/BUILD.gn
+++ b/call/BUILD.gn
@@ -164,6 +164,8 @@
     "bitrate_allocator.h",
   ]
   deps = [
+    "../api/units:data_rate",
+    "../api/units:time_delta",
     "../modules/bitrate_controller",
     "../rtc_base:checks",
     "../rtc_base:rtc_base_approved",
diff --git a/call/bitrate_allocator.cc b/call/bitrate_allocator.cc
index 0fb1bf0..d3cb227 100644
--- a/call/bitrate_allocator.cc
+++ b/call/bitrate_allocator.cc
@@ -55,6 +55,7 @@
       last_non_zero_bitrate_bps_(kDefaultBitrateBps),
       last_fraction_loss_(0),
       last_rtt_(0),
+      last_bwe_period_ms_(1000),
       num_pause_events_(0),
       clock_(Clock::GetRealTimeClock()),
       last_bwe_log_time_(0),
@@ -115,10 +116,13 @@
   for (auto& config : bitrate_observer_configs_) {
     uint32_t allocated_bitrate = allocation[config.observer];
     uint32_t allocated_bandwidth = bandwidth_allocation[config.observer];
-    uint32_t protection_bitrate =
-        config.observer->OnBitrateUpdated(BitrateAllocationUpdate{
-            allocated_bitrate, allocated_bandwidth, last_fraction_loss_,
-            last_rtt_, last_bwe_period_ms_});
+    BitrateAllocationUpdate update;
+    update.target_bitrate = DataRate::bps(allocated_bitrate);
+    update.link_capacity = DataRate::bps(allocated_bandwidth);
+    update.packet_loss_ratio = last_fraction_loss_ / 256.0;
+    update.round_trip_time = TimeDelta::ms(last_rtt_);
+    update.bwe_period = TimeDelta::ms(last_bwe_period_ms_);
+    uint32_t protection_bitrate = config.observer->OnBitrateUpdated(update);
 
     if (allocated_bitrate == 0 && config.allocated_bitrate_bps > 0) {
       if (target_bitrate_bps > 0)
@@ -179,10 +183,13 @@
     for (auto& config : bitrate_observer_configs_) {
       uint32_t allocated_bitrate = allocation[config.observer];
       uint32_t bandwidth = bandwidth_allocation[config.observer];
-      uint32_t protection_bitrate =
-          config.observer->OnBitrateUpdated(BitrateAllocationUpdate{
-              allocated_bitrate, bandwidth, last_fraction_loss_, last_rtt_,
-              last_bwe_period_ms_});
+      BitrateAllocationUpdate update;
+      update.target_bitrate = DataRate::bps(allocated_bitrate);
+      update.link_capacity = DataRate::bps(bandwidth);
+      update.packet_loss_ratio = last_fraction_loss_ / 256.0;
+      update.round_trip_time = TimeDelta::ms(last_rtt_);
+      update.bwe_period = TimeDelta::ms(last_bwe_period_ms_);
+      uint32_t protection_bitrate = config.observer->OnBitrateUpdated(update);
       config.allocated_bitrate_bps = allocated_bitrate;
       if (allocated_bitrate > 0)
         config.media_ratio = MediaRatio(allocated_bitrate, protection_bitrate);
@@ -191,8 +198,14 @@
     // Currently, an encoder is not allowed to produce frames.
     // But we still have to return the initial config bitrate + let the
     // observer know that it can not produce frames.
-    observer->OnBitrateUpdated(BitrateAllocationUpdate{
-        0, 0, last_fraction_loss_, last_rtt_, last_bwe_period_ms_});
+
+    BitrateAllocationUpdate update;
+    update.target_bitrate = DataRate::Zero();
+    update.link_capacity = DataRate::Zero();
+    update.packet_loss_ratio = last_fraction_loss_ / 256.0;
+    update.round_trip_time = TimeDelta::ms(last_rtt_);
+    update.bwe_period = TimeDelta::ms(last_bwe_period_ms_);
+    observer->OnBitrateUpdated(update);
   }
   UpdateAllocationLimits();
 }
diff --git a/call/bitrate_allocator.h b/call/bitrate_allocator.h
index 060bfbf..dbdd14f 100644
--- a/call/bitrate_allocator.h
+++ b/call/bitrate_allocator.h
@@ -19,6 +19,8 @@
 #include <utility>
 #include <vector>
 
+#include "api/units/data_rate.h"
+#include "api/units/time_delta.h"
 #include "rtc_base/bitrateallocationstrategy.h"
 #include "rtc_base/sequenced_task_checker.h"
 
@@ -27,12 +29,11 @@
 class Clock;
 
 struct BitrateAllocationUpdate {
-  // TODO(srte): Rename to target_bitrate.
-  uint32_t bitrate_bps;
-  uint32_t link_capacity_bps;
-  uint8_t fraction_loss;
-  int64_t rtt;
-  int64_t bwe_period_ms;
+  DataRate target_bitrate = DataRate::Zero();
+  DataRate link_capacity = DataRate::Zero();
+  double packet_loss_ratio = 0;
+  TimeDelta round_trip_time = TimeDelta::PlusInfinity();
+  TimeDelta bwe_period = TimeDelta::PlusInfinity();
 };
 // Used by all send streams with adaptive bitrate, to get the currently
 // allocated bitrate for the send stream. The current network properties are
diff --git a/call/bitrate_allocator_unittest.cc b/call/bitrate_allocator_unittest.cc
index e0aae7b..0771f79 100644
--- a/call/bitrate_allocator_unittest.cc
+++ b/call/bitrate_allocator_unittest.cc
@@ -60,11 +60,12 @@
   }
 
   uint32_t OnBitrateUpdated(BitrateAllocationUpdate update) override {
-    last_bitrate_bps_ = update.bitrate_bps;
-    last_fraction_loss_ = update.fraction_loss;
-    last_rtt_ms_ = update.rtt;
-    last_probing_interval_ms_ = update.bwe_period_ms;
-    return update.bitrate_bps * protection_ratio_;
+    last_bitrate_bps_ = update.target_bitrate.bps();
+    last_fraction_loss_ =
+        rtc::dchecked_cast<uint8_t>(update.packet_loss_ratio * 256);
+    last_rtt_ms_ = update.round_trip_time.ms();
+    last_probing_interval_ms_ = update.bwe_period.ms();
+    return update.target_bitrate.bps() * protection_ratio_;
   }
   uint32_t last_bitrate_bps_;
   uint8_t last_fraction_loss_;