transport: Fix not being able to initialize volume properly
Luiz Augusto von Dentz
maintainerPATCH v2 1/1 transport: Fix not being able to initialize volume properly
From: Luiz Augusto von Dentz <[email protected]>
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.
--- profiles/audio/media.c | 8 +++++--- profiles/audio/transport.c | 12 ++++++++++-- src/device.c | 13 +++++++++++++ src/device.h | 3 +++ 4 files changed, 31 insertions(+), 5 deletions(-)
profiles/audio/media.c +5 -3
@@ -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,
profiles/audio/transport.c +10 -2
@@ -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); }
src/device.c +13 -0
@@ -274,6 +274,8 @@ struct btd_device {guint store_id;time_t name_resolve_failed_time; + +int8_t volume; };static const uint16_t uuid_list[] = {
@@ -4334,6 +4336,7 @@ static struct btd_device *device_new(struct btd_adapter *adapter,return NULL ; device->tx_power =127 ; + device->volume =-1 ; device->db =gatt_db_new ();if (!device->db) {
@@ -7303,3 +7306,13 @@ void btd_device_cleanup(void) {btd_service_remove_state_cb (service_state_cb_id); } + +void btd_device_set_volume (struct btd_device *device,int8_t volume) +{ + device->volume = volume; +} + +int8_t btd_device_get_volume (struct btd_device *device) +{ +return device->volume; +}
src/device.h +3 -0
@@ -180,3 +180,6 @@ bool btd_device_all_services_allowed(struct btd_device *dev);void btd_device_update_allowed_services (struct btd_device *dev);void btd_device_init (void );void btd_device_cleanup (void ); + +void btd_device_set_volume (struct btd_device *dev,int8_t volume); +int8_t btd_device_get_volume (struct btd_device *dev);
Signature · 1 line
2.35.1
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=636708
---Test result---
Test Summary:
CheckPatch PASS 1.64 seconds GitLint PASS 1.03 seconds Prep - Setup ELL PASS 53.69 seconds Build - Prep PASS 0.72 seconds Build - Configure PASS 10.65 seconds Build - Make PASS 1500.21 seconds Make Check PASS 13.10 seconds Make Check w/Valgrind PASS 543.56 seconds Make Distcheck PASS 284.26 seconds Build w/ext ELL - Configure PASS 10.81 seconds Build w/ext ELL - Make PASS 1464.59 seconds Incremental Build with patchesPASS 0.00 seconds
---
Regards,
Linux Bluetooth
This patch was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Hello:
This patch was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Quoted 11 lines · On Thu, 28 Apr 2022 13:05:20 -0700 you wrote:
From: Luiz Augusto von Dentz <[email protected]>
In case AVRCP is connected first and
media_transport_update_device_volumeis called without anymedia_playerbeing 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 somedia_player_get_device_volumeis able to restore it when the transport is created.[...]
Here is the summary with links:
- [v2] transport: Fix not being able to initialize volume properly
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=fa7828bddd21
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html