mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
bluez5: get initial node volume from transport
When emitting node, get initial volumes from transport hardware volume, if available. The session manager usually overrides these immediately with saved values, but it's better to show the HW volume when the node first appears.
This commit is contained in:
parent
d82b3d6479
commit
77959a2c1c
1 changed files with 27 additions and 9 deletions
|
|
@ -337,35 +337,51 @@ static void node_update_soft_volumes(struct node *node, float hw_volume)
|
|||
}
|
||||
}
|
||||
|
||||
static void volume_changed(void *userdata)
|
||||
static bool node_update_volume_from_transport(struct node *node, bool reset)
|
||||
{
|
||||
struct node *node = userdata;
|
||||
struct impl *impl = node->impl;
|
||||
struct spa_bt_transport_volume *t_volume;
|
||||
float prev_hw_volume;
|
||||
|
||||
if (!node->transport || !spa_bt_transport_volume_enabled(node->transport))
|
||||
return;
|
||||
return false;
|
||||
|
||||
/* PW is the controller for remote device. */
|
||||
if (impl->profile != DEVICE_PROFILE_A2DP
|
||||
&& impl->profile != DEVICE_PROFILE_HSP_HFP)
|
||||
return;
|
||||
return false;
|
||||
|
||||
t_volume = &node->transport->volumes[node->id];
|
||||
|
||||
if (!t_volume->active)
|
||||
return;
|
||||
return false;
|
||||
|
||||
prev_hw_volume = node_get_hw_volume(node);
|
||||
for (uint32_t i = 0; i < node->n_channels; ++i) {
|
||||
node->volumes[i] = prev_hw_volume > 0.0f
|
||||
? node->volumes[i] * t_volume->volume / prev_hw_volume
|
||||
: t_volume->volume;
|
||||
|
||||
if (!reset) {
|
||||
for (uint32_t i = 0; i < node->n_channels; ++i) {
|
||||
node->volumes[i] = prev_hw_volume > 0.0f
|
||||
? node->volumes[i] * t_volume->volume / prev_hw_volume
|
||||
: t_volume->volume;
|
||||
}
|
||||
} else {
|
||||
for (uint32_t i = 0; i < node->n_channels; ++i)
|
||||
node->volumes[i] = t_volume->volume;
|
||||
}
|
||||
|
||||
node_update_soft_volumes(node, t_volume->volume);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void volume_changed(void *userdata)
|
||||
{
|
||||
struct node *node = userdata;
|
||||
struct impl *impl = node->impl;
|
||||
|
||||
if (!node_update_volume_from_transport(node, false))
|
||||
return;
|
||||
|
||||
emit_volume(impl, node);
|
||||
|
||||
impl->info.change_mask |= SPA_DEVICE_CHANGE_MASK_PARAMS;
|
||||
|
|
@ -469,6 +485,8 @@ static void emit_node(struct impl *this, struct spa_bt_transport *t,
|
|||
this->nodes[id].volumes[i] = this->nodes[id].volumes[i % prev_channels];
|
||||
}
|
||||
|
||||
node_update_volume_from_transport(&this->nodes[id], true);
|
||||
|
||||
boost = get_soft_volume_boost(&this->nodes[id]);
|
||||
if (boost != 1.0f) {
|
||||
size_t i;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue