X-Git-Url: https://code.delx.au/pulseaudio/blobdiff_plain/c43e88553735d480aaf0b1525c64a37beb1d38f4..c93cfc1ca64a3d7e37a3ca63f42abb73ce72bfb6:/src/modules/echo-cancel/module-echo-cancel.c diff --git a/src/modules/echo-cancel/module-echo-cancel.c b/src/modules/echo-cancel/module-echo-cancel.c index 8ce6330d..9df2899d 100644 --- a/src/modules/echo-cancel/module-echo-cancel.c +++ b/src/modules/echo-cancel/module-echo-cancel.c @@ -58,7 +58,7 @@ PA_MODULE_AUTHOR("Wim Taymans"); PA_MODULE_DESCRIPTION("Echo Cancellation"); PA_MODULE_VERSION(PACKAGE_VERSION); -PA_MODULE_LOAD_ONCE(FALSE); +PA_MODULE_LOAD_ONCE(false); PA_MODULE_USAGE( _("source_name= " "source_properties= " @@ -140,8 +140,8 @@ static const pa_echo_canceller ec_table[] = { #define DEFAULT_CHANNELS 1 #define DEFAULT_ADJUST_TIME_USEC (1*PA_USEC_PER_SEC) #define DEFAULT_ADJUST_TOLERANCE (5*PA_USEC_PER_MSEC) -#define DEFAULT_SAVE_AEC FALSE -#define DEFAULT_AUTOLOADED FALSE +#define DEFAULT_SAVE_AEC false +#define DEFAULT_AUTOLOADED false #define MEMBLOCKQ_MAXLENGTH (16*1024*1024) @@ -206,28 +206,29 @@ struct userdata { pa_core *core; pa_module *module; - pa_bool_t autoloaded; - pa_bool_t dead; - pa_bool_t save_aec; + bool autoloaded; + bool dead; + bool save_aec; pa_echo_canceller *ec; + uint32_t source_output_blocksize; uint32_t source_blocksize; uint32_t sink_blocksize; - pa_bool_t need_realign; + bool need_realign; /* to wakeup the source I/O thread */ pa_asyncmsgq *asyncmsgq; pa_rtpoll_item *rtpoll_item_read, *rtpoll_item_write; pa_source *source; - pa_bool_t source_auto_desc; + bool source_auto_desc; pa_source_output *source_output; pa_memblockq *source_memblockq; /* echo canceler needs fixed sized chunks */ size_t source_skip; pa_sink *sink; - pa_bool_t sink_auto_desc; + bool sink_auto_desc; pa_sink_input *sink_input; pa_memblockq *sink_memblockq; int64_t send_counter; /* updated in sink IO thread */ @@ -249,7 +250,7 @@ struct userdata { FILE *canceled_file; FILE *drift_file; - pa_bool_t use_volume_sharing; + bool use_volume_sharing; struct { pa_cvolume current_volume; @@ -311,8 +312,8 @@ static int64_t calc_diff(struct userdata *u, struct snapshot *snapshot) { buffer_latency += source_delay + sink_delay; /* add the latency difference due to samples not yet transferred */ - send_counter = pa_bytes_to_usec(snapshot->send_counter, &u->sink_input->sample_spec); - recv_counter = pa_bytes_to_usec(snapshot->recv_counter, &u->source_output->sample_spec); + send_counter = pa_bytes_to_usec(snapshot->send_counter, &u->sink->sample_spec); + recv_counter = pa_bytes_to_usec(snapshot->recv_counter, &u->sink->sample_spec); if (recv_counter <= send_counter) buffer_latency += (int64_t) (send_counter - recv_counter); else @@ -418,7 +419,7 @@ static int source_process_msg_cb(pa_msgobject *o, int code, void *data, int64_t /* Add the latency internal to our source output on top */ pa_bytes_to_usec(pa_memblockq_get_length(u->source_output->thread_info.delay_memblockq), &u->source_output->source->sample_spec) + /* and the buffering we do on the source */ - pa_bytes_to_usec(u->source_blocksize, &u->source_output->source->sample_spec); + pa_bytes_to_usec(u->source_output_blocksize, &u->source_output->source->sample_spec); return 0; @@ -461,7 +462,6 @@ static int sink_process_msg_cb(pa_msgobject *o, int code, void *data, int64_t of return pa_sink_process_msg(o, code, data, offset, chunk); } - /* Called from main context */ static int source_set_state_cb(pa_source *s, pa_source_state_t state) { struct userdata *u; @@ -479,9 +479,9 @@ static int source_set_state_cb(pa_source *s, pa_source_state_t state) { pa_core_rttime_restart(u->core, u->time_event, pa_rtclock_now() + u->adjust_time); pa_atomic_store(&u->request_resync, 1); - pa_source_output_cork(u->source_output, FALSE); + pa_source_output_cork(u->source_output, false); } else if (state == PA_SOURCE_SUSPENDED) { - pa_source_output_cork(u->source_output, TRUE); + pa_source_output_cork(u->source_output, true); } return 0; @@ -504,9 +504,9 @@ static int sink_set_state_cb(pa_sink *s, pa_sink_state_t state) { pa_core_rttime_restart(u->core, u->time_event, pa_rtclock_now() + u->adjust_time); pa_atomic_store(&u->request_resync, 1); - pa_sink_input_cork(u->sink_input, FALSE); + pa_sink_input_cork(u->sink_input, false); } else if (state == PA_SINK_SUSPENDED) { - pa_sink_input_cork(u->sink_input, TRUE); + pa_sink_input_cork(u->sink_input, true); } return 0; @@ -565,7 +565,7 @@ static void sink_request_rewind_cb(pa_sink *s) { /* Just hand this one over to the master sink */ pa_sink_input_request_rewind(u->sink_input, - s->thread_info.rewind_nbytes, TRUE, FALSE, FALSE); + s->thread_info.rewind_nbytes, true, false, false); } /* Called from main context */ @@ -579,7 +579,7 @@ static void source_set_volume_cb(pa_source *s) { !PA_SOURCE_OUTPUT_IS_LINKED(pa_source_output_get_state(u->source_output))) return; - pa_source_output_set_volume(u->source_output, &s->real_volume, s->save_volume, TRUE); + pa_source_output_set_volume(u->source_output, &s->real_volume, s->save_volume, true); } /* Called from main context */ @@ -593,7 +593,7 @@ static void sink_set_volume_cb(pa_sink *s) { !PA_SINK_INPUT_IS_LINKED(pa_sink_input_get_state(u->sink_input))) return; - pa_sink_input_set_volume(u->sink_input, &s->real_volume, s->save_volume, TRUE); + pa_sink_input_set_volume(u->sink_input, &s->real_volume, s->save_volume, true); } /* Called from main context. */ @@ -608,7 +608,7 @@ static void source_get_volume_cb(pa_source *s) { !PA_SOURCE_OUTPUT_IS_LINKED(pa_source_output_get_state(u->source_output))) return; - pa_source_output_get_volume(u->source_output, &v, TRUE); + pa_source_output_get_volume(u->source_output, &v, true); if (pa_cvolume_equal(&s->real_volume, &v)) /* no change */ @@ -646,20 +646,6 @@ static void sink_set_mute_cb(pa_sink *s) { pa_sink_input_set_mute(u->sink_input, s->muted, s->save_muted); } -/* Called from main context */ -static void source_get_mute_cb(pa_source *s) { - struct userdata *u; - - pa_source_assert_ref(s); - pa_assert_se(u = s->userdata); - - if (!PA_SOURCE_IS_LINKED(pa_source_get_state(s)) || - !PA_SOURCE_OUTPUT_IS_LINKED(pa_source_output_get_state(u->source_output))) - return; - - pa_source_output_get_mute(u->source_output); -} - /* Called from source I/O thread context. */ static void apply_diff_time(struct userdata *u, int64_t diff_time) { int64_t diff; @@ -737,7 +723,7 @@ static void do_push_drift_comp(struct userdata *u) { */ drift = ((float)(plen - u->sink_rem) - (rlen - u->source_rem)) / ((float)(rlen - u->source_rem)); u->sink_rem = plen % u->sink_blocksize; - u->source_rem = rlen % u->source_blocksize; + u->source_rem = rlen % u->source_output_blocksize; /* Now let the canceller work its drift compensation magic */ u->ec->set_drift(u->ec, drift); @@ -770,14 +756,14 @@ static void do_push_drift_comp(struct userdata *u) { } /* And now the capture samples */ - while (rlen >= u->source_blocksize) { - pa_memblockq_peek_fixed_size(u->source_memblockq, u->source_blocksize, &rchunk); + while (rlen >= u->source_output_blocksize) { + pa_memblockq_peek_fixed_size(u->source_memblockq, u->source_output_blocksize, &rchunk); rdata = pa_memblock_acquire(rchunk.memblock); rdata += rchunk.index; cchunk.index = 0; - cchunk.length = u->source_blocksize; + cchunk.length = u->source_output_blocksize; cchunk.memblock = pa_memblock_new(u->source->core->mempool, cchunk.length); cdata = pa_memblock_acquire(cchunk.memblock); @@ -785,11 +771,11 @@ static void do_push_drift_comp(struct userdata *u) { if (u->save_aec) { if (u->drift_file) - fprintf(u->drift_file, "c %d\n", u->source_blocksize); + fprintf(u->drift_file, "c %d\n", u->source_output_blocksize); if (u->captured_file) - unused = fwrite(rdata, 1, u->source_blocksize, u->captured_file); + unused = fwrite(rdata, 1, u->source_output_blocksize, u->captured_file); if (u->canceled_file) - unused = fwrite(cdata, 1, u->source_blocksize, u->canceled_file); + unused = fwrite(cdata, 1, u->source_output_blocksize, u->canceled_file); } pa_memblock_release(cchunk.memblock); @@ -800,8 +786,8 @@ static void do_push_drift_comp(struct userdata *u) { pa_source_post(u->source, &cchunk); pa_memblock_unref(cchunk.memblock); - pa_memblockq_drop(u->source_memblockq, u->source_blocksize); - rlen -= u->source_blocksize; + pa_memblockq_drop(u->source_memblockq, u->source_output_blocksize); + rlen -= u->source_output_blocksize; } } @@ -819,61 +805,62 @@ static void do_push(struct userdata *u) { rlen = pa_memblockq_get_length(u->source_memblockq); plen = pa_memblockq_get_length(u->sink_memblockq); - while (rlen >= u->source_blocksize) { - /* take fixed block from recorded samples */ - pa_memblockq_peek_fixed_size(u->source_memblockq, u->source_blocksize, &rchunk); - - if (plen >= u->sink_blocksize) { - /* take fixed block from played samples */ - pa_memblockq_peek_fixed_size(u->sink_memblockq, u->sink_blocksize, &pchunk); - - rdata = pa_memblock_acquire(rchunk.memblock); - rdata += rchunk.index; - pdata = pa_memblock_acquire(pchunk.memblock); - pdata += pchunk.index; - - cchunk.index = 0; - cchunk.length = u->source_blocksize; - cchunk.memblock = pa_memblock_new(u->source->core->mempool, cchunk.length); - cdata = pa_memblock_acquire(cchunk.memblock); - - if (u->save_aec) { - if (u->captured_file) - unused = fwrite(rdata, 1, u->source_blocksize, u->captured_file); - if (u->played_file) - unused = fwrite(pdata, 1, u->sink_blocksize, u->played_file); - } + while (rlen >= u->source_output_blocksize) { - /* perform echo cancellation */ - u->ec->run(u->ec, rdata, pdata, cdata); + /* take fixed blocks from recorded and played samples */ + pa_memblockq_peek_fixed_size(u->source_memblockq, u->source_output_blocksize, &rchunk); + pa_memblockq_peek_fixed_size(u->sink_memblockq, u->sink_blocksize, &pchunk); - if (u->save_aec) { - if (u->canceled_file) - unused = fwrite(cdata, 1, u->source_blocksize, u->canceled_file); - } + /* we ran out of played data and pchunk has been filled with silence bytes */ + if (plen < u->sink_blocksize) + pa_memblockq_seek(u->sink_memblockq, u->sink_blocksize - plen, PA_SEEK_RELATIVE, true); - pa_memblock_release(cchunk.memblock); - pa_memblock_release(pchunk.memblock); - pa_memblock_release(rchunk.memblock); + rdata = pa_memblock_acquire(rchunk.memblock); + rdata += rchunk.index; + pdata = pa_memblock_acquire(pchunk.memblock); + pdata += pchunk.index; - /* drop consumed sink samples */ - pa_memblockq_drop(u->sink_memblockq, u->sink_blocksize); - pa_memblock_unref(pchunk.memblock); + cchunk.index = 0; + cchunk.length = u->source_blocksize; + cchunk.memblock = pa_memblock_new(u->source->core->mempool, cchunk.length); + cdata = pa_memblock_acquire(cchunk.memblock); - pa_memblock_unref(rchunk.memblock); - /* the filtered samples now become the samples from our - * source */ - rchunk = cchunk; + if (u->save_aec) { + if (u->captured_file) + unused = fwrite(rdata, 1, u->source_output_blocksize, u->captured_file); + if (u->played_file) + unused = fwrite(pdata, 1, u->sink_blocksize, u->played_file); + } - plen -= u->sink_blocksize; + /* perform echo cancellation */ + u->ec->run(u->ec, rdata, pdata, cdata); + + if (u->save_aec) { + if (u->canceled_file) + unused = fwrite(cdata, 1, u->source_blocksize, u->canceled_file); } - /* forward the (echo-canceled) data to the virtual source */ - pa_source_post(u->source, &rchunk); + pa_memblock_release(cchunk.memblock); + pa_memblock_release(pchunk.memblock); + pa_memblock_release(rchunk.memblock); + + /* drop consumed source samples */ + pa_memblockq_drop(u->source_memblockq, u->source_output_blocksize); pa_memblock_unref(rchunk.memblock); + rlen -= u->source_output_blocksize; - pa_memblockq_drop(u->source_memblockq, u->source_blocksize); - rlen -= u->source_blocksize; + /* drop consumed sink samples */ + pa_memblockq_drop(u->sink_memblockq, u->sink_blocksize); + pa_memblock_unref(pchunk.memblock); + + if (plen >= u->sink_blocksize) + plen -= u->sink_blocksize; + else + plen = 0; + + /* forward the (echo-canceled) data to the virtual source */ + pa_source_post(u->source, &cchunk); + pa_memblock_unref(cchunk.memblock); } } @@ -908,7 +895,7 @@ static void source_output_push_cb(pa_source_output *o, const pa_memchunk *chunk) plen = pa_memblockq_get_length(u->sink_memblockq); /* Let's not do anything else till we have enough data to process */ - if (rlen < u->source_blocksize) + if (rlen < u->source_output_blocksize) return; /* See if we need to drop samples in order to sync */ @@ -924,7 +911,7 @@ static void source_output_push_cb(pa_source_output *o, const pa_memchunk *chunk) * means the only way to try to catch up is drop sink samples and let * the canceller cope up with this. */ to_skip = rlen >= u->source_skip ? u->source_skip : rlen; - to_skip -= to_skip % u->source_blocksize; + to_skip -= to_skip % u->source_output_blocksize; if (to_skip) { pa_memblockq_peek_fixed_size(u->source_memblockq, to_skip, &rchunk); @@ -937,9 +924,9 @@ static void source_output_push_cb(pa_source_output *o, const pa_memchunk *chunk) u->source_skip -= to_skip; } - if (rlen && u->source_skip % u->source_blocksize) { - u->sink_skip += (uint64_t) (u->source_blocksize - (u->source_skip % u->source_blocksize)) * u->sink_blocksize / u->source_blocksize; - u->source_skip -= (u->source_skip % u->source_blocksize); + if (rlen && u->source_skip % u->source_output_blocksize) { + u->sink_skip += (uint64_t) (u->source_output_blocksize - (u->source_skip % u->source_output_blocksize)) * u->sink_blocksize / u->source_output_blocksize; + u->source_skip -= (u->source_skip % u->source_output_blocksize); } } @@ -1002,7 +989,7 @@ static void source_output_process_rewind_cb(pa_source_output *o, size_t nbytes) pa_memblockq_rewind(u->sink_memblockq, nbytes); /* manipulate write index */ - pa_memblockq_seek(u->source_memblockq, -nbytes, PA_SEEK_RELATIVE, TRUE); + pa_memblockq_seek(u->source_memblockq, -nbytes, PA_SEEK_RELATIVE, true); pa_log_debug("Source rewind (%lld) %lld", (long long) nbytes, (long long) pa_memblockq_get_length (u->source_memblockq)); @@ -1057,7 +1044,7 @@ static int source_output_process_msg_cb(pa_msgobject *obj, int code, void *data, if (u->source_output->source->thread_info.state == PA_SOURCE_RUNNING) pa_memblockq_push_align(u->sink_memblockq, chunk); else - pa_memblockq_flush_write(u->sink_memblockq, TRUE); + pa_memblockq_flush_write(u->sink_memblockq, true); u->recv_counter += (int64_t) chunk->length; @@ -1068,9 +1055,9 @@ static int source_output_process_msg_cb(pa_msgobject *obj, int code, void *data, /* manipulate write index, never go past what we have */ if (PA_SOURCE_IS_OPENED(u->source_output->source->thread_info.state)) - pa_memblockq_seek(u->sink_memblockq, -offset, PA_SEEK_RELATIVE, TRUE); + pa_memblockq_seek(u->sink_memblockq, -offset, PA_SEEK_RELATIVE, true); else - pa_memblockq_flush_write(u->sink_memblockq, TRUE); + pa_memblockq_flush_write(u->sink_memblockq, true); pa_log_debug("Sink rewind (%lld)", (long long) offset); @@ -1299,7 +1286,6 @@ static void sink_input_attach_cb(pa_sink_input *i) { pa_sink_attach_within_thread(u->sink); } - /* Called from source I/O thread context. */ static void source_output_detach_cb(pa_source_output *o) { struct userdata *u; @@ -1363,7 +1349,7 @@ static void sink_input_state_change_cb(pa_sink_input *i, pa_sink_input_state_t s if (PA_SINK_INPUT_IS_LINKED(state) && i->thread_info.state == PA_SINK_INPUT_INIT) { pa_log_debug("Requesting rewind due to state change."); - pa_sink_input_request_rewind(i, 0, FALSE, TRUE, TRUE); + pa_sink_input_request_rewind(i, 0, false, true, true); } } @@ -1375,7 +1361,7 @@ static void source_output_kill_cb(pa_source_output *o) { pa_assert_ctl_context(); pa_assert_se(u = o->userdata); - u->dead = TRUE; + u->dead = true; /* The order here matters! We first kill the source output, followed * by the source. That means the source callbacks must be protected @@ -1391,7 +1377,7 @@ static void source_output_kill_cb(pa_source_output *o) { pa_log_debug("Source output kill %d", o->index); - pa_module_unload_request(u->module, TRUE); + pa_module_unload_request(u->module, true); } /* Called from main context */ @@ -1401,7 +1387,7 @@ static void sink_input_kill_cb(pa_sink_input *i) { pa_sink_input_assert_ref(i); pa_assert_se(u = i->userdata); - u->dead = TRUE; + u->dead = true; /* The order here matters! We first kill the sink input, followed * by the sink. That means the sink callbacks must be protected @@ -1417,11 +1403,11 @@ static void sink_input_kill_cb(pa_sink_input *i) { pa_log_debug("Sink input kill %d", i->index); - pa_module_unload_request(u->module, TRUE); + pa_module_unload_request(u->module, true); } /* Called from main context. */ -static pa_bool_t source_output_may_move_to_cb(pa_source_output *o, pa_source *dest) { +static bool source_output_may_move_to_cb(pa_source_output *o, pa_source *dest) { struct userdata *u; pa_source_output_assert_ref(o); @@ -1429,20 +1415,20 @@ static pa_bool_t source_output_may_move_to_cb(pa_source_output *o, pa_source *de pa_assert_se(u = o->userdata); if (u->dead || u->autoloaded) - return FALSE; + return false; return (u->source != dest) && (u->sink != dest->monitor_of); } /* Called from main context */ -static pa_bool_t sink_input_may_move_to_cb(pa_sink_input *i, pa_sink *dest) { +static bool sink_input_may_move_to_cb(pa_sink_input *i, pa_sink *dest) { struct userdata *u; pa_sink_input_assert_ref(i); pa_assert_se(u = i->userdata); if (u->dead || u->autoloaded) - return FALSE; + return false; return u->sink != dest; } @@ -1539,9 +1525,9 @@ static int canceller_process_msg_cb(pa_msgobject *o, int code, void *userdata, i pa_cvolume *v = (pa_cvolume *) userdata; if (u->use_volume_sharing) - pa_source_set_volume(u->source, v, TRUE, FALSE); + pa_source_set_volume(u->source, v, true, false); else - pa_source_output_set_volume(u->source_output, v, FALSE, TRUE); + pa_source_output_set_volume(u->source_output, v, false, true); break; } @@ -1645,8 +1631,8 @@ fail: /* Called from main context. */ int pa__init(pa_module*m) { struct userdata *u; - pa_sample_spec source_ss, sink_ss; - pa_channel_map source_map, sink_map; + pa_sample_spec source_output_ss, source_ss, sink_ss; + pa_channel_map source_output_map, source_map, sink_map; pa_modargs *ma; pa_source *source_master=NULL; pa_sink *sink_master=NULL; @@ -1698,9 +1684,9 @@ int pa__init(pa_module*m) { u->core = m->core; u->module = m; m->userdata = u; - u->dead = FALSE; + u->dead = false; - u->use_volume_sharing = TRUE; + u->use_volume_sharing = true; if (pa_modargs_get_value_boolean(ma, "use_volume_sharing", &u->use_volume_sharing) < 0) { pa_log("use_volume_sharing= expects a boolean argument"); goto fail; @@ -1744,14 +1730,26 @@ int pa__init(pa_module*m) { goto fail; u->asyncmsgq = pa_asyncmsgq_new(0); - u->need_realign = TRUE; + u->need_realign = true; + + source_output_ss = source_ss; + source_output_map = source_map; + + if (sink_ss.rate != source_ss.rate) { + pa_log_info("Sample rates of play and out stream differ. Adjusting rate of play stream."); + sink_ss.rate = source_ss.rate; + } pa_assert(u->ec->init); - if (!u->ec->init(u->core, u->ec, &source_ss, &source_map, &sink_ss, &sink_map, &nframes, pa_modargs_get_value(ma, "aec_args", NULL))) { + if (!u->ec->init(u->core, u->ec, &source_output_ss, &source_output_map, &sink_ss, &sink_map, &source_ss, &source_map, &nframes, pa_modargs_get_value(ma, "aec_args", NULL))) { pa_log("Failed to init AEC engine"); goto fail; } + pa_assert(source_output_ss.rate == source_ss.rate); + pa_assert(sink_ss.rate == source_ss.rate); + + u->source_output_blocksize = nframes * pa_frame_size(&source_output_ss); u->source_blocksize = nframes * pa_frame_size(&source_ss); u->sink_blocksize = nframes * pa_frame_size(&sink_ss); @@ -1798,12 +1796,11 @@ int pa__init(pa_module*m) { u->source->parent.process_msg = source_process_msg_cb; u->source->set_state = source_set_state_cb; u->source->update_requested_latency = source_update_requested_latency_cb; - pa_source_set_get_mute_callback(u->source, source_get_mute_cb); pa_source_set_set_mute_callback(u->source, source_set_mute_cb); if (!u->use_volume_sharing) { pa_source_set_get_volume_callback(u->source, source_get_volume_cb); pa_source_set_set_volume_callback(u->source, source_set_volume_cb); - pa_source_enable_decibel_volume(u->source, TRUE); + pa_source_enable_decibel_volume(u->source, true); } u->source->userdata = u; @@ -1853,7 +1850,7 @@ int pa__init(pa_module*m) { pa_sink_set_set_mute_callback(u->sink, sink_set_mute_cb); if (!u->use_volume_sharing) { pa_sink_set_set_volume_callback(u->sink, sink_set_volume_cb); - pa_sink_enable_decibel_volume(u->sink, TRUE); + pa_sink_enable_decibel_volume(u->sink, true); } u->sink->userdata = u; @@ -1863,15 +1860,13 @@ int pa__init(pa_module*m) { pa_source_output_new_data_init(&source_output_data); source_output_data.driver = __FILE__; source_output_data.module = m; - pa_source_output_new_data_set_source(&source_output_data, source_master, FALSE); + pa_source_output_new_data_set_source(&source_output_data, source_master, false); source_output_data.destination_source = u->source; - /* FIXME - source_output_data.flags = PA_SOURCE_OUTPUT_DONT_INHIBIT_AUTO_SUSPEND; */ pa_proplist_sets(source_output_data.proplist, PA_PROP_MEDIA_NAME, "Echo-Cancel Source Stream"); pa_proplist_sets(source_output_data.proplist, PA_PROP_MEDIA_ROLE, "filter"); - pa_source_output_new_data_set_sample_spec(&source_output_data, &source_ss); - pa_source_output_new_data_set_channel_map(&source_output_data, &source_map); + pa_source_output_new_data_set_sample_spec(&source_output_data, &source_output_ss); + pa_source_output_new_data_set_channel_map(&source_output_data, &source_output_map); pa_source_output_new(&u->source_output, m->core, &source_output_data); pa_source_output_new_data_done(&source_output_data); @@ -1900,7 +1895,7 @@ int pa__init(pa_module*m) { pa_sink_input_new_data_init(&sink_input_data); sink_input_data.driver = __FILE__; sink_input_data.module = m; - pa_sink_input_new_data_set_sink(&sink_input_data, sink_master, FALSE); + pa_sink_input_new_data_set_sink(&sink_input_data, sink_master, false); sink_input_data.origin_sink = u->sink; pa_proplist_sets(sink_input_data.proplist, PA_PROP_MEDIA_NAME, "Echo-Cancel Sink Stream"); pa_proplist_sets(sink_input_data.proplist, PA_PROP_MEDIA_ROLE, "filter"); @@ -1938,9 +1933,9 @@ int pa__init(pa_module*m) { pa_sink_input_get_silence(u->sink_input, &silence); u->source_memblockq = pa_memblockq_new("module-echo-cancel source_memblockq", 0, MEMBLOCKQ_MAXLENGTH, 0, - &source_ss, 1, 1, 0, &silence); + &source_output_ss, 1, 1, 0, &silence); u->sink_memblockq = pa_memblockq_new("module-echo-cancel sink_memblockq", 0, MEMBLOCKQ_MAXLENGTH, 0, - &sink_ss, 1, 1, 0, &silence); + &sink_ss, 0, 1, 0, &silence); pa_memblock_unref(silence.memblock); @@ -2019,7 +2014,7 @@ void pa__done(pa_module*m) { if (!(u = m->userdata)) return; - u->dead = TRUE; + u->dead = true; /* See comments in source_output_kill_cb() above regarding * destruction order! */ @@ -2082,8 +2077,8 @@ void pa__done(pa_module*m) { */ int main(int argc, char* argv[]) { struct userdata u; - pa_sample_spec source_ss, sink_ss; - pa_channel_map source_map, sink_map; + pa_sample_spec source_output_ss, source_ss, sink_ss; + pa_channel_map source_output_map, source_map, sink_map; pa_modargs *ma = NULL; uint8_t *rdata = NULL, *pdata = NULL, *cdata = NULL; int unused PA_GCC_UNUSED; @@ -2092,6 +2087,9 @@ int main(int argc, char* argv[]) { float drift; uint32_t nframes; + if (!getenv("MAKE_CHECK")) + pa_log_set_level(PA_LOG_DEBUG); + pa_memzero(&u, sizeof(u)); if (argc < 4 || argc > 7) { @@ -2100,17 +2098,17 @@ int main(int argc, char* argv[]) { u.captured_file = fopen(argv[2], "rb"); if (u.captured_file == NULL) { - perror ("fopen failed"); + perror ("Could not open capture file"); goto fail; } u.played_file = fopen(argv[1], "rb"); if (u.played_file == NULL) { - perror ("fopen failed"); + perror ("Could not open play file"); goto fail; } u.canceled_file = fopen(argv[3], "wb"); if (u.canceled_file == NULL) { - perror ("fopen failed"); + perror ("Could not open canceled file"); goto fail; } @@ -2136,34 +2134,38 @@ int main(int argc, char* argv[]) { if (init_common(ma, &u, &source_ss, &source_map) < 0) goto fail; - if (!u.ec->init(u.core, u.ec, &source_ss, &source_map, &sink_ss, &sink_map, &nframes, - (argc > 5) ? argv[5] : NULL )) { + source_output_ss = source_ss; + source_output_map = source_map; + + if (!u.ec->init(u.core, u.ec, &source_output_ss, &source_output_map, &sink_ss, &sink_map, &source_ss, &source_map, &nframes, + pa_modargs_get_value(ma, "aec_args", NULL))) { pa_log("Failed to init AEC engine"); goto fail; } + u.source_output_blocksize = nframes * pa_frame_size(&source_output_ss); u.source_blocksize = nframes * pa_frame_size(&source_ss); u.sink_blocksize = nframes * pa_frame_size(&sink_ss); if (u.ec->params.drift_compensation) { - if (argc < 7) { + if (argc < 6) { pa_log("Drift compensation enabled but drift file not specified"); goto fail; } - u.drift_file = fopen(argv[6], "rt"); + u.drift_file = fopen(argv[5], "rt"); if (u.drift_file == NULL) { - perror ("fopen failed"); + perror ("Could not open drift file"); goto fail; } } - rdata = pa_xmalloc(u.source_blocksize); + rdata = pa_xmalloc(u.source_output_blocksize); pdata = pa_xmalloc(u.sink_blocksize); cdata = pa_xmalloc(u.source_blocksize); if (!u.ec->params.drift_compensation) { - while (fread(rdata, u.source_blocksize, 1, u.captured_file) > 0) { + while (fread(rdata, u.source_output_blocksize, 1, u.captured_file) > 0) { if (fread(pdata, u.sink_blocksize, 1, u.played_file) == 0) { perror("Played file ended before captured file"); goto fail; @@ -2251,7 +2253,7 @@ out: return ret; usage: - pa_log("Usage: %s play_file rec_file out_file [module args] [aec_args] [drift_file]", argv[0]); + pa_log("Usage: %s play_file rec_file out_file [module args] [drift_file]", argv[0]); fail: ret = -1;