diff --git a/webrtc/modules/audio_coding/main/source/acm_neteq.cc b/webrtc/modules/audio_coding/main/source/acm_neteq.cc index 4f575d3d5a..d9451783d5 100644 --- a/webrtc/modules/audio_coding/main/source/acm_neteq.cc +++ b/webrtc/modules/audio_coding/main/source/acm_neteq.cc @@ -23,6 +23,7 @@ #include "webrtc/system_wrappers/interface/rw_lock_wrapper.h" #include "webrtc/system_wrappers/interface/tick_util.h" #include "webrtc/system_wrappers/interface/trace.h" +#include "webrtc/system_wrappers/interface/trace_event.h" namespace webrtc { @@ -655,6 +656,21 @@ int32_t ACMNetEQ::RecOut(AudioFrame& audio_frame) { } previous_audio_activity_ = audio_frame.vad_activity_; + WebRtcNetEQ_ProcessingActivity processing_stats; + WebRtcNetEQ_GetProcessingActivity(inst_[0], &processing_stats); + TRACE_EVENT2("webrtc", "ACM::RecOut", + "accelerate bgn", processing_stats.accelerate_bgn_samples, + "accelerate normal", processing_stats.accelerate_normal_samples); + TRACE_EVENT2("webrtc", "ACM::RecOut", + "expand bgn", processing_stats.expand_bgn_sampels, + "expand normal", processing_stats.expand_normal_samples); + TRACE_EVENT2("webrtc", "ACM::RecOut", + "preemptive bgn", processing_stats.preemptive_expand_bgn_samples, + "preemptive normal", + processing_stats.preemptive_expand_normal_samples); + TRACE_EVENT2("webrtc", "ACM::RecOut", + "merge bgn", processing_stats.merge_expand_bgn_samples, + "merge normal", processing_stats.merge_expand_normal_samples); return 0; } diff --git a/webrtc/modules/audio_coding/neteq/accelerate.c b/webrtc/modules/audio_coding/neteq/accelerate.c index ce3f3b2352..a345a8fdcd 100644 --- a/webrtc/modules/audio_coding/neteq/accelerate.c +++ b/webrtc/modules/audio_coding/neteq/accelerate.c @@ -166,6 +166,8 @@ int WebRtcNetEQ_Accelerate(DSPInst_t *inst, /* update statistics */ inst->statInst.accelerateLength += w16_bestIndex; + /* Short-term activity statistics. */ + inst->activity_stats.accelerate_bgn_samples += w16_bestIndex; return 0; } /* end of special code for BGN mode */ @@ -456,6 +458,8 @@ int WebRtcNetEQ_Accelerate(DSPInst_t *inst, /* Update in-call statistics */ inst->statInst.accelerateLength += w16_bestIndex; + /* Short-term activity statistics. */ + inst->activity_stats.accelarate_normal_samples += w16_bestIndex; return 0; } diff --git a/webrtc/modules/audio_coding/neteq/dsp.c b/webrtc/modules/audio_coding/neteq/dsp.c index e840ad1b4e..4153d06880 100644 --- a/webrtc/modules/audio_coding/neteq/dsp.c +++ b/webrtc/modules/audio_coding/neteq/dsp.c @@ -396,6 +396,23 @@ int WebRtcNetEQ_ClearPostCallStats(DSPInst_t *inst) return (0); } +/**************************************************************************** + * WebRtcNetEQ_ClearActivityStats(...) + * + * Reset processing activity statistics. + * + * Input: + * - inst : NetEQ DSP instance + * + * Output: + * - inst : Updated instance + * + */ + +void WebRtcNetEQ_ClearActivityStats(DSPInst_t *inst) { + memset(&inst->activity_stats, 0, sizeof(ActivityStats)); +} + #ifdef NETEQ_VAD /**************************************************************************** diff --git a/webrtc/modules/audio_coding/neteq/dsp.h b/webrtc/modules/audio_coding/neteq/dsp.h index 54522729fd..d6e587efc6 100644 --- a/webrtc/modules/audio_coding/neteq/dsp.h +++ b/webrtc/modules/audio_coding/neteq/dsp.h @@ -316,6 +316,9 @@ typedef struct DSPInst_t_ /* Internal statistics instance */ DSPStats_t statInst; + /* Internal instance for short-term processing activity. */ + ActivityStats activity_stats; + #ifdef NETEQ_STEREO /* Pointer to Master/Slave info */ MasterSlaveInfo *msInfo; @@ -398,6 +401,21 @@ int WebRtcNetEQ_ClearInCallStats(DSPInst_t *inst); int WebRtcNetEQ_ClearPostCallStats(DSPInst_t *inst); +/**************************************************************************** + * WebRtcNetEQ_ClearActivityStats(...) + * + * Reset processing activity statistics. + * + * Input: + * - inst : NetEQ DSP instance + * + * Output: + * - inst : Updated instance + * + */ + +void WebRtcNetEQ_ClearActivityStats(DSPInst_t *inst); + /**************************************************************************** * WebRtcNetEQ_RecOutInternal(...) * diff --git a/webrtc/modules/audio_coding/neteq/expand.c b/webrtc/modules/audio_coding/neteq/expand.c index 6a69925b9a..9959f9222d 100644 --- a/webrtc/modules/audio_coding/neteq/expand.c +++ b/webrtc/modules/audio_coding/neteq/expand.c @@ -1141,11 +1141,15 @@ int WebRtcNetEQ_Expand(DSPInst_t *inst, { /* Only noise expansion */ inst->statInst.expandedNoiseSamples += *pw16_len; + /* Short-term activity statistics. */ + inst->activity_stats.expand_bgn_samples += *pw16_len; } else { /* Voice expand (note: not necessarily _voiced_) */ inst->statInst.expandedVoiceSamples += *pw16_len; + /* Short-term activity statistics. */ + inst->activity_stats.expand_normal_samples += *pw16_len; } } diff --git a/webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_internal.h b/webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_internal.h index c124e26fa3..46be2d128c 100644 --- a/webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_internal.h +++ b/webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_internal.h @@ -117,6 +117,46 @@ typedef struct */ int WebRtcNetEQ_GetNetworkStatistics(void *inst, WebRtcNetEQ_NetworkStatistics *stats); + +typedef struct { + /* Samples removed from background noise only segments. */ + int accelerate_bgn_samples; + + /* Samples removed from normal audio segments. */ + int accelerate_normal_samples; + + /* Number of samples synthesized during background noise only segments. */ + int expand_bgn_sampels; + + /* Number of samples synthesized during normal audio segments. */ + int expand_normal_samples; + + /* Number of samples synthesized during background noise only segments, + * in preemptive mode. */ + int preemptive_expand_bgn_samples; + + /* Number of samples synthesized during normal audio segments, in preemptive + * mode. */ + int preemptive_expand_normal_samples; + + /* Number of samples synthesized during background noise only segments, + * while merging. */ + int merge_expand_bgn_samples; + + /* Number of samples synthesized during normal audio segments, while + * merging. */ + int merge_expand_normal_samples; +} WebRtcNetEQ_ProcessingActivity; + +/* + * Get the processing activities from NetEQ. + * The statistics are reset after the query. + * This API is meant to obtain processing activities in high granularity, + * e.g. per RecOut() call. + */ +void WebRtcNetEQ_GetProcessingActivity(void* inst, + WebRtcNetEQ_ProcessingActivity* stat); + /* * Get the raw waiting times for decoded frames. The function writes the last * recorded waiting times (from frame arrival to frame decoding) to the memory diff --git a/webrtc/modules/audio_coding/neteq/merge.c b/webrtc/modules/audio_coding/neteq/merge.c index bd5239c3d0..78da2c7c7d 100644 --- a/webrtc/modules/audio_coding/neteq/merge.c +++ b/webrtc/modules/audio_coding/neteq/merge.c @@ -535,11 +535,17 @@ int WebRtcNetEQ_Merge(DSPInst_t *inst, { /* expansion generates noise only */ inst->statInst.expandedNoiseSamples += (*pw16_len - w16_decodedLen); + /* Short-term activity statistics. */ + inst->activity_stats.merge_expand_bgn_samples += + (*pw16_len - w16_decodedLen); } else { /* expansion generates more than only noise */ inst->statInst.expandedVoiceSamples += (*pw16_len - w16_decodedLen); + /* Short-term activity statistics. */ + inst->activity_stats.merge_expand_normal_samples += + (*pw16_len - w16_decodedLen); } inst->statInst.expandLength += (*pw16_len - w16_decodedLen); diff --git a/webrtc/modules/audio_coding/neteq/neteq_statistics.h b/webrtc/modules/audio_coding/neteq/neteq_statistics.h index f355b58057..bba5b06b96 100644 --- a/webrtc/modules/audio_coding/neteq/neteq_statistics.h +++ b/webrtc/modules/audio_coding/neteq/neteq_statistics.h @@ -37,5 +37,20 @@ typedef struct } DSPStats_t; +typedef struct { + int preemptive_expand_bgn_samples; + int preemptive_expand_normal_samples; + + int expand_bgn_samples; + int expand_normal_samples; + + int merge_expand_bgn_samples; + int merge_expand_normal_samples; + + int accelerate_bgn_samples; + int accelarate_normal_samples; +} ActivityStats; + + #endif diff --git a/webrtc/modules/audio_coding/neteq/preemptive_expand.c b/webrtc/modules/audio_coding/neteq/preemptive_expand.c index 172a171ada..e56c062841 100644 --- a/webrtc/modules/audio_coding/neteq/preemptive_expand.c +++ b/webrtc/modules/audio_coding/neteq/preemptive_expand.c @@ -181,6 +181,8 @@ int WebRtcNetEQ_PreEmptiveExpand(DSPInst_t *inst, /* update statistics */ inst->statInst.preemptiveLength += w16_bestIndex; + /* Short-term activity statistics. */ + inst->activity_stats.preemptive_expand_bgn_samples += w16_bestIndex; return 0; } /* end of special code for BGN mode */ @@ -489,7 +491,8 @@ int WebRtcNetEQ_PreEmptiveExpand(DSPInst_t *inst, /* Update in-call statistics */ inst->statInst.preemptiveLength += w16_bestIndex; - + /* Short-term activity statistics. */ + inst->activity_stats.preemptive_expand_normal_samples += w16_bestIndex; return 0; } else diff --git a/webrtc/modules/audio_coding/neteq/webrtc_neteq.c b/webrtc/modules/audio_coding/neteq/webrtc_neteq.c index 38b3ce4d3a..1be013302d 100644 --- a/webrtc/modules/audio_coding/neteq/webrtc_neteq.c +++ b/webrtc/modules/audio_coding/neteq/webrtc_neteq.c @@ -1644,3 +1644,30 @@ int WebRtcNetEQ_SetVADMode(void *inst, int mode) #endif /* NETEQ_VAD */ } + +void WebRtcNetEQ_GetProcessingActivity(void *inst, + WebRtcNetEQ_ProcessingActivity *stats) { + MainInst_t *NetEqMainInst = (MainInst_t*) inst; + + stats->accelerate_bgn_samples = + NetEqMainInst->DSPinst.activity_stats.accelerate_bgn_samples; + stats->accelerate_normal_samples = + NetEqMainInst->DSPinst.activity_stats.accelarate_normal_samples; + + stats->expand_bgn_sampels = + NetEqMainInst->DSPinst.activity_stats.expand_bgn_samples; + stats->expand_normal_samples = + NetEqMainInst->DSPinst.activity_stats.expand_normal_samples; + + stats->preemptive_expand_bgn_samples = + NetEqMainInst->DSPinst.activity_stats.preemptive_expand_bgn_samples; + stats->preemptive_expand_normal_samples = + NetEqMainInst->DSPinst.activity_stats.preemptive_expand_normal_samples; + + stats->merge_expand_bgn_samples = + NetEqMainInst->DSPinst.activity_stats.merge_expand_bgn_samples; + stats->merge_expand_normal_samples = + NetEqMainInst->DSPinst.activity_stats.merge_expand_normal_samples; + + WebRtcNetEQ_ClearActivityStats(&NetEqMainInst->DSPinst); +}