[pulseaudio-commits] 2 commits - src/pulsecore

Tanu Kaskinen tanuk at kemper.freedesktop.org
Thu Jun 28 06:39:21 PDT 2012


 src/pulsecore/cli-command.c |    2 +-
 src/pulsecore/device-port.c |    2 +-
 src/pulsecore/device-port.h |    4 ++--
 src/pulsecore/sink.c        |   22 ++++++++++++++++------
 src/pulsecore/sink.h        |    6 +++---
 src/pulsecore/source.c      |   22 ++++++++++++++++------
 src/pulsecore/source.h      |    6 +++---
 7 files changed, 42 insertions(+), 22 deletions(-)

New commits:
commit 0c8fdf30d103b0ed877917f39cf6003f40867400
Author: Tanu Kaskinen <tanuk at iki.fi>
Date:   Thu Jun 28 16:34:56 2012 +0300

    sink, source: Fix setting the latency offset when the sink/source is unlinked.

diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 1a1332d..6186204 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -3256,7 +3256,7 @@ void pa_sink_set_latency_offset(pa_sink *s, int64_t 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);
     else
-        s->thread_info.fixed_latency = offset;
+        s->thread_info.latency_offset = offset;
 }
 
 /* Called from main context */
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index 9e3a7dc..f59abea 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -2540,7 +2540,7 @@ void pa_source_set_latency_offset(pa_source *s, int64_t 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);
     else
-        s->thread_info.fixed_latency = offset;
+        s->thread_info.latency_offset = offset;
 }
 
 /* Called from main thread */

commit bf4091dcf8a6d9b5fe627a7d1cad56c24a74a587
Author: poljar (Damir Jelić) <poljarinho at gmail.com>
Date:   Wed Jun 27 17:38:42 2012 +0200

    device-port: Change the latency offset type to a signed int.
    
    The latency offset type should be signed (int64_t) so we can also add
    a negative latency offset.
    
    This also includes changing the type of the sink/source
    offsets and updating pacmd so it handles negative numbers.

diff --git a/src/pulsecore/cli-command.c b/src/pulsecore/cli-command.c
index 33f4d49..a772e1e 100644
--- a/src/pulsecore/cli-command.c
+++ b/src/pulsecore/cli-command.c
@@ -1766,7 +1766,7 @@ static int pa_cli_command_port_offset(pa_core *c, pa_tokenizer *t, pa_strbuf *bu
         return -1;
     }
 
-    pa_device_port_set_latency_offset(port, (pa_usec_t) offset);
+    pa_device_port_set_latency_offset(port, offset);
 
     return 0;
 }
diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
index 46e37e2..28879f7 100644
--- a/src/pulsecore/device-port.c
+++ b/src/pulsecore/device-port.c
@@ -114,7 +114,7 @@ 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 offset) {
+void pa_device_port_set_latency_offset(pa_device_port *p, int64_t offset) {
     uint32_t state;
 
     pa_assert(p);
diff --git a/src/pulsecore/device-port.h b/src/pulsecore/device-port.h
index 5880195..a5c6420 100644
--- a/src/pulsecore/device-port.h
+++ b/src/pulsecore/device-port.h
@@ -51,7 +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;
+    int64_t latency_offset;
 
     /* .. followed by some implementation specific data */
 };
@@ -68,6 +68,6 @@ 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);
 
-void pa_device_port_set_latency_offset(pa_device_port *p, pa_usec_t offset);
+void pa_device_port_set_latency_offset(pa_device_port *p, int64_t offset);
 
 #endif
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 545a8e1..1a1332d 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -1428,7 +1428,12 @@ pa_usec_t pa_sink_get_latency(pa_sink *s) {
 
     pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SINK_MESSAGE_GET_LATENCY, &usec, 0, NULL) == 0);
 
-    usec += s->latency_offset;
+    /* 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;
+    else
+        usec = 0;
 
     return usec;
 }
@@ -1457,7 +1462,12 @@ pa_usec_t pa_sink_get_latency_within_thread(pa_sink *s) {
     if (o->process_msg(o, PA_SINK_MESSAGE_GET_LATENCY, &usec, 0, NULL) < 0)
         return -1;
 
-    usec += s->thread_info.latency_offset;
+    /* 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;
+    else
+        usec = 0;
 
     return usec;
 }
@@ -2823,7 +2833,7 @@ int pa_sink_process_msg(pa_msgobject *o, int code, void *userdata, int64_t offse
             return 0;
 
         case PA_SINK_MESSAGE_SET_LATENCY_OFFSET:
-            s->thread_info.latency_offset = (pa_usec_t) offset;
+            s->thread_info.latency_offset = offset;
             return 0;
 
         case PA_SINK_MESSAGE_GET_LATENCY:
@@ -3238,13 +3248,13 @@ 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, pa_usec_t offset) {
+void pa_sink_set_latency_offset(pa_sink *s, int64_t offset) {
     pa_sink_assert_ref(s);
 
     s->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, (int64_t) offset, NULL) == 0);
+        pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SINK_MESSAGE_SET_LATENCY_OFFSET, NULL, offset, NULL) == 0);
     else
         s->thread_info.fixed_latency = offset;
 }
diff --git a/src/pulsecore/sink.h b/src/pulsecore/sink.h
index b138a1d..2c52348 100644
--- a/src/pulsecore/sink.h
+++ b/src/pulsecore/sink.h
@@ -114,7 +114,7 @@ struct pa_sink {
     pa_atomic_t mixer_dirty;
 
     /* The latency offset is inherited from the currently active port */
-    pa_usec_t latency_offset;
+    int64_t latency_offset;
 
     unsigned priority;
 
@@ -272,7 +272,7 @@ struct pa_sink {
         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 */
-        pa_usec_t latency_offset;
+        int64_t latency_offset;
 
         /* Delayed volume change events are queued here. The events
          * are stored in expiration order. The one expiring next is in
@@ -410,7 +410,7 @@ unsigned pa_device_init_priority(pa_proplist *p);
 /**** May be called by everyone, from main context */
 
 pa_bool_t pa_sink_update_rate(pa_sink *s, uint32_t rate, pa_bool_t passthrough);
-void pa_sink_set_latency_offset(pa_sink *s, pa_usec_t offset);
+void pa_sink_set_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 63a75ef..9e3a7dc 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -1030,7 +1030,12 @@ 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 += s->latency_offset;
+    /* 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;
+    else
+        usec = 0;
 
     return usec;
 }
@@ -1059,7 +1064,12 @@ 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 += s->thread_info.latency_offset;
+    /* 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;
+    else
+        usec = 0;
 
     return usec;
 }
@@ -2179,7 +2189,7 @@ int pa_source_process_msg(pa_msgobject *object, int code, void *userdata, int64_
             return 0;
 
         case PA_SOURCE_MESSAGE_SET_LATENCY_OFFSET:
-            s->thread_info.latency_offset = (pa_usec_t) offset;
+            s->thread_info.latency_offset = offset;
             return 0;
 
         case PA_SOURCE_MESSAGE_MAX:
@@ -2522,13 +2532,13 @@ 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, pa_usec_t offset) {
+void pa_source_set_latency_offset(pa_source *s, int64_t offset) {
     pa_source_assert_ref(s);
 
     s->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, (int64_t) offset, NULL) == 0);
+        pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_SET_LATENCY_OFFSET, NULL, offset, NULL) == 0);
     else
         s->thread_info.fixed_latency = offset;
 }
diff --git a/src/pulsecore/source.h b/src/pulsecore/source.h
index da024e6..dd1e09b 100644
--- a/src/pulsecore/source.h
+++ b/src/pulsecore/source.h
@@ -114,7 +114,7 @@ struct pa_source {
     pa_atomic_t mixer_dirty;
 
     /* The latency offset is inherited from the currently active port */
-    pa_usec_t latency_offset;
+    int64_t latency_offset;
 
     unsigned priority;
 
@@ -213,7 +213,7 @@ 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 */
-        pa_usec_t latency_offset;
+        int64_t latency_offset;
 
         /* Delayed volume change events are queued here. The events
          * are stored in expiration order. The one expiring next is in
@@ -342,7 +342,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, pa_usec_t offset);
+void pa_source_set_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);



More information about the pulseaudio-commits mailing list