Reland "Remove CodecInst pt.1"

This is a reland of 056f9738bf7a3d16da45398239656e165c4e0851

Original change's description:
> Remove CodecInst pt.1
> 
> Update audio_coding tests to not use CodecInst.
> 
> Bug: webrtc:7626
> Change-Id: I880fb8d72d7d0a915d274e67feb6106f023697c2
> Reviewed-on: https://webrtc-review.googlesource.com/c/112594
> Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#25879}

Bug: webrtc:7626
Change-Id: I5d6ca0baf6230bfe9bf95c2c25496d2a56812d90
Reviewed-on: https://webrtc-review.googlesource.com/c/112942
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25902}
diff --git a/modules/audio_coding/test/TestAllCodecs.cc b/modules/audio_coding/test/TestAllCodecs.cc
index 0099b2a..aad80e8 100644
--- a/modules/audio_coding/test/TestAllCodecs.cc
+++ b/modules/audio_coding/test/TestAllCodecs.cc
@@ -14,13 +14,11 @@
 #include <limits>
 #include <string>
 
+#include "absl/strings/match.h"
 #include "api/audio_codecs/builtin_audio_decoder_factory.h"
 #include "api/audio_codecs/builtin_audio_encoder_factory.h"
-#include "common_types.h"  // NOLINT(build/include)
-#include "modules/audio_coding/codecs/audio_format_conversion.h"
-#include "modules/audio_coding/include/audio_coding_module.h"
 #include "modules/audio_coding/include/audio_coding_module_typedefs.h"
-#include "modules/audio_coding/test/utility.h"
+#include "modules/include/module_common_types.h"
 #include "rtc_base/logging.h"
 #include "rtc_base/stringencode.h"
 #include "rtc_base/strings/string_builder.h"
@@ -35,6 +33,11 @@
 // The test loops through all available mono codecs, encode at "a" sends over
 // the channel, and decodes at "b".
 
+#define CHECK_ERROR(f)                      \
+  do {                                      \
+    EXPECT_GE(f, 0) << "Error Calling API"; \
+  } while (0)
+
 namespace {
 const size_t kVariableSize = std::numeric_limits<size_t>::max();
 }
@@ -101,7 +104,7 @@
   payload_size_ = 0;
 }
 
-TestAllCodecs::TestAllCodecs(int test_mode)
+TestAllCodecs::TestAllCodecs()
     : acm_a_(AudioCodingModule::Create(
           AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))),
       acm_b_(AudioCodingModule::Create(
@@ -110,8 +113,6 @@
       test_count_(0),
       packet_size_samples_(0),
       packet_size_bytes_(0) {
-  // test_mode = 0 for silent test (auto test)
-  test_mode_ = test_mode;
 }
 
 TestAllCodecs::~TestAllCodecs() {
@@ -126,23 +127,28 @@
       webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
   infile_a_.Open(file_name, 32000, "rb");
 
-  if (test_mode_ == 0) {
-    RTC_LOG(LS_INFO) << "---------- TestAllCodecs ----------";
-  }
-
   acm_a_->InitializeReceiver();
   acm_b_->InitializeReceiver();
 
-  uint8_t num_encoders = acm_a_->NumberOfCodecs();
-  CodecInst my_codec_param;
-  for (uint8_t n = 0; n < num_encoders; n++) {
-    acm_b_->Codec(n, &my_codec_param);
-    if (!strcmp(my_codec_param.plname, "opus")) {
-      my_codec_param.channels = 1;
-    }
-    acm_b_->RegisterReceiveCodec(my_codec_param.pltype,
-                                 CodecInstToSdp(my_codec_param));
-  }
+  acm_b_->SetReceiveCodecs({{103, {"ISAC", 16000, 1}},
+                            {104, {"ISAC", 32000, 1}},
+                            {107, {"L16", 8000, 1}},
+                            {108, {"L16", 16000, 1}},
+                            {109, {"L16", 32000, 1}},
+                            {111, {"L16", 8000, 2}},
+                            {112, {"L16", 16000, 2}},
+                            {113, {"L16", 32000, 2}},
+                            {0, {"PCMU", 8000, 1}},
+                            {110, {"PCMU", 8000, 2}},
+                            {8, {"PCMA", 8000, 1}},
+                            {118, {"PCMA", 8000, 2}},
+                            {102, {"ILBC", 8000, 1}},
+                            {9, {"G722", 8000, 1}},
+                            {119, {"G722", 8000, 2}},
+                            {120, {"OPUS", 48000, 2, {{"stereo", "1"}}}},
+                            {13, {"CN", 8000, 1}},
+                            {98, {"CN", 16000, 1}},
+                            {99, {"CN", 32000, 1}}});
 
   // Create and connect the channel
   channel_a_to_b_ = new TestPack;
@@ -151,9 +157,6 @@
 
   // All codecs are tested for all allowed sampling frequencies, rates and
   // packet sizes.
-  if (test_mode_ != 0) {
-    printf("===============================================================\n");
-  }
   test_count_++;
   OpenOutFile(test_count_);
   char codec_g722[] = "G722";
@@ -171,9 +174,6 @@
   Run(channel_a_to_b_);
   outfile_b_.Close();
 #ifdef WEBRTC_CODEC_ILBC
-  if (test_mode_ != 0) {
-    printf("===============================================================\n");
-  }
   test_count_++;
   OpenOutFile(test_count_);
   char codec_ilbc[] = "ILBC";
@@ -188,9 +188,6 @@
   outfile_b_.Close();
 #endif
 #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX))
-  if (test_mode_ != 0) {
-    printf("===============================================================\n");
-  }
   test_count_++;
   OpenOutFile(test_count_);
   char codec_isac[] = "ISAC";
@@ -205,9 +202,6 @@
   outfile_b_.Close();
 #endif
 #ifdef WEBRTC_CODEC_ISAC
-  if (test_mode_ != 0) {
-    printf("===============================================================\n");
-  }
   test_count_++;
   OpenOutFile(test_count_);
   RegisterSendCodec('A', codec_isac, 32000, -1, 960, kVariableSize);
@@ -220,9 +214,6 @@
   Run(channel_a_to_b_);
   outfile_b_.Close();
 #endif
-  if (test_mode_ != 0) {
-    printf("===============================================================\n");
-  }
   test_count_++;
   OpenOutFile(test_count_);
   char codec_l16[] = "L16";
@@ -235,9 +226,7 @@
   RegisterSendCodec('A', codec_l16, 8000, 128000, 320, 0);
   Run(channel_a_to_b_);
   outfile_b_.Close();
-  if (test_mode_ != 0) {
-    printf("===============================================================\n");
-  }
+
   test_count_++;
   OpenOutFile(test_count_);
   RegisterSendCodec('A', codec_l16, 16000, 256000, 160, 0);
@@ -249,9 +238,7 @@
   RegisterSendCodec('A', codec_l16, 16000, 256000, 640, 0);
   Run(channel_a_to_b_);
   outfile_b_.Close();
-  if (test_mode_ != 0) {
-    printf("===============================================================\n");
-  }
+
   test_count_++;
   OpenOutFile(test_count_);
   RegisterSendCodec('A', codec_l16, 32000, 512000, 320, 0);
@@ -259,9 +246,7 @@
   RegisterSendCodec('A', codec_l16, 32000, 512000, 640, 0);
   Run(channel_a_to_b_);
   outfile_b_.Close();
-  if (test_mode_ != 0) {
-    printf("===============================================================\n");
-  }
+
   test_count_++;
   OpenOutFile(test_count_);
   char codec_pcma[] = "PCMA";
@@ -277,9 +262,7 @@
   Run(channel_a_to_b_);
   RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, 0);
   Run(channel_a_to_b_);
-  if (test_mode_ != 0) {
-    printf("===============================================================\n");
-  }
+
   char codec_pcmu[] = "PCMU";
   RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, 0);
   Run(channel_a_to_b_);
@@ -295,9 +278,6 @@
   Run(channel_a_to_b_);
   outfile_b_.Close();
 #ifdef WEBRTC_CODEC_OPUS
-  if (test_mode_ != 0) {
-    printf("===============================================================\n");
-  }
   test_count_++;
   OpenOutFile(test_count_);
   char codec_opus[] = "OPUS";
@@ -317,24 +297,6 @@
   Run(channel_a_to_b_);
   outfile_b_.Close();
 #endif
-  if (test_mode_ != 0) {
-    printf("===============================================================\n");
-
-    /* Print out all codecs that were not tested in the run */
-    printf("The following codecs was not included in the test:\n");
-#ifndef WEBRTC_CODEC_ILBC
-    printf("   iLBC\n");
-#endif
-#ifndef WEBRTC_CODEC_ISAC
-    printf("   ISAC float\n");
-#endif
-#ifndef WEBRTC_CODEC_ISACFX
-    printf("   ISAC fix\n");
-#endif
-
-    printf("\nTo complete the test, listen to the %d number of output files.\n",
-           test_count_);
-  }
 }
 
 // Register Codec to use in the test
@@ -354,21 +316,21 @@
                                       int rate,
                                       int packet_size,
                                       size_t extra_byte) {
-  if (test_mode_ != 0) {
-    // Print out codec and settings.
-    printf("codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name,
-           sampling_freq_hz, rate, packet_size);
-  }
-
   // Store packet-size in samples, used to validate the received packet.
   // If G.722, store half the size to compensate for the timestamp bug in the
   // RFC for G.722.
   // If iSAC runs in adaptive mode, packet size in samples can change on the
   // fly, so we exclude this test by setting |packet_size_samples_| to -1.
-  if (!strcmp(codec_name, "G722")) {
+  int clockrate_hz = sampling_freq_hz;
+  size_t num_channels = 1;
+  if (absl::EqualsIgnoreCase(codec_name, "G722")) {
     packet_size_samples_ = packet_size / 2;
-  } else if (!strcmp(codec_name, "ISAC") && (rate == -1)) {
+    clockrate_hz = sampling_freq_hz / 2;
+  } else if (absl::EqualsIgnoreCase(codec_name, "ISAC") && (rate == -1)) {
     packet_size_samples_ = -1;
+  } else if (absl::EqualsIgnoreCase(codec_name, "OPUS")) {
+    packet_size_samples_ = packet_size;
+    num_channels = 2;
   } else {
     packet_size_samples_ = packet_size;
   }
@@ -402,16 +364,9 @@
   }
   ASSERT_TRUE(my_acm != NULL);
 
-  // Get all codec parameters before registering
-  CodecInst my_codec_param;
-  CHECK_ERROR(AudioCodingModule::Codec(codec_name, &my_codec_param,
-                                       sampling_freq_hz, 1));
-  my_codec_param.rate = rate;
-  my_codec_param.pacsize = packet_size;
-
   auto factory = CreateBuiltinAudioEncoderFactory();
   constexpr int payload_type = 17;
-  SdpAudioFormat format = CodecInstToSdp(my_codec_param);
+  SdpAudioFormat format = { codec_name, clockrate_hz, num_channels };
   format.parameters["ptime"] = rtc::ToString(rtc::CheckedDivExact(
       packet_size, rtc::CheckedDivExact(sampling_freq_hz, 1000)));
   my_acm->SetEncoder(
@@ -485,11 +440,4 @@
   outfile_b_.Open(filename, 32000, "wb");
 }
 
-void TestAllCodecs::DisplaySendReceiveCodec() {
-  CodecInst my_codec_param;
-  printf("%s -> ", acm_a_->SendCodec()->plname);
-  acm_b_->ReceiveCodec(&my_codec_param);
-  printf("%s\n", my_codec_param.plname);
-}
-
 }  // namespace webrtc