I recently ran into some very strange sounding audio when trying to use
pulseaudio and bluez4 together with a bluetooth handsfree device. I
noticed that doing a list-modules/list-sinks in pacmd showed that my
handsfree SCO audio device was set to 2 channel 44.1khz audio, which is
not correct. So I modified bluetooth-discover to set the information
correctly for SCO/HFP devices.

I also noticed that the sample format was being set as Unsigned 8-bit,
but all the documentation I can find for SCO audio specifies S16_LE as
the appropriate sample format. So I changed bluetooth-device to support
this change as well.

I am working on an embedded platform for most of my testing, and made
these changes against the 0.9.13 tree. However these patches are against
the current git master branch. 

This is my first time emailing in a patch, so please let me know if I
need to do anything differently. As I comment in the first patch, I am
not certain if setting 44.1khz is correct for A2DP devices in all cases.

Another observation I made, but did not address, is that if HFP mode is
disabled in audio.conf for bluez4, bluez will never create a Headset
device on DBUS, and the current bluetooth-discover module will not see
it. So currently, in order to use a bluetooth handsfree device with
pulse, you must have HFP mode enabled.

It is unclear to me who the current maintainer of the bluetooth plugin
is, but I would be interested in assisting in whatever way I can to get
bluetooth source support working.

-Steve
From 08a05efdd8d14bacd6ea06df22570fa850bc571f Mon Sep 17 00:00:00 2001
From: Stephen Jacobs <[email protected]>
Date: Fri, 26 Dec 2008 13:20:55 -0500
Subject: [PATCH] Changed discover module to set channel and rate.
 8khz / 1 channel for HSP devices
 44.1khz / 2 channel for A2DP devices


diff --git a/src/modules/bluetooth/module-bluetooth-discover.c b/src/modules/bluetooth/module-bluetooth-discover.c
index 2fe0937..cc1f53b 100644
--- a/src/modules/bluetooth/module-bluetooth-discover.c
+++ b/src/modules/bluetooth/module-bluetooth-discover.c
@@ -333,16 +333,18 @@ finish:
     return ret;
 }
 
-static void load_module_for_device(struct userdata *u, struct device *d, const char *profile) {
+static void load_module_for_device(struct userdata *u, struct device *d, const char *profile, int channels, int rate) {
     char *args;
     pa_module *pa_m;
     struct module *m;
 
     pa_assert(u);
     pa_assert(d);
+    pa_assert(channels != 0);
+    pa_assert(rate != 0);
 
     get_device_properties(u, d);
-    args = pa_sprintf_malloc("sink_name=\"%s\" address=\"%s\" profile=\"%s\"", d->name, d->address, profile);
+    args = pa_sprintf_malloc("sink_name=\"%s\" address=\"%s\" profile=\"%s\" channels=\"%d\" rate=\"%d\"", d->name, d->address, profile, channels, rate);
     pa_m = pa_module_load(u->module->core, "module-bluetooth-device", args);
     pa_xfree(args);
 
@@ -411,6 +413,8 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *msg, void *
 
         struct device *d;
         const char *profile;
+        int channels;
+        int rate;
         DBusMessageIter variant_i;
         dbus_bool_t connected;
 
@@ -448,10 +452,17 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *msg, void *
 
         dbus_message_iter_get_basic(&variant_i, &connected);
 
-        if (dbus_message_is_signal(msg, "org.bluez.Headset", "PropertyChanged"))
+        if (dbus_message_is_signal(msg, "org.bluez.Headset", "PropertyChanged")) {
             profile = "hsp";
-        else
+            channels = 1;
+            rate = 8000;
+        }
+        else {
             profile = "a2dp";
+            channels=2;
+            /* Not sure if this is the correct rate for A2DP in all cases */
+            rate=44100;
+        }
 
         d = device_find(u, dbus_message_get_path(msg));
 
@@ -461,7 +472,7 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *msg, void *
                     PA_LLIST_PREPEND(struct device, u->device_list, d);
             }
 
-            load_module_for_device(u, d, profile);
+            load_module_for_device(u, d, profile, channels, rate);
         } else if (d)
             unload_module_for_device(u, d, profile);
     }
-- 
1.5.6.3

From 624f13d45eb1a93b6f27b65922d760010c1a9eaa Mon Sep 17 00:00:00 2001
From: Stephen Jacobs <[email protected]>
Date: Fri, 26 Dec 2008 13:21:41 -0500
Subject: [PATCH] Changed device code to allow S16_LE sample format for HSP devices.


diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index 5974d48..792e3cb 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -443,6 +443,9 @@ static int bt_setconf(struct userdata *u) {
         }
         u->ss.format = PA_SAMPLE_S16LE;
     }
+    else if (u->transport == BT_CAPABILITIES_TRANSPORT_SCO) {
+        u->ss.format = PA_SAMPLE_S16LE;
+    }
     else
         u->ss.format = PA_SAMPLE_U8;
 
-- 
1.5.6.3

_______________________________________________
pulseaudio-discuss mailing list
[email protected]
https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss

Reply via email to