Base overhead calculation for audio priority rate on available data.

This improves the accuracy of the priority bitrate on IPv6 networks
and when the min frame length is longer than 20 ms. Unless either of
those are true, there's no significant change in behavior.

Bug: webrtc:11001
Change-Id: I29530655cb607a8e7e8186431cd9362ca397910b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/155521
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29375}
diff --git a/audio/audio_send_stream.cc b/audio/audio_send_stream.cc
index 7f14768..22bd983 100644
--- a/audio/audio_send_stream.cc
+++ b/audio/audio_send_stream.cc
@@ -877,17 +877,23 @@
   // TODO(srte): Add overhead compensation here.
   auto constraints = GetMinMaxBitrateConstraints();
 
-  DataRate max_overhead = DataRate::Zero();
+  DataRate priority_bitrate = allocation_settings_.priority_bitrate;
   if (send_side_bwe_with_overhead_) {
-    // TODO(srte): Respect |use_legacy_overhead_calculation_| here as well.
-    // OverheadPerPacket = Ipv4(20B) + UDP(8B) + SRTP(10B) + RTP(12)
-    constexpr int kOverheadPerPacket = 20 + 8 + 10 + 12;
-    const TimeDelta kMinPacketDuration = TimeDelta::ms(20);
-    max_overhead = DataSize::bytes(kOverheadPerPacket) / kMinPacketDuration;
+    if (use_legacy_overhead_calculation_) {
+      // OverheadPerPacket = Ipv4(20B) + UDP(8B) + SRTP(10B) + RTP(12)
+      constexpr int kOverheadPerPacket = 20 + 8 + 10 + 12;
+      const TimeDelta kMinPacketDuration = TimeDelta::ms(20);
+      DataRate max_overhead =
+          DataSize::bytes(kOverheadPerPacket) / kMinPacketDuration;
+      priority_bitrate += max_overhead;
+    } else {
+      RTC_DCHECK(frame_length_range_);
+      const DataSize kOverheadPerPacket =
+          DataSize::bytes(total_packet_overhead_bytes_);
+      DataRate max_overhead = kOverheadPerPacket / frame_length_range_->first;
+      priority_bitrate += max_overhead;
+    }
   }
-  DataRate priority_bitrate =
-      allocation_settings_.priority_bitrate + max_overhead;
-
   if (allocation_settings_.priority_bitrate_raw)
     priority_bitrate = *allocation_settings_.priority_bitrate_raw;