summaryrefslogtreecommitdiff
path: root/debian/patches/0014-bluetooth-use-sco_sink-source-to-start-with-right-st.patch
blob: e631511296ae88d60bd86903a0c5b2bb97a1ca12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
From 670c6f5a84c6e2862e2ae2953b17610e3a50ad66 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Marc-Andr=C3=A9=20Lureau?= <marc-andre.lureau@nokia.com>
Date: Mon, 25 May 2009 18:22:16 +0300
Subject: [PATCH 14/87] bluetooth: use sco_sink/source to start with right state

---
 src/modules/bluetooth/module-bluetooth-device.c |   34 +++++++++++++++--------
 1 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index 0e6caa7..9044aab 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -1520,32 +1520,42 @@ static char *get_name(const char *type, pa_modargs *ma, const char *device_id, p
 
 #ifdef NOKIA
 
-static void sco_over_pcm_state_update(struct userdata *u) {
+static int sco_over_pcm_state_update(struct userdata *u) {
     pa_assert(u);
     pa_assert(USE_SCO_OVER_PCM(u));
 
     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->service_fd >= 0)
-            return;
+        if (u->service_fd >= 0 && u->stream_fd >= 0)
+            return 0;
 
         pa_log_debug("Resuming SCO over PCM");
-        if ((init_bt(u) < 0) || (init_profile(u) < 0))
+        if ((init_bt(u) < 0) || (init_profile(u) < 0)) {
             pa_log("Can't resume SCO over PCM");
+            return -1;
+        }
 
-        start_stream_fd(u);
+        return start_stream_fd(u);
     } else {
 
-        if (u->service_fd < 0)
-            return;
-
-        stop_stream_fd(u);
+        if (u->service_fd < 0 && u->stream_fd < 0)
+            return 0;
 
         pa_log_debug("Closing SCO over PCM");
-        pa_close(u->service_fd);
-        u->service_fd = -1;
+
+        if (u->stream_fd >= 0)
+            stop_stream_fd(u);
+
+        if (u->service_fd >= 0) {
+            pa_close(u->service_fd);
+            u->service_fd = -1;
+        }
+
+        return 0;
     }
+
+    return -1;
 }
 
 static pa_hook_result_t sink_state_changed_cb(pa_core *c, pa_sink *s, struct userdata *u) {
@@ -1834,7 +1844,7 @@ static int start_thread(struct userdata *u) {
 
 #ifdef NOKIA
     if (USE_SCO_OVER_PCM(u)) {
-        if (start_stream_fd(u) < 0)
+        if (sco_over_pcm_state_update(u) < 0)
             return -1;
 
         pa_sink_ref(u->sink);
-- 
1.6.3.3