summaryrefslogtreecommitdiff
path: root/profiles/audio
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2022-04-27 13:14:19 -0700
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2022-04-28 13:05:02 -0700
commitfa7828bddd2164408535a9ac45095564e9ebbeea (patch)
treef673f51edb5440a64d18f889087b541cc94429f6 /profiles/audio
parentf65a9c9d21f69942024ea5b9f581533d2788eb2e (diff)
downloadbluez-fa7828bddd2164408535a9ac45095564e9ebbeea.tar.gz
transport: Fix not being able to initialize volume properly
In case AVRCP is connected first and media_transport_update_device_volume is called without any media_player being available the volume setting would be lost and Transport.Volume won't be available, so this introduces btd_device_{set,get}_volume helpers which is used to store the volume temporarely so media_player_get_device_volume is able to restore it when the transport is created. Fixes: https://github.com/bluez/bluez/issues/335
Diffstat (limited to 'profiles/audio')
-rw-r--r--profiles/audio/media.c8
-rw-r--r--profiles/audio/transport.c12
2 files changed, 15 insertions, 5 deletions
diff --git a/profiles/audio/media.c b/profiles/audio/media.c
index 8162417ce..c5d8ab14e 100644
--- a/profiles/audio/media.c
+++ b/profiles/audio/media.c
@@ -456,11 +456,11 @@ int8_t media_player_get_device_volume(struct btd_device *device)
target_player = avrcp_get_target_player_by_device(device);
if (!target_player)
- return -1;
+ goto done;
adapter = find_adapter(device);
if (!adapter)
- return -1;
+ goto done;
for (l = adapter->players; l; l = l->next) {
struct media_player *mp = l->data;
@@ -469,7 +469,9 @@ int8_t media_player_get_device_volume(struct btd_device *device)
return mp->volume;
}
- return -1;
+done:
+ /* If media_player doesn't exists use device_volume */
+ return btd_device_get_volume(device);
}
static gboolean set_configuration(struct media_endpoint *endpoint,
diff --git a/profiles/audio/transport.c b/profiles/audio/transport.c
index d158fc97a..5848e4019 100644
--- a/profiles/audio/transport.c
+++ b/profiles/audio/transport.c
@@ -949,6 +949,7 @@ int8_t media_transport_get_device_volume(struct btd_device *dev)
if (dev == NULL)
return -1;
+ /* Attempt to locate the transport to get its volume */
for (l = transports; l; l = l->next) {
struct media_transport *transport = l->data;
if (transport->device != dev)
@@ -959,7 +960,8 @@ int8_t media_transport_get_device_volume(struct btd_device *dev)
return media_transport_get_volume(transport);
}
- return 0;
+ /* If transport volume doesn't exists use device_volume */
+ return btd_device_get_volume(dev);
}
void media_transport_update_device_volume(struct btd_device *dev,
@@ -970,13 +972,19 @@ void media_transport_update_device_volume(struct btd_device *dev,
if (dev == NULL || volume < 0)
return;
+ /* Attempt to locate the transport to set its volume */
for (l = transports; l; l = l->next) {
struct media_transport *transport = l->data;
if (transport->device != dev)
continue;
/* Volume is A2DP only */
- if (media_endpoint_get_sep(transport->endpoint))
+ if (media_endpoint_get_sep(transport->endpoint)) {
media_transport_update_volume(transport, volume);
+ return;
+ }
}
+
+ /* If transport volume doesn't exists add to device_volume */
+ btd_device_set_volume(dev, volume);
}