From f6a99e63b6e18d3b3db25e0059a4979743046f31 Mon Sep 17 00:00:00 2001 From: Bjorn Volcker Date: Fri, 10 Apr 2015 07:56:57 +0200 Subject: [PATCH] Refactor audio_processing: Free functions return void There is no point in returning an error when Free() fails. In fact it can only happen if we have a null pointer as object. There is further no place where the return value is used. Affected components are - aec - aecm - agc - ns BUG=441 R=kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/50579004 Cr-Commit-Position: refs/heads/master@{#8966} --- webrtc/modules/audio_processing/aec/aec_core.c | 5 ++--- webrtc/modules/audio_processing/aec/aec_core.h | 2 +- webrtc/modules/audio_processing/aec/aec_resampler.c | 4 +--- webrtc/modules/audio_processing/aec/aec_resampler.h | 2 +- .../audio_processing/aec/echo_cancellation.c | 6 ++---- .../aec/echo_cancellation_unittest.cc | 8 ++++---- .../aec/include/echo_cancellation.h | 7 +------ .../audio_processing/aec/system_delay_unittest.cc | 2 +- webrtc/modules/audio_processing/aecm/aecm_core.c | 9 +++------ webrtc/modules/audio_processing/aecm/aecm_core.h | 6 +----- .../audio_processing/aecm/echo_control_mobile.c | 10 +++------- .../aecm/include/echo_control_mobile.h | 7 +------ .../audio_processing/agc/legacy/analog_agc.c | 13 +++++-------- .../audio_processing/agc/legacy/gain_control.h | 5 +---- .../audio_processing/ns/include/noise_suppression.h | 6 +----- .../ns/include/noise_suppression_x.h | 6 +----- .../modules/audio_processing/ns/noise_suppression.c | 4 +--- .../audio_processing/ns/noise_suppression_x.c | 3 +-- 18 files changed, 31 insertions(+), 74 deletions(-) diff --git a/webrtc/modules/audio_processing/aec/aec_core.c b/webrtc/modules/audio_processing/aec/aec_core.c index fc523bf9c..f540f9428 100644 --- a/webrtc/modules/audio_processing/aec/aec_core.c +++ b/webrtc/modules/audio_processing/aec/aec_core.c @@ -1471,10 +1471,10 @@ int WebRtcAec_CreateAec(AecCore** aecInst) { return 0; } -int WebRtcAec_FreeAec(AecCore* aec) { +void WebRtcAec_FreeAec(AecCore* aec) { int i; if (aec == NULL) { - return -1; + return; } WebRtc_FreeBuffer(aec->nearFrBuf); @@ -1498,7 +1498,6 @@ int WebRtcAec_FreeAec(AecCore* aec) { WebRtc_FreeDelayEstimatorFarend(aec->delay_estimator_farend); free(aec); - return 0; } #ifdef WEBRTC_AEC_DEBUG_DUMP diff --git a/webrtc/modules/audio_processing/aec/aec_core.h b/webrtc/modules/audio_processing/aec/aec_core.h index 2b614dd83..cc9e81b44 100644 --- a/webrtc/modules/audio_processing/aec/aec_core.h +++ b/webrtc/modules/audio_processing/aec/aec_core.h @@ -52,7 +52,7 @@ typedef struct Stats { typedef struct AecCore AecCore; int WebRtcAec_CreateAec(AecCore** aec); -int WebRtcAec_FreeAec(AecCore* aec); +void WebRtcAec_FreeAec(AecCore* aec); int WebRtcAec_InitAec(AecCore* aec, int sampFreq); void WebRtcAec_InitAec_SSE2(void); #if defined(MIPS_FPU_LE) diff --git a/webrtc/modules/audio_processing/aec/aec_resampler.c b/webrtc/modules/audio_processing/aec/aec_resampler.c index 28aa8326b..8b07e1658 100644 --- a/webrtc/modules/audio_processing/aec/aec_resampler.c +++ b/webrtc/modules/audio_processing/aec/aec_resampler.c @@ -63,11 +63,9 @@ int WebRtcAec_InitResampler(void* resampInst, int deviceSampleRateHz) { return 0; } -int WebRtcAec_FreeResampler(void* resampInst) { +void WebRtcAec_FreeResampler(void* resampInst) { AecResampler* obj = (AecResampler*)resampInst; free(obj); - - return 0; } void WebRtcAec_ResampleLinear(void* resampInst, diff --git a/webrtc/modules/audio_processing/aec/aec_resampler.h b/webrtc/modules/audio_processing/aec/aec_resampler.h index 73e282125..debe069ee 100644 --- a/webrtc/modules/audio_processing/aec/aec_resampler.h +++ b/webrtc/modules/audio_processing/aec/aec_resampler.h @@ -23,7 +23,7 @@ enum { // Unless otherwise specified, functions return 0 on success and -1 on error int WebRtcAec_CreateResampler(void** resampInst); int WebRtcAec_InitResampler(void* resampInst, int deviceSampleRateHz); -int WebRtcAec_FreeResampler(void* resampInst); +void WebRtcAec_FreeResampler(void* resampInst); // Estimates skew from raw measurement. int WebRtcAec_GetSkew(void* resampInst, int rawSkew, float* skewEst); diff --git a/webrtc/modules/audio_processing/aec/echo_cancellation.c b/webrtc/modules/audio_processing/aec/echo_cancellation.c index 016c45538..33361bec5 100644 --- a/webrtc/modules/audio_processing/aec/echo_cancellation.c +++ b/webrtc/modules/audio_processing/aec/echo_cancellation.c @@ -171,11 +171,11 @@ int32_t WebRtcAec_Create(void** aecInst) { return 0; } -int32_t WebRtcAec_Free(void* aecInst) { +void WebRtcAec_Free(void* aecInst) { Aec* aecpc = aecInst; if (aecpc == NULL) { - return -1; + return; } WebRtc_FreeBuffer(aecpc->far_pre_buf); @@ -189,8 +189,6 @@ int32_t WebRtcAec_Free(void* aecInst) { WebRtcAec_FreeAec(aecpc->aec); WebRtcAec_FreeResampler(aecpc->resampler); free(aecpc); - - return 0; } int32_t WebRtcAec_Init(void* aecInst, int32_t sampFreq, int32_t scSampFreq) { diff --git a/webrtc/modules/audio_processing/aec/echo_cancellation_unittest.cc b/webrtc/modules/audio_processing/aec/echo_cancellation_unittest.cc index 469efd324..6c325e0c5 100644 --- a/webrtc/modules/audio_processing/aec/echo_cancellation_unittest.cc +++ b/webrtc/modules/audio_processing/aec/echo_cancellation_unittest.cc @@ -23,13 +23,13 @@ extern "C" { namespace webrtc { -TEST(EchoCancellationTest, CreateAndFreeHandlesErrors) { +TEST(EchoCancellationTest, CreateAndFreeHasExpectedBehavior) { EXPECT_EQ(-1, WebRtcAec_Create(NULL)); void* handle = NULL; ASSERT_EQ(0, WebRtcAec_Create(&handle)); EXPECT_TRUE(handle != NULL); - EXPECT_EQ(-1, WebRtcAec_Free(NULL)); - EXPECT_EQ(0, WebRtcAec_Free(handle)); + WebRtcAec_Free(nullptr); + WebRtcAec_Free(handle); } TEST(EchoCancellationTest, ApplyAecCoreHandle) { @@ -44,7 +44,7 @@ TEST(EchoCancellationTest, ApplyAecCoreHandle) { int delay = 111; WebRtcAec_SetSystemDelay(aec_core, delay); EXPECT_EQ(delay, WebRtcAec_system_delay(aec_core)); - EXPECT_EQ(0, WebRtcAec_Free(handle)); + WebRtcAec_Free(handle); } } // namespace webrtc diff --git a/webrtc/modules/audio_processing/aec/include/echo_cancellation.h b/webrtc/modules/audio_processing/aec/include/echo_cancellation.h index df9b2a90c..6914ed1a9 100644 --- a/webrtc/modules/audio_processing/aec/include/echo_cancellation.h +++ b/webrtc/modules/audio_processing/aec/include/echo_cancellation.h @@ -84,13 +84,8 @@ int32_t WebRtcAec_Create(void** aecInst); * Inputs Description * ------------------------------------------------------------------- * void* aecInst Pointer to the AEC instance - * - * Outputs Description - * ------------------------------------------------------------------- - * int32_t return 0: OK - * -1: error */ -int32_t WebRtcAec_Free(void* aecInst); +void WebRtcAec_Free(void* aecInst); /* * Initializes an AEC instance. diff --git a/webrtc/modules/audio_processing/aec/system_delay_unittest.cc b/webrtc/modules/audio_processing/aec/system_delay_unittest.cc index 654ae54c7..da28752bc 100644 --- a/webrtc/modules/audio_processing/aec/system_delay_unittest.cc +++ b/webrtc/modules/audio_processing/aec/system_delay_unittest.cc @@ -73,7 +73,7 @@ void SystemDelayTest::SetUp() { void SystemDelayTest::TearDown() { // Free AEC - ASSERT_EQ(0, WebRtcAec_Free(handle_)); + WebRtcAec_Free(handle_); handle_ = NULL; } diff --git a/webrtc/modules/audio_processing/aecm/aecm_core.c b/webrtc/modules/audio_processing/aecm/aecm_core.c index c95c1f2af..6741acba1 100644 --- a/webrtc/modules/audio_processing/aecm/aecm_core.c +++ b/webrtc/modules/audio_processing/aecm/aecm_core.c @@ -546,10 +546,9 @@ int WebRtcAecm_Control(AecmCore* aecm, int delay, int nlpFlag) { return 0; } -int WebRtcAecm_FreeCore(AecmCore* aecm) { - if (aecm == NULL) - { - return -1; +void WebRtcAecm_FreeCore(AecmCore* aecm) { + if (aecm == NULL) { + return; } WebRtc_FreeBuffer(aecm->farFrameBuf); @@ -562,8 +561,6 @@ int WebRtcAecm_FreeCore(AecmCore* aecm) { WebRtcSpl_FreeRealFFT(aecm->real_fft); free(aecm); - - return 0; } int WebRtcAecm_ProcessFrame(AecmCore* aecm, diff --git a/webrtc/modules/audio_processing/aecm/aecm_core.h b/webrtc/modules/audio_processing/aecm/aecm_core.h index 03655b90c..15614d67f 100644 --- a/webrtc/modules/audio_processing/aecm/aecm_core.h +++ b/webrtc/modules/audio_processing/aecm/aecm_core.h @@ -174,11 +174,7 @@ int WebRtcAecm_InitCore(AecmCore* const aecm, int samplingFreq); // Input: // - aecm : Pointer to the AECM instance // -// Return value : 0 - Ok -// -1 - Error -// 11001-11016: Error -// -int WebRtcAecm_FreeCore(AecmCore* aecm); +void WebRtcAecm_FreeCore(AecmCore* aecm); int WebRtcAecm_Control(AecmCore* aecm, int delay, int nlpFlag); diff --git a/webrtc/modules/audio_processing/aecm/echo_control_mobile.c b/webrtc/modules/audio_processing/aecm/echo_control_mobile.c index 389433b8f..2424839ac 100644 --- a/webrtc/modules/audio_processing/aecm/echo_control_mobile.c +++ b/webrtc/modules/audio_processing/aecm/echo_control_mobile.c @@ -130,13 +130,11 @@ int32_t WebRtcAecm_Create(void **aecmInst) return 0; } -int32_t WebRtcAecm_Free(void *aecmInst) -{ +void WebRtcAecm_Free(void* aecmInst) { AecMobile* aecm = aecmInst; - if (aecm == NULL) - { - return -1; + if (aecm == NULL) { + return; } #ifdef AEC_DEBUG @@ -153,8 +151,6 @@ int32_t WebRtcAecm_Free(void *aecmInst) WebRtcAecm_FreeCore(aecm->aecmCore); WebRtc_FreeBuffer(aecm->farendBuf); free(aecm); - - return 0; } int32_t WebRtcAecm_Init(void *aecmInst, int32_t sampFreq) diff --git a/webrtc/modules/audio_processing/aecm/include/echo_control_mobile.h b/webrtc/modules/audio_processing/aecm/include/echo_control_mobile.h index ac43576dd..617c9602d 100644 --- a/webrtc/modules/audio_processing/aecm/include/echo_control_mobile.h +++ b/webrtc/modules/audio_processing/aecm/include/echo_control_mobile.h @@ -61,13 +61,8 @@ int32_t WebRtcAecm_Create(void **aecmInst); * Inputs Description * ------------------------------------------------------------------- * void* aecmInst Pointer to the AECM instance - * - * Outputs Description - * ------------------------------------------------------------------- - * int32_t return 0: OK - * -1: error */ -int32_t WebRtcAecm_Free(void *aecmInst); +void WebRtcAecm_Free(void* aecmInst); /* * Initializes an AECM instance. diff --git a/webrtc/modules/audio_processing/agc/legacy/analog_agc.c b/webrtc/modules/audio_processing/agc/legacy/analog_agc.c index 17e06fe13..bb56cfe95 100644 --- a/webrtc/modules/audio_processing/agc/legacy/analog_agc.c +++ b/webrtc/modules/audio_processing/agc/legacy/analog_agc.c @@ -1340,19 +1340,16 @@ int WebRtcAgc_Create(void **agcInst) return 0; } -int WebRtcAgc_Free(void *state) -{ +void WebRtcAgc_Free(void *state) { LegacyAgc* stt; stt = (LegacyAgc*)state; #ifdef WEBRTC_AGC_DEBUG_DUMP - fclose(stt->fpt); - fclose(stt->agcLog); - fclose(stt->digitalAgc.logFile); + fclose(stt->fpt); + fclose(stt->agcLog); + fclose(stt->digitalAgc.logFile); #endif - free(stt); - - return 0; + free(stt); } /* minLevel - Minimum volume level diff --git a/webrtc/modules/audio_processing/agc/legacy/gain_control.h b/webrtc/modules/audio_processing/agc/legacy/gain_control.h index cf1e4f1fc..3994f55e8 100644 --- a/webrtc/modules/audio_processing/agc/legacy/gain_control.h +++ b/webrtc/modules/audio_processing/agc/legacy/gain_control.h @@ -213,11 +213,8 @@ int WebRtcAgc_Create(void **agcInst); * * Input: * - agcInst : AGC instance. - * - * Return value : 0 - Ok - * -1 - Error */ -int WebRtcAgc_Free(void *agcInst); +void WebRtcAgc_Free(void* agcInst); /* * This function initializes an AGC instance. diff --git a/webrtc/modules/audio_processing/ns/include/noise_suppression.h b/webrtc/modules/audio_processing/ns/include/noise_suppression.h index d912f7112..14e686a8e 100644 --- a/webrtc/modules/audio_processing/ns/include/noise_suppression.h +++ b/webrtc/modules/audio_processing/ns/include/noise_suppression.h @@ -41,12 +41,8 @@ int WebRtcNs_Create(NsHandle** NS_inst); * * Input: * - NS_inst : Pointer to NS instance that should be freed - * - * Return value : 0 - Ok - * -1 - Error */ -int WebRtcNs_Free(NsHandle* NS_inst); - +void WebRtcNs_Free(NsHandle* NS_inst); /* * This function initializes a NS instance and has to be called before any other diff --git a/webrtc/modules/audio_processing/ns/include/noise_suppression_x.h b/webrtc/modules/audio_processing/ns/include/noise_suppression_x.h index e1671a60a..736cb23fa 100644 --- a/webrtc/modules/audio_processing/ns/include/noise_suppression_x.h +++ b/webrtc/modules/audio_processing/ns/include/noise_suppression_x.h @@ -41,12 +41,8 @@ int WebRtcNsx_Create(NsxHandle** nsxInst); * * Input: * - nsxInst : Pointer to NS instance that should be freed - * - * Return value : 0 - Ok - * -1 - Error */ -int WebRtcNsx_Free(NsxHandle* nsxInst); - +void WebRtcNsx_Free(NsxHandle* nsxInst); /* * This function initializes a NS instance diff --git a/webrtc/modules/audio_processing/ns/noise_suppression.c b/webrtc/modules/audio_processing/ns/noise_suppression.c index bae0f2e1e..0efbebcc4 100644 --- a/webrtc/modules/audio_processing/ns/noise_suppression.c +++ b/webrtc/modules/audio_processing/ns/noise_suppression.c @@ -28,12 +28,10 @@ int WebRtcNs_Create(NsHandle** NS_inst) { } -int WebRtcNs_Free(NsHandle* NS_inst) { +void WebRtcNs_Free(NsHandle* NS_inst) { free(NS_inst); - return 0; } - int WebRtcNs_Init(NsHandle* NS_inst, uint32_t fs) { return WebRtcNs_InitCore((NoiseSuppressionC*)NS_inst, fs); } diff --git a/webrtc/modules/audio_processing/ns/noise_suppression_x.c b/webrtc/modules/audio_processing/ns/noise_suppression_x.c index 920b50100..a3b6d0f3b 100644 --- a/webrtc/modules/audio_processing/ns/noise_suppression_x.c +++ b/webrtc/modules/audio_processing/ns/noise_suppression_x.c @@ -31,10 +31,9 @@ int WebRtcNsx_Create(NsxHandle** nsxInst) { } -int WebRtcNsx_Free(NsxHandle* nsxInst) { +void WebRtcNsx_Free(NsxHandle* nsxInst) { WebRtcSpl_FreeRealFFT(((NoiseSuppressionFixedC*)nsxInst)->real_fft); free(nsxInst); - return 0; } int WebRtcNsx_Init(NsxHandle* nsxInst, uint32_t fs) {