Let NetEq use the PLC output from a decoder

This change enables NetEq to use the packet concealment audio (aka
PLC) produced by a decoder. The change also includes a new API to the
AudioDecoder interface, which lets the decoder implementation generate
and deliver concealment audio.

Bug: webrtc:9180
Change-Id: Icaacebccf645d4694b0d2d6310f6f2c7132881c4
Reviewed-on: https://webrtc-review.googlesource.com/96340
Commit-Queue: Henrik Lundin <henrik.lundin@webrtc.org>
Reviewed-by: Minyue Li <minyue@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24738}
diff --git a/modules/audio_coding/neteq/audio_multi_vector_unittest.cc b/modules/audio_coding/neteq/audio_multi_vector_unittest.cc
index 3f3283e..ed4c290 100644
--- a/modules/audio_coding/neteq/audio_multi_vector_unittest.cc
+++ b/modules/audio_coding/neteq/audio_multi_vector_unittest.cc
@@ -14,6 +14,7 @@
 #include <stdlib.h>
 
 #include <string>
+#include <vector>
 
 #include "rtc_base/numerics/safe_conversions.h"
 #include "test/gtest.h"
@@ -32,18 +33,16 @@
  protected:
   AudioMultiVectorTest()
       : num_channels_(GetParam()),  // Get the test parameter.
-        interleaved_length_(num_channels_ * array_length()) {
-    array_interleaved_ = new int16_t[num_channels_ * array_length()];
-  }
+        array_interleaved_(num_channels_ * array_length()) {}
 
-  ~AudioMultiVectorTest() { delete[] array_interleaved_; }
+  ~AudioMultiVectorTest() = default;
 
   virtual void SetUp() {
     // Populate test arrays.
     for (size_t i = 0; i < array_length(); ++i) {
       array_[i] = static_cast<int16_t>(i);
     }
-    int16_t* ptr = array_interleaved_;
+    int16_t* ptr = array_interleaved_.data();
     // Write 100, 101, 102, ... for first channel.
     // Write 200, 201, 202, ... for second channel.
     // And so on.
@@ -58,9 +57,8 @@
   size_t array_length() const { return sizeof(array_) / sizeof(array_[0]); }
 
   const size_t num_channels_;
-  size_t interleaved_length_;
   int16_t array_[10];
-  int16_t* array_interleaved_;
+  std::vector<int16_t> array_interleaved_;
 };
 
 // Create and destroy AudioMultiVector objects, both empty and with a predefined
@@ -95,7 +93,7 @@
 // method is also invoked.
 TEST_P(AudioMultiVectorTest, PushBackInterleavedAndCopy) {
   AudioMultiVector vec(num_channels_);
-  vec.PushBackInterleaved(array_interleaved_, interleaved_length_);
+  vec.PushBackInterleaved(array_interleaved_);
   AudioMultiVector vec_copy(num_channels_);
   vec.CopyTo(&vec_copy);  // Copy from |vec| to |vec_copy|.
   ASSERT_EQ(num_channels_, vec.Channels());
@@ -122,7 +120,7 @@
 TEST_P(AudioMultiVectorTest, CopyToNull) {
   AudioMultiVector vec(num_channels_);
   AudioMultiVector* vec_copy = NULL;
-  vec.PushBackInterleaved(array_interleaved_, interleaved_length_);
+  vec.PushBackInterleaved(array_interleaved_);
   vec.CopyTo(vec_copy);
 }
 
@@ -154,7 +152,7 @@
 // Test the PushBackFromIndex method.
 TEST_P(AudioMultiVectorTest, PushBackFromIndex) {
   AudioMultiVector vec1(num_channels_);
-  vec1.PushBackInterleaved(array_interleaved_, interleaved_length_);
+  vec1.PushBackInterleaved(array_interleaved_);
   AudioMultiVector vec2(num_channels_);
 
   // Append vec1 to the back of vec2 (which is empty). Read vec1 from the second
@@ -173,7 +171,7 @@
 // Starts with pushing some values to the vector, then test the Zeros method.
 TEST_P(AudioMultiVectorTest, Zeros) {
   AudioMultiVector vec(num_channels_);
-  vec.PushBackInterleaved(array_interleaved_, interleaved_length_);
+  vec.PushBackInterleaved(array_interleaved_);
   vec.Zeros(2 * array_length());
   ASSERT_EQ(num_channels_, vec.Channels());
   ASSERT_EQ(2u * array_length(), vec.Size());
@@ -187,20 +185,20 @@
 // Test the ReadInterleaved method
 TEST_P(AudioMultiVectorTest, ReadInterleaved) {
   AudioMultiVector vec(num_channels_);
-  vec.PushBackInterleaved(array_interleaved_, interleaved_length_);
-  int16_t* output = new int16_t[interleaved_length_];
+  vec.PushBackInterleaved(array_interleaved_);
+  int16_t* output = new int16_t[array_interleaved_.size()];
   // Read 5 samples.
   size_t read_samples = 5;
   EXPECT_EQ(num_channels_ * read_samples,
             vec.ReadInterleaved(read_samples, output));
-  EXPECT_EQ(0,
-            memcmp(array_interleaved_, output, read_samples * sizeof(int16_t)));
+  EXPECT_EQ(0, memcmp(array_interleaved_.data(), output,
+                      read_samples * sizeof(int16_t)));
 
   // Read too many samples. Expect to get all samples from the vector.
-  EXPECT_EQ(interleaved_length_,
+  EXPECT_EQ(array_interleaved_.size(),
             vec.ReadInterleaved(array_length() + 1, output));
-  EXPECT_EQ(0,
-            memcmp(array_interleaved_, output, read_samples * sizeof(int16_t)));
+  EXPECT_EQ(0, memcmp(array_interleaved_.data(), output,
+                      read_samples * sizeof(int16_t)));
 
   delete[] output;
 }
@@ -208,7 +206,7 @@
 // Test the PopFront method.
 TEST_P(AudioMultiVectorTest, PopFront) {
   AudioMultiVector vec(num_channels_);
-  vec.PushBackInterleaved(array_interleaved_, interleaved_length_);
+  vec.PushBackInterleaved(array_interleaved_);
   vec.PopFront(1);  // Remove one element from each channel.
   ASSERT_EQ(array_length() - 1u, vec.Size());
   // Let |ptr| point to the second element of the first channel in the
@@ -227,12 +225,12 @@
 // Test the PopBack method.
 TEST_P(AudioMultiVectorTest, PopBack) {
   AudioMultiVector vec(num_channels_);
-  vec.PushBackInterleaved(array_interleaved_, interleaved_length_);
+  vec.PushBackInterleaved(array_interleaved_);
   vec.PopBack(1);  // Remove one element from each channel.
   ASSERT_EQ(array_length() - 1u, vec.Size());
   // Let |ptr| point to the first element of the first channel in the
   // interleaved array.
-  int16_t* ptr = array_interleaved_;
+  int16_t* ptr = array_interleaved_.data();
   for (size_t i = 0; i < array_length() - 1; ++i) {
     for (size_t channel = 0; channel < num_channels_; ++channel) {
       EXPECT_EQ(*ptr, vec[channel][i]);
@@ -265,7 +263,7 @@
 // Test the PushBack method with another AudioMultiVector as input argument.
 TEST_P(AudioMultiVectorTest, OverwriteAt) {
   AudioMultiVector vec1(num_channels_);
-  vec1.PushBackInterleaved(array_interleaved_, interleaved_length_);
+  vec1.PushBackInterleaved(array_interleaved_);
   AudioMultiVector vec2(num_channels_);
   vec2.Zeros(3);  // 3 zeros in each channel.
   // Overwrite vec2 at position 5.
@@ -273,7 +271,7 @@
   // Verify result.
   // Length remains the same.
   ASSERT_EQ(array_length(), vec1.Size());
-  int16_t* ptr = array_interleaved_;
+  int16_t* ptr = array_interleaved_.data();
   for (size_t i = 0; i < array_length() - 1; ++i) {
     for (size_t channel = 0; channel < num_channels_; ++channel) {
       if (i >= 5 && i <= 7) {
@@ -294,7 +292,7 @@
     return;
 
   AudioMultiVector vec(num_channels_);
-  vec.PushBackInterleaved(array_interleaved_, interleaved_length_);
+  vec.PushBackInterleaved(array_interleaved_);
   // Create a reference copy.
   AudioMultiVector ref(num_channels_);
   ref.PushBack(vec);