src/modules/bluetooth/module-bluez4-device.c |   16 ++++------------
 src/modules/bluetooth/module-bluez5-device.c |   24 ++++++++++--------------
 2 files changed, 14 insertions(+), 26 deletions(-)

New commits:
commit f6fe411b32c0cf5932fb4f169f5288c76bc6923d
Author: Tanu Kaskinen <ta...@iki.fi>
Date:   Mon Feb 19 16:48:25 2018 +0200

    bluetooth: fix resume error handling
    
    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.

diff --git a/src/modules/bluetooth/module-bluez4-device.c 
b/src/modules/bluetooth/module-bluez4-device.c
index ff178226..c6baee84 100644
--- a/src/modules/bluetooth/module-bluez4-device.c
+++ b/src/modules/bluetooth/module-bluez4-device.c
@@ -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 */
diff --git a/src/modules/bluetooth/module-bluez5-device.c 
b/src/modules/bluetooth/module-bluez5-device.c
index 7970dda7..b83f0eaf 100644
--- a/src/modules/bluetooth/module-bluez5-device.c
+++ b/src/modules/bluetooth/module-bluez5-device.c
@@ -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 */

_______________________________________________
pulseaudio-commits mailing list
pulseaudio-commits@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/pulseaudio-commits

Reply via email to