Created
October 11, 2022 19:27
-
-
Save Vudentz/19edcf96735567c1f7437a5e1dee7e04 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/profiles/audio/transport.c b/profiles/audio/transport.c | |
index a1445cba7993..23046ff53099 100644 | |
--- a/profiles/audio/transport.c | |
+++ b/profiles/audio/transport.c | |
@@ -118,7 +118,7 @@ struct media_transport { | |
void (*set_state) (struct media_transport *transport, | |
transport_state_t state); | |
void (*set_volume) (struct media_transport *transp, | |
- int8_t volume); | |
+ int8_t volume, bool change); | |
int8_t (*get_volume) (struct media_transport *transp); | |
GDestroyNotify destroy; | |
void *data; | |
@@ -738,10 +738,7 @@ static void set_volume(const GDBusPropertyTable *property, | |
void *data) | |
{ | |
struct media_transport *transport = data; | |
- struct a2dp_transport *a2dp = transport->data; | |
uint16_t arg; | |
- int8_t volume; | |
- bool notify; | |
if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_UINT16) | |
goto error; | |
@@ -750,22 +747,13 @@ static void set_volume(const GDBusPropertyTable *property, | |
if (arg > INT8_MAX) | |
goto error; | |
+ if (!transport->set_volume) | |
+ goto error; | |
+ | |
g_dbus_pending_property_success(id); | |
- volume = (int8_t)arg; | |
- if (a2dp->volume == volume) | |
- return; | |
+ transport->set_volume(transport, arg, true); | |
- notify = transport->source_watch ? true : false; | |
- if (notify) { | |
- a2dp->volume = volume; | |
- g_dbus_emit_property_changed(btd_get_dbus_connection(), | |
- transport->path, | |
- MEDIA_TRANSPORT_INTERFACE, | |
- "Volume"); | |
- } | |
- | |
- avrcp_set_volume(transport->device, volume, notify); | |
return; | |
error: | |
@@ -1112,9 +1100,11 @@ static int8_t get_volume_a2dp(struct media_transport *transport) | |
return a2dp->volume; | |
} | |
-static void set_volume_a2dp(struct media_transport *transport, int8_t volume) | |
+static void set_volume_a2dp(struct media_transport *transport, int8_t volume, | |
+ bool change) | |
{ | |
struct a2dp_transport *a2dp = transport->data; | |
+ bool notify; | |
if (volume < 0) | |
return; | |
@@ -1125,9 +1115,23 @@ static void set_volume_a2dp(struct media_transport *transport, int8_t volume) | |
a2dp->volume = volume; | |
- g_dbus_emit_property_changed(btd_get_dbus_connection(), | |
- transport->path, | |
- MEDIA_TRANSPORT_INTERFACE, "Volume"); | |
+ if (!change) { | |
+ g_dbus_emit_property_changed(btd_get_dbus_connection(), | |
+ transport->path, | |
+ MEDIA_TRANSPORT_INTERFACE, | |
+ "Volume"); | |
+ return; | |
+ } | |
+ | |
+ notify = transport->source_watch ? true : false; | |
+ if (notify) { | |
+ g_dbus_emit_property_changed(btd_get_dbus_connection(), | |
+ transport->path, | |
+ MEDIA_TRANSPORT_INTERFACE, | |
+ "Volume"); | |
+ } | |
+ | |
+ avrcp_set_volume(transport->device, volume, notify); | |
} | |
diff --git a/profiles/audio/transport.c b/profiles/audio/transport.c | |
index a1445cba7993..23046ff53099 100644 | |
--- a/profiles/audio/transport.c | |
+++ b/profiles/audio/transport.c | |
@@ -118,7 +118,7 @@ struct media_transport { | |
void (*set_state) (struct media_transport *transport, | |
transport_state_t state); | |
void (*set_volume) (struct media_transport *transp, | |
- int8_t volume); | |
+ int8_t volume, bool change); | |
int8_t (*get_volume) (struct media_transport *transp); | |
GDestroyNotify destroy; | |
void *data; | |
@@ -738,10 +738,7 @@ static void set_volume(const GDBusPropertyTable *property, | |
void *data) | |
{ | |
struct media_transport *transport = data; | |
- struct a2dp_transport *a2dp = transport->data; | |
uint16_t arg; | |
- int8_t volume; | |
- bool notify; | |
if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_UINT16) | |
goto error; | |
@@ -750,22 +747,13 @@ static void set_volume(const GDBusPropertyTable *property, | |
if (arg > INT8_MAX) | |
goto error; | |
+ if (!transport->set_volume) | |
+ goto error; | |
+ | |
g_dbus_pending_property_success(id); | |
- volume = (int8_t)arg; | |
- if (a2dp->volume == volume) | |
- return; | |
+ transport->set_volume(transport, arg, true); | |
- notify = transport->source_watch ? true : false; | |
- if (notify) { | |
- a2dp->volume = volume; | |
- g_dbus_emit_property_changed(btd_get_dbus_connection(), | |
- transport->path, | |
- MEDIA_TRANSPORT_INTERFACE, | |
- "Volume"); | |
- } | |
- | |
- avrcp_set_volume(transport->device, volume, notify); | |
return; | |
error: | |
@@ -1112,9 +1100,11 @@ static int8_t get_volume_a2dp(struct media_transport *transport) | |
return a2dp->volume; | |
} | |
-static void set_volume_a2dp(struct media_transport *transport, int8_t volume) | |
+static void set_volume_a2dp(struct media_transport *transport, int8_t volume, | |
+ bool change) | |
{ | |
struct a2dp_transport *a2dp = transport->data; | |
+ bool notify; | |
if (volume < 0) | |
return; | |
@@ -1125,9 +1115,23 @@ static void set_volume_a2dp(struct media_transport *transport, int8_t volume) | |
a2dp->volume = volume; | |
- g_dbus_emit_property_changed(btd_get_dbus_connection(), | |
- transport->path, | |
- MEDIA_TRANSPORT_INTERFACE, "Volume"); | |
+ if (!change) { | |
+ g_dbus_emit_property_changed(btd_get_dbus_connection(), | |
+ transport->path, | |
+ MEDIA_TRANSPORT_INTERFACE, | |
+ "Volume"); | |
+ return; | |
+ } | |
+ | |
+ notify = transport->source_watch ? true : false; | |
+ if (notify) { | |
+ g_dbus_emit_property_changed(btd_get_dbus_connection(), | |
+ transport->path, | |
+ MEDIA_TRANSPORT_INTERFACE, | |
+ "Volume"); | |
+ } | |
+ | |
+ avrcp_set_volume(transport->device, volume, notify); | |
} | |
static int media_transport_init_source(struct media_transport *transport) | |
@@ -1471,7 +1475,8 @@ static void free_bap(void *data) | |
free(bap); | |
} | |
-static void set_volume_bap(struct media_transport *transport, int8_t volume) | |
+static void set_volume_bap(struct media_transport *transport, int8_t volume, | |
+ bool change) | |
{ | |
struct bap_transport *bap = transport->data; | |
@@ -1679,7 +1684,7 @@ void media_transport_update_device_volume(struct btd_device *dev, | |
/* Set transport volume */ | |
if (transport->set_volume) { | |
- transport->set_volume(transport, volume); | |
+ transport->set_volume(transport, volume, false); | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment