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}
diff --git a/webrtc/modules/audio_processing/aecm/aecm_core.c b/webrtc/modules/audio_processing/aecm/aecm_core.c
index b124e30..b801f07 100644
--- a/webrtc/modules/audio_processing/aecm/aecm_core.c
+++ b/webrtc/modules/audio_processing/aecm/aecm_core.c
@@ -207,21 +207,15 @@
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 @@
if (!aecm->nearNoisyFrameBuf)
{
WebRtcAecm_FreeCore(aecm);
- aecm = NULL;
- return -1;
+ return NULL;
}
aecm->nearCleanFrameBuf = WebRtc_CreateBuffer(FRAME_LEN + PART_LEN,
@@ -238,8 +231,7 @@
if (!aecm->nearCleanFrameBuf)
{
WebRtcAecm_FreeCore(aecm);
- aecm = NULL;
- return -1;
+ return NULL;
}
aecm->outFrameBuf = WebRtc_CreateBuffer(FRAME_LEN + PART_LEN,
@@ -247,23 +239,20 @@
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 @@
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 @@
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 5646e8f..b52bb62 100644
--- a/webrtc/modules/audio_processing/aecm/aecm_core.h
+++ b/webrtc/modules/audio_processing/aecm/aecm_core.h
@@ -134,27 +134,18 @@
} 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 2424839..5f3fa2a 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 @@
// 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 @@
if (!aecm->farendBuf)
{
WebRtcAecm_Free(aecm);
- aecm = NULL;
- return -1;
+ return NULL;
}
aecm->initFlag = 0;
@@ -127,7 +113,7 @@
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 617c960..22e0fe6 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 @@
/*
* 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 0f5b4fe..33205eb 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 @@
}
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 {