]> code.delx.au - pulseaudio/commitdiff
bluetooth: Call setup_stream() manually
authorMikel Astiz <mikel.astiz@bmw-carit.de>
Fri, 14 Dec 2012 14:14:39 +0000 (15:14 +0100)
committerTanu Kaskinen <tanuk@iki.fi>
Wed, 19 Dec 2012 10:31:49 +0000 (12:31 +0200)
Do not call setup_stream() automatically inside bt_transport_acquire().
Instead, the caller is responsible to use both functions as necessary.

As a first trivial step, setup_stream() is now called manually after
all calls to bt_transport_acquire(u, TRUE), with the exception of
setup_transport() where the thread is still about to start and thus
setup_stream() will be called later on from thread_func().

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

index 9039eb5dd54f5d4a42877d4cb30245b467231659..32fbd03be51d59aa8d68b00ccc527454e8da72ab 100644 (file)
@@ -354,11 +354,8 @@ static void bt_transport_release(struct userdata *u) {
 static int bt_transport_acquire(struct userdata *u, pa_bool_t start) {
     pa_assert(u->transport);
 
-    if (u->transport_acquired) {
-        if (start)
-            goto done;
+    if (u->transport_acquired)
         return 0;
-    }
 
     pa_log_debug("Acquiring transport %s", u->transport->path);
 
@@ -375,16 +372,6 @@ static int bt_transport_acquire(struct userdata *u, pa_bool_t start) {
     u->transport_acquired = true;
     pa_log_info("Transport %s acquired: fd %d", u->transport->path, u->stream_fd);
 
-    if (!start)
-        return 0;
-
-done:
-    /* If thread is still about to start, the stream will be set up in the beginning of thread_func() */
-    if (u->thread == NULL)
-        return 0;
-
-    setup_stream(u);
-
     return 0;
 }
 
@@ -426,6 +413,8 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
                     if (!u->source || !PA_SOURCE_IS_OPENED(u->source->thread_info.state)) {
                         if (bt_transport_acquire(u, TRUE) < 0)
                             failed = TRUE;
+                        else
+                            setup_stream(u);
                     }
                     break;
 
@@ -501,6 +490,8 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off
                     if (!u->sink || !PA_SINK_IS_OPENED(u->sink->thread_info.state)) {
                         if (bt_transport_acquire(u, TRUE) < 0)
                             failed = TRUE;
+                        else
+                            setup_stream(u);
                     }
                     /* We don't resume the smoother here. Instead we
                      * wait until the first packet arrives */
@@ -1425,7 +1416,12 @@ static int sco_over_pcm_state_update(struct userdata *u, pa_bool_t changed) {
             return -1;
         }
 
-        return bt_transport_acquire(u, TRUE);
+        if (bt_transport_acquire(u, TRUE) < 0)
+            return -1;
+
+        setup_stream(u);
+
+        return 0;
     }
 
     if (changed) {