2 * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
4 * gsttaglist.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.
24 * @short_description: List of tags and values used to describe media metadata
26 * List of tags and values used to describe media metadata.
28 * Strings must be in ASCII or UTF-8 encoding. No other encodings are allowed.
30 * Last reviewed on 2009-06-09 (0.10.23)
37 #include "gst_private.h"
38 #include "math-compat.h"
39 #include "gst-i18n-lib.h"
40 #include "gsttaglist.h"
43 #include "gstbuffer.h"
45 #include "gststructure.h"
47 #include <gobject/gvaluecollector.h>
50 /* FIXME: add category for tags */
51 #define GST_CAT_TAGS GST_CAT_DEFAULT
53 #define GST_TAG_IS_VALID(tag) (gst_tag_get_info (tag) != NULL)
55 /* FIXME 0.11: make taglists refcounted maybe? */
56 /* a tag list is basically a structure, but we don't make this fact public */
57 typedef struct _GstTagListImpl
61 GstStructure *structure;
64 #define GST_TAG_LIST_STRUCTURE(taglist) ((GstTagListImpl*)(taglist))->structure
67 /* FIXME 0.11: use GParamSpecs or something similar for tag registrations,
68 * possibly even gst_tag_register(). Especially value ranges might be
69 * useful for some tags. */
73 GType type; /* type the data is in */
75 const gchar *nick; /* translated short description */
76 const gchar *blurb; /* translated long description */
78 GstTagMergeFunc merge_func; /* functions to merge the values */
79 GstTagFlag flag; /* type of tag */
80 GQuark name_quark; /* quark for the name */
84 #define g_value_get_char g_value_get_schar
86 static GMutex __tag_mutex;
87 #define TAG_LOCK g_mutex_lock (&__tag_mutex)
88 #define TAG_UNLOCK g_mutex_unlock (&__tag_mutex)
90 /* tags hash table: maps tag name string => GstTagInfo */
91 static GHashTable *__tags;
93 GST_DEFINE_MINI_OBJECT_TYPE (GstTagList, gst_tag_list);
95 static void __gst_tag_list_free (GstTagList * list);
96 static GstTagList *__gst_tag_list_copy (const GstTagList * list);
99 * g_value_register_transform_func (_gst_tag_list_type, G_TYPE_STRING,
100 * _gst_structure_transform_to_string);
103 _priv_gst_tag_initialize (void)
105 g_mutex_init (&__tag_mutex);
107 __tags = g_hash_table_new (g_str_hash, g_str_equal);
108 gst_tag_register_static (GST_TAG_TITLE, GST_TAG_FLAG_META,
110 _("title"), _("commonly used title"), gst_tag_merge_strings_with_comma);
111 gst_tag_register_static (GST_TAG_TITLE_SORTNAME, GST_TAG_FLAG_META,
113 _("title sortname"), _("commonly used title for sorting purposes"), NULL);
114 gst_tag_register_static (GST_TAG_ARTIST, GST_TAG_FLAG_META,
117 _("person(s) responsible for the recording"),
118 gst_tag_merge_strings_with_comma);
119 gst_tag_register_static (GST_TAG_ARTIST_SORTNAME, GST_TAG_FLAG_META,
121 _("artist sortname"),
122 _("person(s) responsible for the recording for sorting purposes"), NULL);
123 gst_tag_register_static (GST_TAG_ALBUM, GST_TAG_FLAG_META,
126 _("album containing this data"), gst_tag_merge_strings_with_comma);
127 gst_tag_register_static (GST_TAG_ALBUM_SORTNAME, GST_TAG_FLAG_META,
130 _("album containing this data for sorting purposes"), NULL);
131 gst_tag_register_static (GST_TAG_ALBUM_ARTIST, GST_TAG_FLAG_META,
134 _("The artist of the entire album, as it should be displayed"),
135 gst_tag_merge_strings_with_comma);
136 gst_tag_register_static (GST_TAG_ALBUM_ARTIST_SORTNAME, GST_TAG_FLAG_META,
138 _("album artist sortname"),
139 _("The artist of the entire album, as it should be sorted"), NULL);
140 gst_tag_register_static (GST_TAG_DATE, GST_TAG_FLAG_META, G_TYPE_DATE,
141 _("date"), _("date the data was created (as a GDate structure)"), NULL);
142 gst_tag_register_static (GST_TAG_DATE_TIME, GST_TAG_FLAG_META,
143 GST_TYPE_DATE_TIME, _("datetime"),
144 _("date and time the data was created (as a GstDateTime structure)"),
146 gst_tag_register_static (GST_TAG_GENRE, GST_TAG_FLAG_META,
149 _("genre this data belongs to"), gst_tag_merge_strings_with_comma);
150 gst_tag_register_static (GST_TAG_COMMENT, GST_TAG_FLAG_META,
153 _("free text commenting the data"), gst_tag_merge_use_first);
154 gst_tag_register_static (GST_TAG_EXTENDED_COMMENT, GST_TAG_FLAG_META,
156 _("extended comment"),
157 _("free text commenting the data in key=value or key[en]=comment form"),
158 gst_tag_merge_use_first);
159 gst_tag_register_static (GST_TAG_TRACK_NUMBER, GST_TAG_FLAG_META,
162 _("track number inside a collection"), gst_tag_merge_use_first);
163 gst_tag_register_static (GST_TAG_TRACK_COUNT, GST_TAG_FLAG_META,
166 _("count of tracks inside collection this track belongs to"),
167 gst_tag_merge_use_first);
168 gst_tag_register_static (GST_TAG_ALBUM_VOLUME_NUMBER, GST_TAG_FLAG_META,
171 _("disc number inside a collection"), gst_tag_merge_use_first);
172 gst_tag_register_static (GST_TAG_ALBUM_VOLUME_COUNT, GST_TAG_FLAG_META,
175 _("count of discs inside collection this disc belongs to"),
176 gst_tag_merge_use_first);
177 gst_tag_register_static (GST_TAG_LOCATION, GST_TAG_FLAG_META,
179 _("location"), _("Origin of media as a URI (location, where the "
180 "original of the file or stream is hosted)"),
181 gst_tag_merge_strings_with_comma);
182 gst_tag_register_static (GST_TAG_HOMEPAGE, GST_TAG_FLAG_META,
185 _("Homepage for this media (i.e. artist or movie homepage)"),
186 gst_tag_merge_strings_with_comma);
187 gst_tag_register_static (GST_TAG_DESCRIPTION, GST_TAG_FLAG_META,
188 G_TYPE_STRING, _("description"),
189 _("short text describing the content of the data"),
190 gst_tag_merge_strings_with_comma);
191 gst_tag_register_static (GST_TAG_VERSION, GST_TAG_FLAG_META, G_TYPE_STRING,
192 _("version"), _("version of this data"), NULL);
193 gst_tag_register_static (GST_TAG_ISRC, GST_TAG_FLAG_META, G_TYPE_STRING,
196 ("International Standard Recording Code - see http://www.ifpi.org/isrc/"),
198 /* FIXME: organization (fix what? tpm) */
199 gst_tag_register_static (GST_TAG_ORGANIZATION, GST_TAG_FLAG_META,
200 G_TYPE_STRING, _("organization"), _("organization"),
201 gst_tag_merge_strings_with_comma);
202 gst_tag_register_static (GST_TAG_COPYRIGHT, GST_TAG_FLAG_META,
203 G_TYPE_STRING, _("copyright"), _("copyright notice of the data"), NULL);
204 gst_tag_register_static (GST_TAG_COPYRIGHT_URI, GST_TAG_FLAG_META,
205 G_TYPE_STRING, _("copyright uri"),
206 _("URI to the copyright notice of the data"), NULL);
207 gst_tag_register_static (GST_TAG_ENCODED_BY, GST_TAG_FLAG_META, G_TYPE_STRING,
208 _("encoded by"), _("name of the encoding person or organization"),
209 gst_tag_merge_strings_with_comma);
210 gst_tag_register_static (GST_TAG_CONTACT, GST_TAG_FLAG_META,
212 _("contact"), _("contact information"), gst_tag_merge_strings_with_comma);
213 gst_tag_register_static (GST_TAG_LICENSE, GST_TAG_FLAG_META,
214 G_TYPE_STRING, _("license"), _("license of data"), NULL);
215 gst_tag_register_static (GST_TAG_LICENSE_URI, GST_TAG_FLAG_META,
216 G_TYPE_STRING, _("license uri"),
217 _("URI to the license of the data"), NULL);
218 gst_tag_register_static (GST_TAG_PERFORMER, GST_TAG_FLAG_META,
221 _("person(s) performing"), gst_tag_merge_strings_with_comma);
222 gst_tag_register_static (GST_TAG_COMPOSER, GST_TAG_FLAG_META,
225 _("person(s) who composed the recording"),
226 gst_tag_merge_strings_with_comma);
227 gst_tag_register_static (GST_TAG_DURATION, GST_TAG_FLAG_DECODED,
229 _("duration"), _("length in GStreamer time units (nanoseconds)"), NULL);
230 gst_tag_register_static (GST_TAG_CODEC, GST_TAG_FLAG_ENCODED,
233 _("codec the data is stored in"), gst_tag_merge_strings_with_comma);
234 gst_tag_register_static (GST_TAG_VIDEO_CODEC, GST_TAG_FLAG_ENCODED,
236 _("video codec"), _("codec the video data is stored in"), NULL);
237 gst_tag_register_static (GST_TAG_AUDIO_CODEC, GST_TAG_FLAG_ENCODED,
239 _("audio codec"), _("codec the audio data is stored in"), NULL);
240 gst_tag_register_static (GST_TAG_SUBTITLE_CODEC, GST_TAG_FLAG_ENCODED,
242 _("subtitle codec"), _("codec the subtitle data is stored in"), NULL);
243 gst_tag_register_static (GST_TAG_CONTAINER_FORMAT, GST_TAG_FLAG_ENCODED,
244 G_TYPE_STRING, _("container format"),
245 _("container format the data is stored in"), NULL);
246 gst_tag_register_static (GST_TAG_BITRATE, GST_TAG_FLAG_ENCODED,
247 G_TYPE_UINT, _("bitrate"), _("exact or average bitrate in bits/s"), NULL);
248 gst_tag_register_static (GST_TAG_NOMINAL_BITRATE, GST_TAG_FLAG_ENCODED,
249 G_TYPE_UINT, _("nominal bitrate"), _("nominal bitrate in bits/s"), NULL);
250 gst_tag_register_static (GST_TAG_MINIMUM_BITRATE, GST_TAG_FLAG_ENCODED,
251 G_TYPE_UINT, _("minimum bitrate"), _("minimum bitrate in bits/s"), NULL);
252 gst_tag_register_static (GST_TAG_MAXIMUM_BITRATE, GST_TAG_FLAG_ENCODED,
253 G_TYPE_UINT, _("maximum bitrate"), _("maximum bitrate in bits/s"), NULL);
254 gst_tag_register_static (GST_TAG_ENCODER, GST_TAG_FLAG_ENCODED,
256 _("encoder"), _("encoder used to encode this stream"), NULL);
257 gst_tag_register_static (GST_TAG_ENCODER_VERSION, GST_TAG_FLAG_ENCODED,
259 _("encoder version"),
260 _("version of the encoder used to encode this stream"), NULL);
261 gst_tag_register_static (GST_TAG_SERIAL, GST_TAG_FLAG_ENCODED,
262 G_TYPE_UINT, _("serial"), _("serial number of track"), NULL);
263 gst_tag_register_static (GST_TAG_TRACK_GAIN, GST_TAG_FLAG_META,
264 G_TYPE_DOUBLE, _("replaygain track gain"), _("track gain in db"), NULL);
265 gst_tag_register_static (GST_TAG_TRACK_PEAK, GST_TAG_FLAG_META,
266 G_TYPE_DOUBLE, _("replaygain track peak"), _("peak of the track"), NULL);
267 gst_tag_register_static (GST_TAG_ALBUM_GAIN, GST_TAG_FLAG_META,
268 G_TYPE_DOUBLE, _("replaygain album gain"), _("album gain in db"), NULL);
269 gst_tag_register_static (GST_TAG_ALBUM_PEAK, GST_TAG_FLAG_META,
270 G_TYPE_DOUBLE, _("replaygain album peak"), _("peak of the album"), NULL);
271 gst_tag_register_static (GST_TAG_REFERENCE_LEVEL, GST_TAG_FLAG_META,
272 G_TYPE_DOUBLE, _("replaygain reference level"),
273 _("reference level of track and album gain values"), NULL);
274 gst_tag_register_static (GST_TAG_LANGUAGE_CODE, GST_TAG_FLAG_META,
275 G_TYPE_STRING, _("language code"),
276 _("language code for this stream, conforming to ISO-639-1 or ISO-639-2"),
278 gst_tag_register_static (GST_TAG_LANGUAGE_NAME, GST_TAG_FLAG_META,
279 G_TYPE_STRING, _("language name"),
280 _("freeform name of the language this stream is in"), NULL);
281 gst_tag_register_static (GST_TAG_IMAGE, GST_TAG_FLAG_META, GST_TYPE_SAMPLE,
282 _("image"), _("image related to this stream"), gst_tag_merge_use_first);
283 gst_tag_register_static (GST_TAG_PREVIEW_IMAGE, GST_TAG_FLAG_META,
285 /* TRANSLATORS: 'preview image' = image that shows a preview of the full image */
286 _("preview image"), _("preview image related to this stream"), NULL);
287 gst_tag_register_static (GST_TAG_ATTACHMENT, GST_TAG_FLAG_META,
288 GST_TYPE_SAMPLE, _("attachment"), _("file attached to this stream"),
289 gst_tag_merge_use_first);
290 gst_tag_register_static (GST_TAG_BEATS_PER_MINUTE, GST_TAG_FLAG_META,
291 G_TYPE_DOUBLE, _("beats per minute"),
292 _("number of beats per minute in audio"), NULL);
293 gst_tag_register_static (GST_TAG_KEYWORDS, GST_TAG_FLAG_META, G_TYPE_STRING,
294 _("keywords"), _("comma separated keywords describing the content"),
295 gst_tag_merge_strings_with_comma);
296 gst_tag_register_static (GST_TAG_GEO_LOCATION_NAME, GST_TAG_FLAG_META,
297 G_TYPE_STRING, _("geo location name"),
298 _("human readable descriptive location of where "
299 "the media has been recorded or produced"), NULL);
300 gst_tag_register_static (GST_TAG_GEO_LOCATION_LATITUDE, GST_TAG_FLAG_META,
301 G_TYPE_DOUBLE, _("geo location latitude"),
302 _("geo latitude location of where the media has been recorded or "
303 "produced in degrees according to WGS84 (zero at the equator, "
304 "negative values for southern latitudes)"), NULL);
305 gst_tag_register_static (GST_TAG_GEO_LOCATION_LONGITUDE, GST_TAG_FLAG_META,
306 G_TYPE_DOUBLE, _("geo location longitude"),
307 _("geo longitude location of where the media has been recorded or "
308 "produced in degrees according to WGS84 (zero at the prime meridian "
309 "in Greenwich/UK, negative values for western longitudes)"), NULL);
310 gst_tag_register_static (GST_TAG_GEO_LOCATION_ELEVATION, GST_TAG_FLAG_META,
311 G_TYPE_DOUBLE, _("geo location elevation"),
312 _("geo elevation of where the media has been recorded or produced in "
313 "meters according to WGS84 (zero is average sea level)"), NULL);
314 gst_tag_register_static (GST_TAG_GEO_LOCATION_COUNTRY, GST_TAG_FLAG_META,
315 G_TYPE_STRING, _("geo location country"),
316 _("country (english name) where the media has been recorded "
317 "or produced"), NULL);
318 gst_tag_register_static (GST_TAG_GEO_LOCATION_CITY, GST_TAG_FLAG_META,
319 G_TYPE_STRING, _("geo location city"),
320 _("city (english name) where the media has been recorded "
321 "or produced"), NULL);
322 gst_tag_register_static (GST_TAG_GEO_LOCATION_SUBLOCATION, GST_TAG_FLAG_META,
323 G_TYPE_STRING, _("geo location sublocation"),
324 _("a location whithin a city where the media has been produced "
325 "or created (e.g. the neighborhood)"), NULL);
326 gst_tag_register_static (GST_TAG_GEO_LOCATION_HORIZONTAL_ERROR,
327 GST_TAG_FLAG_META, G_TYPE_DOUBLE, _("geo location horizontal error"),
328 _("expected error of the horizontal positioning measures (in meters)"),
330 gst_tag_register_static (GST_TAG_GEO_LOCATION_MOVEMENT_SPEED,
331 GST_TAG_FLAG_META, G_TYPE_DOUBLE, _("geo location movement speed"),
332 _("movement speed of the capturing device while performing the capture "
334 gst_tag_register_static (GST_TAG_GEO_LOCATION_MOVEMENT_DIRECTION,
335 GST_TAG_FLAG_META, G_TYPE_DOUBLE, _("geo location movement direction"),
336 _("indicates the movement direction of the device performing the capture"
337 " of a media. It is represented as degrees in floating point "
338 "representation, 0 means the geographic north, and increases "
340 gst_tag_register_static (GST_TAG_GEO_LOCATION_CAPTURE_DIRECTION,
341 GST_TAG_FLAG_META, G_TYPE_DOUBLE, _("geo location capture direction"),
342 _("indicates the direction the device is pointing to when capturing "
343 " a media. It is represented as degrees in floating point "
344 " representation, 0 means the geographic north, and increases "
346 gst_tag_register_static (GST_TAG_SHOW_NAME, GST_TAG_FLAG_META, G_TYPE_STRING,
347 /* TRANSLATORS: 'show name' = 'TV/radio/podcast show name' here */
349 _("Name of the tv/podcast/series show the media is from"),
350 gst_tag_merge_strings_with_comma);
351 gst_tag_register_static (GST_TAG_SHOW_SORTNAME, GST_TAG_FLAG_META,
353 /* TRANSLATORS: 'show sortname' = 'TV/radio/podcast show name as used for sorting purposes' here */
355 _("Name of the tv/podcast/series show the media is from, for sorting "
357 gst_tag_register_static (GST_TAG_SHOW_EPISODE_NUMBER, GST_TAG_FLAG_META,
358 G_TYPE_UINT, _("episode number"),
359 _("The episode number in the season the media is part of"),
360 gst_tag_merge_use_first);
361 gst_tag_register_static (GST_TAG_SHOW_SEASON_NUMBER, GST_TAG_FLAG_META,
362 G_TYPE_UINT, _("season number"),
363 _("The season number of the show the media is part of"),
364 gst_tag_merge_use_first);
365 gst_tag_register_static (GST_TAG_LYRICS, GST_TAG_FLAG_META, G_TYPE_STRING,
366 _("lyrics"), _("The lyrics of the media, commonly used for songs"),
367 gst_tag_merge_strings_with_comma);
368 gst_tag_register_static (GST_TAG_COMPOSER_SORTNAME, GST_TAG_FLAG_META,
369 G_TYPE_STRING, _("composer sortname"),
370 _("person(s) who composed the recording, for sorting purposes"), NULL);
371 gst_tag_register_static (GST_TAG_GROUPING, GST_TAG_FLAG_META, G_TYPE_STRING,
373 _("Groups related media that spans multiple tracks, like the different "
374 "pieces of a concerto. It is a higher level than a track, "
375 "but lower than an album"), NULL);
376 gst_tag_register_static (GST_TAG_USER_RATING, GST_TAG_FLAG_META, G_TYPE_UINT,
378 _("Rating attributed by a user. The higher the rank, "
379 "the more the user likes this media"), NULL);
380 gst_tag_register_static (GST_TAG_DEVICE_MANUFACTURER, GST_TAG_FLAG_META,
381 G_TYPE_STRING, _("device manufacturer"),
382 _("Manufacturer of the device used to create this media"), NULL);
383 gst_tag_register_static (GST_TAG_DEVICE_MODEL, GST_TAG_FLAG_META,
384 G_TYPE_STRING, _("device model"),
385 _("Model of the device used to create this media"), NULL);
386 gst_tag_register_static (GST_TAG_APPLICATION_NAME, GST_TAG_FLAG_META,
387 G_TYPE_STRING, _("application name"),
388 _("Application used to create the media"), NULL);
389 gst_tag_register_static (GST_TAG_APPLICATION_DATA, GST_TAG_FLAG_META,
390 GST_TYPE_BUFFER, _("application data"),
391 _("Arbitrary application data to be serialized into the media"), NULL);
392 gst_tag_register_static (GST_TAG_IMAGE_ORIENTATION, GST_TAG_FLAG_META,
393 G_TYPE_STRING, _("image orientation"),
394 _("How the image should be rotated or flipped before display"), NULL);
398 * gst_tag_merge_use_first:
399 * @dest: (out caller-allocates): uninitialized GValue to store result in
400 * @src: GValue to copy from
402 * This is a convenience function for the func argument of gst_tag_register().
403 * It creates a copy of the first value from the list.
406 gst_tag_merge_use_first (GValue * dest, const GValue * src)
408 const GValue *ret = gst_value_list_get_value (src, 0);
410 g_value_init (dest, G_VALUE_TYPE (ret));
411 g_value_copy (ret, dest);
415 * gst_tag_merge_strings_with_comma:
416 * @dest: (out caller-allocates): uninitialized GValue to store result in
417 * @src: GValue to copy from
419 * This is a convenience function for the func argument of gst_tag_register().
420 * It concatenates all given strings using a comma. The tag must be registered
421 * as a G_TYPE_STRING or this function will fail.
424 gst_tag_merge_strings_with_comma (GValue * dest, const GValue * src)
429 count = gst_value_list_get_size (src);
430 str = g_string_new (g_value_get_string (gst_value_list_get_value (src, 0)));
431 for (i = 1; i < count; i++) {
432 /* separator between two strings */
433 g_string_append (str, _(", "));
434 g_string_append (str,
435 g_value_get_string (gst_value_list_get_value (src, i)));
438 g_value_init (dest, G_TYPE_STRING);
439 g_value_take_string (dest, str->str);
440 g_string_free (str, FALSE);
444 gst_tag_lookup (const gchar * tag_name)
449 ret = g_hash_table_lookup (__tags, (gpointer) tag_name);
457 * @name: the name or identifier string
458 * @flag: a flag describing the type of tag info
459 * @type: the type this data is in
460 * @nick: human-readable name
461 * @blurb: a human-readable description about this tag
462 * @func: function for merging multiple values of this tag, or NULL
464 * Registers a new tag type for the use with GStreamer's type system. If a type
465 * with that name is already registered, that one is used.
466 * The old registration may have used a different type however. So don't rely
467 * on your supplied values.
469 * Important: if you do not supply a merge function the implication will be
470 * that there can only be one single value for this tag in a tag list and
471 * any additional values will silenty be discarded when being added (unless
472 * #GST_TAG_MERGE_REPLACE, #GST_TAG_MERGE_REPLACE_ALL, or
473 * #GST_TAG_MERGE_PREPEND is used as merge mode, in which case the new
474 * value will replace the old one in the list).
476 * The merge function will be called from gst_tag_list_copy_value() when
477 * it is required that one or more values for a tag be condensed into
478 * one single value. This may happen from gst_tag_list_get_string(),
479 * gst_tag_list_get_int(), gst_tag_list_get_double() etc. What will happen
480 * exactly in that case depends on how the tag was registered and if a
481 * merge function was supplied and if so which one.
483 * Two default merge functions are provided: gst_tag_merge_use_first() and
484 * gst_tag_merge_strings_with_comma().
487 gst_tag_register (const gchar * name, GstTagFlag flag, GType type,
488 const gchar * nick, const gchar * blurb, GstTagMergeFunc func)
490 g_return_if_fail (name != NULL);
491 g_return_if_fail (nick != NULL);
492 g_return_if_fail (blurb != NULL);
493 g_return_if_fail (type != 0 && type != GST_TYPE_LIST);
495 return gst_tag_register_static (g_intern_string (name), flag, type,
496 g_intern_string (nick), g_intern_string (blurb), func);
500 * gst_tag_register_static:
501 * @name: the name or identifier string (string constant)
502 * @flag: a flag describing the type of tag info
503 * @type: the type this data is in
504 * @nick: human-readable name or short description (string constant)
505 * @blurb: a human-readable description for this tag (string constant)
506 * @func: function for merging multiple values of this tag, or NULL
508 * Registers a new tag type for the use with GStreamer's type system.
510 * Same as gst_tag_register(), but @name, @nick, and @blurb must be
511 * static strings or inlined strings, as they will not be copied. (GStreamer
512 * plugins will be made resident once loaded, so this function can be used
513 * even from dynamically loaded plugins.)
516 gst_tag_register_static (const gchar * name, GstTagFlag flag, GType type,
517 const gchar * nick, const gchar * blurb, GstTagMergeFunc func)
521 g_return_if_fail (name != NULL);
522 g_return_if_fail (nick != NULL);
523 g_return_if_fail (blurb != NULL);
524 g_return_if_fail (type != 0 && type != GST_TYPE_LIST);
526 info = gst_tag_lookup (name);
529 g_return_if_fail (info->type == type);
533 info = g_slice_new (GstTagInfo);
536 info->name_quark = g_quark_from_static_string (name);
539 info->merge_func = func;
542 g_hash_table_insert (__tags, (gpointer) name, info);
548 * @tag: name of the tag
550 * Checks if the given type is already registered.
552 * Returns: TRUE if the type is already registered
555 gst_tag_exists (const gchar * tag)
557 g_return_val_if_fail (tag != NULL, FALSE);
559 return gst_tag_lookup (tag) != NULL;
566 * Gets the #GType used for this tag.
568 * Returns: the #GType of this tag
571 gst_tag_get_type (const gchar * tag)
575 g_return_val_if_fail (tag != NULL, 0);
576 info = gst_tag_lookup (tag);
577 g_return_val_if_fail (info != NULL, 0);
586 * Returns the human-readable name of this tag, You must not change or free
589 * Returns: the human-readable name of this tag
592 gst_tag_get_nick (const gchar * tag)
596 g_return_val_if_fail (tag != NULL, NULL);
597 info = gst_tag_lookup (tag);
598 g_return_val_if_fail (info != NULL, NULL);
604 * gst_tag_get_description:
607 * Returns the human-readable description of this tag, You must not change or
610 * Returns: the human-readable description of this tag
613 gst_tag_get_description (const gchar * tag)
617 g_return_val_if_fail (tag != NULL, NULL);
618 info = gst_tag_lookup (tag);
619 g_return_val_if_fail (info != NULL, NULL);
628 * Gets the flag of @tag.
630 * Returns: the flag of this tag.
633 gst_tag_get_flag (const gchar * tag)
637 g_return_val_if_fail (tag != NULL, GST_TAG_FLAG_UNDEFINED);
638 info = gst_tag_lookup (tag);
639 g_return_val_if_fail (info != NULL, GST_TAG_FLAG_UNDEFINED);
648 * Checks if the given tag is fixed. A fixed tag can only contain one value.
649 * Unfixed tags can contain lists of values.
651 * Returns: TRUE, if the given tag is fixed.
654 gst_tag_is_fixed (const gchar * tag)
658 g_return_val_if_fail (tag != NULL, FALSE);
659 info = gst_tag_lookup (tag);
660 g_return_val_if_fail (info != NULL, FALSE);
662 return info->merge_func == NULL;
666 gst_tag_list_init (GstTagList * taglist)
668 gst_mini_object_init (GST_MINI_OBJECT_CAST (taglist),
669 gst_tag_list_get_type ());
671 taglist->mini_object.copy = (GstMiniObjectCopyFunction) __gst_tag_list_copy;
672 taglist->mini_object.dispose = NULL;
673 taglist->mini_object.free = (GstMiniObjectFreeFunction) __gst_tag_list_free;
676 /* takes ownership of the structure */
678 gst_tag_list_new_internal (GstStructure * s)
680 GstTagList *tag_list;
682 g_assert (s != NULL);
684 tag_list = (GstTagList *) g_slice_new (GstTagListImpl);
686 gst_tag_list_init (tag_list);
688 GST_TAG_LIST_STRUCTURE (tag_list) = s;
690 #ifdef DEBUG_REFCOUNT
691 GST_CAT_TRACE (GST_CAT_TAGS, "created taglist %p", tag_list);
698 __gst_tag_list_free (GstTagList * list)
700 g_return_if_fail (GST_IS_TAG_LIST (list));
702 #ifdef DEBUG_REFCOUNT
703 GST_CAT_TRACE (GST_CAT_TAGS, "freeing caps %p", list);
706 gst_structure_free (GST_TAG_LIST_STRUCTURE (list));
708 g_slice_free1 (sizeof (GstTagListImpl), list);
712 __gst_tag_list_copy (const GstTagList * list)
714 const GstStructure *s;
716 g_return_val_if_fail (GST_IS_TAG_LIST (list), NULL);
718 s = GST_TAG_LIST_STRUCTURE (list);
719 return gst_tag_list_new_internal (gst_structure_copy (s));
723 * gst_tag_list_new_empty:
725 * Creates a new empty GstTagList.
727 * Free-function: gst_tag_list_unref
729 * Returns: (transfer full): An empty tag list
732 gst_tag_list_new_empty (void)
735 GstTagList *tag_list;
737 s = gst_structure_new_id_empty (GST_QUARK (TAGLIST));
738 tag_list = gst_tag_list_new_internal (s);
745 * @...: NULL-terminated list of values to set
747 * Creates a new taglist and appends the values for the given tags. It expects
748 * tag-value pairs like gst_tag_list_add(), and a NULL terminator after the
749 * last pair. The type of the values is implicit and is documented in the API
750 * reference, but can also be queried at runtime with gst_tag_get_type(). It
751 * is an error to pass a value of a type not matching the tag type into this
752 * function. The tag list will make copies of any arguments passed
753 * (e.g. strings, buffers).
755 * Free-function: gst_tag_list_unref
757 * Returns: (transfer full): a new #GstTagList. Free with gst_tag_list_unref()
758 * when no longer needed.
763 gst_tag_list_new (const gchar * tag, ...)
768 g_return_val_if_fail (tag != NULL, NULL);
770 list = gst_tag_list_new_empty ();
771 va_start (args, tag);
772 gst_tag_list_add_valist (list, GST_TAG_MERGE_APPEND, tag, args);
779 * gst_tag_list_new_valist:
780 * @var_args: tag / value pairs to set
782 * Just like gst_tag_list_new(), only that it takes a va_list argument.
783 * Useful mostly for language bindings.
785 * Free-function: gst_tag_list_unref
787 * Returns: (transfer full): a new #GstTagList. Free with gst_tag_list_unref()
788 * when no longer needed.
793 gst_tag_list_new_valist (va_list var_args)
798 list = gst_tag_list_new_empty ();
800 tag = va_arg (var_args, gchar *);
801 gst_tag_list_add_valist (list, GST_TAG_MERGE_APPEND, tag, var_args);
807 * gst_tag_list_to_string:
808 * @list: a #GstTagList
810 * Serializes a tag list to a string.
812 * Returns: a newly-allocated string, or NULL in case of an error. The
813 * string must be freed with g_free() when no longer needed.
818 gst_tag_list_to_string (const GstTagList * list)
820 g_return_val_if_fail (GST_IS_TAG_LIST (list), NULL);
822 return gst_structure_to_string (GST_TAG_LIST_STRUCTURE (list));
826 * gst_tag_list_new_from_string:
827 * @str: a string created with gst_tag_list_to_string()
829 * Deserializes a tag list.
831 * Returns: a new #GstTagList, or NULL in case of an error.
836 gst_tag_list_new_from_string (const gchar * str)
838 GstTagList *tag_list;
840 g_return_val_if_fail (str != NULL, NULL);
841 g_return_val_if_fail (g_str_has_prefix (str, "taglist"), NULL);
843 tag_list = gst_tag_list_new_internal (gst_structure_from_string (str, NULL));
848 * gst_tag_list_n_tags:
849 * @list: A #GstTagList.
851 * Get the number of tags in @list.
853 * Returns: The number of tags in @list.
856 gst_tag_list_n_tags (const GstTagList * list)
858 g_return_val_if_fail (list != NULL, 0);
859 g_return_val_if_fail (GST_IS_TAG_LIST (list), 0);
861 return gst_structure_n_fields (GST_TAG_LIST_STRUCTURE (list));
865 * gst_tag_list_nth_tag_name:
866 * @list: A #GstTagList.
869 * Get the name of the tag in @list at @index.
871 * Returns: The name of the tag at @index.
874 gst_tag_list_nth_tag_name (const GstTagList * list, guint index)
876 g_return_val_if_fail (list != NULL, 0);
877 g_return_val_if_fail (GST_IS_TAG_LIST (list), 0);
879 return gst_structure_nth_field_name (GST_TAG_LIST_STRUCTURE (list), index);
883 * gst_tag_list_is_empty:
884 * @list: A #GstTagList.
886 * Checks if the given taglist is empty.
888 * Returns: TRUE if the taglist is empty, otherwise FALSE.
893 gst_tag_list_is_empty (const GstTagList * list)
895 g_return_val_if_fail (list != NULL, FALSE);
896 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
898 return (gst_structure_n_fields (GST_TAG_LIST_STRUCTURE (list)) == 0);
902 gst_tag_list_fields_equal (const GValue * value1, const GValue * value2)
906 if (gst_value_compare (value1, value2) == GST_VALUE_EQUAL)
909 /* fields not equal: add some tolerance for doubles, otherwise bail out */
910 if (!G_VALUE_HOLDS_DOUBLE (value1) || !G_VALUE_HOLDS_DOUBLE (value2))
913 d1 = g_value_get_double (value1);
914 d2 = g_value_get_double (value2);
916 /* This will only work for 'normal' values and values around 0,
917 * which should be good enough for our purposes here
918 * FIXME: maybe add this to gst_value_compare_double() ? */
919 return (fabs (d1 - d2) < 0.0000001);
923 * gst_tag_list_is_equal:
924 * @list1: a #GstTagList.
925 * @list2: a #GstTagList.
927 * Checks if the two given taglists are equal.
929 * Returns: TRUE if the taglists are equal, otherwise FALSE
934 gst_tag_list_is_equal (const GstTagList * list1, const GstTagList * list2)
936 const GstStructure *s1, *s2;
937 gint num_fields1, num_fields2, i;
939 g_return_val_if_fail (GST_IS_TAG_LIST (list1), FALSE);
940 g_return_val_if_fail (GST_IS_TAG_LIST (list2), FALSE);
942 /* we don't just use gst_structure_is_equal() here so we can add some
943 * tolerance for doubles, though maybe we should just add that to
944 * gst_value_compare_double() as well? */
945 s1 = GST_TAG_LIST_STRUCTURE (list1);
946 s2 = GST_TAG_LIST_STRUCTURE (list2);
948 num_fields1 = gst_structure_n_fields (s1);
949 num_fields2 = gst_structure_n_fields (s2);
951 if (num_fields1 != num_fields2)
954 for (i = 0; i < num_fields1; i++) {
955 const GValue *value1, *value2;
956 const gchar *tag_name;
958 tag_name = gst_structure_nth_field_name (s1, i);
959 value1 = gst_structure_get_value (s1, tag_name);
960 value2 = gst_structure_get_value (s2, tag_name);
965 if (!gst_tag_list_fields_equal (value1, value2))
975 GstTagMergeMode mode;
980 gst_tag_list_add_value_internal (GstTagList * tag_list, GstTagMergeMode mode,
981 const gchar * tag, const GValue * value, GstTagInfo * info)
983 GstStructure *list = GST_TAG_LIST_STRUCTURE (tag_list);
984 const GValue *value2;
988 info = gst_tag_lookup (tag);
989 if (G_UNLIKELY (info == NULL)) {
990 g_warning ("unknown tag '%s'", tag);
995 tag_quark = info->name_quark;
998 && (value2 = gst_structure_id_get_value (list, tag_quark)) != NULL) {
999 GValue dest = { 0, };
1002 case GST_TAG_MERGE_REPLACE_ALL:
1003 case GST_TAG_MERGE_REPLACE:
1004 gst_structure_id_set_value (list, tag_quark, value);
1006 case GST_TAG_MERGE_PREPEND:
1007 gst_value_list_merge (&dest, value, value2);
1008 gst_structure_id_set_value (list, tag_quark, &dest);
1009 g_value_unset (&dest);
1011 case GST_TAG_MERGE_APPEND:
1012 gst_value_list_merge (&dest, value2, value);
1013 gst_structure_id_set_value (list, tag_quark, &dest);
1014 g_value_unset (&dest);
1016 case GST_TAG_MERGE_KEEP:
1017 case GST_TAG_MERGE_KEEP_ALL:
1020 g_assert_not_reached ();
1025 case GST_TAG_MERGE_APPEND:
1026 case GST_TAG_MERGE_KEEP:
1027 if (gst_structure_id_get_value (list, tag_quark) != NULL)
1030 case GST_TAG_MERGE_REPLACE_ALL:
1031 case GST_TAG_MERGE_REPLACE:
1032 case GST_TAG_MERGE_PREPEND:
1033 gst_structure_id_set_value (list, tag_quark, value);
1035 case GST_TAG_MERGE_KEEP_ALL:
1038 g_assert_not_reached ();
1045 gst_tag_list_copy_foreach (GQuark tag_quark, const GValue * value,
1048 GstTagCopyData *copy = (GstTagCopyData *) user_data;
1051 tag = g_quark_to_string (tag_quark);
1052 gst_tag_list_add_value_internal (copy->list, copy->mode, tag, value, NULL);
1058 * gst_tag_list_insert:
1059 * @into: list to merge into
1060 * @from: list to merge from
1061 * @mode: the mode to use
1063 * Inserts the tags of the @from list into the first list using the given mode.
1066 gst_tag_list_insert (GstTagList * into, const GstTagList * from,
1067 GstTagMergeMode mode)
1069 GstTagCopyData data;
1071 g_return_if_fail (GST_IS_TAG_LIST (into));
1072 g_return_if_fail (gst_tag_list_is_writable (into));
1073 g_return_if_fail (GST_IS_TAG_LIST (from));
1074 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1078 if (mode == GST_TAG_MERGE_REPLACE_ALL) {
1079 gst_structure_remove_all_fields (GST_TAG_LIST_STRUCTURE (into));
1081 gst_structure_foreach (GST_TAG_LIST_STRUCTURE (from),
1082 gst_tag_list_copy_foreach, &data);
1086 * gst_tag_list_merge:
1087 * @list1: first list to merge
1088 * @list2: second list to merge
1089 * @mode: the mode to use
1091 * Merges the two given lists into a new list. If one of the lists is NULL, a
1092 * copy of the other is returned. If both lists are NULL, NULL is returned.
1094 * Free-function: gst_tag_list_unref
1096 * Returns: (transfer full): the new list
1099 gst_tag_list_merge (const GstTagList * list1, const GstTagList * list2,
1100 GstTagMergeMode mode)
1102 GstTagList *list1_cp;
1103 const GstTagList *list2_cp;
1105 g_return_val_if_fail (list1 == NULL || GST_IS_TAG_LIST (list1), NULL);
1106 g_return_val_if_fail (list2 == NULL || GST_IS_TAG_LIST (list2), NULL);
1107 g_return_val_if_fail (GST_TAG_MODE_IS_VALID (mode), NULL);
1109 /* nothing to merge */
1110 if (!list1 && !list2) {
1114 /* create empty list, we need to do this to correctly handling merge modes */
1115 list1_cp = (list1) ? gst_tag_list_copy (list1) : gst_tag_list_new_empty ();
1116 list2_cp = (list2) ? list2 : gst_tag_list_new_empty ();
1118 gst_tag_list_insert (list1_cp, list2_cp, mode);
1121 gst_tag_list_unref ((GstTagList *) list2_cp);
1127 * gst_tag_list_get_tag_size:
1129 * @tag: the tag to query
1131 * Checks how many value are stored in this tag list for the given tag.
1133 * Returns: The number of tags stored
1136 gst_tag_list_get_tag_size (const GstTagList * list, const gchar * tag)
1138 const GValue *value;
1140 g_return_val_if_fail (GST_IS_TAG_LIST (list), 0);
1142 value = gst_structure_get_value (GST_TAG_LIST_STRUCTURE (list), tag);
1145 if (G_VALUE_TYPE (value) != GST_TYPE_LIST)
1148 return gst_value_list_get_size (value);
1153 * @list: list to set tags in
1154 * @mode: the mode to use
1156 * @...: NULL-terminated list of values to set
1158 * Sets the values for the given tags using the specified mode.
1161 gst_tag_list_add (GstTagList * list, GstTagMergeMode mode, const gchar * tag,
1166 g_return_if_fail (GST_IS_TAG_LIST (list));
1167 g_return_if_fail (gst_tag_list_is_writable (list));
1168 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1169 g_return_if_fail (tag != NULL);
1171 va_start (args, tag);
1172 gst_tag_list_add_valist (list, mode, tag, args);
1177 * gst_tag_list_add_values:
1178 * @list: list to set tags in
1179 * @mode: the mode to use
1181 * @...: GValues to set
1183 * Sets the GValues for the given tags using the specified mode.
1186 gst_tag_list_add_values (GstTagList * list, GstTagMergeMode mode,
1187 const gchar * tag, ...)
1191 g_return_if_fail (GST_IS_TAG_LIST (list));
1192 g_return_if_fail (gst_tag_list_is_writable (list));
1193 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1194 g_return_if_fail (tag != NULL);
1196 va_start (args, tag);
1197 gst_tag_list_add_valist_values (list, mode, tag, args);
1202 * gst_tag_list_add_valist:
1203 * @list: list to set tags in
1204 * @mode: the mode to use
1206 * @var_args: tag / value pairs to set
1208 * Sets the values for the given tags using the specified mode.
1211 gst_tag_list_add_valist (GstTagList * list, GstTagMergeMode mode,
1212 const gchar * tag, va_list var_args)
1215 gchar *error = NULL;
1217 g_return_if_fail (GST_IS_TAG_LIST (list));
1218 g_return_if_fail (gst_tag_list_is_writable (list));
1219 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1220 g_return_if_fail (tag != NULL);
1222 if (mode == GST_TAG_MERGE_REPLACE_ALL) {
1223 gst_structure_remove_all_fields (GST_TAG_LIST_STRUCTURE (list));
1226 while (tag != NULL) {
1227 GValue value = { 0, };
1229 info = gst_tag_lookup (tag);
1230 if (G_UNLIKELY (info == NULL)) {
1231 g_warning ("unknown tag '%s'", tag);
1234 G_VALUE_COLLECT_INIT (&value, info->type, var_args, 0, &error);
1236 g_warning ("%s: %s", G_STRLOC, error);
1238 /* we purposely leak the value here, it might not be
1239 * in a sane state if an error condition occoured
1243 gst_tag_list_add_value_internal (list, mode, tag, &value, info);
1244 g_value_unset (&value);
1245 tag = va_arg (var_args, gchar *);
1250 * gst_tag_list_add_valist_values:
1251 * @list: list to set tags in
1252 * @mode: the mode to use
1254 * @var_args: tag / GValue pairs to set
1256 * Sets the GValues for the given tags using the specified mode.
1259 gst_tag_list_add_valist_values (GstTagList * list, GstTagMergeMode mode,
1260 const gchar * tag, va_list var_args)
1262 g_return_if_fail (GST_IS_TAG_LIST (list));
1263 g_return_if_fail (gst_tag_list_is_writable (list));
1264 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1265 g_return_if_fail (tag != NULL);
1267 if (mode == GST_TAG_MERGE_REPLACE_ALL) {
1268 gst_structure_remove_all_fields (GST_TAG_LIST_STRUCTURE (list));
1271 while (tag != NULL) {
1274 info = gst_tag_lookup (tag);
1275 if (G_UNLIKELY (info == NULL)) {
1276 g_warning ("unknown tag '%s'", tag);
1279 gst_tag_list_add_value_internal (list, mode, tag, va_arg (var_args,
1281 tag = va_arg (var_args, gchar *);
1286 * gst_tag_list_add_value:
1287 * @list: list to set tags in
1288 * @mode: the mode to use
1290 * @value: GValue for this tag
1292 * Sets the GValue for a given tag using the specified mode.
1297 gst_tag_list_add_value (GstTagList * list, GstTagMergeMode mode,
1298 const gchar * tag, const GValue * value)
1300 g_return_if_fail (GST_IS_TAG_LIST (list));
1301 g_return_if_fail (gst_tag_list_is_writable (list));
1302 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1303 g_return_if_fail (tag != NULL);
1305 gst_tag_list_add_value_internal (list, mode, tag, value, NULL);
1309 * gst_tag_list_remove_tag:
1310 * @list: list to remove tag from
1311 * @tag: tag to remove
1313 * Removes the given tag from the taglist.
1316 gst_tag_list_remove_tag (GstTagList * list, const gchar * tag)
1318 g_return_if_fail (GST_IS_TAG_LIST (list));
1319 g_return_if_fail (tag != NULL);
1321 gst_structure_remove_field (GST_TAG_LIST_STRUCTURE (list), tag);
1326 GstTagForeachFunc func;
1327 const GstTagList *tag_list;
1333 structure_foreach_wrapper (GQuark field_id, const GValue * value,
1336 TagForeachData *data = (TagForeachData *) user_data;
1338 data->func (data->tag_list, g_quark_to_string (field_id), data->data);
1343 * gst_tag_list_foreach:
1344 * @list: list to iterate over
1345 * @func: (scope call): function to be called for each tag
1346 * @user_data: (closure): user specified data
1348 * Calls the given function for each tag inside the tag list. Note that if there
1349 * is no tag, the function won't be called at all.
1352 gst_tag_list_foreach (const GstTagList * list, GstTagForeachFunc func,
1355 TagForeachData data;
1357 g_return_if_fail (GST_IS_TAG_LIST (list));
1358 g_return_if_fail (func != NULL);
1361 data.tag_list = list;
1362 data.data = user_data;
1363 gst_structure_foreach (GST_TAG_LIST_STRUCTURE (list),
1364 structure_foreach_wrapper, &data);
1368 * gst_tag_list_get_value_index:
1369 * @list: a #GstTagList
1370 * @tag: tag to read out
1371 * @index: number of entry to read out
1373 * Gets the value that is at the given index for the given tag in the given
1376 * Returns: (transfer none): The GValue for the specified entry or NULL if the
1377 * tag wasn't available or the tag doesn't have as many entries
1380 gst_tag_list_get_value_index (const GstTagList * list, const gchar * tag,
1383 const GValue *value;
1385 g_return_val_if_fail (GST_IS_TAG_LIST (list), NULL);
1386 g_return_val_if_fail (tag != NULL, NULL);
1388 value = gst_structure_get_value (GST_TAG_LIST_STRUCTURE (list), tag);
1392 if (GST_VALUE_HOLDS_LIST (value)) {
1393 if (index >= gst_value_list_get_size (value))
1395 return gst_value_list_get_value (value, index);
1404 * gst_tag_list_copy_value:
1405 * @dest: (out caller-allocates): uninitialized #GValue to copy into
1406 * @list: list to get the tag from
1407 * @tag: tag to read out
1409 * Copies the contents for the given tag into the value,
1410 * merging multiple values into one if multiple values are associated
1412 * You must g_value_unset() the value after use.
1414 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1418 gst_tag_list_copy_value (GValue * dest, const GstTagList * list,
1423 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1424 g_return_val_if_fail (tag != NULL, FALSE);
1425 g_return_val_if_fail (dest != NULL, FALSE);
1426 g_return_val_if_fail (G_VALUE_TYPE (dest) == 0, FALSE);
1428 src = gst_structure_get_value (GST_TAG_LIST_STRUCTURE (list), tag);
1432 if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
1433 GstTagInfo *info = gst_tag_lookup (tag);
1438 /* must be there or lists aren't allowed */
1439 g_assert (info->merge_func);
1440 info->merge_func (dest, src);
1442 g_value_init (dest, G_VALUE_TYPE (src));
1443 g_value_copy (src, dest);
1448 /* FIXME 0.11: this whole merge function business is overdesigned, and the
1449 * _get_foo() API is misleading as well - how many application developers will
1450 * expect gst_tag_list_get_string (list, GST_TAG_ARTIST, &val) might return a
1451 * string with multiple comma-separated artists? _get_foo() should just be
1452 * a convenience wrapper around _get_foo_index (list, tag, 0, &val),
1453 * supplemented by a special _tag_list_get_string_merged() function if needed
1454 * (unless someone can actually think of real use cases where the merge
1455 * function is not 'use first' for non-strings and merge for strings) */
1457 /***** evil macros to get all the gst_tag_list_get_*() functions right *****/
1459 #define TAG_MERGE_FUNCS(name,type,ret) \
1461 gst_tag_list_get_ ## name (const GstTagList *list, const gchar *tag, \
1464 GValue v = { 0, }; \
1466 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE); \
1467 g_return_val_if_fail (tag != NULL, FALSE); \
1468 g_return_val_if_fail (value != NULL, FALSE); \
1470 if (!gst_tag_list_copy_value (&v, list, tag)) \
1472 *value = COPY_FUNC (g_value_get_ ## name (&v)); \
1473 g_value_unset (&v); \
1478 gst_tag_list_get_ ## name ## _index (const GstTagList *list, \
1480 guint index, type *value) \
1484 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE); \
1485 g_return_val_if_fail (tag != NULL, FALSE); \
1486 g_return_val_if_fail (value != NULL, FALSE); \
1488 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL) \
1490 *value = COPY_FUNC (g_value_get_ ## name (v)); \
1494 #define COPY_FUNC /**/
1496 * gst_tag_list_get_boolean:
1497 * @list: a #GstTagList to get the tag from
1498 * @tag: tag to read out
1499 * @value: (out): location for the result
1501 * Copies the contents for the given tag into the value, merging multiple values
1502 * into one if multiple values are associated with the tag.
1504 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1508 * gst_tag_list_get_boolean_index:
1509 * @list: a #GstTagList to get the tag from
1510 * @tag: tag to read out
1511 * @index: number of entry to read out
1512 * @value: (out): location for the result
1514 * Gets the value that is at the given index for the given tag in the given
1517 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1520 TAG_MERGE_FUNCS (boolean, gboolean, TRUE);
1522 * gst_tag_list_get_int:
1523 * @list: a #GstTagList to get the tag from
1524 * @tag: tag to read out
1525 * @value: (out): location for the result
1527 * Copies the contents for the given tag into the value, merging multiple values
1528 * into one if multiple values are associated with the tag.
1530 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1534 * gst_tag_list_get_int_index:
1535 * @list: a #GstTagList to get the tag from
1536 * @tag: tag to read out
1537 * @index: number of entry to read out
1538 * @value: (out): location for the result
1540 * Gets the value that is at the given index for the given tag in the given
1543 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1546 TAG_MERGE_FUNCS (int, gint, TRUE);
1548 * gst_tag_list_get_uint:
1549 * @list: a #GstTagList to get the tag from
1550 * @tag: tag to read out
1551 * @value: (out): location for the result
1553 * Copies the contents for the given tag into the value, merging multiple values
1554 * into one if multiple values are associated with the tag.
1556 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1560 * gst_tag_list_get_uint_index:
1561 * @list: a #GstTagList to get the tag from
1562 * @tag: tag to read out
1563 * @index: number of entry to read out
1564 * @value: (out): location for the result
1566 * Gets the value that is at the given index for the given tag in the given
1569 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1572 TAG_MERGE_FUNCS (uint, guint, TRUE);
1574 * gst_tag_list_get_int64_index:
1575 * @list: a #GstTagList to get the tag from
1576 * @tag: tag to read out
1577 * @index: number of entry to read out
1578 * @value: (out): location for the result
1580 * Gets the value that is at the given index for the given tag in the given
1583 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1586 TAG_MERGE_FUNCS (int64, gint64, TRUE);
1588 * gst_tag_list_get_uint64:
1589 * @list: a #GstTagList to get the tag from
1590 * @tag: tag to read out
1591 * @value: (out): location for the result
1593 * Copies the contents for the given tag into the value, merging multiple values
1594 * into one if multiple values are associated with the tag.
1596 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1600 * gst_tag_list_get_uint64_index:
1601 * @list: a #GstTagList to get the tag from
1602 * @tag: tag to read out
1603 * @index: number of entry to read out
1604 * @value: (out): location for the result
1606 * Gets the value that is at the given index for the given tag in the given
1609 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1612 TAG_MERGE_FUNCS (uint64, guint64, TRUE);
1614 * gst_tag_list_get_float:
1615 * @list: a #GstTagList to get the tag from
1616 * @tag: tag to read out
1617 * @value: (out): location for the result
1619 * Copies the contents for the given tag into the value, merging multiple values
1620 * into one if multiple values are associated with the tag.
1622 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1626 * gst_tag_list_get_float_index:
1627 * @list: a #GstTagList to get the tag from
1628 * @tag: tag to read out
1629 * @index: number of entry to read out
1630 * @value: (out): location for the result
1632 * Gets the value that is at the given index for the given tag in the given
1635 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1638 TAG_MERGE_FUNCS (float, gfloat, TRUE);
1640 * gst_tag_list_get_double:
1641 * @list: a #GstTagList to get the tag from
1642 * @tag: tag to read out
1643 * @value: (out): location for the result
1645 * Copies the contents for the given tag into the value, merging multiple values
1646 * into one if multiple values are associated with the tag.
1648 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1652 * gst_tag_list_get_double_index:
1653 * @list: a #GstTagList to get the tag from
1654 * @tag: tag to read out
1655 * @index: number of entry to read out
1656 * @value: (out): location for the result
1658 * Gets the value that is at the given index for the given tag in the given
1661 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1664 TAG_MERGE_FUNCS (double, gdouble, TRUE);
1666 * gst_tag_list_get_pointer:
1667 * @list: a #GstTagList to get the tag from
1668 * @tag: tag to read out
1669 * @value: (out) (transfer none): location for the result
1671 * Copies the contents for the given tag into the value, merging multiple values
1672 * into one if multiple values are associated with the tag.
1674 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1678 * gst_tag_list_get_pointer_index:
1679 * @list: a #GstTagList to get the tag from
1680 * @tag: tag to read out
1681 * @index: number of entry to read out
1682 * @value: (out) (transfer none): location for the result
1684 * Gets the value that is at the given index for the given tag in the given
1687 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1690 TAG_MERGE_FUNCS (pointer, gpointer, (*value != NULL));
1692 static inline gchar *
1693 _gst_strdup0 (const gchar * s)
1695 if (s == NULL || *s == '\0')
1698 return g_strdup (s);
1702 #define COPY_FUNC _gst_strdup0
1705 * gst_tag_list_get_string:
1706 * @list: a #GstTagList to get the tag from
1707 * @tag: tag to read out
1708 * @value: (out callee-allocates) (transfer full): location for the result
1710 * Copies the contents for the given tag into the value, possibly merging
1711 * multiple values into one if multiple values are associated with the tag.
1713 * Use gst_tag_list_get_string_index (list, tag, 0, value) if you want
1714 * to retrieve the first string associated with this tag unmodified.
1716 * The resulting string in @value will be in UTF-8 encoding and should be
1717 * freed by the caller using g_free when no longer needed. Since 0.10.24 the
1718 * returned string is also guaranteed to be non-NULL and non-empty.
1720 * Free-function: g_free
1722 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1726 * gst_tag_list_get_string_index:
1727 * @list: a #GstTagList to get the tag from
1728 * @tag: tag to read out
1729 * @index: number of entry to read out
1730 * @value: (out callee-allocates) (transfer full): location for the result
1732 * Gets the value that is at the given index for the given tag in the given
1735 * The resulting string in @value will be in UTF-8 encoding and should be
1736 * freed by the caller using g_free when no longer needed. Since 0.10.24 the
1737 * returned string is also guaranteed to be non-NULL and non-empty.
1739 * Free-function: g_free
1741 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1744 TAG_MERGE_FUNCS (string, gchar *, (*value != NULL));
1747 *FIXME 0.11: Instead of _peek (non-copy) and _get (copy), we could have
1748 * _get (non-copy) and _dup (copy) for strings, seems more
1752 * gst_tag_list_peek_string_index:
1753 * @list: a #GstTagList to get the tag from
1754 * @tag: tag to read out
1755 * @index: number of entry to read out
1756 * @value: (out) (transfer none): location for the result
1758 * Peeks at the value that is at the given index for the given tag in the given
1761 * The resulting string in @value will be in UTF-8 encoding and doesn't need
1762 * to be freed by the caller. The returned string is also guaranteed to
1763 * be non-NULL and non-empty.
1765 * Returns: TRUE, if a value was set, FALSE if the tag didn't exist in the
1769 gst_tag_list_peek_string_index (const GstTagList * list,
1770 const gchar * tag, guint index, const gchar ** value)
1774 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1775 g_return_val_if_fail (tag != NULL, FALSE);
1776 g_return_val_if_fail (value != NULL, FALSE);
1778 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)
1780 *value = g_value_get_string (v);
1781 return *value != NULL && **value != '\0';
1785 * gst_tag_list_get_date:
1786 * @list: a #GstTagList to get the tag from
1787 * @tag: tag to read out
1788 * @value: (out callee-allocates) (transfer full): address of a GDate pointer
1789 * variable to store the result into
1791 * Copies the first date for the given tag in the taglist into the variable
1792 * pointed to by @value. Free the date with g_date_free() when it is no longer
1795 * Free-function: g_date_free
1797 * Returns: TRUE, if a date was copied, FALSE if the tag didn't exist in the
1798 * given list or if it was #NULL.
1801 gst_tag_list_get_date (const GstTagList * list, const gchar * tag,
1806 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1807 g_return_val_if_fail (tag != NULL, FALSE);
1808 g_return_val_if_fail (value != NULL, FALSE);
1810 if (!gst_tag_list_copy_value (&v, list, tag))
1812 *value = (GDate *) g_value_dup_boxed (&v);
1814 return (*value != NULL);
1818 * gst_tag_list_get_date_index:
1819 * @list: a #GstTagList to get the tag from
1820 * @tag: tag to read out
1821 * @index: number of entry to read out
1822 * @value: (out callee-allocates) (transfer full): location for the result
1824 * Gets the date that is at the given index for the given tag in the given
1825 * list and copies it into the variable pointed to by @value. Free the date
1826 * with g_date_free() when it is no longer needed.
1828 * Free-function: g_date_free
1830 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1831 * given list or if it was #NULL.
1834 gst_tag_list_get_date_index (const GstTagList * list,
1835 const gchar * tag, guint index, GDate ** value)
1839 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1840 g_return_val_if_fail (tag != NULL, FALSE);
1841 g_return_val_if_fail (value != NULL, FALSE);
1843 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)
1845 *value = (GDate *) g_value_dup_boxed (v);
1846 return (*value != NULL);
1850 * gst_tag_list_get_date_time:
1851 * @list: a #GstTagList to get the tag from
1852 * @tag: tag to read out
1853 * @value: (out callee-allocates) (transfer full): address of a #GstDateTime
1854 * pointer variable to store the result into
1856 * Copies the first datetime for the given tag in the taglist into the variable
1857 * pointed to by @value. Unref the date with gst_date_time_unref() when
1858 * it is no longer needed.
1860 * Free-function: gst_date_time_unref
1862 * Returns: TRUE, if a datetime was copied, FALSE if the tag didn't exist in
1863 * thegiven list or if it was #NULL.
1868 gst_tag_list_get_date_time (const GstTagList * list, const gchar * tag,
1869 GstDateTime ** value)
1873 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1874 g_return_val_if_fail (tag != NULL, FALSE);
1875 g_return_val_if_fail (value != NULL, FALSE);
1877 if (!gst_tag_list_copy_value (&v, list, tag))
1880 g_return_val_if_fail (GST_VALUE_HOLDS_DATE_TIME (&v), FALSE);
1882 *value = (GstDateTime *) g_value_dup_boxed (&v);
1884 return (*value != NULL);
1888 * gst_tag_list_get_date_time_index:
1889 * @list: a #GstTagList to get the tag from
1890 * @tag: tag to read out
1891 * @index: number of entry to read out
1892 * @value: (out callee-allocates) (transfer full): location for the result
1894 * Gets the datetime that is at the given index for the given tag in the given
1895 * list and copies it into the variable pointed to by @value. Unref the datetime
1896 * with gst_date_time_unref() when it is no longer needed.
1898 * Free-function: gst_date_time_unref
1900 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1901 * given list or if it was #NULL.
1906 gst_tag_list_get_date_time_index (const GstTagList * list,
1907 const gchar * tag, guint index, GstDateTime ** value)
1911 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1912 g_return_val_if_fail (tag != NULL, FALSE);
1913 g_return_val_if_fail (value != NULL, FALSE);
1915 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)
1917 *value = (GstDateTime *) g_value_dup_boxed (v);
1918 return (*value != NULL);
1922 * gst_tag_list_get_buffer:
1923 * @list: a #GstTagList to get the tag from
1924 * @tag: tag to read out
1925 * @value: (out callee-allocates) (transfer full): address of a GstBuffer
1926 * pointer variable to store the result into
1928 * Copies the first buffer for the given tag in the taglist into the variable
1929 * pointed to by @value. Free the buffer with gst_buffer_unref() when it is
1932 * Free-function: gst_buffer_unref
1934 * Returns: TRUE, if a buffer was copied, FALSE if the tag didn't exist in the
1935 * given list or if it was #NULL.
1940 gst_tag_list_get_buffer (const GstTagList * list, const gchar * tag,
1945 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1946 g_return_val_if_fail (tag != NULL, FALSE);
1947 g_return_val_if_fail (value != NULL, FALSE);
1949 if (!gst_tag_list_copy_value (&v, list, tag))
1951 *value = g_value_dup_boxed (&v);
1953 return (*value != NULL);
1957 * gst_tag_list_get_buffer_index:
1958 * @list: a #GstTagList to get the tag from
1959 * @tag: tag to read out
1960 * @index: number of entry to read out
1961 * @value: (out callee-allocates) (transfer full): address of a GstBuffer
1962 * pointer variable to store the result into
1964 * Gets the buffer that is at the given index for the given tag in the given
1965 * list and copies it into the variable pointed to by @value. Free the buffer
1966 * with gst_buffer_unref() when it is no longer needed.
1968 * Free-function: gst_buffer_unref
1970 * Returns: TRUE, if a buffer was copied, FALSE if the tag didn't exist in the
1971 * given list or if it was #NULL.
1976 gst_tag_list_get_buffer_index (const GstTagList * list,
1977 const gchar * tag, guint index, GstBuffer ** value)
1981 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1982 g_return_val_if_fail (tag != NULL, FALSE);
1983 g_return_val_if_fail (value != NULL, FALSE);
1985 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)
1987 *value = g_value_dup_boxed (v);
1988 return (*value != NULL);