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   float fraction_poor_delays = 0;
     45 
     46   for (int i = 0; i < 5; i++) {
     47     Sleep(1000);
     48     EXPECT_EQ(0, voe_apm_->GetEchoMetrics(erl, erle, rerl, a_nlp));
     49     EXPECT_EQ(0, voe_apm_->GetEcDelayMetrics(delay_median, delay_std,
     50                                              fraction_poor_delays));
     51     TEST_LOG("    Echo  : ERL=%5d, ERLE=%5d, RERL=%5d, A_NLP=%5d [dB], "
     52         " delay median=%3d, delay std=%3d [ms], "
     53         "fraction_poor_delays=%3.1f [%%]\n", erl, erle, rerl, a_nlp,
     54         delay_median, delay_std, fraction_poor_delays * 100);
     55   }
     56 
     57   EXPECT_EQ(0, voe_apm_->SetEcMetricsStatus(false));
     58 }
     59 
     60 TEST_F(EcMetricsTest, GetEcMetricsFailsIfEcNotEnabled) {
     61   int dummy = 0;
     62   EXPECT_EQ(0, voe_apm_->SetEcMetricsStatus(true));
     63   EXPECT_EQ(-1, voe_apm_->GetEchoMetrics(dummy, dummy, dummy, dummy));
     64   EXPECT_EQ(VE_APM_ERROR, voe_base_->LastError());
     65 }
     66 
     67 TEST_F(EcMetricsTest, GetEcDelayMetricsFailsIfEcNotEnabled) {
     68   int dummy = 0;
     69   float dummy_f = 0;
     70   EXPECT_EQ(0, voe_apm_->SetEcMetricsStatus(true));
     71   EXPECT_EQ(-1, voe_apm_->GetEcDelayMetrics(dummy, dummy, dummy_f));
     72   EXPECT_EQ(VE_APM_ERROR, voe_base_->LastError());
     73 }
     74 
     75 TEST_F(EcMetricsTest, ManualVerifyEcDelayMetrics) {
     76   SwitchToManualMicrophone();
     77   TEST_LOG("Verify EC Delay metrics:");
     78   EXPECT_EQ(0, voe_apm_->SetEcStatus(true));
     79   EXPECT_EQ(0, voe_apm_->SetEcMetricsStatus(true));
     80 
     81   for (int i = 0; i < 5; i++) {
     82     int delay, delay_std;
     83     float fraction_poor_delays;
     84     EXPECT_EQ(0, voe_apm_->GetEcDelayMetrics(delay, delay_std,
     85                                              fraction_poor_delays));
     86     TEST_LOG("Delay = %d, Delay Std = %d, Fraction poor delays = %3.1f\n",
     87              delay, delay_std, fraction_poor_delays * 100);
     88     Sleep(1000);
     89   }
     90 }
     91