diff mbox series

[BlueZ,v2] player: Fix Track being emitted with empty metadata

Message ID 20220218234041.3460546-1-luiz.dentz@gmail.com
State Superseded
Headers show
Series [BlueZ,v2] player: Fix Track being emitted with empty metadata | expand

Commit Message

Luiz Augusto von Dentz Feb. 18, 2022, 11:40 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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.

Fixes: https://github.com/bluez/bluez/issues/291
---
 profiles/audio/player.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

Comments

bluez.test.bot@gmail.com Feb. 19, 2022, 2:35 a.m. UTC | #1
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=615912

---Test result---

Test Summary:
CheckPatch                    PASS      0.54 seconds
GitLint                       PASS      0.39 seconds
Prep - Setup ELL              PASS      41.47 seconds
Build - Prep                  PASS      0.51 seconds
Build - Configure             PASS      8.02 seconds
Build - Make                  PASS      1696.97 seconds
Make Check                    PASS      12.56 seconds
Make Check w/Valgrind         PASS      539.33 seconds
Make Distcheck                PASS      285.54 seconds
Build w/ext ELL - Configure   PASS      10.33 seconds
Build w/ext ELL - Make        PASS      1768.07 seconds
Incremental Build with patchesPASS      0.00 seconds



---
Regards,
Linux Bluetooth
diff mbox series

Patch

diff --git a/profiles/audio/player.c b/profiles/audio/player.c
index d34b39168..ae9c5456a 100644
--- a/profiles/audio/player.c
+++ b/profiles/audio/player.c
@@ -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,11 @@  static gboolean process_metadata_changed(void *user_data)
 	return FALSE;
 }
 
+static gboolean remove_metadata(void *key, void *value, void *user_data)
+{
+	return strcmp(key, "Duration") ? TRUE : FALSE;
+}
+
 void media_player_set_metadata(struct media_player *mp,
 				struct media_item *item, const char *key,
 				void *data, size_t len)
@@ -1434,7 +1444,7 @@  void media_player_set_metadata(struct media_player *mp,
 	}
 
 	if (mp->process_id == 0) {
-		g_hash_table_remove_all(mp->track);
+		g_hash_table_foreach_remove(mp->track, remove_metadata, NULL);
 		mp->process_id = g_idle_add(process_metadata_changed, mp);
 	}