AudioCodingModule: Specify decoders using SdpAudioFormat

NetEq already uses SdpAudioFormat internally; this CL adds an
AudioCodingModule::RegisterReceiveCodec overload that accepts
SdpAudioFormat, and propagates it through AcmReceiver into NetEq.

The intention is to get rid of the other ways to specify decoders and
always use SdpAudioFormat. (And eventually to do the same for encoders
too.)

NOTRY=true
BUG=5801

Review-Url: https://codereview.webrtc.org/2365653004
Cr-Commit-Position: refs/heads/master@{#14506}
diff --git a/webrtc/modules/audio_coding/acm2/acm_receiver.cc b/webrtc/modules/audio_coding/acm2/acm_receiver.cc
index 89eee00..0b19310 100644
--- a/webrtc/modules/audio_coding/acm2/acm_receiver.cc
+++ b/webrtc/modules/audio_coding/acm2/acm_receiver.cc
@@ -230,6 +230,31 @@
   return 0;
 }
 
+bool AcmReceiver::AddCodec(int rtp_payload_type,
+                           const SdpAudioFormat& audio_format) {
+  const auto old_format = neteq_->GetDecoderFormat(rtp_payload_type);
+  if (old_format && *old_format == audio_format) {
+    // Re-registering the same codec. Do nothing and return.
+    return true;
+  }
+
+  if (neteq_->RemovePayloadType(rtp_payload_type) != NetEq::kOK &&
+      neteq_->LastError() != NetEq::kDecoderNotFound) {
+    LOG(LERROR) << "AcmReceiver::AddCodec: Could not remove existing decoder"
+                   " for payload type "
+                << rtp_payload_type;
+    return false;
+  }
+
+  const bool success =
+      neteq_->RegisterPayloadType(rtp_payload_type, audio_format);
+  if (!success) {
+    LOG(LERROR) << "AcmReceiver::AddCodec failed for payload type "
+                << rtp_payload_type << ", decoder format " << audio_format;
+  }
+  return success;
+}
+
 void AcmReceiver::FlushBuffers() {
   neteq_->FlushBuffers();
 }