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)
39 GType type; /* type the data is in */
41 gchar *nick; /* translated name */
42 gchar *blurb; /* translated description of type */
44 GstTagMergeFunc merge_func; /* functions to merge the values */
45 GstTagFlag flag; /* type of tag */
49 #define TAGLIST "taglist"
50 static GQuark gst_tag_list_quark;
51 static GMutex *__tag_mutex;
52 static GHashTable *__tags;
54 #define TAG_LOCK g_mutex_lock (__tag_mutex)
55 #define TAG_UNLOCK g_mutex_unlock (__tag_mutex)
58 gst_tag_list_get_type (void)
60 static GType _gst_tag_list_type;
62 if (_gst_tag_list_type == 0) {
63 _gst_tag_list_type = g_boxed_type_register_static ("GstTagList",
64 (GBoxedCopyFunc) gst_tag_list_copy, (GBoxedFreeFunc) gst_tag_list_free);
67 g_value_register_transform_func (_gst_tag_list_type, G_TYPE_STRING,
68 _gst_structure_transform_to_string);
72 return _gst_tag_list_type;
76 _gst_tag_initialize (void)
78 gst_tag_list_quark = g_quark_from_static_string (TAGLIST);
79 __tag_mutex = g_mutex_new ();
80 __tags = g_hash_table_new (g_direct_hash, g_direct_equal);
81 gst_tag_register (GST_TAG_TITLE, GST_TAG_FLAG_META,
83 _("title"), _("commonly used title"), 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"), gst_tag_merge_strings_with_comma);
93 gst_tag_register (GST_TAG_DATE, GST_TAG_FLAG_META, G_TYPE_UINT, /* FIXME: own data type for dates? */
95 _("date the data was created (in Julian calendar days)"), NULL);
96 gst_tag_register (GST_TAG_GENRE, GST_TAG_FLAG_META,
99 _("genre this data belongs to"), gst_tag_merge_strings_with_comma);
100 gst_tag_register (GST_TAG_COMMENT, GST_TAG_FLAG_META,
103 _("free text commenting the data"), gst_tag_merge_strings_with_comma);
104 gst_tag_register (GST_TAG_TRACK_NUMBER, GST_TAG_FLAG_META,
107 _("track number inside a collection"), gst_tag_merge_use_first);
108 gst_tag_register (GST_TAG_TRACK_COUNT, GST_TAG_FLAG_META,
111 _("count of tracks inside collection this track belongs to"),
112 gst_tag_merge_use_first);
113 gst_tag_register (GST_TAG_ALBUM_VOLUME_NUMBER, GST_TAG_FLAG_META,
116 _("disc number inside a collection"), gst_tag_merge_use_first);
117 gst_tag_register (GST_TAG_ALBUM_VOLUME_COUNT, GST_TAG_FLAG_META,
120 _("count of discs inside collection this disc belongs to"),
121 gst_tag_merge_use_first);
122 gst_tag_register (GST_TAG_LOCATION, GST_TAG_FLAG_META,
125 _("original location of file as a URI"),
126 gst_tag_merge_strings_with_comma);
127 gst_tag_register (GST_TAG_DESCRIPTION, GST_TAG_FLAG_META,
130 _("short text describing the content of the data"),
131 gst_tag_merge_strings_with_comma);
132 gst_tag_register (GST_TAG_VERSION, GST_TAG_FLAG_META,
133 G_TYPE_STRING, _("version"), _("version of this data"), NULL);
134 gst_tag_register (GST_TAG_ISRC, GST_TAG_FLAG_META,
138 ("International Standard Recording Code - see http://www.ifpi.org/isrc/"),
140 gst_tag_register (GST_TAG_ORGANIZATION, GST_TAG_FLAG_META, G_TYPE_STRING, _("organization"), _("organization"), /* FIXME */
141 gst_tag_merge_strings_with_comma);
142 gst_tag_register (GST_TAG_COPYRIGHT, GST_TAG_FLAG_META,
143 G_TYPE_STRING, _("copyright"), _("copyright notice of the data"), NULL);
144 gst_tag_register (GST_TAG_CONTACT, GST_TAG_FLAG_META,
146 _("contact"), _("contact information"), gst_tag_merge_strings_with_comma);
147 gst_tag_register (GST_TAG_LICENSE, GST_TAG_FLAG_META,
148 G_TYPE_STRING, _("license"), _("license of data"), NULL);
149 gst_tag_register (GST_TAG_PERFORMER, GST_TAG_FLAG_META,
152 _("person(s) performing"), gst_tag_merge_strings_with_comma);
153 gst_tag_register (GST_TAG_DURATION, GST_TAG_FLAG_DECODED,
155 _("duration"), _("length in GStreamer time units (nanoseconds)"), NULL);
156 gst_tag_register (GST_TAG_CODEC, GST_TAG_FLAG_ENCODED,
159 _("codec the data is stored in"), gst_tag_merge_strings_with_comma);
160 gst_tag_register (GST_TAG_VIDEO_CODEC, GST_TAG_FLAG_ENCODED,
162 _("video codec"), _("codec the video data is stored in"), NULL);
163 gst_tag_register (GST_TAG_AUDIO_CODEC, GST_TAG_FLAG_ENCODED,
165 _("audio codec"), _("codec the audio data is stored in"), NULL);
166 gst_tag_register (GST_TAG_BITRATE, GST_TAG_FLAG_ENCODED,
167 G_TYPE_UINT, _("bitrate"), _("exact or average bitrate in bits/s"), NULL);
168 gst_tag_register (GST_TAG_NOMINAL_BITRATE, GST_TAG_FLAG_ENCODED,
169 G_TYPE_UINT, _("nominal bitrate"), _("nominal bitrate in bits/s"), NULL);
170 gst_tag_register (GST_TAG_MINIMUM_BITRATE, GST_TAG_FLAG_ENCODED,
171 G_TYPE_UINT, _("minimum bitrate"), _("minimum bitrate in bits/s"), NULL);
172 gst_tag_register (GST_TAG_MAXIMUM_BITRATE, GST_TAG_FLAG_ENCODED,
173 G_TYPE_UINT, _("maximum bitrate"), _("maximum bitrate in bits/s"), NULL);
174 gst_tag_register (GST_TAG_ENCODER, GST_TAG_FLAG_ENCODED,
176 _("encoder"), _("encoder used to encode this stream"), NULL);
177 gst_tag_register (GST_TAG_ENCODER_VERSION, GST_TAG_FLAG_ENCODED,
179 _("encoder version"),
180 _("version of the encoder used to encode this stream"), NULL);
181 gst_tag_register (GST_TAG_SERIAL, GST_TAG_FLAG_ENCODED,
182 G_TYPE_UINT, _("serial"), _("serial number of track"), NULL);
183 gst_tag_register (GST_TAG_TRACK_GAIN, GST_TAG_FLAG_META,
184 G_TYPE_DOUBLE, _("replaygain track gain"), _("track gain in db"), NULL);
185 gst_tag_register (GST_TAG_TRACK_PEAK, GST_TAG_FLAG_META,
186 G_TYPE_DOUBLE, _("replaygain track peak"), _("peak of the track"), NULL);
187 gst_tag_register (GST_TAG_ALBUM_GAIN, GST_TAG_FLAG_META,
188 G_TYPE_DOUBLE, _("replaygain album gain"), _("album gain in db"), NULL);
189 gst_tag_register (GST_TAG_ALBUM_PEAK, GST_TAG_FLAG_META,
190 G_TYPE_DOUBLE, _("replaygain album peak"), _("peak of the album"), NULL);
194 * gst_tag_merge_use_first:
195 * @dest: uninitialized GValue to store result in
196 * @src: GValue to copy from
198 * This is a convenience function for the func argument of gst_tag_register().
199 * It creates a copy of the first value from the list.
202 gst_tag_merge_use_first (GValue * dest, const GValue * src)
204 const GValue *ret = gst_value_list_get_value (src, 0);
206 g_value_init (dest, G_VALUE_TYPE (ret));
207 g_value_copy (ret, dest);
211 * gst_tag_merge_strings_with_comma:
212 * @dest: uninitialized GValue to store result in
213 * @src: GValue to copy from
215 * This is a convenience function for the func argument of gst_tag_register().
216 * It concatenates all given strings using a comma. The tag must be registered
217 * as a G_TYPE_STRING or this function will fail.
220 gst_tag_merge_strings_with_comma (GValue * dest, const GValue * src)
225 count = gst_value_list_get_size (src);
226 str = g_string_new (g_value_get_string (gst_value_list_get_value (src, 0)));
227 for (i = 1; i < count; i++) {
228 /* seperator between two string */
229 str = g_string_append (str, _(", "));
231 g_string_append (str, g_value_get_string (gst_value_list_get_value (src,
235 g_value_init (dest, G_TYPE_STRING);
236 g_value_set_string_take_ownership (dest, str->str);
237 g_string_free (str, FALSE);
240 gst_tag_lookup (GQuark entry)
245 ret = g_hash_table_lookup (__tags, GUINT_TO_POINTER (entry));
253 * @name: the name or identifier string
254 * @flag: a flag describing the type of tag info
255 * @type: the type this data is in
256 * @nick: human-readable name
257 * @blurb: a human-readable description about this tag
258 * @func: function for merging multiple values of this tag
260 * Registers a new tag type for the use with GStreamer's type system. If a type
261 * with that name is already registered, that one is used.
262 * The old registration may have used a different type however. So don't rely
263 * on your supplied values.
264 * This function takes ownership of all supplied variables.
267 gst_tag_register (gchar * name, GstTagFlag flag, GType type,
268 gchar * nick, gchar * blurb, GstTagMergeFunc func)
273 g_return_if_fail (name != NULL);
274 g_return_if_fail (nick != NULL);
275 g_return_if_fail (blurb != NULL);
276 g_return_if_fail (type != 0 && type != GST_TYPE_LIST);
278 key = g_quark_from_string (name);
279 info = gst_tag_lookup (key);
280 g_return_if_fail (info == NULL);
282 info = g_new (GstTagInfo, 1);
287 info->merge_func = func;
290 g_hash_table_insert (__tags, GUINT_TO_POINTER (key), info);
296 * @tag: name of the tag
298 * Checks if the given type is already registered.
300 * Returns: TRUE if the type is already registered
303 gst_tag_exists (const gchar * tag)
305 g_return_val_if_fail (tag != NULL, FALSE);
307 return gst_tag_lookup (g_quark_from_string (tag)) != NULL;
314 * Gets the #GType used for this tag.
316 * Returns: the #GType of this tag
319 gst_tag_get_type (const gchar * tag)
323 g_return_val_if_fail (tag != NULL, 0);
324 info = gst_tag_lookup (g_quark_from_string (tag));
325 g_return_val_if_fail (info != NULL, 0);
334 * Returns the human-readable name of this tag, You must not change or free
337 * Returns: the human-readable name of this tag
340 gst_tag_get_nick (const gchar * tag)
344 g_return_val_if_fail (tag != NULL, NULL);
345 info = gst_tag_lookup (g_quark_from_string (tag));
346 g_return_val_if_fail (info != NULL, NULL);
352 * gst_tag_get_description:
355 * Returns the human-readable description of this tag, You must not change or
358 * Return the human-readable description of this tag
361 gst_tag_get_description (const gchar * tag)
365 g_return_val_if_fail (tag != NULL, NULL);
366 info = gst_tag_lookup (g_quark_from_string (tag));
367 g_return_val_if_fail (info != NULL, NULL);
376 * Returns the flag of this tag.
379 gst_tag_get_flag (const gchar * tag)
383 g_return_val_if_fail (tag != NULL, GST_TAG_FLAG_UNDEFINED);
384 info = gst_tag_lookup (g_quark_from_string (tag));
385 g_return_val_if_fail (info != NULL, GST_TAG_FLAG_UNDEFINED);
391 * gst_tag_list_is_fixed:
394 * Checks if the given tag is fixed. A fixed tag can only contain one value.
395 * Unfixed tags can contain lists of values.
397 * Returns: TRUE, if the given tag is fixed.
400 gst_tag_is_fixed (const gchar * tag)
404 g_return_val_if_fail (tag != NULL, FALSE);
405 info = gst_tag_lookup (g_quark_from_string (tag));
406 g_return_val_if_fail (info != NULL, FALSE);
408 return info->merge_func == NULL;
414 * Creates a new empty GstTagList.
416 * Returns: An empty tag list
419 gst_tag_list_new (void)
421 return GST_TAG_LIST (gst_structure_new (TAGLIST, NULL));
426 * @p: Object that might be a taglist
428 * Checks if the given pointer is a taglist.
430 * Returns: TRUE, if the given pointer is a taglist
433 gst_is_tag_list (gconstpointer p)
435 g_return_val_if_fail (p != NULL, FALSE);
437 return ((GstStructure *) p)->name == gst_tag_list_quark;
442 GstTagMergeMode mode;
446 gst_tag_list_add_value_internal (GstStructure * list, GstTagMergeMode mode,
447 GQuark tag, GValue * value)
449 GstTagInfo *info = gst_tag_lookup (tag);
450 const GValue *value2;
452 g_assert (info != NULL);
455 && (value2 = gst_structure_id_get_value (list, tag)) != NULL) {
456 GValue dest = { 0, };
459 case GST_TAG_MERGE_REPLACE_ALL:
460 case GST_TAG_MERGE_REPLACE:
461 gst_structure_id_set_value (list, tag, value);
463 case GST_TAG_MERGE_PREPEND:
464 gst_value_list_concat (&dest, value, value2);
465 gst_structure_id_set_value (list, tag, &dest);
466 g_value_unset (&dest);
468 case GST_TAG_MERGE_APPEND:
469 gst_value_list_concat (&dest, value2, value);
470 gst_structure_id_set_value (list, tag, &dest);
471 g_value_unset (&dest);
473 case GST_TAG_MERGE_KEEP:
474 case GST_TAG_MERGE_KEEP_ALL:
477 g_assert_not_reached ();
482 case GST_TAG_MERGE_APPEND:
483 case GST_TAG_MERGE_KEEP:
484 if (gst_structure_id_get_value (list, tag) != NULL)
487 case GST_TAG_MERGE_REPLACE_ALL:
488 case GST_TAG_MERGE_REPLACE:
489 case GST_TAG_MERGE_PREPEND:
490 gst_structure_id_set_value (list, tag, value);
492 case GST_TAG_MERGE_KEEP_ALL:
495 g_assert_not_reached ();
501 gst_tag_list_copy_foreach (GQuark tag, GValue * value, gpointer user_data)
503 GstTagCopyData *copy = (GstTagCopyData *) user_data;
505 gst_tag_list_add_value_internal (copy->list, copy->mode, tag, value);
511 * gst_tag_list_insert:
512 * @into: list to merge into
513 * @from: list to merge from
514 * @mode: the mode to use
516 * Inserts the tags of the second list into the first list using the given mode.
519 gst_tag_list_insert (GstTagList * into, const GstTagList * from,
520 GstTagMergeMode mode)
524 g_return_if_fail (GST_IS_TAG_LIST (into));
525 g_return_if_fail (GST_IS_TAG_LIST (from));
526 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
528 data.list = (GstStructure *) into;
530 if (mode == GST_TAG_MERGE_REPLACE_ALL) {
531 gst_structure_remove_all_fields (data.list);
533 gst_structure_foreach ((GstStructure *) from, gst_tag_list_copy_foreach,
539 * @list: list to copy
541 * Copies a given #GstTagList.
543 * Returns: copy of the given list
546 gst_tag_list_copy (const GstTagList * list)
548 g_return_val_if_fail (GST_IS_TAG_LIST (list), NULL);
550 return GST_TAG_LIST (gst_structure_copy ((GstStructure *) list));
554 * gst_tag_list_merge:
555 * @list1: first list to merge
556 * @list2: second list to merge
557 * @mode: the mode to use
559 * Merges the two given lists into a new list. If one of the lists is NULL, a
560 * copy of the other is returned. If both lists are NULL, NULL is returned.
562 * Returns: the new list
565 gst_tag_list_merge (const GstTagList * list1, const GstTagList * list2,
566 GstTagMergeMode mode)
568 g_return_val_if_fail (list1 == NULL || GST_IS_TAG_LIST (list1), NULL);
569 g_return_val_if_fail (list2 == NULL || GST_IS_TAG_LIST (list2), NULL);
570 g_return_val_if_fail (GST_TAG_MODE_IS_VALID (mode), NULL);
572 if (!list1 && !list2) {
575 return gst_tag_list_copy (list2);
577 return gst_tag_list_copy (list1);
581 ret = gst_tag_list_copy (list1);
582 gst_tag_list_insert (ret, list2, mode);
589 * @list: the list to free
591 * Frees the given list and all associated values.
594 gst_tag_list_free (GstTagList * list)
596 g_return_if_fail (GST_IS_TAG_LIST (list));
597 gst_structure_free ((GstStructure *) list);
601 * gst_tag_list_get_tag_size:
603 * @tag: the tag to query
605 * Checks how many value are stored in this tag list for the given tag.
607 * Returns: The number of tags stored
610 gst_tag_list_get_tag_size (const GstTagList * list, const gchar * tag)
614 g_return_val_if_fail (GST_IS_TAG_LIST (list), 0);
616 value = gst_structure_get_value ((GstStructure *) list, tag);
619 if (G_VALUE_TYPE (value) != GST_TYPE_LIST)
622 return gst_value_list_get_size (value);
627 * @list: list to set tags in
628 * @mode: the mode to use
630 * @...: NULL-terminated list of values to set
632 * Sets the values for the given tags using the specified mode.
635 gst_tag_list_add (GstTagList * list, GstTagMergeMode mode, const gchar * tag,
640 g_return_if_fail (GST_IS_TAG_LIST (list));
641 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
642 g_return_if_fail (tag != NULL);
644 va_start (args, tag);
645 gst_tag_list_add_valist (list, mode, tag, args);
650 * gst_tag_list_add_values:
651 * @list: list to set tags in
652 * @mode: the mode to use
654 * @...: GValues to set
656 * Sets the GValues for the given tags using the specified mode.
659 gst_tag_list_add_values (GstTagList * list, GstTagMergeMode mode,
660 const gchar * tag, ...)
664 g_return_if_fail (GST_IS_TAG_LIST (list));
665 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
666 g_return_if_fail (tag != NULL);
668 va_start (args, tag);
669 gst_tag_list_add_valist_values (list, mode, tag, args);
674 * gst_tag_list_add_valist:
675 * @list: list to set tags in
676 * @mode: the mode to use
678 * @var_args: tag / value pairs to set
680 * Sets the values for the given tags using the specified mode.
683 gst_tag_list_add_valist (GstTagList * list, GstTagMergeMode mode,
684 const gchar * tag, va_list var_args)
690 g_return_if_fail (GST_IS_TAG_LIST (list));
691 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
692 g_return_if_fail (tag != NULL);
694 while (tag != NULL) {
695 GValue value = { 0, };
697 quark = g_quark_from_string (tag);
698 info = gst_tag_lookup (quark);
700 g_warning ("no GstTag for %s", tag);
701 g_return_if_fail (info != NULL);
702 g_value_init (&value, info->type);
703 G_VALUE_COLLECT (&value, var_args, 0, &error);
705 g_warning ("%s: %s", G_STRLOC, error);
707 /* we purposely leak the value here, it might not be
708 * in a sane state if an error condition occoured
712 gst_tag_list_add_value_internal (list, mode, quark, &value);
713 g_value_unset (&value);
714 tag = va_arg (var_args, gchar *);
719 * gst_tag_list_add_valist_values:
720 * @list: list to set tags in
721 * @mode: the mode to use
723 * @var_args: tag / GValue pairs to set
725 * Sets the GValues for the given tags using the specified mode.
728 gst_tag_list_add_valist_values (GstTagList * list, GstTagMergeMode mode,
729 const gchar * tag, va_list var_args)
734 g_return_if_fail (GST_IS_TAG_LIST (list));
735 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
736 g_return_if_fail (tag != NULL);
738 while (tag != NULL) {
739 quark = g_quark_from_string (tag);
740 info = gst_tag_lookup (quark);
741 g_return_if_fail (info != NULL);
742 gst_tag_list_add_value_internal (list, mode, quark, va_arg (var_args,
744 tag = va_arg (var_args, gchar *);
749 * gst_tag_list_remove_tag:
750 * @list: list to remove tag from
751 * @tag: tag to remove
753 * Removes the goven tag from the taglist.
756 gst_tag_list_remove_tag (GstTagList * list, const gchar * tag)
758 g_return_if_fail (GST_IS_TAG_LIST (list));
759 g_return_if_fail (tag != NULL);
761 gst_structure_remove_field ((GstStructure *) list, tag);
765 GstTagForeachFunc func;
766 GstTagList *tag_list;
771 structure_foreach_wrapper (GQuark field_id, GValue * value, gpointer user_data)
773 TagForeachData *data = (TagForeachData *) user_data;
775 data->func (data->tag_list, g_quark_to_string (field_id), data->data);
780 * gst_tag_list_foreach:
781 * @list: list to iterate over
782 * @func: function to be called for each tag
783 * @user_data: user specified data
785 * Calls the given function for each tag inside the tag list. Note that if there
786 * is no tag, the function won't be called at all.
789 gst_tag_list_foreach (GstTagList * list, GstTagForeachFunc func,
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,
804 /***** tag events *****/
808 * @list: the tag list to put into the event or NULL for an empty list
810 * Creates a new tag event with the given list and takes ownership of it.
812 * Returns: a new tag event
815 gst_event_new_tag (GstTagList * list)
819 g_return_val_if_fail (list == NULL || GST_IS_TAG_LIST (list), NULL);
821 ret = gst_event_new (GST_EVENT_TAG);
823 list = gst_tag_list_new ();
824 ret->event_data.structure.structure = (GstStructure *) list;
830 * get_event_tag_get_list:
831 * @tag_event: a tagging #GstEvent
833 * Gets the taglist from a given tagging event.
835 * Returns: The #GstTagList of the event
838 gst_event_tag_get_list (GstEvent * tag_event)
840 g_return_val_if_fail (GST_IS_EVENT (tag_event), NULL);
841 g_return_val_if_fail (GST_EVENT_TYPE (tag_event) == GST_EVENT_TAG, NULL);
843 return GST_TAG_LIST (tag_event->event_data.structure.structure);
847 * gst_tag_list_get_value_index:
848 * @list: a #GStTagList
849 * @tag: tag to read out
850 * @index: number of entry to read out
852 * Gets the value that is at the given index for the given tag in the given
855 * Returns: The GValue for the specified entry or NULL if the tag wasn't available
856 * or the tag doesn't have as many entries
858 G_CONST_RETURN GValue *
859 gst_tag_list_get_value_index (const GstTagList * list, const gchar * tag,
864 g_return_val_if_fail (GST_IS_TAG_LIST (list), NULL);
865 g_return_val_if_fail (tag != NULL, NULL);
867 value = gst_structure_get_value ((GstStructure *) list, tag);
871 if (GST_VALUE_HOLDS_LIST (value)) {
872 if (index >= gst_value_list_get_size (value))
874 return gst_value_list_get_value (value, index);
883 * gst_tag_list_copy_value:
884 * @dest: uninitialized #GValue to copy into
885 * @list: list to get the tag from
886 * @tag: tag to read out
888 * Copies the contents for the given tag into the value, merging multiple values
889 * into one if multiple values are associated with the tag.
890 * You must g_value_unset() the value after use.
892 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
896 gst_tag_list_copy_value (GValue * dest, const GstTagList * list,
901 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
902 g_return_val_if_fail (tag != NULL, FALSE);
903 g_return_val_if_fail (dest != NULL, FALSE);
904 g_return_val_if_fail (G_VALUE_TYPE (dest) == 0, FALSE);
906 src = gst_structure_get_value ((GstStructure *) list, tag);
910 if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
911 GstTagInfo *info = gst_tag_lookup (g_quark_from_string (tag));
913 /* must be there or lists aren't allowed */
914 g_assert (info->merge_func);
915 info->merge_func (dest, src);
917 g_value_init (dest, G_VALUE_TYPE (src));
918 g_value_copy (src, dest);
923 /***** evil macros to get all the gst_tag_list_get_*() functions right *****/
925 #define TAG_MERGE_FUNCS(name,type) \
927 gst_tag_list_get_ ## name (const GstTagList *list, const gchar *tag, \
932 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE); \
933 g_return_val_if_fail (tag != NULL, FALSE); \
934 g_return_val_if_fail (value != NULL, FALSE); \
936 if (!gst_tag_list_copy_value (&v, list, tag)) \
938 *value = COPY_FUNC (g_value_get_ ## name (&v)); \
939 g_value_unset (&v); \
944 gst_tag_list_get_ ## name ## _index (const GstTagList *list, const gchar *tag, \
945 guint index, type *value) \
949 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE); \
950 g_return_val_if_fail (tag != NULL, FALSE); \
951 g_return_val_if_fail (value != NULL, FALSE); \
953 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL) \
955 *value = COPY_FUNC (g_value_get_ ## name (v)); \
959 #define COPY_FUNC /**/
960 TAG_MERGE_FUNCS (char, gchar)
961 TAG_MERGE_FUNCS (uchar, guchar)
962 TAG_MERGE_FUNCS (boolean, gboolean)
963 TAG_MERGE_FUNCS (int, gint)
964 TAG_MERGE_FUNCS (uint, guint)
965 TAG_MERGE_FUNCS (long, glong)
966 TAG_MERGE_FUNCS (ulong, gulong)
967 TAG_MERGE_FUNCS (int64, gint64)
968 TAG_MERGE_FUNCS (uint64, guint64)
969 TAG_MERGE_FUNCS (float, gfloat)
970 TAG_MERGE_FUNCS (double, gdouble)
972 #define COPY_FUNC g_strdup
973 TAG_MERGE_FUNCS (string, gchar *)