Fixes a regression from !521 (merged):
Hardware volume is not set up when switching from A2DP to HFP and the device sends AT+VGS
too late (perhaps device-specific, happens at least on the WH1000-XM3s), leading to desyncs and the attenuation being applied twice.
Originally written for A2DP this rework of that patch enables late-bound
hardware volume control on HFP and HSP. As per the specification the
headphones (where gain control for both speaker and microphone could
happen in hardware on the peer) are supposed to send initial values for
these before the SCO connection is created; these AT+VG[MS]
commands
are also used to determine support for it. PA uses this information in
add_{sink,source}
to attach hardware volume callbacks, if it is
supported. Otherwise PA performs the attenuation in software.
Unfortunately headphones like the WH-1000XM3's connect to A2DP
initially and only send AT+VGS
(microphone hardware gain is not
supported) during SCO connection when the user switches to the HFP
profile afterwards; the callbacks set up dynamically in
rfcomm_io_callback
are written after the sink and source have been
created (add_{sink,source}
), leaving them without hardware volume
callbacks and with software volume when adjusted on the PA side. (The
headphones can still send volume updates resulting in abrupt changes if
software and peer volume differ. Furthermore the same attenuation is
applied twice - once in PA software, once on the peer).
To solve this problem we simply check whether the callbacks have been attached whenever the peer sends a volume change, and if not attach the callbacks to the sink/source and reset software volume.
Fixes: d510ddc7 ("bluetooth: Perform software attenuation until HF/HS reports gain control")
CC @igor.v.kovalenko