[pulseaudio-discuss] [PATCH] module-dbus: fix for module incorrectly believing no sinks or sources are available on device disconnection.

John Horan knasher at gmail.com
Fri Mar 11 13:39:40 UTC 2016


If a removable device is the default sink or source, then on disconnection namereg.c in the method
pa_namereg_unregister sets the default sink or source to null.  If the dbus module is in use,
this then sets the fallback_sink variable to null.
However in the handle_get_fallback_sink and handle_set_fallback_sink, and the source
equivelent methods, these variables are used to see if there are any sinks or sources at all,
and therefore these methods assume no sinks are available.  This patch simply checks the
size of the hashmap that keeps track of all sinks to see if it is empty instead.

Signed-off-by: John Horan <knasher at gmail.com>
---
 src/modules/dbus/iface-core.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/src/modules/dbus/iface-core.c b/src/modules/dbus/iface-core.c
index 88e9030..4b47b54 100644
--- a/src/modules/dbus/iface-core.c
+++ b/src/modules/dbus/iface-core.c
@@ -687,9 +687,12 @@ static void handle_get_fallback_sink(DBusConnection *conn, DBusMessage *msg, voi
     pa_assert(c);
 
     if (!c->fallback_sink) {
-        pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY,
-                           "There are no sinks, and therefore no fallback sink either.");
-        return;
+        if(pa_hashmap_size(c->sinks_by_index) == 0) {
+            pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY,
+                              "There are no sinks, and therefore no fallback sink either.");
+            return;
+        }
+        c->fallback_sink = pa_namereg_get_default_sink(c->core);
     }
 
     pa_assert_se((fallback_sink = pa_hashmap_get(c->sinks_by_index, PA_UINT32_TO_PTR(c->fallback_sink->index))));
@@ -708,7 +711,7 @@ static void handle_set_fallback_sink(DBusConnection *conn, DBusMessage *msg, DBu
     pa_assert(iter);
     pa_assert(c);
 
-    if (!c->fallback_sink) {
+    if (!c->fallback_sink && pa_hashmap_size(c->sinks_by_index) == 0) {
         pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY,
                            "There are no sinks, and therefore no fallback sink either.");
         return;
@@ -775,9 +778,13 @@ static void handle_get_fallback_source(DBusConnection *conn, DBusMessage *msg, v
     pa_assert(c);
 
     if (!c->fallback_source) {
-        pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY,
-                           "There are no sources, and therefore no fallback source either.");
-        return;
+        if(pa_hashmap_size(c->sources_by_index) == 0) {
+            pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY,
+                               "There are no sources, and therefore no fallback source either.");
+            return;
+        }
+
+        c->fallback_source = pa_namereg_get_default_source(c->core);
     }
 
     pa_assert_se((fallback_source = pa_hashmap_get(c->sources_by_index, PA_UINT32_TO_PTR(c->fallback_source->index))));
@@ -796,7 +803,7 @@ static void handle_set_fallback_source(DBusConnection *conn, DBusMessage *msg, D
     pa_assert(iter);
     pa_assert(c);
 
-    if (!c->fallback_source) {
+    if (!c->fallback_source && pa_hashmap_size(c->sources_by_index) == 0) {
         pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY,
                            "There are no sources, and therefore no fallback source either.");
         return;
-- 
2.7.2



More information about the pulseaudio-discuss mailing list