[pulseaudio-discuss] [PATCH 05/21 v2] loopback: Add hooks to track port latency offsets
Georg Chini
georg at chini.tk
Sun Feb 19 16:15:13 UTC 2017
The previous patch assumed constant port latency offsets. The offsets can
however be changed by the user, therefore these changes need to be tracked
as well. This patch adds the necessary hooks.
---
src/modules/module-loopback.c | 38 ++++++++++++++++++++++++++++++++++++--
src/pulsecore/core.h | 2 ++
src/pulsecore/sink.c | 2 ++
src/pulsecore/source.c | 2 ++
4 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/src/modules/module-loopback.c b/src/modules/module-loopback.c
index 8ec4723..e6b9e37 100644
--- a/src/modules/module-loopback.c
+++ b/src/modules/module-loopback.c
@@ -1064,7 +1064,7 @@ static int loopback_process_msg_cb(pa_msgobject *o, int code, void *userdata, in
* back to a smaller value is not handled because this is currently not implemented */
pa_log_warn("Source minimum latency increased to %0.2f ms", (double)current_latency / PA_USEC_PER_MSEC);
u->configured_source_latency = current_latency;
- update_latency_boundaries(u, u->source_output->source, u->sink_input->sink, false);
+ update_latency_boundaries(u, u->source_output->source, u->sink_input->sink, true);
}
return 0;
@@ -1078,7 +1078,7 @@ static int loopback_process_msg_cb(pa_msgobject *o, int code, void *userdata, in
* to a smaller value is not handled because this is currently not implemented */
pa_log_warn("Sink minimum latency increased to %0.2f ms", (double)current_latency / PA_USEC_PER_MSEC);
u->configured_sink_latency = current_latency;
- update_latency_boundaries(u, u->source_output->source, u->sink_input->sink, false);
+ update_latency_boundaries(u, u->source_output->source, u->sink_input->sink, true);
}
return 0;
@@ -1087,6 +1087,34 @@ static int loopback_process_msg_cb(pa_msgobject *o, int code, void *userdata, in
return 0;
}
+static pa_hook_result_t sink_port_latency_offset_changed_cb(pa_core *core, pa_sink *sink, struct userdata *u) {
+
+ if (!u->sink_input->sink)
+ return PA_HOOK_OK;
+
+ if (sink != u->sink_input->sink)
+ return PA_HOOK_OK;
+
+ u->sink_latency_offset = sink->port_latency_offset;
+ update_minimum_latency(u, sink, true);
+
+ return PA_HOOK_OK;
+}
+
+static pa_hook_result_t source_port_latency_offset_changed_cb(pa_core *core, pa_source *source, struct userdata *u) {
+
+ if (!u->source_output->source)
+ return PA_HOOK_OK;
+
+ if (source != u->source_output->source)
+ return PA_HOOK_OK;
+
+ u->source_latency_offset = source->port_latency_offset;
+ update_minimum_latency(u, u->sink_input->sink, true);
+
+ return PA_HOOK_OK;
+}
+
int pa__init(pa_module *m) {
pa_modargs *ma = NULL;
struct userdata *u;
@@ -1361,6 +1389,12 @@ int pa__init(pa_module *m) {
&& (n = pa_proplist_gets(u->source_output->source->proplist, PA_PROP_DEVICE_ICON_NAME)))
pa_proplist_sets(u->sink_input->proplist, PA_PROP_MEDIA_ICON_NAME, n);
+ /* Hooks to track changes of latency offsets */
+ pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_PORT_LATENCY_OFFSET_CHANGED],
+ PA_HOOK_NORMAL, (pa_hook_cb_t) sink_port_latency_offset_changed_cb, u);
+ pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_PORT_LATENCY_OFFSET_CHANGED],
+ PA_HOOK_NORMAL, (pa_hook_cb_t) source_port_latency_offset_changed_cb, u);
+
/* Setup message queue for main thread */
u->msg = pa_msgobject_new(loopback_msg);
u->msg->parent.process_msg = loopback_process_msg_cb;
diff --git a/src/pulsecore/core.h b/src/pulsecore/core.h
index 212f6f7..f793f4c 100644
--- a/src/pulsecore/core.h
+++ b/src/pulsecore/core.h
@@ -136,6 +136,8 @@ typedef enum pa_core_hook {
PA_CORE_HOOK_SAMPLE_CACHE_NEW,
PA_CORE_HOOK_SAMPLE_CACHE_CHANGED,
PA_CORE_HOOK_SAMPLE_CACHE_UNLINK,
+ PA_CORE_HOOK_SINK_PORT_LATENCY_OFFSET_CHANGED,
+ PA_CORE_HOOK_SOURCE_PORT_LATENCY_OFFSET_CHANGED,
PA_CORE_HOOK_MAX
} pa_core_hook_t;
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 6011f45..589bfef 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -3295,6 +3295,8 @@ void pa_sink_set_port_latency_offset(pa_sink *s, int64_t offset) {
pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SINK_MESSAGE_SET_PORT_LATENCY_OFFSET, NULL, offset, NULL) == 0);
else
s->thread_info.port_latency_offset = offset;
+
+ pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SINK_PORT_LATENCY_OFFSET_CHANGED], s);
}
/* Called from main context */
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index 09c953f..1425082 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -2586,6 +2586,8 @@ void pa_source_set_port_latency_offset(pa_source *s, int64_t offset) {
pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_SET_PORT_LATENCY_OFFSET, NULL, offset, NULL) == 0);
else
s->thread_info.port_latency_offset = offset;
+
+ pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SOURCE_PORT_LATENCY_OFFSET_CHANGED], s);
}
/* Called from main thread */
--
2.10.1
More information about the pulseaudio-discuss
mailing list