]> code.delx.au - pulseaudio/commitdiff
bluetooth: Process sink messages for BlueZ 5 cards
authorJoão Paulo Rechi Vita <jprvita@openbossa.org>
Tue, 24 Sep 2013 22:45:52 +0000 (19:45 -0300)
committerTanu Kaskinen <tanu.kaskinen@linux.intel.com>
Sun, 29 Sep 2013 13:54:38 +0000 (16:54 +0300)
src/modules/bluetooth/module-bluez5-device.c

index 4f2fbd86b8ce458e1477c711165e7aaee4aa55fa..27ff721805e0ad1036cf3eda9886ba45106dfe29 100644 (file)
@@ -700,6 +700,80 @@ static int add_source(struct userdata *u) {
     return 0;
 }
 
+/* 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);
+
+    switch (code) {
+
+        case PA_SINK_MESSAGE_SET_STATE:
+
+            switch ((pa_sink_state_t) PA_PTR_TO_UINT(data)) {
+
+                case PA_SINK_SUSPENDED:
+                    /* Ignore if transition is PA_SINK_INIT->PA_SINK_SUSPENDED */
+                    if (!PA_SINK_IS_OPENED(u->sink->thread_info.state))
+                        break;
+
+                    /* Stop the device if the source is suspended as well */
+                    if (!u->source || u->source->state == PA_SOURCE_SUSPENDED)
+                        /* We deliberately ignore whether stopping
+                         * actually worked. Since the stream_fd is
+                         * closed it doesn't really matter */
+                        transport_release(u);
+
+                    break;
+
+                case PA_SINK_IDLE:
+                case PA_SINK_RUNNING:
+                    if (u->sink->thread_info.state != PA_SINK_SUSPENDED)
+                        break;
+
+                    /* Resume the device if the source was suspended as well */
+                    if (!u->source || !PA_SOURCE_IS_OPENED(u->source->thread_info.state)) {
+                        if (transport_acquire(u, false) < 0)
+                            failed = true;
+                        else
+                            setup_stream(u);
+                    }
+
+                    break;
+
+                case PA_SINK_UNLINKED:
+                case PA_SINK_INIT:
+                case PA_SINK_INVALID_STATE:
+                    break;
+            }
+
+            break;
+
+        case PA_SINK_MESSAGE_GET_LATENCY: {
+            pa_usec_t wi, ri;
+
+            if (u->read_smoother) {
+                ri = pa_smoother_get(u->read_smoother, pa_rtclock_now());
+                wi = pa_bytes_to_usec(u->write_index + u->write_block_size, &u->sample_spec);
+            } else {
+                ri = pa_rtclock_now() - u->started_at;
+                wi = pa_bytes_to_usec(u->write_index, &u->sample_spec);
+            }
+
+            *((pa_usec_t*) data) = FIXED_LATENCY_PLAYBACK_A2DP + wi > ri ? FIXED_LATENCY_PLAYBACK_A2DP + wi - ri : 0;
+
+            return 0;
+        }
+    }
+
+    r = pa_sink_process_msg(o, code, data, offset, chunk);
+
+    return (r < 0 || !failed) ? r : -1;
+}
+
 /* Run from main thread */
 static int add_sink(struct userdata *u) {
     pa_sink_new_data data;
@@ -735,6 +809,7 @@ static int add_sink(struct userdata *u) {
     }
 
     u->sink->userdata = u;
+    u->sink->parent.process_msg = sink_process_msg;
 
     return 0;
 }