Remove last traces of deferred sequencing.

Bug: webrtc:11340
Change-Id: I761be67d42959192355f9f6f54ed1f735da1fe96
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/228646
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Per Åhgren <peah@webrtc.org>
Commit-Queue: Erik Språng <sprang@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34770}
diff --git a/audio/channel_send.cc b/audio/channel_send.cc
index 37a14b7..6fd2161 100644
--- a/audio/channel_send.cc
+++ b/audio/channel_send.cc
@@ -502,8 +502,6 @@
   configuration.rtcp_packet_type_counter_observer = this;
 
   configuration.local_media_ssrc = ssrc;
-  configuration.use_deferred_sequencing =
-      !field_trial::IsDisabled("WebRTC-Audio-DeferredSequencing");
 
   rtp_rtcp_ = ModuleRtpRtcpImpl2::Create(configuration);
   rtp_rtcp_->SetSendingMediaStatus(false);
diff --git a/call/rtp_video_sender.cc b/call/rtp_video_sender.cc
index f95c743..b778563 100644
--- a/call/rtp_video_sender.cc
+++ b/call/rtp_video_sender.cc
@@ -231,8 +231,6 @@
       crypto_options.sframe.require_frame_encryption;
   configuration.extmap_allow_mixed = rtp_config.extmap_allow_mixed;
   configuration.rtcp_report_interval_ms = rtcp_report_interval_ms;
-  configuration.use_deferred_sequencing = !absl::StartsWith(
-      trials.Lookup("WebRTC-Video-DeferredSequencing"), "Disabled");
   configuration.field_trials = &trials;
 
   std::vector<RtpStreamSender> rtp_streams;
diff --git a/modules/rtp_rtcp/source/rtp_rtcp_interface.h b/modules/rtp_rtcp/source/rtp_rtcp_interface.h
index c1a44fa..df5593c 100644
--- a/modules/rtp_rtcp/source/rtp_rtcp_interface.h
+++ b/modules/rtp_rtcp/source/rtp_rtcp_interface.h
@@ -146,10 +146,6 @@
     // https://tools.ietf.org/html/rfc3611#section-4.4 and #section-4.5
     bool non_sender_rtt_measurement = false;
 
-    // If true, sequence numbers are not assigned until after the pacer stage,
-    // in RtpSenderEgress.
-    bool use_deferred_sequencing = false;
-
    private:
     RTC_DISALLOW_COPY_AND_ASSIGN(Configuration);
   };
diff --git a/modules/rtp_rtcp/source/rtp_sender_egress.cc b/modules/rtp_rtcp/source/rtp_sender_egress.cc
index f2a74e1..89c5597 100644
--- a/modules/rtp_rtcp/source/rtp_sender_egress.cc
+++ b/modules/rtp_rtcp/source/rtp_sender_egress.cc
@@ -86,7 +86,6 @@
           !IsTrialSetTo(config.field_trials,
                         "WebRTC-SendSideBwe-WithOverhead",
                         "Disabled")),
-      deferred_sequencing_(config.use_deferred_sequencing),
       clock_(config.clock),
       packet_history_(packet_history),
       transport_(config.outgoing_transport),
@@ -134,23 +133,19 @@
   RTC_DCHECK_RUN_ON(&pacer_checker_);
   RTC_DCHECK(packet);
 
-  if (deferred_sequencing_) {
-    // Strict increasing of sequence numbers can only be guaranteed with
-    // deferred sequencing due to raciness with the pacer.
-    if (packet->Ssrc() == ssrc_ &&
-        packet->packet_type() != RtpPacketMediaType::kRetransmission) {
-      if (last_sent_seq_.has_value()) {
-        RTC_DCHECK_EQ(static_cast<uint16_t>(*last_sent_seq_ + 1),
-                      packet->SequenceNumber());
-      }
-      last_sent_seq_ = packet->SequenceNumber();
-    } else if (packet->Ssrc() == rtx_ssrc_) {
-      if (last_sent_rtx_seq_.has_value()) {
-        RTC_DCHECK_EQ(static_cast<uint16_t>(*last_sent_rtx_seq_ + 1),
-                      packet->SequenceNumber());
-      }
-      last_sent_rtx_seq_ = packet->SequenceNumber();
+  if (packet->Ssrc() == ssrc_ &&
+      packet->packet_type() != RtpPacketMediaType::kRetransmission) {
+    if (last_sent_seq_.has_value()) {
+      RTC_DCHECK_EQ(static_cast<uint16_t>(*last_sent_seq_ + 1),
+                    packet->SequenceNumber());
     }
+    last_sent_seq_ = packet->SequenceNumber();
+  } else if (packet->Ssrc() == rtx_ssrc_) {
+    if (last_sent_rtx_seq_.has_value()) {
+      RTC_DCHECK_EQ(static_cast<uint16_t>(*last_sent_rtx_seq_ + 1),
+                    packet->SequenceNumber());
+    }
+    last_sent_rtx_seq_ = packet->SequenceNumber();
   }
 
   RTC_DCHECK(packet->packet_type().has_value());
diff --git a/modules/rtp_rtcp/source/rtp_sender_egress.h b/modules/rtp_rtcp/source/rtp_sender_egress.h
index bf9076d..1fd7128 100644
--- a/modules/rtp_rtcp/source/rtp_sender_egress.h
+++ b/modules/rtp_rtcp/source/rtp_sender_egress.h
@@ -134,7 +134,6 @@
   const absl::optional<uint32_t> flexfec_ssrc_;
   const bool populate_network2_timestamp_;
   const bool send_side_bwe_with_overhead_;
-  const bool deferred_sequencing_;
   Clock* const clock_;
   RtpPacketHistory* const packet_history_;
   Transport* const transport_;
diff --git a/modules/rtp_rtcp/source/rtp_sender_egress_unittest.cc b/modules/rtp_rtcp/source/rtp_sender_egress_unittest.cc
index 4f3990c..d95a639 100644
--- a/modules/rtp_rtcp/source/rtp_sender_egress_unittest.cc
+++ b/modules/rtp_rtcp/source/rtp_sender_egress_unittest.cc
@@ -587,6 +587,7 @@
   // Send a media packet.
   std::unique_ptr<RtpPacketToSend> media_packet = BuildRtpPacket();
   media_packet->SetPayloadSize(6);
+  media_packet->SetSequenceNumber(kStartSequenceNumber);
   expected_transmitted_counter.packets += 1;
   expected_transmitted_counter.payload_bytes += media_packet->payload_size();
   expected_transmitted_counter.header_bytes += media_packet->headers_size();
@@ -606,8 +607,9 @@
   // and retransmitted packet statistics.
   std::unique_ptr<RtpPacketToSend> retransmission_packet = BuildRtpPacket();
   retransmission_packet->set_packet_type(RtpPacketMediaType::kRetransmission);
+  retransmission_packet->SetSequenceNumber(kStartSequenceNumber);
   retransmission_packet->set_retransmitted_sequence_number(
-      retransmission_packet->SequenceNumber());
+      kStartSequenceNumber);
   media_packet->SetPayloadSize(7);
   expected_transmitted_counter.packets += 1;
   expected_transmitted_counter.payload_bytes +=
@@ -636,6 +638,7 @@
   std::unique_ptr<RtpPacketToSend> padding_packet = BuildRtpPacket();
   padding_packet->set_packet_type(RtpPacketMediaType::kPadding);
   padding_packet->SetPadding(224);
+  padding_packet->SetSequenceNumber(kStartSequenceNumber + 1);
   expected_transmitted_counter.packets += 1;
   expected_transmitted_counter.padding_bytes += padding_packet->padding_size();
   expected_transmitted_counter.header_bytes += padding_packet->headers_size();