diff --git a/spa/plugins/bluez5/bluez5-device.c b/spa/plugins/bluez5/bluez5-device.c index 04066d034..fcf608700 100644 --- a/spa/plugins/bluez5/bluez5-device.c +++ b/spa/plugins/bluez5/bluez5-device.c @@ -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;