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

@ -982,7 +982,7 @@ static void source_set_volume_cb(pa_source *s) {
pa_cvolume_set(&s->real_volume, u->decoder_sample_spec.channels, volume);
/* Set soft volume when in headset role */
if (u->profile == PA_BLUETOOTH_PROFILE_HFP_AG || u->profile == PA_BLUETOOTH_PROFILE_HSP_AG)
if (pa_bluetooth_profile_should_attenuate_volume(u->profile))
pa_cvolume_set(&s->soft_volume, u->decoder_sample_spec.channels, volume);
}
@ -1162,7 +1162,7 @@ static void sink_set_volume_cb(pa_sink *s) {
pa_cvolume_set(&s->real_volume, u->encoder_sample_spec.channels, volume);
/* Set soft volume when in headset role */
if (u->profile == PA_BLUETOOTH_PROFILE_HFP_AG || u->profile == PA_BLUETOOTH_PROFILE_HSP_AG)
if (pa_bluetooth_profile_should_attenuate_volume(u->profile))
pa_cvolume_set(&s->soft_volume, u->encoder_sample_spec.channels, volume);
}
@ -2257,10 +2257,10 @@ static pa_hook_result_t transport_sink_volume_changed_cb(pa_bluetooth_discovery
volume = t->sink_volume;
pa_cvolume_set(&v, u->encoder_sample_spec.channels, volume);
if (t->profile == PA_BLUETOOTH_PROFILE_HSP_HS || t->profile == PA_BLUETOOTH_PROFILE_HFP_HF)
pa_sink_volume_changed(u->sink, &v);
else
if (pa_bluetooth_profile_should_attenuate_volume(t->profile))
pa_sink_set_volume(u->sink, &v, true, true);
else
pa_sink_volume_changed(u->sink, &v);
return PA_HOOK_OK;
}
@ -2279,10 +2279,10 @@ static pa_hook_result_t transport_source_volume_changed_cb(pa_bluetooth_discover
pa_cvolume_set(&v, u->decoder_sample_spec.channels, volume);
if (t->profile == PA_BLUETOOTH_PROFILE_HSP_HS || t->profile == PA_BLUETOOTH_PROFILE_HFP_HF)
pa_source_volume_changed(u->source, &v);
else
if (pa_bluetooth_profile_should_attenuate_volume(t->profile))
pa_source_set_volume(u->source, &v, true, true);
else
pa_source_volume_changed(u->source, &v);
return PA_HOOK_OK;
}