bluetooth: Move attenuation decision to shared function

Generalize the distinction between local and peer-attenuated volumes
into a function, paving the way for future changes where this needs to
be checked in more places and when A2DP Absolute Volume support is
added.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/521>
This commit is contained in:
Marijn Suijten 2021-03-04 11:30:42 +01:00
parent d84ca03080
commit 9c847b16a8
4 changed files with 64 additions and 16 deletions

View file

@ -1738,6 +1738,34 @@ const char *pa_bluetooth_profile_to_string(pa_bluetooth_profile_t profile) {
return NULL;
}
/* Returns true when PA has to perform attenuation, false if this is the
* responsibility of the peer.
*
* `peer_profile` is the profile of the peer.
*
* When the peer is in the HFP/HSP Audio Gateway role (PA is in headset role) PA
* has to perform attenuation on both the incoming and outgoing stream. In the
* HandsFree/HeadSet role both are attenuated on the peer.
*/
bool pa_bluetooth_profile_should_attenuate_volume(pa_bluetooth_profile_t peer_profile) {
switch(peer_profile) {
case PA_BLUETOOTH_PROFILE_A2DP_SINK:
/* Will be set to false when A2DP absolute volume is supported */
return true;
case PA_BLUETOOTH_PROFILE_A2DP_SOURCE:
return true;
case PA_BLUETOOTH_PROFILE_HFP_HF:
case PA_BLUETOOTH_PROFILE_HSP_HS:
return false;
case PA_BLUETOOTH_PROFILE_HFP_AG:
case PA_BLUETOOTH_PROFILE_HSP_AG:
return true;
case PA_BLUETOOTH_PROFILE_OFF:
pa_assert_not_reached();
}
pa_assert_not_reached();
}
static const pa_a2dp_codec *a2dp_endpoint_to_a2dp_codec(const char *endpoint) {
const char *codec_name;