Linux bluetooth development
 help / color / mirror / Atom feed
From: Simon Mikuda <simon.mikuda@streamunlimited.com>
To: linux-bluetooth@vger.kernel.org
Cc: Simon Mikuda <simon.mikuda@streamunlimited.com>
Subject: [PATCH BlueZ v3 10/10] player: Fix Now Playing NumberOfItems when its content changes
Date: Tue, 24 Nov 2026 10:28:33 +0100	[thread overview]
Message-ID: <20261124092833.1191053-10-simon.mikuda@streamunlimited.com> (raw)
In-Reply-To: <20261124092833.1191053-1-simon.mikuda@streamunlimited.com>

When the target reports that Now Playing changed
(NOW_PLAYING_CONTENT_CHANGED), bluetoothd drops the listed items but
keeps the old NumberOfItems, and ListItems asks the target for only that
many items. So if the list grows while the client stays in Now Playing,
ListItems still returns only as many items as before.

To reproduce, list the 2 items of Now Playing, let the target add 3
items, and list Now Playing again:

  btmon: EventID: 0x09 (EVENT_NOW_PLAYING_CONTENT_CHANGED)
  avrcp_now_playing_changed() NowPlaying changed
  bluetoothd: profiles/audio/player.c:get_items() 2
  btmon: AVRCP: GetFolderItems: len 0x0022
  btmon: Scope: 0x03 (Now Playing)
  btmon: StartItem: 0x00000000 (0)
  btmon: EndItem: 0x00000001 (1)
  avrcp_list_items_rsp() start 0 end 1 items 2 total 2

Only the 2 items listed before are listed again.

When Now Playing changes, reset NumberOfItems to 0 (unknown), so that
ListItems asks for all items until the target reports the new number,
and request the number again if Now Playing is the current folder.

Fixes: 671f370a8e34 ("audio/player: Clear playlist on Now Playing Changed AVRCP event")
Assisted-by: Claude:claude-opus-5-5
---
 profiles/audio/player.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/profiles/audio/player.c b/profiles/audio/player.c
index 9802e52bb..e1458dfb8 100644
--- a/profiles/audio/player.c
+++ b/profiles/audio/player.c
@@ -2065,9 +2065,25 @@ struct media_item *media_player_set_playlist_item(struct media_player *mp,
 
 void media_player_clear_playlist(struct media_player *mp)
 {
+	struct player_callback *cb = mp->cb;
+
 	if (mp->playlist) {
 		g_slist_free_full(mp->playlist->items, media_item_destroy);
 		mp->playlist->items = NULL;
+
+		/* Unknown until the target reports it again */
+		mp->playlist->number_of_items = 0;
+	}
+
+	if (mp->playlist && mp->scope == mp->playlist) {
+		g_dbus_emit_property_changed(btd_get_dbus_connection(),
+						mp->path,
+						MEDIA_FOLDER_INTERFACE,
+						"NumberOfItems");
+
+		if (cb->cbs->total_items)
+			cb->cbs->total_items(mp, mp->scope->item->name,
+							cb->user_data);
 	}
 
 	g_dbus_emit_property_changed(btd_get_dbus_connection(), mp->path,
-- 
2.43.0


  parent reply	other threads:[~2026-11-24  9:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24  9:28 [PATCH BlueZ v3 01/10] avrcp: Fix not checking browsing PDU parameter length Simon Mikuda
2026-11-24  9:28 ` [PATCH BlueZ v3 02/10] avrcp: Fix listing media players up to item 0xffffffff Simon Mikuda
2026-11-24  9:28 ` [PATCH BlueZ v3 03/10] avrcp: Fix byte order of ADDRESSED_PLAYER_CHANGED notification Simon Mikuda
2026-11-24  9:28 ` [PATCH BlueZ v3 04/10] avrcp: Fix byte order of TRACK_CHANGED identifier Simon Mikuda
2026-11-24  9:28 ` [PATCH BlueZ v3 05/10] avrcp: Fix not browsing a player addressed before it was listed Simon Mikuda
2026-11-24  9:28 ` [PATCH BlueZ v3 06/10] player: Fix crash on Search in a folder with a space in its name Simon Mikuda
2026-11-24  9:28 ` [PATCH BlueZ v3 07/10] player: Fix missing Name of listed Now Playing items Simon Mikuda
2026-11-24  9:28 ` [PATCH BlueZ v3 08/10] avrcp: Fix NumberOfItems set from a reply for another folder Simon Mikuda
2026-11-24  9:28 ` [PATCH BlueZ v3 09/10] unit/test-media-player: Add test for a stale NumberOfItems reply Simon Mikuda
2026-11-24  9:28 ` Simon Mikuda [this message]
2026-11-24 11:24 ` [BlueZ,v3,01/10] avrcp: Fix not checking browsing PDU parameter length bluez.test.bot

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=20261124092833.1191053-10-simon.mikuda@streamunlimited.com \
    --to=simon.mikuda@streamunlimited.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