"aec_method=<implementation to use> "
"aec_args=<parameters for the AEC engine> "
"save_aec=<save AEC data in /tmp> "
+ "autoloaded=<set if this module is being loaded automatically> "
));
/* NOTE: Make sure the enum and ec_table are maintained in the correct order */
#define DEFAULT_ADJUST_TIME_USEC (1*PA_USEC_PER_SEC)
#define DEFAULT_SAVE_AEC 0
+#define DEFAULT_AUTOLOADED FALSE
#define MEMBLOCKQ_MAXLENGTH (16*1024*1024)
pa_core *core;
pa_module *module;
+ pa_bool_t autoloaded;
uint32_t save_aec;
pa_echo_canceller *ec;
"aec_method",
"aec_args",
"save_aec",
+ "autoloaded",
NULL
};
struct userdata *u = userdata;
uint32_t old_rate, base_rate, new_rate;
int64_t diff_time;
- size_t fs;
+ /*size_t fs*/
struct snapshot latency_snapshot;
pa_assert(u);
/* calculate drift between capture and playback */
diff_time = calc_diff(u, &latency_snapshot);
- fs = pa_frame_size(&u->source_output->sample_spec);
+ /*fs = pa_frame_size(&u->source_output->sample_spec);*/
old_rate = u->sink_input->sample_spec.rate;
base_rate = u->source_output->sample_spec.rate;
* canceler does not work in this case. */
pa_asyncmsgq_post(u->asyncmsgq, PA_MSGOBJECT(u->source_output), SOURCE_OUTPUT_MESSAGE_APPLY_DIFF_TIME,
NULL, diff_time, NULL, NULL);
- //new_rate = base_rate - ((pa_usec_to_bytes (-diff_time, &u->source_output->sample_spec) / fs) * PA_USEC_PER_SEC) / u->adjust_time;
+ /*new_rate = base_rate - ((pa_usec_to_bytes(-diff_time, &u->source_output->sample_spec) / fs) * PA_USEC_PER_SEC) / u->adjust_time;*/
new_rate = base_rate;
}
else {
}
/* recording behind playback, we need to slowly adjust the rate to match */
- //new_rate = base_rate + ((pa_usec_to_bytes (diff_time, &u->source_output->sample_spec) / fs) * PA_USEC_PER_SEC) / u->adjust_time;
+ /*new_rate = base_rate + ((pa_usec_to_bytes(diff_time, &u->source_output->sample_spec) / fs) * PA_USEC_PER_SEC) / u->adjust_time;*/
/* assume equal samplerates for now */
new_rate = base_rate;
if (u->active_mask == 3)
pa_core_rttime_restart(u->core, u->time_event, pa_rtclock_now() + u->adjust_time);
- pa_atomic_store (&u->request_resync, 1);
+ pa_atomic_store(&u->request_resync, 1);
pa_source_output_cork(u->source_output, FALSE);
} else if (state == PA_SOURCE_SUSPENDED) {
u->active_mask &= ~1;
if (u->active_mask == 3)
pa_core_rttime_restart(u->core, u->time_event, pa_rtclock_now() + u->adjust_time);
- pa_atomic_store (&u->request_resync, 1);
+ pa_atomic_store(&u->request_resync, 1);
pa_sink_input_cork(u->sink_input, FALSE);
} else if (state == PA_SINK_SUSPENDED) {
u->active_mask &= ~2;
int64_t diff;
if (diff_time < 0) {
- diff = pa_usec_to_bytes (-diff_time, &u->source_output->sample_spec);
+ diff = pa_usec_to_bytes(-diff_time, &u->source_output->sample_spec);
if (diff > 0) {
/* add some extra safety samples to compensate for jitter in the
u->source_skip = 0;
}
} else if (diff_time > 0) {
- diff = pa_usec_to_bytes (diff_time, &u->source_output->sample_spec);
+ diff = pa_usec_to_bytes(diff_time, &u->source_output->sample_spec);
if (diff > 0) {
pa_log("playback too far ahead (%lld), drop source %lld", (long long) diff_time, (long long) diff);
u->in_push = FALSE;
if (pa_atomic_cmpxchg (&u->request_resync, 1, 0)) {
- do_resync (u);
+ do_resync(u);
}
pa_memblockq_push_align(u->source_memblockq, chunk);
if (i->thread_info.underrun_for > 0) {
pa_log_debug("Handling end of underrun.");
- pa_atomic_store (&u->request_resync, 1);
+ pa_atomic_store(&u->request_resync, 1);
}
/* let source thread handle the chunk. pass the sample count as well so that
pa_log_debug("Sink input update max rewind %lld", (long long) nbytes);
- pa_memblockq_set_maxrewind (u->sink_memblockq, nbytes);
+ pa_memblockq_set_maxrewind(u->sink_memblockq, nbytes);
pa_sink_set_max_rewind_within_thread(u->sink, nbytes);
}
pa_assert_ctl_context();
pa_assert_se(u = o->userdata);
- return TRUE;
+ return (u->source != dest) && (u->sink != dest->monitor_of);
}
/* Called from main context */
pa_sink_mute_changed(u->sink, i->muted);
}
-static pa_echo_canceller_method_t get_ec_method_from_string(const char *method)
-{
+static pa_echo_canceller_method_t get_ec_method_from_string(const char *method) {
if (strcmp(method, "speex") == 0)
return PA_ECHO_CANCELLER_SPEEX;
else if (strcmp(method, "adrian") == 0)
goto fail;
}
+ u->autoloaded = DEFAULT_AUTOLOADED;
+ if (pa_modargs_get_value_boolean(ma, "autoloaded", &u->autoloaded) < 0) {
+ pa_log("Failed to parse autoloaded value");
+ goto fail;
+ }
+
u->asyncmsgq = pa_asyncmsgq_new(0);
u->need_realign = TRUE;
if (u->ec->init) {
- if (!u->ec->init(u->ec, &source_ss, &source_map, &sink_ss, &sink_map, &u->blocksize, pa_modargs_get_value(ma, "aec_args", NULL))) {
+ if (!u->ec->init(u->core, u->ec, &source_ss, &source_map, &sink_ss, &sink_map, &u->blocksize, pa_modargs_get_value(ma, "aec_args", NULL))) {
pa_log("Failed to init AEC engine");
goto fail;
}
pa_source_new_data_set_channel_map(&source_data, &source_map);
pa_proplist_sets(source_data.proplist, PA_PROP_DEVICE_MASTER_DEVICE, source_master->name);
pa_proplist_sets(source_data.proplist, PA_PROP_DEVICE_CLASS, "filter");
- pa_proplist_sets(source_data.proplist, PA_PROP_DEVICE_INTENDED_ROLES, "phone");
+ if (!u->autoloaded)
+ pa_proplist_sets(source_data.proplist, PA_PROP_DEVICE_INTENDED_ROLES, "phone");
pa_proplist_sets(source_data.proplist, "device.echo-cancel.name", source_data.name);
if (pa_modargs_get_proplist(ma, "source_properties", source_data.proplist, PA_UPDATE_REPLACE) < 0) {
pa_sink_new_data_set_channel_map(&sink_data, &sink_map);
pa_proplist_sets(sink_data.proplist, PA_PROP_DEVICE_MASTER_DEVICE, sink_master->name);
pa_proplist_sets(sink_data.proplist, PA_PROP_DEVICE_CLASS, "filter");
- pa_proplist_sets(sink_data.proplist, PA_PROP_DEVICE_INTENDED_ROLES, "phone");
+ if (!u->autoloaded)
+ pa_proplist_sets(sink_data.proplist, PA_PROP_DEVICE_INTENDED_ROLES, "phone");
pa_proplist_sets(sink_data.proplist, "device.echo-cancel.name", sink_data.name);
if (pa_modargs_get_proplist(ma, "sink_properties", sink_data.proplist, PA_UPDATE_REPLACE) < 0) {
source_output_data.driver = __FILE__;
source_output_data.module = m;
source_output_data.source = source_master;
+ source_output_data.destination_source = u->source;
/* FIXME
source_output_data.flags = PA_SOURCE_OUTPUT_DONT_INHIBIT_AUTO_SUSPEND; */
u->source_output->moving = source_output_moving_cb;
u->source_output->userdata = u;
+ u->source->output_from_master = u->source_output;
+
/* Create sink input */
pa_sink_input_new_data_init(&sink_input_data);
sink_input_data.driver = __FILE__;
sink_input_data.module = m;
sink_input_data.sink = sink_master;
+ 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");
pa_sink_input_new_data_set_sample_spec(&sink_input_data, &sink_ss);
u->sink_input->mute_changed = sink_input_mute_changed_cb;
u->sink_input->userdata = u;
+ u->sink->input_to_master = u->sink_input;
+
pa_sink_input_get_silence(u->sink_input, &silence);
u->source_memblockq = pa_memblockq_new(0, MEMBLOCKQ_MAXLENGTH, 0,
return 0;
- fail:
+fail:
if (ma)
pa_modargs_free(ma);
pa_assert(m);
pa_assert_se(u = m->userdata);
- return pa_sink_linked_by(u->sink) + pa_source_linked_by(u->source);
+ return pa_sink_linked_by(u->sink) + pa_source_linked_by(u->source);
}
void pa__done(pa_module*m) {