From 50aac8cdd84ba53c5cd4f2e746335218f2bccd0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Thu, 2 Dec 2021 08:52:07 +0100 Subject: [PATCH] gstclapper: Merge global tags instead replacing them There is no guarantee that received later tags also contain values from earlier ones, as they might come from different element. Combine them instead while replacing old values with newer ones. --- lib/gst/clapper/gstclapper.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/gst/clapper/gstclapper.c b/lib/gst/clapper/gstclapper.c index e97d6aed..7f5315c2 100644 --- a/lib/gst/clapper/gstclapper.c +++ b/lib/gst/clapper/gstclapper.c @@ -1865,6 +1865,15 @@ media_info_update (GstClapper * self, GstClapperMediaInfo * info) "image_sample: %p", info->title, info->container, info->image_sample); } +static void +merge_tags (GstTagList **my_tags, GstTagList *tags) +{ + if (*my_tags) + gst_tag_list_insert (*my_tags, tags, GST_TAG_MERGE_REPLACE); + else + *my_tags = gst_tag_list_ref (tags); +} + static void tags_cb (G_GNUC_UNUSED GstBus * bus, GstMessage * msg, gpointer user_data) { @@ -1880,17 +1889,12 @@ tags_cb (G_GNUC_UNUSED GstBus * bus, GstMessage * msg, gpointer user_data) if (gst_tag_list_get_scope (tags) == GST_TAG_SCOPE_GLOBAL) { g_mutex_lock (&self->lock); if (self->media_info) { - if (self->media_info->tags) - gst_tag_list_unref (self->media_info->tags); - self->media_info->tags = gst_tag_list_ref (tags); + merge_tags (&self->media_info->tags, tags); media_info_update (self, self->media_info); - g_mutex_unlock (&self->lock); } else { - if (self->global_tags) - gst_tag_list_unref (self->global_tags); - self->global_tags = gst_tag_list_ref (tags); - g_mutex_unlock (&self->lock); + merge_tags (&self->global_tags, tags); } + g_mutex_unlock (&self->lock); } gst_tag_list_unref (tags);