Ubuntu: PulseAudio fails to set card profile to 'a2dp_sink'. How can I see the logs and figure out whats wrong?



Question:

I have currently installed ubuntu 16.04 and a2dp used to work on fresh install, which I'd prefer to leave as a last option. When the pairing is erased from bluetooth settings and is paired again sometimes it manages to be on a2dp profile, but if the headset is disconnected and then reconnected the a2dp profiles doesn't work anymore (though it says is on a2dp), it only works after switching to HSP/HSF and then I'm unable to set it on a2dp.

I have tried doing:

 pacmd set-card-profile <index> a2dp_sink  

but the following error comes out:

"Failed to set card profile to 'a2dp_sink'"  

I'm quite inexperienced in Linux so I don't know how to get logs or what to look for in them, but I got this from pacmd list-cards:

When it works:

name: <bluez_card.50_C9_71_97_A1_86>  driver: <module-bluez5-device.c>  owner module: 27  properties:      device.description = "Jabra REVO a4.0.0"      device.string = "50:C9:71:97:A1:86"      device.api = "bluez"      device.class = "sound"      device.bus = "bluetooth"      device.form_factor = "headset"      bluez.path = "/org/bluez/hci0/dev_50_C9_71_97_A1_86"      bluez.class = "0x240404"      bluez.alias = "Jabra REVO a4.0.0"      device.icon_name = "audio-headset-bluetooth"      device.intended_roles = "phone"  profiles:      headset_head_unit: Headset Head Unit (HSP/HFP) (priority 20, available: unknown)      a2dp_sink: High Fidelity Playback (A2DP Sink) (priority 10, available: unknown)      off: Off (priority 0, available: yes)  active profile: <a2dp_sink>  sinks:      bluez_sink.50_C9_71_97_A1_86/#6: Jabra REVO a4.0.0  sources:      bluez_sink.50_C9_71_97_A1_86.monitor/#10: Monitor of Jabra REVO a4.0.0  ports:      headset-output: Headset (priority 0, latency offset 0 usec, available: unknown)          properties:        headset-input: Headset (priority 0, latency offset 0 usec, available: unknown)          properties:  

When it doesn't:

name: <bluez_card.50_C9_71_97_A1_86>  driver: <module-bluez5-device.c>  owner module: 25  properties:      device.description = "Jabra REVO a4.0.0"      device.string = "50:C9:71:97:A1:86"      device.api = "bluez"      device.class = "sound"      device.bus = "bluetooth"      device.form_factor = "headset"      bluez.path = "/org/bluez/hci0/dev_50_C9_71_97_A1_86"      bluez.class = "0x240404"      bluez.alias = "Jabra REVO a4.0.0"      device.icon_name = "audio-headset-bluetooth"      device.intended_roles = "phone"  profiles:      headset_head_unit: Headset Head Unit (HSP/HFP) (priority 20, available: unknown)      a2dp_sink: High Fidelity Playback (A2DP Sink) (priority 10, available: yes)      off: Off (priority 0, available: yes)  active profile: <off>  ports:      headset-output: Headset (priority 0, latency offset 0 usec, available: yes)          properties:        headset-input: Headset (priority 0, latency offset 0 usec, available: unknown)          properties:  

And the owning module is:

name: <module-bluez5-device>  argument: <path=/org/bluez/hci0/dev_50_C9_71_97_A1_86>  used: 0  load once: no  properties:      module.author = "João Paulo Rechi Vita"      module.description = "BlueZ 5 Bluetooth audio sink and source"      module.version = "8.0"  

I have already tried to modify /etc/bluetooth/audio.conf and install blueman but it didn't work. I also tried to reinstall bluez and pulseaudio but nothing changed.

Is there any way I can know what's wrong and fix it?


Solution:1

Based on the line "active profile: <off>" the sound profile didn't activate.

One program that is easy to use to change the profile is pavucontrol. You can install it with sudo apt install pavucontrol -y. Then run pavucontrol from the command line or Alt+F2 if you are on Kubuntu and entering pavucontrol.

Select the configuration tab and then try changing the profile for your headphones and see if that updates for you. There seem to be a bug with bluetooth a2dp still in linux and it affects two of my 16.04 installations. If it already says A2DP change it to OFF, disconnect the device in the bluetooth applet, then reconnect it. Then finally proceed to change the profile back to A2DP and it should work.

You can also try the following on the command line and it should tab complete most of it for you. Replace the number 2 with the index number currently for both pacmd commands below.

pacmd set-card-profile 2 off  bluetoothctl  disconnect 50:C9:71:97:A1:86  connect 50:C9:71:97:A1:86  pacmd set-card-profile 2 a2dp_sink  

For a more complicated but automated way of doing the same thing for cycling the profile to off and then back to a2dp but not do the bluetooth device disconnect and connect

index=`pacmd list-cards | grep bluez_card -B1 | grep index | awk '{print $2}'`;pacmd set-card-profile $index off; pacmd set-card-profile $index a2dp_sink   

I was also to make a working but sloppy script to do the same thing but also disconnect and reconnect the bluetooth headphones. It grabs the profile index because the index changes every time the device is disconnected and reconnected. This is hardcoded with the device id for the headset you listed above

pacmd set-card-profile `pacmd list-cards | grep bluez_card -B1 | grep index | awk '{print $2}'` off; sleep 2 ; echo -e "disconnect 50:C9:71:97:A1:86\n quit"|bluetoothctl;sleep 5; echo -e "connect 50:C9:71:97:A1:86\n quit"|bluetoothctl; sleep 5; pacmd set-card-profile `pacmd list-cards | grep bluez_card -B1 | grep index | awk '{print $2}'` a2dp_sink  

During testing I ended up with the 5 seconds for sleep instead of 3 because the device wasn't ready to change the audio profile yet. Your results may vary by a few seconds +/- 5 seconds. Edit regarding a potential pitfall. I did find that it's is occasionally needed to run the larger script twice before it works. I'm not sure if increasing the sleep times would help or not as I haven't tested that. But I have used it on two machines with the same brand of BT headphones and it's doing what it's supposed to for automating the process to get the sound working on the headphones.

Eventually the issue will be patched in the bluetooth package but seems to keep returning in new releases of Ubuntu as well as other versions of Linux. But anyhow hope that helps for you


Solution:2

I had this problem on Ubuntu 16.04.1 LTS, and applying the GDM work around found in https://wiki.debian.org/BluetoothUser/a2dp solved it.

Specifically, create/edit /var/lib/gdm3/.config/pulse/client.conf to read:

autospawn = no  daemon-binary = /bin/true  

Then

sudo chown gdm:gdm /var/lib/gdm3/.config/pulse/client.conf  

I also added to /etc/pulse/default.pa

load-module module-switch-on-connect  

Though this might not be strictly necessary.

After a reboot, I connected via bluetooth manager was able to successfully switch the audio profile to a2dp_sink.


Solution:3

In order to allow your system to be detected as an A2DP sink (e.g. to play music from your phone via your computer speakers), add Enable=Source,Sink,Media,Socket under [General] in /etc/bluetooth/audio.conf.

After doing this, restart the bluetooth daemon

systemctl restart bluetooth  

Connect you headphone device

bluetoothctl  connect <MAC>  

Check your card and set profile

pacmd list-cards  pacmd set-card-profile <index> <profile>  


Solution:4

lagerismi posted a script here on launchpad based on the answer by Jamie S.

  • Change the devices MAC-address in the variable inside the script! (can be found with bluetoothctl --> Device)

  • Make the script executable chmod a-x bluetooth_headphone_reactivation.sh

For automatic execution at startup (only works if headset is already turned on):

  • Add the script to the start/shutdown scripts in KDE's control panel

For fast manual execution:

  • Add an entry to the application-starter (you can also set a keyboad shortcut like "CTRL+ALT+H" and/or pin this starter to the window bar)

The script:

#!/bin/sh  device_mac='<your-devices-mac-address-here>'  pacmd set-card-profile `pacmd list-cards | grep bluez_card -B1 | grep index | awk '{print $2}'` off  sleep 2   echo "disconnect $device_mac\n quit"|bluetoothctl  sleep 5  echo "connect $device_mac\n quit"|bluetoothctl  sleep 5  pacmd set-card-profile `pacmd list-cards | grep bluez_card -B1 | grep index | awk '{print $2}'` a2dp_sink  


Solution:5

On Xubuntu 16.04.2
Use blueman-manager:

  1. connect -> set profile off
  2. reconnect -> set profile a2dp
  3. now your headset is ok!

My JBL bash script

#!/bin/bash  #headset mac  mac="00:1D:DF:67:0A:29"  profile="a2dp"  # Special Bluetooth controller, default is empty  btMac=""  #connect|disconnect wait time  waitTime=5    macId="${mac//:/_}"  deviceId="bluez_card.$macId"    declare -A profiles  profiles['a2dp']='a2dp_sink'  profiles['hsp']='headset_head_unit'  profiles['off']='off'    function btCmd() {      cmd="$1\nquit"      [ ! -z "$btMac" ] && cmd="select $btMac\n$cmd"      echo -e "$cmd" | bluetoothctl  }  function setProfile() {      cmd="pactl set-card-profile $deviceId ${profiles[$1]}"      echo $cmd      $cmd  }  function btWaitConnect() {      conState=$1      for ((i=1;i<=$waitTime;++i)); do          tmp="`btCmd "info $mac"|grep 'Connected: '`"          [ ! -z "`echo "$tmp"|grep $conState`" ] && echo "$tmp" && return 0          sleep 1s      done      echo "$tmp"      return 1  }  function btConnect() {      tmp="`btCmd "trust $mac\nconnect $mac" | grep -v 'NEW\|DEL\| quit'`"      echo "$tmp"        tmp="`btWaitConnect yes`"      echo $tmp      [ -z "`echo "$tmp" | grep yes`" ] && echo -e "Device $mac:\n\tConnected: fail." && return 1      sleep 2s      return 0  }  function btDisConnect() {      tmp="`btCmd "disconnect $mac" | grep -v 'NEW\|DEL\| quit'`"      echo "$tmp"        tmp="`btWaitConnect no`"      echo $tmp      [ -z "`echo "$tmp" | grep no`" ] && echo -e "Device $mac:\n\tdisconnected: fail." && return 1      sleep 1s      return 0      }      # controller  echo ""  btCtls="`btCmd list | grep '^Controller' | grep " $btMac"`"  echo -e "controller:\n$btCtls"  [ -z "$btCtls" -o ! -z "`echo "$btCtls" | grep "not available"`" ] && exit 1      # connect -> set off  echo ""  tmp="`btCmd paired-devices | grep '^Device' | grep " $mac"`"  echo -e "paired-devices:\n$tmp"  [ `echo "$tmp" | wc -l` != 1 ] && echo "Please pair the Bluetooth headset first: $mac" && exit 1  btConnect || exit $?  setProfile off    # reconnect -> set profile  btDisConnect || exit $?  btConnect || exit $?  setProfile $profile  


Solution:6

I was trying to set up my Bluetooth and always got this error.

I found that the problem was Skype. If I have Skype running I'm unable to set a2dp_sink profile.

So, if you run into this issue, see if you have Skype running and turn it off.


Solution:7

I'm sure that the previous answers actually try to address the root cause of the problem. I, however, was not able to get any of them to work. I had the exact same issue as OP, but on Linux Mint 17/18. I wrote this script to reliably get bluetooth connected and using a2dp.

Copy/pasted for posterity, but the brunt of the matter is that it exactly replicates what the OP (and I) would have to do in the UI.

The script by Dominik wouldn't reliably work for me, because it would only try once to set everything up. I'd have to run it multiple times to get it to work. This is what I ended up with, that works every time.

#!/bin/bash    MAC=$1  CARD=$(echo "${MAC}" | sed -e 's/:/_/g')  CARD="bluez_card.${CARD}"    $(pactl list | grep -qi 'Active Profile: a2dp_sink')  a2dpUsed=$?    # this loops until a2dp is _actually used_ on the given MAC.  while [ ${a2dpUsed} -ne 0 ];  do      #      echo "Restarting bluetooth."      rfkill unblock bluetooth      sudo service bluetooth restart      sudo hciconfig hci0 up        # reconnect      echo -e "power on\nconnect ${MAC}" | bluetoothctl        #      echo "Waiting for headset to be connected..."      btConnected=1        while [ ${btConnected} -gt 0 ];      do            sleep .1          $(bluetoothctl <<< "info ${MAC}" | grep -qi "Connected: yes")          btConnected=$?      done        #      echo "Bluetooth connected, waiting for profiles to register"        cardFound=1      while [ ${cardFound} -ne 0 ];      do          $(pactl list | grep -qi "${CARD}")          cardFound=$?      done        #      echo "Setting bluetooth a2dp profile"      pactl set-card-profile ${CARD} a2dp_sink      $(pactl list | grep -qi 'Active Profile: a2dp_sink')      a2dpUsed=$?  done    echo "a2dp is working."  


Solution:8

systemctl restart bluetooth  
  • Open sound settings (accessible by clicking on the speaker icon in the tray)
  • Try and change the Output profile to A2DP Sink.
  • If that doesn't work, change your device to Speakers, or something else and then switch it back.
  • I usually find that I can then set my Output profile


Solution:9

In my case my wife's account did steal the a2dp profile and prevented my account from enabling it. Unfortunately I do not have a solution for it yet beside logging her off. I tried to follow this guide [https://rudd-o.com/linux-and-free-software/how-to-make-pulseaudio-run-once-at-boot-for-all-your-users], but it made things worse for me


Solution:10

As documented in here, It is because GDM captures A2DP sink on session start, as GDM needs pulseaudio in the gdm session for accessibility.
Try to add this to "/var/lib/gdm3/.config/pulse/default.pa", or create it, then reboot:

!/usr/bin/pulseaudio -nF

#

load system wide configuration

.include /etc/pulse/default.pa

unload driver modules for Bluetooth hardware

.ifexists module-bluetooth-policy.so unload-module module-bluetooth-policy .endif

.ifexists module-bluetooth-discover.so unload-module module-bluetooth-discover .endif


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »