2 * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
4 * gsttag.c: tag support (aka metadata)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
26 #include "gst_private.h"
27 #include "gst-i18n-lib.h"
32 #include <gobject/gvaluecollector.h>
35 #define GST_TAG_IS_VALID(tag) (gst_tag_get_info (tag) != NULL)
38 GType type; /* type the data is in */
40 gchar * nick; /* translated name */
41 gchar * blurb; /* translated description of type */
43 GstTagMergeFunc merge_func; /* functions to merge the values */
44 GstTagFlag flag; /* type of tag */
47 #define TAGLIST "taglist"
48 static GQuark gst_tag_list_quark;
49 static GMutex *__tag_mutex;
50 static GHashTable *__tags;
51 #define TAG_LOCK g_mutex_lock (__tag_mutex)
52 #define TAG_UNLOCK g_mutex_unlock (__tag_mutex)
55 gst_tag_list_get_type (void)
57 static GType _gst_tag_list_type;
59 if (_gst_tag_list_type == 0) {
60 _gst_tag_list_type = g_boxed_type_register_static ("GstTagList",
61 (GBoxedCopyFunc) gst_tag_list_copy,
62 (GBoxedFreeFunc) gst_tag_list_free);
65 g_value_register_transform_func(_gst_tag_list_type, G_TYPE_STRING,
66 _gst_structure_transform_to_string);
70 return _gst_tag_list_type;
74 _gst_tag_initialize (void)
76 gst_tag_list_quark = g_quark_from_static_string (TAGLIST);
77 __tag_mutex = g_mutex_new ();
78 __tags = g_hash_table_new (g_direct_hash, g_direct_equal);
79 gst_tag_register (GST_TAG_TITLE, GST_TAG_FLAG_META,
82 _("commonly used title"),
83 gst_tag_merge_strings_with_comma);
84 gst_tag_register (GST_TAG_ARTIST, GST_TAG_FLAG_META,
87 _("person(s) responsible for the recording"),
88 gst_tag_merge_strings_with_comma);
89 gst_tag_register (GST_TAG_ALBUM, GST_TAG_FLAG_META,
92 _("album containing this data"),
93 gst_tag_merge_strings_with_comma);
94 gst_tag_register (GST_TAG_DATE, GST_TAG_FLAG_META,
95 G_TYPE_UINT, /* FIXME: own data type for dates? */
97 _("date the data was created (in Julian calendar days)"),
99 gst_tag_register (GST_TAG_GENRE, GST_TAG_FLAG_META,
102 _("genre this data belongs to"),
103 gst_tag_merge_strings_with_comma);
104 gst_tag_register (GST_TAG_COMMENT, GST_TAG_FLAG_META,
107 _("free text commenting the data"),
108 gst_tag_merge_strings_with_comma);
109 gst_tag_register (GST_TAG_TRACK_NUMBER, GST_TAG_FLAG_META,
112 _("track number inside a collection"),
113 gst_tag_merge_use_first);
114 gst_tag_register (GST_TAG_TRACK_COUNT, GST_TAG_FLAG_META,
117 _("count of tracks inside collection this track belongs to"),
118 gst_tag_merge_use_first);
119 gst_tag_register (GST_TAG_ALBUM_VOLUME_NUMBER, GST_TAG_FLAG_META,
122 _("disc number inside a collection"),
123 gst_tag_merge_use_first);
124 gst_tag_register (GST_TAG_ALBUM_VOLUME_COUNT, GST_TAG_FLAG_META,
127 _("count of discs inside collection this disc belongs to"),
128 gst_tag_merge_use_first);
129 gst_tag_register (GST_TAG_LOCATION, GST_TAG_FLAG_META,
132 _("original location of file as a URI"),
133 gst_tag_merge_strings_with_comma);
134 gst_tag_register (GST_TAG_DESCRIPTION, GST_TAG_FLAG_META,
137 _("short text describing the content of the data"),
138 gst_tag_merge_strings_with_comma);
139 gst_tag_register (GST_TAG_VERSION, GST_TAG_FLAG_META,
142 _("version of this data"),
144 gst_tag_register (GST_TAG_ISRC, GST_TAG_FLAG_META,
147 _("International Standard Recording Code - see http://www.ifpi.org/isrc/"),
149 gst_tag_register (GST_TAG_ORGANIZATION, GST_TAG_FLAG_META,
152 _("organization"), /* FIXME */
153 gst_tag_merge_strings_with_comma);
154 gst_tag_register (GST_TAG_COPYRIGHT, GST_TAG_FLAG_META,
157 _("copyright notice of the data"),
159 gst_tag_register (GST_TAG_CONTACT, GST_TAG_FLAG_META,
162 _("contact information"),
163 gst_tag_merge_strings_with_comma);
164 gst_tag_register (GST_TAG_LICENSE, GST_TAG_FLAG_META,
167 _("license of data"),
169 gst_tag_register (GST_TAG_PERFORMER, GST_TAG_FLAG_META,
172 _("person(s) performing"),
173 gst_tag_merge_strings_with_comma);
174 gst_tag_register (GST_TAG_DURATION, GST_TAG_FLAG_DECODED,
177 _("length in GStreamer time units (nanoseconds)"),
179 gst_tag_register (GST_TAG_CODEC, GST_TAG_FLAG_ENCODED,
182 _("codec the data is stored in"),
183 gst_tag_merge_strings_with_comma);
184 gst_tag_register (GST_TAG_VIDEO_CODEC, GST_TAG_FLAG_ENCODED,
187 _("codec the video data is stored in"),
189 gst_tag_register (GST_TAG_AUDIO_CODEC, GST_TAG_FLAG_ENCODED,
192 _("codec the audio data is stored in"),
194 gst_tag_register (GST_TAG_BITRATE, GST_TAG_FLAG_ENCODED,
197 _("exact or average bitrate in bits/s"),
199 gst_tag_register (GST_TAG_NOMINAL_BITRATE, GST_TAG_FLAG_ENCODED,
201 _("nominal bitrate"),
202 _("nominal bitrate in bits/s"),
204 gst_tag_register (GST_TAG_MINIMUM_BITRATE, GST_TAG_FLAG_ENCODED,
206 _("minimum bitrate"),
207 _("minimum bitrate in bits/s"),
209 gst_tag_register (GST_TAG_MAXIMUM_BITRATE, GST_TAG_FLAG_ENCODED,
211 _("maximum bitrate"),
212 _("maximum bitrate in bits/s"),
214 gst_tag_register (GST_TAG_ENCODER, GST_TAG_FLAG_ENCODED,
217 _("encoder used to encode this stream"),
219 gst_tag_register (GST_TAG_ENCODER_VERSION, GST_TAG_FLAG_ENCODED,
221 _("encoder version"),
222 _("version of the encoder used to encode this stream"),
224 gst_tag_register (GST_TAG_SERIAL, GST_TAG_FLAG_ENCODED,
227 _("serial number of track"),
229 gst_tag_register (GST_TAG_TRACK_GAIN, GST_TAG_FLAG_META,
231 _("replaygain track gain"),
232 _("track gain in db"),
234 gst_tag_register (GST_TAG_TRACK_PEAK, GST_TAG_FLAG_META,
236 _("replaygain track peak"),
237 _("peak of the track"),
239 gst_tag_register (GST_TAG_ALBUM_GAIN, GST_TAG_FLAG_META,
241 _("replaygain album gain"),
242 _("album gain in db"),
244 gst_tag_register (GST_TAG_ALBUM_PEAK, GST_TAG_FLAG_META,
246 _("replaygain album peak"),
247 _("peak of the album"),
251 * gst_tag_merge_use_first:
252 * @dest: uninitialized GValue to store result in
253 * @src: GValue to copy from
255 * This is a convenience function for the func argument of gst_tag_register().
256 * It creates a copy of the first value from the list.
259 gst_tag_merge_use_first (GValue *dest, const GValue *src)
261 const GValue *ret = gst_value_list_get_value (src, 0);
263 g_value_init (dest, G_VALUE_TYPE (ret));
264 g_value_copy (ret, dest);
267 * gst_tag_merge_strings_with_comma:
268 * @dest: uninitialized GValue to store result in
269 * @src: GValue to copy from
271 * This is a convenience function for the func argument of gst_tag_register().
272 * It concatenates all given strings using a comma. The tag must be registered
273 * as a G_TYPE_STRING or this function will fail.
276 gst_tag_merge_strings_with_comma (GValue *dest, const GValue *src)
281 count = gst_value_list_get_size (src);
282 str = g_string_new (g_value_get_string (gst_value_list_get_value (src, 0)));
283 for (i = 1; i < count; i++) {
284 /* seperator between two string */
285 str = g_string_append (str, _(", "));
286 str = g_string_append (str, g_value_get_string (gst_value_list_get_value (src, 1)));
289 g_value_init (dest, G_TYPE_STRING);
290 g_value_set_string_take_ownership (dest, str->str);
291 g_string_free (str, FALSE);
294 gst_tag_lookup (GQuark entry)
299 ret = g_hash_table_lookup (__tags, GUINT_TO_POINTER (entry));
306 * @name: the name or identifier string
307 * @flag: a flag describing the type of tag info
308 * @type: the type this data is in
309 * @nick: human-readable name
310 * @blurb: a human-readable description about this tag
311 * @func: function for merging multiple values of this tag
313 * Registers a new tag type for the use with GStreamer's type system. If a type
314 * with that name is already registered, that one is used.
315 * The old registration may have used a different type however. So don't rely
316 * on your supplied values.
317 * This function takes ownership of all supplied variables.
320 gst_tag_register (gchar *name, GstTagFlag flag, GType type,
321 gchar *nick, gchar *blurb, GstTagMergeFunc func)
326 g_return_if_fail (name != NULL);
327 g_return_if_fail (nick != NULL);
328 g_return_if_fail (blurb != NULL);
329 g_return_if_fail (type != 0 && type != GST_TYPE_LIST);
331 key = g_quark_from_string (name);
332 info = gst_tag_lookup (key);
333 g_return_if_fail (info == NULL);
335 info = g_new (GstTagInfo, 1);
340 info->merge_func = func;
343 g_hash_table_insert (__tags, GUINT_TO_POINTER (key), info);
348 * @tag: name of the tag
350 * Checks if the given type is already registered.
352 * Returns: TRUE if the type is already registered
355 gst_tag_exists (const gchar *tag)
357 g_return_val_if_fail (tag != NULL, FALSE);
359 return gst_tag_lookup (g_quark_from_string (tag)) != NULL;
365 * Gets the #GType used for this tag.
367 * Returns: the #GType of this tag
370 gst_tag_get_type (const gchar *tag)
374 g_return_val_if_fail (tag != NULL, 0);
375 info = gst_tag_lookup (g_quark_from_string (tag));
376 g_return_val_if_fail (info != NULL, 0);
384 * Returns the human-readable name of this tag, You must not change or free
387 * Returns: the human-readable name of this tag
390 gst_tag_get_nick (const gchar *tag)
394 g_return_val_if_fail (tag != NULL, NULL);
395 info = gst_tag_lookup (g_quark_from_string (tag));
396 g_return_val_if_fail (info != NULL, NULL);
401 * gst_tag_get_description:
404 * Returns the human-readable description of this tag, You must not change or
407 * Return the human-readable description of this tag
410 gst_tag_get_description (const gchar *tag)
414 g_return_val_if_fail (tag != NULL, NULL);
415 info = gst_tag_lookup (g_quark_from_string (tag));
416 g_return_val_if_fail (info != NULL, NULL);
421 * gst_tag_list_is_fixed:
424 * Checks if the given tag is fixed. A fixed tag can only contain one value.
425 * Unfixed tags can contain lists of values.
427 * Returns: TRUE, if the given tag is fixed.
430 gst_tag_is_fixed (const gchar *tag)
434 g_return_val_if_fail (tag != NULL, FALSE);
435 info = gst_tag_lookup (g_quark_from_string (tag));
436 g_return_val_if_fail (info != NULL, FALSE);
438 return info->merge_func == NULL;
443 * Creates a new empty GstTagList.
445 * Returns: An empty tag list
448 gst_tag_list_new (void)
450 return GST_TAG_LIST (gst_structure_new (TAGLIST, NULL));
454 * @p: Object that might be a taglist
456 * Checks if the given pointer is a taglist.
458 * Returns: TRUE, if the given pointer is a taglist
461 gst_is_tag_list (gconstpointer p)
463 g_return_val_if_fail (p != NULL, FALSE);
465 return ((GstStructure *) p)->name == gst_tag_list_quark;
469 GstTagMergeMode mode;
472 gst_tag_list_add_value_internal (GstStructure *list, GstTagMergeMode mode, GQuark tag, GValue *value)
474 GstTagInfo *info = gst_tag_lookup (tag);
475 const GValue *value2;
477 g_assert (info != NULL);
479 if (info->merge_func && (value2 = gst_structure_id_get_value (list, tag)) != NULL) {
480 GValue dest = { 0, };
482 case GST_TAG_MERGE_REPLACE_ALL:
483 case GST_TAG_MERGE_REPLACE:
484 gst_structure_id_set_value (list, tag, value);
486 case GST_TAG_MERGE_PREPEND:
487 gst_value_list_concat (&dest, value, value2);
488 gst_structure_id_set_value (list, tag, &dest);
489 g_value_unset (&dest);
491 case GST_TAG_MERGE_APPEND:
492 gst_value_list_concat (&dest, value2, value);
493 gst_structure_id_set_value (list, tag, &dest);
494 g_value_unset (&dest);
496 case GST_TAG_MERGE_KEEP:
497 case GST_TAG_MERGE_KEEP_ALL:
500 g_assert_not_reached ();
505 case GST_TAG_MERGE_APPEND:
506 case GST_TAG_MERGE_KEEP:
507 if (gst_structure_id_get_value (list, tag) != NULL)
510 case GST_TAG_MERGE_REPLACE_ALL:
511 case GST_TAG_MERGE_REPLACE:
512 case GST_TAG_MERGE_PREPEND:
513 gst_structure_id_set_value (list, tag, value);
515 case GST_TAG_MERGE_KEEP_ALL:
518 g_assert_not_reached ();
524 gst_tag_list_copy_foreach (GQuark tag, GValue *value, gpointer user_data)
526 GstTagCopyData *copy = (GstTagCopyData *) user_data;
528 gst_tag_list_add_value_internal (copy->list, copy->mode, tag, value);
533 * gst_tag_list_insert:
534 * @into: list to merge into
535 * @from: list to merge from
536 * @mode: the mode to use
538 * Inserts the tags of the second list into the first list using the given mode.
541 gst_tag_list_insert (GstTagList *into, const GstTagList *from, GstTagMergeMode mode)
545 g_return_if_fail (GST_IS_TAG_LIST (into));
546 g_return_if_fail (GST_IS_TAG_LIST (from));
547 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
549 data.list = (GstStructure *) into;
551 if (mode == GST_TAG_MERGE_REPLACE_ALL) {
552 gst_structure_remove_all_fields (data.list);
554 gst_structure_foreach ((GstStructure *) from, gst_tag_list_copy_foreach, &data);
558 * @list: list to copy
560 * Copies a given #GstTagList.
562 * Returns: copy of the given list
565 gst_tag_list_copy (const GstTagList *list)
567 g_return_val_if_fail (GST_IS_TAG_LIST (list), NULL);
569 return GST_TAG_LIST (gst_structure_copy ((GstStructure *) list));
572 * gst_tag_list_merge:
573 * @list1: first list to merge
574 * @list2: second list to merge
575 * @mode: the mode to use
577 * Merges the two given lists into a new list. If one of the lists is NULL, a
578 * copy of the other is returned. If both lists are NULL, NULL is returned.
580 * Returns: the new list
583 gst_tag_list_merge (const GstTagList *list1, const GstTagList *list2, GstTagMergeMode mode)
585 g_return_val_if_fail (list1 == NULL || GST_IS_TAG_LIST (list1), NULL);
586 g_return_val_if_fail (list2 == NULL || GST_IS_TAG_LIST (list2), NULL);
587 g_return_val_if_fail (GST_TAG_MODE_IS_VALID (mode), NULL);
589 if (!list1 && !list2) {
592 return gst_tag_list_copy (list2);
594 return gst_tag_list_copy (list1);
598 ret = gst_tag_list_copy (list1);
599 gst_tag_list_insert (ret, list2, mode);
605 * @list: the list to free
607 * Frees the given list and all associated values.
610 gst_tag_list_free (GstTagList *list)
612 g_return_if_fail (GST_IS_TAG_LIST (list));
613 gst_structure_free ((GstStructure *) list);
616 * gst_tag_list_get_tag_size:
618 * @tag: the tag to query
620 * Checks how many value are stored in this tag list for the given tag.
622 * Returns: The number of tags stored
625 gst_tag_list_get_tag_size (const GstTagList *list, const gchar *tag)
629 g_return_val_if_fail (GST_IS_TAG_LIST (list), 0);
631 value = gst_structure_get_value ((GstStructure *) list, tag);
634 if (G_VALUE_TYPE (value) != GST_TYPE_LIST)
637 return gst_value_list_get_size (value);
641 * @list: list to set tags in
642 * @mode: the mode to use
644 * @...: NULL-terminated list of values to set
646 * Sets the values for the given tags using the specified mode.
649 gst_tag_list_add (GstTagList *list, GstTagMergeMode mode, const gchar *tag, ...)
653 g_return_if_fail (GST_IS_TAG_LIST (list));
654 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
655 g_return_if_fail (tag != NULL);
657 va_start (args, tag);
658 gst_tag_list_add_valist (list, mode, tag, args);
662 * gst_tag_list_add_values:
663 * @list: list to set tags in
664 * @mode: the mode to use
666 * @...: GValues to set
668 * Sets the GValues for the given tags using the specified mode.
671 gst_tag_list_add_values (GstTagList *list, GstTagMergeMode mode, const gchar *tag, ...)
675 g_return_if_fail (GST_IS_TAG_LIST (list));
676 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
677 g_return_if_fail (tag != NULL);
679 va_start (args, tag);
680 gst_tag_list_add_valist_values (list, mode, tag, args);
684 * gst_tag_list_add_valist:
685 * @list: list to set tags in
686 * @mode: the mode to use
688 * @var_args: tag / value pairs to set
690 * Sets the values for the given tags using the specified mode.
693 gst_tag_list_add_valist (GstTagList *list, GstTagMergeMode mode, const gchar *tag, va_list var_args)
699 g_return_if_fail (GST_IS_TAG_LIST (list));
700 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
701 g_return_if_fail (tag != NULL);
703 while (tag != NULL) {
704 GValue value = { 0, };
705 quark = g_quark_from_string (tag);
706 info = gst_tag_lookup (quark);
708 g_warning ("no GstTag for %s", tag);
709 g_return_if_fail (info != NULL);
710 g_value_init (&value, info->type);
711 G_VALUE_COLLECT (&value, var_args, 0, &error);
713 g_warning ("%s: %s", G_STRLOC, error);
715 /* we purposely leak the value here, it might not be
716 * in a sane state if an error condition occoured
720 gst_tag_list_add_value_internal (list, mode, quark, &value);
721 g_value_unset (&value);
722 tag = va_arg (var_args, gchar *);
726 * gst_tag_list_add_valist_values:
727 * @list: list to set tags in
728 * @mode: the mode to use
730 * @var_args: tag / GValue pairs to set
732 * Sets the GValues for the given tags using the specified mode.
735 gst_tag_list_add_valist_values (GstTagList *list, GstTagMergeMode mode, const gchar *tag, va_list var_args)
740 g_return_if_fail (GST_IS_TAG_LIST (list));
741 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
742 g_return_if_fail (tag != NULL);
744 while (tag != NULL) {
745 quark = g_quark_from_string (tag);
746 info = gst_tag_lookup (quark);
747 g_return_if_fail (info != NULL);
748 gst_tag_list_add_value_internal (list, mode, quark, va_arg (var_args, GValue *));
749 tag = va_arg (var_args, gchar *);
753 * gst_tag_list_remove_tag:
754 * @list: list to remove tag from
755 * @tag: tag to remove
757 * Removes the goven tag from the taglist.
760 gst_tag_list_remove_tag (GstTagList *list, const gchar *tag)
762 g_return_if_fail (GST_IS_TAG_LIST (list));
763 g_return_if_fail (tag != NULL);
765 gst_structure_remove_field ((GstStructure *) list, tag);
768 GstTagForeachFunc func;
769 GstTagList * tag_list;
773 structure_foreach_wrapper (GQuark field_id,
774 GValue *value, gpointer user_data)
776 TagForeachData *data = (TagForeachData *) user_data;
777 data->func (data->tag_list, g_quark_to_string (field_id), data->data);
781 * gst_tag_list_foreach:
782 * @list: list to iterate over
783 * @func: function to be called for each tag
784 * @user_data: user specified data
786 * Calls the given function for each tag inside the tag list. Note that if there
787 * is no tag, the function won't be called at all.
790 gst_tag_list_foreach (GstTagList *list, GstTagForeachFunc func, gpointer user_data)
794 g_return_if_fail (GST_IS_TAG_LIST (list));
795 g_return_if_fail (func != NULL);
798 data.tag_list = list;
799 data.data = user_data;
800 gst_structure_foreach ((GstStructure *) list, structure_foreach_wrapper, &data);
803 /***** tag events *****/
807 * @list: the tag list to put into the event or NULL for an empty list
809 * Creates a new tag event with the given list and takes ownership of it.
811 * Returns: a new tag event
814 gst_event_new_tag (GstTagList *list)
818 g_return_val_if_fail (list == NULL || GST_IS_TAG_LIST (list), NULL);
820 ret = gst_event_new (GST_EVENT_TAG);
822 list = gst_tag_list_new ();
823 ret->event_data.structure.structure = (GstStructure *) list;
828 * get_event_tag_get_list:
829 * @tag_event: a tagging #GstEvent
831 * Gets the taglist from a given tagging event.
833 * Returns: The #GstTagList of the event
836 gst_event_tag_get_list (GstEvent *tag_event)
838 g_return_val_if_fail (GST_IS_EVENT (tag_event), NULL);
839 g_return_val_if_fail (GST_EVENT_TYPE (tag_event) == GST_EVENT_TAG, NULL);
841 return GST_TAG_LIST (tag_event->event_data.structure.structure);
845 * gst_tag_list_get_value_index:
846 * @list: a #GStTagList
847 * @tag: tag to read out
848 * @index: number of entry to read out
850 * Gets the value that is at the given index for the given tag in the given
853 * Returns: The GValue for the specified entry or NULL if the tag wasn't available
854 * or the tag doesn't have as many entries
856 G_CONST_RETURN GValue *
857 gst_tag_list_get_value_index (const GstTagList *list, const gchar *tag, guint index)
861 g_return_val_if_fail (GST_IS_TAG_LIST (list), NULL);
862 g_return_val_if_fail (tag != NULL, NULL);
864 value = gst_structure_get_value ((GstStructure *) list, tag);
865 if (value == NULL) return NULL;
867 if (GST_VALUE_HOLDS_LIST (value)) {
868 if (index >= gst_value_list_get_size (value)) return NULL;
869 return gst_value_list_get_value (value, index);
871 if (index > 0) return NULL;
877 * gst_tag_list_copy_value:
878 * @dest: uninitialized #GValue to copy into
879 * @list: list to get the tag from
880 * @tag: tag to read out
882 * Copies the contents for the given tag into the value, merging multiple values
883 * into one if multiple values are associated with the tag.
884 * You must g_value_unset() the value after use.
886 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
890 gst_tag_list_copy_value (GValue *dest, const GstTagList *list, const gchar *tag)
894 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
895 g_return_val_if_fail (tag != NULL, FALSE);
896 g_return_val_if_fail (dest != NULL, FALSE);
897 g_return_val_if_fail (G_VALUE_TYPE (dest) == 0, FALSE);
899 src = gst_structure_get_value ((GstStructure *) list, tag);
900 if (!src) return FALSE;
902 if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
903 GstTagInfo *info = gst_tag_lookup (g_quark_from_string (tag));
904 /* must be there or lists aren't allowed */
905 g_assert (info->merge_func);
906 info->merge_func (dest, src);
908 g_value_init (dest, G_VALUE_TYPE (src));
909 g_value_copy (src, dest);
914 /***** evil macros to get all the gst_tag_list_get_*() functions right *****/
916 #define TAG_MERGE_FUNCS(name,type) \
918 gst_tag_list_get_ ## name (const GstTagList *list, const gchar *tag, \
923 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE); \
924 g_return_val_if_fail (tag != NULL, FALSE); \
925 g_return_val_if_fail (value != NULL, FALSE); \
927 if (!gst_tag_list_copy_value (&v, list, tag)) \
929 *value = COPY_FUNC (g_value_get_ ## name (&v)); \
930 g_value_unset (&v); \
935 gst_tag_list_get_ ## name ## _index (const GstTagList *list, const gchar *tag, \
936 guint index, type *value) \
940 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE); \
941 g_return_val_if_fail (tag != NULL, FALSE); \
942 g_return_val_if_fail (value != NULL, FALSE); \
944 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL) \
946 *value = COPY_FUNC (g_value_get_ ## name (v)); \
950 #define COPY_FUNC /**/
951 TAG_MERGE_FUNCS (char, gchar)
952 TAG_MERGE_FUNCS (uchar, guchar)
953 TAG_MERGE_FUNCS (boolean, gboolean)
954 TAG_MERGE_FUNCS (int, gint)
955 TAG_MERGE_FUNCS (uint, guint)
956 TAG_MERGE_FUNCS (long, glong)
957 TAG_MERGE_FUNCS (ulong, gulong)
958 TAG_MERGE_FUNCS (int64, gint64)
959 TAG_MERGE_FUNCS (uint64, guint64)
960 TAG_MERGE_FUNCS (float, gfloat)
961 TAG_MERGE_FUNCS (double, gdouble)
964 #define COPY_FUNC g_strdup
965 TAG_MERGE_FUNCS (string, gchar *)