SOURCE_OUTPUT_MESSAGE_LATENCY_SNAPSHOT
};
+static void enable_adjust_timer(struct userdata *u, bool enable);
+
/* Called from main context */
static void teardown(struct userdata *u) {
pa_assert(u);
pa_asyncmsgq_flush(u->asyncmsgq, 0);
u->adjust_time = 0;
- if (u->time_event) {
- u->core->mainloop->time_free(u->time_event);
- u->time_event = NULL;
- }
+ enable_adjust_timer(u, false);
if (u->sink_input)
pa_sink_input_unlink(u->sink_input);
adjust_rates(u);
}
+/* Called from main context */
+static void enable_adjust_timer(struct userdata *u, bool enable) {
+ if (enable) {
+ if (u->time_event || u->adjust_time <= 0)
+ return;
+
+ u->time_event = pa_core_rttime_new(u->module->core, pa_rtclock_now() + u->adjust_time, time_callback, u);
+ } else {
+ if (!u->time_event)
+ return;
+
+ u->core->mainloop->time_free(u->time_event);
+ u->time_event = NULL;
+ }
+}
+
+/* Called from main context */
+static void update_adjust_timer(struct userdata *u) {
+ if (u->sink_input->state == PA_SINK_INPUT_CORKED || u->source_output->state == PA_SOURCE_OUTPUT_CORKED)
+ enable_adjust_timer(u, false);
+ else
+ enable_adjust_timer(u, true);
+}
+
/* Called from input thread context */
static void source_output_push_cb(pa_source_output *o, const pa_memchunk *chunk) {
struct userdata *u;
pa_assert_se(u = o->userdata);
pa_sink_input_cork(u->sink_input, suspended);
+
+ update_adjust_timer(u);
}
/* Called from output thread context */
pa_assert_ctl_context();
- if (u->adjust_time > 0)
+ if (u->time_event)
adjust_rates(u);
return 0;
}
pa_assert_se(u = i->userdata);
pa_source_output_cork(u->source_output, suspended);
+
+ update_adjust_timer(u);
}
int pa__init(pa_module *m) {
if (pa_sink_get_state(u->sink_input->sink) != PA_SINK_SUSPENDED)
pa_source_output_cork(u->source_output, FALSE);
- if (u->adjust_time > 0)
- u->time_event = pa_core_rttime_new(m->core, pa_rtclock_now() + u->adjust_time, time_callback, u);
+ update_adjust_timer(u);
pa_modargs_free(ma);
return 0;