Reset speech encoder before hooking it up to RED or CNG

Commit 7e0c7d49 ("Add support for external encoders in ACM") changed
things around so that we no longer recreate the speech encoder when
adding CNG or RED to an existing encoder. This isn't correct, since
those two expect to be in sync with the speech encoder they work with.
Solve the problem by resetting the speech encoder before hooking in


Review URL:

Cr-Commit-Position: refs/heads/master@{#9307}
diff --git a/webrtc/modules/audio_coding/main/acm2/ b/webrtc/modules/audio_coding/main/acm2/
index 5f0671d..4d214be 100644
--- a/webrtc/modules/audio_coding/main/acm2/
+++ b/webrtc/modules/audio_coding/main/acm2/
@@ -195,8 +195,14 @@
 void CodecOwner::ChangeCngAndRed(int cng_payload_type,
                                  ACMVADMode vad_mode,
                                  int red_payload_type) {
+  AudioEncoderMutable* speech_encoder = SpeechEncoder();
+  if (cng_payload_type != -1 || red_payload_type != -1) {
+    // The RED and CNG encoders need to be in sync with the speech encoder, so
+    // reset the latter to ensure its buffer is empty.
+    speech_encoder->Reset();
+  }
   AudioEncoder* encoder =
-      CreateRedEncoder(red_payload_type, SpeechEncoder(), &red_encoder_);
+      CreateRedEncoder(red_payload_type, speech_encoder, &red_encoder_);
   CreateCngEncoder(cng_payload_type, vad_mode, encoder, &cng_encoder_);
   int num_true =
       !!speech_encoder_ + !!external_speech_encoder_ + isac_is_encoder_;