NetEq: Don't forget to save the codec name

BUG=chromium:661362

Review-Url: https://codereview.webrtc.org/2472083002
Cr-Commit-Position: refs/heads/master@{#14909}
diff --git a/webrtc/modules/audio_coding/neteq/decoder_database.cc b/webrtc/modules/audio_coding/neteq/decoder_database.cc
index 483c9b9..fa120d2 100644
--- a/webrtc/modules/audio_coding/neteq/decoder_database.cc
+++ b/webrtc/modules/audio_coding/neteq/decoder_database.cc
@@ -27,24 +27,29 @@
 DecoderDatabase::~DecoderDatabase() = default;
 
 DecoderDatabase::DecoderInfo::DecoderInfo(const SdpAudioFormat& audio_format,
-                                          AudioDecoderFactory* factory)
-    : audio_format_(audio_format),
+                                          AudioDecoderFactory* factory,
+                                          const std::string& codec_name)
+    : name_(codec_name),
+      audio_format_(audio_format),
       factory_(factory),
       external_decoder_(nullptr),
       cng_decoder_(CngDecoder::Create(audio_format)),
       subtype_(SubtypeFromFormat(audio_format)) {}
 
+DecoderDatabase::DecoderInfo::DecoderInfo(const SdpAudioFormat& audio_format,
+                                          AudioDecoderFactory* factory)
+    : DecoderInfo(audio_format, factory, audio_format.name) {}
+
 DecoderDatabase::DecoderInfo::DecoderInfo(NetEqDecoder ct,
                                           AudioDecoderFactory* factory)
-    : audio_format_(*acm2::RentACodec::NetEqDecoderToSdpAudioFormat(ct)),
-      factory_(factory),
-      external_decoder_(nullptr),
-      cng_decoder_(CngDecoder::Create(audio_format_)),
-      subtype_(SubtypeFromFormat(audio_format_)) {}
+    : DecoderInfo(*acm2::RentACodec::NetEqDecoderToSdpAudioFormat(ct),
+                  factory) {}
 
 DecoderDatabase::DecoderInfo::DecoderInfo(const SdpAudioFormat& audio_format,
-                                          AudioDecoder* ext_dec)
-    : audio_format_(audio_format),
+                                          AudioDecoder* ext_dec,
+                                          const std::string& codec_name)
+    : name_(codec_name),
+      audio_format_(audio_format),
       factory_(nullptr),
       external_decoder_(ext_dec),
       subtype_(Subtype::kNormal) {
@@ -135,8 +140,7 @@
   if (!opt_format) {
     return kCodecNotSupported;
   }
-  DecoderInfo info(*opt_format, decoder_factory_);
-  info.name = name;
+  DecoderInfo info(*opt_format, decoder_factory_, name);
   auto ret =
       decoders_.insert(std::make_pair(rtp_payload_type, std::move(info)));
   if (ret.second == false) {
@@ -176,8 +180,7 @@
   const SdpAudioFormat format = opt_db_format.value_or({"arbitrary", 0, 0});
 
   std::pair<DecoderMap::iterator, bool> ret;
-  DecoderInfo info(format, decoder);
-  info.name = codec_name;
+  DecoderInfo info(format, decoder, codec_name);
   ret = decoders_.insert(std::make_pair(rtp_payload_type, std::move(info)));
   if (ret.second == false) {
     // Database already contains a decoder with type |rtp_payload_type|.
diff --git a/webrtc/modules/audio_coding/neteq/decoder_database.h b/webrtc/modules/audio_coding/neteq/decoder_database.h
index 157e022..6e17260 100644
--- a/webrtc/modules/audio_coding/neteq/decoder_database.h
+++ b/webrtc/modules/audio_coding/neteq/decoder_database.h
@@ -41,11 +41,16 @@
   // Class that stores decoder info in the database.
   class DecoderInfo {
    public:
+    DecoderInfo(const SdpAudioFormat& audio_format,
+                AudioDecoderFactory* factory,
+                const std::string& codec_name);
     explicit DecoderInfo(const SdpAudioFormat& audio_format,
                          AudioDecoderFactory* factory = nullptr);
     explicit DecoderInfo(NetEqDecoder ct,
                          AudioDecoderFactory* factory = nullptr);
-    DecoderInfo(const SdpAudioFormat& audio_format, AudioDecoder* ext_dec);
+    DecoderInfo(const SdpAudioFormat& audio_format,
+                AudioDecoder* ext_dec,
+                const std::string& codec_name);
     DecoderInfo(DecoderInfo&&);
     ~DecoderInfo();
 
@@ -85,12 +90,14 @@
     // Returns true if the decoder's format is named |name|.
     bool IsType(const std::string& name) const;
 
-    // TODO(ossu): |name| is kept here while we retain the old external decoder
-    //             interface. Remove this once using an AudioDecoderFactory has
-    //             supplanted the old functionality.
-    std::string name;
+    const std::string& get_name() const { return name_; }
 
    private:
+    // TODO(ossu): |name_| is kept here while we retain the old external
+    //             decoder interface. Remove this once using an
+    //             AudioDecoderFactory has supplanted the old functionality.
+    const std::string name_;
+
     const SdpAudioFormat audio_format_;
     AudioDecoderFactory* const factory_;
     mutable std::unique_ptr<AudioDecoder> decoder_;
diff --git a/webrtc/modules/audio_coding/neteq/decoder_database_unittest.cc b/webrtc/modules/audio_coding/neteq/decoder_database_unittest.cc
index 6c3b6c9..22bbf6c 100644
--- a/webrtc/modules/audio_coding/neteq/decoder_database_unittest.cc
+++ b/webrtc/modules/audio_coding/neteq/decoder_database_unittest.cc
@@ -81,7 +81,7 @@
   info = db.GetDecoderInfo(kPayloadType);
   ASSERT_TRUE(info != NULL);
   EXPECT_TRUE(info->IsType("pcmu"));
-  EXPECT_EQ(kCodecName, info->name);
+  EXPECT_EQ(kCodecName, info->get_name());
   EXPECT_EQ(decoder, db.GetDecoder(kPayloadType));
   info = db.GetDecoderInfo(kPayloadType + 1);  // Other payload type.
   EXPECT_TRUE(info == NULL);  // Should not be found.
@@ -150,8 +150,8 @@
   info = db.GetDecoderInfo(kPayloadType);
   ASSERT_TRUE(info != NULL);
   EXPECT_TRUE(info->IsType("pcmu"));
-  EXPECT_EQ(info->name, kCodecName);
-  EXPECT_EQ(kCodecName, info->name);
+  EXPECT_EQ(info->get_name(), kCodecName);
+  EXPECT_EQ(kCodecName, info->get_name());
   // Expect not to delete the decoder when removing it from the database, since
   // it was declared externally.
   EXPECT_CALL(decoder, Die()).Times(0);
diff --git a/webrtc/modules/audio_coding/neteq/neteq_impl.cc b/webrtc/modules/audio_coding/neteq/neteq_impl.cc
index e5cab16..8019e19 100644
--- a/webrtc/modules/audio_coding/neteq/neteq_impl.cc
+++ b/webrtc/modules/audio_coding/neteq/neteq_impl.cc
@@ -478,7 +478,7 @@
   CodecInst ci = {0};
   rtc::MsanMarkUninitialized(rtc::MakeArrayView(&ci, 1));
   ci.pltype = payload_type;
-  std::strncpy(ci.plname, di->name.c_str(), sizeof(ci.plname));
+  std::strncpy(ci.plname, di->get_name().c_str(), sizeof(ci.plname));
   ci.plname[sizeof(ci.plname) - 1] = '\0';
   ci.plfreq = di->IsRed() || di->IsDtmf() ? 8000 : di->SampleRateHz();
   AudioDecoder* const decoder = di->GetDecoder();