[pulseaudio-commits] 3 commits - src/modules src/pulsecore

David Henningsson diwic at kemper.freedesktop.org
Wed Mar 28 04:31:06 PDT 2012


 src/modules/alsa/mixer/profile-sets/maudio-fasttrack-pro.conf |    4 +-
 src/modules/jack/module-jack-sink.c                           |    9 ++++-
 src/modules/jack/module-jack-source.c                         |    9 ++++-
 src/pulsecore/sink-input.c                                    |   17 ++++++++++
 src/pulsecore/source-output.c                                 |   17 ++++++++++
 5 files changed, 53 insertions(+), 3 deletions(-)

New commits:
commit b7fab75fdde21569ef0be4c7c52887031393d75c
Author: David Henningsson <david.henningsson at canonical.com>
Date:   Fri Mar 23 13:06:27 2012 +0100

    sink-input/source-output: Prevent filter sink/source cycles
    
    Misbehaving clients can try to set a filter sink to output to
    itself, leading to crashes later on. This patch protects us from that.
    
    Thanks to Roman Beslik for testing and finding an error in the first
    version of this patch.
    
    Tested-by: Roman Beslik <rabeslik at gmail.com>
    BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=44397
    Signed-off-by: David Henningsson <david.henningsson at canonical.com>

diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c
index b8412bd..f6f7324 100644
--- a/src/pulsecore/sink-input.c
+++ b/src/pulsecore/sink-input.c
@@ -1383,6 +1383,17 @@ pa_bool_t pa_sink_input_may_move(pa_sink_input *i) {
     return TRUE;
 }
 
+static pa_bool_t find_filter_sink_input(pa_sink_input *target, pa_sink *s) {
+    int i = 0;
+    while (s && s->input_to_master) {
+        if (s->input_to_master == target)
+            return TRUE;
+        s = s->input_to_master->sink;
+        pa_assert(i++ < 100);
+    }
+    return FALSE;
+}
+
 /* Called from main context */
 pa_bool_t pa_sink_input_may_move_to(pa_sink_input *i, pa_sink *dest) {
     pa_sink_input_assert_ref(i);
@@ -1396,6 +1407,12 @@ pa_bool_t pa_sink_input_may_move_to(pa_sink_input *i, pa_sink *dest) {
     if (!pa_sink_input_may_move(i))
         return FALSE;
 
+    /* Make sure we're not creating a filter sink cycle */
+    if (find_filter_sink_input(i, dest)) {
+        pa_log_debug("Can't connect input to %s, as that would create a cycle.", dest->name);
+        return FALSE;
+    }
+
     if (pa_idxset_size(dest->inputs) >= PA_MAX_INPUTS_PER_SINK) {
         pa_log_warn("Failed to move sink input: too many inputs per sink.");
         return FALSE;
diff --git a/src/pulsecore/source-output.c b/src/pulsecore/source-output.c
index fbfea9c..cd7981c 100644
--- a/src/pulsecore/source-output.c
+++ b/src/pulsecore/source-output.c
@@ -1160,6 +1160,17 @@ pa_bool_t pa_source_output_may_move(pa_source_output *o) {
     return TRUE;
 }
 
+static pa_bool_t find_filter_source_output(pa_source_output *target, pa_source *s) {
+    int i = 0;
+    while (s && s->output_from_master) {
+        if (s->output_from_master == target)
+            return TRUE;
+        s = s->output_from_master->source;
+        pa_assert(i++ < 100);
+    }
+    return FALSE;
+}
+
 /* Called from main context */
 pa_bool_t pa_source_output_may_move_to(pa_source_output *o, pa_source *dest) {
     pa_source_output_assert_ref(o);
@@ -1172,6 +1183,12 @@ pa_bool_t pa_source_output_may_move_to(pa_source_output *o, pa_source *dest) {
     if (!pa_source_output_may_move(o))
         return FALSE;
 
+    /* Make sure we're not creating a filter source cycle */
+    if (find_filter_source_output(o, dest)) {
+        pa_log_debug("Can't connect output to %s, as that would create a cycle.", dest->name);
+        return FALSE;
+    }
+
     if (pa_idxset_size(dest->outputs) >= PA_MAX_OUTPUTS_PER_SOURCE) {
         pa_log_warn("Failed to move source output: too many outputs per source.");
         return FALSE;

commit 311654766207b3776e2618ae63ac35115db48bbd
Author: Maarten Lankhorst <m.b.lankhorst at gmail.com>
Date:   Mon Mar 26 23:12:24 2012 +0200

    module-jack-sink/source: Set fixed latency correctly on creation
    
    Changes since v1:
    Use max value of jack_port_get_latency_range to calculate the latency
    and squash compiler warnings cased by using jack_port_get_total_latency
    
    Modifying latency only works inside a callback, and for hardware the
    latency is generally fixed on jack, so just take the max value.
    
    Signed-off-by: Maarten Lankhorst <m.b.lankhorst at gmail.com>

diff --git a/src/modules/jack/module-jack-sink.c b/src/modules/jack/module-jack-sink.c
index ba4ea95..017fbf6 100644
--- a/src/modules/jack/module-jack-sink.c
+++ b/src/modules/jack/module-jack-sink.c
@@ -168,10 +168,12 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
 
         case PA_SINK_MESSAGE_GET_LATENCY: {
             jack_nframes_t l, ft, d;
+            jack_latency_range_t r;
             size_t n;
 
             /* This is the "worst-case" latency */
-            l = jack_port_get_total_latency(u->client, u->port[0]) + u->frames_in_buffer;
+            jack_port_get_latency_range(u->port[0], JackPlaybackLatency, &r);
+            l = r.max + u->frames_in_buffer;
 
             if (u->saved_frame_time_valid) {
                 /* Adjust the worst case latency by the time that
@@ -296,6 +298,8 @@ int pa__init(pa_module*m) {
     unsigned i;
     const char **ports = NULL, **p;
     pa_sink_new_data data;
+    jack_latency_range_t r;
+    size_t n;
 
     pa_assert(m);
 
@@ -443,6 +447,9 @@ int pa__init(pa_module*m) {
         }
     }
 
+    jack_port_get_latency_range(u->port[0], JackPlaybackLatency, &r);
+    n = r.max * pa_frame_size(&u->sink->sample_spec);
+    pa_sink_set_fixed_latency(u->sink, pa_bytes_to_usec(n, &u->sink->sample_spec));
     pa_sink_put(u->sink);
 
     if (ports)
diff --git a/src/modules/jack/module-jack-source.c b/src/modules/jack/module-jack-source.c
index 13109f3..cf62882 100644
--- a/src/modules/jack/module-jack-source.c
+++ b/src/modules/jack/module-jack-source.c
@@ -124,11 +124,13 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off
             return 0;
 
         case PA_SOURCE_MESSAGE_GET_LATENCY: {
+            jack_latency_range_t r;
             jack_nframes_t l, ft, d;
             size_t n;
 
             /* This is the "worst-case" latency */
-            l = jack_port_get_total_latency(u->client, u->port[0]);
+            jack_port_get_latency_range(u->port[0], JackCaptureLatency, &r);
+            l = r.max;
 
             if (u->saved_frame_time_valid) {
                 /* Adjust the worst case latency by the time that
@@ -249,6 +251,8 @@ int pa__init(pa_module*m) {
     unsigned i;
     const char **ports = NULL, **p;
     pa_source_new_data data;
+    jack_latency_range_t r;
+    size_t n;
 
     pa_assert(m);
 
@@ -388,6 +392,9 @@ int pa__init(pa_module*m) {
 
     }
 
+    jack_port_get_latency_range(u->port[0], JackCaptureLatency, &r);
+    n = r.max * pa_frame_size(&u->source->sample_spec);
+    pa_source_set_fixed_latency(u->source, pa_bytes_to_usec(n, &u->source->sample_spec));
     pa_source_put(u->source);
 
     if (ports)

commit 6e449eca9a3b5cc7a0307570e07cbcc949ecc21e
Author: David Henningsson <david.henningsson at canonical.com>
Date:   Mon Mar 19 11:54:12 2012 +0100

    Fix input device for M-audio fasttrack pro
    
    Some M-audio fasttrack pro devices, the input device is at index 1 instead of index 0.
    According to
    http://mailman.alsa-project.org/pipermail/alsa-devel/2012-March/050701.html
    the reason for this is probably that the device has mutually exclusive
    analog and digital input. With this patch we can catch the input regardless
    of state.
    
    BugLink: https://bugs.launchpad.net/bugs/569932
    Signed-off-by: David Henningsson <david.henningsson at canonical.com>

diff --git a/src/modules/alsa/mixer/profile-sets/maudio-fasttrack-pro.conf b/src/modules/alsa/mixer/profile-sets/maudio-fasttrack-pro.conf
index 75f5112..c8025fd 100644
--- a/src/modules/alsa/mixer/profile-sets/maudio-fasttrack-pro.conf
+++ b/src/modules/alsa/mixer/profile-sets/maudio-fasttrack-pro.conf
@@ -33,9 +33,11 @@ device-strings = hw:%f,0,0
 channel-map = left,right
 direction = output
 
+; Try both device 0 and device 1 for input, see
+; http://mailman.alsa-project.org/pipermail/alsa-devel/2012-March/050701.html
 [Mapping analog-stereo-a-input]
 description = Analog Stereo Channel A
-device-strings = hw:%f,0,0
+device-strings = hw:%f,0,0 hw:%f,1,0
 channel-map = left,right
 direction = input
 



More information about the pulseaudio-commits mailing list