From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v1 2/2] vcp: Fix using scaled values for volume
Date: Wed, 22 Jan 2025 16:14:46 -0500 [thread overview]
Message-ID: <20250122211446.142626-2-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20250122211446.142626-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This makes the volume range 0-255 as per VCP spec rather than scaling it
to fit 0-127.
---
profiles/audio/transport.c | 14 +++++++-------
profiles/audio/vcp.c | 23 +++++------------------
profiles/audio/vcp.h | 4 ++--
3 files changed, 14 insertions(+), 27 deletions(-)
diff --git a/profiles/audio/transport.c b/profiles/audio/transport.c
index eff95a7c2655..4635c978bd80 100644
--- a/profiles/audio/transport.c
+++ b/profiles/audio/transport.c
@@ -126,8 +126,8 @@ struct media_transport_ops {
void (*set_state)(struct media_transport *transport,
transport_state_t state);
void *(*get_stream)(struct media_transport *transport);
- int8_t (*get_volume)(struct media_transport *transport);
- int (*set_volume)(struct media_transport *transport, int8_t level);
+ uint8_t (*get_volume)(struct media_transport *transport);
+ int (*set_volume)(struct media_transport *transport, uint8_t level);
int (*set_delay)(struct media_transport *transport, uint16_t delay);
void (*update_links)(const struct media_transport *transport);
GDestroyNotify destroy;
@@ -616,7 +616,7 @@ static void transport_a2dp_remove_owner(struct media_transport *transport,
a2dp->cancel_resume = FALSE;
}
-static int8_t transport_a2dp_get_volume(struct media_transport *transport)
+static uint8_t transport_a2dp_get_volume(struct media_transport *transport)
{
struct a2dp_transport *a2dp = transport->data;
return a2dp->volume;
@@ -624,7 +624,7 @@ static int8_t transport_a2dp_get_volume(struct media_transport *transport)
#ifdef HAVE_AVRCP
static int transport_a2dp_src_set_volume(struct media_transport *transport,
- int8_t level)
+ uint8_t level)
{
struct a2dp_transport *a2dp = transport->data;
@@ -635,7 +635,7 @@ static int transport_a2dp_src_set_volume(struct media_transport *transport,
}
static int transport_a2dp_snk_set_volume(struct media_transport *transport,
- int8_t level)
+ uint8_t level)
{
struct a2dp_transport *a2dp = transport->data;
bool notify;
@@ -2190,13 +2190,13 @@ static void bap_connecting(struct bt_bap_stream *stream, bool state, int fd,
bap_update_links(transport);
}
-static int8_t transport_bap_get_volume(struct media_transport *transport)
+static uint8_t transport_bap_get_volume(struct media_transport *transport)
{
return bt_audio_vcp_get_volume(transport->device);
}
static int transport_bap_set_volume(struct media_transport *transport,
- int8_t volume)
+ uint8_t volume)
{
return bt_audio_vcp_set_volume(transport->device, volume) ? 0 : -EIO;
}
diff --git a/profiles/audio/vcp.c b/profiles/audio/vcp.c
index 608496a003b6..423210b4af3b 100644
--- a/profiles/audio/vcp.c
+++ b/profiles/audio/vcp.c
@@ -103,25 +103,12 @@ static bool match_data(const void *data, const void *match_data)
return vdata->vcp == vcp;
}
-static int8_t scale_volume(uint8_t volume)
-{
- /* Convert 0-255 to 0-127. */
- return volume / 2;
-}
-
-static uint8_t unscale_volume(int8_t volume)
-{
- /* Convert 0-127 to 0-255. */
- return volume * 2;
-}
-
static void vcp_volume_changed(struct bt_vcp *vcp, uint8_t volume)
{
struct vcp_data *data = queue_find(sessions, match_data, vcp);
if (data)
- media_transport_update_device_volume(data->device,
- scale_volume(volume));
+ media_transport_update_device_volume(data->device, volume);
}
static void vcp_data_add(struct vcp_data *data)
@@ -179,22 +166,22 @@ static void vcp_data_remove(struct vcp_data *data)
}
}
-int8_t bt_audio_vcp_get_volume(struct btd_device *device)
+uint8_t bt_audio_vcp_get_volume(struct btd_device *device)
{
struct vcp_data *data = queue_find(sessions, match_device, device);
if (data)
- return scale_volume(bt_vcp_get_volume(data->vcp));
+ return bt_vcp_get_volume(data->vcp);
return 0;
}
-bool bt_audio_vcp_set_volume(struct btd_device *device, int8_t volume)
+bool bt_audio_vcp_set_volume(struct btd_device *device, uint8_t volume)
{
struct vcp_data *data = queue_find(sessions, match_device, device);
if (data)
- return bt_vcp_set_volume(data->vcp, unscale_volume(volume));
+ return bt_vcp_set_volume(data->vcp, volume);
return FALSE;
}
diff --git a/profiles/audio/vcp.h b/profiles/audio/vcp.h
index f313cd96a5fc..cf7935d1a4ea 100644
--- a/profiles/audio/vcp.h
+++ b/profiles/audio/vcp.h
@@ -8,5 +8,5 @@
*
*/
-int8_t bt_audio_vcp_get_volume(struct btd_device *device);
-bool bt_audio_vcp_set_volume(struct btd_device *device, int8_t volume);
+uint8_t bt_audio_vcp_get_volume(struct btd_device *device);
+bool bt_audio_vcp_set_volume(struct btd_device *device, uint8_t volume);
--
2.48.1
next prev parent reply other threads:[~2025-01-22 21:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-22 21:14 [PATCH BlueZ v1 1/2] org.bluez.MediaTransport: Allow Volume property to follow profile range Luiz Augusto von Dentz
2025-01-22 21:14 ` Luiz Augusto von Dentz [this message]
2025-01-22 22:27 ` [BlueZ,v1,1/2] " bluez.test.bot
2025-01-23 18:40 ` [PATCH BlueZ v1 1/2] " patchwork-bot+bluetooth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250122211446.142626-2-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox