[pulseaudio-discuss] [PATCH 3/4] source: Add a latency offset which is inherited from the port

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


From: poljar <poljarinho at gmail.com>

A latency offset variable was added to the sink struct.

This is exactly the same as for the sink latency offset.
---
 src/pulsecore/source.c |   22 ++++++++++++++++++++++
 src/pulsecore/source.h |    7 +++++++
 2 files changed, 29 insertions(+)

diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index 6308f54..109ce89 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -296,6 +296,11 @@ pa_source* pa_source_new(
                 s->active_port = p;
     }
 
+    if (s->active_port)
+        pa_source_set_latency_offset(s, pa_device_port_get_latency_offset(s->active_port));
+    else
+        pa_source_set_latency_offset(s, 0);
+
     s->save_volume = data->save_volume;
     s->save_muted = data->save_muted;
 
@@ -323,6 +328,7 @@ pa_source* pa_source_new(
     pa_sw_cvolume_multiply(&s->thread_info.current_hw_volume, &s->soft_volume, &s->real_volume);
     s->thread_info.volume_change_safety_margin = core->deferred_volume_safety_margin_usec;
     s->thread_info.volume_change_extra_delay = core->deferred_volume_extra_delay_usec;
+    s->thread_info.latency_offset_copy = &s->latency_offset;
 
     /* FIXME: This should probably be moved to pa_source_put() */
     pa_assert_se(pa_idxset_put(core->sources, s, &s->index) >= 0);
@@ -1024,6 +1030,8 @@ pa_usec_t pa_source_get_latency(pa_source *s) {
 
     pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_GET_LATENCY, &usec, 0, NULL) == 0);
 
+    usec += pa_source_get_latency_offset(s);
+
     return usec;
 }
 
@@ -1051,6 +1059,8 @@ pa_usec_t pa_source_get_latency_within_thread(pa_source *s) {
     if (o->process_msg(o, PA_SOURCE_MESSAGE_GET_LATENCY, &usec, 0, NULL) < 0)
         return -1;
 
+    usec += pa_source_get_latency_offset(s);
+
     return usec;
 }
 
@@ -2507,6 +2517,18 @@ void pa_source_set_fixed_latency_within_thread(pa_source *s, pa_usec_t latency)
     pa_source_invalidate_requested_latency(s, FALSE);
 }
 
+void pa_source_set_latency_offset(pa_source *s, pa_usec_t latency) {
+    pa_source_assert_ref(s);
+
+    s->latency_offset = latency;
+}
+
+pa_usec_t pa_source_get_latency_offset(pa_source *s) {
+    pa_source_assert_ref(s);
+
+    return s->latency_offset;
+}
+
 /* Called from main thread */
 size_t pa_source_get_max_rewind(pa_source *s) {
     size_t r;
diff --git a/src/pulsecore/source.h b/src/pulsecore/source.h
index 30c2037..68c521a 100644
--- a/src/pulsecore/source.h
+++ b/src/pulsecore/source.h
@@ -109,8 +109,10 @@ struct pa_source {
 
     pa_memchunk silence;
 
+    /* The latency offset is inherited from the currently active port */
     pa_hashmap *ports;
     pa_device_port *active_port;
+    pa_usec_t latency_offset;
     pa_atomic_t mixer_dirty;
 
     unsigned priority;
@@ -209,6 +211,9 @@ struct pa_source {
 
         pa_usec_t fixed_latency; /* for sources with PA_SOURCE_DYNAMIC_LATENCY this is 0 */
 
+        /* This points to source->latency_offset */
+        pa_usec_t *latency_offset_copy;
+
         /* Delayed volume change events are queued here. The events
          * are stored in expiration order. The one expiring next is in
          * the head of the list. */
@@ -321,6 +326,7 @@ void pa_source_set_rtpoll(pa_source *s, pa_rtpoll *p);
 void pa_source_set_max_rewind(pa_source *s, size_t max_rewind);
 void pa_source_set_latency_range(pa_source *s, pa_usec_t min_latency, pa_usec_t max_latency);
 void pa_source_set_fixed_latency(pa_source *s, pa_usec_t latency);
+void pa_source_set_latency_offset(pa_source *s, pa_usec_t latency);
 
 void pa_source_detach(pa_source *s);
 void pa_source_attach(pa_source *s);
@@ -340,6 +346,7 @@ pa_usec_t pa_source_get_latency(pa_source *s);
 pa_usec_t pa_source_get_requested_latency(pa_source *s);
 void pa_source_get_latency_range(pa_source *s, pa_usec_t *min_latency, pa_usec_t *max_latency);
 pa_usec_t pa_source_get_fixed_latency(pa_source *s);
+pa_usec_t pa_source_get_latency_offset(pa_source *s);
 
 size_t pa_source_get_max_rewind(pa_source *s);
 
-- 
1.7.10.4



More information about the pulseaudio-discuss mailing list