Linux bluetooth development
 help / color / mirror / Atom feed
From: raghu447 <raghavendra.rao@collabora.com>
To: linux-bluetooth@vger.kernel.org
Cc: raghavendra <raghavendra.rao@collabora.com>
Subject: [PATCH 2/4] profiles/audio: Support MCS fast seeking
Date: Fri,  4 Sep 2026 22:23:30 +0530	[thread overview]
Message-ID: <20260904165332.42046-3-raghavendra.rao@collabora.com> (raw)
In-Reply-To: <20260904165332.42046-1-raghavendra.rao@collabora.com>

From: raghavendra <raghavendra.rao@collabora.com>

Map Fast Rewind and Fast Forward to relative MPRIS Seek calls.

Report direction through Seeking Speed until Seeked restores player
state.

This is required by PTS tests GMCS/SR/MCP/BV-05-C to BV-08-C.
---
 profiles/audio/mcp.c | 49 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/profiles/audio/mcp.c b/profiles/audio/mcp.c
index 2d239ac4b..314bce243 100644
--- a/profiles/audio/mcp.c
+++ b/profiles/audio/mcp.c
@@ -60,6 +60,7 @@
 
 #define MCS_UUID_STR	"00001848-0000-1000-8000-00805f9b34fb"
 #define GMCS_UUID_STR	"00001849-0000-1000-8000-00805f9b34fb"
+#define MCS_SEEK_OFFSET_USEC	(10 * G_USEC_PER_SEC)
 
 
 /*
@@ -440,6 +441,7 @@ struct mcs_instance {
 	struct bt_mcs *mcs;
 	struct queue *player_links;
 	bool at_start;
+	int8_t seeking_speed;
 
 	/* GMCS-specific */
 	struct bt_uinput *uinput;
@@ -494,6 +496,11 @@ static void mcs_update_media_state(struct mcs_instance *mcs)
 		state = BT_MCS_STATE_INACTIVE;
 	}
 
+	if (state != BT_MCS_STATE_SEEKING && mcs->seeking_speed) {
+		mcs->seeking_speed = 0;
+		bt_mcs_changed(mcs->mcs, MCS_SEEKING_SPEED_CHRC_UUID);
+	}
+
 	bt_mcs_set_media_state(mcs->mcs, state);
 	bt_mcs_changed(mcs->mcs, MCS_TRACK_POSITION_CHRC_UUID);
 }
@@ -557,6 +564,11 @@ static void lp_track_position(uint32_t old_ms, uint32_t new_ms, void *user_data)
 	if (!player_link_is_active(p))
 		return;
 
+	if (mcs->seeking_speed) {
+		mcs_update_media_state(mcs);
+		return;
+	}
+
 	bt_mcs_changed(mcs->mcs, MCS_TRACK_POSITION_CHRC_UUID);
 }
 
@@ -656,6 +668,33 @@ static bool mcs_pause(void *data)
 	return mcs_command(mcs, BT_MCS_CMD_PAUSE);
 }
 
+/* MPRIS Seek uses signed offsets: negative rewinds, positive advances. */
+static bool mcs_fast_rewind(void *data)
+{
+	struct mcs_instance *mcs = data;
+	struct player_link *p = mcs_get_active(mcs);
+
+	if (!p || !local_player_seek(p->lp, -MCS_SEEK_OFFSET_USEC))
+		return false;
+
+	mcs->seeking_speed = -1;
+	bt_mcs_changed(mcs->mcs, MCS_SEEKING_SPEED_CHRC_UUID);
+	return true;
+}
+
+static bool mcs_fast_forward(void *data)
+{
+	struct mcs_instance *mcs = data;
+	struct player_link *p = mcs_get_active(mcs);
+
+	if (!p || !local_player_seek(p->lp, MCS_SEEK_OFFSET_USEC))
+		return false;
+
+	mcs->seeking_speed = 1;
+	bt_mcs_changed(mcs->mcs, MCS_SEEKING_SPEED_CHRC_UUID);
+	return true;
+}
+
 static bool mcs_stop(void *data)
 {
 	struct mcs_instance *mcs = data;
@@ -752,6 +791,13 @@ static int32_t mcs_track_position(void *data)
 	return local_player_get_position(p->lp) / 10;
 }
 
+static int8_t mcs_seeking_speed(void *data)
+{
+	struct mcs_instance *mcs = data;
+
+	return mcs->seeking_speed;
+}
+
 static uint8_t mcs_playing_order(void *data)
 {
 	struct mcs_instance *mcs = data;
@@ -876,12 +922,15 @@ static const struct bt_mcs_callback gmcs_cb = {
 	.track_title = mcs_track_title,
 	.track_duration = mcs_track_duration,
 	.track_position = mcs_track_position,
+	.seeking_speed = mcs_seeking_speed,
 	.playing_order = mcs_playing_order,
 	.playing_order_supported = mcs_playing_order_supported,
 	.set_track_position = mcs_set_track_position,
 	.set_playing_order = mcs_set_playing_order,
 	.play = mcs_play,
 	.pause = mcs_pause,
+	.fast_rewind = mcs_fast_rewind,
+	.fast_forward = mcs_fast_forward,
 	.stop = mcs_stop,
 	.next_track = mcs_next_track,
 	.previous_track = mcs_previous_track,
-- 
2.43.0


  parent reply	other threads:[~2026-09-04 16:53 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31  6:11 [BlueZ PATCH 0/3] Add MCS fast seek and track position write raghu447
2026-08-31  6:11 ` [BlueZ PATCH 1/3] profiles/audio: Support MCS fast seeking raghu447
2026-09-02 15:31   ` Luiz Augusto von Dentz
2026-08-31  6:11 ` [BlueZ PATCH 2/3] profiles/audio: Support MCS track position writes raghu447
2026-09-02 15:35   ` Luiz Augusto von Dentz
2026-09-03  8:19     ` Bastien Nocera
2026-09-04 16:53       ` [PATCH 0/4] Add MCS fast seek and track position write support raghu447
2026-09-04 16:53         ` [PATCH 1/4] profiles/audio: Support MCS track position writes raghu447
2026-09-04 17:51           ` Add MCS fast seek and track position write support bluez.test.bot
2026-09-04 16:53         ` raghu447 [this message]
2026-09-04 16:53         ` [PATCH 3/4] shared/mcp: Notify unsupported RFU opcodes raghu447
2026-09-04 16:53         ` [PATCH 4/4] unit/test-mcp: Test unsupported RFU opcode raghu447
2026-09-04 20:20         ` [PATCH 0/4] Add MCS fast seek and track position write support patchwork-bot+bluetooth
2026-08-31  6:11 ` [BlueZ PATCH 3/3] shared/mcp: Notify unsupported RFU opcodes raghu447
2026-09-02 15:36   ` Luiz Augusto von Dentz

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=20260904165332.42046-3-raghavendra.rao@collabora.com \
    --to=raghavendra.rao@collabora.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