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}
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user