From 4e5c4122349031264bf47e6af9338f8ae0236d5f Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Fri, 7 May 2010 12:42:23 -0300 Subject: [PATCH] jifmux: Merge xmp and tagsetter tags. When the current file already has tags, they shouldn't be ignored, parse them and merge with the tagsetter ones. --- gst/jpegformat/gstjifmux.c | 59 +++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/gst/jpegformat/gstjifmux.c b/gst/jpegformat/gstjifmux.c index 5bc4d792a6..63ab65e89e 100644 --- a/gst/jpegformat/gstjifmux.c +++ b/gst/jpegformat/gstjifmux.c @@ -336,7 +336,10 @@ static gboolean gst_jif_mux_mangle_markers (GstJifMux * self) { gboolean modified = FALSE; - const GstTagList *tags; + const GstTagList *tagsetter_tags; + GstTagList *tags; + GstTagList *xmp_tags; + gboolean cleanup_tags = TRUE; GstJifMuxMarker *m; GList *node, *file_hdr = NULL, *frame_hdr = NULL, *scan_hdr = NULL; GList *app0_jfif = NULL, *app1_exif = NULL, *app1_xmp = NULL, *com = NULL; @@ -433,6 +436,48 @@ gst_jif_mux_mangle_markers (GstJifMux * self) /* else */ /* remove JFIF if exists */ + /* get tags in the current file */ + if (app1_xmp) { + GstJifMuxMarker *xmp_m; + GstBuffer *buf; + + xmp_m = (GstJifMuxMarker *) app1_xmp->data; + + buf = gst_buffer_new (); + GST_BUFFER_DATA (buf) = (guint8 *) xmp_m->data + 29; + GST_BUFFER_SIZE (buf) = xmp_m->size - 29; + + xmp_tags = gst_tag_list_from_xmp_buffer (buf); + gst_buffer_unref (buf); + GST_DEBUG_OBJECT (self, "Found xmp tags: %" GST_PTR_FORMAT, tags); + } else { + xmp_tags = NULL; + } + + tagsetter_tags = gst_tag_setter_get_tag_list (GST_TAG_SETTER (self)); + if (xmp_tags) { + if (tagsetter_tags) { + tags = gst_tag_list_merge (tagsetter_tags, xmp_tags, + gst_tag_setter_get_tag_merge_mode (GST_TAG_SETTER (self))); + gst_tag_list_free (xmp_tags); + } else { + tags = xmp_tags; + } + xmp_tags = NULL; + } else { + tags = (GstTagList *) tagsetter_tags; + cleanup_tags = FALSE; + } + + if (!tags) { + tags = gst_tag_list_new (); + } + /* FIXME: not happy with those + * - else where we would use VIDEO_CODEC = "Jpeg" + gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE, + GST_TAG_VIDEO_CODEC, "image/jpeg", NULL); + */ + /* if we want combined or EXIF */ /* check if we don't have EXIF APP1 */ if (!app1_exif) { @@ -442,15 +487,7 @@ gst_jif_mux_mangle_markers (GstJifMux * self) /* else */ /* remove EXIF if exists */ - tags = gst_tag_setter_get_tag_list (GST_TAG_SETTER (self)); - if (!tags) { - tags = gst_tag_list_new (); - } - /* FIXME: not happy with those - * - else where we would use VIDEO_CODEC = "Jpeg" - gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE, - GST_TAG_VIDEO_CODEC, "image/jpeg", NULL); - */ + GST_DEBUG_OBJECT (self, "Merged tags: %" GST_PTR_FORMAT, tags); /* add xmp */ xmp_data = gst_tag_list_to_xmp_buffer (tags, FALSE); @@ -500,6 +537,8 @@ gst_jif_mux_mangle_markers (GstJifMux * self) modified = TRUE; } + if (cleanup_tags && tags) + gst_tag_list_free (tags); return modified; }