You are not logged in.

#1 2019-01-27 06:49:45

possessedbysatan
Member
Registered: 2018-01-11
Posts: 7

Bluetooth audio issues

Hi everyone. I have basically this issue: https://bbs.archlinux.org/viewtopic.php?id=228997

Whenever I connect (or turn on) my bluetooth headphones, the HSP/HSF profile is selected automatically, and this in turn results in a very bad quality audio output. I already tried the following:
->  Add the following line to /etc/pulse/default.pa

.ifexists module-bluetooth-discover.so
load-module module-switch-on-connect  # [this]
.endif

-> Add the following line to /etc/bluetooth/main.conf

Disable=Headset

I don't care about HSP/HSF, since I don't use my headphones' mic. Under Windows/macOS (got a hackintosh) the OS will automatically switch to a2dp, with no action needed. Currently I'm using XFCE+lightdm . For sure I can go to blueman, disconnect and then select the A2DP profile and it will work,  but man, I'm tired of doing that.

Here's some important info:
pacmd list-cards (the other entries are completely unrelated to my headphones)

   index: 7
	name: <bluez_card.00_11_67_11_1C_23>
	driver: <module-bluez5-device.c>
	owner module: 35
	properties:
		device.description = "FA-80"
		device.string = "00:11:67:11:1C:23"
		device.api = "bluez"
		device.class = "sound"
		device.bus = "bluetooth"
		device.form_factor = "headset"
		bluez.path = "/org/bluez/hci0/dev_00_11_67_11_1C_23"
		bluez.class = "0x240404"
		bluez.alias = "FA-80"
		device.icon_name = "audio-headset-bluetooth"
		device.intended_roles = "phone"
	profiles:
		headset_head_unit: Headset Head Unit (HSP/HFP) (priority 30, available: yes)
		a2dp_sink: High Fidelity Playback (A2DP Sink) (priority 40, available: no)
		off: Off (priority 0, available: yes)
	active profile: <headset_head_unit>
	sinks:
		bluez_sink.00_11_67_11_1C_23.headset_head_unit/#8: FA-80
	sources:
		bluez_sink.00_11_67_11_1C_23.headset_head_unit.monitor/#13: Monitor of FA-80
		bluez_source.00_11_67_11_1C_23.headset_head_unit/#14: FA-80
	ports:
		headset-output: Headset (priority 0, latency offset 0 usec, available: yes)
			properties:
				
		headset-input: Headset (priority 0, latency offset 0 usec, available: yes)
			properties:

pacmd set-card-profile 7 a2dp_sink

pacmd set-card-profile 7 a2dp_sink
Failed to set card profile to 'a2dp_sink'.

pacman -Q | grep blue

blueman 2.0.7-1
bluez 5.50-6
bluez-libs 5.50-6
bluez-utils 5.50-6
gnome-bluetooth 3.28.2-1

pacman -Q | grep pulseaudio

pulseaudio 12.2-2
pulseaudio-alsa 2-4
pulseaudio-modules-bt-git r87.4b0cde16-1
xfce4-pulseaudio-plugin 0.4.1-1

pacmd list-sinks (again, only relevant output because the other sinks are from hdmi/wired headphone outputs):

* index: 8
	name: <bluez_sink.00_11_67_11_1C_23.headset_head_unit>
	driver: <module-bluez5-device.c>
	flags: HARDWARE HW_VOLUME_CTRL LATENCY 
	state: RUNNING
	suspend cause: (none)
	priority: 9050
	volume: mono: 46530 /  71%
	        balance 0.00
	base volume: 65536 / 100%
	volume steps: 16
	muted: no
	current latency: 34.41 ms
	max request: 0 KiB
	max rewind: 0 KiB
	monitor source: 13
	sample spec: s16le 1ch 8000Hz
	channel map: mono
	             Mono
	used by: 1
	linked by: 1
	fixed latency: 28.00 ms
	card: 7 <bluez_card.00_11_67_11_1C_23>
	module: 35
	properties:
		bluetooth.protocol = "headset_head_unit"
		device.intended_roles = "phone"
		device.description = "FA-80"
		device.string = "00:11:67:11:1C:23"
		device.api = "bluez"
		device.class = "sound"
		device.bus = "bluetooth"
		device.form_factor = "headset"
		bluez.path = "/org/bluez/hci0/dev_00_11_67_11_1C_23"
		bluez.class = "0x240404"
		bluez.alias = "FA-80"
		device.icon_name = "audio-headset-bluetooth"
	ports:
		headset-output: Headset (priority 0, latency offset 0 usec, available: yes)
			properties:
				
	active port: <headset-output>

Last edited by possessedbysatan (2019-01-27 06:52:21)

Offline

#2 2019-01-27 07:47:10

possessedbysatan
Member
Registered: 2018-01-11
Posts: 7

Re: Bluetooth audio issues

Nvm I just solved it but it took me hours of research. For those who are lazy, here's the solution:

Create /usr/local/bin/a2dp-fix, put the following text on it and make it executable with chmod +x:

#!/bin/bash
bt_device_addr=$(pacmd list-cards | grep -i 'name:.*bluez_card' | sed -E 's/.*<?bluez_card\.([A-Z0-9_]+)>?/\1/')
device_mac=$(echo $bt_device_addr | sed 's/_/:/g')
a2dp_available=$(pacmd list-cards | grep -A30 bluez | grep "A2DP Sink" | sed -E 's/.* available: ([a-z]+)\)/\1/g')
if [[ "$a2dp_available" == "no" ]] || [["$a2dp_available" == "unknown"]]
then
    dbus-send --system --dest=org.bluez --print-reply /org/bluez/hci0/dev_$bt_device_addr org.bluez.Device1.Connect
    pacmd set-card-profile bluez_card.$bt_device_addr off
    pacmd set-card-profile bluez_card.$bt_device_addr a2dp_sink
    pacmd set-default-sink bluez_sink.$bt_device_addr.a2dp_sink
fi

/etc/udev/rules.d/80-bt-headset.rules

ACTION=="add", SUBSYSTEM=="bluetooth", RUN+="/usr/local/bin/a2dp-fix-wrapper"

/usr/local/bin/a2dp-fix-wrapper

#!/bin/bash
for PID in $(pgrep pulseaudio); do
    USER=$(grep -z USER= /proc/$PID/environ | sed 's/.*=//' | tr -d '\0')
    USER_ID=$(id -u $USER)
    HOME=$(echo $(getent passwd $USER )| cut -d : -f 6)
export XDG_RUNTIME_DIR=/run/user/$USER_ID
    export XAUTHORITY=$HOME/.Xauthority
    export DISPLAY=:0
sleep 5
    if [[ ! -z $USER ]]; then
        sudo -u $USER -E /usr/local/bin/a2dp-fix
    fi
done

Sources:
https://gitlab.freedesktop.org/pulseaud … issues/525
https://medium.com/@aiguofer/flawless-b … 45cb746671

There's one thing that I'd like to solve, though.
Under Windows/macOS I can use the volume buttons of my headset to control, uh, volume (even with a2dp profile). Under Linux I just simply can't, and xev doesn't show anything when I press the buttons. The volume buttons can control songs (prev/skip) on long press, though. Is there anything I can do to fix this?

Last edited by possessedbysatan (2019-01-27 07:52:59)

Offline

Board footer

Powered by FluxBB