[pulseaudio-commits] r1611 - /branches/lennart/src/modules/module-hal-detect.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Thu Aug 9 17:15:20 PDT 2007


Author: lennart
Date: Fri Aug 10 02:15:20 2007
New Revision: 1611

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1611&root=3Dpulseaudio&vi=
ew=3Drev
Log:
Avoid a race condition when one PA instance gets HAL's ACLAdded message bef=
ore the previous owner instance has given up access to the device, and thus=
 the device is blocked

Modified:
    branches/lennart/src/modules/module-hal-detect.c

Modified: branches/lennart/src/modules/module-hal-detect.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/modules/mo=
dule-hal-detect.c?rev=3D1611&root=3Dpulseaudio&r1=3D1610&r2=3D1611&view=3Dd=
iff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/modules/module-hal-detect.c (original)
+++ branches/lennart/src/modules/module-hal-detect.c Fri Aug 10 02:15:20 20=
07
@@ -540,10 +540,21 @@
                 if (d->sink_name) {
                     pa_sink *sink;
                     =

-                    if ((sink =3D pa_namereg_get(u->core, d->sink_name, PA=
_NAMEREG_SINK, 0)))
-                        if (pa_sink_suspend(sink, suspend) >=3D 0)
-                            if (!suspend)
+                    if ((sink =3D pa_namereg_get(u->core, d->sink_name, PA=
_NAMEREG_SINK, 0))) {
+                        =

+                        int prev_suspended =3D pa_sink_get_state(sink) =3D=
=3D PA_SINK_SUSPENDED;
+
+                        if (pa_sink_suspend(sink, suspend) >=3D 0) {
+                            if (!suspend && prev_suspended)
                                 pa_scache_play_item_by_name(u->core, "puls=
e-access", d->sink_name, PA_VOLUME_NORM, 0);
+                            else if (suspend && !prev_suspended) {
+                                DBusMessage *msg;
+                                msg =3D dbus_message_new_signal(udi, "org.=
pulseaudio.Server", "DirtyGiveUpMessage");
+                                dbus_connection_send(pa_dbus_connection_ge=
t(u->connection), msg, NULL);
+                                dbus_message_unref(msg);
+                            }
+                        }
+                    }
                 }
 =

                 if (d->source_name) {
@@ -555,9 +566,46 @@
                 =

             } else if (!suspend)
                 hal_device_add(u, udi);
-
         }
         =

+    } else if (dbus_message_is_signal(message, "org.pulseaudio.Server", "D=
irtyGiveUpMessage")) {
+        /* We use this message to avoid a dirty race condition when we
+           get an ACLAdded message before the previously owning PA
+           sever has closed the device. We can remove this as
+           soon as HAL learns frevoke() */
+
+        const char *udi;
+        struct device *d;
+
+        pa_log_debug("Got dirty give up message, trying resume ...");
+
+        udi =3D dbus_message_get_path(message);
+        =

+        if ((d =3D pa_hashmap_get(u->devices, udi))) {
+
+            if (d->sink_name) {
+                pa_sink *sink;
+                =

+                if ((sink =3D pa_namereg_get(u->core, d->sink_name, PA_NAM=
EREG_SINK, 0))) {
+
+                    int prev_suspended =3D pa_sink_get_state(sink) =3D=3D =
PA_SINK_SUSPENDED;
+                    =

+                    if (pa_sink_suspend(sink, 0) >=3D 0)
+                        if (prev_suspended && !prev_suspended)
+                            pa_scache_play_item_by_name(u->core, "pulse-ac=
cess", d->sink_name, PA_VOLUME_NORM, 0);
+                }
+            }
+            =

+            if (d->source_name) {
+                pa_source *source;
+                =

+                if ((source =3D pa_namereg_get(u->core, d->source_name, PA=
_NAMEREG_SOURCE, 0)))
+                    pa_source_suspend(source, 0);
+            }
+            =

+        } else =

+            /* Yes, we don't check the UDI for validity, but hopefully HAL=
 will */
+            hal_device_add(u, udi);
     }
 =

 finish:
@@ -673,6 +721,12 @@
         pa_log_error("Unable to subscribe to HAL ACL signals: %s: %s", err=
or.name, error.message);
         goto fail;
     }
+
+    dbus_bus_add_match(pa_dbus_connection_get(conn), "type=3D'signal',inte=
rface=3D'org.pulseaudio.Server'", &error);
+    if (dbus_error_is_set(&error)) {
+        pa_log_error("Unable to subscribe to PulseAudio signals: %s: %s", =
error.name, error.message);
+        goto fail;
+    }
     =

     pa_log_info("Loaded %i modules.", n);
 =





More information about the pulseaudio-commits mailing list