[pulseaudio-discuss] [PATCH 1/4] device-port: Add a latency variable to the port struct

poljar (Damir Jelic) poljarinho at gmail.com
Sun Jun 17 05:47:44 PDT 2012


From: poljar <poljarinho at gmail.com>

A latency offset variable was added to the port struct and functions to
for handling a custom latency.

We can now attach a latency to the port which will be added to the
sink/source latency if the port is active.
---
 src/pulsecore/device-port.c |   34 ++++++++++++++++++++++++++++++++++
 src/pulsecore/device-port.h |    6 ++++++
 2 files changed, 40 insertions(+)

diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
index 5870913..c5639b8 100644
--- a/src/pulsecore/device-port.c
+++ b/src/pulsecore/device-port.c
@@ -97,6 +97,7 @@ pa_device_port *pa_device_port_new(pa_core *c, const char *name, const char *des
     p->profiles = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
     p->is_input = FALSE;
     p->is_output = FALSE;
+    p->latency_offset = 0;
     p->proplist = pa_proplist_new();
 
     return p;
@@ -112,3 +113,36 @@ void pa_device_port_hashmap_free(pa_hashmap *h) {
 
     pa_hashmap_free(h, NULL, NULL);
 }
+
+void pa_device_port_set_latency_offset(pa_device_port *p, pa_usec_t latency) {
+    uint32_t state;
+    union {
+        pa_sink *sink;
+        pa_source *source;
+    } data;
+
+    pa_assert(p);
+
+    p->latency_offset = latency;
+
+    if (p->is_output) {
+        PA_IDXSET_FOREACH(data.sink, p->core->sinks, state)
+            if (data.sink->active_port == p) {
+                pa_sink_set_latency_offset(data.sink, p->latency_offset);
+                break;
+            }
+
+    } else {
+        PA_IDXSET_FOREACH(data.source, p->core->sources, state)
+            if (data.source->active_port == p) {
+                pa_source_set_latency_offset(data.source, p->latency_offset);
+                break;
+        }
+    }
+}
+
+pa_usec_t pa_device_port_get_latency_offset(pa_device_port *p) {
+    pa_assert(p);
+
+    return p->latency_offset;
+}
diff --git a/src/pulsecore/device-port.h b/src/pulsecore/device-port.h
index 63d5ccf..77984db 100644
--- a/src/pulsecore/device-port.h
+++ b/src/pulsecore/device-port.h
@@ -51,6 +51,7 @@ struct pa_device_port {
     pa_hashmap *profiles; /* Does not own the profiles */
     pa_bool_t is_input:1;
     pa_bool_t is_output:1;
+    pa_usec_t latency_offset;
 
     /* .. followed by some implementation specific data */
 };
@@ -67,4 +68,9 @@ void pa_device_port_hashmap_free(pa_hashmap *h);
 /* The port's available status has changed */
 void pa_device_port_set_available(pa_device_port *p, pa_port_available_t available);
 
+/* Functions for handling the extra latency */
+void pa_device_port_set_latency_offset(pa_device_port *p, pa_usec_t latency);
+
+pa_usec_t pa_device_port_get_latency_offset(pa_device_port *p);
+
 #endif
-- 
1.7.10.4



More information about the pulseaudio-discuss mailing list