1. Make a clear distinction between codec internal FEC and RED, confusing mentioning of FEC in the old codes is replaced by RED

2. Add two new APIs to configure codec internal FEC

3. Add a test and listened to results. This is based modifying EncodeDecodeTest and deriving a new class from it.

New ACM gives good result.
Old ACM does not use NetEq 4, so FEC won't be decoded.

BUG=
R=tina.legrand@webrtc.org, turaj@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/11759004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6233 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/modules/audio_coding/main/test/EncodeDecodeTest.cc b/webrtc/modules/audio_coding/main/test/EncodeDecodeTest.cc
index 1ee6abc..d06cc07 100644
--- a/webrtc/modules/audio_coding/main/test/EncodeDecodeTest.cc
+++ b/webrtc/modules/audio_coding/main/test/EncodeDecodeTest.cc
@@ -10,12 +10,9 @@
 
 #include "webrtc/modules/audio_coding/main/test/EncodeDecodeTest.h"
 
+#include <sstream>
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
-
-#include <sstream>
-#include <string>
 
 #include "testing/gtest/include/gtest/gtest.h"
 #include "webrtc/common_types.h"
@@ -54,16 +51,19 @@
       _packetization(NULL) {
 }
 
-void Sender::Setup(AudioCodingModule *acm, RTPStream *rtpStream) {
+void Sender::Setup(AudioCodingModule *acm, RTPStream *rtpStream,
+                   std::string in_file_name, int sample_rate, int channels) {
   acm->InitializeSender();
   struct CodecInst sendCodec;
   int noOfCodecs = acm->NumberOfCodecs();
   int codecNo;
 
   // Open input file
-  const std::string file_name = webrtc::test::ResourcePath(
-      "audio_coding/testfile32kHz", "pcm");
-  _pcmFile.Open(file_name, 32000, "rb");
+  const std::string file_name = webrtc::test::ResourcePath(in_file_name, "pcm");
+  _pcmFile.Open(file_name, sample_rate, "rb");
+  if (channels == 2) {
+    _pcmFile.ReadStereo(true);
+  }
 
   // Set the codec for the current test.
   if ((testMode == 0) || (testMode == 1)) {
@@ -81,10 +81,8 @@
   }
 
   EXPECT_EQ(0, acm->Codec(codecNo, &sendCodec));
-  // Default number of channels is 2 for CELT, so we change to 1 in this test.
-  if (!strcmp(sendCodec.plname, "CELT")) {
-    sendCodec.channels = 1;
-  }
+
+  sendCodec.channels = channels;
 
   EXPECT_EQ(0, acm->RegisterSendCodec(sendCodec));
   _packetization = new TestPacketization(rtpStream, sendCodec.plfreq);
@@ -125,21 +123,28 @@
       _payloadSizeBytes(MAX_INCOMING_PAYLOAD) {
 }
 
-void Receiver::Setup(AudioCodingModule *acm, RTPStream *rtpStream) {
+void Receiver::Setup(AudioCodingModule *acm, RTPStream *rtpStream,
+                     std::string out_file_name, int channels) {
   struct CodecInst recvCodec;
   int noOfCodecs;
   EXPECT_EQ(0, acm->InitializeReceiver());
 
   noOfCodecs = acm->NumberOfCodecs();
   for (int i = 0; i < noOfCodecs; i++) {
-    EXPECT_EQ(0, acm->Codec(static_cast<uint8_t>(i), &recvCodec));
-    EXPECT_EQ(0, acm->RegisterReceiveCodec(recvCodec));
+    EXPECT_EQ(0, acm->Codec(i, &recvCodec));
+    if (recvCodec.channels == channels)
+      EXPECT_EQ(0, acm->RegisterReceiveCodec(recvCodec));
+    // Forces mono/stereo for Opus.
+    if (!strcmp(recvCodec.plname, "opus")) {
+      recvCodec.channels = channels;
+      EXPECT_EQ(0, acm->RegisterReceiveCodec(recvCodec));
+    }
   }
 
   int playSampFreq;
   std::string file_name;
   std::stringstream file_stream;
-  file_stream << webrtc::test::OutputPath() << "encodeDecode_out"
+  file_stream << webrtc::test::OutputPath() << out_file_name
       << static_cast<int>(codeId) << ".pcm";
   file_name = file_stream.str();
   _rtpStream = rtpStream;
@@ -156,7 +161,7 @@
     printf("which means output frequency equal to received signal frequency");
     printf("\n\nChoose output sampling frequency: ");
     ASSERT_GT(scanf("%d", &playSampFreq), 0);
-    file_name = webrtc::test::OutputPath() + "encodeDecode_out.pcm";
+    file_name = webrtc::test::OutputPath() + out_file_name + ".pcm";
     _pcmFile.Open(file_name, playSampFreq, "wb+");
   }
 
@@ -213,7 +218,8 @@
   if (_playoutLengthSmpls == 0) {
     return false;
   }
-  _pcmFile.Write10MsData(audioFrame.data_, audioFrame.samples_per_channel_);
+  _pcmFile.Write10MsData(audioFrame.data_,
+      audioFrame.samples_per_channel_ * audioFrame.num_channels_);
   return true;
 }
 
@@ -310,7 +316,7 @@
       _receiver.codeId = codeId;
 
       rtpFile.ReadHeader();
-      _receiver.Setup(acm.get(), &rtpFile);
+      _receiver.Setup(acm.get(), &rtpFile, "encodeDecode_out", 1);
       _receiver.Run();
       _receiver.Teardown();
       rtpFile.Close();
@@ -335,7 +341,7 @@
   _sender.testMode = testMode;
   _sender.codeId = codeId;
 
-  _sender.Setup(acm.get(), &rtpFile);
+  _sender.Setup(acm.get(), &rtpFile, "audio_coding/testfile32kHz", 32000, 1);
   struct CodecInst sendCodecInst;
   if (acm->SendCodec(&sendCodecInst) >= 0) {
     _sender.Run();