Use NetEq::GetCurrentDecoderFormat in AcmReceiver.

This replaces the payload type tracking in AcmReceiver with the one in
NetEq and should be a noop.

Bug: None
Change-Id: Iaf124b5e56a646f994b5c2af65d349ede550b7fd
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/360840
Commit-Queue: Jakob Ivarsson‎ <jakobi@webrtc.org>
Reviewed-by: Tomas Lundqvist <tomasl@google.com>
Cr-Commit-Position: refs/heads/main@{#42875}
diff --git a/modules/audio_coding/acm2/acm_receiver.cc b/modules/audio_coding/acm2/acm_receiver.cc
index ca79a57..e203a32 100644
--- a/modules/audio_coding/acm2/acm_receiver.cc
+++ b/modules/audio_coding/acm2/acm_receiver.cc
@@ -91,11 +91,12 @@
 }
 
 absl::optional<int> AcmReceiver::last_packet_sample_rate_hz() const {
-  MutexLock lock(&mutex_);
-  if (!last_decoder_) {
+  absl::optional<NetEq::DecoderFormat> decoder =
+      neteq_->GetCurrentDecoderFormat();
+  if (!decoder) {
     return absl::nullopt;
   }
-  return last_decoder_->sample_rate_hz;
+  return decoder->sample_rate_hz;
 }
 
 int AcmReceiver::last_output_sample_rate_hz() const {
@@ -109,36 +110,6 @@
     neteq_->InsertEmptyPacket(rtp_header);
     return 0;
   }
-
-  int payload_type = rtp_header.payloadType;
-  auto format = neteq_->GetDecoderFormat(payload_type);
-  if (format && absl::EqualsIgnoreCase(format->sdp_format.name, "red")) {
-    // This is a RED packet. Get the format of the audio codec.
-    payload_type = incoming_payload[0] & 0x7f;
-    format = neteq_->GetDecoderFormat(payload_type);
-  }
-  if (!format) {
-    RTC_LOG_F(LS_ERROR) << "Payload-type " << payload_type
-                        << " is not registered.";
-    return -1;
-  }
-
-  {
-    MutexLock lock(&mutex_);
-    if (absl::EqualsIgnoreCase(format->sdp_format.name, "cn")) {
-      if (last_decoder_ && last_decoder_->num_channels > 1) {
-        // This is a CNG and the audio codec is not mono, so skip pushing in
-        // packets into NetEq.
-        return 0;
-      }
-    } else {
-      last_decoder_ = DecoderInfo{/*payload_type=*/payload_type,
-                                  /*sample_rate_hz=*/format->sample_rate_hz,
-                                  /*num_channels=*/format->num_channels,
-                                  /*sdp_format=*/std::move(format->sdp_format)};
-    }
-  }  // `mutex_` is released.
-
   if (neteq_->InsertPacket(rtp_header, incoming_payload, receive_time) < 0) {
     RTC_LOG(LS_ERROR) << "AcmReceiver::InsertPacket "
                       << static_cast<int>(rtp_header.payloadType)
@@ -237,12 +208,12 @@
 
 absl::optional<std::pair<int, SdpAudioFormat>> AcmReceiver::LastDecoder()
     const {
-  MutexLock lock(&mutex_);
-  if (!last_decoder_) {
+  absl::optional<NetEq::DecoderFormat> decoder =
+      neteq_->GetCurrentDecoderFormat();
+  if (!decoder) {
     return absl::nullopt;
   }
-  RTC_DCHECK_NE(-1, last_decoder_->payload_type);
-  return std::make_pair(last_decoder_->payload_type, last_decoder_->sdp_format);
+  return std::make_pair(decoder->payload_type, decoder->sdp_format);
 }
 
 void AcmReceiver::GetNetworkStatistics(
diff --git a/modules/audio_coding/acm2/acm_receiver.h b/modules/audio_coding/acm2/acm_receiver.h
index 92305da..1e14248 100644
--- a/modules/audio_coding/acm2/acm_receiver.h
+++ b/modules/audio_coding/acm2/acm_receiver.h
@@ -219,18 +219,10 @@
   void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
 
  private:
-  struct DecoderInfo {
-    int payload_type;
-    int sample_rate_hz;
-    int num_channels;
-    SdpAudioFormat sdp_format;
-  };
-
   uint32_t NowInTimestamp(int decoder_sampling_rate) const;
 
   const Environment env_;
   mutable Mutex mutex_;
-  absl::optional<DecoderInfo> last_decoder_ RTC_GUARDED_BY(mutex_);
   ACMResampler resampler_ RTC_GUARDED_BY(mutex_);
   CallStatistics call_stats_ RTC_GUARDED_BY(mutex_);
   const std::unique_ptr<NetEq> neteq_;  // NetEq is thread-safe; no lock needed.