From f92a5b3bbd89733a32b249c79d5adc94ddd299fd Mon Sep 17 00:00:00 2001 From: Huang-Huang Bao Date: Thu, 3 Jun 2021 05:48:25 +0800 Subject: [PATCH] bluez5: emit node volume and mute right after bluez5 node creating bluez5 nodes will always be removed & created again during profile changing, hence node volume & mute will always be reset. This is OK if profile did changed, because session manager would carries volume & mute to bluez5 route param. But if profile was not changed after setting profile (a2dp-sink-sbc -> a2dp-sink -> a2dp-sink-sbc), session manager would think node volume & mute are not changed and no route setting is performed, causing route volume out of sync with node volume. To fix this, we emit node volume and mute right after bluez5 node is created. Fixes #1254 --- spa/plugins/bluez5/bluez5-device.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/spa/plugins/bluez5/bluez5-device.c b/spa/plugins/bluez5/bluez5-device.c index 701b88d65..5882b6143 100644 --- a/spa/plugins/bluez5/bluez5-device.c +++ b/spa/plugins/bluez5/bluez5-device.c @@ -238,7 +238,7 @@ static void transport_destroy(void *userdata) node->transport = NULL; } -static void emit_volume(struct impl *this, struct node *node) +static void emit_node_props(struct impl *this, struct node *node, bool full) { struct spa_event *event; uint8_t buffer[4096]; @@ -259,11 +259,23 @@ static void emit_volume(struct impl *this, struct node *node) SPA_TYPE_Float, node->n_channels, node->soft_volumes), SPA_PROP_channelMap, SPA_POD_Array(sizeof(uint32_t), SPA_TYPE_Id, node->n_channels, node->channels)); + if (full) { + spa_pod_builder_add(&b, + SPA_PROP_mute, SPA_POD_Bool(node->mute), + SPA_PROP_softMute, SPA_POD_Bool(node->mute), + SPA_PROP_latencyOffsetNsec, SPA_POD_Long(node->latency_offset), + 0); + } event = spa_pod_builder_pop(&b, &f[0]); spa_device_emit_event(&this->hooks, event); } +static void emit_volume(struct impl *this, struct node *node) +{ + emit_node_props(this, node, false); +} + static void emit_info(struct impl *this, bool full); static float node_get_hw_volume(struct node *node) @@ -379,6 +391,8 @@ static void emit_node(struct impl *this, struct spa_bt_transport *t, spa_hook_remove(&this->nodes[id].transport_listener); this->nodes[id].transport = t; spa_bt_transport_add_listener(t, &this->nodes[id].transport_listener, &transport_events, &this->nodes[id]); + + emit_node_props(this, &this->nodes[id], true); } }