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;
|
StoreAdaptiveChannel WebRtcAecm_StoreAdaptiveChannel;
|
||||||
ResetAdaptiveChannel WebRtcAecm_ResetAdaptiveChannel;
|
ResetAdaptiveChannel WebRtcAecm_ResetAdaptiveChannel;
|
||||||
|
|
||||||
int WebRtcAecm_CreateCore(AecmCore** aecmInst) {
|
AecmCore* WebRtcAecm_CreateCore() {
|
||||||
AecmCore* aecm = malloc(sizeof(AecmCore));
|
AecmCore* aecm = malloc(sizeof(AecmCore));
|
||||||
*aecmInst = aecm;
|
|
||||||
if (aecm == NULL)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
aecm->farFrameBuf = WebRtc_CreateBuffer(FRAME_LEN + PART_LEN,
|
aecm->farFrameBuf = WebRtc_CreateBuffer(FRAME_LEN + PART_LEN,
|
||||||
sizeof(int16_t));
|
sizeof(int16_t));
|
||||||
if (!aecm->farFrameBuf)
|
if (!aecm->farFrameBuf)
|
||||||
{
|
{
|
||||||
WebRtcAecm_FreeCore(aecm);
|
WebRtcAecm_FreeCore(aecm);
|
||||||
aecm = NULL;
|
return NULL;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
aecm->nearNoisyFrameBuf = WebRtc_CreateBuffer(FRAME_LEN + PART_LEN,
|
aecm->nearNoisyFrameBuf = WebRtc_CreateBuffer(FRAME_LEN + PART_LEN,
|
||||||
@@ -229,8 +223,7 @@ int WebRtcAecm_CreateCore(AecmCore** aecmInst) {
|
|||||||
if (!aecm->nearNoisyFrameBuf)
|
if (!aecm->nearNoisyFrameBuf)
|
||||||
{
|
{
|
||||||
WebRtcAecm_FreeCore(aecm);
|
WebRtcAecm_FreeCore(aecm);
|
||||||
aecm = NULL;
|
return NULL;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
aecm->nearCleanFrameBuf = WebRtc_CreateBuffer(FRAME_LEN + PART_LEN,
|
aecm->nearCleanFrameBuf = WebRtc_CreateBuffer(FRAME_LEN + PART_LEN,
|
||||||
@@ -238,8 +231,7 @@ int WebRtcAecm_CreateCore(AecmCore** aecmInst) {
|
|||||||
if (!aecm->nearCleanFrameBuf)
|
if (!aecm->nearCleanFrameBuf)
|
||||||
{
|
{
|
||||||
WebRtcAecm_FreeCore(aecm);
|
WebRtcAecm_FreeCore(aecm);
|
||||||
aecm = NULL;
|
return NULL;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
aecm->outFrameBuf = WebRtc_CreateBuffer(FRAME_LEN + PART_LEN,
|
aecm->outFrameBuf = WebRtc_CreateBuffer(FRAME_LEN + PART_LEN,
|
||||||
@@ -247,23 +239,20 @@ int WebRtcAecm_CreateCore(AecmCore** aecmInst) {
|
|||||||
if (!aecm->outFrameBuf)
|
if (!aecm->outFrameBuf)
|
||||||
{
|
{
|
||||||
WebRtcAecm_FreeCore(aecm);
|
WebRtcAecm_FreeCore(aecm);
|
||||||
aecm = NULL;
|
return NULL;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
aecm->delay_estimator_farend = WebRtc_CreateDelayEstimatorFarend(PART_LEN1,
|
aecm->delay_estimator_farend = WebRtc_CreateDelayEstimatorFarend(PART_LEN1,
|
||||||
MAX_DELAY);
|
MAX_DELAY);
|
||||||
if (aecm->delay_estimator_farend == NULL) {
|
if (aecm->delay_estimator_farend == NULL) {
|
||||||
WebRtcAecm_FreeCore(aecm);
|
WebRtcAecm_FreeCore(aecm);
|
||||||
aecm = NULL;
|
return NULL;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
aecm->delay_estimator =
|
aecm->delay_estimator =
|
||||||
WebRtc_CreateDelayEstimator(aecm->delay_estimator_farend, 0);
|
WebRtc_CreateDelayEstimator(aecm->delay_estimator_farend, 0);
|
||||||
if (aecm->delay_estimator == NULL) {
|
if (aecm->delay_estimator == NULL) {
|
||||||
WebRtcAecm_FreeCore(aecm);
|
WebRtcAecm_FreeCore(aecm);
|
||||||
aecm = NULL;
|
return NULL;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
// TODO(bjornv): Explicitly disable robust delay validation until no
|
// TODO(bjornv): Explicitly disable robust delay validation until no
|
||||||
// performance regression has been established. Then remove the line.
|
// 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);
|
aecm->real_fft = WebRtcSpl_CreateRealFFT(PART_LEN_SHIFT);
|
||||||
if (aecm->real_fft == NULL) {
|
if (aecm->real_fft == NULL) {
|
||||||
WebRtcAecm_FreeCore(aecm);
|
WebRtcAecm_FreeCore(aecm);
|
||||||
aecm = NULL;
|
return NULL;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init some aecm pointers. 16 and 32 byte alignment is only necessary
|
// 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 = (int32_t*) (((uintptr_t)
|
||||||
aecm->channelAdapt32_buf + 31) & ~ 31);
|
aecm->channelAdapt32_buf + 31) & ~ 31);
|
||||||
|
|
||||||
return 0;
|
return aecm;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebRtcAecm_InitEchoPathCore(AecmCore* aecm, const int16_t* echo_path) {
|
void WebRtcAecm_InitEchoPathCore(AecmCore* aecm, const int16_t* echo_path) {
|
||||||
|
|||||||
@@ -134,27 +134,18 @@ typedef struct {
|
|||||||
} AecmCore;
|
} AecmCore;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// WebRtcAecm_CreateCore(...)
|
// WebRtcAecm_CreateCore()
|
||||||
//
|
//
|
||||||
// Allocates the memory needed by the AECM. The memory needs to be
|
// Allocates the memory needed by the AECM. The memory needs to be
|
||||||
// initialized separately using the WebRtcAecm_InitCore() function.
|
// initialized separately using the WebRtcAecm_InitCore() function.
|
||||||
//
|
// Returns a pointer to the instance and a nullptr at failure.
|
||||||
// Input:
|
AecmCore* WebRtcAecm_CreateCore();
|
||||||
// - aecm : Instance that should be created
|
|
||||||
//
|
|
||||||
// Output:
|
|
||||||
// - aecm : Created instance
|
|
||||||
//
|
|
||||||
// Return value : 0 - Ok
|
|
||||||
// -1 - Error
|
|
||||||
//
|
|
||||||
int WebRtcAecm_CreateCore(AecmCore** aecm);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// WebRtcAecm_InitCore(...)
|
// WebRtcAecm_InitCore(...)
|
||||||
//
|
//
|
||||||
// This function initializes the AECM instant created with
|
// This function initializes the AECM instant created with
|
||||||
// WebRtcAecm_CreateCore(...)
|
// WebRtcAecm_CreateCore()
|
||||||
// Input:
|
// Input:
|
||||||
// - aecm : Pointer to the AECM instance
|
// - aecm : Pointer to the AECM instance
|
||||||
// - samplingFreq : Sampling Frequency
|
// - 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
|
// Stuffs the farend buffer if the estimated delay is too large
|
||||||
static int WebRtcAecm_DelayComp(AecMobile* aecmInst);
|
static int WebRtcAecm_DelayComp(AecMobile* aecmInst);
|
||||||
|
|
||||||
int32_t WebRtcAecm_Create(void **aecmInst)
|
void* WebRtcAecm_Create() {
|
||||||
{
|
AecMobile* aecm = malloc(sizeof(AecMobile));
|
||||||
AecMobile* aecm;
|
|
||||||
if (aecmInst == NULL)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
aecm = malloc(sizeof(AecMobile));
|
|
||||||
*aecmInst = aecm;
|
|
||||||
if (aecm == NULL)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
WebRtcSpl_Init();
|
WebRtcSpl_Init();
|
||||||
|
|
||||||
if (WebRtcAecm_CreateCore(&aecm->aecmCore) == -1)
|
aecm->aecmCore = WebRtcAecm_CreateCore();
|
||||||
{
|
if (!aecm->aecmCore) {
|
||||||
WebRtcAecm_Free(aecm);
|
WebRtcAecm_Free(aecm);
|
||||||
aecm = NULL;
|
return NULL;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
aecm->farendBuf = WebRtc_CreateBuffer(kBufSizeSamp,
|
aecm->farendBuf = WebRtc_CreateBuffer(kBufSizeSamp,
|
||||||
@@ -109,8 +96,7 @@ int32_t WebRtcAecm_Create(void **aecmInst)
|
|||||||
if (!aecm->farendBuf)
|
if (!aecm->farendBuf)
|
||||||
{
|
{
|
||||||
WebRtcAecm_Free(aecm);
|
WebRtcAecm_Free(aecm);
|
||||||
aecm = NULL;
|
return NULL;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
aecm->initFlag = 0;
|
aecm->initFlag = 0;
|
||||||
@@ -127,7 +113,7 @@ int32_t WebRtcAecm_Create(void **aecmInst)
|
|||||||
aecm->preCompFile = fopen("preComp.pcm", "wb");
|
aecm->preCompFile = fopen("preComp.pcm", "wb");
|
||||||
aecm->postCompFile = fopen("postComp.pcm", "wb");
|
aecm->postCompFile = fopen("postComp.pcm", "wb");
|
||||||
#endif // AEC_DEBUG
|
#endif // AEC_DEBUG
|
||||||
return 0;
|
return aecm;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebRtcAecm_Free(void* aecmInst) {
|
void WebRtcAecm_Free(void* aecmInst) {
|
||||||
|
|||||||
@@ -42,18 +42,9 @@ extern "C" {
|
|||||||
/*
|
/*
|
||||||
* Allocates the memory needed by the AECM. The memory needs to be
|
* Allocates the memory needed by the AECM. The memory needs to be
|
||||||
* initialized separately using the WebRtcAecm_Init() function.
|
* initialized separately using the WebRtcAecm_Init() function.
|
||||||
*
|
* Returns a pointer to the instance and a nullptr at failure.
|
||||||
* Inputs Description
|
|
||||||
* -------------------------------------------------------------------
|
|
||||||
* void** aecmInst Pointer to the AECM instance to be
|
|
||||||
* created and initialized
|
|
||||||
*
|
|
||||||
* Outputs Description
|
|
||||||
* -------------------------------------------------------------------
|
|
||||||
* int32_t return 0: OK
|
|
||||||
* -1: error
|
|
||||||
*/
|
*/
|
||||||
int32_t WebRtcAecm_Create(void **aecmInst);
|
void* WebRtcAecm_Create();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function releases the memory allocated by WebRtcAecm_Create()
|
* This function releases the memory allocated by WebRtcAecm_Create()
|
||||||
|
|||||||
@@ -250,14 +250,7 @@ int EchoControlMobileImpl::Initialize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void* EchoControlMobileImpl::CreateHandle() const {
|
void* EchoControlMobileImpl::CreateHandle() const {
|
||||||
Handle* handle = NULL;
|
return WebRtcAecm_Create();
|
||||||
if (WebRtcAecm_Create(&handle) != apm_->kNoError) {
|
|
||||||
handle = NULL;
|
|
||||||
} else {
|
|
||||||
assert(handle != NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
return handle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EchoControlMobileImpl::DestroyHandle(void* handle) const {
|
void EchoControlMobileImpl::DestroyHandle(void* handle) const {
|
||||||
|
|||||||
Reference in New Issue
Block a user