NetEq decoder database: Don't keep track of sample rate for builtin decoders

This allows us to get rid of the function that computes it, which gets
us one step closer to getting rid of the NetEqDecoder type.

BUG=webrtc:5801

Review-Url: https://codereview.webrtc.org/2021063002
Cr-Commit-Position: refs/heads/master@{#12974}
diff --git a/webrtc/modules/audio_coding/neteq/decoder_database.h b/webrtc/modules/audio_coding/neteq/decoder_database.h
index 72b43df..4169dc2 100644
--- a/webrtc/modules/audio_coding/neteq/decoder_database.h
+++ b/webrtc/modules/audio_coding/neteq/decoder_database.h
@@ -41,9 +41,10 @@
   // Class that stores decoder info in the database.
   class DecoderInfo {
    public:
+    DecoderInfo(NetEqDecoder ct, const std::string& nm);
     DecoderInfo(NetEqDecoder ct,
                 const std::string& nm,
-                int fs,
+                int sample_rate_hz,
                 AudioDecoder* ext_dec);
     DecoderInfo(DecoderInfo&&);
     ~DecoderInfo();
@@ -55,14 +56,35 @@
     // always recreate it later if we need it.)
     void DropDecoder() { decoder_.reset(); }
 
+    int SampleRateHz() const {
+      RTC_DCHECK_EQ(1, !!decoder_ + !!external_decoder + !!cng_decoder_);
+      return decoder_ ? decoder_->SampleRateHz()
+                      : external_decoder ? external_decoder->sample_rate_hz
+                                         : cng_decoder_->sample_rate_hz;
+    }
+
     const NetEqDecoder codec_type;
     const std::string name;
-    const int fs_hz;
-    AudioDecoder* const external_decoder;
 
    private:
     const rtc::Optional<SdpAudioFormat> audio_format_;
     std::unique_ptr<AudioDecoder> decoder_;
+
+    // Set iff this is an external decoder.
+    struct ExternalDecoder {
+      // TODO(kwiberg): Remove sample_rate_hz once we can trust all decoders to
+      // implement SampleRateHz().
+      int sample_rate_hz;
+      AudioDecoder* decoder;
+    };
+    const rtc::Optional<ExternalDecoder> external_decoder;
+
+    // Set iff this is a comfort noise decoder.
+    struct CngDecoder {
+      static rtc::Optional<CngDecoder> Create(NetEqDecoder ct);
+      int sample_rate_hz;
+    };
+    const rtc::Optional<CngDecoder> cng_decoder_;
   };
 
   // Maximum value for 8 bits, and an invalid RTP payload type (since it is