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, gsize size)
668 gst_mini_object_init (GST_MINI_OBJECT_CAST (taglist),
669 gst_tag_list_get_type (), size);
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, sizeof (GstTagListImpl));
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 /* why not just pass sizeof (GstTagListImpl) here? */
709 g_slice_free1 (GST_MINI_OBJECT_SIZE (list), list);
713 __gst_tag_list_copy (const GstTagList * list)
715 const GstStructure *s;
717 g_return_val_if_fail (GST_IS_TAG_LIST (list), NULL);
719 s = GST_TAG_LIST_STRUCTURE (list);
720 return gst_tag_list_new_internal (gst_structure_copy (s));
724 * gst_tag_list_new_empty:
726 * Creates a new empty GstTagList.
728 * Free-function: gst_tag_list_unref
730 * Returns: (transfer full): An empty tag list
733 gst_tag_list_new_empty (void)
736 GstTagList *tag_list;
738 s = gst_structure_new_id_empty (GST_QUARK (TAGLIST));
739 tag_list = gst_tag_list_new_internal (s);
746 * @...: NULL-terminated list of values to set
748 * Creates a new taglist and appends the values for the given tags. It expects
749 * tag-value pairs like gst_tag_list_add(), and a NULL terminator after the
750 * last pair. The type of the values is implicit and is documented in the API
751 * reference, but can also be queried at runtime with gst_tag_get_type(). It
752 * is an error to pass a value of a type not matching the tag type into this
753 * function. The tag list will make copies of any arguments passed
754 * (e.g. strings, buffers).
756 * Free-function: gst_tag_list_unref
758 * Returns: (transfer full): a new #GstTagList. Free with gst_tag_list_unref()
759 * when no longer needed.
764 gst_tag_list_new (const gchar * tag, ...)
769 g_return_val_if_fail (tag != NULL, NULL);
771 list = gst_tag_list_new_empty ();
772 va_start (args, tag);
773 gst_tag_list_add_valist (list, GST_TAG_MERGE_APPEND, tag, args);
780 * gst_tag_list_new_valist:
781 * @var_args: tag / value pairs to set
783 * Just like gst_tag_list_new(), only that it takes a va_list argument.
784 * Useful mostly for language bindings.
786 * Free-function: gst_tag_list_unref
788 * Returns: (transfer full): a new #GstTagList. Free with gst_tag_list_unref()
789 * when no longer needed.
794 gst_tag_list_new_valist (va_list var_args)
799 list = gst_tag_list_new_empty ();
801 tag = va_arg (var_args, gchar *);
802 gst_tag_list_add_valist (list, GST_TAG_MERGE_APPEND, tag, var_args);
808 * gst_tag_list_to_string:
809 * @list: a #GstTagList
811 * Serializes a tag list to a string.
813 * Returns: a newly-allocated string, or NULL in case of an error. The
814 * string must be freed with g_free() when no longer needed.
819 gst_tag_list_to_string (const GstTagList * list)
821 g_return_val_if_fail (GST_IS_TAG_LIST (list), NULL);
823 return gst_structure_to_string (GST_TAG_LIST_STRUCTURE (list));
827 * gst_tag_list_new_from_string:
828 * @str: a string created with gst_tag_list_to_string()
830 * Deserializes a tag list.
832 * Returns: a new #GstTagList, or NULL in case of an error.
837 gst_tag_list_new_from_string (const gchar * str)
839 GstTagList *tag_list;
841 g_return_val_if_fail (str != NULL, NULL);
842 g_return_val_if_fail (g_str_has_prefix (str, "taglist"), NULL);
844 tag_list = gst_tag_list_new_internal (gst_structure_from_string (str, NULL));
849 * gst_tag_list_n_tags:
850 * @list: A #GstTagList.
852 * Get the number of tags in @list.
854 * Returns: The number of tags in @list.
857 gst_tag_list_n_tags (const GstTagList * list)
859 g_return_val_if_fail (list != NULL, 0);
860 g_return_val_if_fail (GST_IS_TAG_LIST (list), 0);
862 return gst_structure_n_fields (GST_TAG_LIST_STRUCTURE (list));
866 * gst_tag_list_nth_tag_name:
867 * @list: A #GstTagList.
870 * Get the name of the tag in @list at @index.
872 * Returns: The name of the tag at @index.
875 gst_tag_list_nth_tag_name (const GstTagList * list, guint index)
877 g_return_val_if_fail (list != NULL, 0);
878 g_return_val_if_fail (GST_IS_TAG_LIST (list), 0);
880 return gst_structure_nth_field_name (GST_TAG_LIST_STRUCTURE (list), index);
884 * gst_tag_list_is_empty:
885 * @list: A #GstTagList.
887 * Checks if the given taglist is empty.
889 * Returns: TRUE if the taglist is empty, otherwise FALSE.
894 gst_tag_list_is_empty (const GstTagList * list)
896 g_return_val_if_fail (list != NULL, FALSE);
897 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
899 return (gst_structure_n_fields (GST_TAG_LIST_STRUCTURE (list)) == 0);
903 gst_tag_list_fields_equal (const GValue * value1, const GValue * value2)
907 if (gst_value_compare (value1, value2) == GST_VALUE_EQUAL)
910 /* fields not equal: add some tolerance for doubles, otherwise bail out */
911 if (!G_VALUE_HOLDS_DOUBLE (value1) || !G_VALUE_HOLDS_DOUBLE (value2))
914 d1 = g_value_get_double (value1);
915 d2 = g_value_get_double (value2);
917 /* This will only work for 'normal' values and values around 0,
918 * which should be good enough for our purposes here
919 * FIXME: maybe add this to gst_value_compare_double() ? */
920 return (fabs (d1 - d2) < 0.0000001);
924 * gst_tag_list_is_equal:
925 * @list1: a #GstTagList.
926 * @list2: a #GstTagList.
928 * Checks if the two given taglists are equal.
930 * Returns: TRUE if the taglists are equal, otherwise FALSE
935 gst_tag_list_is_equal (const GstTagList * list1, const GstTagList * list2)
937 const GstStructure *s1, *s2;
938 gint num_fields1, num_fields2, i;
940 g_return_val_if_fail (GST_IS_TAG_LIST (list1), FALSE);
941 g_return_val_if_fail (GST_IS_TAG_LIST (list2), FALSE);
943 /* we don't just use gst_structure_is_equal() here so we can add some
944 * tolerance for doubles, though maybe we should just add that to
945 * gst_value_compare_double() as well? */
946 s1 = GST_TAG_LIST_STRUCTURE (list1);
947 s2 = GST_TAG_LIST_STRUCTURE (list2);
949 num_fields1 = gst_structure_n_fields (s1);
950 num_fields2 = gst_structure_n_fields (s2);
952 if (num_fields1 != num_fields2)
955 for (i = 0; i < num_fields1; i++) {
956 const GValue *value1, *value2;
957 const gchar *tag_name;
959 tag_name = gst_structure_nth_field_name (s1, i);
960 value1 = gst_structure_get_value (s1, tag_name);
961 value2 = gst_structure_get_value (s2, tag_name);
966 if (!gst_tag_list_fields_equal (value1, value2))
976 GstTagMergeMode mode;
981 gst_tag_list_add_value_internal (GstTagList * tag_list, GstTagMergeMode mode,
982 const gchar * tag, const GValue * value, GstTagInfo * info)
984 GstStructure *list = GST_TAG_LIST_STRUCTURE (tag_list);
985 const GValue *value2;
989 info = gst_tag_lookup (tag);
990 if (G_UNLIKELY (info == NULL)) {
991 g_warning ("unknown tag '%s'", tag);
996 tag_quark = info->name_quark;
999 && (value2 = gst_structure_id_get_value (list, tag_quark)) != NULL) {
1000 GValue dest = { 0, };
1003 case GST_TAG_MERGE_REPLACE_ALL:
1004 case GST_TAG_MERGE_REPLACE:
1005 gst_structure_id_set_value (list, tag_quark, value);
1007 case GST_TAG_MERGE_PREPEND:
1008 gst_value_list_merge (&dest, value, value2);
1009 gst_structure_id_set_value (list, tag_quark, &dest);
1010 g_value_unset (&dest);
1012 case GST_TAG_MERGE_APPEND:
1013 gst_value_list_merge (&dest, value2, value);
1014 gst_structure_id_set_value (list, tag_quark, &dest);
1015 g_value_unset (&dest);
1017 case GST_TAG_MERGE_KEEP:
1018 case GST_TAG_MERGE_KEEP_ALL:
1021 g_assert_not_reached ();
1026 case GST_TAG_MERGE_APPEND:
1027 case GST_TAG_MERGE_KEEP:
1028 if (gst_structure_id_get_value (list, tag_quark) != NULL)
1031 case GST_TAG_MERGE_REPLACE_ALL:
1032 case GST_TAG_MERGE_REPLACE:
1033 case GST_TAG_MERGE_PREPEND:
1034 gst_structure_id_set_value (list, tag_quark, value);
1036 case GST_TAG_MERGE_KEEP_ALL:
1039 g_assert_not_reached ();
1046 gst_tag_list_copy_foreach (GQuark tag_quark, const GValue * value,
1049 GstTagCopyData *copy = (GstTagCopyData *) user_data;
1052 tag = g_quark_to_string (tag_quark);
1053 gst_tag_list_add_value_internal (copy->list, copy->mode, tag, value, NULL);
1059 * gst_tag_list_insert:
1060 * @into: list to merge into
1061 * @from: list to merge from
1062 * @mode: the mode to use
1064 * Inserts the tags of the @from list into the first list using the given mode.
1067 gst_tag_list_insert (GstTagList * into, const GstTagList * from,
1068 GstTagMergeMode mode)
1070 GstTagCopyData data;
1072 g_return_if_fail (GST_IS_TAG_LIST (into));
1073 g_return_if_fail (gst_tag_list_is_writable (into));
1074 g_return_if_fail (GST_IS_TAG_LIST (from));
1075 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1079 if (mode == GST_TAG_MERGE_REPLACE_ALL) {
1080 gst_structure_remove_all_fields (GST_TAG_LIST_STRUCTURE (into));
1082 gst_structure_foreach (GST_TAG_LIST_STRUCTURE (from),
1083 gst_tag_list_copy_foreach, &data);
1087 * gst_tag_list_merge:
1088 * @list1: first list to merge
1089 * @list2: second list to merge
1090 * @mode: the mode to use
1092 * Merges the two given lists into a new list. If one of the lists is NULL, a
1093 * copy of the other is returned. If both lists are NULL, NULL is returned.
1095 * Free-function: gst_tag_list_unref
1097 * Returns: (transfer full): the new list
1100 gst_tag_list_merge (const GstTagList * list1, const GstTagList * list2,
1101 GstTagMergeMode mode)
1103 GstTagList *list1_cp;
1104 const GstTagList *list2_cp;
1106 g_return_val_if_fail (list1 == NULL || GST_IS_TAG_LIST (list1), NULL);
1107 g_return_val_if_fail (list2 == NULL || GST_IS_TAG_LIST (list2), NULL);
1108 g_return_val_if_fail (GST_TAG_MODE_IS_VALID (mode), NULL);
1110 /* nothing to merge */
1111 if (!list1 && !list2) {
1115 /* create empty list, we need to do this to correctly handling merge modes */
1116 list1_cp = (list1) ? gst_tag_list_copy (list1) : gst_tag_list_new_empty ();
1117 list2_cp = (list2) ? list2 : gst_tag_list_new_empty ();
1119 gst_tag_list_insert (list1_cp, list2_cp, mode);
1122 gst_tag_list_unref ((GstTagList *) list2_cp);
1128 * gst_tag_list_get_tag_size:
1130 * @tag: the tag to query
1132 * Checks how many value are stored in this tag list for the given tag.
1134 * Returns: The number of tags stored
1137 gst_tag_list_get_tag_size (const GstTagList * list, const gchar * tag)
1139 const GValue *value;
1141 g_return_val_if_fail (GST_IS_TAG_LIST (list), 0);
1143 value = gst_structure_get_value (GST_TAG_LIST_STRUCTURE (list), tag);
1146 if (G_VALUE_TYPE (value) != GST_TYPE_LIST)
1149 return gst_value_list_get_size (value);
1154 * @list: list to set tags in
1155 * @mode: the mode to use
1157 * @...: NULL-terminated list of values to set
1159 * Sets the values for the given tags using the specified mode.
1162 gst_tag_list_add (GstTagList * list, GstTagMergeMode mode, const gchar * tag,
1167 g_return_if_fail (GST_IS_TAG_LIST (list));
1168 g_return_if_fail (gst_tag_list_is_writable (list));
1169 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1170 g_return_if_fail (tag != NULL);
1172 va_start (args, tag);
1173 gst_tag_list_add_valist (list, mode, tag, args);
1178 * gst_tag_list_add_values:
1179 * @list: list to set tags in
1180 * @mode: the mode to use
1182 * @...: GValues to set
1184 * Sets the GValues for the given tags using the specified mode.
1187 gst_tag_list_add_values (GstTagList * list, GstTagMergeMode mode,
1188 const gchar * tag, ...)
1192 g_return_if_fail (GST_IS_TAG_LIST (list));
1193 g_return_if_fail (gst_tag_list_is_writable (list));
1194 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1195 g_return_if_fail (tag != NULL);
1197 va_start (args, tag);
1198 gst_tag_list_add_valist_values (list, mode, tag, args);
1203 * gst_tag_list_add_valist:
1204 * @list: list to set tags in
1205 * @mode: the mode to use
1207 * @var_args: tag / value pairs to set
1209 * Sets the values for the given tags using the specified mode.
1212 gst_tag_list_add_valist (GstTagList * list, GstTagMergeMode mode,
1213 const gchar * tag, va_list var_args)
1216 gchar *error = NULL;
1218 g_return_if_fail (GST_IS_TAG_LIST (list));
1219 g_return_if_fail (gst_tag_list_is_writable (list));
1220 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1221 g_return_if_fail (tag != NULL);
1223 if (mode == GST_TAG_MERGE_REPLACE_ALL) {
1224 gst_structure_remove_all_fields (GST_TAG_LIST_STRUCTURE (list));
1227 while (tag != NULL) {
1228 GValue value = { 0, };
1230 info = gst_tag_lookup (tag);
1231 if (G_UNLIKELY (info == NULL)) {
1232 g_warning ("unknown tag '%s'", tag);
1235 G_VALUE_COLLECT_INIT (&value, info->type, var_args, 0, &error);
1237 g_warning ("%s: %s", G_STRLOC, error);
1239 /* we purposely leak the value here, it might not be
1240 * in a sane state if an error condition occoured
1244 gst_tag_list_add_value_internal (list, mode, tag, &value, info);
1245 g_value_unset (&value);
1246 tag = va_arg (var_args, gchar *);
1251 * gst_tag_list_add_valist_values:
1252 * @list: list to set tags in
1253 * @mode: the mode to use
1255 * @var_args: tag / GValue pairs to set
1257 * Sets the GValues for the given tags using the specified mode.
1260 gst_tag_list_add_valist_values (GstTagList * list, GstTagMergeMode mode,
1261 const gchar * tag, va_list var_args)
1263 g_return_if_fail (GST_IS_TAG_LIST (list));
1264 g_return_if_fail (gst_tag_list_is_writable (list));
1265 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1266 g_return_if_fail (tag != NULL);
1268 if (mode == GST_TAG_MERGE_REPLACE_ALL) {
1269 gst_structure_remove_all_fields (GST_TAG_LIST_STRUCTURE (list));
1272 while (tag != NULL) {
1275 info = gst_tag_lookup (tag);
1276 if (G_UNLIKELY (info == NULL)) {
1277 g_warning ("unknown tag '%s'", tag);
1280 gst_tag_list_add_value_internal (list, mode, tag, va_arg (var_args,
1282 tag = va_arg (var_args, gchar *);
1287 * gst_tag_list_add_value:
1288 * @list: list to set tags in
1289 * @mode: the mode to use
1291 * @value: GValue for this tag
1293 * Sets the GValue for a given tag using the specified mode.
1298 gst_tag_list_add_value (GstTagList * list, GstTagMergeMode mode,
1299 const gchar * tag, const GValue * value)
1301 g_return_if_fail (GST_IS_TAG_LIST (list));
1302 g_return_if_fail (gst_tag_list_is_writable (list));
1303 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1304 g_return_if_fail (tag != NULL);
1306 gst_tag_list_add_value_internal (list, mode, tag, value, NULL);
1310 * gst_tag_list_remove_tag:
1311 * @list: list to remove tag from
1312 * @tag: tag to remove
1314 * Removes the given tag from the taglist.
1317 gst_tag_list_remove_tag (GstTagList * list, const gchar * tag)
1319 g_return_if_fail (GST_IS_TAG_LIST (list));
1320 g_return_if_fail (tag != NULL);
1322 gst_structure_remove_field (GST_TAG_LIST_STRUCTURE (list), tag);
1327 GstTagForeachFunc func;
1328 const GstTagList *tag_list;
1334 structure_foreach_wrapper (GQuark field_id, const GValue * value,
1337 TagForeachData *data = (TagForeachData *) user_data;
1339 data->func (data->tag_list, g_quark_to_string (field_id), data->data);
1344 * gst_tag_list_foreach:
1345 * @list: list to iterate over
1346 * @func: (scope call): function to be called for each tag
1347 * @user_data: (closure): user specified data
1349 * Calls the given function for each tag inside the tag list. Note that if there
1350 * is no tag, the function won't be called at all.
1353 gst_tag_list_foreach (const GstTagList * list, GstTagForeachFunc func,
1356 TagForeachData data;
1358 g_return_if_fail (GST_IS_TAG_LIST (list));
1359 g_return_if_fail (func != NULL);
1362 data.tag_list = list;
1363 data.data = user_data;
1364 gst_structure_foreach (GST_TAG_LIST_STRUCTURE (list),
1365 structure_foreach_wrapper, &data);
1369 * gst_tag_list_get_value_index:
1370 * @list: a #GstTagList
1371 * @tag: tag to read out
1372 * @index: number of entry to read out
1374 * Gets the value that is at the given index for the given tag in the given
1377 * Returns: (transfer none): The GValue for the specified entry or NULL if the
1378 * tag wasn't available or the tag doesn't have as many entries
1381 gst_tag_list_get_value_index (const GstTagList * list, const gchar * tag,
1384 const GValue *value;
1386 g_return_val_if_fail (GST_IS_TAG_LIST (list), NULL);
1387 g_return_val_if_fail (tag != NULL, NULL);
1389 value = gst_structure_get_value (GST_TAG_LIST_STRUCTURE (list), tag);
1393 if (GST_VALUE_HOLDS_LIST (value)) {
1394 if (index >= gst_value_list_get_size (value))
1396 return gst_value_list_get_value (value, index);
1405 * gst_tag_list_copy_value:
1406 * @dest: (out caller-allocates): uninitialized #GValue to copy into
1407 * @list: list to get the tag from
1408 * @tag: tag to read out
1410 * Copies the contents for the given tag into the value,
1411 * merging multiple values into one if multiple values are associated
1413 * You must g_value_unset() the value after use.
1415 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1419 gst_tag_list_copy_value (GValue * dest, const GstTagList * list,
1424 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1425 g_return_val_if_fail (tag != NULL, FALSE);
1426 g_return_val_if_fail (dest != NULL, FALSE);
1427 g_return_val_if_fail (G_VALUE_TYPE (dest) == 0, FALSE);
1429 src = gst_structure_get_value (GST_TAG_LIST_STRUCTURE (list), tag);
1433 if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
1434 GstTagInfo *info = gst_tag_lookup (tag);
1439 /* must be there or lists aren't allowed */
1440 g_assert (info->merge_func);
1441 info->merge_func (dest, src);
1443 g_value_init (dest, G_VALUE_TYPE (src));
1444 g_value_copy (src, dest);
1449 /* FIXME 0.11: this whole merge function business is overdesigned, and the
1450 * _get_foo() API is misleading as well - how many application developers will
1451 * expect gst_tag_list_get_string (list, GST_TAG_ARTIST, &val) might return a
1452 * string with multiple comma-separated artists? _get_foo() should just be
1453 * a convenience wrapper around _get_foo_index (list, tag, 0, &val),
1454 * supplemented by a special _tag_list_get_string_merged() function if needed
1455 * (unless someone can actually think of real use cases where the merge
1456 * function is not 'use first' for non-strings and merge for strings) */
1458 /***** evil macros to get all the gst_tag_list_get_*() functions right *****/
1460 #define TAG_MERGE_FUNCS(name,type,ret) \
1462 gst_tag_list_get_ ## name (const GstTagList *list, const gchar *tag, \
1465 GValue v = { 0, }; \
1467 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE); \
1468 g_return_val_if_fail (tag != NULL, FALSE); \
1469 g_return_val_if_fail (value != NULL, FALSE); \
1471 if (!gst_tag_list_copy_value (&v, list, tag)) \
1473 *value = COPY_FUNC (g_value_get_ ## name (&v)); \
1474 g_value_unset (&v); \
1479 gst_tag_list_get_ ## name ## _index (const GstTagList *list, \
1481 guint index, type *value) \
1485 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE); \
1486 g_return_val_if_fail (tag != NULL, FALSE); \
1487 g_return_val_if_fail (value != NULL, FALSE); \
1489 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL) \
1491 *value = COPY_FUNC (g_value_get_ ## name (v)); \
1495 #define COPY_FUNC /**/
1497 * gst_tag_list_get_boolean:
1498 * @list: a #GstTagList to get the tag from
1499 * @tag: tag to read out
1500 * @value: (out): location for the result
1502 * Copies the contents for the given tag into the value, merging multiple values
1503 * into one if multiple values are associated with the tag.
1505 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1509 * gst_tag_list_get_boolean_index:
1510 * @list: a #GstTagList to get the tag from
1511 * @tag: tag to read out
1512 * @index: number of entry to read out
1513 * @value: (out): location for the result
1515 * Gets the value that is at the given index for the given tag in the given
1518 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1521 TAG_MERGE_FUNCS (boolean, gboolean, TRUE);
1523 * gst_tag_list_get_int:
1524 * @list: a #GstTagList to get the tag from
1525 * @tag: tag to read out
1526 * @value: (out): location for the result
1528 * Copies the contents for the given tag into the value, merging multiple values
1529 * into one if multiple values are associated with the tag.
1531 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1535 * gst_tag_list_get_int_index:
1536 * @list: a #GstTagList to get the tag from
1537 * @tag: tag to read out
1538 * @index: number of entry to read out
1539 * @value: (out): location for the result
1541 * Gets the value that is at the given index for the given tag in the given
1544 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1547 TAG_MERGE_FUNCS (int, gint, TRUE);
1549 * gst_tag_list_get_uint:
1550 * @list: a #GstTagList to get the tag from
1551 * @tag: tag to read out
1552 * @value: (out): location for the result
1554 * Copies the contents for the given tag into the value, merging multiple values
1555 * into one if multiple values are associated with the tag.
1557 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1561 * gst_tag_list_get_uint_index:
1562 * @list: a #GstTagList to get the tag from
1563 * @tag: tag to read out
1564 * @index: number of entry to read out
1565 * @value: (out): location for the result
1567 * Gets the value that is at the given index for the given tag in the given
1570 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1573 TAG_MERGE_FUNCS (uint, guint, TRUE);
1575 * gst_tag_list_get_int64_index:
1576 * @list: a #GstTagList to get the tag from
1577 * @tag: tag to read out
1578 * @index: number of entry to read out
1579 * @value: (out): location for the result
1581 * Gets the value that is at the given index for the given tag in the given
1584 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1587 TAG_MERGE_FUNCS (int64, gint64, TRUE);
1589 * gst_tag_list_get_uint64:
1590 * @list: a #GstTagList to get the tag from
1591 * @tag: tag to read out
1592 * @value: (out): location for the result
1594 * Copies the contents for the given tag into the value, merging multiple values
1595 * into one if multiple values are associated with the tag.
1597 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1601 * gst_tag_list_get_uint64_index:
1602 * @list: a #GstTagList to get the tag from
1603 * @tag: tag to read out
1604 * @index: number of entry to read out
1605 * @value: (out): location for the result
1607 * Gets the value that is at the given index for the given tag in the given
1610 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1613 TAG_MERGE_FUNCS (uint64, guint64, TRUE);
1615 * gst_tag_list_get_float:
1616 * @list: a #GstTagList to get the tag from
1617 * @tag: tag to read out
1618 * @value: (out): location for the result
1620 * Copies the contents for the given tag into the value, merging multiple values
1621 * into one if multiple values are associated with the tag.
1623 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1627 * gst_tag_list_get_float_index:
1628 * @list: a #GstTagList to get the tag from
1629 * @tag: tag to read out
1630 * @index: number of entry to read out
1631 * @value: (out): location for the result
1633 * Gets the value that is at the given index for the given tag in the given
1636 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1639 TAG_MERGE_FUNCS (float, gfloat, TRUE);
1641 * gst_tag_list_get_double:
1642 * @list: a #GstTagList to get the tag from
1643 * @tag: tag to read out
1644 * @value: (out): location for the result
1646 * Copies the contents for the given tag into the value, merging multiple values
1647 * into one if multiple values are associated with the tag.
1649 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1653 * gst_tag_list_get_double_index:
1654 * @list: a #GstTagList to get the tag from
1655 * @tag: tag to read out
1656 * @index: number of entry to read out
1657 * @value: (out): location for the result
1659 * Gets the value that is at the given index for the given tag in the given
1662 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1665 TAG_MERGE_FUNCS (double, gdouble, TRUE);
1667 * gst_tag_list_get_pointer:
1668 * @list: a #GstTagList to get the tag from
1669 * @tag: tag to read out
1670 * @value: (out) (transfer none): location for the result
1672 * Copies the contents for the given tag into the value, merging multiple values
1673 * into one if multiple values are associated with the tag.
1675 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1679 * gst_tag_list_get_pointer_index:
1680 * @list: a #GstTagList to get the tag from
1681 * @tag: tag to read out
1682 * @index: number of entry to read out
1683 * @value: (out) (transfer none): location for the result
1685 * Gets the value that is at the given index for the given tag in the given
1688 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1691 TAG_MERGE_FUNCS (pointer, gpointer, (*value != NULL));
1693 static inline gchar *
1694 _gst_strdup0 (const gchar * s)
1696 if (s == NULL || *s == '\0')
1699 return g_strdup (s);
1703 #define COPY_FUNC _gst_strdup0
1706 * gst_tag_list_get_string:
1707 * @list: a #GstTagList to get the tag from
1708 * @tag: tag to read out
1709 * @value: (out callee-allocates) (transfer full): location for the result
1711 * Copies the contents for the given tag into the value, possibly merging
1712 * multiple values into one if multiple values are associated with the tag.
1714 * Use gst_tag_list_get_string_index (list, tag, 0, value) if you want
1715 * to retrieve the first string associated with this tag unmodified.
1717 * The resulting string in @value will be in UTF-8 encoding and should be
1718 * freed by the caller using g_free when no longer needed. Since 0.10.24 the
1719 * returned string is also guaranteed to be non-NULL and non-empty.
1721 * Free-function: g_free
1723 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1727 * gst_tag_list_get_string_index:
1728 * @list: a #GstTagList to get the tag from
1729 * @tag: tag to read out
1730 * @index: number of entry to read out
1731 * @value: (out callee-allocates) (transfer full): location for the result
1733 * Gets the value that is at the given index for the given tag in the given
1736 * The resulting string in @value will be in UTF-8 encoding and should be
1737 * freed by the caller using g_free when no longer needed. Since 0.10.24 the
1738 * returned string is also guaranteed to be non-NULL and non-empty.
1740 * Free-function: g_free
1742 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1745 TAG_MERGE_FUNCS (string, gchar *, (*value != NULL));
1748 *FIXME 0.11: Instead of _peek (non-copy) and _get (copy), we could have
1749 * _get (non-copy) and _dup (copy) for strings, seems more
1753 * gst_tag_list_peek_string_index:
1754 * @list: a #GstTagList to get the tag from
1755 * @tag: tag to read out
1756 * @index: number of entry to read out
1757 * @value: (out) (transfer none): location for the result
1759 * Peeks at the value that is at the given index for the given tag in the given
1762 * The resulting string in @value will be in UTF-8 encoding and doesn't need
1763 * to be freed by the caller. The returned string is also guaranteed to
1764 * be non-NULL and non-empty.
1766 * Returns: TRUE, if a value was set, FALSE if the tag didn't exist in the
1770 gst_tag_list_peek_string_index (const GstTagList * list,
1771 const gchar * tag, guint index, const gchar ** value)
1775 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1776 g_return_val_if_fail (tag != NULL, FALSE);
1777 g_return_val_if_fail (value != NULL, FALSE);
1779 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)
1781 *value = g_value_get_string (v);
1782 return *value != NULL && **value != '\0';
1786 * gst_tag_list_get_date:
1787 * @list: a #GstTagList to get the tag from
1788 * @tag: tag to read out
1789 * @value: (out callee-allocates) (transfer full): address of a GDate pointer
1790 * variable to store the result into
1792 * Copies the first date for the given tag in the taglist into the variable
1793 * pointed to by @value. Free the date with g_date_free() when it is no longer
1796 * Free-function: g_date_free
1798 * Returns: TRUE, if a date was copied, FALSE if the tag didn't exist in the
1799 * given list or if it was #NULL.
1802 gst_tag_list_get_date (const GstTagList * list, const gchar * tag,
1807 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1808 g_return_val_if_fail (tag != NULL, FALSE);
1809 g_return_val_if_fail (value != NULL, FALSE);
1811 if (!gst_tag_list_copy_value (&v, list, tag))
1813 *value = (GDate *) g_value_dup_boxed (&v);
1815 return (*value != NULL);
1819 * gst_tag_list_get_date_index:
1820 * @list: a #GstTagList to get the tag from
1821 * @tag: tag to read out
1822 * @index: number of entry to read out
1823 * @value: (out callee-allocates) (transfer full): location for the result
1825 * Gets the date that is at the given index for the given tag in the given
1826 * list and copies it into the variable pointed to by @value. Free the date
1827 * with g_date_free() when it is no longer needed.
1829 * Free-function: g_date_free
1831 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1832 * given list or if it was #NULL.
1835 gst_tag_list_get_date_index (const GstTagList * list,
1836 const gchar * tag, guint index, GDate ** value)
1840 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1841 g_return_val_if_fail (tag != NULL, FALSE);
1842 g_return_val_if_fail (value != NULL, FALSE);
1844 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)
1846 *value = (GDate *) g_value_dup_boxed (v);
1847 return (*value != NULL);
1851 * gst_tag_list_get_date_time:
1852 * @list: a #GstTagList to get the tag from
1853 * @tag: tag to read out
1854 * @value: (out callee-allocates) (transfer full): address of a #GstDateTime
1855 * pointer variable to store the result into
1857 * Copies the first datetime for the given tag in the taglist into the variable
1858 * pointed to by @value. Unref the date with gst_date_time_unref() when
1859 * it is no longer needed.
1861 * Free-function: gst_date_time_unref
1863 * Returns: TRUE, if a datetime was copied, FALSE if the tag didn't exist in
1864 * thegiven list or if it was #NULL.
1869 gst_tag_list_get_date_time (const GstTagList * list, const gchar * tag,
1870 GstDateTime ** value)
1874 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1875 g_return_val_if_fail (tag != NULL, FALSE);
1876 g_return_val_if_fail (value != NULL, FALSE);
1878 if (!gst_tag_list_copy_value (&v, list, tag))
1881 g_return_val_if_fail (GST_VALUE_HOLDS_DATE_TIME (&v), FALSE);
1883 *value = (GstDateTime *) g_value_dup_boxed (&v);
1885 return (*value != NULL);
1889 * gst_tag_list_get_date_time_index:
1890 * @list: a #GstTagList to get the tag from
1891 * @tag: tag to read out
1892 * @index: number of entry to read out
1893 * @value: (out callee-allocates) (transfer full): location for the result
1895 * Gets the datetime that is at the given index for the given tag in the given
1896 * list and copies it into the variable pointed to by @value. Unref the datetime
1897 * with gst_date_time_unref() when it is no longer needed.
1899 * Free-function: gst_date_time_unref
1901 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1902 * given list or if it was #NULL.
1907 gst_tag_list_get_date_time_index (const GstTagList * list,
1908 const gchar * tag, guint index, GstDateTime ** value)
1912 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1913 g_return_val_if_fail (tag != NULL, FALSE);
1914 g_return_val_if_fail (value != NULL, FALSE);
1916 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)
1918 *value = (GstDateTime *) g_value_dup_boxed (v);
1919 return (*value != NULL);
1923 * gst_tag_list_get_buffer:
1924 * @list: a #GstTagList to get the tag from
1925 * @tag: tag to read out
1926 * @value: (out callee-allocates) (transfer full): address of a GstBuffer
1927 * pointer variable to store the result into
1929 * Copies the first buffer for the given tag in the taglist into the variable
1930 * pointed to by @value. Free the buffer with gst_buffer_unref() when it is
1933 * Free-function: gst_buffer_unref
1935 * Returns: TRUE, if a buffer was copied, FALSE if the tag didn't exist in the
1936 * given list or if it was #NULL.
1941 gst_tag_list_get_buffer (const GstTagList * list, const gchar * tag,
1946 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1947 g_return_val_if_fail (tag != NULL, FALSE);
1948 g_return_val_if_fail (value != NULL, FALSE);
1950 if (!gst_tag_list_copy_value (&v, list, tag))
1952 *value = g_value_dup_boxed (&v);
1954 return (*value != NULL);
1958 * gst_tag_list_get_buffer_index:
1959 * @list: a #GstTagList to get the tag from
1960 * @tag: tag to read out
1961 * @index: number of entry to read out
1962 * @value: (out callee-allocates) (transfer full): address of a GstBuffer
1963 * pointer variable to store the result into
1965 * Gets the buffer that is at the given index for the given tag in the given
1966 * list and copies it into the variable pointed to by @value. Free the buffer
1967 * with gst_buffer_unref() when it is no longer needed.
1969 * Free-function: gst_buffer_unref
1971 * Returns: TRUE, if a buffer was copied, FALSE if the tag didn't exist in the
1972 * given list or if it was #NULL.
1977 gst_tag_list_get_buffer_index (const GstTagList * list,
1978 const gchar * tag, guint index, GstBuffer ** value)
1982 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1983 g_return_val_if_fail (tag != NULL, FALSE);
1984 g_return_val_if_fail (value != NULL, FALSE);
1986 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)
1988 *value = g_value_dup_boxed (v);
1989 return (*value != NULL);