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 <caitao@kylinos.cn>
This commit is contained in:
caitao123456789 2024-02-28 16:53:40 +08:00
parent 26ccd1167a
commit 9bbaed40d8
2 changed files with 17 additions and 3 deletions

View file

@ -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;

View file

@ -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 {