[pulseaudio-discuss] [PATCH 2/6] sink, source, device-port: renames to distinguish latency offsets

Chris Billington chrisjbillington at gmail.com
Fri Jan 22 17:31:34 PST 2016


Renamed all variables pertaining to latency offsets of sinks and sources,
calling them "port_latency_offset" or similar instead. All of these variables
refer to latency offsets inherited from ports, rather than being unique to
the sinks or sources themselves.

This change is to pave the way for additional functionality for setting
latency offsets on sources and sinks independenly from the value they inherit
from their port. In order to implement them we first need this rename so that
the two latency offsets can be stored individually and summed when reporting
the total latency of the source or sink.

The renames made are:

pa_sink_set_latency_offset() -> pa_sink_set_port_latency_offset()
pa_source_set_latency_offset() -> pa_source_set_port_latency_offset()
sink->latency_offset -> sink->port_latency_offset
sink->thread_info.latency_offset -> sink->thread_info.port_latency_offset
source->latency_offset -> source->port_latency_offset
source->thread_info.latency_offset -> source->thread_info.port_latency_offset
PA_SINK_MESSAGE_SET_LATENCY_OFFSET -> PA_SINK_MESSAGE_SET_PORT_LATENCY_OFFSET
PA_SOURCE_MESSAGE_SET_LATENCY_OFFSET -> PA_SOURCE_MESSAGE_SET_PORT_LATENCY_OFFSET
source->thread_info.latency_offset -> source->thread_info.port_latency_offset
---
 src/pulsecore/device-port.c |  4 ++--
 src/pulsecore/sink.c        | 28 ++++++++++++++--------------
 src/pulsecore/sink.h        | 10 +++++-----
 src/pulsecore/source.c      | 28 ++++++++++++++--------------
 src/pulsecore/source.h      | 10 +++++-----
 5 files changed, 40 insertions(+), 40 deletions(-)

diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
index 5807d3e..ab3b2e8 100644
--- a/src/pulsecore/device-port.c
+++ b/src/pulsecore/device-port.c
@@ -161,7 +161,7 @@ void pa_device_port_set_latency_offset(pa_device_port *p, int64_t offset) {
 
             PA_IDXSET_FOREACH(sink, p->core->sinks, state) {
                 if (sink->active_port == p) {
-                    pa_sink_set_latency_offset(sink, p->latency_offset);
+                    pa_sink_set_port_latency_offset(sink, p->latency_offset);
                     break;
                 }
             }
@@ -174,7 +174,7 @@ void pa_device_port_set_latency_offset(pa_device_port *p, int64_t offset) {
 
             PA_IDXSET_FOREACH(source, p->core->sources, state) {
                 if (source->active_port == p) {
-                    pa_source_set_latency_offset(source, p->latency_offset);
+                    pa_source_set_port_latency_offset(source, p->latency_offset);
                     break;
                 }
             }
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 0b44fc7..86656f6 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -310,9 +310,9 @@ pa_sink* pa_sink_new(
         s->active_port = pa_device_port_find_best(s->ports);
 
     if (s->active_port)
-        s->latency_offset = s->active_port->latency_offset;
+        s->port_latency_offset = s->active_port->latency_offset;
     else
-        s->latency_offset = 0;
+        s->port_latency_offset = 0;
 
     s->save_volume = data->save_volume;
     s->save_muted = data->save_muted;
@@ -345,7 +345,7 @@ pa_sink* pa_sink_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 = s->latency_offset;
+    s->thread_info.port_latency_offset = s->port_latency_offset;
 
     /* FIXME: This should probably be moved to pa_sink_put() */
     pa_assert_se(pa_idxset_put(core->sinks, s, &s->index) >= 0);
@@ -1507,8 +1507,8 @@ pa_usec_t pa_sink_get_latency(pa_sink *s) {
 
     /* usec is unsigned, so check that the offset can be added to usec without
      * underflowing. */
-    if (-s->latency_offset <= (int64_t) usec)
-        usec += s->latency_offset;
+    if (-s->port_latency_offset <= (int64_t) usec)
+        usec += s->port_latency_offset;
     else
         usec = 0;
 
@@ -1541,8 +1541,8 @@ pa_usec_t pa_sink_get_latency_within_thread(pa_sink *s) {
 
     /* usec is unsigned, so check that the offset can be added to usec without
      * underflowing. */
-    if (-s->thread_info.latency_offset <= (int64_t) usec)
-        usec += s->thread_info.latency_offset;
+    if (-s->thread_info.port_latency_offset <= (int64_t) usec)
+        usec += s->thread_info.port_latency_offset;
     else
         usec = 0;
 
@@ -2888,8 +2888,8 @@ int pa_sink_process_msg(pa_msgobject *o, int code, void *userdata, int64_t offse
             pa_sink_get_mute(s, true);
             return 0;
 
-        case PA_SINK_MESSAGE_SET_LATENCY_OFFSET:
-            s->thread_info.latency_offset = offset;
+        case PA_SINK_MESSAGE_SET_PORT_LATENCY_OFFSET:
+            s->thread_info.port_latency_offset = offset;
             return 0;
 
         case PA_SINK_MESSAGE_GET_LATENCY:
@@ -3288,15 +3288,15 @@ void pa_sink_set_fixed_latency_within_thread(pa_sink *s, pa_usec_t latency) {
 }
 
 /* Called from main context */
-void pa_sink_set_latency_offset(pa_sink *s, int64_t offset) {
+void pa_sink_set_port_latency_offset(pa_sink *s, int64_t offset) {
     pa_sink_assert_ref(s);
 
-    s->latency_offset = offset;
+    s->port_latency_offset = offset;
 
     if (PA_SINK_IS_LINKED(s->state))
-        pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SINK_MESSAGE_SET_LATENCY_OFFSET, NULL, offset, NULL) == 0);
+        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.latency_offset = offset;
+        s->thread_info.port_latency_offset = offset;
 }
 
 /* Called from main context */
@@ -3369,7 +3369,7 @@ int pa_sink_set_port(pa_sink *s, const char *name, bool save) {
     s->active_port = port;
     s->save_port = save;
 
-    pa_sink_set_latency_offset(s, s->active_port->latency_offset);
+    pa_sink_set_port_latency_offset(s, s->active_port->latency_offset);
 
     pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SINK_PORT_CHANGED], s);
 
diff --git a/src/pulsecore/sink.h b/src/pulsecore/sink.h
index 5df109e..06a8ee9 100644
--- a/src/pulsecore/sink.h
+++ b/src/pulsecore/sink.h
@@ -112,7 +112,7 @@ struct pa_sink {
     pa_atomic_t mixer_dirty;
 
     /* The latency offset is inherited from the currently active port */
-    int64_t latency_offset;
+    int64_t port_latency_offset;
 
     unsigned priority;
 
@@ -281,8 +281,8 @@ struct pa_sink {
          * in changing it */
         pa_usec_t fixed_latency; /* for sinks with PA_SINK_DYNAMIC_LATENCY this is 0 */
 
-        /* This latency offset is a direct copy from s->latency_offset */
-        int64_t latency_offset;
+        /* This latency offset is a direct copy from s->port_latency_offset */
+        int64_t port_latency_offset;
 
         /* Delayed volume change events are queued here. The events
          * are stored in expiration order. The one expiring next is in
@@ -331,7 +331,7 @@ typedef enum pa_sink_message {
     PA_SINK_MESSAGE_SET_MAX_REQUEST,
     PA_SINK_MESSAGE_SET_PORT,
     PA_SINK_MESSAGE_UPDATE_VOLUME_AND_MUTE,
-    PA_SINK_MESSAGE_SET_LATENCY_OFFSET,
+    PA_SINK_MESSAGE_SET_PORT_LATENCY_OFFSET,
     PA_SINK_MESSAGE_MAX
 } pa_sink_message_t;
 
@@ -417,7 +417,7 @@ unsigned pa_device_init_priority(pa_proplist *p);
 /**** May be called by everyone, from main context */
 
 int pa_sink_update_rate(pa_sink *s, uint32_t rate, bool passthrough);
-void pa_sink_set_latency_offset(pa_sink *s, int64_t offset);
+void pa_sink_set_port_latency_offset(pa_sink *s, int64_t offset);
 
 /* The returned value is supposed to be in the time domain of the sound card! */
 pa_usec_t pa_sink_get_latency(pa_sink *s);
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index 9c5d6e9..da64e6b 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -298,9 +298,9 @@ pa_source* pa_source_new(
         s->active_port = pa_device_port_find_best(s->ports);
 
     if (s->active_port)
-        s->latency_offset = s->active_port->latency_offset;
+        s->port_latency_offset = s->active_port->latency_offset;
     else
-        s->latency_offset = 0;
+        s->port_latency_offset = 0;
 
     s->save_volume = data->save_volume;
     s->save_muted = data->save_muted;
@@ -330,7 +330,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 = s->latency_offset;
+    s->thread_info.port_latency_offset = s->port_latency_offset;
 
     /* FIXME: This should probably be moved to pa_source_put() */
     pa_assert_se(pa_idxset_put(core->sources, s, &s->index) >= 0);
@@ -1098,8 +1098,8 @@ pa_usec_t pa_source_get_latency(pa_source *s) {
 
     /* usec is unsigned, so check that the offset can be added to usec without
      * underflowing. */
-    if (-s->latency_offset <= (int64_t) usec)
-        usec += s->latency_offset;
+    if (-s->port_latency_offset <= (int64_t) usec)
+        usec += s->port_latency_offset;
     else
         usec = 0;
 
@@ -1132,8 +1132,8 @@ pa_usec_t pa_source_get_latency_within_thread(pa_source *s) {
 
     /* usec is unsigned, so check that the offset can be added to usec without
      * underflowing. */
-    if (-s->thread_info.latency_offset <= (int64_t) usec)
-        usec += s->thread_info.latency_offset;
+    if (-s->thread_info.port_latency_offset <= (int64_t) usec)
+        usec += s->thread_info.port_latency_offset;
     else
         usec = 0;
 
@@ -2239,8 +2239,8 @@ int pa_source_process_msg(pa_msgobject *object, int code, void *userdata, int64_
             pa_source_get_mute(s, true);
             return 0;
 
-        case PA_SOURCE_MESSAGE_SET_LATENCY_OFFSET:
-            s->thread_info.latency_offset = offset;
+        case PA_SOURCE_MESSAGE_SET_PORT_LATENCY_OFFSET:
+            s->thread_info.port_latency_offset = offset;
             return 0;
 
         case PA_SOURCE_MESSAGE_MAX:
@@ -2567,15 +2567,15 @@ void pa_source_set_fixed_latency_within_thread(pa_source *s, pa_usec_t latency)
 }
 
 /* Called from main thread */
-void pa_source_set_latency_offset(pa_source *s, int64_t offset) {
+void pa_source_set_port_latency_offset(pa_source *s, int64_t offset) {
     pa_source_assert_ref(s);
 
-    s->latency_offset = offset;
+    s->port_latency_offset = offset;
 
     if (PA_SOURCE_IS_LINKED(s->state))
-        pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_SET_LATENCY_OFFSET, NULL, offset, NULL) == 0);
+        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.latency_offset = offset;
+        s->thread_info.port_latency_offset = offset;
 }
 
 /* Called from main thread */
@@ -2634,7 +2634,7 @@ int pa_source_set_port(pa_source *s, const char *name, bool save) {
     s->active_port = port;
     s->save_port = save;
 
-    pa_source_set_latency_offset(s, s->active_port->latency_offset);
+    pa_source_set_port_latency_offset(s, s->active_port->latency_offset);
 
     pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SOURCE_PORT_CHANGED], s);
 
diff --git a/src/pulsecore/source.h b/src/pulsecore/source.h
index 19fb41b..31cd158 100644
--- a/src/pulsecore/source.h
+++ b/src/pulsecore/source.h
@@ -113,7 +113,7 @@ struct pa_source {
     pa_atomic_t mixer_dirty;
 
     /* The latency offset is inherited from the currently active port */
-    int64_t latency_offset;
+    int64_t port_latency_offset;
 
     unsigned priority;
 
@@ -223,8 +223,8 @@ struct pa_source {
 
         pa_usec_t fixed_latency; /* for sources with PA_SOURCE_DYNAMIC_LATENCY this is 0 */
 
-        /* This latency offset is a direct copy from s->latency_offset */
-        int64_t latency_offset;
+        /* This latency offset is a direct copy from s->port_latency_offset */
+        int64_t port_latency_offset;
 
         /* Delayed volume change events are queued here. The events
          * are stored in expiration order. The one expiring next is in
@@ -269,7 +269,7 @@ typedef enum pa_source_message {
     PA_SOURCE_MESSAGE_SET_MAX_REWIND,
     PA_SOURCE_MESSAGE_SET_PORT,
     PA_SOURCE_MESSAGE_UPDATE_VOLUME_AND_MUTE,
-    PA_SOURCE_MESSAGE_SET_LATENCY_OFFSET,
+    PA_SOURCE_MESSAGE_SET_PORT_LATENCY_OFFSET,
     PA_SOURCE_MESSAGE_MAX
 } pa_source_message_t;
 
@@ -350,7 +350,7 @@ void pa_source_update_flags(pa_source *s, pa_source_flags_t mask, pa_source_flag
 
 /*** May be called by everyone, from main context */
 
-void pa_source_set_latency_offset(pa_source *s, int64_t offset);
+void pa_source_set_port_latency_offset(pa_source *s, int64_t offset);
 
 /* The returned value is supposed to be in the time domain of the sound card! */
 pa_usec_t pa_source_get_latency(pa_source *s);
-- 
2.5.0



More information about the pulseaudio-discuss mailing list