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 */
48 #define TAGLIST "taglist"
49 static GQuark gst_tag_list_quark;
50 static GMutex *__tag_mutex;
51 static GHashTable *__tags;
53 #define TAG_LOCK g_mutex_lock (__tag_mutex)
54 #define TAG_UNLOCK g_mutex_unlock (__tag_mutex)
57 gst_tag_list_get_type (void)
59 static GType _gst_tag_list_type;
61 if (_gst_tag_list_type == 0) {
62 _gst_tag_list_type = g_boxed_type_register_static ("GstTagList",
63 (GBoxedCopyFunc) gst_tag_list_copy, (GBoxedFreeFunc) gst_tag_list_free);
66 g_value_register_transform_func (_gst_tag_list_type, G_TYPE_STRING,
67 _gst_structure_transform_to_string);
71 return _gst_tag_list_type;
75 _gst_tag_initialize (void)
77 gst_tag_list_quark = g_quark_from_static_string (TAGLIST);
78 __tag_mutex = g_mutex_new ();
79 __tags = g_hash_table_new (g_direct_hash, g_direct_equal);
80 gst_tag_register (GST_TAG_TITLE, GST_TAG_FLAG_META,
82 _("title"), _("commonly used title"), gst_tag_merge_strings_with_comma);
83 gst_tag_register (GST_TAG_ARTIST, GST_TAG_FLAG_META,
86 _("person(s) responsible for the recording"),
87 gst_tag_merge_strings_with_comma);
88 gst_tag_register (GST_TAG_ALBUM, GST_TAG_FLAG_META,
91 _("album containing this data"), gst_tag_merge_strings_with_comma);
92 gst_tag_register (GST_TAG_DATE, GST_TAG_FLAG_META, G_TYPE_UINT, /* FIXME: own data type for dates? */
94 _("date the data was created (in Julian calendar days)"), NULL);
95 gst_tag_register (GST_TAG_GENRE, GST_TAG_FLAG_META,
98 _("genre this data belongs to"), gst_tag_merge_strings_with_comma);
99 gst_tag_register (GST_TAG_COMMENT, GST_TAG_FLAG_META,
102 _("free text commenting the data"), gst_tag_merge_strings_with_comma);
103 gst_tag_register (GST_TAG_TRACK_NUMBER, GST_TAG_FLAG_META,
106 _("track number inside a collection"), gst_tag_merge_use_first);
107 gst_tag_register (GST_TAG_TRACK_COUNT, GST_TAG_FLAG_META,
110 _("count of tracks inside collection this track belongs to"),
111 gst_tag_merge_use_first);
112 gst_tag_register (GST_TAG_ALBUM_VOLUME_NUMBER, GST_TAG_FLAG_META,
115 _("disc number inside a collection"), gst_tag_merge_use_first);
116 gst_tag_register (GST_TAG_ALBUM_VOLUME_COUNT, GST_TAG_FLAG_META,
119 _("count of discs inside collection this disc belongs to"),
120 gst_tag_merge_use_first);
121 gst_tag_register (GST_TAG_LOCATION, GST_TAG_FLAG_META,
124 _("original location of file as a URI"),
125 gst_tag_merge_strings_with_comma);
126 gst_tag_register (GST_TAG_DESCRIPTION, GST_TAG_FLAG_META,
129 _("short text describing the content of the data"),
130 gst_tag_merge_strings_with_comma);
131 gst_tag_register (GST_TAG_VERSION, GST_TAG_FLAG_META,
132 G_TYPE_STRING, _("version"), _("version of this data"), NULL);
133 gst_tag_register (GST_TAG_ISRC, GST_TAG_FLAG_META,
137 ("International Standard Recording Code - see http://www.ifpi.org/isrc/"),
139 gst_tag_register (GST_TAG_ORGANIZATION, GST_TAG_FLAG_META, G_TYPE_STRING, _("organization"), _("organization"), /* FIXME */
140 gst_tag_merge_strings_with_comma);
141 gst_tag_register (GST_TAG_COPYRIGHT, GST_TAG_FLAG_META,
142 G_TYPE_STRING, _("copyright"), _("copyright notice of the data"), NULL);
143 gst_tag_register (GST_TAG_CONTACT, GST_TAG_FLAG_META,
145 _("contact"), _("contact information"), gst_tag_merge_strings_with_comma);
146 gst_tag_register (GST_TAG_LICENSE, GST_TAG_FLAG_META,
147 G_TYPE_STRING, _("license"), _("license of data"), NULL);
148 gst_tag_register (GST_TAG_PERFORMER, GST_TAG_FLAG_META,
151 _("person(s) performing"), gst_tag_merge_strings_with_comma);
152 gst_tag_register (GST_TAG_DURATION, GST_TAG_FLAG_DECODED,
154 _("duration"), _("length in GStreamer time units (nanoseconds)"), NULL);
155 gst_tag_register (GST_TAG_CODEC, GST_TAG_FLAG_ENCODED,
158 _("codec the data is stored in"), gst_tag_merge_strings_with_comma);
159 gst_tag_register (GST_TAG_VIDEO_CODEC, GST_TAG_FLAG_ENCODED,
161 _("video codec"), _("codec the video data is stored in"), NULL);
162 gst_tag_register (GST_TAG_AUDIO_CODEC, GST_TAG_FLAG_ENCODED,
164 _("audio codec"), _("codec the audio data is stored in"), NULL);
165 gst_tag_register (GST_TAG_BITRATE, GST_TAG_FLAG_ENCODED,
166 G_TYPE_UINT, _("bitrate"), _("exact or average bitrate in bits/s"), NULL);
167 gst_tag_register (GST_TAG_NOMINAL_BITRATE, GST_TAG_FLAG_ENCODED,
168 G_TYPE_UINT, _("nominal bitrate"), _("nominal bitrate in bits/s"), NULL);
169 gst_tag_register (GST_TAG_MINIMUM_BITRATE, GST_TAG_FLAG_ENCODED,
170 G_TYPE_UINT, _("minimum bitrate"), _("minimum bitrate in bits/s"), NULL);
171 gst_tag_register (GST_TAG_MAXIMUM_BITRATE, GST_TAG_FLAG_ENCODED,
172 G_TYPE_UINT, _("maximum bitrate"), _("maximum bitrate in bits/s"), NULL);
173 gst_tag_register (GST_TAG_ENCODER, GST_TAG_FLAG_ENCODED,
175 _("encoder"), _("encoder used to encode this stream"), NULL);
176 gst_tag_register (GST_TAG_ENCODER_VERSION, GST_TAG_FLAG_ENCODED,
178 _("encoder version"),
179 _("version of the encoder used to encode this stream"), NULL);
180 gst_tag_register (GST_TAG_SERIAL, GST_TAG_FLAG_ENCODED,
181 G_TYPE_UINT, _("serial"), _("serial number of track"), NULL);
182 gst_tag_register (GST_TAG_TRACK_GAIN, GST_TAG_FLAG_META,
183 G_TYPE_DOUBLE, _("replaygain track gain"), _("track gain in db"), NULL);
184 gst_tag_register (GST_TAG_TRACK_PEAK, GST_TAG_FLAG_META,
185 G_TYPE_DOUBLE, _("replaygain track peak"), _("peak of the track"), NULL);
186 gst_tag_register (GST_TAG_ALBUM_GAIN, GST_TAG_FLAG_META,
187 G_TYPE_DOUBLE, _("replaygain album gain"), _("album gain in db"), NULL);
188 gst_tag_register (GST_TAG_ALBUM_PEAK, GST_TAG_FLAG_META,
189 G_TYPE_DOUBLE, _("replaygain album peak"), _("peak of the album"), NULL);
193 * gst_tag_merge_use_first:
194 * @dest: uninitialized GValue to store result in
195 * @src: GValue to copy from
197 * This is a convenience function for the func argument of gst_tag_register().
198 * It creates a copy of the first value from the list.
201 gst_tag_merge_use_first (GValue * dest, const GValue * src)
203 const GValue *ret = gst_value_list_get_value (src, 0);
205 g_value_init (dest, G_VALUE_TYPE (ret));
206 g_value_copy (ret, dest);
210 * gst_tag_merge_strings_with_comma:
211 * @dest: uninitialized GValue to store result in
212 * @src: GValue to copy from
214 * This is a convenience function for the func argument of gst_tag_register().
215 * It concatenates all given strings using a comma. The tag must be registered
216 * as a G_TYPE_STRING or this function will fail.
219 gst_tag_merge_strings_with_comma (GValue * dest, const GValue * src)
224 count = gst_value_list_get_size (src);
225 str = g_string_new (g_value_get_string (gst_value_list_get_value (src, 0)));
226 for (i = 1; i < count; i++) {
227 /* seperator between two string */
228 str = g_string_append (str, _(", "));
230 g_string_append (str, g_value_get_string (gst_value_list_get_value (src,
234 g_value_init (dest, G_TYPE_STRING);
235 g_value_set_string_take_ownership (dest, str->str);
236 g_string_free (str, FALSE);
239 gst_tag_lookup (GQuark entry)
244 ret = g_hash_table_lookup (__tags, GUINT_TO_POINTER (entry));
252 * @name: the name or identifier string
253 * @flag: a flag describing the type of tag info
254 * @type: the type this data is in
255 * @nick: human-readable name
256 * @blurb: a human-readable description about this tag
257 * @func: function for merging multiple values of this tag
259 * Registers a new tag type for the use with GStreamer's type system. If a type
260 * with that name is already registered, that one is used.
261 * The old registration may have used a different type however. So don't rely
262 * on your supplied values.
263 * This function takes ownership of all supplied variables.
266 gst_tag_register (gchar * name, GstTagFlag flag, GType type,
267 gchar * nick, gchar * blurb, GstTagMergeFunc func)
272 g_return_if_fail (name != NULL);
273 g_return_if_fail (nick != NULL);
274 g_return_if_fail (blurb != NULL);
275 g_return_if_fail (type != 0 && type != GST_TYPE_LIST);
277 key = g_quark_from_string (name);
278 info = gst_tag_lookup (key);
279 g_return_if_fail (info == NULL);
281 info = g_new (GstTagInfo, 1);
286 info->merge_func = func;
289 g_hash_table_insert (__tags, GUINT_TO_POINTER (key), info);
295 * @tag: name of the tag
297 * Checks if the given type is already registered.
299 * Returns: TRUE if the type is already registered
302 gst_tag_exists (const gchar * tag)
304 g_return_val_if_fail (tag != NULL, FALSE);
306 return gst_tag_lookup (g_quark_from_string (tag)) != NULL;
313 * Gets the #GType used for this tag.
315 * Returns: the #GType of this tag
318 gst_tag_get_type (const gchar * tag)
322 g_return_val_if_fail (tag != NULL, 0);
323 info = gst_tag_lookup (g_quark_from_string (tag));
324 g_return_val_if_fail (info != NULL, 0);
333 * Returns the human-readable name of this tag, You must not change or free
336 * Returns: the human-readable name of this tag
339 gst_tag_get_nick (const gchar * tag)
343 g_return_val_if_fail (tag != NULL, NULL);
344 info = gst_tag_lookup (g_quark_from_string (tag));
345 g_return_val_if_fail (info != NULL, NULL);
351 * gst_tag_get_description:
354 * Returns the human-readable description of this tag, You must not change or
357 * Return the human-readable description of this tag
360 gst_tag_get_description (const gchar * tag)
364 g_return_val_if_fail (tag != NULL, NULL);
365 info = gst_tag_lookup (g_quark_from_string (tag));
366 g_return_val_if_fail (info != NULL, NULL);
375 * Returns the flag of this tag.
378 gst_tag_get_flag (const gchar * tag)
382 g_return_val_if_fail (tag != NULL, GST_TAG_FLAG_UNDEFINED);
383 info = gst_tag_lookup (g_quark_from_string (tag));
384 g_return_val_if_fail (info != NULL, GST_TAG_FLAG_UNDEFINED);
390 * gst_tag_list_is_fixed:
393 * Checks if the given tag is fixed. A fixed tag can only contain one value.
394 * Unfixed tags can contain lists of values.
396 * Returns: TRUE, if the given tag is fixed.
399 gst_tag_is_fixed (const gchar * tag)
403 g_return_val_if_fail (tag != NULL, FALSE);
404 info = gst_tag_lookup (g_quark_from_string (tag));
405 g_return_val_if_fail (info != NULL, FALSE);
407 return info->merge_func == NULL;
413 * Creates a new empty GstTagList.
415 * Returns: An empty tag list
418 gst_tag_list_new (void)
420 return GST_TAG_LIST (gst_structure_new (TAGLIST, NULL));
425 * @p: Object that might be a taglist
427 * Checks if the given pointer is a taglist.
429 * Returns: TRUE, if the given pointer is a taglist
432 gst_is_tag_list (gconstpointer p)
434 g_return_val_if_fail (p != NULL, FALSE);
436 return ((GstStructure *) p)->name == gst_tag_list_quark;
441 GstTagMergeMode mode;
444 gst_tag_list_add_value_internal (GstStructure * list, GstTagMergeMode mode,
445 GQuark tag, GValue * value)
447 GstTagInfo *info = gst_tag_lookup (tag);
448 const GValue *value2;
450 g_assert (info != NULL);
453 && (value2 = gst_structure_id_get_value (list, tag)) != NULL) {
454 GValue dest = { 0, };
456 case GST_TAG_MERGE_REPLACE_ALL:
457 case GST_TAG_MERGE_REPLACE:
458 gst_structure_id_set_value (list, tag, value);
460 case GST_TAG_MERGE_PREPEND:
461 gst_value_list_concat (&dest, value, value2);
462 gst_structure_id_set_value (list, tag, &dest);
463 g_value_unset (&dest);
465 case GST_TAG_MERGE_APPEND:
466 gst_value_list_concat (&dest, value2, value);
467 gst_structure_id_set_value (list, tag, &dest);
468 g_value_unset (&dest);
470 case GST_TAG_MERGE_KEEP:
471 case GST_TAG_MERGE_KEEP_ALL:
474 g_assert_not_reached ();
479 case GST_TAG_MERGE_APPEND:
480 case GST_TAG_MERGE_KEEP:
481 if (gst_structure_id_get_value (list, tag) != NULL)
484 case GST_TAG_MERGE_REPLACE_ALL:
485 case GST_TAG_MERGE_REPLACE:
486 case GST_TAG_MERGE_PREPEND:
487 gst_structure_id_set_value (list, tag, value);
489 case GST_TAG_MERGE_KEEP_ALL:
492 g_assert_not_reached ();
498 gst_tag_list_copy_foreach (GQuark tag, GValue * value, gpointer user_data)
500 GstTagCopyData *copy = (GstTagCopyData *) user_data;
502 gst_tag_list_add_value_internal (copy->list, copy->mode, tag, value);
508 * gst_tag_list_insert:
509 * @into: list to merge into
510 * @from: list to merge from
511 * @mode: the mode to use
513 * Inserts the tags of the second list into the first list using the given mode.
516 gst_tag_list_insert (GstTagList * into, const GstTagList * from,
517 GstTagMergeMode mode)
521 g_return_if_fail (GST_IS_TAG_LIST (into));
522 g_return_if_fail (GST_IS_TAG_LIST (from));
523 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
525 data.list = (GstStructure *) into;
527 if (mode == GST_TAG_MERGE_REPLACE_ALL) {
528 gst_structure_remove_all_fields (data.list);
530 gst_structure_foreach ((GstStructure *) from, gst_tag_list_copy_foreach,
536 * @list: list to copy
538 * Copies a given #GstTagList.
540 * Returns: copy of the given list
543 gst_tag_list_copy (const GstTagList * list)
545 g_return_val_if_fail (GST_IS_TAG_LIST (list), NULL);
547 return GST_TAG_LIST (gst_structure_copy ((GstStructure *) list));
551 * gst_tag_list_merge:
552 * @list1: first list to merge
553 * @list2: second list to merge
554 * @mode: the mode to use
556 * Merges the two given lists into a new list. If one of the lists is NULL, a
557 * copy of the other is returned. If both lists are NULL, NULL is returned.
559 * Returns: the new list
562 gst_tag_list_merge (const GstTagList * list1, const GstTagList * list2,
563 GstTagMergeMode mode)
565 g_return_val_if_fail (list1 == NULL || GST_IS_TAG_LIST (list1), NULL);
566 g_return_val_if_fail (list2 == NULL || GST_IS_TAG_LIST (list2), NULL);
567 g_return_val_if_fail (GST_TAG_MODE_IS_VALID (mode), NULL);
569 if (!list1 && !list2) {
572 return gst_tag_list_copy (list2);
574 return gst_tag_list_copy (list1);
578 ret = gst_tag_list_copy (list1);
579 gst_tag_list_insert (ret, list2, mode);
586 * @list: the list to free
588 * Frees the given list and all associated values.
591 gst_tag_list_free (GstTagList * list)
593 g_return_if_fail (GST_IS_TAG_LIST (list));
594 gst_structure_free ((GstStructure *) list);
598 * gst_tag_list_get_tag_size:
600 * @tag: the tag to query
602 * Checks how many value are stored in this tag list for the given tag.
604 * Returns: The number of tags stored
607 gst_tag_list_get_tag_size (const GstTagList * list, const gchar * tag)
611 g_return_val_if_fail (GST_IS_TAG_LIST (list), 0);
613 value = gst_structure_get_value ((GstStructure *) list, tag);
616 if (G_VALUE_TYPE (value) != GST_TYPE_LIST)
619 return gst_value_list_get_size (value);
624 * @list: list to set tags in
625 * @mode: the mode to use
627 * @...: NULL-terminated list of values to set
629 * Sets the values for the given tags using the specified mode.
632 gst_tag_list_add (GstTagList * list, GstTagMergeMode mode, const gchar * tag,
637 g_return_if_fail (GST_IS_TAG_LIST (list));
638 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
639 g_return_if_fail (tag != NULL);
641 va_start (args, tag);
642 gst_tag_list_add_valist (list, mode, tag, args);
647 * gst_tag_list_add_values:
648 * @list: list to set tags in
649 * @mode: the mode to use
651 * @...: GValues to set
653 * Sets the GValues for the given tags using the specified mode.
656 gst_tag_list_add_values (GstTagList * list, GstTagMergeMode mode,
657 const gchar * tag, ...)
661 g_return_if_fail (GST_IS_TAG_LIST (list));
662 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
663 g_return_if_fail (tag != NULL);
665 va_start (args, tag);
666 gst_tag_list_add_valist_values (list, mode, tag, args);
671 * gst_tag_list_add_valist:
672 * @list: list to set tags in
673 * @mode: the mode to use
675 * @var_args: tag / value pairs to set
677 * Sets the values for the given tags using the specified mode.
680 gst_tag_list_add_valist (GstTagList * list, GstTagMergeMode mode,
681 const gchar * tag, va_list var_args)
687 g_return_if_fail (GST_IS_TAG_LIST (list));
688 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
689 g_return_if_fail (tag != NULL);
691 while (tag != NULL) {
692 GValue value = { 0, };
693 quark = g_quark_from_string (tag);
694 info = gst_tag_lookup (quark);
696 g_warning ("no GstTag for %s", tag);
697 g_return_if_fail (info != NULL);
698 g_value_init (&value, info->type);
699 G_VALUE_COLLECT (&value, var_args, 0, &error);
701 g_warning ("%s: %s", G_STRLOC, error);
703 /* we purposely leak the value here, it might not be
704 * in a sane state if an error condition occoured
708 gst_tag_list_add_value_internal (list, mode, quark, &value);
709 g_value_unset (&value);
710 tag = va_arg (var_args, gchar *);
715 * gst_tag_list_add_valist_values:
716 * @list: list to set tags in
717 * @mode: the mode to use
719 * @var_args: tag / GValue pairs to set
721 * Sets the GValues for the given tags using the specified mode.
724 gst_tag_list_add_valist_values (GstTagList * list, GstTagMergeMode mode,
725 const gchar * tag, va_list var_args)
730 g_return_if_fail (GST_IS_TAG_LIST (list));
731 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
732 g_return_if_fail (tag != NULL);
734 while (tag != NULL) {
735 quark = g_quark_from_string (tag);
736 info = gst_tag_lookup (quark);
737 g_return_if_fail (info != NULL);
738 gst_tag_list_add_value_internal (list, mode, quark, va_arg (var_args,
740 tag = va_arg (var_args, gchar *);
745 * gst_tag_list_remove_tag:
746 * @list: list to remove tag from
747 * @tag: tag to remove
749 * Removes the goven tag from the taglist.
752 gst_tag_list_remove_tag (GstTagList * list, const gchar * tag)
754 g_return_if_fail (GST_IS_TAG_LIST (list));
755 g_return_if_fail (tag != NULL);
757 gst_structure_remove_field ((GstStructure *) list, tag);
761 GstTagForeachFunc func;
762 GstTagList *tag_list;
766 structure_foreach_wrapper (GQuark field_id, GValue * value, gpointer user_data)
768 TagForeachData *data = (TagForeachData *) user_data;
770 data->func (data->tag_list, g_quark_to_string (field_id), data->data);
775 * gst_tag_list_foreach:
776 * @list: list to iterate over
777 * @func: function to be called for each tag
778 * @user_data: user specified data
780 * Calls the given function for each tag inside the tag list. Note that if there
781 * is no tag, the function won't be called at all.
784 gst_tag_list_foreach (GstTagList * list, GstTagForeachFunc func,
789 g_return_if_fail (GST_IS_TAG_LIST (list));
790 g_return_if_fail (func != NULL);
793 data.tag_list = list;
794 data.data = user_data;
795 gst_structure_foreach ((GstStructure *) list, structure_foreach_wrapper,
799 /***** tag events *****/
803 * @list: the tag list to put into the event or NULL for an empty list
805 * Creates a new tag event with the given list and takes ownership of it.
807 * Returns: a new tag event
810 gst_event_new_tag (GstTagList * list)
814 g_return_val_if_fail (list == NULL || GST_IS_TAG_LIST (list), NULL);
816 ret = gst_event_new (GST_EVENT_TAG);
818 list = gst_tag_list_new ();
819 ret->event_data.structure.structure = (GstStructure *) list;
825 * get_event_tag_get_list:
826 * @tag_event: a tagging #GstEvent
828 * Gets the taglist from a given tagging event.
830 * Returns: The #GstTagList of the event
833 gst_event_tag_get_list (GstEvent * tag_event)
835 g_return_val_if_fail (GST_IS_EVENT (tag_event), NULL);
836 g_return_val_if_fail (GST_EVENT_TYPE (tag_event) == GST_EVENT_TAG, NULL);
838 return GST_TAG_LIST (tag_event->event_data.structure.structure);
842 * gst_tag_list_get_value_index:
843 * @list: a #GStTagList
844 * @tag: tag to read out
845 * @index: number of entry to read out
847 * Gets the value that is at the given index for the given tag in the given
850 * Returns: The GValue for the specified entry or NULL if the tag wasn't available
851 * or the tag doesn't have as many entries
853 G_CONST_RETURN GValue *
854 gst_tag_list_get_value_index (const GstTagList * list, const gchar * tag,
859 g_return_val_if_fail (GST_IS_TAG_LIST (list), NULL);
860 g_return_val_if_fail (tag != NULL, NULL);
862 value = gst_structure_get_value ((GstStructure *) list, tag);
866 if (GST_VALUE_HOLDS_LIST (value)) {
867 if (index >= gst_value_list_get_size (value))
869 return gst_value_list_get_value (value, index);
878 * gst_tag_list_copy_value:
879 * @dest: uninitialized #GValue to copy into
880 * @list: list to get the tag from
881 * @tag: tag to read out
883 * Copies the contents for the given tag into the value, merging multiple values
884 * into one if multiple values are associated with the tag.
885 * You must g_value_unset() the value after use.
887 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
891 gst_tag_list_copy_value (GValue * dest, const GstTagList * list,
896 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
897 g_return_val_if_fail (tag != NULL, FALSE);
898 g_return_val_if_fail (dest != NULL, FALSE);
899 g_return_val_if_fail (G_VALUE_TYPE (dest) == 0, FALSE);
901 src = gst_structure_get_value ((GstStructure *) list, tag);
905 if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
906 GstTagInfo *info = gst_tag_lookup (g_quark_from_string (tag));
908 /* must be there or lists aren't allowed */
909 g_assert (info->merge_func);
910 info->merge_func (dest, src);
912 g_value_init (dest, G_VALUE_TYPE (src));
913 g_value_copy (src, dest);
918 /***** evil macros to get all the gst_tag_list_get_*() functions right *****/
920 #define TAG_MERGE_FUNCS(name,type) \
922 gst_tag_list_get_ ## name (const GstTagList *list, const gchar *tag, \
927 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE); \
928 g_return_val_if_fail (tag != NULL, FALSE); \
929 g_return_val_if_fail (value != NULL, FALSE); \
931 if (!gst_tag_list_copy_value (&v, list, tag)) \
933 *value = COPY_FUNC (g_value_get_ ## name (&v)); \
934 g_value_unset (&v); \
939 gst_tag_list_get_ ## name ## _index (const GstTagList *list, const gchar *tag, \
940 guint index, type *value) \
944 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE); \
945 g_return_val_if_fail (tag != NULL, FALSE); \
946 g_return_val_if_fail (value != NULL, FALSE); \
948 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL) \
950 *value = COPY_FUNC (g_value_get_ ## name (v)); \
954 #define COPY_FUNC /**/
955 TAG_MERGE_FUNCS (char, gchar)
956 TAG_MERGE_FUNCS (uchar, guchar)
957 TAG_MERGE_FUNCS (boolean, gboolean)
958 TAG_MERGE_FUNCS (int, gint)
959 TAG_MERGE_FUNCS (uint, guint)
960 TAG_MERGE_FUNCS (long, glong)
961 TAG_MERGE_FUNCS (ulong, gulong)
962 TAG_MERGE_FUNCS (int64, gint64)
963 TAG_MERGE_FUNCS (uint64, guint64)
964 TAG_MERGE_FUNCS (float, gfloat)
965 TAG_MERGE_FUNCS (double, gdouble)
967 #define COPY_FUNC g_strdup
968 TAG_MERGE_FUNCS (string, gchar *)