arkq / bluez-alsa

Bluetooth Audio ALSA Backend
MIT License
865 stars 189 forks source link

Volume not updating with bluealsa plugin #733

Open Asikbct opened 1 month ago

Asikbct commented 1 month ago

Problem

When our DUT acts as A2DP source and connects then streams audio to external BT speaker using bluealsa plugin. With some model of speakers like realme buds headsets and JBL speakers, when we start to steam audio we could not control volume at initial. later like after 15 to 20 seconds we could able to control the volume of external BT speaker through MediaTransport volume property.

I have tried with the latest master branch when we try to get bluealsa PCM it throws error "ALSA lib bluealsa-pcm.c:1638:(_snd_pcm_bluealsa_open) Couldn't get BlueALSA PCM: Get PCM: Get properties: Incorrect variant for 'Volume': q != a"

Reproduction steps

  1. connect DUT with external BT speaker.
  2. Start audio stream with bluealsa plugin.
  3. Audio will start play from external BT speaker.
  4. If you increase/decrease the volume from DUT, it will not reflect on the external BT speaker.
  5. After some time, Volume can be updated.

Setup

OS ver: Linux username 5.4.210 #2 SMP PREEMPT Thu Oct 17 10:18:00 IST 2024 aarch64 GNU/Linux bluealsa ver: v4.1.1 bluetoothd ver: v5.72 aplay: version 1.2.1 by Jaroslav Kysela perex@perex.cz

Additional context

whenever we get volume update issue once started the streaming, that time we get this error print from bluez

D/bluetoothd[885]: profiles/audio/avctp.c:req_timeout() transaction 4 retry false D/bluetoothd: bluetoothd[885]: profiles/audio/avctp.c:req_timeout() transaction 4 retry false

arkq commented 4 weeks ago

ALSA lib bluealsa-pcm.c:1638:(_snd_pcm_bluealsa_open) Couldn't get BlueALSA PCM: Get PCM: Get properties: Incorrect variant for 'Volume': q != a

It seems that you are trying to use bluealsad and bluealsa ALSA plugin from different builds. There was a non-backward compatible change in 0d488c7b67.

profiles/audio/avctp.c:req_timeout() transaction 4 retry false

It looks like something is not right with the sink device (speaker/earbuds) then. Alternatively try different versions of BlueZ (maybe there is some bug in BlueZ). If nothing helps, in order to get better user experience with such devices, you will have to switch to software volume. Add SOFTVOL option to the ALSA device string, e.g. bluealsa:DEV=01:23:45:67:89:AB,PROFILE=a2dp,SOFTVOL=yes

Asikbct commented 4 weeks ago

@arkq Thanks for the response. bluealsa:DEV=01:23:45:67:89:AB,PROFILE=a2dp,SOFTVOL=yes if I give a PCM device name like the above, Will it work with Absolute volume support or only software Alsa volume handling? If it does not support abs volume support, how to change the sink speaker's system volume instead of audio volume?

arkq commented 3 weeks ago

if I give a PCM device name like the above, Will it work with Absolute volume support or only software Alsa volume handling?

This will use software volume scaling only (on BlueALSA side).

How to change the sink speaker's system volume instead of audio volume?

If you speaker has some buttons, then you can have (probably not desired, due to double scaling) possibility to scale volume on the speaker side too. Also, you might try adjusting the D-Bus Volume property of acquired media transport, e.g.: gdbus call --system -d org.bluez -o /org/bluez/hci0/dev_1C_48_F9_9D_81_5C/fd1 -m org.freedesktop.DBus.Properties.Set org.bluez.MediaTransport1 Volume '<uint16 30>' when that is possible after that initial 15-20 seconds. But the root cause why it's not possible to control volume has to be either in BlueZ or in your speaker.

Asikbct commented 1 week ago

I tested with BlueZ version 5.72, which is already quite recent. Is there still a need to update BlueZ?

I also verified the same behavior using other third-party Bluetooth audio sources. They are able to control the volume immediately upon connecting to the same Realme Buds and JBL speakers.

I'm not certain which audio server they are using to stream audio to the external speaker.