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 | 16 ++++------------
 src/modules/bluetooth/module-bluez5-device.c | 24 ++++++++++--------------
 2 files changed, 14 insertions(+), 26 deletions(-)

diff --git a/src/modules/bluetooth/module-bluez4-device.c 
b/src/modules/bluetooth/module-bluez4-device.c
index c458fd26a..44e109fdb 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);
@@ -420,7 +418,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);
                     }
@@ -457,16 +455,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);
@@ -504,7 +498,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);
                     }
@@ -536,9 +530,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 855cc8f80..5bd66eeb3 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);
@@ -923,8 +921,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 */
@@ -960,9 +960,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 */
@@ -1064,8 +1062,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);
@@ -1102,8 +1098,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;
 
@@ -1137,9 +1135,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 */
-- 
2.15.1

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

Reply via email to