[pulseaudio-discuss] [PATCH] bluetooth: Poll BT SCO socket for checking remote disconnect.

Tanu Kaskinen tanu.kaskinen at digia.com
Fri Dec 16 04:06:01 PST 2011


From: Marko Ollonen <marko.ollonen at digia.com>

Additional comments from Tanu Kaskinen:

There's this comment in start_thread() for the SCO over PCM
case: "FIXME: monitor stream_fd error". I guess this patch
solves that FIXME item at least partially.

The "u->sink->state == PA_SINK_RUNNING" condition looks a
bit strange to me - why is this only checked when the sink
is RUNNING, why not also when IDLE?

I think it would be better to poll stream_fd in the IO
thread (which is currently not started for the SCO over PCM
case) so that the stream disconnection could be handled
immediately when it happens. I'm not willing to do that
work now, however.

---

This is an old patch that has been made for Harmattan. I'd
like to get this patch to upstream, since it (probably)
does something useful and very likely doesn't break
anything, but if this is not considered the right way to
fix the problem, I can also understand if the patch gets
rejected.


 src/modules/bluetooth/module-bluetooth-device.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index 7992e12..268d30c 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -2004,6 +2004,22 @@ static int sco_over_pcm_state_update(struct userdata *u, pa_bool_t changed) {
     if (PA_SINK_IS_OPENED(pa_sink_get_state(u->hsp.sco_sink)) ||
         PA_SOURCE_IS_OPENED(pa_source_get_state(u->hsp.sco_source))) {
 
+        if ((u->sink->state == PA_SINK_RUNNING) && (u->stream_fd >= 0)) {
+            struct pollfd fds;
+            memset(&fds, 0, sizeof(fds));
+            fds.fd = u->stream_fd;
+            fds.events = POLLHUP | POLLERR;
+            poll(&fds, 1, 0);
+
+            if ((fds.revents & POLLHUP) || (fds.revents & POLLERR)) {
+                pa_log_debug("Stream disconnected by the remote peer");
+                if (u->transport)
+                    bt_transport_release(u);
+                else
+                    stop_stream_fd(u);
+            }
+        }
+
         if (u->service_fd >= 0 && u->stream_fd >= 0)
             return 0;
 
-- 
1.7.8



More information about the pulseaudio-discuss mailing list