Skip to contentSkip to conversation

player: Fix Track being emitted with empty metadata

PATCH Superseded Luiz Augusto von Dentz 2 participants 2 messages Feb 22, 2022 Bluetooth drivers

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH v3 1/1 player: Fix Track being emitted with empty metadata

From: Luiz Augusto von Dentz <[email protected]>

This sometimes causes the Track to be schedule while some metadata are still pending, also don't remove the Duration from track when updating its metadata since Duration is typically updated by player status rather than metadata.

---
 profiles/audio/player.c | 43 ++++++++++++++++++++++++++++-------------
 1 file changed, 30 insertions(+), 13 deletions(-)
profiles/audio/player.c +30 -13
index d34b39168..8ea68e8f8 100644
@@ -1308,9 +1308,14 @@ void media_player_set_duration(struct media_player *mp, uint32_t duration)
 
 	g_hash_table_replace(mp->track, g_strdup("Duration"), value);
 
-	g_dbus_emit_property_changed(btd_get_dbus_connection(),
+	/* If metadata is pending wait for it */
+	if (mp->process_id)
+		return;
+
+	g_dbus_emit_property_changed_full(btd_get_dbus_connection(),
 					mp->path, MEDIA_PLAYER_INTERFACE,
-					"Track");
+					"Track",
+					G_DBUS_PROPERTY_CHANGED_FLAG_FLUSH);
 }
 
 void media_player_set_position(struct media_player *mp, uint32_t position)
@@ -1417,6 +1422,23 @@ static gboolean process_metadata_changed(void *user_data)
 	return FALSE;
 }
 
+static gboolean remove_metadata(void *key, void *value, void *user_data)
+{
+	if (!strcmp(key, "Duration"))
+		return FALSE;
+
+	return strcmp(key, "Item") ? TRUE : FALSE;
+}
+
+static void metadata_changed(struct media_player *mp)
+{
+	if (mp->process_id)
+		return;
+
+	g_hash_table_foreach_remove(mp->track, remove_metadata, NULL);
+	mp->process_id = g_idle_add(process_metadata_changed, mp);
+}
+
 void media_player_set_metadata(struct media_player *mp,
 				struct media_item *item, const char *key,
 				void *data, size_t len)
@@ -1433,10 +1455,7 @@ void media_player_set_metadata(struct media_player *mp,
 		return;
 	}
 
-	if (mp->process_id == 0) {
-		g_hash_table_remove_all(mp->track);
-		mp->process_id = g_idle_add(process_metadata_changed, mp);
-	}
+	metadata_changed(mp);
 
 	g_hash_table_replace(mp->track, g_strdup(key), value);
 }
@@ -1962,6 +1981,7 @@ struct media_item *media_player_set_playlist_item(struct media_player *mp,
 {
 	struct media_folder *folder = mp->playlist;
 	struct media_item *item;
+	char *path;
 
 	DBG("%" PRIu64 "", uid);
 
@@ -1980,16 +2000,13 @@ struct media_item *media_player_set_playlist_item(struct media_player *mp,
 		mp->track = g_hash_table_ref(item->metadata);
 	}
 
-	if (item == g_hash_table_lookup(mp->track, "Item"))
+	path = g_hash_table_lookup(mp->track, "Item");
+	if (path && !strcmp(path, item->path))
 		return item;
 
-	if (mp->process_id == 0) {
-		g_hash_table_remove_all(mp->track);
-		mp->process_id = g_idle_add(process_metadata_changed, mp);
-	}
+	metadata_changed(mp);
 
-	g_hash_table_replace(mp->track, g_strdup("Item"),
-						g_strdup(item->path));
+	g_hash_table_replace(mp->track, g_strdup("Item"), g_strdup(item->path));
 
 	return item;
 }
Signature · 1 line
2.35.1
#1 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=616860

---Test result---

Test Summary:

CheckPatch                    PASS      1.45 seconds
GitLint                       PASS      0.99 seconds
Prep - Setup ELL              PASS      41.05 seconds
Build - Prep                  PASS      0.72 seconds
Build - Configure             PASS      8.43 seconds
Build - Make                  PASS      1252.41 seconds
Make Check                    PASS      11.06 seconds
Make Check w/Valgrind         PASS      451.14 seconds
Make Distcheck                PASS      229.57 seconds
Build w/ext ELL - Configure   PASS      9.63 seconds
Build w/ext ELL - Make        PASS      1230.50 seconds
Incremental Build with patchesPASS      0.00 seconds

---
Regards,
Linux Bluetooth