From 3f08dc656dc22edf658a8393b5b03a46b23aa4e8 Mon Sep 17 00:00:00 2001 From: peah Date: Thu, 5 May 2016 03:03:55 -0700 Subject: [PATCH] Introduced the new APM data logging functionality into the AEC echo_cancellation.* API layer. BUG=webrtc:5298 Review-Url: https://codereview.webrtc.org/1952593002 Cr-Commit-Position: refs/heads/master@{#12635} --- .../audio_processing/aec/echo_cancellation.cc | 49 ++++--------------- .../aec/echo_cancellation_internal.h | 12 ++--- .../logging/apm_data_dumper.h | 26 ++++++++++ 3 files changed, 41 insertions(+), 46 deletions(-) diff --git a/webrtc/modules/audio_processing/aec/echo_cancellation.cc b/webrtc/modules/audio_processing/aec/echo_cancellation.cc index 6b1758a15a..e1dba6e84e 100644 --- a/webrtc/modules/audio_processing/aec/echo_cancellation.cc +++ b/webrtc/modules/audio_processing/aec/echo_cancellation.cc @@ -14,9 +14,6 @@ #include "webrtc/modules/audio_processing/aec/echo_cancellation.h" #include -#if WEBRTC_AEC_DEBUG_DUMP == 1 -#include -#endif #include #include @@ -27,14 +24,9 @@ extern "C" { #include "webrtc/modules/audio_processing/aec/aec_core.h" #include "webrtc/modules/audio_processing/aec/aec_resampler.h" #include "webrtc/modules/audio_processing/aec/echo_cancellation_internal.h" +#include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" #include "webrtc/typedefs.h" -// Check to verify that the define is properly set. -#if !defined(WEBRTC_AEC_DEBUG_DUMP) || \ - (WEBRTC_AEC_DEBUG_DUMP != 0 && WEBRTC_AEC_DEBUG_DUMP != 1) -#error "Set WEBRTC_AEC_DEBUG_DUMP to either 0 or 1" -#endif - namespace webrtc { // Measured delays [ms] @@ -127,11 +119,12 @@ static void ProcessExtended(Aec* self, int32_t skew); void* WebRtcAec_Create() { - Aec* aecpc = reinterpret_cast(malloc(sizeof(Aec))); + Aec* aecpc = new Aec(); if (!aecpc) { return NULL; } + aecpc->data_dumper.reset(new ApmDataDumper(aecpc->instance_count)); aecpc->aec = WebRtcAec_CreateAec(aecpc->instance_count); if (!aecpc->aec) { @@ -155,18 +148,7 @@ void* WebRtcAec_Create() { aecpc->initFlag = 0; -#if WEBRTC_AEC_DEBUG_DUMP == 1 - char filename[64]; - snprintf(filename, sizeof(filename), "aec_buf%d.dat", aecpc->instance_count); - aecpc->bufFile = fopen(filename, "wb"); - snprintf(filename, sizeof(filename), "aec_skew%d.dat", aecpc->instance_count); - aecpc->skewFile = fopen(filename, "wb"); - snprintf(filename, sizeof(filename), "aec_delay%d.dat", - aecpc->instance_count); - aecpc->delayFile = fopen(filename, "wb"); -#endif aecpc->instance_count++; - return aecpc; } @@ -179,19 +161,14 @@ void WebRtcAec_Free(void* aecInst) { WebRtc_FreeBuffer(aecpc->far_pre_buf); -#if WEBRTC_AEC_DEBUG_DUMP == 1 - fclose(aecpc->bufFile); - fclose(aecpc->skewFile); - fclose(aecpc->delayFile); -#endif - WebRtcAec_FreeAec(aecpc->aec); WebRtcAec_FreeResampler(aecpc->resampler); - free(aecpc); + delete aecpc; } int32_t WebRtcAec_Init(void* aecInst, int32_t sampFreq, int32_t scSampFreq) { Aec* aecpc = reinterpret_cast(aecInst); + aecpc->data_dumper->InitiateNewSetOfRecordings(); AecConfig aecConfig; if (sampFreq != 8000 && sampFreq != 16000 && sampFreq != 32000 && @@ -376,15 +353,9 @@ int32_t WebRtcAec_Process(void* aecInst, msInSndCardBuf, skew); } -#if WEBRTC_AEC_DEBUG_DUMP == 1 - { - int16_t far_buf_size_ms = (int16_t)(WebRtcAec_system_delay(aecpc->aec) / - (sampMsNb * aecpc->rate_factor)); - (void)fwrite(&far_buf_size_ms, 2, 1, aecpc->bufFile); - (void)fwrite(&aecpc->knownDelay, sizeof(aecpc->knownDelay), 1, - aecpc->delayFile); - } -#endif + int far_buf_size_samples = WebRtcAec_system_delay(aecpc->aec); + aecpc->data_dumper->DumpRaw("aec_system_delay", 1, &far_buf_size_samples); + aecpc->data_dumper->DumpRaw("aec_known_delay", 1, &aecpc->knownDelay); return retVal; } @@ -603,9 +574,7 @@ static int ProcessNormal(Aec* aecpc, aecpc->skew = maxSkewEst; } -#if WEBRTC_AEC_DEBUG_DUMP == 1 - (void)fwrite(&aecpc->skew, sizeof(aecpc->skew), 1, aecpc->skewFile); -#endif + aecpc->data_dumper->DumpRaw("aec_skew", 1, &aecpc->skew); } } diff --git a/webrtc/modules/audio_processing/aec/echo_cancellation_internal.h b/webrtc/modules/audio_processing/aec/echo_cancellation_internal.h index 188fb576f0..5e79626d6f 100644 --- a/webrtc/modules/audio_processing/aec/echo_cancellation_internal.h +++ b/webrtc/modules/audio_processing/aec/echo_cancellation_internal.h @@ -11,6 +11,8 @@ #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC_ECHO_CANCELLATION_INTERNAL_H_ #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_ECHO_CANCELLATION_INTERNAL_H_ +#include + extern "C" { #include "webrtc/common_audio/ring_buffer.h" } @@ -18,7 +20,11 @@ extern "C" { namespace webrtc { +class ApmDataDumper; + typedef struct Aec { + std::unique_ptr data_dumper; + int delayCtr; int sampFreq; int splitSampFreq; @@ -45,12 +51,6 @@ typedef struct Aec { int checkBuffSize; short lastDelayDiff; -#if WEBRTC_AEC_DEBUG_DUMP - FILE* bufFile; - FILE* delayFile; - FILE* skewFile; -#endif - // Structures void* resampler; diff --git a/webrtc/modules/audio_processing/logging/apm_data_dumper.h b/webrtc/modules/audio_processing/logging/apm_data_dumper.h index 18f9e5e181..93232b7c9d 100644 --- a/webrtc/modules/audio_processing/logging/apm_data_dumper.h +++ b/webrtc/modules/audio_processing/logging/apm_data_dumper.h @@ -73,6 +73,32 @@ class ApmDataDumper { #endif } + void DumpRaw(const char* name, int v_length, const int16_t* v) { +#if WEBRTC_AEC_DEBUG_DUMP == 1 + FILE* file = GetRawFile(name); + fwrite(v, sizeof(v[0]), v_length, file); +#endif + } + + void DumpRaw(const char* name, rtc::ArrayView v) { +#if WEBRTC_AEC_DEBUG_DUMP == 1 + DumpRaw(name, v.size(), v.data()); +#endif + } + + void DumpRaw(const char* name, int v_length, const int32_t* v) { +#if WEBRTC_AEC_DEBUG_DUMP == 1 + FILE* file = GetRawFile(name); + fwrite(v, sizeof(v[0]), v_length, file); +#endif + } + + void DumpRaw(const char* name, rtc::ArrayView v) { +#if WEBRTC_AEC_DEBUG_DUMP == 1 + DumpRaw(name, v.size(), v.data()); +#endif + } + void DumpWav(const char* name, int v_length, const float* v,