echo-cancel: Allow enabling tracing output from the webrtc canceller

This commit is contained in:
Arun Raghavan 2016-02-17 19:47:00 +05:30
parent 6431636fe1
commit 426c98acbb
2 changed files with 41 additions and 1 deletions

View file

@ -66,6 +66,7 @@ struct pa_echo_canceller_params {
void *apm; void *apm;
uint32_t blocksize; uint32_t blocksize;
pa_sample_spec sample_spec; pa_sample_spec sample_spec;
void *trace_callback;
bool agc; bool agc;
} webrtc; } webrtc;
#endif #endif

View file

@ -35,6 +35,7 @@ PA_C_DECL_END
#include <webrtc/modules/audio_processing/include/audio_processing.h> #include <webrtc/modules/audio_processing/include/audio_processing.h>
#include <webrtc/modules/interface/module_common_types.h> #include <webrtc/modules/interface/module_common_types.h>
#include <webrtc/system_wrappers/include/trace.h>
#define BLOCK_SIZE_US 10000 #define BLOCK_SIZE_US 10000
@ -48,6 +49,7 @@ PA_C_DECL_END
#define DEFAULT_DRIFT_COMPENSATION false #define DEFAULT_DRIFT_COMPENSATION false
#define DEFAULT_EXTENDED_FILTER false #define DEFAULT_EXTENDED_FILTER false
#define DEFAULT_INTELLIGIBILITY_ENHANCER false #define DEFAULT_INTELLIGIBILITY_ENHANCER false
#define DEFAULT_TRACE false
static const char* const valid_modargs[] = { static const char* const valid_modargs[] = {
"high_pass_filter", "high_pass_filter",
@ -60,6 +62,7 @@ static const char* const valid_modargs[] = {
"drift_compensation", "drift_compensation",
"extended_filter", "extended_filter",
"intelligibility_enhancer", "intelligibility_enhancer",
"trace",
NULL NULL
}; };
@ -78,6 +81,20 @@ static int routing_mode_from_string(const char *rmode) {
return -1; return -1;
} }
class PaWebrtcTraceCallback : public webrtc::TraceCallback {
void Print(webrtc::TraceLevel level, const char *message, int length)
{
if (level & webrtc::kTraceError || level & webrtc::kTraceCritical)
pa_log(message);
else if (level & webrtc::kTraceWarning)
pa_log_warn(message);
else if (level & webrtc::kTraceInfo)
pa_log_info(message);
else
pa_log_debug(message);
}
};
static void pa_webrtc_ec_fixate_spec(pa_sample_spec *rec_ss, pa_channel_map *rec_map, static void pa_webrtc_ec_fixate_spec(pa_sample_spec *rec_ss, pa_channel_map *rec_map,
pa_sample_spec *play_ss, pa_channel_map *play_map, pa_sample_spec *play_ss, pa_channel_map *play_map,
pa_sample_spec *out_ss, pa_channel_map *out_map) pa_sample_spec *out_ss, pa_channel_map *out_map)
@ -114,6 +131,7 @@ bool pa_webrtc_ec_init(pa_core *c, pa_echo_canceller *ec,
bool hpf, ns, agc, dgc, mobile, cn, ext_filter, intelligibility; bool hpf, ns, agc, dgc, mobile, cn, ext_filter, intelligibility;
int rm = -1; int rm = -1;
pa_modargs *ma; pa_modargs *ma;
bool trace = false;
if (!(ma = pa_modargs_new(args, valid_modargs))) { if (!(ma = pa_modargs_new(args, valid_modargs))) {
pa_log("Failed to parse submodule arguments."); pa_log("Failed to parse submodule arguments.");
@ -201,6 +219,19 @@ bool pa_webrtc_ec_init(pa_core *c, pa_echo_canceller *ec,
if (intelligibility) if (intelligibility)
pa_log_warn("The intelligibility enhancer is not currently supported"); pa_log_warn("The intelligibility enhancer is not currently supported");
trace = DEFAULT_TRACE;
if (pa_modargs_get_value_boolean(ma, "trace", &trace) < 0) {
pa_log("Failed to parse trace value");
goto fail;
}
if (trace) {
webrtc::Trace::CreateTrace();
webrtc::Trace::set_level_filter(webrtc::kTraceAll);
ec->params.priv.webrtc.trace_callback = new PaWebrtcTraceCallback();
webrtc::Trace::SetTraceCallback((PaWebrtcTraceCallback *) ec->params.priv.webrtc.trace_callback);
}
pa_webrtc_ec_fixate_spec(rec_ss, rec_map, play_ss, play_map, out_ss, out_map); pa_webrtc_ec_fixate_spec(rec_ss, rec_map, play_ss, play_map, out_ss, out_map);
apm = webrtc::AudioProcessing::Create(config); apm = webrtc::AudioProcessing::Create(config);
@ -263,7 +294,10 @@ bool pa_webrtc_ec_init(pa_core *c, pa_echo_canceller *ec,
fail: fail:
if (ma) if (ma)
pa_modargs_free(ma); pa_modargs_free(ma);
if (apm) if (ec->params.priv.webrtc.trace_callback) {
webrtc::Trace::ReturnTrace();
delete ((PaWebrtcTraceCallback *) ec->params.priv.webrtc.trace_callback);
} if (apm)
delete apm; delete apm;
return false; return false;
@ -335,6 +369,11 @@ void pa_webrtc_ec_run(pa_echo_canceller *ec, const uint8_t *rec, const uint8_t *
} }
void pa_webrtc_ec_done(pa_echo_canceller *ec) { void pa_webrtc_ec_done(pa_echo_canceller *ec) {
if (ec->params.priv.webrtc.trace_callback) {
webrtc::Trace::ReturnTrace();
delete ((PaWebrtcTraceCallback *) ec->params.priv.webrtc.trace_callback);
}
if (ec->params.priv.webrtc.apm) { if (ec->params.priv.webrtc.apm) {
delete (webrtc::AudioProcessing*)ec->params.priv.webrtc.apm; delete (webrtc::AudioProcessing*)ec->params.priv.webrtc.apm;
ec->params.priv.webrtc.apm = NULL; ec->params.priv.webrtc.apm = NULL;