[pulseaudio-commits] [SCM] PulseAudio Sound Server branch, master, updated. v0.9.15-157-gbab4b94

Lennart Poettering gitmailer-noreply at 0pointer.de
Sat Jun 6 06:33:35 PDT 2009


This is an automated email from the git hooks/post-receive script. It was
generated because of a push to the "PulseAudio Sound Server" repository.

The master branch has been updated
      from  e84644aa88acd7158bb174946dbff630ff2389ad (commit)

- Log -----------------------------------------------------------------
bab4b94 udev: try to unsuspend devices whenever they are closed by other processes
d1646f7 core: monitor sources need to inherit the suspend cause from their sinks
69eab1e core: suppress suspending/resume when we are already in the right state
496be21 hashmap: introduce PA_HASHMAP_FOREACH macro
-----------------------------------------------------------------------

Summary of changes:
 src/modules/module-udev-detect.c |  133 ++++++++++++++++++++++++++++++++++----
 src/pulsecore/hashmap.h          |    4 +
 src/pulsecore/idxset.h           |    2 +-
 src/pulsecore/sink.c             |   10 ++-
 src/pulsecore/source.c           |    3 +
 5 files changed, 137 insertions(+), 15 deletions(-)

-----------------------------------------------------------------------

commit 496be212ad645999647c432a856c906b86d41487
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Jun 6 15:30:24 2009 +0200

    hashmap: introduce PA_HASHMAP_FOREACH macro

diff --git a/src/pulsecore/hashmap.h b/src/pulsecore/hashmap.h
index 08e18ea..828e244 100644
--- a/src/pulsecore/hashmap.h
+++ b/src/pulsecore/hashmap.h
@@ -65,4 +65,8 @@ void *pa_hashmap_steal_first(pa_hashmap *h);
 /* Return the oldest entry in the hashmap */
 void* pa_hashmap_first(pa_hashmap *h);
 
+/* A macro to ease iteration through all entries */
+#define PA_HASHMAP_FOREACH(e, h, state) \
+    for ((state) = NULL, (e) = pa_hashmap_iterate((h), &(state), NULL); (e); (e) = pa_hashmap_iterate((h), &(state), NULL))
+
 #endif
diff --git a/src/pulsecore/idxset.h b/src/pulsecore/idxset.h
index 6b9ff47..a6179fc 100644
--- a/src/pulsecore/idxset.h
+++ b/src/pulsecore/idxset.h
@@ -103,7 +103,7 @@ unsigned pa_idxset_size(pa_idxset*s);
 /* Return TRUE of the idxset is empty */
 pa_bool_t pa_idxset_isempty(pa_idxset *s);
 
-
+/* A macro to ease iteration through all entries */
 #define PA_IDXSET_FOREACH(e, s, idx) \
     for ((e) = pa_idxset_first((s), &(idx)); (e); (e) = pa_idxset_next((s), &(idx)))
 

commit 69eab1e057e000951516cfd381846c33abc8aaf1
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Jun 6 15:31:46 2009 +0200

    core: suppress suspending/resume when we are already in the right state

diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 3c4adc6..a087e42 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -510,6 +510,9 @@ int pa_sink_suspend(pa_sink *s, pa_bool_t suspend, pa_suspend_cause_t cause) {
     else
         s->suspend_cause &= ~cause;
 
+    if ((pa_sink_get_state(s) == PA_SINK_SUSPENDED) == !!s->suspend_cause)
+        return 0;
+
     pa_log_debug("Suspend cause of sink %s is 0x%04x, %s", s->name, s->suspend_cause, s->suspend_cause ? "suspending" : "resuming");
 
     if (s->suspend_cause)
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index 4ade18f..abb5f4d 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -441,6 +441,9 @@ int pa_source_suspend(pa_source *s, pa_bool_t suspend, pa_suspend_cause_t cause)
     else
         s->suspend_cause &= ~cause;
 
+    if ((pa_source_get_state(s) == PA_SOURCE_SUSPENDED) == !!s->suspend_cause)
+        return 0;
+
     pa_log_debug("Suspend cause of source %s is 0x%04x, %s", s->name, s->suspend_cause, s->suspend_cause ? "suspending" : "resuming");
 
     if (suspend)

commit d1646f78af6a43928cb0cd6b3e8d45578c489cb1
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Jun 6 15:32:45 2009 +0200

    core: monitor sources need to inherit the suspend cause from their sinks

diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index a087e42..141084d 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -505,10 +505,13 @@ int pa_sink_suspend(pa_sink *s, pa_bool_t suspend, pa_suspend_cause_t cause) {
     pa_assert(PA_SINK_IS_LINKED(s->state));
     pa_assert(cause != 0);
 
-    if (suspend)
+    if (suspend) {
         s->suspend_cause |= cause;
-    else
+        s->monitor_source->suspend_cause |= cause;
+    } else {
         s->suspend_cause &= ~cause;
+        s->monitor_source->suspend_cause &= ~cause;
+    }
 
     if ((pa_sink_get_state(s) == PA_SINK_SUSPENDED) == !!s->suspend_cause)
         return 0;

commit bab4b94b566f54976836b04f187d97d424f7d750
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Jun 6 15:33:54 2009 +0200

    udev: try to unsuspend devices whenever they are closed by other processes

diff --git a/src/modules/module-udev-detect.c b/src/modules/module-udev-detect.c
index 29c94e1..b667cb4 100644
--- a/src/modules/module-udev-detect.c
+++ b/src/modules/module-udev-detect.c
@@ -24,6 +24,7 @@
 #endif
 
 #include <errno.h>
+#include <limits.h>
 #include <sys/inotify.h>
 #include <libudev.h>
 
@@ -41,6 +42,7 @@ PA_MODULE_LOAD_ONCE(TRUE);
 
 struct device {
     char *path;
+    pa_bool_t accessible;
     char *card_name;
     uint32_t module;
 };
@@ -49,9 +51,13 @@ struct userdata {
     pa_core *core;
     pa_hashmap *devices;
     pa_bool_t use_tsched;
+
     struct udev* udev;
     struct udev_monitor *monitor;
-    pa_io_event *io;
+    pa_io_event *udev_io;
+
+    int inotify_fd;
+    pa_io_event *inotify_io;
 };
 
 static const char* const valid_modargs[] = {
@@ -84,19 +90,20 @@ static const char *path_get_card_id(const char *path) {
 
 static void verify_access(struct userdata *u, struct device *d) {
     char *cd;
-    int r;
     pa_card *card;
 
     pa_assert(u);
     pa_assert(d);
 
-    cd = pa_sprintf_malloc("%s/controlC%s", d->path, path_get_card_id(d->path));
-    r = access(cd, W_OK);
-    pa_log_info("%s is accessible: %s", cd, pa_yes_no(r >= 0));
+    if (!(card = pa_namereg_get(u->core, d->card_name, PA_NAMEREG_CARD)))
+        return;
+
+    cd = pa_sprintf_malloc("%s/snd/controlC%s", udev_get_dev_path(u->udev), path_get_card_id(d->path));
+    d->accessible = access(cd, W_OK) >= 0;
+    pa_log_info("%s is accessible: %s", cd, pa_yes_no(d->accessible));
     pa_xfree(cd);
 
-    if ((card = pa_namereg_get(u->core, d->card_name, PA_NAMEREG_CARD)))
-        pa_card_suspend(card, r < 0, PA_SUSPEND_SESSION);
+    pa_card_suspend(card, !d->accessible, PA_SUSPEND_SESSION);
 }
 
 static void card_changed(struct userdata *u, struct udev_device *dev) {
@@ -146,6 +153,7 @@ static void card_changed(struct userdata *u, struct udev_device *dev) {
         d->path = pa_xstrdup(path);
         d->card_name = card_name;
         d->module = m->index;
+        d->accessible = TRUE;
 
         pa_hashmap_put(u->devices, d->path, d);
     } else
@@ -175,13 +183,13 @@ static void process_device(struct userdata *u, struct udev_device *dev) {
     pa_assert(dev);
 
     if (udev_device_get_property_value(dev, "PULSE_IGNORE")) {
-        pa_log_info("Ignoring %s, because marked so.", udev_device_get_devpath(dev));
+        pa_log_debug("Ignoring %s, because marked so.", udev_device_get_devpath(dev));
         return;
     }
 
     if ((ff = udev_device_get_property_value(dev, "SOUND_FORM_FACTOR")) &&
         pa_streq(ff, "modem")) {
-        pa_log_info("Ignoring %s, because it is a modem.", udev_device_get_devpath(dev));
+        pa_log_debug("Ignoring %s, because it is a modem.", udev_device_get_devpath(dev));
         return;
     }
 
@@ -212,7 +220,13 @@ static void process_path(struct userdata *u, const char *path) {
     udev_device_unref(dev);
 }
 
-static void monitor_cb(pa_mainloop_api*a, pa_io_event* e, int fd, pa_io_event_flags_t events, void *userdata) {
+static void monitor_cb(
+        pa_mainloop_api*a,
+        pa_io_event* e,
+        int fd,
+        pa_io_event_flags_t events,
+        void *userdata) {
+
     struct userdata *u = userdata;
     struct udev_device *dev;
 
@@ -220,7 +234,7 @@ static void monitor_cb(pa_mainloop_api*a, pa_io_event* e, int fd, pa_io_event_fl
 
     if (!(dev = udev_monitor_receive_device(u->monitor))) {
         pa_log("Failed to get udev device object from monitor.");
-        return;
+        goto fail;
     }
 
     if (!path_get_card_id(udev_device_get_devpath(dev)))
@@ -228,6 +242,88 @@ static void monitor_cb(pa_mainloop_api*a, pa_io_event* e, int fd, pa_io_event_fl
 
     process_device(u, dev);
     udev_device_unref(dev);
+    return;
+
+fail:
+    a->io_free(u->udev_io);
+    u->udev_io = NULL;
+}
+
+static void inotify_cb(
+        pa_mainloop_api*a,
+        pa_io_event* e,
+        int fd,
+        pa_io_event_flags_t events,
+        void *userdata) {
+
+    struct {
+        struct inotify_event e;
+        char name[NAME_MAX];
+    } buf;
+    struct userdata *u = userdata;
+    static int type = 0;
+    pa_bool_t verify = FALSE;
+
+    for (;;) {
+        ssize_t r;
+
+        pa_zero(buf);
+        if ((r = pa_read(fd, &buf, sizeof(buf), &type)) <= 0) {
+
+            if (r < 0 && errno == EAGAIN)
+                break;
+
+            pa_log("read() from inotify failed: %s", r < 0 ? pa_cstrerror(errno) : "EOF");
+            goto fail;
+        }
+
+        if ((buf.e.mask & IN_CLOSE_WRITE) && pa_startswith(buf.e.name, "pcmC"))
+            verify = TRUE;
+    }
+
+    if (verify) {
+        struct device *d;
+        void *state;
+
+        pa_log_debug("Verifying access.");
+
+        PA_HASHMAP_FOREACH(d, u->devices, state)
+            verify_access(u, d);
+    }
+
+    return;
+
+fail:
+    a->io_free(u->inotify_io);
+    u->inotify_io = NULL;
+
+    if (u->inotify_fd >= 0) {
+        pa_close(u->inotify_fd);
+        u->inotify_fd = -1;
+    }
+}
+
+static int setup_inotify(struct userdata *u) {
+    char *dev_snd;
+    int r;
+
+    if ((u->inotify_fd = inotify_init1(IN_CLOEXEC|IN_NONBLOCK)) < 0) {
+        pa_log("inotify_init1() failed: %s", pa_cstrerror(errno));
+        return -1;
+    }
+
+    dev_snd = pa_sprintf_malloc("%s/snd", udev_get_dev_path(u->udev));
+    r = inotify_add_watch(u->inotify_fd, dev_snd, IN_CLOSE_WRITE);
+    pa_xfree(dev_snd);
+
+    if (r < 0) {
+        pa_log("inotify_add_watch() failed: %s", pa_cstrerror(errno));
+        return -1;
+    }
+
+    pa_assert_se(u->inotify_io = u->core->mainloop->io_new(u->core->mainloop, u->inotify_fd, PA_IO_EVENT_INPUT, inotify_cb, u));
+
+    return 0;
 }
 
 int pa__init(pa_module *m) {
@@ -248,6 +344,7 @@ int pa__init(pa_module *m) {
     u->core = m->core;
     u->devices = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
     u->use_tsched = TRUE;
+    u->inotify_fd = -1;
 
     if (pa_modargs_get_value_boolean(ma, "tsched", &u->use_tsched) < 0) {
         pa_log("Failed to parse tsched argument.");
@@ -259,6 +356,9 @@ int pa__init(pa_module *m) {
         goto fail;
     }
 
+    if (setup_inotify(u) < 0)
+        goto fail;
+
     if (!(u->monitor = udev_monitor_new_from_netlink(u->udev, "udev"))) {
         pa_log("Failed to initialize monitor.");
         goto fail;
@@ -279,7 +379,7 @@ int pa__init(pa_module *m) {
         goto fail;
     }
 
-    pa_assert_se(u->io = u->core->mainloop->io_new(u->core->mainloop, fd, PA_IO_EVENT_INPUT, monitor_cb, u));
+    pa_assert_se(u->udev_io = u->core->mainloop->io_new(u->core->mainloop, fd, PA_IO_EVENT_INPUT, monitor_cb, u));
 
     if (!(enumerate = udev_enumerate_new(u->udev))) {
         pa_log("Failed to initialize udev enumerator.");
@@ -329,12 +429,21 @@ void pa__done(pa_module *m) {
     if (!(u = m->userdata))
         return;
 
+    if (u->udev_io)
+        m->core->mainloop->io_free(u->udev_io);
+
     if (u->monitor)
         udev_monitor_unref(u->monitor);
 
     if (u->udev)
         udev_unref(u->udev);
 
+    if (u->inotify_io)
+        m->core->mainloop->io_free(u->inotify_io);
+
+    if (u->inotify_fd >= 0)
+        pa_close(u->inotify_fd);
+
     if (u->devices) {
         struct device *d;
 

-- 
hooks/post-receive
PulseAudio Sound Server



More information about the pulseaudio-commits mailing list