From 9bbaed40d8041fc991b2914b98c38a20a093ab20 Mon Sep 17 00:00:00 2001 From: caitao123456789 Date: Wed, 28 Feb 2024 16:53:40 +0800 Subject: [PATCH] bluetooth: Resolve the remote volume anomaly synchronize the local volume When the Bluetooth a2dp protocol is used, local set the Bluetooth volume frequently , and the remote volume may be synchronized with the local volume. For example,b if the local volume is set to 20 and then to 60, and the remote volume is returned to 20, the local volume is inconsistent with the remote volume, and the volume is synchronized The Bluetooth remote volume is abnormal change the local volume Signed-off-by: caitao123456789 --- src/modules/bluetooth/bluez5-util.c | 18 +++++++++++++++--- src/modules/bluetooth/bluez5-util.h | 2 ++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c index 2431b3831..bb15980ed 100644 --- a/src/modules/bluetooth/bluez5-util.c +++ b/src/modules/bluetooth/bluez5-util.c @@ -213,6 +213,7 @@ pa_bluetooth_transport *pa_bluetooth_transport_new(pa_bluetooth_device *d, const /* Always force initial volume to be set/propagated correctly */ t->sink_volume = PA_VOLUME_INVALID; t->source_volume = PA_VOLUME_INVALID; + t->set_sink_volume_count = 0; if (size > 0) { t->config = pa_xnew(uint8_t, size); @@ -590,10 +591,12 @@ static pa_volume_t pa_bluetooth_transport_set_volume(pa_bluetooth_transport *t, if (t->profile == PA_BLUETOOTH_PROFILE_A2DP_SOURCE) t->source_volume = volume; - else if (t->profile == PA_BLUETOOTH_PROFILE_A2DP_SINK) + else if (t->profile == PA_BLUETOOTH_PROFILE_A2DP_SINK){ t->sink_volume = volume; + t->set_sink_volume_count++; + } - pa_log_debug("Sending A2DP volume %d/127 to peer", gain); + pa_log_debug("Sending A2DP volume %d/127 to peer, set_sink_volume_count: %d", gain, t->set_sink_volume_count); pa_assert_se(m = dbus_message_new_method_call(BLUEZ_SERVICE, t->path, DBUS_INTERFACE_PROPERTIES, "Set")); @@ -648,8 +651,17 @@ static void pa_bluetooth_transport_remote_volume_changed(pa_bluetooth_transport t->source_volume = volume; hook = PA_BLUETOOTH_HOOK_TRANSPORT_SOURCE_VOLUME_CHANGED; } else if (t->profile == PA_BLUETOOTH_PROFILE_A2DP_SINK) { - if (t->sink_volume == volume) + if (t->sink_volume == volume){ + t->set_sink_volume_count = 0; return; + } + + if (t->set_sink_volume_count > 0){ + t->set_sink_volume_count--; + pa_log_debug("set_sink_volume_count: %d, volume: %d, sink_volume: %d", t->set_sink_volume_count, volume, t->sink_volume); + return; + } + t->sink_volume = volume; hook = PA_BLUETOOTH_HOOK_TRANSPORT_SINK_VOLUME_CHANGED; diff --git a/src/modules/bluetooth/bluez5-util.h b/src/modules/bluetooth/bluez5-util.h index fff3d573c..41f81e673 100644 --- a/src/modules/bluetooth/bluez5-util.h +++ b/src/modules/bluetooth/bluez5-util.h @@ -134,6 +134,8 @@ struct pa_bluetooth_transport { pa_bluetooth_transport_set_volume_cb set_sink_volume; pa_bluetooth_transport_set_volume_cb set_source_volume; void *userdata; + + int set_sink_volume_count; /* call set_sink_volume count */ }; struct pa_bluetooth_device {