Added calls to set and get external echo channels.
Review URL: http://webrtc-codereview.appspot.com/62005

git-svn-id: http://webrtc.googlecode.com/svn/trunk@196 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/src/modules/audio_processing/main/test/process_test/process_test.cc b/src/modules/audio_processing/main/test/process_test/process_test.cc
index c62345f..2e659ec 100644
--- a/src/modules/audio_processing/main/test/process_test/process_test.cc
+++ b/src/modules/audio_processing/main/test/process_test/process_test.cc
@@ -56,6 +56,8 @@
   printf("  --drift_compensation\n");
   printf("  --no_drift_compensation\n");
   printf("\n  -aecm    Echo control mobile\n");
+  printf("  --aecm_echo_path_in_file FILE");
+  printf("  --aecm_echo_path_out_file FILE");
   printf("\n  -agc     Gain control\n");
   printf("  --analog\n");
   printf("  --adaptive_digital\n");
@@ -103,6 +105,8 @@
   const char* near_filename = NULL;
   const char* out_filename = NULL;
   const char* vad_out_filename = NULL;
+  const char* aecm_echo_path_in_filename = NULL;
+  const char* aecm_echo_path_out_filename = NULL;
 
   int32_t sample_rate_hz = 16000;
   int32_t device_sample_rate_hz = 16000;
@@ -185,6 +189,16 @@
     } else if (strcmp(argv[i], "-aecm") == 0) {
       ASSERT_EQ(apm->kNoError, apm->echo_control_mobile()->Enable(true));
 
+    } else if (strcmp(argv[i], "--aecm_echo_path_in_file") == 0) {
+      i++;
+      ASSERT_LT(i, argc) << "Specify filename after --aecm_echo_path_in_file";
+      aecm_echo_path_in_filename = argv[i];
+
+    } else if (strcmp(argv[i], "--aecm_echo_path_out_file") == 0) {
+      i++;
+      ASSERT_LT(i, argc) << "Specify filename after --aecm_echo_path_out_file";
+      aecm_echo_path_out_filename = argv[i];
+
     } else if (strcmp(argv[i], "-agc") == 0) {
       ASSERT_EQ(apm->kNoError, apm->gain_control()->Enable(true));
 
@@ -323,6 +337,8 @@
   FILE* delay_file = NULL;
   FILE* drift_file = NULL;
   FILE* vad_out_file = NULL;
+  FILE* aecm_echo_path_in_file = NULL;
+  FILE* aecm_echo_path_out_file = NULL;
 
   if (far_filename != NULL) {
     far_file = fopen(far_filename, "rb");
@@ -361,6 +377,30 @@
                                       << vad_out_file;
   }
 
+  if (aecm_echo_path_in_filename != NULL) {
+    aecm_echo_path_in_file = fopen(aecm_echo_path_in_filename, "rb");
+    ASSERT_TRUE(NULL != aecm_echo_path_in_file) << "Unable to open file "
+                                                << aecm_echo_path_in_filename;
+
+    const int path_size = apm->echo_control_mobile()->echo_path_size_bytes();
+    unsigned char echo_path[path_size];
+    ASSERT_EQ(path_size, fread(echo_path,
+                               sizeof(unsigned char),
+                               path_size,
+                               aecm_echo_path_in_file));
+    EXPECT_EQ(apm->kNoError,
+              apm->echo_control_mobile()->SetEchoPath(echo_path, path_size));
+    fclose(aecm_echo_path_in_file);
+    aecm_echo_path_in_file = NULL;
+  }
+
+  if (aecm_echo_path_out_filename != NULL) {
+    aecm_echo_path_out_file = fopen(aecm_echo_path_out_filename, "wb");
+    ASSERT_TRUE(NULL != aecm_echo_path_out_file) << "Unable to open file "
+                                                 << aecm_echo_path_out_filename;
+
+  }
+
   enum Events {
     kInitializeEvent,
     kRenderEvent,
@@ -579,6 +619,18 @@
     }
   }
 
+  if (aecm_echo_path_out_file != NULL) {
+    const int path_size = apm->echo_control_mobile()->echo_path_size_bytes();
+    unsigned char echo_path[path_size];
+    apm->echo_control_mobile()->GetEchoPath(echo_path, path_size);
+    ASSERT_EQ(path_size, fwrite(echo_path,
+                                sizeof(unsigned char),
+                                path_size,
+                                aecm_echo_path_out_file));
+    fclose(aecm_echo_path_out_file);
+    aecm_echo_path_out_file = NULL;
+  }
+
   if (verbose) {
     printf("\nProcessed frames: %d (primary), %d (reverse)\n",
         primary_count, reverse_count);
diff --git a/src/modules/audio_processing/main/test/unit_test/unit_test.cc b/src/modules/audio_processing/main/test/unit_test/unit_test.cc
index 3a6fce5..275ac3f 100644
--- a/src/modules/audio_processing/main/test/unit_test/unit_test.cc
+++ b/src/modules/audio_processing/main/test/unit_test/unit_test.cc
@@ -638,6 +638,31 @@
   EXPECT_EQ(apm_->kNoError,
       apm_->echo_control_mobile()->enable_comfort_noise(true));
   EXPECT_TRUE(apm_->echo_control_mobile()->is_comfort_noise_enabled());
+  // Set and get echo path
+  const int echo_path_size = apm_->echo_control_mobile()->echo_path_size_bytes();
+  unsigned char echo_path_in[echo_path_size];
+  unsigned char echo_path_out[echo_path_size];
+  EXPECT_EQ(apm_->kNullPointerError,
+            apm_->echo_control_mobile()->SetEchoPath(NULL, echo_path_size));
+  EXPECT_EQ(apm_->kNullPointerError,
+            apm_->echo_control_mobile()->GetEchoPath(NULL, echo_path_size));
+  EXPECT_EQ(apm_->kBadParameterError,
+            apm_->echo_control_mobile()->GetEchoPath(echo_path_out, 1));
+  EXPECT_EQ(apm_->kNoError,
+            apm_->echo_control_mobile()->GetEchoPath(echo_path_out,
+                                                     echo_path_size));
+  for (int i = 0; i < echo_path_size; i++) {
+    echo_path_in[i] = echo_path_out[i] + 1;
+  }
+  EXPECT_EQ(apm_->kBadParameterError,
+            apm_->echo_control_mobile()->SetEchoPath(echo_path_in, 1));
+  EXPECT_EQ(apm_->kNoError,
+            apm_->echo_control_mobile()->SetEchoPath(echo_path_in, echo_path_size));
+  EXPECT_EQ(apm_->kNoError,
+            apm_->echo_control_mobile()->GetEchoPath(echo_path_out, echo_path_size));
+  for (int i = 0; i < echo_path_size; i++) {
+    EXPECT_EQ(echo_path_in[i], echo_path_out[i]);
+  }
   // Turn AECM off
   EXPECT_EQ(apm_->kNoError, apm_->echo_control_mobile()->Enable(false));
   EXPECT_FALSE(apm_->echo_control_mobile()->is_enabled());