From a743794d063ac11552e55460b948d34aa734e510 Mon Sep 17 00:00:00 2001 From: Bjorn Volcker Date: Thu, 28 May 2015 15:58:42 +0200 Subject: [PATCH] audio_processing/aecm: Create() now returns a pointer to the object Changed Create() to return a pointer to the object rather than an error message, which is in line with how objects should be created. BUG=441 R=kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/51939004 Cr-Commit-Position: refs/heads/master@{#9315} --- .../modules/audio_processing/aecm/aecm_core.c | 30 ++++++------------- .../modules/audio_processing/aecm/aecm_core.h | 17 +++-------- .../aecm/echo_control_mobile.c | 28 +++++------------ .../aecm/include/echo_control_mobile.h | 13 ++------ .../echo_control_mobile_impl.cc | 9 +----- 5 files changed, 23 insertions(+), 74 deletions(-) diff --git a/webrtc/modules/audio_processing/aecm/aecm_core.c b/webrtc/modules/audio_processing/aecm/aecm_core.c index b124e30bc..b801f07a9 100644 --- a/webrtc/modules/audio_processing/aecm/aecm_core.c +++ b/webrtc/modules/audio_processing/aecm/aecm_core.c @@ -207,21 +207,15 @@ CalcLinearEnergies WebRtcAecm_CalcLinearEnergies; StoreAdaptiveChannel WebRtcAecm_StoreAdaptiveChannel; ResetAdaptiveChannel WebRtcAecm_ResetAdaptiveChannel; -int WebRtcAecm_CreateCore(AecmCore** aecmInst) { +AecmCore* WebRtcAecm_CreateCore() { AecmCore* aecm = malloc(sizeof(AecmCore)); - *aecmInst = aecm; - if (aecm == NULL) - { - return -1; - } aecm->farFrameBuf = WebRtc_CreateBuffer(FRAME_LEN + PART_LEN, sizeof(int16_t)); if (!aecm->farFrameBuf) { WebRtcAecm_FreeCore(aecm); - aecm = NULL; - return -1; + return NULL; } aecm->nearNoisyFrameBuf = WebRtc_CreateBuffer(FRAME_LEN + PART_LEN, @@ -229,8 +223,7 @@ int WebRtcAecm_CreateCore(AecmCore** aecmInst) { if (!aecm->nearNoisyFrameBuf) { WebRtcAecm_FreeCore(aecm); - aecm = NULL; - return -1; + return NULL; } aecm->nearCleanFrameBuf = WebRtc_CreateBuffer(FRAME_LEN + PART_LEN, @@ -238,8 +231,7 @@ int WebRtcAecm_CreateCore(AecmCore** aecmInst) { if (!aecm->nearCleanFrameBuf) { WebRtcAecm_FreeCore(aecm); - aecm = NULL; - return -1; + return NULL; } aecm->outFrameBuf = WebRtc_CreateBuffer(FRAME_LEN + PART_LEN, @@ -247,23 +239,20 @@ int WebRtcAecm_CreateCore(AecmCore** aecmInst) { if (!aecm->outFrameBuf) { WebRtcAecm_FreeCore(aecm); - aecm = NULL; - return -1; + return NULL; } aecm->delay_estimator_farend = WebRtc_CreateDelayEstimatorFarend(PART_LEN1, MAX_DELAY); if (aecm->delay_estimator_farend == NULL) { WebRtcAecm_FreeCore(aecm); - aecm = NULL; - return -1; + return NULL; } aecm->delay_estimator = WebRtc_CreateDelayEstimator(aecm->delay_estimator_farend, 0); if (aecm->delay_estimator == NULL) { WebRtcAecm_FreeCore(aecm); - aecm = NULL; - return -1; + return NULL; } // TODO(bjornv): Explicitly disable robust delay validation until no // performance regression has been established. Then remove the line. @@ -272,8 +261,7 @@ int WebRtcAecm_CreateCore(AecmCore** aecmInst) { aecm->real_fft = WebRtcSpl_CreateRealFFT(PART_LEN_SHIFT); if (aecm->real_fft == NULL) { WebRtcAecm_FreeCore(aecm); - aecm = NULL; - return -1; + return NULL; } // Init some aecm pointers. 16 and 32 byte alignment is only necessary @@ -289,7 +277,7 @@ int WebRtcAecm_CreateCore(AecmCore** aecmInst) { aecm->channelAdapt32 = (int32_t*) (((uintptr_t) aecm->channelAdapt32_buf + 31) & ~ 31); - return 0; + return aecm; } void WebRtcAecm_InitEchoPathCore(AecmCore* aecm, const int16_t* echo_path) { diff --git a/webrtc/modules/audio_processing/aecm/aecm_core.h b/webrtc/modules/audio_processing/aecm/aecm_core.h index 5646e8f84..b52bb62d2 100644 --- a/webrtc/modules/audio_processing/aecm/aecm_core.h +++ b/webrtc/modules/audio_processing/aecm/aecm_core.h @@ -134,27 +134,18 @@ typedef struct { } AecmCore; //////////////////////////////////////////////////////////////////////////////// -// WebRtcAecm_CreateCore(...) +// WebRtcAecm_CreateCore() // // Allocates the memory needed by the AECM. The memory needs to be // initialized separately using the WebRtcAecm_InitCore() function. -// -// Input: -// - aecm : Instance that should be created -// -// Output: -// - aecm : Created instance -// -// Return value : 0 - Ok -// -1 - Error -// -int WebRtcAecm_CreateCore(AecmCore** aecm); +// Returns a pointer to the instance and a nullptr at failure. +AecmCore* WebRtcAecm_CreateCore(); //////////////////////////////////////////////////////////////////////////////// // WebRtcAecm_InitCore(...) // // This function initializes the AECM instant created with -// WebRtcAecm_CreateCore(...) +// WebRtcAecm_CreateCore() // Input: // - aecm : Pointer to the AECM instance // - samplingFreq : Sampling Frequency diff --git a/webrtc/modules/audio_processing/aecm/echo_control_mobile.c b/webrtc/modules/audio_processing/aecm/echo_control_mobile.c index 2424839ac..5f3fa2af6 100644 --- a/webrtc/modules/audio_processing/aecm/echo_control_mobile.c +++ b/webrtc/modules/audio_processing/aecm/echo_control_mobile.c @@ -80,28 +80,15 @@ static int WebRtcAecm_EstBufDelay(AecMobile* aecmInst, short msInSndCardBuf); // Stuffs the farend buffer if the estimated delay is too large static int WebRtcAecm_DelayComp(AecMobile* aecmInst); -int32_t WebRtcAecm_Create(void **aecmInst) -{ - AecMobile* aecm; - if (aecmInst == NULL) - { - return -1; - } - - aecm = malloc(sizeof(AecMobile)); - *aecmInst = aecm; - if (aecm == NULL) - { - return -1; - } +void* WebRtcAecm_Create() { + AecMobile* aecm = malloc(sizeof(AecMobile)); WebRtcSpl_Init(); - if (WebRtcAecm_CreateCore(&aecm->aecmCore) == -1) - { + aecm->aecmCore = WebRtcAecm_CreateCore(); + if (!aecm->aecmCore) { WebRtcAecm_Free(aecm); - aecm = NULL; - return -1; + return NULL; } aecm->farendBuf = WebRtc_CreateBuffer(kBufSizeSamp, @@ -109,8 +96,7 @@ int32_t WebRtcAecm_Create(void **aecmInst) if (!aecm->farendBuf) { WebRtcAecm_Free(aecm); - aecm = NULL; - return -1; + return NULL; } aecm->initFlag = 0; @@ -127,7 +113,7 @@ int32_t WebRtcAecm_Create(void **aecmInst) aecm->preCompFile = fopen("preComp.pcm", "wb"); aecm->postCompFile = fopen("postComp.pcm", "wb"); #endif // AEC_DEBUG - return 0; + return aecm; } void WebRtcAecm_Free(void* aecmInst) { 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 617c9602d..22e0fe6bf 100644 --- a/webrtc/modules/audio_processing/aecm/include/echo_control_mobile.h +++ b/webrtc/modules/audio_processing/aecm/include/echo_control_mobile.h @@ -42,18 +42,9 @@ extern "C" { /* * Allocates the memory needed by the AECM. The memory needs to be * initialized separately using the WebRtcAecm_Init() function. - * - * Inputs Description - * ------------------------------------------------------------------- - * void** aecmInst Pointer to the AECM instance to be - * created and initialized - * - * Outputs Description - * ------------------------------------------------------------------- - * int32_t return 0: OK - * -1: error + * Returns a pointer to the instance and a nullptr at failure. */ -int32_t WebRtcAecm_Create(void **aecmInst); +void* WebRtcAecm_Create(); /* * This function releases the memory allocated by WebRtcAecm_Create() diff --git a/webrtc/modules/audio_processing/echo_control_mobile_impl.cc b/webrtc/modules/audio_processing/echo_control_mobile_impl.cc index 0f5b4fe7a..33205eb74 100644 --- a/webrtc/modules/audio_processing/echo_control_mobile_impl.cc +++ b/webrtc/modules/audio_processing/echo_control_mobile_impl.cc @@ -250,14 +250,7 @@ int EchoControlMobileImpl::Initialize() { } void* EchoControlMobileImpl::CreateHandle() const { - Handle* handle = NULL; - if (WebRtcAecm_Create(&handle) != apm_->kNoError) { - handle = NULL; - } else { - assert(handle != NULL); - } - - return handle; + return WebRtcAecm_Create(); } void EchoControlMobileImpl::DestroyHandle(void* handle) const {