Remove pending packets from the pacer when an RTP module is removed.

This CL adds functionality to remove packets matching a given SSRC from
the pacer queue, and calls that with any SSRCs used by an RTP module
when that module is removed.

Bug: chromium:1395081
Change-Id: I13c0285ddca600e784ad04a806727a508ede6dcc
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/287124
Reviewed-by: Jakob Ivarsson‎ <jakobi@webrtc.org>
Commit-Queue: Erik Språng <sprang@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Philip Eliasson <philipel@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38880}
diff --git a/call/rtp_video_sender.cc b/call/rtp_video_sender.cc
index 3ca72b1..de19b97 100644
--- a/call/rtp_video_sender.cc
+++ b/call/rtp_video_sender.cc
@@ -515,6 +515,17 @@
       // prevent any stray packets in the pacer from asynchronously arriving
       // to a disabled module.
       transport_->packet_router()->RemoveSendRtpModule(&rtp_module);
+
+      // Clear the pacer queue of any packets pertaining to this module.
+      transport_->packet_sender()->RemovePacketsForSsrc(rtp_module.SSRC());
+      if (rtp_module.RtxSsrc().has_value()) {
+        transport_->packet_sender()->RemovePacketsForSsrc(
+            *rtp_module.RtxSsrc());
+      }
+      if (rtp_module.FlexfecSsrc().has_value()) {
+        transport_->packet_sender()->RemovePacketsForSsrc(
+            *rtp_module.FlexfecSsrc());
+      }
     }
 
     // If set to false this module won't send media.