[PATCH BlueZ 2/3] audio/player: Clear playlist on Now Playing Changed AVRCP event

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Some devices reuse the item ids for the Now Playing list on playlist
change. This commit allows to clear the list and prevent to keep the
previous tracks information.
---
 profiles/audio/avrcp.c  | 15 +++++++++++++++
 profiles/audio/avrcp.h  |  1 +
 profiles/audio/player.c | 11 +++++++++++
 profiles/audio/player.h |  1 +
 4 files changed, 28 insertions(+)

diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index ee750f50b..cab9fb4b2 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -3819,6 +3819,17 @@ static void avrcp_setting_changed(struct avrcp *session,
 	}
 }
 
+static void avrcp_now_playing_changed(struct avrcp *session,
+						struct avrcp_header *pdu)
+{
+	struct avrcp_player *player = session->controller->player;
+	struct media_player *mp = player->user_data;
+
+	DBG("NowPlaying changed");
+
+	media_player_clear_playlist(mp);
+}
+
 static void avrcp_available_players_changed(struct avrcp *session,
 						struct avrcp_header *pdu)
 {
@@ -3909,6 +3920,9 @@ static gboolean avrcp_handle_event(struct avctp *conn, uint8_t code,
 	case AVRCP_EVENT_SETTINGS_CHANGED:
 		avrcp_setting_changed(session, pdu);
 		break;
+	case AVRCP_EVENT_NOW_PLAYING_CHANGED:
+		avrcp_now_playing_changed(session, pdu);
+		break;
 	case AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED:
 		avrcp_available_players_changed(session, pdu);
 		break;
@@ -4000,6 +4014,7 @@ static gboolean avrcp_get_capabilities_resp(struct avctp *conn, uint8_t code,
 		case AVRCP_EVENT_TRACK_CHANGED:
 		case AVRCP_EVENT_PLAYBACK_POS_CHANGED:
 		case AVRCP_EVENT_SETTINGS_CHANGED:
+		case AVRCP_EVENT_NOW_PLAYING_CHANGED:
 		case AVRCP_EVENT_ADDRESSED_PLAYER_CHANGED:
 		case AVRCP_EVENT_UIDS_CHANGED:
 		case AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED:
diff --git a/profiles/audio/avrcp.h b/profiles/audio/avrcp.h
index 59117e946..887753ddf 100644
--- a/profiles/audio/avrcp.h
+++ b/profiles/audio/avrcp.h
@@ -64,6 +64,7 @@
 #define AVRCP_EVENT_TRACK_REACHED_START		0x04
 #define AVRCP_EVENT_PLAYBACK_POS_CHANGED	0x05
 #define AVRCP_EVENT_SETTINGS_CHANGED		0x08
+#define AVRCP_EVENT_NOW_PLAYING_CHANGED		0x09
 #define AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED	0x0a
 #define AVRCP_EVENT_ADDRESSED_PLAYER_CHANGED	0x0b
 #define AVRCP_EVENT_UIDS_CHANGED		0x0c
diff --git a/profiles/audio/player.c b/profiles/audio/player.c
index 5bb3bc1a9..0f72d7601 100644
--- a/profiles/audio/player.c
+++ b/profiles/audio/player.c
@@ -2024,6 +2024,17 @@ struct media_item *media_player_set_playlist_item(struct media_player *mp,
 	return item;
 }
 
+void media_player_clear_playlist(struct media_player *mp)
+{
+	if (mp->playlist) {
+		g_slist_free_full(mp->playlist->items, media_item_destroy);
+		mp->playlist->items = NULL;
+	}
+
+	g_dbus_emit_property_changed(btd_get_dbus_connection(), mp->path,
+					MEDIA_PLAYER_INTERFACE, "Playlist");
+}
+
 void media_player_set_obex_port(struct media_player *mp, uint16_t port)
 {
 	mp->obex_port = port;
diff --git a/profiles/audio/player.h b/profiles/audio/player.h
index 0076c4641..5e181591c 100644
--- a/profiles/audio/player.h
+++ b/profiles/audio/player.h
@@ -86,6 +86,7 @@ void media_player_set_folder(struct media_player *mp, const char *path,
 void media_player_set_playlist(struct media_player *mp, const char *name);
 struct media_item *media_player_set_playlist_item(struct media_player *mp,
 								uint64_t uid);
+void media_player_clear_playlist(struct media_player *mp);
 void media_player_set_obex_port(struct media_player *mp, uint16_t port);
 
 struct media_item *media_player_create_folder(struct media_player *mp,
-- 
2.34.1





[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux