Home | History | Annotate | Download | only in extended
      1 /*
      2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 #include "webrtc/voice_engine/test/auto_test/fixtures/after_streaming_fixture.h"
     12 
     13 class EcMetricsTest : public AfterStreamingFixture {
     14 };
     15 
     16 TEST_F(EcMetricsTest, EcMetricsAreOffByDefault) {
     17   bool enabled = true;
     18   EXPECT_EQ(0, voe_apm_->GetEcMetricsStatus(enabled));
     19   EXPECT_FALSE(enabled);
     20 }
     21 
     22 TEST_F(EcMetricsTest, CanEnableAndDisableEcMetrics) {
     23   EXPECT_EQ(0, voe_apm_->SetEcMetricsStatus(true));
     24   bool ec_on = false;
     25   EXPECT_EQ(0, voe_apm_->GetEcMetricsStatus(ec_on));
     26   ASSERT_TRUE(ec_on);
     27   EXPECT_EQ(0, voe_apm_->SetEcMetricsStatus(false));
     28   EXPECT_EQ(0, voe_apm_->GetEcMetricsStatus(ec_on));
     29   ASSERT_FALSE(ec_on);
     30 }
     31 
     32 TEST_F(EcMetricsTest, ManualTestEcMetrics) {
     33   SwitchToManualMicrophone();
     34 
     35   EXPECT_EQ(0, voe_apm_->SetEcMetricsStatus(true));
     36 
     37   // Must enable AEC to get valid echo metrics.
     38   EXPECT_EQ(0, voe_apm_->SetEcStatus(true, webrtc::kEcAec));
     39 
     40   TEST_LOG("Speak into microphone and check metrics for 5 seconds...\n");
     41   int erl, erle, rerl, a_nlp;
     42   int delay_median = 0;
     43   int delay_std = 0;
     44 
     45   for (int i = 0; i < 5; i++) {
     46     Sleep(1000);
     47     EXPECT_EQ(0, voe_apm_->GetEchoMetrics(erl, erle, rerl, a_nlp));
     48     EXPECT_EQ(0, voe_apm_->GetEcDelayMetrics(delay_median, delay_std));
     49     TEST_LOG("    Echo  : ERL=%5d, ERLE=%5d, RERL=%5d, A_NLP=%5d [dB], "
     50         " delay median=%3d, delay std=%3d [ms]\n", erl, erle, rerl, a_nlp,
     51         delay_median, delay_std);
     52   }
     53 
     54   EXPECT_EQ(0, voe_apm_->SetEcMetricsStatus(false));
     55 }
     56 
     57 TEST_F(EcMetricsTest, GetEcMetricsFailsIfEcNotEnabled) {
     58   int dummy = 0;
     59   EXPECT_EQ(0, voe_apm_->SetEcMetricsStatus(true));
     60   EXPECT_EQ(-1, voe_apm_->GetEchoMetrics(dummy, dummy, dummy, dummy));
     61   EXPECT_EQ(VE_APM_ERROR, voe_base_->LastError());
     62 }
     63 
     64 TEST_F(EcMetricsTest, GetEcDelayMetricsFailsIfEcNotEnabled) {
     65   int dummy = 0;
     66   EXPECT_EQ(0, voe_apm_->SetEcMetricsStatus(true));
     67   EXPECT_EQ(-1, voe_apm_->GetEcDelayMetrics(dummy, dummy));
     68   EXPECT_EQ(VE_APM_ERROR, voe_base_->LastError());
     69 }
     70 
     71 TEST_F(EcMetricsTest, ManualVerifyEcDelayMetrics) {
     72   SwitchToManualMicrophone();
     73   TEST_LOG("Verify EC Delay metrics:");
     74   EXPECT_EQ(0, voe_apm_->SetEcStatus(true));
     75   EXPECT_EQ(0, voe_apm_->SetEcMetricsStatus(true));
     76 
     77   for (int i = 0; i < 5; i++) {
     78     int delay, delay_std;
     79     EXPECT_EQ(0, voe_apm_->GetEcDelayMetrics(delay, delay_std));
     80     TEST_LOG("Delay = %d, Delay Std = %d\n", delay, delay_std);
     81     Sleep(1000);
     82   }
     83 }
     84