From 75f1948b0e4da35e0527ded8859478431caceac2 Mon Sep 17 00:00:00 2001 From: "andrew@webrtc.org" Date: Thu, 9 Feb 2012 17:16:18 +0000 Subject: [PATCH] Restore AECM Coverity fix. Add a test which would have caught the crash introduced by r1628. BUG=274 TEST=audioproc_unittest Review URL: https://webrtc-codereview.appspot.com/388002 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1657 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../audio_processing/aecm/echo_control_mobile.c | 7 +++++-- src/modules/audio_processing/test/unit_test.cc | 13 ++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/modules/audio_processing/aecm/echo_control_mobile.c b/src/modules/audio_processing/aecm/echo_control_mobile.c index 4c5edc704b..566ae00d60 100644 --- a/src/modules/audio_processing/aecm/echo_control_mobile.c +++ b/src/modules/audio_processing/aecm/echo_control_mobile.c @@ -339,8 +339,11 @@ WebRtc_Word32 WebRtcAecm_Process(void *aecmInst, const WebRtc_Word16 *nearendNoi { if (nearendClean == NULL) { - memcpy(out, nearendNoisy, sizeof(short) * nrOfSamples); - } else + if (out != nearendNoisy) + { + memcpy(out, nearendNoisy, sizeof(short) * nrOfSamples); + } + } else if (out != nearendClean) { memcpy(out, nearendClean, sizeof(short) * nrOfSamples); } diff --git a/src/modules/audio_processing/test/unit_test.cc b/src/modules/audio_processing/test/unit_test.cc index e43d497a6c..4fa5d7cc12 100644 --- a/src/modules/audio_processing/test/unit_test.cc +++ b/src/modules/audio_processing/test/unit_test.cc @@ -618,8 +618,8 @@ TEST_F(ApmTest, EchoControlMobile) { // AECM won't use super-wideband. EXPECT_EQ(apm_->kNoError, apm_->set_sample_rate_hz(32000)); EXPECT_EQ(apm_->kBadSampleRateError, apm_->echo_control_mobile()->Enable(true)); - EXPECT_EQ(apm_->kNoError, apm_->set_sample_rate_hz(16000)); // Turn AECM on (and AEC off) + Init(16000, 2, 2, 2, false); EXPECT_EQ(apm_->kNoError, apm_->echo_control_mobile()->Enable(true)); EXPECT_TRUE(apm_->echo_control_mobile()->is_enabled()); @@ -672,6 +672,14 @@ TEST_F(ApmTest, EchoControlMobile) { for (size_t i = 0; i < echo_path_size; i++) { EXPECT_EQ(echo_path_in[i], echo_path_out[i]); } + + // Process a few frames with NS in the default disabled state. This exercises + // a different codepath than with it enabled. + EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(0)); + EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); + EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(0)); + EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); + // Turn AECM off EXPECT_EQ(apm_->kNoError, apm_->echo_control_mobile()->Enable(false)); EXPECT_FALSE(apm_->echo_control_mobile()->is_enabled()); @@ -1046,6 +1054,9 @@ TEST_F(ApmTest, DebugDump) { #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP } +// TODO(andrew): Add a test to process a few frames with different combinations +// of enabled components. + // TODO(andrew): Make this test more robust such that it can be run on multiple // platforms. It currently requires bit-exactness. #ifdef WEBRTC_AUDIOPROC_BIT_EXACT