taglist: add to_string and new_from_string functions
[platform/upstream/gstreamer.git] / gst / gsttaglist.c
1 /* GStreamer
2  * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
3  *
4  * gsttaglist.c: tag support (aka metadata)
5  *
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.
10  *
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.
15  *
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.
20  */
21
22 /**
23  * SECTION:gsttaglist
24  * @short_description: List of tags and values used to describe media metadata
25  *
26  * List of tags and values used to describe media metadata.
27  *
28  * Strings must be in ASCII or UTF-8 encoding. No other encodings are allowed.
29  *
30  * Last reviewed on 2009-06-09 (0.10.23)
31  */
32
33 #ifdef HAVE_CONFIG_H
34 #  include "config.h"
35 #endif
36
37 #include "gst_private.h"
38 #include "math-compat.h"
39 #include "gst-i18n-lib.h"
40 #include "gsttaglist.h"
41 #include "gstinfo.h"
42 #include "gstvalue.h"
43 #include "gstbuffer.h"
44 #include "gstquark.h"
45
46 #include <gobject/gvaluecollector.h>
47 #include <string.h>
48
49 #define GST_TAG_IS_VALID(tag)           (gst_tag_get_info (tag) != NULL)
50
51 /* FIXME 0.11: use GParamSpecs or something similar for tag registrations,
52  * possibly even gst_tag_register(). Especially value ranges might be
53  * useful for some tags. */
54
55 typedef struct
56 {
57   GType type;                   /* type the data is in */
58
59   gchar *nick;                  /* translated name */
60   gchar *blurb;                 /* translated description of type */
61
62   GstTagMergeFunc merge_func;   /* functions to merge the values */
63   GstTagFlag flag;              /* type of tag */
64   GQuark name_quark;            /* quark for the name */
65 }
66 GstTagInfo;
67
68 static GMutex *__tag_mutex;
69
70 /* tags hash table: maps tag name string => GstTagInfo */
71 static GHashTable *__tags;
72
73 #define TAG_LOCK g_mutex_lock (__tag_mutex)
74 #define TAG_UNLOCK g_mutex_unlock (__tag_mutex)
75
76 GType
77 gst_tag_list_get_type (void)
78 {
79   static GType _gst_tag_list_type = 0;
80
81   if (G_UNLIKELY (_gst_tag_list_type == 0)) {
82     _gst_tag_list_type = g_boxed_type_register_static ("GstTagList",
83         (GBoxedCopyFunc) gst_tag_list_copy, (GBoxedFreeFunc) gst_tag_list_free);
84
85 #if 0
86     g_value_register_transform_func (_gst_tag_list_type, G_TYPE_STRING,
87         _gst_structure_transform_to_string);
88 #endif
89   }
90
91   return _gst_tag_list_type;
92 }
93
94 void
95 _gst_tag_initialize (void)
96 {
97   __tag_mutex = g_mutex_new ();
98   __tags = g_hash_table_new (g_str_hash, g_str_equal);
99   gst_tag_register (GST_TAG_TITLE, GST_TAG_FLAG_META,
100       G_TYPE_STRING,
101       _("title"), _("commonly used title"), gst_tag_merge_strings_with_comma);
102   gst_tag_register (GST_TAG_TITLE_SORTNAME, GST_TAG_FLAG_META,
103       G_TYPE_STRING,
104       _("title sortname"), _("commonly used title for sorting purposes"), NULL);
105   gst_tag_register (GST_TAG_ARTIST, GST_TAG_FLAG_META,
106       G_TYPE_STRING,
107       _("artist"),
108       _("person(s) responsible for the recording"),
109       gst_tag_merge_strings_with_comma);
110   gst_tag_register (GST_TAG_ARTIST_SORTNAME, GST_TAG_FLAG_META,
111       G_TYPE_STRING,
112       _("artist sortname"),
113       _("person(s) responsible for the recording for sorting purposes"), NULL);
114   gst_tag_register (GST_TAG_ALBUM, GST_TAG_FLAG_META,
115       G_TYPE_STRING,
116       _("album"),
117       _("album containing this data"), gst_tag_merge_strings_with_comma);
118   gst_tag_register (GST_TAG_ALBUM_SORTNAME, GST_TAG_FLAG_META,
119       G_TYPE_STRING,
120       _("album sortname"),
121       _("album containing this data for sorting purposes"), NULL);
122   gst_tag_register (GST_TAG_ALBUM_ARTIST, GST_TAG_FLAG_META,
123       G_TYPE_STRING,
124       _("album artist"),
125       _("The artist of the entire album, as it should be displayed"),
126       gst_tag_merge_strings_with_comma);
127   gst_tag_register (GST_TAG_ALBUM_ARTIST_SORTNAME, GST_TAG_FLAG_META,
128       G_TYPE_STRING,
129       _("album artist sortname"),
130       _("The artist of the entire album, as it should be sorted"), NULL);
131   gst_tag_register (GST_TAG_DATE, GST_TAG_FLAG_META, GST_TYPE_DATE,
132       _("date"), _("date the data was created (as a GDate structure)"), NULL);
133   gst_tag_register (GST_TAG_DATE_TIME, GST_TAG_FLAG_META, GST_TYPE_DATE_TIME,
134       _("datetime"),
135       _("date and time the data was created (as a GstDateTime structure)"),
136       NULL);
137   gst_tag_register (GST_TAG_GENRE, GST_TAG_FLAG_META,
138       G_TYPE_STRING,
139       _("genre"),
140       _("genre this data belongs to"), gst_tag_merge_strings_with_comma);
141   gst_tag_register (GST_TAG_COMMENT, GST_TAG_FLAG_META,
142       G_TYPE_STRING,
143       _("comment"),
144       _("free text commenting the data"), gst_tag_merge_use_first);
145   gst_tag_register (GST_TAG_EXTENDED_COMMENT, GST_TAG_FLAG_META,
146       G_TYPE_STRING,
147       _("extended comment"),
148       _("free text commenting the data in key=value or key[en]=comment form"),
149       gst_tag_merge_use_first);
150   gst_tag_register (GST_TAG_TRACK_NUMBER, GST_TAG_FLAG_META,
151       G_TYPE_UINT,
152       _("track number"),
153       _("track number inside a collection"), gst_tag_merge_use_first);
154   gst_tag_register (GST_TAG_TRACK_COUNT, GST_TAG_FLAG_META,
155       G_TYPE_UINT,
156       _("track count"),
157       _("count of tracks inside collection this track belongs to"),
158       gst_tag_merge_use_first);
159   gst_tag_register (GST_TAG_ALBUM_VOLUME_NUMBER, GST_TAG_FLAG_META,
160       G_TYPE_UINT,
161       _("disc number"),
162       _("disc number inside a collection"), gst_tag_merge_use_first);
163   gst_tag_register (GST_TAG_ALBUM_VOLUME_COUNT, GST_TAG_FLAG_META,
164       G_TYPE_UINT,
165       _("disc count"),
166       _("count of discs inside collection this disc belongs to"),
167       gst_tag_merge_use_first);
168   gst_tag_register (GST_TAG_LOCATION, GST_TAG_FLAG_META,
169       G_TYPE_STRING,
170       _("location"), _("Origin of media as a URI (location, where the "
171           "original of the file or stream is hosted)"),
172       gst_tag_merge_strings_with_comma);
173   gst_tag_register (GST_TAG_HOMEPAGE, GST_TAG_FLAG_META,
174       G_TYPE_STRING,
175       _("homepage"),
176       _("Homepage for this media (i.e. artist or movie homepage)"),
177       gst_tag_merge_strings_with_comma);
178   gst_tag_register (GST_TAG_DESCRIPTION, GST_TAG_FLAG_META, G_TYPE_STRING,
179       _("description"), _("short text describing the content of the data"),
180       gst_tag_merge_strings_with_comma);
181   gst_tag_register (GST_TAG_VERSION, GST_TAG_FLAG_META, G_TYPE_STRING,
182       _("version"), _("version of this data"), NULL);
183   gst_tag_register (GST_TAG_ISRC, GST_TAG_FLAG_META, G_TYPE_STRING, _("ISRC"),
184       _
185       ("International Standard Recording Code - see http://www.ifpi.org/isrc/"),
186       NULL);
187   /* FIXME: organization (fix what? tpm) */
188   gst_tag_register (GST_TAG_ORGANIZATION, GST_TAG_FLAG_META, G_TYPE_STRING,
189       _("organization"), _("organization"), gst_tag_merge_strings_with_comma);
190   gst_tag_register (GST_TAG_COPYRIGHT, GST_TAG_FLAG_META,
191       G_TYPE_STRING, _("copyright"), _("copyright notice of the data"), NULL);
192   gst_tag_register (GST_TAG_COPYRIGHT_URI, GST_TAG_FLAG_META,
193       G_TYPE_STRING, _("copyright uri"),
194       _("URI to the copyright notice of the data"), NULL);
195   gst_tag_register (GST_TAG_ENCODED_BY, GST_TAG_FLAG_META, G_TYPE_STRING,
196       _("encoded by"), _("name of the encoding person or organization"),
197       gst_tag_merge_strings_with_comma);
198   gst_tag_register (GST_TAG_CONTACT, GST_TAG_FLAG_META,
199       G_TYPE_STRING,
200       _("contact"), _("contact information"), gst_tag_merge_strings_with_comma);
201   gst_tag_register (GST_TAG_LICENSE, GST_TAG_FLAG_META,
202       G_TYPE_STRING, _("license"), _("license of data"), NULL);
203   gst_tag_register (GST_TAG_LICENSE_URI, GST_TAG_FLAG_META,
204       G_TYPE_STRING, _("license uri"),
205       _("URI to the license of the data"), NULL);
206   gst_tag_register (GST_TAG_PERFORMER, GST_TAG_FLAG_META,
207       G_TYPE_STRING,
208       _("performer"),
209       _("person(s) performing"), gst_tag_merge_strings_with_comma);
210   gst_tag_register (GST_TAG_COMPOSER, GST_TAG_FLAG_META,
211       G_TYPE_STRING,
212       _("composer"),
213       _("person(s) who composed the recording"),
214       gst_tag_merge_strings_with_comma);
215   gst_tag_register (GST_TAG_DURATION, GST_TAG_FLAG_DECODED,
216       G_TYPE_UINT64,
217       _("duration"), _("length in GStreamer time units (nanoseconds)"), NULL);
218   gst_tag_register (GST_TAG_CODEC, GST_TAG_FLAG_ENCODED,
219       G_TYPE_STRING,
220       _("codec"),
221       _("codec the data is stored in"), gst_tag_merge_strings_with_comma);
222   gst_tag_register (GST_TAG_VIDEO_CODEC, GST_TAG_FLAG_ENCODED,
223       G_TYPE_STRING,
224       _("video codec"), _("codec the video data is stored in"), NULL);
225   gst_tag_register (GST_TAG_AUDIO_CODEC, GST_TAG_FLAG_ENCODED,
226       G_TYPE_STRING,
227       _("audio codec"), _("codec the audio data is stored in"), NULL);
228   gst_tag_register (GST_TAG_SUBTITLE_CODEC, GST_TAG_FLAG_ENCODED,
229       G_TYPE_STRING,
230       _("subtitle codec"), _("codec the subtitle data is stored in"), NULL);
231   gst_tag_register (GST_TAG_CONTAINER_FORMAT, GST_TAG_FLAG_ENCODED,
232       G_TYPE_STRING, _("container format"),
233       _("container format the data is stored in"), NULL);
234   gst_tag_register (GST_TAG_BITRATE, GST_TAG_FLAG_ENCODED,
235       G_TYPE_UINT, _("bitrate"), _("exact or average bitrate in bits/s"), NULL);
236   gst_tag_register (GST_TAG_NOMINAL_BITRATE, GST_TAG_FLAG_ENCODED,
237       G_TYPE_UINT, _("nominal bitrate"), _("nominal bitrate in bits/s"), NULL);
238   gst_tag_register (GST_TAG_MINIMUM_BITRATE, GST_TAG_FLAG_ENCODED,
239       G_TYPE_UINT, _("minimum bitrate"), _("minimum bitrate in bits/s"), NULL);
240   gst_tag_register (GST_TAG_MAXIMUM_BITRATE, GST_TAG_FLAG_ENCODED,
241       G_TYPE_UINT, _("maximum bitrate"), _("maximum bitrate in bits/s"), NULL);
242   gst_tag_register (GST_TAG_ENCODER, GST_TAG_FLAG_ENCODED,
243       G_TYPE_STRING,
244       _("encoder"), _("encoder used to encode this stream"), NULL);
245   gst_tag_register (GST_TAG_ENCODER_VERSION, GST_TAG_FLAG_ENCODED,
246       G_TYPE_UINT,
247       _("encoder version"),
248       _("version of the encoder used to encode this stream"), NULL);
249   gst_tag_register (GST_TAG_SERIAL, GST_TAG_FLAG_ENCODED,
250       G_TYPE_UINT, _("serial"), _("serial number of track"), NULL);
251   gst_tag_register (GST_TAG_TRACK_GAIN, GST_TAG_FLAG_META,
252       G_TYPE_DOUBLE, _("replaygain track gain"), _("track gain in db"), NULL);
253   gst_tag_register (GST_TAG_TRACK_PEAK, GST_TAG_FLAG_META,
254       G_TYPE_DOUBLE, _("replaygain track peak"), _("peak of the track"), NULL);
255   gst_tag_register (GST_TAG_ALBUM_GAIN, GST_TAG_FLAG_META,
256       G_TYPE_DOUBLE, _("replaygain album gain"), _("album gain in db"), NULL);
257   gst_tag_register (GST_TAG_ALBUM_PEAK, GST_TAG_FLAG_META,
258       G_TYPE_DOUBLE, _("replaygain album peak"), _("peak of the album"), NULL);
259   gst_tag_register (GST_TAG_REFERENCE_LEVEL, GST_TAG_FLAG_META,
260       G_TYPE_DOUBLE, _("replaygain reference level"),
261       _("reference level of track and album gain values"), NULL);
262   gst_tag_register (GST_TAG_LANGUAGE_CODE, GST_TAG_FLAG_META, G_TYPE_STRING,
263       _("language code"),
264       _("language code for this stream, conforming to ISO-639-1"), NULL);
265   gst_tag_register (GST_TAG_IMAGE, GST_TAG_FLAG_META, GST_TYPE_BUFFER,
266       _("image"), _("image related to this stream"), gst_tag_merge_use_first);
267   gst_tag_register (GST_TAG_PREVIEW_IMAGE, GST_TAG_FLAG_META, GST_TYPE_BUFFER,
268       /* TRANSLATORS: 'preview image' = image that shows a preview of the full image */
269       _("preview image"), _("preview image related to this stream"), NULL);
270   gst_tag_register (GST_TAG_ATTACHMENT, GST_TAG_FLAG_META, GST_TYPE_BUFFER,
271       _("attachment"), _("file attached to this stream"),
272       gst_tag_merge_use_first);
273   gst_tag_register (GST_TAG_BEATS_PER_MINUTE, GST_TAG_FLAG_META, G_TYPE_DOUBLE,
274       _("beats per minute"), _("number of beats per minute in audio"), NULL);
275   gst_tag_register (GST_TAG_KEYWORDS, GST_TAG_FLAG_META, G_TYPE_STRING,
276       _("keywords"), _("comma separated keywords describing the content"),
277       gst_tag_merge_strings_with_comma);
278   gst_tag_register (GST_TAG_GEO_LOCATION_NAME, GST_TAG_FLAG_META, G_TYPE_STRING,
279       _("geo location name"), _("human readable descriptive location of where "
280           "the media has been recorded or produced"), NULL);
281   gst_tag_register (GST_TAG_GEO_LOCATION_LATITUDE, GST_TAG_FLAG_META,
282       G_TYPE_DOUBLE, _("geo location latitude"),
283       _("geo latitude location of where the media has been recorded or "
284           "produced in degrees according to WGS84 (zero at the equator, "
285           "negative values for southern latitudes)"), NULL);
286   gst_tag_register (GST_TAG_GEO_LOCATION_LONGITUDE, GST_TAG_FLAG_META,
287       G_TYPE_DOUBLE, _("geo location longitude"),
288       _("geo longitude location of where the media has been recorded or "
289           "produced in degrees according to WGS84 (zero at the prime meridian "
290           "in Greenwich/UK,  negative values for western longitudes)"), NULL);
291   gst_tag_register (GST_TAG_GEO_LOCATION_ELEVATION, GST_TAG_FLAG_META,
292       G_TYPE_DOUBLE, _("geo location elevation"),
293       _("geo elevation of where the media has been recorded or produced in "
294           "meters according to WGS84 (zero is average sea level)"), NULL);
295   gst_tag_register (GST_TAG_GEO_LOCATION_COUNTRY, GST_TAG_FLAG_META,
296       G_TYPE_STRING, _("geo location country"),
297       _("country (english name) where the media has been recorded "
298           "or produced"), NULL);
299   gst_tag_register (GST_TAG_GEO_LOCATION_CITY, GST_TAG_FLAG_META,
300       G_TYPE_STRING, _("geo location city"),
301       _("city (english name) where the media has been recorded "
302           "or produced"), NULL);
303   gst_tag_register (GST_TAG_GEO_LOCATION_SUBLOCATION, GST_TAG_FLAG_META,
304       G_TYPE_STRING, _("geo location sublocation"),
305       _("a location whithin a city where the media has been produced "
306           "or created (e.g. the neighborhood)"), NULL);
307   gst_tag_register (GST_TAG_GEO_LOCATION_HORIZONTAL_ERROR, GST_TAG_FLAG_META,
308       G_TYPE_DOUBLE, _("geo location horizontal error"),
309       _("expected error of the horizontal positioning measures (in meters)"),
310       NULL);
311   gst_tag_register (GST_TAG_GEO_LOCATION_MOVEMENT_SPEED, GST_TAG_FLAG_META,
312       G_TYPE_DOUBLE, _("geo location movement speed"),
313       _("movement speed of the capturing device while performing the capture "
314           "in m/s"), NULL);
315   gst_tag_register (GST_TAG_GEO_LOCATION_MOVEMENT_DIRECTION, GST_TAG_FLAG_META,
316       G_TYPE_DOUBLE, _("geo location movement direction"),
317       _("indicates the movement direction of the device performing the capture"
318           " of a media. It is represented as degrees in floating point "
319           "representation, 0 means the geographic north, and increases "
320           "clockwise"), NULL);
321   gst_tag_register (GST_TAG_GEO_LOCATION_CAPTURE_DIRECTION, GST_TAG_FLAG_META,
322       G_TYPE_DOUBLE, _("geo location capture direction"),
323       _("indicates the direction the device is pointing to when capturing "
324           " a media. It is represented as degrees in floating point "
325           " representation, 0 means the geographic north, and increases "
326           "clockwise"), NULL);
327   gst_tag_register (GST_TAG_SHOW_NAME, GST_TAG_FLAG_META, G_TYPE_STRING,
328       /* TRANSLATORS: 'show name' = 'TV/radio/podcast show name' here */
329       _("show name"),
330       _("Name of the tv/podcast/series show the media is from"),
331       gst_tag_merge_strings_with_comma);
332   gst_tag_register (GST_TAG_SHOW_SORTNAME, GST_TAG_FLAG_META, G_TYPE_STRING,
333       /* TRANSLATORS: 'show sortname' = 'TV/radio/podcast show name as used for sorting purposes' here */
334       _("show sortname"),
335       _("Name of the tv/podcast/series show the media is from, for sorting "
336           "purposes"), NULL);
337   gst_tag_register (GST_TAG_SHOW_EPISODE_NUMBER, GST_TAG_FLAG_META, G_TYPE_UINT,
338       _("episode number"),
339       _("The episode number in the season the media is part of"),
340       gst_tag_merge_use_first);
341   gst_tag_register (GST_TAG_SHOW_SEASON_NUMBER, GST_TAG_FLAG_META, G_TYPE_UINT,
342       _("season number"),
343       _("The season number of the show the media is part of"),
344       gst_tag_merge_use_first);
345   gst_tag_register (GST_TAG_LYRICS, GST_TAG_FLAG_META, G_TYPE_STRING,
346       _("lyrics"), _("The lyrics of the media, commonly used for songs"),
347       gst_tag_merge_strings_with_comma);
348   gst_tag_register (GST_TAG_COMPOSER_SORTNAME, GST_TAG_FLAG_META, G_TYPE_STRING,
349       _("composer sortname"),
350       _("person(s) who composed the recording, for sorting purposes"), NULL);
351   gst_tag_register (GST_TAG_GROUPING, GST_TAG_FLAG_META, G_TYPE_STRING,
352       _("grouping"),
353       _("Groups related media that spans multiple tracks, like the different "
354           "pieces of a concerto. It is a higher level than a track, "
355           "but lower than an album"), NULL);
356   gst_tag_register (GST_TAG_USER_RATING, GST_TAG_FLAG_META, G_TYPE_UINT,
357       _("user rating"),
358       _("Rating attributed by a user. The higher the rank, "
359           "the more the user likes this media"), NULL);
360   gst_tag_register (GST_TAG_DEVICE_MANUFACTURER, GST_TAG_FLAG_META,
361       G_TYPE_STRING, _("device manufacturer"),
362       _("Manufacturer of the device used to create this media"), NULL);
363   gst_tag_register (GST_TAG_DEVICE_MODEL, GST_TAG_FLAG_META, G_TYPE_STRING,
364       _("device model"),
365       _("Model of the device used to create this media"), NULL);
366   gst_tag_register (GST_TAG_APPLICATION_NAME, GST_TAG_FLAG_META, G_TYPE_STRING,
367       _("application name"), _("Application used to create the media"), NULL);
368   gst_tag_register (GST_TAG_APPLICATION_DATA, GST_TAG_FLAG_META,
369       GST_TYPE_BUFFER, _("application data"),
370       _("Arbitrary application data to be serialized into the media"), NULL);
371   gst_tag_register (GST_TAG_IMAGE_ORIENTATION, GST_TAG_FLAG_META, G_TYPE_STRING,
372       _("image orientation"),
373       _("How the image should be rotated or flipped before display"), NULL);
374 }
375
376 /**
377  * gst_tag_merge_use_first:
378  * @dest: (out caller-allocates): uninitialized GValue to store result in
379  * @src: GValue to copy from
380  *
381  * This is a convenience function for the func argument of gst_tag_register().
382  * It creates a copy of the first value from the list.
383  */
384 void
385 gst_tag_merge_use_first (GValue * dest, const GValue * src)
386 {
387   const GValue *ret = gst_value_list_get_value (src, 0);
388
389   g_value_init (dest, G_VALUE_TYPE (ret));
390   g_value_copy (ret, dest);
391 }
392
393 /**
394  * gst_tag_merge_strings_with_comma:
395  * @dest: (out caller-allocates): uninitialized GValue to store result in
396  * @src: GValue to copy from
397  *
398  * This is a convenience function for the func argument of gst_tag_register().
399  * It concatenates all given strings using a comma. The tag must be registered
400  * as a G_TYPE_STRING or this function will fail.
401  */
402 void
403 gst_tag_merge_strings_with_comma (GValue * dest, const GValue * src)
404 {
405   GString *str;
406   gint i, count;
407
408   count = gst_value_list_get_size (src);
409   str = g_string_new (g_value_get_string (gst_value_list_get_value (src, 0)));
410   for (i = 1; i < count; i++) {
411     /* separator between two strings */
412     g_string_append (str, _(", "));
413     g_string_append (str,
414         g_value_get_string (gst_value_list_get_value (src, i)));
415   }
416
417   g_value_init (dest, G_TYPE_STRING);
418   g_value_take_string (dest, str->str);
419   g_string_free (str, FALSE);
420 }
421
422 static GstTagInfo *
423 gst_tag_lookup (const gchar * tag_name)
424 {
425   GstTagInfo *ret;
426
427   TAG_LOCK;
428   ret = g_hash_table_lookup (__tags, (gpointer) tag_name);
429   TAG_UNLOCK;
430
431   return ret;
432 }
433
434 /**
435  * gst_tag_register:
436  * @name: the name or identifier string
437  * @flag: a flag describing the type of tag info
438  * @type: the type this data is in
439  * @nick: human-readable name
440  * @blurb: a human-readable description about this tag
441  * @func: function for merging multiple values of this tag, or NULL
442  *
443  * Registers a new tag type for the use with GStreamer's type system. If a type
444  * with that name is already registered, that one is used.
445  * The old registration may have used a different type however. So don't rely
446  * on your supplied values.
447  *
448  * Important: if you do not supply a merge function the implication will be
449  * that there can only be one single value for this tag in a tag list and
450  * any additional values will silenty be discarded when being added (unless
451  * #GST_TAG_MERGE_REPLACE, #GST_TAG_MERGE_REPLACE_ALL, or
452  * #GST_TAG_MERGE_PREPEND is used as merge mode, in which case the new
453  * value will replace the old one in the list).
454  *
455  * The merge function will be called from gst_tag_list_copy_value() when
456  * it is required that one or more values for a tag be condensed into
457  * one single value. This may happen from gst_tag_list_get_string(),
458  * gst_tag_list_get_int(), gst_tag_list_get_double() etc. What will happen
459  * exactly in that case depends on how the tag was registered and if a
460  * merge function was supplied and if so which one.
461  *
462  * Two default merge functions are provided: gst_tag_merge_use_first() and
463  * gst_tag_merge_strings_with_comma().
464  */
465 void
466 gst_tag_register (const gchar * name, GstTagFlag flag, GType type,
467     const gchar * nick, const gchar * blurb, GstTagMergeFunc func)
468 {
469   GstTagInfo *info;
470   gchar *name_dup;
471
472   g_return_if_fail (name != NULL);
473   g_return_if_fail (nick != NULL);
474   g_return_if_fail (blurb != NULL);
475   g_return_if_fail (type != 0 && type != GST_TYPE_LIST);
476
477   info = gst_tag_lookup (name);
478
479   if (info) {
480     g_return_if_fail (info->type == type);
481     return;
482   }
483
484   info = g_slice_new (GstTagInfo);
485   info->flag = flag;
486   info->type = type;
487   info->nick = g_strdup (nick);
488   info->blurb = g_strdup (blurb);
489   info->merge_func = func;
490
491   /* we make a copy for the hash table anyway, which will stay around, so
492    * can use that for the quark table too */
493   name_dup = g_strdup (name);
494   info->name_quark = g_quark_from_static_string (name_dup);
495
496   TAG_LOCK;
497   g_hash_table_insert (__tags, (gpointer) name_dup, info);
498   TAG_UNLOCK;
499 }
500
501 /**
502  * gst_tag_exists:
503  * @tag: name of the tag
504  *
505  * Checks if the given type is already registered.
506  *
507  * Returns: TRUE if the type is already registered
508  */
509 gboolean
510 gst_tag_exists (const gchar * tag)
511 {
512   g_return_val_if_fail (tag != NULL, FALSE);
513
514   return gst_tag_lookup (tag) != NULL;
515 }
516
517 /**
518  * gst_tag_get_type:
519  * @tag: the tag
520  *
521  * Gets the #GType used for this tag.
522  *
523  * Returns: the #GType of this tag
524  */
525 GType
526 gst_tag_get_type (const gchar * tag)
527 {
528   GstTagInfo *info;
529
530   g_return_val_if_fail (tag != NULL, 0);
531   info = gst_tag_lookup (tag);
532   g_return_val_if_fail (info != NULL, 0);
533
534   return info->type;
535 }
536
537 /**
538  * gst_tag_get_nick
539  * @tag: the tag
540  *
541  * Returns the human-readable name of this tag, You must not change or free
542  * this string.
543  *
544  * Returns: the human-readable name of this tag
545  */
546 const gchar *
547 gst_tag_get_nick (const gchar * tag)
548 {
549   GstTagInfo *info;
550
551   g_return_val_if_fail (tag != NULL, NULL);
552   info = gst_tag_lookup (tag);
553   g_return_val_if_fail (info != NULL, NULL);
554
555   return info->nick;
556 }
557
558 /**
559  * gst_tag_get_description:
560  * @tag: the tag
561  *
562  * Returns the human-readable description of this tag, You must not change or
563  * free this string.
564  *
565  * Returns: the human-readable description of this tag
566  */
567 const gchar *
568 gst_tag_get_description (const gchar * tag)
569 {
570   GstTagInfo *info;
571
572   g_return_val_if_fail (tag != NULL, NULL);
573   info = gst_tag_lookup (tag);
574   g_return_val_if_fail (info != NULL, NULL);
575
576   return info->blurb;
577 }
578
579 /**
580  * gst_tag_get_flag:
581  * @tag: the tag
582  *
583  * Gets the flag of @tag.
584  *
585  * Returns: the flag of this tag.
586  */
587 GstTagFlag
588 gst_tag_get_flag (const gchar * tag)
589 {
590   GstTagInfo *info;
591
592   g_return_val_if_fail (tag != NULL, GST_TAG_FLAG_UNDEFINED);
593   info = gst_tag_lookup (tag);
594   g_return_val_if_fail (info != NULL, GST_TAG_FLAG_UNDEFINED);
595
596   return info->flag;
597 }
598
599 /**
600  * gst_tag_is_fixed:
601  * @tag: tag to check
602  *
603  * Checks if the given tag is fixed. A fixed tag can only contain one value.
604  * Unfixed tags can contain lists of values.
605  *
606  * Returns: TRUE, if the given tag is fixed.
607  */
608 gboolean
609 gst_tag_is_fixed (const gchar * tag)
610 {
611   GstTagInfo *info;
612
613   g_return_val_if_fail (tag != NULL, FALSE);
614   info = gst_tag_lookup (tag);
615   g_return_val_if_fail (info != NULL, FALSE);
616
617   return info->merge_func == NULL;
618 }
619
620 /**
621  * gst_tag_list_new:
622  *
623  * Creates a new empty GstTagList.
624  *
625  * Free-function: gst_tag_list_free
626  *
627  * Returns: (transfer full): An empty tag list
628  */
629 GstTagList *
630 gst_tag_list_new (void)
631 {
632   return GST_TAG_LIST (gst_structure_id_empty_new (GST_QUARK (TAGLIST)));
633 }
634
635 /**
636  * gst_tag_list_new_full:
637  * @tag: tag
638  * @...: NULL-terminated list of values to set
639  *
640  * Creates a new taglist and appends the values for the given tags. It expects
641  * tag-value pairs like gst_tag_list_add(), and a NULL terminator after the
642  * last pair. The type of the values is implicit and is documented in the API
643  * reference, but can also be queried at runtime with gst_tag_get_type(). It
644  * is an error to pass a value of a type not matching the tag type into this
645  * function. The tag list will make copies of any arguments passed
646  * (e.g. strings, buffers).
647  *
648  * Free-function: gst_tag_list_free
649  *
650  * Returns: (transfer full): a new #GstTagList. Free with gst_tag_list_free()
651  *     when no longer needed.
652  *
653  * Since: 0.10.24
654  */
655 /* FIXME 0.11: rename gst_tag_list_new_full to _new and _new to _new_empty */
656 GstTagList *
657 gst_tag_list_new_full (const gchar * tag, ...)
658 {
659   GstTagList *list;
660   va_list args;
661
662   g_return_val_if_fail (tag != NULL, NULL);
663
664   list = gst_tag_list_new ();
665   va_start (args, tag);
666   gst_tag_list_add_valist (list, GST_TAG_MERGE_APPEND, tag, args);
667   va_end (args);
668
669   return list;
670 }
671
672 /**
673  * gst_tag_list_new_full_valist:
674  * @var_args: tag / value pairs to set
675  *
676  * Just like gst_tag_list_new_full(), only that it takes a va_list argument.
677  * Useful mostly for language bindings.
678  *
679  * Free-function: gst_tag_list_free
680  *
681  * Returns: (transfer full): a new #GstTagList. Free with gst_tag_list_free()
682  *     when no longer needed.
683  *
684  * Since: 0.10.24
685  */
686 GstTagList *
687 gst_tag_list_new_full_valist (va_list var_args)
688 {
689   GstTagList *list;
690   const gchar *tag;
691
692   list = gst_tag_list_new ();
693
694   tag = va_arg (var_args, gchar *);
695   gst_tag_list_add_valist (list, GST_TAG_MERGE_APPEND, tag, var_args);
696
697   return list;
698 }
699
700 /**
701  * gst_tag_list_to_string:
702  * @list: a #GstTagList
703  *
704  * Serializes a tag list to a string.
705  *
706  * Returns: a newly-allocated string, or NULL in case of an error. The
707  *    string must be freed with g_free() when no longer needed.
708  *
709  * Since: 0.10.36
710  */
711 gchar *
712 gst_tag_list_to_string (const GstTagList * list)
713 {
714   g_return_val_if_fail (GST_IS_TAG_LIST (list), NULL);
715
716   return gst_structure_to_string (GST_STRUCTURE (list));
717 }
718
719 /**
720  * gst_tag_list_new_from_string:
721  * @str: a string created with gst_tag_list_to_string()
722  *
723  * Deserializes a tag list.
724  *
725  * Returns: a new #GstTagList, or NULL in case of an error.
726  *
727  * Since: 0.10.36
728  */
729 GstTagList *
730 gst_tag_list_new_from_string (const gchar * str)
731 {
732   g_return_val_if_fail (str != NULL, NULL);
733   g_return_val_if_fail (g_str_has_prefix (str, "taglist"), NULL);
734
735   return GST_TAG_LIST (gst_structure_from_string (str, NULL));
736 }
737
738 /**
739  * gst_tag_list_is_empty:
740  * @list: A #GstTagList.
741  *
742  * Checks if the given taglist is empty.
743  *
744  * Returns: TRUE if the taglist is empty, otherwise FALSE.
745  *
746  * Since: 0.10.11
747  */
748 gboolean
749 gst_tag_list_is_empty (const GstTagList * list)
750 {
751   g_return_val_if_fail (list != NULL, FALSE);
752   g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
753
754   return (gst_structure_n_fields ((GstStructure *) list) == 0);
755 }
756
757 static gboolean
758 gst_tag_list_fields_equal (const GValue * value1, const GValue * value2)
759 {
760   gdouble d1, d2;
761
762   if (gst_value_compare (value1, value2) == GST_VALUE_EQUAL)
763     return TRUE;
764
765   /* fields not equal: add some tolerance for doubles, otherwise bail out */
766   if (!G_VALUE_HOLDS_DOUBLE (value1) || !G_VALUE_HOLDS_DOUBLE (value2))
767     return FALSE;
768
769   d1 = g_value_get_double (value1);
770   d2 = g_value_get_double (value2);
771
772   /* This will only work for 'normal' values and values around 0,
773    * which should be good enough for our purposes here
774    * FIXME: maybe add this to gst_value_compare_double() ? */
775   return (fabs (d1 - d2) < 0.0000001);
776 }
777
778 /**
779  * gst_tag_list_is_equal:
780  * @list1: a #GstTagList.
781  * @list2: a #GstTagList.
782  *
783  * Checks if the two given taglists are equal.
784  *
785  * Returns: TRUE if the taglists are equal, otherwise FALSE
786  *
787  * Since: 0.10.36
788  */
789 gboolean
790 gst_tag_list_is_equal (const GstTagList * list1, const GstTagList * list2)
791 {
792   const GstStructure *s1, *s2;
793   gint num_fields1, num_fields2, i;
794
795   g_return_val_if_fail (GST_IS_TAG_LIST (list1), FALSE);
796   g_return_val_if_fail (GST_IS_TAG_LIST (list2), FALSE);
797
798   /* we don't just use gst_structure_is_equal() here so we can add some
799    * tolerance for doubles, though maybe we should just add that to
800    * gst_value_compare_double() as well? */
801   s1 = (const GstStructure *) list1;
802   s2 = (const GstStructure *) list2;
803
804   num_fields1 = gst_structure_n_fields (s1);
805   num_fields2 = gst_structure_n_fields (s2);
806
807   if (num_fields1 != num_fields2)
808     return FALSE;
809
810   for (i = 0; i < num_fields1; i++) {
811     const GValue *value1, *value2;
812     const gchar *tag_name;
813
814     tag_name = gst_structure_nth_field_name (s1, i);
815     value1 = gst_structure_get_value (s1, tag_name);
816     value2 = gst_structure_get_value (s2, tag_name);
817
818     if (value2 == NULL)
819       return FALSE;
820
821     if (!gst_tag_list_fields_equal (value1, value2))
822       return FALSE;
823   }
824
825   return TRUE;
826 }
827
828 /**
829  * gst_is_tag_list:
830  * @p: Object that might be a taglist
831  *
832  * Checks if the given pointer is a taglist.
833  *
834  * Returns: TRUE, if the given pointer is a taglist
835  */
836 gboolean
837 gst_is_tag_list (gconstpointer p)
838 {
839   GstStructure *s = (GstStructure *) p;
840
841   g_return_val_if_fail (p != NULL, FALSE);
842
843   return (GST_IS_STRUCTURE (s) && s->name == GST_QUARK (TAGLIST));
844 }
845
846 typedef struct
847 {
848   GstStructure *list;
849   GstTagMergeMode mode;
850 }
851 GstTagCopyData;
852
853 static void
854 gst_tag_list_add_value_internal (GstStructure * list, GstTagMergeMode mode,
855     const gchar * tag, const GValue * value, GstTagInfo * info)
856 {
857   const GValue *value2;
858   GQuark tag_quark;
859
860   if (info == NULL) {
861     info = gst_tag_lookup (tag);
862     if (G_UNLIKELY (info == NULL)) {
863       g_warning ("unknown tag '%s'", tag);
864       return;
865     }
866   }
867
868   tag_quark = info->name_quark;
869
870   if (info->merge_func
871       && (value2 = gst_structure_id_get_value (list, tag_quark)) != NULL) {
872     GValue dest = { 0, };
873
874     switch (mode) {
875       case GST_TAG_MERGE_REPLACE_ALL:
876       case GST_TAG_MERGE_REPLACE:
877         gst_structure_id_set_value (list, tag_quark, value);
878         break;
879       case GST_TAG_MERGE_PREPEND:
880         gst_value_list_merge (&dest, value, value2);
881         gst_structure_id_set_value (list, tag_quark, &dest);
882         g_value_unset (&dest);
883         break;
884       case GST_TAG_MERGE_APPEND:
885         gst_value_list_merge (&dest, value2, value);
886         gst_structure_id_set_value (list, tag_quark, &dest);
887         g_value_unset (&dest);
888         break;
889       case GST_TAG_MERGE_KEEP:
890       case GST_TAG_MERGE_KEEP_ALL:
891         break;
892       default:
893         g_assert_not_reached ();
894         break;
895     }
896   } else {
897     switch (mode) {
898       case GST_TAG_MERGE_APPEND:
899       case GST_TAG_MERGE_KEEP:
900         if (gst_structure_id_get_value (list, tag_quark) != NULL)
901           break;
902         /* fall through */
903       case GST_TAG_MERGE_REPLACE_ALL:
904       case GST_TAG_MERGE_REPLACE:
905       case GST_TAG_MERGE_PREPEND:
906         gst_structure_id_set_value (list, tag_quark, value);
907         break;
908       case GST_TAG_MERGE_KEEP_ALL:
909         break;
910       default:
911         g_assert_not_reached ();
912         break;
913     }
914   }
915 }
916
917 static gboolean
918 gst_tag_list_copy_foreach (GQuark tag_quark, const GValue * value,
919     gpointer user_data)
920 {
921   GstTagCopyData *copy = (GstTagCopyData *) user_data;
922   const gchar *tag;
923
924   tag = g_quark_to_string (tag_quark);
925   gst_tag_list_add_value_internal (copy->list, copy->mode, tag, value, NULL);
926
927   return TRUE;
928 }
929
930 /**
931  * gst_tag_list_insert:
932  * @into: list to merge into
933  * @from: list to merge from
934  * @mode: the mode to use
935  *
936  * Inserts the tags of the @from list into the first list using the given mode.
937  */
938 void
939 gst_tag_list_insert (GstTagList * into, const GstTagList * from,
940     GstTagMergeMode mode)
941 {
942   GstTagCopyData data;
943
944   g_return_if_fail (GST_IS_TAG_LIST (into));
945   g_return_if_fail (GST_IS_TAG_LIST (from));
946   g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
947
948   data.list = (GstStructure *) into;
949   data.mode = mode;
950   if (mode == GST_TAG_MERGE_REPLACE_ALL) {
951     gst_structure_remove_all_fields (data.list);
952   }
953   gst_structure_foreach ((GstStructure *) from, gst_tag_list_copy_foreach,
954       &data);
955 }
956
957 /**
958  * gst_tag_list_copy:
959  * @list: list to copy
960  *
961  * Copies a given #GstTagList.
962  *
963  * Free-function: gst_tag_list_free
964  *
965  * Returns: (transfer full): copy of the given list
966  */
967 GstTagList *
968 gst_tag_list_copy (const GstTagList * list)
969 {
970   g_return_val_if_fail (GST_IS_TAG_LIST (list), NULL);
971
972   return GST_TAG_LIST (gst_structure_copy ((GstStructure *) list));
973 }
974
975 /**
976  * gst_tag_list_merge:
977  * @list1: first list to merge
978  * @list2: second list to merge
979  * @mode: the mode to use
980  *
981  * Merges the two given lists into a new list. If one of the lists is NULL, a
982  * copy of the other is returned. If both lists are NULL, NULL is returned.
983  *
984  * Free-function: gst_tag_list_free
985  *
986  * Returns: (transfer full): the new list
987  */
988 GstTagList *
989 gst_tag_list_merge (const GstTagList * list1, const GstTagList * list2,
990     GstTagMergeMode mode)
991 {
992   GstTagList *list1_cp;
993   const GstTagList *list2_cp;
994
995   g_return_val_if_fail (list1 == NULL || GST_IS_TAG_LIST (list1), NULL);
996   g_return_val_if_fail (list2 == NULL || GST_IS_TAG_LIST (list2), NULL);
997   g_return_val_if_fail (GST_TAG_MODE_IS_VALID (mode), NULL);
998
999   /* nothing to merge */
1000   if (!list1 && !list2) {
1001     return NULL;
1002   }
1003
1004   /* create empty list, we need to do this to correctly handling merge modes */
1005   list1_cp = (list1) ? gst_tag_list_copy (list1) : gst_tag_list_new ();
1006   list2_cp = (list2) ? list2 : gst_tag_list_new ();
1007
1008   gst_tag_list_insert (list1_cp, list2_cp, mode);
1009
1010   if (!list2)
1011     gst_tag_list_free ((GstTagList *) list2_cp);
1012
1013   return list1_cp;
1014 }
1015
1016 /**
1017  * gst_tag_list_free:
1018  * @list: (in) (transfer full): the list to free
1019  *
1020  * Frees the given list and all associated values.
1021  */
1022 void
1023 gst_tag_list_free (GstTagList * list)
1024 {
1025   g_return_if_fail (GST_IS_TAG_LIST (list));
1026   gst_structure_free ((GstStructure *) list);
1027 }
1028
1029 /**
1030  * gst_tag_list_get_tag_size:
1031  * @list: a taglist
1032  * @tag: the tag to query
1033  *
1034  * Checks how many value are stored in this tag list for the given tag.
1035  *
1036  * Returns: The number of tags stored
1037  */
1038 guint
1039 gst_tag_list_get_tag_size (const GstTagList * list, const gchar * tag)
1040 {
1041   const GValue *value;
1042
1043   g_return_val_if_fail (GST_IS_TAG_LIST (list), 0);
1044
1045   value = gst_structure_get_value ((GstStructure *) list, tag);
1046   if (value == NULL)
1047     return 0;
1048   if (G_VALUE_TYPE (value) != GST_TYPE_LIST)
1049     return 1;
1050
1051   return gst_value_list_get_size (value);
1052 }
1053
1054 /**
1055  * gst_tag_list_add:
1056  * @list: list to set tags in
1057  * @mode: the mode to use
1058  * @tag: tag
1059  * @...: NULL-terminated list of values to set
1060  *
1061  * Sets the values for the given tags using the specified mode.
1062  */
1063 void
1064 gst_tag_list_add (GstTagList * list, GstTagMergeMode mode, const gchar * tag,
1065     ...)
1066 {
1067   va_list args;
1068
1069   g_return_if_fail (GST_IS_TAG_LIST (list));
1070   g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1071   g_return_if_fail (tag != NULL);
1072
1073   va_start (args, tag);
1074   gst_tag_list_add_valist (list, mode, tag, args);
1075   va_end (args);
1076 }
1077
1078 /**
1079  * gst_tag_list_add_values:
1080  * @list: list to set tags in
1081  * @mode: the mode to use
1082  * @tag: tag
1083  * @...: GValues to set
1084  *
1085  * Sets the GValues for the given tags using the specified mode.
1086  */
1087 void
1088 gst_tag_list_add_values (GstTagList * list, GstTagMergeMode mode,
1089     const gchar * tag, ...)
1090 {
1091   va_list args;
1092
1093   g_return_if_fail (GST_IS_TAG_LIST (list));
1094   g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1095   g_return_if_fail (tag != NULL);
1096
1097   va_start (args, tag);
1098   gst_tag_list_add_valist_values (list, mode, tag, args);
1099   va_end (args);
1100 }
1101
1102 /**
1103  * gst_tag_list_add_valist:
1104  * @list: list to set tags in
1105  * @mode: the mode to use
1106  * @tag: tag
1107  * @var_args: tag / value pairs to set
1108  *
1109  * Sets the values for the given tags using the specified mode.
1110  */
1111 void
1112 gst_tag_list_add_valist (GstTagList * list, GstTagMergeMode mode,
1113     const gchar * tag, va_list var_args)
1114 {
1115   GstTagInfo *info;
1116   gchar *error = NULL;
1117
1118   g_return_if_fail (GST_IS_TAG_LIST (list));
1119   g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1120   g_return_if_fail (tag != NULL);
1121
1122   if (mode == GST_TAG_MERGE_REPLACE_ALL) {
1123     gst_structure_remove_all_fields (list);
1124   }
1125
1126   while (tag != NULL) {
1127     GValue value = { 0, };
1128
1129     info = gst_tag_lookup (tag);
1130     if (G_UNLIKELY (info == NULL)) {
1131       g_warning ("unknown tag '%s'", tag);
1132       return;
1133     }
1134     G_VALUE_COLLECT_INIT (&value, info->type, var_args, 0, &error);
1135     if (error) {
1136       g_warning ("%s: %s", G_STRLOC, error);
1137       g_free (error);
1138       /* we purposely leak the value here, it might not be
1139        * in a sane state if an error condition occoured
1140        */
1141       return;
1142     }
1143     gst_tag_list_add_value_internal (list, mode, tag, &value, info);
1144     g_value_unset (&value);
1145     tag = va_arg (var_args, gchar *);
1146   }
1147 }
1148
1149 /**
1150  * gst_tag_list_add_valist_values:
1151  * @list: list to set tags in
1152  * @mode: the mode to use
1153  * @tag: tag
1154  * @var_args: tag / GValue pairs to set
1155  *
1156  * Sets the GValues for the given tags using the specified mode.
1157  */
1158 void
1159 gst_tag_list_add_valist_values (GstTagList * list, GstTagMergeMode mode,
1160     const gchar * tag, va_list var_args)
1161 {
1162   g_return_if_fail (GST_IS_TAG_LIST (list));
1163   g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1164   g_return_if_fail (tag != NULL);
1165
1166   if (mode == GST_TAG_MERGE_REPLACE_ALL) {
1167     gst_structure_remove_all_fields (list);
1168   }
1169
1170   while (tag != NULL) {
1171     GstTagInfo *info;
1172
1173     info = gst_tag_lookup (tag);
1174     if (G_UNLIKELY (info == NULL)) {
1175       g_warning ("unknown tag '%s'", tag);
1176       return;
1177     }
1178     gst_tag_list_add_value_internal (list, mode, tag, va_arg (var_args,
1179             GValue *), info);
1180     tag = va_arg (var_args, gchar *);
1181   }
1182 }
1183
1184 /**
1185  * gst_tag_list_add_value:
1186  * @list: list to set tags in
1187  * @mode: the mode to use
1188  * @tag: tag
1189  * @value: GValue for this tag
1190  *
1191  * Sets the GValue for a given tag using the specified mode.
1192  *
1193  * Since: 0.10.24
1194  */
1195 void
1196 gst_tag_list_add_value (GstTagList * list, GstTagMergeMode mode,
1197     const gchar * tag, const GValue * value)
1198 {
1199   g_return_if_fail (GST_IS_TAG_LIST (list));
1200   g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1201   g_return_if_fail (tag != NULL);
1202
1203   gst_tag_list_add_value_internal (list, mode, tag, value, NULL);
1204 }
1205
1206 /**
1207  * gst_tag_list_remove_tag:
1208  * @list: list to remove tag from
1209  * @tag: tag to remove
1210  *
1211  * Removes the given tag from the taglist.
1212  */
1213 void
1214 gst_tag_list_remove_tag (GstTagList * list, const gchar * tag)
1215 {
1216   g_return_if_fail (GST_IS_TAG_LIST (list));
1217   g_return_if_fail (tag != NULL);
1218
1219   gst_structure_remove_field ((GstStructure *) list, tag);
1220 }
1221
1222 typedef struct
1223 {
1224   GstTagForeachFunc func;
1225   const GstTagList *tag_list;
1226   gpointer data;
1227 }
1228 TagForeachData;
1229
1230 static int
1231 structure_foreach_wrapper (GQuark field_id, const GValue * value,
1232     gpointer user_data)
1233 {
1234   TagForeachData *data = (TagForeachData *) user_data;
1235
1236   data->func (data->tag_list, g_quark_to_string (field_id), data->data);
1237   return TRUE;
1238 }
1239
1240 /**
1241  * gst_tag_list_foreach:
1242  * @list: list to iterate over
1243  * @func: (scope call): function to be called for each tag
1244  * @user_data: (closure): user specified data
1245  *
1246  * Calls the given function for each tag inside the tag list. Note that if there
1247  * is no tag, the function won't be called at all.
1248  */
1249 void
1250 gst_tag_list_foreach (const GstTagList * list, GstTagForeachFunc func,
1251     gpointer user_data)
1252 {
1253   TagForeachData data;
1254
1255   g_return_if_fail (GST_IS_TAG_LIST (list));
1256   g_return_if_fail (func != NULL);
1257
1258   data.func = func;
1259   data.tag_list = list;
1260   data.data = user_data;
1261   gst_structure_foreach ((GstStructure *) list, structure_foreach_wrapper,
1262       &data);
1263 }
1264
1265 /**
1266  * gst_tag_list_get_value_index:
1267  * @list: a #GstTagList
1268  * @tag: tag to read out
1269  * @index: number of entry to read out
1270  *
1271  * Gets the value that is at the given index for the given tag in the given
1272  * list.
1273  *
1274  * Returns: (transfer none): The GValue for the specified entry or NULL if the
1275  *          tag wasn't available or the tag doesn't have as many entries
1276  */
1277 const GValue *
1278 gst_tag_list_get_value_index (const GstTagList * list, const gchar * tag,
1279     guint index)
1280 {
1281   const GValue *value;
1282
1283   g_return_val_if_fail (GST_IS_TAG_LIST (list), NULL);
1284   g_return_val_if_fail (tag != NULL, NULL);
1285
1286   value = gst_structure_get_value ((GstStructure *) list, tag);
1287   if (value == NULL)
1288     return NULL;
1289
1290   if (GST_VALUE_HOLDS_LIST (value)) {
1291     if (index >= gst_value_list_get_size (value))
1292       return NULL;
1293     return gst_value_list_get_value (value, index);
1294   } else {
1295     if (index > 0)
1296       return NULL;
1297     return value;
1298   }
1299 }
1300
1301 /**
1302  * gst_tag_list_copy_value:
1303  * @dest: (out caller-allocates): uninitialized #GValue to copy into
1304  * @list: list to get the tag from
1305  * @tag: tag to read out
1306  *
1307  * Copies the contents for the given tag into the value,
1308  * merging multiple values into one if multiple values are associated
1309  * with the tag.
1310  * You must g_value_unset() the value after use.
1311  *
1312  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1313  *          given list.
1314  */
1315 gboolean
1316 gst_tag_list_copy_value (GValue * dest, const GstTagList * list,
1317     const gchar * tag)
1318 {
1319   const GValue *src;
1320
1321   g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1322   g_return_val_if_fail (tag != NULL, FALSE);
1323   g_return_val_if_fail (dest != NULL, FALSE);
1324   g_return_val_if_fail (G_VALUE_TYPE (dest) == 0, FALSE);
1325
1326   src = gst_structure_get_value ((GstStructure *) list, tag);
1327   if (!src)
1328     return FALSE;
1329
1330   if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
1331     GstTagInfo *info = gst_tag_lookup (tag);
1332
1333     if (!info)
1334       return FALSE;
1335
1336     /* must be there or lists aren't allowed */
1337     g_assert (info->merge_func);
1338     info->merge_func (dest, src);
1339   } else {
1340     g_value_init (dest, G_VALUE_TYPE (src));
1341     g_value_copy (src, dest);
1342   }
1343   return TRUE;
1344 }
1345
1346 /* FIXME 0.11: this whole merge function business is overdesigned, and the
1347  * _get_foo() API is misleading as well - how many application developers will
1348  * expect gst_tag_list_get_string (list, GST_TAG_ARTIST, &val) might return a
1349  * string with multiple comma-separated artists? _get_foo() should just be
1350  * a convenience wrapper around _get_foo_index (list, tag, 0, &val),
1351  * supplemented by a special _tag_list_get_string_merged() function if needed
1352  * (unless someone can actually think of real use cases where the merge
1353  * function is not 'use first' for non-strings and merge for strings) */
1354
1355 /***** evil macros to get all the gst_tag_list_get_*() functions right *****/
1356
1357 #define TAG_MERGE_FUNCS(name,type,ret)                                  \
1358 gboolean                                                                \
1359 gst_tag_list_get_ ## name (const GstTagList *list, const gchar *tag,    \
1360                            type *value)                                 \
1361 {                                                                       \
1362   GValue v = { 0, };                                                    \
1363                                                                         \
1364   g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);                 \
1365   g_return_val_if_fail (tag != NULL, FALSE);                            \
1366   g_return_val_if_fail (value != NULL, FALSE);                          \
1367                                                                         \
1368   if (!gst_tag_list_copy_value (&v, list, tag))                         \
1369       return FALSE;                                                     \
1370   *value = COPY_FUNC (g_value_get_ ## name (&v));                       \
1371   g_value_unset (&v);                                                   \
1372   return ret;                                                           \
1373 }                                                                       \
1374                                                                         \
1375 gboolean                                                                \
1376 gst_tag_list_get_ ## name ## _index (const GstTagList *list,            \
1377                                      const gchar *tag,                  \
1378                                      guint index, type *value)          \
1379 {                                                                       \
1380   const GValue *v;                                                      \
1381                                                                         \
1382   g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);                 \
1383   g_return_val_if_fail (tag != NULL, FALSE);                            \
1384   g_return_val_if_fail (value != NULL, FALSE);                          \
1385                                                                         \
1386   if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)    \
1387       return FALSE;                                                     \
1388   *value = COPY_FUNC (g_value_get_ ## name (v));                        \
1389   return ret;                                                           \
1390 }
1391
1392 /* FIXME 0.11: maybe get rid of _get_char*(), _get_uchar*(), _get_long*(),
1393  * _get_ulong*() and _get_pointer*()? - they are not really useful/common
1394  * enough to warrant convenience accessor functions */
1395
1396 #define COPY_FUNC /**/
1397 /**
1398  * gst_tag_list_get_char:
1399  * @list: a #GstTagList to get the tag from
1400  * @tag: tag to read out
1401  * @value: (out): location for the result
1402  *
1403  * Copies the contents for the given tag into the value, merging multiple values
1404  * into one if multiple values are associated with the tag.
1405  *
1406  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1407  *              given list.
1408  */
1409 /**
1410  * gst_tag_list_get_char_index:
1411  * @list: a #GstTagList to get the tag from
1412  * @tag: tag to read out
1413  * @index: number of entry to read out
1414  * @value: (out): location for the result
1415  *
1416  * Gets the value that is at the given index for the given tag in the given
1417  * list.
1418  *
1419  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1420  *              given list.
1421  */
1422 TAG_MERGE_FUNCS (char, gchar, TRUE);
1423 /**
1424  * gst_tag_list_get_uchar:
1425  * @list: a #GstTagList to get the tag from
1426  * @tag: tag to read out
1427  * @value: (out): location for the result
1428  *
1429  * Copies the contents for the given tag into the value, merging multiple values
1430  * into one if multiple values are associated with the tag.
1431  *
1432  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1433  *              given list.
1434  */
1435 /**
1436  * gst_tag_list_get_uchar_index:
1437  * @list: a #GstTagList to get the tag from
1438  * @tag: tag to read out
1439  * @index: number of entry to read out
1440  * @value: (out): location for the result
1441  *
1442  * Gets the value that is at the given index for the given tag in the given
1443  * list.
1444  *
1445  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1446  *              given list.
1447  */
1448 TAG_MERGE_FUNCS (uchar, guchar, TRUE);
1449 /**
1450  * gst_tag_list_get_boolean:
1451  * @list: a #GstTagList to get the tag from
1452  * @tag: tag to read out
1453  * @value: (out): location for the result
1454  *
1455  * Copies the contents for the given tag into the value, merging multiple values
1456  * into one if multiple values are associated with the tag.
1457  *
1458  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1459  *              given list.
1460  */
1461 /**
1462  * gst_tag_list_get_boolean_index:
1463  * @list: a #GstTagList to get the tag from
1464  * @tag: tag to read out
1465  * @index: number of entry to read out
1466  * @value: (out): location for the result
1467  *
1468  * Gets the value that is at the given index for the given tag in the given
1469  * list.
1470  *
1471  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1472  *              given list.
1473  */
1474 TAG_MERGE_FUNCS (boolean, gboolean, TRUE);
1475 /**
1476  * gst_tag_list_get_int:
1477  * @list: a #GstTagList to get the tag from
1478  * @tag: tag to read out
1479  * @value: (out): location for the result
1480  *
1481  * Copies the contents for the given tag into the value, merging multiple values
1482  * into one if multiple values are associated with the tag.
1483  *
1484  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1485  *              given list.
1486  */
1487 /**
1488  * gst_tag_list_get_int_index:
1489  * @list: a #GstTagList to get the tag from
1490  * @tag: tag to read out
1491  * @index: number of entry to read out
1492  * @value: (out): location for the result
1493  *
1494  * Gets the value that is at the given index for the given tag in the given
1495  * list.
1496  *
1497  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1498  *              given list.
1499  */
1500 TAG_MERGE_FUNCS (int, gint, TRUE);
1501 /**
1502  * gst_tag_list_get_uint:
1503  * @list: a #GstTagList to get the tag from
1504  * @tag: tag to read out
1505  * @value: (out): location for the result
1506  *
1507  * Copies the contents for the given tag into the value, merging multiple values
1508  * into one if multiple values are associated with the tag.
1509  *
1510  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1511  *              given list.
1512  */
1513 /**
1514  * gst_tag_list_get_uint_index:
1515  * @list: a #GstTagList to get the tag from
1516  * @tag: tag to read out
1517  * @index: number of entry to read out
1518  * @value: (out): location for the result
1519  *
1520  * Gets the value that is at the given index for the given tag in the given
1521  * list.
1522  *
1523  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1524  *              given list.
1525  */
1526 TAG_MERGE_FUNCS (uint, guint, TRUE);
1527 /**
1528  * gst_tag_list_get_long:
1529  * @list: a #GstTagList to get the tag from
1530  * @tag: tag to read out
1531  * @value: (out): location for the result
1532  *
1533  * Copies the contents for the given tag into the value, merging multiple values
1534  * into one if multiple values are associated with the tag.
1535  *
1536  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1537  *              given list.
1538  */
1539 /**
1540  * gst_tag_list_get_long_index:
1541  * @list: a #GstTagList to get the tag from
1542  * @tag: tag to read out
1543  * @index: number of entry to read out
1544  * @value: (out): location for the result
1545  *
1546  * Gets the value that is at the given index for the given tag in the given
1547  * list.
1548  *
1549  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1550  *              given list.
1551  */
1552 TAG_MERGE_FUNCS (long, glong, TRUE);
1553 /**
1554  * gst_tag_list_get_ulong:
1555  * @list: a #GstTagList to get the tag from
1556  * @tag: tag to read out
1557  * @value: (out): location for the result
1558  *
1559  * Copies the contents for the given tag into the value, merging multiple values
1560  * into one if multiple values are associated with the tag.
1561  *
1562  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1563  *              given list.
1564  */
1565 /**
1566  * gst_tag_list_get_ulong_index:
1567  * @list: a #GstTagList to get the tag from
1568  * @tag: tag to read out
1569  * @index: number of entry to read out
1570  * @value: (out): location for the result
1571  *
1572  * Gets the value that is at the given index for the given tag in the given
1573  * list.
1574  *
1575  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1576  *              given list.
1577  */
1578 TAG_MERGE_FUNCS (ulong, gulong, TRUE);
1579 /**
1580  * gst_tag_list_get_int64:
1581  * @list: a #GstTagList to get the tag from
1582  * @tag: tag to read out
1583  * @value: (out): location for the result
1584  *
1585  * Copies the contents for the given tag into the value, merging multiple values
1586  * into one if multiple values are associated with the tag.
1587  *
1588  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1589  *              given list.
1590  */
1591 /**
1592  * gst_tag_list_get_int64_index:
1593  * @list: a #GstTagList to get the tag from
1594  * @tag: tag to read out
1595  * @index: number of entry to read out
1596  * @value: (out): location for the result
1597  *
1598  * Gets the value that is at the given index for the given tag in the given
1599  * list.
1600  *
1601  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1602  *              given list.
1603  */
1604 TAG_MERGE_FUNCS (int64, gint64, TRUE);
1605 /**
1606  * gst_tag_list_get_uint64:
1607  * @list: a #GstTagList to get the tag from
1608  * @tag: tag to read out
1609  * @value: (out): location for the result
1610  *
1611  * Copies the contents for the given tag into the value, merging multiple values
1612  * into one if multiple values are associated with the tag.
1613  *
1614  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1615  *              given list.
1616  */
1617 /**
1618  * gst_tag_list_get_uint64_index:
1619  * @list: a #GstTagList to get the tag from
1620  * @tag: tag to read out
1621  * @index: number of entry to read out
1622  * @value: (out): location for the result
1623  *
1624  * Gets the value that is at the given index for the given tag in the given
1625  * list.
1626  *
1627  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1628  *              given list.
1629  */
1630 TAG_MERGE_FUNCS (uint64, guint64, TRUE);
1631 /**
1632  * gst_tag_list_get_float:
1633  * @list: a #GstTagList to get the tag from
1634  * @tag: tag to read out
1635  * @value: (out): location for the result
1636  *
1637  * Copies the contents for the given tag into the value, merging multiple values
1638  * into one if multiple values are associated with the tag.
1639  *
1640  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1641  *              given list.
1642  */
1643 /**
1644  * gst_tag_list_get_float_index:
1645  * @list: a #GstTagList to get the tag from
1646  * @tag: tag to read out
1647  * @index: number of entry to read out
1648  * @value: (out): location for the result
1649  *
1650  * Gets the value that is at the given index for the given tag in the given
1651  * list.
1652  *
1653  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1654  *              given list.
1655  */
1656 TAG_MERGE_FUNCS (float, gfloat, TRUE);
1657 /**
1658  * gst_tag_list_get_double:
1659  * @list: a #GstTagList to get the tag from
1660  * @tag: tag to read out
1661  * @value: (out): location for the result
1662  *
1663  * Copies the contents for the given tag into the value, merging multiple values
1664  * into one if multiple values are associated with the tag.
1665  *
1666  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1667  *              given list.
1668  */
1669 /**
1670  * gst_tag_list_get_double_index:
1671  * @list: a #GstTagList to get the tag from
1672  * @tag: tag to read out
1673  * @index: number of entry to read out
1674  * @value: (out): location for the result
1675  *
1676  * Gets the value that is at the given index for the given tag in the given
1677  * list.
1678  *
1679  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1680  *              given list.
1681  */
1682 TAG_MERGE_FUNCS (double, gdouble, TRUE);
1683 /**
1684  * gst_tag_list_get_pointer:
1685  * @list: a #GstTagList to get the tag from
1686  * @tag: tag to read out
1687  * @value: (out) (transfer none): location for the result
1688  *
1689  * Copies the contents for the given tag into the value, merging multiple values
1690  * into one if multiple values are associated with the tag.
1691  *
1692  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1693  *              given list.
1694  */
1695 /**
1696  * gst_tag_list_get_pointer_index:
1697  * @list: a #GstTagList to get the tag from
1698  * @tag: tag to read out
1699  * @index: number of entry to read out
1700  * @value: (out) (transfer none): location for the result
1701  *
1702  * Gets the value that is at the given index for the given tag in the given
1703  * list.
1704  *
1705  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1706  *              given list.
1707  */
1708 TAG_MERGE_FUNCS (pointer, gpointer, (*value != NULL));
1709
1710 static inline gchar *
1711 _gst_strdup0 (const gchar * s)
1712 {
1713   if (s == NULL || *s == '\0')
1714     return NULL;
1715
1716   return g_strdup (s);
1717 }
1718
1719 #undef COPY_FUNC
1720 #define COPY_FUNC _gst_strdup0
1721
1722 /**
1723  * gst_tag_list_get_string:
1724  * @list: a #GstTagList to get the tag from
1725  * @tag: tag to read out
1726  * @value: (out callee-allocates) (transfer full): location for the result
1727  *
1728  * Copies the contents for the given tag into the value, possibly merging
1729  * multiple values into one if multiple values are associated with the tag.
1730  *
1731  * Use gst_tag_list_get_string_index (list, tag, 0, value) if you want
1732  * to retrieve the first string associated with this tag unmodified.
1733  *
1734  * The resulting string in @value will be in UTF-8 encoding and should be
1735  * freed by the caller using g_free when no longer needed. Since 0.10.24 the
1736  * returned string is also guaranteed to be non-NULL and non-empty.
1737  *
1738  * Free-function: g_free
1739  *
1740  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1741  *              given list.
1742  */
1743 /**
1744  * gst_tag_list_get_string_index:
1745  * @list: a #GstTagList to get the tag from
1746  * @tag: tag to read out
1747  * @index: number of entry to read out
1748  * @value: (out callee-allocates) (transfer full): location for the result
1749  *
1750  * Gets the value that is at the given index for the given tag in the given
1751  * list.
1752  *
1753  * The resulting string in @value will be in UTF-8 encoding and should be
1754  * freed by the caller using g_free when no longer needed. Since 0.10.24 the
1755  * returned string is also guaranteed to be non-NULL and non-empty.
1756  *
1757  * Free-function: g_free
1758  *
1759  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1760  *              given list.
1761  */
1762 TAG_MERGE_FUNCS (string, gchar *, (*value != NULL));
1763
1764 /*
1765  *FIXME 0.11: Instead of _peek (non-copy) and _get (copy), we could have
1766  *            _get (non-copy) and _dup (copy) for strings, seems more
1767  *            widely used
1768  */
1769 /**
1770  * gst_tag_list_peek_string_index:
1771  * @list: a #GstTagList to get the tag from
1772  * @tag: tag to read out
1773  * @index: number of entry to read out
1774  * @value: (out) (transfer none): location for the result
1775  *
1776  * Peeks at the value that is at the given index for the given tag in the given
1777  * list.
1778  *
1779  * The resulting string in @value will be in UTF-8 encoding and doesn't need
1780  * to be freed by the caller. The returned string is also guaranteed to
1781  * be non-NULL and non-empty.
1782  *
1783  * Returns: TRUE, if a value was set, FALSE if the tag didn't exist in the
1784  *              given list.
1785  */
1786 gboolean
1787 gst_tag_list_peek_string_index (const GstTagList * list,
1788     const gchar * tag, guint index, const gchar ** value)
1789 {
1790   const GValue *v;
1791
1792   g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1793   g_return_val_if_fail (tag != NULL, FALSE);
1794   g_return_val_if_fail (value != NULL, FALSE);
1795
1796   if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)
1797     return FALSE;
1798   *value = g_value_get_string (v);
1799   return *value != NULL && **value != '\0';
1800 }
1801
1802 /**
1803  * gst_tag_list_get_date:
1804  * @list: a #GstTagList to get the tag from
1805  * @tag: tag to read out
1806  * @value: (out callee-allocates) (transfer full): address of a GDate pointer
1807  *     variable to store the result into
1808  *
1809  * Copies the first date for the given tag in the taglist into the variable
1810  * pointed to by @value. Free the date with g_date_free() when it is no longer
1811  * needed.
1812  *
1813  * Free-function: g_date_free
1814  *
1815  * Returns: TRUE, if a date was copied, FALSE if the tag didn't exist in the
1816  *              given list or if it was #NULL.
1817  */
1818 gboolean
1819 gst_tag_list_get_date (const GstTagList * list, const gchar * tag,
1820     GDate ** value)
1821 {
1822   GValue v = { 0, };
1823
1824   g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1825   g_return_val_if_fail (tag != NULL, FALSE);
1826   g_return_val_if_fail (value != NULL, FALSE);
1827
1828   if (!gst_tag_list_copy_value (&v, list, tag))
1829     return FALSE;
1830   *value = (GDate *) g_value_dup_boxed (&v);
1831   g_value_unset (&v);
1832   return (*value != NULL);
1833 }
1834
1835 /**
1836  * gst_tag_list_get_date_index:
1837  * @list: a #GstTagList to get the tag from
1838  * @tag: tag to read out
1839  * @index: number of entry to read out
1840  * @value: (out callee-allocates) (transfer full): location for the result
1841  *
1842  * Gets the date that is at the given index for the given tag in the given
1843  * list and copies it into the variable pointed to by @value. Free the date
1844  * with g_date_free() when it is no longer needed.
1845  *
1846  * Free-function: g_date_free
1847  *
1848  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1849  *              given list or if it was #NULL.
1850  */
1851 gboolean
1852 gst_tag_list_get_date_index (const GstTagList * list,
1853     const gchar * tag, guint index, GDate ** value)
1854 {
1855   const GValue *v;
1856
1857   g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1858   g_return_val_if_fail (tag != NULL, FALSE);
1859   g_return_val_if_fail (value != NULL, FALSE);
1860
1861   if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)
1862     return FALSE;
1863   *value = (GDate *) g_value_dup_boxed (v);
1864   return (*value != NULL);
1865 }
1866
1867 /**
1868  * gst_tag_list_get_date_time:
1869  * @list: a #GstTagList to get the tag from
1870  * @tag: tag to read out
1871  * @value: (out callee-allocates) (transfer full): address of a #GstDateTime
1872  *     pointer variable to store the result into
1873  *
1874  * Copies the first datetime for the given tag in the taglist into the variable
1875  * pointed to by @value. Unref the date with gst_date_time_unref() when
1876  * it is no longer needed.
1877  *
1878  * Free-function: gst_date_time_unref
1879  *
1880  * Returns: TRUE, if a datetime was copied, FALSE if the tag didn't exist in
1881  *              thegiven list or if it was #NULL.
1882  *
1883  * Since: 0.10.31
1884  */
1885 gboolean
1886 gst_tag_list_get_date_time (const GstTagList * list, const gchar * tag,
1887     GstDateTime ** value)
1888 {
1889   GValue v = { 0, };
1890
1891   g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1892   g_return_val_if_fail (tag != NULL, FALSE);
1893   g_return_val_if_fail (value != NULL, FALSE);
1894
1895   if (!gst_tag_list_copy_value (&v, list, tag))
1896     return FALSE;
1897
1898   g_return_val_if_fail (GST_VALUE_HOLDS_DATE_TIME (&v), FALSE);
1899
1900   *value = (GstDateTime *) g_value_dup_boxed (&v);
1901   g_value_unset (&v);
1902   return (*value != NULL);
1903 }
1904
1905 /**
1906  * gst_tag_list_get_date_time_index:
1907  * @list: a #GstTagList to get the tag from
1908  * @tag: tag to read out
1909  * @index: number of entry to read out
1910  * @value: (out callee-allocates) (transfer full): location for the result
1911  *
1912  * Gets the datetime that is at the given index for the given tag in the given
1913  * list and copies it into the variable pointed to by @value. Unref the datetime
1914  * with gst_date_time_unref() when it is no longer needed.
1915  *
1916  * Free-function: gst_date_time_unref
1917  *
1918  * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1919  *              given list or if it was #NULL.
1920  *
1921  * Since: 0.10.31
1922  */
1923 gboolean
1924 gst_tag_list_get_date_time_index (const GstTagList * list,
1925     const gchar * tag, guint index, GstDateTime ** value)
1926 {
1927   const GValue *v;
1928
1929   g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1930   g_return_val_if_fail (tag != NULL, FALSE);
1931   g_return_val_if_fail (value != NULL, FALSE);
1932
1933   if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)
1934     return FALSE;
1935   *value = (GstDateTime *) g_value_dup_boxed (v);
1936   return (*value != NULL);
1937 }
1938
1939 /**
1940  * gst_tag_list_get_buffer:
1941  * @list: a #GstTagList to get the tag from
1942  * @tag: tag to read out
1943  * @value: (out callee-allocates) (transfer full): address of a GstBuffer
1944  *     pointer variable to store the result into
1945  *
1946  * Copies the first buffer for the given tag in the taglist into the variable
1947  * pointed to by @value. Free the buffer with gst_buffer_unref() when it is
1948  * no longer needed.
1949  *
1950  * Free-function: gst_buffer_unref
1951  *
1952  * Returns: TRUE, if a buffer was copied, FALSE if the tag didn't exist in the
1953  *              given list or if it was #NULL.
1954  *
1955  * Since: 0.10.23
1956  */
1957 gboolean
1958 gst_tag_list_get_buffer (const GstTagList * list, const gchar * tag,
1959     GstBuffer ** value)
1960 {
1961   GValue v = { 0, };
1962
1963   g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1964   g_return_val_if_fail (tag != NULL, FALSE);
1965   g_return_val_if_fail (value != NULL, FALSE);
1966
1967   if (!gst_tag_list_copy_value (&v, list, tag))
1968     return FALSE;
1969   *value = (GstBuffer *) gst_value_dup_mini_object (&v);
1970   g_value_unset (&v);
1971   return (*value != NULL);
1972 }
1973
1974 /**
1975  * gst_tag_list_get_buffer_index:
1976  * @list: a #GstTagList to get the tag from
1977  * @tag: tag to read out
1978  * @index: number of entry to read out
1979  * @value: (out callee-allocates) (transfer full): address of a GstBuffer
1980  *     pointer variable to store the result into
1981  *
1982  * Gets the buffer that is at the given index for the given tag in the given
1983  * list and copies it into the variable pointed to by @value. Free the buffer
1984  * with gst_buffer_unref() when it is no longer needed.
1985  *
1986  * Free-function: gst_buffer_unref
1987  *
1988  * Returns: TRUE, if a buffer was copied, FALSE if the tag didn't exist in the
1989  *              given list or if it was #NULL.
1990  *
1991  * Since: 0.10.23
1992  */
1993 gboolean
1994 gst_tag_list_get_buffer_index (const GstTagList * list,
1995     const gchar * tag, guint index, GstBuffer ** value)
1996 {
1997   const GValue *v;
1998
1999   g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
2000   g_return_val_if_fail (tag != NULL, FALSE);
2001   g_return_val_if_fail (value != NULL, FALSE);
2002
2003   if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)
2004     return FALSE;
2005   *value = (GstBuffer *) gst_value_dup_mini_object (v);
2006   return (*value != NULL);
2007 }