Replaces OverheadObserver with simple getter.

This interface has a couple of issues. Primarily for me, it makes it
difficult work with the paced sender as we need to either temporarily
release a lock or force a thread-handover in order to avoid a cyclic
lock order.

For video in particular, its behavior is also falky since header sizes
can vary not only form frame to frame, but from packet to packet within
a frame (e.g. TimingInfo extension is only on the last packet, if set).
On bitrate allocation, the last reported value is picked, leading to
timing issues affecting the bitrate set.

This CL removes the callback interface and instead we simply poll the
RTP module for a packet overhead. This consists of an expected overhead
based on which non-volatile header extensions are registered (so for
instance AbsoluteCaptureTime is disregarded since it's only populated
once per second). The overhead estimation is a little less accurate but
instead simpler and deterministic.

Bug: webrtc:10809
Change-Id: I2c3d3fcca6ad35704c4c1b6b9e0a39227aada1ea
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/173704
Commit-Queue: Erik Språng <sprang@webrtc.org>
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Reviewed-by: Ali Tofigh <alito@webrtc.org>
Reviewed-by: Jakob Ivarsson <jakobi@webrtc.org>
Reviewed-by: Per Åhgren <peah@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31185}
diff --git a/audio/audio_send_stream_unittest.cc b/audio/audio_send_stream_unittest.cc
index ea753f7..334fdf5 100644
--- a/audio/audio_send_stream_unittest.cc
+++ b/audio/audio_send_stream_unittest.cc
@@ -660,9 +660,9 @@
       "WebRTC-Audio-LegacyOverhead/Disabled/");
   for (bool use_null_audio_processing : {false, true}) {
     ConfigHelper helper(true, true, use_null_audio_processing);
+    EXPECT_CALL(*helper.rtp_rtcp(), ExpectedPerPacketOverhead)
+        .WillRepeatedly(Return(kOverheadPerPacket.bytes<size_t>()));
     auto send_stream = helper.CreateAudioSendStream();
-    EXPECT_CALL(*helper.channel_send(), CallEncoder(_)).Times(1);
-    send_stream->OnOverheadChanged(kOverheadPerPacket.bytes<size_t>());
     const DataRate bitrate =
         DataRate::BitsPerSec(helper.config().max_bitrate_bps) +
         kMaxOverheadRate;
@@ -684,9 +684,9 @@
       "WebRTC-Audio-Allocation/min:6kbps,max:64kbps/");
   for (bool use_null_audio_processing : {false, true}) {
     ConfigHelper helper(true, true, use_null_audio_processing);
+    EXPECT_CALL(*helper.rtp_rtcp(), ExpectedPerPacketOverhead)
+        .WillRepeatedly(Return(kOverheadPerPacket.bytes<size_t>()));
     auto send_stream = helper.CreateAudioSendStream();
-    EXPECT_CALL(*helper.channel_send(), CallEncoder(_)).Times(1);
-    send_stream->OnOverheadChanged(kOverheadPerPacket.bytes<size_t>());
     const DataRate bitrate = DataRate::KilobitsPerSec(6) + kMinOverheadRate;
     EXPECT_CALL(*helper.channel_send(),
                 OnBitrateAllocation(Field(
@@ -706,9 +706,9 @@
       "WebRTC-Audio-Allocation/min:6kbps,max:64kbps/");
   for (bool use_null_audio_processing : {false, true}) {
     ConfigHelper helper(true, true, use_null_audio_processing);
+    EXPECT_CALL(*helper.rtp_rtcp(), ExpectedPerPacketOverhead)
+        .WillRepeatedly(Return(kOverheadPerPacket.bytes<size_t>()));
     auto send_stream = helper.CreateAudioSendStream();
-    EXPECT_CALL(*helper.channel_send(), CallEncoder(_)).Times(1);
-    send_stream->OnOverheadChanged(kOverheadPerPacket.bytes<size_t>());
     const DataRate bitrate = DataRate::KilobitsPerSec(64) + kMaxOverheadRate;
     EXPECT_CALL(*helper.channel_send(),
                 OnBitrateAllocation(Field(
@@ -804,36 +804,56 @@
   }
 }
 
-TEST(AudioSendStreamTest, OnAudioOverheadChanged) {
+TEST(AudioSendStreamTest, AudioOverheadChanged) {
   for (bool use_null_audio_processing : {false, true}) {
     ConfigHelper helper(false, true, use_null_audio_processing);
+    const size_t audio_overhead_per_packet_bytes = 555;
+    EXPECT_CALL(*helper.rtp_rtcp(), ExpectedPerPacketOverhead)
+        .WillRepeatedly(Return(audio_overhead_per_packet_bytes));
     auto send_stream = helper.CreateAudioSendStream();
     auto new_config = helper.config();
 
-    // CallEncoder will be called on overhead change.
-    EXPECT_CALL(*helper.channel_send(), CallEncoder(::testing::_)).Times(1);
+    BitrateAllocationUpdate update;
+    update.target_bitrate =
+        DataRate::BitsPerSec(helper.config().max_bitrate_bps) +
+        kMaxOverheadRate;
+    EXPECT_CALL(*helper.channel_send(), OnBitrateAllocation);
+    helper.worker()->SendTask([&] { send_stream->OnBitrateUpdated(update); },
+                              RTC_FROM_HERE);
 
-    const size_t audio_overhead_per_packet_bytes = 555;
-    send_stream->OnOverheadChanged(audio_overhead_per_packet_bytes);
     EXPECT_EQ(audio_overhead_per_packet_bytes,
               send_stream->TestOnlyGetPerPacketOverheadBytes());
+
+    EXPECT_CALL(*helper.rtp_rtcp(), ExpectedPerPacketOverhead)
+        .WillRepeatedly(Return(audio_overhead_per_packet_bytes + 20));
+    EXPECT_CALL(*helper.channel_send(), OnBitrateAllocation);
+    helper.worker()->SendTask([&] { send_stream->OnBitrateUpdated(update); },
+                              RTC_FROM_HERE);
+
+    EXPECT_EQ(audio_overhead_per_packet_bytes + 20,
+              send_stream->TestOnlyGetPerPacketOverheadBytes());
   }
 }
 
 TEST(AudioSendStreamTest, OnAudioAndTransportOverheadChanged) {
   for (bool use_null_audio_processing : {false, true}) {
     ConfigHelper helper(false, true, use_null_audio_processing);
+    const size_t audio_overhead_per_packet_bytes = 555;
+    EXPECT_CALL(*helper.rtp_rtcp(), ExpectedPerPacketOverhead)
+        .WillRepeatedly(Return(audio_overhead_per_packet_bytes));
     auto send_stream = helper.CreateAudioSendStream();
     auto new_config = helper.config();
 
-    // CallEncoder will be called when each of overhead changes.
-    EXPECT_CALL(*helper.channel_send(), CallEncoder(::testing::_)).Times(2);
-
     const size_t transport_overhead_per_packet_bytes = 333;
     send_stream->SetTransportOverhead(transport_overhead_per_packet_bytes);
 
-    const size_t audio_overhead_per_packet_bytes = 555;
-    send_stream->OnOverheadChanged(audio_overhead_per_packet_bytes);
+    BitrateAllocationUpdate update;
+    update.target_bitrate =
+        DataRate::BitsPerSec(helper.config().max_bitrate_bps) +
+        kMaxOverheadRate;
+    EXPECT_CALL(*helper.channel_send(), OnBitrateAllocation);
+    helper.worker()->SendTask([&] { send_stream->OnBitrateUpdated(update); },
+                              RTC_FROM_HERE);
 
     EXPECT_EQ(
         transport_overhead_per_packet_bytes + audio_overhead_per_packet_bytes,