bluetooth: fix resume error handling
authorTanu Kaskinen <tanuk@iki.fi>
Mon, 19 Feb 2018 14:48:25 +0000 (16:48 +0200)
committerTanu Kaskinen <tanuk@iki.fi>
Wed, 7 Mar 2018 11:40:23 +0000 (13:40 +0200)
When resuming a sink or source, pa_sink/source_process_msg() should be
called only if resuming is successful. pa_sink/source_process_msg()
updates thread_info.state and notifies streams about the new state, but
if resuming fails, there's no state change.

src/modules/bluetooth/module-bluez4-device.c
src/modules/bluetooth/module-bluez5-device.c

index ff178226469ebba3fcd3b72eafbb77dfe4caf9a3..c6baee84c636c463a2e107a2ae9bf6ec14c28df7 100644 (file)
@@ -380,8 +380,6 @@ static int bt_transport_acquire(struct userdata *u, bool optional) {
 /* Run from IO thread */
 static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) {
     struct userdata *u = PA_SINK(o)->userdata;
-    bool failed = false;
-    int r;
 
     pa_assert(u->sink == PA_SINK(o));
     pa_assert(u->transport);
@@ -414,7 +412,7 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
                     /* Resume the device if the source was suspended as well */
                     if (!u->source || !PA_SOURCE_IS_OPENED(u->source->thread_info.state)) {
                         if (bt_transport_acquire(u, false) < 0)
-                            failed = true;
+                            return -1;
                         else
                             setup_stream(u);
                     }
@@ -450,16 +448,12 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
         }
     }
 
-    r = pa_sink_process_msg(o, code, data, offset, chunk);
-
-    return (r < 0 || !failed) ? r : -1;
+    return pa_sink_process_msg(o, code, data, offset, chunk);
 }
 
 /* Run from IO thread */
 static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) {
     struct userdata *u = PA_SOURCE(o)->userdata;
-    bool failed = false;
-    int r;
 
     pa_assert(u->source == PA_SOURCE(o));
     pa_assert(u->transport);
@@ -491,7 +485,7 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off
                     /* Resume the device if the sink was suspended as well */
                     if (!u->sink || !PA_SINK_IS_OPENED(u->sink->thread_info.state)) {
                         if (bt_transport_acquire(u, false) < 0)
-                            failed = true;
+                            return -1;
                         else
                             setup_stream(u);
                     }
@@ -522,9 +516,7 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off
 
     }
 
-    r = pa_source_process_msg(o, code, data, offset, chunk);
-
-    return (r < 0 || !failed) ? r : -1;
+    return pa_source_process_msg(o, code, data, offset, chunk);
 }
 
 /* Called from main thread context */
index 7970dda70f47e122302439c29eb845f6b784ae73..b83f0eafa919420c3be8b9f34503d1ee76b104f3 100644 (file)
@@ -885,8 +885,6 @@ static bool setup_transport_and_stream(struct userdata *u) {
 /* Run from IO thread */
 static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) {
     struct userdata *u = PA_SOURCE(o)->userdata;
-    bool failed = false;
-    int r;
 
     pa_assert(u->source == PA_SOURCE(o));
     pa_assert(u->transport);
@@ -917,8 +915,10 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off
                         break;
 
                     /* Resume the device if the sink was suspended as well */
-                    if (!u->sink || !PA_SINK_IS_OPENED(u->sink->thread_info.state))
-                        failed = !setup_transport_and_stream(u);
+                    if (!u->sink || !PA_SINK_IS_OPENED(u->sink->thread_info.state)) {
+                        if (!setup_transport_and_stream(u))
+                            return -1;
+                    }
 
                     /* We don't resume the smoother here. Instead we
                      * wait until the first packet arrives */
@@ -953,9 +953,7 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off
 
     }
 
-    r = pa_source_process_msg(o, code, data, offset, chunk);
-
-    return (r < 0 || !failed) ? r : -1;
+    return pa_source_process_msg(o, code, data, offset, chunk);
 }
 
 /* Run from main thread */
@@ -1057,8 +1055,6 @@ static int add_source(struct userdata *u) {
 /* Run from IO thread */
 static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) {
     struct userdata *u = PA_SINK(o)->userdata;
-    bool failed = false;
-    int r;
 
     pa_assert(u->sink == PA_SINK(o));
     pa_assert(u->transport);
@@ -1089,8 +1085,10 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
                         break;
 
                     /* Resume the device if the source was suspended as well */
-                    if (!u->source || !PA_SOURCE_IS_OPENED(u->source->thread_info.state))
-                        failed = !setup_transport_and_stream(u);
+                    if (!u->source || !PA_SOURCE_IS_OPENED(u->source->thread_info.state)) {
+                        if (!setup_transport_and_stream(u))
+                            return -1;
+                    }
 
                     break;
 
@@ -1123,9 +1121,7 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
             return 0;
     }
 
-    r = pa_sink_process_msg(o, code, data, offset, chunk);
-
-    return (r < 0 || !failed) ? r : -1;
+    return pa_sink_process_msg(o, code, data, offset, chunk);
 }
 
 /* Run from main thread */