Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4985441ioa; Wed, 27 Apr 2022 16:06:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6HizI6RpjiUTbTfxk/KW+dTbqVyn8BvBZNG1XpYcTCX474MP11PBMhvKB5jrsJk79P15B X-Received: by 2002:a50:fb83:0:b0:425:cb1f:dc57 with SMTP id e3-20020a50fb83000000b00425cb1fdc57mr26815981edq.150.1651100799476; Wed, 27 Apr 2022 16:06:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651100799; cv=none; d=google.com; s=arc-20160816; b=QgXb+bm+xMgTR9VSXhP5c4cdeqR99rIhfnOhLtuEUVMqlLYb7s12I5oV00FDJXiMnf 7jLJEpM3l9/5otL7cIywvOkTjNYAoRWEGwHVq69vUDePzfuVBiDLITM1/7natNQ6e2uY Sy3/WKcAb1+DZxuvc+2TV7/Y1E/K47RvDTL3LsTR69zcuUpVBPT6U+xuYb0T9EJE3TMa QMkX77WYpJrJEDG1G5zMyt2EtcPG/kHRGVXHSPd2lQEiT46furszLIQa7W600CUI3Yf5 to/6KatmQhZ6vVw61dhNPJj83FJxerakEi2a87PC7JM341XwqOR8eMZUDCgR4d4ktYuz 3JDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=cETnd29l+7iiB9xh0H31tkH84AUx5Esjc6woAPerXBU=; b=Xh7Ra6duqTutFZRa7U8CSxWOtMyGa2pGwbWedXpnwC6iKGKpvRVd7bEiCSUs6OzJ2L ieiZG0NftRL1BDiNio95iUJWjFAUFf/HwG88CUWoNFC4kEZsc8qAVu0/Et3NeZqCS9T9 0uvF/Ei5BTjvG/gUuLg66F2EKVM2hpYIaKq0MBsX3Eeb9bSDxUjV76C3yrYxK2aZcHZ2 IP8qSugghdIFs4HBeSnO9miAPxLZv7PklhGgR8aPomDwjNcNv+Vu3jtOtiul/gGH/Po1 C9UXUW/Smd72RAK2TGfQxFuxXzI6GYPcD+VsXZoGQ6je/X2FGp1VeRW//9sn7zaSw/K1 ikpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Uy7VBbEc; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c12-20020a170906528c00b006e83ff45dfasi2278364ejm.154.2022.04.27.16.06.13; Wed, 27 Apr 2022 16:06:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Uy7VBbEc; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235742AbiD0UXU (ORCPT + 99 others); Wed, 27 Apr 2022 16:23:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235664AbiD0UXS (ORCPT ); Wed, 27 Apr 2022 16:23:18 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF926606E1 for ; Wed, 27 Apr 2022 13:19:59 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id cu23-20020a17090afa9700b001d98d8e53b7so4641651pjb.0 for ; Wed, 27 Apr 2022 13:19:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=cETnd29l+7iiB9xh0H31tkH84AUx5Esjc6woAPerXBU=; b=Uy7VBbEccXWwfgTPCH+mFaaFtL+sLHdW9Dns7skSZCH+HHqjQsCzV8QbIFZEW2L0kJ BD11WOT+L6EsdT69DoUrgFQcY8jqiLe/12CDIv3f5tDXK21+tikhpJjfXd3vbzl9OU9X Te3hwEoohfucN8IMMtMNgwxE4ytrJ/viY9TWwlk5lxQPULytL9t9sOwrw87U3NsE4oBY JCttYGb8FgGt7vk5/ziYq/WKNhI/s2k3jS+PFwJ2ftltQp3vYabMQYcwpe92lRblZ455 T0KJ3+OcB7dyMg/0WsoGVBofFW0VN1Eqrhtc1tqaFc8R8fZhjCKZud8q+1n5hWdr7cAq s/6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=cETnd29l+7iiB9xh0H31tkH84AUx5Esjc6woAPerXBU=; b=G+N2HKlsd7hz2Xkj2LveG+TJp44dQ2x+w7M5bg7VSWypuhYkYL6ikbrWXunzFo+XEb PkvZpRR9XdWtz2oddUSV9KPq19cAMz7U5XzLSvHdCH7bisDJ1x5cppkiIrPXZrGJiDsl xfmWLFUS8NgtBy/HDzViMWzVntEdYQ2jo0tUryQW7Z6w/mwO67O24lUbC3jsOAgGirTB nbhvM3e+QctDuwip0RC8LvprX9P5ZqFN0awilQb+i/wRPgm/K1YckNFp6+pf/H6gZcmk 2Bfz+tj0ZyEUi7U3eQpc19TLZUeM0vmkYdVGCbRIoEdpyQnu5ni8rO0EWuQ63bdfWiRP 0Ixw== X-Gm-Message-State: AOAM532HUeiicfzvHn2q/TSbARWNQpykMuBdsK2kJQmntnfN+RTF+yp/ PL0awBXy33lnvY0X1OezF728CbXDzN8= X-Received: by 2002:a17:902:e393:b0:15c:f1c1:c527 with SMTP id g19-20020a170902e39300b0015cf1c1c527mr22952793ple.22.1651090799092; Wed, 27 Apr 2022 13:19:59 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id 35-20020a631063000000b003c14af50602sm149708pgq.26.2022.04.27.13.19.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 13:19:58 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ] transport: Fix not being able to initialize volume properly Date: Wed, 27 Apr 2022 13:19:57 -0700 Message-Id: <20220427201957.1004671-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz 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 --- profiles/audio/transport.c | 12 ++++++++++-- src/device.c | 13 +++++++++++++ src/device.h | 3 +++ 3 files changed, 26 insertions(+), 2 deletions(-) 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); } diff --git a/src/device.c b/src/device.c index 38f4993f2..112bcc1f9 100644 --- a/src/device.c +++ b/src/device.c @@ -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; +} diff --git a/src/device.h b/src/device.h index 071576d6b..9cdc0e68d 100644 --- a/src/device.h +++ b/src/device.h @@ -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); -- 2.35.1